2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2007 - INRIA - Bruno JOFRET
4 * Copyright (C) 2011 - DIGITEO - Bruno JOFRET
6 * This file must be used under the terms of the CeCILL.
7 * This source file is licensed as described in the file COPYING, which
8 * you should have received as part of this distribution. The terms
9 * are also available at
10 * http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt
14 package org.scilab.modules.gui.events;
16 import java.awt.Component;
17 import java.awt.MouseInfo;
18 import java.awt.event.MouseEvent;
20 import org.scilab.modules.gui.utils.SciTranslator;
23 * This class is to manage Events as Scilab used to.
24 * Means we need a global overview for a little set of them
25 * in particular "event waiting" functions.
26 * @author Bruno Jofret
28 public class GlobalEventFilter {
30 private static final int SCILAB_CALLBACK = -2;
35 protected GlobalEventFilter() {
36 throw new UnsupportedOperationException();
40 * Update ClickInfos structure when a KeyEvent occurs.
42 * @param keyPressed : the key pressed.
43 * @param figureUID Scilab ID of the figure where the even occurred
44 * @param isControlDown : is CTRL key modifier activated.
46 public static void filterKey(int keyPressed, Integer figureUID, boolean isControlDown, Component source) {
47 synchronized (ClickInfos.getInstance()) {
48 ClickInfos.getInstance().setMouseButtonNumber(SciTranslator.javaKey2Scilab(keyPressed, isControlDown));
49 ClickInfos.getInstance().setWindowID(figureUID);
50 ClickInfos.getInstance().setXCoordinate(MouseInfo.getPointerInfo().getLocation().x - source.getLocationOnScreen().getX());
51 ClickInfos.getInstance().setYCoordinate(MouseInfo.getPointerInfo().getLocation().y - source.getLocationOnScreen().getY());
52 ClickInfos.getInstance().notify();
57 * Update ClickInfos structure when some callback is about to be called.
59 * @param command : the callback that was supposed to be called.
61 public static void filterCallback(String command) {
62 synchronized (ClickInfos.getInstance()) {
63 ClickInfos.getInstance().setMouseButtonNumber(SCILAB_CALLBACK);
64 ClickInfos.getInstance().setMenuCallback(command);
65 ClickInfos.getInstance().setWindowID(0);
66 ClickInfos.getInstance().setXCoordinate(-1);
67 ClickInfos.getInstance().setYCoordinate(-1);
68 ClickInfos.getInstance().notify();
73 * Update ClickInfos structure when some callback is about to be called.
75 * @param command : the callback that was supposed to be called.
76 * @param returnCode : used for closing windows.
77 * @param figureUID : the figure ID where callback occurred.
79 public static void filterCallback(String command, int returnCode, Integer figureUID) {
80 synchronized (ClickInfos.getInstance()) {
81 ClickInfos.getInstance().setMouseButtonNumber(returnCode);
82 ClickInfos.getInstance().setMenuCallback(command);
83 ClickInfos.getInstance().setWindowID(figureUID);
84 ClickInfos.getInstance().setXCoordinate(-1);
85 ClickInfos.getInstance().setYCoordinate(-1);
86 ClickInfos.getInstance().notify();
90 * Update ClickInfos structure when a mouse event occurs on a Canvas.
92 * @param mouseEvent the event caught.
93 * @param axesUID the axes where the event occurs.
94 * @param buttonAction the Scilab button code mean PRESSED / RELEASED / CLICKED / DCLICKED.
95 * @param isControlDown true if the CTRL key has been pressed
97 public static void filterMouse(MouseEvent mouseEvent, Integer axesUID, int buttonAction, boolean isControlDown) {
98 if (axesUID != null) {
99 synchronized (ClickInfos.getInstance()) {
100 ClickInfos.getInstance().setMouseButtonNumber(
101 SciTranslator.javaButton2Scilab(mouseEvent.getButton(), buttonAction, isControlDown)
103 ClickInfos.getInstance().setWindowID(axesUID);
105 ClickInfos.getInstance().setXCoordinate(mouseEvent.getX());
106 ClickInfos.getInstance().setYCoordinate(mouseEvent.getY());
107 } catch (Exception e) {
108 ClickInfos.getInstance().setXCoordinate(mouseEvent.getX());
109 ClickInfos.getInstance().setYCoordinate(mouseEvent.getY());
111 ClickInfos.getInstance().notify();