Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
AddFileTypeSignatureDialog.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-2016 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 javax.swing.BoxLayout;
29 import javax.swing.JButton;
30 import javax.swing.JDialog;
31 import javax.swing.JFrame;
32 import javax.swing.JPanel;
33 import org.openide.util.NbBundle;
34 import org.openide.util.NbBundle.Messages;
37 
42 final class AddFileTypeSignatureDialog extends JDialog {
43 
44  private static final long serialVersionUID = 1L;
45  private final AddFileTypeSignaturePanel addFileTypeSigPanel;
46  private static final String TITLE = NbBundle.getMessage(RunIngestModulesDialog.class, "IngestDialog.title.text");
47  private Signature signature;
48  private BUTTON_PRESSED result;
49 
54  enum BUTTON_PRESSED {
55 
56  OK, CANCEL;
57  }
58 
62  AddFileTypeSignatureDialog() {
63  super(new JFrame(TITLE), TITLE, true);
64  this.addFileTypeSigPanel = new AddFileTypeSignaturePanel();
65  this.display(true);
66  }
67 
73  AddFileTypeSignatureDialog(Signature toEdit) {
74  super(new JFrame(TITLE), TITLE, true);
75  this.addFileTypeSigPanel = new AddFileTypeSignaturePanel(toEdit);
76  this.display(false);
77  }
78 
84  public Signature getSignature() {
85  return signature;
86  }
87 
93  public BUTTON_PRESSED getResult() {
94  return result;
95  }
96 
102  @Messages({
103  "AddFileTypeSignatureDialog.addButton.title=Add",
104  "AddFileTypeSignatureDialog.addButton.title2=Done",
105  "AddFileTypeSignatureDialog.cancelButton.title=Cancel"})
106  void display(boolean add) {
107  setLayout(new BorderLayout());
108 
112  Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
113  int width = this.getSize().width;
114  int height = this.getSize().height;
115  setLocation((screenDimension.width - width) / 2, (screenDimension.height - height) / 2);
116 
121  add(this.addFileTypeSigPanel, BorderLayout.PAGE_START);
122 
123  // Add the add/done button.
124  JButton addButton;
125  if (add) {
126  addButton = new JButton(Bundle.AddFileTypeSignatureDialog_addButton_title());
127  } else {
128  addButton = new JButton(Bundle.AddFileTypeSignatureDialog_addButton_title2());
129  }
130  addButton.addActionListener(new ActionListener() {
131  @Override
132  public void actionPerformed(ActionEvent e) {
133  doButtonAction(true);
134  }
135  });
136 
137  // Add a close button.
138  JButton closeButton = new JButton(Bundle.AddFileTypeSignatureDialog_cancelButton_title());
139  closeButton.addActionListener(new ActionListener() {
140  @Override
141  public void actionPerformed(ActionEvent e) {
142  doButtonAction(false);
143  }
144  });
145 
146  // Put the buttons in their own panel, under the settings panel.
147  JPanel buttonPanel = new JPanel();
148  buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
149  buttonPanel.add(new javax.swing.Box.Filler(new Dimension(10, 10), new Dimension(10, 10), new Dimension(10, 10)));
150  buttonPanel.add(addButton);
151  buttonPanel.add(new javax.swing.Box.Filler(new Dimension(10, 10), new Dimension(10, 10), new Dimension(10, 10)));
152  buttonPanel.add(closeButton);
153  add(buttonPanel, BorderLayout.LINE_START);
154 
159  this.addWindowListener(new WindowAdapter() {
160  @Override
161  public void windowClosing(WindowEvent e) {
162  doButtonAction(false);
163  }
164  });
165 
169  pack();
170  setResizable(false);
171  setVisible(true);
172  }
173 
180  @Messages({"AddFileTypeSignatureDialog.invalidSignature.message=Invalid signature"})
181  private void doButtonAction(boolean okPressed) {
182  if (okPressed) {
183  Signature sig = addFileTypeSigPanel.getSignature();
184  if (sig != null) {
185  this.signature = sig;
186  this.result = BUTTON_PRESSED.OK;
187  setVisible(false);
188  }
189  } else {
190  this.signature = null;
191  this.result = BUTTON_PRESSED.CANCEL;
192  setVisible(false);
193  }
194  }
195 
196 }

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