2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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
20 package jalview.appletgui;
\r
24 import java.awt.event.*;
\r
26 public class FontChooser
\r
27 extends Panel implements ActionListener, ItemListener
\r
32 boolean init = true;
\r
35 public FontChooser(TreePanel tp)
\r
43 e.printStackTrace();
\r
47 oldFont = tp.getTreeFont();
\r
51 public FontChooser(AlignmentPanel ap)
\r
59 e.printStackTrace();
\r
63 oldFont = ap.av.getFont();
\r
69 String fonts[] = Toolkit.getDefaultToolkit().getFontList();
\r
70 for (int i = 0; i < fonts.length; i++)
\r
72 fontName.addItem(fonts[i]);
\r
75 for (int i = 1; i < 31; i++)
\r
77 fontSize.addItem(i + "");
\r
80 fontStyle.addItem("plain");
\r
81 fontStyle.addItem("bold");
\r
82 fontStyle.addItem("italic");
\r
84 fontName.select(oldFont.getName());
\r
85 fontSize.select(oldFont.getSize() + "");
\r
86 fontStyle.select(oldFont.getStyle());
\r
88 Frame frame = new Frame();
\r
91 jalview.bin.JalviewLite.addFrame(frame, "Change Font", 440, 115);
\r
96 public void actionPerformed(ActionEvent evt)
\r
98 if(evt.getSource()==ok)
\r
99 ok_actionPerformed();
\r
100 else if(evt.getSource()==cancel)
\r
101 cancel_actionPerformed();
\r
104 public void itemStateChanged(ItemEvent evt)
\r
106 if(evt.getSource()==fontName)
\r
107 fontName_actionPerformed();
\r
108 else if(evt.getSource()==fontSize)
\r
109 fontSize_actionPerformed();
\r
110 else if(evt.getSource()==fontStyle)
\r
111 fontStyle_actionPerformed();
\r
115 protected void ok_actionPerformed()
\r
117 frame.setVisible(false);
\r
120 if (ap.getOverviewPanel() != null)
\r
122 ap.getOverviewPanel().updateOverviewImage();
\r
128 protected void cancel_actionPerformed()
\r
132 ap.av.setFont(oldFont);
\r
137 tp.setTreeFont(oldFont);
\r
138 tp.treeCanvas.repaint();
\r
141 fontName.select(oldFont.getName());
\r
142 fontSize.select(oldFont.getSize() + "");
\r
143 fontStyle.select(oldFont.getStyle());
\r
145 frame.setVisible(false);
\r
150 Font newFont = new Font(fontName.getSelectedItem().toString(),
\r
151 fontStyle.getSelectedIndex(),
\r
152 Integer.parseInt(fontSize.getSelectedItem().
\r
157 ap.av.setFont(newFont);
\r
160 else if(tp != null)
\r
162 tp.setTreeFont(newFont);
\r
166 protected void fontName_actionPerformed()
\r
175 protected void fontSize_actionPerformed()
\r
184 protected void fontStyle_actionPerformed()
\r
192 Label label1 = new Label();
\r
193 protected Choice fontSize = new Choice();
\r
194 protected Choice fontStyle = new Choice();
\r
195 Label label2 = new Label();
\r
196 Label label3 = new Label();
\r
197 protected Choice fontName = new Choice();
\r
198 Button ok = new Button();
\r
199 Button cancel = new Button();
\r
200 Panel panel1 = new Panel();
\r
201 Panel panel2 = new Panel();
\r
202 Panel panel3 = new Panel();
\r
203 BorderLayout borderLayout1 = new BorderLayout();
\r
204 BorderLayout borderLayout2 = new BorderLayout();
\r
205 BorderLayout borderLayout3 = new BorderLayout();
\r
206 Panel panel4 = new Panel();
\r
207 Panel panel5 = new Panel();
\r
208 BorderLayout borderLayout4 = new BorderLayout();
\r
211 private void jbInit() throws Exception {
\r
212 label1.setFont(new java.awt.Font("Verdana", 0, 11));
\r
213 label1.setAlignment(Label.RIGHT);
\r
214 label1.setText("Font: ");
\r
215 this.setLayout(borderLayout4);
\r
216 fontSize.setFont(new java.awt.Font("Verdana", 0, 11));
\r
217 fontSize.addItemListener(this);
\r
218 fontStyle.setFont(new java.awt.Font("Verdana", 0, 11));
\r
219 fontStyle.addItemListener(this);
\r
220 label2.setAlignment(Label.RIGHT);
\r
221 label2.setFont(new java.awt.Font("Verdana", 0, 11));
\r
222 label2.setText("Size: ");
\r
223 label3.setAlignment(Label.RIGHT);
\r
224 label3.setFont(new java.awt.Font("Verdana", 0, 11));
\r
225 label3.setText("Style: ");
\r
226 fontName.setFont(new java.awt.Font("Verdana", 0, 11));
\r
227 fontName.addItemListener(this);
\r
228 ok.setFont(new java.awt.Font("Verdana", 0, 11));
\r
230 ok.addActionListener(this);
\r
231 cancel.setFont(new java.awt.Font("Verdana", 0, 11));
\r
232 cancel.setLabel("Cancel");
\r
233 cancel.addActionListener(this);
\r
234 this.setBackground(Color.white);
\r
235 panel1.setLayout(borderLayout1);
\r
236 panel2.setLayout(borderLayout3);
\r
237 panel3.setLayout(borderLayout2);
\r
238 panel5.setBackground(Color.white);
\r
239 panel4.setBackground(Color.white);
\r
240 panel1.setBackground(Color.white);
\r
241 panel2.setBackground(Color.white);
\r
242 panel3.setBackground(Color.white);
\r
243 panel1.add(label1, BorderLayout.WEST);
\r
244 panel1.add(fontName, BorderLayout.CENTER);
\r
245 panel5.add(panel1, null);
\r
246 panel5.add(panel3, null);
\r
247 panel5.add(panel2, null);
\r
248 panel2.add(label3, BorderLayout.WEST);
\r
249 panel2.add(fontStyle, BorderLayout.CENTER);
\r
250 panel3.add(label2, BorderLayout.WEST);
\r
251 panel3.add(fontSize, BorderLayout.CENTER);
\r
252 this.add(panel4, BorderLayout.SOUTH);
\r
253 panel4.add(ok, null);
\r
254 panel4.add(cancel, null);
\r
255 this.add(panel5, BorderLayout.CENTER);
\r