Autopsy  4.1
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-2016 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.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;
34 
38 class AddExternalViewerRuleDialog extends JDialog {
39 
40  private ExternalViewerRule rule;
41  private final AddExternalViewerRulePanel addRulePanel;
42  private BUTTON_PRESSED result;
43  private JButton saveButton;
44  private JButton closeButton;
45 
46  enum BUTTON_PRESSED {
47  OK, CANCEL;
48  }
49 
53  AddExternalViewerRuleDialog() {
54  super(new JFrame(NbBundle.getMessage(AddExternalViewerRuleDialog.class, "AddExternalViewerRuleDialog.title")),
55  NbBundle.getMessage(AddExternalViewerRuleDialog.class, "AddExternalViewerRuleDialog.title"), true);
56  addRulePanel = new AddExternalViewerRulePanel();
57  this.display();
58  }
59 
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);
69  this.display();
70  }
71 
75  private void display() {
76  setLayout(new BorderLayout());
77 
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);
85 
86  add(this.addRulePanel, BorderLayout.PAGE_START);
87 
88  // Add a save button.
89  saveButton = new JButton(NbBundle.getMessage(AddExternalViewerRuleDialog.class, "AddExternalViewerRuleDialog.saveButton.title"));
90  saveButton.addActionListener((ActionEvent e) -> {
91  doButtonAction(true);
92  });
93 
94  // Add a close button.
95  closeButton = new JButton(NbBundle.getMessage(AddExternalViewerRuleDialog.class, "AddExternalViewerRuleDialog.cancelButton.title"));
96  closeButton.addActionListener((ActionEvent e) -> {
97  doButtonAction(false);
98  });
99 
100  // Put the buttons in their own panel, under the settings panel.
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);
108 
113  this.addWindowListener(new WindowAdapter() {
114  @Override
115  public void windowClosing(WindowEvent e) {
116  doButtonAction(false);
117  }
118  });
119 
124  this.addRulePanel.addPropertyChangeListener((PropertyChangeEvent evt) -> {
125  if (evt.getPropertyName().equals(AddExternalViewerRulePanel.EVENT.CHANGED.toString())) {
126  enableSaveButton();
127  }
128  });
129 
130  enableSaveButton();
131 
135  pack();
136  setResizable(false);
137  setVisible(true);
138  }
139 
145  private void doButtonAction(boolean savePressed) {
146  if (savePressed) {
147  ExternalViewerRule ruleFromPanel = addRulePanel.getRule();
148  if (null != ruleFromPanel) {
149  this.rule = ruleFromPanel;
150  this.result = BUTTON_PRESSED.OK;
151  setVisible(false);
152  }
153  } else {
154  this.rule = null;
155  this.result = BUTTON_PRESSED.CANCEL;
156  setVisible(false);
157  }
158  }
159 
165  ExternalViewerRule getRule() {
166  return rule;
167  }
168 
174  BUTTON_PRESSED getResult() {
175  return result;
176  }
177 
182  private void enableSaveButton() {
183  this.saveButton.setEnabled(addRulePanel.hasFields());
184  getRootPane().setDefaultButton(saveButton);
185  }
186 }

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