2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2b1)
3 * Copyright (C) 2014 The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.appletgui;
23 import jalview.util.MessageManager;
26 import java.awt.event.*;
28 public class FontChooser extends Panel implements ActionListener,
41 public FontChooser(TreePanel tp)
52 oldFont = tp.getTreeFont();
56 public FontChooser(AlignmentPanel ap)
67 oldFont = ap.av.getFont();
73 String fonts[] = Toolkit.getDefaultToolkit().getFontList();
74 for (int i = 0; i < fonts.length; i++)
76 fontName.addItem(fonts[i]);
79 for (int i = 1; i < 31; i++)
81 fontSize.addItem(i + "");
84 fontStyle.addItem("plain");
85 fontStyle.addItem("bold");
86 fontStyle.addItem("italic");
88 fontName.select(oldFont.getName());
89 fontSize.select(oldFont.getSize() + "");
90 fontStyle.select(oldFont.getStyle());
92 Frame frame = new Frame();
95 jalview.bin.JalviewLite.addFrame(frame,
96 MessageManager.getString("action.change_font"), 440, 115);
101 public void actionPerformed(ActionEvent evt)
103 if (evt.getSource() == ok)
105 ok_actionPerformed();
107 else if (evt.getSource() == cancel)
109 cancel_actionPerformed();
113 public void itemStateChanged(ItemEvent evt)
115 if (evt.getSource() == fontName)
117 fontName_actionPerformed();
119 else if (evt.getSource() == fontSize)
121 fontSize_actionPerformed();
123 else if (evt.getSource() == fontStyle)
125 fontStyle_actionPerformed();
129 protected void ok_actionPerformed()
131 frame.setVisible(false);
134 if (ap.getOverviewPanel() != null)
136 ap.getOverviewPanel().updateOverviewImage();
142 protected void cancel_actionPerformed()
146 ap.av.setFont(oldFont);
147 ap.paintAlignment(true);
151 tp.setTreeFont(oldFont);
152 tp.treeCanvas.repaint();
155 fontName.select(oldFont.getName());
156 fontSize.select(oldFont.getSize() + "");
157 fontStyle.select(oldFont.getStyle());
159 frame.setVisible(false);
162 private Font lastSelected = null;
164 private int lastSelStyle = 0;
166 private int lastSelSize = 0;
173 if (lastSelected == null)
175 // initialise with original font
176 lastSelected = oldFont;
177 lastSelSize = oldFont.getSize();
178 lastSelStyle = oldFont.getStyle();
181 Font newFont = new Font(fontName.getSelectedItem().toString(),
182 fontStyle.getSelectedIndex(), Integer.parseInt(fontSize
183 .getSelectedItem().toString()));
184 FontMetrics fm = getGraphics().getFontMetrics(newFont);
185 double mw = fm.getStringBounds("M", getGraphics()).getWidth(), iw = fm
186 .getStringBounds("I", getGraphics()).getWidth();
187 if (mw < 1 || iw < 1)
190 fontName.select(lastSelected.getName());
191 fontStyle.select(lastSelStyle);
192 fontSize.select("" + lastSelSize);
193 JVDialog d = new JVDialog(this.frame,
194 MessageManager.getString("label.invalid_font"), true, 350,
196 Panel mp = new Panel();
197 d.cancel.setVisible(false);
198 mp.setLayout(new FlowLayout());
200 "Font doesn't have letters defined\nso cannot be used\nwith alignment data."));
207 tp.setTreeFont(newFont);
211 ap.av.setFont(newFont);
214 // remember last selected
215 lastSelected = newFont;
218 protected void fontName_actionPerformed()
227 protected void fontSize_actionPerformed()
236 protected void fontStyle_actionPerformed()
245 Label label1 = new Label();
247 protected Choice fontSize = new Choice();
249 protected Choice fontStyle = new Choice();
251 Label label2 = new Label();
253 Label label3 = new Label();
255 protected Choice fontName = new Choice();
257 Button ok = new Button();
259 Button cancel = new Button();
261 Panel panel1 = new Panel();
263 Panel panel2 = new Panel();
265 Panel panel3 = new Panel();
267 BorderLayout borderLayout1 = new BorderLayout();
269 BorderLayout borderLayout2 = new BorderLayout();
271 BorderLayout borderLayout3 = new BorderLayout();
273 Panel panel4 = new Panel();
275 Panel panel5 = new Panel();
277 BorderLayout borderLayout4 = new BorderLayout();
279 private void jbInit() throws Exception
281 label1.setFont(new java.awt.Font("Verdana", 0, 11));
282 label1.setAlignment(Label.RIGHT);
283 label1.setText(MessageManager.getString("label.font"));
284 this.setLayout(borderLayout4);
285 fontSize.setFont(new java.awt.Font("Verdana", 0, 11));
286 fontSize.addItemListener(this);
287 fontStyle.setFont(new java.awt.Font("Verdana", 0, 11));
288 fontStyle.addItemListener(this);
289 label2.setAlignment(Label.RIGHT);
290 label2.setFont(new java.awt.Font("Verdana", 0, 11));
291 label2.setText(MessageManager.getString("label.size"));
292 label3.setAlignment(Label.RIGHT);
293 label3.setFont(new java.awt.Font("Verdana", 0, 11));
294 label3.setText(MessageManager.getString("label.style"));
295 fontName.setFont(new java.awt.Font("Verdana", 0, 11));
296 fontName.addItemListener(this);
297 ok.setFont(new java.awt.Font("Verdana", 0, 11));
298 ok.setLabel(MessageManager.getString("action.ok"));
299 ok.addActionListener(this);
300 cancel.setFont(new java.awt.Font("Verdana", 0, 11));
301 cancel.setLabel(MessageManager.getString("action.cancel"));
302 cancel.addActionListener(this);
303 this.setBackground(Color.white);
304 panel1.setLayout(borderLayout1);
305 panel2.setLayout(borderLayout3);
306 panel3.setLayout(borderLayout2);
307 panel5.setBackground(Color.white);
308 panel4.setBackground(Color.white);
309 panel1.setBackground(Color.white);
310 panel2.setBackground(Color.white);
311 panel3.setBackground(Color.white);
312 panel1.add(label1, BorderLayout.WEST);
313 panel1.add(fontName, BorderLayout.CENTER);
314 panel5.add(panel1, null);
315 panel5.add(panel3, null);
316 panel5.add(panel2, null);
317 panel2.add(label3, BorderLayout.WEST);
318 panel2.add(fontStyle, BorderLayout.CENTER);
319 panel3.add(label2, BorderLayout.WEST);
320 panel3.add(fontSize, BorderLayout.CENTER);
321 this.add(panel4, BorderLayout.SOUTH);
322 panel4.add(ok, null);
323 panel4.add(cancel, null);
324 this.add(panel5, BorderLayout.CENTER);