2 * Jalview - A Sequence Alignment Editor and Viewer (Development Version 2.4.1)
3 * Copyright (C) 2009 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 extends GFontChooser
47 * Creates a new FontChooser object.
52 public FontChooser(TreePanel tp)
55 ap = tp.treeCanvas.ap;
56 oldFont = tp.getTreeFont();
57 defaultButton.setVisible(false);
58 smoothFont.setEnabled(false);
63 * Creates a new FontChooser object.
68 public FontChooser(AlignmentPanel ap)
70 oldFont = ap.av.getFont();
77 frame = new JInternalFrame();
78 frame.setContentPane(this);
80 smoothFont.setSelected(ap.av.antiAlias);
84 Desktop.addInternalFrame(frame, "Change Font (Tree Panel)", 340, 170,
89 Desktop.addInternalFrame(frame, "Change Font", 340, 170, false);
92 frame.setLayer(JLayeredPane.PALETTE_LAYER);
94 String[] fonts = java.awt.GraphicsEnvironment
95 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
97 for (int i = 0; i < fonts.length; i++)
99 fontName.addItem(fonts[i]);
102 for (int i = 1; i < 51; i++)
104 fontSize.addItem(i + "");
107 fontStyle.addItem("plain");
108 fontStyle.addItem("bold");
109 fontStyle.addItem("italic");
111 fontName.setSelectedItem(oldFont.getName());
112 fontSize.setSelectedItem(oldFont.getSize() + "");
113 fontStyle.setSelectedIndex(oldFont.getStyle());
115 FontMetrics fm = getGraphics().getFontMetrics(oldFont);
116 monospaced.setSelected(fm.getStringBounds("M", getGraphics())
117 .getWidth() == fm.getStringBounds("|", getGraphics())
123 public void smoothFont_actionPerformed(ActionEvent e)
125 ap.av.antiAlias = smoothFont.isSelected();
126 ap.annotationPanel.image = null;
127 ap.paintAlignment(true);
136 protected void ok_actionPerformed(ActionEvent e)
140 frame.setClosed(true);
141 } catch (Exception ex)
147 if (ap.getOverviewPanel() != null)
149 ap.getOverviewPanel().updateOverviewImage();
160 protected void cancel_actionPerformed(ActionEvent e)
164 ap.av.setFont(oldFont);
165 ap.paintAlignment(true);
169 tp.setTreeFont(oldFont);
171 fontName.setSelectedItem(oldFont.getName());
172 fontSize.setSelectedItem(oldFont.getSize() + "");
173 fontStyle.setSelectedIndex(oldFont.getStyle());
177 frame.setClosed(true);
178 } catch (Exception ex)
188 Font newFont = new Font(fontName.getSelectedItem().toString(),
189 fontStyle.getSelectedIndex(), Integer.parseInt(fontSize
190 .getSelectedItem().toString()));
193 tp.setTreeFont(newFont);
197 ap.av.setFont(newFont);
201 FontMetrics fm = getGraphics().getFontMetrics(newFont);
203 monospaced.setSelected(fm.getStringBounds("M", getGraphics())
204 .getWidth() == fm.getStringBounds("|", getGraphics())
215 protected void fontName_actionPerformed(ActionEvent e)
231 protected void fontSize_actionPerformed(ActionEvent e)
247 protected void fontStyle_actionPerformed(ActionEvent e)
263 public void defaultButton_actionPerformed(ActionEvent e)
265 Cache.setProperty("FONT_NAME", fontName.getSelectedItem().toString());
266 Cache.setProperty("FONT_STYLE", fontStyle.getSelectedIndex() + "");
267 Cache.setProperty("FONT_SIZE", fontSize.getSelectedItem().toString());
268 Cache.setProperty("ANTI_ALIAS", Boolean.toString(smoothFont