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;
42 @SuppressWarnings(
"PMD.SingularField")
43 class MissingImageDialog extends javax.swing.JDialog {
45 private static final Logger logger = Logger.getLogger(MissingImageDialog.class.getName());
49 private JFileChooser fileChooser;
50 private final JFileChooserFactory chooserHelper;
58 private MissingImageDialog(
long obj_id, SleuthkitCase db) {
59 super((JFrame) WindowManager.getDefault().getMainWindow(),
true);
64 chooserHelper =
new JFileChooserFactory();
65 selectButton.setEnabled(
false);
74 static void makeDialog(
long obj_id, SleuthkitCase db) {
75 final MissingImageDialog dialog =
new MissingImageDialog(obj_id, db);
76 dialog.addWindowListener(
new WindowAdapter() {
78 public void windowClosing(WindowEvent e) {
88 private void display() {
89 this.setTitle(NbBundle.getMessage(
this.getClass(),
"MissingImageDialog.display.title"));
90 setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
91 this.setVisible(
true);
97 private void updateSelectButton() {
100 if (!pathNameTextField.getText().isEmpty()) {
101 String filePath = pathNameTextField.getText();
102 boolean isExist =
new File(filePath).isFile() || DriveUtils.driveExists(filePath);
103 selectButton.setEnabled(isExist);
112 @SuppressWarnings(
"unchecked")
114 private
void initComponents() {
116 buttonPanel =
new javax.swing.JPanel();
117 selectButton =
new javax.swing.JButton();
118 cancelButton =
new javax.swing.JButton();
119 containerPanel =
new javax.swing.JPanel();
120 pathNameTextField =
new javax.swing.JTextField();
121 browseButton =
new javax.swing.JButton();
122 lbWarning =
new javax.swing.JLabel();
123 titleLabel =
new javax.swing.JLabel();
124 titleSeparator =
new javax.swing.JSeparator();
126 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
128 org.openide.awt.Mnemonics.setLocalizedText(selectButton,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.selectButton.text"));
129 selectButton.addActionListener(
new java.awt.event.ActionListener() {
130 public void actionPerformed(java.awt.event.ActionEvent evt) {
131 selectButtonActionPerformed(evt);
135 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.cancelButton.text"));
136 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
137 public void actionPerformed(java.awt.event.ActionEvent evt) {
138 cancelButtonActionPerformed(evt);
142 javax.swing.GroupLayout buttonPanelLayout =
new javax.swing.GroupLayout(buttonPanel);
143 buttonPanel.setLayout(buttonPanelLayout);
144 buttonPanelLayout.setHorizontalGroup(
145 buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
146 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup()
147 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
148 .addComponent(selectButton)
149 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
150 .addComponent(cancelButton)
153 buttonPanelLayout.setVerticalGroup(
154 buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
155 .addGroup(buttonPanelLayout.createSequentialGroup()
157 .addGroup(buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
158 .addComponent(selectButton)
159 .addComponent(cancelButton))
160 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
163 pathNameTextField.setText(
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.pathNameTextField.text"));
164 pathNameTextField.addActionListener(
new java.awt.event.ActionListener() {
165 public void actionPerformed(java.awt.event.ActionEvent evt) {
166 pathNameTextFieldActionPerformed(evt);
170 org.openide.awt.Mnemonics.setLocalizedText(browseButton,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.browseButton.text"));
171 browseButton.addActionListener(
new java.awt.event.ActionListener() {
172 public void actionPerformed(java.awt.event.ActionEvent evt) {
173 browseButtonActionPerformed(evt);
177 lbWarning.setFont(lbWarning.getFont().deriveFont(lbWarning.getFont().getStyle() | java.awt.Font.BOLD, lbWarning.getFont().getSize()+1));
178 lbWarning.setForeground(
new java.awt.Color(244, 0, 0));
179 org.openide.awt.Mnemonics.setLocalizedText(lbWarning,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.lbWarning.text"));
180 lbWarning.setToolTipText(
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.lbWarning.toolTipText"));
182 javax.swing.GroupLayout containerPanelLayout =
new javax.swing.GroupLayout(containerPanel);
183 containerPanel.setLayout(containerPanelLayout);
184 containerPanelLayout.setHorizontalGroup(
185 containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
186 .addGroup(containerPanelLayout.createSequentialGroup()
188 .addGroup(containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
189 .addComponent(lbWarning, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
190 .addGroup(containerPanelLayout.createSequentialGroup()
191 .addComponent(pathNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE)
192 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
193 .addComponent(browseButton)
194 .addContainerGap(83, Short.MAX_VALUE))))
196 containerPanelLayout.setVerticalGroup(
197 containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
198 .addGroup(containerPanelLayout.createSequentialGroup()
200 .addGroup(containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
201 .addComponent(pathNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
202 .addComponent(browseButton))
203 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
204 .addComponent(lbWarning, javax.swing.GroupLayout.DEFAULT_SIZE, 19, Short.MAX_VALUE)
208 titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | java.awt.Font.BOLD, titleLabel.getFont().getSize()+1));
209 org.openide.awt.Mnemonics.setLocalizedText(titleLabel,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.titleLabel.text"));
211 titleSeparator.setForeground(
new java.awt.Color(102, 102, 102));
213 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
214 getContentPane().setLayout(layout);
215 layout.setHorizontalGroup(
216 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
217 .addComponent(buttonPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
218 .addGroup(layout.createSequentialGroup()
220 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
221 .addComponent(containerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
222 .addGroup(layout.createSequentialGroup()
223 .addComponent(titleLabel)
224 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
225 .addComponent(titleSeparator)))
228 layout.setVerticalGroup(
229 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
230 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
232 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
233 .addComponent(titleLabel)
234 .addComponent(titleSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE))
235 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
236 .addComponent(containerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
237 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
238 .addComponent(buttonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
244 private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {
246 String newPath = pathNameTextField.getText();
248 db.setImagePaths(obj_id, Arrays.asList(
new String[]{newPath}));
250 }
catch (TskCoreException ex) {
251 lbWarning.setText(NbBundle.getMessage(
this.getClass(),
"MissingImageDialog.ErrorSettingImage"));
252 logger.log(Level.SEVERE,
"Error setting image paths", ex);
256 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
260 private void pathNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {
261 updateSelectButton();
264 private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {
266 if(fileChooser == null) {
267 fileChooser = chooserHelper.getChooser();
268 fileChooser.setDragEnabled(
false);
269 fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
270 fileChooser.setMultiSelectionEnabled(
false);
272 List<FileFilter> fileFiltersList = ImageDSProcessor.getFileFiltersList();
273 for (FileFilter fileFilter : fileFiltersList) {
274 fileChooser.addChoosableFileFilter(fileFilter);
276 fileChooser.setFileFilter(fileFiltersList.get(0));
279 String oldText = pathNameTextField.getText();
280 lbWarning.setText(
"");
282 File currentDir =
new File(oldText);
283 if (currentDir.exists()) {
284 fileChooser.setCurrentDirectory(currentDir);
287 int retval = fileChooser.showOpenDialog(
this);
288 if (retval == JFileChooser.APPROVE_OPTION) {
289 String path = fileChooser.getSelectedFile().getPath();
290 pathNameTextField.setText(path);
294 updateSelectButton();
297 private javax.swing.JButton browseButton;
298 private javax.swing.JPanel buttonPanel;
299 private javax.swing.JButton cancelButton;
300 private javax.swing.JPanel containerPanel;
301 private javax.swing.JLabel lbWarning;
302 private javax.swing.JTextField pathNameTextField;
303 private javax.swing.JButton selectButton;
304 private javax.swing.JLabel titleLabel;
305 private javax.swing.JSeparator titleSeparator;
312 int ret = JOptionPane.showConfirmDialog(
this,
313 NbBundle.getMessage(
this.getClass(),
314 "MissingImageDialog.confDlg.noFileSel.msg"),
315 NbBundle.getMessage(
this.getClass(),
316 "MissingImageDialog.confDlg.noFileSel.title"),
317 JOptionPane.YES_NO_OPTION);
318 if (ret == JOptionPane.YES_OPTION) {