Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
RawDSInputPanel.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.datasourceprocessors;
20 
21 import java.io.File;
22 import java.util.Calendar;
23 import java.util.SimpleTimeZone;
24 import java.util.TimeZone;
25 import javax.swing.JFileChooser;
26 import javax.swing.JPanel;
27 import javax.swing.event.DocumentEvent;
28 import javax.swing.event.DocumentListener;
29 import org.openide.util.NbBundle.Messages;
34 
35 final class RawDSInputPanel extends JPanel implements DocumentListener {
36  private static final long TWO_GB = 2000000000L;
37  private static final long serialVersionUID = 1L; //default
38  private final String PROP_LASTINPUT_PATH = "LBL_LastInputFile_PATH";
39  private final JFileChooser fc = new JFileChooser();
40  // Externally supplied name is used to store settings
41  private final String contextName;
45  private RawDSInputPanel(String context) {
46  initComponents();
47 
48  errorLabel.setVisible(false);
49 
50  fc.setDragEnabled(false);
51  fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
52  fc.setMultiSelectionEnabled(false);
53 
54  this.contextName = context;
55  }
56 
60  static synchronized RawDSInputPanel createInstance(String context) {
61  RawDSInputPanel instance = new RawDSInputPanel(context);
62 
63  instance.postInit();
64  instance.createTimeZoneList();
65 
66  return instance;
67  }
68 
69  //post-constructor initialization to properly initialize listener support
70  //without leaking references of uninitialized objects
71  private void postInit() {
72  pathTextField.getDocument().addDocumentListener(this);
73  }
74 
79  private void createTimeZoneList() {
80  // load and add all timezone
81  String[] ids = SimpleTimeZone.getAvailableIDs();
82  for (String id : ids) {
83  TimeZone zone = TimeZone.getTimeZone(id);
84  int offset = zone.getRawOffset() / 1000;
85  int hour = offset / 3600;
86  int minutes = (offset % 3600) / 60;
87  String item = String.format("(GMT%+d:%02d) %s", hour, minutes, id);
88 
89  timeZoneComboBox.addItem(item);
90  }
91  // get the current timezone
92  TimeZone thisTimeZone = Calendar.getInstance().getTimeZone();
93  int thisOffset = thisTimeZone.getRawOffset() / 1000;
94  int thisHour = thisOffset / 3600;
95  int thisMinutes = (thisOffset % 3600) / 60;
96  String formatted = String.format("(GMT%+d:%02d) %s", thisHour, thisMinutes, thisTimeZone.getID());
97 
98  // set the selected timezone
99  timeZoneComboBox.setSelectedItem(formatted);
100  }
101 
107  @SuppressWarnings("unchecked")
108  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
109  private void initComponents() {
110 
111  infileTypeButtonGroup = new javax.swing.ButtonGroup();
112  pathLabel = new javax.swing.JLabel();
113  pathTextField = new javax.swing.JTextField();
114  browseButton = new javax.swing.JButton();
115  j2GBBreakupRadioButton = new javax.swing.JRadioButton();
116  jBreakFileUpLabel = new javax.swing.JLabel();
117  jNoBreakupRadioButton = new javax.swing.JRadioButton();
118  errorLabel = new javax.swing.JLabel();
119  timeZoneLabel = new javax.swing.JLabel();
120  timeZoneComboBox = new javax.swing.JComboBox<>();
121 
122  org.openide.awt.Mnemonics.setLocalizedText(pathLabel, org.openide.util.NbBundle.getMessage(RawDSInputPanel.class, "RawDSInputPanel.pathLabel.text")); // NOI18N
123 
124  pathTextField.setText(org.openide.util.NbBundle.getMessage(RawDSInputPanel.class, "RawDSInputPanel.pathTextField.text")); // NOI18N
125 
126  org.openide.awt.Mnemonics.setLocalizedText(browseButton, org.openide.util.NbBundle.getMessage(RawDSInputPanel.class, "RawDSInputPanel.browseButton.text")); // NOI18N
127  browseButton.addActionListener(new java.awt.event.ActionListener() {
128  public void actionPerformed(java.awt.event.ActionEvent evt) {
129  browseButtonActionPerformed(evt);
130  }
131  });
132 
133  infileTypeButtonGroup.add(j2GBBreakupRadioButton);
134  j2GBBreakupRadioButton.setSelected(true);
135  org.openide.awt.Mnemonics.setLocalizedText(j2GBBreakupRadioButton, org.openide.util.NbBundle.getMessage(RawDSInputPanel.class, "RawDSInputPanel.j2GBBreakupRadioButton.text")); // NOI18N
136  j2GBBreakupRadioButton.addActionListener(new java.awt.event.ActionListener() {
137  public void actionPerformed(java.awt.event.ActionEvent evt) {
138  j2GBBreakupRadioButtonActionPerformed(evt);
139  }
140  });
141 
142  org.openide.awt.Mnemonics.setLocalizedText(jBreakFileUpLabel, org.openide.util.NbBundle.getMessage(RawDSInputPanel.class, "RawDSInputPanel.jBreakFileUpLabel.text")); // NOI18N
143 
144  infileTypeButtonGroup.add(jNoBreakupRadioButton);
145  org.openide.awt.Mnemonics.setLocalizedText(jNoBreakupRadioButton, org.openide.util.NbBundle.getMessage(RawDSInputPanel.class, "RawDSInputPanel.jNoBreakupRadioButton.text")); // NOI18N
146  jNoBreakupRadioButton.addActionListener(new java.awt.event.ActionListener() {
147  public void actionPerformed(java.awt.event.ActionEvent evt) {
148  jNoBreakupRadioButtonActionPerformed(evt);
149  }
150  });
151 
152  errorLabel.setForeground(new java.awt.Color(255, 0, 0));
153  org.openide.awt.Mnemonics.setLocalizedText(errorLabel, org.openide.util.NbBundle.getMessage(RawDSInputPanel.class, "RawDSInputPanel.errorLabel.text")); // NOI18N
154 
155  org.openide.awt.Mnemonics.setLocalizedText(timeZoneLabel, org.openide.util.NbBundle.getMessage(RawDSInputPanel.class, "RawDSInputPanel.timeZoneLabel.text")); // NOI18N
156 
157  timeZoneComboBox.setMaximumRowCount(30);
158 
159  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
160  this.setLayout(layout);
161  layout.setHorizontalGroup(
162  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
163  .addGroup(layout.createSequentialGroup()
164  .addComponent(pathTextField)
165  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
166  .addComponent(browseButton, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))
167  .addGroup(layout.createSequentialGroup()
168  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
169  .addComponent(pathLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 218, javax.swing.GroupLayout.PREFERRED_SIZE)
170  .addGroup(layout.createSequentialGroup()
171  .addComponent(timeZoneLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 168, javax.swing.GroupLayout.PREFERRED_SIZE)
172  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
173  .addComponent(timeZoneComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)))
174  .addGap(0, 19, Short.MAX_VALUE))
175  .addGroup(layout.createSequentialGroup()
176  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
177  .addComponent(jBreakFileUpLabel)
178  .addComponent(errorLabel)
179  .addGroup(layout.createSequentialGroup()
180  .addGap(10, 10, 10)
181  .addComponent(j2GBBreakupRadioButton)
182  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
183  .addComponent(jNoBreakupRadioButton)))
184  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
185  );
186  layout.setVerticalGroup(
187  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
188  .addGroup(layout.createSequentialGroup()
189  .addComponent(pathLabel)
190  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
191  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
192  .addComponent(pathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
193  .addComponent(browseButton))
194  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
195  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
196  .addComponent(timeZoneLabel)
197  .addComponent(timeZoneComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
198  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
199  .addComponent(errorLabel)
200  .addGap(5, 5, 5)
201  .addComponent(jBreakFileUpLabel)
202  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
203  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
204  .addComponent(jNoBreakupRadioButton)
205  .addComponent(j2GBBreakupRadioButton))
206  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
207  );
208  }// </editor-fold>//GEN-END:initComponents
209  @SuppressWarnings("deprecation")
210  private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
211  String oldText = pathTextField.getText();
212  // set the current directory of the FileChooser if the ImagePath Field is valid
213  File currentDir = new File(oldText);
214  if (currentDir.exists()) {
215  fc.setCurrentDirectory(currentDir);
216  }
217 
218  int retval = fc.showOpenDialog(this);
219  if (retval == JFileChooser.APPROVE_OPTION) {
220  String path = fc.getSelectedFile().getPath();
221  pathTextField.setText(path);
222  }
223  }//GEN-LAST:event_browseButtonActionPerformed
224 
225  private void j2GBBreakupRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_j2GBBreakupRadioButtonActionPerformed
226  // TODO add your handling code here:
227  }//GEN-LAST:event_j2GBBreakupRadioButtonActionPerformed
228 
229  private void jNoBreakupRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jNoBreakupRadioButtonActionPerformed
230  // TODO add your handling code here:
231  }//GEN-LAST:event_jNoBreakupRadioButtonActionPerformed
232 
233  // Variables declaration - do not modify//GEN-BEGIN:variables
234  private javax.swing.JButton browseButton;
235  private javax.swing.JLabel errorLabel;
236  private javax.swing.ButtonGroup infileTypeButtonGroup;
237  private javax.swing.JRadioButton j2GBBreakupRadioButton;
238  private javax.swing.JLabel jBreakFileUpLabel;
239  private javax.swing.JRadioButton jNoBreakupRadioButton;
240  private javax.swing.JLabel pathLabel;
241  private javax.swing.JTextField pathTextField;
242  private javax.swing.JComboBox<String> timeZoneComboBox;
243  private javax.swing.JLabel timeZoneLabel;
244  // End of variables declaration//GEN-END:variables
250  String getImageFilePath() {
251  return pathTextField.getText();
252  }
253 
254  void reset() {
255  //reset the UI elements to default
256  pathTextField.setText(null);
257  j2GBBreakupRadioButton.setSelected(true);
258  }
259 
260  long getChunkSize() {
261  if (jNoBreakupRadioButton.isSelected()) {
262  return -1;
263  } else { //if have more choices here, the selection of each radiobutton should be checked
264  return TWO_GB;
265  }
266  }
267 
268  String getTimeZone() {
269  String tz = timeZoneComboBox.getSelectedItem().toString();
270  return tz.substring(tz.indexOf(")") + 2).trim();
271  }
272 
278  boolean validatePanel() {
279  errorLabel.setVisible(false);
280  String path = getImageFilePath();
281  if (path == null || path.isEmpty()) {
282  return false;
283  }
284 
285  // display warning if there is one (but don't disable "next" button)
286  warnIfPathIsInvalid(path);
287 
288  boolean isExist = new File(path).exists();
289 
290  return (isExist);
291  }
292 
299  @Messages({"RawDSInputPanel.error.text=Path to multi-user data source is on \"C:\" drive"})
300  private void warnIfPathIsInvalid(String path) {
301  if (!PathValidator.isValid(path, Case.getCurrentCase().getCaseType())) {
302  errorLabel.setVisible(true);
303  errorLabel.setText(Bundle.RawDSInputPanel_error_text());
304  }
305  }
306 
307  void storeSettings() {
308  String inFilePath = getImageFilePath();
309  if (null != inFilePath) {
310  String imagePath = inFilePath.substring(0, inFilePath.lastIndexOf(File.separator) + 1);
311  ModuleSettings.setConfigSetting(contextName, PROP_LASTINPUT_PATH, imagePath);
312  }
313  }
314 
315  void readSettings() {
316  String inFilePath = ModuleSettings.getConfigSetting(contextName, PROP_LASTINPUT_PATH);
317  if (null != inFilePath) {
318  if (!inFilePath.isEmpty()) {
319  pathTextField.setText(inFilePath);
320  }
321  }
322  }
323 
331  @Override
332  public void insertUpdate(DocumentEvent e) {
333  firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), false, true);
334  }
335 
336  @Override
337  public void removeUpdate(DocumentEvent e) {
338  firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), false, true);
339  }
340 
341  @Override
342  public void changedUpdate(DocumentEvent e) {
343  firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), false, true);
344  }
345 
349  void select() {
350  pathTextField.requestFocusInWindow();
351  }
352 }

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