19 package org.sleuthkit.autopsy.casemodule;
21 import java.awt.event.WindowAdapter;
22 import java.awt.event.WindowEvent;
23 import java.util.Arrays;
24 import java.util.List;
25 import java.util.ArrayList;
26 import java.util.logging.Level;
28 import javax.swing.JFileChooser;
29 import javax.swing.JFrame;
30 import javax.swing.JOptionPane;
31 import org.openide.util.NbBundle;
32 import org.openide.windows.WindowManager;
38 class MissingImageDialog
extends javax.swing.JDialog {
40 private static final Logger logger = Logger.getLogger(MissingImageDialog.class.getName());
43 static final GeneralFilter rawFilter =
new GeneralFilter(GeneralFilter.RAW_IMAGE_EXTS, GeneralFilter.RAW_IMAGE_DESC);
44 static final GeneralFilter encaseFilter =
new GeneralFilter(GeneralFilter.ENCASE_IMAGE_EXTS, GeneralFilter.ENCASE_IMAGE_DESC);
45 static final List<String> allExt =
new ArrayList<String>();
48 allExt.addAll(GeneralFilter.RAW_IMAGE_EXTS);
49 allExt.addAll(GeneralFilter.ENCASE_IMAGE_EXTS);
51 static final String allDesc = NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.allDesc.text");
52 static final GeneralFilter allFilter =
new GeneralFilter(allExt, allDesc);
53 private JFileChooser fc =
new JFileChooser();
61 private MissingImageDialog(
long obj_id, SleuthkitCase db) {
62 super((JFrame) WindowManager.getDefault().getMainWindow(),
true);
67 fc.setDragEnabled(
false);
68 fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
69 fc.setMultiSelectionEnabled(
false);
71 fc.addChoosableFileFilter(rawFilter);
72 fc.addChoosableFileFilter(encaseFilter);
73 fc.setFileFilter(allFilter);
75 selectButton.setEnabled(
false);
84 static void makeDialog(
long obj_id, SleuthkitCase db) {
85 final MissingImageDialog dialog =
new MissingImageDialog(obj_id, db);
86 dialog.addWindowListener(
new WindowAdapter() {
88 public void windowClosing(WindowEvent e) {
98 private void display() {
99 this.setTitle(NbBundle.getMessage(
this.getClass(),
"MissingImageDialog.display.title"));
100 setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
101 this.setVisible(
true);
107 private void updateSelectButton() {
110 if (!pathNameTextField.getText().isEmpty()) {
111 String filePath = pathNameTextField.getText();
112 boolean isExist =
new File(filePath).isFile() || DriveUtils.driveExists(filePath);
113 selectButton.setEnabled(isExist);
122 @SuppressWarnings(
"unchecked")
124 private
void initComponents() {
126 buttonPanel =
new javax.swing.JPanel();
127 selectButton =
new javax.swing.JButton();
128 cancelButton =
new javax.swing.JButton();
129 containerPanel =
new javax.swing.JPanel();
130 pathNameTextField =
new javax.swing.JTextField();
131 browseButton =
new javax.swing.JButton();
132 lbWarning =
new javax.swing.JLabel();
133 titleLabel =
new javax.swing.JLabel();
134 titleSeparator =
new javax.swing.JSeparator();
136 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
138 selectButton.setFont(selectButton.getFont().deriveFont(selectButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
139 org.openide.awt.Mnemonics.setLocalizedText(selectButton,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.selectButton.text"));
140 selectButton.addActionListener(
new java.awt.event.ActionListener() {
141 public void actionPerformed(java.awt.event.ActionEvent evt) {
142 selectButtonActionPerformed(evt);
146 cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
147 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.cancelButton.text"));
148 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
149 public void actionPerformed(java.awt.event.ActionEvent evt) {
150 cancelButtonActionPerformed(evt);
154 javax.swing.GroupLayout buttonPanelLayout =
new javax.swing.GroupLayout(buttonPanel);
155 buttonPanel.setLayout(buttonPanelLayout);
156 buttonPanelLayout.setHorizontalGroup(
157 buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
158 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup()
159 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
160 .addComponent(selectButton)
161 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
162 .addComponent(cancelButton)
165 buttonPanelLayout.setVerticalGroup(
166 buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
167 .addGroup(buttonPanelLayout.createSequentialGroup()
169 .addGroup(buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
170 .addComponent(selectButton)
171 .addComponent(cancelButton))
172 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
175 pathNameTextField.setFont(pathNameTextField.getFont().deriveFont(pathNameTextField.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
176 pathNameTextField.setText(
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.pathNameTextField.text"));
177 pathNameTextField.addActionListener(
new java.awt.event.ActionListener() {
178 public void actionPerformed(java.awt.event.ActionEvent evt) {
179 pathNameTextFieldActionPerformed(evt);
183 browseButton.setFont(browseButton.getFont().deriveFont(browseButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
184 org.openide.awt.Mnemonics.setLocalizedText(browseButton,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.browseButton.text"));
185 browseButton.addActionListener(
new java.awt.event.ActionListener() {
186 public void actionPerformed(java.awt.event.ActionEvent evt) {
187 browseButtonActionPerformed(evt);
191 lbWarning.setFont(lbWarning.getFont().deriveFont(lbWarning.getFont().getStyle() | java.awt.Font.BOLD, 12));
192 lbWarning.setForeground(
new java.awt.Color(244, 0, 0));
193 org.openide.awt.Mnemonics.setLocalizedText(lbWarning,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.lbWarning.text"));
194 lbWarning.setToolTipText(
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.lbWarning.toolTipText"));
196 javax.swing.GroupLayout containerPanelLayout =
new javax.swing.GroupLayout(containerPanel);
197 containerPanel.setLayout(containerPanelLayout);
198 containerPanelLayout.setHorizontalGroup(
199 containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
200 .addGroup(containerPanelLayout.createSequentialGroup()
202 .addGroup(containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
203 .addComponent(lbWarning, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
204 .addGroup(containerPanelLayout.createSequentialGroup()
205 .addComponent(pathNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE)
206 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
207 .addComponent(browseButton)
208 .addContainerGap(83, Short.MAX_VALUE))))
210 containerPanelLayout.setVerticalGroup(
211 containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
212 .addGroup(containerPanelLayout.createSequentialGroup()
214 .addGroup(containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
215 .addComponent(pathNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
216 .addComponent(browseButton))
217 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
218 .addComponent(lbWarning, javax.swing.GroupLayout.DEFAULT_SIZE, 19, Short.MAX_VALUE)
222 titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | java.awt.Font.BOLD, 12));
223 org.openide.awt.Mnemonics.setLocalizedText(titleLabel,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.titleLabel.text"));
225 titleSeparator.setForeground(
new java.awt.Color(102, 102, 102));
227 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
228 getContentPane().setLayout(layout);
229 layout.setHorizontalGroup(
230 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
231 .addComponent(buttonPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
232 .addGroup(layout.createSequentialGroup()
234 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
235 .addComponent(containerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
236 .addGroup(layout.createSequentialGroup()
237 .addComponent(titleLabel)
238 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
239 .addComponent(titleSeparator)))
242 layout.setVerticalGroup(
243 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
244 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
246 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
247 .addComponent(titleLabel)
248 .addComponent(titleSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE))
249 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
250 .addComponent(containerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
251 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
252 .addComponent(buttonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
258 private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {
260 String newPath = pathNameTextField.getText();
262 db.setImagePaths(obj_id, Arrays.asList(
new String[]{newPath}));
264 }
catch (TskCoreException ex) {
265 lbWarning.setText(NbBundle.getMessage(
this.getClass(),
"MissingImageDialog.ErrorSettingImage"));
266 logger.log(Level.WARNING,
"Error setting image paths", ex);
270 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
274 private void pathNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {
275 updateSelectButton();
278 private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {
280 String oldText = pathNameTextField.getText();
281 lbWarning.setText(
"");
283 File currentDir =
new File(oldText);
284 if (currentDir.exists()) {
285 fc.setCurrentDirectory(currentDir);
288 int retval = fc.showOpenDialog(
this);
289 if (retval == JFileChooser.APPROVE_OPTION) {
290 String path = fc.getSelectedFile().getPath();
291 pathNameTextField.setText(path);
295 updateSelectButton();
298 private javax.swing.JButton browseButton;
299 private javax.swing.JPanel buttonPanel;
300 private javax.swing.JButton cancelButton;
301 private javax.swing.JPanel containerPanel;
302 private javax.swing.JLabel lbWarning;
303 private javax.swing.JTextField pathNameTextField;
304 private javax.swing.JButton selectButton;
305 private javax.swing.JLabel titleLabel;
306 private javax.swing.JSeparator titleSeparator;
313 int ret = JOptionPane.showConfirmDialog(
this,
314 NbBundle.getMessage(
this.getClass(),
315 "MissingImageDialog.confDlg.noFileSel.msg"),
316 NbBundle.getMessage(
this.getClass(),
317 "MissingImageDialog.confDlg.noFileSel.title"),
318 JOptionPane.YES_NO_OPTION);
319 if (ret == JOptionPane.YES_OPTION) {