Autopsy  4.10.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-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.modules.filetypeid;
20 
21 import java.awt.BorderLayout;
22 import java.awt.Dimension;
23 import java.awt.event.ActionEvent;
24 import java.awt.event.ActionListener;
25 import java.awt.event.WindowAdapter;
26 import java.awt.event.WindowEvent;
27 import java.beans.PropertyChangeEvent;
28 import java.beans.PropertyChangeListener;
29 import javax.swing.BoxLayout;
30 import javax.swing.JButton;
31 import javax.swing.JDialog;
32 import javax.swing.JPanel;
33 import org.openide.util.NbBundle;
34 import org.openide.util.NbBundle.Messages;
35 import org.openide.windows.WindowManager;
36 
40 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
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 static final Dimension BUTTON_SIZE = new Dimension(65, 23);
54  private FileType fileType;
55  final private AddFileTypePanel addMimeTypePanel;
56  private BUTTON_PRESSED result;
57  private JButton okButton;
58  private JButton cancelButton;
59 
63  @Messages({"AddMimeTypedialog.title=File Type"})
64  AddFileTypeDialog() {
65  super(WindowManager.getDefault().getMainWindow(), Bundle.AddMimeTypedialog_title(), true);
66  addMimeTypePanel = new AddFileTypePanel();
67  }
68 
74  AddFileTypeDialog(FileType fileType) {
75  super(WindowManager.getDefault().getMainWindow(), Bundle.AddMimeTypedialog_title(), true);
76  addMimeTypePanel = new AddFileTypePanel(fileType);
77  }
78 
83  @NbBundle.Messages({
84  "AddMimeTypeDialog.addButton.title=OK",
85  "AddMimeTypeDialog.cancelButton.title=Cancel"})
86  void display() {
87  setLayout(new BorderLayout());
88 
92  setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
93 
98  add(this.addMimeTypePanel, BorderLayout.PAGE_START);
99 
100  // Add the OK button
101  okButton = new JButton(Bundle.AddMimeTypeDialog_addButton_title());
102  okButton.addActionListener(new ActionListener() {
103  @Override
104  public void actionPerformed(ActionEvent e) {
105  doButtonAction(true);
106  }
107  });
108  //setting both max and preffered size appears to be necessary to change the button size
109  okButton.setMaximumSize(BUTTON_SIZE);
110  okButton.setPreferredSize(BUTTON_SIZE);
111 
112  // Add a close button.
113  cancelButton = new JButton(Bundle.AddMimeTypeDialog_cancelButton_title());
114  cancelButton.addActionListener(new ActionListener() {
115  @Override
116  public void actionPerformed(ActionEvent e) {
117  doButtonAction(false);
118  }
119  });
120  //setting both max and preffered size appears to be necessary to change the button size
121  cancelButton.setMaximumSize(BUTTON_SIZE);
122  cancelButton.setPreferredSize(BUTTON_SIZE);
123 
124  // Put the buttons in their own panel, under the settings panel.
125  JPanel buttonPanel = new JPanel();
126  buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
127 
128  buttonPanel.add(okButton);
129  buttonPanel.add(new javax.swing.Box.Filler(new Dimension(10, 10), new Dimension(10, 10), new Dimension(10, 10)));
130  buttonPanel.add(cancelButton);
131  buttonPanel.add(new javax.swing.Box.Filler(new Dimension(10, 10), new Dimension(10, 10), new Dimension(10, 10)));
132  add(buttonPanel, BorderLayout.LINE_END);
133 
138  this.addWindowListener(new WindowAdapter() {
139  @Override
140  public void windowClosing(WindowEvent e) {
141  doButtonAction(false);
142  }
143  });
144  this.addMimeTypePanel.addPropertyChangeListener(new PropertyChangeListener() {
145  @Override
146  public void propertyChange(PropertyChangeEvent evt) {
147  if (evt.getPropertyName().equals(AddFileTypePanel.EVENT.SIG_LIST_CHANGED.toString())) {
148  enableOkButton();
149  }
150  }
151  });
152  enableOkButton();
156  pack();
157  setResizable(false);
158  setVisible(true);
159 
160  }
161 
168  private void doButtonAction(boolean okPressed) {
169  if (okPressed) {
170  FileType fType = addMimeTypePanel.getFileType();
171  if (fType != null) {
172  this.fileType = fType;
173  this.result = BUTTON_PRESSED.OK;
174  setVisible(false);
175  }
176  } else {
177  this.fileType = null;
178  this.result = BUTTON_PRESSED.CANCEL;
179  setVisible(false);
180  }
181  }
182 
188  FileType getFileType() {
189  return fileType;
190  }
191 
197  BUTTON_PRESSED getResult() {
198  return result;
199  }
200 
201  private void enableOkButton() {
202  this.okButton.setEnabled(addMimeTypePanel.hasSignature());
203  }
204 
205 }

Copyright © 2012-2018 Basis Technology. Generated on: Fri Mar 22 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.