Autopsy  4.16.0
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 int ingestPanelIndex;
45  private final static String PROP_LASTPROFILE_NAME = "AIW_LASTPROFILE_NAME"; //NON-NLS
46 
47  AddImageWizardIterator(AddImageAction action) {
48  this.action = action;
49  }
50 
55  private List<ShortcutWizardDescriptorPanel> getPanels() {
56  if (panels == null) {
57  panels = new ArrayList<>();
58  AddImageWizardSelectDspPanel dspSelection = new AddImageWizardSelectDspPanel();
59  panels.add(dspSelection);
60  AddImageWizardAddingProgressPanel progressPanel = new AddImageWizardAddingProgressPanel(action);
61 
62  AddImageWizardDataSourceSettingsPanel dsPanel = new AddImageWizardDataSourceSettingsPanel();
63  AddImageWizardIngestConfigPanel ingestConfigPanel = new AddImageWizardIngestConfigPanel(progressPanel);
64  panels.add(dsPanel);
65  List<IngestProfiles.IngestProfile> profiles = IngestProfiles.getIngestProfiles();
66  if (!profiles.isEmpty()) {
67  panels.add(new IngestProfileSelectionWizardPanel(AddImageWizardIngestConfigPanel.class.getCanonicalName(), getPropLastprofileName()));
68  }
69  panels.add(ingestConfigPanel);
70  panels.add(progressPanel);
71  progressPanelIndex = panels.indexOf(progressPanel); //Doing programatically because number of panels is variable
72  dsPanelIndex = panels.indexOf(dsPanel);
73  ingestPanelIndex = panels.indexOf(ingestConfigPanel);
74  String[] steps = new String[panels.size()];
75  for (int i = 0; i < panels.size(); i++) {
76  Component c = panels.get(i).getComponent();
77  // Default step name to component name of panel.
78  steps[i] = c.getName();
79  if (c instanceof JComponent) { // assume Swing components
80  JComponent jc = (JComponent) c;
81  // Sets step number of a component
82  jc.putClientProperty("WizardPanel_contentSelectedIndex", i);
83  // Sets steps names for a panel
84  jc.putClientProperty("WizardPanel_contentData", steps);
85  // Turn on subtitle creation on each step
86  jc.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE);
87  // Show steps on the left side with the image on the background
88  jc.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE);
89  // Turn on numbering of all steps
90  jc.putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE);
91  }
92  }
93  }
94  return panels;
95  }
96 
103  public int getIndex() {
104  return index;
105  }
106 
113  static String getPropLastprofileName() {
114  return PROP_LASTPROFILE_NAME;
115  }
116 
120  static String getPROP_LASTPROFILE_NAME() {
121  return PROP_LASTPROFILE_NAME;
122  }
123 
129  @Override
130  public ShortcutWizardDescriptorPanel current() {
131  if (panels != null) {
132  return panels.get(index);
133  } else {
134  return getPanels().get(index);
135  }
136  }
137 
143  @Override
144  public String name() {
145  return NbBundle.getMessage(this.getClass(), "AddImageWizardIterator.stepXofN", Integer.toString(index + 1),
146  getPanels().size());
147  }
148 
154  @Override
155  public boolean hasNext() {
156  return index < getPanels().size() - 1;
157  }
158 
164  @Override
165  // disable the previous button on all panels except the data source panel
166  public boolean hasPrevious() {
167  return (index == dsPanelIndex); //Users should be able to back up to select a different DSP
168  }
169 
174  @Override
175  public void nextPanel() {
176  if (!hasNext()) {
177  throw new NoSuchElementException();
178  }
179  // Start processing the data source by handing it off to the selected DSP,
180  // so it gets going in the background while the user is still picking the Ingest modules
181  // This will occur when the next button is clicked on the panel where you have chosen your data to process
182  if (index == ingestPanelIndex) {
183  ((AddImageWizardAddingProgressPanel) panels.get(progressPanelIndex)).
184  startDataSourceProcessing(((AddImageWizardDataSourceSettingsPanel) panels.get(dsPanelIndex)).getComponent().getCurrentDSProcessor());
185  }
186  boolean panelEnablesSkipping = current().panelEnablesSkipping();
187  boolean skipNextPanel = current().skipNextPanel();
188  index++;
189  if (panelEnablesSkipping && skipNextPanel) {
190  current().processThisPanelBeforeSkipped();
191  nextPanel();
192  }
193  }
194 
199  @Override
200  public void previousPanel() {
201  if (!hasPrevious()) {
202  throw new NoSuchElementException();
203  }
204  if (index == progressPanelIndex) {
205  index--;
206  }
207  index--;
208  }
209 
210  // If nothing unusual changes in the middle of the wizard, simply:
211  @Override
212  public void addChangeListener(ChangeListener l) {
213  }
214 
215  @Override
216  public void removeChangeListener(ChangeListener l) {
217  }
218 }

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