src/macosx/classes/sun/lwawt/LWWindowPeer.java

Print this page




  24  */
  25 
  26 package sun.lwawt;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.awt.peer.*;
  31 import java.util.List;
  32 
  33 import javax.swing.*;
  34 
  35 import sun.awt.*;
  36 import sun.java2d.*;
  37 import sun.java2d.loops.Blit;
  38 import sun.java2d.loops.CompositeType;
  39 import sun.java2d.pipe.Region;
  40 import sun.util.logging.PlatformLogger;
  41 
  42 public class LWWindowPeer
  43     extends LWContainerPeer<Window, JComponent>
  44     implements WindowPeer, FramePeer, DialogPeer, FullScreenCapable
  45 {
  46     public static enum PeerType {
  47         SIMPLEWINDOW,
  48         FRAME,
  49         DIALOG,
  50         EMBEDDED_FRAME,
  51         VIEW_EMBEDDED_FRAME,
  52         LW_FRAME
  53     }
  54 
  55     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWWindowPeer");
  56 
  57     private final PlatformWindow platformWindow;
  58 
  59     // Window bounds reported by the native system (as opposed to
  60     // regular bounds inherited from LWComponentPeer which are
  61     // requested by user and may haven't been applied yet because
  62     // of asynchronous requests to the windowing system)
  63     private int sysX;
  64     private int sysY;


 172 
 173         setAlwaysOnTop(getTarget().isAlwaysOnTop());
 174         updateMinimumSize();
 175 
 176         final Shape shape = getTarget().getShape();
 177         if (shape != null) {
 178             applyShape(Region.getInstance(shape, null));
 179         }
 180 
 181         final float opacity = getTarget().getOpacity();
 182         if (opacity < 1.0f) {
 183             setOpacity(opacity);
 184         }
 185 
 186         setOpaque(getTarget().isOpaque());
 187 
 188         updateInsets(platformWindow.getInsets());
 189         if (getSurfaceData() == null) {
 190             replaceSurfaceData(false);
 191         }

 192     }
 193 
 194     // Just a helper method
 195     public PlatformWindow getPlatformWindow() {
 196         return platformWindow;
 197     }
 198 
 199     @Override
 200     protected LWWindowPeer getWindowPeerOrSelf() {
 201         return this;
 202     }
 203 
 204     @Override
 205     protected void initializeContainerPeer() {
 206         // No-op as LWWindowPeer doesn't have any containerPeer
 207     }
 208 
 209     // ---- PEER METHODS ---- //
 210 
 211     @Override
 212     protected void disposeImpl() {

 213         SurfaceData oldData = getSurfaceData();
 214         synchronized (surfaceDataLock){
 215             surfaceData = null;
 216         }
 217         if (oldData != null) {
 218             oldData.invalidate();
 219         }
 220         if (isGrabbing()) {
 221             ungrab();
 222         }
 223         platformWindow.dispose();
 224         super.disposeImpl();
 225     }
 226 
 227     @Override
 228     protected void setVisibleImpl(final boolean visible) {
 229         super.setVisibleImpl(visible);
 230         // TODO: update graphicsConfig, see 4868278
 231         platformWindow.setVisible(visible);
 232         if (isSimpleWindow()) {


 863      * Called by the delegate when a key is pressed.
 864      */
 865     public void dispatchKeyEvent(int id, long when, int modifiers,
 866                                  int keyCode, char keyChar, int keyLocation)
 867     {
 868         LWKeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
 869         Component focusOwner = kfmPeer.getCurrentFocusOwner();
 870 
 871         if (focusOwner == null) {
 872             focusOwner = kfmPeer.getCurrentFocusedWindow();
 873             if (focusOwner == null) {
 874                 focusOwner = this.getTarget();
 875             }
 876         }
 877         postEvent(new KeyEvent(focusOwner, id, when, modifiers, keyCode, keyChar, keyLocation));
 878     }
 879 
 880 
 881     // ---- UTILITY METHODS ---- //
 882 












 883     private void postWindowStateChangedEvent(int newWindowState) {
 884         if (getTarget() instanceof Frame) {
 885             AWTAccessor.getFrameAccessor().setExtendedState(
 886                     (Frame)getTarget(), newWindowState);
 887         }
 888         WindowEvent stateChangedEvent = new WindowEvent(getTarget(),
 889                 WindowEvent.WINDOW_STATE_CHANGED,
 890                 windowState, newWindowState);
 891         postEvent(stateChangedEvent);
 892         windowState = newWindowState;
 893     }
 894 
 895     private static int getGraphicsConfigScreen(GraphicsConfiguration gc) {
 896         // TODO: this method can be implemented in a more
 897         // efficient way by forwarding to the delegate
 898         GraphicsDevice gd = gc.getDevice();
 899         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
 900         GraphicsDevice[] gds = ge.getScreenDevices();
 901         for (int i = 0; i < gds.length; i++) {
 902             if (gds[i] == gd) {


 924             // is moved by user, graphicsDevice is updated in notifyReshape().
 925             // In either case, there's nothing to do with screenOn here
 926             graphicsConfig = gc;
 927         }
 928         // SurfaceData is replaced later in updateGraphicsData()
 929         return true;
 930     }
 931 
 932     /**
 933      * Returns true if the GraphicsDevice has been changed, false otherwise.
 934      */
 935     public boolean updateGraphicsDevice() {
 936         GraphicsDevice newGraphicsDevice = platformWindow.getGraphicsDevice();
 937         synchronized (getStateLock()) {
 938             if (graphicsDevice == newGraphicsDevice) {
 939                 return false;
 940             }
 941             graphicsDevice = newGraphicsDevice;
 942         }
 943 
 944         // TODO: DisplayChangedListener stuff
 945         final GraphicsConfiguration newGC = newGraphicsDevice.getDefaultConfiguration();
 946 
 947         if (!setGraphicsConfig(newGC)) return false;
 948 
 949         SunToolkit.executeOnEventHandlerThread(getTarget(), new Runnable() {
 950             public void run() {
 951                 AWTAccessor.getComponentAccessor().setGraphicsConfiguration(getTarget(), newGC);
 952             }
 953         });
 954         return true;














 955     }
 956 
 957     /*
 958      * May be called by delegate to provide SD to Java2D code.
 959      */
 960     public SurfaceData getSurfaceData() {
 961         synchronized (surfaceDataLock) {
 962             return surfaceData;
 963         }
 964     }
 965 
 966     private void replaceSurfaceData() {
 967         replaceSurfaceData(true);
 968     }
 969 
 970     private void replaceSurfaceData(final boolean blit) {
 971         synchronized (surfaceDataLock) {
 972             final SurfaceData oldData = getSurfaceData();
 973             surfaceData = platformWindow.replaceSurfaceData();
 974             final Rectangle size = getSize();




  24  */
  25 
  26 package sun.lwawt;
  27 
  28 import java.awt.*;
  29 import java.awt.event.*;
  30 import java.awt.peer.*;
  31 import java.util.List;
  32 
  33 import javax.swing.*;
  34 
  35 import sun.awt.*;
  36 import sun.java2d.*;
  37 import sun.java2d.loops.Blit;
  38 import sun.java2d.loops.CompositeType;
  39 import sun.java2d.pipe.Region;
  40 import sun.util.logging.PlatformLogger;
  41 
  42 public class LWWindowPeer
  43     extends LWContainerPeer<Window, JComponent>
  44     implements FramePeer, DialogPeer, FullScreenCapable, DisplayChangedListener
  45 {
  46     public static enum PeerType {
  47         SIMPLEWINDOW,
  48         FRAME,
  49         DIALOG,
  50         EMBEDDED_FRAME,
  51         VIEW_EMBEDDED_FRAME,
  52         LW_FRAME
  53     }
  54 
  55     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWWindowPeer");
  56 
  57     private final PlatformWindow platformWindow;
  58 
  59     // Window bounds reported by the native system (as opposed to
  60     // regular bounds inherited from LWComponentPeer which are
  61     // requested by user and may haven't been applied yet because
  62     // of asynchronous requests to the windowing system)
  63     private int sysX;
  64     private int sysY;


 172 
 173         setAlwaysOnTop(getTarget().isAlwaysOnTop());
 174         updateMinimumSize();
 175 
 176         final Shape shape = getTarget().getShape();
 177         if (shape != null) {
 178             applyShape(Region.getInstance(shape, null));
 179         }
 180 
 181         final float opacity = getTarget().getOpacity();
 182         if (opacity < 1.0f) {
 183             setOpacity(opacity);
 184         }
 185 
 186         setOpaque(getTarget().isOpaque());
 187 
 188         updateInsets(platformWindow.getInsets());
 189         if (getSurfaceData() == null) {
 190             replaceSurfaceData(false);
 191         }
 192         activateDisplayListener();
 193     }
 194 
 195     // Just a helper method
 196     public PlatformWindow getPlatformWindow() {
 197         return platformWindow;
 198     }
 199 
 200     @Override
 201     protected LWWindowPeer getWindowPeerOrSelf() {
 202         return this;
 203     }
 204 
 205     @Override
 206     protected void initializeContainerPeer() {
 207         // No-op as LWWindowPeer doesn't have any containerPeer
 208     }
 209 
 210     // ---- PEER METHODS ---- //
 211 
 212     @Override
 213     protected void disposeImpl() {
 214         deactivateDisplayListener();
 215         SurfaceData oldData = getSurfaceData();
 216         synchronized (surfaceDataLock){
 217             surfaceData = null;
 218         }
 219         if (oldData != null) {
 220             oldData.invalidate();
 221         }
 222         if (isGrabbing()) {
 223             ungrab();
 224         }
 225         platformWindow.dispose();
 226         super.disposeImpl();
 227     }
 228 
 229     @Override
 230     protected void setVisibleImpl(final boolean visible) {
 231         super.setVisibleImpl(visible);
 232         // TODO: update graphicsConfig, see 4868278
 233         platformWindow.setVisible(visible);
 234         if (isSimpleWindow()) {


 865      * Called by the delegate when a key is pressed.
 866      */
 867     public void dispatchKeyEvent(int id, long when, int modifiers,
 868                                  int keyCode, char keyChar, int keyLocation)
 869     {
 870         LWKeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
 871         Component focusOwner = kfmPeer.getCurrentFocusOwner();
 872 
 873         if (focusOwner == null) {
 874             focusOwner = kfmPeer.getCurrentFocusedWindow();
 875             if (focusOwner == null) {
 876                 focusOwner = this.getTarget();
 877             }
 878         }
 879         postEvent(new KeyEvent(focusOwner, id, when, modifiers, keyCode, keyChar, keyLocation));
 880     }
 881 
 882 
 883     // ---- UTILITY METHODS ---- //
 884 
 885     private void activateDisplayListener() {
 886         final GraphicsEnvironment ge =
 887                 GraphicsEnvironment.getLocalGraphicsEnvironment();
 888         ((SunGraphicsEnvironment) ge).addDisplayChangedListener(this);
 889     }
 890 
 891     private void deactivateDisplayListener() {
 892         final GraphicsEnvironment ge =
 893                 GraphicsEnvironment.getLocalGraphicsEnvironment();
 894         ((SunGraphicsEnvironment) ge).removeDisplayChangedListener(this);
 895     }
 896 
 897     private void postWindowStateChangedEvent(int newWindowState) {
 898         if (getTarget() instanceof Frame) {
 899             AWTAccessor.getFrameAccessor().setExtendedState(
 900                     (Frame)getTarget(), newWindowState);
 901         }
 902         WindowEvent stateChangedEvent = new WindowEvent(getTarget(),
 903                 WindowEvent.WINDOW_STATE_CHANGED,
 904                 windowState, newWindowState);
 905         postEvent(stateChangedEvent);
 906         windowState = newWindowState;
 907     }
 908 
 909     private static int getGraphicsConfigScreen(GraphicsConfiguration gc) {
 910         // TODO: this method can be implemented in a more
 911         // efficient way by forwarding to the delegate
 912         GraphicsDevice gd = gc.getDevice();
 913         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
 914         GraphicsDevice[] gds = ge.getScreenDevices();
 915         for (int i = 0; i < gds.length; i++) {
 916             if (gds[i] == gd) {


 938             // is moved by user, graphicsDevice is updated in notifyReshape().
 939             // In either case, there's nothing to do with screenOn here
 940             graphicsConfig = gc;
 941         }
 942         // SurfaceData is replaced later in updateGraphicsData()
 943         return true;
 944     }
 945 
 946     /**
 947      * Returns true if the GraphicsDevice has been changed, false otherwise.
 948      */
 949     public boolean updateGraphicsDevice() {
 950         GraphicsDevice newGraphicsDevice = platformWindow.getGraphicsDevice();
 951         synchronized (getStateLock()) {
 952             if (graphicsDevice == newGraphicsDevice) {
 953                 return false;
 954             }
 955             graphicsDevice = newGraphicsDevice;
 956         }
 957 

 958         final GraphicsConfiguration newGC = newGraphicsDevice.getDefaultConfiguration();
 959 
 960         if (!setGraphicsConfig(newGC)) return false;
 961 
 962         SunToolkit.executeOnEventHandlerThread(getTarget(), new Runnable() {
 963             public void run() {
 964                 AWTAccessor.getComponentAccessor().setGraphicsConfiguration(getTarget(), newGC);
 965             }
 966         });
 967         return true;
 968     }
 969 
 970     @Override
 971     public final void displayChanged() {
 972         updateGraphicsDevice();
 973         // Replace surface unconditionally, because internal state of the
 974         // GraphicsDevice could be changed.
 975         replaceSurfaceData();
 976         repaintPeer();
 977     }
 978 
 979     @Override
 980     public final void paletteChanged() {
 981         // components do not need to react to this event.
 982     }
 983 
 984     /*
 985      * May be called by delegate to provide SD to Java2D code.
 986      */
 987     public SurfaceData getSurfaceData() {
 988         synchronized (surfaceDataLock) {
 989             return surfaceData;
 990         }
 991     }
 992 
 993     private void replaceSurfaceData() {
 994         replaceSurfaceData(true);
 995     }
 996 
 997     private void replaceSurfaceData(final boolean blit) {
 998         synchronized (surfaceDataLock) {
 999             final SurfaceData oldData = getSurfaceData();
1000             surfaceData = platformWindow.replaceSurfaceData();
1001             final Rectangle size = getSize();