1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.gui; |
22 |
|
|
23 |
|
import java.awt.BorderLayout; |
24 |
|
import java.awt.Color; |
25 |
|
import java.awt.Dimension; |
26 |
|
import java.awt.event.MouseAdapter; |
27 |
|
import java.awt.event.MouseEvent; |
28 |
|
import java.util.HashMap; |
29 |
|
import java.util.Map; |
30 |
|
|
31 |
|
import javax.swing.BorderFactory; |
32 |
|
import javax.swing.JLabel; |
33 |
|
import javax.swing.JPanel; |
34 |
|
import javax.swing.JSlider; |
35 |
|
import javax.swing.event.ChangeEvent; |
36 |
|
import javax.swing.event.ChangeListener; |
37 |
|
|
38 |
|
import jalview.datamodel.SequenceGroup; |
39 |
|
import jalview.gui.JalviewColourChooser.ColourChooserListener; |
40 |
|
import jalview.util.MessageManager; |
41 |
|
|
|
|
| 0% |
Uncovered Elements: 123 (123) |
Complexity: 23 |
Complexity Density: 0.25 |
|
42 |
|
public class TextColourChooser |
43 |
|
{ |
44 |
|
AlignmentPanel ap; |
45 |
|
|
46 |
|
SequenceGroup sg; |
47 |
|
|
48 |
|
Color original1, original2; |
49 |
|
|
50 |
|
int originalThreshold; |
51 |
|
|
52 |
|
Map<SequenceGroup, Color> groupColour1; |
53 |
|
|
54 |
|
Map<SequenceGroup, Color> groupColour2; |
55 |
|
|
56 |
|
Map<SequenceGroup, Integer> groupThreshold; |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
@param |
63 |
|
|
64 |
|
@param |
65 |
|
|
66 |
|
|
|
|
| 0% |
Uncovered Elements: 29 (29) |
Complexity: 1 |
Complexity Density: 0.03 |
|
67 |
0 |
public void chooseColour(AlignmentPanel alignPanel,... |
68 |
|
SequenceGroup sequenceGroup) |
69 |
|
{ |
70 |
0 |
this.ap = alignPanel; |
71 |
0 |
this.sg = sequenceGroup; |
72 |
|
|
73 |
0 |
saveInitialSettings(); |
74 |
|
|
75 |
0 |
final JSlider slider = new JSlider(0, 750, originalThreshold); |
76 |
0 |
final JPanel col1 = new JPanel(); |
77 |
0 |
col1.setPreferredSize(new Dimension(40, 20)); |
78 |
0 |
col1.setBorder(BorderFactory.createEtchedBorder()); |
79 |
0 |
col1.setToolTipText(MessageManager.getString("label.dark_colour")); |
80 |
0 |
col1.setBackground(original1); |
81 |
0 |
final JPanel col2 = new JPanel(); |
82 |
0 |
col2.setPreferredSize(new Dimension(40, 20)); |
83 |
0 |
col2.setBorder(BorderFactory.createEtchedBorder()); |
84 |
0 |
col2.setToolTipText(MessageManager.getString("label.light_colour")); |
85 |
0 |
col2.setBackground(original2); |
86 |
0 |
final JPanel bigpanel = new JPanel(new BorderLayout()); |
87 |
0 |
JPanel panel = new JPanel(new BorderLayout()); |
88 |
0 |
bigpanel.add(panel, BorderLayout.CENTER); |
89 |
0 |
bigpanel.add( |
90 |
|
new JLabel("<html>" |
91 |
|
+ MessageManager.getString( |
92 |
|
"label.select_dark_light_set_threshold") |
93 |
|
+ "</html>"), |
94 |
|
BorderLayout.NORTH); |
95 |
0 |
panel.add(col1, BorderLayout.WEST); |
96 |
0 |
panel.add(slider, BorderLayout.CENTER); |
97 |
0 |
panel.add(col2, BorderLayout.EAST); |
98 |
|
|
99 |
0 |
col1.addMouseListener(new MouseAdapter() |
100 |
|
{ |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
101 |
0 |
@Override... |
102 |
|
public void mousePressed(MouseEvent e) |
103 |
|
{ |
104 |
0 |
String ttl = MessageManager |
105 |
|
.getString("label.select_colour_for_text"); |
106 |
0 |
ColourChooserListener listener = new ColourChooserListener() |
107 |
|
{ |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
108 |
0 |
@Override... |
109 |
|
public void colourSelected(Color c) |
110 |
|
{ |
111 |
0 |
colour1Changed(c); |
112 |
0 |
col1.setBackground(c); |
113 |
|
} |
114 |
|
}; |
115 |
0 |
JalviewColourChooser.showColourChooser(bigpanel, ttl, |
116 |
|
col1.getBackground(), listener); |
117 |
|
} |
118 |
|
}); |
119 |
|
|
120 |
0 |
col2.addMouseListener(new MouseAdapter() |
121 |
|
{ |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
122 |
0 |
@Override... |
123 |
|
public void mousePressed(MouseEvent e) |
124 |
|
{ |
125 |
0 |
String ttl = MessageManager |
126 |
|
.getString("label.select_colour_for_text"); |
127 |
0 |
ColourChooserListener listener = new ColourChooserListener() |
128 |
|
{ |
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
129 |
0 |
@Override... |
130 |
|
public void colourSelected(Color c) |
131 |
|
{ |
132 |
0 |
colour2Changed(c); |
133 |
0 |
col2.setBackground(c); |
134 |
|
} |
135 |
|
}; |
136 |
0 |
JalviewColourChooser.showColourChooser(bigpanel, ttl, |
137 |
|
col2.getBackground(), listener); |
138 |
|
} |
139 |
|
}); |
140 |
|
|
141 |
0 |
slider.addChangeListener(new ChangeListener() |
142 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
143 |
0 |
@Override... |
144 |
|
public void stateChanged(ChangeEvent evt) |
145 |
|
{ |
146 |
0 |
thresholdChanged(slider.getValue()); |
147 |
|
} |
148 |
|
}); |
149 |
|
|
150 |
0 |
Object[] options = new Object[] { MessageManager.getString("action.ok"), |
151 |
|
MessageManager.getString("action.cancel") }; |
152 |
0 |
String title = MessageManager |
153 |
|
.getString("label.adjust_foreground_text_colour_threshold"); |
154 |
0 |
Runnable action = () -> |
155 |
|
{ |
156 |
0 |
restoreInitialSettings(); |
157 |
|
}; |
158 |
0 |
JvOptionPane.newOptionDialog(alignPanel.alignFrame) |
159 |
|
.setResponseHandler(1, action).showInternalDialog(bigpanel, |
160 |
|
title, JvOptionPane.YES_NO_CANCEL_OPTION, |
161 |
|
JvOptionPane.PLAIN_MESSAGE, null, options, |
162 |
|
MessageManager.getString("action.ok")); |
163 |
|
} |
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 2 |
Complexity Density: 0.17 |
|
168 |
0 |
protected void restoreInitialSettings()... |
169 |
|
{ |
170 |
0 |
if (sg == null) |
171 |
|
{ |
172 |
0 |
ap.av.setTextColour(original1); |
173 |
0 |
ap.av.setTextColour2(original2); |
174 |
0 |
ap.av.setThresholdTextColour(originalThreshold); |
175 |
|
} |
176 |
|
else |
177 |
|
{ |
178 |
0 |
sg.textColour = original1; |
179 |
0 |
sg.textColour2 = original2; |
180 |
0 |
sg.thresholdTextColour = originalThreshold; |
181 |
|
} |
182 |
|
|
183 |
|
|
184 |
|
|
185 |
|
|
186 |
|
|
187 |
0 |
for (SequenceGroup group : this.groupColour1.keySet()) |
188 |
|
{ |
189 |
0 |
group.textColour = groupColour1.get(group); |
190 |
0 |
group.textColour2 = groupColour2.get(group); |
191 |
0 |
group.thresholdTextColour = groupThreshold.get(group); |
192 |
|
} |
193 |
|
|
194 |
0 |
ap.paintAlignment(false, false); |
195 |
|
} |
196 |
|
|
197 |
|
|
198 |
|
|
199 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 4 |
Complexity Density: 0.27 |
|
200 |
0 |
protected void saveInitialSettings()... |
201 |
|
{ |
202 |
0 |
groupColour1 = new HashMap<>(); |
203 |
0 |
groupColour2 = new HashMap<>(); |
204 |
0 |
groupThreshold = new HashMap<>(); |
205 |
|
|
206 |
0 |
if (sg == null) |
207 |
|
{ |
208 |
|
|
209 |
|
|
210 |
|
|
211 |
0 |
original1 = ap.av.getTextColour(); |
212 |
0 |
original2 = ap.av.getTextColour2(); |
213 |
0 |
originalThreshold = ap.av.getThresholdTextColour(); |
214 |
0 |
if (ap.av.getColourAppliesToAllGroups() |
215 |
|
&& ap.av.getAlignment().getGroups() != null) |
216 |
|
{ |
217 |
|
|
218 |
|
|
219 |
|
|
220 |
|
|
221 |
0 |
for (SequenceGroup group : ap.av.getAlignment().getGroups()) |
222 |
|
{ |
223 |
0 |
groupColour1.put(group, group.textColour); |
224 |
0 |
groupColour2.put(group, group.textColour2); |
225 |
0 |
groupThreshold.put(group, group.thresholdTextColour); |
226 |
|
} |
227 |
|
} |
228 |
|
} |
229 |
|
else |
230 |
|
{ |
231 |
|
|
232 |
|
|
233 |
|
|
234 |
0 |
original1 = sg.textColour; |
235 |
0 |
original2 = sg.textColour2; |
236 |
0 |
originalThreshold = sg.thresholdTextColour; |
237 |
|
} |
238 |
|
} |
239 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
240 |
0 |
void colour1Changed(Color col)... |
241 |
|
{ |
242 |
0 |
if (sg == null) |
243 |
|
{ |
244 |
0 |
ap.av.setTextColour(col); |
245 |
0 |
if (ap.av.getColourAppliesToAllGroups()) |
246 |
|
{ |
247 |
0 |
setGroupTextColour(); |
248 |
|
} |
249 |
|
} |
250 |
|
else |
251 |
|
{ |
252 |
0 |
sg.textColour = col; |
253 |
|
} |
254 |
|
|
255 |
0 |
ap.paintAlignment(false, false); |
256 |
|
} |
257 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
258 |
0 |
void colour2Changed(Color col)... |
259 |
|
{ |
260 |
0 |
if (sg == null) |
261 |
|
{ |
262 |
0 |
ap.av.setTextColour2(col); |
263 |
0 |
if (ap.av.getColourAppliesToAllGroups()) |
264 |
|
{ |
265 |
0 |
setGroupTextColour(); |
266 |
|
} |
267 |
|
} |
268 |
|
else |
269 |
|
{ |
270 |
0 |
sg.textColour2 = col; |
271 |
|
} |
272 |
|
|
273 |
0 |
ap.paintAlignment(false, false); |
274 |
|
} |
275 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.5 |
|
276 |
0 |
void thresholdChanged(int value)... |
277 |
|
{ |
278 |
0 |
if (sg == null) |
279 |
|
{ |
280 |
0 |
ap.av.setThresholdTextColour(value); |
281 |
0 |
if (ap.av.getColourAppliesToAllGroups()) |
282 |
|
{ |
283 |
0 |
setGroupTextColour(); |
284 |
|
} |
285 |
|
} |
286 |
|
else |
287 |
|
{ |
288 |
0 |
sg.thresholdTextColour = value; |
289 |
|
} |
290 |
|
|
291 |
0 |
ap.paintAlignment(false, false); |
292 |
|
} |
293 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
294 |
0 |
void setGroupTextColour()... |
295 |
|
{ |
296 |
0 |
if (ap.av.getAlignment().getGroups() == null) |
297 |
|
{ |
298 |
0 |
return; |
299 |
|
} |
300 |
|
|
301 |
0 |
for (SequenceGroup group : ap.av.getAlignment().getGroups()) |
302 |
|
{ |
303 |
0 |
group.textColour = ap.av.getTextColour(); |
304 |
0 |
group.textColour2 = ap.av.getTextColour2(); |
305 |
0 |
group.thresholdTextColour = ap.av.getThresholdTextColour(); |
306 |
|
} |
307 |
|
} |
308 |
|
|
309 |
|
} |