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