19 package org.sleuthkit.autopsy.casemodule;
22 import java.awt.event.WindowAdapter;
23 import java.awt.event.WindowEvent;
24 import java.util.Arrays;
25 import java.util.List;
26 import java.util.ArrayList;
27 import java.util.logging.Level;
29 import javax.swing.JFileChooser;
30 import javax.swing.JFrame;
31 import javax.swing.JOptionPane;
32 import org.openide.util.NbBundle;
37 class MissingImageDialog
extends javax.swing.JDialog {
39 private static final Logger logger = Logger.getLogger(MissingImageDialog.class.getName());
42 static final GeneralFilter rawFilter =
new GeneralFilter(GeneralFilter.RAW_IMAGE_EXTS, GeneralFilter.RAW_IMAGE_DESC);
43 static final GeneralFilter encaseFilter =
new GeneralFilter(GeneralFilter.ENCASE_IMAGE_EXTS, GeneralFilter.ENCASE_IMAGE_DESC);
44 static final List<String> allExt =
new ArrayList<String>();
47 allExt.addAll(GeneralFilter.RAW_IMAGE_EXTS);
48 allExt.addAll(GeneralFilter.ENCASE_IMAGE_EXTS);
50 static final String allDesc = NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.allDesc.text");
51 static final GeneralFilter allFilter =
new GeneralFilter(allExt, allDesc);
52 private JFileChooser fc =
new JFileChooser();
54 private MissingImageDialog(
long obj_id, SleuthkitCase db) {
55 super(
new JFrame(),
true);
60 fc.setDragEnabled(
false);
61 fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
62 fc.setMultiSelectionEnabled(
false);
64 fc.addChoosableFileFilter(rawFilter);
65 fc.addChoosableFileFilter(encaseFilter);
66 fc.setFileFilter(allFilter);
77 static void makeDialog(
long obj_id, SleuthkitCase db) {
78 final MissingImageDialog dialog =
new MissingImageDialog(obj_id, db);
79 dialog.addWindowListener(
new WindowAdapter() {
81 public void windowClosing(WindowEvent e) {
88 private void customInit() {
90 selectButton.setEnabled(
false);
93 private void display() {
94 this.setTitle(NbBundle.getMessage(
this.getClass(),
"MissingImageDialog.display.title"));
95 Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
97 int w = this.getSize().width;
98 int h = this.getSize().height;
100 setLocation((screenDimension.width - w) / 2, (screenDimension.height - h) / 2);
102 this.setVisible(
true);
108 private void moveFocusToSelect() {
109 this.selectButton.requestFocusInWindow();
115 private void updateSelectButton() {
118 if (!pathNameTextField.getText().isEmpty()) {
119 String filePath = pathNameTextField.getText();
120 boolean isExist = Case.pathExists(filePath) || Case.driveExists(filePath);
121 selectButton.setEnabled(isExist);
130 @SuppressWarnings(
"unchecked")
132 private
void initComponents() {
134 buttonPanel =
new javax.swing.JPanel();
135 selectButton =
new javax.swing.JButton();
136 cancelButton =
new javax.swing.JButton();
137 containerPanel =
new javax.swing.JPanel();
138 pathNameTextField =
new javax.swing.JTextField();
139 browseButton =
new javax.swing.JButton();
140 lbWarning =
new javax.swing.JLabel();
141 titleLabel =
new javax.swing.JLabel();
142 titleSeparator =
new javax.swing.JSeparator();
144 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
146 selectButton.setFont(selectButton.getFont().deriveFont(selectButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
147 org.openide.awt.Mnemonics.setLocalizedText(selectButton,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.selectButton.text"));
148 selectButton.addActionListener(
new java.awt.event.ActionListener() {
149 public void actionPerformed(java.awt.event.ActionEvent evt) {
150 selectButtonActionPerformed(evt);
154 cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
155 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.cancelButton.text"));
156 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
157 public void actionPerformed(java.awt.event.ActionEvent evt) {
158 cancelButtonActionPerformed(evt);
162 javax.swing.GroupLayout buttonPanelLayout =
new javax.swing.GroupLayout(buttonPanel);
163 buttonPanel.setLayout(buttonPanelLayout);
164 buttonPanelLayout.setHorizontalGroup(
165 buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
166 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup()
167 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
168 .addComponent(selectButton)
169 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
170 .addComponent(cancelButton)
173 buttonPanelLayout.setVerticalGroup(
174 buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
175 .addGroup(buttonPanelLayout.createSequentialGroup()
177 .addGroup(buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
178 .addComponent(selectButton)
179 .addComponent(cancelButton))
180 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
183 pathNameTextField.setFont(pathNameTextField.getFont().deriveFont(pathNameTextField.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
184 pathNameTextField.setText(
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.pathNameTextField.text"));
185 pathNameTextField.addActionListener(
new java.awt.event.ActionListener() {
186 public void actionPerformed(java.awt.event.ActionEvent evt) {
187 pathNameTextFieldActionPerformed(evt);
191 browseButton.setFont(browseButton.getFont().deriveFont(browseButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
192 org.openide.awt.Mnemonics.setLocalizedText(browseButton,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.browseButton.text"));
193 browseButton.addActionListener(
new java.awt.event.ActionListener() {
194 public void actionPerformed(java.awt.event.ActionEvent evt) {
195 browseButtonActionPerformed(evt);
199 lbWarning.setFont(lbWarning.getFont().deriveFont(lbWarning.getFont().getStyle() | java.awt.Font.BOLD, 12));
200 lbWarning.setForeground(
new java.awt.Color(244, 0, 0));
201 org.openide.awt.Mnemonics.setLocalizedText(lbWarning,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.lbWarning.text"));
202 lbWarning.setToolTipText(
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.lbWarning.toolTipText"));
204 javax.swing.GroupLayout containerPanelLayout =
new javax.swing.GroupLayout(containerPanel);
205 containerPanel.setLayout(containerPanelLayout);
206 containerPanelLayout.setHorizontalGroup(
207 containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
208 .addGroup(containerPanelLayout.createSequentialGroup()
210 .addGroup(containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
211 .addComponent(lbWarning, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
212 .addGroup(containerPanelLayout.createSequentialGroup()
213 .addComponent(pathNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE)
214 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
215 .addComponent(browseButton)
216 .addContainerGap(83, Short.MAX_VALUE))))
218 containerPanelLayout.setVerticalGroup(
219 containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
220 .addGroup(containerPanelLayout.createSequentialGroup()
222 .addGroup(containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
223 .addComponent(pathNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
224 .addComponent(browseButton))
225 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
226 .addComponent(lbWarning, javax.swing.GroupLayout.DEFAULT_SIZE, 19, Short.MAX_VALUE)
230 titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | java.awt.Font.BOLD, 12));
231 org.openide.awt.Mnemonics.setLocalizedText(titleLabel,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.titleLabel.text"));
233 titleSeparator.setForeground(
new java.awt.Color(102, 102, 102));
235 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
236 getContentPane().setLayout(layout);
237 layout.setHorizontalGroup(
238 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
239 .addComponent(buttonPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
240 .addGroup(layout.createSequentialGroup()
242 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
243 .addComponent(containerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
244 .addGroup(layout.createSequentialGroup()
245 .addComponent(titleLabel)
246 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
247 .addComponent(titleSeparator)))
250 layout.setVerticalGroup(
251 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
252 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
254 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
255 .addComponent(titleLabel)
256 .addComponent(titleSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE))
257 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
258 .addComponent(containerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
259 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
260 .addComponent(buttonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
266 private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {
268 String newPath = pathNameTextField.getText();
270 db.setImagePaths(obj_id, Arrays.asList(
new String[]{newPath}));
272 }
catch (TskCoreException ex) {
273 lbWarning.setText(NbBundle.getMessage(
this.getClass(),
"MissingImageDialog.ErrorSettingImage"));
274 logger.log(Level.WARNING,
"Error setting image paths", ex);
278 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
282 private void pathNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {
285 updateSelectButton();
288 private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {
290 String oldText = pathNameTextField.getText();
291 lbWarning.setText(
"");
293 File currentDir =
new File(oldText);
294 if (currentDir.exists()) {
295 fc.setCurrentDirectory(currentDir);
298 int retval = fc.showOpenDialog(
this);
299 if (retval == JFileChooser.APPROVE_OPTION) {
300 String path = fc.getSelectedFile().getPath();
301 pathNameTextField.setText(path);
305 updateSelectButton();
308 private javax.swing.JButton browseButton;
309 private javax.swing.JPanel buttonPanel;
310 private javax.swing.JButton cancelButton;
311 private javax.swing.JPanel containerPanel;
312 private javax.swing.JLabel lbWarning;
313 private javax.swing.JTextField pathNameTextField;
314 private javax.swing.JButton selectButton;
315 private javax.swing.JLabel titleLabel;
316 private javax.swing.JSeparator titleSeparator;
323 int ret = JOptionPane.showConfirmDialog(null,
324 NbBundle.getMessage(
this.getClass(),
325 "MissingImageDialog.confDlg.noFileSel.msg"),
326 NbBundle.getMessage(
this.getClass(),
327 "MissingImageDialog.confDlg.noFileSel.title"),
328 JOptionPane.YES_NO_OPTION);
329 if (ret == JOptionPane.YES_OPTION) {