JAL-1807 test
[jalviewjs.git] / bin / jalview / appletgui / ScalePanel.js
1 Clazz.declarePackage ("jalview.appletgui");
2 Clazz.load (["awt2swing.Panel", "java.awt.event.MouseListener", "$.MouseMotionListener"], "jalview.appletgui.ScalePanel", ["awt2swing.MenuItem", "$.PopupMenu", "jalview.datamodel.SequenceGroup", "jalview.util.MessageManager", "java.awt.Color", "java.awt.event.ActionListener"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.offy = 4;
5 this.$width = 0;
6 this.av = null;
7 this.ap = null;
8 this.stretchingGroup = false;
9 this.min = 0;
10 this.max = 0;
11 this.mouseDragging = false;
12 this.reveal = null;
13 Clazz.instantialize (this, arguments);
14 }, jalview.appletgui, "ScalePanel", awt2swing.Panel, [java.awt.event.MouseMotionListener, java.awt.event.MouseListener]);
15 Clazz.makeConstructor (c$, 
16 function (av, ap) {
17 Clazz.superConstructor (this, jalview.appletgui.ScalePanel, []);
18 this.setName ("scalePanel");
19 this.setLayout (null);
20 this.av = av;
21 this.ap = ap;
22 this.addMouseListener (this);
23 this.addMouseMotionListener (this);
24 }, "jalview.appletgui.AlignViewport,jalview.appletgui.AlignmentPanel");
25 Clazz.overrideMethod (c$, "mousePressed", 
26 function (evt) {
27 var x = (Clazz.doubleToInt (evt.getX () / this.av.getCharWidth ())) + this.av.getStartRes ();
28 var res;
29 if (this.av.hasHiddenColumns ()) {
30 res = this.av.getColumnSelection ().adjustForHiddenColumns (x);
31 } else {
32 res = x;
33 }this.min = res;
34 this.max = res;
35 if ((evt.getModifiers () & 4) == 4) {
36 var pop =  new awt2swing.PopupMenu ();
37 if (this.reveal != null) {
38 var item =  new awt2swing.MenuItem (jalview.util.MessageManager.getString ("label.reveal"));
39 item.addActionListener (((Clazz.isClassDefined ("jalview.appletgui.ScalePanel$1") ? 0 : jalview.appletgui.ScalePanel.$ScalePanel$1$ ()), Clazz.innerTypeInstance (jalview.appletgui.ScalePanel$1, this, null)));
40 pop.add (item);
41 if (this.av.getColumnSelection ().hasManyHiddenColumns ()) {
42 item =  new awt2swing.MenuItem (jalview.util.MessageManager.getString ("action.reveal_all"));
43 item.addActionListener (((Clazz.isClassDefined ("jalview.appletgui.ScalePanel$2") ? 0 : jalview.appletgui.ScalePanel.$ScalePanel$2$ ()), Clazz.innerTypeInstance (jalview.appletgui.ScalePanel$2, this, null)));
44 pop.add (item);
45 }this.add (pop);
46 pop.show (this, evt.getX (), evt.getY ());
47 } else if (this.av.getColumnSelection ().contains (res)) {
48 var item =  new awt2swing.MenuItem (jalview.util.MessageManager.getString ("label.hide_columns"));
49 item.addActionListener (((Clazz.isClassDefined ("jalview.appletgui.ScalePanel$3") ? 0 : jalview.appletgui.ScalePanel.$ScalePanel$3$ ()), Clazz.innerTypeInstance (jalview.appletgui.ScalePanel$3, this, Clazz.cloneFinals ("res", res))));
50 pop.add (item);
51 this.add (pop);
52 pop.show (this, evt.getX (), evt.getY ());
53 }} else {
54 if (!evt.isControlDown () && !evt.isShiftDown ()) {
55 this.av.getColumnSelection ().clear ();
56 }this.av.getColumnSelection ().addElement (res);
57 var sg =  new jalview.datamodel.SequenceGroup ();
58 for (var i = 0; i < this.av.getAlignment ().getSequences ().size (); i++) {
59 sg.addSequence (this.av.getAlignment ().getSequenceAt (i), false);
60 }
61 sg.setStartRes (res);
62 sg.setEndRes (res);
63 this.av.setSelectionGroup (sg);
64 if (evt.isShiftDown ()) {
65 var min = Math.min (this.av.getColumnSelection ().getMin (), res);
66 var max = Math.max (this.av.getColumnSelection ().getMax (), res);
67 for (var i = min; i < max; i++) {
68 this.av.getColumnSelection ().addElement (i);
69 }
70 sg.setStartRes (min);
71 sg.setEndRes (max);
72 }}this.ap.paintAlignment (true);
73 this.av.sendSelection ();
74 }, "java.awt.event.MouseEvent");
75 Clazz.overrideMethod (c$, "mouseReleased", 
76 function (evt) {
77 this.mouseDragging = false;
78 var res = (Clazz.doubleToInt (evt.getX () / this.av.getCharWidth ())) + this.av.getStartRes ();
79 if (res > this.av.getAlignment ().getWidth ()) {
80 res = this.av.getAlignment ().getWidth () - 1;
81 }if (this.av.hasHiddenColumns ()) {
82 res = this.av.getColumnSelection ().adjustForHiddenColumns (res);
83 }if (!this.stretchingGroup) {
84 this.ap.paintAlignment (false);
85 return;
86 }var sg = this.av.getSelectionGroup ();
87 if (res > sg.getStartRes ()) {
88 sg.setEndRes (res);
89 } else if (res < sg.getStartRes ()) {
90 sg.setStartRes (res);
91 }this.stretchingGroup = false;
92 this.ap.paintAlignment (false);
93 this.av.sendSelection ();
94 }, "java.awt.event.MouseEvent");
95 Clazz.overrideMethod (c$, "mouseDragged", 
96 function (evt) {
97 this.mouseDragging = true;
98 var res = (Clazz.doubleToInt (evt.getX () / this.av.getCharWidth ())) + this.av.getStartRes ();
99 if (res < 0) {
100 res = 0;
101 }if (this.av.hasHiddenColumns ()) {
102 res = this.av.getColumnSelection ().adjustForHiddenColumns (res);
103 }if (res > this.av.getAlignment ().getWidth ()) {
104 res = this.av.getAlignment ().getWidth () - 1;
105 }if (res < this.min) {
106 this.min = res;
107 }if (res > this.max) {
108 this.max = res;
109 }var sg = this.av.getSelectionGroup ();
110 if (sg != null) {
111 this.stretchingGroup = true;
112 if (!this.av.getColumnSelection ().contains (res)) {
113 this.av.getColumnSelection ().addElement (res);
114 }if (res > sg.getStartRes ()) {
115 sg.setEndRes (res);
116 }if (res < sg.getStartRes ()) {
117 sg.setStartRes (res);
118 }var col;
119 for (var i = this.min; i <= this.max; i++) {
120 col = this.av.getColumnSelection ().adjustForHiddenColumns (i);
121 if ((col < sg.getStartRes ()) || (col > sg.getEndRes ())) {
122 this.av.getColumnSelection ().removeElement (col);
123 } else {
124 this.av.getColumnSelection ().addElement (col);
125 }}
126 this.ap.paintAlignment (false);
127 }}, "java.awt.event.MouseEvent");
128 Clazz.overrideMethod (c$, "mouseEntered", 
129 function (evt) {
130 if (this.mouseDragging) {
131 this.ap.seqPanel.scrollCanvas (null);
132 }}, "java.awt.event.MouseEvent");
133 Clazz.overrideMethod (c$, "mouseExited", 
134 function (evt) {
135 if (this.mouseDragging) {
136 this.ap.seqPanel.scrollCanvas (evt);
137 }}, "java.awt.event.MouseEvent");
138 Clazz.overrideMethod (c$, "mouseClicked", 
139 function (evt) {
140 }, "java.awt.event.MouseEvent");
141 Clazz.overrideMethod (c$, "mouseMoved", 
142 function (evt) {
143 if (!this.av.hasHiddenColumns ()) {
144 return;
145 }var res = (Clazz.doubleToInt (evt.getX () / this.av.getCharWidth ())) + this.av.getStartRes ();
146 res = this.av.getColumnSelection ().adjustForHiddenColumns (res);
147 this.reveal = null;
148 for (var region, $region = this.av.getColumnSelection ().getHiddenColumns ().iterator (); $region.hasNext () && ((region = $region.next ()) || true);) {
149 if (res + 1 == region[0] || res - 1 == region[1]) {
150 this.reveal = region;
151 break;
152 }}
153 this.repaint ();
154 }, "java.awt.event.MouseEvent");
155 Clazz.overrideMethod (c$, "paintComponent", 
156 function (g) {
157 if (this.av.getWrapAlignment ()) return;
158 this.drawScale (g, this.av.getStartRes (), this.av.getEndRes (), this.getSize ().width, this.getSize ().height);
159 }, "java.awt.Graphics");
160 Clazz.defineMethod (c$, "drawScale", 
161 function (gg, startx, endx, width, height) {
162 gg.setFont (this.av.getFont ());
163 gg.setColor (java.awt.Color.white);
164 gg.fillRect (0, 0, width, height);
165 gg.setColor (java.awt.Color.black);
166 var cs = this.av.getColumnSelection ();
167 gg.setColor ( new java.awt.Color (220, 0, 0));
168 var avcharWidth = this.av.getCharWidth ();
169 var avcharHeight = this.av.getCharHeight ();
170 for (var i = 0; i < cs.size (); i++) {
171 var sel = cs.columnAt (i);
172 if (this.av.hasHiddenColumns ()) {
173 sel = this.av.getColumnSelection ().findColumnPosition (sel);
174 }if ((sel >= startx) && (sel <= endx)) {
175 gg.fillRect ((sel - startx) * avcharWidth, 0, avcharWidth, this.getSize ().height);
176 }}
177 gg.setColor (java.awt.Color.black);
178 var scalestartx = (Clazz.doubleToInt (startx / 10)) * 10;
179 var fm = gg.getFontMetrics (this.av.getFont ());
180 var y = avcharHeight - fm.getDescent ();
181 if ((scalestartx % 10) == 0) {
182 scalestartx += 5;
183 }var string;
184 var maxX = 0;
185 for (var i = scalestartx; i < endx; i += 5) {
186 if ((i % 10) == 0) {
187 string = String.valueOf (this.av.getColumnSelection ().adjustForHiddenColumns (i));
188 if ((i - startx - 1) * avcharWidth > maxX) {
189 gg.drawString (string, (i - startx - 1) * avcharWidth, y);
190 maxX = (i - startx + 1) * avcharWidth + fm.stringWidth (string);
191 }gg.drawLine (((i - startx - 1) * avcharWidth) + (Clazz.doubleToInt (avcharWidth / 2)), y + 2, ((i - startx - 1) * avcharWidth) + (Clazz.doubleToInt (avcharWidth / 2)), y + (fm.getDescent () * 2));
192 } else {
193 gg.drawLine (((i - startx - 1) * avcharWidth) + (Clazz.doubleToInt (avcharWidth / 2)), y + fm.getDescent (), ((i - startx - 1) * avcharWidth) + (Clazz.doubleToInt (avcharWidth / 2)), y + (fm.getDescent () * 2));
194 }}
195 if (this.av.hasHiddenColumns ()) {
196 gg.setColor (java.awt.Color.blue);
197 var res;
198 if (this.av.getShowHiddenMarkers ()) {
199 for (var i = 0; i < this.av.getColumnSelection ().getHiddenColumns ().size (); i++) {
200 res = this.av.getColumnSelection ().findHiddenRegionPosition (i) - startx;
201 if (res < 0 || res > endx - scalestartx) {
202 continue;
203 }gg.fillPolygon ( Clazz.newIntArray (-1, [res * avcharWidth - Clazz.doubleToInt (avcharHeight / 4), res * avcharWidth + Clazz.doubleToInt (avcharHeight / 4), res * avcharWidth]),  Clazz.newIntArray (-1, [y - Clazz.doubleToInt (avcharHeight / 2), y - Clazz.doubleToInt (avcharHeight / 2), y + 8]), 3);
204 }
205 }if (this.reveal != null && this.reveal[0] > startx && this.reveal[0] < endx) {
206 gg.drawString (jalview.util.MessageManager.getString ("label.reveal_columns"), this.reveal[0] * avcharWidth, 0);
207 }}}, "java.awt.Graphics,~N,~N,~N,~N");
208 c$.$ScalePanel$1$ = function () {
209 Clazz.pu$h ();
210 c$ = Clazz.declareAnonymous (jalview.appletgui, "ScalePanel$1", null, java.awt.event.ActionListener);
211 Clazz.overrideMethod (c$, "actionPerformed", 
212 function (e) {
213 this.b$["jalview.appletgui.ScalePanel"].av.showColumn (this.b$["jalview.appletgui.ScalePanel"].reveal[0]);
214 this.b$["jalview.appletgui.ScalePanel"].reveal = null;
215 this.b$["jalview.appletgui.ScalePanel"].ap.paintAlignment (true);
216 if (this.b$["jalview.appletgui.ScalePanel"].ap.overviewPanel != null) {
217 this.b$["jalview.appletgui.ScalePanel"].ap.overviewPanel.updateOverviewImage ();
218 }}, "java.awt.event.ActionEvent");
219 c$ = Clazz.p0p ();
220 };
221 c$.$ScalePanel$2$ = function () {
222 Clazz.pu$h ();
223 c$ = Clazz.declareAnonymous (jalview.appletgui, "ScalePanel$2", null, java.awt.event.ActionListener);
224 Clazz.overrideMethod (c$, "actionPerformed", 
225 function (e) {
226 this.b$["jalview.appletgui.ScalePanel"].av.showAllHiddenColumns ();
227 this.b$["jalview.appletgui.ScalePanel"].reveal = null;
228 this.b$["jalview.appletgui.ScalePanel"].ap.paintAlignment (true);
229 if (this.b$["jalview.appletgui.ScalePanel"].ap.overviewPanel != null) {
230 this.b$["jalview.appletgui.ScalePanel"].ap.overviewPanel.updateOverviewImage ();
231 }}, "java.awt.event.ActionEvent");
232 c$ = Clazz.p0p ();
233 };
234 c$.$ScalePanel$3$ = function () {
235 Clazz.pu$h ();
236 c$ = Clazz.declareAnonymous (jalview.appletgui, "ScalePanel$3", null, java.awt.event.ActionListener);
237 Clazz.overrideMethod (c$, "actionPerformed", 
238 function (e) {
239 this.b$["jalview.appletgui.ScalePanel"].av.hideColumns (this.f$.res, this.f$.res);
240 if (this.b$["jalview.appletgui.ScalePanel"].av.getSelectionGroup () != null && this.b$["jalview.appletgui.ScalePanel"].av.getSelectionGroup ().getSize () == this.b$["jalview.appletgui.ScalePanel"].av.getAlignment ().getHeight ()) {
241 this.b$["jalview.appletgui.ScalePanel"].av.setSelectionGroup (null);
242 }this.b$["jalview.appletgui.ScalePanel"].ap.paintAlignment (true);
243 if (this.b$["jalview.appletgui.ScalePanel"].ap.overviewPanel != null) {
244 this.b$["jalview.appletgui.ScalePanel"].ap.overviewPanel.updateOverviewImage ();
245 }}, "java.awt.event.ActionEvent");
246 c$ = Clazz.p0p ();
247 };
248 });