Autopsy  4.17.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddExternalViewerRuleDialog.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2018 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.directorytree;
20 
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;
34 
38 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
39 class AddExternalViewerRuleDialog extends JDialog {
40 
41  private ExternalViewerRule rule;
42  private final AddExternalViewerRulePanel addRulePanel;
43  private BUTTON_PRESSED result;
44  private JButton saveButton;
45  private JButton closeButton;
46 
47  enum BUTTON_PRESSED {
48  OK, CANCEL;
49  }
50 
54  AddExternalViewerRuleDialog() {
55  super(new JFrame(NbBundle.getMessage(AddExternalViewerRuleDialog.class, "AddExternalViewerRuleDialog.title")),
56  NbBundle.getMessage(AddExternalViewerRuleDialog.class, "AddExternalViewerRuleDialog.title"), true);
57  addRulePanel = new AddExternalViewerRulePanel();
58  this.display();
59  }
60 
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);
70  this.display();
71  }
72 
76  private void display() {
77  setLayout(new BorderLayout());
78 
82  setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
83 
84  add(this.addRulePanel, BorderLayout.PAGE_START);
85 
86  // Add a save button.
87  saveButton = new JButton(NbBundle.getMessage(AddExternalViewerRuleDialog.class, "AddExternalViewerRuleDialog.saveButton.title"));
88  saveButton.addActionListener((ActionEvent e) -> {
89  doButtonAction(true);
90  });
91 
92  // Add a close button.
93  closeButton = new JButton(NbBundle.getMessage(AddExternalViewerRuleDialog.class, "AddExternalViewerRuleDialog.cancelButton.title"));
94  closeButton.addActionListener((ActionEvent e) -> {
95  doButtonAction(false);
96  });
97 
98  // Put the buttons in their own panel, under the settings panel.
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);
106 
111  this.addWindowListener(new WindowAdapter() {
112  @Override
113  public void windowClosing(WindowEvent e) {
114  doButtonAction(false);
115  }
116  });
117 
122  this.addRulePanel.addPropertyChangeListener((PropertyChangeEvent evt) -> {
123  if (evt.getPropertyName().equals(AddExternalViewerRulePanel.EVENT.CHANGED.toString())) {
124  enableSaveButton();
125  }
126  });
127 
128  enableSaveButton();
129 
133  pack();
134  setResizable(false);
135  setVisible(true);
136  }
137 
143  private void doButtonAction(boolean savePressed) {
144  if (savePressed) {
145  ExternalViewerRule ruleFromPanel = addRulePanel.getRule();
146  if (null != ruleFromPanel) {
147  this.rule = ruleFromPanel;
148  this.result = BUTTON_PRESSED.OK;
149  setVisible(false);
150  }
151  } else {
152  this.rule = null;
153  this.result = BUTTON_PRESSED.CANCEL;
154  setVisible(false);
155  }
156  }
157 
163  ExternalViewerRule getRule() {
164  return rule;
165  }
166 
172  BUTTON_PRESSED getResult() {
173  return result;
174  }
175 
180  private void enableSaveButton() {
181  this.saveButton.setEnabled(addRulePanel.hasFields());
182  getRootPane().setDefaultButton(saveButton);
183  }
184 }

Copyright © 2012-2021 Basis Technology. Generated on: Tue Jan 19 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.