< prev index next >

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

Print this page


   1 /*
   2  * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  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 
  27 package sun.lwawt;
  28 
  29 import java.awt.*;
  30 















  31 import java.awt.dnd.DropTarget;
  32 import java.awt.dnd.peer.DropTargetPeer;
  33 import java.awt.event.*;
  34 






  35 import java.awt.image.ColorModel;
  36 import java.awt.image.ImageObserver;
  37 import java.awt.image.ImageProducer;
  38 import java.awt.image.VolatileImage;
  39 
  40 import java.awt.peer.ComponentPeer;
  41 import java.awt.peer.ContainerPeer;
  42 
  43 import java.awt.peer.KeyboardFocusManagerPeer;
  44 import java.util.concurrent.atomic.AtomicBoolean;
  45 import java.lang.reflect.Field;
  46 import java.security.AccessController;
  47 import java.security.PrivilegedAction;

  48 
  49 import sun.awt.*;


  50 





  51 import sun.awt.event.IgnorePaintEvent;
  52 
  53 import sun.awt.image.SunVolatileImage;
  54 import sun.awt.image.ToolkitImage;
  55 
  56 import sun.java2d.SunGraphics2D;
  57 import sun.java2d.opengl.OGLRenderQueue;
  58 import sun.java2d.pipe.Region;
  59 
  60 import sun.util.logging.PlatformLogger;
  61 
  62 import javax.swing.JComponent;
  63 import javax.swing.SwingUtilities;
  64 import javax.swing.RepaintManager;
  65 
  66 import com.sun.java.swing.SwingUtilities3;
  67 
  68 public abstract class LWComponentPeer<T extends Component, D extends JComponent>
  69     implements ComponentPeer, DropTargetPeer
  70 {
  71     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWComponentPeer");
  72 
  73     /**
  74      * State lock is to be used for modifications to this peer's fields (e.g.
  75      * bounds, background, font, etc.) It should be the last lock in the lock
  76      * chain
  77      */
  78     private final Object stateLock = new Object();
  79 
  80     /**
  81      * The lock to operate with the peers hierarchy. AWT tree lock is not used
  82      * as there are many peers related ops to be done on the toolkit thread, and
  83      * we don't want to depend on a public lock on this thread
  84      */
  85     private static final Object peerTreeLock = new Object();
  86 
  87     /**


1088                     } else
1089                         System.err.println("CComponent.removeDropTarget(): current drop target is null.");
1090                 }
1091             }
1092         }
1093     }
1094 
1095     // ---- PEER NOTIFICATIONS ---- //
1096 
1097     /**
1098      * Called when this peer's location has been changed either as a result
1099      * of target.setLocation() or as a result of user actions (window is
1100      * dragged with mouse).
1101      *
1102      * This method could be called on the toolkit thread.
1103      */
1104     protected final void handleMove(final int x, final int y,
1105                                     final boolean updateTarget) {
1106         if (updateTarget) {
1107             AWTAccessor.getComponentAccessor().setLocation(getTarget(), x, y);
1108         }
1109         postEvent(new ComponentEvent(getTarget(),
1110                                      ComponentEvent.COMPONENT_MOVED));
1111     }

1112 
1113     /**
1114      * Called when this peer's size has been changed either as a result of
1115      * target.setSize() or as a result of user actions (window is resized).
1116      *
1117      * This method could be called on the toolkit thread.
1118      */
1119     protected final void handleResize(final int w, final int h,
1120                                       final boolean updateTarget) {
1121         Image oldBB = null;
1122         synchronized (getStateLock()) {
1123             if (backBuffer != null) {
1124                 oldBB = backBuffer;
1125                 backBuffer = getLWGC().createBackBuffer(this);
1126             }
1127         }
1128         getLWGC().destroyBackBuffer(oldBB);
1129 
1130         if (updateTarget) {
1131             AWTAccessor.getComponentAccessor().setSize(getTarget(), w, h);
1132         }
1133         postEvent(new ComponentEvent(getTarget(),
1134                                      ComponentEvent.COMPONENT_RESIZED));
1135     }

