19 package org.sleuthkit.autopsy.directorytree;
21 import java.awt.BorderLayout;
22 import java.awt.Dimension;
23 import java.awt.Toolkit;
24 import java.awt.event.ActionEvent;
25 import java.awt.event.WindowAdapter;
26 import java.awt.event.WindowEvent;
27 import java.beans.PropertyChangeEvent;
28 import javax.swing.BoxLayout;
29 import javax.swing.JButton;
30 import javax.swing.JDialog;
31 import javax.swing.JFrame;
32 import javax.swing.JPanel;
33 import org.openide.util.NbBundle;
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 Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
82 int width = this.getSize().width;
83 int height = this.getSize().height;
84 setLocation((screenDimension.width - width) / 2, (screenDimension.height - height) / 2);
86 add(this.addRulePanel, BorderLayout.PAGE_START);
89 saveButton =
new JButton(NbBundle.getMessage(AddExternalViewerRuleDialog.class,
"AddExternalViewerRuleDialog.saveButton.title"));
90 saveButton.addActionListener((ActionEvent e) -> {
95 closeButton =
new JButton(NbBundle.getMessage(AddExternalViewerRuleDialog.class,
"AddExternalViewerRuleDialog.cancelButton.title"));
96 closeButton.addActionListener((ActionEvent e) -> {
97 doButtonAction(
false);
101 JPanel buttonPanel =
new JPanel();
102 buttonPanel.setLayout(
new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
103 buttonPanel.add(
new javax.swing.Box.Filler(
new Dimension(10, 10),
new Dimension(10, 10),
new Dimension(10, 10)));
104 buttonPanel.add(saveButton);
105 buttonPanel.add(
new javax.swing.Box.Filler(
new Dimension(10, 10),
new Dimension(10, 10),
new Dimension(10, 10)));
106 buttonPanel.add(closeButton);
107 add(buttonPanel, BorderLayout.LINE_START);
113 this.addWindowListener(
new WindowAdapter() {
115 public void windowClosing(WindowEvent e) {
116 doButtonAction(
false);
124 this.addRulePanel.addPropertyChangeListener((PropertyChangeEvent evt) -> {
125 if (evt.getPropertyName().equals(AddExternalViewerRulePanel.EVENT.CHANGED.toString())) {
145 private void doButtonAction(
boolean savePressed) {
147 ExternalViewerRule ruleFromPanel = addRulePanel.getRule();
148 if (null != ruleFromPanel) {
149 this.rule = ruleFromPanel;
150 this.result = BUTTON_PRESSED.OK;
155 this.result = BUTTON_PRESSED.CANCEL;
165 ExternalViewerRule getRule() {
174 BUTTON_PRESSED getResult() {
182 private void enableSaveButton() {
183 this.saveButton.setEnabled(addRulePanel.hasFields());
184 getRootPane().setDefaultButton(saveButton);