Project

General

Profile

lost_keys_input_fix_20151103_4.txt

Sergey Ivanovskiy, 11/03/2015 01:47 PM

Download (9.79 KB)

 
1
=== modified file 'src/com/goldencode/p2j/ui/chui/ThinClient.java'
2
--- src/com/goldencode/p2j/ui/chui/ThinClient.java	2015-11-03 15:54:27 +0000
3
+++ src/com/goldencode/p2j/ui/chui/ThinClient.java	2015-11-03 18:12:23 +0000
4
@@ -2177,6 +2177,7 @@
5
 **     SVL 20151029          Added queryRepositioned.
6
 **     EVL 20151103          Adding handing image names without extensions while loading from
7
 **                           client file system.
8
+**     SBI 20151103          Changed terminate() to reset windows for gui as for chui.
9
 */
10
 
11
 package com.goldencode.p2j.ui.chui;
12
@@ -2879,11 +2880,7 @@
13
       ClientConfigManager mgr = ConfigManager.getInstance();
14
       mgr.deactivateConfigUpdates();
15
       
16
-      if (tc.isChui())
17
-      {
18
-         // this is needed only for chui...
19
-         WindowManager.resetWindow();
20
-      }
21
+      WindowManager.resetWindow();
22
    }
23
 
24
    /**
25

    
26
=== modified file 'src/com/goldencode/p2j/ui/client/WindowManager.java'
27
--- src/com/goldencode/p2j/ui/client/WindowManager.java	2015-10-16 12:11:54 +0000
28
+++ src/com/goldencode/p2j/ui/client/WindowManager.java	2015-11-03 18:10:07 +0000
29
@@ -45,6 +45,7 @@
30
 ** 020 HC  20151013 Changes to extend GUI multi-window focus management and ACTIVE-WINDOW system
31
 **                  handle processing to modal windows.
32
 ** 021 GES 20151015 moveToTop()/moveToBottom() forces the driver to move the specified window.
33
+**     SBI 20151103 Changed clearWindowList() to dispose the default window.
34
 */
35
 
36
 package com.goldencode.p2j.ui.client;
37
@@ -310,7 +311,7 @@
38
          w.hide();
39
          if (w instanceof Window)
40
          {
41
-            removeWindow(w.getId().asInt());
42
+            remove(w);
43
          }
44
          else 
45
          {
46

    
47
=== modified file 'src/com/goldencode/p2j/ui/client/gui/driver/swing/SwingEmulatedWindow.java'
48
--- src/com/goldencode/p2j/ui/client/gui/driver/swing/SwingEmulatedWindow.java	2015-10-24 19:51:34 +0000
49
+++ src/com/goldencode/p2j/ui/client/gui/driver/swing/SwingEmulatedWindow.java	2015-11-03 18:43:00 +0000
50
@@ -73,6 +73,7 @@
51
 **                  operations.  Removed save/restore of focus listeners and replaced it with
52
 **                  a global flag.
53
 ** 035 CA  20151024 Added support for WINDOW:SENSITIVE attribute.
54
+**     SBI 20151103 Added the drivers keyboard focus manager to fix the lost keys input.
55
 */
56
 
57
 package com.goldencode.p2j.ui.client.gui.driver.swing;
58
@@ -104,6 +105,7 @@
59
 import com.goldencode.p2j.ui.client.event.*;
60
 import com.goldencode.p2j.ui.client.gui.*;
61
 import com.goldencode.p2j.ui.client.gui.driver.*;
62
+
63
 import sun.java2d.*;
64
 import sun.java2d.loops.*;
65
 
66
@@ -213,7 +215,7 @@
67
             SwingEmulatedWindow.this.graphics = null;
68
          }   
69
       };
70
-
71
+      KeyboardFocusManager.setCurrentKeyboardFocusManager(new SwingEmulatedKeyboardFocusManager());
72
       // let the app above handle the decoration itself
73
       if (window instanceof JFrame)
74
       {
75
@@ -302,7 +304,22 @@
76
             }
