2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ 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.
23 import jalview.bin.Cache;
24 import jalview.jbgui.GFontChooser;
25 import jalview.util.MessageManager;
28 import java.awt.FontMetrics;
29 import java.awt.event.ActionEvent;
31 import javax.swing.JInternalFrame;
32 import javax.swing.JLayeredPane;
33 import javax.swing.JOptionPane;
41 public class FontChooser extends GFontChooser
54 * Creates a new FontChooser object.
59 public FontChooser(TreePanel tp)
62 ap = tp.treeCanvas.ap;
63 oldFont = tp.getTreeFont();
64 defaultButton.setVisible(false);
65 smoothFont.setEnabled(false);
70 * Creates a new FontChooser object.
75 public FontChooser(AlignmentPanel ap)
77 oldFont = ap.av.getFont();
84 frame = new JInternalFrame();
85 frame.setContentPane(this);
87 smoothFont.setSelected(ap.av.antiAlias);
91 Desktop.addInternalFrame(frame,
92 MessageManager.getString("action.change_font_tree_panel"),
97 Desktop.addInternalFrame(frame,
98 MessageManager.getString("action.change_font"), 340, 170,
102 frame.setLayer(JLayeredPane.PALETTE_LAYER);
104 String[] fonts = java.awt.GraphicsEnvironment
105 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
107 for (int i = 0; i < fonts.length; i++)
109 fontName.addItem(fonts[i]);
112 for (int i = 1; i < 51; i++)
114 fontSize.addItem(i + "");
117 fontStyle.addItem("plain");
118 fontStyle.addItem("bold");
119 fontStyle.addItem("italic");
121 fontName.setSelectedItem(oldFont.getName());
122 fontSize.setSelectedItem(oldFont.getSize() + "");
123 fontStyle.setSelectedIndex(oldFont.getStyle());
125 FontMetrics fm = getGraphics().getFontMetrics(oldFont);
126 monospaced.setSelected(fm.getStringBounds("M", getGraphics())
127 .getWidth() == fm.getStringBounds("|", getGraphics())
133 public void smoothFont_actionPerformed(ActionEvent e)
135 ap.av.antiAlias = smoothFont.isSelected();
136 ap.getAnnotationPanel().image = null;
137 ap.paintAlignment(true);
146 protected void ok_actionPerformed(ActionEvent e)
150 frame.setClosed(true);
151 } catch (Exception ex)
157 if (ap.getOverviewPanel() != null)
159 ap.getOverviewPanel().updateOverviewImage();
170 protected void cancel_actionPerformed(ActionEvent e)
174 ap.av.setFont(oldFont, true);
175 ap.paintAlignment(true);
179 tp.setTreeFont(oldFont);
181 fontName.setSelectedItem(oldFont.getName());
182 fontSize.setSelectedItem(oldFont.getSize() + "");
183 fontStyle.setSelectedIndex(oldFont.getStyle());
187 frame.setClosed(true);
188 } catch (Exception ex)
193 private Font lastSelected = null;
195 private int lastSelStyle = 0;
197 private int lastSelSize = 0;
199 private boolean lastSelMono = false;
206 if (lastSelected == null)
208 // initialise with original font
209 lastSelected = oldFont;
210 lastSelSize = oldFont.getSize();
211 lastSelStyle = oldFont.getStyle();
212 FontMetrics fm = getGraphics().getFontMetrics(oldFont);
213 double mw = fm.getStringBounds("M", getGraphics()).getWidth(), iw = fm
214 .getStringBounds("I", getGraphics()).getWidth();
215 lastSelMono = mw == iw;
218 Font newFont = new Font(fontName.getSelectedItem().toString(),
219 fontStyle.getSelectedIndex(), Integer.parseInt(fontSize
220 .getSelectedItem().toString()));
221 FontMetrics fm = getGraphics().getFontMetrics(newFont);
222 double mw = fm.getStringBounds("M", getGraphics()).getWidth(), iw = fm
223 .getStringBounds("I", getGraphics()).getWidth();
224 if (mw < 1 || iw < 1)
226 fontName.setSelectedItem(lastSelected.getName());
227 fontStyle.setSelectedIndex(lastSelStyle);
228 fontSize.setSelectedItem("" + lastSelSize);
229 monospaced.setSelected(lastSelMono);
231 .showInternalMessageDialog(
233 MessageManager.getString("label.font_doesnt_have_letters_defined"),
234 MessageManager.getString("label.invalid_font"), JOptionPane.WARNING_MESSAGE);
239 tp.setTreeFont(newFont);
243 ap.av.setFont(newFont, true);
247 monospaced.setSelected(mw == iw);
248 // remember last selected
249 lastSelected = newFont;
258 protected void fontName_actionPerformed(ActionEvent e)
274 protected void fontSize_actionPerformed(ActionEvent e)
290 protected void fontStyle_actionPerformed(ActionEvent e)
306 public void defaultButton_actionPerformed(ActionEvent e)
308 Cache.setProperty("FONT_NAME", fontName.getSelectedItem().toString());
309 Cache.setProperty("FONT_STYLE", fontStyle.getSelectedIndex() + "");
310 Cache.setProperty("FONT_SIZE", fontSize.getSelectedItem().toString());
311 Cache.setProperty("ANTI_ALIAS",
312 Boolean.toString(smoothFont.isSelected()));