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.List;
29 import java.util.TreeMap;
30 import javax.swing.AbstractAction;
31 import javax.swing.ActionMap;
32 import javax.swing.DefaultListCellRenderer;
33 import javax.swing.InputMap;
34 import javax.swing.JComponent;
35 import javax.swing.JDialog;
36 import javax.swing.JList;
37 import javax.swing.KeyStroke;
38 import org.openide.util.NbBundle;
39 import org.openide.windows.WindowManager;
51 @SuppressWarnings(
"PMD.SingularField")
54 private static final long serialVersionUID = 1L;
55 private final List<TagName> tagNamesList =
new ArrayList<>();
56 private final List<TagName> standardTagNamesList =
new ArrayList<>();
65 this.tagName = tagName;
66 this.comment = comment;
88 return doDialog(WindowManager.getDefault().getMainWindow());
115 return tagNameAndComment;
121 ModalityType.APPLICATION_MODAL);
126 tagCombo.setRenderer(
new DefaultListCellRenderer() {
127 private static final long serialVersionUID = 1L;
130 public Component getListCellRendererComponent(JList<?> list, Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
132 String newValue = ((TagName) value).getDisplayName() + status;
133 return super.getListCellRendererComponent(list, newValue, index, isSelected, cellHasFocus);
137 String cancelName = NbBundle.getMessage(this.getClass(),
"GetTagNameAndCommentDialog.cancelName");
138 InputMap inputMap = getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
140 inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName);
141 ActionMap actionMap = getRootPane().getActionMap();
143 actionMap.put(cancelName,
new AbstractAction() {
144 private static final long serialVersionUID = 1L;
147 public void actionPerformed(ActionEvent e) {
162 tagNamesMap.entrySet().stream().map((entry) -> entry.getValue()).forEachOrdered((tagName) -> {
163 if (standardTagNames.contains(tagName.getDisplayName())) {
164 standardTagNamesList.add(tagName);
166 tagNamesList.add(tagName);
172 .getName()).log(Level.SEVERE,
"Failed to get tag names", ex);
174 tagNamesList.forEach((tag) -> {
175 tagCombo.addItem(tag);
178 standardTagNamesList.forEach((tag) -> {
179 tagCombo.addItem(tag);
183 this.setLocationRelativeTo(this.getOwner());
192 @SuppressWarnings(
"unchecked")
194 private
void initComponents() {
196 okButton =
new javax.swing.JButton();
197 cancelButton =
new javax.swing.JButton();
198 tagCombo =
new javax.swing.JComboBox<TagName>();
199 tagLabel =
new javax.swing.JLabel();
200 commentLabel =
new javax.swing.JLabel();
201 newTagButton =
new javax.swing.JButton();
202 jScrollPane1 =
new javax.swing.JScrollPane();
203 commentText =
new javax.swing.JTextArea();
205 addWindowListener(
new java.awt.event.WindowAdapter() {
206 public void windowClosing(java.awt.event.WindowEvent evt) {
211 org.openide.awt.Mnemonics.setLocalizedText(okButton,
org.openide.util.NbBundle.getMessage(
GetTagNameAndCommentDialog.class,
"GetTagNameAndCommentDialog.okButton.text"));
212 okButton.addActionListener(
new java.awt.event.ActionListener() {
213 public void actionPerformed(java.awt.event.ActionEvent evt) {
214 okButtonActionPerformed(evt);
218 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(
GetTagNameAndCommentDialog.class,
"GetTagNameAndCommentDialog.cancelButton.text"));
219 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
220 public void actionPerformed(java.awt.event.ActionEvent evt) {
221 cancelButtonActionPerformed(evt);
225 tagCombo.setToolTipText(
org.openide.util.NbBundle.getMessage(
GetTagNameAndCommentDialog.class,
"GetTagNameAndCommentDialog.tagCombo.toolTipText"));
227 org.openide.awt.Mnemonics.setLocalizedText(tagLabel,
org.openide.util.NbBundle.getMessage(
GetTagNameAndCommentDialog.class,
"GetTagNameAndCommentDialog.tagLabel.text"));
229 org.openide.awt.Mnemonics.setLocalizedText(commentLabel,
org.openide.util.NbBundle.getMessage(
GetTagNameAndCommentDialog.class,
"GetTagNameAndCommentDialog.commentLabel.text"));
231 org.openide.awt.Mnemonics.setLocalizedText(newTagButton,
org.openide.util.NbBundle.getMessage(
GetTagNameAndCommentDialog.class,
"GetTagNameAndCommentDialog.newTagButton.text"));
232 newTagButton.addActionListener(
new java.awt.event.ActionListener() {
233 public void actionPerformed(java.awt.event.ActionEvent evt) {
234 newTagButtonActionPerformed(evt);
238 commentText.setColumns(20);
239 commentText.setRows(5);
241 commentText.setToolTipText(
org.openide.util.NbBundle.getMessage(
GetTagNameAndCommentDialog.class,
"GetTagNameAndCommentDialog.commentText.toolTipText"));
242 jScrollPane1.setViewportView(commentText);
244 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
245 getContentPane().setLayout(layout);
246 layout.setHorizontalGroup(
247 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
248 .addGroup(layout.createSequentialGroup()
250 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
251 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
252 .addComponent(newTagButton)
253 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
254 .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
255 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
256 .addComponent(cancelButton))
257 .addGroup(layout.createSequentialGroup()
258 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
259 .addComponent(commentLabel)
260 .addComponent(tagLabel))
261 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
262 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
263 .addComponent(tagCombo, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
264 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 318, Short.MAX_VALUE))))
268 layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,
new java.awt.Component[] {cancelButton, okButton});
270 layout.setVerticalGroup(
271 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
272 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
274 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
275 .addComponent(tagCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
276 .addComponent(tagLabel))
277 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
278 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
279 .addComponent(commentLabel)
280 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE))
281 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 22, Short.MAX_VALUE)
282 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
283 .addComponent(cancelButton)
284 .addComponent(okButton)
285 .addComponent(newTagButton))
289 getRootPane().setDefaultButton(okButton);
295 TagName tagNameFromCombo = (TagName) tagCombo.getSelectedItem();
296 tagNameAndComment =
new TagNameAndComment(tagNameFromCombo, commentText.getText());
301 tagNameAndComment = null;
306 tagNameAndComment = null;
312 if (newTagName != null) {
313 tagNamesList.add(newTagName);
314 tagCombo.addItem(newTagName);
315 tagCombo.setSelectedItem(newTagName);
TagsManager getTagsManager()
synchronized static Logger getLogger(String name)
static Case getCurrentCaseThrows()
static TagName doDialog()