Autopsy  4.9.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddImageWizardIterator.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2017 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.awt.Component;
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.NoSuchElementException;
25 import javax.swing.JComponent;
26 import javax.swing.event.ChangeListener;
27 import org.openide.WizardDescriptor;
28 import org.openide.util.NbBundle;
32 
37 class AddImageWizardIterator implements WizardDescriptor.Iterator<WizardDescriptor> {
38 
39  private int index = 0;
40  private List<ShortcutWizardDescriptorPanel> panels;
41  private final AddImageAction action;
42  private int progressPanelIndex;
43  private int dsPanelIndex;
44  private final static String PROP_LASTPROFILE_NAME = "AIW_LASTPROFILE_NAME"; //NON-NLS
45 
46  AddImageWizardIterator(AddImageAction action) {
47  this.action = action;
48  }
49 
54  private List<ShortcutWizardDescriptorPanel> getPanels() {
55  if (panels == null) {
56  panels = new ArrayList<>();
57  AddImageWizardSelectDspPanel dspSelection = new AddImageWizardSelectDspPanel();
58  panels.add(dspSelection);
59  AddImageWizardAddingProgressPanel progressPanel = new AddImageWizardAddingProgressPanel(action);
60 
61  AddImageWizardDataSourceSettingsPanel dsPanel = new AddImageWizardDataSourceSettingsPanel();
62  AddImageWizardIngestConfigPanel ingestConfigPanel = new AddImageWizardIngestConfigPanel(progressPanel);
63  panels.add(dsPanel);
64  List<IngestProfiles.IngestProfile> profiles = IngestProfiles.getIngestProfiles();
65  if (!profiles.isEmpty()) {
66  panels.add(new IngestProfileSelectionWizardPanel(AddImageWizardIngestConfigPanel.class.getCanonicalName(), getPropLastprofileName()));
67  }
68  panels.add(ingestConfigPanel);
69  panels.add(progressPanel);
70  progressPanelIndex = panels.indexOf(progressPanel); //Doing programatically because number of panels is variable
71  dsPanelIndex = panels.indexOf(dsPanel);
72  String[] steps = new String[panels.size()];
73  for (int i = 0; i < panels.size(); i++) {
74  Component c = panels.get(i).getComponent();
75  // Default step name to component name of panel.
76  steps[i] = c.getName();
77  if (c instanceof JComponent) { // assume Swing components
78  JComponent jc = (JComponent) c;
79  // Sets step number of a component
80  jc.putClientProperty("WizardPanel_contentSelectedIndex", i);
81  // Sets steps names for a panel
82  jc.putClientProperty("WizardPanel_contentData", steps);
83  // Turn on subtitle creation on each step
84  jc.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE);
85  // Show steps on the left side with the image on the background
86  jc.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE);
87  // Turn on numbering of all steps
88  jc.putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE);
89  }
90  }
91  }
92  return panels;
93  }
94 
101  public int getIndex() {
102  return index;
103  }
104 
111  static String getPropLastprofileName() {
112  return PROP_LASTPROFILE_NAME;
113  }
114 
118  static String getPROP_LASTPROFILE_NAME() {
119  return PROP_LASTPROFILE_NAME;
120  }
121 
127  @Override
128  public ShortcutWizardDescriptorPanel current() {
129  if (panels != null) {
130  return panels.get(index);
131  } else {
132  return getPanels().get(index);
133  }
134  }
135 
141  @Override
142  public String name() {
143  return NbBundle.getMessage(this.getClass(), "AddImageWizardIterator.stepXofN", Integer.toString(index + 1),
144  getPanels().size());
145  }
146 
152  @Override
153  public boolean hasNext() {
154  return index < getPanels().size() - 1;
155  }
156 
162  @Override
163  // disable the previous button on all panels except the data source panel
164  public boolean hasPrevious() {
165  return (index == dsPanelIndex); //Users should be able to back up to select a different DSP
166  }
167 
172  @Override
173  public void nextPanel() {
174  if (!hasNext()) {
175  throw new NoSuchElementException();
176  }
177  // Start processing the data source by handing it off to the selected DSP,
178  // so it gets going in the background while the user is still picking the Ingest modules
179  // This will occur when the next button is clicked on the panel where you have chosen your data to process
180  if (index == dsPanelIndex) {
181  ((AddImageWizardAddingProgressPanel) panels.get(progressPanelIndex)).
182  startDataSourceProcessing(((AddImageWizardDataSourceSettingsPanel) panels.get(dsPanelIndex)).getComponent().getCurrentDSProcessor());
183  }
184  boolean panelEnablesSkipping = current().panelEnablesSkipping();
185  boolean skipNextPanel = current().skipNextPanel();
186  index++;
187  if (panelEnablesSkipping && skipNextPanel) {
188  current().processThisPanelBeforeSkipped();
189  nextPanel();
190  }
191  }
192 
197  @Override
198  public void previousPanel() {
199  if (!hasPrevious()) {
200  throw new NoSuchElementException();
201  }
202  if (index == progressPanelIndex) {
203  index--;
204  }
205  index--;
206  }
207 
208  // If nothing unusual changes in the middle of the wizard, simply:
209  @Override
210  public void addChangeListener(ChangeListener l) {
211  }
212 
213  @Override
214  public void removeChangeListener(ChangeListener l) {
215  }
216 }

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