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;
42 @SuppressWarnings(
"PMD.SingularField")
43 final class ExternalViewerGlobalSettingsPanel extends javax.swing.JPanel implements OptionsPanel {
45 private ExternalViewerGlobalSettingsTableModel tableModel;
47 public ExternalViewerGlobalSettingsPanel() {
48 this(
new ExternalViewerGlobalSettingsTableModel(
new String[] {
49 "Mime type/Extension",
"Application"}));
55 public ExternalViewerGlobalSettingsPanel(ExternalViewerGlobalSettingsTableModel tableModel) {
57 this.tableModel = tableModel;
58 customizeComponents(tableModel);
64 private void customizeComponents(ExternalViewerGlobalSettingsTableModel tableModel) {
65 ExternalViewerRulesTable.setModel(tableModel);
66 ExternalViewerRulesTable.setAutoCreateRowSorter(
true);
67 ExternalViewerRulesTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
68 ListSelectionModel selectionModel = ExternalViewerRulesTable.getSelectionModel();
70 selectionModel.addListSelectionListener((ListSelectionEvent selection) -> {
80 public void deleteRuleButtonClick(
int selectedIndex) {
81 setSelectionInterval(selectedIndex, selectedIndex);
82 deleteRuleButton.getListeners(ActionListener.class)[0].actionPerformed(null);
92 public void setSelectionInterval(
int startingIndex,
int endIndex) {
93 ExternalViewerRulesTable.getSelectionModel().setSelectionInterval(startingIndex, endIndex);
102 public boolean isSelected(
int index) {
103 return ExternalViewerRulesTable.getSelectionModel().isSelectedIndex(index);
111 @SuppressWarnings(
"unchecked")
113 private
void initComponents() {
115 newRuleButton1 =
new javax.swing.JButton();
116 jButton2 =
new javax.swing.JButton();
117 jPanel1 =
new javax.swing.JPanel();
118 jPanel2 =
new javax.swing.JPanel();
119 newRuleButton =
new javax.swing.JButton();
120 jScrollPane4 =
new javax.swing.JScrollPane();
121 ExternalViewerRulesTable =
new javax.swing.JTable();
122 externalViewerTitleLabel =
new javax.swing.JLabel();
123 deleteRuleButton =
new javax.swing.JButton();
124 editRuleButton =
new javax.swing.JButton();
125 jPanel3 =
new javax.swing.JPanel();
126 HxDPath =
new javax.swing.JTextField();
127 HxDLabel =
new javax.swing.JLabel();
128 ContentViewerExtensionLabel =
new javax.swing.JLabel();
129 browseHxDDirectory =
new javax.swing.JButton();
131 newRuleButton1.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/images/add16.png")));
132 org.openide.awt.Mnemonics.setLocalizedText(newRuleButton1,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.newRuleButton1.text"));
133 newRuleButton1.setMaximumSize(
new java.awt.Dimension(111, 25));
134 newRuleButton1.setMinimumSize(
new java.awt.Dimension(111, 25));
136 org.openide.awt.Mnemonics.setLocalizedText(jButton2,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.jButton2.text"));
138 setPreferredSize(
new java.awt.Dimension(701, 453));
140 jPanel1.setPreferredSize(
new java.awt.Dimension(701, 453));
142 newRuleButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/images/add16.png")));
143 org.openide.awt.Mnemonics.setLocalizedText(newRuleButton,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.newRuleButton.text"));
144 newRuleButton.setMaximumSize(
new java.awt.Dimension(111, 25));
145 newRuleButton.setMinimumSize(
new java.awt.Dimension(111, 25));
146 newRuleButton.addActionListener(
new java.awt.event.ActionListener() {
147 public void actionPerformed(java.awt.event.ActionEvent evt) {
148 newRuleButtonActionPerformed(evt);
152 jScrollPane4.setBorder(javax.swing.BorderFactory.createLineBorder(
new java.awt.Color(204, 204, 204)));
154 jScrollPane4.setViewportView(ExternalViewerRulesTable);
155 if (ExternalViewerRulesTable.getColumnModel().getColumnCount() > 0) {
156 ExternalViewerRulesTable.getColumnModel().getColumn(0).setHeaderValue(
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.ExternalViewerRulesTable.columnModel.title0"));
157 ExternalViewerRulesTable.getColumnModel().getColumn(1).setHeaderValue(
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.ExternalViewerRulesTable.columnModel.title1"));
160 org.openide.awt.Mnemonics.setLocalizedText(externalViewerTitleLabel,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.externalViewerTitleLabel.text"));
162 deleteRuleButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/images/delete16.png")));
163 org.openide.awt.Mnemonics.setLocalizedText(deleteRuleButton,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.deleteRuleButton.text"));
164 deleteRuleButton.setMaximumSize(
new java.awt.Dimension(111, 25));
165 deleteRuleButton.setMinimumSize(
new java.awt.Dimension(111, 25));
166 deleteRuleButton.addActionListener(
new java.awt.event.ActionListener() {
167 public void actionPerformed(java.awt.event.ActionEvent evt) {
168 deleteRuleButtonActionPerformed(evt);
172 editRuleButton.setIcon(
new javax.swing.ImageIcon(getClass().getResource(
"/org/sleuthkit/autopsy/images/edit16.png")));
173 org.openide.awt.Mnemonics.setLocalizedText(editRuleButton,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.editRuleButton.text"));
174 editRuleButton.setMaximumSize(
new java.awt.Dimension(111, 25));
175 editRuleButton.setMinimumSize(
new java.awt.Dimension(111, 25));
176 editRuleButton.addActionListener(
new java.awt.event.ActionListener() {
177 public void actionPerformed(java.awt.event.ActionEvent evt) {
178 editRuleButtonActionPerformed(evt);
182 javax.swing.GroupLayout jPanel2Layout =
new javax.swing.GroupLayout(jPanel2);
183 jPanel2.setLayout(jPanel2Layout);
184 jPanel2Layout.setHorizontalGroup(
185 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
186 .addGroup(jPanel2Layout.createSequentialGroup()
188 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
189 .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 634, javax.swing.GroupLayout.PREFERRED_SIZE)
190 .addGroup(jPanel2Layout.createSequentialGroup()
191 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
192 .addComponent(externalViewerTitleLabel)
193 .addGroup(jPanel2Layout.createSequentialGroup()
194 .addComponent(newRuleButton, javax.swing.GroupLayout.PREFERRED_SIZE, 97, javax.swing.GroupLayout.PREFERRED_SIZE)
195 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
196 .addComponent(editRuleButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
197 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
198 .addComponent(deleteRuleButton, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE)))
199 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
201 jPanel2Layout.setVerticalGroup(
202 jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
203 .addGroup(jPanel2Layout.createSequentialGroup()
204 .addComponent(externalViewerTitleLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
206 .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
207 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
208 .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
209 .addComponent(newRuleButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
210 .addComponent(editRuleButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
211 .addComponent(deleteRuleButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
215 HxDPath.setEditable(
false);
217 org.openide.awt.Mnemonics.setLocalizedText(HxDLabel,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.HxDLabel.text"));
219 org.openide.awt.Mnemonics.setLocalizedText(ContentViewerExtensionLabel,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.ContentViewerExtensionLabel.text"));
221 org.openide.awt.Mnemonics.setLocalizedText(browseHxDDirectory,
org.openide.util.NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.browseHxDDirectory.text"));
222 browseHxDDirectory.addActionListener(
new java.awt.event.ActionListener() {
223 public void actionPerformed(java.awt.event.ActionEvent evt) {
224 browseHxDDirectoryActionPerformed(evt);
228 javax.swing.GroupLayout jPanel3Layout =
new javax.swing.GroupLayout(jPanel3);
229 jPanel3.setLayout(jPanel3Layout);
230 jPanel3Layout.setHorizontalGroup(
231 jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
232 .addGroup(jPanel3Layout.createSequentialGroup()
233 .addComponent(ContentViewerExtensionLabel)
234 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
235 .addGroup(jPanel3Layout.createSequentialGroup()
237 .addComponent(HxDLabel)
238 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
239 .addComponent(HxDPath, javax.swing.GroupLayout.DEFAULT_SIZE, 441, Short.MAX_VALUE)
240 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
241 .addComponent(browseHxDDirectory, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
243 jPanel3Layout.setVerticalGroup(
244 jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
245 .addGroup(jPanel3Layout.createSequentialGroup()
246 .addComponent(ContentViewerExtensionLabel)
247 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
248 .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
249 .addComponent(HxDPath, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
250 .addComponent(HxDLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
251 .addComponent(browseHxDDirectory))
252 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
255 browseHxDDirectory.setEnabled(PlatformUtil.isWindowsOS());
257 javax.swing.GroupLayout jPanel1Layout =
new javax.swing.GroupLayout(jPanel1);
258 jPanel1.setLayout(jPanel1Layout);
259 jPanel1Layout.setHorizontalGroup(
260 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
261 .addGroup(jPanel1Layout.createSequentialGroup()
262 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
263 .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
264 .addGroup(jPanel1Layout.createSequentialGroup()
266 .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
267 .addGap(547, 547, 547))
269 jPanel1Layout.setVerticalGroup(
270 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
271 .addGroup(jPanel1Layout.createSequentialGroup()
273 .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
275 .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
276 .addContainerGap(83, Short.MAX_VALUE))
279 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
280 this.setLayout(layout);
281 layout.setHorizontalGroup(
282 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
283 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 1191, Short.MAX_VALUE)
285 layout.setVerticalGroup(
286 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
287 .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
291 private void newRuleButtonActionPerformed(java.awt.event.ActionEvent evt) {
292 AddExternalViewerRuleDialog dialog =
new AddExternalViewerRuleDialog();
293 AddExternalViewerRuleDialog.BUTTON_PRESSED result = dialog.getResult();
294 if (result == AddExternalViewerRuleDialog.BUTTON_PRESSED.OK) {
295 ExternalViewerRule newRule = dialog.getRule();
297 if (tableModel.containsRule(newRule)) {
298 JOptionPane.showMessageDialog(
this,
299 NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.JOptionPane.ruleAlreadyExists.message"),
300 NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.JOptionPane.ruleAlreadyExists.title"),
301 JOptionPane.ERROR_MESSAGE);
303 tableModel.addRule(newRule);
305 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
310 private void editRuleButtonActionPerformed(java.awt.event.ActionEvent evt) {
311 int selectedIndex = ExternalViewerRulesTable.convertRowIndexToModel(ExternalViewerRulesTable.getSelectedRow());
312 ExternalViewerRule selectedRule = tableModel.getRuleAt(selectedIndex);
313 AddExternalViewerRuleDialog dialog =
new AddExternalViewerRuleDialog(selectedRule);
314 AddExternalViewerRuleDialog.BUTTON_PRESSED result = dialog.getResult();
315 if (result == AddExternalViewerRuleDialog.BUTTON_PRESSED.OK) {
316 ExternalViewerRule newRule = dialog.getRule();
318 if (tableModel.containsRule(newRule)) {
319 JOptionPane.showMessageDialog(
this,
320 NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.JOptionPane.ruleAlreadyExists.message"),
321 NbBundle.getMessage(ExternalViewerGlobalSettingsPanel.class,
"ExternalViewerGlobalSettingsPanel.JOptionPane.ruleAlreadyExists.title"),
322 JOptionPane.ERROR_MESSAGE);
324 tableModel.setRule(selectedIndex, dialog.getRule());
325 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
330 private void deleteRuleButtonActionPerformed(java.awt.event.ActionEvent evt) {
331 tableModel.removeRule(ExternalViewerRulesTable.convertRowIndexToModel(ExternalViewerRulesTable.getSelectedRow()));
332 ExternalViewerRulesTable.getSelectionModel().clearSelection();
334 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
337 private void browseHxDDirectoryActionPerformed(java.awt.event.ActionEvent evt) {
338 JFileChooser fileWindow =
new JFileChooser();
339 fileWindow.setFileSelectionMode(JFileChooser.FILES_ONLY);
340 GeneralFilter exeFilter =
new GeneralFilter(GeneralFilter.EXECUTABLE_EXTS, GeneralFilter.EXECUTABLE_DESC);
341 File HxDPathFile =
new File(HxDPath.getText());
342 if(HxDPathFile.exists() && HxDPathFile.canExecute()) {
343 fileWindow.setCurrentDirectory(
new File(HxDPath.getText()));
345 fileWindow.setDragEnabled(
false);
346 fileWindow.setFileFilter(exeFilter);
347 fileWindow.setMultiSelectionEnabled(
false);
348 int returnVal = fileWindow.showSaveDialog(
this);
349 if(returnVal == JFileChooser.APPROVE_OPTION) {
350 File HxDExecutable = fileWindow.getSelectedFile();
351 HxDPath.setForeground(Color.BLACK);
352 HxDPath.setText(HxDExecutable.getAbsolutePath());
353 firePropertyChange(OptionsPanelController.PROP_CHANGED, null, null);
358 public void store() {
360 List<ExternalViewerRule> rules =
new ArrayList<>();
361 for(
int i = 0; i < tableModel.getRowCount(); i++) {
362 rules.add(tableModel.getRuleAt(i));
364 ExternalViewerRulesManager.getInstance().setUserRules(rules);
365 UserPreferences.setExternalHexEditorPath(HxDPath.getText());
370 List<ExternalViewerRule> rules = ExternalViewerRulesManager.getInstance().getUserRules();
371 for(ExternalViewerRule rule : rules) {
372 if(!tableModel.containsRule(rule)) {
373 tableModel.addRule(rule);
376 String editorPath = UserPreferences.getExternalHexEditorPath();
377 File HdXExecutable =
new File(editorPath);
378 if(HdXExecutable.exists() || HdXExecutable.canExecute()) {
379 HxDPath.setText(editorPath);
381 HxDPath.setForeground(Color.RED);
382 HxDPath.setText(editorPath);
390 boolean enableButtons() {
391 boolean ruleIsSelected = ExternalViewerRulesTable.getSelectedRow() >= 0;
392 editRuleButton.setEnabled(ruleIsSelected);
393 deleteRuleButton.setEnabled(ruleIsSelected);
394 return ruleIsSelected;
398 private javax.swing.JLabel ContentViewerExtensionLabel;
399 private javax.swing.JTable ExternalViewerRulesTable;
400 private javax.swing.JLabel HxDLabel;
401 private javax.swing.JTextField HxDPath;
402 private javax.swing.JButton browseHxDDirectory;
403 private javax.swing.JButton deleteRuleButton;
404 private javax.swing.JButton editRuleButton;
405 private javax.swing.JLabel externalViewerTitleLabel;
406 private javax.swing.JButton jButton2;
407 private javax.swing.JPanel jPanel1;
408 private javax.swing.JPanel jPanel2;
409 private javax.swing.JPanel jPanel3;
410 private javax.swing.JScrollPane jScrollPane4;
411 private javax.swing.JButton newRuleButton;
412 private javax.swing.JButton newRuleButton1;