1 package org.catacomb.graph.gui;
2
3
4 import org.catacomb.interlish.content.ColorTable;
5 import org.catacomb.interlish.structure.ColorMapped;
6 import org.catacomb.interlish.structure.Colored;
7 import org.catacomb.interlish.structure.IDable;
8 import org.catacomb.report.E;
9
10
11 import java.awt.Color;
12
13
14 public class DisplayStyleSet implements Colored, ColorMapped, IDable {
15
16 public String id;
17
18 public final static String[] styleNames= {"solid", "dotted", "short dash",
19 "long dash", "dot-dash"
20 };
21
22
23 int lineStyle;
24
25 public final static String[] widthNames = {"1", "1.5", "2", "3", "4"};
26 public final static double[] widths = {1., 1.5, 2., 3., 4.};
27 int lineWidthIndex;
28 double lineWidth;
29
30
31 static Color defaultColor = new Color(201, 202, 203);
32
33 Color lineColor;
34
35 String colorTableName;
36 ColorTable r_colorTable;
37
38 boolean assignedLine;
39 boolean assignedColor;
40
41 static int lineStyleCounter;
42 static int colorCounter;
43
44
45 public DisplayStyleSet() {
46 lineStyle = 0;
47 setLineWidthName("1");
48 setLineColor(defaultColor);
49 setColorTable("default");
50 assignedLine = false;
51 assignedColor = false;
52 }
53
54 public DisplayStyleSet(String s) {
55 this();
56 setID(s);
57 }
58
59 public void setID(String s) {
60 id = s;
61 }
62
63 public String getID() {
64 return id;
65 }
66
67
68 public String toString() {
69 return id;
70 }
71
72
73 public Color getColor() {
74 return lineColor;
75 }
76
77
78 public final void setLineStyle(String s) {
79 int isty = -1;
80 for (int i = 0; i < styleNames.length; i++) {
81 if (styleNames[i].equals(s)) {
82 isty = i;
83 break;
84 }
85 }
86 if (isty < 0) {
87 lineStyle = 0;
88 E.warning("unrecognized style " + s);
89
90 } else {
91 lineStyle = isty;
92 }
93 assignedLine = true;
94 }
95
96 public final void setLineWidthName(String s) {
97 int isty = -1;
98 for (int i = 0; i < widthNames.length; i++) {
99 if (widthNames[i].equals(s)) {
100 isty = i;
101 break;
102 }
103 }
104 if (isty < 0) {
105 isty = 0;
106 E.warning("unrecognized width " + s);
107 }
108 lineWidthIndex = isty;
109 lineWidth = widths[isty];
110 }
111
112
113 public int getLineWidthIndex() {
114 return lineWidthIndex;
115 }
116
117
118 public static double[] getIndexedWidths() {
119 return widths;
120 }
121
122 public static String[] getStyleNames() {
123 return styleNames;
124 }
125
126
127 public final void setLineColor(Color c) {
128 lineColor = c;
129 assignedColor = true;
130 }
131
132
133 public final void setColorTable(String s) {
134 colorTableName = s;
135 r_colorTable = null;
136 }
137
138 public final void setColorTable(ColorTable ct) {
139 r_colorTable = ct;
140 colorTableName = ct.getName();
141 }
142
143 public String getStringLineStyle() {
144 return styleNames[lineStyle];
145 }
146
147 public int getLineStyleIndex() {
148 return lineStyle;
149 }
150
151 public double getLineWidth() {
152 return lineWidth;
153 }
154
155 public Color getLineColor() {
156 return lineColor;
157 }
158
159 public ColorTable getColorTable() {
160 return r_colorTable;
161 }
162
163
164 public String getColorTableName() {
165 return colorTableName;
166 }
167
168
169 public String getStringLineWidth() {
170 return widthNames[lineWidthIndex];
171 }
172
173
174 public void assignIfUnset() {
175 if (assignedLine) {
176
177 } else {
178 lineStyle = lineStyleCounter;
179 lineStyleCounter = (lineStyleCounter + 1) % (styleNames.length);
180 assignedLine = true;
181 }
182
183 if (assignedColor) {
184
185 } else {
186 Color c = new Color((int)(255 * Math.random()),(int)(255 * Math.random()),(int)(255 * Math.random()));
187 setLineColor(c);
188 assignedColor = true;
189 }
190
191 }
192
193
194
195 }