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