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;
41 class ReportWizardFileOptionsVisualPanel
extends javax.swing.JPanel {
42 private List<FileReportDataTypes> options;
43 private Map<FileReportDataTypes, Boolean> optionStates =
new EnumMap<>(FileReportDataTypes.class);
44 private ListModel<FileReportDataTypes> model;
45 private ReportWizardFileOptionsPanel wizPanel;
48 public ReportWizardFileOptionsVisualPanel(ReportWizardFileOptionsPanel wizPanel) {
49 this.wizPanel = wizPanel;
55 public String getName() {
56 return NbBundle.getMessage(this.getClass(),
"ReportWizardFileOptionsVisualPanel.getName.text");
62 private void initOptionsList() {
63 options = Arrays.asList(FileReportDataTypes.values());
64 for(FileReportDataTypes col : options) {
65 optionStates.put(col, Boolean.FALSE);
68 model =
new OptionsListModel();
69 optionsList.setModel(model);
70 optionsList.setCellRenderer(
new OptionsListRenderer());
71 optionsList.setVisibleRowCount(-1);
73 selectAllButton.setEnabled(
true);
74 deselectAllButton.setEnabled(
false);
77 optionsList.addMouseListener(
new MouseAdapter() {
79 public void mousePressed(MouseEvent evt) {
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());
97 private boolean anySelected() {
98 for (Boolean b : optionStates.values()) {
110 private boolean notAllSelected() {
111 for (Boolean b : optionStates.values()) {
123 Map<FileReportDataTypes, Boolean> getFileReportOptions() {
131 @SuppressWarnings(
"unchecked")
133 private
void initComponents() {
135 jScrollPane1 =
new javax.swing.JScrollPane();
136 optionsList =
new javax.swing.JList<>();
137 selectAllButton =
new javax.swing.JButton();
138 deselectAllButton =
new javax.swing.JButton();
139 jLabel1 =
new javax.swing.JLabel();
141 optionsList.setModel(
new javax.swing.AbstractListModel<FileReportDataTypes>() {
142 FileReportDataTypes[] types = { };
143 public int getSize() {
return types.length; }
144 public FileReportDataTypes getElementAt(
int i) {
return types[i]; }
146 jScrollPane1.setViewportView(optionsList);
148 org.openide.awt.Mnemonics.setLocalizedText(selectAllButton,
org.openide.util.NbBundle.getMessage(ReportWizardFileOptionsVisualPanel.class,
"ReportWizardFileOptionsVisualPanel.selectAllButton.text"));
149 selectAllButton.addActionListener(
new java.awt.event.ActionListener() {
150 public void actionPerformed(java.awt.event.ActionEvent evt) {
151 selectAllButtonActionPerformed(evt);
155 org.openide.awt.Mnemonics.setLocalizedText(deselectAllButton,
org.openide.util.NbBundle.getMessage(ReportWizardFileOptionsVisualPanel.class,
"ReportWizardFileOptionsVisualPanel.deselectAllButton.text"));
156 deselectAllButton.addActionListener(
new java.awt.event.ActionListener() {
157 public void actionPerformed(java.awt.event.ActionEvent evt) {
158 deselectAllButtonActionPerformed(evt);
162 org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
org.openide.util.NbBundle.getMessage(ReportWizardFileOptionsVisualPanel.class,
"ReportWizardFileOptionsVisualPanel.jLabel1.text"));
164 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
165 this.setLayout(layout);
166 layout.setHorizontalGroup(
167 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
168 .addGroup(layout.createSequentialGroup()
170 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
171 .addComponent(jScrollPane1)
172 .addGroup(layout.createSequentialGroup()
173 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
174 .addComponent(jLabel1)
175 .addGroup(layout.createSequentialGroup()
176 .addComponent(selectAllButton, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
177 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
178 .addComponent(deselectAllButton)))
179 .addGap(0, 210, Short.MAX_VALUE)))
182 layout.setVerticalGroup(
183 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
184 .addGroup(layout.createSequentialGroup()
186 .addComponent(jLabel1)
187 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
188 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
189 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
190 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
191 .addComponent(deselectAllButton)
192 .addComponent(selectAllButton))
197 private void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
198 for (FileReportDataTypes option : options) {
199 optionStates.put(option, Boolean.TRUE);
201 optionsList.repaint();
202 selectAllButton.setEnabled(
false);
203 deselectAllButton.setEnabled(
true);
204 wizPanel.setFinish(
true);
207 private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
208 for (FileReportDataTypes option : options) {
209 optionStates.put(option, Boolean.FALSE);
211 optionsList.repaint();
212 selectAllButton.setEnabled(
true);
213 deselectAllButton.setEnabled(
false);
214 wizPanel.setFinish(
false);
218 private javax.swing.JButton deselectAllButton;
219 private javax.swing.JLabel jLabel1;
220 private javax.swing.JScrollPane jScrollPane1;
221 private javax.swing.JList<FileReportDataTypes> optionsList;
222 private javax.swing.JButton selectAllButton;
229 return options.size();
234 return options.get(index);
252 public Component
getListCellRendererComponent(JList<? extends FileReportDataTypes> list, FileReportDataTypes value,
int index,
boolean isSelected,
boolean cellHasFocus) {
254 FileReportDataTypes col = value;
255 setEnabled(list.isEnabled());
256 setSelected(optionStates.get(col));
257 setFont(list.getFont());
258 setBackground(list.getBackground());
259 setForeground(list.getForeground());
260 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)