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 class AddExternalViewerRuleDialog
extends JDialog {
40 private ExternalViewerRule rule;
41 private final AddExternalViewerRulePanel addRulePanel;
42 private BUTTON_PRESSED result;
43 private JButton saveButton;
44 private JButton closeButton;
53 AddExternalViewerRuleDialog() {
54 super(
new JFrame(NbBundle.getMessage(AddExternalViewerRuleDialog.class,
"AddExternalViewerRuleDialog.title")),
55 NbBundle.getMessage(AddExternalViewerRuleDialog.class,
"AddExternalViewerRuleDialog.title"),
true);
56 addRulePanel =
new AddExternalViewerRulePanel();
65 AddExternalViewerRuleDialog(ExternalViewerRule rule) {
66 super(
new JFrame(NbBundle.getMessage(AddExternalViewerRuleDialog.class,
"AddExternalViewerRuleDialog.title")),
67 NbBundle.getMessage(AddExternalViewerRuleDialog.class,
"AddExternalViewerRuleDialog.title"),
true);
68 addRulePanel =
new AddExternalViewerRulePanel(rule);
75 private void display() {
76 setLayout(
new BorderLayout());
81 setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
83 add(this.addRulePanel, BorderLayout.PAGE_START);
86 saveButton =
new JButton(NbBundle.getMessage(AddExternalViewerRuleDialog.class,
"AddExternalViewerRuleDialog.saveButton.title"));
87 saveButton.addActionListener((ActionEvent e) -> {
92 closeButton =
new JButton(NbBundle.getMessage(AddExternalViewerRuleDialog.class,
"AddExternalViewerRuleDialog.cancelButton.title"));
93 closeButton.addActionListener((ActionEvent e) -> {
94 doButtonAction(
false);
98 JPanel buttonPanel =
new JPanel();
99 buttonPanel.setLayout(
new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
100 buttonPanel.add(
new javax.swing.Box.Filler(
new Dimension(10, 10),
new Dimension(10, 10),
new Dimension(10, 10)));
101 buttonPanel.add(saveButton);
102 buttonPanel.add(
new javax.swing.Box.Filler(
new Dimension(10, 10),
new Dimension(10, 10),
new Dimension(10, 10)));
103 buttonPanel.add(closeButton);
104 add(buttonPanel, BorderLayout.LINE_START);
110 this.addWindowListener(
new WindowAdapter() {
112 public void windowClosing(WindowEvent e) {
113 doButtonAction(
false);
121 this.addRulePanel.addPropertyChangeListener((PropertyChangeEvent evt) -> {
122 if (evt.getPropertyName().equals(AddExternalViewerRulePanel.EVENT.CHANGED.toString())) {
142 private void doButtonAction(
boolean savePressed) {
144 ExternalViewerRule ruleFromPanel = addRulePanel.getRule();
145 if (null != ruleFromPanel) {
146 this.rule = ruleFromPanel;
147 this.result = BUTTON_PRESSED.OK;
152 this.result = BUTTON_PRESSED.CANCEL;
162 ExternalViewerRule getRule() {
171 BUTTON_PRESSED getResult() {
179 private void enableSaveButton() {
180 this.saveButton.setEnabled(addRulePanel.hasFields());
181 getRootPane().setDefaultButton(saveButton);