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.ArrayList;
26 import java.util.logging.Level;
27 import java.util.HashSet;
28 import java.util.List;
31 import java.util.TreeMap;
32 import javax.swing.AbstractAction;
33 import javax.swing.ActionMap;
34 import javax.swing.DefaultListCellRenderer;
35 import javax.swing.InputMap;
36 import javax.swing.JComponent;
37 import javax.swing.JDialog;
38 import javax.swing.JList;
39 import javax.swing.KeyStroke;
40 import org.openide.util.NbBundle;
41 import org.openide.windows.WindowManager;
53 @SuppressWarnings(
"PMD.SingularField")
56 private static final long serialVersionUID = 1L;
57 private final List<TagName> tagNamesList =
new ArrayList<>();
58 private final List<TagName> standardTagNamesList =
new ArrayList<>();
67 this.tagName = tagName;
68 this.comment = comment;
90 return doDialog(WindowManager.getDefault().getMainWindow());
114 ModalityType.APPLICATION_MODAL);
120 tagCombo.setRenderer(
new DefaultListCellRenderer() {
121 private static final long serialVersionUID = 1L;
123 public Component getListCellRendererComponent(JList<?> list, Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
125 String newValue = ((TagName) value).getDisplayName() + status;
126 return super.getListCellRendererComponent(list, newValue, index, isSelected, cellHasFocus);
130 String cancelName = NbBundle.getMessage(this.getClass(),
"GetTagNameAndCommentDialog.cancelName");
131 InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
133 inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName);
134 ActionMap actionMap = getRootPane().getActionMap();
136 actionMap.put(cancelName,
new AbstractAction() {
137 private static final long serialVersionUID = 1L;
140 public void actionPerformed(ActionEvent e) {
155 tagNamesMap.entrySet().stream().map((entry) -> entry.getValue()).forEachOrdered((tagName) -> {
156 if (standardTagNames.contains(tagName.getDisplayName())) {
157 standardTagNamesList.add(tagName);
159 tagNamesList.add(tagName);
166 .getName()).log(Level.SEVERE,
"Failed to get tag names", ex);
168 tagNamesList.forEach((tag) -> {
169 tagCombo.addItem(tag);
172 standardTagNamesList.forEach((tag) -> {
173 tagCombo.addItem(tag);
177 this.setLocationRelativeTo(this.getOwner());
186 @SuppressWarnings(
"unchecked")
188 private
void initComponents() {
190 okButton =
new javax.swing.JButton();
191 cancelButton =
new javax.swing.JButton();
192 tagCombo =
new javax.swing.JComboBox<TagName>();
193 tagLabel =
new javax.swing.JLabel();
194 commentLabel =
new javax.swing.JLabel();
195 newTagButton =
new javax.swing.JButton();
196 jScrollPane1 =
new javax.swing.JScrollPane();
197 commentText =
new javax.swing.JTextArea();
199 addWindowListener(
new java.awt.event.WindowAdapter() {
200 public void windowClosing(java.awt.event.WindowEvent evt) {
205 org.openide.awt.Mnemonics.setLocalizedText(okButton,
org.openide.util.NbBundle.getMessage(
GetTagNameAndCommentDialog.class,
"GetTagNameAndCommentDialog.okButton.text"));
206 okButton.addActionListener(
new java.awt.event.ActionListener() {
207 public void actionPerformed(java.awt.event.ActionEvent evt) {
208 okButtonActionPerformed(evt);
212 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(
GetTagNameAndCommentDialog.class,
"GetTagNameAndCommentDialog.cancelButton.text"));
213 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
214 public void actionPerformed(java.awt.event.ActionEvent evt) {
215 cancelButtonActionPerformed(evt);
219 tagCombo.setToolTipText(
org.openide.util.NbBundle.getMessage(
GetTagNameAndCommentDialog.class,
"GetTagNameAndCommentDialog.tagCombo.toolTipText"));
221 org.openide.awt.Mnemonics.setLocalizedText(tagLabel,
org.openide.util.NbBundle.getMessage(
GetTagNameAndCommentDialog.class,
"GetTagNameAndCommentDialog.tagLabel.text"));
223 org.openide.awt.Mnemonics.setLocalizedText(commentLabel,
org.openide.util.NbBundle.getMessage(
GetTagNameAndCommentDialog.class,
"GetTagNameAndCommentDialog.commentLabel.text"));
225 org.openide.awt.Mnemonics.setLocalizedText(newTagButton,
org.openide.util.NbBundle.getMessage(
GetTagNameAndCommentDialog.class,
"GetTagNameAndCommentDialog.newTagButton.text"));
226 newTagButton.addActionListener(
new java.awt.event.ActionListener() {
227 public void actionPerformed(java.awt.event.ActionEvent evt) {
228 newTagButtonActionPerformed(evt);
232 commentText.setColumns(20);
233 commentText.setRows(5);
235 commentText.setToolTipText(
org.openide.util.NbBundle.getMessage(
GetTagNameAndCommentDialog.class,
"GetTagNameAndCommentDialog.commentText.toolTipText"));
236 jScrollPane1.setViewportView(commentText);
238 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
239 getContentPane().setLayout(layout);
240 layout.setHorizontalGroup(
241 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
242 .addGroup(layout.createSequentialGroup()
244 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
245 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
246 .addComponent(newTagButton)
247 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
248 .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
249 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
250 .addComponent(cancelButton))
251 .addGroup(layout.createSequentialGroup()
252 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
253 .addComponent(commentLabel)
254 .addComponent(tagLabel))
255 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
256 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
257 .addComponent(tagCombo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
258 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 318, Short.MAX_VALUE))))
262 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {cancelButton, okButton});
264 layout.setVerticalGroup(
265 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
266 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
268 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
269 .addComponent(tagCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
270 .addComponent(tagLabel))
271 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
272 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
273 .addComponent(commentLabel)
274 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
275 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
276 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
277 .addComponent(cancelButton)
278 .addComponent(okButton)
279 .addComponent(newTagButton))
283 getRootPane().setDefaultButton(okButton);
289 TagName tagNameFromCombo = (TagName) tagCombo.getSelectedItem();
290 tagNameAndComment =
new TagNameAndComment(tagNameFromCombo, commentText.getText());
295 tagNameAndComment = null;
300 tagNameAndComment = null;
306 if (newTagName != null) {
307 tagNamesList.add(newTagName);
308 tagCombo.addItem(newTagName);
309 tagCombo.setSelectedItem(newTagName);
TagsManager getTagsManager()
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
static TagName doDialog()