Autopsy  4.6.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
IngestOptionsPanel.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.ingest;
20 
21 import java.awt.EventQueue;
22 import java.beans.PropertyChangeEvent;
23 import java.beans.PropertyChangeListener;
24 import javax.swing.JTabbedPane;
25 import javax.swing.event.ChangeEvent;
26 import javax.swing.event.ChangeListener;
27 import org.openide.util.NbBundle;
31 
36 
37  @NbBundle.Messages({"IngestOptionsPanel.settingsTab.text=Settings",
38  "IngestOptionsPanel.settingsTab.toolTipText=Settings regarding resources available to ingest.",
39  "IngestOptionsPanel.fileFiltersTab.text=File Filters",
40  "IngestOptionsPanel.fileFiltersTab.toolTipText=Settings for creating and editing ingest file filters.",
41  "IngestOptionsPanel.profilesTab.text=Profiles",
42  "IngestOptionsPanel.profilesTab.toolTipText=Settings for creating and editing profiles."})
43 
45  private final static int INDEX_OF_FILTER_PANEL = 0;
46  private IngestSettingsPanel settingsPanel;
47  private final static int INDEX_OF_SETTINGS_PANEL = 2;
48  private ProfileSettingsPanel profilePanel;
49  private final static int INDEX_OF_PROFILE_PANEL = 1;
50  private int indexOfPreviousTab;
57  IngestJobEventPropertyChangeListener ingestJobEventsListener;
58 
59  public IngestOptionsPanel() {
62  indexOfPreviousTab = tabbedPane.getSelectedIndex();
63  }
64 
65  private void customizeComponents() {
67  settingsPanel = new IngestSettingsPanel();
68  profilePanel = new ProfileSettingsPanel();
69 
70  tabbedPane.insertTab(NbBundle.getMessage(IngestOptionsPanel.class, "IngestOptionsPanel.fileFiltersTab.text"), null,
71  filterPanel, NbBundle.getMessage(IngestOptionsPanel.class, "IngestOptionsPanel.fileFiltersTab.toolTipText"), INDEX_OF_FILTER_PANEL);
72  tabbedPane.insertTab(NbBundle.getMessage(IngestOptionsPanel.class, "IngestOptionsPanel.profilesTab.text"), null,
73  profilePanel, NbBundle.getMessage(IngestOptionsPanel.class, "IngestOptionsPanel.profilesTab.toolTipText"), INDEX_OF_PROFILE_PANEL);
74  tabbedPane.insertTab(NbBundle.getMessage(IngestOptionsPanel.class, "IngestOptionsPanel.settingsTab.text"), null,
75  settingsPanel, NbBundle.getMessage(IngestOptionsPanel.class, "IngestOptionsPanel.settingsTab.toolTipText"), INDEX_OF_SETTINGS_PANEL);
76  //Listener for when tabbed panes are switched, because we can have two file filter definitions panels open at the same time
77  //we may wind up in a situation where the user has created and saved one in the profiles panel
78  //so we need to refresh the filterPanel in those cases before proceeding.
79  tabbedPane.addChangeListener(new ChangeListener() {
80  @Override
81  public void stateChanged(ChangeEvent e) {
82  if (e.getSource() instanceof JTabbedPane) {
83  //If we are switching to a filter panel we should load
84  //load the filter panel to ensure it is up to date
85  //incase a filter was addded through the Profile->new->create new filter manner
86  if (tabbedPane.getSelectedIndex() == INDEX_OF_FILTER_PANEL && tabbedPane.getSelectedIndex() != indexOfPreviousTab) {
87  filterPanel.load();
88  }
89  //save the contents of whichever Tab we just switched from
90  saveTabByIndex(indexOfPreviousTab);
91  //save the index of the current tab for the next time we switch
92  indexOfPreviousTab = tabbedPane.getSelectedIndex();
93  }
94  }
95  });
96 
98  enableTabs();
99  }
100 
107  private void addIngestJobEventsListener() {
108  ingestJobEventsListener = new IngestJobEventPropertyChangeListener();
109  IngestManager.getInstance().addIngestJobEventListener(ingestJobEventsListener);
110  }
111 
115  private class IngestJobEventPropertyChangeListener implements PropertyChangeListener {
116 
117  @Override
118  public void propertyChange(PropertyChangeEvent evt) {
119  EventQueue.invokeLater(new Runnable() {
120  @Override
121  public void run() {
122  enableTabs();
123  }
124  });
125  }
126  }
127 
132  private void enableTabs() {
133  boolean ingestIsRunning = IngestManager.getInstance().isIngestRunning();
134  tabbedPane.setEnabled(!ingestIsRunning);
135  settingsPanel.enableButtons(!ingestIsRunning);
136  profilePanel.enableButtons(!ingestIsRunning);
137  filterPanel.enableButtons(!ingestIsRunning);
138 
139  }
140 
141  @Override
142  public void addPropertyChangeListener(PropertyChangeListener l) {
143  super.addPropertyChangeListener(l);
144  /*
145  * There is at least one look and feel library that follows the bad
146  * practice of calling overrideable methods in a constructor, e.g.:
147  *
148  * at
149  * javax.swing.plaf.synth.SynthPanelUI.installListeners(SynthPanelUI.java:83)
150  * at
151  * javax.swing.plaf.synth.SynthPanelUI.installUI(SynthPanelUI.java:63)
152  * at javax.swing.JComponent.setUI(JComponent.java:666) at
153  * javax.swing.JPanel.setUI(JPanel.java:153) at
154  * javax.swing.JPanel.updateUI(JPanel.java:126) at
155  * javax.swing.JPanel.<init>(JPanel.java:86) at
156  * javax.swing.JPanel.<init>(JPanel.java:109) at
157  * javax.swing.JPanel.<init>(JPanel.java:117)
158  *
159  * When this happens, the following child components of this JPanel
160  * subclass have not been constructed yet, since this panel's
161  * constructor has not been called yet.
162  */
163  if (null != filterPanel) {
164  filterPanel.addPropertyChangeListener(l);
165  }
166  if (null != settingsPanel) {
167  settingsPanel.addPropertyChangeListener(l);
168  }
169  if (null != profilePanel) {
170  profilePanel.addPropertyChangeListener(l);
171  }
172  }
173 
174  @Override
175  public void removePropertyChangeListener(PropertyChangeListener l) {
176  filterPanel.removePropertyChangeListener(l);
177  settingsPanel.removePropertyChangeListener(l);
178  profilePanel.removePropertyChangeListener(l);
179  }
180 
181  @Override
182  public void saveSettings() {
183  saveTabByIndex(tabbedPane.getSelectedIndex());
184  }
185 
191  private void saveTabByIndex(int index) {
192  //Because we can create filters in two seperate windows here we need
193  //to be careful not to save an out of date list over the current list
194  switch (index) {
195  case (INDEX_OF_FILTER_PANEL):
197  break;
198  case (INDEX_OF_PROFILE_PANEL):
199  profilePanel.saveSettings();
200  break;
201  case (INDEX_OF_SETTINGS_PANEL):
202  settingsPanel.saveSettings();
203  break;
204  default:
205  //don't save anything if it wasn't a tab index that should exist
206  }
207  }
208 
209  @Override
210  public void store() {
211  saveSettings();
212  }
213 
214  @Override
215  public void load() {
216  filterPanel.load();
217  settingsPanel.load();
218  profilePanel.load();
219  }
220 
221  boolean valid() {
222  return true;
223  }
224 
228  void cancel() {
229  //doesn't need to do anything
230  }
231 
237  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
238  private void initComponents() {
239 
240  tabbedPane = new javax.swing.JTabbedPane();
241 
242  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
243  this.setLayout(layout);
244  layout.setHorizontalGroup(
245  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
246  .addGroup(layout.createSequentialGroup()
247  .addComponent(tabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 824, Short.MAX_VALUE)
248  .addGap(0, 0, 0))
249  );
250  layout.setVerticalGroup(
251  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
252  .addGroup(layout.createSequentialGroup()
253  .addComponent(tabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 543, Short.MAX_VALUE)
254  .addGap(0, 0, 0))
255  );
256  }// </editor-fold>//GEN-END:initComponents
257 
258  // Variables declaration - do not modify//GEN-BEGIN:variables
259  private javax.swing.JTabbedPane tabbedPane;
260  // End of variables declaration//GEN-END:variables
261 }
static synchronized IngestManager getInstance()
void addPropertyChangeListener(PropertyChangeListener l)
void addIngestJobEventListener(final PropertyChangeListener listener)
void removePropertyChangeListener(PropertyChangeListener l)

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