Autopsy  4.10.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-2018 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.awt.Dimension;
24 import java.util.ArrayList;
25 import java.util.List;
26 import java.util.logging.Level;
28 import org.sleuthkit.datamodel.AbstractFile;
29 
33 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
34 class MediaFileViewer extends javax.swing.JPanel implements FileTypeViewer {
35 
36  private static final Logger LOGGER = Logger.getLogger(MediaFileViewer.class.getName());
37  private AbstractFile lastFile;
38  //UI
39  private final MediaPlayerPanel mediaPlayerPanel;
40  private final boolean mediaPlayerPanelInited;
41  private final MediaViewImagePanel imagePanel;
42  private final boolean imagePanelInited;
43 
44  private static final String IMAGE_VIEWER_LAYER = "IMAGE"; //NON-NLS
45  private static final String MEDIA_PLAYER_LAYER = "AUDIO_VIDEO"; //NON-NLS
46 
50  public MediaFileViewer() {
51 
52  initComponents();
53 
54  // get the right panel for our platform
55  mediaPlayerPanel = new MediaPlayerPanel();
56  mediaPlayerPanelInited = mediaPlayerPanel.isInited();
57 
58  imagePanel = new MediaViewImagePanel();
59  imagePanelInited = imagePanel.isInited();
60 
61  customizeComponents();
62  LOGGER.log(Level.INFO, "Created MediaView instance: {0}", this); //NON-NLS
63  }
64 
65  private void customizeComponents() {
66  add(imagePanel, IMAGE_VIEWER_LAYER);
67  add(mediaPlayerPanel, MEDIA_PLAYER_LAYER);
68 
69  showImagePanel();
70  }
71 
77  @SuppressWarnings("unchecked")
78  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
79  private void initComponents() {
80 
81  setLayout(new java.awt.CardLayout());
82  getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(MediaFileViewer.class, "MediaFileViewer.AccessibleContext.accessibleDescription")); // NOI18N
83  }// </editor-fold>//GEN-END:initComponents
84  // Variables declaration - do not modify//GEN-BEGIN:variables
85  // End of variables declaration//GEN-END:variables
86 
92  @Override
93  public List<String> getSupportedMIMETypes() {
94 
95  List<String> mimeTypes = new ArrayList<>();
96 
97  mimeTypes.addAll(this.imagePanel.getSupportedMimeTypes());
98  mimeTypes.addAll(this.mediaPlayerPanel.getSupportedMimeTypes());
99 
100  return mimeTypes;
101  }
102 
103 
109  @Override
110  public void setFile(AbstractFile file) {
111  try {
112 
113  if (file == null) {
114  resetComponent();
115  return;
116  }
117 
118  if (file.equals(lastFile)) {
119  return; //prevent from loading twice if setNode() called mult. times
120  }
121 
122  lastFile = file;
123 
124  final Dimension dims = MediaFileViewer.this.getSize();
125  //logger.info("setting node on media viewer"); //NON-NLS
126  if (mediaPlayerPanelInited && mediaPlayerPanel.isSupported(file)) {
127  mediaPlayerPanel.loadFile(file, dims);
128  this.showVideoPanel();
129  } else if (imagePanelInited && imagePanel.isSupported(file)) {
130  imagePanel.showImageFx(file, dims);
131  this.showImagePanel();
132  }
133  } catch (Exception e) {
134  LOGGER.log(Level.SEVERE, "Exception while setting node", e); //NON-NLS
135  }
136  }
137 
141  private void showVideoPanel() {
142  CardLayout layout = (CardLayout) this.getLayout();
143  layout.show(this, MEDIA_PLAYER_LAYER);
144  }
145 
149  private void showImagePanel() {
150  CardLayout layout = (CardLayout) this.getLayout();
151  layout.show(this, IMAGE_VIEWER_LAYER);
152  }
153 
154  @Override
155  public Component getComponent() {
156  return this;
157  }
158 
159  @Override
160  public void resetComponent() {
161  mediaPlayerPanel.reset();
162  imagePanel.reset();
163  lastFile = null;
164  }
165 
169  protected interface MediaViewPanel {
170 
174  List<String> getSupportedMimeTypes();
175 
181  List<String> getSupportedExtensions();
182 
183  boolean isSupported(AbstractFile file);
184  }
185 }

Copyright © 2012-2018 Basis Technology. Generated on: Fri Mar 22 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.