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

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