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;
52 @Messages({
"GetTagNameDialog.descriptionLabel.text=Description:",
53 "GetTagNameDialog.notableCheckbox.text=Tag indicates item is notable."})
54 @SuppressWarnings(
"PMD.SingularField")
57 private static final long serialVersionUID = 1L;
58 private static final String TAG_ICON_PATH =
"org/sleuthkit/autopsy/images/tag-folder-blue-icon-16.png";
59 private final Map<String, TagName> tagNamesMap =
new TreeMap<>();
60 private TagName tagName = null;
71 return doDialog(WindowManager.getDefault().getMainWindow());
93 ModalityType.APPLICATION_MODAL);
97 setIconImage(ImageUtilities.loadImage(TAG_ICON_PATH));
101 String cancelName = NbBundle.getMessage(this.getClass(),
"GetTagNameDialog.cancelName");
102 InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
103 inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName);
104 ActionMap actionMap = getRootPane().getActionMap();
105 actionMap.put(cancelName,
new AbstractAction() {
106 private static final long serialVersionUID = 1L;
109 public void actionPerformed(ActionEvent e) {
110 cancelButtonActionPerformed(e);
124 tagsTable.setModel(
new TagsTableModel(
new ArrayList<>(tagNamesMap.keySet())));
125 tagsTable.setTableHeader(null);
126 tagsTable.setCellSelectionEnabled(
false);
127 tagsTable.setFocusable(
false);
128 tagsTable.setRowHeight(tagsTable.getRowHeight() + 5);
131 this.setLocationRelativeTo(this.getOwner());
137 private static final long serialVersionUID = 1L;
138 private final ArrayList<String> tagDisplayNames =
new ArrayList<>();
141 for (String tagDisplayName : tagDisplayNames) {
142 this.tagDisplayNames.add(tagDisplayName);
148 return tagDisplayNames.size();
163 return tagDisplayNames.get(rowIndex);
172 @SuppressWarnings(
"unchecked")
174 private
void initComponents() {
176 cancelButton =
new javax.swing.JButton();
177 okButton =
new javax.swing.JButton();
178 jScrollPane1 =
new javax.swing.JScrollPane();
179 tagsTable =
new javax.swing.JTable();
180 preexistingLabel =
new javax.swing.JLabel();
181 newTagPanel =
new javax.swing.JPanel();
182 tagNameLabel =
new javax.swing.JLabel();
183 tagNameField =
new javax.swing.JTextField();
184 descriptionLabel =
new javax.swing.JLabel();
185 descriptionScrollPane =
new javax.swing.JScrollPane();
186 descriptionTextArea =
new javax.swing.JTextArea();
187 notableCheckbox =
new javax.swing.JCheckBox();
189 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
190 addKeyListener(
new java.awt.event.KeyAdapter() {
191 public void keyReleased(java.awt.event.KeyEvent evt) {
192 formKeyReleased(evt);
196 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.cancelButton.text"));
197 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
198 public void actionPerformed(java.awt.event.ActionEvent evt) {
199 cancelButtonActionPerformed(evt);
203 org.openide.awt.Mnemonics.setLocalizedText(okButton,
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.okButton.text"));
204 okButton.addActionListener(
new java.awt.event.ActionListener() {
205 public void actionPerformed(java.awt.event.ActionEvent evt) {
206 okButtonActionPerformed(evt);
210 jScrollPane1.setBackground(
new java.awt.Color(255, 255, 255));
212 tagsTable.setBackground(
new java.awt.Color(240, 240, 240));
213 tagsTable.setModel(
new javax.swing.table.DefaultTableModel(
221 tagsTable.setOpaque(
false);
222 tagsTable.setShowHorizontalLines(
false);
223 tagsTable.setShowVerticalLines(
false);
224 tagsTable.setTableHeader(null);
225 jScrollPane1.setViewportView(tagsTable);
227 org.openide.awt.Mnemonics.setLocalizedText(preexistingLabel,
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.preexistingLabel.text"));
229 newTagPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.newTagPanel.border.title")));
231 org.openide.awt.Mnemonics.setLocalizedText(tagNameLabel,
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.tagNameLabel.text"));
233 tagNameField.setText(
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.tagNameField.text"));
234 tagNameField.addKeyListener(
new java.awt.event.KeyAdapter() {
235 public void keyReleased(java.awt.event.KeyEvent evt) {
236 tagNameFieldKeyReleased(evt);
240 org.openide.awt.Mnemonics.setLocalizedText(descriptionLabel,
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.descriptionLabel.text"));
242 descriptionTextArea.setColumns(20);
243 descriptionTextArea.setFont(
new java.awt.Font(
"Tahoma", 0, 11));
244 descriptionTextArea.setRows(3);
245 descriptionScrollPane.setViewportView(descriptionTextArea);
247 org.openide.awt.Mnemonics.setLocalizedText(notableCheckbox,
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.notableCheckbox.text"));
249 javax.swing.GroupLayout newTagPanelLayout =
new javax.swing.GroupLayout(newTagPanel);
250 newTagPanel.setLayout(newTagPanelLayout);
251 newTagPanelLayout.setHorizontalGroup(
252 newTagPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
253 .addGroup(newTagPanelLayout.createSequentialGroup()
255 .addGroup(newTagPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
256 .addComponent(descriptionScrollPane, javax.swing.GroupLayout.Alignment.TRAILING)
257 .addComponent(tagNameField, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
258 .addGroup(newTagPanelLayout.createSequentialGroup()
259 .addGroup(newTagPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
260 .addComponent(notableCheckbox)
261 .addComponent(descriptionLabel)
262 .addComponent(tagNameLabel))
263 .addGap(0, 0, Short.MAX_VALUE)))
266 newTagPanelLayout.setVerticalGroup(
267 newTagPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
268 .addGroup(newTagPanelLayout.createSequentialGroup()
270 .addComponent(tagNameLabel)
271 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
272 .addComponent(tagNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
273 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
274 .addComponent(descriptionLabel)
275 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
276 .addComponent(descriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
277 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
278 .addComponent(notableCheckbox)
279 .addContainerGap(31, Short.MAX_VALUE))
282 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
283 getContentPane().setLayout(layout);
284 layout.setHorizontalGroup(
285 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
286 .addGroup(layout.createSequentialGroup()
288 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
289 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)
290 .addComponent(preexistingLabel))
291 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
292 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
293 .addGroup(layout.createSequentialGroup()
294 .addGap(0, 233, Short.MAX_VALUE)
295 .addComponent(okButton)
296 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
297 .addComponent(cancelButton))
298 .addComponent(newTagPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
301 layout.setVerticalGroup(
302 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
303 .addGroup(layout.createSequentialGroup()
305 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
306 .addGroup(layout.createSequentialGroup()
307 .addComponent(preexistingLabel)
308 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
309 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
310 .addComponent(newTagPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
311 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
312 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
313 .addComponent(cancelButton)
314 .addComponent(okButton))
326 @NbBundle.Messages({
"GetTagNameDialog.tagNameAlreadyExists.message=Tag name must be unique. A tag with this name already exists.",
327 "GetTagNameDialog.tagNameAlreadyExists.title=Duplicate Tag Name",
328 "GetTagNameDialog.tagDescriptionIllegalCharacters.message=Tag descriptions may not contain commas (,) or semicolons (;)",
329 "GetTagNameDialog.tagDescriptionIllegalCharacters.title=Invalid character in tag description"})
331 String tagDisplayName = tagNameField.getText();
332 String userTagDescription = descriptionTextArea.getText();
333 TskData.FileKnown status = notableCheckbox.isSelected() ? TskData.FileKnown.BAD : TskData.FileKnown.UNKNOWN;
334 if (tagDisplayName.isEmpty()) {
335 JOptionPane.showMessageDialog(
this,
336 NbBundle.getMessage(
this.getClass(),
337 "GetTagNameDialog.mustSupplyTtagName.msg"),
338 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.tagNameErr"),
339 JOptionPane.ERROR_MESSAGE);
341 JOptionPane.showMessageDialog(
this,
342 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.illegalChars.msg"),
343 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.illegalCharsErr"),
344 JOptionPane.ERROR_MESSAGE);
345 }
else if (userTagDescription.contains(
",")
346 || userTagDescription.contains(
";")) {
347 JOptionPane.showMessageDialog(
this,
348 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.tagDescriptionIllegalCharacters.message"),
349 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.tagDescriptionIllegalCharacters.title"),
350 JOptionPane.ERROR_MESSAGE);
352 tagName = tagNamesMap.get(tagDisplayName);
354 if (tagName == null) {
359 Logger.
getLogger(AddTagAction.class.getName()).log(Level.SEVERE,
"Error adding " + tagDisplayName +
" tag name", ex);
360 JOptionPane.showMessageDialog(
this,
361 NbBundle.getMessage(
this.getClass(),
362 "GetTagNameDialog.unableToAddTagNameToCase.msg",
364 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.taggingErr"),
365 JOptionPane.ERROR_MESSAGE);
371 Logger.
getLogger(AddTagAction.class.getName()).log(Level.SEVERE, tagDisplayName +
" exists in database but an error occurred in retrieving it.", ex1);
372 JOptionPane.showMessageDialog(
this,
373 NbBundle.getMessage(
this.getClass(),
374 "GetTagNameDialog.tagNameExistsTskCore.msg",
376 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.dupTagErr"),
377 JOptionPane.ERROR_MESSAGE);
382 JOptionPane.showMessageDialog(
this,
383 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.tagNameAlreadyExists.message"),
384 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.tagNameAlreadyExists.title"),
385 JOptionPane.INFORMATION_MESSAGE);
391 if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
392 okButtonActionPerformed(null);
397 if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
398 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)
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 Case getCurrentCaseThrows()
static TagName doDialog()
GetTagNameDialog(Window owner)
javax.swing.JCheckBox notableCheckbox
void cancelButtonActionPerformed(java.awt.event.ActionEvent evt)