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) {
67 GlobalEventWatcher.disable();
71 * @return the mouseButtonNumber
73 public static int getMouseButtonNumber() {
74 return ClickInfos.getInstance().getMouseButtonNumber();
77 * @return the xCoordinate
79 public static double getXCoordinate() {
80 return ClickInfos.getInstance().getXCoordinate();
83 * @return the yCoordinate
85 public static double getYCoordinate() {
86 return ClickInfos.getInstance().getYCoordinate();
89 * @return the windowID
91 public static int getWindowID() {
92 return ClickInfos.getInstance().getWindowID();
95 * @return the menuCallback
97 public static String getMenuCallback() {
98 return ClickInfos.getInstance().getMenuCallback();
102 * Manage xclick behaviour for keyboard entry.
103 * 1 - Key has been pressed.
104 * 2 - CTRL + Key has been pressed.
106 * @param keyEvent : the Key Event caught
108 private static void keyActionFilter(KeyEvent keyEvent) {
109 if (keyEvent.getID() == KeyEvent.KEY_PRESSED) {
110 if (!Character.isJavaIdentifierStart(keyEvent.getKeyChar())) {
111 keyChar = keyEvent.getKeyChar();
114 if (keyEvent.isShiftDown()) {
115 keyChar = keyEvent.getKeyCode();
118 keyChar = Character.toLowerCase(keyEvent.getKeyCode());
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());
131 * Manage xclick behaviour for mouse entry.
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
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);