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.setShowHorizontalLines(
false);
222 tagsTable.setShowVerticalLines(
false);
223 tagsTable.setTableHeader(null);
224 jScrollPane1.setViewportView(tagsTable);
226 org.openide.awt.Mnemonics.setLocalizedText(preexistingLabel,
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.preexistingLabel.text"));
228 newTagPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.newTagPanel.border.title")));
230 org.openide.awt.Mnemonics.setLocalizedText(tagNameLabel,
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.tagNameLabel.text"));
232 tagNameField.setText(
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.tagNameField.text"));
233 tagNameField.addKeyListener(
new java.awt.event.KeyAdapter() {
234 public void keyReleased(java.awt.event.KeyEvent evt) {
235 tagNameFieldKeyReleased(evt);
239 org.openide.awt.Mnemonics.setLocalizedText(descriptionLabel,
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.descriptionLabel.text"));
241 descriptionTextArea.setColumns(20);
242 descriptionTextArea.setFont(
new java.awt.Font(
"Tahoma", 0, 11));
243 descriptionTextArea.setRows(3);
244 descriptionScrollPane.setViewportView(descriptionTextArea);
246 org.openide.awt.Mnemonics.setLocalizedText(notableCheckbox,
org.openide.util.NbBundle.getMessage(
GetTagNameDialog.class,
"GetTagNameDialog.notableCheckbox.text"));
248 javax.swing.GroupLayout newTagPanelLayout =
new javax.swing.GroupLayout(newTagPanel);
249 newTagPanel.setLayout(newTagPanelLayout);
250 newTagPanelLayout.setHorizontalGroup(
251 newTagPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
252 .addGroup(newTagPanelLayout.createSequentialGroup()
254 .addGroup(newTagPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
255 .addComponent(descriptionScrollPane, javax.swing.GroupLayout.Alignment.TRAILING)
256 .addComponent(tagNameField, javax.swing.GroupLayout.DEFAULT_SIZE, 323, Short.MAX_VALUE)
257 .addGroup(newTagPanelLayout.createSequentialGroup()
258 .addGroup(newTagPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
259 .addComponent(notableCheckbox)
260 .addComponent(descriptionLabel)
261 .addComponent(tagNameLabel))
262 .addGap(0, 0, Short.MAX_VALUE)))
265 newTagPanelLayout.setVerticalGroup(
266 newTagPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
267 .addGroup(newTagPanelLayout.createSequentialGroup()
269 .addComponent(tagNameLabel)
270 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
271 .addComponent(tagNameField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
272 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
273 .addComponent(descriptionLabel)
274 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
275 .addComponent(descriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
276 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
277 .addComponent(notableCheckbox)
278 .addContainerGap(31, Short.MAX_VALUE))
281 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
282 getContentPane().setLayout(layout);
283 layout.setHorizontalGroup(
284 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
285 .addGroup(layout.createSequentialGroup()
287 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
288 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 198, javax.swing.GroupLayout.PREFERRED_SIZE)
289 .addComponent(preexistingLabel))
290 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
291 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
292 .addGroup(layout.createSequentialGroup()
293 .addGap(0, 233, Short.MAX_VALUE)
294 .addComponent(okButton)
295 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
296 .addComponent(cancelButton))
297 .addComponent(newTagPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
300 layout.setVerticalGroup(
301 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
302 .addGroup(layout.createSequentialGroup()
304 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
305 .addGroup(layout.createSequentialGroup()
306 .addComponent(preexistingLabel)
307 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
308 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
309 .addComponent(newTagPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
310 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
311 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
312 .addComponent(cancelButton)
313 .addComponent(okButton))
325 @NbBundle.Messages({
"GetTagNameDialog.tagNameAlreadyExists.message=Tag name must be unique. A tag with this name already exists.",
326 "GetTagNameDialog.tagNameAlreadyExists.title=Duplicate Tag Name",
327 "GetTagNameDialog.tagDescriptionIllegalCharacters.message=Tag descriptions may not contain commas (,) or semicolons (;)",
328 "GetTagNameDialog.tagDescriptionIllegalCharacters.title=Invalid character in tag description"})
330 String tagDisplayName = tagNameField.getText();
331 String userTagDescription = descriptionTextArea.getText();
332 TskData.FileKnown status = notableCheckbox.isSelected() ? TskData.FileKnown.BAD : TskData.FileKnown.UNKNOWN;
333 if (tagDisplayName.isEmpty()) {
334 JOptionPane.showMessageDialog(
this,
335 NbBundle.getMessage(
this.getClass(),
336 "GetTagNameDialog.mustSupplyTtagName.msg"),
337 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.tagNameErr"),
338 JOptionPane.ERROR_MESSAGE);
340 JOptionPane.showMessageDialog(
this,
341 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.illegalChars.msg"),
342 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.illegalCharsErr"),
343 JOptionPane.ERROR_MESSAGE);
344 }
else if (userTagDescription.contains(
",")
345 || userTagDescription.contains(
";")) {
346 JOptionPane.showMessageDialog(
this,
347 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.tagDescriptionIllegalCharacters.message"),
348 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.tagDescriptionIllegalCharacters.title"),
349 JOptionPane.ERROR_MESSAGE);
351 tagName = tagNamesMap.get(tagDisplayName);
353 if (tagName == null) {
358 Logger.
getLogger(AddTagAction.class.getName()).log(Level.SEVERE,
"Error adding " + tagDisplayName +
" tag name", ex);
359 JOptionPane.showMessageDialog(
this,
360 NbBundle.getMessage(
this.getClass(),
361 "GetTagNameDialog.unableToAddTagNameToCase.msg",
363 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.taggingErr"),
364 JOptionPane.ERROR_MESSAGE);
370 Logger.
getLogger(AddTagAction.class.getName()).log(Level.SEVERE, tagDisplayName +
" exists in database but an error occurred in retrieving it.", ex1);
371 JOptionPane.showMessageDialog(
this,
372 NbBundle.getMessage(
this.getClass(),
373 "GetTagNameDialog.tagNameExistsTskCore.msg",
375 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.dupTagErr"),
376 JOptionPane.ERROR_MESSAGE);
381 JOptionPane.showMessageDialog(
this,
382 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.tagNameAlreadyExists.message"),
383 NbBundle.getMessage(
this.getClass(),
"GetTagNameDialog.tagNameAlreadyExists.title"),
384 JOptionPane.INFORMATION_MESSAGE);
390 if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
391 okButtonActionPerformed(null);
396 if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
397 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)