11/*******************************************************************************************************
22 *
33 * 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 ).
55 *
66 * (c) 2007-2023 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
77 *
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.
99 *
1010 ********************************************************************************************************/
1111package ummisco .gama .ui .views .displays ;
1212
13+ import java .util .HashSet ;
14+ import java .util .Set ;
1315import java .util .function .Consumer ;
1416
1517import org .eclipse .swt .SWT ;
1820import msi .gama .common .interfaces .IDisplaySurface ;
1921import msi .gama .runtime .GAMA ;
2022import msi .gama .runtime .PlatformHelper ;
23+ import ummisco .gama .dev .utils .DEBUG ;
2124import ummisco .gama .ui .utils .WorkbenchHelper ;
2225import ummisco .gama .ui .views .WorkaroundForIssue1353 ;
23- import ummisco .gama .dev .utils .DEBUG ;
2426
2527/**
2628 * The listener interface for receiving layeredDisplayMulti events. The class that is interested in processing a
3335public class LayeredDisplayMultiListener {
3436
3537 static {
36- DEBUG .OFF ();
38+ DEBUG .ON ();
3739 }
3840
3941 /** The view. */
@@ -60,6 +62,12 @@ public class LayeredDisplayMultiListener {
6062 /** The key listener. */
6163 final Consumer <Character > keyListener ;
6264
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+
6371 /**
6472 * Instantiates a new layered display multi listener.
6573 *
@@ -93,11 +101,13 @@ public LayeredDisplayMultiListener(final IDisplaySurface surface, final LayeredD
93101 * @param isCommand
94102 */
95103 public void keyPressed (final char e , final boolean isCommand ) {
104+ DEBUG .OUT ("Key pressed: " + e );
96105 if (isCommand ) {
97106 keyListener .accept (e );
98107 return ;
99108 }
100- surface .dispatchKeyEvent (e );
109+ pressedCharacters .add (e );
110+ for (Character c : pressedCharacters ) { surface .dispatchKeyEvent (c ); }
101111 WorkbenchHelper .asyncRun (view .displayOverlay );
102112 }
103113
@@ -108,7 +118,8 @@ public void keyPressed(final char e, final boolean isCommand) {
108118 * the key code
109119 */
110120 public void specialKeyPressed (final int keyCode ) {
111- surface .dispatchSpecialKeyEvent (keyCode );
121+ pressedSpecialCharacters .add (keyCode );
122+ for (Integer code : pressedSpecialCharacters ) { surface .dispatchSpecialKeyEvent (code ); }
112123 WorkbenchHelper .asyncRun (view .displayOverlay ); // ??
113124 }
114125
@@ -120,7 +131,22 @@ public void specialKeyPressed(final int keyCode) {
120131 * @param command
121132 * the command
122133 */
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+ }
124150
125151 /**
126152 * Mouse enter.
@@ -170,6 +196,7 @@ public void mouseExit(final int x, final int y, final boolean modifier, final in
170196 setMousePosition (-1 , -1 );
171197 if (button > 0 ) return ;
172198 // DEBUG.LOG("Mouse exiting " + e);
199+
173200 surface .dispatchMouseEvent (SWT .MouseExit , x , y );
174201 if (!view .isFullScreen () && WorkaroundForIssue1353 .isInstalled ()) {
175202 // suppressNextEnter = true;
@@ -204,13 +231,13 @@ public void mouseHover(final int x, final int y, final int button) {
204231 public void mouseMove (final int x , final int y , final boolean modifier ) {
205232 WorkbenchHelper .asyncRun (view .displayOverlay );
206233 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 + ")");
208235 if (mouseIsDown ) {
209236 // Depending on the plateform or display, this case is never called,
210237 // because DragDetect events are emitted instead. But on Windows
211238 // Java2D displays, it seems that MouseMove events are emitted even
212239 // when the mouse button is down.
213-
240+
214241 // Eventually moves the surface view
215242 surface .draggedTo (x , y );
216243 // 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) {
241268 * whetehr ALT, CTRL, CMD, META or other modifiers are used
242269 */
243270 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);
245272 setMousePosition (x , y );
246273 if (inMenu ) {
247274 inMenu = false ;
@@ -269,7 +296,7 @@ public void mouseDown(final int x, final int y, final int button, final boolean
269296 * whetehr ALT, CTRL, CMD, META or other modifiers are used
270297 */
271298 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());
273300 // In case the mouse has moved (for example on a menu)
274301 if (!mouseIsDown ) return ;
275302 setMousePosition (x , y );
@@ -300,7 +327,7 @@ public void menuDetected(final int x, final int y) {
300327 * Drag detected.
301328 */
302329 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 + ")");
304331 surface .draggedTo (x , y );
305332 setMousePosition (x , y );
306333 surface .dispatchMouseEvent (SWT .DragDetect , x , y );
@@ -314,7 +341,10 @@ public void focusGained() {}
314341 /**
315342 * Focus lost.
316343 */
317- public void focusLost () {}
344+ public void focusLost () {
345+ pressedCharacters .clear ();
346+ pressedSpecialCharacters .clear ();
347+ }
318348
319349 /**
320350 * Sets the mouse position.
0 commit comments