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.logging.Level;
27 import javax.swing.JFileChooser;
28 import javax.swing.JFrame;
29 import javax.swing.JOptionPane;
30 import javax.swing.filechooser.FileFilter;
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());
48 private final JFileChooser fileChooser =
new JFileChooser();
56 private MissingImageDialog(
long obj_id, SleuthkitCase db) {
57 super((JFrame) WindowManager.getDefault().getMainWindow(),
true);
62 fileChooser.setDragEnabled(
false);
63 fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
64 fileChooser.setMultiSelectionEnabled(
false);
66 List<FileFilter> fileFiltersList = ImageDSProcessor.getFileFiltersList();
67 for (FileFilter fileFilter : fileFiltersList) {
68 fileChooser.addChoosableFileFilter(fileFilter);
70 fileChooser.setFileFilter(fileFiltersList.get(0));
72 selectButton.setEnabled(
false);
81 static void makeDialog(
long obj_id, SleuthkitCase db) {
82 final MissingImageDialog dialog =
new MissingImageDialog(obj_id, db);
83 dialog.addWindowListener(
new WindowAdapter() {
85 public void windowClosing(WindowEvent e) {
95 private void display() {
96 this.setTitle(NbBundle.getMessage(
this.getClass(),
"MissingImageDialog.display.title"));
97 setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
98 this.setVisible(
true);
104 private void updateSelectButton() {
107 if (!pathNameTextField.getText().isEmpty()) {
108 String filePath = pathNameTextField.getText();
109 boolean isExist =
new File(filePath).isFile() || DriveUtils.driveExists(filePath);
110 selectButton.setEnabled(isExist);
119 @SuppressWarnings(
"unchecked")
121 private
void initComponents() {
123 buttonPanel =
new javax.swing.JPanel();
124 selectButton =
new javax.swing.JButton();
125 cancelButton =
new javax.swing.JButton();
126 containerPanel =
new javax.swing.JPanel();
127 pathNameTextField =
new javax.swing.JTextField();
128 browseButton =
new javax.swing.JButton();
129 lbWarning =
new javax.swing.JLabel();
130 titleLabel =
new javax.swing.JLabel();
131 titleSeparator =
new javax.swing.JSeparator();
133 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
135 org.openide.awt.Mnemonics.setLocalizedText(selectButton,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.selectButton.text"));
136 selectButton.addActionListener(
new java.awt.event.ActionListener() {
137 public void actionPerformed(java.awt.event.ActionEvent evt) {
138 selectButtonActionPerformed(evt);
142 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.cancelButton.text"));
143 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
144 public void actionPerformed(java.awt.event.ActionEvent evt) {
145 cancelButtonActionPerformed(evt);
149 javax.swing.GroupLayout buttonPanelLayout =
new javax.swing.GroupLayout(buttonPanel);
150 buttonPanel.setLayout(buttonPanelLayout);
151 buttonPanelLayout.setHorizontalGroup(
152 buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
153 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup()
154 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
155 .addComponent(selectButton)
156 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
157 .addComponent(cancelButton)
160 buttonPanelLayout.setVerticalGroup(
161 buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
162 .addGroup(buttonPanelLayout.createSequentialGroup()
164 .addGroup(buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
165 .addComponent(selectButton)
166 .addComponent(cancelButton))
167 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
170 pathNameTextField.setText(
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.pathNameTextField.text"));
171 pathNameTextField.addActionListener(
new java.awt.event.ActionListener() {
172 public void actionPerformed(java.awt.event.ActionEvent evt) {
173 pathNameTextFieldActionPerformed(evt);
177 org.openide.awt.Mnemonics.setLocalizedText(browseButton,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.browseButton.text"));
178 browseButton.addActionListener(
new java.awt.event.ActionListener() {
179 public void actionPerformed(java.awt.event.ActionEvent evt) {
180 browseButtonActionPerformed(evt);
184 lbWarning.setFont(lbWarning.getFont().deriveFont(lbWarning.getFont().getStyle() | java.awt.Font.BOLD, lbWarning.getFont().getSize()+1));
185 lbWarning.setForeground(
new java.awt.Color(244, 0, 0));
186 org.openide.awt.Mnemonics.setLocalizedText(lbWarning,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.lbWarning.text"));
187 lbWarning.setToolTipText(
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.lbWarning.toolTipText"));
189 javax.swing.GroupLayout containerPanelLayout =
new javax.swing.GroupLayout(containerPanel);
190 containerPanel.setLayout(containerPanelLayout);
191 containerPanelLayout.setHorizontalGroup(
192 containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
193 .addGroup(containerPanelLayout.createSequentialGroup()
195 .addGroup(containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
196 .addComponent(lbWarning, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
197 .addGroup(containerPanelLayout.createSequentialGroup()
198 .addComponent(pathNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE)
199 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
200 .addComponent(browseButton)
201 .addContainerGap(83, Short.MAX_VALUE))))
203 containerPanelLayout.setVerticalGroup(
204 containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
205 .addGroup(containerPanelLayout.createSequentialGroup()
207 .addGroup(containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
208 .addComponent(pathNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
209 .addComponent(browseButton))
210 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
211 .addComponent(lbWarning, javax.swing.GroupLayout.DEFAULT_SIZE, 19, Short.MAX_VALUE)
215 titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | java.awt.Font.BOLD, titleLabel.getFont().getSize()+1));
216 org.openide.awt.Mnemonics.setLocalizedText(titleLabel,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.titleLabel.text"));
218 titleSeparator.setForeground(
new java.awt.Color(102, 102, 102));
220 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
221 getContentPane().setLayout(layout);
222 layout.setHorizontalGroup(
223 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
224 .addComponent(buttonPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
225 .addGroup(layout.createSequentialGroup()
227 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
228 .addComponent(containerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
229 .addGroup(layout.createSequentialGroup()
230 .addComponent(titleLabel)
231 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
232 .addComponent(titleSeparator)))
235 layout.setVerticalGroup(
236 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
237 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
239 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
240 .addComponent(titleLabel)
241 .addComponent(titleSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE))
242 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
243 .addComponent(containerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
244 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
245 .addComponent(buttonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
251 private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {
253 String newPath = pathNameTextField.getText();
255 db.setImagePaths(obj_id, Arrays.asList(
new String[]{newPath}));
257 }
catch (TskCoreException ex) {
258 lbWarning.setText(NbBundle.getMessage(
this.getClass(),
"MissingImageDialog.ErrorSettingImage"));
259 logger.log(Level.SEVERE,
"Error setting image paths", ex);
263 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
267 private void pathNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {
268 updateSelectButton();
271 private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {
273 String oldText = pathNameTextField.getText();
274 lbWarning.setText(
"");
276 File currentDir =
new File(oldText);
277 if (currentDir.exists()) {
278 fileChooser.setCurrentDirectory(currentDir);
281 int retval = fileChooser.showOpenDialog(
this);
282 if (retval == JFileChooser.APPROVE_OPTION) {
283 String path = fileChooser.getSelectedFile().getPath();
284 pathNameTextField.setText(path);
288 updateSelectButton();
291 private javax.swing.JButton browseButton;
292 private javax.swing.JPanel buttonPanel;
293 private javax.swing.JButton cancelButton;
294 private javax.swing.JPanel containerPanel;
295 private javax.swing.JLabel lbWarning;
296 private javax.swing.JTextField pathNameTextField;
297 private javax.swing.JButton selectButton;
298 private javax.swing.JLabel titleLabel;
299 private javax.swing.JSeparator titleSeparator;
306 int ret = JOptionPane.showConfirmDialog(
this,
307 NbBundle.getMessage(
this.getClass(),
308 "MissingImageDialog.confDlg.noFileSel.msg"),
309 NbBundle.getMessage(
this.getClass(),
310 "MissingImageDialog.confDlg.noFileSel.title"),
311 JOptionPane.YES_NO_OPTION);
312 if (ret == JOptionPane.YES_OPTION) {