19 package org.sleuthkit.autopsy.actions;
21 import java.awt.Component;
22 import java.awt.Window;
23 import java.awt.event.ActionEvent;
24 import java.awt.event.KeyEvent;
25 import java.util.logging.Level;
26 import java.util.HashSet;
28 import javax.swing.AbstractAction;
29 import javax.swing.ActionMap;
30 import javax.swing.DefaultListCellRenderer;
31 import javax.swing.InputMap;
32 import javax.swing.JComponent;
33 import javax.swing.JDialog;
34 import javax.swing.JList;
35 import javax.swing.KeyStroke;
36 import org.openide.util.NbBundle;
37 import org.openide.windows.WindowManager;
80 return doDialog(WindowManager.getDefault().getMainWindow());
104 ModalityType.APPLICATION_MODAL);
110 tagCombo.setRenderer(
new DefaultListCellRenderer() {
111 private static final long serialVersionUID = 1L;
113 public Component getListCellRendererComponent(JList<?> list, Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
115 String newValue = ((TagName) value).getDisplayName() + status;
116 return super.getListCellRendererComponent(list, newValue, index, isSelected, cellHasFocus);
120 String cancelName = NbBundle.getMessage(this.getClass(),
"GetTagNameAndCommentDialog.cancelName");
121 InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
123 inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName);
124 ActionMap actionMap = getRootPane().getActionMap();
126 actionMap.put(cancelName,
new AbstractAction() {
127 private static final long serialVersionUID = 1L;
130 public void actionPerformed(ActionEvent e) {
144 }
catch (TskCoreException ex) {
146 .getName()).log(Level.SEVERE,
"Failed to get tag names", ex);
148 for (TagName tag : tagNamesSet) {
154 this.setLocationRelativeTo(this.getOwner());
163 @SuppressWarnings(
"unchecked")
167 okButton =
new javax.swing.JButton();
169 tagCombo =
new javax.swing.JComboBox<TagName>();
170 tagLabel =
new javax.swing.JLabel();
175 addWindowListener(
new java.awt.event.WindowAdapter() {
176 public void windowClosing(java.awt.event.WindowEvent evt) {
182 okButton.addActionListener(
new java.awt.event.ActionListener() {
183 public void actionPerformed(java.awt.event.ActionEvent evt) {
189 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
190 public void actionPerformed(java.awt.event.ActionEvent evt) {
197 org.openide.awt.Mnemonics.setLocalizedText(tagLabel,
org.openide.util.NbBundle.getMessage(
GetTagNameAndCommentDialog.class,
"GetTagNameAndCommentDialog.tagLabel.text"));
205 newTagButton.addActionListener(
new java.awt.event.ActionListener() {
206 public void actionPerformed(java.awt.event.ActionEvent evt) {
211 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
212 getContentPane().setLayout(layout);
213 layout.setHorizontalGroup(
214 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
215 .addGroup(layout.createSequentialGroup()
217 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
218 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
220 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 165, Short.MAX_VALUE)
221 .addComponent(
okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
222 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
224 .addGroup(layout.createSequentialGroup()
225 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
227 .addComponent(tagLabel))
228 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
229 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
231 .addComponent(
tagCombo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
235 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {cancelButton, okButton});
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.BASELINE)
242 .addComponent(
tagCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
243 .addComponent(tagLabel))
244 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
245 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
247 .addComponent(
commentText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
248 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
249 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
256 getRootPane().setDefaultButton(
okButton);
262 TagName tagNameFromCombo = (TagName)
tagCombo.getSelectedItem();
268 tagNameAndComment = null;
273 tagNameAndComment = null;
279 if (newTagName != null) {
280 tagNamesSet.add(newTagName);
282 tagCombo.setSelectedItem(newTagName);
TagsManager getTagsManager()
static Case getCurrentCase()
synchronized static Logger getLogger(String name)
static TagName doDialog()