88 // on MOUSE_RELEASE. Click events are only generated if there were no drag
89 // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button
90 private static int mouseClickButtons = 0;
91
92 private volatile boolean isOpaque = true;
93
94 private static final Font DEFAULT_FONT = new Font("Lucida Grande", Font.PLAIN, 13);
95
96 private static LWWindowPeer grabbingWindow;
97
98 private volatile boolean skipNextFocusChange;
99
100 private static final Color nonOpaqueBackground = new Color(0, 0, 0, 0);
101
102 private volatile boolean textured;
103
104 private final PeerType peerType;
105
106 private final SecurityWarningWindow warningWindow;
107
108 /**
109 * Current modal blocker or null.
110 *
111 * Synchronization: peerTreeLock.
112 */
113 private LWWindowPeer blocker;
114
115 public LWWindowPeer(Window target, PlatformComponent platformComponent,
116 PlatformWindow platformWindow, PeerType peerType)
117 {
118 super(target, platformComponent);
119 this.platformWindow = platformWindow;
120 this.peerType = peerType;
121
122 Window owner = target.getOwner();
123 LWWindowPeer ownerPeer = owner == null ? null :
124 (LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(owner);
125 PlatformWindow ownerDelegate = (ownerPeer != null) ? ownerPeer.getPlatformWindow() : null;
126
127 // The delegate.initialize() needs a non-null GC on X11.
165 }
166
167 warningWindow = warn;
168 }
169
170 @Override
171 void initializeImpl() {
172 super.initializeImpl();
173
174
175 if (getTarget() instanceof Frame) {
176 setTitle(((Frame) getTarget()).getTitle());
177 setState(((Frame) getTarget()).getExtendedState());
178 } else if (getTarget() instanceof Dialog) {
179 setTitle(((Dialog) getTarget()).getTitle());
180 }
181
182 updateAlwaysOnTopState();
183 updateMinimumSize();
184
185 final Shape shape = getTarget().getShape();
186 if (shape != null) {
187 applyShape(Region.getInstance(shape, null));
188 }
189
190 final float opacity = getTarget().getOpacity();
191 if (opacity < 1.0f) {
192 setOpacity(opacity);
193 }
194
195 setOpaque(getTarget().isOpaque());
196
197 updateInsets(platformWindow.getInsets());
198 if (getSurfaceData() == null) {
199 replaceSurfaceData(false);
200 }
201 activateDisplayListener();
202 }
203
204 // Just a helper method
223 }
224 if (oldData != null) {
225 oldData.invalidate();
226 }
227 if (isGrabbing()) {
228 ungrab();
229 }
230 if (warningWindow != null) {
231 warningWindow.dispose();
232 }
233
234 platformWindow.dispose();
235 super.disposeImpl();
236 }
237
238 @Override
239 protected void setVisibleImpl(final boolean visible) {
240 if (!visible && warningWindow != null) {
241 warningWindow.setVisible(false, false);
242 }
243
244 super.setVisibleImpl(visible);
245 // TODO: update graphicsConfig, see 4868278
246 platformWindow.setVisible(visible);
247 if (isSimpleWindow()) {
248 KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
249
250 if (visible) {
251 if (!getTarget().isAutoRequestFocus()) {
252 return;
253 } else {
254 requestWindowFocus(CausedFocusEvent.Cause.ACTIVATION);
255 }
256 // Focus the owner in case this window is focused.
257 } else if (kfmPeer.getCurrentFocusedWindow() == getTarget()) {
258 // Transfer focus to the owner.
259 LWWindowPeer owner = getOwnerFrameDialog(LWWindowPeer.this);
260 if (owner != null) {
261 owner.requestWindowFocus(CausedFocusEvent.Cause.ACTIVATION);
262 }
263 }
264 }
265 }
266
267 @Override
268 public final GraphicsConfiguration getGraphicsConfiguration() {
269 synchronized (getStateLock()) {
270 return graphicsConfig;
271 }
272 }
273
274 @Override
275 public boolean updateGraphicsData(GraphicsConfiguration gc) {
276 setGraphicsConfig(gc);
277 return false;
278 }
279
280 protected final Graphics getOnscreenGraphics(Color fg, Color bg, Font f) {
281 if (getSurfaceData() == null) {
282 return null;
283 }
284 if (fg == null) {
380 platformWindow.toFront();
381 }
382
383 @Override
384 public void toBack() {
385 platformWindow.toBack();
386 }
387
388 @Override
389 public void setZOrder(ComponentPeer above) {
390 throw new RuntimeException("not implemented");
391 }
392
393 @Override
394 public void updateAlwaysOnTopState() {
395 platformWindow.setAlwaysOnTop(getTarget().isAlwaysOnTop());
396 }
397
398 @Override
399 public void updateFocusableWindowState() {
400 platformWindow.updateFocusableWindowState();
401 }
402
403 @Override
404 public void setModalBlocked(Dialog blocker, boolean blocked) {
405 synchronized (getPeerTreeLock()) {
406 ComponentPeer peer = AWTAccessor.getComponentAccessor().getPeer(blocker);
407 if (blocked && (peer instanceof LWWindowPeer)) {
408 this.blocker = (LWWindowPeer) peer;
409 } else {
410 this.blocker = null;
411 }
412 }
413
414 platformWindow.setModalBlocked(blocked);
415 }
416
417 @Override
418 public void updateMinimumSize() {
419 final Dimension min;
1202 changeFocusedWindow(true, opposite);
1203 return true;
1204
1205 // In case the toplevel is active but not focused, change focus directly,
1206 // as requesting native focus on it will not have effect.
1207 } else if (getTarget() == currentActive && !getTarget().hasFocus()) {
1208
1209 changeFocusedWindow(true, opposite);
1210 return true;
1211 }
1212
1213 return platformWindow.requestWindowFocus();
1214 }
1215
1216 protected boolean focusAllowedFor() {
1217 Window window = getTarget();
1218 // TODO: check if modal blocked
1219 return window.isVisible() && window.isEnabled() && isFocusableWindow();
1220 }
1221
1222 private boolean isFocusableWindow() {
1223 boolean focusable = getTarget().isFocusableWindow();
1224 if (isSimpleWindow()) {
1225 LWWindowPeer ownerPeer = getOwnerFrameDialog(this);
1226 if (ownerPeer == null) {
1227 return false;
1228 }
1229 return focusable && ownerPeer.getTarget().isFocusableWindow();
1230 }
1231 return focusable;
1232 }
1233
1234 public boolean isSimpleWindow() {
1235 Window window = getTarget();
1236 return !(window instanceof Dialog || window instanceof Frame);
1237 }
1238
1239 @Override
1240 public void emulateActivation(boolean activate) {
1241 changeFocusedWindow(activate, null);
1242 }
1243
1244 private boolean isOneOfOwnersOf(LWWindowPeer peer) {
1245 Window owner = (peer != null ? peer.getTarget().getOwner() : null);
1246 while (owner != null) {
1247 if ((LWWindowPeer)owner.getPeer() == this) {
1248 return true;
1249 }
|
88 // on MOUSE_RELEASE. Click events are only generated if there were no drag
89 // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button
90 private static int mouseClickButtons = 0;
91
92 private volatile boolean isOpaque = true;
93
94 private static final Font DEFAULT_FONT = new Font("Lucida Grande", Font.PLAIN, 13);
95
96 private static LWWindowPeer grabbingWindow;
97
98 private volatile boolean skipNextFocusChange;
99
100 private static final Color nonOpaqueBackground = new Color(0, 0, 0, 0);
101
102 private volatile boolean textured;
103
104 private final PeerType peerType;
105
106 private final SecurityWarningWindow warningWindow;
107
108 private volatile boolean targetFocusable;
109
110 /**
111 * Current modal blocker or null.
112 *
113 * Synchronization: peerTreeLock.
114 */
115 private LWWindowPeer blocker;
116
117 public LWWindowPeer(Window target, PlatformComponent platformComponent,
118 PlatformWindow platformWindow, PeerType peerType)
119 {
120 super(target, platformComponent);
121 this.platformWindow = platformWindow;
122 this.peerType = peerType;
123
124 Window owner = target.getOwner();
125 LWWindowPeer ownerPeer = owner == null ? null :
126 (LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(owner);
127 PlatformWindow ownerDelegate = (ownerPeer != null) ? ownerPeer.getPlatformWindow() : null;
128
129 // The delegate.initialize() needs a non-null GC on X11.
167 }
168
169 warningWindow = warn;
170 }
171
172 @Override
173 void initializeImpl() {
174 super.initializeImpl();
175
176
177 if (getTarget() instanceof Frame) {
178 setTitle(((Frame) getTarget()).getTitle());
179 setState(((Frame) getTarget()).getExtendedState());
180 } else if (getTarget() instanceof Dialog) {
181 setTitle(((Dialog) getTarget()).getTitle());
182 }
183
184 updateAlwaysOnTopState();
185 updateMinimumSize();
186
187 targetFocusable = getTarget().isFocusableWindow();
188
189 final Shape shape = getTarget().getShape();
190 if (shape != null) {
191 applyShape(Region.getInstance(shape, null));
192 }
193
194 final float opacity = getTarget().getOpacity();
195 if (opacity < 1.0f) {
196 setOpacity(opacity);
197 }
198
199 setOpaque(getTarget().isOpaque());
200
201 updateInsets(platformWindow.getInsets());
202 if (getSurfaceData() == null) {
203 replaceSurfaceData(false);
204 }
205 activateDisplayListener();
206 }
207
208 // Just a helper method
227 }
228 if (oldData != null) {
229 oldData.invalidate();
230 }
231 if (isGrabbing()) {
232 ungrab();
233 }
234 if (warningWindow != null) {
235 warningWindow.dispose();
236 }
237
238 platformWindow.dispose();
239 super.disposeImpl();
240 }
241
242 @Override
243 protected void setVisibleImpl(final boolean visible) {
244 if (!visible && warningWindow != null) {
245 warningWindow.setVisible(false, false);
246 }
247 updateFocusableWindowState();
248 super.setVisibleImpl(visible);
249 // TODO: update graphicsConfig, see 4868278
250 platformWindow.setVisible(visible);
251 if (isSimpleWindow()) {
252 KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
253 if (visible) {
254 if (!getTarget().isAutoRequestFocus()) {
255 return;
256 } else {
257 requestWindowFocus(CausedFocusEvent.Cause.ACTIVATION);
258 }
259 // Focus the owner in case this window is focused.
260 } else if (kfmPeer.getCurrentFocusedWindow() == getTarget()) {
261 // Transfer focus to the owner.
262 LWWindowPeer owner = getOwnerFrameDialog(LWWindowPeer.this);
263 if (owner != null) {
264 owner.requestWindowFocus(CausedFocusEvent.Cause.ACTIVATION);
265 }
266 }
267 }
268
269 }
270
271 @Override
272 public final GraphicsConfiguration getGraphicsConfiguration() {
273 synchronized (getStateLock()) {
274 return graphicsConfig;
275 }
276 }
277
278 @Override
279 public boolean updateGraphicsData(GraphicsConfiguration gc) {
280 setGraphicsConfig(gc);
281 return false;
282 }
283
284 protected final Graphics getOnscreenGraphics(Color fg, Color bg, Font f) {
285 if (getSurfaceData() == null) {
286 return null;
287 }
288 if (fg == null) {
384 platformWindow.toFront();
385 }
386
387 @Override
388 public void toBack() {
389 platformWindow.toBack();
390 }
391
392 @Override
393 public void setZOrder(ComponentPeer above) {
394 throw new RuntimeException("not implemented");
395 }
396
397 @Override
398 public void updateAlwaysOnTopState() {
399 platformWindow.setAlwaysOnTop(getTarget().isAlwaysOnTop());
400 }
401
402 @Override
403 public void updateFocusableWindowState() {
404 targetFocusable = getTarget().isFocusableWindow();
405 platformWindow.updateFocusableWindowState();
406 }
407
408 @Override
409 public void setModalBlocked(Dialog blocker, boolean blocked) {
410 synchronized (getPeerTreeLock()) {
411 ComponentPeer peer = AWTAccessor.getComponentAccessor().getPeer(blocker);
412 if (blocked && (peer instanceof LWWindowPeer)) {
413 this.blocker = (LWWindowPeer) peer;
414 } else {
415 this.blocker = null;
416 }
417 }
418
419 platformWindow.setModalBlocked(blocked);
420 }
421
422 @Override
423 public void updateMinimumSize() {
424 final Dimension min;
1207 changeFocusedWindow(true, opposite);
1208 return true;
1209
1210 // In case the toplevel is active but not focused, change focus directly,
1211 // as requesting native focus on it will not have effect.
1212 } else if (getTarget() == currentActive && !getTarget().hasFocus()) {
1213
1214 changeFocusedWindow(true, opposite);
1215 return true;
1216 }
1217
1218 return platformWindow.requestWindowFocus();
1219 }
1220
1221 protected boolean focusAllowedFor() {
1222 Window window = getTarget();
1223 // TODO: check if modal blocked
1224 return window.isVisible() && window.isEnabled() && isFocusableWindow();
1225 }
1226
1227 protected boolean isTargetFocusable() {
1228 return targetFocusable;
1229 }
1230
1231 private boolean isFocusableWindow() {
1232 boolean focusable = isTargetFocusable();
1233 if (isSimpleWindow()) {
1234 LWWindowPeer ownerPeer = getOwnerFrameDialog(this);
1235 if (ownerPeer == null) {
1236 return false;
1237 }
1238 return focusable && ownerPeer.isTargetFocusable();
1239 }
1240 return focusable;
1241 }
1242
1243 public boolean isSimpleWindow() {
1244 Window window = getTarget();
1245 return !(window instanceof Dialog || window instanceof Frame);
1246 }
1247
1248 @Override
1249 public void emulateActivation(boolean activate) {
1250 changeFocusedWindow(activate, null);
1251 }
1252
1253 private boolean isOneOfOwnersOf(LWWindowPeer peer) {
1254 Window owner = (peer != null ? peer.getTarget().getOwner() : null);
1255 while (owner != null) {
1256 if ((LWWindowPeer)owner.getPeer() == this) {
1257 return true;
1258 }
|