Autopsy  4.6.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddFileTypeDialog.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2017 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.modules.filetypeid;
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.ActionListener;
26 import java.awt.event.WindowAdapter;
27 import java.awt.event.WindowEvent;
28 import java.beans.PropertyChangeEvent;
29 import java.beans.PropertyChangeListener;
30 import javax.swing.BoxLayout;
31 import javax.swing.JButton;
32 import javax.swing.JDialog;
33 import javax.swing.JFrame;
34 import javax.swing.JPanel;
35 import org.openide.util.NbBundle;
36 import org.openide.util.NbBundle.Messages;
37 import org.openide.windows.WindowManager;
38 
42 class AddFileTypeDialog extends JDialog {
43 
48  enum BUTTON_PRESSED {
49 
50  OK, CANCEL;
51  }
52 
53  private static final long serialVersionUID = 1L;
54  private FileType fileType;
55  private AddFileTypePanel addMimeTypePanel;
56  private BUTTON_PRESSED result;
57  private JButton okButton;
58  private JButton closeButton;
59 
63  @Messages({"AddMimeTypedialog.title=File Type"})
64  public AddFileTypeDialog() {
65  super(new JFrame(Bundle.AddMimeTypedialog_title()), Bundle.AddMimeTypedialog_title(), true);
66  addMimeTypePanel = new AddFileTypePanel();
67  this.display(true);
68  }
69 
75  public AddFileTypeDialog(FileType fileType) {
76  super(new JFrame(Bundle.AddMimeTypedialog_title()), Bundle.AddMimeTypedialog_title(), true);
77  addMimeTypePanel = new AddFileTypePanel(fileType);
78  this.display(false);
79  }
80 
86  @NbBundle.Messages({
87  "AddMimeTypeDialog.addButton.title=Add",
88  "AddMimeTypeDialog.addButton.title2=Done",
89  "AddMimeTypeDialog.cancelButton.title=Cancel"})
90  void display(boolean add) {
91  setLayout(new BorderLayout());
92 
96  setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
97 
102  add(this.addMimeTypePanel, BorderLayout.PAGE_START);
103 
104  // Add the add/done button.
105  if (add) {
106  okButton = new JButton(Bundle.AddMimeTypeDialog_addButton_title());
107  } else {
108  okButton = new JButton(Bundle.AddMimeTypeDialog_addButton_title2());
109  }
110  okButton.addActionListener(new ActionListener() {
111  @Override
112  public void actionPerformed(ActionEvent e) {
113  doButtonAction(true);
114  }
115  });
116 
117  // Add a close button.
118  closeButton = new JButton(Bundle.AddMimeTypeDialog_cancelButton_title());
119  closeButton.addActionListener(new ActionListener() {
120  @Override
121  public void actionPerformed(ActionEvent e) {
122  doButtonAction(false);
123  }
124  });
125 
126  // Put the buttons in their own panel, under the settings panel.
127  JPanel buttonPanel = new JPanel();
128  buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
129  buttonPanel.add(new javax.swing.Box.Filler(new Dimension(10, 10), new Dimension(10, 10), new Dimension(10, 10)));
130  buttonPanel.add(okButton);
131  buttonPanel.add(new javax.swing.Box.Filler(new Dimension(10, 10), new Dimension(10, 10), new Dimension(10, 10)));
132  buttonPanel.add(closeButton);
133  add(buttonPanel, BorderLayout.LINE_START);
134 
139  this.addWindowListener(new WindowAdapter() {
140  @Override
141  public void windowClosing(WindowEvent e) {
142  doButtonAction(false);
143  }
144  });
145  this.addMimeTypePanel.addPropertyChangeListener(new PropertyChangeListener() {
146  @Override
147  public void propertyChange(PropertyChangeEvent evt) {
148  if (evt.getPropertyName().equals(AddFileTypePanel.EVENT.SIG_LIST_CHANGED.toString())) {
149  enableOkButton();
150  }
151  }
152  });
153  enableOkButton();
157  pack();
158  setResizable(false);
159  setVisible(true);
160 
161  }
162 
169  private void doButtonAction(boolean okPressed) {
170  if (okPressed) {
171  FileType fType = addMimeTypePanel.getFileType();
172  if (fType != null) {
173  this.fileType = fType;
174  this.result = BUTTON_PRESSED.OK;
175  setVisible(false);
176  }
177  } else {
178  this.fileType = null;
179  this.result = BUTTON_PRESSED.CANCEL;
180  setVisible(false);
181  }
182  }
183 
189  public FileType getFileType() {
190  return fileType;
191  }
192 
198  public BUTTON_PRESSED getResult() {
199  return result;
200  }
201 
202  private void enableOkButton() {
203  this.okButton.setEnabled(addMimeTypePanel.hasSignature());
204  }
205 
206 }

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.