Remove redundancy in Eclipse
[jalview.git] / src / jalview / appletgui / FontChooser.java
1 /*\r
2  * Jalview - A Sequence Alignment Editor and Viewer\r
3  * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4  *\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
9  *\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
14  *\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
18  */\r
19 \r
20 package jalview.appletgui;\r
21 \r
22 import java.awt.*;\r
23 \r
24 import jalview.jbappletgui.*;\r
25 \r
26 public class FontChooser\r
27     extends GFontChooser\r
28 {\r
29   AlignmentPanel ap;\r
30   TreePanel tp;\r
31   Font oldFont;\r
32   boolean init = true;\r
33   Frame frame;\r
34 \r
35   public FontChooser(TreePanel tp)\r
36   {\r
37     this.tp = tp;\r
38     oldFont = tp.getTreeFont();\r
39     init();\r
40   }\r
41 \r
42   public FontChooser(AlignmentPanel ap)\r
43   {\r
44     this.ap = ap;\r
45     oldFont = ap.av.getFont();\r
46     init();\r
47   }\r
48 \r
49   void init()\r
50     {\r
51     String fonts[] = Toolkit.getDefaultToolkit().getFontList();\r
52     for (int i = 0; i < fonts.length; i++)\r
53     {\r
54       fontName.addItem(fonts[i]);\r
55     }\r
56 \r
57     for (int i = 1; i < 31; i++)\r
58     {\r
59       fontSize.addItem(i + "");\r
60     }\r
61 \r
62     fontStyle.addItem("plain");\r
63     fontStyle.addItem("bold");\r
64     fontStyle.addItem("italic");\r
65 \r
66     fontName.select(oldFont.getName());\r
67     fontSize.select(oldFont.getSize() + "");\r
68     fontStyle.select(oldFont.getStyle());\r
69 \r
70     Frame frame = new Frame();\r
71     this.frame = frame;\r
72     frame.add(this);\r
73     jalview.bin.JalviewLite.addFrame(frame, "Change Font", 440, 100);\r
74 \r
75     init = false;\r
76   }\r
77 \r
78   protected void ok_actionPerformed()\r
79   {\r
80     frame.setVisible(false);\r
81     if (ap != null)\r
82     {\r
83       if (ap.getOverviewPanel() != null)\r
84       {\r
85         ap.getOverviewPanel().updateOverviewImage();\r
86       }\r
87     }\r
88 \r
89   }\r
90 \r
91   protected void cancel_actionPerformed()\r
92   {\r
93     if(ap!=null)\r
94     {\r
95       ap.av.setFont(oldFont);\r
96       ap.repaint();\r
97     }\r
98     else if(tp!=null)\r
99     {\r
100       tp.setTreeFont(oldFont);\r
101       tp.treeCanvas.repaint();\r
102     }\r
103 \r
104     fontName.select(oldFont.getName());\r
105     fontSize.select(oldFont.getSize() + "");\r
106     fontStyle.select(oldFont.getStyle());\r
107 \r
108     frame.setVisible(false);\r
109   }\r
110 \r
111   void changeFont()\r
112   {\r
113     Font newFont = new Font(fontName.getSelectedItem().toString(),\r
114                             fontStyle.getSelectedIndex(),\r
115                             Integer.parseInt(fontSize.getSelectedItem().\r
116                                              toString())\r
117         );\r
118     if (ap != null)\r
119     {\r
120       ap.av.setFont(newFont);\r
121       ap.fontChanged();\r
122     }\r
123     else if(tp != null)\r
124     {\r
125       tp.setTreeFont(newFont);\r
126       }\r
127   }\r
128 \r
129   protected void fontName_actionPerformed()\r
130   {\r
131     if (init)\r
132     {\r
133       return;\r
134     }\r
135     changeFont();\r
136   }\r
137 \r
138   protected void fontSize_actionPerformed()\r
139   {\r
140     if (init)\r
141     {\r
142       return;\r
143     }\r
144     changeFont();\r
145   }\r
146 \r
147   protected void fontStyle_actionPerformed()\r
148   {\r
149     if (init)\r
150     {\r
151       return;\r
152     }\r
153     changeFont();\r
154   }\r
155 \r
156 }\r