update author list in license for (JAL-826)
[jalview.git] / src / jalview / javascript / MouseOverListener.java
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
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 of the License, or (at your option) any later version.
10  *
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.
15  *
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;
19
20 import java.util.Vector;
21
22 import jalview.appletgui.AlignFrame;
23 import jalview.bin.JalviewLite;
24 import jalview.datamodel.SequenceI;
25 import jalview.structure.VamsasListener;
26 import jalview.structure.VamsasSource;
27 import netscape.javascript.JSObject;
28
29 public class MouseOverListener extends JSFunctionExec implements
30         VamsasListener, JsCallBack
31 {
32   AlignFrame _af;
33
34   String _listener;
35
36   SequenceI last = null;
37
38   int i = -1;
39
40   public void mouseOver(SequenceI seq, int index, VamsasSource source)
41   {
42     if (seq != last || i != index)
43     {
44       // this should really be a trace message.
45       // Cache.log.debug("Mouse over " + v.getId() + " bound to "
46       // + seq + " at " + index);
47       last = seq;
48       i = index;
49       AlignFrame src = null;
50       try
51       {
52         if (source != null)
53         {
54           if (source instanceof jalview.appletgui.AlignViewport
55                   && ((jalview.appletgui.AlignViewport) source).applet.currentAlignFrame.viewport == source)
56           {
57             // should be valid if it just generated an event!
58             src = ((jalview.appletgui.AlignViewport) source).applet.currentAlignFrame;
59
60           }
61           // TODO: ensure that if '_af' is specified along with a handler function, then only events from that alignFrame are sent to that function
62         }
63         executeJavascriptFunction(_listener, new Object[]
64         { src, seq.getDisplayId(false), "" + (1 + i), ""+seq.findPosition(i) });
65       } catch (Exception ex)
66       {
67
68         System.err
69                 .println("JalviewLite javascript error: Couldn't send mouseOver with handler '"
70                         + _listener + "'");
71         if (ex instanceof netscape.javascript.JSException)
72         {
73           System.err.println("Javascript Exception: "
74                   + ((netscape.javascript.JSException) ex).getMessage());
75         }
76         ex.printStackTrace();
77       }
78     }
79   }
80
81   public MouseOverListener(JalviewLite applet, AlignFrame af,
82           String listener)
83   {
84     super(applet);
85     _af = af;
86     _listener = listener;
87   }
88
89   @Override
90   public AlignFrame getAlignFrame()
91   {
92     return _af;
93   }
94
95   @Override
96   public String getListenerFunction()
97   {
98     return _listener;
99   }
100
101 }