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;
32 final class NewTagNameDialog
extends javax.swing.JDialog {
34 private static final long serialVersionUID = 1L;
35 private String userTagDisplayName;
36 private BUTTON_PRESSED result;
46 super(
new JFrame(NbBundle.getMessage(NewTagNameDialog.class,
"NewTagNameDialog.title.text")),
47 NbBundle.getMessage(NewTagNameDialog.class,
"NewTagNameDialog.title.text"),
true);
55 private void display() {
56 setLayout(
new BorderLayout());
61 Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
62 int width = this.getSize().width;
63 int height = this.getSize().height;
64 setLocation((screenDimension.width - width) / 2, (screenDimension.height - height) / 2);
69 this.addWindowListener(
new WindowAdapter() {
71 public void windowClosing(WindowEvent e) {
72 doButtonAction(
false);
79 tagNameTextField.getDocument().addDocumentListener(
new DocumentListener() {
81 public void changedUpdate(DocumentEvent e) {
85 public void removeUpdate(DocumentEvent e) {
89 public void insertUpdate(DocumentEvent e) {
110 private void doButtonAction(
boolean okPressed) {
112 String newTagDisplayName = tagNameTextField.getText().trim();
113 if (newTagDisplayName.isEmpty()) {
114 JOptionPane.showMessageDialog(null,
115 NbBundle.getMessage(NewTagNameDialog.class,
"NewTagNameDialog.JOptionPane.tagNameEmpty.message"),
116 NbBundle.getMessage(NewTagNameDialog.class,
"NewTagNameDialog.JOptionPane.tagNameEmpty.title"),
117 JOptionPane.ERROR_MESSAGE);
120 if (TagsManager.containsIllegalCharacters(newTagDisplayName)) {
121 JOptionPane.showMessageDialog(null,
122 NbBundle.getMessage(NewTagNameDialog.class,
"NewTagNameDialog.JOptionPane.tagNameIllegalCharacters.message"),
123 NbBundle.getMessage(NewTagNameDialog.class,
"NewTagNameDialog.JOptionPane.tagNameIllegalCharacters.title"),
124 JOptionPane.ERROR_MESSAGE);
127 userTagDisplayName = newTagDisplayName;
128 result = BUTTON_PRESSED.OK;
130 result = BUTTON_PRESSED.CANCEL;
140 String getTagName() {
141 return userTagDisplayName;
149 BUTTON_PRESSED getResult() {
158 private void enableOkButton() {
159 okButton.setEnabled(!tagNameTextField.getText().isEmpty());
160 getRootPane().setDefaultButton(okButton);
168 @SuppressWarnings(
"unchecked")
170 private
void initComponents() {
172 newTagNameLabel =
new javax.swing.JLabel();
173 tagNameTextField =
new javax.swing.JTextField();
174 cancelButton =
new javax.swing.JButton();
175 okButton =
new javax.swing.JButton();
177 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
179 org.openide.awt.Mnemonics.setLocalizedText(newTagNameLabel,
org.openide.util.NbBundle.getMessage(NewTagNameDialog.class,
"NewTagNameDialog.newTagNameLabel.text"));
181 tagNameTextField.setText(
org.openide.util.NbBundle.getMessage(NewTagNameDialog.class,
"NewTagNameDialog.tagNameTextField.text"));
183 org.openide.awt.Mnemonics.setLocalizedText(cancelButton,
org.openide.util.NbBundle.getMessage(NewTagNameDialog.class,
"NewTagNameDialog.cancelButton.text"));
184 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
185 public void actionPerformed(java.awt.event.ActionEvent evt) {
186 cancelButtonActionPerformed(evt);
190 org.openide.awt.Mnemonics.setLocalizedText(okButton,
org.openide.util.NbBundle.getMessage(NewTagNameDialog.class,
"NewTagNameDialog.okButton.text"));
191 okButton.addActionListener(
new java.awt.event.ActionListener() {
192 public void actionPerformed(java.awt.event.ActionEvent evt) {
193 okButtonActionPerformed(evt);
197 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
198 getContentPane().setLayout(layout);
199 layout.setHorizontalGroup(
200 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
201 .addGroup(layout.createSequentialGroup()
203 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
204 .addComponent(tagNameTextField, javax.swing.GroupLayout.DEFAULT_SIZE, 220, Short.MAX_VALUE)
205 .addGroup(layout.createSequentialGroup()
206 .addGap(0, 0, Short.MAX_VALUE)
207 .addComponent(okButton)
208 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
209 .addComponent(cancelButton))
210 .addComponent(newTagNameLabel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
213 layout.setVerticalGroup(
214 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
215 .addGroup(layout.createSequentialGroup()
217 .addComponent(newTagNameLabel)
218 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
219 .addComponent(tagNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
220 .addContainerGap(50, Short.MAX_VALUE))
221 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
222 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
223 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
224 .addComponent(cancelButton)
225 .addComponent(okButton))
232 private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
233 doButtonAction(
true);
236 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
237 doButtonAction(
false);
242 private javax.swing.JButton cancelButton;
243 private javax.swing.JLabel newTagNameLabel;
244 private javax.swing.JButton okButton;
245 private javax.swing.JTextField tagNameTextField;