JAL-1807 test
[jalviewjs.git] / bin / jalview / appletgui / FeatureColourChooser.js
1 Clazz.declarePackage ("jalview.appletgui");
2 Clazz.load (["awt2swing.Panel", "java.awt.event.ActionListener", "$.AdjustmentListener", "$.ItemListener", "$.MouseListener", "awt2swing.Checkbox", "$.Choice", "$.Scrollbar", "$.TextField"], "jalview.appletgui.FeatureColourChooser", ["awt2swing.Label", "jalview.appletgui.JVDialog", "$.PaintRefresher", "$.UserDefinedColours", "jalview.datamodel.GraphLine", "jalview.schemes.GraduatedColor", "jalview.util.MessageManager", "java.awt.Color", "$.Dimension", "$.FlowLayout", "$.Font", "$.GridLayout", "java.awt.event.ActionEvent", "java.lang.Float"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.frame = null;
5 this.owner = null;
6 this.fr = null;
7 this.fs = null;
8 this.cs = null;
9 this.oldcs = null;
10 this.oldgroupColours = null;
11 this.adjusting = false;
12 this.min = 0;
13 this.max = 0;
14 this.type = null;
15 this.af = null;
16 this.minColour = null;
17 this.maxColour = null;
18 this.jPanel1 = null;
19 this.jPanel2 = null;
20 this.threshold = null;
21 this.jPanel3 = null;
22 this.jPanel4 = null;
23 this.slider = null;
24 this.thresholdValue = null;
25 this.thresholdIsMin = null;
26 this.colourFromLabel = null;
27 this.threshline = null;
28 Clazz.instantialize (this, arguments);
29 }, jalview.appletgui, "FeatureColourChooser", awt2swing.Panel, [java.awt.event.ActionListener, java.awt.event.AdjustmentListener, java.awt.event.ItemListener, java.awt.event.MouseListener]);
30 Clazz.prepareFields (c$, function () {
31 this.minColour =  new awt2swing.Panel ();
32 this.maxColour =  new awt2swing.Panel ();
33 this.jPanel1 =  new awt2swing.Panel ();
34 this.jPanel2 =  new awt2swing.Panel ();
35 this.threshold =  new awt2swing.Choice ();
36 this.jPanel3 =  new awt2swing.Panel ();
37 this.jPanel4 =  new awt2swing.Panel ();
38 this.slider =  new awt2swing.Scrollbar (0);
39 this.thresholdValue =  new awt2swing.TextField (20);
40 this.thresholdIsMin =  new awt2swing.Checkbox ();
41 this.colourFromLabel =  new awt2swing.Checkbox ();
42 });
43 Clazz.makeConstructor (c$, 
44 function (af, type) {
45 Clazz.superConstructor (this, jalview.appletgui.FeatureColourChooser, []);
46 this.af = af;
47 this.init (af.getSeqcanvas ().getFeatureRenderer (), type);
48 }, "jalview.appletgui.AlignFrame,~S");
49 Clazz.makeConstructor (c$, 
50 function (fsettings, type) {
51 Clazz.superConstructor (this, jalview.appletgui.FeatureColourChooser, []);
52 this.fs = fsettings;
53 this.init (fsettings.fr, type);
54 }, "jalview.appletgui.FeatureSettings,~S");
55 Clazz.defineMethod (c$, "init", 
56 ($fz = function (frenderer, type) {
57 this.type = type;
58 this.fr = frenderer;
59 var mm = (this.fr.getMinMax ().get (type))[0];
60 this.min = mm[0];
61 this.max = mm[1];
62 this.oldcs = this.fr.getFeatureColours ().get (type);
63 if (Clazz.instanceOf (this.oldcs, jalview.schemes.GraduatedColor)) {
64 this.cs =  new jalview.schemes.GraduatedColor (this.oldcs, this.min, this.max);
65 } else {
66 var bl = java.awt.Color.black;
67 if (Clazz.instanceOf (this.oldcs, java.awt.Color)) {
68 bl = this.oldcs;
69 }this.cs =  new jalview.schemes.GraduatedColor (java.awt.Color.white, bl, mm[0], mm[1]);
70 }this.minColour.setBackground (this.cs.getMinColor ());
71 this.maxColour.setBackground (this.cs.getMaxColor ());
72 this.minColour.setForeground (this.cs.getMinColor ());
73 this.maxColour.setForeground (this.cs.getMaxColor ());
74 this.colourFromLabel.setState (this.cs.isColourByLabel ());
75 this.adjusting = true;
76 try {
77 this.jbInit ();
78 } catch (ex) {
79 if (Clazz.exceptionOf (ex, Exception)) {
80 } else {
81 throw ex;
82 }
83 }
84 this.threshold.select (new Integer (this.cs.getThreshType () == -1 ? 0 : this.cs.getThreshType () == 1 ? 1 : 2));
85 this.adjusting = false;
86 this.changeColour ();
87 this.colourFromLabel.addItemListener (this);
88 this.slider.addAdjustmentListener (this);
89 this.slider.addMouseListener (this);
90 this.owner = (this.af != null) ? this.af : this.fs.frame;
91 this.frame =  new jalview.appletgui.JVDialog (this.owner, jalview.util.MessageManager.formatMessage ("label.graduated_color_for_params",  Clazz.newArray (-1, [type])), true, 480, 248);
92 this.frame.setMainPanel (this);
93 this.validate ();
94 this.frame.setVisible (true);
95 if (this.frame.accept) {
96 this.changeColour ();
97 } else {
98 this.reset ();
99 jalview.appletgui.PaintRefresher.Refresh (this, this.fr.getViewport ().getSequenceSetId ());
100 this.frame.setVisible (false);
101 }}, $fz.isPrivate = true, $fz), "jalview.appletgui.FeatureRenderer,~S");
102 Clazz.makeConstructor (c$, 
103 function () {
104 Clazz.superConstructor (this, jalview.appletgui.FeatureColourChooser, []);
105 try {
106 this.jbInit ();
107 } catch (ex) {
108 if (Clazz.exceptionOf (ex, Exception)) {
109 ex.printStackTrace ();
110 } else {
111 throw ex;
112 }
113 }
114 });
115 Clazz.defineMethod (c$, "jbInit", 
116 ($fz = function () {
117 var minLabel =  new awt2swing.Label (jalview.util.MessageManager.getString ("label.min"));
118 var maxLabel =  new awt2swing.Label (jalview.util.MessageManager.getString ("label.max"));
119 minLabel.setFont ( new java.awt.Font ("Verdana", 0, 11));
120 maxLabel.setFont ( new java.awt.Font ("Verdana", 0, 11));
121 this.minColour.setBounds (0, 0, 40, 27);
122 this.maxColour.setBounds (0, 0, 40, 27);
123 this.minColour.addMouseListener (this);
124 this.maxColour.setFont ( new java.awt.Font ("Verdana", 0, 11));
125 this.maxColour.addMouseListener (this);
126 this.thresholdIsMin.addItemListener (this);
127 this.setLayout ( new java.awt.GridLayout (4, 1));
128 this.jPanel1.setLayout ( new java.awt.FlowLayout ());
129 this.jPanel2.setLayout ( new java.awt.FlowLayout ());
130 this.jPanel3.setLayout ( new java.awt.GridLayout (1, 1));
131 this.jPanel4.setLayout ( new java.awt.FlowLayout ());
132 this.jPanel1.setBackground (java.awt.Color.white);
133 this.jPanel2.setBackground (java.awt.Color.white);
134 this.jPanel4.setBackground (java.awt.Color.white);
135 this.threshold.addItemListener (this);
136 this.threshold.addItem (jalview.util.MessageManager.getString ("label.threshold_feature_no_thereshold"));
137 this.threshold.addItem (jalview.util.MessageManager.getString ("label.threshold_feature_above_thereshold"));
138 this.threshold.addItem (jalview.util.MessageManager.getString ("label.threshold_feature_below_thereshold"));
139 this.thresholdValue.addActionListener (this);
140 this.slider.setBackground (java.awt.Color.white);
141 this.slider.setEnabled (false);
142 this.slider.setSize ( new java.awt.Dimension (93, 21));
143 this.thresholdValue.setEnabled (false);
144 this.thresholdValue.setSize ( new java.awt.Dimension (79, 22));
145 this.thresholdValue.setColumns (5);
146 this.jPanel3.setBackground (java.awt.Color.white);
147 this.colourFromLabel.setFont ( new java.awt.Font ("Verdana", 0, 11));
148 this.colourFromLabel.setLabel (jalview.util.MessageManager.getString ("label.colour_by_label"));
149 this.colourFromLabel.setSize ( new java.awt.Dimension (139, 22));
150 this.thresholdIsMin.setBackground (java.awt.Color.white);
151 this.thresholdIsMin.setLabel (jalview.util.MessageManager.getString ("label.threshold_minmax"));
152 this.thresholdIsMin.setSize ( new java.awt.Dimension (135, 23));
153 this.jPanel1.add (minLabel);
154 this.jPanel1.add (this.minColour);
155 this.jPanel1.add (maxLabel);
156 this.jPanel1.add (this.maxColour);
157 this.jPanel1.add (this.colourFromLabel);
158 this.jPanel2.add (this.threshold);
159 this.jPanel3.add (this.slider);
160 this.jPanel4.add (this.thresholdValue);
161 this.jPanel4.add (this.thresholdIsMin);
162 this.add (this.jPanel1);
163 this.add (this.jPanel2);
164 this.add (this.jPanel3);
165 this.add (this.jPanel4);
166 }, $fz.isPrivate = true, $fz));
167 Clazz.overrideMethod (c$, "actionPerformed", 
168 function (evt) {
169 if (evt.getSource () === this.thresholdValue) {
170 try {
171 var f =  new Float (this.thresholdValue.getText ()).floatValue ();
172 this.slider.setValue (Clazz.floatToInt (f * 1000));
173 this.adjustmentValueChanged (null);
174 } catch (ex) {
175 if (Clazz.exceptionOf (ex, NumberFormatException)) {
176 } else {
177 throw ex;
178 }
179 }
180 } else if (evt.getSource () === this.minColour) {
181 this.minColour_actionPerformed (null);
182 } else if (evt.getSource () === this.maxColour) {
183 this.maxColour_actionPerformed (null);
184 } else {
185 this.changeColour ();
186 }}, "java.awt.event.ActionEvent");
187 Clazz.overrideMethod (c$, "itemStateChanged", 
188 function (evt) {
189 this.maxColour.setEnabled (!this.colourFromLabel.getState ());
190 this.minColour.setEnabled (!this.colourFromLabel.getState ());
191 this.changeColour ();
192 }, "java.awt.event.ItemEvent");
193 Clazz.overrideMethod (c$, "adjustmentValueChanged", 
194 function (evt) {
195 if (!this.adjusting) {
196 this.thresholdValue.setText ((this.slider.getValue () / 1000) + "");
197 this.valueChanged ();
198 }}, "java.awt.event.AdjustmentEvent");
199 Clazz.defineMethod (c$, "valueChanged", 
200 function () {
201 this.threshline.value = this.slider.getValue () / 1000;
202 this.cs.setThresh (this.threshline.value);
203 this.changeColour ();
204 jalview.appletgui.PaintRefresher.Refresh (this, this.fr.getViewport ().getSequenceSetId ());
205 });
206 Clazz.defineMethod (c$, "minColour_actionPerformed", 
207 function (newCol) {
208 if (newCol == null) {
209 var udc =  new jalview.appletgui.UserDefinedColours (this, this.minColour.getBackground (), this.owner, jalview.util.MessageManager.getString ("label.select_colour_minimum_value"));
210 } else {
211 this.minColour.setBackground (newCol);
212 this.minColour.setForeground (newCol);
213 this.minColour.repaint ();
214 this.changeColour ();
215 }}, "java.awt.Color");
216 Clazz.defineMethod (c$, "maxColour_actionPerformed", 
217 function (newCol) {
218 if (newCol == null) {
219 var udc =  new jalview.appletgui.UserDefinedColours (this, this.maxColour.getBackground (), this.owner, jalview.util.MessageManager.getString ("label.select_colour_maximum_value"));
220 } else {
221 this.maxColour.setBackground (newCol);
222 this.maxColour.setForeground (newCol);
223 this.maxColour.repaint ();
224 this.changeColour ();
225 }}, "java.awt.Color");
226 Clazz.defineMethod (c$, "changeColour", 
227 function () {
228 if (this.adjusting) {
229 return;
230 }var aboveThreshold = -1;
231 if (this.threshold.getSelectedIndex () == 1) {
232 aboveThreshold = 1;
233 } else if (this.threshold.getSelectedIndex () == 2) {
234 aboveThreshold = 0;
235 }this.slider.setEnabled (true);
236 this.thresholdValue.setEnabled (true);
237 var acg =  new jalview.schemes.GraduatedColor (this.minColour.getBackground (), this.maxColour.getBackground (), this.min, this.max);
238 acg.setColourByLabel (this.colourFromLabel.getState ());
239 this.maxColour.setEnabled (!this.colourFromLabel.getState ());
240 this.minColour.setEnabled (!this.colourFromLabel.getState ());
241 if (aboveThreshold == -1) {
242 this.slider.setEnabled (false);
243 this.thresholdValue.setEnabled (false);
244 this.thresholdValue.setText ("");
245 } else if (aboveThreshold != -1 && this.threshline == null) {
246 this.threshline =  new jalview.datamodel.GraphLine ((this.max - this.min) / 2, "Threshold", java.awt.Color.black);
247 }if (aboveThreshold != -1) {
248 this.adjusting = true;
249 acg.setThresh (this.threshline.value);
250 var range = this.max * 1000 - this.min * 1000;
251 this.slider.setMinimum (Clazz.floatToInt (this.min * 1000));
252 this.slider.setMaximum (Clazz.floatToInt (this.max * 1000));
253 this.slider.setValue (Clazz.floatToInt (this.threshline.value * 1000));
254 this.thresholdValue.setText (this.threshline.value + "");
255 this.slider.setEnabled (true);
256 this.thresholdValue.setEnabled (true);
257 this.adjusting = false;
258 }acg.setThreshType (aboveThreshold);
259 if (this.thresholdIsMin.getState () && aboveThreshold != -1) {
260 if (aboveThreshold == 1) {
261 acg =  new jalview.schemes.GraduatedColor (acg, this.threshline.value, this.max);
262 } else {
263 acg =  new jalview.schemes.GraduatedColor (acg, this.min, this.threshline.value);
264 }}this.fr.setColour (this.type, acg);
265 this.cs = acg;
266 jalview.appletgui.PaintRefresher.Refresh (this, this.fr.getViewport ().getSequenceSetId ());
267 });
268 Clazz.defineMethod (c$, "reset", 
269 function () {
270 this.fr.setColour (this.type, this.oldcs);
271 jalview.appletgui.PaintRefresher.Refresh (this, this.fr.getViewport ().getSequenceSetId ());
272 });
273 Clazz.overrideMethod (c$, "mouseClicked", 
274 function (evt) {
275 }, "java.awt.event.MouseEvent");
276 Clazz.overrideMethod (c$, "mousePressed", 
277 function (evt) {
278 }, "java.awt.event.MouseEvent");
279 Clazz.overrideMethod (c$, "mouseReleased", 
280 function (evt) {
281 if (evt.getSource () === this.minColour || evt.getSource () === this.maxColour) {
282 this.actionPerformed ( new java.awt.event.ActionEvent (evt.getSource (), 1, "Clicked"));
283 } else {
284 jalview.appletgui.PaintRefresher.Refresh (this, this.fr.getViewport ().getSequenceSetId ());
285 }}, "java.awt.event.MouseEvent");
286 Clazz.overrideMethod (c$, "mouseEntered", 
287 function (evt) {
288 }, "java.awt.event.MouseEvent");
289 Clazz.overrideMethod (c$, "mouseExited", 
290 function (evt) {
291 }, "java.awt.event.MouseEvent");
292 });