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

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