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.io.JalviewFileChooser; |
25 |
|
import jalview.io.JalviewFileView; |
26 |
|
import jalview.jbgui.GUserDefinedColours; |
27 |
|
import jalview.schemes.ColourSchemeI; |
28 |
|
import jalview.schemes.ColourSchemeLoader; |
29 |
|
import jalview.schemes.ColourSchemes; |
30 |
|
import jalview.schemes.ResidueProperties; |
31 |
|
import jalview.schemes.UserColourScheme; |
32 |
|
import jalview.util.ColorUtils; |
33 |
|
import jalview.util.Format; |
34 |
|
import jalview.util.MessageManager; |
35 |
|
import jalview.util.Platform; |
36 |
|
import jalview.xml.binding.jalview.JalviewUserColours; |
37 |
|
import jalview.xml.binding.jalview.JalviewUserColours.Colour; |
38 |
|
import jalview.xml.binding.jalview.ObjectFactory; |
39 |
|
|
40 |
|
import java.awt.Color; |
41 |
|
import java.awt.Font; |
42 |
|
import java.awt.Insets; |
43 |
|
import java.awt.event.MouseAdapter; |
44 |
|
import java.awt.event.MouseEvent; |
45 |
|
import java.io.File; |
46 |
|
import java.io.FileOutputStream; |
47 |
|
import java.io.OutputStreamWriter; |
48 |
|
import java.io.PrintWriter; |
49 |
|
import java.util.ArrayList; |
50 |
|
import java.util.List; |
51 |
|
|
52 |
|
import javax.swing.JButton; |
53 |
|
import javax.swing.JInternalFrame; |
54 |
|
import javax.swing.event.ChangeEvent; |
55 |
|
import javax.swing.event.ChangeListener; |
56 |
|
import javax.xml.bind.JAXBContext; |
57 |
|
import javax.xml.bind.Marshaller; |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
@author |
64 |
|
@author |
65 |
|
|
|
|
| 0% |
Uncovered Elements: 398 (398) |
Complexity: 86 |
Complexity Density: 0.32 |
|
66 |
|
public class UserDefinedColours extends GUserDefinedColours |
67 |
|
implements ChangeListener |
68 |
|
{ |
69 |
|
private static final Font VERDANA_BOLD_10 = new Font("Verdana", Font.BOLD, |
70 |
|
10); |
71 |
|
|
72 |
|
public static final String USER_DEFINED_COLOURS = "USER_DEFINED_COLOURS"; |
73 |
|
|
74 |
|
private static final String LAST_DIRECTORY = "LAST_DIRECTORY"; |
75 |
|
|
76 |
|
private static final int MY_FRAME_HEIGHT = 440; |
77 |
|
|
78 |
|
private static final int MY_FRAME_WIDTH = 810; |
79 |
|
|
80 |
|
private static final int MY_FRAME_WIDTH_CASE_SENSITIVE = 970; |
81 |
|
|
82 |
|
AlignmentPanel ap; |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
ColourSchemeI oldColourScheme; |
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
boolean changedButNotSaved; |
95 |
|
|
96 |
|
JInternalFrame frame; |
97 |
|
|
98 |
|
List<JButton> upperCaseButtons; |
99 |
|
|
100 |
|
List<JButton> lowerCaseButtons; |
101 |
|
|
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
@param |
106 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 3 |
Complexity Density: 0.23 |
|
107 |
0 |
public UserDefinedColours(AlignmentPanel alignPanel)... |
108 |
|
{ |
109 |
0 |
this(); |
110 |
|
|
111 |
0 |
lcaseColour.setEnabled(false); |
112 |
|
|
113 |
0 |
this.ap = alignPanel; |
114 |
|
|
115 |
0 |
oldColourScheme = alignPanel.av.getGlobalColourScheme(); |
116 |
|
|
117 |
0 |
if (oldColourScheme instanceof UserColourScheme) |
118 |
|
{ |
119 |
0 |
schemeName.setText(oldColourScheme.getSchemeName()); |
120 |
0 |
if (((UserColourScheme) oldColourScheme) |
121 |
|
.getLowerCaseColours() != null) |
122 |
|
{ |
123 |
0 |
caseSensitive.setSelected(true); |
124 |
0 |
lcaseColour.setEnabled(true); |
125 |
0 |
resetButtonPanel(true); |
126 |
|
} |
127 |
|
else |
128 |
|
{ |
129 |
0 |
resetButtonPanel(false); |
130 |
|
} |
131 |
|
} |
132 |
|
else |
133 |
|
{ |
134 |
0 |
resetButtonPanel(false); |
135 |
|
} |
136 |
|
|
137 |
0 |
showFrame(); |
138 |
|
} |
139 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
140 |
0 |
UserDefinedColours()... |
141 |
|
{ |
142 |
0 |
super(); |
143 |
0 |
selectedButtons = new ArrayList<>(); |
144 |
|
} |
145 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
146 |
0 |
void showFrame()... |
147 |
|
{ |
148 |
0 |
colorChooser.getSelectionModel().addChangeListener(this); |
149 |
0 |
frame = new JInternalFrame(); |
150 |
0 |
frame.setContentPane(this); |
151 |
0 |
Desktop.addInternalFrame(frame, |
152 |
|
MessageManager.getString("label.user_defined_colours"), |
153 |
|
MY_FRAME_WIDTH, MY_FRAME_HEIGHT, true); |
154 |
|
} |
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
@param |
163 |
|
|
|
|
| 0% |
Uncovered Elements: 51 (51) |
Complexity: 10 |
Complexity Density: 0.3 |
|
164 |
0 |
void resetButtonPanel(boolean isCaseSensitive)... |
165 |
|
{ |
166 |
0 |
buttonPanel.removeAll(); |
167 |
|
|
168 |
0 |
if (upperCaseButtons == null) |
169 |
|
{ |
170 |
0 |
upperCaseButtons = new ArrayList<>(); |
171 |
|
} |
172 |
|
|
173 |
0 |
for (int i = 0; i < 20; i++) |
174 |
|
{ |
175 |
0 |
String label = isCaseSensitive ? ResidueProperties.aa[i] |
176 |
|
: ResidueProperties.aa2Triplet.get(ResidueProperties.aa[i]) |
177 |
|
.toString(); |
178 |
0 |
JButton button = makeButton(label, ResidueProperties.aa[i], |
179 |
|
upperCaseButtons, i); |
180 |
0 |
buttonPanel.add(button); |
181 |
|
} |
182 |
|
|
183 |
0 |
buttonPanel.add(makeButton("B", "B", upperCaseButtons, 20)); |
184 |
0 |
buttonPanel.add(makeButton("Z", "Z", upperCaseButtons, 21)); |
185 |
0 |
buttonPanel.add(makeButton("X", "X", upperCaseButtons, 22)); |
186 |
0 |
buttonPanel.add(makeButton("Gap", "-", upperCaseButtons, 23)); |
187 |
|
|
188 |
0 |
if (!isCaseSensitive) |
189 |
|
{ |
190 |
0 |
gridLayout.setRows(6); |
191 |
0 |
gridLayout.setColumns(4); |
192 |
|
} |
193 |
|
else |
194 |
|
{ |
195 |
0 |
gridLayout.setRows(7); |
196 |
0 |
int cols = 7; |
197 |
0 |
gridLayout.setColumns(cols + 1); |
198 |
|
|
199 |
0 |
if (lowerCaseButtons == null) |
200 |
|
{ |
201 |
0 |
lowerCaseButtons = new ArrayList<>(); |
202 |
|
} |
203 |
|
|
204 |
0 |
for (int i = 0; i < 20; i++) |
205 |
|
{ |
206 |
0 |
int row = i / cols + 1; |
207 |
0 |
int index = (row * cols) + i; |
208 |
0 |
JButton button = makeButton(ResidueProperties.aa[i].toLowerCase(), |
209 |
|
ResidueProperties.aa[i].toLowerCase(), lowerCaseButtons, i); |
210 |
|
|
211 |
0 |
buttonPanel.add(button, index); |
212 |
|
} |
213 |
|
} |
214 |
|
|
215 |
0 |
if (isCaseSensitive) |
216 |
|
{ |
217 |
0 |
buttonPanel.add(makeButton("b", "b", lowerCaseButtons, 20)); |
218 |
0 |
buttonPanel.add(makeButton("z", "z", lowerCaseButtons, 21)); |
219 |
0 |
buttonPanel.add(makeButton("x", "x", lowerCaseButtons, 22)); |
220 |
|
} |
221 |
|
|
222 |
|
|
223 |
|
|
224 |
0 |
if (this.frame != null) |
225 |
|
{ |
226 |
0 |
int newWidth = isCaseSensitive ? MY_FRAME_WIDTH_CASE_SENSITIVE |
227 |
|
: MY_FRAME_WIDTH; |
228 |
0 |
this.frame.setSize(newWidth, this.frame.getHeight()); |
229 |
|
} |
230 |
|
|
231 |
0 |
buttonPanel.validate(); |
232 |
0 |
validate(); |
233 |
|
} |
234 |
|
|
235 |
|
|
236 |
|
|
237 |
|
|
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
@param |
244 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 4 |
Complexity Density: 0.31 |
|
245 |
0 |
@Override... |
246 |
|
public void stateChanged(ChangeEvent evt) |
247 |
|
{ |
248 |
0 |
JButton button = null; |
249 |
0 |
final Color newColour = colorChooser.getColor(); |
250 |
0 |
if (lcaseColour.isSelected()) |
251 |
|
{ |
252 |
0 |
selectedButtons.clear(); |
253 |
0 |
for (int i = 0; i < lowerCaseButtons.size(); i++) |
254 |
|
{ |
255 |
0 |
button = lowerCaseButtons.get(i); |
256 |
0 |
button.setBackground(newColour); |
257 |
0 |
button.setForeground( |
258 |
|
ColorUtils.brighterThan(button.getBackground())); |
259 |
|
} |
260 |
|
} |
261 |
0 |
for (int i = 0; i < selectedButtons.size(); i++) |
262 |
|
{ |
263 |
0 |
button = selectedButtons.get(i); |
264 |
0 |
button.setBackground(newColour); |
265 |
0 |
button.setForeground(ColorUtils.brighterThan(newColour)); |
266 |
|
} |
267 |
|
|
268 |
0 |
changedButNotSaved = true; |
269 |
|
} |
270 |
|
|
271 |
|
|
272 |
|
|
273 |
|
|
274 |
|
|
275 |
|
|
276 |
|
|
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
|
286 |
|
|
287 |
|
@param |
288 |
|
|
|
|
| 0% |
Uncovered Elements: 62 (62) |
Complexity: 14 |
Complexity Density: 0.39 |
|
289 |
0 |
public void colourButtonPressed(MouseEvent e)... |
290 |
|
{ |
291 |
0 |
JButton pressed = (JButton) e.getSource(); |
292 |
|
|
293 |
0 |
if (e.isShiftDown()) |
294 |
|
{ |
295 |
0 |
JButton start, end = (JButton) e.getSource(); |
296 |
0 |
if (selectedButtons.size() > 0) |
297 |
|
{ |
298 |
0 |
start = selectedButtons.get(selectedButtons.size() - 1); |
299 |
|
} |
300 |
|
else |
301 |
|
{ |
302 |
0 |
start = (JButton) e.getSource(); |
303 |
|
} |
304 |
|
|
305 |
0 |
int startIndex = 0, endIndex = 0; |
306 |
0 |
for (int b = 0; b < buttonPanel.getComponentCount(); b++) |
307 |
|
{ |
308 |
0 |
if (buttonPanel.getComponent(b) == start) |
309 |
|
{ |
310 |
0 |
startIndex = b; |
311 |
|
} |
312 |
0 |
if (buttonPanel.getComponent(b) == end) |
313 |
|
{ |
314 |
0 |
endIndex = b; |
315 |
|
} |
316 |
|
} |
317 |
|
|
318 |
0 |
if (startIndex > endIndex) |
319 |
|
{ |
320 |
0 |
int temp = startIndex; |
321 |
0 |
startIndex = endIndex; |
322 |
0 |
endIndex = temp; |
323 |
|
} |
324 |
|
|
325 |
0 |
for (int b = startIndex; b <= endIndex; b++) |
326 |
|
{ |
327 |
0 |
JButton button = (JButton) buttonPanel.getComponent(b); |
328 |
0 |
if (!selectedButtons.contains(button)) |
329 |
|
{ |
330 |
0 |
button.setForeground( |
331 |
|
ColorUtils.brighterThan(button.getBackground())); |
332 |
0 |
selectedButtons.add(button); |
333 |
|
} |
334 |
|
} |
335 |
|
} |
336 |
0 |
else if (!e.isControlDown()) |
337 |
|
{ |
338 |
0 |
for (int b = 0; b < selectedButtons.size(); b++) |
339 |
|
{ |
340 |
0 |
JButton button = selectedButtons.get(b); |
341 |
0 |
button.setForeground(ColorUtils.darkerThan(button.getBackground())); |
342 |
|
} |
343 |
0 |
selectedButtons.clear(); |
344 |
0 |
pressed.setForeground( |
345 |
|
ColorUtils.brighterThan(pressed.getBackground())); |
346 |
0 |
selectedButtons.add(pressed); |
347 |
|
|
348 |
|
} |
349 |
0 |
else if (e.isControlDown()) |
350 |
|
{ |
351 |
0 |
if (selectedButtons.contains(pressed)) |
352 |
|
{ |
353 |
0 |
pressed.setForeground( |
354 |
|
ColorUtils.darkerThan(pressed.getBackground())); |
355 |
0 |
selectedButtons.remove(pressed); |
356 |
|
} |
357 |
|
else |
358 |
|
{ |
359 |
0 |
pressed.setForeground( |
360 |
|
ColorUtils.brighterThan(pressed.getBackground())); |
361 |
0 |
selectedButtons.add(pressed); |
362 |
|
} |
363 |
|
} |
364 |
|
|
365 |
0 |
if (selectedButtons.size() > 0) |
366 |
|
{ |
367 |
0 |
colorChooser.setColor((selectedButtons.get(0)).getBackground()); |
368 |
|
} |
369 |
|
} |
370 |
|
|
371 |
|
|
372 |
|
|
373 |
|
|
374 |
|
|
375 |
|
|
376 |
|
|
377 |
|
|
378 |
|
|
379 |
|
@param |
380 |
|
@param |
381 |
|
@param |
382 |
|
|
383 |
|
@param |
384 |
|
|
385 |
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 5 |
Complexity Density: 0.25 |
|
386 |
0 |
JButton makeButton(String label, String residue, List<JButton> buttons,... |
387 |
|
int buttonIndex) |
388 |
|
{ |
389 |
0 |
final JButton button; |
390 |
0 |
Color col; |
391 |
|
|
392 |
0 |
if (buttonIndex < buttons.size()) |
393 |
|
{ |
394 |
0 |
button = buttons.get(buttonIndex); |
395 |
0 |
col = button.getBackground(); |
396 |
|
} |
397 |
|
else |
398 |
|
{ |
399 |
0 |
button = new JButton(); |
400 |
0 |
button.addMouseListener(new MouseAdapter() |
401 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
402 |
0 |
@Override... |
403 |
|
public void mouseClicked(MouseEvent e) |
404 |
|
{ |
405 |
0 |
colourButtonPressed(e); |
406 |
|
} |
407 |
|
}); |
408 |
|
|
409 |
0 |
buttons.add(button); |
410 |
|
|
411 |
|
|
412 |
|
|
413 |
|
|
414 |
|
|
415 |
0 |
col = Color.white; |
416 |
0 |
if (oldColourScheme != null && oldColourScheme.isSimple()) |
417 |
|
{ |
418 |
0 |
col = oldColourScheme.findColour(residue.charAt(0), 0, null, null, |
419 |
|
0f); |
420 |
|
} |
421 |
|
} |
422 |
|
|
423 |
0 |
if (caseSensitive.isSelected()) |
424 |
|
{ |
425 |
0 |
button.setMargin(new Insets(2, 2, 2, 2)); |
426 |
|
} |
427 |
|
else |
428 |
|
{ |
429 |
0 |
button.setMargin(new Insets(2, 14, 2, 14)); |
430 |
|
} |
431 |
|
|
432 |
0 |
button.setOpaque(true); |
433 |
0 |
button.setBackground(col); |
434 |
0 |
button.setText(label); |
435 |
0 |
button.setForeground(ColorUtils.darkerThan(col)); |
436 |
0 |
button.setFont(VERDANA_BOLD_10); |
437 |
|
|
438 |
0 |
return button; |
439 |
|
} |
440 |
|
|
441 |
|
|
442 |
|
|
443 |
|
|
444 |
|
|
445 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.5 |
|
446 |
0 |
@Override... |
447 |
|
protected void okButton_actionPerformed() |
448 |
|
{ |
449 |
0 |
if (isNoSelectionMade()) |
450 |
|
{ |
451 |
0 |
JvOptionPane.showMessageDialog(Desktop.desktop, |
452 |
|
MessageManager |
453 |
|
.getString("label.no_colour_selection_in_scheme"), |
454 |
|
MessageManager.getString("label.no_colour_selection_warn"), |
455 |
|
JvOptionPane.WARNING_MESSAGE); |
456 |
|
} |
457 |
|
else |
458 |
|
{ |
459 |
|
|
460 |
|
|
461 |
|
|
462 |
0 |
applyButton_actionPerformed(); |
463 |
|
|
464 |
|
|
465 |
|
|
466 |
|
|
467 |
|
|
468 |
0 |
warnIfUnsavedChanges(); |
469 |
|
|
470 |
0 |
try |
471 |
|
{ |
472 |
0 |
frame.setClosed(true); |
473 |
|
} catch (Exception ex) |
474 |
|
{ |
475 |
|
} |
476 |
|
} |
477 |
|
} |
478 |
|
|
479 |
|
|
480 |
|
|
481 |
|
|
482 |
|
|
483 |
|
|
484 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 8 |
Complexity Density: 0.62 |
|
485 |
0 |
protected void warnIfUnsavedChanges()... |
486 |
|
{ |
487 |
|
|
488 |
|
|
489 |
0 |
if (!Platform.isJS() && changedButNotSaved) |
490 |
|
|
491 |
|
|
492 |
|
|
493 |
|
|
494 |
|
|
495 |
|
{ |
496 |
0 |
String name = schemeName.getText().trim(); |
497 |
0 |
if (oldColourScheme != null && !"".equals(name) |
498 |
|
&& name.equals(oldColourScheme.getSchemeName())) |
499 |
|
{ |
500 |
0 |
String message = MessageManager |
501 |
|
.formatMessage("label.scheme_changed", name); |
502 |
0 |
String title = MessageManager.getString("label.save_changes"); |
503 |
0 |
String[] options = new String[] { title, |
504 |
|
MessageManager.getString("label.dont_save_changes"), }; |
505 |
0 |
final String question = JvSwingUtils.wrapTooltip(true, message); |
506 |
0 |
int response = JvOptionPane.showOptionDialog(Desktop.desktop, |
507 |
|
question, title, JvOptionPane.DEFAULT_OPTION, |
508 |
|
JvOptionPane.PLAIN_MESSAGE, null, options, options[0]); |
509 |
|
|
510 |
0 |
if (response == 0) |
511 |
|
{ |
512 |
|
|
513 |
|
|
514 |
|
|
515 |
|
|
516 |
0 |
savebutton_actionPerformed(); |
517 |
|
} |
518 |
|
|
519 |
|
|
520 |
|
|
521 |
|
|
522 |
|
|
523 |
0 |
if (changedButNotSaved) |
524 |
|
{ |
525 |
|
|
526 |
|
|
527 |
|
|
528 |
0 |
schemeName.setText(""); |
529 |
0 |
applyButton_actionPerformed(); |
530 |
|
} |
531 |
|
} |
532 |
|
} |
533 |
|
} |
534 |
|
|
535 |
|
|
536 |
|
|
537 |
|
|
538 |
|
|
539 |
|
@return |
540 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
541 |
0 |
protected boolean isNoSelectionMade()... |
542 |
|
{ |
543 |
0 |
final boolean noUpperCaseSelected = upperCaseButtons == null |
544 |
|
|| upperCaseButtons.isEmpty(); |
545 |
0 |
final boolean noLowerCaseSelected = caseSensitive.isSelected() |
546 |
|
&& (lowerCaseButtons == null || lowerCaseButtons.isEmpty()); |
547 |
0 |
final boolean noSelectionMade = noUpperCaseSelected |
548 |
|
|| noLowerCaseSelected; |
549 |
0 |
return noSelectionMade; |
550 |
|
} |
551 |
|
|
552 |
|
|
553 |
|
|
554 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
555 |
0 |
@Override... |
556 |
|
protected void applyButton_actionPerformed() |
557 |
|
{ |
558 |
0 |
if (isNoSelectionMade()) |
559 |
|
{ |
560 |
0 |
JvOptionPane.showMessageDialog(Desktop.desktop, |
561 |
|
MessageManager |
562 |
|
.getString("label.no_colour_selection_in_scheme"), |
563 |
|
MessageManager.getString("label.no_colour_selection_warn"), |
564 |
|
JvOptionPane.WARNING_MESSAGE); |
565 |
|
|
566 |
|
} |
567 |
0 |
UserColourScheme ucs = getSchemeFromButtons(); |
568 |
|
|
569 |
0 |
ap.alignFrame.changeColour(ucs); |
570 |
|
} |
571 |
|
|
572 |
|
|
573 |
|
|
574 |
|
|
575 |
|
|
576 |
|
@return |
577 |
|
|
|
|
| 0% |
Uncovered Elements: 35 (35) |
Complexity: 6 |
Complexity Density: 0.24 |
|
578 |
0 |
UserColourScheme getSchemeFromButtons()... |
579 |
|
{ |
580 |
|
|
581 |
0 |
Color[] newColours = new Color[24]; |
582 |
|
|
583 |
0 |
int length = upperCaseButtons.size(); |
584 |
0 |
if (length < 24) |
585 |
|
{ |
586 |
0 |
int i = 0; |
587 |
0 |
for (JButton btn : upperCaseButtons) |
588 |
|
{ |
589 |
0 |
newColours[i] = btn.getBackground(); |
590 |
0 |
i++; |
591 |
|
} |
592 |
|
} |
593 |
|
else |
594 |
|
{ |
595 |
0 |
for (int i = 0; i < 24; i++) |
596 |
|
{ |
597 |
0 |
JButton button = upperCaseButtons.get(i); |
598 |
0 |
newColours[i] = button.getBackground(); |
599 |
|
} |
600 |
|
} |
601 |
|
|
602 |
0 |
UserColourScheme ucs = new UserColourScheme(newColours); |
603 |
0 |
ucs.setName(schemeName.getText()); |
604 |
|
|
605 |
0 |
if (caseSensitive.isSelected()) |
606 |
|
{ |
607 |
0 |
newColours = new Color[23]; |
608 |
0 |
length = lowerCaseButtons.size(); |
609 |
0 |
if (length < 23) |
610 |
|
{ |
611 |
0 |
int i = 0; |
612 |
0 |
for (JButton btn : lowerCaseButtons) |
613 |
|
{ |
614 |
0 |
newColours[i] = btn.getBackground(); |
615 |
0 |
i++; |
616 |
|
} |
617 |
|
} |
618 |
|
else |
619 |
|
{ |
620 |
0 |
for (int i = 0; i < 23; i++) |
621 |
|
{ |
622 |
0 |
JButton button = lowerCaseButtons.get(i); |
623 |
0 |
newColours[i] = button.getBackground(); |
624 |
|
} |
625 |
|
} |
626 |
0 |
ucs.setLowerCaseColours(newColours); |
627 |
|
} |
628 |
|
|
629 |
0 |
return ucs; |
630 |
|
} |
631 |
|
|
632 |
|
|
633 |
|
|
634 |
|
|
635 |
|
|
636 |
|
|
637 |
|
|
638 |
|
|
639 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
|
640 |
0 |
@Override... |
641 |
|
protected void loadbutton_actionPerformed() |
642 |
|
{ |
643 |
0 |
upperCaseButtons = new ArrayList<>(); |
644 |
0 |
lowerCaseButtons = new ArrayList<>(); |
645 |
0 |
JalviewFileChooser chooser = new JalviewFileChooser("jc", |
646 |
|
"Jalview User Colours"); |
647 |
0 |
chooser.setFileView(new JalviewFileView()); |
648 |
0 |
chooser.setDialogTitle( |
649 |
|
MessageManager.getString("label.load_colour_scheme")); |
650 |
0 |
chooser.setToolTipText(MessageManager.getString("action.load")); |
651 |
0 |
chooser.setResponseHandler(0, new Runnable() |
652 |
|
{ |
|
|
| 0% |
Uncovered Elements: 25 (25) |
Complexity: 4 |
Complexity Density: 0.21 |
|
653 |
0 |
@Override... |
654 |
|
public void run() |
655 |
|
{ |
656 |
0 |
File choice = chooser.getSelectedFile(); |
657 |
0 |
Cache.setProperty(LAST_DIRECTORY, choice.getParent()); |
658 |
|
|
659 |
0 |
UserColourScheme ucs = ColourSchemeLoader |
660 |
|
.loadColourScheme(choice.getAbsolutePath()); |
661 |
0 |
Color[] colors = ucs.getColours(); |
662 |
0 |
schemeName.setText(ucs.getSchemeName()); |
663 |
|
|
664 |
0 |
if (ucs.getLowerCaseColours() != null) |
665 |
|
{ |
666 |
0 |
caseSensitive.setSelected(true); |
667 |
0 |
lcaseColour.setEnabled(true); |
668 |
0 |
resetButtonPanel(true); |
669 |
0 |
for (int i = 0; i < lowerCaseButtons.size(); i++) |
670 |
|
{ |
671 |
0 |
JButton button = lowerCaseButtons.get(i); |
672 |
0 |
button.setBackground(ucs.getLowerCaseColours()[i]); |
673 |
|
} |
674 |
|
} |
675 |
|
else |
676 |
|
{ |
677 |
0 |
caseSensitive.setSelected(false); |
678 |
0 |
lcaseColour.setEnabled(false); |
679 |
0 |
resetButtonPanel(false); |
680 |
|
} |
681 |
|
|
682 |
0 |
for (int i = 0; i < upperCaseButtons.size(); i++) |
683 |
|
{ |
684 |
0 |
JButton button = upperCaseButtons.get(i); |
685 |
0 |
button.setBackground(colors[i]); |
686 |
|
} |
687 |
|
|
688 |
0 |
addNewColourScheme(choice.getPath()); |
689 |
|
} |
690 |
|
}); |
691 |
|
|
692 |
0 |
chooser.showOpenDialog(this); |
693 |
|
} |
694 |
|
|
695 |
|
|
696 |
|
|
697 |
|
|
698 |
|
|
699 |
|
@return |
700 |
|
|
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.44 |
|
701 |
0 |
public static UserColourScheme loadDefaultColours()... |
702 |
|
{ |
703 |
0 |
UserColourScheme ret = null; |
704 |
|
|
705 |
0 |
String colours = Cache.getProperty(USER_DEFINED_COLOURS); |
706 |
0 |
if (colours != null) |
707 |
|
{ |
708 |
0 |
if (colours.indexOf("|") > -1) |
709 |
|
{ |
710 |
0 |
colours = colours.substring(0, colours.indexOf("|")); |
711 |
|
} |
712 |
0 |
ret = ColourSchemeLoader.loadColourScheme(colours); |
713 |
|
} |
714 |
|
|
715 |
0 |
if (ret == null) |
716 |
|
{ |
717 |
0 |
ret = new UserColourScheme("white"); |
718 |
|
} |
719 |
|
|
720 |
0 |
return ret; |
721 |
|
} |
722 |
|
|
723 |
|
|
724 |
|
|
725 |
|
|
726 |
|
|
727 |
|
|
728 |
|
|
729 |
|
|
730 |
|
|
731 |
|
|
732 |
|
|
733 |
|
|
734 |
|
|
735 |
|
|
736 |
|
|
737 |
|
|
|
|
| 0% |
Uncovered Elements: 31 (31) |
Complexity: 8 |
Complexity Density: 0.38 |
|
738 |
0 |
@Override... |
739 |
|
protected void savebutton_actionPerformed() |
740 |
|
{ |
741 |
0 |
String name = schemeName.getText().trim(); |
742 |
0 |
if (name.length() < 1) |
743 |
|
{ |
744 |
0 |
JvOptionPane.showInternalMessageDialog(Desktop.desktop, |
745 |
|
MessageManager |
746 |
|
.getString("label.user_colour_scheme_must_have_name"), |
747 |
|
MessageManager.getString("label.no_name_colour_scheme"), |
748 |
|
JvOptionPane.WARNING_MESSAGE); |
749 |
|
} |
750 |
|
|
751 |
0 |
if (!Platform.isJS() && ColourSchemes.getInstance().nameExists(name)) |
752 |
|
{ |
753 |
|
|
754 |
|
|
755 |
|
|
756 |
|
|
757 |
|
|
758 |
|
{ |
759 |
0 |
int reply = JvOptionPane.showInternalConfirmDialog(Desktop.desktop, |
760 |
|
MessageManager.formatMessage( |
761 |
|
"label.colour_scheme_exists_overwrite", new Object[] |
762 |
|
{ name, name }), |
763 |
|
MessageManager.getString("label.duplicate_scheme_name"), |
764 |
|
JvOptionPane.YES_NO_OPTION); |
765 |
0 |
if (reply != JvOptionPane.YES_OPTION) |
766 |
|
{ |
767 |
0 |
return; |
768 |
|
} |
769 |
|
} |
770 |
|
} |
771 |
|
|
772 |
0 |
JalviewFileChooser chooser = new JalviewFileChooser("jc", |
773 |
|
"Jalview User Colours"); |
774 |
|
|
775 |
0 |
JalviewFileView fileView = new JalviewFileView(); |
776 |
0 |
chooser.setFileView(fileView); |
777 |
0 |
chooser.setDialogTitle( |
778 |
|
MessageManager.getString("label.save_colour_scheme")); |
779 |
0 |
chooser.setToolTipText(MessageManager.getString("action.save")); |
780 |
0 |
int option = chooser.showSaveDialog(this); |
781 |
0 |
if (option == JalviewFileChooser.APPROVE_OPTION) |
782 |
|
{ |
783 |
0 |
File file = chooser.getSelectedFile(); |
784 |
0 |
UserColourScheme updatedScheme = addNewColourScheme(file.getPath()); |
785 |
0 |
saveToFile(file); |
786 |
0 |
changedButNotSaved = false; |
787 |
|
|
788 |
|
|
789 |
|
|
790 |
|
|
791 |
|
|
792 |
|
|
793 |
0 |
if (oldColourScheme != null |
794 |
|
&& name.equals(oldColourScheme.getSchemeName())) |
795 |
|
{ |
796 |
0 |
oldColourScheme = updatedScheme; |
797 |
0 |
applyButton_actionPerformed(); |
798 |
|
} |
799 |
|
} |
800 |
|
} |
801 |
|
|
802 |
|
|
803 |
|
|
804 |
|
|
805 |
|
|
806 |
|
|
807 |
|
|
808 |
|
@param |
809 |
|
@return |
810 |
|
|
|
|
| 0% |
Uncovered Elements: 17 (17) |
Complexity: 4 |
Complexity Density: 0.36 |
|
811 |
0 |
protected UserColourScheme addNewColourScheme(String filePath)... |
812 |
|
{ |
813 |
|
|
814 |
|
|
815 |
|
|
816 |
|
|
817 |
0 |
String defaultColours = Cache.getDefault(USER_DEFINED_COLOURS, |
818 |
|
filePath); |
819 |
0 |
if (defaultColours.indexOf(filePath) == -1) |
820 |
|
{ |
821 |
0 |
if (defaultColours.length() > 0) |
822 |
|
{ |
823 |
0 |
defaultColours = defaultColours.concat("|"); |
824 |
|
} |
825 |
0 |
defaultColours = defaultColours.concat(filePath); |
826 |
|
} |
827 |
0 |
Cache.setProperty(USER_DEFINED_COLOURS, defaultColours); |
828 |
|
|
829 |
|
|
830 |
|
|
831 |
|
|
832 |
0 |
UserColourScheme ucs = getSchemeFromButtons(); |
833 |
0 |
ColourSchemes.getInstance().registerColourScheme(ucs); |
834 |
|
|
835 |
|
|
836 |
|
|
837 |
|
|
838 |
0 |
if (ap != null) |
839 |
|
{ |
840 |
0 |
ap.alignFrame.buildColourMenu(); |
841 |
|
} |
842 |
|
|
843 |
0 |
return ucs; |
844 |
|
} |
845 |
|
|
846 |
|
|
847 |
|
|
848 |
|
|
849 |
|
@param |
850 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 3 |
Complexity Density: 0.19 |
|
851 |
0 |
protected void saveToFile(File toFile)... |
852 |
|
{ |
853 |
|
|
854 |
|
|
855 |
|
|
856 |
|
|
857 |
0 |
JalviewUserColours ucs = new JalviewUserColours(); |
858 |
0 |
String name = schemeName.getText(); |
859 |
0 |
ucs.setSchemeName(name); |
860 |
0 |
try |
861 |
|
{ |
862 |
0 |
PrintWriter out = new PrintWriter(new OutputStreamWriter( |
863 |
|
new FileOutputStream(toFile), "UTF-8")); |
864 |
|
|
865 |
0 |
for (int i = 0; i < buttonPanel.getComponentCount(); i++) |
866 |
|
{ |
867 |
0 |
JButton button = (JButton) buttonPanel.getComponent(i); |
868 |
0 |
Colour col = new Colour(); |
869 |
0 |
col.setName(button.getText()); |
870 |
0 |
col.setRGB(Format.getHexString(button.getBackground())); |
871 |
0 |
ucs.getColour().add(col); |
872 |
|
} |
873 |
0 |
JAXBContext jaxbContext = JAXBContext |
874 |
|
.newInstance(JalviewUserColours.class); |
875 |
0 |
Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); |
876 |
0 |
jaxbMarshaller.marshal( |
877 |
|
new ObjectFactory().createJalviewUserColours(ucs), out); |
878 |
|
|
879 |
0 |
out.close(); |
880 |
|
} catch (Exception ex) |
881 |
|
{ |
882 |
0 |
ex.printStackTrace(); |
883 |
|
} |
884 |
|
} |
885 |
|
|
886 |
|
|
887 |
|
|
888 |
|
|
889 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 0.5 |
|
890 |
0 |
@Override... |
891 |
|
protected void cancelButton_actionPerformed() |
892 |
|
{ |
893 |
0 |
ap.alignFrame.changeColour(oldColourScheme); |
894 |
0 |
ap.paintAlignment(true, true); |
895 |
|
|
896 |
0 |
try |
897 |
|
{ |
898 |
0 |
frame.setClosed(true); |
899 |
|
} catch (Exception ex) |
900 |
|
{ |
901 |
|
} |
902 |
|
} |
903 |
|
|
904 |
|
|
905 |
|
|
906 |
|
|
907 |
|
|
908 |
|
|
909 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
910 |
0 |
@Override... |
911 |
|
public void caseSensitive_actionPerformed() |
912 |
|
{ |
913 |
0 |
boolean selected = caseSensitive.isSelected(); |
914 |
0 |
resetButtonPanel(selected); |
915 |
0 |
lcaseColour.setEnabled(selected); |
916 |
|
} |
917 |
|
} |