Autopsy  3.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
ImageFilePanel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2012 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.casemodule;
20 
21 import java.beans.PropertyChangeListener;
22 import java.beans.PropertyChangeSupport;
23 import java.io.File;
24 import java.util.Calendar;
25 import java.util.List;
26 import java.util.SimpleTimeZone;
27 import java.util.TimeZone;
28 import javax.swing.JFileChooser;
29 import javax.swing.event.DocumentEvent;
30 import javax.swing.event.DocumentListener;
31 import javax.swing.JPanel;
32 import javax.swing.filechooser.FileFilter;
33 
34 import org.openide.util.NbBundle;
38 import java.util.logging.Level;
40 
44 public class ImageFilePanel extends JPanel implements DocumentListener {
45 
46  private final String PROP_LASTIMAGE_PATH = "LBL_LastImage_PATH"; //NON-NLS
47  private static final Logger logger = Logger.getLogger(ImageFilePanel.class.getName());
48  private PropertyChangeSupport pcs = null;
49  private JFileChooser fc = new JFileChooser();
50 
51  // Externally supplied name is used to store settings
52  private String contextName;
53 
59  private ImageFilePanel(String context, List<FileFilter> fileChooserFilters) {
61  fc.setDragEnabled(false);
62  fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
63  fc.setMultiSelectionEnabled(false);
64 
65  boolean firstFilter = true;
66  for (FileFilter filter: fileChooserFilters ) {
67  if (firstFilter) { // set the first on the list as the default selection
68  fc.setFileFilter(filter);
69  firstFilter = false;
70  }
71  else {
72  fc.addChoosableFileFilter(filter);
73  }
74  }
75 
76  this.contextName = context;
77  pcs = new PropertyChangeSupport(this);
78 
80  }
81 
85  public static synchronized ImageFilePanel createInstance(String context, List<FileFilter> fileChooserFilters) {
86 
87  ImageFilePanel instance = new ImageFilePanel(context, fileChooserFilters );
88 
89  instance.postInit();
90 
91  return instance;
92  }
93 
94  //post-constructor initialization to properly initialize listener support
95  //without leaking references of uninitialized objects
96  private void postInit() {
97  pathTextField.getDocument().addDocumentListener(this);
98  }
99 
100 
101 
107  @SuppressWarnings("unchecked")
108  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
109  private void initComponents() {
110 
111  pathLabel = new javax.swing.JLabel();
112  browseButton = new javax.swing.JButton();
113  pathTextField = new javax.swing.JTextField();
114  timeZoneLabel = new javax.swing.JLabel();
115  timeZoneComboBox = new javax.swing.JComboBox<String>();
116  noFatOrphansCheckbox = new javax.swing.JCheckBox();
117  descLabel = new javax.swing.JLabel();
118 
119  setMinimumSize(new java.awt.Dimension(0, 65));
120  setPreferredSize(new java.awt.Dimension(403, 65));
121 
122  org.openide.awt.Mnemonics.setLocalizedText(pathLabel, org.openide.util.NbBundle.getMessage(ImageFilePanel.class, "ImageFilePanel.pathLabel.text")); // NOI18N
123 
124  org.openide.awt.Mnemonics.setLocalizedText(browseButton, org.openide.util.NbBundle.getMessage(ImageFilePanel.class, "ImageFilePanel.browseButton.text")); // NOI18N
125  browseButton.addActionListener(new java.awt.event.ActionListener() {
126  public void actionPerformed(java.awt.event.ActionEvent evt) {
128  }
129  });
130 
131  pathTextField.setText(org.openide.util.NbBundle.getMessage(ImageFilePanel.class, "ImageFilePanel.pathTextField.text")); // NOI18N
132 
133  org.openide.awt.Mnemonics.setLocalizedText(timeZoneLabel, org.openide.util.NbBundle.getMessage(ImageFilePanel.class, "ImageFilePanel.timeZoneLabel.text")); // NOI18N
134 
135  timeZoneComboBox.setMaximumRowCount(30);
136 
137  org.openide.awt.Mnemonics.setLocalizedText(noFatOrphansCheckbox, org.openide.util.NbBundle.getMessage(ImageFilePanel.class, "ImageFilePanel.noFatOrphansCheckbox.text")); // NOI18N
138  noFatOrphansCheckbox.setToolTipText(org.openide.util.NbBundle.getMessage(ImageFilePanel.class, "ImageFilePanel.noFatOrphansCheckbox.toolTipText")); // NOI18N
139 
140  org.openide.awt.Mnemonics.setLocalizedText(descLabel, org.openide.util.NbBundle.getMessage(ImageFilePanel.class, "ImageFilePanel.descLabel.text")); // NOI18N
141 
142  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
143  this.setLayout(layout);
144  layout.setHorizontalGroup(
145  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
146  .addGroup(layout.createSequentialGroup()
147  .addComponent(pathTextField)
148  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
149  .addComponent(browseButton)
150  .addGap(2, 2, 2))
151  .addGroup(layout.createSequentialGroup()
152  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
153  .addGroup(layout.createSequentialGroup()
154  .addComponent(timeZoneLabel)
155  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
156  .addComponent(timeZoneComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE))
157  .addComponent(pathLabel)
158  .addComponent(noFatOrphansCheckbox)
159  .addGroup(layout.createSequentialGroup()
160  .addGap(21, 21, 21)
161  .addComponent(descLabel)))
162  .addGap(0, 20, Short.MAX_VALUE))
163  );
164  layout.setVerticalGroup(
165  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
166  .addGroup(layout.createSequentialGroup()
167  .addComponent(pathLabel)
168  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
169  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
170  .addComponent(browseButton)
171  .addComponent(pathTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
172  .addGap(18, 18, 18)
173  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
174  .addComponent(timeZoneLabel)
175  .addComponent(timeZoneComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
176  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
177  .addComponent(noFatOrphansCheckbox)
178  .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
179  .addComponent(descLabel)
180  .addContainerGap(13, Short.MAX_VALUE))
181  );
182  }// </editor-fold>//GEN-END:initComponents
183 
184  private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
185  String oldText = pathTextField.getText();
186  // set the current directory of the FileChooser if the ImagePath Field is valid
187  File currentDir = new File(oldText);
188  if (currentDir.exists()) {
189  fc.setCurrentDirectory(currentDir);
190  }
191 
192  int retval = fc.showOpenDialog(this);
193  if (retval == JFileChooser.APPROVE_OPTION) {
194  String path = fc.getSelectedFile().getPath();
195  pathTextField.setText(path);
196  }
197 
198 
199 
200  try {
201  pcs.firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.FOCUS_NEXT.toString(), false, true);
202  }
203  catch (Exception e) {
204  logger.log(Level.SEVERE, "ImageFilePanel listener threw exception", e); //NON-NLS
205  MessageNotifyUtil.Notify.show(NbBundle.getMessage(this.getClass(), "ImageFilePanel.moduleErr"),
206  NbBundle.getMessage(this.getClass(), "ImageFilePanel.moduleErr.msg"),
208  }
209  }//GEN-LAST:event_browseButtonActionPerformed
210 
211  // Variables declaration - do not modify//GEN-BEGIN:variables
212  private javax.swing.JButton browseButton;
213  private javax.swing.JLabel descLabel;
214  private javax.swing.JCheckBox noFatOrphansCheckbox;
215  private javax.swing.JLabel pathLabel;
216  private javax.swing.JTextField pathTextField;
217  private javax.swing.JComboBox<String> timeZoneComboBox;
218  private javax.swing.JLabel timeZoneLabel;
219  // End of variables declaration//GEN-END:variables
220 
225  public String getContentPaths() {
226  return pathTextField.getText();
227  }
228 
232  public void setContentPath(String s) {
233  pathTextField.setText(s);
234  }
235 
236  public String getTimeZone() {
237  String tz = timeZoneComboBox.getSelectedItem().toString();
238  return tz.substring(tz.indexOf(")") + 2).trim();
239 
240  }
241 
242  public boolean getNoFatOrphans() {
243  return noFatOrphansCheckbox.isSelected();
244  }
245 
246 
247 
248  public void reset() {
249  //reset the UI elements to default
250  pathTextField.setText(null);
251  }
252 
257  public boolean validatePanel() {
258  String path = getContentPaths();
259  if (path == null || path.isEmpty()) {
260  return false;
261  }
262 
263  boolean isExist = Case.pathExists(path);
264  boolean isPhysicalDrive = Case.isPhysicalDrive(path);
265  boolean isPartition = Case.isPartition(path);
266 
267  return (isExist || isPhysicalDrive || isPartition);
268  }
269 
270 
271  public void storeSettings() {
272  String imagePathName = getContentPaths();
273  if (null != imagePathName ) {
274  String imagePath = imagePathName.substring(0, imagePathName.lastIndexOf(File.separator) + 1);
275  ModuleSettings.setConfigSetting(contextName, PROP_LASTIMAGE_PATH, imagePath);
276  }
277  }
278 
279  public void readSettings() {
280  String lastImagePath = ModuleSettings.getConfigSetting(contextName, PROP_LASTIMAGE_PATH);
281  if (null != lastImagePath) {
282  if (!lastImagePath.isEmpty())
283  pathTextField.setText(lastImagePath);
284  }
285  }
290  public void createTimeZoneList() {
291  // load and add all timezone
292  String[] ids = SimpleTimeZone.getAvailableIDs();
293  for (String id : ids) {
294  TimeZone zone = TimeZone.getTimeZone(id);
295  int offset = zone.getRawOffset() / 1000;
296  int hour = offset / 3600;
297  int minutes = (offset % 3600) / 60;
298  String item = String.format("(GMT%+d:%02d) %s", hour, minutes, id); //NON-NLS
299 
300  /*
301  * DateFormat dfm = new SimpleDateFormat("z");
302  * dfm.setTimeZone(zone); boolean hasDaylight =
303  * zone.useDaylightTime(); String first = dfm.format(new Date(2010,
304  * 1, 1)); String second = dfm.format(new Date(2011, 6, 6)); int mid
305  * = hour * -1; String result = first + Integer.toString(mid);
306  * if(hasDaylight){ result = result + second; }
307  * timeZoneComboBox.addItem(item + " (" + result + ")");
308  */
309  timeZoneComboBox.addItem(item);
310  }
311  // get the current timezone
312  TimeZone thisTimeZone = Calendar.getInstance().getTimeZone();
313  int thisOffset = thisTimeZone.getRawOffset() / 1000;
314  int thisHour = thisOffset / 3600;
315  int thisMinutes = (thisOffset % 3600) / 60;
316  String formatted = String.format("(GMT%+d:%02d) %s", thisHour, thisMinutes, thisTimeZone.getID()); //NON-NLS
317 
318  // set the selected timezone
319  timeZoneComboBox.setSelectedItem(formatted);
320  }
327  @Override
328  public void insertUpdate(DocumentEvent e) {
329 
330  try {
331  pcs.firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), false, true);
332  }
333  catch (Exception ee) {
334  logger.log(Level.SEVERE, "ImageFilePanel listener threw exception", ee); //NON-NLS
335  MessageNotifyUtil.Notify.show(NbBundle.getMessage(this.getClass(), "ImageFilePanel.moduleErr"),
336  NbBundle.getMessage(this.getClass(), "ImageFilePanel.moduleErr.msg"),
338  }
339  }
340 
341  @Override
342  public void removeUpdate(DocumentEvent e) {
343  try {
344  pcs.firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), false, true);
345  }
346  catch (Exception ee) {
347  logger.log(Level.SEVERE, "ImageFilePanel listener threw exception", ee); //NON-NLS
348  MessageNotifyUtil.Notify.show(NbBundle.getMessage(this.getClass(), "ImageFilePanel.moduleErr"),
349  NbBundle.getMessage(this.getClass(), "ImageFilePanel.moduleErr.msg"),
351  }
352  }
353 
354  @Override
355  public void changedUpdate(DocumentEvent e) {
356 
357  try {
358  pcs.firePropertyChange(DataSourceProcessor.DSP_PANEL_EVENT.UPDATE_UI.toString(), false, true);
359  }
360  catch (Exception ee) {
361  logger.log(Level.SEVERE, "ImageFilePanel listener threw exception", ee); //NON-NLS
362  MessageNotifyUtil.Notify.show(NbBundle.getMessage(this.getClass(), "ImageFilePanel.moduleErr"),
363  NbBundle.getMessage(this.getClass(), "ImageFilePanel.moduleErr.msg"),
365  }
366  }
367 
371  public void select() {
372  pathTextField.requestFocusInWindow();
373  }
374 
375 
376  @Override
377  public synchronized void addPropertyChangeListener(PropertyChangeListener pcl) {
378  super.addPropertyChangeListener(pcl);
379 
380  if (pcs == null) {
381  pcs = new PropertyChangeSupport(this);
382  }
383 
384  pcs.addPropertyChangeListener(pcl);
385  }
386 
387  @Override
388  public void removePropertyChangeListener(PropertyChangeListener pcl) {
389  super.removePropertyChangeListener(pcl);
390 
391  pcs.removePropertyChangeListener(pcl);
392  }
393 
394 }
void removePropertyChangeListener(PropertyChangeListener pcl)
FOCUS_NEXT
the caller UI may move focus the the next UI element, following the panel.
UPDATE_UI
the content of JPanel has changed that MAY warrant updates to the caller UI
synchronized void addPropertyChangeListener(PropertyChangeListener pcl)
static synchronized ImageFilePanel createInstance(String context, List< FileFilter > fileChooserFilters)
void browseButtonActionPerformed(java.awt.event.ActionEvent evt)
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
ImageFilePanel(String context, List< FileFilter > fileChooserFilters)
javax.swing.JComboBox< String > timeZoneComboBox
static boolean pathExists(String imgPath)
Definition: Case.java:848
static String getConfigSetting(String moduleName, String settingName)
static void show(String title, String message, MessageType type, ActionListener actionListener)
static Logger getLogger(String name)
Definition: Logger.java:131

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