Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
DataContentTopComponent.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
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.beans.PropertyChangeEvent;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.logging.Level;
26 import javax.swing.JTabbedPane;
27 import org.openide.nodes.Node;
28 import org.openide.util.NbBundle;
29 import org.openide.windows.TopComponent;
30 import org.openide.windows.WindowManager;
33 
39 // Registered as a service provider in layer.xml
40 //@TopComponent.Description(preferredID = "DataContentTopComponent")
41 //@TopComponent.Registration(mode = "output", openAtStartup = true)
42 //@TopComponent.OpenActionRegistration(displayName = "#CTL_DataContentAction", preferredID = "DataContentTopComponent")
43 public final class DataContentTopComponent extends TopComponent implements DataContent {
44 
45  private static Logger logger = Logger.getLogger(DataContentTopComponent.class.getName());
46 
47  // reference to the "default" TC that always stays open
49  // set to true if this is the TC that always stays open and is the default place to display content
50  private boolean isDefault;
51  // the content panel holding tabs with content viewers
53 
54  // contains a list of the undocked TCs
55  private static ArrayList<DataContentTopComponent> newWindowList = new ArrayList<DataContentTopComponent>();
56  private static final String PREFERRED_ID = "DataContentTopComponent"; //NON-NLS
57  private static final String DEFAULT_NAME = NbBundle.getMessage(DataContentTopComponent.class, "CTL_DataContentTopComponent");
58  private static final String TOOLTIP_TEXT = NbBundle.getMessage(DataContentTopComponent.class, "HINT_DataContentTopComponent");
59 
60  private DataContentTopComponent(boolean isDefault, String name) {
62  setName(name);
63  setToolTipText(TOOLTIP_TEXT);
64 
65  this.isDefault = isDefault;
66 
67  dataContentPanel = new DataContentPanel(isDefault);
68  add(dataContentPanel);
69 
70  putClientProperty(TopComponent.PROP_CLOSING_DISABLED, Boolean.valueOf(isDefault)); // prevent option to close compoment in GUI
71  logger.log(Level.INFO, "Created DataContentTopComponent instance: " + this); //NON-NLS
72  }
73 
83  public static DataContentTopComponent createUndocked(String filePath, Node givenNode) {
84 
85  DataContentTopComponent dctc = new DataContentTopComponent(false, filePath);
86  dctc.componentOpened();
87  dctc.setNode(givenNode);
88 
89  newWindowList.add(dctc);
90 
91  return dctc;
92  }
93 
99  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
100  private void initComponents() {
101 
102  setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS));
103  }// </editor-fold>//GEN-END:initComponents
104  // Variables declaration - do not modify//GEN-BEGIN:variables
105  // End of variables declaration//GEN-END:variables
106 
113  public static synchronized DataContentTopComponent getDefault() {
114  if (defaultInstance == null) {
115  defaultInstance = new DataContentTopComponent(true, DEFAULT_NAME);
116  }
117  return defaultInstance;
118  }
119 
124  public static synchronized DataContentTopComponent findInstance() {
125  TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
126  if (win == null) {
127  logger.warning("Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system."); //NON-NLS
128  return getDefault();
129  }
130  if (win instanceof DataContentTopComponent) {
131  return (DataContentTopComponent) win;
132  }
133  logger.warning(
134  "There seem to be multiple components with the '" + PREFERRED_ID //NON-NLS
135  + "' ID. That is a potential source of errors and unexpected behavior."); //NON-NLS
136  return getDefault();
137  }
138 
139  @Override
140  public int getPersistenceType() {
141  return TopComponent.PERSISTENCE_NEVER;
142  }
143 
144  @Override
145  public void componentOpened() {
146  }
147 
148  @Override
149  public void componentClosed() {
150 
151  dataContentPanel.setNode(null);
152 
153  if (!this.isDefault) {
154  newWindowList.remove(this);
155  }
156  }
157 
158  @Override
159  protected String preferredID() {
160  if (this.isDefault) {
161  return PREFERRED_ID;
162  } else {
163  return this.getName();
164  }
165  }
166 
167  @Override
168  public void setNode(Node selectedNode) {
169  dataContentPanel.setNode(selectedNode);
170  }
171 
172  @Override
173  public boolean canClose() {
174  return (!this.isDefault) || !Case.isCaseOpen() || Case.getCurrentCase().hasData() == false; // only allow this window to be closed when there's no case opened or no image in this case
175  }
176 
177  @Override
178  public void propertyChange(PropertyChangeEvent evt) {
179  }
180 
186  public JTabbedPane getTabPanels() {
187  return dataContentPanel.getTabPanels();
188  }
189 
195  public static List<DataContentTopComponent> getNewWindowList() {
196  return newWindowList;
197  }
198 }
static DataContentTopComponent createUndocked(String filePath, Node givenNode)
static synchronized DataContentTopComponent findInstance()
synchronized static Logger getLogger(String name)
Definition: Logger.java:161

Copyright © 2012-2016 Basis Technology. Generated on: Tue Oct 25 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.