19 package org.sleuthkit.autopsy.casemodule;
22 import java.awt.event.WindowAdapter;
23 import java.awt.event.WindowEvent;
24 import java.util.Arrays;
25 import java.util.List;
26 import java.util.ArrayList;
27 import java.util.logging.Level;
29 import javax.swing.JFileChooser;
30 import javax.swing.JFrame;
31 import javax.swing.JOptionPane;
32 import org.openide.util.NbBundle;
37 class MissingImageDialog
extends javax.swing.JDialog {
39 private static final Logger logger = Logger.getLogger(MissingImageDialog.class.getName());
42 static final GeneralFilter rawFilter =
new GeneralFilter(GeneralFilter.RAW_IMAGE_EXTS, GeneralFilter.RAW_IMAGE_DESC);
43 static final GeneralFilter encaseFilter =
new GeneralFilter(GeneralFilter.ENCASE_IMAGE_EXTS, GeneralFilter.ENCASE_IMAGE_DESC);
44 static final List<String> allExt =
new ArrayList<String>();
47 allExt.addAll(GeneralFilter.RAW_IMAGE_EXTS);
48 allExt.addAll(GeneralFilter.ENCASE_IMAGE_EXTS);
50 static final String allDesc = NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.allDesc.text");
51 static final GeneralFilter allFilter =
new GeneralFilter(allExt, allDesc);
52 private JFileChooser fc =
new JFileChooser();
54 private MissingImageDialog(
long obj_id, SleuthkitCase db) {
55 super(
new JFrame(),
true);
60 fc.setDragEnabled(
false);
61 fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
62 fc.setMultiSelectionEnabled(
false);
64 fc.addChoosableFileFilter(rawFilter);
65 fc.addChoosableFileFilter(encaseFilter);
66 fc.setFileFilter(allFilter);
78 static void makeDialog(
long obj_id, SleuthkitCase db) {
79 final MissingImageDialog dialog =
new MissingImageDialog(obj_id, db);
80 dialog.addWindowListener(
new WindowAdapter() {
82 public void windowClosing(WindowEvent e) {
89 private void customInit() {
91 selectButton.setEnabled(
false);
94 private void display() {
95 this.setTitle(NbBundle.getMessage(
this.getClass(),
"MissingImageDialog.display.title"));
96 Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
98 int w = this.getSize().width;
99 int h = this.getSize().height;
101 setLocation((screenDimension.width - w) / 2, (screenDimension.height - h) / 2);
103 this.setVisible(
true);
109 private void moveFocusToSelect() {
110 this.selectButton.requestFocusInWindow();
116 private void updateSelectButton() {
119 if (!pathNameTextField.getText().isEmpty()) {
120 String filePath = pathNameTextField.getText();
121 boolean isExist = Case.pathExists(filePath) || Case.driveExists(filePath);
122 selectButton.setEnabled(isExist);
131 @SuppressWarnings(
"unchecked")
133 private
void initComponents() {
135 buttonPanel =
new javax.swing.JPanel();
136 selectButton =
new javax.swing.JButton();
137 cancelButton =
new javax.swing.JButton();
138 containerPanel =
new javax.swing.JPanel();
139 pathNameTextField =
new javax.swing.JTextField();
140 browseButton =
new javax.swing.JButton();
141 titleLabel =
new javax.swing.JLabel();
142 titleSeparator =
new javax.swing.JSeparator();
144 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
146 org.openide.awt.Mnemonics.setLocalizedText(selectButton,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.selectButton.text"));
147 selectButton.addActionListener(
new java.awt.event.ActionListener() {
148 public void actionPerformed(java.awt.event.ActionEvent evt) {
149 selectButtonActionPerformed(evt);
153 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.cancelButton.text"));
154 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
155 public void actionPerformed(java.awt.event.ActionEvent evt) {
156 cancelButtonActionPerformed(evt);
160 javax.swing.GroupLayout buttonPanelLayout =
new javax.swing.GroupLayout(buttonPanel);
161 buttonPanel.setLayout(buttonPanelLayout);
162 buttonPanelLayout.setHorizontalGroup(
163 buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
164 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, buttonPanelLayout.createSequentialGroup()
165 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
166 .addComponent(selectButton)
167 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
168 .addComponent(cancelButton)
171 buttonPanelLayout.setVerticalGroup(
172 buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
173 .addGroup(buttonPanelLayout.createSequentialGroup()
175 .addGroup(buttonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
176 .addComponent(selectButton)
177 .addComponent(cancelButton))
178 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
181 pathNameTextField.setText(
org.openide.util.NbBundle.getMessage(MissingImageDialog.class,
"MissingImageDialog.pathNameTextField.text"));
182 pathNameTextField.addActionListener(
new java.awt.event.ActionListener() {
183 public void actionPerformed(java.awt.event.ActionEvent evt) {
184 pathNameTextFieldActionPerformed(evt);
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 javax.swing.GroupLayout containerPanelLayout =
new javax.swing.GroupLayout(containerPanel);
196 containerPanel.setLayout(containerPanelLayout);
197 containerPanelLayout.setHorizontalGroup(
198 containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
199 .addGroup(containerPanelLayout.createSequentialGroup()
201 .addComponent(pathNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE)
202 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
203 .addComponent(browseButton)
204 .addContainerGap(83, Short.MAX_VALUE))
206 containerPanelLayout.setVerticalGroup(
207 containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
208 .addGroup(containerPanelLayout.createSequentialGroup()
210 .addGroup(containerPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
211 .addComponent(pathNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
212 .addComponent(browseButton))
213 .addContainerGap(62, Short.MAX_VALUE))
216 titleLabel.setFont(titleLabel.getFont().deriveFont(Font.BOLD, 12));
217 org.openide.awt.Mnemonics.setLocalizedText(titleLabel,
org.openide.util.NbBundle
218 .getMessage(MissingImageDialog.class,
"MissingImageDialog.titleLabel.text"));
220 titleSeparator.setForeground(
new java.awt.Color(102, 102, 102));
222 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
223 getContentPane().setLayout(layout);
224 layout.setHorizontalGroup(
225 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
226 .addComponent(buttonPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
227 .addGroup(layout.createSequentialGroup()
229 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
230 .addComponent(containerPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
231 .addGroup(layout.createSequentialGroup()
232 .addComponent(titleLabel)
233 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
234 .addComponent(titleSeparator)))
237 layout.setVerticalGroup(
238 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
239 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
241 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
242 .addComponent(titleLabel)
243 .addComponent(titleSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 7, javax.swing.GroupLayout.PREFERRED_SIZE))
244 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
245 .addComponent(containerPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
246 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
247 .addComponent(buttonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
253 private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {
255 String newPath = pathNameTextField.getText();
257 db.setImagePaths(obj_id, Arrays.asList(
new String[]{newPath}));
258 }
catch (TskCoreException ex) {
259 logger.log(Level.WARNING,
"Error setting image paths", ex);
264 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
268 private void pathNameTextFieldActionPerformed(java.awt.event.ActionEvent evt) {
271 updateSelectButton();
274 private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {
276 String oldText = pathNameTextField.getText();
279 File currentDir =
new File(oldText);
280 if (currentDir.exists()) {
281 fc.setCurrentDirectory(currentDir);
284 int retval = fc.showOpenDialog(
this);
285 if (retval == JFileChooser.APPROVE_OPTION) {
286 String path = fc.getSelectedFile().getPath();
287 pathNameTextField.setText(path);
291 updateSelectButton();
294 private javax.swing.JButton browseButton;
295 private javax.swing.JPanel buttonPanel;
296 private javax.swing.JButton cancelButton;
297 private javax.swing.JPanel containerPanel;
298 private javax.swing.JTextField pathNameTextField;
299 private javax.swing.JButton selectButton;
300 private javax.swing.JLabel titleLabel;
301 private javax.swing.JSeparator titleSeparator;
308 int ret = JOptionPane.showConfirmDialog(null,
309 NbBundle.getMessage(
this.getClass(),
310 "MissingImageDialog.confDlg.noFileSel.msg"),
311 NbBundle.getMessage(
this.getClass(),
312 "MissingImageDialog.confDlg.noFileSel.title"),
313 JOptionPane.YES_NO_OPTION);
314 if (ret == JOptionPane.YES_OPTION) {