2 * Jalview - A Sequence Alignment Editor and Viewer
3 * Copyright (C) 2006 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
23 import jalview.jbgui.*;
26 import java.awt.event.*;
37 public class FontChooser extends GFontChooser
46 * Creates a new FontChooser object.
48 * @param ap DOCUMENT ME!
50 public FontChooser(TreePanel tp)
53 oldFont = tp.getTreeFont();
54 defaultButton.setVisible(false);
58 * Creates a new FontChooser object.
60 * @param ap DOCUMENT ME!
62 public FontChooser(AlignmentPanel ap)
64 oldFont = ap.av.getFont();
71 frame = new JInternalFrame();
72 frame.setContentPane(this);
74 Desktop.addInternalFrame(frame, "Change Font (Tree Panel)", 540, 100, false);
76 Desktop.addInternalFrame(frame, "Change Font", 540, 100, false);
78 frame.setLayer(JLayeredPane.PALETTE_LAYER);
80 String[] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment()
81 .getAvailableFontFamilyNames();
83 for (int i = 0; i < fonts.length; i++)
85 fontName.addItem(fonts[i]);
88 for (int i = 1; i < 51; i++)
90 fontSize.addItem(i + "");
93 fontStyle.addItem("plain");
94 fontStyle.addItem("bold");
95 fontStyle.addItem("italic");
97 fontName.setSelectedItem(oldFont.getName());
98 fontSize.setSelectedItem(oldFont.getSize() + "");
99 fontStyle.setSelectedIndex(oldFont.getStyle());
101 FontMetrics fm = getGraphics().getFontMetrics(oldFont);
102 monospaced.setSelected( fm.getStringBounds("M",getGraphics()).getWidth()
103 ==fm.getStringBounds("|",getGraphics()).getWidth());
112 * @param e DOCUMENT ME!
114 protected void ok_actionPerformed(ActionEvent e)
118 frame.setClosed(true);
126 if (ap.getOverviewPanel() != null)
128 ap.getOverviewPanel().updateOverviewImage();
136 * @param e DOCUMENT ME!
138 protected void cancel_actionPerformed(ActionEvent e)
142 ap.av.setFont(oldFont);
147 tp.setTreeFont(oldFont);
149 fontName.setSelectedItem(oldFont.getName());
150 fontSize.setSelectedItem(oldFont.getSize() + "");
151 fontStyle.setSelectedIndex(oldFont.getStyle());
155 frame.setClosed(true);
167 Font newFont = new Font(fontName.getSelectedItem().toString(),
168 fontStyle.getSelectedIndex(),
169 Integer.parseInt(fontSize.getSelectedItem().toString()));
172 ap.av.setFont(newFont);
177 tp.setTreeFont(newFont);
180 FontMetrics fm = getGraphics().getFontMetrics(newFont);
182 monospaced.setSelected( fm.getStringBounds("M",getGraphics()).getWidth()
183 ==fm.getStringBounds("|",getGraphics()).getWidth());
190 * @param e DOCUMENT ME!
192 protected void fontName_actionPerformed(ActionEvent e)
205 * @param e DOCUMENT ME!
207 protected void fontSize_actionPerformed(ActionEvent e)
220 * @param e DOCUMENT ME!
222 protected void fontStyle_actionPerformed(ActionEvent e)
235 * @param e DOCUMENT ME!
237 public void defaultButton_actionPerformed(ActionEvent e)
239 Cache.setProperty("FONT_NAME", fontName.getSelectedItem().toString());
240 Cache.setProperty("FONT_STYLE", fontStyle.getSelectedIndex() + "");
241 Cache.setProperty("FONT_SIZE", fontSize.getSelectedItem().toString());