Autopsy  4.11.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ConfigVisualPanel2.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2019 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.logicalimager.configuration;
20 
21 import java.io.IOException;
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.Comparator;
25 import java.util.List;
26 import javax.swing.JButton;
27 import javax.swing.JOptionPane;
28 import javax.swing.JPanel;
29 import javax.swing.JTable;
30 import javax.swing.table.AbstractTableModel;
31 import org.apache.commons.lang3.tuple.ImmutablePair;
32 import org.openide.util.NbBundle;
33 
37 @NbBundle.Messages({
38  "ConfigVisualPanel2.ok=OK",
39  "ConfigVisualPanel2.cancel=Cancel"
40 })
41 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
42 final class ConfigVisualPanel2 extends JPanel {
43 
44  private static final List<String> EMPTY_LIST = new ArrayList<>();
45  private String configFilename;
46  private LogicalImagerConfig config = null;
47  private final JButton okButton = new JButton(Bundle.ConfigVisualPanel2_ok());
48  private final JButton cancelButton = new JButton(Bundle.ConfigVisualPanel2_cancel());
49  private boolean flagEncryptionPrograms = false;
50 
54  ConfigVisualPanel2() {
55  initComponents();
56  if (config != null) {
57  updatePanel(configFilename, config);
58  }
59  }
60 
61  @NbBundle.Messages({
62  "ConfigVisualPanel2.editConfiguration=Edit configuration"
63  })
64  @Override
65  public String getName() {
66  return Bundle.ConfigVisualPanel2_editConfiguration();
67  }
68 
74  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
75  private void initComponents() {
76 
77  modifiedDateLabel = new javax.swing.JLabel();
78  daysIncludedTextField = new javax.swing.JTextField();
79  daysIncludedLabel = new javax.swing.JLabel();
80  fullPathsLabel = new javax.swing.JLabel();
81  flagEncryptionProgramsCheckBox = new javax.swing.JCheckBox();
82  ruleNameLabel = new javax.swing.JLabel();
83  ruleNameEditTextField = new javax.swing.JTextField();
84  newRuleButton = new javax.swing.JButton();
85  descriptionLabel = new javax.swing.JLabel();
86  editRuleButton = new javax.swing.JButton();
87  descriptionEditTextField = new javax.swing.JTextField();
88  deleteRuleButton = new javax.swing.JButton();
89  jScrollPane5 = new javax.swing.JScrollPane();
90  fullPathsTable = new javax.swing.JTable();
91  jScrollPane6 = new javax.swing.JScrollPane();
92  filenamesTable = new javax.swing.JTable();
93  shouldSaveCheckBox = new javax.swing.JCheckBox();
94  shouldAlertCheckBox = new javax.swing.JCheckBox();
95  jScrollPane7 = new javax.swing.JScrollPane();
96  folderNamesTable = new javax.swing.JTable();
97  extensionsLabel = new javax.swing.JLabel();
98  extensionsTextField = new javax.swing.JTextField();
99  filenamesLabel = new javax.swing.JLabel();
100  configFileTextField = new javax.swing.JTextField();
101  ruleSetFileLabel = new javax.swing.JLabel();
102  finalizeImageWriter = new javax.swing.JCheckBox();
103  jScrollPane1 = new javax.swing.JScrollPane();
104  rulesTable = new javax.swing.JTable();
105  folderNamesLabel = new javax.swing.JLabel();
106  fileSizeLabel = new javax.swing.JLabel();
107  jSeparator1 = new javax.swing.JSeparator();
108  minSizeLabel = new javax.swing.JLabel();
109  minSizeTextField = new javax.swing.JFormattedTextField();
110  maxSizeLabel = new javax.swing.JLabel();
111  maxSizeTextField = new javax.swing.JFormattedTextField();
112 
113  org.openide.awt.Mnemonics.setLocalizedText(modifiedDateLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.modifiedDateLabel.text")); // NOI18N
114 
115  daysIncludedTextField.setEditable(false);
116  daysIncludedTextField.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
117  daysIncludedTextField.setText(org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.daysIncludedTextField.text")); // NOI18N
118  daysIncludedTextField.setEnabled(false);
119  daysIncludedTextField.setMinimumSize(new java.awt.Dimension(60, 20));
120  daysIncludedTextField.setPreferredSize(new java.awt.Dimension(60, 20));
121 
122  org.openide.awt.Mnemonics.setLocalizedText(daysIncludedLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.daysIncludedLabel.text")); // NOI18N
123  daysIncludedLabel.setEnabled(false);
124 
125  org.openide.awt.Mnemonics.setLocalizedText(fullPathsLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.fullPathsLabel.text")); // NOI18N
126 
127  org.openide.awt.Mnemonics.setLocalizedText(flagEncryptionProgramsCheckBox, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.flagEncryptionProgramsCheckBox.text")); // NOI18N
128  flagEncryptionProgramsCheckBox.addActionListener(new java.awt.event.ActionListener() {
129  public void actionPerformed(java.awt.event.ActionEvent evt) {
130  flagEncryptionProgramsCheckBoxActionPerformed(evt);
131  }
132  });
133 
134  org.openide.awt.Mnemonics.setLocalizedText(ruleNameLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.ruleNameLabel.text")); // NOI18N
135 
136  ruleNameEditTextField.setText(org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.ruleNameEditTextField.text")); // NOI18N
137  ruleNameEditTextField.setEnabled(false);
138 
139  newRuleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/add16.png"))); // NOI18N
140  org.openide.awt.Mnemonics.setLocalizedText(newRuleButton, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.newRuleButton.text")); // NOI18N
141  newRuleButton.addActionListener(new java.awt.event.ActionListener() {
142  public void actionPerformed(java.awt.event.ActionEvent evt) {
143  newRuleButtonActionPerformed(evt);
144  }
145  });
146 
147  org.openide.awt.Mnemonics.setLocalizedText(descriptionLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.descriptionLabel.text")); // NOI18N
148 
149  editRuleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/edit16.png"))); // NOI18N
150  org.openide.awt.Mnemonics.setLocalizedText(editRuleButton, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.editRuleButton.text")); // NOI18N
151  editRuleButton.addActionListener(new java.awt.event.ActionListener() {
152  public void actionPerformed(java.awt.event.ActionEvent evt) {
153  editRuleButtonActionPerformed(evt);
154  }
155  });
156 
157  descriptionEditTextField.setText(org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.descriptionEditTextField.text")); // NOI18N
158  descriptionEditTextField.setEnabled(false);
159 
160  deleteRuleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/delete16.png"))); // NOI18N
161  org.openide.awt.Mnemonics.setLocalizedText(deleteRuleButton, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.deleteRuleButton.text")); // NOI18N
162  deleteRuleButton.addActionListener(new java.awt.event.ActionListener() {
163  public void actionPerformed(java.awt.event.ActionEvent evt) {
164  deleteRuleButtonActionPerformed(evt);
165  }
166  });
167 
168  fullPathsTable.setColumnSelectionAllowed(true);
169  fullPathsTable.setEnabled(false);
170  fullPathsTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
171  fullPathsTable.setShowHorizontalLines(false);
172  fullPathsTable.setShowVerticalLines(false);
173  fullPathsTable.getTableHeader().setReorderingAllowed(false);
174  jScrollPane5.setViewportView(fullPathsTable);
175  fullPathsTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);
176  if (fullPathsTable.getColumnModel().getColumnCount() > 0) {
177  fullPathsTable.getColumnModel().getColumn(0).setHeaderValue(org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.fullPathsTable.columnModel.title0")); // NOI18N
178  }
179 
180  filenamesTable.setEnabled(false);
181  filenamesTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
182  filenamesTable.setShowHorizontalLines(false);
183  filenamesTable.setShowVerticalLines(false);
184  filenamesTable.getTableHeader().setReorderingAllowed(false);
185  jScrollPane6.setViewportView(filenamesTable);
186  if (filenamesTable.getColumnModel().getColumnCount() > 0) {
187  filenamesTable.getColumnModel().getColumn(0).setHeaderValue(org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.filenamesTable.columnModel.title0")); // NOI18N
188  }
189 
190  shouldSaveCheckBox.setSelected(true);
191  org.openide.awt.Mnemonics.setLocalizedText(shouldSaveCheckBox, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.shouldSaveCheckBox.text")); // NOI18N
192  shouldSaveCheckBox.setToolTipText(org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.shouldSaveCheckBox.toolTipText")); // NOI18N
193  shouldSaveCheckBox.setEnabled(false);
194 
195  shouldAlertCheckBox.setSelected(true);
196  org.openide.awt.Mnemonics.setLocalizedText(shouldAlertCheckBox, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.shouldAlertCheckBox.text")); // NOI18N
197  shouldAlertCheckBox.setEnabled(false);
198 
199  folderNamesTable.setEnabled(false);
200  folderNamesTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
201  folderNamesTable.setShowHorizontalLines(false);
202  folderNamesTable.setShowVerticalLines(false);
203  folderNamesTable.getTableHeader().setReorderingAllowed(false);
204  jScrollPane7.setViewportView(folderNamesTable);
205  if (folderNamesTable.getColumnModel().getColumnCount() > 0) {
206  folderNamesTable.getColumnModel().getColumn(0).setHeaderValue(org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.folderNamesTable.columnModel.title0")); // NOI18N
207  }
208 
209  org.openide.awt.Mnemonics.setLocalizedText(extensionsLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.extensionsLabel.text")); // NOI18N
210 
211  extensionsTextField.setText(org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.extensionsTextField.text")); // NOI18N
212  extensionsTextField.setEnabled(false);
213 
214  org.openide.awt.Mnemonics.setLocalizedText(filenamesLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.filenamesLabel.text")); // NOI18N
215 
216  configFileTextField.setText(org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.configFileTextField.text")); // NOI18N
217  configFileTextField.setToolTipText(org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.configFileTextField.toolTipText")); // NOI18N
218  configFileTextField.setEnabled(false);
219 
220  org.openide.awt.Mnemonics.setLocalizedText(ruleSetFileLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.ruleSetFileLabel.text")); // NOI18N
221 
222  org.openide.awt.Mnemonics.setLocalizedText(finalizeImageWriter, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.finalizeImageWriter.text")); // NOI18N
223  finalizeImageWriter.addActionListener(new java.awt.event.ActionListener() {
224  public void actionPerformed(java.awt.event.ActionEvent evt) {
225  finalizeImageWriterActionPerformed(evt);
226  }
227  });
228 
229  rulesTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
230  rulesTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
231  rulesTable.setShowHorizontalLines(false);
232  rulesTable.setShowVerticalLines(false);
233  rulesTable.getTableHeader().setReorderingAllowed(false);
234  rulesTable.addMouseListener(new java.awt.event.MouseAdapter() {
235  public void mouseReleased(java.awt.event.MouseEvent evt) {
236  rulesTableMouseReleased(evt);
237  }
238  });
239  rulesTable.addKeyListener(new java.awt.event.KeyAdapter() {
240  public void keyReleased(java.awt.event.KeyEvent evt) {
241  rulesTableKeyReleased(evt);
242  }
243  });
244  jScrollPane1.setViewportView(rulesTable);
245  if (rulesTable.getColumnModel().getColumnCount() > 0) {
246  rulesTable.getColumnModel().getColumn(0).setHeaderValue(org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.rulesTable.columnModel.title0")); // NOI18N
247  rulesTable.getColumnModel().getColumn(1).setHeaderValue(org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.rulesTable.columnModel.title1")); // NOI18N
248  }
249 
250  org.openide.awt.Mnemonics.setLocalizedText(folderNamesLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.folderNamesLabel.text")); // NOI18N
251 
252  org.openide.awt.Mnemonics.setLocalizedText(fileSizeLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.fileSizeLabel.text")); // NOI18N
253 
254  org.openide.awt.Mnemonics.setLocalizedText(minSizeLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.minSizeLabel.text")); // NOI18N
255 
256  minSizeTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,###; "))));
257  minSizeTextField.setText(org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.minSizeTextField.text")); // NOI18N
258  minSizeTextField.setEnabled(false);
259 
260  org.openide.awt.Mnemonics.setLocalizedText(maxSizeLabel, org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.maxSizeLabel.text")); // NOI18N
261 
262  maxSizeTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#,###; "))));
263  maxSizeTextField.setText(org.openide.util.NbBundle.getMessage(ConfigVisualPanel2.class, "ConfigVisualPanel2.maxSizeTextField.text")); // NOI18N
264  maxSizeTextField.setEnabled(false);
265 
266  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
267  this.setLayout(layout);
268  layout.setHorizontalGroup(
269  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
270  .addGroup(layout.createSequentialGroup()
271  .addGap(480, 480, 480)
272  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
273  .addGroup(layout.createSequentialGroup()
274  .addComponent(daysIncludedTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
275  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
276  .addComponent(daysIncludedLabel))
277  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
278  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
279  .addComponent(ruleNameEditTextField, javax.swing.GroupLayout.Alignment.LEADING)
280  .addComponent(descriptionEditTextField, javax.swing.GroupLayout.Alignment.LEADING)
281  .addComponent(extensionsTextField, javax.swing.GroupLayout.Alignment.LEADING)
282  .addComponent(jScrollPane5, javax.swing.GroupLayout.Alignment.LEADING)
283  .addComponent(jScrollPane6, javax.swing.GroupLayout.Alignment.LEADING)
284  .addComponent(jScrollPane7, javax.swing.GroupLayout.Alignment.LEADING))
285  .addContainerGap())))
286  .addGroup(layout.createSequentialGroup()
287  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
288  .addGroup(layout.createSequentialGroup()
289  .addContainerGap()
290  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
291  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 377, javax.swing.GroupLayout.PREFERRED_SIZE)
292  .addGroup(layout.createSequentialGroup()
293  .addComponent(newRuleButton)
294  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
295  .addComponent(editRuleButton)
296  .addGap(37, 37, 37)
297  .addComponent(deleteRuleButton)))
298  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
299  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
300  .addComponent(flagEncryptionProgramsCheckBox)
301  .addComponent(finalizeImageWriter)))
302  .addGroup(layout.createSequentialGroup()
303  .addGap(393, 393, 393)
304  .addComponent(shouldSaveCheckBox))
305  .addGroup(layout.createSequentialGroup()
306  .addGap(397, 397, 397)
307  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
308  .addComponent(extensionsLabel)
309  .addComponent(filenamesLabel)
310  .addComponent(descriptionLabel)
311  .addComponent(ruleNameLabel)))
312  .addGroup(layout.createSequentialGroup()
313  .addGap(397, 397, 397)
314  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
315  .addComponent(modifiedDateLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
316  .addComponent(fileSizeLabel)
317  .addComponent(fullPathsLabel)
318  .addComponent(folderNamesLabel))
319  .addGap(4, 4, 4)
320  .addComponent(minSizeLabel)
321  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
322  .addComponent(minSizeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
323  .addGap(18, 18, 18)
324  .addComponent(maxSizeLabel)
325  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
326  .addComponent(maxSizeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
327  .addGroup(layout.createSequentialGroup()
328  .addGap(393, 393, 393)
329  .addComponent(shouldAlertCheckBox)))
330  .addContainerGap())
331  .addGroup(layout.createSequentialGroup()
332  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
333  .addGroup(layout.createSequentialGroup()
334  .addGap(17, 17, 17)
335  .addComponent(ruleSetFileLabel)
336  .addGap(18, 18, 18)
337  .addComponent(configFileTextField))
338  .addGroup(layout.createSequentialGroup()
339  .addGap(397, 397, 397)
340  .addComponent(jSeparator1)))
341  .addGap(10, 10, 10))
342  );
343  layout.setVerticalGroup(
344  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
345  .addGroup(layout.createSequentialGroup()
346  .addContainerGap()
347  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
348  .addComponent(configFileTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
349  .addComponent(ruleSetFileLabel))
350  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
351  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
352  .addGroup(layout.createSequentialGroup()
353  .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 527, Short.MAX_VALUE)
354  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
355  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
356  .addComponent(newRuleButton)
357  .addComponent(editRuleButton)
358  .addComponent(deleteRuleButton)))
359  .addGroup(layout.createSequentialGroup()
360  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
361  .addGroup(layout.createSequentialGroup()
362  .addGap(30, 30, 30)
363  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
364  .addComponent(descriptionEditTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
365  .addComponent(descriptionLabel))
366  .addGap(9, 9, 9)
367  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
368  .addComponent(extensionsTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
369  .addComponent(extensionsLabel)))
370  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
371  .addComponent(ruleNameEditTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
372  .addComponent(ruleNameLabel)))
373  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
374  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
375  .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
376  .addGroup(layout.createSequentialGroup()
377  .addComponent(filenamesLabel)
378  .addGap(0, 0, Short.MAX_VALUE)))
379  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
380  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
381  .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
382  .addGroup(layout.createSequentialGroup()
383  .addComponent(folderNamesLabel)
384  .addGap(0, 0, Short.MAX_VALUE)))
385  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
386  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
387  .addGroup(layout.createSequentialGroup()
388  .addComponent(fullPathsLabel)
389  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
390  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
391  .addComponent(jScrollPane5, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
392  .addGap(11, 11, 11)))
393  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
394  .addComponent(minSizeLabel)
395  .addComponent(minSizeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
396  .addComponent(maxSizeLabel)
397  .addComponent(maxSizeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
398  .addComponent(fileSizeLabel))
399  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
400  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
401  .addComponent(modifiedDateLabel)
402  .addComponent(daysIncludedTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
403  .addComponent(daysIncludedLabel))
404  .addGap(3, 3, 3)
405  .addComponent(shouldAlertCheckBox)
406  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
407  .addComponent(shouldSaveCheckBox)
408  .addGap(18, 18, 18)
409  .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
410  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
411  .addComponent(flagEncryptionProgramsCheckBox)
412  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
413  .addComponent(finalizeImageWriter)))
414  .addContainerGap())
415  );
416  }// </editor-fold>//GEN-END:initComponents
417 
418  private void finalizeImageWriterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_finalizeImageWriterActionPerformed
419  config.setFinalizeImageWriter(finalizeImageWriter.isSelected());
420  }//GEN-LAST:event_finalizeImageWriterActionPerformed
421 
422  private void rulesTableKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_rulesTableKeyReleased
423  rulesTableSelect();
424  }//GEN-LAST:event_rulesTableKeyReleased
425 
426  @NbBundle.Messages({
427  "ConfigVisualPanel2.editRuleSet=Edit rule",
428  "ConfigVisualPanel2.editRuleError=Edit rule error"
429  })
430  private void editRuleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editRuleButtonActionPerformed
431  int row = rulesTable.getSelectedRow();
432  if (row != -1) {
433  String ruleName = (String) rulesTable.getModel().getValueAt(row, 0);
434  LogicalImagerRule rule = getFirstRuleSet().getRules().get(row);
435  EditRulePanel editPanel = new EditRulePanel(okButton, cancelButton, ruleName, rule);
436  editPanel.setEnabled(true);
437  editPanel.setVisible(true);
438 
439  while (true) {
440  int option = JOptionPane.showOptionDialog(this, editPanel.getPanel(), Bundle.ConfigVisualPanel2_editRuleSet(),
441  JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,
442  null, new Object[]{okButton, cancelButton}, okButton);
443  if (option == JOptionPane.OK_OPTION) {
444  try {
445  ImmutablePair<String, LogicalImagerRule> ruleMap = editPanel.toRule();
446  updateRow(row, ruleMap);
447  break;
448  } catch (IOException | NumberFormatException ex) {
449  JOptionPane.showMessageDialog(this,
450  ex.getMessage(),
451  Bundle.ConfigVisualPanel2_editRuleError(),
452  JOptionPane.ERROR_MESSAGE);
453  // let user fix the error
454  }
455  } else {
456  break;
457  }
458  }
459  }
460  }//GEN-LAST:event_editRuleButtonActionPerformed
461 
462  private void newRuleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newRuleButtonActionPerformed
463  NewRuleSetPanel panel;
464  panel = new NewRuleSetPanel(okButton, cancelButton);
465  panel.setEnabled(true);
466  panel.setVisible(true);
467 
468  while (true) {
469  int option = JOptionPane.showOptionDialog(this, panel, "New rule",
470  JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE,
471  null, new Object[]{okButton, cancelButton}, okButton);
472  if (option == JOptionPane.OK_OPTION) {
473  try {
474  // Save the new rule
475  ImmutablePair<String, LogicalImagerRule> ruleMap = panel.toRule();
476  appendRow(ruleMap);
477  break;
478  } catch (IOException | NumberFormatException ex) {
479  JOptionPane.showMessageDialog(this,
480  ex.getMessage(),
481  "New rule error",
482  JOptionPane.ERROR_MESSAGE);
483  // let user fix the error
484  }
485  } else {
486  break;
487  }
488  }
489  }//GEN-LAST:event_newRuleButtonActionPerformed
490 
491  @NbBundle.Messages({
492  "ConfigVisualPanel2.deleteRuleSet=Delete rule ",
493  "ConfigVisualPanel2.deleteRuleSetConfirmation=Delete rule confirmation",
494  })
495  private void deleteRuleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteRuleButtonActionPerformed
496  int index = rulesTable.getSelectedRow();
497  if (index != -1) {
498  String ruleName = (String) rulesTable.getModel().getValueAt(index, 0);
499 
500  int option = JOptionPane.showOptionDialog(this,
501  Bundle.ConfigVisualPanel2_deleteRuleSet() + ruleName,
502  Bundle.ConfigVisualPanel2_deleteRuleSetConfirmation(),
503  JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, null, null);
504  if (option == JOptionPane.NO_OPTION) {
505  return;
506  }
507 
508  getFirstRuleSet().getRules().remove(index);
509  updatePanel(configFilename, config);
510  if (rulesTable.getRowCount() > 0) {
511  rulesTable.setRowSelectionInterval(0, 0);
512  rulesTableSelect();
513  }
514  }
515  }//GEN-LAST:event_deleteRuleButtonActionPerformed
516 
517  private void flagEncryptionProgramsCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_flagEncryptionProgramsCheckBoxActionPerformed
518  flagEncryptionPrograms = flagEncryptionProgramsCheckBox.isSelected();
519  toggleEncryptionProgramsRule(flagEncryptionPrograms);
520  }//GEN-LAST:event_flagEncryptionProgramsCheckBoxActionPerformed
521 
522  private void rulesTableMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rulesTableMouseReleased
523  rulesTableSelect();
524  }//GEN-LAST:event_rulesTableMouseReleased
525 
526  private void toggleEncryptionProgramsRule(boolean flagEncryptionPrograms) {
527  if (flagEncryptionPrograms) {
528  // add the special rule
529  ImmutablePair<String, LogicalImagerRule> ruleMap = createEncryptionProgramsRule();
530  appendRow(ruleMap);
531  } else {
532  // remove it
533  int index = ((RulesTableModel) rulesTable.getModel()).findRow(EncryptionProgramsRule.getName());
534  if (index != -1) {
535  getFirstRuleSet().getRules().remove(index);
536  updatePanel(configFilename, config);
537  if (rulesTable.getRowCount() > 0) {
538  rulesTable.setRowSelectionInterval(0, 0);
539  rulesTableSelect();
540  }
541  }
542  }
543  }
544 
545  /*
546  * Create an encryption programs rule
547  */
548  private ImmutablePair<String, LogicalImagerRule> createEncryptionProgramsRule() {
549  LogicalImagerRule.Builder builder = new LogicalImagerRule.Builder();
550  builder.getName(EncryptionProgramsRule.getName())
551  .getDescription(EncryptionProgramsRule.getDescription())
552  .getShouldAlert(true)
553  .getShouldSave(true)
554  .getFilenames(EncryptionProgramsRule.getFilenames());
555  LogicalImagerRule rule = builder.build();
556  return new ImmutablePair<>(EncryptionProgramsRule.getName(), rule);
557  }
558 
559  // Variables declaration - do not modify//GEN-BEGIN:variables
560  private javax.swing.JTextField configFileTextField;
561  private javax.swing.JLabel daysIncludedLabel;
562  private javax.swing.JTextField daysIncludedTextField;
563  private javax.swing.JButton deleteRuleButton;
564  private javax.swing.JTextField descriptionEditTextField;
565  private javax.swing.JLabel descriptionLabel;
566  private javax.swing.JButton editRuleButton;
567  private javax.swing.JLabel extensionsLabel;
568  private javax.swing.JTextField extensionsTextField;
569  private javax.swing.JLabel fileSizeLabel;
570  private javax.swing.JLabel filenamesLabel;
571  private javax.swing.JTable filenamesTable;
572  private javax.swing.JCheckBox finalizeImageWriter;
573  private javax.swing.JCheckBox flagEncryptionProgramsCheckBox;
574  private javax.swing.JLabel folderNamesLabel;
575  private javax.swing.JTable folderNamesTable;
576  private javax.swing.JLabel fullPathsLabel;
577  private javax.swing.JTable fullPathsTable;
578  private javax.swing.JScrollPane jScrollPane1;
579  private javax.swing.JScrollPane jScrollPane5;
580  private javax.swing.JScrollPane jScrollPane6;
581  private javax.swing.JScrollPane jScrollPane7;
582  private javax.swing.JSeparator jSeparator1;
583  private javax.swing.JLabel maxSizeLabel;
584  private javax.swing.JFormattedTextField maxSizeTextField;
585  private javax.swing.JLabel minSizeLabel;
586  private javax.swing.JFormattedTextField minSizeTextField;
587  private javax.swing.JLabel modifiedDateLabel;
588  private javax.swing.JButton newRuleButton;
589  private javax.swing.JTextField ruleNameEditTextField;
590  private javax.swing.JLabel ruleNameLabel;
591  private javax.swing.JLabel ruleSetFileLabel;
592  private javax.swing.JTable rulesTable;
593  private javax.swing.JCheckBox shouldAlertCheckBox;
594  private javax.swing.JCheckBox shouldSaveCheckBox;
595  // End of variables declaration//GEN-END:variables
596 
597  private LogicalImagerRuleSet getFirstRuleSet() {
598  if (config.getRuleSets().isEmpty()) {
599  List<LogicalImagerRuleSet> ruleSets = new ArrayList<>();
600  ruleSets.add(new LogicalImagerRuleSet("no-set-name", new ArrayList<>())); // NON-NLS
601  config.setRuleSet(ruleSets);
602  }
603  return config.getRuleSets().get(0);
604  }
605 
606  private void updatePanel(String configFilePath, LogicalImagerConfig config, String rowSelectionkey) {
607  configFileTextField.setText(configFilePath);
608  finalizeImageWriter.setSelected(config.isFinalizeImageWriter());
609  LogicalImagerRuleSet ruleSet = getFirstRuleSet();
610  flagEncryptionProgramsCheckBox.setSelected(ruleSet.find(EncryptionProgramsRule.getName()) != null);
611  RulesTableModel rulesTableModel = new RulesTableModel();
612  int row = 0;
613  int selectThisRow = 0;
614 
615  Collections.sort(ruleSet.getRules(), new SortRuleByName());
616 
617  for (LogicalImagerRule rule : ruleSet.getRules()) {
618  rulesTableModel.setValueAt(rule.getName(), row, 0);
619  if (rowSelectionkey != null && rowSelectionkey.equals(rule.getName())) {
620  selectThisRow = row;
621  }
622  rulesTableModel.setValueAt(rule.getDescription(), row, 1);
623  rulesTableModel.setValueAt(rule, row, 2);
624  row++;
625  }
626  rulesTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
627  rulesTable.setModel(rulesTableModel);
628  // If there are any rules, select the first one
629  if (rulesTableModel.getRowCount() > 0) {
630  rulesTable.setRowSelectionInterval(selectThisRow, selectThisRow);
631  rulesTableSelect();
632  } else {
633  updateRuleSetButtons(false);
634  }
635  }
636 
637  private void updatePanel(String configFilePath, LogicalImagerConfig config) {
638  updatePanel(configFilePath, config, null);
639  }
640 
641  private void rulesTableSelect() {
642  int index = rulesTable.getSelectedRow();
643  if (index != -1) {
644  String ruleName = (String) rulesTable.getModel().getValueAt(index, 0);
645  String description = (String) rulesTable.getModel().getValueAt(index, 1);
646  updateRuleDetails(ruleName, description, config);
647  updateRuleSetButtons(ruleName.equals(EncryptionProgramsRule.getName()) ? false : true);
648  } else {
649  updateRuleSetButtons(false);
650  }
651  }
652 
653  private void updateRuleDetails(String ruleName, String description, LogicalImagerConfig config) {
654  clearRuleDetails();
655  LogicalImagerRule rule = getFirstRuleSet().find(ruleName);
656  shouldAlertCheckBox.setSelected(rule.isShouldAlert());
657  shouldSaveCheckBox.setSelected(rule.isShouldSave());
658  ruleNameEditTextField.setText(ruleName);
659  descriptionEditTextField.setText(description);
660  updateExtensions(rule.getExtensions());
661  updateList(filenamesTable, rule.getFilenames());
662  updateList(folderNamesTable, rule.getPaths());
663  updateList(fullPathsTable, rule.getFullPaths());
664  if (rule.getMinFileSize() == null) {
665  minSizeTextField.setText("");
666  } else {
667  minSizeTextField.setText(rule.getMinFileSize().toString());
668  }
669  if (rule.getMaxFileSize() == null) {
670  maxSizeTextField.setText("");
671  } else {
672  maxSizeTextField.setText(rule.getMaxFileSize().toString());
673  }
674  if (rule.getMinDays() == null) {
675  daysIncludedTextField.setText("");
676  } else {
677  daysIncludedTextField.setText(Integer.toString(rule.getMinDays()));
678  }
679  }
680 
681  private void clearRuleDetails() {
682  extensionsTextField.setText("");
683  shouldAlertCheckBox.setSelected(false);
684  shouldSaveCheckBox.setSelected(true);
685  }
686 
687  private void updateExtensions(List<String> extensions) {
688  extensionsTextField.setText("");
689  if (extensions == null) {
690  return;
691  }
692  String content = "";
693  boolean first = true;
694  for (String ext : extensions) {
695  content += (first ? "" : ",") + ext;
696  first = false;
697  }
698  extensionsTextField.setText(content);
699  }
700 
701  private void updateList(javax.swing.JTable jTable, List<String> set) {
702  SingleColumnTableModel tableModel = new SingleColumnTableModel();
703  jTable.setTableHeader(null);
704  if (set == null) {
705  jTable.setModel(tableModel);
706  return;
707  }
708  int row = 0;
709  for (String s : set) {
710  tableModel.setValueAt(s, row, 0);
711  row++;
712  }
713  jTable.setModel(tableModel);
714  }
715 
716  void setConfiguration(String configFilename, LogicalImagerConfig config, boolean newFile) {
717  this.configFilename = configFilename;
718  this.config = config;
719  if (newFile) {
720  initPanel();
721  }
722  updatePanel(configFilename, config);
723  }
724 
725  private void initPanel() {
726  configFileTextField.setText("");
727  rulesTable.setModel(new RulesTableModel());
728  shouldAlertCheckBox.setSelected(false);
729  shouldSaveCheckBox.setSelected(true);
730  ruleNameEditTextField.setText("");
731  descriptionEditTextField.setText("");
732  extensionsTextField.setText("");
733  updateList(filenamesTable, EMPTY_LIST);
734  updateList(folderNamesTable, EMPTY_LIST);
735  }
736 
737  private void updateRow(int index, ImmutablePair<String, LogicalImagerRule> ruleMap) {
738  getFirstRuleSet().getRules().remove(index);
739  getFirstRuleSet().getRules().add(ruleMap.getValue());
740  updatePanel(configFilename, config, ruleMap.getKey());
741  }
742 
743  private void appendRow(ImmutablePair<String, LogicalImagerRule> ruleMap) {
744  getFirstRuleSet().getRules().add(ruleMap.getValue());
745  updatePanel(configFilename, config, ruleMap.getKey());
746  }
747 
748  private void updateRuleSetButtons(boolean isRowSelected) {
749  newRuleButton.setEnabled(true);
750  editRuleButton.setEnabled(isRowSelected);
751  deleteRuleButton.setEnabled(isRowSelected);
752  }
753 
757  private class SortRuleByName implements Comparator<LogicalImagerRule> {
758 
759  public int compare(LogicalImagerRule a, LogicalImagerRule b) {
760  return a.getName().compareToIgnoreCase(b.getName());
761  }
762  }
763 
767  private class RulesTableModel extends AbstractTableModel {
768 
769  private final List<String> ruleName = new ArrayList<>();
770  private final List<String> ruleDescription = new ArrayList<>();
771  private final List<LogicalImagerRule> rule = new ArrayList<>();
772 
773  int findRow(String name) {
774  return ruleName.indexOf(name);
775  }
776 
777  @Override
778  public int getRowCount() {
779  return ruleName.size();
780  }
781 
782  @Override
783  public int getColumnCount() {
784  return 2;
785  }
786 
787  @NbBundle.Messages({
788  "ConfigVisualPanel2.rulesTable.columnModel.title0=Rule Name",
789  "ConfigVisualPanel2.rulesTable.columnModel.title1=Description"
790  })
791  @Override
792  public String getColumnName(int column) {
793  String colName = null;
794  switch (column) {
795  case 0:
796  colName = Bundle.ConfigVisualPanel2_rulesTable_columnModel_title0();
797  break;
798  case 1:
799  colName = Bundle.ConfigVisualPanel2_rulesTable_columnModel_title1();
800  break;
801  default:
802  break;
803  }
804  return colName;
805  }
806 
807  @Override
808  public Object getValueAt(int rowIndex, int columnIndex) {
809  Object ret = null;
810  switch (columnIndex) {
811  case 0:
812  ret = ruleName.get(rowIndex);
813  break;
814  case 1:
815  ret = ruleDescription.get(rowIndex);
816  break;
817  case 2:
818  ret = rule.get(rowIndex);
819  break;
820  default:
821  throw new UnsupportedOperationException("Invalid table column index: " + columnIndex); //NON-NLS
822  }
823  return ret;
824  }
825 
826  @Override
827  public boolean isCellEditable(int rowIndex, int columnIndex) {
828  return false;
829  }
830 
831  @Override
832  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
833  switch (columnIndex) {
834  case 0:
835  ruleName.add((String) aValue);
836  break;
837  case 1:
838  ruleDescription.add((String) aValue);
839  break;
840  case 2:
841  rule.add((LogicalImagerRule) aValue);
842  break;
843  default:
844  throw new UnsupportedOperationException("Invalid table column index: " + columnIndex); //NON-NLS
845  }
846  // Only show the name and description column
847  if (columnIndex < 2) {
848  super.setValueAt(aValue, rowIndex, columnIndex);
849  }
850  }
851  }
852 
856  private class SingleColumnTableModel extends AbstractTableModel {
857 
858  private final List<String> list = new ArrayList<>();
859 
860  @Override
861  public int getRowCount() {
862  return list.size();
863  }
864 
865  @Override
866  public int getColumnCount() {
867  return 1;
868  }
869 
870  @Override
871  public String getColumnName(int column) {
872  return "";
873  }
874 
875  @Override
876  public Object getValueAt(int rowIndex, int columnIndex) {
877  Object ret = null;
878  if (columnIndex == 0) {
879  ret = list.get(rowIndex);
880  } else {
881  throw new UnsupportedOperationException("Invalid table column index: " + columnIndex); //NON-NLS
882  }
883  return ret;
884  }
885 
886  @Override
887  public boolean isCellEditable(int rowIndex, int columnIndex) {
888  return true;
889  }
890 
891  @Override
892  public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
893  if (columnIndex == 0) {
894  list.add((String) aValue);
895  } else {
896  throw new UnsupportedOperationException("Invalid table column index: " + columnIndex); //NON-NLS
897  }
898  }
899  }
900 }

Copyright © 2012-2018 Basis Technology. Generated on: Fri Jun 21 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.