31 import java.awt.peer.*;
32 import java.util.List;
33
34 import javax.swing.*;
35
36 import sun.awt.*;
37 import sun.java2d.*;
38 import sun.java2d.loops.Blit;
39 import sun.java2d.loops.CompositeType;
40 import sun.java2d.pipe.Region;
41 import sun.util.logging.PlatformLogger;
42
43 public class LWWindowPeer
44 extends LWContainerPeer<Window, JComponent>
45 implements WindowPeer, FramePeer, DialogPeer, FullScreenCapable
46 {
47 public static enum PeerType {
48 SIMPLEWINDOW,
49 FRAME,
50 DIALOG,
51 EMBEDDEDFRAME
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
97 // depending on what mouse button is being dragged according to Cocoa
98 private static LWComponentPeer mouseDownTarget[] = new LWComponentPeer[3];
99
100 // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events
101 // on MOUSE_RELEASE. Click events are only generated if there were no drag
102 // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button
103 private static int mouseClickButtons = 0;
104
105 private volatile boolean isOpaque = true;
106
107 private static final Font DEFAULT_FONT = new Font("Lucida Grande", Font.PLAIN, 13);
108
109 private static LWWindowPeer grabbingWindow;
110
111 private volatile boolean skipNextFocusChange;
112
113 private static final Color nonOpaqueBackground = new Color(0, 0, 0, 0);
114
115 private volatile boolean textured;
116
117 /**
118 * Current modal blocker or null.
119 *
120 * Synchronization: peerTreeLock.
121 */
122 private LWWindowPeer blocker;
123
124 public LWWindowPeer(Window target, PlatformComponent platformComponent,
125 PlatformWindow platformWindow)
126 {
127 super(target, platformComponent);
128 this.platformWindow = platformWindow;
129
130 Window owner = target.getOwner();
131 LWWindowPeer ownerPeer = (owner != null) ? (LWWindowPeer)owner.getPeer() : null;
132 PlatformWindow ownerDelegate = (ownerPeer != null) ? ownerPeer.getPlatformWindow() : null;
133
134 // The delegate.initialize() needs a non-null GC on X11.
135 GraphicsConfiguration gc = getTarget().getGraphicsConfiguration();
136 synchronized (getStateLock()) {
137 // graphicsConfig should be updated according to the real window
138 // bounds when the window is shown, see 4868278
139 this.graphicsConfig = gc;
140 }
141
142 if (!target.isFontSet()) {
143 target.setFont(DEFAULT_FONT);
144 }
145
146 if (!target.isBackgroundSet()) {
147 target.setBackground(SystemColor.window);
148 } else {
322 bg.clearRect(0, 0, buffer.getWidth(), buffer.getHeight());
323 } finally {
324 bg.dispose();
325 }
326 }
327 }
328
329 @Override
330 public final void destroyBuffers() {
331 final Image oldBB = getBackBuffer();
332 synchronized (getStateLock()) {
333 backBuffer = null;
334 }
335 if (oldBB != null) {
336 oldBB.flush();
337 }
338 }
339
340 @Override
341 public void setBounds(int x, int y, int w, int h, int op) {
342 if ((op & SET_CLIENT_SIZE) != 0) {
343 // SET_CLIENT_SIZE is only applicable to window peers, so handle it here
344 // instead of pulling 'insets' field up to LWComponentPeer
345 // no need to add insets since Window's notion of width and height includes insets.
346 op &= ~SET_CLIENT_SIZE;
347 op |= SET_SIZE;
348 }
349
350 if (w < MINIMUM_WIDTH) {
351 w = MINIMUM_WIDTH;
352 }
353 if (h < MINIMUM_HEIGHT) {
354 h = MINIMUM_HEIGHT;
355 }
356
357 if (graphicsConfig instanceof TextureSizeConstraining) {
358 final int maxW = ((TextureSizeConstraining)graphicsConfig).getMaxTextureWidth();
359 final int maxH = ((TextureSizeConstraining)graphicsConfig).getMaxTextureHeight();
360
361 if (w > maxW) {
1290 }
1291
1292 void grab() {
1293 if (grabbingWindow != null && !isGrabbing()) {
1294 grabbingWindow.ungrab();
1295 }
1296 grabbingWindow = this;
1297 }
1298
1299 void ungrab() {
1300 if (isGrabbing()) {
1301 grabbingWindow = null;
1302 postEvent(new UngrabEvent(getTarget()));
1303 }
1304 }
1305
1306 private boolean isGrabbing() {
1307 return this == grabbingWindow;
1308 }
1309
1310 @Override
1311 public String toString() {
1312 return super.toString() + " [target is " + getTarget() + "]";
1313 }
1314 }
|
31 import java.awt.peer.*;
32 import java.util.List;
33
34 import javax.swing.*;
35
36 import sun.awt.*;
37 import sun.java2d.*;
38 import sun.java2d.loops.Blit;
39 import sun.java2d.loops.CompositeType;
40 import sun.java2d.pipe.Region;
41 import sun.util.logging.PlatformLogger;
42
43 public class LWWindowPeer
44 extends LWContainerPeer<Window, JComponent>
45 implements WindowPeer, FramePeer, DialogPeer, FullScreenCapable
46 {
47 public static enum PeerType {
48 SIMPLEWINDOW,
49 FRAME,
50 DIALOG,
51 EMBEDDEDFRAME,
52 VIEWEMBEDDEDFRAME
53 }
54
55 private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWWindowPeer");
56
57 private 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;
65 private int sysW;
66 private int sysH;
67
68 private static final int MINIMUM_WIDTH = 1;
69 private static final int MINIMUM_HEIGHT = 1;
70
71 private Insets insets = new Insets(0, 0, 0, 0);
72
98 // depending on what mouse button is being dragged according to Cocoa
99 private static LWComponentPeer mouseDownTarget[] = new LWComponentPeer[3];
100
101 // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events
102 // on MOUSE_RELEASE. Click events are only generated if there were no drag
103 // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button
104 private static int mouseClickButtons = 0;
105
106 private volatile boolean isOpaque = true;
107
108 private static final Font DEFAULT_FONT = new Font("Lucida Grande", Font.PLAIN, 13);
109
110 private static LWWindowPeer grabbingWindow;
111
112 private volatile boolean skipNextFocusChange;
113
114 private static final Color nonOpaqueBackground = new Color(0, 0, 0, 0);
115
116 private volatile boolean textured;
117
118 private final PeerType peerType;
119
120 /**
121 * Current modal blocker or null.
122 *
123 * Synchronization: peerTreeLock.
124 */
125 private LWWindowPeer blocker;
126
127 public LWWindowPeer(Window target, PlatformComponent platformComponent,
128 PlatformWindow platformWindow, PeerType peerType)
129 {
130 super(target, platformComponent);
131 this.platformWindow = platformWindow;
132 this.peerType = peerType;
133
134 Window owner = target.getOwner();
135 LWWindowPeer ownerPeer = (owner != null) ? (LWWindowPeer)owner.getPeer() : null;
136 PlatformWindow ownerDelegate = (ownerPeer != null) ? ownerPeer.getPlatformWindow() : null;
137
138 // The delegate.initialize() needs a non-null GC on X11.
139 GraphicsConfiguration gc = getTarget().getGraphicsConfiguration();
140 synchronized (getStateLock()) {
141 // graphicsConfig should be updated according to the real window
142 // bounds when the window is shown, see 4868278
143 this.graphicsConfig = gc;
144 }
145
146 if (!target.isFontSet()) {
147 target.setFont(DEFAULT_FONT);
148 }
149
150 if (!target.isBackgroundSet()) {
151 target.setBackground(SystemColor.window);
152 } else {
326 bg.clearRect(0, 0, buffer.getWidth(), buffer.getHeight());
327 } finally {
328 bg.dispose();
329 }
330 }
331 }
332
333 @Override
334 public final void destroyBuffers() {
335 final Image oldBB = getBackBuffer();
336 synchronized (getStateLock()) {
337 backBuffer = null;
338 }
339 if (oldBB != null) {
340 oldBB.flush();
341 }
342 }
343
344 @Override
345 public void setBounds(int x, int y, int w, int h, int op) {
346
347 if((op & NO_EMBEDDED_CHECK) == 0 && getPeerType() == PeerType.VIEWEMBEDDEDFRAME) {
348 return;
349 }
350
351 if ((op & SET_CLIENT_SIZE) != 0) {
352 // SET_CLIENT_SIZE is only applicable to window peers, so handle it here
353 // instead of pulling 'insets' field up to LWComponentPeer
354 // no need to add insets since Window's notion of width and height includes insets.
355 op &= ~SET_CLIENT_SIZE;
356 op |= SET_SIZE;
357 }
358
359 if (w < MINIMUM_WIDTH) {
360 w = MINIMUM_WIDTH;
361 }
362 if (h < MINIMUM_HEIGHT) {
363 h = MINIMUM_HEIGHT;
364 }
365
366 if (graphicsConfig instanceof TextureSizeConstraining) {
367 final int maxW = ((TextureSizeConstraining)graphicsConfig).getMaxTextureWidth();
368 final int maxH = ((TextureSizeConstraining)graphicsConfig).getMaxTextureHeight();
369
370 if (w > maxW) {
1299 }
1300
1301 void grab() {
1302 if (grabbingWindow != null && !isGrabbing()) {
1303 grabbingWindow.ungrab();
1304 }
1305 grabbingWindow = this;
1306 }
1307
1308 void ungrab() {
1309 if (isGrabbing()) {
1310 grabbingWindow = null;
1311 postEvent(new UngrabEvent(getTarget()));
1312 }
1313 }
1314
1315 private boolean isGrabbing() {
1316 return this == grabbingWindow;
1317 }
1318
1319 public PeerType getPeerType() {
1320 return peerType;
1321 }
1322
1323 @Override
1324 public String toString() {
1325 return super.toString() + " [target is " + getTarget() + "]";
1326 }
1327 }
|