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

Print this page




  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  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, PlatformEventNotifier
  45 {
  46     public 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");


 488         synchronized (getStateLock()) {
 489             /*
 490              * Textured window is a special case of translucent window.
 491              * The difference is only in nswindow background. So when we set
 492              * texture property our peer became fully translucent. It doesn't
 493              * fill background, create non opaque backbuffers and layer etc.
 494              */
 495             return !isOpaque || isShaped() || isTextured();
 496         }
 497     }
 498 
 499     @Override
 500     final void applyShapeImpl(final Region shape) {
 501         super.applyShapeImpl(shape);
 502         updateOpaque();
 503     }
 504 
 505     @Override
 506     public void repositionSecurityWarning() {
 507         if (warningWindow != null) {
 508             AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
 509             Window target = getTarget();
 510             int x = compAccessor.getX(target);
 511             int y = compAccessor.getY(target);
 512             int width = compAccessor.getWidth(target);
 513             int height = compAccessor.getHeight(target);
 514             warningWindow.reposition(x, y, width, height);
 515         }
 516     }
 517 
 518     // ---- FRAME PEER METHODS ---- //
 519 
 520     @Override // FramePeer and DialogPeer
 521     public void setTitle(String title) {
 522         platformWindow.setTitle(title == null ? "" : title);
 523     }
 524 
 525     @Override
 526     public void setMenuBar(MenuBar mb) {
 527          platformWindow.setMenuBar(mb);
 528     }


 546     public void setMaximizedBounds(Rectangle bounds) {
 547         // TODO: not implemented
 548     }
 549 
 550     @Override
 551     public void setBoundsPrivate(int x, int y, int width, int height) {
 552         setBounds(x, y, width, height, SET_BOUNDS | NO_EMBEDDED_CHECK);
 553     }
 554 
 555     @Override
 556     public Rectangle getBoundsPrivate() {
 557         throw new RuntimeException("not implemented");
 558     }
 559 
 560     // ---- DIALOG PEER METHODS ---- //
 561 
 562     @Override
 563     public void blockWindows(List<Window> windows) {
 564         //TODO: LWX will probably need some collectJavaToplevels to speed this up
 565         for (Window w : windows) {
 566             WindowPeer wp =
 567                     (WindowPeer) AWTAccessor.getComponentAccessor().getPeer(w);
 568             if (wp != null) {
 569                 wp.setModalBlocked((Dialog)getTarget(), true);
 570             }
 571         }
 572     }
 573 
 574     // ---- PEER NOTIFICATIONS ---- //
 575 
 576     @Override
 577     public void notifyIconify(boolean iconify) {
 578         //The toplevel target is Frame and states are applicable to it.
 579         //Otherwise, the target is Window and it don't have state property.
 580         //Hopefully, no such events are posted in the queue so consider the
 581         //target as Frame in all cases.
 582 
 583         // REMIND: should we send it anyway if the state not changed since last
 584         // time?
 585         WindowEvent iconifyEvent = new WindowEvent(getTarget(),
 586                 iconify ? WindowEvent.WINDOW_ICONIFIED
 587                         : WindowEvent.WINDOW_DEICONIFIED);


1230             }
1231             return focusable && ownerPeer.targetFocusable;
1232         }
1233         return focusable;
1234     }
1235 
1236     public boolean isSimpleWindow() {
1237         Window window = getTarget();
1238         return !(window instanceof Dialog || window instanceof Frame);
1239     }
1240 
1241     @Override
1242     public void emulateActivation(boolean activate) {
1243         changeFocusedWindow(activate, null);
1244     }
1245 
1246     @SuppressWarnings("deprecation")
1247     private boolean isOneOfOwnersOf(LWWindowPeer peer) {
1248         Window owner = (peer != null ? peer.getTarget().getOwner() : null);
1249         while (owner != null) {
1250             if ((LWWindowPeer)owner.getPeer() == this) {

1251                 return true;
1252             }
1253             owner = owner.getOwner();
1254         }
1255         return false;
1256     }
1257 
1258     /*
1259      * Changes focused window on java level.
1260      */
1261     protected void changeFocusedWindow(boolean becomesFocused, Window opposite) {
1262         if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
1263             focusLog.fine((becomesFocused?"gaining":"loosing") + " focus window: " + this);
1264         }
1265         if (skipNextFocusChange) {
1266             focusLog.fine("skipping focus change");
1267             skipNextFocusChange = false;
1268             return;
1269         }
1270         if (!isFocusableWindow() && becomesFocused) {


1298         KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
1299         kfmPeer.setCurrentFocusedWindow(becomesFocused ? getTarget() : null);
1300 
1301         int eventID = becomesFocused ? WindowEvent.WINDOW_GAINED_FOCUS : WindowEvent.WINDOW_LOST_FOCUS;
1302         WindowEvent windowEvent = new TimedWindowEvent(getTarget(), eventID, opposite, System.currentTimeMillis());
1303 
1304         // TODO: wrap in SequencedEvent
1305         postEvent(windowEvent);
1306     }
1307 
1308     /*
1309      * Retrieves the owner of the peer.
1310      * Note: this method returns the owner which can be activated, (i.e. the instance
1311      * of Frame or Dialog may be returned).
1312      */
1313     static LWWindowPeer getOwnerFrameDialog(LWWindowPeer peer) {
1314         Window owner = (peer != null ? peer.getTarget().getOwner() : null);
1315         while (owner != null && !(owner instanceof Frame || owner instanceof Dialog)) {
1316             owner = owner.getOwner();
1317         }
1318         return owner == null ? null :
1319                (LWWindowPeer) AWTAccessor.getComponentAccessor().getPeer(owner);
1320     }
1321 
1322     /**
1323      * Returns the foremost modal blocker of this window, or null.
1324      */
1325     public LWWindowPeer getBlocker() {
1326         synchronized (getPeerTreeLock()) {
1327             LWWindowPeer blocker = this.blocker;
1328             if (blocker == null) {
1329                 return null;
1330             }
1331             while (blocker.blocker != null) {
1332                 blocker = blocker.blocker;
1333             }
1334             return blocker;
1335         }
1336     }
1337 
1338     @Override
1339     public void enterFullScreenMode() {




  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  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.awt.AWTAccessor.ComponentAccessor;
  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 FramePeer, DialogPeer, FullScreenCapable, DisplayChangedListener, PlatformEventNotifier
  46 {
  47     public enum PeerType {
  48         SIMPLEWINDOW,
  49         FRAME,
  50         DIALOG,
  51         EMBEDDED_FRAME,
  52         VIEW_EMBEDDED_FRAME,
  53         LW_FRAME
  54     }
  55 
  56     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWWindowPeer");


 489         synchronized (getStateLock()) {
 490             /*
 491              * Textured window is a special case of translucent window.
 492              * The difference is only in nswindow background. So when we set
 493              * texture property our peer became fully translucent. It doesn't
 494              * fill background, create non opaque backbuffers and layer etc.
 495              */
 496             return !isOpaque || isShaped() || isTextured();
 497         }
 498     }
 499 
 500     @Override
 501     final void applyShapeImpl(final Region shape) {
 502         super.applyShapeImpl(shape);
 503         updateOpaque();
 504     }
 505 
 506     @Override
 507     public void repositionSecurityWarning() {
 508         if (warningWindow != null) {
 509             ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
 510             Window target = getTarget();
 511             int x = compAccessor.getX(target);
 512             int y = compAccessor.getY(target);
 513             int width = compAccessor.getWidth(target);
 514             int height = compAccessor.getHeight(target);
 515             warningWindow.reposition(x, y, width, height);
 516         }
 517     }
 518 
 519     // ---- FRAME PEER METHODS ---- //
 520 
 521     @Override // FramePeer and DialogPeer
 522     public void setTitle(String title) {
 523         platformWindow.setTitle(title == null ? "" : title);
 524     }
 525 
 526     @Override
 527     public void setMenuBar(MenuBar mb) {
 528          platformWindow.setMenuBar(mb);
 529     }


 547     public void setMaximizedBounds(Rectangle bounds) {
 548         // TODO: not implemented
 549     }
 550 
 551     @Override
 552     public void setBoundsPrivate(int x, int y, int width, int height) {
 553         setBounds(x, y, width, height, SET_BOUNDS | NO_EMBEDDED_CHECK);
 554     }
 555 
 556     @Override
 557     public Rectangle getBoundsPrivate() {
 558         throw new RuntimeException("not implemented");
 559     }
 560 
 561     // ---- DIALOG PEER METHODS ---- //
 562 
 563     @Override
 564     public void blockWindows(List<Window> windows) {
 565         //TODO: LWX will probably need some collectJavaToplevels to speed this up
 566         for (Window w : windows) {
 567             WindowPeer wp = AWTAccessor.getComponentAccessor().getPeer(w);

 568             if (wp != null) {
 569                 wp.setModalBlocked((Dialog)getTarget(), true);
 570             }
 571         }
 572     }
 573 
 574     // ---- PEER NOTIFICATIONS ---- //
 575 
 576     @Override
 577     public void notifyIconify(boolean iconify) {
 578         //The toplevel target is Frame and states are applicable to it.
 579         //Otherwise, the target is Window and it don't have state property.
 580         //Hopefully, no such events are posted in the queue so consider the
 581         //target as Frame in all cases.
 582 
 583         // REMIND: should we send it anyway if the state not changed since last
 584         // time?
 585         WindowEvent iconifyEvent = new WindowEvent(getTarget(),
 586                 iconify ? WindowEvent.WINDOW_ICONIFIED
 587                         : WindowEvent.WINDOW_DEICONIFIED);


1230             }
1231             return focusable && ownerPeer.targetFocusable;
1232         }
1233         return focusable;
1234     }
1235 
1236     public boolean isSimpleWindow() {
1237         Window window = getTarget();
1238         return !(window instanceof Dialog || window instanceof Frame);
1239     }
1240 
1241     @Override
1242     public void emulateActivation(boolean activate) {
1243         changeFocusedWindow(activate, null);
1244     }
1245 
1246     @SuppressWarnings("deprecation")
1247     private boolean isOneOfOwnersOf(LWWindowPeer peer) {
1248         Window owner = (peer != null ? peer.getTarget().getOwner() : null);
1249         while (owner != null) {
1250             final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
1251             if (acc.getPeer(owner) == this) {
1252                 return true;
1253             }
1254             owner = owner.getOwner();
1255         }
1256         return false;
1257     }
1258 
1259     /*
1260      * Changes focused window on java level.
1261      */
1262     protected void changeFocusedWindow(boolean becomesFocused, Window opposite) {
1263         if (focusLog.isLoggable(PlatformLogger.Level.FINE)) {
1264             focusLog.fine((becomesFocused?"gaining":"loosing") + " focus window: " + this);
1265         }
1266         if (skipNextFocusChange) {
1267             focusLog.fine("skipping focus change");
1268             skipNextFocusChange = false;
1269             return;
1270         }
1271         if (!isFocusableWindow() && becomesFocused) {


1299         KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
1300         kfmPeer.setCurrentFocusedWindow(becomesFocused ? getTarget() : null);
1301 
1302         int eventID = becomesFocused ? WindowEvent.WINDOW_GAINED_FOCUS : WindowEvent.WINDOW_LOST_FOCUS;
1303         WindowEvent windowEvent = new TimedWindowEvent(getTarget(), eventID, opposite, System.currentTimeMillis());
1304 
1305         // TODO: wrap in SequencedEvent
1306         postEvent(windowEvent);
1307     }
1308 
1309     /*
1310      * Retrieves the owner of the peer.
1311      * Note: this method returns the owner which can be activated, (i.e. the instance
1312      * of Frame or Dialog may be returned).
1313      */
1314     static LWWindowPeer getOwnerFrameDialog(LWWindowPeer peer) {
1315         Window owner = (peer != null ? peer.getTarget().getOwner() : null);
1316         while (owner != null && !(owner instanceof Frame || owner instanceof Dialog)) {
1317             owner = owner.getOwner();
1318         }
1319         return owner == null ? null : AWTAccessor.getComponentAccessor()
1320                                                  .getPeer(owner);
1321     }
1322 
1323     /**
1324      * Returns the foremost modal blocker of this window, or null.
1325      */
1326     public LWWindowPeer getBlocker() {
1327         synchronized (getPeerTreeLock()) {
1328             LWWindowPeer blocker = this.blocker;
1329             if (blocker == null) {
1330                 return null;
1331             }
1332             while (blocker.blocker != null) {
1333                 blocker = blocker.blocker;
1334             }
1335             return blocker;
1336         }
1337     }
1338 
1339     @Override
1340     public void enterFullScreenMode() {