19 package org.sleuthkit.autopsy.actions;
21 import java.awt.Window;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.KeyEvent;
24 import java.util.ArrayList;
25 import java.util.List;
27 import java.util.TreeMap;
28 import java.util.logging.Level;
29 import javax.swing.AbstractAction;
30 import javax.swing.ActionMap;
31 import javax.swing.InputMap;
32 import javax.swing.JComponent;
33 import javax.swing.JDialog;
34 import javax.swing.JOptionPane;
35 import javax.swing.KeyStroke;
36 import javax.swing.table.AbstractTableModel;
37 import org.openide.util.ImageUtilities;
38 import org.openide.util.NbBundle;
39 import org.openide.util.NbBundle.Messages;
40 import org.openide.windows.WindowManager;
49 @Messages({
"GetTagNameDialog.descriptionLabel.text=Description:",
50 "GetTagNameDialog.notableCheckbox.text=Tag indicates item is notable."})
53 private static final long serialVersionUID = 1L;
54 private static final String TAG_ICON_PATH =
"org/sleuthkit/autopsy/images/tag-folder-blue-icon-16.png";
55 private final Map<String, TagName> tagNamesMap =
new TreeMap<>();
56 private TagName tagName = null;
67 return doDialog(WindowManager.getDefault().getMainWindow());
89 ModalityType.APPLICATION_MODAL);
93 setIconImage(ImageUtilities.loadImage(TAG_ICON_PATH));
97 String cancelName = NbBundle.getMessage(this.getClass(),
"GetTagNameDialog.cancelName");
98 InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
99 inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName);
100 ActionMap actionMap = getRootPane().getActionMap();
101 actionMap.put(cancelName,
new AbstractAction() {
102 private static final long serialVersionUID = 1L;
105 public void actionPerformed(ActionEvent e) {
106 cancelButtonActionPerformed(e);
120 tagsTable.setModel(
new TagsTableModel(
new ArrayList<>(tagNamesMap.keySet())));
121 tagsTable.setTableHeader(null);
122 tagsTable.setCellSelectionEnabled(
false);
123 tagsTable.setFocusable(
false);
124 tagsTable.setRowHeight(tagsTable.getRowHeight() + 5);
127 this.setLocationRelativeTo(this.getOwner());
133 private static final long serialVersionUID = 1L;
134 private final ArrayList<String> tagDisplayNames =
new ArrayList<>();
137 for (String tagDisplayName : tagDisplayNames) {
138 this.tagDisplayNames.add(tagDisplayName);
144 return tagDisplayNames.size();
159 return tagDisplayNames.get(rowIndex);
168 @SuppressWarnings(
"unchecked")
170 private
void initComponents() {
172 cancelButton =
new javax.swing.JButton();
173 okButton =
new javax.swing.JButton();
174 jScrollPane1 =
new javax.swing.JScrollPane();
175 tagsTable =
new javax.swing.JTable();
176 preexistingLabel =
new javax.swing.JLabel();
177 newTagPanel =
new javax.swing.JPanel();
178 tagNameLabel =
new javax.swing.JLabel();
179 tagNameField =
new javax.swing.JTextField();
180 descriptionLabel =
new javax.swing.JLabel();
181 descriptionScrollPane =
new javax.swing.JScrollPane();
182 descriptionTextArea =
new javax.swing.JTextArea();
183 notableCheckbox =
new javax.swing.JCheckBox();
185 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
186 addKeyListener(
new java.awt.event.KeyAdapter() {
187 public void keyReleased(java.awt.event.KeyEvent evt) {
188 formKeyReleased(evt);
192 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.cancelButton.text"));
193 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
194 public void actionPerformed(java.awt.event.ActionEvent evt) {
195 cancelButtonActionPerformed(evt);
199 org.openide.awt.Mnemonics.setLocalizedText(okButton,
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.okButton.text"));
200 okButton.addActionListener(
new java.awt.event.ActionListener() {
201 public void actionPerformed(java.awt.event.ActionEvent evt) {
202 okButtonActionPerformed(evt);
206 jScrollPane1.setBackground(
new java.awt.Color(255, 255, 255));
208 tagsTable.setBackground(
new java.awt.Color(240, 240, 240));
209 tagsTable.setModel(
new javax.swing.table.DefaultTableModel(
217 tagsTable.setShowHorizontalLines(
false);
218 tagsTable.setShowVerticalLines(
false);
219 tagsTable.setTableHeader(null);
220 jScrollPane1.setViewportView(tagsTable);
222 org.openide.awt.Mnemonics.setLocalizedText(preexistingLabel,
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.preexistingLabel.text"));
224 newTagPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.newTagPanel.border.title")));
226 org.openide.awt.Mnemonics.setLocalizedText(tagNameLabel,
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.tagNameLabel.text"));
228 tagNameField.setText(
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.tagNameField.text"));
229 tagNameField.addKeyListener(
new java.awt.event.KeyAdapter() {
230 public void keyReleased(java.awt.event.KeyEvent evt) {
231 tagNameFieldKeyReleased(evt);
235 org.openide.awt.Mnemonics.setLocalizedText(descriptionLabel,
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.descriptionLabel.text"));
237 descriptionTextArea.setColumns(20);
238 descriptionTextArea.setFont(
new java.awt.Font(
"Tahoma", 0, 11));
239 descriptionTextArea.setRows(3);
240 descriptionScrollPane.setViewportView(descriptionTextArea);
242 org.openide.awt.Mnemonics.setLocalizedText(notableCheckbox,
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.notableCheckbox.text"));
244 javax.swing.GroupLayout newTagPanelLayout =
new javax.swing.GroupLayout(newTagPanel);
245 newTagPanel.setLayout(newTagPanelLayout);
246 newTagPanelLayout.setHorizontalGroup(
247 newTagPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
248 .addGroup(newTagPanelLayout.createSequentialGroup()
250 .addGroup(newTagPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
251 .addComponent(descriptionScrollPane, javax.swing.GroupLayout.Alignment.TRAILING)
252 .addComponent(tagNameField, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
253 .addGroup(newTagPanelLayout.createSequentialGroup()
254 .addGroup(newTagPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
255 .addComponent(notableCheckbox)
256 .addComponent(descriptionLabel)
257 .addComponent(tagNameLabel))
258 .addGap(0, 0, Short.MAX_VALUE)))
261 newTagPanelLayout.setVerticalGroup(
262 newTagPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
263 .addGroup(newTagPanelLayout.createSequentialGroup()
265 .addComponent(tagNameLabel)
266 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
267 .addComponent(tagNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
268 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
269 .addComponent(descriptionLabel)
270 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
271 .addComponent(descriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
272 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
273 .addComponent(notableCheckbox)
274 .addContainerGap(31, Short.MAX_VALUE))
277 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
278 getContentPane().setLayout(layout);
279 layout.setHorizontalGroup(
280 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
281 .addGroup(layout.createSequentialGroup()
283 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
284 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)
285 .addComponent(preexistingLabel))
286 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
287 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
288 .addGroup(layout.createSequentialGroup()
289 .addGap(0, 233, Short.MAX_VALUE)
290 .addComponent(okButton)
291 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
292 .addComponent(cancelButton))
293 .addComponent(newTagPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
296 layout.setVerticalGroup(
297 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
298 .addGroup(layout.createSequentialGroup()
300 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
301 .addGroup(layout.createSequentialGroup()
302 .addComponent(preexistingLabel)
303 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
304 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
305 .addComponent(newTagPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
306 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
307 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
308 .addComponent(cancelButton)
309 .addComponent(okButton))
321 @NbBundle.Messages({
"GetTagNameDialog.tagNameAlreadyExists.message=Tag name must be unique. A tag with this name already exists.",
322 "GetTagNameDialog.tagNameAlreadyExists.title=Duplicate Tag Name",
323 "GetTagNameDialog.tagDescriptionIllegalCharacters.message=Tag descriptions may not contain commas (,) or semicolons (;)",
324 "GetTagNameDialog.tagDescriptionIllegalCharacters.title=Invalid character in tag description"})
326 String tagDisplayName = tagNameField.getText();
327 String userTagDescription = descriptionTextArea.getText();
328 TskData.FileKnown status = notableCheckbox.isSelected() ? TskData.FileKnown.BAD : TskData.FileKnown.UNKNOWN;
329 if (tagDisplayName.isEmpty()) {
330 JOptionPane.showMessageDialog(
this,
331 NbBundle.getMessage(
this.getClass(),
332 "GetTagNameDialog.mustSupplyTtagName.msg"),
333 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.tagNameErr"),
334 JOptionPane.ERROR_MESSAGE);
336 JOptionPane.showMessageDialog(
this,
337 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.illegalChars.msg"),
338 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.illegalCharsErr"),
339 JOptionPane.ERROR_MESSAGE);
340 }
else if (userTagDescription.contains(
",")
341 || userTagDescription.contains(
";")) {
342 JOptionPane.showMessageDialog(
this,
343 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.tagDescriptionIllegalCharacters.message"),
344 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.tagDescriptionIllegalCharacters.title"),
345 JOptionPane.ERROR_MESSAGE);
347 tagName = tagNamesMap.get(tagDisplayName);
349 if (tagName == null) {
354 Logger.
getLogger(AddTagAction.class.getName()).log(Level.SEVERE,
"Error adding " + tagDisplayName +
" tag name", ex);
355 JOptionPane.showMessageDialog(
this,
356 NbBundle.getMessage(
this.getClass(),
357 "GetTagNameDialog.unableToAddTagNameToCase.msg",
359 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.taggingErr"),
360 JOptionPane.ERROR_MESSAGE);
366 Logger.
getLogger(AddTagAction.class.getName()).log(Level.SEVERE, tagDisplayName +
" exists in database but an error occurred in retrieving it.", ex1);
367 JOptionPane.showMessageDialog(
this,
368 NbBundle.getMessage(
this.getClass(),
369 "GetTagNameDialog.tagNameExistsTskCore.msg",
371 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.dupTagErr"),
372 JOptionPane.ERROR_MESSAGE);
377 JOptionPane.showMessageDialog(
this,
378 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.tagNameAlreadyExists.message"),
379 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.tagNameAlreadyExists.title"),
380 JOptionPane.INFORMATION_MESSAGE);
386 if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
387 okButtonActionPerformed(null);
392 if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
393 okButtonActionPerformed(null);
javax.swing.JLabel preexistingLabel
void tagNameFieldKeyReleased(java.awt.event.KeyEvent evt)
javax.swing.JButton cancelButton
javax.swing.JScrollPane jScrollPane1
javax.swing.JTable tagsTable
void okButtonActionPerformed(java.awt.event.ActionEvent evt)
static Case getOpenCase()
javax.swing.JScrollPane descriptionScrollPane
javax.swing.JTextArea descriptionTextArea
javax.swing.JPanel newTagPanel
static TagName doDialog(Window owner)
TagsManager getTagsManager()
javax.swing.JLabel tagNameLabel
void formKeyReleased(java.awt.event.KeyEvent evt)
javax.swing.JButton okButton
javax.swing.JLabel descriptionLabel
javax.swing.JTextField tagNameField
synchronized static Logger getLogger(String name)
static TagName doDialog()
GetTagNameDialog(Window owner)
javax.swing.JCheckBox notableCheckbox
void cancelButtonActionPerformed(java.awt.event.ActionEvent evt)