19 package org.sleuthkit.autopsy.datasourceprocessors;
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;
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() {
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);
94 timeZoneComboBox.addItem(item);
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());
104 timeZoneComboBox.setSelectedItem(formatted);
112 @SuppressWarnings(
"unchecked")
114 private
void initComponents() {
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<>();
127 org.openide.awt.Mnemonics.setLocalizedText(pathLabel,
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.pathLabel.text"));
129 pathTextField.setText(
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.pathTextField.text"));
131 org.openide.awt.Mnemonics.setLocalizedText(browseButton,
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.browseButton.text"));
132 browseButton.addActionListener(
new java.awt.event.ActionListener() {
133 public void actionPerformed(java.awt.event.ActionEvent evt) {
134 browseButtonActionPerformed(evt);
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"));
141 j2GBBreakupRadioButton.addActionListener(
new java.awt.event.ActionListener() {
142 public void actionPerformed(java.awt.event.ActionEvent evt) {
143 j2GBBreakupRadioButtonActionPerformed(evt);
147 org.openide.awt.Mnemonics.setLocalizedText(jBreakFileUpLabel,
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.jBreakFileUpLabel.text"));
149 infileTypeButtonGroup.add(jNoBreakupRadioButton);
150 org.openide.awt.Mnemonics.setLocalizedText(jNoBreakupRadioButton,
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.jNoBreakupRadioButton.text"));
151 jNoBreakupRadioButton.addActionListener(
new java.awt.event.ActionListener() {
152 public void actionPerformed(java.awt.event.ActionEvent evt) {
153 jNoBreakupRadioButtonActionPerformed(evt);
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"));
160 org.openide.awt.Mnemonics.setLocalizedText(timeZoneLabel,
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.timeZoneLabel.text"));
162 timeZoneComboBox.setMaximumRowCount(30);
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()
186 .addComponent(j2GBBreakupRadioButton)
187 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
188 .addComponent(jNoBreakupRadioButton)))
189 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
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)
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))
214 @SuppressWarnings(
"deprecation")
215 private
void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {
216 String oldText = pathTextField.getText();
218 File currentDir =
new File(oldText);
219 if (currentDir.exists()) {
220 fc.setCurrentDirectory(currentDir);
223 int retval = fc.showOpenDialog(
this);
224 if (retval == JFileChooser.APPROVE_OPTION) {
225 String path = fc.getSelectedFile().getPath();
226 pathTextField.setText(path);
230 private void j2GBBreakupRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
234 private void jNoBreakupRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
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;
255 String getImageFilePath() {
256 return pathTextField.getText();
261 pathTextField.setText(null);
262 j2GBBreakupRadioButton.setSelected(
true);
265 long getChunkSize() {
266 if (jNoBreakupRadioButton.isSelected()) {
273 String getTimeZone() {
274 String tz = timeZoneComboBox.getSelectedItem().toString();
275 return tz.substring(tz.indexOf(
")") + 2).trim();
283 boolean validatePanel() {
284 errorLabel.setVisible(
false);
285 String path = getImageFilePath();
286 if (path == null || path.isEmpty()) {
291 warnIfPathIsInvalid(path);
293 boolean isExist =
new File(path).exists();
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) {
308 if (!PathValidator.isValid(path, Case.getCurrentCaseThrows().getCaseType())) {
309 errorLabel.setVisible(
true);
310 errorLabel.setText(Bundle.RawDSInputPanel_error_text());
312 }
catch (NoCurrentCaseException ex) {
313 errorLabel.setVisible(
true);
314 errorLabel.setText(Bundle.RawDSInputPanel_noOpenCase_errMsg());
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);
326 void readSettings() {
327 String inFilePath = ModuleSettings.getConfigSetting(contextName, PROP_LASTINPUT_PATH);
328 if (null != inFilePath) {
329 if (!inFilePath.isEmpty()) {
330 pathTextField.setText(inFilePath);
343 public void insertUpdate(DocumentEvent e) {
344 firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(),
false,
true);
348 public void removeUpdate(DocumentEvent e) {
349 firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(),
false,
true);
353 public void changedUpdate(DocumentEvent e) {
354 firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(),
false,
true);
361 pathTextField.requestFocusInWindow();