2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
19 package jalview.gui;
\r
21 import jalview.bin.*;
\r
23 import jalview.jbgui.*;
\r
26 import java.awt.event.*;
\r
28 import javax.swing.*;
\r
35 * @version $Revision$
\r
37 public class FontChooser extends GFontChooser
\r
42 boolean init = true;
\r
43 JInternalFrame frame;
\r
46 * Creates a new FontChooser object.
\r
48 * @param ap DOCUMENT ME!
\r
50 public FontChooser(TreePanel tp)
\r
53 oldFont = tp.getTreeFont();
\r
54 defaultButton.setVisible(false);
\r
58 * Creates a new FontChooser object.
\r
60 * @param ap DOCUMENT ME!
\r
62 public FontChooser(AlignmentPanel ap)
\r
64 oldFont = ap.av.getFont();
\r
71 frame = new JInternalFrame();
\r
72 frame.setContentPane(this);
\r
74 Desktop.addInternalFrame(frame, "Change Font (Tree Panel)", 540, 100, false);
\r
76 Desktop.addInternalFrame(frame, "Change Font", 540, 100, false);
\r
78 frame.setLayer(JLayeredPane.PALETTE_LAYER);
\r
80 String[] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment()
\r
81 .getAvailableFontFamilyNames();
\r
83 for (int i = 0; i < fonts.length; i++)
\r
85 fontName.addItem(fonts[i]);
\r
88 for (int i = 1; i < 51; i++)
\r
90 fontSize.addItem(i + "");
\r
93 fontStyle.addItem("plain");
\r
94 fontStyle.addItem("bold");
\r
95 fontStyle.addItem("italic");
\r
97 fontName.setSelectedItem(oldFont.getName());
\r
98 fontSize.setSelectedItem(oldFont.getSize() + "");
\r
99 fontStyle.setSelectedIndex(oldFont.getStyle());
\r
101 FontMetrics fm = getGraphics().getFontMetrics(oldFont);
\r
102 monospaced.setSelected( fm.getStringBounds("M",getGraphics()).getWidth()
\r
103 ==fm.getStringBounds("|",getGraphics()).getWidth());
\r
112 * @param e DOCUMENT ME!
\r
114 protected void ok_actionPerformed(ActionEvent e)
\r
118 frame.setClosed(true);
\r
120 catch (Exception ex)
\r
126 if (ap.getOverviewPanel() != null)
\r
128 ap.getOverviewPanel().updateOverviewImage();
\r
136 * @param e DOCUMENT ME!
\r
138 protected void cancel_actionPerformed(ActionEvent e)
\r
142 ap.av.setFont(oldFont);
\r
147 tp.setTreeFont(oldFont);
\r
149 fontName.setSelectedItem(oldFont.getName());
\r
150 fontSize.setSelectedItem(oldFont.getSize() + "");
\r
151 fontStyle.setSelectedIndex(oldFont.getStyle());
\r
155 frame.setClosed(true);
\r
157 catch (Exception ex)
\r
167 Font newFont = new Font(fontName.getSelectedItem().toString(),
\r
168 fontStyle.getSelectedIndex(),
\r
169 Integer.parseInt(fontSize.getSelectedItem().toString()));
\r
172 ap.av.setFont(newFont);
\r
175 else if(tp != null)
\r
177 tp.setTreeFont(newFont);
\r
180 FontMetrics fm = getGraphics().getFontMetrics(newFont);
\r
182 monospaced.setSelected( fm.getStringBounds("M",getGraphics()).getWidth()
\r
183 ==fm.getStringBounds("|",getGraphics()).getWidth());
\r
190 * @param e DOCUMENT ME!
\r
192 protected void fontName_actionPerformed(ActionEvent e)
\r
205 * @param e DOCUMENT ME!
\r
207 protected void fontSize_actionPerformed(ActionEvent e)
\r
220 * @param e DOCUMENT ME!
\r
222 protected void fontStyle_actionPerformed(ActionEvent e)
\r
235 * @param e DOCUMENT ME!
\r
237 public void defaultButton_actionPerformed(ActionEvent e)
\r
239 Cache.setProperty("FONT_NAME", fontName.getSelectedItem().toString());
\r
240 Cache.setProperty("FONT_STYLE", fontStyle.getSelectedIndex() + "");
\r
241 Cache.setProperty("FONT_SIZE", fontSize.getSelectedItem().toString());
\r