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 {
43 private List<FileReportDataTypes> options;
44 private Map<FileReportDataTypes, Boolean> optionStates =
new EnumMap<>(FileReportDataTypes.class);
45 private ListModel<FileReportDataTypes> model;
46 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());
98 private boolean anySelected() {
99 for (Boolean b : optionStates.values()) {
112 private boolean notAllSelected() {
113 for (Boolean b : optionStates.values()) {
126 Map<FileReportDataTypes, Boolean> getFileReportOptions() {
135 @SuppressWarnings(
"unchecked")
137 private
void initComponents() {
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();
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]; }
150 jScrollPane1.setViewportView(optionsList);
152 org.openide.awt.Mnemonics.setLocalizedText(selectAllButton,
org.openide.util.NbBundle.getMessage(ReportWizardFileOptionsVisualPanel.class,
"ReportWizardFileOptionsVisualPanel.selectAllButton.text"));
153 selectAllButton.addActionListener(
new java.awt.event.ActionListener() {
154 public void actionPerformed(java.awt.event.ActionEvent evt) {
155 selectAllButtonActionPerformed(evt);
159 org.openide.awt.Mnemonics.setLocalizedText(deselectAllButton,
org.openide.util.NbBundle.getMessage(ReportWizardFileOptionsVisualPanel.class,
"ReportWizardFileOptionsVisualPanel.deselectAllButton.text"));
160 deselectAllButton.addActionListener(
new java.awt.event.ActionListener() {
161 public void actionPerformed(java.awt.event.ActionEvent evt) {
162 deselectAllButtonActionPerformed(evt);
166 org.openide.awt.Mnemonics.setLocalizedText(jLabel1,
org.openide.util.NbBundle.getMessage(ReportWizardFileOptionsVisualPanel.class,
"ReportWizardFileOptionsVisualPanel.jLabel1.text"));
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()
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)))
186 layout.setVerticalGroup(
187 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
188 .addGroup(layout.createSequentialGroup()
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))
201 private void selectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
202 for (FileReportDataTypes option : options) {
203 optionStates.put(option, Boolean.TRUE);
205 optionsList.repaint();
206 selectAllButton.setEnabled(
false);
207 deselectAllButton.setEnabled(
true);
208 wizPanel.setFinish(
true);
211 private void deselectAllButtonActionPerformed(java.awt.event.ActionEvent evt) {
212 for (FileReportDataTypes option : options) {
213 optionStates.put(option, Boolean.FALSE);
215 optionsList.repaint();
216 selectAllButton.setEnabled(
true);
217 deselectAllButton.setEnabled(
false);
218 wizPanel.setFinish(
false);
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;
233 return options.size();
238 return options.get(index);
256 public Component
getListCellRendererComponent(JList<? extends FileReportDataTypes> list, FileReportDataTypes value,
int index,
boolean isSelected,
boolean cellHasFocus) {
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());
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)