19 package org.sleuthkit.autopsy.directorytree;
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;
37 @SuppressWarnings(
"PMD.SingularField")
38 final class ExternalViewerGlobalSettingsPanel extends javax.swing.JPanel implements OptionsPanel {
40 private static final Logger logger = Logger.
getLogger(ExternalViewerGlobalSettingsPanel.class.getName());
41 private DefaultListModel<ExternalViewerRule> rulesListModel;
42 private java.util.List<ExternalViewerRule> rules;
47 public ExternalViewerGlobalSettingsPanel() {
49 customizeComponents();
55 private void customizeComponents() {
56 rulesListModel =
new DefaultListModel<>();
57 rules =
new ArrayList<>();
58 rulesList.setModel(rulesListModel);
59 rulesList.addListSelectionListener(
new ListSelectionListener() {
61 public void valueChanged(ListSelectionEvent e) {
62 if (e.getValueIsAdjusting() ==
false) {
63 if (rulesList.getSelectedIndex() == -1) {
78 @SuppressWarnings(
"unchecked")
80 private
void initComponents() {
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<>();
97 setPreferredSize(
new java.awt.Dimension(701, 453));
99 jPanel1.setPreferredSize(
new java.awt.Dimension(701, 453));
101 org.openide.awt.Mnemonics.setLocalizedText(externalViewerTitleLabel,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.externalViewerTitleLabel.text"));
103 jSplitPane1.setDividerSize(1);
105 exePanel.setPreferredSize(
new java.awt.Dimension(311, 224));
107 org.openide.awt.Mnemonics.setLocalizedText(exePathLabel,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.exePathLabel.text"));
109 org.openide.awt.Mnemonics.setLocalizedText(exePathNameLabel,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.exePathNameLabel.text"));
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()
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))
122 exePanelLayout.setVerticalGroup(
123 exePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
124 .addGroup(exePanelLayout.createSequentialGroup()
126 .addComponent(exePathLabel)
127 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
128 .addComponent(exePathNameLabel)
129 .addContainerGap(355, Short.MAX_VALUE))
132 jSplitPane1.setRightComponent(exePanel);
134 org.openide.awt.Mnemonics.setLocalizedText(ruleListLabel,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.ruleListLabel.text"));
136 newRuleButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/images/add16.png")));
137 org.openide.awt.Mnemonics.setLocalizedText(newRuleButton,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.newRuleButton.text"));
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);
146 editRuleButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/images/edit16.png")));
147 org.openide.awt.Mnemonics.setLocalizedText(editRuleButton,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.editRuleButton.text"));
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);
156 deleteRuleButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/images/delete16.png")));
157 org.openide.awt.Mnemonics.setLocalizedText(deleteRuleButton,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.deleteRuleButton.text"));
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);
166 jScrollPane2.setViewportView(rulesList);
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()
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()
178 .addComponent(newRuleButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
180 .addComponent(editRuleButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
182 .addComponent(deleteRuleButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
183 .addComponent(jScrollPane2))
186 rulesPanelLayout.setVerticalGroup(
187 rulesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
188 .addGroup(rulesPanelLayout.createSequentialGroup()
190 .addComponent(ruleListLabel)
191 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
192 .addComponent(jScrollPane2)
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))
201 jSplitPane1.setLeftComponent(rulesPanel);
203 jScrollPane1.setViewportView(jSplitPane1);
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()
211 .addComponent(externalViewerTitleLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 681, Short.MAX_VALUE)
213 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
214 .addGroup(jPanel1Layout.createSequentialGroup()
216 .addComponent(jScrollPane1)
219 jPanel1Layout.setVerticalGroup(
220 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
221 .addGroup(jPanel1Layout.createSequentialGroup()
223 .addComponent(externalViewerTitleLabel)
224 .addContainerGap(428, Short.MAX_VALUE))
225 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
226 .addGroup(jPanel1Layout.createSequentialGroup()
228 .addComponent(jScrollPane1)
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)
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)
244 private void newRuleButtonActionPerformed(java.awt.event.ActionEvent evt) {
245 AddExternalViewerRuleDialog dialog =
new AddExternalViewerRuleDialog();
246 AddExternalViewerRuleDialog.BUTTON_PRESSED result = dialog.getResult();
247 if (result == AddExternalViewerRuleDialog.BUTTON_PRESSED.OK) {
248 ExternalViewerRule newRule = dialog.getRule();
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);
257 updateRulesListModel();
258 int index = rules.indexOf(newRule);
259 rulesList.setSelectedIndex(index);
261 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
266 private void editRuleButtonActionPerformed(java.awt.event.ActionEvent evt) {
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();
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);
280 rules.add(selected, dialog.getRule());
281 updateRulesListModel();
282 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
285 rulesList.setSelectedIndex(selected);
289 private void deleteRuleButtonActionPerformed(java.awt.event.ActionEvent evt) {
290 ExternalViewerRule rule = rulesList.getSelectedValue();
292 updateRulesListModel();
293 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
297 public void store() {
298 ExternalViewerRulesManager.getInstance().setUserRules(rules);
303 rules = ExternalViewerRulesManager.getInstance().getUserRules();
304 updateRulesListModel();
311 private void enableButtons() {
312 boolean ruleIsSelected = rulesList.getSelectedIndex() != -1;
313 editRuleButton.setEnabled(ruleIsSelected);
314 deleteRuleButton.setEnabled(ruleIsSelected);
321 private void updateRulesListModel() {
322 rulesListModel.clear();
323 Collections.sort(rules);
324 for (ExternalViewerRule rule : rules) {
325 rulesListModel.addElement(rule);
332 private void populateExePath() {
333 ExternalViewerRule rule = rulesList.getSelectedValue();
335 if (rule.getRuleType() == ExternalViewerRule.RuleType.MIME) {
336 exePathLabel.setText(NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
337 "ExternalViewerGlobalSettingsPanel.exePathLabel.MIME.text"));
339 exePathLabel.setText(NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
340 "ExternalViewerGlobalSettingsPanel.exePathLabel.EXT.text"));
342 exePathNameLabel.setText(rule.getExePath());
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"));
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;
synchronized static Logger getLogger(String name)