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    import java.io.*;
8    import javax.swing.*;
9    import java.util.*;
10   
11   public class LineType implements Serializable,Comparable {
12   
13     private static final long serialVersionUID = Version.getSUID();
14   
15     static final int DEFAULT = 0;
16     static final int NONE = 1;
17     static final int SOLID = 2;
18     static final int DASHED = 3;
19     static final int DROP = 4;
20     static final int DOTTED = 5;
21     static final int CCHANGE = 6;
22   
23     static double DEFSCALE = 100;
24     static double DEFPERIOD = 5;
25   
26     public static TreeSet predefined;
27   
28     public String name;
29     public transient SavableStroke oldstroke =  null;
30   //  public Stroke samplestroke =  null;
31   
32     public transient double oldscale = 0;
33   //  double curscale=0;
34   
35     int type = SOLID;
36   //  int overtype = DOTTED;
37   //  int undertype = DASHED;
38   
39   //  Scaler width = null;
40   //  Scaler period = null;
41   //  Scaler tick = null;
42     
43   //  public Color color = null;
44   
45     public LineType(String name,int type) {
46       this.type = type;
47       this.name = name;
48     }
49   
50   //  public LineType(String name,int type,String size) {
51   //    this.name = name;
52   //    this.type = type;
53   //    width = new Scaler(size);
54   //    resize(DEFSCALE);
55   //    samplestroke = stroke;
56   //  }
57   
58     public int getType() {
59       return(type);
60     }
61   
62     public int setType() {
63       return(type);
64     }
65   
66     public String toString() {
67       return(name);
68     }
69   
70     public int compareTo(Object that) {
71       return(name.compareTo(((LineType)that).name));
72     }
73   
74     public boolean equals(Object that) {
75       return((that instanceof LineType)&&name.compareTo(((LineType)that).name)==0);
76     }
77   
78     public SavableStroke getStroke(double scale) {
79       if (scale==oldscale) return(oldstroke);
80       oldscale=scale;
81       if (scale<0.0001) return(oldstroke=null);     //scale is pixels so thats ~=0
82       else
83         switch (type) {
84         case SOLID:
85           return(oldstroke = new SavableStroke(scale));
86         case NONE:
87           return(oldstroke = null);
88         case DROP:
89           return(oldstroke = new Drop(scale,scale*DEFPERIOD));
90         case CCHANGE:
91           return(oldstroke = new Cchange(scale,scale*DEFPERIOD/2));
92         case DOTTED:
93           return(oldstroke = new Doted(scale,scale*DEFPERIOD/2));
94         case DASHED:
95           float[] ndash = {(float)(scale*DEFPERIOD/2),(float)(scale*DEFPERIOD/2)};
96           return(oldstroke = new SavableStroke((float)scale,BasicStroke.CAP_BUTT,
97           			      BasicStroke.JOIN_MITER,(float)10.0,ndash,0));
98         }
99       return(null);
100    }
101  
102  //  public static String ONEPIXEL = "1 0";
103  //  public static String BIG = "1 0 20 0.05 1.0 100 5 0";
104  //  public static String MEDIUM = "0 0 20 1 0 40 0.025 1 100 2.5 0";
105  //  public static String SMALL = "0 0 40 1 0 80 0.0125 1 100 1.25 0";
106  //  public static String TINY = "0 0 80 1 0";
107    static String[] majornames = {"Generic","Invisible","Wall","Detail","Drop","Block","Ceiling","Dashed","Dotted"};//,"Over"};
108    static String[] sizenames = {"Major","Medium","Minor","Thin"};
109    static int[] types = {SOLID,NONE,SOLID,SOLID,DROP,SOLID,CCHANGE,DASHED,DOTTED};
110  //  static String[][] sizes = {{ONEPIXEL},
111  //        		     null,
112  //        		     {BIG,MEDIUM,SMALL,ONEPIXEL},
113  //        		     {MEDIUM,SMALL,TINY,ONEPIXEL},
114  //        		     {BIG,MEDIUM,SMALL,ONEPIXEL},
115  //        		     {MEDIUM,SMALL,TINY,ONEPIXEL},
116  //        		     {BIG,MEDIUM,SMALL,ONEPIXEL},
117  //        		     {BIG,MEDIUM,SMALL,ONEPIXEL},
118  //        		     {MEDIUM,SMALL,TINY,ONEPIXEL}};
119  
120    static  {
121      predefined = new TreeSet();
122      for (int i=0;i<majornames.length;i++) {
123        predefined.add(new LineType(majornames[i],types[i]));
124      }
125    }
126  
127    static LineType lookup(String newname) {
128      for (Iterator it=predefined.iterator();it.hasNext();) {
129        LineType type = (LineType)it.next();
130        if (newname.startsWith(type.name)) return(type);
131      }
132      return(null);
133    }
134  
135  }
136