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

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.