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
19 package jalview.appletgui;
22 import java.awt.event.*;
24 public class FontChooser extends Panel implements ActionListener,
37 public FontChooser(TreePanel tp)
48 oldFont = tp.getTreeFont();
52 public FontChooser(AlignmentPanel ap)
63 oldFont = ap.av.getFont();
69 String fonts[] = Toolkit.getDefaultToolkit().getFontList();
70 for (int i = 0; i < fonts.length; i++)
72 fontName.addItem(fonts[i]);
75 for (int i = 1; i < 31; i++)
77 fontSize.addItem(i + "");
80 fontStyle.addItem("plain");
81 fontStyle.addItem("bold");
82 fontStyle.addItem("italic");
84 fontName.select(oldFont.getName());
85 fontSize.select(oldFont.getSize() + "");
86 fontStyle.select(oldFont.getStyle());
88 Frame frame = new Frame();
91 jalview.bin.JalviewLite.addFrame(frame, "Change Font", 440, 115);
96 public void actionPerformed(ActionEvent evt)
98 if (evt.getSource() == ok)
100 ok_actionPerformed();
102 else if (evt.getSource() == cancel)
104 cancel_actionPerformed();
108 public void itemStateChanged(ItemEvent evt)
110 if (evt.getSource() == fontName)
112 fontName_actionPerformed();
114 else if (evt.getSource() == fontSize)
116 fontSize_actionPerformed();
118 else if (evt.getSource() == fontStyle)
120 fontStyle_actionPerformed();
124 protected void ok_actionPerformed()
126 frame.setVisible(false);
129 if (ap.getOverviewPanel() != null)
131 ap.getOverviewPanel().updateOverviewImage();
137 protected void cancel_actionPerformed()
141 ap.av.setFont(oldFont);
142 ap.paintAlignment(true);
146 tp.setTreeFont(oldFont);
147 tp.treeCanvas.repaint();
150 fontName.select(oldFont.getName());
151 fontSize.select(oldFont.getSize() + "");
152 fontStyle.select(oldFont.getStyle());
154 frame.setVisible(false);
159 Font newFont = new Font(fontName.getSelectedItem().toString(),
160 fontStyle.getSelectedIndex(), Integer.parseInt(fontSize
161 .getSelectedItem().toString()));
164 ap.av.setFont(newFont);
169 tp.setTreeFont(newFont);
173 protected void fontName_actionPerformed()
182 protected void fontSize_actionPerformed()
191 protected void fontStyle_actionPerformed()
200 Label label1 = new Label();
202 protected Choice fontSize = new Choice();
204 protected Choice fontStyle = new Choice();
206 Label label2 = new Label();
208 Label label3 = new Label();
210 protected Choice fontName = new Choice();
212 Button ok = new Button();
214 Button cancel = new Button();
216 Panel panel1 = new Panel();
218 Panel panel2 = new Panel();
220 Panel panel3 = new Panel();
222 BorderLayout borderLayout1 = new BorderLayout();
224 BorderLayout borderLayout2 = new BorderLayout();
226 BorderLayout borderLayout3 = new BorderLayout();
228 Panel panel4 = new Panel();
230 Panel panel5 = new Panel();
232 BorderLayout borderLayout4 = new BorderLayout();
234 private void jbInit() throws Exception
236 label1.setFont(new java.awt.Font("Verdana", 0, 11));
237 label1.setAlignment(Label.RIGHT);
238 label1.setText("Font: ");
239 this.setLayout(borderLayout4);
240 fontSize.setFont(new java.awt.Font("Verdana", 0, 11));
241 fontSize.addItemListener(this);
242 fontStyle.setFont(new java.awt.Font("Verdana", 0, 11));
243 fontStyle.addItemListener(this);
244 label2.setAlignment(Label.RIGHT);
245 label2.setFont(new java.awt.Font("Verdana", 0, 11));
246 label2.setText("Size: ");
247 label3.setAlignment(Label.RIGHT);
248 label3.setFont(new java.awt.Font("Verdana", 0, 11));
249 label3.setText("Style: ");
250 fontName.setFont(new java.awt.Font("Verdana", 0, 11));
251 fontName.addItemListener(this);
252 ok.setFont(new java.awt.Font("Verdana", 0, 11));
254 ok.addActionListener(this);
255 cancel.setFont(new java.awt.Font("Verdana", 0, 11));
256 cancel.setLabel("Cancel");
257 cancel.addActionListener(this);
258 this.setBackground(Color.white);
259 panel1.setLayout(borderLayout1);
260 panel2.setLayout(borderLayout3);
261 panel3.setLayout(borderLayout2);
262 panel5.setBackground(Color.white);
263 panel4.setBackground(Color.white);
264 panel1.setBackground(Color.white);
265 panel2.setBackground(Color.white);
266 panel3.setBackground(Color.white);
267 panel1.add(label1, BorderLayout.WEST);
268 panel1.add(fontName, BorderLayout.CENTER);
269 panel5.add(panel1, null);
270 panel5.add(panel3, null);
271 panel5.add(panel2, null);
272 panel2.add(label3, BorderLayout.WEST);
273 panel2.add(fontStyle, BorderLayout.CENTER);
274 panel3.add(label2, BorderLayout.WEST);
275 panel3.add(fontSize, BorderLayout.CENTER);
276 this.add(panel4, BorderLayout.SOUTH);
277 panel4.add(ok, null);
278 panel4.add(cancel, null);
279 this.add(panel5, BorderLayout.CENTER);