Autopsy  3.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 
38 // Registered as a service provider in layer.xml
39 //@TopComponent.Description(preferredID = "DataContentTopComponent")
40 //@TopComponent.Registration(mode = "output", openAtStartup = true)
41 //@TopComponent.OpenActionRegistration(displayName = "#CTL_DataContentAction", preferredID = "DataContentTopComponent")
42 public final class DataContentTopComponent extends TopComponent implements DataContent {
43 
44  private static Logger logger = Logger.getLogger(DataContentTopComponent.class.getName());
45 
46  // reference to the "default" TC that always stays open
48  // set to true if this is the TC that always stays open and is the default place to display content
49  private boolean isDefault;
50  // the content panel holding tabs with content viewers
52 
53  // contains a list of the undocked TCs
54  private static ArrayList<DataContentTopComponent> newWindowList = new ArrayList<DataContentTopComponent>();
55  private static final String PREFERRED_ID = "DataContentTopComponent"; //NON-NLS
56  private static final String DEFAULT_NAME = NbBundle.getMessage(DataContentTopComponent.class, "CTL_DataContentTopComponent");
57  private static final String TOOLTIP_TEXT = NbBundle.getMessage(DataContentTopComponent.class, "HINT_DataContentTopComponent");
58 
59  private DataContentTopComponent(boolean isDefault, String name) {
61  setName(name);
62  setToolTipText(TOOLTIP_TEXT);
63 
64  this.isDefault = isDefault;
65 
66  dataContentPanel = new DataContentPanel(isDefault);
67  add(dataContentPanel);
68 
69  putClientProperty(TopComponent.PROP_CLOSING_DISABLED, Boolean.valueOf(isDefault)); // prevent option to close compoment in GUI
70  logger.log(Level.INFO, "Created DataContentTopComponent instance: " + this); //NON-NLS
71  }
72 
80  public static DataContentTopComponent createUndocked(String filePath, Node givenNode) {
81 
82  DataContentTopComponent dctc = new DataContentTopComponent(false, filePath);
83  dctc.componentOpened();
84  dctc.setNode(givenNode);
85 
86  newWindowList.add(dctc);
87 
88  return dctc;
89  }
90 
96  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
97  private void initComponents() {
98 
99  setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS));
100  }// </editor-fold>//GEN-END:initComponents
101  // Variables declaration - do not modify//GEN-BEGIN:variables
102  // End of variables declaration//GEN-END:variables
103 
109  public static synchronized DataContentTopComponent getDefault() {
110  if (defaultInstance == null) {
111  defaultInstance = new DataContentTopComponent(true, DEFAULT_NAME);
112  }
113  return defaultInstance;
114  }
115 
119  public static synchronized DataContentTopComponent findInstance() {
120  TopComponent win = WindowManager.getDefault().findTopComponent(PREFERRED_ID);
121  if (win == null) {
122  logger.warning("Cannot find " + PREFERRED_ID + " component. It will not be located properly in the window system."); //NON-NLS
123  return getDefault();
124  }
125  if (win instanceof DataContentTopComponent) {
126  return (DataContentTopComponent) win;
127  }
128  logger.warning(
129  "There seem to be multiple components with the '" + PREFERRED_ID //NON-NLS
130  + "' ID. That is a potential source of errors and unexpected behavior."); //NON-NLS
131  return getDefault();
132  }
133 
134  @Override
135  public int getPersistenceType() {
136  return TopComponent.PERSISTENCE_NEVER;
137  }
138 
139  @Override
140  public void componentOpened() {
141  }
142 
143  @Override
144  public void componentClosed() {
145 
146  dataContentPanel.setNode(null);
147 
148  if (!this.isDefault) {
149  newWindowList.remove(this);
150  }
151  }
152 
153  @Override
154  protected String preferredID() {
155  if (this.isDefault) {
156  return PREFERRED_ID;
157  } else {
158  return this.getName();
159  }
160  }
161 
162  @Override
163  public void setNode(Node selectedNode) {
164  dataContentPanel.setNode(selectedNode);
165  }
166 
167  @Override
168  public boolean canClose() {
169  return (!this.isDefault) || !Case.existsCurrentCase() || Case.getCurrentCase().hasData() == false; // only allow this window to be closed when there's no case opened or no image in this case
170  }
171 
172  @Override
173  public void propertyChange(PropertyChangeEvent evt) {
174  }
175 
180  public JTabbedPane getTabPanels() {
181  return dataContentPanel.getTabPanels();
182  }
183 
188  public static List<DataContentTopComponent> getNewWindowList() {
189  return newWindowList;
190  }
191 }
static boolean existsCurrentCase()
Definition: Case.java:622
static DataContentTopComponent createUndocked(String filePath, Node givenNode)
static Logger getLogger(String name)
Definition: Logger.java:131

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