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;
39 @SuppressWarnings(
"PMD.SingularField")
40 final class RawDSInputPanel extends JPanel implements DocumentListener {
41 private static final long TWO_GB = 2000000000L;
42 private static final long serialVersionUID = 1L;
43 private final String PROP_LASTINPUT_PATH =
"LBL_LastInputFile_PATH";
44 private final JFileChooser fc =
new JFileChooser();
46 private final String contextName;
50 private RawDSInputPanel(String context) {
53 errorLabel.setVisible(
false);
55 fc.setDragEnabled(
false);
56 fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
57 fc.setMultiSelectionEnabled(
false);
59 this.contextName = context;
65 static synchronized RawDSInputPanel createInstance(String context) {
66 RawDSInputPanel instance =
new RawDSInputPanel(context);
69 instance.createTimeZoneList();
76 private void postInit() {
77 pathTextField.getDocument().addDocumentListener(
this);
84 private void createTimeZoneList() {
85 List<String> timeZoneList = TimeZoneUtils.createTimeZoneList();
86 for (String timeZone : timeZoneList) {
87 timeZoneComboBox.addItem(timeZone);
91 timeZoneComboBox.setSelectedItem(TimeZoneUtils.createTimeZoneString(Calendar.getInstance().getTimeZone()));
99 @SuppressWarnings(
"unchecked")
101 private
void initComponents() {
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<>();
114 org.openide.awt.Mnemonics.setLocalizedText(pathLabel,
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.pathLabel.text"));
116 pathTextField.setText(
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.pathTextField.text"));
118 org.openide.awt.Mnemonics.setLocalizedText(browseButton,
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.browseButton.text"));
119 browseButton.addActionListener(
new java.awt.event.ActionListener() {
120 public void actionPerformed(java.awt.event.ActionEvent evt) {
121 browseButtonActionPerformed(evt);
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"));
128 j2GBBreakupRadioButton.addActionListener(
new java.awt.event.ActionListener() {
129 public void actionPerformed(java.awt.event.ActionEvent evt) {
130 j2GBBreakupRadioButtonActionPerformed(evt);
134 org.openide.awt.Mnemonics.setLocalizedText(jBreakFileUpLabel,
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.jBreakFileUpLabel.text"));
136 infileTypeButtonGroup.add(jNoBreakupRadioButton);
137 org.openide.awt.Mnemonics.setLocalizedText(jNoBreakupRadioButton,
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.jNoBreakupRadioButton.text"));
138 jNoBreakupRadioButton.addActionListener(
new java.awt.event.ActionListener() {
139 public void actionPerformed(java.awt.event.ActionEvent evt) {
140 jNoBreakupRadioButtonActionPerformed(evt);
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"));
147 org.openide.awt.Mnemonics.setLocalizedText(timeZoneLabel,
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.timeZoneLabel.text"));
149 timeZoneComboBox.setMaximumRowCount(30);
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()
173 .addComponent(j2GBBreakupRadioButton)
174 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
175 .addComponent(jNoBreakupRadioButton)))
176 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
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)
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))
201 @SuppressWarnings(
"deprecation")
202 private
void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {
203 String oldText = pathTextField.getText();
205 File currentDir =
new File(oldText);
206 if (currentDir.exists()) {
207 fc.setCurrentDirectory(currentDir);
210 int retval = fc.showOpenDialog(
this);
211 if (retval == JFileChooser.APPROVE_OPTION) {
212 String path = fc.getSelectedFile().getPath();
213 pathTextField.setText(path);
217 private void j2GBBreakupRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
221 private void jNoBreakupRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
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;
242 String getImageFilePath() {
243 return pathTextField.getText();
248 pathTextField.setText(null);
249 j2GBBreakupRadioButton.setSelected(
true);
252 long getChunkSize() {
253 if (jNoBreakupRadioButton.isSelected()) {
260 String getTimeZone() {
261 String tz = timeZoneComboBox.getSelectedItem().toString();
262 return tz.substring(tz.indexOf(
")") + 2).trim();
270 boolean validatePanel() {
271 errorLabel.setVisible(
false);
272 String path = getImageFilePath();
273 if (path == null || path.isEmpty()) {
278 warnIfPathIsInvalid(path);
280 boolean isExist =
new File(path).exists();
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) {
295 if (!PathValidator.isValidForCaseType(path, Case.getCurrentCaseThrows().getCaseType())) {
296 errorLabel.setVisible(
true);
297 errorLabel.setText(Bundle.RawDSInputPanel_error_text());
299 }
catch (NoCurrentCaseException ex) {
300 errorLabel.setVisible(
true);
301 errorLabel.setText(Bundle.RawDSInputPanel_noOpenCase_errMsg());
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);
313 void readSettings() {
314 String inFilePath = ModuleSettings.getConfigSetting(contextName, PROP_LASTINPUT_PATH);
315 if (null != inFilePath) {
316 if (!inFilePath.isEmpty()) {
317 pathTextField.setText(inFilePath);
330 public void insertUpdate(DocumentEvent e) {
331 firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(),
false,
true);
335 public void removeUpdate(DocumentEvent e) {
336 firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(),
false,
true);
340 public void changedUpdate(DocumentEvent e) {
341 firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(),
false,
true);
348 pathTextField.requestFocusInWindow();