56efe701b120ddca9c70dd438d306ecaee3d9d73
[jalview.git] / src / jalview / javascript / JsSelectionSender.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
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.
11  *  
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.
16  * 
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.
20  */
21 package jalview.javascript;
22
23 import jalview.api.JalviewApp;
24 import jalview.appletgui.AlignFrame;
25 import jalview.datamodel.ColumnSelection;
26 import jalview.datamodel.HiddenColumns;
27 import jalview.datamodel.SequenceGroup;
28 import jalview.structure.SelectionSource;
29
30 public class JsSelectionSender extends JSFunctionExec
31         implements jalview.structure.SelectionListener, JsCallBack
32 {
33
34   AlignFrame _af;
35
36   String _listener;
37
38   public JsSelectionSender(JalviewApp jvlite, AlignFrame af,
39           String listener, boolean debug)
40   {
41     super(jvlite, debug);
42     _af = af;
43     _listener = listener;
44   }
45
46   @Override
47   public void selection(SequenceGroup seqsel, ColumnSelection colsel,
48           HiddenColumns hidden, SelectionSource source)
49   {
50     Object[] info = jvlite.getSelectionForListener(seqsel, colsel, hidden, source, _af);
51     try
52     {
53
54       System.err.println("Relaying selection to jsfunction:" + _listener);
55       executeJavascriptFunction(_listener, info);
56
57     } catch (Exception ex)
58     {
59       System.err.println(
60               "Jalview Javascript exec error: Couldn't send selection message using function '"
61                       + _listener + "'");
62       ex.printStackTrace();
63       if (ex instanceof netscape.javascript.JSException)
64       {
65         System.err.println("Javascript Exception: "
66                 + ((netscape.javascript.JSException) ex).getCause()
67                         .toString());
68       }
69
70     }
71
72   }
73
74   @Override
75   public AlignFrame getAlignFrame()
76   {
77     return _af;
78   }
79
80   @Override
81   public String getListenerFunction()
82   {
83     return _listener;
84   }
85
86 }