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 javax.swing.filechooser.FileFilter;
32 import org.openide.util.NbBundle;
33 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 final JFileChooser fileChooser =
new JFileChooser();
57 private MissingImageDialog(
long obj_id, SleuthkitCase db) {
58 super((JFrame) WindowManager.getDefault().getMainWindow(),
true);
63 fileChooser.setDragEnabled(
false);
64 fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
65 fileChooser.setMultiSelectionEnabled(
false);
67 List<FileFilter> fileFiltersList = ImageDSProcessor.getFileFiltersList();
68 for (FileFilter fileFilter : fileFiltersList) {
69 fileChooser.addChoosableFileFilter(fileFilter);
71 fileChooser.setFileFilter(fileFiltersList.get(0));
73 selectButton.setEnabled(
false);
82 static void makeDialog(
long obj_id, SleuthkitCase db) {
83 final MissingImageDialog dialog =
new MissingImageDialog(obj_id, db);
84 dialog.addWindowListener(
new WindowAdapter() {
86 public void windowClosing(WindowEvent e) {
96 private void display() {
97 this.setTitle(NbBundle.getMessage(
this.getClass(),
"MissingImageDialog.display.title"));
98 setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
99 this.setVisible(
true);
105 private void updateSelectButton() {
108 if (!pathNameTextField.getText().isEmpty()) {
109 String filePath = pathNameTextField.getText();
110 boolean isExist =
new File(filePath).isFile() || DriveUtils.driveExists(filePath);
111 selectButton.setEnabled(isExist);
120 @SuppressWarnings(
"unchecked")
122 private
void initComponents() {
124 buttonPanel =
new javax.swing.JPanel();
125 selectButton =
new javax.swing.JButton();
126 cancelButton =
new javax.swing.JButton();
127 containerPanel =
new javax.swing.JPanel();
128 pathNameTextField =
new javax.swing.JTextField();
129 browseButton =
new javax.swing.JButton();
130 lbWarning =
new javax.swing.JLabel();
131 titleLabel =
new javax.swing.JLabel();
132 titleSeparator =
new javax.swing.JSeparator();
134 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
136 selectButton.setFont(selectButton.getFont().deriveFont(selectButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
137 org.openide.awt.Mnemonics.setLocalizedText(selectButton,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.selectButton.text"));
138 selectButton.addActionListener(
new java.awt.event.ActionListener() {
139 public void actionPerformed(java.awt.event.ActionEvent evt) {
140 selectButtonActionPerformed(evt);
144 cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
145 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.cancelButton.text"));
146 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
147 public void actionPerformed(java.awt.event.ActionEvent evt) {
148 cancelButtonActionPerformed(evt);
152 javax.swing.GroupLayout buttonPanelLayout =
new javax.swing.GroupLayout(buttonPanel);
153 buttonPanel.setLayout(buttonPanelLayout);
154 buttonPanelLayout.setHorizontalGroup(
155 buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
156 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup()
157 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
158 .addComponent(selectButton)
159 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
160 .addComponent(cancelButton)
163 buttonPanelLayout.setVerticalGroup(
164 buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
165 .addGroup(buttonPanelLayout.createSequentialGroup()
167 .addGroup(buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
168 .addComponent(selectButton)
169 .addComponent(cancelButton))
170 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
173 pathNameTextField.setFont(pathNameTextField.getFont().deriveFont(pathNameTextField.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
174 pathNameTextField.setText(
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.pathNameTextField.text"));
175 pathNameTextField.addActionListener(
new java.awt.event.ActionListener() {
176 public void actionPerformed(java.awt.event.ActionEvent evt) {
177 pathNameTextFieldActionPerformed(evt);
181 browseButton.setFont(browseButton.getFont().deriveFont(browseButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
182 org.openide.awt.Mnemonics.setLocalizedText(browseButton,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.browseButton.text"));
183 browseButton.addActionListener(
new java.awt.event.ActionListener() {
184 public void actionPerformed(java.awt.event.ActionEvent evt) {
185 browseButtonActionPerformed(evt);
189 lbWarning.setFont(lbWarning.getFont().deriveFont(lbWarning.getFont().getStyle() | java.awt.Font.BOLD, 12));
190 lbWarning.setForeground(
new java.awt.Color(244, 0, 0));
191 org.openide.awt.Mnemonics.setLocalizedText(lbWarning,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.lbWarning.text"));
192 lbWarning.setToolTipText(
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.lbWarning.toolTipText"));
194 javax.swing.GroupLayout containerPanelLayout =
new javax.swing.GroupLayout(containerPanel);
195 containerPanel.setLayout(containerPanelLayout);
196 containerPanelLayout.setHorizontalGroup(
197 containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
198 .addGroup(containerPanelLayout.createSequentialGroup()
200 .addGroup(containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
201 .addComponent(lbWarning, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
202 .addGroup(containerPanelLayout.createSequentialGroup()
203 .addComponent(pathNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE)
204 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
205 .addComponent(browseButton)
206 .addContainerGap(83, Short.MAX_VALUE))))
208 containerPanelLayout.setVerticalGroup(
209 containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
210 .addGroup(containerPanelLayout.createSequentialGroup()
212 .addGroup(containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
213 .addComponent(pathNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
214 .addComponent(browseButton))
215 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
216 .addComponent(lbWarning, javax.swing.GroupLayout.DEFAULT_SIZE, 19, Short.MAX_VALUE)
220 titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | java.awt.Font.BOLD, 12));
221 org.openide.awt.Mnemonics.setLocalizedText(titleLabel,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.titleLabel.text"));
223 titleSeparator.setForeground(
new java.awt.Color(102, 102, 102));
225 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
226 getContentPane().setLayout(layout);
227 layout.setHorizontalGroup(
228 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
229 .addComponent(buttonPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
230 .addGroup(layout.createSequentialGroup()
232 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
233 .addComponent(containerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
234 .addGroup(layout.createSequentialGroup()
235 .addComponent(titleLabel)
236 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
237 .addComponent(titleSeparator)))
240 layout.setVerticalGroup(
241 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
242 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
244 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
245 .addComponent(titleLabel)
246 .addComponent(titleSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE))
247 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
248 .addComponent(containerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
249 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
250 .addComponent(buttonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
256 private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {
258 String newPath = pathNameTextField.getText();
260 db.setImagePaths(obj_id, Arrays.asList(
new String[]{newPath}));
262 }
catch (TskCoreException ex) {
263 lbWarning.setText(NbBundle.getMessage(
this.getClass(),
"MissingImageDialog.ErrorSettingImage"));
264 logger.log(Level.WARNING,
"Error setting image paths", ex);
268 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
272 private void pathNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {
273 updateSelectButton();
276 private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {
278 String oldText = pathNameTextField.getText();
279 lbWarning.setText(
"");
281 File currentDir =
new File(oldText);
282 if (currentDir.exists()) {
283 fileChooser.setCurrentDirectory(currentDir);
286 int retval = fileChooser.showOpenDialog(
this);
287 if (retval == JFileChooser.APPROVE_OPTION) {
288 String path = fileChooser.getSelectedFile().getPath();
289 pathNameTextField.setText(path);
293 updateSelectButton();
296 private javax.swing.JButton browseButton;
297 private javax.swing.JPanel buttonPanel;
298 private javax.swing.JButton cancelButton;
299 private javax.swing.JPanel containerPanel;
300 private javax.swing.JLabel lbWarning;
301 private javax.swing.JTextField pathNameTextField;
302 private javax.swing.JButton selectButton;
303 private javax.swing.JLabel titleLabel;
304 private javax.swing.JSeparator titleSeparator;
311 int ret = JOptionPane.showConfirmDialog(
this,
312 NbBundle.getMessage(
this.getClass(),
313 "MissingImageDialog.confDlg.noFileSel.msg"),
314 NbBundle.getMessage(
this.getClass(),
315 "MissingImageDialog.confDlg.noFileSel.title"),
316 JOptionPane.YES_NO_OPTION);
317 if (ret == JOptionPane.YES_OPTION) {