2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
3 * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
21 import java.awt.event.*;
25 import jalview.jbgui.*;
33 public class FontChooser extends GFontChooser
46 * Creates a new FontChooser object.
51 public FontChooser(TreePanel tp)
54 ap = tp.treeCanvas.ap;
55 oldFont = tp.getTreeFont();
56 defaultButton.setVisible(false);
57 smoothFont.setEnabled(false);
62 * Creates a new FontChooser object.
67 public FontChooser(AlignmentPanel ap)
69 oldFont = ap.av.getFont();
76 frame = new JInternalFrame();
77 frame.setContentPane(this);
79 smoothFont.setSelected(ap.av.antiAlias);
83 Desktop.addInternalFrame(frame, "Change Font (Tree Panel)", 340, 170,
88 Desktop.addInternalFrame(frame, "Change Font", 340, 170, false);
91 frame.setLayer(JLayeredPane.PALETTE_LAYER);
93 String[] fonts = java.awt.GraphicsEnvironment
94 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
96 for (int i = 0; i < fonts.length; i++)
98 fontName.addItem(fonts[i]);
101 for (int i = 1; i < 51; i++)
103 fontSize.addItem(i + "");
106 fontStyle.addItem("plain");
107 fontStyle.addItem("bold");
108 fontStyle.addItem("italic");
110 fontName.setSelectedItem(oldFont.getName());
111 fontSize.setSelectedItem(oldFont.getSize() + "");
112 fontStyle.setSelectedIndex(oldFont.getStyle());
114 FontMetrics fm = getGraphics().getFontMetrics(oldFont);
115 monospaced.setSelected(fm.getStringBounds("M", getGraphics())
116 .getWidth() == fm.getStringBounds("|", getGraphics())
122 public void smoothFont_actionPerformed(ActionEvent e)
124 ap.av.antiAlias = smoothFont.isSelected();
125 ap.annotationPanel.image = null;
126 ap.paintAlignment(true);
135 protected void ok_actionPerformed(ActionEvent e)
139 frame.setClosed(true);
140 } catch (Exception ex)
146 if (ap.getOverviewPanel() != null)
148 ap.getOverviewPanel().updateOverviewImage();
159 protected void cancel_actionPerformed(ActionEvent e)
163 ap.av.setFont(oldFont);
164 ap.paintAlignment(true);
168 tp.setTreeFont(oldFont);
170 fontName.setSelectedItem(oldFont.getName());
171 fontSize.setSelectedItem(oldFont.getSize() + "");
172 fontStyle.setSelectedIndex(oldFont.getStyle());
176 frame.setClosed(true);
177 } catch (Exception ex)
187 Font newFont = new Font(fontName.getSelectedItem().toString(),
188 fontStyle.getSelectedIndex(), Integer.parseInt(fontSize
189 .getSelectedItem().toString()));
192 tp.setTreeFont(newFont);
196 ap.av.setFont(newFont);
200 FontMetrics fm = getGraphics().getFontMetrics(newFont);
202 monospaced.setSelected(fm.getStringBounds("M", getGraphics())
203 .getWidth() == fm.getStringBounds("|", getGraphics())
214 protected void fontName_actionPerformed(ActionEvent e)
230 protected void fontSize_actionPerformed(ActionEvent e)
246 protected void fontStyle_actionPerformed(ActionEvent e)
262 public void defaultButton_actionPerformed(ActionEvent e)
264 Cache.setProperty("FONT_NAME", fontName.getSelectedItem().toString());
265 Cache.setProperty("FONT_STYLE", fontStyle.getSelectedIndex() + "");
266 Cache.setProperty("FONT_SIZE", fontSize.getSelectedItem().toString());
267 Cache.setProperty("ANTI_ALIAS",
268 Boolean.toString(smoothFont.isSelected()));