19 package org.sleuthkit.autopsy.modules.filetypeid;
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;
40 @SuppressWarnings(
"PMD.SingularField")
41 class AddFileTypeDialog
extends JDialog {
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;
63 @Messages({
"AddMimeTypedialog.title=File Type"})
65 super(WindowManager.getDefault().getMainWindow(), Bundle.AddMimeTypedialog_title(),
true);
66 addMimeTypePanel =
new AddFileTypePanel();
74 AddFileTypeDialog(FileType fileType) {
75 super(WindowManager.getDefault().getMainWindow(), Bundle.AddMimeTypedialog_title(),
true);
76 addMimeTypePanel =
new AddFileTypePanel(fileType);
84 "AddMimeTypeDialog.addButton.title=OK",
85 "AddMimeTypeDialog.cancelButton.title=Cancel"})
87 setLayout(
new BorderLayout());
92 setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
98 add(this.addMimeTypePanel, BorderLayout.PAGE_START);
101 okButton =
new JButton(Bundle.AddMimeTypeDialog_addButton_title());
102 okButton.addActionListener(
new ActionListener() {
104 public void actionPerformed(ActionEvent e) {
105 doButtonAction(
true);
109 okButton.setMaximumSize(BUTTON_SIZE);
110 okButton.setPreferredSize(BUTTON_SIZE);
113 cancelButton =
new JButton(Bundle.AddMimeTypeDialog_cancelButton_title());
114 cancelButton.addActionListener(
new ActionListener() {
116 public void actionPerformed(ActionEvent e) {
117 doButtonAction(
false);
121 cancelButton.setMaximumSize(BUTTON_SIZE);
122 cancelButton.setPreferredSize(BUTTON_SIZE);
125 JPanel buttonPanel =
new JPanel();
126 buttonPanel.setLayout(
new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
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);
138 this.addWindowListener(
new WindowAdapter() {
140 public void windowClosing(WindowEvent e) {
141 doButtonAction(
false);
144 this.addMimeTypePanel.addPropertyChangeListener(
new PropertyChangeListener() {
146 public void propertyChange(PropertyChangeEvent evt) {
147 if (evt.getPropertyName().equals(AddFileTypePanel.EVENT.SIG_LIST_CHANGED.toString())) {
168 private void doButtonAction(
boolean okPressed) {
170 FileType fType = addMimeTypePanel.getFileType();
172 this.fileType = fType;
173 this.result = BUTTON_PRESSED.OK;
177 this.fileType = null;
178 this.result = BUTTON_PRESSED.CANCEL;
188 FileType getFileType() {
197 BUTTON_PRESSED getResult() {
201 private void enableOkButton() {
202 this.okButton.setEnabled(addMimeTypePanel.hasSignature());