Autopsy  4.7.0
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-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 javax.swing.BoxLayout;
28 import javax.swing.JButton;
29 import javax.swing.JDialog;
30 import javax.swing.JFrame;
31 import javax.swing.JPanel;
32 import org.openide.util.NbBundle;
33 import org.openide.util.NbBundle.Messages;
34 import org.openide.windows.WindowManager;
37 
42 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
43 final class AddFileTypeSignatureDialog extends JDialog {
44 
45  private static final long serialVersionUID = 1L;
46  private final AddFileTypeSignaturePanel addFileTypeSigPanel;
47  private static final String TITLE = NbBundle.getMessage(RunIngestModulesAction.class, "RunIngestModulesAction.name");
48  private Signature signature;
49  private BUTTON_PRESSED result;
50 
55  enum BUTTON_PRESSED {
56 
57  OK, CANCEL;
58  }
59 
63  AddFileTypeSignatureDialog() {
64  super(new JFrame(TITLE), TITLE, true);
65  this.addFileTypeSigPanel = new AddFileTypeSignaturePanel();
66  this.display(true);
67  }
68 
74  AddFileTypeSignatureDialog(Signature toEdit) {
75  super(new JFrame(TITLE), TITLE, true);
76  this.addFileTypeSigPanel = new AddFileTypeSignaturePanel(toEdit);
77  this.display(false);
78  }
79 
85  public Signature getSignature() {
86  return signature;
87  }
88 
94  public BUTTON_PRESSED getResult() {
95  return result;
96  }
97 
103  @Messages({
104  "AddFileTypeSignatureDialog.addButton.title=Add",
105  "AddFileTypeSignatureDialog.addButton.title2=Done",
106  "AddFileTypeSignatureDialog.cancelButton.title=Cancel"})
107  void display(boolean add) {
108  setLayout(new BorderLayout());
109 
113  setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
114 
119  add(this.addFileTypeSigPanel, BorderLayout.PAGE_START);
120 
121  // Add the add/done button.
122  JButton addButton;
123  if (add) {
124  addButton = new JButton(Bundle.AddFileTypeSignatureDialog_addButton_title());
125  } else {
126  addButton = new JButton(Bundle.AddFileTypeSignatureDialog_addButton_title2());
127  }
128  addButton.addActionListener(new ActionListener() {
129  @Override
130  public void actionPerformed(ActionEvent e) {
131  doButtonAction(true);
132  }
133  });
134 
135  // Add a close button.
136  JButton closeButton = new JButton(Bundle.AddFileTypeSignatureDialog_cancelButton_title());
137  closeButton.addActionListener(new ActionListener() {
138  @Override
139  public void actionPerformed(ActionEvent e) {
140  doButtonAction(false);
141  }
142  });
143 
144  // Put the buttons in their own panel, under the settings panel.
145  JPanel buttonPanel = new JPanel();
146  buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
147  buttonPanel.add(new javax.swing.Box.Filler(new Dimension(10, 10), new Dimension(10, 10), new Dimension(10, 10)));
148  buttonPanel.add(addButton);
149  buttonPanel.add(new javax.swing.Box.Filler(new Dimension(10, 10), new Dimension(10, 10), new Dimension(10, 10)));
150  buttonPanel.add(closeButton);
151  add(buttonPanel, BorderLayout.LINE_START);
152 
157  this.addWindowListener(new WindowAdapter() {
158  @Override
159  public void windowClosing(WindowEvent e) {
160  doButtonAction(false);
161  }
162  });
163 
167  pack();
168  setResizable(false);
169  setVisible(true);
170  }
171 
178  @Messages({"AddFileTypeSignatureDialog.invalidSignature.message=Invalid signature"})
179  private void doButtonAction(boolean okPressed) {
180  if (okPressed) {
181  Signature sig = addFileTypeSigPanel.getSignature();
182  if (sig != null) {
183  this.signature = sig;
184  this.result = BUTTON_PRESSED.OK;
185  setVisible(false);
186  }
187  } else {
188  this.signature = null;
189  this.result = BUTTON_PRESSED.CANCEL;
190  setVisible(false);
191  }
192  }
193 
194 }

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