1    /*
2    Copyright 2000 by Ralph Hartley
3    This software is licenced under the terms of the
4    Gnu Public Licence
5    */
6    import java.awt.*;
7    
8    public class CurveAtt implements java.io.Serializable {
9    
10     private static final long serialVersionUID = Version.getSUID();
11   
12     public Color color;
13     public LineType type;
14     public Size thickness;
15     public boolean flip;
16   
17     public CurveAtt(LineType type,Color color,boolean flip,Size thickness) {
18       this.color = color;
19       this.type = type;
20       this.flip = flip;
21       this.thickness = thickness;
22     }
23   
24     public CurveAtt(CurveAtt old) {
25       color = old.color;
26       type = old.type;
27       flip = old.flip;
28       thickness = old.thickness;
29     }
30   
31     public boolean equals(Object other) {
32       return((other instanceof CurveAtt) &&
33              ((CurveAtt)other).color==color &&
34              ((CurveAtt)other).type==type &&
35              ((CurveAtt)other).flip==flip &&
36              ((CurveAtt)other).thickness==thickness
37         );
38     }
39   
40     static boolean warned = false;
41   
42     /**
43      * Older versions did not have thickness separate from type.
44      * When reading one of those, thickness will be null,
45      * so we try to guess its thickness from the type name.
46      * Old line types of many thicknesses didn't work
47      * well anyway.
48      */
49     private void readObject(java.io.ObjectInputStream stream)
50         throws java.io.IOException,java.lang.ClassNotFoundException {
51       stream.defaultReadObject();
52   //    System.out.print(""+thickness.toSuperString()+" aka ");
53   //    if (thickness!=null) thickness = (Size)thickness.getGlobal(Size.class);
54   //    System.out.println(""+thickness+" is now "+thickness.toSuperString());
55       if (type==null) {
56         type = LineType.lookup("Generic");
57         thickness = (Size)FileDefaultable.lookup(Size.class,Size.PIXEL);
58       }
59       if (color==null) color = color.black;
60       if (thickness==null) {
61         String oldname = type.name;
62         if (type.name.endsWith("Major")) thickness = (Size)FileDefaultable.lookup(Size.class,Size.MAJOR);
63         else if (type.name.endsWith("Medium")) thickness = (Size)FileDefaultable.lookup(Size.class,Size.MEDIUM);
64         else if (type.name.endsWith("Minor")) thickness = (Size)FileDefaultable.lookup(Size.class,Size.SMALL);
65         else thickness = (Size)FileDefaultable.lookup(Size.class,Size.PIXEL);
66   
67         // This is an old type, better replace with a new one.
68         for (java.util.Iterator it=LineType.predefined.iterator();it.hasNext();) {
69           LineType newtype = (LineType)it.next();
70           if (type.name.startsWith(newtype.name)) {
71             type = newtype;
72             break;
73           }
74         }
75   
76         if (!warned || thickness==null || type==null) {
77           String warning = "Reading an old style line type\n"+
78             "Old type has name "+oldname+"\n";
79   
80           if (type!=null) warning += "Replacing it with type "+type.name+".\n";
81           else warning += "--- FAILED --- to find an equivalent new type,\nThis could be bad!\n";
82   
83           if (thickness!=null) warning += "New thickness is "+thickness.name+".\n";
84           else warning += "--- FAILED --- to find a size for the new type,\nThis could be very bad!\n"+
85                  "(In fact it should be impossible)\n";
86   
87           warning += "More substitutions may be made, but no warning will\n"+
88             "be given unless there is a problem.";
89           
90           ErrorLog.log(warning);
91   //        ErrorLog.exception(new Exception("Stack trace for old style linetype"));
92           warned = true;
93         }
94       }
95     }
96   }
97