19 package org.sleuthkit.autopsy.corecomponents;
21 import java.awt.Dimension;
22 import java.awt.EventQueue;
23 import java.awt.event.ActionEvent;
24 import java.util.Collections;
25 import java.util.List;
26 import static java.util.Objects.nonNull;
27 import java.util.SortedSet;
28 import java.util.concurrent.ExecutionException;
29 import java.util.stream.Collectors;
30 import javafx.application.Platform;
31 import javafx.concurrent.Task;
32 import javafx.embed.swing.JFXPanel;
33 import javafx.geometry.Pos;
34 import javafx.scene.Cursor;
35 import javafx.scene.Scene;
36 import javafx.scene.control.Button;
37 import javafx.scene.control.Label;
38 import javafx.scene.control.ProgressBar;
39 import javafx.scene.image.Image;
40 import javafx.scene.image.ImageView;
41 import javafx.scene.layout.BorderPane;
42 import javafx.scene.layout.VBox;
43 import javax.imageio.ImageIO;
44 import javax.swing.JPanel;
45 import org.controlsfx.control.MaskerPane;
46 import org.openide.util.NbBundle;
47 import org.python.google.common.collect.Lists;
59 @NbBundle.Messages({
"MediaViewImagePanel.externalViewerButton.text=Open in External Viewer",
60 "MediaViewImagePanel.errorLabel.text=Could not load file into Media View.",
61 "MediaViewImagePanel.errorLabel.OOMText=Could not load file into Media View: insufficent memory."})
64 private static final Image EXTERNAL =
new Image(
MediaViewImagePanel.class.getResource(
"/org/sleuthkit/autopsy/images/external.png").toExternalForm());
73 private final ProgressBar progressBar =
new ProgressBar();
74 private final MaskerPane maskerPane =
new MaskerPane();
77 ImageIO.scanForPlugins();
91 .collect(Collectors.toList());
102 Platform.runLater(() -> {
105 fxImageView =
new ImageView();
106 borderpane =
new BorderPane(fxImageView);
107 borderpane.getStyleClass().add(
"bg");
108 fxPanel =
new JFXPanel();
109 Scene scene =
new Scene(borderpane);
110 scene.getStylesheets().add(
MediaViewImagePanel.class.getResource(
"MediaViewImagePanel.css").toExternalForm());
111 fxPanel.setScene(scene);
114 fxImageView.fitWidthProperty().bind(scene.widthProperty());
115 fxImageView.fitHeightProperty().bind(scene.heightProperty());
116 fxImageView.setPreserveRatio(
true);
117 fxImageView.setSmooth(
true);
118 fxImageView.setCache(
true);
120 EventQueue.invokeLater(() -> {
135 Platform.runLater(() -> {
136 fxImageView.setImage(null);
137 borderpane.setCenter(null);
142 final Button externalViewerButton =
new Button(Bundle.MediaViewImagePanel_externalViewerButton_text(),
new ImageView(EXTERNAL));
143 externalViewerButton.setOnAction(actionEvent
149 .actionPerformed(
new ActionEvent(
this, ActionEvent.ACTION_PERFORMED,
""))
152 final VBox errorNode =
new VBox(10,
new Label(errorMessage), externalViewerButton);
153 errorNode.setAlignment(Pos.CENTER);
154 borderpane.setCenter(errorNode);
163 void showImageFx(
final AbstractFile file,
final Dimension dims) {
168 Platform.runLater(() -> {
169 if (readImageTask != null) {
170 readImageTask.cancel();
172 readImageTask = ImageUtils.newReadImageTask(file);
173 readImageTask.setOnSucceeded(succeeded -> {
174 if (!Case.isCaseOpen()) {
186 Image fxImage = readImageTask.get();
187 if (nonNull(fxImage)) {
189 fxImageView.setImage(fxImage);
190 borderpane.setCenter(fxImageView);
192 showErrorNode(Bundle.MediaViewImagePanel_errorLabel_text(), file);
194 }
catch (InterruptedException | ExecutionException ex) {
195 showErrorNode(Bundle.MediaViewImagePanel_errorLabel_text(), file);
197 borderpane.setCursor(Cursor.DEFAULT);
199 readImageTask.setOnFailed(failed -> {
200 if (!Case.isCaseOpen()) {
210 Throwable exception = readImageTask.getException();
211 if (exception instanceof OutOfMemoryError
212 && exception.getMessage().contains(
"Java heap space")) {
213 showErrorNode(Bundle.MediaViewImagePanel_errorLabel_OOMText(), file);
215 showErrorNode(Bundle.MediaViewImagePanel_errorLabel_text(), file);
218 borderpane.setCursor(Cursor.DEFAULT);
221 maskerPane.setProgressNode(progressBar);
222 progressBar.progressProperty().bind(readImageTask.progressProperty());
223 maskerPane.textProperty().bind(readImageTask.messageProperty());
224 borderpane.setCenter(maskerPane);
225 borderpane.setCursor(Cursor.WAIT);
226 new Thread(readImageTask).start();
235 return Collections.unmodifiableList(Lists.newArrayList(supportedMimes));
245 return getExtensions();
254 return Collections.unmodifiableList(supportedExtensions);
267 @SuppressWarnings(
"unchecked")
269 private
void initComponents() {
271 setBackground(
new java.awt.Color(0, 0, 0));
272 setLayout(
new javax.swing.BoxLayout(
this, javax.swing.BoxLayout.Y_AXIS));
static boolean isJavaFxInited()
static List< String > getSupportedImageExtensions()
synchronized static Logger getLogger(String name)
static boolean isImageThumbnailSupported(AbstractFile file)
static SortedSet< String > getSupportedImageMimeTypes()