2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 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
22 import java.awt.event.*;
\r
23 import javax.swing.*;
\r
25 import jalview.bin.*;
\r
26 import jalview.jbgui.*;
\r
32 * @version $Revision$
\r
34 public class FontChooser
\r
35 extends GFontChooser
\r
40 boolean init = true;
\r
41 JInternalFrame frame;
\r
44 * Creates a new FontChooser object.
\r
46 * @param ap DOCUMENT ME!
\r
48 public FontChooser(TreePanel tp)
\r
51 ap = tp.treeCanvas.ap;
\r
52 oldFont = tp.getTreeFont();
\r
53 defaultButton.setVisible(false);
\r
54 smoothFont.setEnabled(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
79 Desktop.addInternalFrame(frame, "Change Font (Tree Panel)", 340, 170, false);
\r
83 Desktop.addInternalFrame(frame, "Change Font", 340, 170, false);
\r
86 frame.setLayer(JLayeredPane.PALETTE_LAYER);
\r
88 String[] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment()
\r
89 .getAvailableFontFamilyNames();
\r
91 for (int i = 0; i < fonts.length; i++)
\r
93 fontName.addItem(fonts[i]);
\r
96 for (int i = 1; i < 51; i++)
\r
98 fontSize.addItem(i + "");
\r
101 fontStyle.addItem("plain");
\r
102 fontStyle.addItem("bold");
\r
103 fontStyle.addItem("italic");
\r
105 fontName.setSelectedItem(oldFont.getName());
\r
106 fontSize.setSelectedItem(oldFont.getSize() + "");
\r
107 fontStyle.setSelectedIndex(oldFont.getStyle());
\r
109 FontMetrics fm = getGraphics().getFontMetrics(oldFont);
\r
110 monospaced.setSelected(fm.getStringBounds("M", getGraphics()).getWidth()
\r
111 == fm.getStringBounds("|", getGraphics()).getWidth());
\r
116 public void smoothFont_actionPerformed(ActionEvent e)
\r
118 ap.av.antiAlias = smoothFont.isSelected();
\r
119 ap.annotationPanel.image = null;
\r
120 ap.paintAlignment(true);
\r
126 * @param e DOCUMENT ME!
\r
128 protected void ok_actionPerformed(ActionEvent e)
\r
132 frame.setClosed(true);
\r
134 catch (Exception ex)
\r
140 if (ap.getOverviewPanel() != null)
\r
142 ap.getOverviewPanel().updateOverviewImage();
\r
150 * @param e DOCUMENT ME!
\r
152 protected void cancel_actionPerformed(ActionEvent e)
\r
156 ap.av.setFont(oldFont);
\r
157 ap.paintAlignment(true);
\r
159 else if (tp != null)
\r
161 tp.setTreeFont(oldFont);
\r
163 fontName.setSelectedItem(oldFont.getName());
\r
164 fontSize.setSelectedItem(oldFont.getSize() + "");
\r
165 fontStyle.setSelectedIndex(oldFont.getStyle());
\r
169 frame.setClosed(true);
\r
171 catch (Exception ex)
\r
181 Font newFont = new Font(fontName.getSelectedItem().toString(),
\r
182 fontStyle.getSelectedIndex(),
\r
183 Integer.parseInt(fontSize.getSelectedItem().
\r
187 tp.setTreeFont(newFont);
\r
189 else if (ap != null)
\r
191 ap.av.setFont(newFont);
\r
195 FontMetrics fm = getGraphics().getFontMetrics(newFont);
\r
197 monospaced.setSelected(fm.getStringBounds("M", getGraphics()).getWidth()
\r
198 == fm.getStringBounds("|", getGraphics()).getWidth());
\r
205 * @param e DOCUMENT ME!
\r
207 protected void fontName_actionPerformed(ActionEvent e)
\r
220 * @param e DOCUMENT ME!
\r
222 protected void fontSize_actionPerformed(ActionEvent e)
\r
235 * @param e DOCUMENT ME!
\r
237 protected void fontStyle_actionPerformed(ActionEvent e)
\r
250 * @param e DOCUMENT ME!
\r
252 public void defaultButton_actionPerformed(ActionEvent e)
\r
254 Cache.setProperty("FONT_NAME", fontName.getSelectedItem().toString());
\r
255 Cache.setProperty("FONT_STYLE", fontStyle.getSelectedIndex() + "");
\r
256 Cache.setProperty("FONT_SIZE", fontSize.getSelectedItem().toString());
\r
257 Cache.setProperty("ANTI_ALIAS", Boolean.toString(smoothFont.isSelected()));
\r