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

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