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.Font; |
24 |
|
import java.awt.FontMetrics; |
25 |
|
import java.awt.geom.Rectangle2D; |
26 |
|
|
27 |
|
import javax.swing.JInternalFrame; |
28 |
|
import javax.swing.JLayeredPane; |
29 |
|
|
30 |
|
import jalview.bin.Cache; |
31 |
|
import jalview.jbgui.GFontChooser; |
32 |
|
import jalview.util.MessageManager; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
@author |
38 |
|
@version |
39 |
|
|
|
|
| 0% |
Uncovered Elements: 212 (212) |
Complexity: 48 |
Complexity Density: 0.34 |
|
40 |
|
public class FontChooser extends GFontChooser |
41 |
|
{ |
42 |
|
AlignmentPanel ap; |
43 |
|
|
44 |
|
TreePanel tp; |
45 |
|
|
46 |
|
CutAndPasteTransfer cap; |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
Font oldFont; |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
Font oldComplementFont; |
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
boolean oldProteinScale; |
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
boolean oldMirrorFont; |
68 |
|
|
69 |
|
boolean init = true; |
70 |
|
|
71 |
|
JInternalFrame frame; |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
private Font lastSelected = null; |
77 |
|
|
78 |
|
private boolean lastSelMono = false; |
79 |
|
|
80 |
|
private boolean oldSmoothFont; |
81 |
|
|
82 |
|
private boolean oldComplementSmooth; |
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
@param |
88 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
89 |
0 |
public FontChooser(TreePanel treePanel)... |
90 |
|
{ |
91 |
0 |
this.tp = treePanel; |
92 |
0 |
ap = treePanel.getTreeCanvas().getAssociatedPanel(); |
93 |
0 |
oldFont = treePanel.getTreeFont(); |
94 |
0 |
defaultButton.setVisible(false); |
95 |
0 |
smoothFont.setEnabled(false); |
96 |
0 |
init(); |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
@param |
103 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
|
104 |
0 |
public FontChooser(AlignmentPanel alignPanel)... |
105 |
|
{ |
106 |
0 |
oldFont = alignPanel.av.getFont(); |
107 |
0 |
oldProteinScale = alignPanel.av.isScaleProteinAsCdna(); |
108 |
0 |
oldMirrorFont = alignPanel.av.isProteinFontAsCdna(); |
109 |
0 |
oldSmoothFont = alignPanel.av.antiAlias; |
110 |
0 |
this.ap = alignPanel; |
111 |
0 |
init(); |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
@param |
118 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
119 |
0 |
public FontChooser(CutAndPasteTransfer cap)... |
120 |
|
{ |
121 |
0 |
oldFont = new Font("Monospaced", Font.PLAIN, 12); |
122 |
0 |
this.cap = cap; |
123 |
0 |
init(); |
124 |
|
} |
125 |
|
|
|
|
| 0% |
Uncovered Elements: 41 (41) |
Complexity: 6 |
Complexity Density: 0.19 |
|
126 |
0 |
void init()... |
127 |
|
{ |
128 |
0 |
frame = new JInternalFrame(); |
129 |
0 |
frame.setFrameIcon(null); |
130 |
0 |
frame.setContentPane(this); |
131 |
|
|
132 |
0 |
if (!isCapFont()) |
133 |
|
{ |
134 |
0 |
smoothFont.setSelected(ap.av.antiAlias); |
135 |
|
|
136 |
|
|
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
0 |
boolean inSplitFrame = ap.av.getCodingComplement() != null; |
142 |
0 |
if (inSplitFrame) |
143 |
|
{ |
144 |
0 |
oldComplementFont = ((AlignViewport) ap.av.getCodingComplement()) |
145 |
|
.getFont(); |
146 |
0 |
oldComplementSmooth = ((AlignViewport) ap.av |
147 |
|
.getCodingComplement()).antiAlias; |
148 |
0 |
scaleAsCdna.setVisible(true); |
149 |
0 |
scaleAsCdna.setSelected(ap.av.isScaleProteinAsCdna()); |
150 |
0 |
fontAsCdna.setVisible(true); |
151 |
0 |
fontAsCdna.setSelected(ap.av.isProteinFontAsCdna()); |
152 |
|
} |
153 |
|
} |
154 |
|
|
155 |
0 |
if (isTreeFont()) |
156 |
|
{ |
157 |
0 |
Desktop.addInternalFrame(frame, |
158 |
|
MessageManager.getString("action.change_font_tree_panel"), |
159 |
|
400, 200, false); |
160 |
|
} |
161 |
|
else |
162 |
|
{ |
163 |
0 |
Desktop.addInternalFrame(frame, |
164 |
|
MessageManager.getString("action.change_font"), 380, 220, |
165 |
|
false); |
166 |
|
} |
167 |
|
|
168 |
0 |
frame.setLayer(JLayeredPane.PALETTE_LAYER); |
169 |
|
|
170 |
0 |
String[] fonts = java.awt.GraphicsEnvironment |
171 |
|
.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); |
172 |
|
|
173 |
0 |
for (int i = 0; i < fonts.length; i++) |
174 |
|
{ |
175 |
0 |
fontName.addItem(fonts[i]); |
176 |
|
} |
177 |
|
|
178 |
0 |
for (int i = 1; i < 51; i++) |
179 |
|
{ |
180 |
0 |
fontSize.addItem(i); |
181 |
|
} |
182 |
|
|
183 |
0 |
fontStyle.addItem("plain"); |
184 |
0 |
fontStyle.addItem("bold"); |
185 |
0 |
fontStyle.addItem("italic"); |
186 |
|
|
187 |
0 |
fontName.setSelectedItem(oldFont.getName()); |
188 |
0 |
fontSize.setSelectedItem(oldFont.getSize()); |
189 |
0 |
fontStyle.setSelectedIndex(oldFont.getStyle()); |
190 |
|
|
191 |
0 |
FontMetrics fm = getGraphics().getFontMetrics(oldFont); |
192 |
0 |
monospaced.setSelected( |
193 |
|
fm.getStringBounds("M", getGraphics()).getWidth() == fm |
194 |
|
.getStringBounds("|", getGraphics()).getWidth()); |
195 |
|
|
196 |
0 |
init = false; |
197 |
|
} |
198 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 3 |
Complexity Density: 0.38 |
|
199 |
0 |
@Override... |
200 |
|
protected void smoothFont_actionPerformed() |
201 |
|
{ |
202 |
0 |
ap.av.antiAlias = smoothFont.isSelected(); |
203 |
0 |
ap.getAnnotationPanel().image = null; |
204 |
0 |
ap.paintAlignment(true, false); |
205 |
0 |
if (ap.av.getCodingComplement() != null && ap.av.isProteinFontAsCdna()) |
206 |
|
{ |
207 |
0 |
((AlignViewport) ap.av |
208 |
|
.getCodingComplement()).antiAlias = ap.av.antiAlias; |
209 |
0 |
SplitFrame sv = (SplitFrame) ap.alignFrame.getSplitViewContainer(); |
210 |
0 |
sv.adjustLayout(); |
211 |
0 |
sv.repaint(); |
212 |
|
} |
213 |
|
|
214 |
|
} |
215 |
|
|
216 |
|
|
217 |
|
|
218 |
|
|
219 |
|
@param |
220 |
|
|
221 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 4 |
Complexity Density: 0.8 |
|
222 |
0 |
@Override... |
223 |
|
protected void ok_actionPerformed() |
224 |
|
{ |
225 |
0 |
try |
226 |
|
{ |
227 |
0 |
frame.setClosed(true); |
228 |
|
} catch (Exception ex) |
229 |
|
{ |
230 |
|
} |
231 |
|
|
232 |
0 |
if (ap != null) |
233 |
|
{ |
234 |
0 |
if (ap.getOverviewPanel() != null) |
235 |
|
{ |
236 |
0 |
ap.getOverviewPanel().updateOverviewImage(); |
237 |
|
} |
238 |
|
} |
239 |
|
} |
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
@param |
245 |
|
|
246 |
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 6 |
Complexity Density: 0.33 |
|
247 |
0 |
@Override... |
248 |
|
protected void cancel_actionPerformed() |
249 |
|
{ |
250 |
0 |
if (isTreeFont()) |
251 |
|
{ |
252 |
0 |
tp.setTreeFont(oldFont); |
253 |
|
} |
254 |
0 |
else if (ap != null) |
255 |
|
{ |
256 |
0 |
ap.av.setFont(oldFont, true); |
257 |
0 |
ap.av.setScaleProteinAsCdna(oldProteinScale); |
258 |
0 |
ap.av.setProteinFontAsCdna(oldMirrorFont); |
259 |
0 |
ap.av.antiAlias = oldSmoothFont; |
260 |
0 |
ap.fontChanged(); |
261 |
|
|
262 |
0 |
if (scaleAsCdna.isVisible() && scaleAsCdna.isEnabled()) |
263 |
|
{ |
264 |
0 |
ap.av.getCodingComplement().setScaleProteinAsCdna(oldProteinScale); |
265 |
0 |
ap.av.getCodingComplement().setProteinFontAsCdna(oldMirrorFont); |
266 |
0 |
((AlignViewport) ap.av |
267 |
|
.getCodingComplement()).antiAlias = oldComplementSmooth; |
268 |
0 |
ap.av.getCodingComplement().setFont(oldComplementFont, true); |
269 |
0 |
SplitFrame splitFrame = (SplitFrame) ap.alignFrame |
270 |
|
.getSplitViewContainer(); |
271 |
0 |
splitFrame.adjustLayout(); |
272 |
0 |
splitFrame.repaint(); |
273 |
|
} |
274 |
|
} |
275 |
|
|
276 |
0 |
try |
277 |
|
{ |
278 |
0 |
frame.setClosed(true); |
279 |
|
} catch (Exception ex) |
280 |
|
{ |
281 |
|
} |
282 |
|
} |
283 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
284 |
0 |
private boolean isTreeFont()... |
285 |
|
{ |
286 |
0 |
return tp != null; |
287 |
|
} |
288 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
289 |
0 |
private boolean isCapFont()... |
290 |
|
{ |
291 |
0 |
return cap != null; |
292 |
|
} |
293 |
|
|
294 |
|
|
295 |
|
|
296 |
|
|
|
|
| 0% |
Uncovered Elements: 62 (62) |
Complexity: 14 |
Complexity Density: 0.37 |
|
297 |
0 |
void changeFont()... |
298 |
|
{ |
299 |
0 |
if (lastSelected == null) |
300 |
|
{ |
301 |
|
|
302 |
0 |
lastSelected = oldFont; |
303 |
0 |
FontMetrics fm = getGraphics().getFontMetrics(oldFont); |
304 |
0 |
double mw = fm.getStringBounds("M", getGraphics()).getWidth(); |
305 |
0 |
double iw = fm.getStringBounds("I", getGraphics()).getWidth(); |
306 |
0 |
lastSelMono = (mw == iw); |
307 |
|
} |
308 |
|
|
309 |
0 |
Font newFont = new Font(fontName.getSelectedItem().toString(), |
310 |
|
fontStyle.getSelectedIndex(), |
311 |
|
(Integer) fontSize.getSelectedItem()); |
312 |
0 |
FontMetrics fm = getGraphics().getFontMetrics(newFont); |
313 |
0 |
double mw = fm.getStringBounds("M", getGraphics()).getWidth(); |
314 |
0 |
final Rectangle2D iBounds = fm.getStringBounds("I", getGraphics()); |
315 |
0 |
double iw = iBounds.getWidth(); |
316 |
0 |
if (mw < 1 || iw < 1) |
317 |
|
{ |
318 |
0 |
String message = iBounds.getHeight() < 1 |
319 |
|
? MessageManager |
320 |
|
.getString("label.font_doesnt_have_letters_defined") |
321 |
|
: MessageManager.getString("label.font_too_small"); |
322 |
0 |
JvOptionPane.showInternalMessageDialog(this, message, |
323 |
|
MessageManager.getString("label.invalid_font"), |
324 |
|
JvOptionPane.WARNING_MESSAGE); |
325 |
|
|
326 |
|
|
327 |
|
|
328 |
|
|
329 |
0 |
if (lastSelected.getSize() != (Integer) fontSize.getSelectedItem()) |
330 |
|
{ |
331 |
0 |
fontSize.setSelectedItem(lastSelected.getSize()); |
332 |
|
} |
333 |
0 |
if (!lastSelected.getName() |
334 |
|
.equals(fontName.getSelectedItem().toString())) |
335 |
|
{ |
336 |
0 |
fontName.setSelectedItem(lastSelected.getName()); |
337 |
|
} |
338 |
0 |
if (lastSelected.getStyle() != fontStyle.getSelectedIndex()) |
339 |
|
{ |
340 |
0 |
fontStyle.setSelectedIndex(lastSelected.getStyle()); |
341 |
|
} |
342 |
0 |
if (lastSelMono != monospaced.isSelected()) |
343 |
|
{ |
344 |
0 |
monospaced.setSelected(lastSelMono); |
345 |
|
} |
346 |
0 |
return; |
347 |
|
} |
348 |
0 |
if (isTreeFont()) |
349 |
|
{ |
350 |
0 |
tp.setTreeFont(newFont); |
351 |
|
} |
352 |
0 |
else if (ap != null) |
353 |
|
{ |
354 |
0 |
ap.av.setFont(newFont, true); |
355 |
0 |
ap.fontChanged(); |
356 |
|
|
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
|
361 |
|
|
362 |
0 |
if (fontAsCdna.isVisible()) |
363 |
|
{ |
364 |
0 |
if (fontAsCdna.isSelected()) |
365 |
|
{ |
366 |
0 |
ap.av.getCodingComplement().setFont(newFont, true); |
367 |
|
} |
368 |
|
|
369 |
0 |
SplitFrame splitFrame = (SplitFrame) ap.alignFrame |
370 |
|
.getSplitViewContainer(); |
371 |
0 |
splitFrame.adjustLayout(); |
372 |
0 |
splitFrame.repaint(); |
373 |
|
} |
374 |
|
} |
375 |
0 |
else if (isCapFont()) |
376 |
|
{ |
377 |
0 |
cap.setFont(newFont); |
378 |
|
} |
379 |
|
|
380 |
0 |
monospaced.setSelected(mw == iw); |
381 |
|
|
382 |
|
|
383 |
|
|
384 |
|
|
385 |
|
|
386 |
0 |
lastSelected = newFont; |
387 |
|
} |
388 |
|
|
389 |
|
|
390 |
|
|
391 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
392 |
0 |
@Override... |
393 |
|
protected void fontName_actionPerformed() |
394 |
|
{ |
395 |
0 |
if (init) |
396 |
|
{ |
397 |
0 |
return; |
398 |
|
} |
399 |
|
|
400 |
0 |
changeFont(); |
401 |
|
} |
402 |
|
|
403 |
|
|
404 |
|
|
405 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
406 |
0 |
@Override... |
407 |
|
protected void fontSize_actionPerformed() |
408 |
|
{ |
409 |
0 |
if (init) |
410 |
|
{ |
411 |
0 |
return; |
412 |
|
} |
413 |
|
|
414 |
0 |
changeFont(); |
415 |
|
} |
416 |
|
|
417 |
|
|
418 |
|
|
419 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
420 |
0 |
@Override... |
421 |
|
protected void fontStyle_actionPerformed() |
422 |
|
{ |
423 |
0 |
if (init) |
424 |
|
{ |
425 |
0 |
return; |
426 |
|
} |
427 |
|
|
428 |
0 |
changeFont(); |
429 |
|
} |
430 |
|
|
431 |
|
|
432 |
|
|
433 |
|
|
434 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
435 |
0 |
@Override... |
436 |
|
public void defaultButton_actionPerformed() |
437 |
|
{ |
438 |
0 |
Cache.setProperty("FONT_NAME", fontName.getSelectedItem().toString()); |
439 |
0 |
Cache.setProperty("FONT_STYLE", fontStyle.getSelectedIndex() + ""); |
440 |
0 |
Cache.setProperty("FONT_SIZE", fontSize.getSelectedItem().toString()); |
441 |
0 |
Cache.setProperty("ANTI_ALIAS", |
442 |
|
Boolean.toString(smoothFont.isSelected())); |
443 |
0 |
Cache.setProperty(Preferences.SCALE_PROTEIN_TO_CDNA, |
444 |
|
Boolean.toString(scaleAsCdna.isSelected())); |
445 |
|
} |
446 |
|
|
447 |
|
|
448 |
|
|
449 |
|
|
450 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
451 |
0 |
@Override... |
452 |
|
protected void scaleAsCdna_actionPerformed() |
453 |
|
{ |
454 |
0 |
ap.av.setScaleProteinAsCdna(scaleAsCdna.isSelected()); |
455 |
0 |
ap.av.getCodingComplement() |
456 |
|
.setScaleProteinAsCdna(scaleAsCdna.isSelected()); |
457 |
0 |
final SplitFrame splitFrame = (SplitFrame) ap.alignFrame |
458 |
|
.getSplitViewContainer(); |
459 |
0 |
splitFrame.adjustLayout(); |
460 |
0 |
splitFrame.repaint(); |
461 |
|
} |
462 |
|
|
463 |
|
|
464 |
|
|
465 |
|
|
466 |
|
|
467 |
|
|
|
|
| 0% |
Uncovered Elements: 8 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
468 |
0 |
@Override... |
469 |
|
protected void mirrorFonts_actionPerformed() |
470 |
|
{ |
471 |
0 |
boolean selected = fontAsCdna.isSelected(); |
472 |
0 |
ap.av.setProteinFontAsCdna(selected); |
473 |
0 |
ap.av.getCodingComplement().setProteinFontAsCdna(selected); |
474 |
|
|
475 |
|
|
476 |
|
|
477 |
|
|
478 |
0 |
if (!selected) |
479 |
|
{ |
480 |
0 |
ap.av.getCodingComplement().setFont(oldComplementFont, true); |
481 |
|
} |
482 |
|
|
483 |
0 |
changeFont(); |
484 |
|
} |
485 |
|
} |