2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2007 - INRIA - Bruno Jofret
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
12 package org.scilab.modules.gui.events;
14 import java.awt.AWTEvent;
15 import java.awt.event.KeyEvent;
16 import java.awt.event.MouseEvent;
18 import org.scilab.modules.gui.bridge.tab.SwingScilabAxes;
19 import org.scilab.modules.gui.utils.SciTranslator;
22 * This class implements the xclick Scilab method
23 * by updating the ClickInfos attributes.
24 * @author Bruno Jofret
26 public final class Jxclick {
28 private static int keyChar;
32 * We do not want a Jxclick object.
37 * Scilab call point for xclick.
39 public static void xclick() {
41 * Enable the local keyActionFilter function
42 * to be called when a keyEvent is caught.
44 GlobalEventWatcher.enable(new GlobalKeyEventWatcher() {
45 public void keyEventFilter(KeyEvent keyEvent) {
46 keyActionFilter(keyEvent);
50 * Enable the local mouseActionFilter function
51 * to be called when a mouseEvent is caught.
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);
59 synchronized (ClickInfos.getInstance()) {
61 ClickInfos.getInstance().init();
62 ClickInfos.getInstance().wait();
63 } catch (InterruptedException e) {
64 // TODO Auto-generated catch block
68 GlobalEventWatcher.disable();
72 * @return the mouseButtonNumber
74 public static int getMouseButtonNumber() {
75 return ClickInfos.getInstance().getMouseButtonNumber();
78 * @return the xCoordinate
80 public static double getXCoordinate() {
81 return ClickInfos.getInstance().getXCoordinate();
84 * @return the yCoordinate
86 public static double getYCoordinate() {
87 return ClickInfos.getInstance().getYCoordinate();
90 * @return the windowID
92 public static int getWindowID() {
93 return ClickInfos.getInstance().getWindowID();
96 * @return the menuCallback
98 public static String getMenuCallback() {
99 return ClickInfos.getInstance().getMenuCallback();
103 * Manage xclick behaviour for keyboard entry.
104 * 1 - Key has been pressed.
105 * 2 - CTRL + Key has been pressed.
107 * @param keyEvent : the Key Event caught
109 private static void keyActionFilter(KeyEvent keyEvent) {
110 if (keyEvent.getID() == KeyEvent.KEY_PRESSED) {
111 if (!Character.isJavaIdentifierStart(keyEvent.getKeyChar())) {
112 keyChar = keyEvent.getKeyChar();
115 if (keyEvent.isShiftDown()) {
116 keyChar = keyEvent.getKeyCode();
119 keyChar = Character.toLowerCase(keyEvent.getKeyCode());
123 else if (keyEvent.getID() == KeyEvent.KEY_TYPED) {
124 if (keyEvent.getSource() instanceof SwingScilabAxes) {
125 if (GlobalEventWatcher.isActivated()) {
126 GlobalEventFilter.filterKey(keyChar, ((SwingScilabAxes)keyEvent.getSource()).getFigureId(),((KeyEvent) keyEvent).isControlDown());
132 * Manage xclick behaviour for mouse entry.
134 * @param mouseEvent : the Mouse Event caught
135 * @param scilabMouseAction : the integer scilab code for mouse action.
136 * @param axes : the axes where action occurs.
137 * @param isControlDown true if the CTRL key has been pressed
139 private static void mouseActionFilter(MouseEvent mouseEvent, SwingScilabAxes axes, int scilabMouseAction, boolean isControlDown) {
140 if (scilabMouseAction == SciTranslator.PRESSED
141 || scilabMouseAction == SciTranslator.CLICKED
142 || scilabMouseAction == SciTranslator.DCLICKED) {
143 GlobalEventFilter.filterMouse(mouseEvent, axes, scilabMouseAction, isControlDown);