< prev index next >

modules/javafx.swing/src/main/java/javafx/embed/swing/JFXPanel.java

Print this page

        

*** 24,34 **** */ package javafx.embed.swing; import java.awt.AlphaComposite; - import java.awt.AWTEvent; import java.awt.Component; import java.awt.Cursor; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; --- 24,33 ----
*** 36,90 **** import java.awt.Point; import java.awt.Window; import java.awt.Insets; import java.awt.EventQueue; import java.awt.SecondaryLoop; import java.awt.event.AWTEventListener; import java.awt.event.ComponentEvent; import java.awt.event.FocusEvent; import java.awt.event.HierarchyEvent; import java.awt.event.InputEvent; import java.awt.event.InputMethodEvent; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseWheelEvent; ! import java.awt.event.FocusAdapter; ! import java.awt.event.FocusListener; import java.awt.im.InputMethodRequests; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; - import java.awt.datatransfer.Clipboard; import java.nio.IntBuffer; import java.security.AccessController; import java.security.PrivilegedAction; ! import java.util.concurrent.CountDownLatch; import javafx.application.Platform; import javafx.scene.Scene; - import javax.swing.JComponent; - import javax.swing.SwingUtilities; - import com.sun.javafx.application.PlatformImpl; import com.sun.javafx.cursor.CursorFrame; - import com.sun.javafx.embed.AbstractEvents; - import com.sun.javafx.embed.EmbeddedSceneInterface; - import com.sun.javafx.embed.EmbeddedStageInterface; - import com.sun.javafx.embed.HostInterface; import com.sun.javafx.stage.EmbeddedWindow; import com.sun.javafx.tk.Toolkit; import com.sun.javafx.PlatformUtil; - import java.awt.event.InvocationEvent; - import java.lang.reflect.Method; - import java.util.concurrent.atomic.AtomicInteger; - import sun.awt.AppContext; - import sun.awt.SunToolkit; - import sun.java2d.SunGraphics2D; - import sun.java2d.SurfaceData; import com.sun.javafx.logging.PlatformLogger; ! import com.sun.javafx.logging.PlatformLogger.Level; /** * {@code JFXPanel} is a component to embed JavaFX content into * Swing applications. The content to be displayed is specified * with the {@link #setScene} method that accepts an instance of --- 35,86 ---- import java.awt.Point; import java.awt.Window; import java.awt.Insets; import java.awt.EventQueue; import java.awt.SecondaryLoop; + import java.awt.GraphicsEnvironment; import java.awt.event.AWTEventListener; import java.awt.event.ComponentEvent; import java.awt.event.FocusEvent; import java.awt.event.HierarchyEvent; import java.awt.event.InputEvent; import java.awt.event.InputMethodEvent; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseWheelEvent; ! import java.awt.event.InvocationEvent; import java.awt.im.InputMethodRequests; import java.awt.image.BufferedImage; import java.awt.image.DataBufferInt; import java.nio.IntBuffer; + import java.util.concurrent.atomic.AtomicInteger; import java.security.AccessController; import java.security.PrivilegedAction; ! import javax.swing.JComponent; ! import javax.swing.SwingUtilities; import javafx.application.Platform; import javafx.scene.Scene; import com.sun.javafx.application.PlatformImpl; import com.sun.javafx.cursor.CursorFrame; import com.sun.javafx.stage.EmbeddedWindow; import com.sun.javafx.tk.Toolkit; import com.sun.javafx.PlatformUtil; import com.sun.javafx.logging.PlatformLogger; ! import com.sun.javafx.embed.AbstractEvents; ! import com.sun.javafx.embed.EmbeddedSceneInterface; ! import com.sun.javafx.embed.EmbeddedStageInterface; ! import com.sun.javafx.embed.HostInterface; ! ! import com.sun.javafx.embed.swing.InteropFactory; ! import com.sun.javafx.embed.swing.SwingDnD; ! import com.sun.javafx.embed.swing.SwingEvents; ! import com.sun.javafx.embed.swing.SwingCursors; ! import com.sun.javafx.embed.swing.SwingNodeHelper; ! import com.sun.javafx.embed.swing.JFXPanelInterop; /** * {@code JFXPanel} is a component to embed JavaFX content into * Swing applications. The content to be displayed is specified * with the {@link #setScene} method that accepts an instance of
*** 183,192 **** --- 179,199 ---- private boolean isCapturingMouse = false; private static boolean fxInitialized; + private static InteropFactory iopFactoryInstance = null; + private JFXPanelInterop jfxPanelIOP; + + static { + try { + iopFactoryInstance = InteropFactory.getInstance(); + } catch (Exception e) { + throw new ExceptionInInitializerError(e); + } + } + private synchronized void registerFinishListener() { if (instanceCount.getAndIncrement() > 0) { // Already registered return; }
*** 254,263 **** --- 261,271 ---- * preferred way to initialize JavaFX in Swing. */ public JFXPanel() { super(); + jfxPanelIOP = iopFactoryInstance.createJFXPanelImpl(); initFx(); hostContainer = new HostContainer(); enableEvents(InputEvent.COMPONENT_EVENT_MASK |
*** 448,461 **** // asynchronously handled so MOUSE_PRESSED event will not be // honoured by FX immediately due to lack of focus in fx // component. Fire the same MOUSE_PRESSED event after // requestFocus() so that 2nd mouse press will be honoured // since now fx have focus ! AppContext context = SunToolkit.targetToAppContext(this); ! if (context != null) { ! SunToolkit.postEvent(context, e); ! } } } sendMouseEventToFX(e); super.processMouseEvent(e); --- 456,466 ---- // asynchronously handled so MOUSE_PRESSED event will not be // honoured by FX immediately due to lack of focus in fx // component. Fire the same MOUSE_PRESSED event after // requestFocus() so that 2nd mouse press will be honoured // since now fx have focus ! jfxPanelIOP.postEvent(this, e); } } sendMouseEventToFX(e); super.processMouseEvent(e);
*** 568,582 **** pHeight -= (i.top + i.bottom); } double newScaleFactorX = scaleFactorX; double newScaleFactorY = scaleFactorY; Graphics g = getGraphics(); ! if (g instanceof SunGraphics2D) { ! SurfaceData sd = ((SunGraphics2D) g).surfaceData; ! newScaleFactorX = sd.getDefaultScaleX(); ! newScaleFactorY = sd.getDefaultScaleY(); ! } if (oldWidth != pWidth || oldHeight != pHeight || newScaleFactorX != scaleFactorX || newScaleFactorY != scaleFactorY) { createResizePixelBuffer(newScaleFactorX, newScaleFactorY); if (scenePeer != null) { --- 573,588 ---- pHeight -= (i.top + i.bottom); } double newScaleFactorX = scaleFactorX; double newScaleFactorY = scaleFactorY; Graphics g = getGraphics(); ! newScaleFactorX = GraphicsEnvironment.getLocalGraphicsEnvironment(). ! getDefaultScreenDevice().getDefaultConfiguration(). ! getDefaultTransform().getScaleX(); ! newScaleFactorY = GraphicsEnvironment.getLocalGraphicsEnvironment(). ! getDefaultScreenDevice().getDefaultConfiguration(). ! getDefaultTransform().getScaleY(); if (oldWidth != pWidth || oldHeight != pHeight || newScaleFactorX != scaleFactorX || newScaleFactorY != scaleFactorY) { createResizePixelBuffer(newScaleFactorX, newScaleFactorY); if (scenePeer != null) {
*** 763,777 **** } gg.drawImage(pixelsIm, 0, 0, pWidth, pHeight, null); double newScaleFactorX = scaleFactorX; double newScaleFactorY = scaleFactorY; ! if (g instanceof SunGraphics2D) { ! SurfaceData sd = ((SunGraphics2D)g).surfaceData; ! newScaleFactorX = sd.getDefaultScaleX(); ! newScaleFactorY = sd.getDefaultScaleY(); ! } if (scaleFactorX != newScaleFactorX || scaleFactorY != newScaleFactorY) { createResizePixelBuffer(newScaleFactorX, newScaleFactorY); // The scene will request repaint. scenePeer.setPixelScaleFactors((float) newScaleFactorX, (float) newScaleFactorY); --- 769,784 ---- } gg.drawImage(pixelsIm, 0, 0, pWidth, pHeight, null); double newScaleFactorX = scaleFactorX; double newScaleFactorY = scaleFactorY; ! newScaleFactorX = GraphicsEnvironment.getLocalGraphicsEnvironment(). ! getDefaultScreenDevice().getDefaultConfiguration(). ! getDefaultTransform().getScaleX(); ! newScaleFactorY = GraphicsEnvironment.getLocalGraphicsEnvironment(). ! getDefaultScreenDevice().getDefaultConfiguration(). ! getDefaultTransform().getScaleY(); if (scaleFactorX != newScaleFactorX || scaleFactorY != newScaleFactorY) { createResizePixelBuffer(newScaleFactorX, newScaleFactorY); // The scene will request repaint. scenePeer.setPixelScaleFactors((float) newScaleFactorX, (float) newScaleFactorY);
*** 826,837 **** } } } private transient AWTEventListener ungrabListener = event -> { ! if (event instanceof sun.awt.UngrabEvent) { ! SwingFXUtils.runOnFxThread(() -> { if (JFXPanel.this.stagePeer != null && getScene() != null && getScene().getFocusOwner() != null && getScene().getFocusOwner().isFocused()) { JFXPanel.this.stagePeer.focusUngrab(); --- 833,844 ---- } } } private transient AWTEventListener ungrabListener = event -> { ! if (jfxPanelIOP.isUngrabEvent(event)) { ! SwingNodeHelper.runOnFxThread(() -> { if (JFXPanel.this.stagePeer != null && getScene() != null && getScene().getFocusOwner() != null && getScene().getFocusOwner().isFocused()) { JFXPanel.this.stagePeer.focusUngrab();
*** 845,855 **** final Window jfxPanelWindow = SwingUtilities.getWindowAncestor(JFXPanel.this); final Component source = (Component)event.getSource(); final Window eventWindow = source instanceof Window ? (Window)source : SwingUtilities.getWindowAncestor(source); if (jfxPanelWindow == eventWindow) { ! SwingFXUtils.runOnFxThread(() -> { if (JFXPanel.this.stagePeer != null) { // No need to check if grab is active or not. // NoAutoHide popups don't request the grab and // ignore the Ungrab event anyway. // AutoHide popups actually should be hidden when --- 852,862 ---- final Window jfxPanelWindow = SwingUtilities.getWindowAncestor(JFXPanel.this); final Component source = (Component)event.getSource(); final Window eventWindow = source instanceof Window ? (Window)source : SwingUtilities.getWindowAncestor(source); if (jfxPanelWindow == eventWindow) { ! SwingNodeHelper.runOnFxThread(() -> { if (JFXPanel.this.stagePeer != null) { // No need to check if grab is active or not. // NoAutoHide popups don't request the grab and // ignore the Ungrab event anyway. // AutoHide popups actually should be hidden when
*** 875,889 **** registerFinishListener(); AccessController.doPrivileged((PrivilegedAction<Void>) () -> { JFXPanel.this.getToolkit().addAWTEventListener(ungrabListener, ! SunToolkit.GRAB_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK); return null; }); updateComponentSize(); // see RT-23603 ! SwingFXUtils.runOnFxThread(() -> { if ((stage != null) && !stage.isShowing()) { stage.show(); sendMoveEventToFX(); } }); --- 882,896 ---- registerFinishListener(); AccessController.doPrivileged((PrivilegedAction<Void>) () -> { JFXPanel.this.getToolkit().addAWTEventListener(ungrabListener, ! jfxPanelIOP.getMask()); return null; }); updateComponentSize(); // see RT-23603 ! SwingNodeHelper.runOnFxThread(() -> { if ((stage != null) && !stage.isShowing()) { stage.show(); sendMoveEventToFX(); } });
*** 902,912 **** * Notifies this component that it no longer has a parent component. * When this method is invoked, any KeyboardActions set up in the the * chain of parent components are removed. */ @Override public void removeNotify() { ! SwingFXUtils.runOnFxThread(() -> { if ((stage != null) && stage.isShowing()) { stage.hide(); } }); --- 909,919 ---- * Notifies this component that it no longer has a parent component. * When this method is invoked, any KeyboardActions set up in the the * chain of parent components are removed. */ @Override public void removeNotify() { ! SwingNodeHelper.runOnFxThread(() -> { if ((stage != null) && stage.isShowing()) { stage.hide(); } });
*** 926,941 **** deregisterFinishListener(); } private void invokeOnClientEDT(Runnable r) { ! AppContext context = SunToolkit.targetToAppContext(this); ! if (context == null) { ! if (log.isLoggable(Level.FINE)) log.fine("null AppContext encountered!"); ! return; ! } ! SunToolkit.postEvent(context, new InvocationEvent(this, r)); } private class HostContainer implements HostInterface { @Override --- 933,943 ---- deregisterFinishListener(); } private void invokeOnClientEDT(Runnable r) { ! jfxPanelIOP.postEvent(this, new InvocationEvent(this, r)); } private class HostContainer implements HostInterface { @Override
*** 1052,1064 **** if (PlatformUtil.isLinux()) return true; invokeOnClientEDT(() -> { Window window = SwingUtilities.getWindowAncestor(JFXPanel.this); if (window != null) { ! if (JFXPanel.this.getToolkit() instanceof SunToolkit) { ! ((SunToolkit)JFXPanel.this.getToolkit()).grab(window); ! } } }); return true; // Oh, well... } --- 1054,1064 ---- if (PlatformUtil.isLinux()) return true; invokeOnClientEDT(() -> { Window window = SwingUtilities.getWindowAncestor(JFXPanel.this); if (window != null) { ! jfxPanelIOP.grab(JFXPanel.this.getToolkit(), window); } }); return true; // Oh, well... }
*** 1070,1082 **** if (PlatformUtil.isLinux()) return; invokeOnClientEDT(() -> { Window window = SwingUtilities.getWindowAncestor(JFXPanel.this); if (window != null) { ! if (JFXPanel.this.getToolkit() instanceof SunToolkit) { ! ((SunToolkit)JFXPanel.this.getToolkit()).ungrab(window); ! } } }); } } } --- 1070,1080 ---- if (PlatformUtil.isLinux()) return; invokeOnClientEDT(() -> { Window window = SwingUtilities.getWindowAncestor(JFXPanel.this); if (window != null) { ! jfxPanelIOP.ungrab(JFXPanel.this.getToolkit(), window); } }); } } }
< prev index next >