src/share/classes/sun/swing/JLightweightFrame.java

Print this page

        

*** 23,44 **** --- 23,51 ---- * questions. */ package sun.swing; + import java.awt.AWTEvent; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Graphics; import java.awt.Graphics2D; + import java.awt.MouseInfo; + import java.awt.Point; import java.awt.Rectangle; + import java.awt.event.AWTEventListener; + import java.awt.event.ComponentAdapter; + import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener; import java.awt.event.ContainerEvent; import java.awt.event.ContainerListener; + import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.security.AccessController;
*** 46,57 **** --- 53,66 ---- import javax.swing.JLayeredPane; import javax.swing.JPanel; import javax.swing.JRootPane; import javax.swing.LayoutFocusTraversalPolicy; import javax.swing.RootPaneContainer; + import javax.swing.SwingUtilities; import sun.awt.LightweightFrame; + import sun.awt.LightweightFramePeer; import sun.security.action.GetPropertyAction; /** * The frame serves as a lightweight container which paints its content * to an offscreen image and provides access to the image's data via the
*** 62,71 **** --- 71,89 ---- * @author Artem Ananiev * @author Anton Tarasov */ public final class JLightweightFrame extends LightweightFrame implements RootPaneContainer { + static { + SwingAccessor.setJLightweightFrameAccessor(new SwingAccessor.JLightweightFrameAccessor() { + @Override + public LightweightContent getLightweightContent(JLightweightFrame frame) { + return frame.content; + } + }); + } + private final JRootPane rootPane = new JRootPane(); private LightweightContent content; private Component component;
*** 119,128 **** --- 137,194 ---- } } }; } + private LightweightFramePeer getLwPeer() { + return (LightweightFramePeer)getPeer(); + } + + private final AWTEventListener mouseEventListener = (AWTEvent event) -> { + MouseEvent m = (MouseEvent)event; + + if (!SwingUtilities.isDescendingFrom(m.getComponent(), this)) return; + + switch (m.getID()) { + case MouseEvent.MOUSE_ENTERED: + getLwPeer().setLightweightFrameUnderMouse(); + getLwPeer().updateCursorImmediately(); + break; + case MouseEvent.MOUSE_EXITED: + Point location = SwingUtilities.convertPoint(m.getComponent(), m.getPoint(), this); + if ((!this.contains(location) || !this.isActive()) && + getLwPeer().cleanLightweightFrameUnderMouse()) { + getLwPeer().updateCursorImmediately(); + } + break; + } + }; + + private final ComponentListener componentListener = new ComponentAdapter() { + @Override + public void componentShown(ComponentEvent e) { + if (getBounds().contains(MouseInfo.getPointerInfo().getLocation())) { + getLwPeer().setLightweightFrameUnderMouse(); + getLwPeer().updateCursorImmediately(); + } + } + }; + + @Override + public void addNotify() { + super.addNotify(); + getToolkit().addAWTEventListener(mouseEventListener, AWTEvent.MOUSE_EVENT_MASK); + addComponentListener(componentListener); + } + + @Override + public void removeNotify() { + super.removeNotify(); + getToolkit().removeAWTEventListener(mouseEventListener); + removeComponentListener(componentListener); + } + /** * Sets the {@link LightweightContent} instance for this frame. * The {@code JComponent} object returned by the * {@link LightweightContent#getComponent()} method is immediately * added to the frame's content pane.