JAL-1807 Bob's JalviewJS prototype first commit
[jalviewjs.git] / bin / jalview / appletgui / RedundancyPanel.js
1 Clazz.declarePackage ("jalview.appletgui");\r
2 Clazz.load (["jalview.appletgui.SliderPanel", "java.awt.event.WindowListener", "java.util.Stack"], "jalview.appletgui.RedundancyPanel", ["awt2swing.Frame", "jalview.analysis.AlignSeq", "jalview.appletgui.PaintRefresher", "jalview.bin.JalviewLite", "jalview.commands.EditCommand", "jalview.util.MessageManager", "java.awt.event.AdjustmentListener", "java.lang.Thread", "java.util.ArrayList", "$.Vector"], function () {\r
3 c$ = Clazz.decorateAsClass (function () {\r
4 this.historyList = null;\r
5 this.redundancy = null;\r
6 this.originalSequences = null;\r
7 this.frame = null;\r
8 this.redundantSeqs = null;\r
9 Clazz.instantialize (this, arguments);\r
10 }, jalview.appletgui, "RedundancyPanel", jalview.appletgui.SliderPanel, [Runnable, java.awt.event.WindowListener]);\r
11 Clazz.prepareFields (c$, function () {\r
12 this.historyList =  new java.util.Stack ();\r
13 });\r
14 Clazz.makeConstructor (c$, \r
15 function (ap) {\r
16 Clazz.superConstructor (this, jalview.appletgui.RedundancyPanel, [ap, 0, false, null]);\r
17 this.redundantSeqs =  new java.util.Vector ();\r
18 this.ap = ap;\r
19 this.undoButton.setVisible (true);\r
20 this.applyButton.setVisible (true);\r
21 this.allGroupsCheck.setVisible (false);\r
22 this.label.setText (jalview.util.MessageManager.getString ("label.enter_redundancy_threshold"));\r
23 this.valueField.setText ("100");\r
24 this.slider.setVisibleAmount (1);\r
25 this.slider.setMinimum (0);\r
26 this.slider.setMaximum (100 + this.slider.getVisibleAmount ());\r
27 this.slider.setValue (100);\r
28 this.slider.addAdjustmentListener (((Clazz.isClassDefined ("jalview.appletgui.RedundancyPanel$1") ? 0 : jalview.appletgui.RedundancyPanel.$RedundancyPanel$1$ ()), Clazz.innerTypeInstance (jalview.appletgui.RedundancyPanel$1, this, null)));\r
29 this.frame =  new awt2swing.Frame ();\r
30 this.frame.add (this);\r
31 jalview.bin.JalviewLite.addFrame (this.frame, jalview.util.MessageManager.getString ("label.redundancy_threshold_selection"), 400, 100);\r
32 this.frame.addWindowListener (this);\r
33 var worker =  new Thread (this);\r
34 worker.start ();\r
35 }, "jalview.appletgui.AlignmentPanel");\r
36 Clazz.overrideMethod (c$, "run", \r
37 function () {\r
38 this.label.setText (jalview.util.MessageManager.getString ("label.calculating"));\r
39 this.slider.setVisible (false);\r
40 this.applyButton.setEnabled (false);\r
41 this.valueField.setVisible (false);\r
42 this.validate ();\r
43 var omitHidden = null;\r
44 var sg = this.ap.av.getSelectionGroup ();\r
45 var height;\r
46 var start;\r
47 var end;\r
48 if ((sg != null) && (sg.getSize () >= 1)) {\r
49 this.originalSequences = sg.getSequencesInOrder (this.ap.av.getAlignment ());\r
50 start = sg.getStartRes ();\r
51 end = sg.getEndRes ();\r
52 } else {\r
53 this.originalSequences = this.ap.av.getAlignment ().getSequencesArray ();\r
54 start = 0;\r
55 end = this.ap.av.getAlignment ().getWidth ();\r
56 }height = this.originalSequences.length;\r
57 this.redundancy = jalview.analysis.AlignSeq.computeRedundancyMatrix (this.originalSequences, omitHidden, start, end, false);\r
58 this.label.setText (jalview.util.MessageManager.getString ("label.enter_redundancy_threshold"));\r
59 this.slider.setVisible (true);\r
60 this.applyButton.setEnabled (true);\r
61 this.valueField.setVisible (true);\r
62 this.validate ();\r
63 this.sliderValueChanged ();\r
64 });\r
65 Clazz.defineMethod (c$, "sliderValueChanged", \r
66 function () {\r
67 if (this.redundancy == null) {\r
68 return;\r
69 }var value = this.slider.getValue ();\r
70 var redundantSequences =  new java.util.ArrayList ();\r
71 for (var i = 0; i < this.redundancy.length; i++) {\r
72 if (value <= this.redundancy[i]) {\r
73 redundantSequences.add (this.originalSequences[i]);\r
74 }}\r
75 this.ap.idPanel.idCanvas.setHighlighted (redundantSequences);\r
76 jalview.appletgui.PaintRefresher.Refresh (this, this.ap.av.getSequenceSetId (), true, true);\r
77 });\r
78 Clazz.overrideMethod (c$, "applyButton_actionPerformed", \r
79 function () {\r
80 var del =  new java.util.Vector ();\r
81 this.undoButton.setEnabled (true);\r
82 var value = this.slider.getValue ();\r
83 var sg = this.ap.av.getSelectionGroup ();\r
84 for (var i = 0; i < this.redundancy.length; i++) {\r
85 if (value <= this.redundancy[i]) {\r
86 del.addElement (this.originalSequences[i]);\r
87 }}\r
88 if (del.size () > 0) {\r
89 var deleted =  new Array (del.size ());\r
90 var width = 0;\r
91 for (var i = 0; i < del.size (); i++) {\r
92 deleted[i] = del.elementAt (i);\r
93 if (deleted[i].getLength () > width) {\r
94 width = deleted[i].getLength ();\r
95 }}\r
96 var cut =  new jalview.commands.EditCommand (jalview.util.MessageManager.getString ("action.remove_redundancy"), jalview.commands.EditCommand.Action.CUT, deleted, 0, width, this.ap.av.getAlignment ());\r
97 var alignment = this.ap.av.getAlignment ();\r
98 for (var i = 0; i < del.size (); i++) {\r
99 alignment.deleteSequence (deleted[i]);\r
100 if (sg != null) {\r
101 sg.deleteSequence (deleted[i], false);\r
102 }}\r
103 this.historyList.push (cut);\r
104 this.ap.alignFrame.addHistoryItem (cut);\r
105 jalview.appletgui.PaintRefresher.Refresh (this, this.ap.av.getSequenceSetId (), true, true);\r
106 this.ap.av.firePropertyChange ("alignment", null, this.ap.av.getAlignment ().getSequences ());\r
107 }});\r
108 Clazz.overrideMethod (c$, "undoButton_actionPerformed", \r
109 function () {\r
110 var command = this.historyList.pop ();\r
111 command.undoCommand (null);\r
112 if (this.ap.av.getHistoryList ().contains (command)) {\r
113 this.ap.av.getHistoryList ().remove (command);\r
114 this.ap.alignFrame.updateEditMenuBar ();\r
115 this.ap.av.firePropertyChange ("alignment", null, this.ap.av.getAlignment ().getSequences ());\r
116 }this.ap.paintAlignment (true);\r
117 if (this.historyList.size () == 0) {\r
118 this.undoButton.setEnabled (false);\r
119 }});\r
120 Clazz.defineMethod (c$, "valueField_actionPerformed", \r
121 function (e) {\r
122 try {\r
123 var i = Integer.parseInt (this.valueField.getText ());\r
124 this.slider.setValue (i);\r
125 } catch (ex) {\r
126 if (Clazz.exceptionOf (ex, Exception)) {\r
127 this.valueField.setText (this.slider.getValue () + "");\r
128 } else {\r
129 throw ex;\r
130 }\r
131 }\r
132 }, "java.awt.event.ActionEvent");\r
133 Clazz.overrideMethod (c$, "windowOpened", \r
134 function (evt) {\r
135 }, "java.awt.event.WindowEvent");\r
136 Clazz.overrideMethod (c$, "windowClosing", \r
137 function (evt) {\r
138 this.ap.idPanel.idCanvas.setHighlighted (null);\r
139 }, "java.awt.event.WindowEvent");\r
140 Clazz.overrideMethod (c$, "windowClosed", \r
141 function (evt) {\r
142 }, "java.awt.event.WindowEvent");\r
143 Clazz.overrideMethod (c$, "windowActivated", \r
144 function (evt) {\r
145 }, "java.awt.event.WindowEvent");\r
146 Clazz.overrideMethod (c$, "windowDeactivated", \r
147 function (evt) {\r
148 }, "java.awt.event.WindowEvent");\r
149 Clazz.overrideMethod (c$, "windowIconified", \r
150 function (evt) {\r
151 }, "java.awt.event.WindowEvent");\r
152 Clazz.overrideMethod (c$, "windowDeiconified", \r
153 function (evt) {\r
154 }, "java.awt.event.WindowEvent");\r
155 c$.$RedundancyPanel$1$ = function () {\r
156 Clazz.pu$h ();\r
157 c$ = Clazz.declareAnonymous (jalview.appletgui, "RedundancyPanel$1", null, java.awt.event.AdjustmentListener);\r
158 Clazz.overrideMethod (c$, "adjustmentValueChanged", \r
159 function (evt) {\r
160 this.b$["jalview.appletgui.RedundancyPanel"].valueField.setText (this.b$["jalview.appletgui.RedundancyPanel"].slider.getValue () + "");\r
161 this.b$["jalview.appletgui.RedundancyPanel"].sliderValueChanged ();\r
162 }, "java.awt.event.AdjustmentEvent");\r
163 c$ = Clazz.p0p ();\r
164 };\r
165 });\r