Autopsy  4.17.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-2020 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.JPanel;
31 import org.openide.util.NbBundle;
32 import org.openide.util.NbBundle.Messages;
33 import org.openide.windows.WindowManager;
36 
41 @SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
42 final class AddFileTypeSignatureDialog extends JDialog {
43 
44  private static final long serialVersionUID = 1L;
45  private static final Dimension BUTTON_SIZE = new Dimension(85, 23);
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(WindowManager.getDefault().getMainWindow(), TITLE, true);
65  this.addFileTypeSigPanel = new AddFileTypeSignaturePanel();
66  init();
67  }
68 
74  AddFileTypeSignatureDialog(Signature toEdit) {
75  super(WindowManager.getDefault().getMainWindow(), TITLE, true);
76  this.addFileTypeSigPanel = new AddFileTypeSignaturePanel(toEdit);
77  init();
78  }
79 
80  private void init() {
81  setLayout(new BorderLayout());
82 
87  add(this.addFileTypeSigPanel, BorderLayout.PAGE_START);
88 
89  // Add the add/done button.
90  JButton okButton;
91  okButton = new JButton(Bundle.AddFileTypeSignatureDialog_addButton_title());
92  okButton.addActionListener(new ActionListener() {
93  @Override
94  public void actionPerformed(ActionEvent e) {
95  doButtonAction(true);
96  }
97  });
98  //setting both max and preffered size appears to be necessary to change the button size
99  okButton.setMaximumSize(BUTTON_SIZE);
100  okButton.setPreferredSize(BUTTON_SIZE);
101 
102  // Add a close button.
103  JButton cancelButton = new JButton(Bundle.AddFileTypeSignatureDialog_cancelButton_title());
104  cancelButton.addActionListener(new ActionListener() {
105  @Override
106  public void actionPerformed(ActionEvent e) {
107  doButtonAction(false);
108  }
109  });
110  //setting both max and preffered size appears to be necessary to change the button size
111  cancelButton.setMaximumSize(BUTTON_SIZE);
112  cancelButton.setPreferredSize(BUTTON_SIZE);
113 
114  // Put the buttons in their own panel, under the settings panel.
115  JPanel buttonPanel = new JPanel();
116  buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
117  buttonPanel.add(okButton);
118  buttonPanel.add(new javax.swing.Box.Filler(new Dimension(10, 35), new Dimension(10, 35), new Dimension(10, 35)));
119  buttonPanel.add(cancelButton);
120  buttonPanel.add(new javax.swing.Box.Filler(new Dimension(10, 35), new Dimension(10, 35), new Dimension(10, 35)));
121  buttonPanel.validate();
122  add(buttonPanel, BorderLayout.LINE_END);
123 
128  this.addWindowListener(new WindowAdapter() {
129  @Override
130  public void windowClosing(WindowEvent e) {
131  doButtonAction(false);
132  }
133  });
134  setResizable(false);
135  pack();
136  }
137 
143  public Signature getSignature() {
144  return signature;
145  }
146 
152  public BUTTON_PRESSED getResult() {
153  return result;
154  }
155 
161  @Messages({
162  "AddFileTypeSignatureDialog.addButton.title=OK",
163  "AddFileTypeSignatureDialog.cancelButton.title=Cancel"})
164  void display(boolean add) {
168  setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
172  setVisible(true);
173  }
174 
181  @Messages({"AddFileTypeSignatureDialog.invalidSignature.message=Invalid signature"})
182  private void doButtonAction(boolean okPressed) {
183  if (okPressed) {
184  Signature sig = addFileTypeSigPanel.getSignature();
185  if (sig != null) {
186  this.signature = sig;
187  this.result = BUTTON_PRESSED.OK;
188  setVisible(false);
189  }
190  } else {
191  this.signature = null;
192  this.result = BUTTON_PRESSED.CANCEL;
193  setVisible(false);
194  }
195  }
196 
197 }

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