src/share/classes/sun/swing/JLightweightFrame.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.swing;
  27 
  28 import java.awt.BorderLayout;
  29 import java.awt.Color;
  30 import java.awt.Component;
  31 import java.awt.Container;
  32 import java.awt.Dimension;
  33 import java.awt.EventQueue;
  34 import java.awt.Graphics;
  35 import java.awt.Graphics2D;


  36 import java.awt.Rectangle;
  37 import java.awt.event.ComponentListener;
  38 import java.awt.event.ContainerEvent;
  39 import java.awt.event.ContainerListener;
  40 import java.awt.image.BufferedImage;
  41 import java.awt.image.DataBufferInt;
  42 import java.beans.PropertyChangeEvent;
  43 import java.beans.PropertyChangeListener;
  44 import java.security.AccessController;
  45 
  46 import javax.swing.JLayeredPane;
  47 import javax.swing.JPanel;
  48 import javax.swing.JRootPane;
  49 import javax.swing.LayoutFocusTraversalPolicy;
  50 import javax.swing.RootPaneContainer;

  51 
  52 import sun.awt.LightweightFrame;
  53 import sun.security.action.GetPropertyAction;
  54 
  55 /**
  56  * The frame serves as a lightweight container which paints its content
  57  * to an offscreen image and provides access to the image's data via the
  58  * {@link LightweightContent} interface. Note, that it may not be shown
  59  * as a standalone toplevel frame. Its purpose is to provide functionality
  60  * for lightweight embedding.
  61  *
  62  * @author Artem Ananiev
  63  * @author Anton Tarasov
  64  */
  65 public final class JLightweightFrame extends LightweightFrame implements RootPaneContainer {
  66 
  67     private final JRootPane rootPane = new JRootPane();
  68 
  69     private LightweightContent content;
  70 
  71     private Component component;
  72     private JPanel contentPane;
  73 
  74     private BufferedImage bbImage;
  75 
  76     /**
  77      * {@code copyBufferEnabled}, true by default, defines the following strategy.
  78      * A duplicating (copy) buffer is created for the original pixel buffer.
  79      * The copy buffer is synchronized with the original buffer every time the
  80      * latter changes. {@code JLightweightFrame} passes the copy buffer array
  81      * to the {@link LightweightContent#imageBufferReset} method. The code spot
  82      * which synchronizes two buffers becomes the only critical section guarded
  83      * by the lock (managed with the {@link LightweightContent#paintLock()},
  84      * {@link LightweightContent#paintUnlock()} methods).
  85      */
  86     private boolean copyBufferEnabled;
  87     private int[] copyBuffer;
  88 
  89     private PropertyChangeListener layoutSizeListener;
  90 









  91     /**
  92      * Constructs a new, initially invisible {@code JLightweightFrame}
  93      * instance.
  94      */
  95     public JLightweightFrame() {
  96         super();
  97         copyBufferEnabled = "true".equals(AccessController.
  98             doPrivileged(new GetPropertyAction("jlf.copyBufferEnabled", "true")));
  99 
 100         add(rootPane, BorderLayout.CENTER);
 101         setFocusTraversalPolicy(new LayoutFocusTraversalPolicy());
 102         if (getGraphicsConfiguration().isTranslucencyCapable()) {
 103             setBackground(new Color(0, 0, 0, 0));
 104         }
 105 
 106         layoutSizeListener = new PropertyChangeListener() {
 107             @Override
 108             public void propertyChange(PropertyChangeEvent e) {
 109                 Dimension d = (Dimension)e.getNewValue();
 110 


 341 
 342     @Override
 343     public void setLayeredPane(JLayeredPane layeredPane) {
 344         getRootPane().setLayeredPane(layeredPane);
 345     }
 346 
 347     @Override
 348     public JLayeredPane getLayeredPane() {
 349         return getRootPane().getLayeredPane();
 350     }
 351 
 352     @Override
 353     public void setGlassPane(Component glassPane) {
 354         getRootPane().setGlassPane(glassPane);
 355     }
 356 
 357     @Override
 358     public Component getGlassPane() {
 359         return getRootPane().getGlassPane();
 360     }

















 361 }


  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.swing;
  27 
  28 import java.awt.BorderLayout;
  29 import java.awt.Color;
  30 import java.awt.Component;
  31 import java.awt.Container;
  32 import java.awt.Dimension;
  33 import java.awt.EventQueue;
  34 import java.awt.Graphics;
  35 import java.awt.Graphics2D;
  36 import java.awt.MouseInfo;
  37 import java.awt.Point;
  38 import java.awt.Rectangle;

  39 import java.awt.event.ContainerEvent;
  40 import java.awt.event.ContainerListener;
  41 import java.awt.image.BufferedImage;
  42 import java.awt.image.DataBufferInt;
  43 import java.beans.PropertyChangeEvent;
  44 import java.beans.PropertyChangeListener;
  45 import java.security.AccessController;
  46 
  47 import javax.swing.JLayeredPane;
  48 import javax.swing.JPanel;
  49 import javax.swing.JRootPane;
  50 import javax.swing.LayoutFocusTraversalPolicy;
  51 import javax.swing.RootPaneContainer;
  52 import javax.swing.SwingUtilities;
  53 
  54 import sun.awt.LightweightFrame;
  55 import sun.security.action.GetPropertyAction;
  56 
  57 /**
  58  * The frame serves as a lightweight container which paints its content
  59  * to an offscreen image and provides access to the image's data via the
  60  * {@link LightweightContent} interface. Note, that it may not be shown
  61  * as a standalone toplevel frame. Its purpose is to provide functionality
  62  * for lightweight embedding.
  63  *
  64  * @author Artem Ananiev
  65  * @author Anton Tarasov
  66  */
  67 public final class JLightweightFrame extends LightweightFrame implements RootPaneContainer {
  68 
  69     private final JRootPane rootPane = new JRootPane();
  70 
  71     private LightweightContent content;
  72 
  73     private Component component;
  74     private JPanel contentPane;
  75 
  76     private BufferedImage bbImage;
  77 
  78     /**
  79      * {@code copyBufferEnabled}, true by default, defines the following strategy.
  80      * A duplicating (copy) buffer is created for the original pixel buffer.
  81      * The copy buffer is synchronized with the original buffer every time the
  82      * latter changes. {@code JLightweightFrame} passes the copy buffer array
  83      * to the {@link LightweightContent#imageBufferReset} method. The code spot
  84      * which synchronizes two buffers becomes the only critical section guarded
  85      * by the lock (managed with the {@link LightweightContent#paintLock()},
  86      * {@link LightweightContent#paintUnlock()} methods).
  87      */
  88     private boolean copyBufferEnabled;
  89     private int[] copyBuffer;
  90 
  91     private PropertyChangeListener layoutSizeListener;
  92 
  93     static {
  94         SwingAccessor.setJLightweightFrameAccessor(new SwingAccessor.JLightweightFrameAccessor() {
  95             @Override
  96             public void updateCursor(JLightweightFrame frame) {
  97                 frame.updateClientCursor();
  98             }
  99         });
 100     }
 101 
 102     /**
 103      * Constructs a new, initially invisible {@code JLightweightFrame}
 104      * instance.
 105      */
 106     public JLightweightFrame() {
 107         super();
 108         copyBufferEnabled = "true".equals(AccessController.
 109             doPrivileged(new GetPropertyAction("jlf.copyBufferEnabled", "true")));
 110 
 111         add(rootPane, BorderLayout.CENTER);
 112         setFocusTraversalPolicy(new LayoutFocusTraversalPolicy());
 113         if (getGraphicsConfiguration().isTranslucencyCapable()) {
 114             setBackground(new Color(0, 0, 0, 0));
 115         }
 116 
 117         layoutSizeListener = new PropertyChangeListener() {
 118             @Override
 119             public void propertyChange(PropertyChangeEvent e) {
 120                 Dimension d = (Dimension)e.getNewValue();
 121 


 352 
 353     @Override
 354     public void setLayeredPane(JLayeredPane layeredPane) {
 355         getRootPane().setLayeredPane(layeredPane);
 356     }
 357 
 358     @Override
 359     public JLayeredPane getLayeredPane() {
 360         return getRootPane().getLayeredPane();
 361     }
 362 
 363     @Override
 364     public void setGlassPane(Component glassPane) {
 365         getRootPane().setGlassPane(glassPane);
 366     }
 367 
 368     @Override
 369     public Component getGlassPane() {
 370         return getRootPane().getGlassPane();
 371     }
 372 
 373 
 374     /*
 375      * Notifies client toolkit that it should change a cursor.
 376      *
 377      * Called from the peer via SwingAccessor, because the
 378      * Component.updateCursorImmediately method is final
 379      * and could not be overridden.
 380      */
 381     private void updateClientCursor() {
 382         Point p = MouseInfo.getPointerInfo().getLocation();
 383         SwingUtilities.convertPointFromScreen(p, this);
 384         Component target = SwingUtilities.getDeepestComponentAt(this, p.x, p.y);
 385         if (target != null) {
 386             content.setCursor(target.getCursor());
 387         }
 388     }
 389 }