summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--scilab/CHANGES_5.3.X14
-rw-r--r--scilab/modules/gui/src/java/org/scilab/modules/gui/events/GlobalEventFilter.java127
2 files changed, 78 insertions, 63 deletions
diff --git a/scilab/CHANGES_5.3.X b/scilab/CHANGES_5.3.X
index 700d0bd..0811361 100644
--- a/scilab/CHANGES_5.3.X
+++ b/scilab/CHANGES_5.3.X
@@ -185,6 +185,8 @@ Graphics:
185 185
186* New functions 'comet' and 'comet3d' have been added. 186* New functions 'comet' and 'comet3d' have been added.
187 187
188* Bug 9428 fixed - A Java exception was displayed in some cases when using event handlers.
189
188 190
189Localization: 191Localization:
190============= 192=============
@@ -194,12 +196,12 @@ Localization:
194 196
195 197
196Help: 198Help:
197============== 199=====
198 200
199* Creation of a "complex" sub-section of "Elementary Functions". 201* Creation of a "complex" sub-section of "Elementary Functions".
200 202
201* Bug 6975 partially-fixed - Beginning of the documentation of xlabel(), 203* Bug 6975 partially-fixed - Beginning of the documentation of xlabel(),
202 ylabel() and zlabel() functions. 204 ylabel() and zlabel() functions.
203 205
204* Bug 7072 fixed - Fix various issues in the documentation. 206* Bug 7072 fixed - Fix various issues in the documentation.
205 Thanks to Yves Barois. 207 Thanks to Yves Barois.
@@ -244,7 +246,7 @@ Numerical Maths:
244================ 246================
245 247
246* Bug 7101 fixed - The roots had convergence problems for some polynomials. 248* Bug 7101 fixed - The roots had convergence problems for some polynomials.
247 The default algorithm has been changed to the eigenvalue 249 The default algorithm has been changed to the eigenvalue
248 of the companion matrix. 250 of the companion matrix.
249 251
250* Bug 9350 fixed - abs(complex(%nan,0)) returned zero instead of nan. 252* Bug 9350 fixed - abs(complex(%nan,0)) returned zero instead of nan.
@@ -256,7 +258,7 @@ CACSD Module:
256 258
257* Bug 6744 fixed - p_margin() returned an erroneous result (new fix). 259* Bug 6744 fixed - p_margin() returned an erroneous result (new fix).
258 260
259* Bug 9205 fixed - Optional argument added to nyquist to control the drawing of 261* Bug 9205 fixed - Optional argument added to nyquist to control the drawing of
260 the symetric part and a new function added for high 262 the symetric part and a new function added for high
261 definition zoom. 263 definition zoom.
262 264
@@ -267,7 +269,7 @@ Bug Fixes:
267* Bug 5687 fixed - The window title of a figure was not immediately updated when 269* Bug 5687 fixed - The window title of a figure was not immediately updated when
268 figure_name was changed. 270 figure_name was changed.
269 271
270* Bug 6789 fixed - The page header was not printed with 272* Bug 6789 fixed - The page header was not printed with
271 toprint(["line 1" "line 2"],"Page header"). 273 toprint(["line 1" "line 2"],"Page header").
272 274
273* Bug 6945 fixed - Conflicting options were confusing Scilab argument processing 275* Bug 6945 fixed - Conflicting options were confusing Scilab argument processing
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}