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

Copyright © 2012-2015 Basis Technology. Generated on: Mon Oct 19 2015
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.