1136 
1137     protected final void repaintOldNewBounds(final Rectangle oldB) {
1138         repaintParent(oldB);
1139         repaintPeer(getSize());
1140     }
1141 
1142     protected final void repaintParent(final Rectangle oldB) {
1143         final LWContainerPeer<?, ?> cp = getContainerPeer();
1144         if (cp != null) {
1145             // Repaint unobscured part of the parent
1146             cp.repaintPeer(cp.getContentSize().intersection(oldB));
1147         }
1148     }
1149 
1150     // ---- EVENTS ---- //
1151 
1152     /**
1153      * Post an event to the proper Java EDT.
1154      */
1155     public void postEvent(final AWTEvent event) {


   1 /*
   2  * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  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.AWTEvent;
  29 import java.awt.AWTException;
  30 import java.awt.BufferCapabilities;
  31 import java.awt.Color;
  32 import java.awt.Component;
  33 import java.awt.Container;
  34 import java.awt.Cursor;
  35 import java.awt.Dimension;
  36 import java.awt.Font;
  37 import java.awt.FontMetrics;
  38 import java.awt.Graphics;
  39 import java.awt.GraphicsConfiguration;
  40 import java.awt.Image;
  41 import java.awt.Point;
  42 import java.awt.Rectangle;
  43 import java.awt.Toolkit;
  44 import java.awt.Window;
  45 import java.awt.dnd.DropTarget;
  46 import java.awt.dnd.peer.DropTargetPeer;
  47 import java.awt.event.AWTEventListener;
  48 import java.awt.event.ComponentEvent;
  49 import java.awt.event.FocusEvent;
  50 import java.awt.event.InputEvent;
  51 import java.awt.event.KeyEvent;
  52 import java.awt.event.MouseEvent;
  53 import java.awt.event.MouseWheelEvent;
  54 import java.awt.event.PaintEvent;
  55 import java.awt.image.ColorModel;
  56 import java.awt.image.ImageObserver;
  57 import java.awt.image.ImageProducer;
  58 import java.awt.image.VolatileImage;

  59 import java.awt.peer.ComponentPeer;
  60 import java.awt.peer.ContainerPeer;

  61 import java.awt.peer.KeyboardFocusManagerPeer;

  62 import java.lang.reflect.Field;
  63 import java.security.AccessController;
  64 import java.security.PrivilegedAction;
  65 import java.util.concurrent.atomic.AtomicBoolean;
  66 
  67 import javax.swing.JComponent;
  68 import javax.swing.RepaintManager;
  69 import javax.swing.SwingUtilities;
  70 
  71 import com.sun.java.swing.SwingUtilities3;
  72 import sun.awt.AWTAccessor;
  73 import sun.awt.PaintEventDispatcher;
  74 import sun.awt.RepaintArea;
  75 import sun.awt.SunToolkit;
  76 import sun.awt.event.IgnorePaintEvent;

  77 import sun.awt.image.SunVolatileImage;
  78 import sun.awt.image.ToolkitImage;

  79 import sun.java2d.SunGraphics2D;
  80 import sun.java2d.opengl.OGLRenderQueue;
  81 import sun.java2d.pipe.Region;

  82 import sun.util.logging.PlatformLogger;
  83 






  84 public abstract class LWComponentPeer<T extends Component, D extends JComponent>
  85     implements ComponentPeer, DropTargetPeer
  86 {
  87     private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWComponentPeer");
  88 
  89     /**
  90      * State lock is to be used for modifications to this peer's fields (e.g.
  91      * bounds, background, font, etc.) It should be the last lock in the lock
  92      * chain
  93      */
  94     private final Object stateLock = new Object();
  95 
  96     /**
  97      * The lock to operate with the peers hierarchy. AWT tree lock is not used
  98      * as there are many peers related ops to be done on the toolkit thread, and
  99      * we don't want to depend on a public lock on this thread
 100      */
 101     private static final Object peerTreeLock = new Object();
 102 
 103     /**


1104                     } else
1105                         System.err.println("CComponent.removeDropTarget(): current drop target is null.");
1106                 }
1107             }
1108         }
1109     }
1110 
1111     // ---- PEER NOTIFICATIONS ---- //
1112 
1113     /**
1114      * Called when this peer's location has been changed either as a result
1115      * of target.setLocation() or as a result of user actions (window is
1116      * dragged with mouse).
1117      *
1118      * This method could be called on the toolkit thread.
1119      */
1120     protected final void handleMove(final int x, final int y,
1121                                     final boolean updateTarget) {
1122         if (updateTarget) {
1123             AWTAccessor.getComponentAccessor().setLocation(getTarget(), x, y);

1124             postEvent(new ComponentEvent(getTarget(),
1125                                          ComponentEvent.COMPONENT_MOVED));
1126         }
1127     }
1128 
1129     /**
1130      * Called when this peer's size has been changed either as a result of
1131      * target.setSize() or as a result of user actions (window is resized).
1132      *
1133      * This method could be called on the toolkit thread.
1134      */
1135     protected final void handleResize(final int w, final int h,
1136                                       final boolean updateTarget) {
1137         Image oldBB = null;
1138         synchronized (getStateLock()) {
1139             if (backBuffer != null) {
1140                 oldBB = backBuffer;
1141                 backBuffer = getLWGC().createBackBuffer(this);
1142             }
1143         }
1144         getLWGC().destroyBackBuffer(oldBB);
1145 
1146         if (updateTarget) {
1147             AWTAccessor.getComponentAccessor().setSize(getTarget(), w, h);

1148             postEvent(new ComponentEvent(getTarget(),
1149                                          ComponentEvent.COMPONENT_RESIZED));
1150         }
1151     }
1152 
1153     protected final void repaintOldNewBounds(final Rectangle oldB) {
1154         repaintParent(oldB);
1155         repaintPeer(getSize());
1156     }
1157 
1158     protected final void repaintParent(final Rectangle oldB) {
1159         final LWContainerPeer<?, ?> cp = getContainerPeer();
1160         if (cp != null) {
1161             // Repaint unobscured part of the parent
1162             cp.repaintPeer(cp.getContentSize().intersection(oldB));
1163         }
1164     }
1165 
1166     // ---- EVENTS ---- //
1167 
1168     /**
1169      * Post an event to the proper Java EDT.
1170      */
1171     public void postEvent(final AWTEvent event) {


< prev index next >