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 selectButton.setFont(selectButton.getFont().deriveFont(selectButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
136 org.openide.awt.Mnemonics.setLocalizedText(selectButton,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.selectButton.text"));
137 selectButton.addActionListener(
new java.awt.event.ActionListener() {
138 public void actionPerformed(java.awt.event.ActionEvent evt) {
139 selectButtonActionPerformed(evt);
143 cancelButton.setFont(cancelButton.getFont().deriveFont(cancelButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
144 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.cancelButton.text"));
145 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
146 public void actionPerformed(java.awt.event.ActionEvent evt) {
147 cancelButtonActionPerformed(evt);
151 javax.swing.GroupLayout buttonPanelLayout =
new javax.swing.GroupLayout(buttonPanel);
152 buttonPanel.setLayout(buttonPanelLayout);
153 buttonPanelLayout.setHorizontalGroup(
154 buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
155 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup()
156 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
157 .addComponent(selectButton)
158 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
159 .addComponent(cancelButton)
162 buttonPanelLayout.setVerticalGroup(
163 buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
164 .addGroup(buttonPanelLayout.createSequentialGroup()
166 .addGroup(buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
167 .addComponent(selectButton)
168 .addComponent(cancelButton))
169 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
172 pathNameTextField.setFont(pathNameTextField.getFont().deriveFont(pathNameTextField.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
173 pathNameTextField.setText(
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.pathNameTextField.text"));
174 pathNameTextField.addActionListener(
new java.awt.event.ActionListener() {
175 public void actionPerformed(java.awt.event.ActionEvent evt) {
176 pathNameTextFieldActionPerformed(evt);
180 browseButton.setFont(browseButton.getFont().deriveFont(browseButton.getFont().getStyle() & ~java.awt.Font.BOLD, 11));
181 org.openide.awt.Mnemonics.setLocalizedText(browseButton,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.browseButton.text"));
182 browseButton.addActionListener(
new java.awt.event.ActionListener() {
183 public void actionPerformed(java.awt.event.ActionEvent evt) {
184 browseButtonActionPerformed(evt);
188 lbWarning.setFont(lbWarning.getFont().deriveFont(lbWarning.getFont().getStyle() | java.awt.Font.BOLD, 12));
189 lbWarning.setForeground(
new java.awt.Color(244, 0, 0));
190 org.openide.awt.Mnemonics.setLocalizedText(lbWarning,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.lbWarning.text"));
191 lbWarning.setToolTipText(
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.lbWarning.toolTipText"));
193 javax.swing.GroupLayout containerPanelLayout =
new javax.swing.GroupLayout(containerPanel);
194 containerPanel.setLayout(containerPanelLayout);
195 containerPanelLayout.setHorizontalGroup(
196 containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
197 .addGroup(containerPanelLayout.createSequentialGroup()
199 .addGroup(containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
200 .addComponent(lbWarning, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
201 .addGroup(containerPanelLayout.createSequentialGroup()
202 .addComponent(pathNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE)
203 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
204 .addComponent(browseButton)
205 .addContainerGap(83, Short.MAX_VALUE))))
207 containerPanelLayout.setVerticalGroup(
208 containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
209 .addGroup(containerPanelLayout.createSequentialGroup()
211 .addGroup(containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
212 .addComponent(pathNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
213 .addComponent(browseButton))
214 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
215 .addComponent(lbWarning, javax.swing.GroupLayout.DEFAULT_SIZE, 19, Short.MAX_VALUE)
219 titleLabel.setFont(titleLabel.getFont().deriveFont(titleLabel.getFont().getStyle() | java.awt.Font.BOLD, 12));
220 org.openide.awt.Mnemonics.setLocalizedText(titleLabel,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.titleLabel.text"));
222 titleSeparator.setForeground(
new java.awt.Color(102, 102, 102));
224 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
225 getContentPane().setLayout(layout);
226 layout.setHorizontalGroup(
227 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
228 .addComponent(buttonPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
229 .addGroup(layout.createSequentialGroup()
231 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
232 .addComponent(containerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
233 .addGroup(layout.createSequentialGroup()
234 .addComponent(titleLabel)
235 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
236 .addComponent(titleSeparator)))
239 layout.setVerticalGroup(
240 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
241 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
243 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
244 .addComponent(titleLabel)
245 .addComponent(titleSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE))
246 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
247 .addComponent(containerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
248 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
249 .addComponent(buttonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
255 private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {
257 String newPath = pathNameTextField.getText();
259 db.setImagePaths(obj_id, Arrays.asList(
new String[]{newPath}));
261 }
catch (TskCoreException ex) {
262 lbWarning.setText(NbBundle.getMessage(
this.getClass(),
"MissingImageDialog.ErrorSettingImage"));
263 logger.log(Level.SEVERE,
"Error setting image paths", ex);
267 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
271 private void pathNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {
272 updateSelectButton();
275 private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {
277 String oldText = pathNameTextField.getText();
278 lbWarning.setText(
"");
280 File currentDir =
new File(oldText);
281 if (currentDir.exists()) {
282 fileChooser.setCurrentDirectory(currentDir);
285 int retval = fileChooser.showOpenDialog(
this);
286 if (retval == JFileChooser.APPROVE_OPTION) {
287 String path = fileChooser.getSelectedFile().getPath();
288 pathNameTextField.setText(path);
292 updateSelectButton();
295 private javax.swing.JButton browseButton;
296 private javax.swing.JPanel buttonPanel;
297 private javax.swing.JButton cancelButton;
298 private javax.swing.JPanel containerPanel;
299 private javax.swing.JLabel lbWarning;
300 private javax.swing.JTextField pathNameTextField;
301 private javax.swing.JButton selectButton;
302 private javax.swing.JLabel titleLabel;
303 private javax.swing.JSeparator titleSeparator;
310 int ret = JOptionPane.showConfirmDialog(
this,
311 NbBundle.getMessage(
this.getClass(),
312 "MissingImageDialog.confDlg.noFileSel.msg"),
313 NbBundle.getMessage(
this.getClass(),
314 "MissingImageDialog.confDlg.noFileSel.title"),
315 JOptionPane.YES_NO_OPTION);
316 if (ret == JOptionPane.YES_OPTION) {