Autopsy  4.5.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 
41 class AddFileTypeDialog extends JDialog {
42 
47  enum BUTTON_PRESSED {
48 
49  OK, CANCEL;
50  }
51 
52  private static final long serialVersionUID = 1L;
53  private FileType fileType;
54  private AddFileTypePanel addMimeTypePanel;
55  private BUTTON_PRESSED result;
56  private JButton okButton;
57  private JButton closeButton;
58 
62  @Messages({"AddMimeTypedialog.title=File Type"})
63  public AddFileTypeDialog() {
64  super(new JFrame(Bundle.AddMimeTypedialog_title()), Bundle.AddMimeTypedialog_title(), true);
65  addMimeTypePanel = new AddFileTypePanel();
66  this.display(true);
67  }
68 
74  public AddFileTypeDialog(FileType fileType) {
75  super(new JFrame(Bundle.AddMimeTypedialog_title()), Bundle.AddMimeTypedialog_title(), true);
76  addMimeTypePanel = new AddFileTypePanel(fileType);
77  this.display(false);
78  }
79 
85  @NbBundle.Messages({
86  "AddMimeTypeDialog.addButton.title=Add",
87  "AddMimeTypeDialog.addButton.title2=Done",
88  "AddMimeTypeDialog.cancelButton.title=Cancel"})
89  void display(boolean add) {
90  setLayout(new BorderLayout());
91 
95  Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
96  int width = this.getSize().width;
97  int height = this.getSize().height;
98  setLocation((screenDimension.width - width) / 2, (screenDimension.height - height) / 2);
99 
104  add(this.addMimeTypePanel, BorderLayout.PAGE_START);
105 
106  // Add the add/done button.
107  if (add) {
108  okButton = new JButton(Bundle.AddMimeTypeDialog_addButton_title());
109  } else {
110  okButton = new JButton(Bundle.AddMimeTypeDialog_addButton_title2());
111  }
112  okButton.addActionListener(new ActionListener() {
113  @Override
114  public void actionPerformed(ActionEvent e) {
115  doButtonAction(true);
116  }
117  });
118 
119  // Add a close button.
120  closeButton = new JButton(Bundle.AddMimeTypeDialog_cancelButton_title());
121  closeButton.addActionListener(new ActionListener() {
122  @Override
123  public void actionPerformed(ActionEvent e) {
124  doButtonAction(false);
125  }
126  });
127 
128  // Put the buttons in their own panel, under the settings panel.
129  JPanel buttonPanel = new JPanel();
130  buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
131  buttonPanel.add(new javax.swing.Box.Filler(new Dimension(10, 10), new Dimension(10, 10), new Dimension(10, 10)));
132  buttonPanel.add(okButton);
133  buttonPanel.add(new javax.swing.Box.Filler(new Dimension(10, 10), new Dimension(10, 10), new Dimension(10, 10)));
134  buttonPanel.add(closeButton);
135  add(buttonPanel, BorderLayout.LINE_START);
136 
141  this.addWindowListener(new WindowAdapter() {
142  @Override
143  public void windowClosing(WindowEvent e) {
144  doButtonAction(false);
145  }
146  });
147  this.addMimeTypePanel.addPropertyChangeListener(new PropertyChangeListener() {
148  @Override
149  public void propertyChange(PropertyChangeEvent evt) {
150  if (evt.getPropertyName().equals(AddFileTypePanel.EVENT.SIG_LIST_CHANGED.toString())) {
151  enableOkButton();
152  }
153  }
154  });
155  enableOkButton();
159  pack();
160  setResizable(false);
161  setVisible(true);
162 
163  }
164 
171  private void doButtonAction(boolean okPressed) {
172  if (okPressed) {
173  FileType fType = addMimeTypePanel.getFileType();
174  if (fType != null) {
175  this.fileType = fType;
176  this.result = BUTTON_PRESSED.OK;
177  setVisible(false);
178  }
179  } else {
180  this.fileType = null;
181  this.result = BUTTON_PRESSED.CANCEL;
182  setVisible(false);
183  }
184  }
185 
191  public FileType getFileType() {
192  return fileType;
193  }
194 
200  public BUTTON_PRESSED getResult() {
201  return result;
202  }
203 
204  private void enableOkButton() {
205  this.okButton.setEnabled(addMimeTypePanel.hasSignature());
206  }
207 
208 }

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