JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / bin / jalview / appletgui / AnnotationColourChooser.js
1 Clazz.declarePackage ("jalview.appletgui");\r
2 Clazz.load (["awt2swing.Panel", "java.awt.event.ActionListener", "$.AdjustmentListener", "$.ItemListener", "$.MouseListener", "awt2swing.Button", "$.Checkbox", "$.Choice", "$.Scrollbar", "$.TextField", "java.awt.BorderLayout", "$.FlowLayout"], "jalview.appletgui.AnnotationColourChooser", ["awt2swing.Frame", "jalview.appletgui.UserDefinedColours", "jalview.bin.JalviewLite", "jalview.datamodel.GraphLine", "jalview.schemes.AnnotationColourGradient", "$.ColourSchemeI", "jalview.util.MessageManager", "java.awt.Color", "$.Dimension", "$.Font", "java.lang.Error", "$.Float", "java.util.Hashtable", "$.Vector"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.frame = null;\r
5 this.av = null;\r
6 this.ap = null;\r
7 this.oldcs = null;\r
8 this.oldgroupColours = null;\r
9 this.currentAnnotation = null;\r
10 this.adjusting = false;\r
11 this.annotations = null;\r
12 this.minColour = null;\r
13 this.maxColour = null;\r
14 this.ok = null;\r
15 this.cancel = null;\r
16 this.defColours = null;\r
17 this.jPanel1 = null;\r
18 this.jPanel2 = null;\r
19 this.threshold = null;\r
20 this.flowLayout1 = null;\r
21 this.jPanel3 = null;\r
22 this.slider = null;\r
23 this.thresholdValue = null;\r
24 this.currentColours = null;\r
25 this.borderLayout1 = null;\r
26 this.thresholdIsMin = null;\r
27 Clazz.instantialize (this, arguments);\r
28 }, jalview.appletgui, "AnnotationColourChooser", awt2swing.Panel, [java.awt.event.ActionListener, java.awt.event.AdjustmentListener, java.awt.event.ItemListener, java.awt.event.MouseListener]);\r
29 Clazz.prepareFields (c$, function () {\r
30 this.annotations =  new awt2swing.Choice ();\r
31 this.minColour =  new awt2swing.Button ();\r
32 this.maxColour =  new awt2swing.Button ();\r
33 this.ok =  new awt2swing.Button ();\r
34 this.cancel =  new awt2swing.Button ();\r
35 this.defColours =  new awt2swing.Button ();\r
36 this.jPanel1 =  new awt2swing.Panel ();\r
37 this.jPanel2 =  new awt2swing.Panel ();\r
38 this.threshold =  new awt2swing.Choice ();\r
39 this.flowLayout1 =  new java.awt.FlowLayout ();\r
40 this.jPanel3 =  new awt2swing.Panel ();\r
41 this.slider =  new awt2swing.Scrollbar (0);\r
42 this.thresholdValue =  new awt2swing.TextField (20);\r
43 this.currentColours =  new awt2swing.Checkbox ();\r
44 this.borderLayout1 =  new java.awt.BorderLayout ();\r
45 this.thresholdIsMin =  new awt2swing.Checkbox ();\r
46 });\r
47 Clazz.makeConstructor (c$, \r
48 function (av, ap) {\r
49 Clazz.superConstructor (this, jalview.appletgui.AnnotationColourChooser, []);\r
50 try {\r
51 this.jbInit ();\r
52 } catch (ex) {\r
53 if (Clazz.exceptionOf (ex, Exception)) {\r
54 } else {\r
55 throw ex;\r
56 }\r
57 }\r
58 this.oldcs = av.getGlobalColourScheme ();\r
59 if (av.getAlignment ().getGroups () != null) {\r
60 this.oldgroupColours =  new java.util.Hashtable ();\r
61 for (var sg, $sg = ap.av.getAlignment ().getGroups ().iterator (); $sg.hasNext () && ((sg = $sg.next ()) || true);) {\r
62 if (sg.cs != null) {\r
63 this.oldgroupColours.put (sg, sg.cs);\r
64 } else {\r
65 this.oldgroupColours.put (sg, "null");\r
66 }}\r
67 }this.av = av;\r
68 this.ap = ap;\r
69 this.slider.addAdjustmentListener (this);\r
70 this.slider.addMouseListener (this);\r
71 if (av.getAlignment ().getAlignmentAnnotation () == null) {\r
72 return;\r
73 }this.setDefaultMinMax ();\r
74 this.adjusting = true;\r
75 if (Clazz.instanceOf (this.oldcs, jalview.schemes.AnnotationColourGradient)) {\r
76 var acg = this.oldcs;\r
77 this.currentColours.setState (acg.isPredefinedColours () || acg.getBaseColour () != null);\r
78 if (!acg.isPredefinedColours () && acg.getBaseColour () == null) {\r
79 this.minColour.setBackground (acg.getMinColour ());\r
80 this.maxColour.setBackground (acg.getMaxColour ());\r
81 }}var list =  new java.util.Vector ();\r
82 var index = 1;\r
83 for (var i = 0; i < av.getAlignment ().getAlignmentAnnotation ().length; i++) {\r
84 var label = av.getAlignment ().getAlignmentAnnotation ()[i].label;\r
85 if (!list.contains (label)) {\r
86 list.addElement (label);\r
87 } else {\r
88 list.addElement (label + "_" + (index++));\r
89 }}\r
90 for (var i = 0; i < list.size (); i++) {\r
91 this.annotations.addItem (list.elementAt (i).toString ());\r
92 }\r
93 this.threshold.addItem (jalview.util.MessageManager.getString ("label.threshold_feature_no_thereshold"));\r
94 this.threshold.addItem (jalview.util.MessageManager.getString ("label.threshold_feature_above_thereshold"));\r
95 this.threshold.addItem (jalview.util.MessageManager.getString ("label.threshold_feature_below_thereshold"));\r
96 if (Clazz.instanceOf (this.oldcs, jalview.schemes.AnnotationColourGradient)) {\r
97 var acg = this.oldcs;\r
98 this.annotations.select (acg.getAnnotation ());\r
99 switch (acg.getAboveThreshold ()) {\r
100 case -1:\r
101 this.threshold.select (new Integer (0));\r
102 break;\r
103 case 1:\r
104 this.threshold.select (new Integer (1));\r
105 break;\r
106 case 0:\r
107 this.threshold.select (new Integer (1));\r
108 break;\r
109 default:\r
110 throw  new Error (jalview.util.MessageManager.getString ("error.implementation_error_dont_know_thereshold_annotationcolourgradient"));\r
111 }\r
112 this.thresholdIsMin.setState (acg.thresholdIsMinMax);\r
113 this.thresholdValue.setText ("" + acg.getAnnotationThreshold ());\r
114 }this.adjusting = false;\r
115 this.changeColour ();\r
116 this.frame =  new awt2swing.Frame ();\r
117 this.frame.add (this);\r
118 jalview.bin.JalviewLite.addFrame (this.frame, jalview.util.MessageManager.getString ("label.colour_by_annotation"), 560, 175);\r
119 this.validate ();\r
120 }, "jalview.appletgui.AlignViewport,jalview.appletgui.AlignmentPanel");\r
121 Clazz.defineMethod (c$, "setDefaultMinMax", \r
122 ($fz = function () {\r
123 this.minColour.setBackground (this.av.applet.getDefaultColourParameter ("ANNOTATIONCOLOUR_MIN", java.awt.Color.orange));\r
124 this.maxColour.setBackground (this.av.applet.getDefaultColourParameter ("ANNOTATIONCOLOUR_MAX", java.awt.Color.red));\r
125 }, $fz.isPrivate = true, $fz));\r
126 Clazz.makeConstructor (c$, \r
127 function () {\r
128 Clazz.superConstructor (this, jalview.appletgui.AnnotationColourChooser, []);\r
129 try {\r
130 this.jbInit ();\r
131 } catch (ex) {\r
132 if (Clazz.exceptionOf (ex, Exception)) {\r
133 ex.printStackTrace ();\r
134 } else {\r
135 throw ex;\r
136 }\r
137 }\r
138 });\r
139 Clazz.defineMethod (c$, "jbInit", \r
140 ($fz = function () {\r
141 this.minColour.setFont ( new java.awt.Font ("Verdana", 0, 11));\r
142 this.minColour.setLabel (jalview.util.MessageManager.getString ("label.min_colour"));\r
143 this.minColour.addActionListener (this);\r
144 this.maxColour.setFont ( new java.awt.Font ("Verdana", 0, 11));\r
145 this.maxColour.setLabel (jalview.util.MessageManager.getString ("label.max_colour"));\r
146 this.maxColour.addActionListener (this);\r
147 this.thresholdIsMin.addItemListener (this);\r
148 this.ok.setLabel (jalview.util.MessageManager.getString ("action.ok"));\r
149 this.ok.addActionListener (this);\r
150 this.cancel.setLabel (jalview.util.MessageManager.getString ("action.cancel"));\r
151 this.cancel.addActionListener (this);\r
152 this.defColours.setLabel (jalview.util.MessageManager.getString ("action.set_defaults"));\r
153 this.defColours.addActionListener (this);\r
154 this.annotations.addItemListener (this);\r
155 this.thresholdValue.addActionListener (this);\r
156 this.slider.setBackground (java.awt.Color.white);\r
157 this.slider.setPreferredSize ( new java.awt.Dimension (193, 21));\r
158 this.slider.setEnabled (false);\r
159 this.thresholdValue.setPreferredSize ( new java.awt.Dimension (79, 22));\r
160 this.thresholdValue.setEnabled (false);\r
161 this.thresholdValue.setColumns (5);\r
162 this.currentColours.setFont ( new java.awt.Font ("Verdana", 0, 11));\r
163 this.currentColours.setLabel (jalview.util.MessageManager.getString ("label.use_original_colours"));\r
164 this.currentColours.addItemListener (this);\r
165 this.thresholdIsMin.setBackground (java.awt.Color.white);\r
166 this.thresholdIsMin.setLabel (jalview.util.MessageManager.getString ("label.threshold_minmax"));\r
167 this.setLayout (this.borderLayout1);\r
168 this.jPanel1.setBackground (java.awt.Color.white);\r
169 this.jPanel2.setLayout ( new java.awt.FlowLayout ());\r
170 this.jPanel2.setBackground (java.awt.Color.white);\r
171 this.threshold.addItemListener (this);\r
172 this.jPanel3.setLayout ( new java.awt.FlowLayout ());\r
173 this.jPanel3.setBackground (java.awt.Color.white);\r
174 var jPanel4 =  new awt2swing.Panel ();\r
175 jPanel4.setLayout ( new java.awt.BorderLayout ());\r
176 jPanel4.setBackground (java.awt.Color.white);\r
177 this.jPanel1.add (this.ok);\r
178 this.jPanel1.add (this.cancel);\r
179 this.jPanel2.add (this.annotations);\r
180 this.jPanel2.add (this.currentColours);\r
181 this.jPanel2.add (this.minColour);\r
182 this.jPanel2.add (this.maxColour);\r
183 jPanel4.add (this.thresholdIsMin, "West");\r
184 jPanel4.add (this.slider, "Center");\r
185 jPanel4.add (this.thresholdValue, "East");\r
186 var jPanel34 =  new awt2swing.Panel ();\r
187 jPanel34.setLayout ( new java.awt.BorderLayout ());\r
188 jPanel34.setBackground (java.awt.Color.white);\r
189 jPanel34.add (this.jPanel2, "North");\r
190 jPanel34.add (this.threshold, "West");\r
191 this.jPanel3.add (this.defColours);\r
192 jPanel34.add (this.jPanel3, "East");\r
193 jPanel34.add (jPanel4, "South");\r
194 this.add (jPanel34, "Center");\r
195 this.add (this.jPanel1, "South");\r
196 }, $fz.isPrivate = true, $fz));\r
197 Clazz.overrideMethod (c$, "actionPerformed", \r
198 function (evt) {\r
199 if (evt.getSource () === this.thresholdValue) {\r
200 try {\r
201 var f =  new Float (this.thresholdValue.getText ()).floatValue ();\r
202 this.slider.setValue (Clazz.floatToInt (f * 1000));\r
203 this.adjustmentValueChanged (null);\r
204 } catch (ex) {\r
205 if (Clazz.exceptionOf (ex, NumberFormatException)) {\r
206 } else {\r
207 throw ex;\r
208 }\r
209 }\r
210 } else if (evt.getSource () === this.minColour) {\r
211 this.minColour_actionPerformed (null);\r
212 } else if (evt.getSource () === this.maxColour) {\r
213 this.maxColour_actionPerformed (null);\r
214 } else if (evt.getSource () === this.defColours) {\r
215 this.defColour_actionPerformed ();\r
216 } else if (evt.getSource () === this.ok) {\r
217 this.changeColour ();\r
218 this.frame.setVisible (false);\r
219 } else if (evt.getSource () === this.cancel) {\r
220 this.reset ();\r
221 this.ap.paintAlignment (true);\r
222 this.frame.setVisible (false);\r
223 } else {\r
224 this.changeColour ();\r
225 }}, "java.awt.event.ActionEvent");\r
226 Clazz.overrideMethod (c$, "itemStateChanged", \r
227 function (evt) {\r
228 if (evt.getSource () === this.currentColours) {\r
229 if (this.currentColours.getState ()) {\r
230 this.reset ();\r
231 }this.maxColour.setEnabled (!this.currentColours.getState ());\r
232 this.minColour.setEnabled (!this.currentColours.getState ());\r
233 }this.changeColour ();\r
234 }, "java.awt.event.ItemEvent");\r
235 Clazz.overrideMethod (c$, "adjustmentValueChanged", \r
236 function (evt) {\r
237 if (!this.adjusting) {\r
238 this.thresholdValue.setText ((this.slider.getValue () / 1000) + "");\r
239 if (this.currentColours.getState () && !(Clazz.instanceOf (this.av.getGlobalColourScheme (), jalview.schemes.AnnotationColourGradient))) {\r
240 this.changeColour ();\r
241 }this.currentAnnotation.threshold.value = this.slider.getValue () / 1000;\r
242 this.ap.paintAlignment (false);\r
243 }}, "java.awt.event.AdjustmentEvent");\r
244 Clazz.defineMethod (c$, "minColour_actionPerformed", \r
245 function (newCol) {\r
246 if (newCol != null) {\r
247 this.minColour.setBackground (newCol);\r
248 this.minColour.repaint ();\r
249 this.changeColour ();\r
250 } else {\r
251  new jalview.appletgui.UserDefinedColours (this, "Min Colour", this.minColour.getBackground ());\r
252 }}, "java.awt.Color");\r
253 Clazz.defineMethod (c$, "maxColour_actionPerformed", \r
254 function (newCol) {\r
255 if (newCol != null) {\r
256 this.maxColour.setBackground (newCol);\r
257 this.maxColour.repaint ();\r
258 this.changeColour ();\r
259 } else {\r
260  new jalview.appletgui.UserDefinedColours (this, "Max Colour", this.maxColour.getBackground ());\r
261 }}, "java.awt.Color");\r
262 Clazz.defineMethod (c$, "defColour_actionPerformed", \r
263 function () {\r
264 this.setDefaultMinMax ();\r
265 this.minColour.repaint ();\r
266 this.maxColour.repaint ();\r
267 this.changeColour ();\r
268 });\r
269 Clazz.defineMethod (c$, "changeColour", \r
270 function () {\r
271 if (this.adjusting) {\r
272 return;\r
273 }this.currentAnnotation = this.av.getAlignment ().getAlignmentAnnotation ()[this.annotations.getSelectedIndex ()];\r
274 var aboveThreshold = -1;\r
275 if (this.threshold.getSelectedIndex () == 1) {\r
276 aboveThreshold = 1;\r
277 } else if (this.threshold.getSelectedIndex () == 2) {\r
278 aboveThreshold = 0;\r
279 }this.slider.setEnabled (true);\r
280 this.thresholdValue.setEnabled (true);\r
281 this.thresholdIsMin.setEnabled (true);\r
282 if (aboveThreshold == -1) {\r
283 this.slider.setEnabled (false);\r
284 this.thresholdValue.setEnabled (false);\r
285 this.thresholdIsMin.setEnabled (false);\r
286 this.thresholdValue.setText ("");\r
287 } else if (aboveThreshold != -1 && this.currentAnnotation.threshold == null) {\r
288 this.currentAnnotation.setThreshold ( new jalview.datamodel.GraphLine ((this.currentAnnotation.graphMax - this.currentAnnotation.graphMin) / 2, "Threshold", java.awt.Color.black));\r
289 }if (aboveThreshold != -1) {\r
290 this.adjusting = true;\r
291 this.slider.setMinimum (Clazz.floatToInt (this.currentAnnotation.graphMin * 1000));\r
292 this.slider.setMaximum (Clazz.floatToInt (this.currentAnnotation.graphMax * 1000));\r
293 this.slider.setValue (Clazz.floatToInt (this.currentAnnotation.threshold.value * 1000));\r
294 this.thresholdValue.setText (this.currentAnnotation.threshold.value + "");\r
295 this.slider.setEnabled (true);\r
296 this.thresholdValue.setEnabled (true);\r
297 this.adjusting = false;\r
298 }var acg = null;\r
299 if (this.currentColours.getState ()) {\r
300 acg =  new jalview.schemes.AnnotationColourGradient (this.currentAnnotation, this.av.getGlobalColourScheme (), aboveThreshold);\r
301 } else {\r
302 acg =  new jalview.schemes.AnnotationColourGradient (this.currentAnnotation, this.minColour.getBackground (), this.maxColour.getBackground (), aboveThreshold);\r
303 }if (this.currentAnnotation.graphMin == 0 && this.currentAnnotation.graphMax == 0) {\r
304 acg.setPredefinedColours (true);\r
305 }acg.thresholdIsMinMax = this.thresholdIsMin.getState ();\r
306 this.av.setGlobalColourScheme (acg);\r
307 if (this.av.getAlignment ().getGroups () != null) {\r
308 for (var sg, $sg = this.ap.av.getAlignment ().getGroups ().iterator (); $sg.hasNext () && ((sg = $sg.next ()) || true);) {\r
309 if (sg.cs == null) {\r
310 continue;\r
311 }if (this.currentColours.getState ()) {\r
312 sg.cs =  new jalview.schemes.AnnotationColourGradient (this.currentAnnotation, sg.cs, aboveThreshold);\r
313 } else {\r
314 sg.cs =  new jalview.schemes.AnnotationColourGradient (this.currentAnnotation, this.minColour.getBackground (), this.maxColour.getBackground (), aboveThreshold);\r
315 }}\r
316 }this.ap.alignmentChanged ();\r
317 this.ap.paintAlignment (true);\r
318 });\r
319 Clazz.defineMethod (c$, "reset", \r
320 function () {\r
321 this.av.setGlobalColourScheme (this.oldcs);\r
322 if (this.av.getAlignment ().getGroups () != null) {\r
323 for (var sg, $sg = this.ap.av.getAlignment ().getGroups ().iterator (); $sg.hasNext () && ((sg = $sg.next ()) || true);) {\r
324 var cs = this.oldgroupColours.get (sg);\r
325 if (Clazz.instanceOf (cs, jalview.schemes.ColourSchemeI)) {\r
326 sg.cs = cs;\r
327 } else {\r
328 sg.cs = null;\r
329 }}\r
330 }this.ap.paintAlignment (true);\r
331 });\r
332 Clazz.overrideMethod (c$, "mouseClicked", \r
333 function (evt) {\r
334 }, "java.awt.event.MouseEvent");\r
335 Clazz.overrideMethod (c$, "mousePressed", \r
336 function (evt) {\r
337 }, "java.awt.event.MouseEvent");\r
338 Clazz.overrideMethod (c$, "mouseReleased", \r
339 function (evt) {\r
340 this.ap.paintAlignment (true);\r
341 }, "java.awt.event.MouseEvent");\r
342 Clazz.overrideMethod (c$, "mouseEntered", \r
343 function (evt) {\r
344 }, "java.awt.event.MouseEvent");\r
345 Clazz.overrideMethod (c$, "mouseExited", \r
346 function (evt) {\r
347 }, "java.awt.event.MouseEvent");\r
348 });\r