Autopsy  4.14.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
EditNonFullPathsRulePanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy
3  *
4  * Copyright 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.awt.Color;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.KeyAdapter;
24 import java.awt.event.KeyEvent;
25 import java.io.IOException;
26 import java.text.ParseException;
27 import java.util.ArrayList;
28 import java.util.List;
29 import java.util.logging.Level;
30 import javax.swing.JButton;
31 import javax.swing.JComboBox;
32 import javax.swing.JComponent;
33 import javax.swing.JOptionPane;
34 import javax.swing.JScrollPane;
35 import javax.swing.JTextArea;
36 import javax.swing.JTextField;
37 import javax.swing.SwingUtilities;
38 import javax.swing.event.DocumentEvent;
39 import javax.swing.event.DocumentListener;
40 import org.apache.commons.lang.StringUtils;
41 import static org.apache.commons.lang.StringUtils.isBlank;
42 import static org.apache.commons.lang3.StringUtils.strip;
43 import org.apache.commons.lang3.tuple.ImmutablePair;
44 import org.openide.util.NbBundle;
46 
50 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
51 final class EditNonFullPathsRulePanel extends javax.swing.JPanel {
52 
53  private static final Logger logger = Logger.getLogger(EditNonFullPathsRulePanel.class.getName());
54  private static final long serialVersionUID = 1L;
55  private static final Color DISABLED_COLOR = new Color(240, 240, 240);
56  private static final int BYTE_UNIT_CONVERSION = 1000;
57  private JButton okButton;
58  private JButton cancelButton;
59  private final javax.swing.JTextArea fileNamesTextArea;
60  private final javax.swing.JTextArea folderNamesTextArea;
61 
65  @NbBundle.Messages({
66  "EditNonFullPathsRulePanel.example=Example: ",
67  "EditNonFullPathsRulePanel.units.bytes=Bytes",
68  "EditNonFullPathsRulePanel.units.kilobytes=Kilobytes",
69  "EditNonFullPathsRulePanel.units.megabytes=Megabytes",
70  "EditNonFullPathsRulePanel.units.gigabytes=Gigabytes"
71  })
72  EditNonFullPathsRulePanel(JButton okButton, JButton cancelButton, String ruleName, LogicalImagerRule rule, boolean editing) {
73  initComponents();
74 
75  this.setRule(ruleName, rule);
76  this.setButtons(okButton, cancelButton);
77 
78  setExtensions(rule.getExtensions());
79  fileNamesTextArea = new JTextArea();
80  initTextArea(filenamesScrollPane, fileNamesTextArea);
81  setTextArea(fileNamesTextArea, rule.getFilenames());
82  if (rule.getExtensions() != null && !rule.getExtensions().isEmpty()) {
83  extensionsCheckbox.setSelected(true);
84  extensionsTextField.setEnabled(extensionsCheckbox.isSelected());
85  } else if (rule.getFilenames() != null && !rule.getFilenames().isEmpty()) {
86  fileNamesCheckbox.setSelected(true);
87  fileNamesTextArea.setEnabled(fileNamesCheckbox.isSelected());
88  }
89  updateExclusiveConditions();
90  folderNamesTextArea = new JTextArea();
91  initTextArea(folderNamesScrollPane, folderNamesTextArea);
92  setTextArea(folderNamesTextArea, rule.getPaths());
93  folderNamesCheckbox.setSelected(!StringUtils.isBlank(folderNamesTextArea.getText()));
94  folderNamesTextArea.setEnabled(folderNamesCheckbox.isSelected());
95  updateTextAreaBackgroundColor(folderNamesTextArea);
96  setModifiedWithin(rule.getMinDays());
97 
98  setupMinMaxSizeOptions(rule);
99  ruleNameTextField.requestFocus();
100 
101  EditRulePanel.setTextFieldPrompts(extensionsTextField, Bundle.EditNonFullPathsRulePanel_example() + "gif,jpg,png"); // NON-NLS
102  EditRulePanel.setTextFieldPrompts(fileNamesTextArea, "<html>"
103  + Bundle.EditNonFullPathsRulePanel_example()
104  + "<br>filename.txt<br>readme.txt</html>"); // NON-NLS
105  EditRulePanel.setTextFieldPrompts(folderNamesTextArea, "<html>"
106  + Bundle.EditNonFullPathsRulePanel_example()
107  + "<br>[USER_FOLDER]/My Documents/Downloads"
108  + "<br>/Program Files/Common Files</html>"); // NON-NLS
109  validate();
110  repaint();
111  addDocumentListeners();
112  }
113 
119  private void setupMinMaxSizeOptions(LogicalImagerRule rule) {
120  String savedMinSize = rule.getMinFileSize() == null ? "" : rule.getMinFileSize().toString();
121  setSizeAndUnits(minSizeTextField, minSizeUnitsCombobox, savedMinSize);
122  minSizeCheckbox.setSelected(!StringUtils.isBlank(minSizeTextField.getText()));
123  minSizeTextField.setEnabled(minSizeCheckbox.isSelected());
124  minSizeUnitsCombobox.setEnabled(minSizeCheckbox.isSelected());
125 
126  String savedMaxSize = rule.getMaxFileSize() == null ? "" : rule.getMaxFileSize().toString();
127  setSizeAndUnits(maxSizeTextField, maxSizeUnitsCombobox, savedMaxSize);
128  maxSizeCheckbox.setSelected(!StringUtils.isBlank(maxSizeTextField.getText()));
129  maxSizeTextField.setEnabled(maxSizeCheckbox.isSelected());
130  maxSizeUnitsCombobox.setEnabled(maxSizeCheckbox.isSelected());
131  }
132 
136  private void addDocumentListeners() {
137  SwingUtilities.invokeLater(() -> {
138  setOkButton(); //ensure initial state before listeners added is correct
139  });
140  DocumentListener docListener;
141  docListener = new DocumentListener() {
142  @Override
143  public void changedUpdate(DocumentEvent e) {
144  setOkButton();
145  }
146 
147  @Override
148  public void insertUpdate(DocumentEvent e) {
149  setOkButton();
150  }
151 
152  @Override
153  public void removeUpdate(DocumentEvent e) {
154  setOkButton();
155  }
156  };
157  ruleNameTextField.getDocument().addDocumentListener(docListener);
158  extensionsTextField.getDocument().addDocumentListener(docListener);
159  fileNamesTextArea.getDocument().addDocumentListener(docListener);
160  folderNamesTextArea.getDocument().addDocumentListener(docListener);
161  minSizeTextField.getDocument().addDocumentListener(docListener);
162  maxSizeTextField.getDocument().addDocumentListener(docListener);
163  modifiedWithinTextField.getDocument().addDocumentListener(docListener);
164  }
165 
172  private void initTextArea(JScrollPane pane, JTextArea textArea) {
173  textArea.setColumns(20);
174  textArea.setRows(4);
175  pane.setViewportView(textArea);
176  textArea.setEnabled(false);
177  textArea.setEditable(false);
178  textArea.setBackground(DISABLED_COLOR);
179  textArea.addKeyListener(new KeyAdapter() {
180  @Override
181  public void keyPressed(KeyEvent e) {
182  if (e.getKeyCode() == KeyEvent.VK_TAB) {
183  if (e.getModifiers() > 0) {
184  textArea.transferFocusBackward();
185  } else {
186  textArea.transferFocus();
187  }
188  e.consume();
189  }
190  }
191  });
192  }
193 
203  private long convertToBytes(long value, String units) {
204  long convertedValue = value;
205  if (units.equals(Bundle.EditNonFullPathsRulePanel_units_gigabytes())) {
206  convertedValue = convertedValue * BYTE_UNIT_CONVERSION * BYTE_UNIT_CONVERSION * BYTE_UNIT_CONVERSION;
207  } else if (units.equals(Bundle.EditNonFullPathsRulePanel_units_megabytes())) {
208  convertedValue = convertedValue * BYTE_UNIT_CONVERSION * BYTE_UNIT_CONVERSION;
209  } else if (units.equals(Bundle.EditNonFullPathsRulePanel_units_kilobytes())) {
210  convertedValue *= BYTE_UNIT_CONVERSION;
211  }
212  return convertedValue;
213  }
214 
223  private void setSizeAndUnits(JTextField sizeField, JComboBox<String> unitsComboBox, String value) {
224  if (StringUtils.isBlank(value)) {
225  unitsComboBox.setSelectedItem(Bundle.EditNonFullPathsRulePanel_units_bytes());
226  sizeField.setText("");
227  return;
228  }
229  long longValue = Long.valueOf(value);
230  if (longValue % BYTE_UNIT_CONVERSION != 0) {
231  unitsComboBox.setSelectedItem(Bundle.EditNonFullPathsRulePanel_units_bytes());
232  sizeField.setText(value); //value stored in bytes is correct value to display
233  return;
234  }
235  longValue /= BYTE_UNIT_CONVERSION;
236  if (longValue % BYTE_UNIT_CONVERSION != 0) {
237  unitsComboBox.setSelectedItem(Bundle.EditNonFullPathsRulePanel_units_kilobytes());
238  sizeField.setText(String.valueOf(longValue));
239  return;
240  }
241  longValue /= BYTE_UNIT_CONVERSION;
242  if (longValue % BYTE_UNIT_CONVERSION != 0) {
243  unitsComboBox.setSelectedItem(Bundle.EditNonFullPathsRulePanel_units_megabytes());
244  sizeField.setText(String.valueOf(longValue));
245  return;
246  }
247  longValue /= BYTE_UNIT_CONVERSION;
248  unitsComboBox.setSelectedItem(Bundle.EditNonFullPathsRulePanel_units_gigabytes());
249  sizeField.setText(String.valueOf(longValue));
250 
251  }
252 
258  private void setModifiedWithin(Integer minDays) {
259  modifiedWithinTextField.setText(minDays == null ? "" : minDays.toString());
260  modifiedWithinCheckbox.setSelected(!StringUtils.isBlank(modifiedWithinTextField.getText()));
261  modifiedWithinTextField.setEnabled(modifiedWithinCheckbox.isSelected());
262  }
263 
270  private void setTextArea(JTextArea textArea, List<String> list) {
271  String text = "";
272  if (list != null) {
273  text = list.stream().map((s) -> s + System.getProperty("line.separator")).reduce(text, String::concat); // NON-NLS
274  }
275  textArea.setText(text);
276  }
277 
283  private void setExtensions(List<String> extensions) {
284  extensionsTextField.setText("");
285  String content = "";
286  if (extensions != null) {
287  boolean first = true;
288  for (String ext : extensions) {
289  content += (first ? "" : ",") + ext;
290  first = false;
291  }
292  }
293  extensionsCheckbox.setSelected(!StringUtils.isBlank(content));
294  extensionsTextField.setText(content);
295  }
296 
302  @SuppressWarnings("unchecked")
303  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
304  private void initComponents() {
305 
306  daysIncludedLabel = new javax.swing.JLabel();
307  shouldSaveCheckBox = new javax.swing.JCheckBox();
308  shouldAlertCheckBox = new javax.swing.JCheckBox();
309  extensionsTextField = new javax.swing.JTextField();
310  descriptionTextField = new javax.swing.JTextField();
311  ruleNameLabel = new javax.swing.JLabel();
312  ruleNameTextField = new javax.swing.JTextField();
313  filenamesScrollPane = new javax.swing.JScrollPane();
314  folderNamesScrollPane = new javax.swing.JScrollPane();
315  minSizeTextField = new javax.swing.JFormattedTextField();
316  maxSizeTextField = new javax.swing.JFormattedTextField();
317  modifiedWithinTextField = new javax.swing.JFormattedTextField();
318  userFolderNote = new javax.swing.JLabel();
319  minSizeCheckbox = new javax.swing.JCheckBox();
320  maxSizeCheckbox = new javax.swing.JCheckBox();
321  modifiedWithinCheckbox = new javax.swing.JCheckBox();
322  folderNamesCheckbox = new javax.swing.JCheckBox();
323  fileNamesCheckbox = new javax.swing.JCheckBox();
324  extensionsCheckbox = new javax.swing.JCheckBox();
325  minSizeUnitsCombobox = new javax.swing.JComboBox<>();
326  maxSizeUnitsCombobox = new javax.swing.JComboBox<>();
327  jSeparator1 = new javax.swing.JSeparator();
328  jSeparator2 = new javax.swing.JSeparator();
329  descriptionLabel = new javax.swing.JLabel();
330  jLabel2 = new javax.swing.JLabel();
331  jLabel1 = new javax.swing.JLabel();
332  extensionsInfoLabel = new javax.swing.JLabel();
333  fileNamesInfoLabel = new javax.swing.JLabel();
334 
335  org.openide.awt.Mnemonics.setLocalizedText(daysIncludedLabel, org.openide.util.NbBundle.getMessage(EditNonFullPathsRulePanel.class, "EditNonFullPathsRulePanel.daysIncludedLabel.text")); // NOI18N
336 
337  shouldSaveCheckBox.setSelected(true);
338  org.openide.awt.Mnemonics.setLocalizedText(shouldSaveCheckBox, org.openide.util.NbBundle.getMessage(EditNonFullPathsRulePanel.class, "EditNonFullPathsRulePanel.shouldSaveCheckBox.text")); // NOI18N
339  shouldSaveCheckBox.addActionListener(new java.awt.event.ActionListener() {
340  public void actionPerformed(java.awt.event.ActionEvent evt) {
341  shouldSaveCheckBoxActionPerformed(evt);
342  }
343  });
344 
345  org.openide.awt.Mnemonics.setLocalizedText(shouldAlertCheckBox, org.openide.util.NbBundle.getMessage(EditNonFullPathsRulePanel.class, "EditNonFullPathsRulePanel.shouldAlertCheckBox.text")); // NOI18N
346  shouldAlertCheckBox.setActionCommand(org.openide.util.NbBundle.getMessage(EditNonFullPathsRulePanel.class, "EditNonFullPathsRulePanel.shouldAlertCheckBox.actionCommand")); // NOI18N
347  shouldAlertCheckBox.addActionListener(new java.awt.event.ActionListener() {
348  public void actionPerformed(java.awt.event.ActionEvent evt) {
349  shouldAlertCheckBoxActionPerformed(evt);
350  }
351  });
352 
353  extensionsTextField.setEnabled(false);
354 
355  org.openide.awt.Mnemonics.setLocalizedText(ruleNameLabel, org.openide.util.NbBundle.getMessage(EditNonFullPathsRulePanel.class, "EditNonFullPathsRulePanel.ruleNameLabel.text")); // NOI18N
356  ruleNameLabel.setPreferredSize(new java.awt.Dimension(112, 14));
357 
358  filenamesScrollPane.setToolTipText(org.openide.util.NbBundle.getMessage(EditNonFullPathsRulePanel.class, "EditNonFullPathsRulePanel.filenamesScrollPane.toolTipText")); // NOI18N
359  filenamesScrollPane.setEnabled(false);
360 
361  folderNamesScrollPane.setEnabled(false);
362 
363  minSizeTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new DefaultToEmptyNumberFormatter(new java.text.DecimalFormat("#,###; "))));
364  minSizeTextField.setEnabled(false);
365 
366  maxSizeTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new DefaultToEmptyNumberFormatter(new java.text.DecimalFormat("#,###; "))));
367  maxSizeTextField.setEnabled(false);
368 
369  modifiedWithinTextField.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new DefaultToEmptyNumberFormatter(new java.text.DecimalFormat("#,###; "))));
370  modifiedWithinTextField.setEnabled(false);
371 
372  userFolderNote.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/info-icon-16.png"))); // NOI18N
373  org.openide.awt.Mnemonics.setLocalizedText(userFolderNote, org.openide.util.NbBundle.getMessage(EditNonFullPathsRulePanel.class, "EditNonFullPathsRulePanel.userFolderNote.text")); // NOI18N
374 
375  org.openide.awt.Mnemonics.setLocalizedText(minSizeCheckbox, org.openide.util.NbBundle.getMessage(EditNonFullPathsRulePanel.class, "EditNonFullPathsRulePanel.minSizeCheckbox.text")); // NOI18N
376  minSizeCheckbox.setPreferredSize(new java.awt.Dimension(112, 23));
377  minSizeCheckbox.addActionListener(new java.awt.event.ActionListener() {
378  public void actionPerformed(java.awt.event.ActionEvent evt) {
379  minSizeCheckboxActionPerformed(evt);
380  }
381  });
382 
383  org.openide.awt.Mnemonics.setLocalizedText(maxSizeCheckbox, org.openide.util.NbBundle.getMessage(EditNonFullPathsRulePanel.class, "EditNonFullPathsRulePanel.maxSizeCheckbox.text")); // NOI18N
384  maxSizeCheckbox.setPreferredSize(new java.awt.Dimension(112, 23));
385  maxSizeCheckbox.addActionListener(new java.awt.event.ActionListener() {
386  public void actionPerformed(java.awt.event.ActionEvent evt) {
387  maxSizeCheckboxActionPerformed(evt);
388  }
389  });
390 
391  org.openide.awt.Mnemonics.setLocalizedText(modifiedWithinCheckbox, org.openide.util.NbBundle.getMessage(EditNonFullPathsRulePanel.class, "EditNonFullPathsRulePanel.modifiedWithinCheckbox.text")); // NOI18N
392  modifiedWithinCheckbox.setPreferredSize(new java.awt.Dimension(112, 23));
393  modifiedWithinCheckbox.addActionListener(new java.awt.event.ActionListener() {
394  public void actionPerformed(java.awt.event.ActionEvent evt) {
395  modifiedWithinCheckboxActionPerformed(evt);
396  }
397  });
398 
399  org.openide.awt.Mnemonics.setLocalizedText(folderNamesCheckbox, org.openide.util.NbBundle.getMessage(EditNonFullPathsRulePanel.class, "EditNonFullPathsRulePanel.folderNamesCheckbox.text")); // NOI18N
400  folderNamesCheckbox.setPreferredSize(new java.awt.Dimension(112, 23));
401  folderNamesCheckbox.addActionListener(new java.awt.event.ActionListener() {
402  public void actionPerformed(java.awt.event.ActionEvent evt) {
403  folderNamesCheckboxActionPerformed(evt);
404  }
405  });
406 
407  org.openide.awt.Mnemonics.setLocalizedText(fileNamesCheckbox, org.openide.util.NbBundle.getMessage(EditNonFullPathsRulePanel.class, "EditNonFullPathsRulePanel.fileNamesCheckbox.text")); // NOI18N
408  fileNamesCheckbox.setPreferredSize(new java.awt.Dimension(112, 23));
409  fileNamesCheckbox.addActionListener(new java.awt.event.ActionListener() {
410  public void actionPerformed(java.awt.event.ActionEvent evt) {
411  fileNamesCheckboxActionPerformed(evt);
412  }
413  });
414 
415  org.openide.awt.Mnemonics.setLocalizedText(extensionsCheckbox, org.openide.util.NbBundle.getMessage(EditNonFullPathsRulePanel.class, "EditNonFullPathsRulePanel.extensionsCheckbox.text")); // NOI18N
416  extensionsCheckbox.setPreferredSize(new java.awt.Dimension(112, 23));
417  extensionsCheckbox.addActionListener(new java.awt.event.ActionListener() {
418  public void actionPerformed(java.awt.event.ActionEvent evt) {
419  extensionsCheckboxActionPerformed(evt);
420  }
421  });
422 
423  minSizeUnitsCombobox.setModel(new javax.swing.DefaultComboBoxModel<String>(new String[] { Bundle.EditNonFullPathsRulePanel_units_bytes(), Bundle.EditNonFullPathsRulePanel_units_kilobytes(), Bundle.EditNonFullPathsRulePanel_units_megabytes(), Bundle.EditNonFullPathsRulePanel_units_gigabytes()}));
424  minSizeUnitsCombobox.setEnabled(false);
425 
426  maxSizeUnitsCombobox.setModel(new javax.swing.DefaultComboBoxModel<String>(new String[] { Bundle.EditNonFullPathsRulePanel_units_bytes(), Bundle.EditNonFullPathsRulePanel_units_kilobytes(), Bundle.EditNonFullPathsRulePanel_units_megabytes(), Bundle.EditNonFullPathsRulePanel_units_gigabytes()}));
427  maxSizeUnitsCombobox.setEnabled(false);
428 
429  org.openide.awt.Mnemonics.setLocalizedText(descriptionLabel, org.openide.util.NbBundle.getMessage(EditNonFullPathsRulePanel.class, "EditNonFullPathsRulePanel.descriptionLabel.text")); // NOI18N
430  descriptionLabel.setPreferredSize(new java.awt.Dimension(112, 14));
431 
432  org.openide.awt.Mnemonics.setLocalizedText(jLabel2, org.openide.util.NbBundle.getMessage(EditNonFullPathsRulePanel.class, "EditNonFullPathsRulePanel.jLabel2.text")); // NOI18N
433 
434  org.openide.awt.Mnemonics.setLocalizedText(jLabel1, org.openide.util.NbBundle.getMessage(EditNonFullPathsRulePanel.class, "EditNonFullPathsRulePanel.jLabel1.text")); // NOI18N
435 
436  extensionsInfoLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/info-icon-16.png"))); // NOI18N
437  org.openide.awt.Mnemonics.setLocalizedText(extensionsInfoLabel, org.openide.util.NbBundle.getMessage(EditNonFullPathsRulePanel.class, "EditNonFullPathsRulePanel.extensionsInfoLabel.text")); // NOI18N
438 
439  fileNamesInfoLabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/info-icon-16.png"))); // NOI18N
440  org.openide.awt.Mnemonics.setLocalizedText(fileNamesInfoLabel, org.openide.util.NbBundle.getMessage(EditNonFullPathsRulePanel.class, "EditNonFullPathsRulePanel.fileNamesInfoLabel.text")); // NOI18N
441 
442  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
443  this.setLayout(layout);
444  layout.setHorizontalGroup(
445  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
446  .addGroup(layout.createSequentialGroup()
447  .addContainerGap()
448  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
449  .addComponent(jSeparator2)
450  .addComponent(jSeparator1)
451  .addGroup(layout.createSequentialGroup()
452  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
453  .addComponent(shouldAlertCheckBox)
454  .addComponent(shouldSaveCheckBox)
455  .addComponent(fileNamesCheckbox, javax.swing.GroupLayout.PREFERRED_SIZE, 112, javax.swing.GroupLayout.PREFERRED_SIZE)
456  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
457  .addComponent(modifiedWithinCheckbox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
458  .addComponent(maxSizeCheckbox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
459  .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
460  .addGap(0, 0, Short.MAX_VALUE))
461  .addGroup(layout.createSequentialGroup()
462  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
463  .addComponent(extensionsCheckbox, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
464  .addComponent(ruleNameLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
465  .addComponent(descriptionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
466  .addComponent(minSizeCheckbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
467  .addComponent(folderNamesCheckbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
468  .addGap(0, 0, 0)
469  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
470  .addComponent(ruleNameTextField, javax.swing.GroupLayout.Alignment.TRAILING)
471  .addComponent(descriptionTextField, javax.swing.GroupLayout.Alignment.TRAILING)
472  .addComponent(extensionsTextField, javax.swing.GroupLayout.Alignment.TRAILING)
473  .addComponent(folderNamesScrollPane)
474  .addComponent(filenamesScrollPane, javax.swing.GroupLayout.Alignment.TRAILING)
475  .addGroup(layout.createSequentialGroup()
476  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
477  .addComponent(fileNamesInfoLabel)
478  .addComponent(extensionsInfoLabel)
479  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
480  .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 522, javax.swing.GroupLayout.PREFERRED_SIZE)
481  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
482  .addComponent(userFolderNote)
483  .addGroup(layout.createSequentialGroup()
484  .addComponent(minSizeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
485  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
486  .addComponent(minSizeUnitsCombobox, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
487  .addGroup(layout.createSequentialGroup()
488  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
489  .addComponent(modifiedWithinTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
490  .addComponent(maxSizeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))
491  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
492  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
493  .addComponent(maxSizeUnitsCombobox, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
494  .addComponent(daysIncludedLabel))))))
495  .addGap(0, 11, Short.MAX_VALUE)))))
496  .addContainerGap())
497  );
498 
499  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {maxSizeTextField, minSizeTextField, modifiedWithinTextField});
500 
501  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {descriptionLabel, extensionsCheckbox, fileNamesCheckbox, folderNamesCheckbox, maxSizeCheckbox, minSizeCheckbox, modifiedWithinCheckbox, ruleNameLabel});
502 
503  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {maxSizeUnitsCombobox, minSizeUnitsCombobox});
504 
505  layout.setVerticalGroup(
506  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
507  .addGroup(layout.createSequentialGroup()
508  .addGap(8, 8, 8)
509  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
510  .addComponent(ruleNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
511  .addComponent(ruleNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
512  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
513  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
514  .addComponent(descriptionTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
515  .addComponent(descriptionLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
516  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
517  .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
518  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
519  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
520  .addComponent(extensionsTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
521  .addComponent(extensionsCheckbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
522  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
523  .addComponent(extensionsInfoLabel)
524  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
525  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
526  .addComponent(filenamesScrollPane)
527  .addGroup(layout.createSequentialGroup()
528  .addComponent(fileNamesCheckbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
529  .addGap(0, 0, Short.MAX_VALUE)))
530  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
531  .addComponent(fileNamesInfoLabel)
532  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
533  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
534  .addComponent(folderNamesScrollPane)
535  .addGroup(layout.createSequentialGroup()
536  .addComponent(folderNamesCheckbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
537  .addGap(0, 0, Short.MAX_VALUE)))
538  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
539  .addComponent(userFolderNote, javax.swing.GroupLayout.PREFERRED_SIZE, 16, javax.swing.GroupLayout.PREFERRED_SIZE)
540  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
541  .addComponent(jLabel2)
542  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
543  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
544  .addComponent(minSizeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
545  .addComponent(minSizeCheckbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
546  .addComponent(minSizeUnitsCombobox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
547  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
548  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
549  .addComponent(maxSizeTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
550  .addComponent(maxSizeCheckbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
551  .addComponent(maxSizeUnitsCombobox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
552  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
553  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
554  .addComponent(daysIncludedLabel)
555  .addComponent(modifiedWithinTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
556  .addComponent(modifiedWithinCheckbox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
557  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
558  .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
559  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
560  .addComponent(jLabel1)
561  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
562  .addComponent(shouldSaveCheckBox)
563  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
564  .addComponent(shouldAlertCheckBox)
565  .addContainerGap())
566  );
567  }// </editor-fold>//GEN-END:initComponents
568 
569  private void extensionsCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_extensionsCheckboxActionPerformed
570  if (fileNamesCheckbox.isSelected() && extensionsCheckbox.isSelected()) {
571  fileNamesCheckbox.setSelected(false);
572  }
573  updateExclusiveConditions();
574  setOkButton();
575  }//GEN-LAST:event_extensionsCheckboxActionPerformed
576 
577  private void fileNamesCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fileNamesCheckboxActionPerformed
578  if (fileNamesCheckbox.isSelected() && extensionsCheckbox.isSelected()) {
579  extensionsCheckbox.setSelected(false);
580  }
581  updateExclusiveConditions();
582  setOkButton();
583  }//GEN-LAST:event_fileNamesCheckboxActionPerformed
584 
585  private void folderNamesCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_folderNamesCheckboxActionPerformed
586  folderNamesScrollPane.setEnabled(folderNamesCheckbox.isSelected());
587  folderNamesTextArea.setEditable(folderNamesCheckbox.isSelected());
588  folderNamesTextArea.setEnabled(folderNamesCheckbox.isSelected());
589  updateTextAreaBackgroundColor(folderNamesTextArea);
590  setOkButton();
591 
592  }//GEN-LAST:event_folderNamesCheckboxActionPerformed
593 
594  private void minSizeCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_minSizeCheckboxActionPerformed
595  minSizeTextField.setEnabled(minSizeCheckbox.isSelected());
596  minSizeUnitsCombobox.setEnabled(minSizeCheckbox.isSelected());
597  setOkButton();
598  }//GEN-LAST:event_minSizeCheckboxActionPerformed
599 
600  private void maxSizeCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_maxSizeCheckboxActionPerformed
601  maxSizeTextField.setEnabled(maxSizeCheckbox.isSelected());
602  maxSizeUnitsCombobox.setEnabled(maxSizeCheckbox.isSelected());
603  setOkButton();
604  }//GEN-LAST:event_maxSizeCheckboxActionPerformed
605 
606  private void modifiedWithinCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_modifiedWithinCheckboxActionPerformed
607  modifiedWithinTextField.setEnabled(modifiedWithinCheckbox.isSelected());
608  setOkButton();
609  }//GEN-LAST:event_modifiedWithinCheckboxActionPerformed
610 
611  private void shouldSaveCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shouldSaveCheckBoxActionPerformed
612  setOkButton();
613  }//GEN-LAST:event_shouldSaveCheckBoxActionPerformed
614 
615  private void shouldAlertCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_shouldAlertCheckBoxActionPerformed
616  setOkButton();
617  }//GEN-LAST:event_shouldAlertCheckBoxActionPerformed
618 
625  private static void updateTextAreaBackgroundColor(JTextArea textArea) {
626  if (textArea.isEnabled()) {
627  textArea.setBackground(Color.WHITE);
628  } else {
629  textArea.setBackground(DISABLED_COLOR);
630  }
631  }
632 
637  private void updateExclusiveConditions() {
638  extensionsTextField.setEnabled(extensionsCheckbox.isSelected());
639  filenamesScrollPane.setEnabled(fileNamesCheckbox.isSelected());
640  fileNamesTextArea.setEditable(fileNamesCheckbox.isSelected());
641  fileNamesTextArea.setEnabled(fileNamesCheckbox.isSelected());
642  updateTextAreaBackgroundColor(fileNamesTextArea);
643  }
644 
645  // Variables declaration - do not modify//GEN-BEGIN:variables
646  private javax.swing.JLabel daysIncludedLabel;
647  private javax.swing.JLabel descriptionLabel;
648  private javax.swing.JTextField descriptionTextField;
649  private javax.swing.JCheckBox extensionsCheckbox;
650  private javax.swing.JLabel extensionsInfoLabel;
651  private javax.swing.JTextField extensionsTextField;
652  private javax.swing.JCheckBox fileNamesCheckbox;
653  private javax.swing.JLabel fileNamesInfoLabel;
654  private javax.swing.JScrollPane filenamesScrollPane;
655  private javax.swing.JCheckBox folderNamesCheckbox;
656  private javax.swing.JScrollPane folderNamesScrollPane;
657  private javax.swing.JLabel jLabel1;
658  private javax.swing.JLabel jLabel2;
659  private javax.swing.JSeparator jSeparator1;
660  private javax.swing.JSeparator jSeparator2;
661  private javax.swing.JCheckBox maxSizeCheckbox;
662  private javax.swing.JFormattedTextField maxSizeTextField;
663  private javax.swing.JComboBox<String> maxSizeUnitsCombobox;
664  private javax.swing.JCheckBox minSizeCheckbox;
665  private javax.swing.JFormattedTextField minSizeTextField;
666  private javax.swing.JComboBox<String> minSizeUnitsCombobox;
667  private javax.swing.JCheckBox modifiedWithinCheckbox;
668  private javax.swing.JFormattedTextField modifiedWithinTextField;
669  private javax.swing.JLabel ruleNameLabel;
670  private javax.swing.JTextField ruleNameTextField;
671  private javax.swing.JCheckBox shouldAlertCheckBox;
672  private javax.swing.JCheckBox shouldSaveCheckBox;
673  private javax.swing.JLabel userFolderNote;
674  // End of variables declaration//GEN-END:variables
675 
682  private void setRule(String ruleName, LogicalImagerRule rule) {
683  ruleNameTextField.setText(ruleName);
684  descriptionTextField.setText(rule.getDescription());
685  shouldAlertCheckBox.setSelected(rule.isShouldAlert());
686  shouldSaveCheckBox.setSelected(rule.isShouldSave());
687  }
688 
693  void setOkButton() {
694  if (this.okButton != null) {
695  this.okButton.setEnabled(!StringUtils.isBlank(ruleNameTextField.getText()) && atLeastOneConditionSet() && (shouldAlertCheckBox.isSelected() || shouldSaveCheckBox.isSelected()));
696  }
697  }
698 
705  private boolean atLeastOneConditionSet() {
706  try {
707  return (extensionsCheckbox.isSelected() && !StringUtils.isBlank(extensionsTextField.getText()) && !validateExtensions(extensionsTextField).isEmpty())
708  || (fileNamesCheckbox.isSelected() && !StringUtils.isBlank(fileNamesTextArea.getText()))
709  || (folderNamesCheckbox.isSelected() && !StringUtils.isBlank(folderNamesTextArea.getText()))
710  || (minSizeCheckbox.isSelected() && !StringUtils.isBlank(minSizeTextField.getText()) && isNonZeroLong(minSizeTextField.getValue()))
711  || (maxSizeCheckbox.isSelected() && !StringUtils.isBlank(maxSizeTextField.getText()) && isNonZeroLong(maxSizeTextField.getValue()))
712  || (modifiedWithinCheckbox.isSelected() && !StringUtils.isBlank(modifiedWithinTextField.getText()) && isNonZeroLong(modifiedWithinTextField.getValue()));
713  } catch (IOException ex) {
714  logger.log(Level.WARNING, "Invalid contents of extensionsTextField", ex);
715  return false;
716  }
717  }
718 
726  private boolean isNonZeroLong(Object numberObject) {
727  Long value = 0L;
728  try {
729  if (numberObject instanceof Number) {
730  value = ((Number) numberObject).longValue();
731  }
732  } catch (NumberFormatException ignored) {
733  //The string was not a number, this method will return false becaue the value is still 0L
734  }
735  return (value != 0);
736  }
737 
745  private JOptionPane getOptionPane(JComponent parent) {
746  JOptionPane pane;
747  if (!(parent instanceof JOptionPane)) {
748  pane = getOptionPane((JComponent) parent.getParent());
749  } else {
750  pane = (JOptionPane) parent;
751  }
752  return pane;
753  }
754 
761  private void setButtons(JButton ok, JButton cancel) {
762  this.okButton = ok;
763  this.cancelButton = cancel;
764  okButton.addActionListener((ActionEvent e) -> {
765  JOptionPane pane = getOptionPane(okButton);
766  pane.setValue(okButton);
767  });
768  cancelButton.addActionListener((ActionEvent e) -> {
769  JOptionPane pane = getOptionPane(cancelButton);
770  pane.setValue(cancelButton);
771  });
772  this.setOkButton();
773  }
774 
783  @NbBundle.Messages({
784  "EditNonFullPathsRulePanel.modifiedDaysNotPositiveException=Modified days must be a positive",
785  "# {0} - message",
786  "EditNonFullPathsRulePanel.modifiedDaysMustBeNumberException=Modified days must be a number: {0}",
787  "EditNonFullPathsRulePanel.minFileSizeNotPositiveException=Minimum file size must be a positive",
788  "# {0} - message",
789  "EditNonFullPathsRulePanel.minFileSizeMustBeNumberException=Minimum file size must be a number: {0}",
790  "EditNonFullPathsRulePanel.maxFileSizeNotPositiveException=Maximum file size must be a positive",
791  "# {0} - message",
792  "EditNonFullPathsRulePanel.maxFileSizeMustBeNumberException=Maximum file size must be a number: {0}",
793  "# {0} - maxFileSize",
794  "# {1} - minFileSize",
795  "EditNonFullPathsRulePanel.maxFileSizeSmallerThanMinException=Maximum file size: {0} bytes must be bigger than minimum file size: {1} bytes",
796  "EditNonFullPathsRulePanel.fileNames=File names",
797  "EditNonFullPathsRulePanel.folderNames=Folder names",})
798  ImmutablePair<String, LogicalImagerRule> toRule() throws IOException {
799  String ruleName = EditRulePanel.validRuleName(ruleNameTextField.getText());
800  List<String> folderNames = folderNamesCheckbox.isSelected() ? EditRulePanel.validateTextList(folderNamesTextArea, Bundle.EditNonFullPathsRulePanel_folderNames()) : null;
801 
802  LogicalImagerRule.Builder builder = new LogicalImagerRule.Builder();
803  builder.getName(ruleName)
804  .getDescription(descriptionTextField.getText())
805  .getShouldAlert(shouldAlertCheckBox.isSelected())
806  .getShouldSave(shouldSaveCheckBox.isSelected())
807  .getPaths(folderNames);
808 
809  if (extensionsCheckbox.isSelected()) {
810  builder.getExtensions(validateExtensions(extensionsTextField));
811  } else if (fileNamesCheckbox.isSelected()) {
812  builder.getFilenames(EditRulePanel.validateTextList(fileNamesTextArea, Bundle.EditNonFullPathsRulePanel_fileNames()));
813  }
814 
815  int minDays;
816  if (modifiedWithinCheckbox.isSelected() && !isBlank(modifiedWithinTextField.getText())) {
817  try {
818  modifiedWithinTextField.commitEdit();
819  minDays = ((Number) modifiedWithinTextField.getValue()).intValue();
820  if (minDays < 0) {
821  throw new IOException(Bundle.EditNonFullPathsRulePanel_modifiedDaysNotPositiveException());
822  }
823  builder.getMinDays(minDays);
824  } catch (NumberFormatException | ParseException ex) {
825  throw new IOException(Bundle.EditNonFullPathsRulePanel_modifiedDaysMustBeNumberException(ex.getMessage()), ex);
826  }
827  }
828 
829  long minFileSize = 0;
830  if (minSizeCheckbox.isSelected() && !isBlank(minSizeTextField.getText())) {
831  try {
832  minSizeTextField.commitEdit();
833  minFileSize = ((Number) minSizeTextField.getValue()).longValue();
834  if (minFileSize < 0) {
835  throw new IOException(Bundle.EditNonFullPathsRulePanel_minFileSizeNotPositiveException());
836  }
837  minFileSize = convertToBytes(minFileSize, minSizeUnitsCombobox.getItemAt(minSizeUnitsCombobox.getSelectedIndex()));
838  } catch (NumberFormatException | ParseException ex) {
839  throw new IOException(Bundle.EditNonFullPathsRulePanel_minFileSizeMustBeNumberException(ex.getMessage()), ex);
840  }
841  }
842 
843  long maxFileSize = 0;
844  if (maxSizeCheckbox.isSelected() && !isBlank(maxSizeTextField.getText())) {
845  try {
846  maxSizeTextField.commitEdit();
847  maxFileSize = ((Number) maxSizeTextField.getValue()).longValue();
848  if (maxFileSize < 0) {
849  throw new IOException(Bundle.EditNonFullPathsRulePanel_maxFileSizeNotPositiveException());
850  }
851  maxFileSize = convertToBytes(maxFileSize, maxSizeUnitsCombobox.getItemAt(maxSizeUnitsCombobox.getSelectedIndex()));
852  } catch (NumberFormatException | ParseException ex) {
853  throw new IOException(Bundle.EditNonFullPathsRulePanel_maxFileSizeMustBeNumberException(ex.getMessage()), ex);
854  }
855  }
856 
857  if (maxFileSize != 0 && (maxFileSize < minFileSize)) {
858  throw new IOException(Bundle.EditNonFullPathsRulePanel_maxFileSizeSmallerThanMinException(maxFileSize, minFileSize));
859  }
860  if (minSizeCheckbox.isSelected() && minFileSize != 0) {
861  builder.getMinFileSize(minFileSize);
862  }
863  if (maxSizeCheckbox.isSelected() && maxFileSize != 0) {
864  builder.getMaxFileSize(maxFileSize);
865  }
866 
867  LogicalImagerRule rule = builder.build();
868  return new ImmutablePair<>(ruleName, rule);
869  }
870 
881  @NbBundle.Messages({
882  "EditNonFullPathsRulePanel.emptyExtensionException=Extensions cannot have an empty entry",})
883  private List<String> validateExtensions(JTextField textField) throws IOException {
884  if (isBlank(textField.getText())) {
885  return null;
886  }
887  List<String> extensions = new ArrayList<>();
888  for (String extension : textField.getText().split(",")) {
889  String strippedExtension = strip(extension);
890  if (strippedExtension.isEmpty()) {
891  throw new IOException(Bundle.EditNonFullPathsRulePanel_emptyExtensionException());
892  }
893  extensions.add(strippedExtension);
894  }
895  if (extensions.isEmpty()) {
896  return null;
897  }
898  return extensions;
899  }
900 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2020 Basis Technology. Generated on: Wed Apr 8 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.