2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
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
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
21 package jalview.javascript;
23 import jalview.appletgui.AlignFrame;
24 import jalview.appletgui.AlignViewport;
25 import jalview.bin.JalviewLite;
26 import jalview.datamodel.ColumnSelection;
27 import jalview.datamodel.SequenceGroup;
28 import jalview.structure.SelectionListener;
29 import jalview.structure.SelectionSource;
31 import netscape.javascript.JSException;
33 public class JsSelectionSender extends JSFunctionExec implements
34 SelectionListener, JsCallBack
41 public JsSelectionSender(JalviewLite jvlite, AlignFrame af,
50 public void selection(SequenceGroup seqsel, ColumnSelection colsel,
51 SelectionSource source)
53 // System.err.println("Testing selection event relay to jsfunction:"+_listener);
61 if (source instanceof AlignViewport
62 && ((AlignViewport) source).applet.currentAlignFrame.viewport == source)
64 // should be valid if it just generated an event!
65 src = ((AlignViewport) source).applet.currentAlignFrame;
69 String[] seqs = new String[]
71 String[] cols = new String[]
73 int strt = 0, end = (src == null) ? -1 : src.alignPanel.av
74 .getAlignment().getWidth();
75 if (seqsel != null && seqsel.getSize() > 0)
77 seqs = new String[seqsel.getSize()];
78 for (int i = 0; i < seqs.length; i++)
80 seqs[i] = seqsel.getSequenceAt(i).getName();
82 if (strt < seqsel.getStartRes())
84 strt = seqsel.getStartRes();
86 if (end == -1 || end > seqsel.getEndRes())
88 end = seqsel.getEndRes();
91 if (colsel != null && colsel.size() > 0)
95 end = colsel.getMax() + 1;
97 cols = new String[colsel.getSelected().size()];
99 for (int i = 0; i < cols.length; i++)
102 + (1 + colsel.getSelected().elementAt(i)
108 if (seqsel != null && seqsel.getSize() > 0)
110 // send a valid range, otherwise we send the empty selection
111 cols = new String[2];
112 cols[0] = "" + (1 + strt) + "-" + (1 + end);
117 System.err.println("Relaying selection to jsfunction:" + _listener);
118 executeJavascriptFunction(
121 { src, setid, jvlite.arrayToSeparatorList(seqs),
122 jvlite.arrayToSeparatorList(cols) });
123 } catch (Exception ex)
126 .println("Jalview Javascript exec error: Couldn't send selection message using function '"
128 ex.printStackTrace();
129 if (ex instanceof netscape.javascript.JSException)
131 System.err.println("Javascript Exception: "
132 + ((netscape.javascript.JSException) ex).getCause()
140 public AlignFrame getAlignFrame()
146 public String getListenerFunction()