Remove autogenerated comments
[scilab.git] / scilab / modules / gui / src / java / org / scilab / modules / gui / events / Jxclick.java
1 /*
2  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3  * Copyright (C) 2007 - INRIA - Bruno Jofret
4  * 
5  * This file must be used under the terms of the CeCILL.
6  * This source file is licensed as described in the file COPYING, which
7  * you should have received as part of this distribution.  The terms
8  * are also available at    
9  * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
10  *
11  */
12 package org.scilab.modules.gui.events;
13
14 import java.awt.AWTEvent;
15 import java.awt.event.KeyEvent;
16 import java.awt.event.MouseEvent;
17
18 import org.scilab.modules.gui.bridge.tab.SwingScilabAxes;
19 import org.scilab.modules.gui.utils.SciTranslator;
20
21 /**
22  * This class implements the xclick Scilab method
23  * by updating the ClickInfos attributes.
24  * @author Bruno Jofret
25  */
26 public final class Jxclick {
27
28         private static int keyChar;
29
30         /**
31          * PRIVATE constructor
32          * We do not want a Jxclick object.
33          */
34         private Jxclick() { }
35
36         /**
37          * Scilab call point for xclick.
38          */
39         public static void xclick() {
40                 /*
41                  *  Enable the local keyActionFilter function
42                  *  to be called when a keyEvent is caught.
43                  */     
44                 GlobalEventWatcher.enable(new GlobalKeyEventWatcher() {
45                         public void keyEventFilter(KeyEvent keyEvent) {
46                                 keyActionFilter(keyEvent);
47                         }
48                 });
49                 /*
50                  *  Enable the local mouseActionFilter function
51                  *  to be called when a mouseEvent is caught.
52                  */             
53                 GlobalEventWatcher.enable(new GlobalMouseEventWatcher(AWTEvent.MOUSE_EVENT_MASK) {
54                         public void mouseEventFilter(MouseEvent mouseEvent,
55                                         SwingScilabAxes axes, int scilabMouseAction, boolean isControlDown) {
56                                 mouseActionFilter(mouseEvent, axes, scilabMouseAction, isControlDown);  
57                         }
58                 });
59                 synchronized (ClickInfos.getInstance()) {
60                         try {
61                                 ClickInfos.getInstance().init();
62                                 ClickInfos.getInstance().wait();
63                         } catch (InterruptedException e) {
64                                 e.printStackTrace();
65                         }
66                 }
67                 GlobalEventWatcher.disable();
68         }
69
70         /**
71          * @return the mouseButtonNumber
72          */
73         public static int getMouseButtonNumber() {
74                 return ClickInfos.getInstance().getMouseButtonNumber();
75         }
76         /**
77          * @return the xCoordinate
78          */
79         public static double getXCoordinate() {
80                 return ClickInfos.getInstance().getXCoordinate();
81         }
82         /**
83          * @return the yCoordinate
84          */
85         public static double getYCoordinate() {
86                 return ClickInfos.getInstance().getYCoordinate();
87         }
88         /**
89          * @return the windowID
90          */
91         public static int getWindowID() {
92                 return ClickInfos.getInstance().getWindowID();
93         }
94         /**
95          * @return the menuCallback
96          */
97         public static String getMenuCallback() {
98                 return ClickInfos.getInstance().getMenuCallback();
99         }
100
101         /**
102          * Manage xclick behaviour for keyboard entry.
103          * 1 - Key has been pressed.
104          * 2 - CTRL + Key has been pressed.
105          * 
106          * @param keyEvent : the Key Event caught
107          */
108         private static void keyActionFilter(KeyEvent keyEvent) {        
109                 if (keyEvent.getID() == KeyEvent.KEY_PRESSED) {
110                         if (!Character.isJavaIdentifierStart(keyEvent.getKeyChar())) {
111                                 keyChar = keyEvent.getKeyChar(); 
112                         } 
113                         else {
114                                 if (keyEvent.isShiftDown()) {
115                                         keyChar = keyEvent.getKeyCode();
116                                 } 
117                                 else {
118                                         keyChar = Character.toLowerCase(keyEvent.getKeyCode());
119                                 }
120                         }
121                 } 
122                 else if (keyEvent.getID() == KeyEvent.KEY_TYPED) {      
123                         if (keyEvent.getSource() instanceof SwingScilabAxes) {
124                                 if (GlobalEventWatcher.isActivated()) {
125                                         GlobalEventFilter.filterKey(keyChar, ((SwingScilabAxes)keyEvent.getSource()).getFigureId(),((KeyEvent) keyEvent).isControlDown());
126                                 }
127                         }
128                 } 
129         }
130         /**
131          * Manage xclick behaviour for mouse entry.
132          * 
133          * @param mouseEvent : the Mouse Event caught
134          * @param scilabMouseAction : the integer scilab code for mouse action.
135          * @param axes : the axes where action occurs.
136          * @param isControlDown true if the CTRL key has been pressed
137          */
138         private static void mouseActionFilter(MouseEvent mouseEvent, SwingScilabAxes axes, int scilabMouseAction, boolean isControlDown) {      
139                 if (scilabMouseAction == SciTranslator.PRESSED
140                                 || scilabMouseAction == SciTranslator.CLICKED
141                                 || scilabMouseAction == SciTranslator.DCLICKED) {
142                         GlobalEventFilter.filterMouse(mouseEvent, axes, scilabMouseAction, isControlDown);
143                 }
144         }       
145 }