Autopsy  4.7.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 MediaViewVideoPanel videoPanel;
40  private final boolean videoPanelInited;
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 VIDEO_VIEWER_LAYER = "VIDEO"; //NON-NLS
46 
50  public MediaFileViewer() {
51 
52  initComponents();
53 
54  // get the right panel for our platform
55  videoPanel = MediaViewVideoPanel.createVideoPanel();
56  videoPanelInited = videoPanel.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(videoPanel, VIDEO_VIEWER_LAYER);
68 
69  showVideoPanel(false);
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.getMimeTypes());
98  mimeTypes.addAll(this.videoPanel.getMimeTypes());
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 (videoPanelInited && videoPanel.isSupported(file)) {
127  videoPanel.setupVideo(file, dims);
128  this.showVideoPanel(true);
129  } else if (imagePanelInited && imagePanel.isSupported(file)) {
130  imagePanel.showImageFx(file, dims);
131  this.showVideoPanel(false);
132  }
133  } catch (Exception e) {
134  LOGGER.log(Level.SEVERE, "Exception while setting node", e); //NON-NLS
135  }
136  }
137 
143  private void showVideoPanel(boolean showVideo) {
144  CardLayout layout = (CardLayout) this.getLayout();
145  if (showVideo) {
146  layout.show(this, VIDEO_VIEWER_LAYER);
147  } else {
148  layout.show(this, IMAGE_VIEWER_LAYER);
149  }
150  }
151 
152  @Override
153  public Component getComponent() {
154  return this;
155  }
156 
157  @Override
158  public void resetComponent() {
159  videoPanel.reset();
160  imagePanel.reset();
161  lastFile = null;
162  }
163 
164  interface MediaViewPanel {
165 
169  List<String> getMimeTypes();
170 
176  List<String> getExtensionsList();
177 
178  boolean isSupported(AbstractFile file);
179  }
180 }

Copyright © 2012-2016 Basis Technology. Generated on: Mon Jun 18 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.