19 package org.sleuthkit.autopsy.datasourceprocessors;
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;
40 @SuppressWarnings(
"PMD.SingularField")
41 final class RawDSInputPanel extends JPanel implements DocumentListener {
42 private static final long TWO_GB = 2000000000L;
43 private static final long serialVersionUID = 1L;
44 private final String PROP_LASTINPUT_PATH =
"LBL_LastInputFile_PATH";
45 private JFileChooser fc;
46 private JFileChooserFactory chooserHelper =
new JFileChooserFactory();
48 private final String contextName;
52 private RawDSInputPanel(String context) {
55 errorLabel.setVisible(
false);
56 this.contextName = context;
62 static synchronized RawDSInputPanel createInstance(String context) {
63 RawDSInputPanel instance =
new RawDSInputPanel(context);
66 instance.createTimeZoneList();
73 private void postInit() {
74 pathTextField.getDocument().addDocumentListener(
this);
81 private void createTimeZoneList() {
82 List<String> timeZoneList = TimeZoneUtils.createTimeZoneList();
83 for (String timeZone : timeZoneList) {
84 timeZoneComboBox.addItem(timeZone);
88 timeZoneComboBox.setSelectedItem(TimeZoneUtils.createTimeZoneString(Calendar.getInstance().getTimeZone()));
96 @SuppressWarnings(
"unchecked")
98 private
void initComponents() {
100 infileTypeButtonGroup =
new javax.swing.ButtonGroup();
101 pathLabel =
new javax.swing.JLabel();
102 pathTextField =
new javax.swing.JTextField();
103 browseButton =
new javax.swing.JButton();
104 j2GBBreakupRadioButton =
new javax.swing.JRadioButton();
105 jBreakFileUpLabel =
new javax.swing.JLabel();
106 jNoBreakupRadioButton =
new javax.swing.JRadioButton();
107 errorLabel =
new javax.swing.JLabel();
108 timeZoneLabel =
new javax.swing.JLabel();
109 timeZoneComboBox =
new javax.swing.JComboBox<>();
111 org.openide.awt.Mnemonics.setLocalizedText(pathLabel,
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.pathLabel.text"));
113 pathTextField.setText(
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.pathTextField.text"));
115 org.openide.awt.Mnemonics.setLocalizedText(browseButton,
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.browseButton.text"));
116 browseButton.addActionListener(
new java.awt.event.ActionListener() {
117 public void actionPerformed(java.awt.event.ActionEvent evt) {
118 browseButtonActionPerformed(evt);
122 infileTypeButtonGroup.add(j2GBBreakupRadioButton);
123 j2GBBreakupRadioButton.setSelected(
true);
124 org.openide.awt.Mnemonics.setLocalizedText(j2GBBreakupRadioButton,
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.j2GBBreakupRadioButton.text"));
125 j2GBBreakupRadioButton.addActionListener(
new java.awt.event.ActionListener() {
126 public void actionPerformed(java.awt.event.ActionEvent evt) {
127 j2GBBreakupRadioButtonActionPerformed(evt);
131 org.openide.awt.Mnemonics.setLocalizedText(jBreakFileUpLabel,
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.jBreakFileUpLabel.text"));
133 infileTypeButtonGroup.add(jNoBreakupRadioButton);
134 org.openide.awt.Mnemonics.setLocalizedText(jNoBreakupRadioButton,
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.jNoBreakupRadioButton.text"));
135 jNoBreakupRadioButton.addActionListener(
new java.awt.event.ActionListener() {
136 public void actionPerformed(java.awt.event.ActionEvent evt) {
137 jNoBreakupRadioButtonActionPerformed(evt);
141 errorLabel.setForeground(
new java.awt.Color(255, 0, 0));
142 org.openide.awt.Mnemonics.setLocalizedText(errorLabel,
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.errorLabel.text"));
144 org.openide.awt.Mnemonics.setLocalizedText(timeZoneLabel,
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.timeZoneLabel.text"));
146 timeZoneComboBox.setMaximumRowCount(30);
148 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
149 this.setLayout(layout);
150 layout.setHorizontalGroup(
151 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
152 .addGroup(layout.createSequentialGroup()
153 .addComponent(pathTextField)
154 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
155 .addComponent(browseButton))
156 .addGroup(layout.createSequentialGroup()
157 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
158 .addComponent(pathLabel)
159 .addGroup(layout.createSequentialGroup()
160 .addComponent(timeZoneLabel)
161 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
162 .addComponent(timeZoneComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
163 .addGap(0, 0, Short.MAX_VALUE))
164 .addGroup(layout.createSequentialGroup()
165 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
166 .addComponent(jBreakFileUpLabel)
167 .addComponent(errorLabel)
168 .addGroup(layout.createSequentialGroup()
170 .addComponent(j2GBBreakupRadioButton)
171 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
172 .addComponent(jNoBreakupRadioButton)))
173 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
175 layout.setVerticalGroup(
176 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
177 .addGroup(layout.createSequentialGroup()
178 .addComponent(pathLabel)
179 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
180 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
181 .addComponent(pathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
182 .addComponent(browseButton))
183 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
184 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
185 .addComponent(timeZoneLabel)
186 .addComponent(timeZoneComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
187 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
188 .addComponent(errorLabel)
190 .addComponent(jBreakFileUpLabel)
191 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
192 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
193 .addComponent(jNoBreakupRadioButton)
194 .addComponent(j2GBBreakupRadioButton))
195 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
198 @SuppressWarnings(
"deprecation")
199 private
void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {
201 fc = chooserHelper.getChooser();
202 fc.setDragEnabled(
false);
203 fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
204 fc.setMultiSelectionEnabled(
false);
207 String oldText = pathTextField.getText();
209 File currentDir =
new File(oldText);
210 if (currentDir.exists()) {
211 fc.setCurrentDirectory(currentDir);
214 int retval = fc.showOpenDialog(
this);
215 if (retval == JFileChooser.APPROVE_OPTION) {
216 String path = fc.getSelectedFile().getPath();
217 pathTextField.setText(path);
221 private void j2GBBreakupRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
225 private void jNoBreakupRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
230 private javax.swing.JButton browseButton;
231 private javax.swing.JLabel errorLabel;
232 private javax.swing.ButtonGroup infileTypeButtonGroup;
233 private javax.swing.JRadioButton j2GBBreakupRadioButton;
234 private javax.swing.JLabel jBreakFileUpLabel;
235 private javax.swing.JRadioButton jNoBreakupRadioButton;
236 private javax.swing.JLabel pathLabel;
237 private javax.swing.JTextField pathTextField;
238 private javax.swing.JComboBox<String> timeZoneComboBox;
239 private javax.swing.JLabel timeZoneLabel;
246 String getImageFilePath() {
247 return pathTextField.getText();
252 pathTextField.setText(null);
253 j2GBBreakupRadioButton.setSelected(
true);
256 long getChunkSize() {
257 if (jNoBreakupRadioButton.isSelected()) {
264 String getTimeZone() {
265 String tz = timeZoneComboBox.getSelectedItem().toString();
266 return tz.substring(tz.indexOf(
")") + 2).trim();
274 boolean validatePanel() {
275 errorLabel.setVisible(
false);
276 String path = getImageFilePath();
277 if (path == null || path.isEmpty()) {
282 warnIfPathIsInvalid(path);
284 boolean isExist =
new File(path).exists();
295 @Messages({
"RawDSInputPanel.error.text=Path to multi-user data source is on \"C:\" drive",
296 "RawDSInputPanel.noOpenCase.errMsg=Exception while getting open case."})
297 private void warnIfPathIsInvalid(String path) {
299 if (!PathValidator.isValidForCaseType(path, Case.getCurrentCaseThrows().getCaseType())) {
300 errorLabel.setVisible(
true);
301 errorLabel.setText(Bundle.RawDSInputPanel_error_text());
303 }
catch (NoCurrentCaseException ex) {
304 errorLabel.setVisible(
true);
305 errorLabel.setText(Bundle.RawDSInputPanel_noOpenCase_errMsg());
309 void storeSettings() {
310 String inFilePath = getImageFilePath();
311 if (null != inFilePath) {
312 String imagePath = inFilePath.substring(0, inFilePath.lastIndexOf(File.separator) + 1);
313 ModuleSettings.setConfigSetting(contextName, PROP_LASTINPUT_PATH, imagePath);
317 void readSettings() {
318 String inFilePath = ModuleSettings.getConfigSetting(contextName, PROP_LASTINPUT_PATH);
319 if (null != inFilePath) {
320 if (!inFilePath.isEmpty()) {
321 pathTextField.setText(inFilePath);
334 public void insertUpdate(DocumentEvent e) {
335 firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(),
false,
true);
339 public void removeUpdate(DocumentEvent e) {
340 firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(),
false,
true);
344 public void changedUpdate(DocumentEvent e) {
345 firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(),
false,
true);
352 pathTextField.requestFocusInWindow();