summaryrefslogtreecommitdiffstats
path: root/scilab/modules
diff options
context:
space:
mode:
authorBruno JOFRET <bruno.jofret@scilab.org>2011-05-09 14:43:34 +0200
committerSylvestre Ledru <sylvestre.ledru@scilab.org>2011-05-09 15:08:45 +0200
commitef3eff2a6b154cd2e7450b1410d895d0b72015d5 (patch)
treeb5e29a7e990779a43ab5a77e9a20fb9927945a65 /scilab/modules
parentdaba6120a32c9c1b05a9ee88081731d145c7be47 (diff)
downloadscilab-ef3eff2a6b154cd2e7450b1410d895d0b72015d5.zip
scilab-ef3eff2a6b154cd2e7450b1410d895d0b72015d5.tar.gz
Fix BUG #9428: try to get location of some Component that is not showing.
Change-Id: Ia6376ed1c8d47a7f0942ad059b434e08e3d57ae1
Diffstat (limited to 'scilab/modules')
-rw-r--r--scilab/modules/gui/src/java/org/scilab/modules/gui/events/GlobalEventFilter.java127
1 files changed, 70 insertions, 57 deletions
diff --git a/scilab/modules/gui/src/java/org/scilab/modules/gui/events/GlobalEventFilter.java b/scilab/modules/gui/src/java/org/scilab/modules/gui/events/GlobalEventFilter.java
index bb17adc..8af8823 100644
--- a/scilab/modules/gui/src/java/org/scilab/modules/gui/events/GlobalEventFilter.java
+++ b/scilab/modules/gui/src/java/org/scilab/modules/gui/events/GlobalEventFilter.java
@@ -1,24 +1,25 @@
1package org.scilab.modules.gui.events;
2
3import java.awt.Component;
4import java.awt.MouseInfo;
5import java.awt.event.MouseEvent;
6
7import org.scilab.modules.gui.bridge.tab.SwingScilabAxes;
8import org.scilab.modules.gui.utils.SciTranslator;
9
10/* 1/*
11 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab 2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
12 * Copyright (C) 2007 - INRIA - Bruno Jofret 3 * Copyright (C) 2007 - INRIA - Bruno JOFRET
13 * 4 * Copyright (C) 2011 - DIGITEO - Bruno JOFRET
5 *
14 * This file must be used under the terms of the CeCILL. 6 * This file must be used under the terms of the CeCILL.
15 * This source file is licensed as described in the file COPYING, which 7 * This source file is licensed as described in the file COPYING, which
16 * you should have received as part of this distribution. The terms 8 * you should have received as part of this distribution. The terms
17 * are also available at 9 * are also available at
18 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt 10 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
19 * 11 *
20 */ 12 */
21 13
14package org.scilab.modules.gui.events;
15
16import java.awt.Component;
17import java.awt.MouseInfo;
18import java.awt.event.MouseEvent;
19
20import org.scilab.modules.gui.bridge.tab.SwingScilabAxes;
21import org.scilab.modules.gui.utils.SciTranslator;
22
22/** 23/**
23 * This class is to manage Events as Scilab used to. 24 * This class is to manage Events as Scilab used to.
24 * Means we need a global overview for a little set of them 25 * Means we need a global overview for a little set of them
@@ -33,82 +34,94 @@ public class GlobalEventFilter {
33 * Constructor 34 * Constructor
34 */ 35 */
35 protected GlobalEventFilter() { 36 protected GlobalEventFilter() {
36 throw new UnsupportedOperationException(); 37 throw new UnsupportedOperationException();
37 } 38 }
38 39
39 /** 40 /**
40 * Update ClickInfos structure when a KeyEvent occurs. 41 * Update ClickInfos structure when a KeyEvent occurs.
41 * 42 *
42 * @param keyPressed : the key pressed. 43 * @param keyPressed : the key pressed.
43 * @param figureID Scilab ID of the figure where the even occurred 44 * @param figureID Scilab ID of the figure where the even occurred
44 * @param isControlDown : is CTRL key modifier activated. 45 * @param isControlDown : is CTRL key modifier activated.
45 */ 46 */
46 public static void filterKey(int keyPressed, int figureID, boolean isControlDown) { 47 public static void filterKey(int keyPressed, int figureID, boolean isControlDown) {
47 synchronized (ClickInfos.getInstance()) { 48 synchronized (ClickInfos.getInstance()) {
48 ClickInfos.getInstance().setMouseButtonNumber(SciTranslator.javaKey2Scilab(keyPressed, isControlDown)); 49 ClickInfos.getInstance().setMouseButtonNumber(SciTranslator.javaKey2Scilab(keyPressed, isControlDown));
49 ClickInfos.getInstance().setWindowID(figureID); 50 ClickInfos.getInstance().setWindowID(figureID);
50 ClickInfos.getInstance().setXCoordinate(MouseInfo.getPointerInfo().getLocation().x); 51 ClickInfos.getInstance().setXCoordinate(MouseInfo.getPointerInfo().getLocation().x);
51 ClickInfos.getInstance().setYCoordinate(MouseInfo.getPointerInfo().getLocation().y); 52 ClickInfos.getInstance().setYCoordinate(MouseInfo.getPointerInfo().getLocation().y);
52 ClickInfos.getInstance().notify(); 53 ClickInfos.getInstance().notify();
53 } 54 }
54 } 55 }
55 56
56 /** 57 /**
57 * Update ClickInfos structure when some callback is about to be called. 58 * Update ClickInfos structure when some callback is about to be called.
58 * 59 *
59 * @param command : the callback that was supposed to be called. 60 * @param command : the callback that was supposed to be called.
60 */ 61 */
61 public static void filterCallback(String command) { 62 public static void filterCallback(String command) {
62 synchronized (ClickInfos.getInstance()) { 63 synchronized (ClickInfos.getInstance()) {
63 ClickInfos.getInstance().setMouseButtonNumber(SCILAB_CALLBACK); 64 ClickInfos.getInstance().setMouseButtonNumber(SCILAB_CALLBACK);
64 ClickInfos.getInstance().setMenuCallback(command); 65 ClickInfos.getInstance().setMenuCallback(command);
65 ClickInfos.getInstance().setWindowID(-1); 66 ClickInfos.getInstance().setWindowID(-1);
66 ClickInfos.getInstance().setXCoordinate(-1); 67 ClickInfos.getInstance().setXCoordinate(-1);
67 ClickInfos.getInstance().setYCoordinate(-1); 68 ClickInfos.getInstance().setYCoordinate(-1);
68 ClickInfos.getInstance().notify(); 69 ClickInfos.getInstance().notify();
69 } 70 }
70 } 71 }
71 72
72 /** 73 /**
73 * Update ClickInfos structure when some callback is about to be called. 74 * Update ClickInfos structure when some callback is about to be called.
74 * 75 *
75 * @param command : the callback that was supposed to be called. 76 * @param command : the callback that was supposed to be called.
76 * @param returnCode : used for closing windows. 77 * @param returnCode : used for closing windows.
77 * @param figureIndex : the figure ID where callback occured. 78 * @param figureIndex : the figure ID where callback occured.
78 */ 79 */
79 public static void filterCallback(String command, int returnCode, int figureIndex) { 80 public static void filterCallback(String command, int returnCode, int figureIndex) {
80 synchronized (ClickInfos.getInstance()) { 81 synchronized (ClickInfos.getInstance()) {
81 ClickInfos.getInstance().setMouseButtonNumber(returnCode); 82 ClickInfos.getInstance().setMouseButtonNumber(returnCode);
82 ClickInfos.getInstance().setMenuCallback(command); 83 ClickInfos.getInstance().setMenuCallback(command);
83 ClickInfos.getInstance().setWindowID(figureIndex); 84 ClickInfos.getInstance().setWindowID(figureIndex);
84 ClickInfos.getInstance().setXCoordinate(-1); 85 ClickInfos.getInstance().setXCoordinate(-1);
85 ClickInfos.getInstance().setYCoordinate(-1); 86 ClickInfos.getInstance().setYCoordinate(-1);
86 ClickInfos.getInstance().notify(); 87 ClickInfos.getInstance().notify();
87 } 88 }
88 } 89 }
89 /** 90 /**
90 * Update ClickInfos structure when a mouse event occurs on a Canvas. 91 * Update ClickInfos structure when a mouse event occurs on a Canvas.
91 * 92 *
92 * @param mouseEvent the event caught. 93 * @param mouseEvent the event caught.
93 * @param source the canvas where the event occurs. 94 * @param source the canvas where the event occurs.
94 * @param buttonAction the Scilab button code mean PRESSED / RELEASED / CLICKED / DCLICKED. 95 * @param buttonAction the Scilab button code mean PRESSED / RELEASED / CLICKED / DCLICKED.
95 * @param isControlDown true if the CTRL key has been pressed 96 * @param isControlDown true if the CTRL key has been pressed
96 */ 97 */
97 public static void filterMouse(MouseEvent mouseEvent, SwingScilabAxes source, int buttonAction, boolean isControlDown) { 98 public static void filterMouse(MouseEvent mouseEvent, SwingScilabAxes source, int buttonAction, boolean isControlDown) {
98 if (source != null) { 99 if (source != null) {
99 synchronized (ClickInfos.getInstance()) { 100 synchronized (ClickInfos.getInstance()) {
100 ClickInfos.getInstance().setXCoordinate(mouseEvent.getX() 101 ClickInfos.getInstance().setMouseButtonNumber(
101 + ((Component) mouseEvent.getSource()).getLocationOnScreen().getX() 102 SciTranslator.javaButton2Scilab(mouseEvent.getButton(), buttonAction, isControlDown)
102 - source.getLocationOnScreen().getX()); 103 );
103 ClickInfos.getInstance().setYCoordinate(mouseEvent.getY() 104 ClickInfos.getInstance().setWindowID(source.getFigureId());
104 + ((Component) mouseEvent.getSource()).getLocationOnScreen().getY() 105 try {
105 - source.getLocationOnScreen().getY()); 106 ClickInfos.getInstance().setXCoordinate(mouseEvent.getX()
106 ClickInfos.getInstance().setMouseButtonNumber( 107 + ((Component) mouseEvent.getSource()).getLocationOnScreen().getX()
107 SciTranslator.javaButton2Scilab(mouseEvent.getButton(), buttonAction, isControlDown) 108 - source.getLocationOnScreen().getX());
108 ); 109 ClickInfos.getInstance().setYCoordinate(mouseEvent.getY()
109 ClickInfos.getInstance().setWindowID(source.getFigureId()); 110 + ((Component) mouseEvent.getSource()).getLocationOnScreen().getY()
110 ClickInfos.getInstance().notify(); 111 - source.getLocationOnScreen().getY());
111 } 112 }
112 } 113 catch (Exception e) {
114 ClickInfos.getInstance().setXCoordinate(mouseEvent.getX()
115 + ((Component) mouseEvent.getSource()).getX()
116 - source.getX());
117 ClickInfos.getInstance().setYCoordinate(mouseEvent.getY()
118 + ((Component) mouseEvent.getSource()).getY()
119 - source.getY());
120 }
121 finally {
122 ClickInfos.getInstance().notify();
123 }
124 }
125 }
113 } 126 }
114} 127}