2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 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/>.
18 package jalview.appletgui;
21 import java.awt.event.*;
23 public class FontChooser extends Panel implements ActionListener,
36 public FontChooser(TreePanel tp)
47 oldFont = tp.getTreeFont();
51 public FontChooser(AlignmentPanel ap)
62 oldFont = ap.av.getFont();
68 String fonts[] = Toolkit.getDefaultToolkit().getFontList();
69 for (int i = 0; i < fonts.length; i++)
71 fontName.addItem(fonts[i]);
74 for (int i = 1; i < 31; i++)
76 fontSize.addItem(i + "");
79 fontStyle.addItem("plain");
80 fontStyle.addItem("bold");
81 fontStyle.addItem("italic");
83 fontName.select(oldFont.getName());
84 fontSize.select(oldFont.getSize() + "");
85 fontStyle.select(oldFont.getStyle());
87 Frame frame = new Frame();
90 jalview.bin.JalviewLite.addFrame(frame, "Change Font", 440, 115);
95 public void actionPerformed(ActionEvent evt)
97 if (evt.getSource() == ok)
101 else if (evt.getSource() == cancel)
103 cancel_actionPerformed();
107 public void itemStateChanged(ItemEvent evt)
109 if (evt.getSource() == fontName)
111 fontName_actionPerformed();
113 else if (evt.getSource() == fontSize)
115 fontSize_actionPerformed();
117 else if (evt.getSource() == fontStyle)
119 fontStyle_actionPerformed();
123 protected void ok_actionPerformed()
125 frame.setVisible(false);
128 if (ap.getOverviewPanel() != null)
130 ap.getOverviewPanel().updateOverviewImage();
136 protected void cancel_actionPerformed()
140 ap.av.setFont(oldFont);
141 ap.paintAlignment(true);
145 tp.setTreeFont(oldFont);
146 tp.treeCanvas.repaint();
149 fontName.select(oldFont.getName());
150 fontSize.select(oldFont.getSize() + "");
151 fontStyle.select(oldFont.getStyle());
153 frame.setVisible(false);
158 Font newFont = new Font(fontName.getSelectedItem().toString(),
159 fontStyle.getSelectedIndex(), Integer.parseInt(fontSize
160 .getSelectedItem().toString()));
163 ap.av.setFont(newFont);
168 tp.setTreeFont(newFont);
172 protected void fontName_actionPerformed()
181 protected void fontSize_actionPerformed()
190 protected void fontStyle_actionPerformed()
199 Label label1 = new Label();
201 protected Choice fontSize = new Choice();
203 protected Choice fontStyle = new Choice();
205 Label label2 = new Label();
207 Label label3 = new Label();
209 protected Choice fontName = new Choice();
211 Button ok = new Button();
213 Button cancel = new Button();
215 Panel panel1 = new Panel();
217 Panel panel2 = new Panel();
219 Panel panel3 = new Panel();
221 BorderLayout borderLayout1 = new BorderLayout();
223 BorderLayout borderLayout2 = new BorderLayout();
225 BorderLayout borderLayout3 = new BorderLayout();
227 Panel panel4 = new Panel();
229 Panel panel5 = new Panel();
231 BorderLayout borderLayout4 = new BorderLayout();
233 private void jbInit() throws Exception
235 label1.setFont(new java.awt.Font("Verdana", 0, 11));
236 label1.setAlignment(Label.RIGHT);
237 label1.setText("Font: ");
238 this.setLayout(borderLayout4);
239 fontSize.setFont(new java.awt.Font("Verdana", 0, 11));
240 fontSize.addItemListener(this);
241 fontStyle.setFont(new java.awt.Font("Verdana", 0, 11));
242 fontStyle.addItemListener(this);
243 label2.setAlignment(Label.RIGHT);
244 label2.setFont(new java.awt.Font("Verdana", 0, 11));
245 label2.setText("Size: ");
246 label3.setAlignment(Label.RIGHT);
247 label3.setFont(new java.awt.Font("Verdana", 0, 11));
248 label3.setText("Style: ");
249 fontName.setFont(new java.awt.Font("Verdana", 0, 11));
250 fontName.addItemListener(this);
251 ok.setFont(new java.awt.Font("Verdana", 0, 11));
253 ok.addActionListener(this);
254 cancel.setFont(new java.awt.Font("Verdana", 0, 11));
255 cancel.setLabel("Cancel");
256 cancel.addActionListener(this);
257 this.setBackground(Color.white);
258 panel1.setLayout(borderLayout1);
259 panel2.setLayout(borderLayout3);
260 panel3.setLayout(borderLayout2);
261 panel5.setBackground(Color.white);
262 panel4.setBackground(Color.white);
263 panel1.setBackground(Color.white);
264 panel2.setBackground(Color.white);
265 panel3.setBackground(Color.white);
266 panel1.add(label1, BorderLayout.WEST);
267 panel1.add(fontName, BorderLayout.CENTER);
268 panel5.add(panel1, null);
269 panel5.add(panel3, null);
270 panel5.add(panel2, null);
271 panel2.add(label3, BorderLayout.WEST);
272 panel2.add(fontStyle, BorderLayout.CENTER);
273 panel3.add(label2, BorderLayout.WEST);
274 panel3.add(fontSize, BorderLayout.CENTER);
275 this.add(panel4, BorderLayout.SOUTH);
276 panel4.add(ok, null);
277 panel4.add(cancel, null);
278 this.add(panel5, BorderLayout.CENTER);