19 package org.sleuthkit.autopsy.corecomponents;
21 import java.awt.Dimension;
22 import java.awt.EventQueue;
23 import java.awt.image.BufferedImage;
24 import java.io.IOException;
25 import java.io.InputStream;
26 import java.util.ArrayList;
27 import java.util.Arrays;
28 import java.util.List;
29 import java.util.logging.Level;
30 import javafx.application.Platform;
31 import javafx.embed.swing.JFXPanel;
32 import javafx.embed.swing.SwingFXUtils;
33 import javafx.scene.Scene;
34 import javafx.scene.image.Image;
35 import javafx.scene.image.ImageView;
36 import javafx.scene.layout.BorderPane;
37 import javax.imageio.ImageIO;
38 import javax.swing.SwingUtilities;
39 import org.openide.util.NbBundle;
58 static private final List<String>
supportedMimes = Arrays.asList(
"image/jpeg",
"image/png",
"image/gif",
"image/bmp",
"image/x-ms-bmp");
70 supportedExtensions =
new ArrayList<>();
72 for (String suffix : ImageIO.getReaderFileSuffixes()) {
74 supportedExtensions.add(
"." + suffix);
87 Platform.runLater(
new Runnable() {
90 fxPanel =
new JFXPanel();
91 fxImageView =
new ImageView();
95 fxImageView.setPreserveRatio(
true);
96 fxImageView.setSmooth(
true);
97 fxImageView.setCache(
true);
99 EventQueue.invokeLater(
new Runnable() {
113 Platform.runLater(
new Runnable() {
116 fxImageView.setImage(null);
127 void showImageFx(
final AbstractFile file,
final Dimension dims) {
132 final String fileName = file.
getName();
135 fxPanel.setVisible(
false);
138 Platform.runLater(
new Runnable() {
141 if (!Case.isCaseOpen()) {
147 final InputStream inputStream =
new ReadContentInputStream(file);
152 BufferedImage bi = ImageIO.read(inputStream);
154 logger.log(Level.WARNING,
"Could image reader not found for file: " + fileName);
158 BufferedImage biScaled = ScalrWrapper.resizeHighQuality(bi, (
int) dims.getWidth(), (int) dims.getHeight());
160 fxImage = SwingFXUtils.toFXImage(biScaled, null);
161 }
catch (IOException ex) {
162 logger.log(Level.WARNING,
"Could not load image file into media view: " + fileName, ex);
164 }
catch (OutOfMemoryError ex) {
165 logger.log(Level.WARNING,
"Could not load image file into media view (too large): " + fileName, ex);
166 MessageNotifyUtil.Notify.warn(
167 NbBundle.getMessage(
this.getClass(),
"MediaViewImagePanel.imgFileTooLarge.msg", file.
getName()),
173 }
catch (IOException ex) {
174 logger.log(Level.WARNING,
"Could not close input stream after loading image in media view: " + fileName, ex);
178 if (fxImage == null || fxImage.isError()) {
179 logger.log(Level.WARNING,
"Could not load image file into media view: " + fileName);
184 BorderPane borderpane =
new BorderPane();
185 borderpane.setCenter(fxImageView);
187 fxImageView.setImage(fxImage);
188 fxImageView.setFitWidth(dims.getWidth());
189 fxImageView.setFitHeight(dims.getHeight());
194 Scene fxScene =
new Scene(borderpane, javafx.scene.paint.Color.BLACK);
197 fxPanel.setScene(fxScene);
199 SwingUtilities.invokeLater(
new Runnable() {
203 fxPanel.setVisible(
true);
233 @SuppressWarnings(
"unchecked")
237 setBackground(
new java.awt.Color(0, 0, 0));
238 setLayout(
new javax.swing.BoxLayout(
this, javax.swing.BoxLayout.Y_AXIS));
static boolean isJavaFxInited()
static Logger getLogger(String name)