1
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
31
32 public transient double oldscale = 0;
33
34
35 int type = SOLID;
36
37
38
39
40
41
42
43
44
45 public LineType(String name,int type) {
46 this.type = type;
47 this.name = name;
48 }
49
50
51
52
53
54
55
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);
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
103
104
105
106
107 static String[] majornames = {"Generic","Invisible","Wall","Detail","Drop","Block","Ceiling","Dashed","Dotted"};
108 static String[] sizenames = {"Major","Medium","Minor","Thin"};
109 static int[] types = {SOLID,NONE,SOLID,SOLID,DROP,SOLID,CCHANGE,DASHED,DOTTED};
110
111
112
113
114
115
116
117
118
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