JAL-1807 test
[jalviewjs.git] / bin / jalview / appletgui / OverviewPanel.js
1 Clazz.declarePackage ("jalview.appletgui");
2 Clazz.load (["awt2swing.Panel", "java.awt.event.MouseListener", "$.MouseMotionListener"], "jalview.appletgui.OverviewPanel", ["awt2swing.Frame", "jalview.appletgui.FeatureRenderer", "$.SequenceRenderer", "java.awt.Color", "$.Dimension", "java.awt.event.ComponentAdapter", "java.lang.Thread"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.miniMe = null;
5 this.offscreen = null;
6 this.av = null;
7 this.ap = null;
8 this.scalew = 1;
9 this.scaleh = 1;
10 this.$width = 0;
11 this.sequencesHeight = 0;
12 this.graphHeight = 20;
13 this.boxX = -1;
14 this.boxY = -1;
15 this.boxWidth = -1;
16 this.boxHeight = -1;
17 this.resizing = false;
18 this.sr = null;
19 this.fr = null;
20 this.nullFrame = null;
21 this.resizeAgain = false;
22 Clazz.instantialize (this, arguments);
23 }, jalview.appletgui, "OverviewPanel", awt2swing.Panel, [Runnable, java.awt.event.MouseMotionListener, java.awt.event.MouseListener]);
24 Clazz.makeConstructor (c$, 
25 function (ap) {
26 Clazz.superConstructor (this, jalview.appletgui.OverviewPanel, []);
27 this.av = ap.av;
28 this.ap = ap;
29 this.setLayout (null);
30 this.nullFrame =  new awt2swing.Frame ();
31 this.nullFrame.addNotify ();
32 this.sr =  new jalview.appletgui.SequenceRenderer (this.av);
33 this.sr.graphics = this.nullFrame.getGraphics ();
34 this.sr.renderGaps = false;
35 this.sr.forOverview = true;
36 this.fr =  new jalview.appletgui.FeatureRenderer (this.av);
37 var initialScale = this.av.getAlignment ().getWidth () / this.av.getAlignment ().getHeight ();
38 if (this.av.getSequenceConsensusHash () == null) {
39 this.graphHeight = 0;
40 }if (this.av.getAlignment ().getWidth () > this.av.getAlignment ().getHeight ()) {
41 this.$width = 400;
42 this.sequencesHeight = Clazz.floatToInt (400 / initialScale);
43 if (this.sequencesHeight < 40) {
44 this.sequencesHeight = 40;
45 }} else {
46 this.$width = Clazz.floatToInt (400 * initialScale);
47 this.sequencesHeight = 300;
48 if (this.$width < 120) {
49 this.$width = 120;
50 }}this.setSize ( new java.awt.Dimension (this.$width, this.sequencesHeight + this.graphHeight));
51 this.addComponentListener (((Clazz.isClassDefined ("jalview.appletgui.OverviewPanel$1") ? 0 : jalview.appletgui.OverviewPanel.$OverviewPanel$1$ ()), Clazz.innerTypeInstance (jalview.appletgui.OverviewPanel$1, this, null)));
52 this.addMouseMotionListener (this);
53 this.addMouseListener (this);
54 this.updateOverviewImage ();
55 }, "jalview.appletgui.AlignmentPanel");
56 Clazz.overrideMethod (c$, "mouseEntered", 
57 function (evt) {
58 }, "java.awt.event.MouseEvent");
59 Clazz.overrideMethod (c$, "mouseExited", 
60 function (evt) {
61 }, "java.awt.event.MouseEvent");
62 Clazz.overrideMethod (c$, "mouseClicked", 
63 function (evt) {
64 }, "java.awt.event.MouseEvent");
65 Clazz.overrideMethod (c$, "mouseMoved", 
66 function (evt) {
67 }, "java.awt.event.MouseEvent");
68 Clazz.overrideMethod (c$, "mousePressed", 
69 function (evt) {
70 this.boxX = evt.getX ();
71 this.boxY = evt.getY ();
72 this.checkValid ();
73 }, "java.awt.event.MouseEvent");
74 Clazz.overrideMethod (c$, "mouseReleased", 
75 function (evt) {
76 this.boxX = evt.getX ();
77 this.boxY = evt.getY ();
78 this.checkValid ();
79 }, "java.awt.event.MouseEvent");
80 Clazz.overrideMethod (c$, "mouseDragged", 
81 function (evt) {
82 this.boxX = evt.getX ();
83 this.boxY = evt.getY ();
84 this.checkValid ();
85 }, "java.awt.event.MouseEvent");
86 Clazz.defineMethod (c$, "checkValid", 
87 function () {
88 if (this.boxY < 0) {
89 this.boxY = 0;
90 }if (this.boxY > (this.sequencesHeight - this.boxHeight)) {
91 this.boxY = this.sequencesHeight - this.boxHeight + 1;
92 }if (this.boxX < 0) {
93 this.boxX = 0;
94 }if (this.boxX > (this.$width - this.boxWidth)) {
95 if (this.av.hasHiddenColumns ()) {
96 this.boxWidth = Clazz.floatToInt ((this.av.endRes - this.av.startRes + 1) * this.av.getCharWidth () * this.scalew);
97 }this.boxX = this.$width - this.boxWidth;
98 }var col = Clazz.floatToInt (this.boxX / this.scalew / this.av.getCharWidth ());
99 var row = Clazz.floatToInt (this.boxY / this.scaleh / this.av.getCharHeight ());
100 if (this.av.hasHiddenColumns ()) {
101 if (!this.av.getColumnSelection ().isVisible (col)) {
102 return;
103 }col = this.av.getColumnSelection ().findColumnPosition (col);
104 }if (this.av.hasHiddenRows ()) {
105 row = this.av.getAlignment ().getHiddenSequences ().findIndexWithoutHiddenSeqs (row);
106 }this.ap.setScrollValues (col, row);
107 this.ap.paintAlignment (false);
108 });
109 Clazz.defineMethod (c$, "updateOverviewImage", 
110 function () {
111 if (this.resizing) {
112 this.resizeAgain = true;
113 return;
114 }if (this.av.isShowSequenceFeatures ()) {
115 this.fr.transferSettings (this.ap.seqPanel.seqCanvas.fr);
116 }this.resizing = true;
117 if ((this.getSize ().width > 0) && (this.getSize ().height > 0)) {
118 this.$width = this.getSize ().width;
119 this.sequencesHeight = this.getSize ().height - this.graphHeight;
120 }this.setSize ( new java.awt.Dimension (this.$width, this.sequencesHeight + this.graphHeight));
121 var thread =  new Thread (this);
122 thread.start ();
123 this.repaint ();
124 });
125 Clazz.overrideMethod (c$, "run", 
126 function () {
127 this.miniMe = null;
128 var alwidth = this.av.getAlignment ().getWidth ();
129 var alheight = this.av.getAlignment ().getHeight ();
130 if (this.av.isShowSequenceFeatures ()) {
131 this.fr.transferSettings (this.ap.seqPanel.seqCanvas.getFeatureRenderer ());
132 }if (this.getSize ().width > 0 && this.getSize ().height > 0) {
133 this.$width = this.getSize ().width;
134 this.sequencesHeight = this.getSize ().height - this.graphHeight;
135 }this.setSize ( new java.awt.Dimension (this.$width, this.sequencesHeight + this.graphHeight));
136 var fullsizeWidth = alwidth * this.av.getCharWidth ();
137 var fullsizeHeight = alheight * this.av.getCharHeight ();
138 this.scalew = this.$width / fullsizeWidth;
139 this.scaleh = this.sequencesHeight / fullsizeHeight;
140 this.miniMe = this.nullFrame.createImage (this.$width, this.sequencesHeight + this.graphHeight);
141 this.offscreen = this.nullFrame.createImage (this.$width, this.sequencesHeight + this.graphHeight);
142 var mg = this.miniMe.getGraphics ();
143 var sampleCol = alwidth / this.$width;
144 var sampleRow = alheight / this.sequencesHeight;
145 var lastcol = 0;
146 var lastrow = 0;
147 var xstart = 0;
148 var ystart = 0;
149 var color = java.awt.Color.yellow;
150 var row;
151 var col;
152 var sameRow = 0;
153 var sameCol = 0;
154 var seq;
155 var hasHiddenRows = this.av.hasHiddenRows ();
156 var hasHiddenCols = this.av.hasHiddenColumns ();
157 var hiddenRow = false;
158 var alignment = this.av.getAlignment ();
159 for (row = 0; row <= this.sequencesHeight; row++) {
160 if (Clazz.floatToInt (row * sampleRow) == lastrow) {
161 sameRow++;
162 continue;
163 }hiddenRow = false;
164 if (hasHiddenRows) {
165 seq = alignment.getHiddenSequences ().getHiddenSequence (lastrow);
166 if (seq == null) {
167 var index = alignment.getHiddenSequences ().findIndexWithoutHiddenSeqs (lastrow);
168 seq = alignment.getSequenceAt (index);
169 } else {
170 hiddenRow = true;
171 }} else {
172 seq = alignment.getSequenceAt (lastrow);
173 }for (col = 0; col < this.$width; col++) {
174 if (Clazz.floatToInt (col * sampleCol) == lastcol && Clazz.floatToInt (row * sampleRow) == lastrow) {
175 sameCol++;
176 continue;
177 }lastcol = Clazz.floatToInt (col * sampleCol);
178 if (seq.getLength () > lastcol) {
179 color = this.sr.getResidueBoxColour (seq, lastcol);
180 if (this.av.isShowSequenceFeatures ()) {
181 color = this.fr.findFeatureColour (color, seq, lastcol);
182 }} else {
183 color = java.awt.Color.white;
184 }if (hiddenRow || (hasHiddenCols && !this.av.getColumnSelection ().isVisible (lastcol))) {
185 color = color.darker ().darker ();
186 }mg.setColor (color);
187 if (sameCol == 1 && sameRow == 1) {
188 mg.drawLine (xstart, ystart, xstart, ystart);
189 } else {
190 mg.fillRect (xstart, ystart, sameCol, sameRow);
191 }xstart = col;
192 sameCol = 1;
193 }
194 lastrow = Clazz.floatToInt (row * sampleRow);
195 ystart = row;
196 sameRow = 1;
197 }
198 if (this.av.getAlignmentConservationAnnotation () != null) {
199 for (col = 0; col < this.$width; col++) {
200 lastcol = Clazz.floatToInt (col * sampleCol);
201 {
202 mg.translate (col, this.sequencesHeight);
203 this.ap.annotationPanel.renderer.drawGraph (mg, this.av.getAlignmentConservationAnnotation (), this.av.getAlignmentConservationAnnotation ().annotations, Clazz.floatToInt (sampleCol) + 1, this.graphHeight, Clazz.floatToInt (col * sampleCol), Clazz.floatToInt (col * sampleCol) + 1);
204 mg.translate (-col, -this.sequencesHeight);
205 }}
206 }System.gc ();
207 this.resizing = false;
208 this.setBoxPosition ();
209 if (this.resizeAgain) {
210 this.resizeAgain = false;
211 this.updateOverviewImage ();
212 }});
213 Clazz.defineMethod (c$, "setBoxPosition", 
214 function () {
215 var fullsizeWidth = this.av.getAlignment ().getWidth () * this.av.getCharWidth ();
216 var fullsizeHeight = (this.av.getAlignment ().getHeight () + this.av.getAlignment ().getHiddenSequences ().getSize ()) * this.av.getCharHeight ();
217 var startRes = this.av.getStartRes ();
218 var endRes = this.av.getEndRes ();
219 if (this.av.hasHiddenColumns ()) {
220 startRes = this.av.getColumnSelection ().adjustForHiddenColumns (startRes);
221 endRes = this.av.getColumnSelection ().adjustForHiddenColumns (endRes);
222 }var startSeq = this.av.startSeq;
223 var endSeq = this.av.endSeq;
224 if (this.av.hasHiddenRows ()) {
225 startSeq = this.av.getAlignment ().getHiddenSequences ().adjustForHiddenSeqs (startSeq);
226 endSeq = this.av.getAlignment ().getHiddenSequences ().adjustForHiddenSeqs (endSeq);
227 }this.scalew = this.$width / fullsizeWidth;
228 this.scaleh = this.sequencesHeight / fullsizeHeight;
229 this.boxX = Clazz.floatToInt (startRes * this.av.getCharWidth () * this.scalew);
230 this.boxY = Clazz.floatToInt (startSeq * this.av.getCharHeight () * this.scaleh);
231 if (this.av.hasHiddenColumns ()) {
232 this.boxWidth = Clazz.floatToInt ((endRes - startRes + 1) * this.av.getCharWidth () * this.scalew);
233 } else {
234 this.boxWidth = Clazz.floatToInt ((endRes - startRes + 1) * this.av.getCharWidth () * this.scalew);
235 }this.boxHeight = Clazz.floatToInt ((endSeq - startSeq) * this.av.getCharHeight () * this.scaleh);
236 this.repaint ();
237 });
238 Clazz.overrideMethod (c$, "update", 
239 function (g) {
240 this.paint (g);
241 }, "java.awt.Graphics");
242 Clazz.overrideMethod (c$, "paintComponent", 
243 function (g) {
244 var og = this.offscreen.getGraphics ();
245 if (this.miniMe != null) {
246 og.drawImage (this.miniMe, 0, 0, this);
247 og.setColor (java.awt.Color.red);
248 og.drawRect (this.boxX, this.boxY, this.boxWidth, this.boxHeight);
249 og.drawRect (this.boxX + 1, this.boxY + 1, this.boxWidth - 2, this.boxHeight - 2);
250 g.drawImage (this.offscreen, 0, 0, this);
251 }}, "java.awt.Graphics");
252 c$.$OverviewPanel$1$ = function () {
253 Clazz.pu$h ();
254 c$ = Clazz.declareAnonymous (jalview.appletgui, "OverviewPanel$1", java.awt.event.ComponentAdapter);
255 Clazz.overrideMethod (c$, "componentResized", 
256 function (evt) {
257 if (this.b$["jalview.appletgui.OverviewPanel"].getSize ().width != this.b$["jalview.appletgui.OverviewPanel"].$width || this.b$["jalview.appletgui.OverviewPanel"].getSize ().height != this.b$["jalview.appletgui.OverviewPanel"].sequencesHeight + this.b$["jalview.appletgui.OverviewPanel"].graphHeight) {
258 this.b$["jalview.appletgui.OverviewPanel"].updateOverviewImage ();
259 }}, "java.awt.event.ComponentEvent");
260 c$ = Clazz.p0p ();
261 };
262 });