Autopsy  4.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddImageWizardChooseDataSourcePanel.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.casemodule;
20 
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
23 import java.util.HashSet;
24 import java.util.Iterator;
25 import java.util.Set;
26 import java.util.logging.Level;
27 import org.openide.util.NbBundle;
29 import javax.swing.event.ChangeEvent;
30 import javax.swing.event.ChangeListener;
31 import org.openide.WizardDescriptor;
32 import org.openide.util.HelpCtx;
33 import org.openide.util.Lookup;
34 import org.openide.windows.WindowManager;
35 import java.awt.Cursor;
36 
41 class AddImageWizardChooseDataSourcePanel implements WizardDescriptor.Panel<WizardDescriptor>, PropertyChangeListener {
42 
47  private AddImageWizardAddingProgressPanel progressPanel;
48  private AddImageWizardChooseDataSourceVisual component;
49  private boolean isNextEnable = false;
50  private static final String PROP_LASTDATASOURCE_PATH = "LBL_LastDataSource_PATH"; //NON-NLS
51  private static final String PROP_LASTDATASOURCE_TYPE = "LBL_LastDataSource_TYPE"; //NON-NLS
52  // paths to any set hash lookup databases (can be null)
53  private String NSRLPath, knownBadPath;
54 
55  AddImageWizardChooseDataSourcePanel(AddImageWizardAddingProgressPanel proPanel) {
56 
57  this.progressPanel = proPanel;
58 
59  }
60 
69  @Override
70  public AddImageWizardChooseDataSourceVisual getComponent() {
71  if (component == null) {
72  WindowManager.getDefault().getMainWindow().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
73  component = new AddImageWizardChooseDataSourceVisual(this);
74  }
75  component.addPropertyChangeListener(this);
76  return component;
77  }
78 
85  @Override
86  public HelpCtx getHelp() {
87  // Show no Help button for this panel:
88  return HelpCtx.DEFAULT_HELP;
89  // If you have context help:
90  // return new HelpCtx(SampleWizardPanel1.class);
91  }
92 
100  @Override
101  public boolean isValid() {
102  return isNextEnable;
103  }
104 
108  void moveFocusToNext() {
109  // set the focus to the next button of the wizard dialog if it's enabled
110  if (isNextEnable) {
111  Lookup.getDefault().lookup(AddImageAction.class).requestFocusButton(
112  NbBundle.getMessage(this.getClass(), "AddImageWizardChooseDataSourcePanel.moveFocusNext"));
113  }
114  }
115 
121  public void enableNextButton(boolean isEnabled) {
122  isNextEnable = isEnabled;
123  fireChangeEvent();
124  }
125  private final Set<ChangeListener> listeners = new HashSet<ChangeListener>(1); // or can use ChangeSupport in NB 6.0
126 
132  @Override
133  public final void addChangeListener(ChangeListener l) {
134  synchronized (listeners) {
135  listeners.add(l);
136  }
137  }
138 
144  @Override
145  public final void removeChangeListener(ChangeListener l) {
146  synchronized (listeners) {
147  listeners.remove(l);
148  }
149  }
150 
155  protected final void fireChangeEvent() {
156  Iterator<ChangeListener> it;
157  synchronized (listeners) {
158  it = new HashSet<ChangeListener>(listeners).iterator();
159  }
160  ChangeEvent ev = new ChangeEvent(this);
161  while (it.hasNext()) {
162  it.next().stateChanged(ev);
163  }
164  }
165 
166  // You can use a settings object to keep track of state. Normally the
167  // settings object will be the WizardDescriptor, so you can use
168  // WizardDescriptor.getProperty & putProperty to store information entered
169  // by the user.
178  @Override
179  public void readSettings(WizardDescriptor settings) {
180 
181  //reset settings if supports it
182  //getComponent().reset();
183  // Prepopulate the image directory from the properties file
184  try {
185 
186  // Load hash database settings, enable or disable the checkbox
187  this.NSRLPath = null;
188  this.knownBadPath = null;
189  //JCheckBox lookupFilesCheckbox = component.getLookupFilesCheckbox();
190  //lookupFilesCheckbox.setSelected(false);
191  //lookupFilesCheckbox.setEnabled(this.NSRLPath != null || this.knownBadPath != null);
192 
193  // If there is a process object in the settings, revert it and remove it from the settings
194  AddImageAction.CleanupTask cleanupTask = (AddImageAction.CleanupTask) settings.getProperty(AddImageAction.IMAGECLEANUPTASK_PROP);
195  if (cleanupTask != null) {
196  try {
197  cleanupTask.cleanup();
198  } catch (Exception ex) {
199  Logger logger = Logger.getLogger(AddImageWizardChooseDataSourcePanel.class.getName());
200  logger.log(Level.WARNING, "Error cleaning up image task", ex); //NON-NLS
201  } finally {
202  cleanupTask.disable();
203  }
204  }
205  } catch (Exception e) {
206  }
207 
208  }
209 
219  @Override
220  public void storeSettings(WizardDescriptor settings) {
221 
222  return;
223  }
224 
231  @Override
232  public void propertyChange(PropertyChangeEvent evt) {
233  fireChangeEvent();
234  }
235 }

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