1 /*******************************************************************************
2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3 * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 *******************************************************************************/
18 package jalview.javascript;
21 import jalview.appletgui.AlignFrame;
22 import jalview.appletgui.AlignViewport;
23 import jalview.bin.JalviewLite;
24 import jalview.datamodel.ColumnSelection;
25 import jalview.datamodel.SequenceGroup;
26 import jalview.structure.SelectionSource;
27 import netscape.javascript.JSObject;
29 public class JsSelectionSender extends JSFunctionExec implements
30 jalview.structure.SelectionListener, JsCallBack
37 public JsSelectionSender(JalviewLite jvlite, AlignFrame af,
46 public void selection(SequenceGroup seqsel, ColumnSelection colsel,
47 SelectionSource source)
49 // System.err.println("Testing selection event relay to jsfunction:"+_listener);
57 if (source instanceof jalview.appletgui.AlignViewport
58 && ((jalview.appletgui.AlignViewport) source).applet.currentAlignFrame.viewport == source)
60 // should be valid if it just generated an event!
61 src = ((jalview.appletgui.AlignViewport) source).applet.currentAlignFrame;
65 String[] seqs = new String[]
67 String[] cols = new String[]
69 int strt = 0, end = (src == null) ? -1 : src.alignPanel.av
70 .getAlignment().getWidth();
71 if (seqsel != null && seqsel.getSize() > 0)
73 seqs = new String[seqsel.getSize()];
74 for (int i = 0; i < seqs.length; i++)
76 seqs[i] = seqsel.getSequenceAt(i).getName();
78 if (strt < seqsel.getStartRes())
80 strt = seqsel.getStartRes();
82 if (end==-1 || end > seqsel.getEndRes())
84 end = seqsel.getEndRes();
87 if (colsel != null && colsel.size() > 0)
91 end = colsel.getMax() + 1;
93 cols = new String[colsel.getSelected().size()];
95 for (int i = 0; i < cols.length; i++)
98 + (1 + ((Integer) colsel.getSelected().elementAt(i))
104 if (seqsel != null && seqsel.getSize() > 0)
106 // send a valid range, otherwise we send the empty selection
107 cols = new String[2];
108 cols[0] = "" + (1 + strt) + "-" + (1 + end);
113 System.err.println("Relaying selection to jsfunction:" + _listener);
114 executeJavascriptFunction( _listener,
116 { src, setid, jvlite.arrayToSeparatorList(seqs),
117 jvlite.arrayToSeparatorList(cols) });
118 } catch (Exception ex)
121 .println("Jalview Javascript exec error: Couldn't send selection message using function '"
123 ex.printStackTrace();
124 if (ex instanceof netscape.javascript.JSException)
126 System.err.println("Javascript Exception: "
127 + ((netscape.javascript.JSException) ex).getCause()
136 public AlignFrame getAlignFrame()
142 public String getListenerFunction()