2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
24 import java.awt.event.*;
28 import jalview.jbgui.*;
29 import jalview.util.MessageManager;
37 public class FontChooser extends GFontChooser
50 * Creates a new FontChooser object.
55 public FontChooser(TreePanel tp)
58 ap = tp.treeCanvas.ap;
59 oldFont = tp.getTreeFont();
60 defaultButton.setVisible(false);
61 smoothFont.setEnabled(false);
66 * Creates a new FontChooser object.
71 public FontChooser(AlignmentPanel ap)
73 oldFont = ap.av.getFont();
80 frame = new JInternalFrame();
81 frame.setContentPane(this);
83 smoothFont.setSelected(ap.av.antiAlias);
87 Desktop.addInternalFrame(frame,
88 MessageManager.getString("action.change_font_tree_panel"),
93 Desktop.addInternalFrame(frame,
94 MessageManager.getString("action.change_font"), 340, 170,
98 frame.setLayer(JLayeredPane.PALETTE_LAYER);
100 String[] fonts = java.awt.GraphicsEnvironment
101 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
103 for (int i = 0; i < fonts.length; i++)
105 fontName.addItem(fonts[i]);
108 for (int i = 1; i < 51; i++)
110 fontSize.addItem(i + "");
113 fontStyle.addItem("plain");
114 fontStyle.addItem("bold");
115 fontStyle.addItem("italic");
117 fontName.setSelectedItem(oldFont.getName());
118 fontSize.setSelectedItem(oldFont.getSize() + "");
119 fontStyle.setSelectedIndex(oldFont.getStyle());
121 FontMetrics fm = getGraphics().getFontMetrics(oldFont);
122 monospaced.setSelected(fm.getStringBounds("M", getGraphics())
123 .getWidth() == fm.getStringBounds("|", getGraphics())
129 public void smoothFont_actionPerformed(ActionEvent e)
131 ap.av.antiAlias = smoothFont.isSelected();
132 ap.annotationPanel.image = null;
133 ap.paintAlignment(true);
142 protected void ok_actionPerformed(ActionEvent e)
146 frame.setClosed(true);
147 } catch (Exception ex)
153 if (ap.getOverviewPanel() != null)
155 ap.getOverviewPanel().updateOverviewImage();
166 protected void cancel_actionPerformed(ActionEvent e)
170 ap.av.setFont(oldFont);
171 ap.paintAlignment(true);
175 tp.setTreeFont(oldFont);
177 fontName.setSelectedItem(oldFont.getName());
178 fontSize.setSelectedItem(oldFont.getSize() + "");
179 fontStyle.setSelectedIndex(oldFont.getStyle());
183 frame.setClosed(true);
184 } catch (Exception ex)
189 private Font lastSelected = null;
191 private int lastSelStyle = 0;
193 private int lastSelSize = 0;
195 private boolean lastSelMono = false;
202 if (lastSelected == null)
204 // initialise with original font
205 lastSelected = oldFont;
206 lastSelSize = oldFont.getSize();
207 lastSelStyle = oldFont.getStyle();
208 FontMetrics fm = getGraphics().getFontMetrics(oldFont);
209 double mw = fm.getStringBounds("M", getGraphics()).getWidth(), iw = fm
210 .getStringBounds("I", getGraphics()).getWidth();
211 lastSelMono = mw == iw;
214 Font newFont = new Font(fontName.getSelectedItem().toString(),
215 fontStyle.getSelectedIndex(), Integer.parseInt(fontSize
216 .getSelectedItem().toString()));
217 FontMetrics fm = getGraphics().getFontMetrics(newFont);
218 double mw = fm.getStringBounds("M", getGraphics()).getWidth(), iw = fm
219 .getStringBounds("I", getGraphics()).getWidth();
220 if (mw < 1 || iw < 1)
222 fontName.setSelectedItem(lastSelected.getName());
223 fontStyle.setSelectedIndex(lastSelStyle);
224 fontSize.setSelectedItem("" + lastSelSize);
225 monospaced.setSelected(lastSelMono);
227 .showInternalMessageDialog(
229 "Font doesn't have letters defined\nso cannot be used\nwith alignment data.",
230 "Invalid Font", JOptionPane.WARNING_MESSAGE);
235 tp.setTreeFont(newFont);
239 ap.av.setFont(newFont);
243 monospaced.setSelected(mw == iw);
244 // remember last selected
245 lastSelected = newFont;
254 protected void fontName_actionPerformed(ActionEvent e)
270 protected void fontSize_actionPerformed(ActionEvent e)
286 protected void fontStyle_actionPerformed(ActionEvent e)
302 public void defaultButton_actionPerformed(ActionEvent e)
304 Cache.setProperty("FONT_NAME", fontName.getSelectedItem().toString());
305 Cache.setProperty("FONT_STYLE", fontStyle.getSelectedIndex() + "");
306 Cache.setProperty("FONT_SIZE", fontSize.getSelectedItem().toString());
307 Cache.setProperty("ANTI_ALIAS",
308 Boolean.toString(smoothFont.isSelected()));