2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2007-2008 - 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
13 package org.scilab.modules.gui.utils;
16 * This class aims at converting Java constants that stay
17 * as user input : keychar, mouseclick, pressed, released...
18 * into scilab "standard" integer encryption.
22 public class SciTranslator {
24 * Those static final constant are only for reverse compatibility
30 * We add those statics state integers such as
31 * button + state = scilab return value.
33 * ex : left PRESSED = 1 + (-1) = 0
35 * MOVE does not feat the rule because
36 * it does not have any Button associated with.
38 /** Internal state PRESSED */
39 public static final int PRESSED = -1;
40 /** Internal state RELEASED */
41 public static final int RELEASED = -6;
42 /** Internal state CLICKED */
43 public static final int CLICKED = 2;
44 /** Internal state DCLICKED */
45 public static final int DCLICKED = 9;
47 * Internal state SCIMOVED
48 * differs from move because otherwise
49 * other clicks can raise such a code
51 public static final int SCIMOVED = -1;
52 /** Internal state CLOSE */
53 public static final int SCICLOSE = -1000;
55 /** Internal state MOVED */
56 public static final int MOVED = -1000;
57 /** Internal initial state */
58 public static final int UNMANAGED = -10000;
60 private static final int SCILAB_CTRL_OFFSET = 1000;
62 private static final int TIMETOSLEEP = 300;
64 private int clickAction = UNMANAGED;
66 public SciTranslator() {
67 clickAction = UNMANAGED;
70 public static int javaKey2Scilab(int keyPressed, boolean isControlDown) {
71 int keyCode = keyPressed;
73 keyCode += SCILAB_CTRL_OFFSET;
78 public static int javaButton2Scilab(int mouseEventButton, int buttonAction, boolean isControlDown) {
79 int buttonCode = mouseEventButton + buttonAction;
81 buttonCode += SCILAB_CTRL_OFFSET;
86 public void setClickAction(int newClickAction) {
87 clickAction = newClickAction;
90 public int getClickAction() {
94 public int javaClick2Scilab() {
99 } catch (InterruptedException e) {
102 return getClickAction();