19 package org.sleuthkit.autopsy.actions;
21 import java.awt.Window;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.KeyEvent;
25 import java.util.TreeMap;
26 import java.util.logging.Level;
27 import javax.swing.AbstractAction;
28 import javax.swing.ActionMap;
29 import javax.swing.InputMap;
30 import javax.swing.JComponent;
31 import javax.swing.JDialog;
32 import javax.swing.KeyStroke;
33 import org.openide.util.NbBundle;
34 import org.openide.windows.WindowManager;
45 "GetTagNameAndCommentDialog.noTags");
46 private final Map<String, TagName>
tagNamesMap =
new TreeMap<>();
78 return doDialog(WindowManager.getDefault().getMainWindow());
102 ModalityType.APPLICATION_MODAL);
109 String cancelName = NbBundle.getMessage(this.getClass(),
"GetTagNameAndCommentDialog.cancelName");
110 InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
111 inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName);
112 ActionMap actionMap = getRootPane().getActionMap();
113 actionMap.put(cancelName,
new AbstractAction() {
114 private static final long serialVersionUID = 1L;
116 public void actionPerformed(ActionEvent e) {
128 }
catch (TskCoreException ex) {
131 if (null != tagNamesMap && tagNamesMap.isEmpty()) {
132 tagCombo.addItem(NO_TAG_NAMES_MESSAGE);
134 for (String tagDisplayName : tagNamesMap.keySet()) {
140 this.setLocationRelativeTo(this.getOwner());
149 @SuppressWarnings(
"unchecked")
153 okButton =
new javax.swing.JButton();
155 tagCombo =
new javax.swing.JComboBox<String>();
156 tagLabel =
new javax.swing.JLabel();
161 addWindowListener(
new java.awt.event.WindowAdapter() {
162 public void windowClosing(java.awt.event.WindowEvent evt) {
168 okButton.addActionListener(
new java.awt.event.ActionListener() {
169 public void actionPerformed(java.awt.event.ActionEvent evt) {
175 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
176 public void actionPerformed(java.awt.event.ActionEvent evt) {
183 org.openide.awt.Mnemonics.setLocalizedText(tagLabel,
org.openide.util.NbBundle.getMessage(
GetTagNameAndCommentDialog.class,
"GetTagNameAndCommentDialog.tagLabel.text"));
191 newTagButton.addActionListener(
new java.awt.event.ActionListener() {
192 public void actionPerformed(java.awt.event.ActionEvent evt) {
197 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
198 getContentPane().setLayout(layout);
199 layout.setHorizontalGroup(
200 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
201 .addGroup(layout.createSequentialGroup()
203 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
204 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
206 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 48, Short.MAX_VALUE)
207 .addComponent(
okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
208 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
210 .addGroup(layout.createSequentialGroup()
211 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
213 .addComponent(tagLabel))
214 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
215 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
217 .addComponent(
tagCombo, 0, 214, Short.MAX_VALUE))
218 .addGap(0, 0, Short.MAX_VALUE)))
222 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {cancelButton, okButton});
224 layout.setVerticalGroup(
225 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
226 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
228 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
229 .addComponent(
tagCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
230 .addComponent(tagLabel))
231 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
232 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
234 .addComponent(
commentText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
235 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
236 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
243 getRootPane().setDefaultButton(
okButton);
249 String tagDisplayName = (String)
tagCombo.getSelectedItem();
250 TagName tagNameFromCombo = tagNamesMap.get(tagDisplayName);
251 if (tagNameFromCombo == null) {
257 }
catch (TskCoreException ex1) {
258 Logger.
getLogger(AddTagAction.class.getName()).log(Level.SEVERE, tagDisplayName +
" already exists in database but an error occurred in retrieving it.", ex1);
260 }
catch (TskCoreException ex) {
261 Logger.
getLogger(AddTagAction.class.getName()).log(Level.SEVERE,
"Error adding " + tagDisplayName +
" tag name", ex);
269 tagNameAndComment = null;
274 tagNameAndComment = null;
280 if (newTagName != null) {
281 tagNamesMap.put(newTagName.getDisplayName(), newTagName);
282 tagCombo.addItem(newTagName.getDisplayName());
283 tagCombo.setSelectedItem(newTagName.getDisplayName());
TagsManager getTagsManager()
static Case getCurrentCase()
synchronized static Logger getLogger(String name)
static TagName doDialog()