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

Print this page




  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         EMBEDDEDFRAME

  51     }
  52 
  53     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWWindowPeer");
  54 
  55     private PlatformWindow platformWindow;
  56 
  57     // Window bounds reported by the native system (as opposed to
  58     // regular bounds inherited from LWComponentPeer which are
  59     // requested by user and may haven't been applied yet because
  60     // of asynchronous requests to the windowing system)
  61     private int sysX;
  62     private int sysY;
  63     private int sysW;
  64     private int sysH;
  65 
  66     private static final int MINIMUM_WIDTH = 1;
  67     private static final int MINIMUM_HEIGHT = 1;
  68 
  69     private Insets insets = new Insets(0, 0, 0, 0);
  70 


  91     // depending on what mouse button is being dragged according to Cocoa
  92     private static LWComponentPeer mouseDownTarget[] = new LWComponentPeer[3];
  93 
  94     // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events
  95     // on MOUSE_RELEASE. Click events are only generated if there were no drag
  96     // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button
  97     private static int mouseClickButtons = 0;
  98 
  99     private volatile boolean isOpaque = true;
 100 
 101     private static final Font DEFAULT_FONT = new Font("Lucida Grande", Font.PLAIN, 13);
 102 
 103     private static LWWindowPeer grabbingWindow;
 104 
 105     private volatile boolean skipNextFocusChange;
 106 
 107     private static final Color nonOpaqueBackground = new Color(0, 0, 0, 0);
 108 
 109     private volatile boolean textured;
 110 


 111     /**
 112      * Current modal blocker or null.
 113      *
 114      * Synchronization: peerTreeLock.
 115      */
 116     private LWWindowPeer blocker;
 117 
 118     public LWWindowPeer(Window target, PlatformComponent platformComponent,
 119                         PlatformWindow platformWindow)
 120     {
 121         super(target, platformComponent);
 122         this.platformWindow = platformWindow;

 123 
 124         Window owner = target.getOwner();
 125         LWWindowPeer ownerPeer = (owner != null) ? (LWWindowPeer)owner.getPeer() : null;
 126         PlatformWindow ownerDelegate = (ownerPeer != null) ? ownerPeer.getPlatformWindow() : null;
 127 
 128         // The delegate.initialize() needs a non-null GC on X11.
 129         GraphicsConfiguration gc = getTarget().getGraphicsConfiguration();
 130         synchronized (getStateLock()) {
 131             // graphicsConfig should be updated according to the real window
 132             // bounds when the window is shown, see 4868278
 133             this.graphicsConfig = gc;
 134         }
 135 
 136         if (!target.isFontSet()) {
 137             target.setFont(DEFAULT_FONT);
 138         }
 139 
 140         if (!target.isBackgroundSet()) {
 141             target.setBackground(SystemColor.window);
 142         } else {


 258     }
 259 
 260     protected final Graphics getOnscreenGraphics(Color fg, Color bg, Font f) {
 261         if (getSurfaceData() == null) {
 262             return null;
 263         }
 264         if (fg == null) {
 265             fg = SystemColor.windowText;
 266         }
 267         if (bg == null) {
 268             bg = SystemColor.window;
 269         }
 270         if (f == null) {
 271             f = DEFAULT_FONT;
 272         }
 273         return platformWindow.transformGraphics(new SunGraphics2D(getSurfaceData(), fg, bg, f));
 274     }
 275 
 276     @Override
 277     public void setBounds(int x, int y, int w, int h, int op) {





 278         if ((op & SET_CLIENT_SIZE) != 0) {
 279             // SET_CLIENT_SIZE is only applicable to window peers, so handle it here
 280             // instead of pulling 'insets' field up to LWComponentPeer
 281             // no need to add insets since Window's notion of width and height includes insets.
 282             op &= ~SET_CLIENT_SIZE;
 283             op |= SET_SIZE;
 284         }
 285 
 286         if (w < MINIMUM_WIDTH) {
 287             w = MINIMUM_WIDTH;
 288         }
 289         if (h < MINIMUM_HEIGHT) {
 290             h = MINIMUM_HEIGHT;
 291         }
 292 
 293         final int maxW = getLWGC().getMaxTextureWidth();
 294         final int maxH = getLWGC().getMaxTextureHeight();
 295 
 296         if (w > maxW) {
 297             w = maxW;


1193     }
1194 
1195     void grab() {
1196         if (grabbingWindow != null && !isGrabbing()) {
1197             grabbingWindow.ungrab();
1198         }
1199         grabbingWindow = this;
1200     }
1201 
1202     void ungrab() {
1203         if (isGrabbing()) {
1204             grabbingWindow = null;
1205             postEvent(new UngrabEvent(getTarget()));
1206         }
1207     }
1208 
1209     private boolean isGrabbing() {
1210         return this == grabbingWindow;
1211     }
1212 




1213     @Override
1214     public String toString() {
1215         return super.toString() + " [target is " + getTarget() + "]";
1216     }
1217 }


  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         EMBEDDEDFRAME,
  51         VIEWEMBEDDEDFRAME
  52     }
  53 
  54     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWWindowPeer");
  55 
  56     private PlatformWindow platformWindow;
  57 
  58     // Window bounds reported by the native system (as opposed to
  59     // regular bounds inherited from LWComponentPeer which are
  60     // requested by user and may haven't been applied yet because
  61     // of asynchronous requests to the windowing system)
  62     private int sysX;
  63     private int sysY;
  64     private int sysW;
  65     private int sysH;
  66 
  67     private static final int MINIMUM_WIDTH = 1;
  68     private static final int MINIMUM_HEIGHT = 1;
  69 
  70     private Insets insets = new Insets(0, 0, 0, 0);
  71 


  92     // depending on what mouse button is being dragged according to Cocoa
  93     private static LWComponentPeer mouseDownTarget[] = new LWComponentPeer[3];
  94 
  95     // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events
  96     // on MOUSE_RELEASE. Click events are only generated if there were no drag
  97     // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button
  98     private static int mouseClickButtons = 0;
  99 
 100     private volatile boolean isOpaque = true;
 101 
 102     private static final Font DEFAULT_FONT = new Font("Lucida Grande", Font.PLAIN, 13);
 103 
 104     private static LWWindowPeer grabbingWindow;
 105 
 106     private volatile boolean skipNextFocusChange;
 107 
 108     private static final Color nonOpaqueBackground = new Color(0, 0, 0, 0);
 109 
 110     private volatile boolean textured;
 111 
 112     private final PeerType peerType;
 113   
 114     /**
 115      * Current modal blocker or null.
 116      *
 117      * Synchronization: peerTreeLock.
 118      */
 119     private LWWindowPeer blocker;
 120     
 121     public LWWindowPeer(Window target, PlatformComponent platformComponent,
 122                         PlatformWindow platformWindow, PeerType peerType)
 123     {
 124         super(target, platformComponent);
 125         this.platformWindow = platformWindow;
 126         this.peerType = peerType;
 127         
 128         Window owner = target.getOwner();
 129         LWWindowPeer ownerPeer = (owner != null) ? (LWWindowPeer)owner.getPeer() : null;
 130         PlatformWindow ownerDelegate = (ownerPeer != null) ? ownerPeer.getPlatformWindow() : null;
 131 
 132         // The delegate.initialize() needs a non-null GC on X11.
 133         GraphicsConfiguration gc = getTarget().getGraphicsConfiguration();
 134         synchronized (getStateLock()) {
 135             // graphicsConfig should be updated according to the real window
 136             // bounds when the window is shown, see 4868278
 137             this.graphicsConfig = gc;
 138         }
 139 
 140         if (!target.isFontSet()) {
 141             target.setFont(DEFAULT_FONT);
 142         }
 143 
 144         if (!target.isBackgroundSet()) {
 145             target.setBackground(SystemColor.window);
 146         } else {


 262     }
 263 
 264     protected final Graphics getOnscreenGraphics(Color fg, Color bg, Font f) {
 265         if (getSurfaceData() == null) {
 266             return null;
 267         }
 268         if (fg == null) {
 269             fg = SystemColor.windowText;
 270         }
 271         if (bg == null) {
 272             bg = SystemColor.window;
 273         }
 274         if (f == null) {
 275             f = DEFAULT_FONT;
 276         }
 277         return platformWindow.transformGraphics(new SunGraphics2D(getSurfaceData(), fg, bg, f));
 278     }
 279 
 280     @Override
 281     public void setBounds(int x, int y, int w, int h, int op) {
 282         
 283         if((op & NO_EMBEDDED_CHECK) == 0 && getPeerType() == PeerType.VIEWEMBEDDEDFRAME) {
 284             return;
 285         }
 286         
 287         if ((op & SET_CLIENT_SIZE) != 0) {
 288             // SET_CLIENT_SIZE is only applicable to window peers, so handle it here
 289             // instead of pulling 'insets' field up to LWComponentPeer
 290             // no need to add insets since Window's notion of width and height includes insets.
 291             op &= ~SET_CLIENT_SIZE;
 292             op |= SET_SIZE;
 293         }
 294 
 295         if (w < MINIMUM_WIDTH) {
 296             w = MINIMUM_WIDTH;
 297         }
 298         if (h < MINIMUM_HEIGHT) {
 299             h = MINIMUM_HEIGHT;
 300         }
 301 
 302         final int maxW = getLWGC().getMaxTextureWidth();
 303         final int maxH = getLWGC().getMaxTextureHeight();
 304 
 305         if (w > maxW) {
 306             w = maxW;


1202     }
1203     
1204     void grab() {
1205         if (grabbingWindow != null && !isGrabbing()) {
1206             grabbingWindow.ungrab();
1207         }
1208         grabbingWindow = this;
1209     }
1210 
1211     void ungrab() {
1212         if (isGrabbing()) {
1213             grabbingWindow = null;
1214             postEvent(new UngrabEvent(getTarget()));
1215         }
1216     }
1217 
1218     private boolean isGrabbing() {
1219         return this == grabbingWindow;
1220     }
1221 
1222     public PeerType getPeerType() {
1223         return peerType;
1224     }
1225 
1226     @Override
1227     public String toString() {
1228         return super.toString() + " [target is " + getTarget() + "]";
1229     }
1230 }