19 package org.sleuthkit.autopsy.report;
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;
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;
39 @SuppressWarnings(
"PMD.SingularField")
40 class ReportWizardFileOptionsVisualPanel extends javax.swing.JPanel {
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;
47 public ReportWizardFileOptionsVisualPanel(ReportWizardFileOptionsPanel wizPanel) {
48 this.wizPanel = wizPanel;
54 public String getName() {
55 return NbBundle.getMessage(this.getClass(),
"ReportWizardFileOptionsVisualPanel.getName.text");
61 private void initOptionsList() {
62 options = Arrays.asList(FileReportDataTypes.values());
63 for (FileReportDataTypes col : options) {
64 optionStates.put(col, Boolean.FALSE);
67 model =
new OptionsListModel();
68 optionsList.setModel(model);
69 optionsList.setCellRenderer(
new OptionsListRenderer());
70 optionsList.setVisibleRowCount(-1);
72 selectAllButton.setEnabled(
true);
73 deselectAllButton.setEnabled(
false);
76 optionsList.addMouseListener(
new MouseAdapter() {
78 public void mousePressed(MouseEvent evt) {
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());
97 private boolean anySelected() {
98 for (Boolean b : optionStates.values()) {
111 private boolean notAllSelected() {
112 for (Boolean b : optionStates.values()) {
125 Map<FileReportDataTypes, Boolean> getFileReportOptions() {
134 @SuppressWarnings(
"unchecked")
136 private
void initComponents() {
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();
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]; }
149 jScrollPane1.setViewportView(optionsList);
151 org.openide.awt.Mnemonics.setLocalizedText(selectAllButton,
org.openide.util.NbBundle.getMessage(ReportWizardFileOptionsVisualPanel.class,
"ReportWizardFileOptionsVisualPanel.selectAllButton.text"));
152 selectAllButton.addActionListener(
new java.awt.event.ActionListener() {
153 public void actionPerformed(java.awt.event.ActionEvent evt) {
154 selectAllButtonActionPerformed(evt);
158 org.openide.awt.Mnemonics.setLocalizedText(deselectAllButton,
org.openide.util.NbBundle.getMessage(ReportWizardFileOptionsVisualPanel.class,
"ReportWizardFileOptionsVisualPanel.deselectAllButton.text"));
159 deselectAllButton.addActionListener(
new java.awt.event.ActionListener() {
160 public void actionPerformed(java.awt.event.ActionEvent evt) {
161 deselectAllButtonActionPerformed(evt);
165 org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
org.openide.util.NbBundle.getMessage(ReportWizardFileOptionsVisualPanel.class,
"ReportWizardFileOptionsVisualPanel.jLabel1.text"));
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()
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)))
185 layout.setVerticalGroup(
186 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
187 .addGroup(layout.createSequentialGroup()
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))
200 private void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
201 for (FileReportDataTypes option : options) {
202 optionStates.put(option, Boolean.TRUE);
204 optionsList.repaint();
205 selectAllButton.setEnabled(
false);
206 deselectAllButton.setEnabled(
true);
207 wizPanel.setFinish(
true);
210 private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
211 for (FileReportDataTypes option : options) {
212 optionStates.put(option, Boolean.FALSE);
214 optionsList.repaint();
215 selectAllButton.setEnabled(
true);
216 deselectAllButton.setEnabled(
false);
217 wizPanel.setFinish(
false);
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;
232 return options.size();
237 return options.get(index);
255 public Component
getListCellRendererComponent(JList<? extends FileReportDataTypes> list, FileReportDataTypes value,
int index,
boolean isSelected,
boolean cellHasFocus) {
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());
FileReportDataTypes getElementAt(int index)
void addListDataListener(ListDataListener l)
void removeListDataListener(ListDataListener l)
Component getListCellRendererComponent(JList<?extends FileReportDataTypes > list, FileReportDataTypes value, int index, boolean isSelected, boolean cellHasFocus)