2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 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
23 import java.awt.event.*;
\r
25 public class FontChooser
\r
26 extends Panel implements ActionListener, ItemListener
\r
31 boolean init = true;
\r
34 public FontChooser(TreePanel tp)
\r
42 e.printStackTrace();
\r
46 oldFont = tp.getTreeFont();
\r
50 public FontChooser(AlignmentPanel ap)
\r
58 e.printStackTrace();
\r
62 oldFont = ap.av.getFont();
\r
68 String fonts[] = Toolkit.getDefaultToolkit().getFontList();
\r
69 for (int i = 0; i < fonts.length; i++)
\r
71 fontName.addItem(fonts[i]);
\r
74 for (int i = 1; i < 31; i++)
\r
76 fontSize.addItem(i + "");
\r
79 fontStyle.addItem("plain");
\r
80 fontStyle.addItem("bold");
\r
81 fontStyle.addItem("italic");
\r
83 fontName.select(oldFont.getName());
\r
84 fontSize.select(oldFont.getSize() + "");
\r
85 fontStyle.select(oldFont.getStyle());
\r
87 Frame frame = new Frame();
\r
90 jalview.bin.JalviewLite.addFrame(frame, "Change Font", 440, 115);
\r
95 public void actionPerformed(ActionEvent evt)
\r
97 if (evt.getSource() == ok)
\r
99 ok_actionPerformed();
\r
101 else if (evt.getSource() == cancel)
\r
103 cancel_actionPerformed();
\r
107 public void itemStateChanged(ItemEvent evt)
\r
109 if (evt.getSource() == fontName)
\r
111 fontName_actionPerformed();
\r
113 else if (evt.getSource() == fontSize)
\r
115 fontSize_actionPerformed();
\r
117 else if (evt.getSource() == fontStyle)
\r
119 fontStyle_actionPerformed();
\r
123 protected void ok_actionPerformed()
\r
125 frame.setVisible(false);
\r
128 if (ap.getOverviewPanel() != null)
\r
130 ap.getOverviewPanel().updateOverviewImage();
\r
136 protected void cancel_actionPerformed()
\r
140 ap.av.setFont(oldFont);
\r
143 else if (tp != null)
\r
145 tp.setTreeFont(oldFont);
\r
146 tp.treeCanvas.repaint();
\r
149 fontName.select(oldFont.getName());
\r
150 fontSize.select(oldFont.getSize() + "");
\r
151 fontStyle.select(oldFont.getStyle());
\r
153 frame.setVisible(false);
\r
158 Font newFont = new Font(fontName.getSelectedItem().toString(),
\r
159 fontStyle.getSelectedIndex(),
\r
160 Integer.parseInt(fontSize.getSelectedItem().
\r
165 ap.av.setFont(newFont);
\r
168 else if (tp != null)
\r
170 tp.setTreeFont(newFont);
\r
174 protected void fontName_actionPerformed()
\r
183 protected void fontSize_actionPerformed()
\r
192 protected void fontStyle_actionPerformed()
\r
201 Label label1 = new Label();
\r
202 protected Choice fontSize = new Choice();
\r
203 protected Choice fontStyle = new Choice();
\r
204 Label label2 = new Label();
\r
205 Label label3 = new Label();
\r
206 protected Choice fontName = new Choice();
\r
207 Button ok = new Button();
\r
208 Button cancel = new Button();
\r
209 Panel panel1 = new Panel();
\r
210 Panel panel2 = new Panel();
\r
211 Panel panel3 = new Panel();
\r
212 BorderLayout borderLayout1 = new BorderLayout();
\r
213 BorderLayout borderLayout2 = new BorderLayout();
\r
214 BorderLayout borderLayout3 = new BorderLayout();
\r
215 Panel panel4 = new Panel();
\r
216 Panel panel5 = new Panel();
\r
217 BorderLayout borderLayout4 = new BorderLayout();
\r
219 private void jbInit()
\r
222 label1.setFont(new java.awt.Font("Verdana", 0, 11));
\r
223 label1.setAlignment(Label.RIGHT);
\r
224 label1.setText("Font: ");
\r
225 this.setLayout(borderLayout4);
\r
226 fontSize.setFont(new java.awt.Font("Verdana", 0, 11));
\r
227 fontSize.addItemListener(this);
\r
228 fontStyle.setFont(new java.awt.Font("Verdana", 0, 11));
\r
229 fontStyle.addItemListener(this);
\r
230 label2.setAlignment(Label.RIGHT);
\r
231 label2.setFont(new java.awt.Font("Verdana", 0, 11));
\r
232 label2.setText("Size: ");
\r
233 label3.setAlignment(Label.RIGHT);
\r
234 label3.setFont(new java.awt.Font("Verdana", 0, 11));
\r
235 label3.setText("Style: ");
\r
236 fontName.setFont(new java.awt.Font("Verdana", 0, 11));
\r
237 fontName.addItemListener(this);
\r
238 ok.setFont(new java.awt.Font("Verdana", 0, 11));
\r
240 ok.addActionListener(this);
\r
241 cancel.setFont(new java.awt.Font("Verdana", 0, 11));
\r
242 cancel.setLabel("Cancel");
\r
243 cancel.addActionListener(this);
\r
244 this.setBackground(Color.white);
\r
245 panel1.setLayout(borderLayout1);
\r
246 panel2.setLayout(borderLayout3);
\r
247 panel3.setLayout(borderLayout2);
\r
248 panel5.setBackground(Color.white);
\r
249 panel4.setBackground(Color.white);
\r
250 panel1.setBackground(Color.white);
\r
251 panel2.setBackground(Color.white);
\r
252 panel3.setBackground(Color.white);
\r
253 panel1.add(label1, BorderLayout.WEST);
\r
254 panel1.add(fontName, BorderLayout.CENTER);
\r
255 panel5.add(panel1, null);
\r
256 panel5.add(panel3, null);
\r
257 panel5.add(panel2, null);
\r
258 panel2.add(label3, BorderLayout.WEST);
\r
259 panel2.add(fontStyle, BorderLayout.CENTER);
\r
260 panel3.add(label2, BorderLayout.WEST);
\r
261 panel3.add(fontSize, BorderLayout.CENTER);
\r
262 this.add(panel4, BorderLayout.SOUTH);
\r
263 panel4.add(ok, null);
\r
264 panel4.add(cancel, null);
\r
265 this.add(panel5, BorderLayout.CENTER);
\r