Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataContentViewerMedia.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2015 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.corecomponents;
20 
21 import java.awt.CardLayout;
22 import java.awt.Component;
23 import java.awt.Dimension;
24 import java.util.List;
25 import java.util.logging.Level;
26 import org.openide.nodes.Node;
27 import org.openide.util.NbBundle;
28 import org.openide.util.lookup.ServiceProvider;
29 import org.openide.util.lookup.ServiceProviders;
34 
38 @ServiceProviders(value = {
39  @ServiceProvider(service = DataContentViewer.class, position = 5)
40 })
41 public class DataContentViewerMedia extends javax.swing.JPanel implements DataContentViewer {
42 
43  private static final Logger logger = Logger.getLogger(DataContentViewerMedia.class.getName());
45  //UI
47  private final boolean videoPanelInited;
49  private final boolean imagePanelInited;
50 
51  private static final String IMAGE_VIEWER_LAYER = "IMAGE"; //NON-NLS
52  private static final String VIDEO_VIEWER_LAYER = "VIDEO"; //NON-NLS
53 
58 
59  initComponents();
60 
61  // get the right panel for our platform
63  videoPanelInited = videoPanel.isInited();
64 
65  imagePanel = new MediaViewImagePanel();
66  imagePanelInited = imagePanel.isInited();
67 
68  customizeComponents();
69  logger.log(Level.INFO, "Created MediaView instance: {0}", this); //NON-NLS
70  }
71 
72  private void customizeComponents() {
73  add(imagePanel, IMAGE_VIEWER_LAYER);
74  add(videoPanel, VIDEO_VIEWER_LAYER);
75 
76  showVideoPanel(false);
77  }
78 
84  @SuppressWarnings("unchecked")
85  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
86  private void initComponents() {
87 
88  setLayout(new java.awt.CardLayout());
89  getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(DataContentViewerMedia.class, "DataContentViewerMedia.AccessibleContext.accessibleDescription")); // NOI18N
90  }// </editor-fold>//GEN-END:initComponents
91  // Variables declaration - do not modify//GEN-BEGIN:variables
92  // End of variables declaration//GEN-END:variables
93 
94  @Override
95  public void setNode(Node selectedNode) {
96  try {
97  if (selectedNode == null) {
98  resetComponent();
99  return;
100  }
101 
102  AbstractFile file = selectedNode.getLookup().lookup(AbstractFile.class);
103  if (file == null) {
104  resetComponent();
105  return;
106  }
107 
108  if (file.equals(lastFile)) {
109  return; //prevent from loading twice if setNode() called mult. times
110  }
111 
112  lastFile = file;
113 
114  final Dimension dims = DataContentViewerMedia.this.getSize();
115  //logger.info("setting node on media viewer"); //NON-NLS
116  if (videoPanelInited && videoPanel.isSupported(file)) {
117  videoPanel.setupVideo(file, dims);
118  this.showVideoPanel(true);
119  } else if (imagePanelInited && imagePanel.isSupported(file)) {
120  imagePanel.showImageFx(file, dims);
121  this.showVideoPanel(false);
122  }
123  } catch (Exception e) {
124  logger.log(Level.SEVERE, "Exception while setting node", e); //NON-NLS
125  }
126  }
127 
133  private void showVideoPanel(boolean showVideo) {
134  CardLayout layout = (CardLayout) this.getLayout();
135  if (showVideo) {
136  layout.show(this, VIDEO_VIEWER_LAYER);
137  } else {
138  layout.show(this, IMAGE_VIEWER_LAYER);
139  }
140  }
141 
142  @Override
143  public String getTitle() {
144  return NbBundle.getMessage(this.getClass(), "DataContentViewerMedia.title");
145  }
146 
147  @Override
148  public String getToolTip() {
149  return NbBundle.getMessage(this.getClass(), "DataContentViewerMedia.toolTip");
150  }
151 
152  @Override
154  return new DataContentViewerMedia();
155  }
156 
157  @Override
158  public Component getComponent() {
159  return this;
160  }
161 
162  @Override
163  public void resetComponent() {
164  videoPanel.reset();
165  imagePanel.reset();
166  lastFile = null;
167  }
168 
176  private boolean isVideoSupported(AbstractFile file) {
177  if (null == file || file.getSize() == 0) {
178  return false;
179  }
180  return videoPanel.isSupported(file);
181  }
182 
190  private boolean isImageSupported(AbstractFile file) {
191  if (null == file || file.getSize() == 0) {
192  return false;
193  }
194 
195  return imagePanel.isSupported(file);
196  }
197 
198  @Override
199  public boolean isSupported(Node node) {
200  if (node == null) {
201  return false;
202  }
203 
204  AbstractFile file = node.getLookup().lookup(AbstractFile.class);
205  if (file == null) {
206  return false;
207  }
208 
209  if (file.getSize() == 0) {
210  return false;
211  }
212 
213  if (imagePanelInited && isImageSupported(file)) {
214  return true;
215  }
216 
217  return videoPanelInited && isVideoSupported(file);
218  }
219 
220  @Override
221  public int isPreferred(Node node) {
222  //special case, check if deleted video, then do not make it preferred
223  AbstractFile file = node.getLookup().lookup(AbstractFile.class);
224  if (file == null) {
225  return 0;
226  }
227  boolean deleted = file.isDirNameFlagSet(TSK_FS_NAME_FLAG_ENUM.UNALLOC);
228 
229  if (videoPanel.isSupported(file) && deleted) {
230  return 0;
231  } else {
232  return 7;
233  }
234  }
235 
236  interface MediaViewPanel {
237 
241  List<String> getMimeTypes();
242 
248  List<String> getExtensionsList();
249 
250  boolean isSupported(AbstractFile file);
251  }
252 }
boolean isDirNameFlagSet(TSK_FS_NAME_FLAG_ENUM flag)
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

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