< prev index next >
modules/javafx.swing/src/main/java/com/sun/javafx/embed/swing/SwingNodeHelper.java
Print this page
*** 23,40 ****
--- 23,48 ----
* questions.
*/
package com.sun.javafx.embed.swing;
+ import java.util.concurrent.locks.ReentrantLock;
+
import com.sun.javafx.geom.BaseBounds;
import com.sun.javafx.geom.transform.BaseTransform;
import com.sun.javafx.scene.NodeHelper;
import com.sun.javafx.sg.prism.NGNode;
import com.sun.javafx.util.Utils;
import javafx.embed.swing.SwingNode;
import javafx.scene.Node;
+ import java.util.Set;
+ import java.util.HashSet;
+ import javafx.application.Platform;
+ import javax.swing.SwingUtilities;
+ import com.sun.javafx.tk.Toolkit;
+
/**
* Used to access internal methods of SwingNode.
*/
public class SwingNodeHelper extends NodeHelper {
*** 74,83 ****
--- 82,223 ----
@Override
protected boolean computeContainsImpl(Node node, double localX, double localY) {
return swingNodeAccessor.doComputeContains(node, localX, localY);
}
+ public static Object getLightweightFrame(SwingNode node) {
+ return swingNodeAccessor.getLightweightFrame(node);
+ }
+
+ public static ReentrantLock getPaintLock(SwingNode node) {
+ return swingNodeAccessor.getPaintLock(node);
+ }
+
+ public static void setImageBuffer(SwingNode node, final int[] data,
+ final int x, final int y,
+ final int w, final int h, final int linestride,
+ final double scaleX, final double scaleY) {
+ swingNodeAccessor.setImageBuffer(node, data, x, y, w, h,
+ linestride, scaleX, scaleY);
+ }
+
+ public static void setImageBounds(SwingNode node, final int x, final int y,
+ final int w, final int h) {
+ swingNodeAccessor.setImageBounds(node, x, y, w, h);
+ }
+
+ public static void repaintDirtyRegion(SwingNode node, final int dirtyX, final int dirtyY,
+ final int dirtyWidth, final int dirtyHeight) {
+ swingNodeAccessor.repaintDirtyRegion(node, dirtyX, dirtyY,
+ dirtyWidth, dirtyHeight);
+ }
+
+ public static void ungrabFocus(SwingNode node, boolean postUngrabEvent) {
+ swingNodeAccessor.ungrabFocus(node, postUngrabEvent);
+ }
+
+ public static void setSwingPrefWidth(SwingNode node, int swingPrefWidth) {
+ swingNodeAccessor.setSwingPrefWidth(node, swingPrefWidth);;
+ }
+
+ public static void setSwingPrefHeight(SwingNode node, int swingPrefHeight) {
+ swingNodeAccessor.setSwingPrefHeight(node, swingPrefHeight);
+ }
+
+ public static void setSwingMaxWidth(SwingNode node, int swingMaxWidth) {
+ swingNodeAccessor.setSwingMaxWidth(node, swingMaxWidth);
+ }
+
+ public static void setSwingMaxHeight(SwingNode node, int swingMaxHeight) {
+ swingNodeAccessor.setSwingMaxHeight(node, swingMaxHeight);
+ }
+
+ public static void setSwingMinWidth(SwingNode node, int swingMinWidth) {
+ swingNodeAccessor.setSwingMinWidth(node, swingMinWidth);
+ }
+
+ public static void setSwingMinHeight(SwingNode node, int swingMinHeight) {
+ swingNodeAccessor.setSwingMinHeight(node, swingMinHeight);
+ }
+
+ public static void setGrabbed(SwingNode node, boolean grab) {
+ swingNodeAccessor.setGrabbed(node, grab);
+ }
+
+ /**
+ * If called from the FX Application Thread
+ * invokes a runnable directly blocking the calling code
+ * Otherwise
+ * uses Platform.runLater without blocking
+ *
+ * @param runnable {@code Runnable} to be invoked
+ */
+ public static void runOnFxThread(Runnable runnable) {
+ if (Platform.isFxApplicationThread()) {
+ runnable.run();
+ } else {
+ Platform.runLater(runnable);
+ }
+ }
+
+ /**
+ * If called from the event dispatch thread
+ * invokes a runnable directly blocking the calling code
+ * Otherwise
+ * uses SwingUtilities.invokeLater without blocking
+ *
+ * @param r {@code Runnable} to be invoked
+ */
+ public static void runOnEDT(final Runnable r) {
+ if (SwingUtilities.isEventDispatchThread()) {
+ r.run();
+ } else {
+ SwingUtilities.invokeLater(r);
+ }
+ }
+
+ private static final Set<Object> eventLoopKeys = new HashSet<>();
+
+ /**
+ * The runnable is responsible for entering the nested event loop.
+ *
+ * @param nestedLoopKey the Object that identifies the nested event loop,
+ * which must not be null
+ * @param r {@code Runnable} to be invoked
+ */
+ public static void runOnEDTAndWait(Object nestedLoopKey, Runnable r) {
+ Toolkit.getToolkit().checkFxUserThread();
+
+ if (SwingUtilities.isEventDispatchThread()) {
+ r.run();
+ } else {
+ eventLoopKeys.add(nestedLoopKey);
+ SwingUtilities.invokeLater(r);
+ Toolkit.getToolkit().enterNestedEventLoop(nestedLoopKey);
+ }
+ }
+
+ /**
+ * The runnable is responsible for leaving the nested event loop.
+ *
+ * @param nestedLoopKey the Object that identifies the nested event loop,
+ * which must not be null
+ */
+ public static void leaveFXNestedLoop(Object nestedLoopKey) {
+ if (!eventLoopKeys.contains(nestedLoopKey)) return;
+
+ if (Platform.isFxApplicationThread()) {
+ Toolkit.getToolkit().exitNestedEventLoop(nestedLoopKey, null);
+ } else {
+ Platform.runLater(() -> {
+ Toolkit.getToolkit().exitNestedEventLoop(nestedLoopKey, null);
+ });
+ }
+
+ eventLoopKeys.remove(nestedLoopKey);
+ }
+
public static void setSwingNodeAccessor(final SwingNodeAccessor newAccessor) {
if (swingNodeAccessor != null) {
throw new IllegalStateException();
}
*** 87,94 ****
--- 227,252 ----
public interface SwingNodeAccessor {
NGNode doCreatePeer(Node node);
void doUpdatePeer(Node node);
BaseBounds doComputeGeomBounds(Node node, BaseBounds bounds, BaseTransform tx);
boolean doComputeContains(Node node, double localX, double localY);
+ Object getLightweightFrame(SwingNode node);
+ ReentrantLock getPaintLock(SwingNode node);
+ void setImageBuffer(SwingNode node, final int[] data,
+ final int x, final int y,
+ final int w, final int h, final int linestride,
+ final double scaleX, final double scaleY);
+ void setImageBounds(SwingNode node, final int x, final int y,
+ final int w, final int h);
+ void repaintDirtyRegion(SwingNode node, final int dirtyX, final int dirtyY,
+ final int dirtyWidth, final int dirtyHeight);
+ void ungrabFocus(SwingNode node, boolean postUngrabEvent);
+ void setSwingPrefWidth(SwingNode node, int swingPrefWidth);
+ void setSwingPrefHeight(SwingNode node, int swingPrefHeight);
+ void setSwingMaxWidth(SwingNode node, int swingMaxWidth);
+ void setSwingMaxHeight(SwingNode node, int swingMaxHeight);
+ void setSwingMinWidth(SwingNode node, int swingMinWidth);
+ void setSwingMinHeight(SwingNode node, int swingMinHeight);
+ void setGrabbed(SwingNode node, boolean grab);
}
}
< prev index next >