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

Copyright © 2012-2022 Basis Technology. Generated on: Tue Feb 6 2024
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.