1
1
/*******************************************************************************************************
2
2
*
3
3
* LayeredDisplayMultiListener.java, in ummisco.gama.ui.experiment, is part of the source code of the GAMA modeling and
4
- * simulation platform (v.1.9.2 ).
4
+ * simulation platform (v.2.0.0 ).
5
5
*
6
6
* (c) 2007-2023 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
7
7
*
8
- * Visit https://github.com/gama-platform/gama for license information and contacts.
8
+ * Visit https://github.com/gama-platform/gama2 for license information and contacts.
9
9
*
10
10
********************************************************************************************************/
11
11
package ummisco .gama .ui .views .displays ;
12
12
13
+ import java .util .HashSet ;
14
+ import java .util .Set ;
13
15
import java .util .function .Consumer ;
14
16
15
17
import org .eclipse .swt .SWT ;
18
20
import msi .gama .common .interfaces .IDisplaySurface ;
19
21
import msi .gama .runtime .GAMA ;
20
22
import msi .gama .runtime .PlatformHelper ;
23
+ import ummisco .gama .dev .utils .DEBUG ;
21
24
import ummisco .gama .ui .utils .WorkbenchHelper ;
22
25
import ummisco .gama .ui .views .WorkaroundForIssue1353 ;
23
- import ummisco .gama .dev .utils .DEBUG ;
24
26
25
27
/**
26
28
* The listener interface for receiving layeredDisplayMulti events. The class that is interested in processing a
33
35
public class LayeredDisplayMultiListener {
34
36
35
37
static {
36
- DEBUG .OFF ();
38
+ DEBUG .ON ();
37
39
}
38
40
39
41
/** The view. */
@@ -60,6 +62,12 @@ public class LayeredDisplayMultiListener {
60
62
/** The key listener. */
61
63
final Consumer <Character > keyListener ;
62
64
65
+ /** The pressed characters. */
66
+ final Set <Character > pressedCharacters = new HashSet <>();
67
+
68
+ /** The pressed special characters. */
69
+ final Set <Integer > pressedSpecialCharacters = new HashSet <>();
70
+
63
71
/**
64
72
* Instantiates a new layered display multi listener.
65
73
*
@@ -93,11 +101,13 @@ public LayeredDisplayMultiListener(final IDisplaySurface surface, final LayeredD
93
101
* @param isCommand
94
102
*/
95
103
public void keyPressed (final char e , final boolean isCommand ) {
104
+ DEBUG .OUT ("Key pressed: " + e );
96
105
if (isCommand ) {
97
106
keyListener .accept (e );
98
107
return ;
99
108
}
100
- surface .dispatchKeyEvent (e );
109
+ pressedCharacters .add (e );
110
+ for (Character c : pressedCharacters ) { surface .dispatchKeyEvent (c ); }
101
111
WorkbenchHelper .asyncRun (view .displayOverlay );
102
112
}
103
113
@@ -108,7 +118,8 @@ public void keyPressed(final char e, final boolean isCommand) {
108
118
* the key code
109
119
*/
110
120
public void specialKeyPressed (final int keyCode ) {
111
- surface .dispatchSpecialKeyEvent (keyCode );
121
+ pressedSpecialCharacters .add (keyCode );
122
+ for (Integer code : pressedSpecialCharacters ) { surface .dispatchSpecialKeyEvent (code ); }
112
123
WorkbenchHelper .asyncRun (view .displayOverlay ); // ??
113
124
}
114
125
@@ -120,7 +131,22 @@ public void specialKeyPressed(final int keyCode) {
120
131
* @param command
121
132
* the command
122
133
*/
123
- public void keyReleased (final char e , final boolean command ) {}
134
+ public void keyReleased (final char e , final boolean command ) {
135
+ DEBUG .OUT ("Key released: " + e );
136
+ if (!command ) { pressedCharacters .remove (e ); }
137
+ }
138
+
139
+ /**
140
+ * Special key released.
141
+ *
142
+ * @param keyCode
143
+ * the key code
144
+ */
145
+ public void specialKeyReleased (final int keyCode ) {
146
+ pressedSpecialCharacters .remove (keyCode );
147
+ // for (Integer code : pressedSpecialCharacters) { surface.dispatchSpecialKeyEvent(code); }
148
+ // WorkbenchHelper.asyncRun(view.displayOverlay); // ??
149
+ }
124
150
125
151
/**
126
152
* Mouse enter.
@@ -170,6 +196,7 @@ public void mouseExit(final int x, final int y, final boolean modifier, final in
170
196
setMousePosition (-1 , -1 );
171
197
if (button > 0 ) return ;
172
198
// DEBUG.LOG("Mouse exiting " + e);
199
+
173
200
surface .dispatchMouseEvent (SWT .MouseExit , x , y );
174
201
if (!view .isFullScreen () && WorkaroundForIssue1353 .isInstalled ()) {
175
202
// suppressNextEnter = true;
@@ -204,13 +231,13 @@ public void mouseHover(final int x, final int y, final int button) {
204
231
public void mouseMove (final int x , final int y , final boolean modifier ) {
205
232
WorkbenchHelper .asyncRun (view .displayOverlay );
206
233
if (modifier ) return ;
207
- //DEBUG.LOG("Mouse moving on " + view.view.getPartName() + " at (" + x + "," + y + ")");
234
+ // DEBUG.LOG("Mouse moving on " + view.view.getPartName() + " at (" + x + "," + y + ")");
208
235
if (mouseIsDown ) {
209
236
// Depending on the plateform or display, this case is never called,
210
237
// because DragDetect events are emitted instead. But on Windows
211
238
// Java2D displays, it seems that MouseMove events are emitted even
212
239
// when the mouse button is down.
213
-
240
+
214
241
// Eventually moves the surface view
215
242
surface .draggedTo (x , y );
216
243
// Updates the mouse position. If the surface view is locked, the
@@ -241,7 +268,7 @@ public void mouseMove(final int x, final int y, final boolean modifier) {
241
268
* whetehr ALT, CTRL, CMD, META or other modifiers are used
242
269
*/
243
270
public void mouseDown (final int x , final int y , final int button , final boolean modifier ) {
244
- //DEBUG.LOG("Mouse down at " + x + ", " + y);
271
+ // DEBUG.LOG("Mouse down at " + x + ", " + y);
245
272
setMousePosition (x , y );
246
273
if (inMenu ) {
247
274
inMenu = false ;
@@ -269,7 +296,7 @@ public void mouseDown(final int x, final int y, final int button, final boolean
269
296
* whetehr ALT, CTRL, CMD, META or other modifiers are used
270
297
*/
271
298
public void mouseUp (final int x , final int y , final int button , final boolean modifier ) {
272
- //DEBUG.LOG("Mouse up at " + x + ", " + y + " on " + view.getPartName());
299
+ // DEBUG.LOG("Mouse up at " + x + ", " + y + " on " + view.getPartName());
273
300
// In case the mouse has moved (for example on a menu)
274
301
if (!mouseIsDown ) return ;
275
302
setMousePosition (x , y );
@@ -300,7 +327,7 @@ public void menuDetected(final int x, final int y) {
300
327
* Drag detected.
301
328
*/
302
329
public void dragDetected (final int x , final int y ) {
303
- //DEBUG.LOG("Mouse drag detected on " + view.view.getPartName() + " at (" + x + "," + y + ")");
330
+ // DEBUG.LOG("Mouse drag detected on " + view.view.getPartName() + " at (" + x + "," + y + ")");
304
331
surface .draggedTo (x , y );
305
332
setMousePosition (x , y );
306
333
surface .dispatchMouseEvent (SWT .DragDetect , x , y );
@@ -314,7 +341,10 @@ public void focusGained() {}
314
341
/**
315
342
* Focus lost.
316
343
*/
317
- public void focusLost () {}
344
+ public void focusLost () {
345
+ pressedCharacters .clear ();
346
+ pressedSpecialCharacters .clear ();
347
+ }
318
348
319
349
/**
320
350
* Sets the mouse position.
0 commit comments