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