Autopsy  4.21.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
MediaFileViewer.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2019 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *s
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.contentviewers;
20 
21 import java.awt.CardLayout;
22 import java.awt.Component;
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.logging.Level;
26 import org.freedesktop.gstreamer.GstException;
27 import org.openide.util.NbBundle;
30 import org.sleuthkit.datamodel.AbstractFile;
31 
35 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
36 class MediaFileViewer extends javax.swing.JPanel implements FileTypeViewer {
37 
38  private static final Logger LOGGER = Logger.getLogger(MediaFileViewer.class.getName());
39  private static final long serialVersionUID = 1L;
40  private AbstractFile lastFile;
41  //UI
42  private MediaPlayerPanel mediaPlayerPanel;
43  private final MediaViewImagePanel imagePanel;
44  private final boolean imagePanelInited;
45 
46  private static final String IMAGE_VIEWER_LAYER = "IMAGE"; //NON-NLS
47  private static final String MEDIA_PLAYER_LAYER = "AUDIO_VIDEO"; //NON-NLS
48 
52  MediaFileViewer() {
53 
54  initComponents();
55 
56  try {
57  mediaPlayerPanel = new MediaPlayerPanel();
58  } catch (GstException | UnsatisfiedLinkError ex) {
59  LOGGER.log(Level.SEVERE, "Error initializing gstreamer for audio/video viewing and frame extraction capabilities", ex); //NON-NLS
60  MessageNotifyUtil.Notify.error(
61  NbBundle.getMessage(this.getClass(), "MediaFileViewer.initGst.gstException.msg"),
62  ex.getMessage());
63  }
64  imagePanel = new MediaViewImagePanel();
65  imagePanelInited = imagePanel.isInited();
66 
67  customizeComponents();
68  LOGGER.log(Level.INFO, "Created MediaView instance: {0}", this); //NON-NLS
69  }
70 
71  private void customizeComponents() {
72  add(imagePanel, IMAGE_VIEWER_LAYER);
73 
74  if (mediaPlayerPanel != null) {
75  add(mediaPlayerPanel, MEDIA_PLAYER_LAYER);
76  }
77 
78  showImagePanel();
79  }
80 
86  @SuppressWarnings("unchecked")
87  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
88  private void initComponents() {
89 
90  setLayout(new java.awt.CardLayout());
91  getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MediaFileViewer.class, "MediaFileViewer.AccessibleContext.accessibleDescription")); // NOI18N
92  }// </editor-fold>//GEN-END:initComponents
93  // Variables declaration - do not modify//GEN-BEGIN:variables
94  // End of variables declaration//GEN-END:variables
95 
101  @Override
102  public List<String> getSupportedMIMETypes() {
103 
104  List<String> mimeTypes = new ArrayList<>();
105 
106  mimeTypes.addAll(this.imagePanel.getSupportedMimeTypes());
107  if (mediaPlayerPanel != null) {
108  mimeTypes.addAll(this.mediaPlayerPanel.getSupportedMimeTypes());
109  }
110 
111  return mimeTypes;
112  }
113 
119  @Override
120  public void setFile(AbstractFile file) {
121  try {
122 
123  if (file == null) {
124  resetComponent();
125  return;
126  }
127 
128  if (file.equals(lastFile)) {
129  return; //prevent from loading twice if setNode() called mult. times
130  }
131 
132  lastFile = file;
133  if (mediaPlayerPanel != null && mediaPlayerPanel.isSupported(file)) {
134  mediaPlayerPanel.loadFile(file);
135  this.showVideoPanel();
136  } else if (imagePanelInited && imagePanel.isSupported(file)) {
137  imagePanel.loadFile(file);
138  this.showImagePanel();
139  }
140  } catch (Exception e) {
141  LOGGER.log(Level.SEVERE, "Exception while setting node", e); //NON-NLS
142  }
143  }
144 
148  private void showVideoPanel() {
149  CardLayout layout = (CardLayout) this.getLayout();
150  layout.show(this, MEDIA_PLAYER_LAYER);
151  }
152 
156  private void showImagePanel() {
157  CardLayout layout = (CardLayout) this.getLayout();
158  layout.show(this, IMAGE_VIEWER_LAYER);
159  }
160 
161  @Override
162  public Component getComponent() {
163  return this;
164  }
165 
166  @Override
167  public void resetComponent() {
168  if (mediaPlayerPanel != null) {
169  mediaPlayerPanel.reset();
170  }
171  imagePanel.reset();
172  lastFile = null;
173  }
174 
178  protected interface MediaViewPanel {
179 
183  List<String> getSupportedMimeTypes();
184 
190  List<String> getSupportedExtensions();
191 
192  boolean isSupported(AbstractFile file);
193  }
194 
195  @Override
196  public boolean isSupported(AbstractFile file){
197  return mediaPlayerPanel.isSupported(file) || imagePanel.isSupported(file);
198  }
199 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.