19 package org.sleuthkit.autopsy.report.infrastructure;
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;
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;
41 @SuppressWarnings(
"PMD.SingularField")
42 class ReportWizardFileOptionsVisualPanel extends javax.swing.JPanel {
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;
49 public ReportWizardFileOptionsVisualPanel(ReportWizardFileOptionsPanel wizPanel, FileReportSettings settings) {
50 this.wizPanel = wizPanel;
52 initOptionsList(settings);
56 public String getName() {
57 return NbBundle.getMessage(this.getClass(),
"ReportWizardFileOptionsVisualPanel.getName.text");
63 private void initOptionsList(FileReportSettings settings) {
64 if (settings != null && settings.getFileProperties() != null && !settings.getFileProperties().isEmpty()) {
66 for (Entry<FileReportDataTypes, Boolean> entry : settings.getFileProperties().entrySet()) {
67 optionStates.put(entry.getKey(), entry.getValue());
68 options.add(entry.getKey());
72 options = Arrays.asList(FileReportDataTypes.values());
73 for (FileReportDataTypes entry : options) {
74 optionStates.put(entry, Boolean.TRUE);
78 model =
new OptionsListModel();
79 optionsList.setModel(model);
80 optionsList.setCellRenderer(
new OptionsListRenderer());
81 optionsList.setVisibleRowCount(-1);
83 selectAllButton.setEnabled(notAllSelected());
84 deselectAllButton.setEnabled(anySelected());
86 wizPanel.setFinish(anySelected());
89 optionsList.addMouseListener(
new MouseAdapter() {
91 public void mousePressed(MouseEvent evt) {
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());
110 private boolean anySelected() {
111 for (Boolean b : optionStates.values()) {
124 private boolean notAllSelected() {
125 for (Boolean b : optionStates.values()) {
138 Map<FileReportDataTypes, Boolean> getFileReportOptions() {
147 @SuppressWarnings(
"unchecked")
149 private
void initComponents() {
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();
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]; }
162 jScrollPane1.setViewportView(optionsList);
164 org.openide.awt.Mnemonics.setLocalizedText(selectAllButton,
org.openide.util.NbBundle.getMessage(ReportWizardFileOptionsVisualPanel.class,
"ReportWizardFileOptionsVisualPanel.selectAllButton.text"));
165 selectAllButton.addActionListener(
new java.awt.event.ActionListener() {
166 public void actionPerformed(java.awt.event.ActionEvent evt) {
167 selectAllButtonActionPerformed(evt);
171 org.openide.awt.Mnemonics.setLocalizedText(deselectAllButton,
org.openide.util.NbBundle.getMessage(ReportWizardFileOptionsVisualPanel.class,
"ReportWizardFileOptionsVisualPanel.deselectAllButton.text"));
172 deselectAllButton.addActionListener(
new java.awt.event.ActionListener() {
173 public void actionPerformed(java.awt.event.ActionEvent evt) {
174 deselectAllButtonActionPerformed(evt);
178 org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
org.openide.util.NbBundle.getMessage(ReportWizardFileOptionsVisualPanel.class,
"ReportWizardFileOptionsVisualPanel.jLabel1.text"));
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()
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)))
198 layout.setVerticalGroup(
199 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
200 .addGroup(layout.createSequentialGroup()
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))
213 private void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
214 for (FileReportDataTypes option : options) {
215 optionStates.put(option, Boolean.TRUE);
217 optionsList.repaint();
218 selectAllButton.setEnabled(
false);
219 deselectAllButton.setEnabled(
true);
220 wizPanel.setFinish(
true);
223 private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
224 for (FileReportDataTypes option : options) {
225 optionStates.put(option, Boolean.FALSE);
227 optionsList.repaint();
228 selectAllButton.setEnabled(
true);
229 deselectAllButton.setEnabled(
false);
230 wizPanel.setFinish(
false);
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;
245 return options.size();
250 return options.get(index);
271 setEnabled(list.isEnabled());
272 setSelected(optionStates.get(col));
273 setFont(list.getFont());
274 setBackground(list.getBackground());
275 setForeground(list.getForeground());
Component getListCellRendererComponent(JList<?extends FileReportDataTypes > list, FileReportDataTypes value, int index, boolean isSelected, boolean cellHasFocus)
void addListDataListener(ListDataListener l)
void removeListDataListener(ListDataListener l)
FileReportDataTypes getElementAt(int index)