Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
IngestProfileSelectionPanel.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.runIngestModuleWizard;
20 
21 import java.awt.Color;
22 import java.awt.Component;
23 import java.awt.Dimension;
24 import java.awt.GridBagConstraints;
25 import java.awt.GridBagLayout;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
28 import java.util.Collections;
29 import java.util.List;
30 import javax.swing.Box;
31 import static javax.swing.Box.createVerticalGlue;
32 import javax.swing.ButtonModel;
33 import javax.swing.JPanel;
34 import javax.swing.JScrollPane;
35 import javax.swing.JTextArea;
36 import javax.swing.JToggleButton;
37 import org.openide.util.NbBundle.Messages;
42 
47 final class IngestProfileSelectionPanel extends JPanel {
48 
49  @Messages({"IngestProfileSelectionPanel.customSettings.name=Custom Settings",
50  "IngestProfileSelectionPanel.customSettings.description=configure individual module settings in next step of wizard"})
51 
52  private static final long serialVersionUID = 1L;
53  private static final String CUSTOM_SETTINGS_DISPLAY_NAME = Bundle.IngestProfileSelectionPanel_customSettings_name();
54  private static final String CUSTOM_SETTINGS_DESCRIPTION = Bundle.IngestProfileSelectionPanel_customSettings_description();
55  private final IngestProfileSelectionWizardPanel wizardPanel;
56  private String selectedProfile;
57  private List<IngestProfile> profiles = Collections.emptyList();
58  boolean isLastPanel = false;
59 
60  //Listener for profile button selection
61  ActionListener buttonGroupActionListener = (ActionEvent e) -> {
62  updateSelectedProfile();
63  };
70  IngestProfileSelectionPanel(IngestProfileSelectionWizardPanel panel, String lastSelectedProfile) {
71  initComponents();
72  wizardPanel = panel;
73  selectedProfile = lastSelectedProfile;
74  isLastPanel = !selectedProfile.equals(wizardPanel.getDefaultContext());
75 
76  populateProfilesList();
77  }
78 
84  String getLastSelectedProfile() {
85  return selectedProfile;
86  }
87 
93  private void updateSelectedProfile() {
94 
95  ButtonModel selectedButton = profileListButtonGroup.getSelection();
96  selectedProfile = selectedButton.getActionCommand();
97 
98  boolean wasLastPanel = isLastPanel;
99  isLastPanel = !selectedProfile.equals(wizardPanel.getDefaultContext());
100  wizardPanel.fireChangeEvent();
101  this.firePropertyChange("LAST_ENABLED", wasLastPanel, isLastPanel); //NON-NLS
102  }
103 
108  private void populateProfilesList() {
109  profiles = getProfiles();
110 
111  GridBagLayout gridBagLayout = new GridBagLayout();
112  GridBagConstraints constraints = new GridBagConstraints();
113  constraints.fill = GridBagConstraints.HORIZONTAL;
114  constraints.gridx = 0;
115  constraints.gridy = 0;
116  constraints.weighty = .0;
117  constraints.anchor = GridBagConstraints.LINE_START;
118 
119  addButton(CUSTOM_SETTINGS_DISPLAY_NAME, wizardPanel.getDefaultContext(), CUSTOM_SETTINGS_DESCRIPTION, gridBagLayout, constraints);
120 
121  profiles.forEach((profile) -> {
122  constraints.weightx = 0;
123  constraints.gridy++;
124  constraints.gridx = 0;
125 
126  addButton(profile.toString(), profile.toString(), profile.getDescription(), gridBagLayout, constraints);
127  });
128  //Add vertical glue at the bottom of the scroll panel so spacing
129  //between elements is less dependent on the number of elements
130  constraints.gridy++;
131  constraints.gridx = 0;
132  constraints.weighty = 1;
133  Component vertGlue = createVerticalGlue();
134  profileListPanel.add(vertGlue);
135  gridBagLayout.setConstraints(vertGlue, constraints);
136  profileListPanel.setLayout(gridBagLayout);
137  }
138 
148  private void addButton(String profileDisplayName, String profileContextName, String profileDesc, GridBagLayout layout, GridBagConstraints constraints) {
149 
150  //Add a spacer
151  Dimension spacerBlockDimension = new Dimension(6, 4); // Space between left edge and button, Space between rows
152  Box.Filler spacer = new Box.Filler(spacerBlockDimension, spacerBlockDimension, spacerBlockDimension);
153  constraints.weightx = 1;
154  layout.setConstraints(spacer, constraints);
155  profileListPanel.add(spacer);
156  constraints.gridx++;
157  constraints.gridy++;
158 
159 
160  JToggleButton profileButton = new JToggleButton();
161  profileButton.setMaximumSize(new java.awt.Dimension(48, 48));
162  profileButton.setMinimumSize(new java.awt.Dimension(48, 48));
163  profileButton.setPreferredSize(new java.awt.Dimension(48, 48));
164 
165  profileButton.setName(profileContextName);
166  profileButton.setActionCommand(profileContextName);
167 
168  profileButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/timeline/images/magnifier-zoom-in-green.png")));
169  profileButton.setSelectedIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/corecomponents/checkbox24.png")));
170  profileButton.setFocusable(false);
171  profileButton.setFocusPainted(false);
172  profileButton.addActionListener(buttonGroupActionListener);
173 
174  if (profileContextName.equals(selectedProfile)) {
175  profileButton.setSelected(true);
176  }
177 
178  profileListButtonGroup.add(profileButton);
179  profileListPanel.add(profileButton);
180  layout.setConstraints(profileButton, constraints);
181  constraints.gridx++;
182  constraints.weightx = 1;
183 
184  //Using a JTextArea as though it is a label in order to get multi-line support
185  String displayText = profileDisplayName;
186  if (!profileDesc.isEmpty()) {
187  displayText += " - " + profileDesc;
188  }
189  JTextArea myLabel = new JTextArea(displayText);
190  Color gray = new Color(240, 240, 240); //matches background of panel
191  myLabel.setBackground(gray);
192  myLabel.setEditable(false);
193  myLabel.setWrapStyleWord(true);
194  myLabel.setLineWrap(true);
195 
196  //Add space between the button and text
197  Box.Filler buttonTextSpacer = new Box.Filler(spacerBlockDimension, spacerBlockDimension, spacerBlockDimension);
198  layout.setConstraints(buttonTextSpacer, constraints);
199  profileListPanel.add(buttonTextSpacer);
200  constraints.gridx++;
201 
202  //Add the text area serving as a label to the right of the button
203  profileListPanel.add(myLabel);
204  layout.setConstraints(myLabel, constraints);
205 
206  }
207 
213  private List<IngestProfile> getProfiles() {
214  if (profiles.isEmpty()) {
215  fetchProfileList();
216  }
217  return profiles;
218  }
219 
223  private void clearListOfCheckBoxes() {
224  profileListButtonGroup = new javax.swing.ButtonGroup();
225  profileListPanel.removeAll();
226  }
227 
231  private void fetchProfileList() {
232  profiles = IngestProfiles.getIngestProfiles();
233  }
234 
240  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
241  private void initComponents() {
242 
243  profileListButtonGroup = new javax.swing.ButtonGroup();
244  ingestSettingsButton = new javax.swing.JButton();
245  profileListScrollPane = new javax.swing.JScrollPane();
246  profileListPanel = new javax.swing.JPanel();
247  profileListLabel = new javax.swing.JLabel();
248 
249  setMaximumSize(new java.awt.Dimension(5750, 3000));
250  setPreferredSize(new java.awt.Dimension(625, 450));
251 
252  org.openide.awt.Mnemonics.setLocalizedText(ingestSettingsButton, org.openide.util.NbBundle.getMessage(IngestProfileSelectionPanel.class, "IngestProfileSelectionPanel.ingestSettingsButton.text")); // NOI18N
253  ingestSettingsButton.addActionListener(new java.awt.event.ActionListener() {
254  public void actionPerformed(java.awt.event.ActionEvent evt) {
255  ingestSettingsButtonActionPerformed(evt);
256  }
257  });
258 
259  profileListScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
260 
261  profileListPanel.setAutoscrolls(true);
262  profileListPanel.setLayout(new java.awt.GridBagLayout());
263  profileListScrollPane.setViewportView(profileListPanel);
264 
265  org.openide.awt.Mnemonics.setLocalizedText(profileListLabel, org.openide.util.NbBundle.getMessage(IngestProfileSelectionPanel.class, "IngestProfileSelectionPanel.profileListLabel.text")); // NOI18N
266 
267  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
268  this.setLayout(layout);
269  layout.setHorizontalGroup(
270  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
271  .addGroup(layout.createSequentialGroup()
272  .addContainerGap()
273  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
274  .addComponent(profileListScrollPane)
275  .addGroup(layout.createSequentialGroup()
276  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
277  .addComponent(ingestSettingsButton, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
278  .addComponent(profileListLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
279  .addGap(0, 523, Short.MAX_VALUE)))
280  .addContainerGap())
281  );
282  layout.setVerticalGroup(
283  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
284  .addGroup(layout.createSequentialGroup()
285  .addContainerGap()
286  .addComponent(profileListLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
287  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
288  .addComponent(profileListScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
289  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
290  .addComponent(ingestSettingsButton)
291  .addGap(18, 18, 18))
292  );
293  }// </editor-fold>//GEN-END:initComponents
294 
301  private void ingestSettingsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ingestSettingsButtonActionPerformed
302  final AdvancedConfigurationDialog dialog = new AdvancedConfigurationDialog(true);
303  IngestOptionsPanel ingestOptions = new IngestOptionsPanel();
304  ingestOptions.load();
305  dialog.addApplyButtonListener(
306  (ActionEvent e) -> {
307  ingestOptions.store();
308  clearListOfCheckBoxes();
309  fetchProfileList();
310  profileListPanel.revalidate();
311  profileListPanel.repaint();
312  populateProfilesList();
313  dialog.close();
314  }
315  );
316  dialog.display(ingestOptions);
317  }//GEN-LAST:event_ingestSettingsButtonActionPerformed
318 
319  // Variables declaration - do not modify//GEN-BEGIN:variables
320  private javax.swing.JButton ingestSettingsButton;
321  private javax.swing.ButtonGroup profileListButtonGroup;
322  private javax.swing.JLabel profileListLabel;
323  private javax.swing.JPanel profileListPanel;
324  private javax.swing.JScrollPane profileListScrollPane;
325  // End of variables declaration//GEN-END:variables
326 
327  }

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.