Autopsy  4.6.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 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  setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
82 
83  add(this.addRulePanel, BorderLayout.PAGE_START);
84 
85  // Add a save button.
86  saveButton = new JButton(NbBundle.getMessage(AddExternalViewerRuleDialog.class, "AddExternalViewerRuleDialog.saveButton.title"));
87  saveButton.addActionListener((ActionEvent e) -> {
88  doButtonAction(true);
89  });
90 
91  // Add a close button.
92  closeButton = new JButton(NbBundle.getMessage(AddExternalViewerRuleDialog.class, "AddExternalViewerRuleDialog.cancelButton.title"));
93  closeButton.addActionListener((ActionEvent e) -> {
94  doButtonAction(false);
95  });
96 
97  // Put the buttons in their own panel, under the settings panel.
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);
105 
110  this.addWindowListener(new WindowAdapter() {
111  @Override
112  public void windowClosing(WindowEvent e) {
113  doButtonAction(false);
114  }
115  });
116 
121  this.addRulePanel.addPropertyChangeListener((PropertyChangeEvent evt) -> {
122  if (evt.getPropertyName().equals(AddExternalViewerRulePanel.EVENT.CHANGED.toString())) {
123  enableSaveButton();
124  }
125  });
126 
127  enableSaveButton();
128 
132  pack();
133  setResizable(false);
134  setVisible(true);
135  }
136 
142  private void doButtonAction(boolean savePressed) {
143  if (savePressed) {
144  ExternalViewerRule ruleFromPanel = addRulePanel.getRule();
145  if (null != ruleFromPanel) {
146  this.rule = ruleFromPanel;
147  this.result = BUTTON_PRESSED.OK;
148  setVisible(false);
149  }
150  } else {
151  this.rule = null;
152  this.result = BUTTON_PRESSED.CANCEL;
153  setVisible(false);
154  }
155  }
156 
162  ExternalViewerRule getRule() {
163  return rule;
164  }
165 
171  BUTTON_PRESSED getResult() {
172  return result;
173  }
174 
179  private void enableSaveButton() {
180  this.saveButton.setEnabled(addRulePanel.hasFields());
181  getRootPane().setDefaultButton(saveButton);
182  }
183 }

Copyright © 2012-2016 Basis Technology. Generated on: Mon May 7 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.