JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / bin / jalview / appletgui / FontChooser.js
1 Clazz.declarePackage ("jalview.appletgui");\r
2 Clazz.load (["awt2swing.Panel", "java.awt.event.ItemListener", "awt2swing.Button", "$.Checkbox", "$.Choice", "java.awt.Font"], "jalview.appletgui.FontChooser", ["awt2swing.Frame", "$.Label", "jalview.appletgui.JVDialog", "jalview.bin.JalviewLite", "jalview.util.MessageManager", "java.awt.BorderLayout", "$.Color", "$.FlowLayout", "$.Toolkit", "java.awt.event.ActionListener"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.fontSize = null;\r
5 this.fontStyle = null;\r
6 this.fontName = null;\r
7 this.scaleAsCdna = null;\r
8 this.ok = null;\r
9 this.cancel = null;\r
10 this.ap = null;\r
11 this.tp = null;\r
12 this.oldFont = null;\r
13 this.oldCharWidth = 0;\r
14 this.oldScaleProtein = false;\r
15 this.lastSelected = null;\r
16 this.lastSelStyle = 0;\r
17 this.lastSelSize = 0;\r
18 this.$init = true;\r
19 this.frame = null;\r
20 Clazz.instantialize (this, arguments);\r
21 }, jalview.appletgui, "FontChooser", awt2swing.Panel, java.awt.event.ItemListener);\r
22 Clazz.prepareFields (c$, function () {\r
23 this.fontSize =  new awt2swing.Choice ();\r
24 this.fontStyle =  new awt2swing.Choice ();\r
25 this.fontName =  new awt2swing.Choice ();\r
26 this.scaleAsCdna =  new awt2swing.Checkbox ();\r
27 this.ok =  new awt2swing.Button ();\r
28 this.cancel =  new awt2swing.Button ();\r
29 });\r
30 Clazz.makeConstructor (c$, \r
31 function (tp) {\r
32 Clazz.superConstructor (this, jalview.appletgui.FontChooser, []);\r
33 try {\r
34 this.jbInit ();\r
35 } catch (e) {\r
36 if (Clazz.exceptionOf (e, Exception)) {\r
37 e.printStackTrace ();\r
38 } else {\r
39 throw e;\r
40 }\r
41 }\r
42 this.tp = tp;\r
43 this.oldFont = tp.getTreeFont ();\r
44 this.init ();\r
45 }, "jalview.appletgui.TreePanel");\r
46 Clazz.makeConstructor (c$, \r
47 function (ap) {\r
48 Clazz.superConstructor (this, jalview.appletgui.FontChooser, []);\r
49 this.ap = ap;\r
50 this.oldFont = ap.av.getFont ();\r
51 this.oldCharWidth = ap.av.getViewStyle ().getCharWidth ();\r
52 this.oldScaleProtein = ap.av.getViewStyle ().isScaleProteinAsCdna ();\r
53 try {\r
54 this.jbInit ();\r
55 } catch (e) {\r
56 if (Clazz.exceptionOf (e, Exception)) {\r
57 e.printStackTrace ();\r
58 } else {\r
59 throw e;\r
60 }\r
61 }\r
62 this.init ();\r
63 }, "jalview.appletgui.AlignmentPanel");\r
64 Clazz.defineMethod (c$, "init", \r
65 function () {\r
66 var fonts = java.awt.Toolkit.getDefaultToolkit ().getFontList ();\r
67 for (var i = 0; i < fonts.length; i++) {\r
68 this.fontName.addItem (fonts[i]);\r
69 }\r
70 for (var i = 1; i < 31; i++) {\r
71 this.fontSize.addItem (i + "");\r
72 }\r
73 this.fontStyle.addItem ("plain");\r
74 this.fontStyle.addItem ("bold");\r
75 this.fontStyle.addItem ("italic");\r
76 this.fontName.select (this.oldFont.getName ());\r
77 this.fontSize.select (this.oldFont.getSize () + "");\r
78 this.fontStyle.select (new Integer (this.oldFont.getStyle ()));\r
79 this.frame =  new awt2swing.Frame ();\r
80 this.frame.add (this);\r
81 jalview.bin.JalviewLite.addFrame (this.frame, jalview.util.MessageManager.getString ("action.change_font"), 440, 115);\r
82 this.$init = false;\r
83 });\r
84 Clazz.overrideMethod (c$, "itemStateChanged", \r
85 function (evt) {\r
86 var source = evt.getSource ();\r
87 if (source === this.fontName) {\r
88 this.fontName_actionPerformed ();\r
89 } else if (source === this.fontSize) {\r
90 this.fontSize_actionPerformed ();\r
91 } else if (source === this.fontStyle) {\r
92 this.fontStyle_actionPerformed ();\r
93 } else if (source === this.scaleAsCdna) {\r
94 this.scaleAsCdna_actionPerformed ();\r
95 }}, "java.awt.event.ItemEvent");\r
96 Clazz.defineMethod (c$, "ok_actionPerformed", \r
97 function () {\r
98 this.frame.setVisible (false);\r
99 if (this.ap != null) {\r
100 if (this.ap.getOverviewPanel () != null) {\r
101 this.ap.getOverviewPanel ().updateOverviewImage ();\r
102 }}});\r
103 Clazz.defineMethod (c$, "cancel_actionPerformed", \r
104 function () {\r
105 if (this.ap != null) {\r
106 this.ap.av.setScaleProteinAsCdna (this.oldScaleProtein);\r
107 if (this.ap.av.getCodingComplement () != null) {\r
108 this.ap.av.getCodingComplement ().setScaleProteinAsCdna (this.oldScaleProtein);\r
109 this.ap.alignFrame.getSplitFrame ().repaint ();\r
110 }this.ap.av.setFont (this.oldFont);\r
111 var style = this.ap.av.getViewStyle ();\r
112 if (style.getCharWidth () != this.oldCharWidth) {\r
113 style.setCharWidth (this.oldCharWidth);\r
114 this.ap.av.setViewStyle (style);\r
115 }this.ap.paintAlignment (true);\r
116 } else if (this.tp != null) {\r
117 this.tp.setTreeFont (this.oldFont);\r
118 this.tp.treeCanvas.repaint ();\r
119 }this.fontName.select (this.oldFont.getName ());\r
120 this.fontSize.select (this.oldFont.getSize () + "");\r
121 this.fontStyle.select (new Integer (this.oldFont.getStyle ()));\r
122 this.frame.setVisible (false);\r
123 });\r
124 Clazz.defineMethod (c$, "changeFont", \r
125 function () {\r
126 if (this.lastSelected == null) {\r
127 this.lastSelected = this.oldFont;\r
128 this.lastSelSize = this.oldFont.getSize ();\r
129 this.lastSelStyle = this.oldFont.getStyle ();\r
130 }var newFont =  new java.awt.Font (this.fontName.getSelectedItem ().toString (), this.fontStyle.getSelectedIndex (), Integer.parseInt (this.fontSize.getSelectedItem ().toString ()));\r
131 var fm = this.getGraphics ().getFontMetrics (newFont);\r
132 var mw = fm.getStringBounds ("M", this.getGraphics ()).getWidth ();\r
133 var iw = fm.getStringBounds ("I", this.getGraphics ()).getWidth ();\r
134 if (mw < 1 || iw < 1) {\r
135 this.fontName.select (this.lastSelected.getName ());\r
136 this.fontStyle.select (new Integer (this.lastSelStyle));\r
137 this.fontSize.select ("" + this.lastSelSize);\r
138 var d =  new jalview.appletgui.JVDialog (this.frame, jalview.util.MessageManager.getString ("label.invalid_font"), true, 350, 200);\r
139 var mp =  new awt2swing.Panel ();\r
140 d.cancel.setVisible (false);\r
141 mp.setLayout ( new java.awt.FlowLayout ());\r
142 mp.add ( new awt2swing.Label ("Font doesn't have letters defined\nso cannot be used\nwith alignment data."));\r
143 d.setMainPanel (mp);\r
144 d.setVisible (true);\r
145 return;\r
146 }if (this.tp != null) {\r
147 this.tp.setTreeFont (newFont);\r
148 } else if (this.ap != null) {\r
149 this.ap.av.setFont (newFont);\r
150 this.ap.fontChanged ();\r
151 }this.lastSelected = newFont;\r
152 });\r
153 Clazz.defineMethod (c$, "fontName_actionPerformed", \r
154 function () {\r
155 if (this.$init) {\r
156 return;\r
157 }this.changeFont ();\r
158 });\r
159 Clazz.defineMethod (c$, "fontSize_actionPerformed", \r
160 function () {\r
161 if (this.$init) {\r
162 return;\r
163 }this.changeFont ();\r
164 });\r
165 Clazz.defineMethod (c$, "fontStyle_actionPerformed", \r
166 function () {\r
167 if (this.$init) {\r
168 return;\r
169 }this.changeFont ();\r
170 });\r
171 Clazz.defineMethod (c$, "jbInit", \r
172 ($fz = function () {\r
173 this.setLayout ( new java.awt.BorderLayout ());\r
174 this.setBackground (java.awt.Color.white);\r
175 var fontLabel =  new awt2swing.Label (jalview.util.MessageManager.getString ("label.font"));\r
176 fontLabel.setFont (jalview.appletgui.FontChooser.VERDANA_11PT);\r
177 fontLabel.setAlignment (4);\r
178 this.fontSize.setFont (jalview.appletgui.FontChooser.VERDANA_11PT);\r
179 this.fontSize.addItemListener (this);\r
180 this.fontStyle.setFont (jalview.appletgui.FontChooser.VERDANA_11PT);\r
181 this.fontStyle.addItemListener (this);\r
182 var sizeLabel =  new awt2swing.Label (jalview.util.MessageManager.getString ("label.size"));\r
183 sizeLabel.setAlignment (4);\r
184 sizeLabel.setFont (jalview.appletgui.FontChooser.VERDANA_11PT);\r
185 var styleLabel =  new awt2swing.Label (jalview.util.MessageManager.getString ("label.style"));\r
186 styleLabel.setAlignment (4);\r
187 styleLabel.setFont (jalview.appletgui.FontChooser.VERDANA_11PT);\r
188 this.fontName.setFont (jalview.appletgui.FontChooser.VERDANA_11PT);\r
189 this.fontName.addItemListener (this);\r
190 this.scaleAsCdna.setLabel (jalview.util.MessageManager.getString ("label.scale_as_cdna"));\r
191 this.scaleAsCdna.setFont (jalview.appletgui.FontChooser.VERDANA_11PT);\r
192 this.scaleAsCdna.addItemListener (this);\r
193 this.scaleAsCdna.setState (this.ap.av.isScaleProteinAsCdna ());\r
194 this.ok.setFont (jalview.appletgui.FontChooser.VERDANA_11PT);\r
195 this.ok.setLabel (jalview.util.MessageManager.getString ("action.ok"));\r
196 this.ok.addActionListener (((Clazz.isClassDefined ("jalview.appletgui.FontChooser$1") ? 0 : jalview.appletgui.FontChooser.$FontChooser$1$ ()), Clazz.innerTypeInstance (jalview.appletgui.FontChooser$1, this, null)));\r
197 this.cancel.setFont (jalview.appletgui.FontChooser.VERDANA_11PT);\r
198 this.cancel.setLabel (jalview.util.MessageManager.getString ("action.cancel"));\r
199 this.cancel.addActionListener (((Clazz.isClassDefined ("jalview.appletgui.FontChooser$2") ? 0 : jalview.appletgui.FontChooser.$FontChooser$2$ ()), Clazz.innerTypeInstance (jalview.appletgui.FontChooser$2, this, null)));\r
200 var fontPanel =  new awt2swing.Panel ();\r
201 fontPanel.setLayout ( new java.awt.BorderLayout ());\r
202 var stylePanel =  new awt2swing.Panel ();\r
203 stylePanel.setLayout ( new java.awt.BorderLayout ());\r
204 var sizePanel =  new awt2swing.Panel ();\r
205 sizePanel.setLayout ( new java.awt.BorderLayout ());\r
206 var scalePanel =  new awt2swing.Panel ();\r
207 scalePanel.setLayout ( new java.awt.BorderLayout ());\r
208 var okCancelPanel =  new awt2swing.Panel ();\r
209 var optionsPanel =  new awt2swing.Panel ();\r
210 fontPanel.setBackground (java.awt.Color.white);\r
211 stylePanel.setBackground (java.awt.Color.white);\r
212 sizePanel.setBackground (java.awt.Color.white);\r
213 okCancelPanel.setBackground (java.awt.Color.white);\r
214 optionsPanel.setBackground (java.awt.Color.white);\r
215 fontPanel.add (fontLabel, "West");\r
216 fontPanel.add (this.fontName, "Center");\r
217 stylePanel.add (styleLabel, "West");\r
218 stylePanel.add (this.fontStyle, "Center");\r
219 sizePanel.add (sizeLabel, "West");\r
220 sizePanel.add (this.fontSize, "Center");\r
221 scalePanel.add (this.scaleAsCdna, "Center");\r
222 okCancelPanel.add (this.ok, null);\r
223 okCancelPanel.add (this.cancel, null);\r
224 optionsPanel.add (fontPanel, null);\r
225 optionsPanel.add (sizePanel, null);\r
226 optionsPanel.add (stylePanel, null);\r
227 this.add (optionsPanel, "North");\r
228 if (this.ap.alignFrame.getSplitFrame () != null) {\r
229 this.add (scalePanel, "Center");\r
230 }this.add (okCancelPanel, "South");\r
231 }, $fz.isPrivate = true, $fz));\r
232 Clazz.defineMethod (c$, "scaleAsCdna_actionPerformed", \r
233 function () {\r
234 this.ap.av.setScaleProteinAsCdna (this.scaleAsCdna.getState ());\r
235 this.ap.av.getCodingComplement ().setScaleProteinAsCdna (this.scaleAsCdna.getState ());\r
236 this.ap.alignFrame.getSplitFrame ().adjustLayout ();\r
237 this.ap.paintAlignment (true);\r
238 this.ap.alignFrame.getSplitFrame ().repaint ();\r
239 });\r
240 c$.$FontChooser$1$ = function () {\r
241 Clazz.pu$h ();\r
242 c$ = Clazz.declareAnonymous (jalview.appletgui, "FontChooser$1", null, java.awt.event.ActionListener);\r
243 Clazz.overrideMethod (c$, "actionPerformed", \r
244 function (e) {\r
245 this.b$["jalview.appletgui.FontChooser"].ok_actionPerformed ();\r
246 }, "java.awt.event.ActionEvent");\r
247 c$ = Clazz.p0p ();\r
248 };\r
249 c$.$FontChooser$2$ = function () {\r
250 Clazz.pu$h ();\r
251 c$ = Clazz.declareAnonymous (jalview.appletgui, "FontChooser$2", null, java.awt.event.ActionListener);\r
252 Clazz.overrideMethod (c$, "actionPerformed", \r
253 function (e) {\r
254 this.b$["jalview.appletgui.FontChooser"].cancel_actionPerformed ();\r
255 }, "java.awt.event.ActionEvent");\r
256 c$ = Clazz.p0p ();\r
257 };\r
258 c$.VERDANA_11PT = c$.prototype.VERDANA_11PT =  new java.awt.Font ("Verdana", 0, 11);\r
259 });\r