19 package org.sleuthkit.autopsy.directorytree;
21 import java.awt.Color;
22 import java.awt.event.ActionListener;
24 import java.util.ArrayList;
25 import java.util.List;
26 import javax.swing.JFileChooser;
28 import javax.swing.JOptionPane;
29 import javax.swing.ListSelectionModel;
30 import javax.swing.event.ListSelectionEvent;
31 import org.openide.util.NbBundle;
32 import org.netbeans.spi.options.OptionsPanelController;
43 @SuppressWarnings(
"PMD.SingularField")
44 final class ExternalViewerGlobalSettingsPanel extends javax.swing.JPanel implements OptionsPanel {
46 private static final long serialVersionUID = 1L;
48 private ExternalViewerGlobalSettingsTableModel tableModel;
50 private final JFileChooserFactory chooserHelper =
new JFileChooserFactory();
52 ExternalViewerGlobalSettingsPanel() {
53 this(
new ExternalViewerGlobalSettingsTableModel(
new String[] {
54 "Mime type/Extension",
"Application"}));
60 ExternalViewerGlobalSettingsPanel(ExternalViewerGlobalSettingsTableModel tableModel) {
62 this.tableModel = tableModel;
63 customizeComponents(tableModel);
69 private void customizeComponents(ExternalViewerGlobalSettingsTableModel tableModel) {
70 ExternalViewerRulesTable.setModel(tableModel);
71 ExternalViewerRulesTable.setAutoCreateRowSorter(
true);
72 ExternalViewerRulesTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
73 ListSelectionModel selectionModel = ExternalViewerRulesTable.getSelectionModel();
75 selectionModel.addListSelectionListener((ListSelectionEvent selection) -> {
85 public void deleteRuleButtonClick(
int selectedIndex) {
86 setSelectionInterval(selectedIndex, selectedIndex);
87 deleteRuleButton.getListeners(ActionListener.class)[0].actionPerformed(null);
97 public void setSelectionInterval(
int startingIndex,
int endIndex) {
98 ExternalViewerRulesTable.getSelectionModel().setSelectionInterval(startingIndex, endIndex);
107 public boolean isSelected(
int index) {
108 return ExternalViewerRulesTable.getSelectionModel().isSelectedIndex(index);
116 @SuppressWarnings(
"unchecked")
118 private
void initComponents() {
120 newRuleButton1 =
new javax.swing.JButton();
121 jButton2 =
new javax.swing.JButton();
122 jPanel1 =
new javax.swing.JPanel();
123 jPanel2 =
new javax.swing.JPanel();
124 newRuleButton =
new javax.swing.JButton();
125 jScrollPane4 =
new javax.swing.JScrollPane();
126 ExternalViewerRulesTable =
new javax.swing.JTable();
127 externalViewerTitleLabel =
new javax.swing.JLabel();
128 deleteRuleButton =
new javax.swing.JButton();
129 editRuleButton =
new javax.swing.JButton();
130 jPanel3 =
new javax.swing.JPanel();
131 HxDPath =
new javax.swing.JTextField();
132 HxDLabel =
new javax.swing.JLabel();
133 ContentViewerExtensionLabel =
new javax.swing.JLabel();
134 browseHxDDirectory =
new javax.swing.JButton();
136 newRuleButton1.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/images/add16.png")));
137 org.openide.awt.Mnemonics.setLocalizedText(newRuleButton1,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.newRuleButton1.text"));
138 newRuleButton1.setMaximumSize(
new java.awt.Dimension(111, 25));
139 newRuleButton1.setMinimumSize(
new java.awt.Dimension(111, 25));
141 org.openide.awt.Mnemonics.setLocalizedText(jButton2,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.jButton2.text"));
143 setPreferredSize(
new java.awt.Dimension(701, 453));
145 jPanel1.setPreferredSize(
new java.awt.Dimension(701, 453));
147 newRuleButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/images/add16.png")));
148 org.openide.awt.Mnemonics.setLocalizedText(newRuleButton,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.newRuleButton.text"));
149 newRuleButton.setMaximumSize(
new java.awt.Dimension(111, 25));
150 newRuleButton.setMinimumSize(
new java.awt.Dimension(111, 25));
151 newRuleButton.addActionListener(
new java.awt.event.ActionListener() {
152 public void actionPerformed(java.awt.event.ActionEvent evt) {
153 newRuleButtonActionPerformed(evt);
157 jScrollPane4.setBorder(javax.swing.BorderFactory.createLineBorder(
new java.awt.Color(204, 204, 204)));
159 jScrollPane4.setViewportView(ExternalViewerRulesTable);
160 if (ExternalViewerRulesTable.getColumnModel().getColumnCount() > 0) {
161 ExternalViewerRulesTable.getColumnModel().getColumn(0).setHeaderValue(
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.ExternalViewerRulesTable.columnModel.title0"));
162 ExternalViewerRulesTable.getColumnModel().getColumn(1).setHeaderValue(
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.ExternalViewerRulesTable.columnModel.title1"));
165 org.openide.awt.Mnemonics.setLocalizedText(externalViewerTitleLabel,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.externalViewerTitleLabel.text"));
167 deleteRuleButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/images/delete16.png")));
168 org.openide.awt.Mnemonics.setLocalizedText(deleteRuleButton,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.deleteRuleButton.text"));
169 deleteRuleButton.setMaximumSize(
new java.awt.Dimension(111, 25));
170 deleteRuleButton.setMinimumSize(
new java.awt.Dimension(111, 25));
171 deleteRuleButton.addActionListener(
new java.awt.event.ActionListener() {
172 public void actionPerformed(java.awt.event.ActionEvent evt) {
173 deleteRuleButtonActionPerformed(evt);
177 editRuleButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/images/edit16.png")));
178 org.openide.awt.Mnemonics.setLocalizedText(editRuleButton,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.editRuleButton.text"));
179 editRuleButton.setMaximumSize(
new java.awt.Dimension(111, 25));
180 editRuleButton.setMinimumSize(
new java.awt.Dimension(111, 25));
181 editRuleButton.addActionListener(
new java.awt.event.ActionListener() {
182 public void actionPerformed(java.awt.event.ActionEvent evt) {
183 editRuleButtonActionPerformed(evt);
187 javax.swing.GroupLayout jPanel2Layout =
new javax.swing.GroupLayout(jPanel2);
188 jPanel2.setLayout(jPanel2Layout);
189 jPanel2Layout.setHorizontalGroup(
190 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
191 .addGroup(jPanel2Layout.createSequentialGroup()
193 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
194 .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 634, javax.swing.GroupLayout.PREFERRED_SIZE)
195 .addGroup(jPanel2Layout.createSequentialGroup()
196 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
197 .addComponent(externalViewerTitleLabel)
198 .addGroup(jPanel2Layout.createSequentialGroup()
199 .addComponent(newRuleButton, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
200 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
201 .addComponent(editRuleButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
202 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
203 .addComponent(deleteRuleButton, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)))
204 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
206 jPanel2Layout.setVerticalGroup(
207 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
208 .addGroup(jPanel2Layout.createSequentialGroup()
209 .addComponent(externalViewerTitleLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
211 .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
212 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
213 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
214 .addComponent(newRuleButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
215 .addComponent(editRuleButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
216 .addComponent(deleteRuleButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
220 HxDPath.setEditable(
false);
222 org.openide.awt.Mnemonics.setLocalizedText(HxDLabel,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.HxDLabel.text"));
224 org.openide.awt.Mnemonics.setLocalizedText(ContentViewerExtensionLabel,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.ContentViewerExtensionLabel.text"));
226 org.openide.awt.Mnemonics.setLocalizedText(browseHxDDirectory,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.browseHxDDirectory.text"));
227 browseHxDDirectory.addActionListener(
new java.awt.event.ActionListener() {
228 public void actionPerformed(java.awt.event.ActionEvent evt) {
229 browseHxDDirectoryActionPerformed(evt);
233 javax.swing.GroupLayout jPanel3Layout =
new javax.swing.GroupLayout(jPanel3);
234 jPanel3.setLayout(jPanel3Layout);
235 jPanel3Layout.setHorizontalGroup(
236 jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
237 .addGroup(jPanel3Layout.createSequentialGroup()
238 .addComponent(ContentViewerExtensionLabel)
239 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
240 .addGroup(jPanel3Layout.createSequentialGroup()
242 .addComponent(HxDLabel)
243 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
244 .addComponent(HxDPath, javax.swing.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
245 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
246 .addComponent(browseHxDDirectory, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
248 jPanel3Layout.setVerticalGroup(
249 jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
250 .addGroup(jPanel3Layout.createSequentialGroup()
251 .addComponent(ContentViewerExtensionLabel)
252 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
253 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
254 .addComponent(HxDPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
255 .addComponent(HxDLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
256 .addComponent(browseHxDDirectory))
257 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
260 browseHxDDirectory.setEnabled(PlatformUtil.isWindowsOS());
262 javax.swing.GroupLayout jPanel1Layout =
new javax.swing.GroupLayout(jPanel1);
263 jPanel1.setLayout(jPanel1Layout);
264 jPanel1Layout.setHorizontalGroup(
265 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
266 .addGroup(jPanel1Layout.createSequentialGroup()
267 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
268 .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
269 .addGroup(jPanel1Layout.createSequentialGroup()
271 .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
272 .addGap(547, 547, 547))
274 jPanel1Layout.setVerticalGroup(
275 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
276 .addGroup(jPanel1Layout.createSequentialGroup()
278 .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
280 .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
281 .addContainerGap(83, Short.MAX_VALUE))
284 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
285 this.setLayout(layout);
286 layout.setHorizontalGroup(
287 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
288 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 1191, Short.MAX_VALUE)
290 layout.setVerticalGroup(
291 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
292 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
296 private void newRuleButtonActionPerformed(java.awt.event.ActionEvent evt) {
297 AddExternalViewerRuleDialog dialog =
new AddExternalViewerRuleDialog();
298 AddExternalViewerRuleDialog.BUTTON_PRESSED result = dialog.getResult();
299 if (result == AddExternalViewerRuleDialog.BUTTON_PRESSED.OK) {
300 ExternalViewerRule newRule = dialog.getRule();
302 if (tableModel.containsRule(newRule)) {
303 JOptionPane.showMessageDialog(
this,
304 NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.JOptionPane.ruleAlreadyExists.message"),
305 NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.JOptionPane.ruleAlreadyExists.title"),
306 JOptionPane.ERROR_MESSAGE);
308 tableModel.addRule(newRule);
310 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
315 private void editRuleButtonActionPerformed(java.awt.event.ActionEvent evt) {
316 int selectedIndex = ExternalViewerRulesTable.convertRowIndexToModel(ExternalViewerRulesTable.getSelectedRow());
317 ExternalViewerRule selectedRule = tableModel.getRuleAt(selectedIndex);
318 AddExternalViewerRuleDialog dialog =
new AddExternalViewerRuleDialog(selectedRule);
319 AddExternalViewerRuleDialog.BUTTON_PRESSED result = dialog.getResult();
320 if (result == AddExternalViewerRuleDialog.BUTTON_PRESSED.OK) {
321 ExternalViewerRule newRule = dialog.getRule();
323 if (tableModel.containsRule(newRule)) {
324 JOptionPane.showMessageDialog(
this,
325 NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.JOptionPane.ruleAlreadyExists.message"),
326 NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.JOptionPane.ruleAlreadyExists.title"),
327 JOptionPane.ERROR_MESSAGE);
329 tableModel.setRule(selectedIndex, dialog.getRule());
330 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
335 private void deleteRuleButtonActionPerformed(java.awt.event.ActionEvent evt) {
336 tableModel.removeRule(ExternalViewerRulesTable.convertRowIndexToModel(ExternalViewerRulesTable.getSelectedRow()));
337 ExternalViewerRulesTable.getSelectionModel().clearSelection();
339 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
342 private void browseHxDDirectoryActionPerformed(java.awt.event.ActionEvent evt) {
343 JFileChooser fileWindow = chooserHelper.getChooser();
344 fileWindow.setFileSelectionMode(JFileChooser.FILES_ONLY);
345 GeneralFilter exeFilter =
new GeneralFilter(GeneralFilter.EXECUTABLE_EXTS, GeneralFilter.EXECUTABLE_DESC);
346 File HxDPathFile =
new File(HxDPath.getText());
347 if(HxDPathFile.exists() && HxDPathFile.canExecute()) {
348 fileWindow.setCurrentDirectory(
new File(HxDPath.getText()));
350 fileWindow.setDragEnabled(
false);
351 fileWindow.setFileFilter(exeFilter);
352 fileWindow.setMultiSelectionEnabled(
false);
353 int returnVal = fileWindow.showSaveDialog(
this);
354 if(returnVal == JFileChooser.APPROVE_OPTION) {
355 File HxDExecutable = fileWindow.getSelectedFile();
356 HxDPath.setForeground(Color.BLACK);
357 HxDPath.setText(HxDExecutable.getAbsolutePath());
358 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
363 public void store() {
365 List<ExternalViewerRule> rules =
new ArrayList<>();
366 for(
int i = 0; i < tableModel.getRowCount(); i++) {
367 rules.add(tableModel.getRuleAt(i));
369 ExternalViewerRulesManager.getInstance().setUserRules(rules);
370 UserPreferences.setExternalHexEditorPath(HxDPath.getText());
375 List<ExternalViewerRule> rules = ExternalViewerRulesManager.getInstance().getUserRules();
376 for(ExternalViewerRule rule : rules) {
377 if(!tableModel.containsRule(rule)) {
378 tableModel.addRule(rule);
381 String editorPath = UserPreferences.getExternalHexEditorPath();
382 File HdXExecutable =
new File(editorPath);
383 if(HdXExecutable.exists() || HdXExecutable.canExecute()) {
384 HxDPath.setText(editorPath);
386 HxDPath.setForeground(Color.RED);
387 HxDPath.setText(editorPath);
395 boolean enableButtons() {
396 boolean ruleIsSelected = ExternalViewerRulesTable.getSelectedRow() >= 0;
397 editRuleButton.setEnabled(ruleIsSelected);
398 deleteRuleButton.setEnabled(ruleIsSelected);
399 return ruleIsSelected;
403 private javax.swing.JLabel ContentViewerExtensionLabel;
404 private javax.swing.JTable ExternalViewerRulesTable;
405 private javax.swing.JLabel HxDLabel;
406 private javax.swing.JTextField HxDPath;
407 private javax.swing.JButton browseHxDDirectory;
408 private javax.swing.JButton deleteRuleButton;
409 private javax.swing.JButton editRuleButton;
410 private javax.swing.JLabel externalViewerTitleLabel;
411 private javax.swing.JButton jButton2;
412 private javax.swing.JPanel jPanel1;
413 private javax.swing.JPanel jPanel2;
414 private javax.swing.JPanel jPanel3;
415 private javax.swing.JScrollPane jScrollPane4;
416 private javax.swing.JButton newRuleButton;
417 private javax.swing.JButton newRuleButton1;