39 import sun.java2d.pipe.Region; |
39 import sun.java2d.pipe.Region; |
40 import sun.util.logging.PlatformLogger; |
40 import sun.util.logging.PlatformLogger; |
41 |
41 |
42 public class LWWindowPeer |
42 public class LWWindowPeer |
43 extends LWContainerPeer<Window, JComponent> |
43 extends LWContainerPeer<Window, JComponent> |
44 implements WindowPeer, FramePeer, DialogPeer, FullScreenCapable, PlatformEventNotifier { |
44 implements FramePeer, DialogPeer, FullScreenCapable, DisplayChangedListener, PlatformEventNotifier |
|
45 { |
45 public static enum PeerType { |
46 public static enum PeerType { |
46 SIMPLEWINDOW, |
47 SIMPLEWINDOW, |
47 FRAME, |
48 FRAME, |
48 DIALOG, |
49 DIALOG, |
49 EMBEDDED_FRAME, |
50 EMBEDDED_FRAME, |
203 |
204 |
204 updateInsets(platformWindow.getInsets()); |
205 updateInsets(platformWindow.getInsets()); |
205 if (getSurfaceData() == null) { |
206 if (getSurfaceData() == null) { |
206 replaceSurfaceData(false); |
207 replaceSurfaceData(false); |
207 } |
208 } |
|
209 activateDisplayListener(); |
208 } |
210 } |
209 |
211 |
210 // Just a helper method |
212 // Just a helper method |
211 public PlatformWindow getPlatformWindow() { |
213 public PlatformWindow getPlatformWindow() { |
212 return platformWindow; |
214 return platformWindow; |
215 @Override |
217 @Override |
216 protected LWWindowPeer getWindowPeerOrSelf() { |
218 protected LWWindowPeer getWindowPeerOrSelf() { |
217 return this; |
219 return this; |
218 } |
220 } |
219 |
221 |
220 @Override |
|
221 protected void initializeContainerPeer() { |
|
222 // No-op as LWWindowPeer doesn't have any containerPeer |
|
223 } |
|
224 |
|
225 // ---- PEER METHODS ---- // |
222 // ---- PEER METHODS ---- // |
226 |
223 |
227 @Override |
224 @Override |
228 protected void disposeImpl() { |
225 protected void disposeImpl() { |
|
226 deactivateDisplayListener(); |
229 SurfaceData oldData = getSurfaceData(); |
227 SurfaceData oldData = getSurfaceData(); |
230 synchronized (surfaceDataLock){ |
228 synchronized (surfaceDataLock){ |
231 surfaceData = null; |
229 surfaceData = null; |
232 } |
230 } |
233 if (oldData != null) { |
231 if (oldData != null) { |
938 postEvent(new KeyEvent(focusOwner, id, when, modifiers, keyCode, keyChar, keyLocation)); |
936 postEvent(new KeyEvent(focusOwner, id, when, modifiers, keyCode, keyChar, keyLocation)); |
939 } |
937 } |
940 |
938 |
941 // ---- UTILITY METHODS ---- // |
939 // ---- UTILITY METHODS ---- // |
942 |
940 |
|
941 private void activateDisplayListener() { |
|
942 final GraphicsEnvironment ge = |
|
943 GraphicsEnvironment.getLocalGraphicsEnvironment(); |
|
944 ((SunGraphicsEnvironment) ge).addDisplayChangedListener(this); |
|
945 } |
|
946 |
|
947 private void deactivateDisplayListener() { |
|
948 final GraphicsEnvironment ge = |
|
949 GraphicsEnvironment.getLocalGraphicsEnvironment(); |
|
950 ((SunGraphicsEnvironment) ge).removeDisplayChangedListener(this); |
|
951 } |
|
952 |
943 private void postWindowStateChangedEvent(int newWindowState) { |
953 private void postWindowStateChangedEvent(int newWindowState) { |
944 if (getTarget() instanceof Frame) { |
954 if (getTarget() instanceof Frame) { |
945 AWTAccessor.getFrameAccessor().setExtendedState( |
955 AWTAccessor.getFrameAccessor().setExtendedState( |
946 (Frame)getTarget(), newWindowState); |
956 (Frame)getTarget(), newWindowState); |
947 } |
957 } |
1002 return false; |
1012 return false; |
1003 } |
1013 } |
1004 graphicsDevice = newGraphicsDevice; |
1014 graphicsDevice = newGraphicsDevice; |
1005 } |
1015 } |
1006 |
1016 |
1007 // TODO: DisplayChangedListener stuff |
|
1008 final GraphicsConfiguration newGC = newGraphicsDevice.getDefaultConfiguration(); |
1017 final GraphicsConfiguration newGC = newGraphicsDevice.getDefaultConfiguration(); |
1009 |
1018 |
1010 if (!setGraphicsConfig(newGC)) return false; |
1019 if (!setGraphicsConfig(newGC)) return false; |
1011 |
1020 |
1012 SunToolkit.executeOnEventHandlerThread(getTarget(), new Runnable() { |
1021 SunToolkit.executeOnEventHandlerThread(getTarget(), new Runnable() { |
1013 public void run() { |
1022 public void run() { |
1014 AWTAccessor.getComponentAccessor().setGraphicsConfiguration(getTarget(), newGC); |
1023 AWTAccessor.getComponentAccessor().setGraphicsConfiguration(getTarget(), newGC); |
1015 } |
1024 } |
1016 }); |
1025 }); |
1017 return true; |
1026 return true; |
|
1027 } |
|
1028 |
|
1029 @Override |
|
1030 public final void displayChanged() { |
|
1031 updateGraphicsDevice(); |
|
1032 // Replace surface unconditionally, because internal state of the |
|
1033 // GraphicsDevice could be changed. |
|
1034 replaceSurfaceData(); |
|
1035 repaintPeer(); |
|
1036 } |
|
1037 |
|
1038 @Override |
|
1039 public final void paletteChanged() { |
|
1040 // components do not need to react to this event. |
1018 } |
1041 } |
1019 |
1042 |
1020 /* |
1043 /* |
1021 * May be called by delegate to provide SD to Java2D code. |
1044 * May be called by delegate to provide SD to Java2D code. |
1022 */ |
1045 */ |