提交 c2e785bd 编写于 作者: P pchelko

8024170: [SwingNode] Implement cursor change

Reviewed-by: anthony, ant
上级 2eff0cdb
......@@ -34,6 +34,8 @@ import java.awt.dnd.DropTarget;
import sun.awt.CausedFocusEvent;
import sun.awt.LightweightFrame;
import sun.swing.JLightweightFrame;
import sun.swing.SwingAccessor;
public class LWLightweightFramePeer extends LWWindowPeer {
......@@ -90,11 +92,6 @@ public class LWLightweightFramePeer extends LWWindowPeer {
setBounds(x, y, w, h, op, true, false);
}
@Override
public void updateCursorImmediately() {
// TODO: tries to switch to the awt/fx toolkit thread and causes a deadlock on macosx
}
@Override
public void addDropTarget(DropTarget dt) {
}
......@@ -112,4 +109,9 @@ public class LWLightweightFramePeer extends LWWindowPeer {
public void ungrab() {
getLwTarget().ungrabFocus();
}
@Override
public void updateCursorImmediately() {
SwingAccessor.getJLightweightFrameAccessor().updateCursor((JLightweightFrame)getLwTarget());
}
}
......@@ -33,8 +33,9 @@ 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.ComponentListener;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
import java.awt.image.BufferedImage;
......@@ -48,6 +49,7 @@ 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.security.action.GetPropertyAction;
......@@ -88,6 +90,15 @@ public final class JLightweightFrame extends LightweightFrame implements RootPan
private PropertyChangeListener layoutSizeListener;
static {
SwingAccessor.setJLightweightFrameAccessor(new SwingAccessor.JLightweightFrameAccessor() {
@Override
public void updateCursor(JLightweightFrame frame) {
frame.updateClientCursor();
}
});
}
/**
* Constructs a new, initially invisible {@code JLightweightFrame}
* instance.
......@@ -358,4 +369,21 @@ public final class JLightweightFrame extends LightweightFrame implements RootPan
public Component getGlassPane() {
return getRootPane().getGlassPane();
}
/*
* Notifies client toolkit that it should change a cursor.
*
* Called from the peer via SwingAccessor, because the
* Component.updateCursorImmediately method is final
* and could not be overridden.
*/
private void updateClientCursor() {
Point p = MouseInfo.getPointerInfo().getLocation();
SwingUtilities.convertPointFromScreen(p, this);
Component target = SwingUtilities.getDeepestComponentAt(this, p.x, p.y);
if (target != null) {
content.setCursor(target.getCursor());
}
}
}
......@@ -26,6 +26,7 @@
package sun.swing;
import javax.swing.JComponent;
import java.awt.Cursor;
/**
* The interface by means of which the {@link JLightweightFrame} class
......@@ -179,4 +180,11 @@ public interface LightweightContent {
* application that the content minimum size has changed.
*/
public void minimumSizeChanged(int width, int height);
/**
* {@code JLightweightFrame} calls this method to notify the client
* application that in needs to set a cursor
* @param cursor a cursor to set
*/
default public void setCursor(Cursor cursor) { }
}
......@@ -71,6 +71,16 @@ public final class SwingAccessor {
Object state, boolean forDrop);
}
/**
* An accessor for the JLightweightFrame class.
*/
public interface JLightweightFrameAccessor {
/**
* Notifies the JLightweight frame that it needs to update a cursor
*/
void updateCursor(JLightweightFrame frame);
}
/**
* The javax.swing.text.JTextComponent class accessor object.
*/
......@@ -93,4 +103,23 @@ public final class SwingAccessor {
return jtextComponentAccessor;
}
/**
* The JLightweightFrame class accessor object
*/
private static JLightweightFrameAccessor jLightweightFrameAccessor;
/**
* Set an accessor object for the JLightweightFrame class.
*/
public static void setJLightweightFrameAccessor(JLightweightFrameAccessor accessor) {
jLightweightFrameAccessor = accessor;
}
/**
* Retrieve the accessor object for the JLightweightFrame class
*/
public static JLightweightFrameAccessor getJLightweightFrameAccessor() {
return jLightweightFrameAccessor;
}
}
......@@ -28,6 +28,8 @@ package sun.awt.X11;
import java.awt.Graphics;
import sun.awt.LightweightFrame;
import sun.swing.JLightweightFrame;
import sun.swing.SwingAccessor;
public class XLightweightFramePeer extends XFramePeer {
......@@ -62,4 +64,9 @@ public class XLightweightFramePeer extends XFramePeer {
getLwTarget().ungrabFocus();
}
}
@Override
public void updateCursorImmediately() {
SwingAccessor.getJLightweightFrameAccessor().updateCursor((JLightweightFrame)getLwTarget());
}
}
......@@ -656,7 +656,7 @@ public abstract class WComponentPeer extends WObjectPeer
_setFont(f);
}
public synchronized native void _setFont(Font f);
public final void updateCursorImmediately() {
public void updateCursorImmediately() {
WGlobalCursorManager.getCursorManager().updateCursorImmediately();
}
......
......@@ -31,6 +31,8 @@ import java.awt.event.ComponentEvent;
import java.awt.event.MouseEvent;
import sun.awt.LightweightFrame;
import sun.swing.JLightweightFrame;
import sun.swing.SwingAccessor;
public class WLightweightFramePeer extends WFramePeer {
......@@ -83,4 +85,9 @@ public class WLightweightFramePeer extends WFramePeer {
public void ungrab() {
getLwTarget().ungrabFocus();
}
@Override
public void updateCursorImmediately() {
SwingAccessor.getJLightweightFrameAccessor().updateCursor((JLightweightFrame)getLwTarget());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册