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, MessageManager.getString("action.change_font_tree_panel"), 340, 170,
92 Desktop.addInternalFrame(frame, MessageManager.getString("action.change_font"), 340, 170, false);
95 frame.setLayer(JLayeredPane.PALETTE_LAYER);
97 String[] fonts = java.awt.GraphicsEnvironment
98 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
100 for (int i = 0; i < fonts.length; i++)
102 fontName.addItem(fonts[i]);
105 for (int i = 1; i < 51; i++)
107 fontSize.addItem(i + "");
110 fontStyle.addItem("plain");
111 fontStyle.addItem("bold");
112 fontStyle.addItem("italic");
114 fontName.setSelectedItem(oldFont.getName());
115 fontSize.setSelectedItem(oldFont.getSize() + "");
116 fontStyle.setSelectedIndex(oldFont.getStyle());
118 FontMetrics fm = getGraphics().getFontMetrics(oldFont);
119 monospaced.setSelected(fm.getStringBounds("M", getGraphics())
120 .getWidth() == fm.getStringBounds("|", getGraphics())
126 public void smoothFont_actionPerformed(ActionEvent e)
128 ap.av.antiAlias = smoothFont.isSelected();
129 ap.annotationPanel.image = null;
130 ap.paintAlignment(true);
139 protected void ok_actionPerformed(ActionEvent e)
143 frame.setClosed(true);
144 } catch (Exception ex)
150 if (ap.getOverviewPanel() != null)
152 ap.getOverviewPanel().updateOverviewImage();
163 protected void cancel_actionPerformed(ActionEvent e)
167 ap.av.setFont(oldFont);
168 ap.paintAlignment(true);
172 tp.setTreeFont(oldFont);
174 fontName.setSelectedItem(oldFont.getName());
175 fontSize.setSelectedItem(oldFont.getSize() + "");
176 fontStyle.setSelectedIndex(oldFont.getStyle());
180 frame.setClosed(true);
181 } catch (Exception ex)
186 private Font lastSelected = null;
188 private int lastSelStyle = 0;
190 private int lastSelSize = 0;
192 private boolean lastSelMono = false;
199 if (lastSelected == null)
201 // initialise with original font
202 lastSelected = oldFont;
203 lastSelSize = oldFont.getSize();
204 lastSelStyle = oldFont.getStyle();
205 FontMetrics fm = getGraphics().getFontMetrics(oldFont);
206 double mw = fm.getStringBounds("M", getGraphics()).getWidth(), iw = fm
207 .getStringBounds("I", getGraphics()).getWidth();
208 lastSelMono = mw == iw;
211 Font newFont = new Font(fontName.getSelectedItem().toString(),
212 fontStyle.getSelectedIndex(), Integer.parseInt(fontSize
213 .getSelectedItem().toString()));
214 FontMetrics fm = getGraphics().getFontMetrics(newFont);
215 double mw = fm.getStringBounds("M", getGraphics()).getWidth(), iw = fm
216 .getStringBounds("I", getGraphics()).getWidth();
217 if (mw < 1 || iw < 1)
219 fontName.setSelectedItem(lastSelected.getName());
220 fontStyle.setSelectedIndex(lastSelStyle);
221 fontSize.setSelectedItem("" + lastSelSize);
222 monospaced.setSelected(lastSelMono);
224 .showInternalMessageDialog(
226 "Font doesn't have letters defined\nso cannot be used\nwith alignment data.",
227 "Invalid Font", JOptionPane.WARNING_MESSAGE);
232 tp.setTreeFont(newFont);
236 ap.av.setFont(newFont);
240 monospaced.setSelected(mw == iw);
241 // remember last selected
242 lastSelected = newFont;
251 protected void fontName_actionPerformed(ActionEvent e)
267 protected void fontSize_actionPerformed(ActionEvent e)
283 protected void fontStyle_actionPerformed(ActionEvent e)
299 public void defaultButton_actionPerformed(ActionEvent e)
301 Cache.setProperty("FONT_NAME", fontName.getSelectedItem().toString());
302 Cache.setProperty("FONT_STYLE", fontStyle.getSelectedIndex() + "");
303 Cache.setProperty("FONT_SIZE", fontSize.getSelectedItem().toString());
304 Cache.setProperty("ANTI_ALIAS",
305 Boolean.toString(smoothFont.isSelected()));