< prev index next >

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

Print this page

        

*** 26,35 **** --- 26,38 ---- package javafx.embed.swing; import java.awt.AlphaComposite; import java.awt.Graphics2D; import java.awt.image.BufferedImage; + import java.awt.image.DataBufferInt; + import java.awt.image.SampleModel; + import java.awt.image.SinglePixelPackedSampleModel; import java.nio.IntBuffer; import java.util.Set; import java.util.HashSet; import javafx.application.Platform; import javafx.scene.image.Image;
*** 39,49 **** import javafx.scene.image.WritableImage; import javafx.scene.image.WritablePixelFormat; import javafx.scene.paint.Color; import com.sun.javafx.tk.Toolkit; import javax.swing.SwingUtilities; - import sun.awt.image.IntegerComponentRaster; /** * This class provides utility methods for converting data types between * Swing/AWT and JavaFX formats. * @since JavaFX 2.2 --- 42,51 ----
*** 109,122 **** } if (wimg == null) { wimg = new WritableImage(bw, bh); } PixelWriter pw = wimg.getPixelWriter(); ! IntegerComponentRaster icr = (IntegerComponentRaster) bimg.getRaster(); ! int data[] = icr.getDataStorage(); ! int offset = icr.getDataOffset(0); ! int scan = icr.getScanlineStride(); PixelFormat<IntBuffer> pf = (bimg.isAlphaPremultiplied() ? PixelFormat.getIntArgbPreInstance() : PixelFormat.getIntArgbInstance()); pw.setPixels(0, 0, bw, bh, pf, data, offset, scan); return wimg; --- 111,129 ---- } if (wimg == null) { wimg = new WritableImage(bw, bh); } PixelWriter pw = wimg.getPixelWriter(); ! DataBufferInt db = (DataBufferInt)bimg.getRaster().getDataBuffer(); ! int data[] = db.getData(); ! int offset = bimg.getRaster().getDataBuffer().getOffset(); ! int scan = 0; ! SampleModel sm = bimg.getRaster().getSampleModel(); ! if (sm instanceof SinglePixelPackedSampleModel) { ! scan = ((SinglePixelPackedSampleModel)sm).getScanlineStride(); ! } ! PixelFormat<IntBuffer> pf = (bimg.isAlphaPremultiplied() ? PixelFormat.getIntArgbPreInstance() : PixelFormat.getIntArgbInstance()); pw.setPixels(0, 0, bw, bh, pf, data, offset, scan); return wimg;
*** 279,304 **** } } if (bimg == null) { bimg = new BufferedImage(iw, ih, prefBimgType); } ! IntegerComponentRaster icr = (IntegerComponentRaster) bimg.getRaster(); ! int offset = icr.getDataOffset(0); ! int scan = icr.getScanlineStride(); ! int data[] = icr.getDataStorage(); WritablePixelFormat<IntBuffer> pf = getAssociatedPixelFormat(bimg); pr.getPixels(0, 0, iw, ih, pf, data, offset, scan); return bimg; } /** * If called from the FX Application Thread * invokes a runnable directly blocking the calling code * Otherwise * uses Platform.runLater without blocking */ ! static void runOnFxThread(Runnable runnable) { if (Platform.isFxApplicationThread()) { runnable.run(); } else { Platform.runLater(runnable); } --- 286,318 ---- } } if (bimg == null) { bimg = new BufferedImage(iw, ih, prefBimgType); } ! DataBufferInt db = (DataBufferInt)bimg.getRaster().getDataBuffer(); ! int data[] = db.getData(); ! int offset = bimg.getRaster().getDataBuffer().getOffset(); ! int scan = 0; ! SampleModel sm = bimg.getRaster().getSampleModel(); ! if (sm instanceof SinglePixelPackedSampleModel) { ! scan = ((SinglePixelPackedSampleModel)sm).getScanlineStride(); ! } ! WritablePixelFormat<IntBuffer> pf = getAssociatedPixelFormat(bimg); pr.getPixels(0, 0, iw, ih, pf, data, offset, scan); return bimg; } /** * 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); }
*** 307,331 **** /** * If called from the event dispatch thread * invokes a runnable directly blocking the calling code * Otherwise * uses SwingUtilities.invokeLater without blocking */ ! 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 leaving the nested event loop. */ ! static void runOnEDTAndWait(Object nestedLoopKey, Runnable r) { Toolkit.getToolkit().checkFxUserThread(); if (SwingUtilities.isEventDispatchThread()) { r.run(); } else { --- 321,351 ---- /** * 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 {
*** 333,343 **** SwingUtilities.invokeLater(r); Toolkit.getToolkit().enterNestedEventLoop(nestedLoopKey); } } ! static void leaveFXNestedLoop(Object nestedLoopKey) { if (!eventLoopKeys.contains(nestedLoopKey)) return; if (Platform.isFxApplicationThread()) { Toolkit.getToolkit().exitNestedEventLoop(nestedLoopKey, null); } else { --- 353,369 ---- 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 {
< prev index next >