77
          }
78
       });
79
-   
80
+
81
+      window.addComponentListener(new ComponentAdapter()
82
+      {
83
+         
84
+         @Override
85
+         public void componentShown(ComponentEvent e)
86
+         {
87
+            KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
88
+            if (kfm instanceof SwingEmulatedKeyboardFocusManager)
89
+            {
90
+               ((SwingEmulatedKeyboardFocusManager) kfm).setWindowFocused(window);
91
+            }
92
+         }
93
+         
94
+      });
95
+
96
       // setup mouse listeners
97
       pane.addMouseListener(mouseHandler);
98
       pane.addMouseMotionListener(mouseHandler);
99
@@ -375,37 +392,63 @@
100
    @Override
101
    public void quit()
102
    {
103
-      for (MouseListener l : pane.getMouseListeners())
104
-      {
105
-         pane.removeMouseListener(l);
106
-      }
107
-      for (MouseMotionListener l : pane.getMouseMotionListeners())
108
-      {
109
-         pane.removeMouseMotionListener(l);
110
-      }
111
-      for (MouseWheelListener l : pane.getMouseWheelListeners())
112
-      {
113
-         pane.removeMouseWheelListener(l);
114
-      }
115
-      for (WindowListener l : window.getWindowListeners())
116
-      {
117
-         window.removeWindowListener(l);
118
-      }
119
-      for (WindowFocusListener l : window.getWindowFocusListeners())
120
-      {
121
-         window.removeWindowFocusListener(l);
122
-      }
123
-      for (WindowStateListener l : window.getWindowStateListeners())
124
-      {
125
-         window.removeWindowStateListener(l);
126
-      }
127
-      for (KeyListener l : window.getKeyListeners())
128
-      {
129
-         window.removeKeyListener(l);
130
-      }
131
-      
132
-      // cleanup window resources
133
-      pane.quit();
134
+      Runnable r = new Runnable()
135
+      {
136
+         
137
+         @Override
138
+         public void run()
139
+         {
140
+            for (MouseListener l : pane.getMouseListeners())
141
+            {
142
+               pane.removeMouseListener(l);
143
+            }
144
+            for (MouseMotionListener l : pane.getMouseMotionListeners())
145
+            {
146
+               pane.removeMouseMotionListener(l);
147
+            }
148
+            for (MouseWheelListener l : pane.getMouseWheelListeners())
149
+            {
150
+               pane.removeMouseWheelListener(l);
151
+            }
152
+            for (WindowListener l : window.getWindowListeners())
153
+            {
154
+               window.removeWindowListener(l);
155
+            }
156
+            for (WindowFocusListener l : window.getWindowFocusListeners())
157
+            {
158
+               window.removeWindowFocusListener(l);
159
+            }
160
+            for (WindowStateListener l : window.getWindowStateListeners())
161
+            {
162
+               window.removeWindowStateListener(l);
163
+            }
164
+            for (KeyListener l : window.getKeyListeners())
165
+            {
166
+               window.removeKeyListener(l);
167
+            }
168
+            for (ComponentListener l : window.getComponentListeners())
169
+            {
170
+               window.removeComponentListener(l);
171
+            }
172
+            
173
+            // cleanup window resources
174
+            pane.quit();
175
+         }
176
+      };
177
+      if (SwingUtilities.isEventDispatchThread())
178
+      {
179
+         r.run();
180
+      }
181
+      else
182
+      {
183
+         try
184
+         {
185
+            SwingUtilities.invokeAndWait(r);
186
+         }
187
+         catch (InvocationTargetException | InterruptedException e)
188
+         {
189
+         }
190
+      }
191
    }
192
    
