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;
41 @SuppressWarnings(
"PMD.SingularField")
42 class MissingImageDialog extends javax.swing.JDialog {
44 private static final Logger logger = Logger.getLogger(MissingImageDialog.class.getName());
47 static final GeneralFilter rawFilter =
new GeneralFilter(GeneralFilter.RAW_IMAGE_EXTS, GeneralFilter.RAW_IMAGE_DESC);
48 static final GeneralFilter encaseFilter =
new GeneralFilter(GeneralFilter.ENCASE_IMAGE_EXTS, GeneralFilter.ENCASE_IMAGE_DESC);
49 static final List<String> allExt =
new ArrayList<String>();
52 allExt.addAll(GeneralFilter.RAW_IMAGE_EXTS);
53 allExt.addAll(GeneralFilter.ENCASE_IMAGE_EXTS);
55 static final String allDesc = NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.allDesc.text");
56 static final GeneralFilter allFilter =
new GeneralFilter(allExt, allDesc);
57 private final JFileChooser fc =
new JFileChooser();
65 private MissingImageDialog(
long obj_id, SleuthkitCase db) {
66 super((JFrame) WindowManager.getDefault().getMainWindow(),
true);
71 fc.setDragEnabled(
false);
72 fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
73 fc.setMultiSelectionEnabled(
false);
75 fc.addChoosableFileFilter(rawFilter);
76 fc.addChoosableFileFilter(encaseFilter);
77 fc.setFileFilter(allFilter);
79 selectButton.setEnabled(
false);
88 static void makeDialog(
long obj_id, SleuthkitCase db) {
89 final MissingImageDialog dialog =
new MissingImageDialog(obj_id, db);
90 dialog.addWindowListener(
new WindowAdapter() {
92 public void windowClosing(WindowEvent e) {
102 private void display() {
103 this.setTitle(NbBundle.getMessage(
this.getClass(),
"MissingImageDialog.display.title"));
104 setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
105 this.setVisible(
true);
111 private void updateSelectButton() {
114 if (!pathNameTextField.getText().isEmpty()) {
115 String filePath = pathNameTextField.getText();
116 boolean isExist =
new File(filePath).isFile() || DriveUtils.driveExists(filePath);
117 selectButton.setEnabled(isExist);
126 @SuppressWarnings(
"unchecked")
128 private
void initComponents() {
130 buttonPanel =
new javax.swing.JPanel();
131 selectButton =
new javax.swing.JButton();
132 cancelButton =
new javax.swing.JButton();
133 containerPanel =
new javax.swing.JPanel();
134 pathNameTextField =
new javax.swing.JTextField();
135 browseButton =
new javax.swing.JButton();
136 lbWarning =
new javax.swing.JLabel();
137 titleLabel =
new javax.swing.JLabel();
138 titleSeparator =
new javax.swing.JSeparator();
140 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
142 selectButton.setFont(selectButton.getFont().deriveFont(selectButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
143 org.openide.awt.Mnemonics.setLocalizedText(selectButton,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.selectButton.text"));
144 selectButton.addActionListener(
new java.awt.event.ActionListener() {
145 public void actionPerformed(java.awt.event.ActionEvent evt) {
146 selectButtonActionPerformed(evt);
150 cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
151 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.cancelButton.text"));
152 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
153 public void actionPerformed(java.awt.event.ActionEvent evt) {
154 cancelButtonActionPerformed(evt);
158 javax.swing.GroupLayout buttonPanelLayout =
new javax.swing.GroupLayout(buttonPanel);
159 buttonPanel.setLayout(buttonPanelLayout);
160 buttonPanelLayout.setHorizontalGroup(
161 buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
162 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup()
163 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
164 .addComponent(selectButton)
165 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
166 .addComponent(cancelButton)
169 buttonPanelLayout.setVerticalGroup(
170 buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
171 .addGroup(buttonPanelLayout.createSequentialGroup()
173 .addGroup(buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
174 .addComponent(selectButton)
175 .addComponent(cancelButton))
176 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
179 pathNameTextField.setFont(pathNameTextField.getFont().deriveFont(pathNameTextField.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
180 pathNameTextField.setText(
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.pathNameTextField.text"));
181 pathNameTextField.addActionListener(
new java.awt.event.ActionListener() {
182 public void actionPerformed(java.awt.event.ActionEvent evt) {
183 pathNameTextFieldActionPerformed(evt);
187 browseButton.setFont(browseButton.getFont().deriveFont(browseButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
188 org.openide.awt.Mnemonics.setLocalizedText(browseButton,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.browseButton.text"));
189 browseButton.addActionListener(
new java.awt.event.ActionListener() {
190 public void actionPerformed(java.awt.event.ActionEvent evt) {
191 browseButtonActionPerformed(evt);
195 lbWarning.setFont(lbWarning.getFont().deriveFont(lbWarning.getFont().getStyle() | java.awt.Font.BOLD, 12));
196 lbWarning.setForeground(
new java.awt.Color(244, 0, 0));
197 org.openide.awt.Mnemonics.setLocalizedText(lbWarning,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.lbWarning.text"));
198 lbWarning.setToolTipText(
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.lbWarning.toolTipText"));
200 javax.swing.GroupLayout containerPanelLayout =
new javax.swing.GroupLayout(containerPanel);
201 containerPanel.setLayout(containerPanelLayout);
202 containerPanelLayout.setHorizontalGroup(
203 containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
204 .addGroup(containerPanelLayout.createSequentialGroup()
206 .addGroup(containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
207 .addComponent(lbWarning, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
208 .addGroup(containerPanelLayout.createSequentialGroup()
209 .addComponent(pathNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE)
210 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
211 .addComponent(browseButton)
212 .addContainerGap(83, Short.MAX_VALUE))))
214 containerPanelLayout.setVerticalGroup(
215 containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
216 .addGroup(containerPanelLayout.createSequentialGroup()
218 .addGroup(containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
219 .addComponent(pathNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
220 .addComponent(browseButton))
221 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
222 .addComponent(lbWarning, javax.swing.GroupLayout.DEFAULT_SIZE, 19, Short.MAX_VALUE)
226 titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | java.awt.Font.BOLD, 12));
227 org.openide.awt.Mnemonics.setLocalizedText(titleLabel,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.titleLabel.text"));
229 titleSeparator.setForeground(
new java.awt.Color(102, 102, 102));
231 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
232 getContentPane().setLayout(layout);
233 layout.setHorizontalGroup(
234 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
235 .addComponent(buttonPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
236 .addGroup(layout.createSequentialGroup()
238 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
239 .addComponent(containerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
240 .addGroup(layout.createSequentialGroup()
241 .addComponent(titleLabel)
242 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
243 .addComponent(titleSeparator)))
246 layout.setVerticalGroup(
247 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
248 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
250 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
251 .addComponent(titleLabel)
252 .addComponent(titleSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE))
253 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
254 .addComponent(containerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
255 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
256 .addComponent(buttonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
262 private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {
264 String newPath = pathNameTextField.getText();
266 db.setImagePaths(obj_id, Arrays.asList(
new String[]{newPath}));
268 }
catch (TskCoreException ex) {
269 lbWarning.setText(NbBundle.getMessage(
this.getClass(),
"MissingImageDialog.ErrorSettingImage"));
270 logger.log(Level.WARNING,
"Error setting image paths", ex);
274 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
278 private void pathNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {
279 updateSelectButton();
282 private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {
284 String oldText = pathNameTextField.getText();
285 lbWarning.setText(
"");
287 File currentDir =
new File(oldText);
288 if (currentDir.exists()) {
289 fc.setCurrentDirectory(currentDir);
292 int retval = fc.showOpenDialog(
this);
293 if (retval == JFileChooser.APPROVE_OPTION) {
294 String path = fc.getSelectedFile().getPath();
295 pathNameTextField.setText(path);
299 updateSelectButton();
302 private javax.swing.JButton browseButton;
303 private javax.swing.JPanel buttonPanel;
304 private javax.swing.JButton cancelButton;
305 private javax.swing.JPanel containerPanel;
306 private javax.swing.JLabel lbWarning;
307 private javax.swing.JTextField pathNameTextField;
308 private javax.swing.JButton selectButton;
309 private javax.swing.JLabel titleLabel;
310 private javax.swing.JSeparator titleSeparator;
317 int ret = JOptionPane.showConfirmDialog(
this,
318 NbBundle.getMessage(
this.getClass(),
319 "MissingImageDialog.confDlg.noFileSel.msg"),
320 NbBundle.getMessage(
this.getClass(),
321 "MissingImageDialog.confDlg.noFileSel.title"),
322 JOptionPane.YES_NO_OPTION);
323 if (ret == JOptionPane.YES_OPTION) {