< prev index next >

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

Print this page

        

*** 75,91 **** 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 * JavaFX {@code Scene}. After the scene is assigned, it gets --- 75,90 ---- import com.sun.javafx.PlatformUtil; import java.awt.event.InvocationEvent; import java.lang.reflect.Method; import java.util.concurrent.atomic.AtomicInteger; ! import com.sun.javafx.logging.PlatformLogger; import com.sun.javafx.logging.PlatformLogger.Level; + import jdk.swing.interop.SwingInterOpUtils; + /** * {@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 * JavaFX {@code Scene}. After the scene is assigned, it gets
*** 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); --- 447,457 ---- // 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 ! SwingInterOpUtils.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) { --- 564,575 ---- pHeight -= (i.top + i.bottom); } double newScaleFactorX = scaleFactorX; double newScaleFactorY = scaleFactorY; Graphics g = getGraphics(); ! newScaleFactorX = SwingInterOpUtils.getDefaultScaleX(g); ! newScaleFactorY = SwingInterOpUtils.getDefaultScaleY(g); 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); --- 756,767 ---- } gg.drawImage(pixelsIm, 0, 0, pWidth, pHeight, null); double newScaleFactorX = scaleFactorX; double newScaleFactorY = scaleFactorY; ! newScaleFactorX = SwingInterOpUtils.getDefaultScaleX(g); ! newScaleFactorY = SwingInterOpUtils.getDefaultScaleY(g); if (scaleFactorX != newScaleFactorX || scaleFactorY != newScaleFactorY) { createResizePixelBuffer(newScaleFactorX, newScaleFactorY); // The scene will request repaint. scenePeer.setPixelScaleFactors((float) newScaleFactorX, (float) newScaleFactorY);
*** 826,836 **** } } } 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()) { --- 816,826 ---- } } } private transient AWTEventListener ungrabListener = event -> { ! if (SwingInterOpUtils.isUngrabEvent(event)) { SwingFXUtils.runOnFxThread(() -> { if (JFXPanel.this.stagePeer != null && getScene() != null && getScene().getFocusOwner() != null && getScene().getFocusOwner().isFocused()) {
*** 875,885 **** 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()) { --- 865,875 ---- registerFinishListener(); AccessController.doPrivileged((PrivilegedAction<Void>) () -> { JFXPanel.this.getToolkit().addAWTEventListener(ungrabListener, ! SwingInterOpUtils.GRAB_EVENT_MASK | AWTEvent.MOUSE_EVENT_MASK); return null; }); updateComponentSize(); // see RT-23603 SwingFXUtils.runOnFxThread(() -> { if ((stage != null) && !stage.isShowing()) {
*** 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 --- 916,926 ---- deregisterFinishListener(); } private void invokeOnClientEDT(Runnable r) { ! SwingInterOpUtils.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... } --- 1037,1047 ---- if (PlatformUtil.isLinux()) return true; invokeOnClientEDT(() -> { Window window = SwingUtilities.getWindowAncestor(JFXPanel.this); if (window != null) { ! SwingInterOpUtils.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); ! } } }); } } } --- 1053,1063 ---- if (PlatformUtil.isLinux()) return; invokeOnClientEDT(() -> { Window window = SwingUtilities.getWindowAncestor(JFXPanel.this); if (window != null) { ! SwingInterOpUtils.ungrab(JFXPanel.this.getToolkit(), window); } }); } } }
< prev index next >