1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.cosylab.gui.displayers;
21
22 import java.awt.Color;
23
24 import com.cosylab.util.BitCondition;
25
26
27
28
29
30
31
32 public class DefaultConditionDescriptor implements ConditionDescriptor
33 {
34
35 public static final Color DEFAULT_ERROR = Color.RED;
36
37
38 public static final Color DEFAULT_UNUSED = Color.GRAY;
39
40
41 public static final Color DEFAULT_WARNING = Color.YELLOW;
42
43
44 public static final Color DEFAULT_OK = Color.GREEN;
45 private static BitCondition[] conditions = null;
46 private static Color[] colors = null;
47 private static boolean overRide = false;
48
49
50
51
52 public DefaultConditionDescriptor()
53 {
54 conditions=BitCondition.values();
55
56 colors = new Color[conditions.length];
57
58 for (int i = 0; i < conditions.length; i++) {
59 colors[i] = Color.BLACK;
60 }
61
62 setDefaultColors();
63 }
64
65
66
67
68 public void setDefaultColors()
69 {
70 for (int i = 0; i < conditions.length; i++) {
71 if (conditions[i] == BitCondition.UNUSED) {
72 colors[i] = DEFAULT_UNUSED;
73 } else if (conditions[i] == BitCondition.OK) {
74 colors[i] = DEFAULT_OK;
75 } else if (conditions[i] == BitCondition.WARNING) {
76 colors[i] = DEFAULT_WARNING;
77 } else if (conditions[i] == BitCondition.ERROR) {
78 colors[i] = DEFAULT_ERROR;
79 }
80 }
81 }
82
83
84
85
86
87
88 public Color toColor(BitCondition condition)
89 {
90 Color c = null;
91
92 for (int i = 0; i < conditions.length; i++) {
93 if (condition == conditions[i]) {
94 c = colors[i];
95 }
96 }
97
98 return c;
99 }
100
101 private void checkIfColorAllreadyUsed(BitCondition condition, Color color)
102 throws IllegalArgumentException
103 {
104 for (int i = 0; i < conditions.length; i++) {
105 if (colors[i] == color && condition != conditions[i]) {
106 if (overRide == false) {
107 throw new IllegalArgumentException();
108 }
109 }
110 }
111 }
112
113
114
115
116
117
118
119
120
121 public void putConditionToColor(BitCondition condition, Color color)
122 {
123 checkIfColorAllreadyUsed(condition, color);
124
125 for (int i = 0; i < conditions.length; i++) {
126 if (condition == conditions[i]) {
127 colors[i] = color;
128 }
129 }
130 }
131
132
133
134
135
136
137
138
139 public void setOverRideOn(boolean value)
140 {
141 overRide = value;
142 }
143
144
145
146
147
148
149 public boolean isOverRideOn()
150 {
151 return overRide;
152 }
153
154
155
156
157
158
159 public BitCondition toCondition(Color color)
160 {
161 BitCondition c = null;
162
163 for (int i = 0; i < conditions.length; i++) {
164 if (color == colors[i]) {
165 c = conditions[i];
166 }
167 }
168
169 return c;
170 }
171
172
173
174
175 public void clear()
176 {
177 colors = null;
178 }
179 }
180
181