Autopsy  4.16.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ReportWizardFileOptionsVisualPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-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.report.infrastructure;
20 
21 import java.awt.Component;
22 import java.awt.event.MouseAdapter;
23 import java.awt.event.MouseEvent;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.EnumMap;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.Map.Entry;
30 import javax.swing.JCheckBox;
31 import javax.swing.JLabel;
32 import javax.swing.JList;
33 import javax.swing.ListCellRenderer;
34 import javax.swing.ListModel;
35 import javax.swing.event.ListDataListener;
36 import org.openide.util.NbBundle;
37 
41 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
42 class ReportWizardFileOptionsVisualPanel extends javax.swing.JPanel {
43 
44  private List<FileReportDataTypes> options = new ArrayList<>();
45  private final Map<FileReportDataTypes, Boolean> optionStates = new EnumMap<>(FileReportDataTypes.class);
46  private ListModel<FileReportDataTypes> model;
47  private final ReportWizardFileOptionsPanel wizPanel;
48 
49  public ReportWizardFileOptionsVisualPanel(ReportWizardFileOptionsPanel wizPanel, FileReportSettings settings) {
50  this.wizPanel = wizPanel;
51  initComponents();
52  initOptionsList(settings);
53  }
54 
55  @Override
56  public String getName() {
57  return NbBundle.getMessage(this.getClass(), "ReportWizardFileOptionsVisualPanel.getName.text");
58  }
59 
63  private void initOptionsList(FileReportSettings settings) {
64  if (settings != null && settings.getFileProperties() != null && !settings.getFileProperties().isEmpty()) {
65  // load the configuration
66  for (Entry<FileReportDataTypes, Boolean> entry : settings.getFileProperties().entrySet()) {
67  optionStates.put(entry.getKey(), entry.getValue());
68  options.add(entry.getKey());
69  }
70  } else {
71  // load defaults
72  options = Arrays.asList(FileReportDataTypes.values());
73  for (FileReportDataTypes entry : options) {
74  optionStates.put(entry, Boolean.TRUE);
75  }
76  }
77 
78  model = new OptionsListModel();
79  optionsList.setModel(model);
80  optionsList.setCellRenderer(new OptionsListRenderer());
81  optionsList.setVisibleRowCount(-1);
82 
83  selectAllButton.setEnabled(notAllSelected());
84  deselectAllButton.setEnabled(anySelected());
85 
86  wizPanel.setFinish(anySelected());
87 
88  // Add the ability to enable and disable Tag checkboxes to the list
89  optionsList.addMouseListener(new MouseAdapter() {
90  @Override
91  public void mousePressed(MouseEvent evt) {
92 
93  int index = optionsList.locationToIndex(evt.getPoint());
94  FileReportDataTypes value = model.getElementAt(index);
95  optionStates.put(value, !optionStates.get(value));
96  optionsList.repaint();
97  boolean anySelected = anySelected();
98  deselectAllButton.setEnabled(anySelected);
99  wizPanel.setFinish(anySelected);
100  selectAllButton.setEnabled(notAllSelected());
101  }
102  });
103  }
104 
110  private boolean anySelected() {
111  for (Boolean b : optionStates.values()) {
112  if (b) {
113  return true;
114  }
115  }
116  return false;
117  }
118 
124  private boolean notAllSelected() {
125  for (Boolean b : optionStates.values()) {
126  if (!b) {
127  return true;
128  }
129  }
130  return false;
131  }
132 
138  Map<FileReportDataTypes, Boolean> getFileReportOptions() {
139  return optionStates;
140  }
141 
147  @SuppressWarnings("unchecked")
148  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
149  private void initComponents() {
150 
151  jScrollPane1 = new javax.swing.JScrollPane();
152  optionsList = new javax.swing.JList<>();
153  selectAllButton = new javax.swing.JButton();
154  deselectAllButton = new javax.swing.JButton();
155  jLabel1 = new javax.swing.JLabel();
156 
157  optionsList.setModel(new javax.swing.AbstractListModel<FileReportDataTypes>() {
158  FileReportDataTypes[] types = { };
159  public int getSize() { return types.length; }
160  public FileReportDataTypes getElementAt(int i) { return types[i]; }
161  });
162  jScrollPane1.setViewportView(optionsList);
163 
164  org.openide.awt.Mnemonics.setLocalizedText(selectAllButton, org.openide.util.NbBundle.getMessage(ReportWizardFileOptionsVisualPanel.class, "ReportWizardFileOptionsVisualPanel.selectAllButton.text")); // NOI18N
165  selectAllButton.addActionListener(new java.awt.event.ActionListener() {
166  public void actionPerformed(java.awt.event.ActionEvent evt) {
167  selectAllButtonActionPerformed(evt);
168  }
169  });
170 
171  org.openide.awt.Mnemonics.setLocalizedText(deselectAllButton, org.openide.util.NbBundle.getMessage(ReportWizardFileOptionsVisualPanel.class, "ReportWizardFileOptionsVisualPanel.deselectAllButton.text")); // NOI18N
172  deselectAllButton.addActionListener(new java.awt.event.ActionListener() {
173  public void actionPerformed(java.awt.event.ActionEvent evt) {
174  deselectAllButtonActionPerformed(evt);
175  }
176  });
177 
178  org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(ReportWizardFileOptionsVisualPanel.class, "ReportWizardFileOptionsVisualPanel.jLabel1.text")); // NOI18N
179 
180  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
181  this.setLayout(layout);
182  layout.setHorizontalGroup(
183  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
184  .addGroup(layout.createSequentialGroup()
185  .addContainerGap()
186  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
187  .addComponent(jScrollPane1)
188  .addGroup(layout.createSequentialGroup()
189  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
190  .addComponent(jLabel1)
191  .addGroup(layout.createSequentialGroup()
192  .addComponent(selectAllButton)
193  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
194  .addComponent(deselectAllButton)))
195  .addGap(0, 210, Short.MAX_VALUE)))
196  .addContainerGap())
197  );
198  layout.setVerticalGroup(
199  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
200  .addGroup(layout.createSequentialGroup()
201  .addGap(10, 10, 10)
202  .addComponent(jLabel1)
203  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
204  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
205  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
206  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
207  .addComponent(deselectAllButton)
208  .addComponent(selectAllButton))
209  .addContainerGap())
210  );
211  }// </editor-fold>//GEN-END:initComponents
212 
213  private void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectAllButtonActionPerformed
214  for (FileReportDataTypes option : options) {
215  optionStates.put(option, Boolean.TRUE);
216  }
217  optionsList.repaint();
218  selectAllButton.setEnabled(false);
219  deselectAllButton.setEnabled(true);
220  wizPanel.setFinish(true);
221  }//GEN-LAST:event_selectAllButtonActionPerformed
222 
223  private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deselectAllButtonActionPerformed
224  for (FileReportDataTypes option : options) {
225  optionStates.put(option, Boolean.FALSE);
226  }
227  optionsList.repaint();
228  selectAllButton.setEnabled(true);
229  deselectAllButton.setEnabled(false);
230  wizPanel.setFinish(false);
231  }//GEN-LAST:event_deselectAllButtonActionPerformed
232 
233  // Variables declaration - do not modify//GEN-BEGIN:variables
234  private javax.swing.JButton deselectAllButton;
235  private javax.swing.JLabel jLabel1;
236  private javax.swing.JScrollPane jScrollPane1;
237  private javax.swing.JList<FileReportDataTypes> optionsList;
238  private javax.swing.JButton selectAllButton;
239  // End of variables declaration//GEN-END:variables
240 
241  private class OptionsListModel implements ListModel<FileReportDataTypes> {
242 
243  @Override
244  public int getSize() {
245  return options.size();
246  }
247 
248  @Override
249  public FileReportDataTypes getElementAt(int index) {
250  return options.get(index);
251  }
252 
253  @Override
254  public void addListDataListener(ListDataListener l) {
255  }
256 
257  @Override
258  public void removeListDataListener(ListDataListener l) {
259  }
260  }
261 
265  private class OptionsListRenderer extends JCheckBox implements ListCellRenderer<FileReportDataTypes> {
266 
267  @Override
268  public Component getListCellRendererComponent(JList<? extends FileReportDataTypes> list, FileReportDataTypes value, int index, boolean isSelected, boolean cellHasFocus) {
269  if (value != null) {
270  FileReportDataTypes col = value;
271  setEnabled(list.isEnabled());
272  setSelected(optionStates.get(col));
273  setFont(list.getFont());
274  setBackground(list.getBackground());
275  setForeground(list.getForeground());
276  setText(col.getName());
277  return this;
278  }
279  return new JLabel();
280  }
281 
282  }
283 
284 }
Component getListCellRendererComponent(JList<?extends FileReportDataTypes > list, FileReportDataTypes value, int index, boolean isSelected, boolean cellHasFocus)

Copyright © 2012-2020 Basis Technology. Generated on: Tue Sep 22 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.