Project

General

Profile

lost_keys_input_fix_20151103_3.txt

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

Download (9.45 KB)

 
1
=== modified file 'src/com/goldencode/p2j/ui/chui/ThinClient.java'
2
--- src/com/goldencode/p2j/ui/chui/ThinClient.java	2015-10-30 16:15:33 +0000
3
+++ src/com/goldencode/p2j/ui/chui/ThinClient.java	2015-11-03 18:05:52 +0000
4
@@ -2175,6 +2175,7 @@
5
 **         20151027          Implemented WINDOW MESSAGE-AREA and STATUS-AREA attributes.
6
 **     VIG 20151027          Commented out eventDrawingBrackets call in pushMenuDescription.
7
 **     SVL 20151029          Added queryRepositioned.
8
+**     SBI 20151103          Changed terminate() to reset windows for gui as for chui.
9
 */
10
 
11
 package com.goldencode.p2j.ui.chui;
12
@@ -2877,11 +2878,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 14:07:35 +0000
29
@@ -310,7 +310,7 @@
30
          w.hide();
31
          if (w instanceof Window)
32
          {
33
-            removeWindow(w.getId().asInt());
34
+            remove(w);
35
          }
36
          else 
37
          {
38

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

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