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

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.