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 ap = tp.treeCanvas.ap;
\r
54 oldFont = tp.getTreeFont();
\r
55 defaultButton.setVisible(false);
\r
59 * Creates a new FontChooser object.
\r
61 * @param ap DOCUMENT ME!
\r
63 public FontChooser(AlignmentPanel ap)
\r
65 oldFont = ap.av.getFont();
\r
72 frame = new JInternalFrame();
\r
73 frame.setContentPane(this);
\r
75 smoothFont.setSelected(ap.av.antiAlias);
\r
78 Desktop.addInternalFrame(frame, "Change Font (Tree Panel)", 340, 170, false);
\r
80 Desktop.addInternalFrame(frame, "Change Font", 340, 170, false);
\r
82 frame.setLayer(JLayeredPane.PALETTE_LAYER);
\r
84 String[] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment()
\r
85 .getAvailableFontFamilyNames();
\r
87 for (int i = 0; i < fonts.length; i++)
\r
89 fontName.addItem(fonts[i]);
\r
92 for (int i = 1; i < 51; i++)
\r
94 fontSize.addItem(i + "");
\r
97 fontStyle.addItem("plain");
\r
98 fontStyle.addItem("bold");
\r
99 fontStyle.addItem("italic");
\r
101 fontName.setSelectedItem(oldFont.getName());
\r
102 fontSize.setSelectedItem(oldFont.getSize() + "");
\r
103 fontStyle.setSelectedIndex(oldFont.getStyle());
\r
105 FontMetrics fm = getGraphics().getFontMetrics(oldFont);
\r
106 monospaced.setSelected( fm.getStringBounds("M",getGraphics()).getWidth()
\r
107 ==fm.getStringBounds("|",getGraphics()).getWidth());
\r
113 public void smoothFont_actionPerformed(ActionEvent e)
\r
115 ap.av.antiAlias = smoothFont.isSelected();
\r
116 ap.annotationPanel.image = null;
\r
125 * @param e DOCUMENT ME!
\r
127 protected void ok_actionPerformed(ActionEvent e)
\r
131 frame.setClosed(true);
\r
133 catch (Exception ex)
\r
139 if (ap.getOverviewPanel() != null)
\r
141 ap.getOverviewPanel().updateOverviewImage();
\r
149 * @param e DOCUMENT ME!
\r
151 protected void cancel_actionPerformed(ActionEvent e)
\r
155 ap.av.setFont(oldFont);
\r
160 tp.setTreeFont(oldFont);
\r
162 fontName.setSelectedItem(oldFont.getName());
\r
163 fontSize.setSelectedItem(oldFont.getSize() + "");
\r
164 fontStyle.setSelectedIndex(oldFont.getStyle());
\r
168 frame.setClosed(true);
\r
170 catch (Exception ex)
\r
180 Font newFont = new Font(fontName.getSelectedItem().toString(),
\r
181 fontStyle.getSelectedIndex(),
\r
182 Integer.parseInt(fontSize.getSelectedItem().toString()));
\r
185 tp.setTreeFont(newFont);
\r
187 else if(ap != null)
\r
189 ap.av.setFont(newFont);
\r
194 FontMetrics fm = getGraphics().getFontMetrics(newFont);
\r
196 monospaced.setSelected( fm.getStringBounds("M",getGraphics()).getWidth()
\r
197 ==fm.getStringBounds("|",getGraphics()).getWidth());
\r
204 * @param e DOCUMENT ME!
\r
206 protected void fontName_actionPerformed(ActionEvent e)
\r
219 * @param e DOCUMENT ME!
\r
221 protected void fontSize_actionPerformed(ActionEvent e)
\r
234 * @param e DOCUMENT ME!
\r
236 protected void fontStyle_actionPerformed(ActionEvent e)
\r
249 * @param e DOCUMENT ME!
\r
251 public void defaultButton_actionPerformed(ActionEvent e)
\r
253 Cache.setProperty("FONT_NAME", fontName.getSelectedItem().toString());
\r
254 Cache.setProperty("FONT_STYLE", fontStyle.getSelectedIndex() + "");
\r
255 Cache.setProperty("FONT_SIZE", fontSize.getSelectedItem().toString());
\r
256 Cache.setProperty("ANTI_ALIAS", Boolean.toString(smoothFont.isSelected()));
\r