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 jalview.bin.Cache; |
24 |
|
import jalview.datamodel.AlignmentAnnotation; |
25 |
|
import jalview.datamodel.GraphLine; |
26 |
|
import jalview.datamodel.SequenceGroup; |
27 |
|
import jalview.gui.JalviewColourChooser.ColourChooserListener; |
28 |
|
import jalview.schemes.AnnotationColourGradient; |
29 |
|
import jalview.schemes.ColourSchemeI; |
30 |
|
import jalview.util.MessageManager; |
31 |
|
|
32 |
|
import java.awt.BorderLayout; |
33 |
|
import java.awt.Color; |
34 |
|
import java.awt.Dimension; |
35 |
|
import java.awt.FlowLayout; |
36 |
|
import java.awt.event.ActionEvent; |
37 |
|
import java.awt.event.ActionListener; |
38 |
|
import java.awt.event.MouseAdapter; |
39 |
|
import java.awt.event.MouseEvent; |
40 |
|
import java.util.Hashtable; |
41 |
|
import java.util.Vector; |
42 |
|
|
43 |
|
import javax.swing.BorderFactory; |
44 |
|
import javax.swing.JButton; |
45 |
|
import javax.swing.JCheckBox; |
46 |
|
import javax.swing.JComboBox; |
47 |
|
import javax.swing.JInternalFrame; |
48 |
|
import javax.swing.JLayeredPane; |
49 |
|
import javax.swing.JPanel; |
50 |
|
|
51 |
|
import net.miginfocom.swing.MigLayout; |
52 |
|
|
53 |
|
@SuppressWarnings("serial") |
|
|
| 0% |
Uncovered Elements: 239 (239) |
Complexity: 45 |
Complexity Density: 0.25 |
|
54 |
|
public class AnnotationColourChooser extends AnnotationRowFilter |
55 |
|
{ |
56 |
|
private static final int ONETHOUSAND = 1000; |
57 |
|
|
58 |
|
private ColourSchemeI oldcs; |
59 |
|
|
60 |
|
private JButton defColours; |
61 |
|
|
62 |
|
private Hashtable<SequenceGroup, ColourSchemeI> oldgroupColours; |
63 |
|
|
64 |
|
private JCheckBox useOriginalColours = new JCheckBox(); |
65 |
|
|
66 |
|
JPanel minColour = new JPanel(); |
67 |
|
|
68 |
|
JPanel maxColour = new JPanel(); |
69 |
|
|
70 |
|
private JCheckBox thresholdIsMin = new JCheckBox(); |
71 |
|
|
72 |
|
protected static final int MIN_WIDTH = 500; |
73 |
|
|
74 |
|
protected static final int MIN_HEIGHT = 240; |
75 |
|
|
|
|
| 0% |
Uncovered Elements: 63 (63) |
Complexity: 11 |
Complexity Density: 0.22 |
|
76 |
0 |
public AnnotationColourChooser(AlignViewport av, final AlignmentPanel ap)... |
77 |
|
{ |
78 |
0 |
super(av, ap); |
79 |
0 |
oldcs = av.getGlobalColourScheme(); |
80 |
0 |
if (av.getAlignment().getGroups() != null) |
81 |
|
{ |
82 |
0 |
oldgroupColours = new Hashtable<>(); |
83 |
0 |
for (SequenceGroup sg : ap.av.getAlignment().getGroups()) |
84 |
|
{ |
85 |
0 |
if (sg.getColourScheme() != null) |
86 |
|
{ |
87 |
0 |
oldgroupColours.put(sg, sg.getColourScheme()); |
88 |
|
} |
89 |
|
} |
90 |
|
} |
91 |
0 |
frame = new JInternalFrame(); |
92 |
0 |
frame.setContentPane(this); |
93 |
0 |
frame.setLayer(JLayeredPane.PALETTE_LAYER); |
94 |
0 |
Desktop.addInternalFrame(frame, |
95 |
|
MessageManager.getString("label.colour_by_annotation"), 520, |
96 |
|
215); |
97 |
0 |
frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT)); |
98 |
0 |
addSliderChangeListener(); |
99 |
0 |
addSliderMouseListeners(); |
100 |
|
|
101 |
0 |
if (av.getAlignment().getAlignmentAnnotation() == null) |
102 |
|
{ |
103 |
0 |
return; |
104 |
|
} |
105 |
|
|
106 |
|
|
107 |
0 |
setDefaultMinMax(); |
108 |
|
|
109 |
0 |
adjusting = true; |
110 |
0 |
if (oldcs instanceof AnnotationColourGradient) |
111 |
|
{ |
112 |
0 |
AnnotationColourGradient acg = (AnnotationColourGradient) oldcs; |
113 |
0 |
useOriginalColours.setSelected( |
114 |
|
acg.isPredefinedColours() || acg.getBaseColour() != null); |
115 |
0 |
if (!acg.isPredefinedColours() && acg.getBaseColour() == null) |
116 |
|
{ |
117 |
0 |
minColour.setBackground(acg.getMinColour()); |
118 |
0 |
maxColour.setBackground(acg.getMaxColour()); |
119 |
|
} |
120 |
0 |
seqAssociated.setSelected(acg.isSeqAssociated()); |
121 |
|
|
122 |
|
} |
123 |
0 |
Vector<String> annotItems = getAnnotationItems( |
124 |
|
seqAssociated.isSelected()); |
125 |
0 |
annotations = new JComboBox<>(annotItems); |
126 |
|
|
127 |
0 |
populateThresholdComboBox(threshold); |
128 |
|
|
129 |
0 |
if (oldcs instanceof AnnotationColourGradient) |
130 |
|
{ |
131 |
0 |
AnnotationColourGradient acg = (AnnotationColourGradient) oldcs; |
132 |
0 |
String label = getAnnotationMenuLabel(acg.getAnnotation()); |
133 |
0 |
annotations.setSelectedItem(label); |
134 |
0 |
switch (acg.getAboveThreshold()) |
135 |
|
{ |
136 |
0 |
case AnnotationColourGradient.NO_THRESHOLD: |
137 |
0 |
getThreshold().setSelectedIndex(0); |
138 |
0 |
break; |
139 |
0 |
case AnnotationColourGradient.ABOVE_THRESHOLD: |
140 |
0 |
getThreshold().setSelectedIndex(1); |
141 |
0 |
break; |
142 |
0 |
case AnnotationColourGradient.BELOW_THRESHOLD: |
143 |
0 |
getThreshold().setSelectedIndex(2); |
144 |
0 |
break; |
145 |
0 |
default: |
146 |
0 |
throw new Error(MessageManager.getString( |
147 |
|
"error.implementation_error_dont_know_about_threshold_setting")); |
148 |
|
} |
149 |
0 |
thresholdIsMin.setSelected(acg.isThresholdIsMinMax()); |
150 |
0 |
thresholdValue.setText("" + acg.getAnnotationThreshold()); |
151 |
|
} |
152 |
|
|
153 |
0 |
jbInit(); |
154 |
0 |
adjusting = false; |
155 |
|
|
156 |
0 |
updateView(); |
157 |
0 |
frame.invalidate(); |
158 |
0 |
frame.pack(); |
159 |
|
} |
160 |
|
|
|
|
| 0% |
Uncovered Elements: 52 (52) |
Complexity: 1 |
Complexity Density: 0.02 |
|
161 |
0 |
@Override... |
162 |
|
protected void jbInit() |
163 |
|
{ |
164 |
0 |
super.jbInit(); |
165 |
|
|
166 |
0 |
minColour.setFont(JvSwingUtils.getLabelFont()); |
167 |
0 |
minColour.setBorder(BorderFactory.createEtchedBorder()); |
168 |
0 |
minColour.setPreferredSize(new Dimension(40, 20)); |
169 |
0 |
minColour.setToolTipText(MessageManager.getString("label.min_colour")); |
170 |
0 |
minColour.addMouseListener(new MouseAdapter() |
171 |
|
{ |
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
172 |
0 |
@Override... |
173 |
|
public void mousePressed(MouseEvent e) |
174 |
|
{ |
175 |
0 |
if (minColour.isEnabled()) |
176 |
|
{ |
177 |
0 |
showColourChooser(minColour, "label.select_colour_minimum_value"); |
178 |
|
} |
179 |
|
} |
180 |
|
}); |
181 |
0 |
maxColour.setFont(JvSwingUtils.getLabelFont()); |
182 |
0 |
maxColour.setBorder(BorderFactory.createEtchedBorder()); |
183 |
0 |
maxColour.setPreferredSize(new Dimension(40, 20)); |
184 |
0 |
maxColour.setToolTipText(MessageManager.getString("label.max_colour")); |
185 |
0 |
maxColour.addMouseListener(new MouseAdapter() |
186 |
|
{ |
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
187 |
0 |
@Override... |
188 |
|
public void mousePressed(MouseEvent e) |
189 |
|
{ |
190 |
0 |
if (maxColour.isEnabled()) |
191 |
|
{ |
192 |
0 |
showColourChooser(maxColour, "label.select_colour_maximum_value"); |
193 |
|
} |
194 |
|
} |
195 |
|
}); |
196 |
|
|
197 |
0 |
defColours = new JButton(); |
198 |
0 |
defColours.setOpaque(false); |
199 |
0 |
defColours.setText(MessageManager.getString("action.set_defaults")); |
200 |
0 |
defColours.setToolTipText(MessageManager |
201 |
|
.getString("label.reset_min_max_colours_to_defaults")); |
202 |
0 |
defColours.addActionListener(new ActionListener() |
203 |
|
{ |
204 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
205 |
0 |
@Override... |
206 |
|
public void actionPerformed(ActionEvent arg0) |
207 |
|
{ |
208 |
0 |
resetColours_actionPerformed(); |
209 |
|
} |
210 |
|
}); |
211 |
|
|
212 |
0 |
useOriginalColours.setFont(JvSwingUtils.getLabelFont()); |
213 |
0 |
useOriginalColours.setOpaque(false); |
214 |
0 |
useOriginalColours.setText( |
215 |
|
MessageManager.getString("label.use_original_colours")); |
216 |
0 |
useOriginalColours.addActionListener(new ActionListener() |
217 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
218 |
0 |
@Override... |
219 |
|
public void actionPerformed(ActionEvent e) |
220 |
|
{ |
221 |
0 |
originalColours_actionPerformed(); |
222 |
|
} |
223 |
|
}); |
224 |
0 |
thresholdIsMin.setBackground(Color.white); |
225 |
0 |
thresholdIsMin.setFont(JvSwingUtils.getLabelFont()); |
226 |
0 |
thresholdIsMin |
227 |
|
.setText(MessageManager.getString("label.threshold_minmax")); |
228 |
0 |
thresholdIsMin.addActionListener(new ActionListener() |
229 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
230 |
0 |
@Override... |
231 |
|
public void actionPerformed(ActionEvent actionEvent) |
232 |
|
{ |
233 |
0 |
thresholdIsMin_actionPerformed(); |
234 |
|
} |
235 |
|
}); |
236 |
0 |
seqAssociated.setBackground(Color.white); |
237 |
0 |
seqAssociated.setFont(JvSwingUtils.getLabelFont()); |
238 |
0 |
seqAssociated |
239 |
|
.setText(MessageManager.getString("label.per_sequence_only")); |
240 |
0 |
seqAssociated.addActionListener(new ActionListener() |
241 |
|
{ |
242 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
243 |
0 |
@Override... |
244 |
|
public void actionPerformed(ActionEvent arg0) |
245 |
|
{ |
246 |
0 |
seqAssociated_actionPerformed(annotations); |
247 |
|
} |
248 |
|
}); |
249 |
|
|
250 |
0 |
this.setLayout(new BorderLayout()); |
251 |
0 |
JPanel jPanel1 = new JPanel(); |
252 |
0 |
JPanel jPanel2 = new JPanel(); |
253 |
0 |
jPanel2.setLayout(new MigLayout("", "[left][center][right]", "[][][]")); |
254 |
0 |
jPanel1.setBackground(Color.white); |
255 |
0 |
jPanel2.setBackground(Color.white); |
256 |
|
|
257 |
0 |
jPanel1.add(ok); |
258 |
0 |
jPanel1.add(cancel); |
259 |
0 |
jPanel2.add(annotations, "grow, wrap"); |
260 |
0 |
jPanel2.add(seqAssociated); |
261 |
0 |
jPanel2.add(useOriginalColours); |
262 |
0 |
JPanel colpanel = new JPanel(new FlowLayout()); |
263 |
0 |
colpanel.setBackground(Color.white); |
264 |
0 |
colpanel.add(minColour); |
265 |
0 |
colpanel.add(maxColour); |
266 |
0 |
jPanel2.add(colpanel, "wrap"); |
267 |
0 |
jPanel2.add(getThreshold()); |
268 |
0 |
jPanel2.add(defColours, "skip 1, wrap"); |
269 |
0 |
jPanel2.add(thresholdIsMin); |
270 |
0 |
jPanel2.add(slider, "grow"); |
271 |
0 |
jPanel2.add(thresholdValue, "grow"); |
272 |
0 |
this.add(jPanel1, java.awt.BorderLayout.SOUTH); |
273 |
0 |
this.add(jPanel2, java.awt.BorderLayout.CENTER); |
274 |
0 |
this.validate(); |
275 |
|
} |
276 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
277 |
0 |
protected void resetColours_actionPerformed()... |
278 |
|
{ |
279 |
0 |
setDefaultMinMax(); |
280 |
0 |
updateView(); |
281 |
|
} |
282 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
283 |
0 |
private void setDefaultMinMax()... |
284 |
|
{ |
285 |
0 |
minColour.setBackground( |
286 |
|
Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange)); |
287 |
0 |
maxColour.setBackground( |
288 |
|
Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red)); |
289 |
|
} |
290 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
291 |
0 |
protected void showColourChooser(JPanel colourPanel, String titleKey)... |
292 |
|
{ |
293 |
0 |
String ttl = MessageManager.getString(titleKey); |
294 |
0 |
ColourChooserListener listener = new ColourChooserListener() |
295 |
|
{ |
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
296 |
0 |
@Override... |
297 |
|
public void colourSelected(Color c) |
298 |
|
{ |
299 |
0 |
colourPanel.setBackground(c); |
300 |
0 |
colourPanel.repaint(); |
301 |
0 |
updateView(); |
302 |
|
} |
303 |
|
}; |
304 |
0 |
JalviewColourChooser.showColourChooser(Desktop.getDesktop(), ttl, |
305 |
|
colourPanel.getBackground(), listener); |
306 |
|
} |
307 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
308 |
0 |
@Override... |
309 |
|
public void reset() |
310 |
|
{ |
311 |
0 |
av.setGlobalColourScheme(oldcs); |
312 |
0 |
if (av.getAlignment().getGroups() != null) |
313 |
|
{ |
314 |
|
|
315 |
0 |
for (SequenceGroup sg : ap.av.getAlignment().getGroups()) |
316 |
|
{ |
317 |
0 |
sg.setColourScheme(oldgroupColours.get(sg)); |
318 |
|
} |
319 |
|
} |
320 |
|
} |
321 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 4 |
Complexity Density: 0.67 |
|
322 |
0 |
@Override... |
323 |
|
public void valueChanged(boolean updateAllAnnotation) |
324 |
|
{ |
325 |
0 |
if (slider.isEnabled()) |
326 |
|
{ |
327 |
0 |
if (useOriginalColours.isSelected() && !(av |
328 |
|
.getGlobalColourScheme() instanceof AnnotationColourGradient)) |
329 |
|
{ |
330 |
0 |
updateView(); |
331 |
|
} |
332 |
0 |
getCurrentAnnotation().threshold.value = slider.getValue() / 1000f; |
333 |
0 |
propagateSeqAssociatedThreshold(updateAllAnnotation, |
334 |
|
getCurrentAnnotation()); |
335 |
0 |
ap.paintAlignment(false, false); |
336 |
|
} |
337 |
|
} |
338 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
339 |
0 |
public void originalColours_actionPerformed()... |
340 |
|
{ |
341 |
0 |
boolean selected = useOriginalColours.isSelected(); |
342 |
0 |
if (selected) |
343 |
|
{ |
344 |
0 |
reset(); |
345 |
|
} |
346 |
0 |
maxColour.setEnabled(!selected); |
347 |
0 |
minColour.setEnabled(!selected); |
348 |
0 |
thresholdIsMin.setEnabled(!selected); |
349 |
0 |
updateView(); |
350 |
|
} |
351 |
|
|
|
|
| 0% |
Uncovered Elements: 35 (35) |
Complexity: 6 |
Complexity Density: 0.22 |
|
352 |
0 |
@Override... |
353 |
|
public void updateView() |
354 |
|
{ |
355 |
|
|
356 |
0 |
if (adjusting) |
357 |
|
{ |
358 |
0 |
return; |
359 |
|
} |
360 |
|
|
361 |
0 |
setCurrentAnnotation( |
362 |
|
av.getAlignment().getAlignmentAnnotation()[annmap[annotations |
363 |
|
.getSelectedIndex()]]); |
364 |
|
|
365 |
0 |
int selectedThresholdItem = getSelectedThresholdItem( |
366 |
|
getThreshold().getSelectedIndex()); |
367 |
|
|
368 |
0 |
slider.setEnabled(true); |
369 |
0 |
thresholdValue.setEnabled(true); |
370 |
0 |
thresholdIsMin.setEnabled(!useOriginalColours.isSelected()); |
371 |
|
|
372 |
0 |
if (selectedThresholdItem == AnnotationColourGradient.NO_THRESHOLD) |
373 |
|
{ |
374 |
0 |
slider.setEnabled(false); |
375 |
0 |
thresholdValue.setEnabled(false); |
376 |
0 |
thresholdValue.setText(""); |
377 |
0 |
thresholdIsMin.setEnabled(false); |
378 |
|
} |
379 |
0 |
else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD |
380 |
|
&& getCurrentAnnotation().threshold == null) |
381 |
|
{ |
382 |
0 |
getCurrentAnnotation().setThreshold(new GraphLine( |
383 |
|
(getCurrentAnnotation().graphMax |
384 |
|
- getCurrentAnnotation().graphMin) / 2f, |
385 |
|
"Threshold", Color.black)); |
386 |
|
} |
387 |
|
|
388 |
0 |
if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD) |
389 |
|
{ |
390 |
0 |
adjusting = true; |
391 |
0 |
float range = getCurrentAnnotation().graphMax * ONETHOUSAND |
392 |
|
- getCurrentAnnotation().graphMin * ONETHOUSAND; |
393 |
|
|
394 |
0 |
slider.setMinimum( |
395 |
|
(int) (getCurrentAnnotation().graphMin * ONETHOUSAND)); |
396 |
0 |
slider.setMaximum( |
397 |
|
(int) (getCurrentAnnotation().graphMax * ONETHOUSAND)); |
398 |
0 |
slider.setValue( |
399 |
|
(int) (getCurrentAnnotation().threshold.value * ONETHOUSAND)); |
400 |
0 |
thresholdValue.setText(getCurrentAnnotation().threshold.value + ""); |
401 |
0 |
slider.setMajorTickSpacing((int) (range / 10f)); |
402 |
0 |
slider.setEnabled(true); |
403 |
0 |
thresholdValue.setEnabled(true); |
404 |
0 |
adjusting = false; |
405 |
|
} |
406 |
0 |
colorAlignmentContaining(getCurrentAnnotation(), selectedThresholdItem); |
407 |
|
|
408 |
0 |
ap.alignmentChanged(); |
409 |
|
} |
410 |
|
|
|
|
| 0% |
Uncovered Elements: 22 (22) |
Complexity: 6 |
Complexity Density: 0.43 |
|
411 |
0 |
protected void colorAlignmentContaining(AlignmentAnnotation currentAnn,... |
412 |
|
int selectedThresholdOption) |
413 |
|
{ |
414 |
|
|
415 |
0 |
AnnotationColourGradient acg = null; |
416 |
0 |
if (useOriginalColours.isSelected()) |
417 |
|
{ |
418 |
0 |
acg = new AnnotationColourGradient(currentAnn, |
419 |
|
av.getGlobalColourScheme(), selectedThresholdOption); |
420 |
|
} |
421 |
|
else |
422 |
|
{ |
423 |
0 |
acg = new AnnotationColourGradient(currentAnn, |
424 |
|
minColour.getBackground(), maxColour.getBackground(), |
425 |
|
selectedThresholdOption); |
426 |
|
} |
427 |
0 |
acg.setSeqAssociated(seqAssociated.isSelected()); |
428 |
|
|
429 |
0 |
if (currentAnn.graphMin == 0f && currentAnn.graphMax == 0f) |
430 |
|
{ |
431 |
0 |
acg.setPredefinedColours(true); |
432 |
|
} |
433 |
|
|
434 |
0 |
acg.setThresholdIsMinMax(thresholdIsMin.isSelected()); |
435 |
|
|
436 |
0 |
av.setGlobalColourScheme(acg); |
437 |
|
|
438 |
0 |
if (av.getAlignment().getGroups() != null) |
439 |
|
{ |
440 |
|
|
441 |
0 |
for (SequenceGroup sg : ap.av.getAlignment().getGroups()) |
442 |
|
{ |
443 |
0 |
if (sg.cs == null) |
444 |
|
{ |
445 |
0 |
continue; |
446 |
|
} |
447 |
0 |
sg.setColourScheme( |
448 |
|
acg.getInstance(sg, ap.av.getHiddenRepSequences())); |
449 |
|
} |
450 |
|
} |
451 |
|
} |
452 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
453 |
0 |
@Override... |
454 |
|
protected void sliderDragReleased() |
455 |
|
{ |
456 |
0 |
super.sliderDragReleased(); |
457 |
0 |
ap.paintAlignment(true, true); |
458 |
|
} |
459 |
|
|
460 |
|
} |