< prev index next >
modules/javafx.swing/src/main/java/javafx/embed/swing/SwingFXUtils.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 26,49 ****
package javafx.embed.swing;
import java.awt.AlphaComposite;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.nio.IntBuffer;
- import java.util.Set;
- import java.util.HashSet;
- import javafx.application.Platform;
import javafx.scene.image.Image;
import javafx.scene.image.PixelFormat;
import javafx.scene.image.PixelReader;
import javafx.scene.image.PixelWriter;
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
--- 26,46 ----
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 javafx.scene.image.Image;
import javafx.scene.image.PixelFormat;
import javafx.scene.image.PixelReader;
import javafx.scene.image.PixelWriter;
import javafx.scene.image.WritableImage;
import javafx.scene.image.WritablePixelFormat;
import javafx.scene.paint.Color;
/**
* This class provides utility methods for converting data types between
* Swing/AWT and JavaFX formats.
* @since JavaFX 2.2
*** 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;
--- 106,124 ----
}
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,352 ****
}
}
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);
- }
- }
-
- /**
- * 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 {
- eventLoopKeys.add(nestedLoopKey);
- 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 {
- Platform.runLater(() -> {
- Toolkit.getToolkit().exitNestedEventLoop(nestedLoopKey, null);
- });
- }
-
- eventLoopKeys.remove(nestedLoopKey);
- }
-
}
--- 281,299 ----
}
}
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;
}
}
< prev index next >