Autopsy  4.12.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ReportWizardIterator.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2012 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.report;
20 
21 import java.awt.Component;
22 import java.util.Arrays;
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.NbPreferences;
29 
30 final class ReportWizardIterator implements WizardDescriptor.Iterator<WizardDescriptor> {
31 
32  private int index;
33 
34  private final ReportWizardPanel1 firstPanel;
35  private final ReportWizardPanel2 tableConfigPanel;
36  private final ReportWizardFileOptionsPanel fileConfigPanel;
37  private final ReportWizardPortableCaseOptionsPanel portableCaseConfigPanel;
38 
39  private List<WizardDescriptor.Panel<WizardDescriptor>> panels;
40 
41  // Panels that should be shown if both Table and File report modules should
42  // be configured.
43  private final WizardDescriptor.Panel<WizardDescriptor>[] allConfigPanels;
44 
45  // Panels that should be shown if only Table report modules should
46  // be configured.
47  private final WizardDescriptor.Panel<WizardDescriptor>[] tableConfigPanels;
48 
49  // Panels that should be shown if only File report modules should
50  // be configured.
51  private final WizardDescriptor.Panel<WizardDescriptor>[] fileConfigPanels;
52 
53  // Panels that should be shown if only Portable Case report modules should
54  // be configured.
55  private final WizardDescriptor.Panel<WizardDescriptor>[] portableCaseConfigPanels;
56 
57  @SuppressWarnings({"rawtypes", "unchecked"})
58  ReportWizardIterator() {
59  firstPanel = new ReportWizardPanel1();
60  tableConfigPanel = new ReportWizardPanel2();
61  fileConfigPanel = new ReportWizardFileOptionsPanel();
62  portableCaseConfigPanel = new ReportWizardPortableCaseOptionsPanel();
63 
64  allConfigPanels = new WizardDescriptor.Panel[]{firstPanel, tableConfigPanel, fileConfigPanel, portableCaseConfigPanel};
65  tableConfigPanels = new WizardDescriptor.Panel[]{firstPanel, tableConfigPanel};
66  fileConfigPanels = new WizardDescriptor.Panel[]{firstPanel, fileConfigPanel};
67  portableCaseConfigPanels = new WizardDescriptor.Panel[]{firstPanel, portableCaseConfigPanel};
68  }
69 
70  private List<WizardDescriptor.Panel<WizardDescriptor>> getPanels() {
71  if (panels == null) {
72  panels = Arrays.asList(allConfigPanels);
73  String[] steps = new String[panels.size()];
74  for (int i = 0; i < panels.size(); i++) {
75  Component c = panels.get(i).getComponent();
76  // Default step name to component name of panel.
77  steps[i] = c.getName();
78  if (c instanceof JComponent) { // assume Swing components
79  JComponent jc = (JComponent) c;
80  jc.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, i);
81  jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, steps);
82  jc.putClientProperty(WizardDescriptor.PROP_AUTO_WIZARD_STYLE, true);
83  jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DISPLAYED, false);
84  jc.putClientProperty(WizardDescriptor.PROP_CONTENT_NUMBERED, true);
85  }
86  }
87  }
88  return panels;
89  }
90 
98  private void enableConfigPanels(boolean generalModule, boolean tableModule, boolean portableCaseModule) {
99  if (generalModule) {
100  // General Module selected, no additional panels
101  } else if (tableModule) {
102  // Table Module selected, need Artifact Configuration Panel
103  // (ReportWizardPanel2)
104  panels = Arrays.asList(tableConfigPanels);
105  } else if (portableCaseModule) {
106  // Portable Case Module selected, need Portable Case Configuration Panel
107  // (ReportWizardPortableCaseOptionsPanel)
108  panels = Arrays.asList(portableCaseConfigPanels);
109  } else {
110  // File Module selected, need File Report Configuration Panel
111  // (ReportWizardFileOptionsPanel)
112  panels = Arrays.asList(fileConfigPanels);
113  }
114  }
115 
116  @Override
117  public WizardDescriptor.Panel<WizardDescriptor> current() {
118  return getPanels().get(index);
119  }
120 
121  @Override
122  public String name() {
123  return "";
124  }
125 
126  @Override
127  public boolean hasNext() {
128  return index < getPanels().size() - 1;
129  }
130 
131  @Override
132  public boolean hasPrevious() {
133  return index > 0;
134  }
135 
136  @Override
137  public void nextPanel() {
138  if (!hasNext()) {
139  throw new NoSuchElementException();
140  }
141 
142  if (index == 0) {
143  // Update path through configuration panels
144  boolean generalModule, tableModule, portableModule;
145  // These preferences are set in ReportWizardPanel1.storeSettings()
146  generalModule = NbPreferences.forModule(ReportWizardPanel1.class).getBoolean("generalModule", true); //NON-NLS
147  tableModule = NbPreferences.forModule(ReportWizardPanel1.class).getBoolean("tableModule", true); //NON-NLS
148  portableModule = NbPreferences.forModule(ReportWizardPanel1.class).getBoolean("portableCaseModule", true); //NON-NLS
149  enableConfigPanels(generalModule, tableModule, portableModule);
150  }
151 
152  index++;
153  }
154 
155  @Override
156  public void previousPanel() {
157  if (!hasPrevious()) {
158  throw new NoSuchElementException();
159  }
160  index--;
161  }
162 
163  @Override
164  public void addChangeListener(ChangeListener l) {
165  }
166 
167  @Override
168  public void removeChangeListener(ChangeListener l) {
169  }
170 }

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