JAL-1807 test
[jalviewjs.git] / bin / jalview / appletgui / IdPanel.js
1 Clazz.declarePackage ("jalview.appletgui");
2 Clazz.load (["awt2swing.Panel", "java.awt.event.MouseListener", "$.MouseMotionListener", "java.lang.Thread", "java.util.Vector"], "jalview.appletgui.IdPanel", ["jalview.appletgui.APopupMenu", "$.IdCanvas", "$.PaintRefresher", "$.Tooltip", "jalview.datamodel.SequenceGroup", "jalview.util.UrlLink", "java.awt.BorderLayout", "java.lang.Float", "$.StringBuffer"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.idCanvas = null;
5 this.av = null;
6 this.alignPanel = null;
7 this.scrollThread = null;
8 this.lastid = -1;
9 this.mouseDragging = false;
10 this.links = null;
11 this.tooltip = null;
12 if (!Clazz.isClassDefined ("jalview.appletgui.IdPanel.ScrollThread")) {
13 jalview.appletgui.IdPanel.$IdPanel$ScrollThread$ ();
14 }
15 Clazz.instantialize (this, arguments);
16 }, jalview.appletgui, "IdPanel", awt2swing.Panel, [java.awt.event.MouseListener, java.awt.event.MouseMotionListener]);
17 Clazz.prepareFields (c$, function () {
18 this.links =  new java.util.Vector ();
19 });
20 Clazz.makeConstructor (c$, 
21 function (av, parent) {
22 Clazz.superConstructor (this, jalview.appletgui.IdPanel, []);
23 this.setName ("idPanel");
24 this.av = av;
25 this.alignPanel = parent;
26 this.idCanvas =  new jalview.appletgui.IdCanvas (av);
27 this.setLayout ( new java.awt.BorderLayout ());
28 this.add (this.idCanvas, "Center");
29 this.idCanvas.addMouseListener (this);
30 this.idCanvas.addMouseMotionListener (this);
31 if (av.applet != null) {
32 av.applet.getLinkParams (this.links);
33 }{
34 var srsPos = this.links.indexOf ("SRS|http://srs.ebi.ac.uk/srsbin/cgi-bin/wgetz?-newId+(([uniprot-all:$SEQUENCE_ID$]))+-view+SwissEntry");
35 if (srsPos > -1) {
36 this.links.setElementAt ("EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$", srsPos);
37 }}if (this.links.size () < 1) {
38 this.links =  new java.util.Vector ();
39 this.links.addElement ("EMBL-EBI Search|http://www.ebi.ac.uk/ebisearch/search.ebi?db=allebi&query=$SEQUENCE_ID$");
40 }}, "jalview.appletgui.AlignViewport,jalview.appletgui.AlignmentPanel");
41 Clazz.overrideMethod (c$, "mouseMoved", 
42 function (e) {
43 var seq = this.alignPanel.seqPanel.findSeq (e);
44 var sequence = this.av.getAlignment ().getSequenceAt (seq);
45 var tooltiptext =  new StringBuffer ();
46 if (sequence != null) {
47 if (sequence.getDescription () != null) {
48 tooltiptext.append (sequence.getDescription ());
49 tooltiptext.append ("\n");
50 }var sf = sequence.getSequenceFeatures ();
51 for (var sl = 0; sf != null && sl < sf.length; sl++) {
52 if (sf[sl].begin == sf[sl].end && sf[sl].begin == 0) {
53 var nl = false;
54 if (sf[sl].getFeatureGroup () != null) {
55 tooltiptext.append (sf[sl].getFeatureGroup ());
56 nl = true;
57 };if (sf[sl].getType () != null) {
58 tooltiptext.append (" ");
59 tooltiptext.append (sf[sl].getType ());
60 nl = true;
61 };if (sf[sl].getDescription () != null) {
62 tooltiptext.append (" ");
63 tooltiptext.append (sf[sl].getDescription ());
64 nl = true;
65 };if (!Float.isNaN (sf[sl].getScore ()) && sf[sl].getScore () != 0) {
66 tooltiptext.append (" Score = ");
67 tooltiptext.append (sf[sl].getScore ());
68 nl = true;
69 };if (sf[sl].getStatus () != null && sf[sl].getStatus ().length > 0) {
70 tooltiptext.append (" (");
71 tooltiptext.append (sf[sl].getStatus ());
72 tooltiptext.append (")");
73 nl = true;
74 };if (nl) {
75 tooltiptext.append ("\n");
76 }}}
77 }if (tooltiptext.length () == 0) {
78 if (this.tooltip != null) {
79 this.tooltip.setVisible (false);
80 }this.tooltip = null;
81 tooltiptext = null;
82 return;
83 }if (this.tooltip == null) {
84 this.tooltip =  new jalview.appletgui.Tooltip (sequence.getDisplayId (true) + "\n" + tooltiptext.toString (), this.idCanvas);
85 } else {
86 this.tooltip.setTip (sequence.getDisplayId (true) + "\n" + tooltiptext.toString ());
87 }tooltiptext = null;
88 }, "java.awt.event.MouseEvent");
89 Clazz.overrideMethod (c$, "mouseDragged", 
90 function (e) {
91 this.mouseDragging = true;
92 var seq = Math.max (0, this.alignPanel.seqPanel.findSeq (e));
93 if (seq < this.lastid) {
94 this.selectSeqs (this.lastid - 1, seq);
95 } else if (seq > this.lastid) {
96 this.selectSeqs (this.lastid + 1, seq);
97 }this.lastid = seq;
98 this.alignPanel.paintAlignment (false);
99 }, "java.awt.event.MouseEvent");
100 Clazz.overrideMethod (c$, "mouseClicked", 
101 function (e) {
102 if (e.getClickCount () < 2) {
103 return;
104 }var seq = this.alignPanel.seqPanel.findSeq (e);
105 var sq = this.av.getAlignment ().getSequenceAt (seq);
106 if (sq == null) {
107 return;
108 }var id = sq.getName ();
109 var target = null;
110 var url = null;
111 var i = 0;
112 while (url == null && i < this.links.size ()) {
113 url = this.links.elementAt (i++).toString ();
114 var urlLink = null;
115 try {
116 urlLink =  new jalview.util.UrlLink (url);
117 target = urlLink.getTarget ();
118 } catch (foo) {
119 if (Clazz.exceptionOf (foo, Exception)) {
120 System.err.println ("Exception for URLLink '" + url + "'");
121 foo.printStackTrace ();
122 url = null;
123 continue;
124 } else {
125 throw foo;
126 }
127 }
128 ;if (!urlLink.isValid ()) {
129 System.err.println (urlLink.getInvalidMessage ());
130 url = null;
131 continue;
132 }var urls = urlLink.makeUrls (id, true);
133 if (urls == null || urls[0] == null || urls[0].length < 1) {
134 url = null;
135 continue;
136 }url = urls[1];
137 }
138 try {
139 this.alignPanel.alignFrame.showURL (url, target);
140 } catch (ex) {
141 if (Clazz.exceptionOf (ex, Exception)) {
142 ex.printStackTrace ();
143 } else {
144 throw ex;
145 }
146 }
147 }, "java.awt.event.MouseEvent");
148 Clazz.overrideMethod (c$, "mouseEntered", 
149 function (e) {
150 if (this.scrollThread != null) {
151 this.scrollThread.running = false;
152 }}, "java.awt.event.MouseEvent");
153 Clazz.overrideMethod (c$, "mouseExited", 
154 function (e) {
155 if (this.av.getWrapAlignment ()) {
156 return;
157 }if (this.mouseDragging && e.getY () < 0 && this.av.getStartSeq () > 0) {
158 this.scrollThread = Clazz.innerTypeInstance (jalview.appletgui.IdPanel.ScrollThread, this, null, true);
159 }if (this.mouseDragging && e.getY () >= this.getSize ().height && this.av.getAlignment ().getHeight () > this.av.getEndSeq ()) {
160 this.scrollThread = Clazz.innerTypeInstance (jalview.appletgui.IdPanel.ScrollThread, this, null, false);
161 }}, "java.awt.event.MouseEvent");
162 Clazz.overrideMethod (c$, "mousePressed", 
163 function (e) {
164 if (e.getClickCount () > 1) {
165 return;
166 }var y = e.getY ();
167 if (this.av.getWrapAlignment ()) {
168 y -= 2 * this.av.getCharHeight ();
169 }var seq = this.alignPanel.seqPanel.findSeq (e);
170 if ((e.getModifiers () & 4) == 4) {
171 var sq = this.av.getAlignment ().getSequenceAt (seq);
172 var nlinks =  new java.util.Vector ();
173 for (var l = 0, lSize = this.links.size (); l < lSize; l++) {
174 nlinks.addElement (this.links.elementAt (l));
175 }
176 var sf = sq == null ? null : sq.getSequenceFeatures ();
177 for (var sl = 0; sf != null && sl < sf.length; sl++) {
178 if (sf[sl].begin == sf[sl].end && sf[sl].begin == 0) {
179 if (sf[sl].links != null && sf[sl].links.size () > 0) {
180 for (var l = 0, lSize = sf[sl].links.size (); l < lSize; l++) {
181 nlinks.addElement (sf[sl].links.elementAt (l));
182 }
183 }}}
184 var popup =  new jalview.appletgui.APopupMenu (this.alignPanel, sq, nlinks);
185 this.add (popup);
186 popup.show (this, e.getX (), e.getY ());
187 return;
188 }if ((this.av.getSelectionGroup () == null) || ((!e.isControlDown () && !e.isShiftDown ()) && this.av.getSelectionGroup () != null)) {
189 this.av.setSelectionGroup ( new jalview.datamodel.SequenceGroup ());
190 this.av.getSelectionGroup ().setStartRes (0);
191 this.av.getSelectionGroup ().setEndRes (this.av.getAlignment ().getWidth () - 1);
192 }if (e.isShiftDown () && this.lastid != -1) {
193 this.selectSeqs (this.lastid, seq);
194 } else {
195 this.selectSeq (seq);
196 }this.alignPanel.paintAlignment (false);
197 }, "java.awt.event.MouseEvent");
198 Clazz.defineMethod (c$, "selectSeq", 
199 function (seq) {
200 this.lastid = seq;
201 var pickedSeq = this.av.getAlignment ().getSequenceAt (seq);
202 this.av.getSelectionGroup ().addOrRemove (pickedSeq, true);
203 }, "~N");
204 Clazz.defineMethod (c$, "selectSeqs", 
205 function (start, end) {
206 this.lastid = start;
207 if (end >= this.av.getAlignment ().getHeight ()) {
208 end = this.av.getAlignment ().getHeight () - 1;
209 }if (end < start) {
210 var tmp = start;
211 start = end;
212 end = tmp;
213 this.lastid = end;
214 }if (this.av.getSelectionGroup () == null) {
215 this.av.setSelectionGroup ( new jalview.datamodel.SequenceGroup ());
216 }for (var i = start; i <= end; i++) {
217 this.av.getSelectionGroup ().addSequence (this.av.getAlignment ().getSequenceAt (i), i == end);
218 }
219 }, "~N,~N");
220 Clazz.overrideMethod (c$, "mouseReleased", 
221 function (e) {
222 if (this.scrollThread != null) {
223 this.scrollThread.running = false;
224 }if (this.av.getSelectionGroup () != null) {
225 this.av.getSelectionGroup ().recalcConservation ();
226 }this.mouseDragging = false;
227 jalview.appletgui.PaintRefresher.Refresh (this, this.av.getSequenceSetId ());
228 this.av.sendSelection ();
229 }, "java.awt.event.MouseEvent");
230 Clazz.defineMethod (c$, "highlightSearchResults", 
231 function (list) {
232 this.idCanvas.setHighlighted (list);
233 if (list == null) {
234 return;
235 }var index = this.av.getAlignment ().findIndex (list.get (0));
236 if (this.av.getStartSeq () > index || this.av.getEndSeq () < index) {
237 this.alignPanel.setScrollValues (this.av.getStartRes (), index);
238 }}, "java.util.List");
239 c$.$IdPanel$ScrollThread$ = function () {
240 Clazz.pu$h ();
241 c$ = Clazz.decorateAsClass (function () {
242 Clazz.prepareCallback (this, arguments);
243 this.running = false;
244 this.up = true;
245 Clazz.instantialize (this, arguments);
246 }, jalview.appletgui.IdPanel, "ScrollThread", Thread);
247 Clazz.makeConstructor (c$, 
248 function (a) {
249 Clazz.superConstructor (this, jalview.appletgui.IdPanel.ScrollThread, []);
250 this.up = a;
251 this.start ();
252 }, "~B");
253 Clazz.defineMethod (c$, "stopScrolling", 
254 function () {
255 this.running = false;
256 });
257 Clazz.overrideMethod (c$, "run", 
258 function () {
259 this.running = true;
260 while (this.running) {
261 if (this.b$["jalview.appletgui.IdPanel"].alignPanel.scrollUp (this.up)) {
262 var a = this.b$["jalview.appletgui.IdPanel"].av.getStartSeq ();
263 if (!this.up) {
264 a = this.b$["jalview.appletgui.IdPanel"].av.getEndSeq ();
265 }if (a < this.b$["jalview.appletgui.IdPanel"].lastid) {
266 this.b$["jalview.appletgui.IdPanel"].selectSeqs (this.b$["jalview.appletgui.IdPanel"].lastid - 1, a);
267 } else if (a > this.b$["jalview.appletgui.IdPanel"].lastid && a < this.b$["jalview.appletgui.IdPanel"].av.getAlignment ().getHeight ()) {
268 this.b$["jalview.appletgui.IdPanel"].selectSeqs (this.b$["jalview.appletgui.IdPanel"].lastid + 1, a);
269 }this.b$["jalview.appletgui.IdPanel"].lastid = a;
270 } else {
271 this.running = false;
272 }this.b$["jalview.appletgui.IdPanel"].alignPanel.paintAlignment (true);
273 try {
274 Thread.sleep (100);
275 } catch (ex) {
276 if (Clazz.exceptionOf (ex, Exception)) {
277 } else {
278 throw ex;
279 }
280 }
281 }
282 });
283 c$ = Clazz.p0p ();
284 };
285 });