Autopsy  4.7.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
ExternalViewerGlobalSettingsPanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2018 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.directorytree;
20 
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import javax.swing.DefaultListModel;
24 import javax.swing.JOptionPane;
25 import javax.swing.event.ListSelectionEvent;
26 import javax.swing.event.ListSelectionListener;
27 import org.netbeans.spi.options.OptionsPanelController;
28 import org.openide.util.NbBundle;
31 
37 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
38 final class ExternalViewerGlobalSettingsPanel extends javax.swing.JPanel implements OptionsPanel {
39 
40  private static final Logger logger = Logger.getLogger(ExternalViewerGlobalSettingsPanel.class.getName());
41  private DefaultListModel<ExternalViewerRule> rulesListModel;
42  private java.util.List<ExternalViewerRule> rules;
43 
47  public ExternalViewerGlobalSettingsPanel() {
48  initComponents();
49  customizeComponents();
50  }
51 
55  private void customizeComponents() {
56  rulesListModel = new DefaultListModel<>();
57  rules = new ArrayList<>();
58  rulesList.setModel(rulesListModel);
59  rulesList.addListSelectionListener(new ListSelectionListener() {
60  @Override
61  public void valueChanged(ListSelectionEvent e) {
62  if (e.getValueIsAdjusting() == false) {
63  if (rulesList.getSelectedIndex() == -1) {
64  clearExePath();
65  } else {
66  populateExePath();
67  }
68  }
69  }
70  });
71  }
72 
78  @SuppressWarnings("unchecked")
79  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
80  private void initComponents() {
81 
82  jPanel1 = new javax.swing.JPanel();
83  externalViewerTitleLabel = new javax.swing.JLabel();
84  jScrollPane1 = new javax.swing.JScrollPane();
85  jSplitPane1 = new javax.swing.JSplitPane();
86  exePanel = new javax.swing.JPanel();
87  exePathLabel = new javax.swing.JLabel();
88  exePathNameLabel = new javax.swing.JLabel();
89  rulesPanel = new javax.swing.JPanel();
90  ruleListLabel = new javax.swing.JLabel();
91  newRuleButton = new javax.swing.JButton();
92  editRuleButton = new javax.swing.JButton();
93  deleteRuleButton = new javax.swing.JButton();
94  jScrollPane2 = new javax.swing.JScrollPane();
95  rulesList = new javax.swing.JList<>();
96 
97  setPreferredSize(new java.awt.Dimension(701, 453));
98 
99  jPanel1.setPreferredSize(new java.awt.Dimension(701, 453));
100 
101  org.openide.awt.Mnemonics.setLocalizedText(externalViewerTitleLabel, org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class, "ExternalViewerGlobalSettingsPanel.externalViewerTitleLabel.text")); // NOI18N
102 
103  jSplitPane1.setDividerSize(1);
104 
105  exePanel.setPreferredSize(new java.awt.Dimension(311, 224));
106 
107  org.openide.awt.Mnemonics.setLocalizedText(exePathLabel, org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class, "ExternalViewerGlobalSettingsPanel.exePathLabel.text")); // NOI18N
108 
109  org.openide.awt.Mnemonics.setLocalizedText(exePathNameLabel, org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class, "ExternalViewerGlobalSettingsPanel.exePathNameLabel.text")); // NOI18N
110 
111  javax.swing.GroupLayout exePanelLayout = new javax.swing.GroupLayout(exePanel);
112  exePanel.setLayout(exePanelLayout);
113  exePanelLayout.setHorizontalGroup(
114  exePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
115  .addGroup(exePanelLayout.createSequentialGroup()
116  .addContainerGap()
117  .addGroup(exePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
118  .addComponent(exePathLabel)
119  .addComponent(exePathNameLabel))
120  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
121  );
122  exePanelLayout.setVerticalGroup(
123  exePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
124  .addGroup(exePanelLayout.createSequentialGroup()
125  .addContainerGap()
126  .addComponent(exePathLabel)
127  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
128  .addComponent(exePathNameLabel)
129  .addContainerGap(355, Short.MAX_VALUE))
130  );
131 
132  jSplitPane1.setRightComponent(exePanel);
133 
134  org.openide.awt.Mnemonics.setLocalizedText(ruleListLabel, org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class, "ExternalViewerGlobalSettingsPanel.ruleListLabel.text")); // NOI18N
135 
136  newRuleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/add16.png"))); // NOI18N
137  org.openide.awt.Mnemonics.setLocalizedText(newRuleButton, org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class, "ExternalViewerGlobalSettingsPanel.newRuleButton.text")); // NOI18N
138  newRuleButton.setMaximumSize(new java.awt.Dimension(111, 25));
139  newRuleButton.setMinimumSize(new java.awt.Dimension(111, 25));
140  newRuleButton.addActionListener(new java.awt.event.ActionListener() {
141  public void actionPerformed(java.awt.event.ActionEvent evt) {
142  newRuleButtonActionPerformed(evt);
143  }
144  });
145 
146  editRuleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/edit16.png"))); // NOI18N
147  org.openide.awt.Mnemonics.setLocalizedText(editRuleButton, org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class, "ExternalViewerGlobalSettingsPanel.editRuleButton.text")); // NOI18N
148  editRuleButton.setMaximumSize(new java.awt.Dimension(111, 25));
149  editRuleButton.setMinimumSize(new java.awt.Dimension(111, 25));
150  editRuleButton.addActionListener(new java.awt.event.ActionListener() {
151  public void actionPerformed(java.awt.event.ActionEvent evt) {
152  editRuleButtonActionPerformed(evt);
153  }
154  });
155 
156  deleteRuleButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/org/sleuthkit/autopsy/images/delete16.png"))); // NOI18N
157  org.openide.awt.Mnemonics.setLocalizedText(deleteRuleButton, org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class, "ExternalViewerGlobalSettingsPanel.deleteRuleButton.text")); // NOI18N
158  deleteRuleButton.setMaximumSize(new java.awt.Dimension(111, 25));
159  deleteRuleButton.setMinimumSize(new java.awt.Dimension(111, 25));
160  deleteRuleButton.addActionListener(new java.awt.event.ActionListener() {
161  public void actionPerformed(java.awt.event.ActionEvent evt) {
162  deleteRuleButtonActionPerformed(evt);
163  }
164  });
165 
166  jScrollPane2.setViewportView(rulesList);
167 
168  javax.swing.GroupLayout rulesPanelLayout = new javax.swing.GroupLayout(rulesPanel);
169  rulesPanel.setLayout(rulesPanelLayout);
170  rulesPanelLayout.setHorizontalGroup(
171  rulesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
172  .addGroup(rulesPanelLayout.createSequentialGroup()
173  .addContainerGap()
174  .addGroup(rulesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
175  .addComponent(ruleListLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
176  .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, rulesPanelLayout.createSequentialGroup()
177  .addGap(6, 6, 6)
178  .addComponent(newRuleButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
179  .addGap(16, 16, 16)
180  .addComponent(editRuleButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
181  .addGap(16, 16, 16)
182  .addComponent(deleteRuleButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
183  .addComponent(jScrollPane2))
184  .addContainerGap())
185  );
186  rulesPanelLayout.setVerticalGroup(
187  rulesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
188  .addGroup(rulesPanelLayout.createSequentialGroup()
189  .addContainerGap()
190  .addComponent(ruleListLabel)
191  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
192  .addComponent(jScrollPane2)
193  .addGap(12, 12, 12)
194  .addGroup(rulesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
195  .addComponent(newRuleButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
196  .addComponent(editRuleButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
197  .addComponent(deleteRuleButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
198  .addContainerGap())
199  );
200 
201  jSplitPane1.setLeftComponent(rulesPanel);
202 
203  jScrollPane1.setViewportView(jSplitPane1);
204 
205  javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
206  jPanel1.setLayout(jPanel1Layout);
207  jPanel1Layout.setHorizontalGroup(
208  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
209  .addGroup(jPanel1Layout.createSequentialGroup()
210  .addContainerGap()
211  .addComponent(externalViewerTitleLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 681, Short.MAX_VALUE)
212  .addContainerGap())
213  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
214  .addGroup(jPanel1Layout.createSequentialGroup()
215  .addContainerGap()
216  .addComponent(jScrollPane1)
217  .addContainerGap()))
218  );
219  jPanel1Layout.setVerticalGroup(
220  jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
221  .addGroup(jPanel1Layout.createSequentialGroup()
222  .addContainerGap()
223  .addComponent(externalViewerTitleLabel)
224  .addContainerGap(428, Short.MAX_VALUE))
225  .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
226  .addGroup(jPanel1Layout.createSequentialGroup()
227  .addGap(32, 32, 32)
228  .addComponent(jScrollPane1)
229  .addContainerGap()))
230  );
231 
232  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
233  this.setLayout(layout);
234  layout.setHorizontalGroup(
235  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
236  .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
237  );
238  layout.setVerticalGroup(
239  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
240  .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
241  );
242  }// </editor-fold>//GEN-END:initComponents
243 
244  private void newRuleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_newRuleButtonActionPerformed
245  AddExternalViewerRuleDialog dialog = new AddExternalViewerRuleDialog();
246  AddExternalViewerRuleDialog.BUTTON_PRESSED result = dialog.getResult();
247  if (result == AddExternalViewerRuleDialog.BUTTON_PRESSED.OK) {
248  ExternalViewerRule newRule = dialog.getRule();
249  // Only allow one association for each MIME type or extension.
250  if (rules.contains(newRule)) {
251  JOptionPane.showMessageDialog(this,
252  NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class, "ExternalViewerGlobalSettingsPanel.JOptionPane.ruleAlreadyExists.message"),
253  NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class, "ExternalViewerGlobalSettingsPanel.JOptionPane.ruleAlreadyExists.title"),
254  JOptionPane.ERROR_MESSAGE);
255  } else {
256  rules.add(newRule);
257  updateRulesListModel();
258  int index = rules.indexOf(newRule);
259  rulesList.setSelectedIndex(index);
260  enableButtons();
261  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
262  }
263  }
264  }//GEN-LAST:event_newRuleButtonActionPerformed
265 
266  private void editRuleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editRuleButtonActionPerformed
267  int selected = rulesList.getSelectedIndex();
268  AddExternalViewerRuleDialog dialog = new AddExternalViewerRuleDialog(rulesListModel.get(rulesList.getSelectedIndex()));
269  AddExternalViewerRuleDialog.BUTTON_PRESSED result = dialog.getResult();
270  if (result == AddExternalViewerRuleDialog.BUTTON_PRESSED.OK) {
271  rules.remove(selected);
272  ExternalViewerRule newRule = dialog.getRule();
273  // Only allow one association for each MIME type or extension.
274  if (rules.contains(newRule)) {
275  JOptionPane.showMessageDialog(this,
276  NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class, "ExternalViewerGlobalSettingsPanel.JOptionPane.ruleAlreadyExists.message"),
277  NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class, "ExternalViewerGlobalSettingsPanel.JOptionPane.ruleAlreadyExists.title"),
278  JOptionPane.ERROR_MESSAGE);
279  } else {
280  rules.add(selected, dialog.getRule());
281  updateRulesListModel();
282  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
283  }
284  }
285  rulesList.setSelectedIndex(selected);
286  enableButtons();
287  }//GEN-LAST:event_editRuleButtonActionPerformed
288 
289  private void deleteRuleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteRuleButtonActionPerformed
290  ExternalViewerRule rule = rulesList.getSelectedValue();
291  rules.remove(rule);
292  updateRulesListModel();
293  firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
294  }//GEN-LAST:event_deleteRuleButtonActionPerformed
295 
296  @Override
297  public void store() {
298  ExternalViewerRulesManager.getInstance().setUserRules(rules);
299  }
300 
301  @Override
302  public void load() {
303  rules = ExternalViewerRulesManager.getInstance().getUserRules();
304  updateRulesListModel();
305  enableButtons();
306  }
307 
311  private void enableButtons() {
312  boolean ruleIsSelected = rulesList.getSelectedIndex() != -1;
313  editRuleButton.setEnabled(ruleIsSelected);
314  deleteRuleButton.setEnabled(ruleIsSelected);
315  }
316 
321  private void updateRulesListModel() {
322  rulesListModel.clear();
323  Collections.sort(rules);
324  for (ExternalViewerRule rule : rules) {
325  rulesListModel.addElement(rule);
326  }
327  }
328 
332  private void populateExePath() {
333  ExternalViewerRule rule = rulesList.getSelectedValue();
334  if (rule != null) {
335  if (rule.getRuleType() == ExternalViewerRule.RuleType.MIME) {
336  exePathLabel.setText(NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
337  "ExternalViewerGlobalSettingsPanel.exePathLabel.MIME.text"));
338  } else {
339  exePathLabel.setText(NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
340  "ExternalViewerGlobalSettingsPanel.exePathLabel.EXT.text"));
341  }
342  exePathNameLabel.setText(rule.getExePath());
343  }
344  enableButtons();
345  }
346 
350  private void clearExePath() {
351  rulesList.clearSelection();
352  exePathLabel.setText(NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
353  "ExternalViewerGlobalSettingsPanel.exePathLabel.text"));
354  exePathNameLabel.setText(NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
355  "ExternalViewerGlobalSettingsPanel.exePathLabel.empty.text"));
356  enableButtons();
357  }
358 
359  // Variables declaration - do not modify//GEN-BEGIN:variables
360  private javax.swing.JButton deleteRuleButton;
361  private javax.swing.JButton editRuleButton;
362  private javax.swing.JPanel exePanel;
363  private javax.swing.JLabel exePathLabel;
364  private javax.swing.JLabel exePathNameLabel;
365  private javax.swing.JLabel externalViewerTitleLabel;
366  private javax.swing.JPanel jPanel1;
367  private javax.swing.JScrollPane jScrollPane1;
368  private javax.swing.JScrollPane jScrollPane2;
369  private javax.swing.JSplitPane jSplitPane1;
370  private javax.swing.JButton newRuleButton;
371  private javax.swing.JLabel ruleListLabel;
372  private javax.swing.JList<ExternalViewerRule> rulesList;
373  private javax.swing.JPanel rulesPanel;
374  private javax.swing.JScrollPane rulesScrollPane;
375  // End of variables declaration//GEN-END:variables
376 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

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