193
    /**
194
@@ -1448,4 +1491,28 @@
195
       
196
       highlightRestoreBuffer = null;
197
    }
198
+
199
+   /**
200
+    * The driver level keyboard focus manager.
201
+    */
202
+   class SwingEmulatedKeyboardFocusManager extends DefaultKeyboardFocusManager 
203
+   {
204
+      /**
205
+       * Sets the target window to be able to receive keys input.
206
+       * 
207
+       * @param    focusedWindow
208
+       *           The target clients window
209
+       * @throws   SecurityException
210
+       *           if this KeyboardFocusManager is not the current KeyboardFocusManager
211
+       *           for the calling thread's context and if the calling thread does not have
212
+       *           "replaceKeyboardFocusManager" permission.
213
+       */
214
+      public void setWindowFocused(Window focusedWindow) throws SecurityException
215
+      {
216
+         setGlobalFocusOwner(focusedWindow);
217
+         setGlobalFocusedWindow(focusedWindow);
218
+         setGlobalActiveWindow(focusedWindow);
219
+      }
220
+   };
221
+
222
 }
223

    
224
=== modified file 'src/com/goldencode/p2j/ui/client/gui/driver/swing/SwingGuiDriver.java'
225
--- src/com/goldencode/p2j/ui/client/gui/driver/swing/SwingGuiDriver.java	2015-10-22 23:14:19 +0000
226
+++ src/com/goldencode/p2j/ui/client/gui/driver/swing/SwingGuiDriver.java	2015-11-03 16:17:30 +0000
227
@@ -68,6 +68,7 @@
228
 **     HC  20151022 A fix for JWindow not able to receive focus when its owner window is not
229
 **                  visible. This resolves ALERT-BOX and DIALOG-BOX not receiving key input when
230
 **                  no main window visible.
231
+**     SBI 20151102 To do the keyboard reader a final driver's field.
232
 */
233
 
234
 package com.goldencode.p2j.ui.client.gui.driver.swing;
235
@@ -82,7 +83,6 @@
236
 import java.io.*;
237
 import java.util.*;
238
 
239
-import com.goldencode.p2j.security.*;
240
 import com.goldencode.p2j.ui.client.*;
241
 import com.goldencode.p2j.ui.client.gui.driver.*;
242
 import com.goldencode.p2j.ui.client.driver.swing.*;
243
@@ -97,14 +97,7 @@
244
     * The key reader.  This is global per the entire application, no matter how many frames are
245
     * alive.
246
     */
247
-   private static final ContextLocal<SwingKeyboardReader> keyReader = 
248
-   new ContextLocal<SwingKeyboardReader>()
249
-   {
250
-      protected SwingKeyboardReader initialValue()
251
-      {
252
-         return new WinKeyboardReader();
253
-      };
254
-   };
255
+   private final SwingKeyboardReader keyReader = new WinKeyboardReader();
256
 
257
    /** A special map containing the attributes of a underlined font. */
258
    static Map<TextAttribute, Integer> UNDERLINE_FONT = new HashMap<>();
259
@@ -246,7 +239,7 @@
260
    @Override
261
    public int readKey()                      
262
    {
263
-      return keyReader.get().read();
264
+      return keyReader.read();
265
    }
266
 
267
    /**
268
@@ -264,7 +257,7 @@
269
 
270
       try
271
       {
272
-         ews = SwingGuiClient.load(keyReader.get(), true);
273
+         ews = SwingGuiClient.load(keyReader, true);
274
          
275
          // the real window size is unknown at this time; it will be set later, when the layout
276
          // is performed
277
@@ -304,14 +297,14 @@
278
          {
279
             ews = GuiWindowContainer.load((SwingEmulatedWindow) owner, 
280
                                           windowTitle, 
281
-                                          keyReader.get());
282
+                                          keyReader);
283
          }
284
          else
285
          {
286
             // GuiWindowContainer is backed by JWindow Swing component which
287
             // requires a visible owner window in order to be focusable.
288
             // So if no visible owner, use SwingGuiClient backed by JFrame. 
289
-            ews = SwingGuiClient.load(keyReader.get(), false);
290
+            ews = SwingGuiClient.load(keyReader, false);
291
          }
292
          
293
          // the real window size is unknown at this time; it will be set later, when the layout
294