LWWindowPeer.java revision 4802
4632N/A/*
4767N/A * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
4632N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4632N/A *
4632N/A * This code is free software; you can redistribute it and/or modify it
4632N/A * under the terms of the GNU General Public License version 2 only, as
4632N/A * published by the Free Software Foundation. Oracle designates this
4632N/A * particular file as subject to the "Classpath" exception as provided
4632N/A * by Oracle in the LICENSE file that accompanied this code.
4632N/A *
4632N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4632N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4632N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4632N/A * version 2 for more details (a copy is included in the LICENSE file that
4632N/A * accompanied this code).
4632N/A *
4632N/A * You should have received a copy of the GNU General Public License version
4632N/A * 2 along with this work; if not, write to the Free Software Foundation,
4632N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4632N/A *
4632N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4632N/A * or visit www.oracle.com if you need additional information or have any
4632N/A * questions.
4632N/A */
4632N/A
4632N/Apackage sun.lwawt;
4632N/A
4632N/Aimport java.awt.*;
4632N/Aimport java.awt.event.*;
4632N/Aimport java.awt.image.BufferedImage;
4632N/Aimport java.awt.peer.*;
4632N/Aimport java.util.List;
4632N/A
4632N/Aimport javax.swing.*;
4632N/A
4632N/Aimport sun.awt.*;
4632N/Aimport sun.java2d.*;
4639N/Aimport sun.java2d.loops.Blit;
4639N/Aimport sun.java2d.loops.CompositeType;
5232N/Aimport sun.util.logging.PlatformLogger;
4717N/A
4632N/Apublic class LWWindowPeer
4632N/A extends LWContainerPeer<Window, JComponent>
4632N/A implements WindowPeer, FramePeer, DialogPeer, FullScreenCapable
4632N/A{
4632N/A public static enum PeerType {
4632N/A SIMPLEWINDOW,
4632N/A FRAME,
4632N/A DIALOG,
4632N/A EMBEDDEDFRAME
5555N/A }
5555N/A
4632N/A private static final sun.util.logging.PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWWindowPeer");
4632N/A
4886N/A private PlatformWindow platformWindow;
4717N/A
4632N/A // Window bounds reported by the native system (as opposed to
4632N/A // regular bounds inherited from LWComponentPeer which are
4632N/A // requested by user and may haven't been applied yet because
4632N/A // of asynchronous requests to the windowing system)
4632N/A private int sysX;
4632N/A private int sysY;
4632N/A private int sysW;
4632N/A private int sysH;
4632N/A
4632N/A private static final int MINIMUM_WIDTH = 1;
4632N/A private static final int MINIMUM_HEIGHT = 1;
4639N/A
4639N/A private Insets insets = new Insets(0, 0, 0, 0);
4639N/A
4632N/A private int screenOn = -1;
4632N/A private GraphicsConfiguration graphicsConfig;
5041N/A
4632N/A private SurfaceData surfaceData;
4632N/A private final Object surfaceDataLock = new Object();
4632N/A
4686N/A private int backBufferCount;
4632N/A private BufferCapabilities backBufferCaps;
4632N/A
4632N/A // The back buffer is used for two purposes:
4632N/A // 1. To render all the lightweight peers
4632N/A // 2. To provide user with a BufferStrategy
4632N/A // Need to check if a single back buffer can be used for both
4632N/A// TODO: VolatileImage
4632N/A// private VolatileImage backBuffer;
4632N/A private volatile BufferedImage backBuffer;
4632N/A
4632N/A private volatile int windowState = Frame.NORMAL;
4632N/A
4632N/A // A peer where the last mouse event came to. Used to generate
4632N/A // MOUSE_ENTERED/EXITED notifications and by cursor manager to
4632N/A // find the component under cursor
4632N/A private static volatile LWComponentPeer lastMouseEventPeer = null;
4632N/A
4632N/A // Peers where all dragged/released events should come to,
4632N/A // depending on what mouse button is being dragged according to Cocoa
4632N/A private static LWComponentPeer mouseDownTarget[] = new LWComponentPeer[3];
4632N/A
4632N/A // A bitmask that indicates what mouse buttons produce MOUSE_CLICKED events
4632N/A // on MOUSE_RELEASE. Click events are only generated if there were no drag
4632N/A // events between MOUSE_PRESSED and MOUSE_RELEASED for particular button
4632N/A private static int mouseClickButtons = 0;
4632N/A
4632N/A private volatile boolean cachedFocusableWindow;
4632N/A
4691N/A private volatile boolean isOpaque = true;
4632N/A
4691N/A private static final Font DEFAULT_FONT = new Font("Lucida Grande", Font.PLAIN, 13);
4639N/A
4665N/A private static LWWindowPeer grabbingWindow;
4665N/A
4717N/A private volatile boolean skipNextFocusChange;
4717N/A
5232N/A /**
5232N/A * Current modal blocker or null.
5233N/A *
5233N/A * Synchronization: peerTreeLock.
5555N/A */
5555N/A private LWWindowPeer blocker;
4632N/A
4632N/A public LWWindowPeer(Window target, PlatformComponent platformComponent,
4632N/A PlatformWindow platformWindow)
4632N/A {
4632N/A super(target, platformComponent);
4632N/A this.platformWindow = platformWindow;
4632N/A
4632N/A Window owner = target.getOwner();
5555N/A LWWindowPeer ownerPeer = (owner != null) ? (LWWindowPeer)owner.getPeer() : null;
4632N/A PlatformWindow ownerDelegate = (ownerPeer != null) ? ownerPeer.getPlatformWindow() : null;
4632N/A
4632N/A // The delegate.initialize() needs a non-null GC on X11.
5555N/A GraphicsConfiguration gc = getTarget().getGraphicsConfiguration();
4632N/A synchronized (getStateLock()) {
4632N/A // graphicsConfig should be updated according to the real window
4632N/A // bounds when the window is shown, see 4868278
4632N/A this.graphicsConfig = gc;
4632N/A }
4632N/A
4632N/A if (!target.isFontSet()) {
4632N/A target.setFont(DEFAULT_FONT);
4632N/A }
4632N/A
4632N/A if (!target.isBackgroundSet()) {
4632N/A target.setBackground(SystemColor.window);
4632N/A } else {
4691N/A // first we check if user provided alpha for background. This is
4691N/A // similar to what Apple's Java do.
4691N/A // Since JDK7 we should rely on setOpacity() only.
4691N/A // this.opacity = c.getAlpha();
4691N/A // System.out.println("Delegate assigns alpha (we ignore setOpacity()):"
4691N/A // +this.opacity);
4691N/A }
4691N/A
4691N/A if (!target.isForegroundSet()) {
4691N/A target.setForeground(SystemColor.windowText);
4691N/A // we should not call setForeground because it will call a repaint
4691N/A // which the peer may not be ready to do yet.
4691N/A }
4691N/A
4691N/A platformWindow.initialize(target, this, ownerDelegate);
4691N/A }
4691N/A
4691N/A @Override
4691N/A public void initialize() {
4632N/A if (getTarget() instanceof Frame) {
4632N/A setTitle(((Frame)getTarget()).getTitle());
4632N/A setState(((Frame)getTarget()).getExtendedState());
4632N/A } else if (getTarget() instanceof Dialog) {
5166N/A setTitle(((Dialog)getTarget()).getTitle());
5166N/A }
4632N/A
5166N/A setAlwaysOnTop(getTarget().isAlwaysOnTop());
5166N/A updateMinimumSize();
4632N/A
5166N/A cachedFocusableWindow = getTarget().isFocusableWindow();
4632N/A
4632N/A setOpacity(getTarget().getOpacity());
4632N/A setOpaque(getTarget().isOpaque());
4632N/A
4632N/A super.initialize();
5232N/A
5232N/A updateInsets(platformWindow.getInsets());
5232N/A }
5232N/A
5232N/A // Just a helper method
5166N/A public PlatformWindow getPlatformWindow() {
5166N/A return platformWindow;
5166N/A }
5166N/A
5166N/A @Override
4639N/A protected LWWindowPeer getWindowPeerOrSelf() {
4632N/A return this;
4767N/A }
5166N/A
5232N/A @Override
5166N/A protected void initializeContainerPeer() {
4632N/A // No-op as LWWindowPeer doesn't have any containerPeer
4632N/A }
4632N/A
4632N/A // ---- PEER METHODS ---- //
4632N/A
4632N/A @Override
4632N/A protected void disposeImpl() {
4632N/A SurfaceData oldData = getSurfaceData();
4632N/A synchronized (surfaceDataLock){
4632N/A surfaceData = null;
4632N/A }
4632N/A if (oldData != null) {
4632N/A oldData.invalidate();
4632N/A }
4632N/A if (isGrabbing()) {
4632N/A ungrab();
4632N/A }
4632N/A destroyBuffers();
4632N/A platformWindow.dispose();
4632N/A super.disposeImpl();
4632N/A }
4639N/A
4686N/A @Override
4686N/A public void setVisible(final boolean visible) {
4686N/A if (getSurfaceData() == null) {
4632N/A replaceSurfaceData();
4632N/A }
4632N/A
4665N/A if (isVisible() == visible) {
4665N/A return;
4665N/A }
4693N/A super.setVisible(visible);
4632N/A
4632N/A // TODO: update graphicsConfig, see 4868278
4632N/A // TODO: don't notify the delegate if our visibility is unchanged
4632N/A
4632N/A // it is important to call this method on EDT
5166N/A // to prevent the deadlocks during the painting of the lightweight delegates
5166N/A //TODO: WHY? This is a native-system related call. Perhaps NOT calling
4632N/A // the painting procedure right from the setVisible(), but rather relying
5166N/A // on the native Expose event (or, scheduling the repainting asynchronously)
5166N/A // is better?
5336N/A SwingUtilities.invokeLater(new Runnable() {
4632N/A @Override
5166N/A public void run() {
5166N/A platformWindow.setVisible(visible);
5166N/A if (isSimpleWindow()) {
5166N/A LWKeyboardFocusManagerPeer manager = LWKeyboardFocusManagerPeer.
5166N/A getInstance(getAppContext());
5166N/A
5336N/A if (visible) {
5166N/A updateFocusableWindowState();
5166N/A changeFocusedWindow(true, true);
5166N/A
5166N/A // Focus the owner in case this window is focused.
4632N/A } else if (manager.getCurrentFocusedWindow() == getTarget()) {
4632N/A LWWindowPeer owner = getOwnerFrameDialog(LWWindowPeer.this);
5166N/A if (owner != null) {
4632N/A // KFM will do all the rest.
4632N/A owner.changeFocusedWindow(true, false);
4632N/A }
4632N/A }
4632N/A }
4632N/A }
4632N/A });
4632N/A }
4632N/A
4632N/A @Override
4632N/A public GraphicsConfiguration getGraphicsConfiguration() {
4632N/A return graphicsConfig;
4632N/A }
4686N/A
4639N/A @Override
4639N/A public boolean updateGraphicsData(GraphicsConfiguration gc) {
4639N/A setGraphicsConfig(gc);
4632N/A return false;
4632N/A }
4632N/A
4632N/A protected final Graphics getOnscreenGraphics(Color fg, Color bg, Font f) {
4632N/A if (getSurfaceData() == null) {
4632N/A return null;
4632N/A }
4632N/A if (fg == null) {
4632N/A fg = SystemColor.windowText;
4639N/A }
4632N/A if (bg == null) {
4632N/A bg = SystemColor.window;
4632N/A }
4632N/A if (f == null) {
4632N/A f = DEFAULT_FONT;
4632N/A }
4632N/A return platformWindow.transformGraphics(new SunGraphics2D(getSurfaceData(), fg, bg, f));
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void createBuffers(int numBuffers, BufferCapabilities caps)
4632N/A throws AWTException
4632N/A {
5232N/A try {
4632N/A // Assume this method is never called with numBuffers <= 1, as 0 is
4632N/A // unsupported, and 1 corresponds to a SingleBufferStrategy which
4632N/A // doesn't depend on the peer. Screen is considered as a separate
4632N/A // "buffer", that's why numBuffers - 1
4632N/A assert numBuffers > 1;
4632N/A
4693N/A replaceSurfaceData(numBuffers - 1, caps);
4693N/A } catch (InvalidPipeException z) {
4693N/A throw new AWTException(z.toString());
4693N/A }
4632N/A }
4632N/A
4632N/A @Override
4632N/A public final Image getBackBuffer() {
4632N/A synchronized (getStateLock()) {
4632N/A return backBuffer;
4869N/A }
4869N/A }
4869N/A
4869N/A @Override
4869N/A public void flip(int x1, int y1, int x2, int y2,
4869N/A BufferCapabilities.FlipContents flipAction)
4869N/A {
4869N/A platformWindow.flip(x1, y1, x2, y2, flipAction);
4869N/A }
4869N/A
4869N/A @Override
4869N/A public final void destroyBuffers() {
4869N/A final Image oldBB = getBackBuffer();
4869N/A synchronized (getStateLock()) {
4869N/A backBuffer = null;
4869N/A }
4869N/A if (oldBB != null) {
4869N/A oldBB.flush();
4869N/A }
4632N/A }
4632N/A
4632N/A @Override
4693N/A public void setBounds(int x, int y, int w, int h, int op) {
4693N/A if ((op & SET_CLIENT_SIZE) != 0) {
4693N/A // SET_CLIENT_SIZE is only applicable to window peers, so handle it here
4693N/A // instead of pulling 'insets' field up to LWComponentPeer
4693N/A // no need to add insets since Window's notion of width and height includes insets.
4693N/A op &= ~SET_CLIENT_SIZE;
4693N/A op |= SET_SIZE;
4693N/A }
4632N/A
4632N/A if (w < MINIMUM_WIDTH) {
4632N/A w = MINIMUM_WIDTH;
4632N/A }
5555N/A if (h < MINIMUM_HEIGHT) {
5555N/A h = MINIMUM_HEIGHT;
5555N/A }
5555N/A
5555N/A // Don't post ComponentMoved/Resized and Paint events
4632N/A // until we've got a notification from the delegate
4632N/A setBounds(x, y, w, h, op, false, false);
4632N/A // Get updated bounds, so we don't have to handle 'op' here manually
4632N/A Rectangle r = getBounds();
4632N/A platformWindow.setBounds(r.x, r.y, r.width, r.height);
4632N/A }
4632N/A
4632N/A @Override
4639N/A public Point getLocationOnScreen() {
4639N/A return platformWindow.getLocationOnScreen();
4639N/A }
4639N/A
4639N/A /**
4639N/A * Overridden from LWContainerPeer to return the correct insets.
4632N/A * Insets are queried from the delegate and are kept up to date by
5276N/A * requiering when needed (i.e. when the window geometry is changed).
5276N/A */
5276N/A @Override
5276N/A public Insets getInsets() {
5276N/A synchronized (getStateLock()) {
5276N/A return insets;
5276N/A }
5276N/A }
5276N/A
5276N/A @Override
5276N/A public FontMetrics getFontMetrics(Font f) {
5276N/A // TODO: check for "use platform metrics" settings
4632N/A return platformWindow.getFontMetrics(f);
4632N/A }
4639N/A
4632N/A @Override
4632N/A public void toFront() {
4632N/A platformWindow.toFront();
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void toBack() {
4632N/A platformWindow.toBack();
4632N/A }
4632N/A
4639N/A @Override
4632N/A public void setZOrder(ComponentPeer above) {
4632N/A throw new RuntimeException("not implemented");
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void setAlwaysOnTop(boolean value) {
4632N/A platformWindow.setAlwaysOnTop(value);
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void updateFocusableWindowState() {
4632N/A cachedFocusableWindow = getTarget().isFocusableWindow();
4632N/A platformWindow.updateFocusableWindowState();
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void setModalBlocked(Dialog blocker, boolean blocked) {
4632N/A synchronized (getPeerTreeLock()) {
4632N/A if(blocked && blocker.getPeer() instanceof LWWindowPeer) {
4632N/A this.blocker = (LWWindowPeer)blocker.getPeer();
4632N/A } else {
4632N/A this.blocker = null;
4632N/A }
4632N/A }
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void updateMinimumSize() {
4632N/A Dimension d = null;
4632N/A if (getTarget().isMinimumSizeSet()) {
4632N/A d = getTarget().getMinimumSize();
4632N/A }
4632N/A if (d == null) {
4632N/A d = new Dimension(MINIMUM_WIDTH, MINIMUM_HEIGHT);
4632N/A }
4632N/A platformWindow.setMinimumSize(d.width, d.height);
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void updateIconImages() {
4632N/A getPlatformWindow().updateIconImages();
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void setOpacity(float opacity) {
4802N/A getPlatformWindow().setOpacity(opacity);
4802N/A repaintPeer();
4802N/A }
4802N/A
4802N/A @Override
4632N/A public final void setOpaque(final boolean isOpaque) {
4996N/A if (this.isOpaque != isOpaque) {
4996N/A this.isOpaque = isOpaque;
4632N/A getPlatformWindow().setOpaque(isOpaque);
4632N/A replaceSurfaceData();
4632N/A repaintPeer();
4632N/A }
5276N/A }
4632N/A
5276N/A public final boolean isOpaque() {
5276N/A return isOpaque;
5276N/A }
5276N/A
5276N/A @Override
4632N/A public void updateWindow() {
5276N/A flushOffscreenGraphics();
5276N/A }
5276N/A
5276N/A @Override
5276N/A public void repositionSecurityWarning() {
5276N/A throw new RuntimeException("not implemented");
5276N/A }
4632N/A
5276N/A // ---- FRAME PEER METHODS ---- //
5276N/A
5276N/A @Override // FramePeer and DialogPeer
5276N/A public void setTitle(String title) {
5276N/A platformWindow.setTitle(title == null ? "" : title);
5276N/A }
5276N/A
5276N/A @Override
5276N/A public void setMenuBar(MenuBar mb) {
5276N/A platformWindow.setMenuBar(mb);
5276N/A }
4632N/A
4632N/A @Override // FramePeer and DialogPeer
4632N/A public void setResizable(boolean resizable) {
4632N/A platformWindow.setResizable(resizable);
4632N/A }
4632N/A
4632N/A @Override
4632N/A public void setState(int state) {
4632N/A platformWindow.setWindowState(state);
4632N/A }
4767N/A
4632N/A @Override
4632N/A public int getState() {
4632N/A return windowState;
4767N/A }
4639N/A
4639N/A @Override
5232N/A public void setMaximizedBounds(Rectangle bounds) {
4639N/A // TODO: not implemented
4639N/A }
4639N/A
5232N/A @Override
5232N/A public void setBoundsPrivate(int x, int y, int width, int height) {
5232N/A setBounds(x, y, width, height, SET_BOUNDS | NO_EMBEDDED_CHECK);
5232N/A }
4632N/A
4632N/A @Override
4632N/A public Rectangle getBoundsPrivate() {
4632N/A throw new RuntimeException("not implemented");
5232N/A }
5232N/A
5233N/A // ---- DIALOG PEER METHODS ---- //
5233N/A
5233N/A @Override
5233N/A public void blockWindows(List<Window> windows) {
5233N/A //TODO: LWX will probably need some collectJavaToplevels to speed this up
5233N/A for (Window w : windows) {
5233N/A WindowPeer wp = (WindowPeer)w.getPeer();
5233N/A if (wp != null) {
5232N/A wp.setModalBlocked((Dialog)getTarget(), true);
5232N/A }
5233N/A }
5233N/A }
5233N/A
5233N/A // ---- PEER NOTIFICATIONS ---- //
5233N/A
5233N/A public void notifyIconify(boolean iconify) {
5233N/A //The toplevel target is Frame and states are applicable to it.
5232N/A //Otherwise, the target is Window and it don't have state property.
5232N/A //Hopefully, no such events are posted in the queue so consider the
5232N/A //target as Frame in all cases.
5232N/A
5232N/A // REMIND: should we send it anyway if the state not changed since last
5232N/A // time?
5232N/A WindowEvent iconifyEvent = new WindowEvent(getTarget(),
4632N/A iconify ? WindowEvent.WINDOW_ICONIFIED
4632N/A : WindowEvent.WINDOW_DEICONIFIED);
4632N/A postEvent(iconifyEvent);
4632N/A
4632N/A int newWindowState = iconify ? Frame.ICONIFIED : Frame.NORMAL;
4632N/A postWindowStateChangedEvent(newWindowState);
4632N/A
4632N/A // REMIND: RepaintManager doesn't repaint iconified windows and
4632N/A // hence ignores any repaint request during deiconification.
4632N/A // So, we need to repaint window explicitly when it becomes normal.
4632N/A if (!iconify) {
4632N/A repaintPeer();
4632N/A }
4632N/A }
4632N/A
4632N/A public void notifyZoom(boolean isZoomed) {
4632N/A int newWindowState = isZoomed ? Frame.MAXIMIZED_BOTH : Frame.NORMAL;
4632N/A postWindowStateChangedEvent(newWindowState);
4632N/A }
4632N/A
4632N/A /**
4632N/A * Called by the delegate when any part of the window should be repainted.
4632N/A */
4632N/A public void notifyExpose(final int x, final int y, final int w, final int h) {
4632N/A // TODO: there's a serious problem with Swing here: it handles
4632N/A // the exposition internally, so SwingPaintEventDispatcher always
4632N/A // return null from createPaintEvent(). However, we flush the
4632N/A // back buffer here unconditionally, so some flickering may appear.
4632N/A // A possible solution is to split postPaintEvent() into two parts,
4632N/A // and override that part which is only called after if
4632N/A // createPaintEvent() returned non-null value and flush the buffer
4632N/A // from the overridden method
4632N/A flushOnscreenGraphics();
4632N/A repaintPeer(new Rectangle(x, y, w, h));
4632N/A }
4632N/A
4632N/A /**
4632N/A * Called by the delegate when this window is moved/resized by user.
4632N/A * There's no notifyReshape() in LWComponentPeer as the only
4632N/A * components which could be resized by user are top-level windows.
4632N/A */
4655N/A public final void notifyReshape(int x, int y, int w, int h) {
4632N/A boolean moved = false;
4632N/A boolean resized = false;
4632N/A synchronized (getStateLock()) {
4632N/A moved = (x != sysX) || (y != sysY);
4632N/A resized = (w != sysW) || (h != sysH);
4632N/A sysX = x;
4632N/A sysY = y;
4632N/A sysW = w;
4632N/A sysH = h;
4632N/A }
4632N/A
4632N/A // Check if anything changed
4632N/A if (!moved && !resized) {
4632N/A return;
4632N/A }
4632N/A // First, update peer's bounds
4632N/A setBounds(x, y, w, h, SET_BOUNDS, false, false);
4632N/A
4632N/A // Second, update the graphics config and surface data
4632N/A checkIfOnNewScreen();
4632N/A if (resized) {
4632N/A replaceSurfaceData();
4632N/A flushOnscreenGraphics();
4632N/A }
4632N/A
4632N/A // Third, COMPONENT_MOVED/COMPONENT_RESIZED events
4632N/A if (moved) {
4632N/A handleMove(x, y, true);
4632N/A }
4632N/A if (resized) {
4632N/A handleResize(w, h,true);
4632N/A }
4632N/A }
4632N/A
4632N/A private void clearBackground(final int w, final int h) {
4632N/A final Graphics g = getOnscreenGraphics(getForeground(), getBackground(),
4632N/A getFont());
4632N/A if (g != null) {
4632N/A try {
4632N/A g.clearRect(0, 0, w, h);
4632N/A } finally {
4632N/A g.dispose();
4632N/A }
4632N/A }
4632N/A }
4632N/A
4632N/A public void notifyUpdateCursor() {
4632N/A getLWToolkit().getCursorManager().updateCursorLater(this);
4632N/A }
4632N/A
4632N/A public void notifyActivation(boolean activation) {
4639N/A changeFocusedWindow(activation, false);
4632N/A }
4632N/A
4632N/A // MouseDown in non-client area
4632N/A public void notifyNCMouseDown() {
4632N/A // Ungrab except for a click on a Dialog with the grabbing owner
4632N/A if (grabbingWindow != null &&
4632N/A grabbingWindow != getOwnerFrameDialog(this))
4632N/A {
4632N/A grabbingWindow.ungrab();
4632N/A }
4632N/A }
4639N/A
4639N/A // ---- EVENTS ---- //
4632N/A
4632N/A /*
4639N/A * Called by the delegate to dispatch the event to Java. Event
4632N/A * coordinates are relative to non-client window are, i.e. the top-left
4632N/A * point of the client area is (insets.top, insets.left).
4632N/A */
4632N/A public void dispatchMouseEvent(int id, long when, int button,
4639N/A int x, int y, int screenX, int screenY,
4632N/A int modifiers, int clickCount, boolean popupTrigger,
4632N/A byte[] bdata)
4632N/A {
4632N/A // TODO: fill "bdata" member of AWTEvent
4632N/A Rectangle r = getBounds();
4632N/A // findPeerAt() expects parent coordinates
4632N/A LWComponentPeer targetPeer = findPeerAt(r.x + x, r.y + y);
4632N/A LWWindowPeer lastWindowPeer =
4632N/A (lastMouseEventPeer != null) ? lastMouseEventPeer.getWindowPeerOrSelf() : null;
4632N/A LWWindowPeer curWindowPeer =
4632N/A (targetPeer != null) ? targetPeer.getWindowPeerOrSelf() : null;
4632N/A
4632N/A if (id == MouseEvent.MOUSE_EXITED) {
4632N/A // Sometimes we may get MOUSE_EXITED after lastMouseEventPeer is switched
4632N/A // to a peer from another window. So we must first check if this peer is
4632N/A // the same as lastWindowPeer
4639N/A if (lastWindowPeer == this) {
4632N/A if (isEnabled()) {
4632N/A Point lp = lastMouseEventPeer.windowToLocal(x, y,
4632N/A lastWindowPeer);
4632N/A postEvent(new MouseEvent(lastMouseEventPeer.getTarget(),
4632N/A MouseEvent.MOUSE_EXITED, when,
4639N/A modifiers, lp.x, lp.y, screenX,
4632N/A screenY, clickCount, popupTrigger,
4632N/A button));
4639N/A }
4632N/A lastMouseEventPeer = null;
4639N/A }
4632N/A } else {
4632N/A if (targetPeer != lastMouseEventPeer) {
4639N/A // lastMouseEventPeer may be null if mouse was out of Java windows
4639N/A if (lastMouseEventPeer != null && lastMouseEventPeer.isEnabled()) {
4639N/A // Sometimes, MOUSE_EXITED is not sent by delegate (or is sent a bit
4639N/A // later), in which case lastWindowPeer is another window
4639N/A if (lastWindowPeer != this) {
4639N/A Point oldp = lastMouseEventPeer.windowToLocal(x, y, lastWindowPeer);
4639N/A // Additionally translate from this to lastWindowPeer coordinates
4639N/A Rectangle lr = lastWindowPeer.getBounds();
4639N/A oldp.x += r.x - lr.x;
5232N/A oldp.y += r.y - lr.y;
5232N/A postEvent(new MouseEvent(lastMouseEventPeer.getTarget(),
5232N/A MouseEvent.MOUSE_EXITED,
5232N/A when, modifiers,
5232N/A oldp.x, oldp.y, screenX, screenY,
5232N/A clickCount, popupTrigger, button));
5232N/A } else {
5233N/A Point oldp = lastMouseEventPeer.windowToLocal(x, y, this);
5233N/A postEvent(new MouseEvent(lastMouseEventPeer.getTarget(),
5233N/A MouseEvent.MOUSE_EXITED,
5233N/A when, modifiers,
5233N/A oldp.x, oldp.y, screenX, screenY,
5233N/A clickCount, popupTrigger, button));
5232N/A }
4639N/A }
4639N/A lastMouseEventPeer = targetPeer;
4639N/A if (targetPeer != null && targetPeer.isEnabled() && id != MouseEvent.MOUSE_ENTERED) {
4632N/A Point newp = targetPeer.windowToLocal(x, y, curWindowPeer);
4632N/A postEvent(new MouseEvent(targetPeer.getTarget(),
4632N/A MouseEvent.MOUSE_ENTERED,
4632N/A when, modifiers,
4632N/A newp.x, newp.y, screenX, screenY,
4632N/A clickCount, popupTrigger, button));
4632N/A }
4632N/A }
4886N/A // TODO: fill "bdata" member of AWTEvent
4632N/A
4632N/A int eventButtonMask = (button > 0)? MouseEvent.getMaskForButton(button) : 0;
4665N/A int otherButtonsPressed = modifiers & ~eventButtonMask;
4665N/A
4665N/A // For pressed/dragged/released events OS X treats other
4665N/A // mouse buttons as if they were BUTTON2, so we do the same
4722N/A int targetIdx = (button > 3) ? MouseEvent.BUTTON2 - 1 : button - 1;
4665N/A
4665N/A // MOUSE_ENTERED/EXITED are generated for the components strictly under
4665N/A // mouse even when dragging. That's why we first update lastMouseEventPeer
4665N/A // based on initial targetPeer value and only then recalculate targetPeer
4665N/A // for MOUSE_DRAGGED/RELEASED events
4632N/A if (id == MouseEvent.MOUSE_PRESSED) {
4632N/A
4632N/A // Ungrab only if this window is not an owned window of the grabbing one.
4632N/A if (!isGrabbing() && grabbingWindow != null &&
4632N/A grabbingWindow != getOwnerFrameDialog(this))
4632N/A {
4632N/A grabbingWindow.ungrab();
4632N/A }
4632N/A if (otherButtonsPressed == 0) {
4632N/A mouseClickButtons = eventButtonMask;
4632N/A } else {
4632N/A mouseClickButtons |= eventButtonMask;
4632N/A }
4632N/A
4632N/A mouseDownTarget[targetIdx] = targetPeer;
4632N/A } else if (id == MouseEvent.MOUSE_DRAGGED) {
4632N/A // Cocoa dragged event has the information about which mouse
4632N/A // button is being dragged. Use it to determine the peer that
4632N/A // should receive the dragged event.
4632N/A targetPeer = mouseDownTarget[targetIdx];
4632N/A mouseClickButtons &= ~modifiers;
4632N/A } else if (id == MouseEvent.MOUSE_RELEASED) {
4632N/A // TODO: currently, mouse released event goes to the same component
4632N/A // that received corresponding mouse pressed event. For most cases,
4632N/A // it's OK, however, we need to make sure that our behavior is consistent
4632N/A // with 1.6 for cases where component in question have been
4632N/A // hidden/removed in between of mouse pressed/released events.
4632N/A targetPeer = mouseDownTarget[targetIdx];
4632N/A
4632N/A if ((modifiers & eventButtonMask) == 0) {
4632N/A mouseDownTarget[targetIdx] = null;
4632N/A }
4632N/A
4632N/A // mouseClickButtons is updated below, after MOUSE_CLICK is sent
4632N/A }
4632N/A
4632N/A // check if we receive mouseEvent from outside the window's bounds
4632N/A // it can be either mouseDragged or mouseReleased
4632N/A if (curWindowPeer == null) {
5295N/A //TODO This can happen if this window is invisible. this is correct behavior in this case?
5295N/A curWindowPeer = this;
5295N/A }
5295N/A if (targetPeer == null) {
5295N/A //TODO This can happen if this window is invisible. this is correct behavior in this case?
5295N/A targetPeer = this;
5295N/A }
5295N/A
5295N/A
5295N/A Point lp = targetPeer.windowToLocal(x, y, curWindowPeer);
5295N/A if (targetPeer.isEnabled()) {
5295N/A MouseEvent event = new MouseEvent(targetPeer.getTarget(), id,
4632N/A when, modifiers, lp.x, lp.y,
5295N/A screenX, screenY, clickCount,
5295N/A popupTrigger, button);
5295N/A postEvent(event);
5295N/A }
5295N/A
5295N/A if (id == MouseEvent.MOUSE_RELEASED) {
5295N/A if ((mouseClickButtons & eventButtonMask) != 0
5295N/A && targetPeer.isEnabled()) {
4632N/A postEvent(new MouseEvent(targetPeer.getTarget(),
4632N/A MouseEvent.MOUSE_CLICKED,
4632N/A when, modifiers,
4632N/A lp.x, lp.y, screenX, screenY,
5295N/A clickCount, popupTrigger, button));
5295N/A }
5295N/A mouseClickButtons &= ~eventButtonMask;
5295N/A }
5295N/A
5295N/A notifyUpdateCursor();
5295N/A }
5295N/A }
4632N/A
4632N/A public void dispatchMouseWheelEvent(long when, int x, int y, int modifiers,
4632N/A int scrollType, int scrollAmount,
4734N/A int wheelRotation, double preciseWheelRotation,
4734N/A byte[] bdata)
4734N/A {
4734N/A // TODO: could we just use the last mouse event target here?
4632N/A Rectangle r = getBounds();
4734N/A // findPeerAt() expects parent coordinates
4632N/A final LWComponentPeer targetPeer = findPeerAt(r.x + x, r.y + y);
4632N/A if (targetPeer == null || !targetPeer.isEnabled()) {
4632N/A return;
4632N/A }
4632N/A
4632N/A Point lp = targetPeer.windowToLocal(x, y, this);
4665N/A // TODO: fill "bdata" member of AWTEvent
4665N/A // TODO: screenX/screenY
4665N/A postEvent(new MouseWheelEvent(targetPeer.getTarget(),
4722N/A MouseEvent.MOUSE_WHEEL,
4665N/A when, modifiers,
4665N/A lp.x, lp.y,
4665N/A 0, 0, /* screenX, Y */
4632N/A 0 /* clickCount */, false /* popupTrigger */,
4632N/A scrollType, scrollAmount,
4632N/A wheelRotation, preciseWheelRotation));
4632N/A }
4632N/A
4632N/A /*
4632N/A * Called by the delegate when a key is pressed.
4632N/A */
4632N/A public void dispatchKeyEvent(int id, long when, int modifiers,
4632N/A int keyCode, char keyChar, int keyLocation)
4632N/A {
4632N/A LWComponentPeer focusOwner =
4734N/A LWKeyboardFocusManagerPeer.getInstance(getAppContext()).
4632N/A getFocusOwner();
4632N/A
4632N/A // Null focus owner may receive key event when
4632N/A // application hides the focused window upon ESC press
4632N/A // (AWT transfers/clears the focus owner) and pending ESC release
4632N/A // may come to already hidden window. This check eliminates NPE.
4632N/A if (focusOwner != null) {
4632N/A KeyEvent event =
4734N/A new KeyEvent(focusOwner.getTarget(), id, when, modifiers,
4632N/A keyCode, keyChar, keyLocation);
4632N/A focusOwner.postEvent(event);
4632N/A }
4632N/A }
4632N/A
4632N/A
4632N/A // ---- UTILITY METHODS ---- //
4632N/A
4632N/A private void postWindowStateChangedEvent(int newWindowState) {
4632N/A if (getTarget() instanceof Frame) {
4632N/A AWTAccessor.getFrameAccessor().setExtendedState(
4632N/A (Frame)getTarget(), newWindowState);
4632N/A }
4632N/A WindowEvent stateChangedEvent = new WindowEvent(getTarget(),
4632N/A WindowEvent.WINDOW_STATE_CHANGED,
4632N/A windowState, newWindowState);
4632N/A postEvent(stateChangedEvent);
4632N/A windowState = newWindowState;
4632N/A }
4632N/A
4632N/A private static int getGraphicsConfigScreen(GraphicsConfiguration gc) {
4632N/A // TODO: this method can be implemented in a more
4632N/A // efficient way by forwarding to the delegate
4632N/A GraphicsDevice gd = gc.getDevice();
4632N/A GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
4632N/A GraphicsDevice[] gds = ge.getScreenDevices();
4632N/A for (int i = 0; i < gds.length; i++) {
4632N/A if (gds[i] == gd) {
4632N/A return i;
4632N/A }
4632N/A }
4632N/A // Should never happen if gc is a screen device config
4632N/A return 0;
4632N/A }
4632N/A
4632N/A private static GraphicsConfiguration getScreenGraphicsConfig(int screen) {
4632N/A GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
4632N/A GraphicsDevice[] gds = ge.getScreenDevices();
4632N/A if (screen >= gds.length) {
5137N/A // This could happen during device addition/removal. Use
4632N/A // the default screen device in this case
4632N/A return ge.getDefaultScreenDevice().getDefaultConfiguration();
4632N/A }
4632N/A return gds[screen].getDefaultConfiguration();
4632N/A }
4632N/A
4632N/A /*
4632N/A * This method is called when window's graphics config is changed from
4632N/A * the app code (e.g. when the window is made non-opaque) or when
4632N/A * the window is moved to another screen by user.
4632N/A *
4632N/A * Returns true if the graphics config has been changed, false otherwise.
4632N/A */
4632N/A private boolean setGraphicsConfig(GraphicsConfiguration gc) {
4632N/A synchronized (getStateLock()) {
4632N/A if (graphicsConfig == gc) {
4632N/A return false;
4632N/A }
4632N/A // If window's graphics config is changed from the app code, the
4632N/A // config correspond to the same device as before; when the window
4632N/A // is moved by user, screenOn is updated in checkIfOnNewScreen().
4632N/A // In either case, there's nothing to do with screenOn here
4632N/A graphicsConfig = gc;
4632N/A }
4632N/A // SurfaceData is replaced later in updateGraphicsData()
4632N/A return true;
4632N/A }
4632N/A
4632N/A private void checkIfOnNewScreen() {
4632N/A int windowScreen = platformWindow.getScreenImOn();
4632N/A synchronized (getStateLock()) {
4632N/A if (windowScreen == screenOn) {
4632N/A return;
4632N/A }
5642N/A screenOn = windowScreen;
5336N/A }
4632N/A
5642N/A // TODO: DisplayChangedListener stuff
5642N/A final GraphicsConfiguration newGC = getScreenGraphicsConfig(windowScreen);
5642N/A if (!setGraphicsConfig(newGC)) return;
5642N/A
5642N/A SunToolkit.executeOnEventHandlerThread(getTarget(), new Runnable() {
4632N/A public void run() {
5642N/A AWTAccessor.getComponentAccessor().setGraphicsConfiguration(getTarget(), newGC);
4632N/A }
4632N/A });
4632N/A }
4632N/A
4632N/A /**
4632N/A * This method returns a back buffer Graphics to render all the
4632N/A * peers to. After the peer is painted, the back buffer contents
4632N/A * should be flushed to the screen. All the target painting
4632N/A * (Component.paint() method) should be done directly to the screen.
4632N/A */
4639N/A protected final Graphics getOffscreenGraphics(Color fg, Color bg, Font f) {
4632N/A final Image bb = getBackBuffer();
4632N/A if (bb == null) {
4632N/A return null;
4632N/A }
4632N/A if (fg == null) {
4632N/A fg = SystemColor.windowText;
4632N/A }
4632N/A if (bg == null) {
4632N/A bg = SystemColor.window;
4632N/A }
4632N/A if (f == null) {
4632N/A f = DEFAULT_FONT;
4632N/A }
4632N/A final Graphics2D g = (Graphics2D) bb.getGraphics();
4632N/A if (g != null) {
4632N/A g.setColor(fg);
4632N/A g.setBackground(bg);
4632N/A g.setFont(f);
4632N/A }
4632N/A return g;
4632N/A }
4632N/A
4632N/A /*
4632N/A * May be called by delegate to provide SD to Java2D code.
4632N/A */
4632N/A public SurfaceData getSurfaceData() {
4632N/A synchronized (surfaceDataLock) {
4632N/A return surfaceData;
4632N/A }
4632N/A }
4632N/A
4632N/A private void replaceSurfaceData() {
4632N/A replaceSurfaceData(backBufferCount, backBufferCaps);
4632N/A }
4632N/A
5041N/A private void replaceSurfaceData(int newBackBufferCount,
4632N/A BufferCapabilities newBackBufferCaps) {
4632N/A synchronized (surfaceDataLock) {
4632N/A final SurfaceData oldData = getSurfaceData();
4632N/A surfaceData = platformWindow.replaceSurfaceData();
4632N/A // TODO: volatile image
4632N/A // VolatileImage oldBB = backBuffer;
4632N/A BufferedImage oldBB = backBuffer;
4632N/A backBufferCount = newBackBufferCount;
5041N/A backBufferCaps = newBackBufferCaps;
4632N/A final Rectangle size = getSize();
5041N/A if (getSurfaceData() != null && oldData != getSurfaceData()) {
4632N/A clearBackground(size.width, size.height);
4632N/A }
5041N/A blitSurfaceData(oldData, getSurfaceData());
4632N/A
4632N/A if (oldData != null && oldData != getSurfaceData()) {
4632N/A // TODO: drop oldData for D3D/WGL pipelines
5041N/A // This can only happen when this peer is being created
5041N/A oldData.flush();
4632N/A }
4632N/A
4632N/A // TODO: volatile image
4632N/A // backBuffer = (VolatileImage)delegate.createBackBuffer();
4632N/A backBuffer = (BufferedImage) platformWindow.createBackBuffer();
4632N/A if (backBuffer != null) {
4632N/A Graphics g = backBuffer.getGraphics();
4632N/A try {
4632N/A Rectangle r = getBounds();
4632N/A g.setColor(getBackground());
4632N/A g.fillRect(0, 0, r.width, r.height);
4632N/A if (oldBB != null) {
4686N/A // Draw the old back buffer to the new one
4686N/A g.drawImage(oldBB, 0, 0, null);
4686N/A oldBB.flush();
4686N/A }
4632N/A } finally {
4632N/A g.dispose();
4632N/A }
5232N/A }
5232N/A }
5232N/A }
5232N/A
5232N/A private void blitSurfaceData(final SurfaceData src, final SurfaceData dst) {
4632N/A //TODO blit. proof-of-concept
4632N/A if (src != dst && src != null && dst != null
4686N/A && !(dst instanceof NullSurfaceData)
5232N/A && !(src instanceof NullSurfaceData)
5232N/A && src.getSurfaceType().equals(dst.getSurfaceType())) {
4686N/A final Rectangle size = getSize();
4686N/A final Blit blit = Blit.locate(src.getSurfaceType(),
4686N/A CompositeType.Src,
4686N/A dst.getSurfaceType());
4686N/A if (blit != null) {
4686N/A blit.Blit(src, dst, ((Graphics2D) getGraphics()).getComposite(),
4686N/A getRegion(), 0, 0, 0, 0, size.width, size.height);
4686N/A }
4686N/A }
4686N/A }
4686N/A
4686N/A public int getBackBufferCount() {
5232N/A return backBufferCount;
5232N/A }
5232N/A
5232N/A public BufferCapabilities getBackBufferCaps() {
4639N/A return backBufferCaps;
4686N/A }
4686N/A
4686N/A /*
4686N/A * Request the window insets from the delegate and compares it
4686N/A * with the current one. This method is mostly called by the
4639N/A * delegate, e.g. when the window state is changed and insets
4686N/A * should be recalculated.
4686N/A *
4686N/A * This method may be called on the toolkit thread.
4686N/A */
4686N/A public boolean updateInsets(Insets newInsets) {
4686N/A boolean changed = false;
4686N/A synchronized (getStateLock()) {
5166N/A changed = (insets.equals(newInsets));
5166N/A insets = newInsets;
5166N/A }
5232N/A
5232N/A if (changed) {
5232N/A replaceSurfaceData();
5232N/A repaintPeer();
5232N/A }
5233N/A
5233N/A return changed;
5233N/A }
5233N/A
4686N/A public static LWWindowPeer getWindowUnderCursor() {
4686N/A return lastMouseEventPeer != null ? lastMouseEventPeer.getWindowPeerOrSelf() : null;
4686N/A }
4686N/A
4686N/A public boolean requestWindowFocus(CausedFocusEvent.Cause cause) {
4686N/A if (focusLog.isLoggable(PlatformLogger.FINE)) {
4686N/A focusLog.fine("requesting native focus to " + this);
4632N/A }
4632N/A
4632N/A if (!focusAllowedFor()) {
4632N/A focusLog.fine("focus is not allowed");
4632N/A return false;
4639N/A }
4639N/A
4639N/A // Cross-app activation requests are not allowed.
4639N/A if (cause != CausedFocusEvent.Cause.MOUSE_EVENT &&
4639N/A !((LWToolkit)Toolkit.getDefaultToolkit()).isApplicationActive())
4639N/A {
4639N/A focusLog.fine("the app is inactive, so the request is rejected");
4639N/A return false;
4639N/A }
4639N/A
4639N/A Window currentActive = KeyboardFocusManager.
5232N/A getCurrentKeyboardFocusManager().getActiveWindow();
4639N/A
4639N/A // Make the owner active window.
4639N/A if (isSimpleWindow()) {
4639N/A LWWindowPeer owner = getOwnerFrameDialog(this);
4639N/A
4632N/A // If owner is not natively active, request native
4632N/A // activation on it w/o sending events up to java.
4632N/A if (owner != null && !owner.platformWindow.isActive()) {
4632N/A if (focusLog.isLoggable(PlatformLogger.FINE)) {
4632N/A focusLog.fine("requesting native focus to the owner " + owner);
4632N/A }
4632N/A LWWindowPeer currentActivePeer = (currentActive != null ?
4632N/A (LWWindowPeer)currentActive.getPeer() : null);
4632N/A
4632N/A // Ensure the opposite is natively active and suppress sending events.
4632N/A if (currentActivePeer != null && currentActivePeer.platformWindow.isActive()) {
4632N/A if (focusLog.isLoggable(PlatformLogger.FINE)) {
4632N/A focusLog.fine("the opposite is " + currentActivePeer);
4632N/A }
4632N/A currentActivePeer.skipNextFocusChange = true;
4632N/A }
4632N/A owner.skipNextFocusChange = true;
4632N/A
4632N/A owner.platformWindow.requestWindowFocus();
4632N/A }
4632N/A
4632N/A // DKFM will synthesize all the focus/activation events correctly.
4632N/A changeFocusedWindow(true, false);
4632N/A return true;
4632N/A
4767N/A // In case the toplevel is active but not focused, change focus directly,
4632N/A // as requesting native focus on it will not have effect.
4632N/A } else if (getTarget() == currentActive && !getTarget().hasFocus()) {
4632N/A
4632N/A changeFocusedWindow(true, false);
4632N/A return true;
4632N/A }
4632N/A return platformWindow.requestWindowFocus();
4632N/A }
4632N/A
5137N/A private boolean focusAllowedFor() {
5137N/A Window window = getTarget();
5137N/A // TODO: check if modal blocked
5137N/A return window.isVisible() && window.isEnabled() && window.isFocusableWindow();
4886N/A }
4886N/A
4886N/A public boolean isSimpleWindow() {
4886N/A Window window = getTarget();
4632N/A return !(window instanceof Dialog || window instanceof Frame);
4717N/A }
4717N/A
4717N/A /*
4717N/A * "Delegates" the responsibility of managing focus to keyboard focus manager.
4632N/A */
4717N/A private void changeFocusedWindow(boolean becomesFocused, boolean isShowing) {
4717N/A if (focusLog.isLoggable(PlatformLogger.FINE)) {
4717N/A focusLog.fine((becomesFocused?"gaining":"loosing") + " focus window: " + this);
4717N/A }
4858N/A if (isShowing && !getTarget().isAutoRequestFocus() || skipNextFocusChange) {
4632N/A focusLog.fine("skipping focus change");
4632N/A skipNextFocusChange = false;
4717N/A return;
4717N/A }
4717N/A
4717N/A if (!cachedFocusableWindow) {
4717N/A return;
4717N/A }
4722N/A if (becomesFocused) {
4717N/A synchronized (getPeerTreeLock()) {
4717N/A if (blocker != null) {
4717N/A if (focusLog.isLoggable(PlatformLogger.FINEST)) {
4722N/A focusLog.finest("the window is blocked by " + blocker);
4717N/A }
4722N/A return;
4717N/A }
4717N/A }
4717N/A }
4717N/A
4717N/A LWKeyboardFocusManagerPeer manager = LWKeyboardFocusManagerPeer.
4717N/A getInstance(getAppContext());
4717N/A
4717N/A Window oppositeWindow = becomesFocused ? manager.getCurrentFocusedWindow() : null;
4717N/A
4717N/A // Note, the method is not called:
4717N/A // - when the opposite (gaining focus) window is an owned/owner window.
4722N/A // - for a simple window in any case.
4717N/A if (!becomesFocused &&
4722N/A (isGrabbing() || getOwnerFrameDialog(grabbingWindow) == this))
4717N/A {
4717N/A focusLog.fine("ungrabbing on " + grabbingWindow);
4717N/A // ungrab a simple window if its owner looses activation.
4886N/A grabbingWindow.ungrab();
4717N/A }
4717N/A
4717N/A manager.setFocusedWindow(becomesFocused ? LWWindowPeer.this : null);
4717N/A
4717N/A int eventID = becomesFocused ? WindowEvent.WINDOW_GAINED_FOCUS : WindowEvent.WINDOW_LOST_FOCUS;
4717N/A WindowEvent windowEvent = new WindowEvent(getTarget(), eventID, oppositeWindow);
4886N/A
4717N/A // TODO: wrap in SequencedEvent
4717N/A postEvent(windowEvent);
4717N/A }
4632N/A
4632N/A private static LWWindowPeer getOwnerFrameDialog(LWWindowPeer peer) {
4632N/A Window owner = (peer != null ? peer.getTarget().getOwner() : null);
4632N/A while (owner != null && !(owner instanceof Frame || owner instanceof Dialog)) {
4632N/A owner = owner.getOwner();
4878N/A }
4878N/A return owner != null ? (LWWindowPeer)owner.getPeer() : null;
4878N/A }
4878N/A
4878N/A /**
4878N/A * Returns the foremost modal blocker of this window, or null.
4878N/A */
4878N/A public LWWindowPeer getBlocker() {
4878N/A synchronized (getPeerTreeLock()) {
4878N/A LWWindowPeer blocker = this.blocker;
4878N/A if (blocker == null) {
4878N/A return null;
4878N/A }
4632N/A while (blocker.blocker != null) {
4632N/A blocker = blocker.blocker;
4632N/A }
4632N/A return blocker;
4632N/A }
4632N/A }
4632N/A
4632N/A public void enterFullScreenMode() {
4886N/A platformWindow.enterFullScreenMode();
4632N/A }
4886N/A
4717N/A public void exitFullScreenMode() {
4717N/A platformWindow.exitFullScreenMode();
4717N/A }
4886N/A
4717N/A public long getLayerPtr() {
4717N/A return getPlatformWindow().getLayerPtr();
4632N/A }
4632N/A
4878N/A void grab() {
4878N/A if (grabbingWindow != null && !isGrabbing()) {
4632N/A grabbingWindow.ungrab();
4632N/A }
4632N/A grabbingWindow = this;
4632N/A }
4632N/A
4717N/A void ungrab() {
4717N/A if (isGrabbing()) {
4717N/A grabbingWindow = null;
4632N/A postEvent(new UngrabEvent(getTarget()));
4632N/A }
4632N/A }
4632N/A
4632N/A private boolean isGrabbing() {
5336N/A return this == grabbingWindow;
5336N/A }
4665N/A
4665N/A @Override
4665N/A public String toString() {
4665N/A return super.toString() + " [target is " + getTarget() + "]";
4665N/A }
4722N/A}
4665N/A