1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.appletgui; |
22 |
|
|
23 |
|
import jalview.util.MessageManager; |
24 |
|
|
25 |
|
import java.awt.BorderLayout; |
26 |
|
import java.awt.Button; |
27 |
|
import java.awt.Checkbox; |
28 |
|
import java.awt.Choice; |
29 |
|
import java.awt.Color; |
30 |
|
import java.awt.FlowLayout; |
31 |
|
import java.awt.Font; |
32 |
|
import java.awt.FontMetrics; |
33 |
|
import java.awt.Frame; |
34 |
|
import java.awt.GraphicsEnvironment; |
35 |
|
import java.awt.Label; |
36 |
|
import java.awt.Panel; |
37 |
|
import java.awt.event.ActionEvent; |
38 |
|
import java.awt.event.ActionListener; |
39 |
|
import java.awt.event.ItemEvent; |
40 |
|
import java.awt.event.ItemListener; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
@SuppressWarnings("serial") |
|
|
| 0% |
Uncovered Elements: 247 (247) |
Complexity: 42 |
Complexity Density: 0.23 |
|
49 |
|
public class FontChooser extends Panel implements ItemListener |
50 |
|
{ |
51 |
|
private static final Font VERDANA_11PT = new Font("Verdana", 0, 11); |
52 |
|
|
53 |
|
private Choice fontSize = new Choice(); |
54 |
|
|
55 |
|
private Choice fontStyle = new Choice(); |
56 |
|
|
57 |
|
private Choice fontName = new Choice(); |
58 |
|
|
59 |
|
private Checkbox scaleAsCdna = new Checkbox(); |
60 |
|
|
61 |
|
private Checkbox fontAsCdna = new Checkbox(); |
62 |
|
|
63 |
|
private Button ok = new Button(); |
64 |
|
|
65 |
|
private Button cancel = new Button(); |
66 |
|
|
67 |
|
private AlignmentPanel ap; |
68 |
|
|
69 |
|
private TreePanel tp; |
70 |
|
|
71 |
|
private Font oldFont; |
72 |
|
|
73 |
|
private Font oldComplementFont; |
74 |
|
|
75 |
|
private int oldCharWidth = 0; |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
private boolean oldScaleProtein = false; |
81 |
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
boolean oldMirrorFont; |
86 |
|
|
87 |
|
private Font lastSelected = null; |
88 |
|
|
89 |
|
private int lastSelStyle = 0; |
90 |
|
|
91 |
|
private int lastSelSize = 0; |
92 |
|
|
93 |
|
private boolean init = true; |
94 |
|
|
95 |
|
private Frame frame; |
96 |
|
|
97 |
|
boolean inSplitFrame = false; |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
@param |
103 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.33 |
|
104 |
0 |
public FontChooser(TreePanel tp)... |
105 |
|
{ |
106 |
0 |
try |
107 |
|
{ |
108 |
0 |
jbInit(); |
109 |
|
} catch (Exception e) |
110 |
|
{ |
111 |
0 |
e.printStackTrace(); |
112 |
|
} |
113 |
|
|
114 |
0 |
this.tp = tp; |
115 |
0 |
oldFont = tp.getTreeFont(); |
116 |
0 |
init(); |
117 |
|
} |
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
@param |
123 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.22 |
|
124 |
0 |
public FontChooser(AlignmentPanel ap)... |
125 |
|
{ |
126 |
0 |
this.ap = ap; |
127 |
0 |
oldFont = ap.av.getFont(); |
128 |
0 |
oldCharWidth = ap.av.getCharWidth(); |
129 |
0 |
oldScaleProtein = ap.av.isScaleProteinAsCdna(); |
130 |
0 |
oldMirrorFont = ap.av.isProteinFontAsCdna(); |
131 |
|
|
132 |
0 |
try |
133 |
|
{ |
134 |
0 |
jbInit(); |
135 |
|
} catch (Exception e) |
136 |
|
{ |
137 |
0 |
e.printStackTrace(); |
138 |
|
} |
139 |
0 |
init(); |
140 |
|
} |
141 |
|
|
142 |
|
|
143 |
|
|
144 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 3 |
Complexity Density: 0.2 |
|
145 |
0 |
void init()... |
146 |
|
{ |
147 |
|
|
148 |
0 |
String fonts[] = GraphicsEnvironment.getLocalGraphicsEnvironment() |
149 |
|
.getAvailableFontFamilyNames(); |
150 |
0 |
for (int i = 0; i < fonts.length; i++) |
151 |
|
{ |
152 |
0 |
fontName.addItem(fonts[i]); |
153 |
|
} |
154 |
|
|
155 |
0 |
for (int i = 1; i < 31; i++) |
156 |
|
{ |
157 |
0 |
fontSize.addItem(i + ""); |
158 |
|
} |
159 |
|
|
160 |
0 |
fontStyle.addItem("plain"); |
161 |
0 |
fontStyle.addItem("bold"); |
162 |
0 |
fontStyle.addItem("italic"); |
163 |
|
|
164 |
0 |
fontName.select(oldFont.getName()); |
165 |
0 |
fontSize.select(oldFont.getSize() + ""); |
166 |
0 |
fontStyle.select(oldFont.getStyle()); |
167 |
|
|
168 |
0 |
this.frame = new Frame(); |
169 |
0 |
frame.add(this); |
170 |
0 |
jalview.bin.JalviewLite.addFrame(frame, |
171 |
|
MessageManager.getString("action.change_font"), 440, 145); |
172 |
|
|
173 |
0 |
init = false; |
174 |
|
} |
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 6 |
Complexity Density: 0.55 |
|
179 |
0 |
@Override... |
180 |
|
public void itemStateChanged(ItemEvent evt) |
181 |
|
{ |
182 |
0 |
final Object source = evt.getSource(); |
183 |
0 |
if (source == fontName) |
184 |
|
{ |
185 |
0 |
fontName_actionPerformed(); |
186 |
|
} |
187 |
0 |
else if (source == fontSize) |
188 |
|
{ |
189 |
0 |
fontSize_actionPerformed(); |
190 |
|
} |
191 |
0 |
else if (source == fontStyle) |
192 |
|
{ |
193 |
0 |
fontStyle_actionPerformed(); |
194 |
|
} |
195 |
0 |
else if (source == scaleAsCdna) |
196 |
|
{ |
197 |
0 |
scaleAsCdna_actionPerformed(); |
198 |
|
} |
199 |
0 |
else if (source == fontAsCdna) |
200 |
|
{ |
201 |
0 |
mirrorFont_actionPerformed(); |
202 |
|
} |
203 |
|
} |
204 |
|
|
205 |
|
|
206 |
|
|
207 |
|
|
208 |
|
|
209 |
|
|
210 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
211 |
0 |
protected void mirrorFont_actionPerformed()... |
212 |
|
{ |
213 |
0 |
boolean selected = fontAsCdna.getState(); |
214 |
0 |
ap.av.setProteinFontAsCdna(selected); |
215 |
0 |
ap.av.getCodingComplement().setProteinFontAsCdna(selected); |
216 |
|
|
217 |
0 |
if (!selected) |
218 |
|
{ |
219 |
0 |
ap.av.getCodingComplement().setFont(oldComplementFont, true); |
220 |
|
} |
221 |
0 |
changeFont(); |
222 |
|
} |
223 |
|
|
224 |
|
|
225 |
|
|
226 |
|
|
227 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 3 |
Complexity Density: 0.75 |
|
228 |
0 |
protected void ok_actionPerformed()... |
229 |
|
{ |
230 |
0 |
frame.setVisible(false); |
231 |
0 |
if (ap != null) |
232 |
|
{ |
233 |
0 |
if (ap.getOverviewPanel() != null) |
234 |
|
{ |
235 |
0 |
ap.getOverviewPanel().updateOverviewImage(); |
236 |
|
} |
237 |
|
} |
238 |
|
} |
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
|
|
| 0% |
Uncovered Elements: 30 (30) |
Complexity: 5 |
Complexity Density: 0.23 |
|
243 |
0 |
protected void cancel_actionPerformed()... |
244 |
|
{ |
245 |
0 |
if (ap != null) |
246 |
|
{ |
247 |
0 |
ap.av.setScaleProteinAsCdna(oldScaleProtein); |
248 |
0 |
ap.av.setProteinFontAsCdna(oldMirrorFont); |
249 |
|
|
250 |
0 |
if (ap.av.getCodingComplement() != null) |
251 |
|
{ |
252 |
0 |
ap.av.getCodingComplement().setScaleProteinAsCdna(oldScaleProtein); |
253 |
0 |
ap.av.getCodingComplement().setProteinFontAsCdna(oldMirrorFont); |
254 |
0 |
ap.av.getCodingComplement().setFont(oldComplementFont, true); |
255 |
0 |
SplitFrame splitFrame = ap.alignFrame.getSplitFrame(); |
256 |
0 |
splitFrame.adjustLayout(); |
257 |
0 |
splitFrame.getComplement(ap.alignFrame).alignPanel.fontChanged(); |
258 |
0 |
splitFrame.repaint(); |
259 |
|
} |
260 |
|
|
261 |
0 |
ap.av.setFont(oldFont, true); |
262 |
0 |
if (ap.av.getCharWidth() != oldCharWidth) |
263 |
|
{ |
264 |
0 |
ap.av.setCharWidth(oldCharWidth); |
265 |
|
} |
266 |
0 |
ap.paintAlignment(true, false); |
267 |
|
} |
268 |
0 |
else if (tp != null) |
269 |
|
{ |
270 |
0 |
tp.setTreeFont(oldFont); |
271 |
0 |
tp.treeCanvas.repaint(); |
272 |
|
} |
273 |
|
|
274 |
0 |
fontName.select(oldFont.getName()); |
275 |
0 |
fontSize.select(oldFont.getSize() + ""); |
276 |
0 |
fontStyle.select(oldFont.getStyle()); |
277 |
|
|
278 |
0 |
frame.setVisible(false); |
279 |
|
} |
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
|
|
|
| 0% |
Uncovered Elements: 44 (44) |
Complexity: 8 |
Complexity Density: 0.25 |
|
284 |
0 |
void changeFont()... |
285 |
|
{ |
286 |
0 |
if (lastSelected == null) |
287 |
|
{ |
288 |
|
|
289 |
0 |
lastSelected = oldFont; |
290 |
0 |
lastSelSize = oldFont.getSize(); |
291 |
0 |
lastSelStyle = oldFont.getStyle(); |
292 |
|
} |
293 |
|
|
294 |
0 |
Font newFont = new Font(fontName.getSelectedItem().toString(), |
295 |
|
fontStyle.getSelectedIndex(), |
296 |
|
Integer.parseInt(fontSize.getSelectedItem().toString())); |
297 |
0 |
FontMetrics fm = getGraphics().getFontMetrics(newFont); |
298 |
0 |
double mw = fm.getStringBounds("M", getGraphics()).getWidth(), |
299 |
|
iw = fm.getStringBounds("I", getGraphics()).getWidth(); |
300 |
0 |
if (mw < 1 || iw < 1) |
301 |
|
{ |
302 |
|
|
303 |
0 |
fontName.select(lastSelected.getName()); |
304 |
0 |
fontStyle.select(lastSelStyle); |
305 |
0 |
fontSize.select("" + lastSelSize); |
306 |
0 |
JVDialog d = new JVDialog(this.frame, |
307 |
|
MessageManager.getString("label.invalid_font"), true, 350, |
308 |
|
200); |
309 |
0 |
Panel mp = new Panel(); |
310 |
0 |
d.cancel.setVisible(false); |
311 |
0 |
mp.setLayout(new FlowLayout()); |
312 |
0 |
mp.add(new Label( |
313 |
|
"Font doesn't have letters defined\nso cannot be used\nwith alignment data.")); |
314 |
0 |
d.setMainPanel(mp); |
315 |
0 |
d.setVisible(true); |
316 |
0 |
return; |
317 |
|
} |
318 |
0 |
if (tp != null) |
319 |
|
{ |
320 |
0 |
tp.setTreeFont(newFont); |
321 |
|
} |
322 |
0 |
else if (ap != null) |
323 |
|
{ |
324 |
0 |
ap.av.setFont(newFont, true); |
325 |
0 |
ap.fontChanged(); |
326 |
|
|
327 |
|
|
328 |
|
|
329 |
|
|
330 |
0 |
if (inSplitFrame) |
331 |
|
{ |
332 |
0 |
if (fontAsCdna.getState()) |
333 |
|
{ |
334 |
0 |
ap.av.getCodingComplement().setFont(newFont, true); |
335 |
|
} |
336 |
0 |
SplitFrame splitFrame = ap.alignFrame.getSplitFrame(); |
337 |
0 |
splitFrame.adjustLayout(); |
338 |
0 |
splitFrame.getComplement(ap.alignFrame).alignPanel.fontChanged(); |
339 |
0 |
splitFrame.repaint(); |
340 |
|
} |
341 |
|
} |
342 |
|
|
343 |
0 |
lastSelected = newFont; |
344 |
|
} |
345 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
346 |
0 |
protected void fontName_actionPerformed()... |
347 |
|
{ |
348 |
0 |
if (init) |
349 |
|
{ |
350 |
0 |
return; |
351 |
|
} |
352 |
0 |
changeFont(); |
353 |
|
} |
354 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
355 |
0 |
protected void fontSize_actionPerformed()... |
356 |
|
{ |
357 |
0 |
if (init) |
358 |
|
{ |
359 |
0 |
return; |
360 |
|
} |
361 |
0 |
changeFont(); |
362 |
|
} |
363 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
364 |
0 |
protected void fontStyle_actionPerformed()... |
365 |
|
{ |
366 |
0 |
if (init) |
367 |
|
{ |
368 |
0 |
return; |
369 |
|
} |
370 |
0 |
changeFont(); |
371 |
|
} |
372 |
|
|
373 |
|
|
374 |
|
|
375 |
|
|
376 |
|
@throws |
377 |
|
|
|
|
| 0% |
Uncovered Elements: 67 (67) |
Complexity: 2 |
Complexity Density: 0.03 |
|
378 |
0 |
private void jbInit() throws Exception... |
379 |
|
{ |
380 |
0 |
this.setLayout(new BorderLayout()); |
381 |
0 |
this.setBackground(Color.white); |
382 |
|
|
383 |
0 |
Label fontLabel = new Label(MessageManager.getString("label.font")); |
384 |
0 |
fontLabel.setFont(VERDANA_11PT); |
385 |
0 |
fontLabel.setAlignment(Label.RIGHT); |
386 |
0 |
fontSize.setFont(VERDANA_11PT); |
387 |
0 |
fontSize.addItemListener(this); |
388 |
0 |
fontStyle.setFont(VERDANA_11PT); |
389 |
0 |
fontStyle.addItemListener(this); |
390 |
|
|
391 |
0 |
Label sizeLabel = new Label(MessageManager.getString("label.size")); |
392 |
0 |
sizeLabel.setAlignment(Label.RIGHT); |
393 |
0 |
sizeLabel.setFont(VERDANA_11PT); |
394 |
|
|
395 |
0 |
Label styleLabel = new Label(MessageManager.getString("label.style")); |
396 |
0 |
styleLabel.setAlignment(Label.RIGHT); |
397 |
0 |
styleLabel.setFont(VERDANA_11PT); |
398 |
|
|
399 |
0 |
fontName.setFont(VERDANA_11PT); |
400 |
0 |
fontName.addItemListener(this); |
401 |
|
|
402 |
0 |
scaleAsCdna.setLabel(MessageManager.getString("label.scale_as_cdna")); |
403 |
0 |
scaleAsCdna.setFont(VERDANA_11PT); |
404 |
0 |
scaleAsCdna.addItemListener(this); |
405 |
0 |
scaleAsCdna.setState(ap.av.isScaleProteinAsCdna()); |
406 |
|
|
407 |
0 |
fontAsCdna.setLabel(MessageManager.getString("label.font_as_cdna")); |
408 |
0 |
fontAsCdna.setFont(VERDANA_11PT); |
409 |
0 |
fontAsCdna.addItemListener(this); |
410 |
0 |
fontAsCdna.setState(ap.av.isProteinFontAsCdna()); |
411 |
|
|
412 |
0 |
ok.setFont(VERDANA_11PT); |
413 |
0 |
ok.setLabel(MessageManager.getString("action.ok")); |
414 |
0 |
ok.addActionListener(new ActionListener() |
415 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
416 |
0 |
@Override... |
417 |
|
public void actionPerformed(ActionEvent e) |
418 |
|
{ |
419 |
0 |
ok_actionPerformed(); |
420 |
|
} |
421 |
|
}); |
422 |
0 |
cancel.setFont(VERDANA_11PT); |
423 |
0 |
cancel.setLabel(MessageManager.getString("action.cancel")); |
424 |
0 |
cancel.addActionListener(new ActionListener() |
425 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
426 |
0 |
@Override... |
427 |
|
public void actionPerformed(ActionEvent e) |
428 |
|
{ |
429 |
0 |
cancel_actionPerformed(); |
430 |
|
} |
431 |
|
}); |
432 |
|
|
433 |
0 |
Panel fontPanel = new Panel(); |
434 |
0 |
fontPanel.setLayout(new BorderLayout()); |
435 |
0 |
Panel stylePanel = new Panel(); |
436 |
0 |
stylePanel.setLayout(new BorderLayout()); |
437 |
0 |
Panel sizePanel = new Panel(); |
438 |
0 |
sizePanel.setLayout(new BorderLayout()); |
439 |
0 |
Panel scalePanel = new Panel(); |
440 |
0 |
scalePanel.setLayout(new BorderLayout()); |
441 |
0 |
Panel okCancelPanel = new Panel(); |
442 |
0 |
Panel optionsPanel = new Panel(); |
443 |
|
|
444 |
0 |
fontPanel.setBackground(Color.white); |
445 |
0 |
stylePanel.setBackground(Color.white); |
446 |
0 |
sizePanel.setBackground(Color.white); |
447 |
0 |
okCancelPanel.setBackground(Color.white); |
448 |
0 |
optionsPanel.setBackground(Color.white); |
449 |
|
|
450 |
0 |
fontPanel.add(fontLabel, BorderLayout.WEST); |
451 |
0 |
fontPanel.add(fontName, BorderLayout.CENTER); |
452 |
0 |
stylePanel.add(styleLabel, BorderLayout.WEST); |
453 |
0 |
stylePanel.add(fontStyle, BorderLayout.CENTER); |
454 |
0 |
sizePanel.add(sizeLabel, BorderLayout.WEST); |
455 |
0 |
sizePanel.add(fontSize, BorderLayout.CENTER); |
456 |
0 |
scalePanel.add(scaleAsCdna, BorderLayout.NORTH); |
457 |
0 |
scalePanel.add(fontAsCdna, BorderLayout.SOUTH); |
458 |
0 |
okCancelPanel.add(ok, null); |
459 |
0 |
okCancelPanel.add(cancel, null); |
460 |
|
|
461 |
0 |
optionsPanel.add(fontPanel, null); |
462 |
0 |
optionsPanel.add(sizePanel, null); |
463 |
0 |
optionsPanel.add(stylePanel, null); |
464 |
|
|
465 |
|
|
466 |
|
|
467 |
|
|
468 |
0 |
this.add(optionsPanel, BorderLayout.NORTH); |
469 |
0 |
if (ap.alignFrame.getSplitFrame() != null) |
470 |
|
{ |
471 |
0 |
inSplitFrame = true; |
472 |
0 |
oldComplementFont = ((AlignViewport) ap.av.getCodingComplement()) |
473 |
|
.getFont(); |
474 |
0 |
this.add(scalePanel, BorderLayout.CENTER); |
475 |
|
} |
476 |
0 |
this.add(okCancelPanel, BorderLayout.SOUTH); |
477 |
|
} |
478 |
|
|
479 |
|
|
480 |
|
|
481 |
|
|
482 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
483 |
0 |
protected void scaleAsCdna_actionPerformed()... |
484 |
|
{ |
485 |
0 |
ap.av.setScaleProteinAsCdna(scaleAsCdna.getState()); |
486 |
0 |
ap.av.getCodingComplement() |
487 |
|
.setScaleProteinAsCdna(scaleAsCdna.getState()); |
488 |
0 |
changeFont(); |
489 |
|
} |
490 |
|
|
491 |
|
} |