Autopsy  4.15.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.List;
24 import javax.swing.JFileChooser;
25 import javax.swing.JPanel;
26 import javax.swing.event.DocumentEvent;
27 import javax.swing.event.DocumentListener;
28 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  List<String> timeZoneList = TimeZoneUtils.createTimeZoneList();
86  for (String timeZone : timeZoneList) {
87  timeZoneComboBox.addItem(timeZone);
88  }
89 
90  // set the selected timezone
91  timeZoneComboBox.setSelectedItem(TimeZoneUtils.createTimeZoneString(Calendar.getInstance().getTimeZone()));
92  }
93 
99  @SuppressWarnings("unchecked")
100  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
101  private void initComponents() {
102 
103  infileTypeButtonGroup = new javax.swing.ButtonGroup();
104  pathLabel = new javax.swing.JLabel();
105  pathTextField = new javax.swing.JTextField();
106  browseButton = new javax.swing.JButton();
107  j2GBBreakupRadioButton = new javax.swing.JRadioButton();
108  jBreakFileUpLabel = new javax.swing.JLabel();
109  jNoBreakupRadioButton = new javax.swing.JRadioButton();
110  errorLabel = new javax.swing.JLabel();
111  timeZoneLabel = new javax.swing.JLabel();
112  timeZoneComboBox = new javax.swing.JComboBox<>();
113 
114  org.openide.awt.Mnemonics.setLocalizedText(pathLabel, org.openide.util.NbBundle.getMessage(RawDSInputPanel.class, "RawDSInputPanel.pathLabel.text")); // NOI18N
115 
116  pathTextField.setText(org.openide.util.NbBundle.getMessage(RawDSInputPanel.class, "RawDSInputPanel.pathTextField.text")); // NOI18N
117 
118  org.openide.awt.Mnemonics.setLocalizedText(browseButton, org.openide.util.NbBundle.getMessage(RawDSInputPanel.class, "RawDSInputPanel.browseButton.text")); // NOI18N
119  browseButton.addActionListener(new java.awt.event.ActionListener() {
120  public void actionPerformed(java.awt.event.ActionEvent evt) {
121  browseButtonActionPerformed(evt);
122  }
123  });
124 
125  infileTypeButtonGroup.add(j2GBBreakupRadioButton);
126  j2GBBreakupRadioButton.setSelected(true);
127  org.openide.awt.Mnemonics.setLocalizedText(j2GBBreakupRadioButton, org.openide.util.NbBundle.getMessage(RawDSInputPanel.class, "RawDSInputPanel.j2GBBreakupRadioButton.text")); // NOI18N
128  j2GBBreakupRadioButton.addActionListener(new java.awt.event.ActionListener() {
129  public void actionPerformed(java.awt.event.ActionEvent evt) {
130  j2GBBreakupRadioButtonActionPerformed(evt);
131  }
132  });
133 
134  org.openide.awt.Mnemonics.setLocalizedText(jBreakFileUpLabel, org.openide.util.NbBundle.getMessage(RawDSInputPanel.class, "RawDSInputPanel.jBreakFileUpLabel.text")); // NOI18N
135 
136  infileTypeButtonGroup.add(jNoBreakupRadioButton);
137  org.openide.awt.Mnemonics.setLocalizedText(jNoBreakupRadioButton, org.openide.util.NbBundle.getMessage(RawDSInputPanel.class, "RawDSInputPanel.jNoBreakupRadioButton.text")); // NOI18N
138  jNoBreakupRadioButton.addActionListener(new java.awt.event.ActionListener() {
139  public void actionPerformed(java.awt.event.ActionEvent evt) {
140  jNoBreakupRadioButtonActionPerformed(evt);
141  }
142  });
143 
144  errorLabel.setForeground(new java.awt.Color(255, 0, 0));
145  org.openide.awt.Mnemonics.setLocalizedText(errorLabel, org.openide.util.NbBundle.getMessage(RawDSInputPanel.class, "RawDSInputPanel.errorLabel.text")); // NOI18N
146 
147  org.openide.awt.Mnemonics.setLocalizedText(timeZoneLabel, org.openide.util.NbBundle.getMessage(RawDSInputPanel.class, "RawDSInputPanel.timeZoneLabel.text")); // NOI18N
148 
149  timeZoneComboBox.setMaximumRowCount(30);
150 
151  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
152  this.setLayout(layout);
153  layout.setHorizontalGroup(
154  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
155  .addGroup(layout.createSequentialGroup()
156  .addComponent(pathTextField)
157  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
158  .addComponent(browseButton))
159  .addGroup(layout.createSequentialGroup()
160  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
161  .addComponent(pathLabel)
162  .addGroup(layout.createSequentialGroup()
163  .addComponent(timeZoneLabel)
164  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
165  .addComponent(timeZoneComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
166  .addGap(0, 0, Short.MAX_VALUE))
167  .addGroup(layout.createSequentialGroup()
168  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
169  .addComponent(jBreakFileUpLabel)
170  .addComponent(errorLabel)
171  .addGroup(layout.createSequentialGroup()
172  .addGap(10, 10, 10)
173  .addComponent(j2GBBreakupRadioButton)
174  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
175  .addComponent(jNoBreakupRadioButton)))
176  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
177  );
178  layout.setVerticalGroup(
179  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
180  .addGroup(layout.createSequentialGroup()
181  .addComponent(pathLabel)
182  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
183  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
184  .addComponent(pathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
185  .addComponent(browseButton))
186  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
187  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
188  .addComponent(timeZoneLabel)
189  .addComponent(timeZoneComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
190  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
191  .addComponent(errorLabel)
192  .addGap(5, 5, 5)
193  .addComponent(jBreakFileUpLabel)
194  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
195  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
196  .addComponent(jNoBreakupRadioButton)
197  .addComponent(j2GBBreakupRadioButton))
198  .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
199  );
200  }// </editor-fold>//GEN-END:initComponents
201  @SuppressWarnings("deprecation")
202  private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
203  String oldText = pathTextField.getText();
204  // set the current directory of the FileChooser if the ImagePath Field is valid
205  File currentDir = new File(oldText);
206  if (currentDir.exists()) {
207  fc.setCurrentDirectory(currentDir);
208  }
209 
210  int retval = fc.showOpenDialog(this);
211  if (retval == JFileChooser.APPROVE_OPTION) {
212  String path = fc.getSelectedFile().getPath();
213  pathTextField.setText(path);
214  }
215  }//GEN-LAST:event_browseButtonActionPerformed
216 
217  private void j2GBBreakupRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_j2GBBreakupRadioButtonActionPerformed
218  // TODO add your handling code here:
219  }//GEN-LAST:event_j2GBBreakupRadioButtonActionPerformed
220 
221  private void jNoBreakupRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jNoBreakupRadioButtonActionPerformed
222  // TODO add your handling code here:
223  }//GEN-LAST:event_jNoBreakupRadioButtonActionPerformed
224 
225  // Variables declaration - do not modify//GEN-BEGIN:variables
226  private javax.swing.JButton browseButton;
227  private javax.swing.JLabel errorLabel;
228  private javax.swing.ButtonGroup infileTypeButtonGroup;
229  private javax.swing.JRadioButton j2GBBreakupRadioButton;
230  private javax.swing.JLabel jBreakFileUpLabel;
231  private javax.swing.JRadioButton jNoBreakupRadioButton;
232  private javax.swing.JLabel pathLabel;
233  private javax.swing.JTextField pathTextField;
234  private javax.swing.JComboBox<String> timeZoneComboBox;
235  private javax.swing.JLabel timeZoneLabel;
236  // End of variables declaration//GEN-END:variables
242  String getImageFilePath() {
243  return pathTextField.getText();
244  }
245 
246  void reset() {
247  //reset the UI elements to default
248  pathTextField.setText(null);
249  j2GBBreakupRadioButton.setSelected(true);
250  }
251 
252  long getChunkSize() {
253  if (jNoBreakupRadioButton.isSelected()) {
254  return -1;
255  } else { //if have more choices here, the selection of each radiobutton should be checked
256  return TWO_GB;
257  }
258  }
259 
260  String getTimeZone() {
261  String tz = timeZoneComboBox.getSelectedItem().toString();
262  return tz.substring(tz.indexOf(")") + 2).trim();
263  }
264 
270  boolean validatePanel() {
271  errorLabel.setVisible(false);
272  String path = getImageFilePath();
273  if (path == null || path.isEmpty()) {
274  return false;
275  }
276 
277  // display warning if there is one (but don't disable "next" button)
278  warnIfPathIsInvalid(path);
279 
280  boolean isExist = new File(path).exists();
281 
282  return (isExist);
283  }
284 
291  @Messages({"RawDSInputPanel.error.text=Path to multi-user data source is on \"C:\" drive",
292  "RawDSInputPanel.noOpenCase.errMsg=Exception while getting open case."})
293  private void warnIfPathIsInvalid(String path) {
294  try {
295  if (!PathValidator.isValidForMultiUserCase(path, Case.getCurrentCaseThrows().getCaseType())) {
296  errorLabel.setVisible(true);
297  errorLabel.setText(Bundle.RawDSInputPanel_error_text());
298  }
299  } catch (NoCurrentCaseException ex) {
300  errorLabel.setVisible(true);
301  errorLabel.setText(Bundle.RawDSInputPanel_noOpenCase_errMsg());
302  }
303  }
304 
305  void storeSettings() {
306  String inFilePath = getImageFilePath();
307  if (null != inFilePath) {
308  String imagePath = inFilePath.substring(0, inFilePath.lastIndexOf(File.separator) + 1);
309  ModuleSettings.setConfigSetting(contextName, PROP_LASTINPUT_PATH, imagePath);
310  }
311  }
312 
313  void readSettings() {
314  String inFilePath = ModuleSettings.getConfigSetting(contextName, PROP_LASTINPUT_PATH);
315  if (null != inFilePath) {
316  if (!inFilePath.isEmpty()) {
317  pathTextField.setText(inFilePath);
318  }
319  }
320  }
321 
329  @Override
330  public void insertUpdate(DocumentEvent e) {
331  firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), false, true);
332  }
333 
334  @Override
335  public void removeUpdate(DocumentEvent e) {
336  firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), false, true);
337  }
338 
339  @Override
340  public void changedUpdate(DocumentEvent e) {
341  firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), false, true);
342  }
343 
347  void select() {
348  pathTextField.requestFocusInWindow();
349  }
350 }

Copyright © 2012-2020 Basis Technology. Generated on: Mon Jul 6 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.