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;
36 final class RawDSInputPanel
extends JPanel implements DocumentListener {
37 private static final long TWO_GB = 2000000000L;
38 private static final long serialVersionUID = 1L;
39 private final String PROP_LASTINPUT_PATH =
"LBL_LastInputFile_PATH";
40 private final JFileChooser fc =
new JFileChooser();
42 private final String contextName;
46 private RawDSInputPanel(String context) {
49 errorLabel.setVisible(
false);
51 fc.setDragEnabled(
false);
52 fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
53 fc.setMultiSelectionEnabled(
false);
55 this.contextName = context;
61 static synchronized RawDSInputPanel createInstance(String context) {
62 RawDSInputPanel instance =
new RawDSInputPanel(context);
65 instance.createTimeZoneList();
72 private void postInit() {
73 pathTextField.getDocument().addDocumentListener(
this);
80 private void createTimeZoneList() {
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);
90 timeZoneComboBox.addItem(item);
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());
100 timeZoneComboBox.setSelectedItem(formatted);
108 @SuppressWarnings(
"unchecked")
110 private
void initComponents() {
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<>();
123 org.openide.awt.Mnemonics.setLocalizedText(pathLabel,
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.pathLabel.text"));
125 pathTextField.setText(
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.pathTextField.text"));
127 org.openide.awt.Mnemonics.setLocalizedText(browseButton,
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.browseButton.text"));
128 browseButton.addActionListener(
new java.awt.event.ActionListener() {
129 public void actionPerformed(java.awt.event.ActionEvent evt) {
130 browseButtonActionPerformed(evt);
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"));
137 j2GBBreakupRadioButton.addActionListener(
new java.awt.event.ActionListener() {
138 public void actionPerformed(java.awt.event.ActionEvent evt) {
139 j2GBBreakupRadioButtonActionPerformed(evt);
143 org.openide.awt.Mnemonics.setLocalizedText(jBreakFileUpLabel,
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.jBreakFileUpLabel.text"));
145 infileTypeButtonGroup.add(jNoBreakupRadioButton);
146 org.openide.awt.Mnemonics.setLocalizedText(jNoBreakupRadioButton,
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.jNoBreakupRadioButton.text"));
147 jNoBreakupRadioButton.addActionListener(
new java.awt.event.ActionListener() {
148 public void actionPerformed(java.awt.event.ActionEvent evt) {
149 jNoBreakupRadioButtonActionPerformed(evt);
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"));
156 org.openide.awt.Mnemonics.setLocalizedText(timeZoneLabel,
org.openide.util.NbBundle.getMessage(RawDSInputPanel.class,
"RawDSInputPanel.timeZoneLabel.text"));
158 timeZoneComboBox.setMaximumRowCount(30);
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()
182 .addComponent(j2GBBreakupRadioButton)
183 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
184 .addComponent(jNoBreakupRadioButton)))
185 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
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)
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))
210 @SuppressWarnings(
"deprecation")
211 private
void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {
212 String oldText = pathTextField.getText();
214 File currentDir =
new File(oldText);
215 if (currentDir.exists()) {
216 fc.setCurrentDirectory(currentDir);
219 int retval = fc.showOpenDialog(
this);
220 if (retval == JFileChooser.APPROVE_OPTION) {
221 String path = fc.getSelectedFile().getPath();
222 pathTextField.setText(path);
226 private void j2GBBreakupRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
230 private void jNoBreakupRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
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;
251 String getImageFilePath() {
252 return pathTextField.getText();
257 pathTextField.setText(null);
258 j2GBBreakupRadioButton.setSelected(
true);
261 long getChunkSize() {
262 if (jNoBreakupRadioButton.isSelected()) {
269 String getTimeZone() {
270 String tz = timeZoneComboBox.getSelectedItem().toString();
271 return tz.substring(tz.indexOf(
")") + 2).trim();
279 boolean validatePanel() {
280 errorLabel.setVisible(
false);
281 String path = getImageFilePath();
282 if (path == null || path.isEmpty()) {
287 warnIfPathIsInvalid(path);
289 boolean isExist =
new File(path).exists();
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) {
304 if (!PathValidator.isValid(path, Case.getOpenCase().getCaseType())) {
305 errorLabel.setVisible(
true);
306 errorLabel.setText(Bundle.RawDSInputPanel_error_text());
308 }
catch (NoCurrentCaseException ex) {
309 errorLabel.setVisible(
true);
310 errorLabel.setText(Bundle.RawDSInputPanel_noOpenCase_errMsg());
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);
322 void readSettings() {
323 String inFilePath = ModuleSettings.getConfigSetting(contextName, PROP_LASTINPUT_PATH);
324 if (null != inFilePath) {
325 if (!inFilePath.isEmpty()) {
326 pathTextField.setText(inFilePath);
339 public void insertUpdate(DocumentEvent e) {
340 firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(),
false,
true);
344 public void removeUpdate(DocumentEvent e) {
345 firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(),
false,
true);
349 public void changedUpdate(DocumentEvent e) {
350 firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(),
false,
true);
357 pathTextField.requestFocusInWindow();