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;
34 @Messages({
"TagNameDialog.descriptionLabel.text=Description:",
35 "TagNameDialog.notableCheckbox.text=Tag indicates item is notable."})
36 final class TagNameDialog extends javax.swing.JDialog {
38 private static final long serialVersionUID = 1L;
39 private String userTagDisplayName;
40 private String userTagDescription;
41 private boolean userTagIsNotable;
42 private BUTTON_PRESSED result;
52 super(
new JFrame(NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.title.text")),
53 NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.title.text"),
true);
58 @Messages({
"TagNameDialog.editTitle.text=Edit Tag"})
59 TagNameDialog(TagNameDefinition tagNameToEdit) {
60 super(
new JFrame(NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.editTitle.text")),
61 NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.editTitle.text"),
true);
63 tagNameTextField.setText(tagNameToEdit.getDisplayName());
64 descriptionTextArea.setText(tagNameToEdit.getDescription());
65 notableCheckbox.setSelected(tagNameToEdit.getKnownStatus() == TskData.FileKnown.BAD);
66 tagNameTextField.setEnabled(
false);
73 private void display() {
74 setLayout(
new BorderLayout());
79 Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
80 int width = this.getSize().width;
81 int height = this.getSize().height;
82 setLocation((screenDimension.width - width) / 2, (screenDimension.height - height) / 2);
87 this.addWindowListener(
new WindowAdapter() {
89 public void windowClosing(WindowEvent e) {
90 doButtonAction(
false);
97 tagNameTextField.getDocument().addDocumentListener(
new DocumentListener() {
99 public void changedUpdate(DocumentEvent e) {
104 public void removeUpdate(DocumentEvent e) {
109 public void insertUpdate(DocumentEvent e) {
113 private void fire() {
132 @Messages({
"TagNameDialog.JOptionPane.tagDescriptionIllegalCharacters.message=Tag descriptions may not contain commas (,) or semicolons (;)",
133 "TagNameDialog.JOptionPane.tagDescriptionIllegalCharacters.title=Invalid character in tag description"})
134 private void doButtonAction(
boolean okPressed) {
136 String newTagDisplayName = tagNameTextField.getText().trim();
137 String descriptionText = descriptionTextArea.getText();
138 if (newTagDisplayName.isEmpty()) {
139 JOptionPane.showMessageDialog(null,
140 NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.JOptionPane.tagNameEmpty.message"),
141 NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.JOptionPane.tagNameEmpty.title"),
142 JOptionPane.ERROR_MESSAGE);
146 if (TagsManager.containsIllegalCharacters(newTagDisplayName) && !TagNameDefinition.getStandardTagNames().contains(newTagDisplayName)) {
147 JOptionPane.showMessageDialog(null,
148 NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.JOptionPane.tagDescriptionIllegalCharacters.message"),
149 NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.JOptionPane.tagDescriptionIllegalCharacters.title"),
150 JOptionPane.ERROR_MESSAGE);
152 }
else if (descriptionText.contains(
",")
153 || descriptionText.contains(
";")) {
154 JOptionPane.showMessageDialog(null,
155 NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.JOptionPane.tagDescriptionIllegalCharacters.message"),
156 NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.JOptionPane.tagDescriptionIllegalCharacters.title"),
157 JOptionPane.ERROR_MESSAGE);
161 userTagDescription = descriptionTextArea.getText();
162 userTagDisplayName = newTagDisplayName;
163 userTagIsNotable = notableCheckbox.isSelected();
164 result = BUTTON_PRESSED.OK;
166 result = BUTTON_PRESSED.CANCEL;
176 String getTagName() {
177 return userTagDisplayName;
180 String getTagDesciption() {
181 return userTagDescription;
184 boolean isTagNotable() {
185 return userTagIsNotable;
193 BUTTON_PRESSED getResult() {
202 private void enableOkButton() {
203 okButton.setEnabled(!tagNameTextField.getText().isEmpty());
204 getRootPane().setDefaultButton(okButton);
212 @SuppressWarnings(
"unchecked")
214 private
void initComponents() {
216 newTagNameLabel =
new javax.swing.JLabel();
217 tagNameTextField =
new javax.swing.JTextField();
218 cancelButton =
new javax.swing.JButton();
219 okButton =
new javax.swing.JButton();
220 descriptionScrollPane =
new javax.swing.JScrollPane();
221 descriptionTextArea =
new javax.swing.JTextArea();
222 descriptionLabel =
new javax.swing.JLabel();
223 notableCheckbox =
new javax.swing.JCheckBox();
225 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
227 org.openide.awt.Mnemonics.setLocalizedText(newTagNameLabel,
org.openide.util.NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.newTagNameLabel.text"));
229 tagNameTextField.setText(
org.openide.util.NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.tagNameTextField.text"));
231 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.cancelButton.text"));
232 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
233 public void actionPerformed(java.awt.event.ActionEvent evt) {
234 cancelButtonActionPerformed(evt);
238 org.openide.awt.Mnemonics.setLocalizedText(okButton,
org.openide.util.NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.okButton.text"));
239 okButton.addActionListener(
new java.awt.event.ActionListener() {
240 public void actionPerformed(java.awt.event.ActionEvent evt) {
241 okButtonActionPerformed(evt);
245 descriptionTextArea.setColumns(20);
246 descriptionTextArea.setFont(
new java.awt.Font(
"Tahoma", 0, 11));
247 descriptionTextArea.setRows(3);
248 descriptionScrollPane.setViewportView(descriptionTextArea);
250 org.openide.awt.Mnemonics.setLocalizedText(descriptionLabel,
org.openide.util.NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.descriptionLabel.text"));
252 org.openide.awt.Mnemonics.setLocalizedText(notableCheckbox,
org.openide.util.NbBundle.getMessage(TagNameDialog.class,
"TagNameDialog.notableCheckbox.text"));
254 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
255 getContentPane().setLayout(layout);
256 layout.setHorizontalGroup(
257 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
258 .addGroup(layout.createSequentialGroup()
260 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
261 .addComponent(tagNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 284, Short.MAX_VALUE)
262 .addGroup(layout.createSequentialGroup()
263 .addGap(0, 0, Short.MAX_VALUE)
264 .addComponent(okButton)
265 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
266 .addComponent(cancelButton))
267 .addComponent(newTagNameLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
268 .addComponent(descriptionScrollPane, javax.swing.GroupLayout.Alignment.TRAILING)
269 .addGroup(layout.createSequentialGroup()
270 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
271 .addComponent(notableCheckbox)
272 .addComponent(descriptionLabel))
273 .addGap(0, 0, Short.MAX_VALUE)))
276 layout.setVerticalGroup(
277 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
278 .addGroup(layout.createSequentialGroup()
280 .addComponent(newTagNameLabel)
281 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
282 .addComponent(tagNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
283 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
284 .addComponent(descriptionLabel)
285 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
286 .addComponent(descriptionScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 57, javax.swing.GroupLayout.PREFERRED_SIZE)
287 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
288 .addComponent(notableCheckbox)
289 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 42, Short.MAX_VALUE)
290 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
291 .addComponent(cancelButton)
292 .addComponent(okButton)))
298 private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
299 doButtonAction(
true);
302 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
303 doButtonAction(
false);
308 private javax.swing.JButton cancelButton;
309 private javax.swing.JLabel descriptionLabel;
310 private javax.swing.JScrollPane descriptionScrollPane;
311 private javax.swing.JTextArea descriptionTextArea;
312 private javax.swing.JLabel newTagNameLabel;
313 private javax.swing.JCheckBox notableCheckbox;
314 private javax.swing.JButton okButton;
315 private javax.swing.JTextField tagNameTextField;