19 package org.sleuthkit.autopsy.modules.filetypeid;
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;
41 class AddFileTypeDialog
extends JDialog {
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;
62 @Messages({
"AddMimeTypedialog.title=File Type"})
63 public AddFileTypeDialog() {
64 super(
new JFrame(Bundle.AddMimeTypedialog_title()), Bundle.AddMimeTypedialog_title(),
true);
65 addMimeTypePanel =
new AddFileTypePanel();
74 public AddFileTypeDialog(FileType fileType) {
75 super(
new JFrame(Bundle.AddMimeTypedialog_title()), Bundle.AddMimeTypedialog_title(),
true);
76 addMimeTypePanel =
new AddFileTypePanel(fileType);
86 "AddMimeTypeDialog.addButton.title=Add",
87 "AddMimeTypeDialog.addButton.title2=Done",
88 "AddMimeTypeDialog.cancelButton.title=Cancel"})
89 void display(
boolean add) {
90 setLayout(
new BorderLayout());
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);
104 add(this.addMimeTypePanel, BorderLayout.PAGE_START);
108 okButton =
new JButton(Bundle.AddMimeTypeDialog_addButton_title());
110 okButton =
new JButton(Bundle.AddMimeTypeDialog_addButton_title2());
112 okButton.addActionListener(
new ActionListener() {
114 public void actionPerformed(ActionEvent e) {
115 doButtonAction(
true);
120 closeButton =
new JButton(Bundle.AddMimeTypeDialog_cancelButton_title());
121 closeButton.addActionListener(
new ActionListener() {
123 public void actionPerformed(ActionEvent e) {
124 doButtonAction(
false);
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);
141 this.addWindowListener(
new WindowAdapter() {
143 public void windowClosing(WindowEvent e) {
144 doButtonAction(
false);
147 this.addMimeTypePanel.addPropertyChangeListener(
new PropertyChangeListener() {
149 public void propertyChange(PropertyChangeEvent evt) {
150 if (evt.getPropertyName().equals(AddFileTypePanel.EVENT.SIG_LIST_CHANGED.toString())) {
171 private void doButtonAction(
boolean okPressed) {
173 FileType fileType = addMimeTypePanel.getFileType();
174 if (fileType != null) {
175 this.fileType = fileType;
176 this.result = BUTTON_PRESSED.OK;
180 this.fileType = null;
181 this.result = BUTTON_PRESSED.CANCEL;
191 public FileType getFileType() {
200 public BUTTON_PRESSED getResult() {
204 private void enableOkButton() {
205 this.okButton.setEnabled(addMimeTypePanel.hasSignature());