19 package org.sleuthkit.autopsy.directorytree;
21 import java.awt.BorderLayout;
22 import java.awt.Dimension;
23 import java.awt.event.ActionEvent;
24 import java.awt.event.WindowAdapter;
25 import java.awt.event.WindowEvent;
26 import java.beans.PropertyChangeEvent;
27 import javax.swing.BoxLayout;
28 import javax.swing.JButton;
29 import javax.swing.JDialog;
30 import javax.swing.JFrame;
31 import javax.swing.JPanel;
32 import org.openide.util.NbBundle;
33 import org.openide.windows.WindowManager;
38 @SuppressWarnings(
"PMD.SingularField")
39 class AddExternalViewerRuleDialog extends JDialog {
41 private ExternalViewerRule rule;
42 private final AddExternalViewerRulePanel addRulePanel;
43 private BUTTON_PRESSED result;
44 private JButton saveButton;
45 private JButton closeButton;
54 AddExternalViewerRuleDialog() {
55 super(
new JFrame(NbBundle.getMessage(AddExternalViewerRuleDialog.class,
"AddExternalViewerRuleDialog.title")),
56 NbBundle.getMessage(AddExternalViewerRuleDialog.class,
"AddExternalViewerRuleDialog.title"),
true);
57 addRulePanel =
new AddExternalViewerRulePanel();
66 AddExternalViewerRuleDialog(ExternalViewerRule rule) {
67 super(
new JFrame(NbBundle.getMessage(AddExternalViewerRuleDialog.class,
"AddExternalViewerRuleDialog.title")),
68 NbBundle.getMessage(AddExternalViewerRuleDialog.class,
"AddExternalViewerRuleDialog.title"),
true);
69 addRulePanel =
new AddExternalViewerRulePanel(rule);
76 private void display() {
77 setLayout(
new BorderLayout());
82 setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
84 add(this.addRulePanel, BorderLayout.PAGE_START);
87 saveButton =
new JButton(NbBundle.getMessage(AddExternalViewerRuleDialog.class,
"AddExternalViewerRuleDialog.saveButton.title"));
88 saveButton.addActionListener((ActionEvent e) -> {
93 closeButton =
new JButton(NbBundle.getMessage(AddExternalViewerRuleDialog.class,
"AddExternalViewerRuleDialog.cancelButton.title"));
94 closeButton.addActionListener((ActionEvent e) -> {
95 doButtonAction(
false);
99 JPanel buttonPanel =
new JPanel();
100 buttonPanel.setLayout(
new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
101 buttonPanel.add(
new javax.swing.Box.Filler(
new Dimension(10, 10),
new Dimension(10, 10),
new Dimension(10, 10)));
102 buttonPanel.add(saveButton);
103 buttonPanel.add(
new javax.swing.Box.Filler(
new Dimension(10, 10),
new Dimension(10, 10),
new Dimension(10, 10)));
104 buttonPanel.add(closeButton);
105 add(buttonPanel, BorderLayout.LINE_START);
111 this.addWindowListener(
new WindowAdapter() {
113 public void windowClosing(WindowEvent e) {
114 doButtonAction(
false);
122 this.addRulePanel.addPropertyChangeListener((PropertyChangeEvent evt) -> {
123 if (evt.getPropertyName().equals(AddExternalViewerRulePanel.EVENT.CHANGED.toString())) {
143 private void doButtonAction(
boolean savePressed) {
145 ExternalViewerRule ruleFromPanel = addRulePanel.getRule();
146 if (null != ruleFromPanel) {
147 this.rule = ruleFromPanel;
148 this.result = BUTTON_PRESSED.OK;
153 this.result = BUTTON_PRESSED.CANCEL;
163 ExternalViewerRule getRule() {
172 BUTTON_PRESSED getResult() {
180 private void enableSaveButton() {
181 this.saveButton.setEnabled(addRulePanel.hasFields());
182 getRootPane().setDefaultButton(saveButton);