2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 import java.awt.event.*;
26 import jalview.jbgui.*;
34 public class FontChooser
44 * Creates a new FontChooser object.
46 * @param ap DOCUMENT ME!
48 public FontChooser(TreePanel tp)
51 ap = tp.treeCanvas.ap;
52 oldFont = tp.getTreeFont();
53 defaultButton.setVisible(false);
54 smoothFont.setEnabled(false);
59 * Creates a new FontChooser object.
61 * @param ap DOCUMENT ME!
63 public FontChooser(AlignmentPanel ap)
65 oldFont = ap.av.getFont();
72 frame = new JInternalFrame();
73 frame.setContentPane(this);
75 smoothFont.setSelected(ap.av.antiAlias);
79 Desktop.addInternalFrame(frame, "Change Font (Tree Panel)", 340, 170, false);
83 Desktop.addInternalFrame(frame, "Change Font", 340, 170, false);
86 frame.setLayer(JLayeredPane.PALETTE_LAYER);
88 String[] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment()
89 .getAvailableFontFamilyNames();
91 for (int i = 0; i < fonts.length; i++)
93 fontName.addItem(fonts[i]);
96 for (int i = 1; i < 51; i++)
98 fontSize.addItem(i + "");
101 fontStyle.addItem("plain");
102 fontStyle.addItem("bold");
103 fontStyle.addItem("italic");
105 fontName.setSelectedItem(oldFont.getName());
106 fontSize.setSelectedItem(oldFont.getSize() + "");
107 fontStyle.setSelectedIndex(oldFont.getStyle());
109 FontMetrics fm = getGraphics().getFontMetrics(oldFont);
110 monospaced.setSelected(fm.getStringBounds("M", getGraphics()).getWidth()
111 == fm.getStringBounds("|", getGraphics()).getWidth());
116 public void smoothFont_actionPerformed(ActionEvent e)
118 ap.av.antiAlias = smoothFont.isSelected();
119 ap.annotationPanel.image = null;
120 ap.paintAlignment(true);
126 * @param e DOCUMENT ME!
128 protected void ok_actionPerformed(ActionEvent e)
132 frame.setClosed(true);
140 if (ap.getOverviewPanel() != null)
142 ap.getOverviewPanel().updateOverviewImage();
150 * @param e DOCUMENT ME!
152 protected void cancel_actionPerformed(ActionEvent e)
156 ap.av.setFont(oldFont);
157 ap.paintAlignment(true);
161 tp.setTreeFont(oldFont);
163 fontName.setSelectedItem(oldFont.getName());
164 fontSize.setSelectedItem(oldFont.getSize() + "");
165 fontStyle.setSelectedIndex(oldFont.getStyle());
169 frame.setClosed(true);
181 Font newFont = new Font(fontName.getSelectedItem().toString(),
182 fontStyle.getSelectedIndex(),
183 Integer.parseInt(fontSize.getSelectedItem().
187 tp.setTreeFont(newFont);
191 ap.av.setFont(newFont);
195 FontMetrics fm = getGraphics().getFontMetrics(newFont);
197 monospaced.setSelected(fm.getStringBounds("M", getGraphics()).getWidth()
198 == fm.getStringBounds("|", getGraphics()).getWidth());
205 * @param e DOCUMENT ME!
207 protected void fontName_actionPerformed(ActionEvent e)
220 * @param e DOCUMENT ME!
222 protected void fontSize_actionPerformed(ActionEvent e)
235 * @param e DOCUMENT ME!
237 protected void fontStyle_actionPerformed(ActionEvent e)
250 * @param e DOCUMENT ME!
252 public void defaultButton_actionPerformed(ActionEvent e)
254 Cache.setProperty("FONT_NAME", fontName.getSelectedItem().toString());
255 Cache.setProperty("FONT_STYLE", fontStyle.getSelectedIndex() + "");
256 Cache.setProperty("FONT_SIZE", fontSize.getSelectedItem().toString());
257 Cache.setProperty("ANTI_ALIAS", Boolean.toString(smoothFont.isSelected()));