19 package org.sleuthkit.autopsy.casemodule.services;
21 import java.awt.BorderLayout;
22 import java.awt.Dimension;
23 import java.awt.Toolkit;
24 import java.awt.event.WindowAdapter;
25 import java.awt.event.WindowEvent;
26 import javax.swing.JFrame;
27 import javax.swing.JOptionPane;
28 import javax.swing.event.DocumentEvent;
29 import javax.swing.event.DocumentListener;
30 import org.openide.util.NbBundle;
31 import org.openide.util.NbBundle.Messages;
32 import org.openide.windows.WindowManager;
35 @Messages({
"TagNameDialog.descriptionLabel.text=Description:",
36 "TagNameDialog.notableCheckbox.text=Tag indicates item is notable."})
37 final class TagNameDialog extends javax.swing.JDialog {
39 private static final long serialVersionUID = 1L;
40 private String userTagDisplayName;
41 private String userTagDescription;
42 private boolean userTagIsNotable;
43 private BUTTON_PRESSED result;
53 super(
new JFrame(NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.title.text")),
54 NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.title.text"),
true);
59 @Messages({
"TagNameDialog.editTitle.text=Edit Tag"})
60 TagNameDialog(TagNameDefinition tagNameToEdit) {
61 super(
new JFrame(NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.editTitle.text")),
62 NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.editTitle.text"),
true);
64 tagNameTextField.setText(tagNameToEdit.getDisplayName());
65 descriptionTextArea.setText(tagNameToEdit.getDescription());
66 notableCheckbox.setSelected(tagNameToEdit.getKnownStatus() == TskData.FileKnown.BAD);
67 tagNameTextField.setEnabled(
false);
74 private void display() {
75 setLayout(
new BorderLayout());
80 setLocationRelativeTo(WindowManager.getDefault().getMainWindow());
85 this.addWindowListener(
new WindowAdapter() {
87 public void windowClosing(WindowEvent e) {
88 doButtonAction(
false);
95 tagNameTextField.getDocument().addDocumentListener(
new DocumentListener() {
97 public void changedUpdate(DocumentEvent e) {
102 public void removeUpdate(DocumentEvent e) {
107 public void insertUpdate(DocumentEvent e) {
111 private void fire() {
130 @Messages({
"TagNameDialog.JOptionPane.tagDescriptionIllegalCharacters.message=Tag descriptions may not contain commas (,) or semicolons (;)",
131 "TagNameDialog.JOptionPane.tagDescriptionIllegalCharacters.title=Invalid character in tag description"})
132 private void doButtonAction(
boolean okPressed) {
134 String newTagDisplayName = tagNameTextField.getText().trim();
135 String descriptionText = descriptionTextArea.getText();
136 if (newTagDisplayName.isEmpty()) {
137 JOptionPane.showMessageDialog(
this,
138 NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.JOptionPane.tagNameEmpty.message"),
139 NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.JOptionPane.tagNameEmpty.title"),
140 JOptionPane.ERROR_MESSAGE);
144 if (TagsManager.containsIllegalCharacters(newTagDisplayName) && !TagNameDefinition.getStandardTagNames().contains(newTagDisplayName)) {
145 JOptionPane.showMessageDialog(
this,
146 NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.JOptionPane.tagDescriptionIllegalCharacters.message"),
147 NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.JOptionPane.tagDescriptionIllegalCharacters.title"),
148 JOptionPane.ERROR_MESSAGE);
150 }
else if (descriptionText.contains(
",")
151 || descriptionText.contains(
";")) {
152 JOptionPane.showMessageDialog(
this,
153 NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.JOptionPane.tagDescriptionIllegalCharacters.message"),
154 NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.JOptionPane.tagDescriptionIllegalCharacters.title"),
155 JOptionPane.ERROR_MESSAGE);
159 userTagDescription = descriptionTextArea.getText();
160 userTagDisplayName = newTagDisplayName;
161 userTagIsNotable = notableCheckbox.isSelected();
162 result = BUTTON_PRESSED.OK;
164 result = BUTTON_PRESSED.CANCEL;
174 String getTagName() {
175 return userTagDisplayName;
178 String getTagDesciption() {
179 return userTagDescription;
182 boolean isTagNotable() {
183 return userTagIsNotable;
191 BUTTON_PRESSED getResult() {
200 private void enableOkButton() {
201 okButton.setEnabled(!tagNameTextField.getText().isEmpty());
202 getRootPane().setDefaultButton(okButton);
210 @SuppressWarnings(
"unchecked")
212 private
void initComponents() {
214 newTagNameLabel =
new javax.swing.JLabel();
215 tagNameTextField =
new javax.swing.JTextField();
216 cancelButton =
new javax.swing.JButton();
217 okButton =
new javax.swing.JButton();
218 descriptionScrollPane =
new javax.swing.JScrollPane();
219 descriptionTextArea =
new javax.swing.JTextArea();
220 descriptionLabel =
new javax.swing.JLabel();
221 notableCheckbox =
new javax.swing.JCheckBox();
223 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
225 org.openide.awt.Mnemonics.setLocalizedText(newTagNameLabel,
org.openide.util.NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.newTagNameLabel.text"));
227 tagNameTextField.setText(
org.openide.util.NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.tagNameTextField.text"));
229 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.cancelButton.text"));
230 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
231 public void actionPerformed(java.awt.event.ActionEvent evt) {
232 cancelButtonActionPerformed(evt);
236 org.openide.awt.Mnemonics.setLocalizedText(okButton,
org.openide.util.NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.okButton.text"));
237 okButton.addActionListener(
new java.awt.event.ActionListener() {
238 public void actionPerformed(java.awt.event.ActionEvent evt) {
239 okButtonActionPerformed(evt);
243 descriptionTextArea.setColumns(20);
244 descriptionTextArea.setFont(
new java.awt.Font(
"Tahoma", 0, 11));
245 descriptionTextArea.setRows(3);
246 descriptionScrollPane.setViewportView(descriptionTextArea);
248 org.openide.awt.Mnemonics.setLocalizedText(descriptionLabel,
org.openide.util.NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.descriptionLabel.text"));
250 org.openide.awt.Mnemonics.setLocalizedText(notableCheckbox,
org.openide.util.NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.notableCheckbox.text"));
252 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
253 getContentPane().setLayout(layout);
254 layout.setHorizontalGroup(
255 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
256 .addGroup(layout.createSequentialGroup()
258 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
259 .addComponent(tagNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 284, Short.MAX_VALUE)
260 .addGroup(layout.createSequentialGroup()
261 .addGap(0, 0, Short.MAX_VALUE)
262 .addComponent(okButton)
263 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
264 .addComponent(cancelButton))
265 .addComponent(newTagNameLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
266 .addComponent(descriptionScrollPane, javax.swing.GroupLayout.Alignment.TRAILING)
267 .addGroup(layout.createSequentialGroup()
268 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
269 .addComponent(notableCheckbox)
270 .addComponent(descriptionLabel))
271 .addGap(0, 0, Short.MAX_VALUE)))
274 layout.setVerticalGroup(
275 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
276 .addGroup(layout.createSequentialGroup()
278 .addComponent(newTagNameLabel)
279 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
280 .addComponent(tagNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
281 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
282 .addComponent(descriptionLabel)
283 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
284 .addComponent(descriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
285 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
286 .addComponent(notableCheckbox)
287 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 42, Short.MAX_VALUE)
288 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
289 .addComponent(cancelButton)
290 .addComponent(okButton)))
296 private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
297 doButtonAction(
true);
300 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
301 doButtonAction(
false);
306 private javax.swing.JButton cancelButton;
307 private javax.swing.JLabel descriptionLabel;
308 private javax.swing.JScrollPane descriptionScrollPane;
309 private javax.swing.JTextArea descriptionTextArea;
310 private javax.swing.JLabel newTagNameLabel;
311 private javax.swing.JCheckBox notableCheckbox;
312 private javax.swing.JButton okButton;
313 private javax.swing.JTextField tagNameTextField;