19 package org.sleuthkit.autopsy.datamodel.hosts;
21 import java.awt.Color;
23 import java.util.Collection;
25 import javax.swing.event.DocumentEvent;
26 import javax.swing.event.DocumentListener;
27 import org.openide.util.NbBundle.Messages;
33 class AddEditHostDialog
extends javax.swing.JDialog {
35 private static final long serialVersionUID = 1L;
37 private boolean changed =
false;
40 private final Set<String> hostNamesSanitized;
41 private final Host initialHost;
49 AddEditHostDialog(java.awt.Frame parent, Collection<Host> currentHosts) {
50 this(parent, currentHosts, null);
63 "AddEditHostDialog_addHost_title=Add Host",
64 "AddEditHostDialog_editHost_title=Edit Host"
66 AddEditHostDialog(java.awt.Frame parent, Collection<Host> currentHosts, Host initialHost) {
68 this.initialHost = initialHost;
69 setTitle(initialHost == null ? Bundle.AddEditHostDialog_addHost_title() : Bundle.AddEditHostDialog_editHost_title());
74 onNameUpdate(initialHost == null ? null : initialHost.getName());
78 validationLabel.setText(
"");
80 inputTextField.getDocument().addDocumentListener(
new DocumentListener() {
82 public void changedUpdate(DocumentEvent e) {
83 onNameUpdate(inputTextField.getText());
87 public void removeUpdate(DocumentEvent e) {
88 onNameUpdate(inputTextField.getText());
92 public void insertUpdate(DocumentEvent e) {
93 onNameUpdate(inputTextField.getText());
103 return inputTextField.getText();
110 boolean isChanged() {
119 private void onNameUpdate(String newNameValue) {
120 String newNameValueOrEmpty = newNameValue == null ?
"" : newNameValue;
122 if (!newNameValueOrEmpty.equals(
this.inputTextField.getText())) {
123 inputTextField.setText(newNameValue);
129 newNameValue, initialHost == null ? null : initialHost.getName(), hostNamesSanitized);
131 okButton.setEnabled(validationMessage == null);
132 validationLabel.setText(validationMessage == null ?
"" : validationMessage);
140 @SuppressWarnings(
"unchecked")
142 private void initComponents() {
144 inputTextField =
new javax.swing.JTextField();
145 javax.swing.JLabel nameLabel =
new javax.swing.JLabel();
146 validationLabel =
new javax.swing.JLabel();
147 okButton =
new javax.swing.JButton();
148 javax.swing.JButton cancelButton =
new javax.swing.JButton();
150 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
152 inputTextField.setText(
org.openide.util.NbBundle.getMessage(AddEditHostDialog.class,
"AddEditHostDialog.inputTextField.text"));
154 nameLabel.setText(
org.openide.util.NbBundle.getMessage(AddEditHostDialog.class,
"AddEditHostDialog.nameLabel.text"));
156 validationLabel.setForeground(Color.RED);
157 validationLabel.setVerticalAlignment(javax.swing.SwingConstants.TOP);
159 okButton.setText(
org.openide.util.NbBundle.getMessage(AddEditHostDialog.class,
"AddEditHostDialog.okButton.text"));
160 okButton.addActionListener(
new java.awt.event.ActionListener() {
161 public void actionPerformed(java.awt.event.ActionEvent evt) {
162 okButtonActionPerformed(evt);
166 cancelButton.setText(
org.openide.util.NbBundle.getMessage(AddEditHostDialog.class,
"AddEditHostDialog.cancelButton.text"));
167 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
168 public void actionPerformed(java.awt.event.ActionEvent evt) {
169 cancelButtonActionPerformed(evt);
173 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
174 getContentPane().setLayout(layout);
175 layout.setHorizontalGroup(
176 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
177 .addGroup(layout.createSequentialGroup()
179 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
180 .addComponent(validationLabel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
181 .addComponent(inputTextField)
182 .addGroup(layout.createSequentialGroup()
183 .addComponent(nameLabel)
184 .addGap(0, 0, Short.MAX_VALUE))
185 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
186 .addGap(0, 288, Short.MAX_VALUE)
187 .addComponent(okButton)
188 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
189 .addComponent(cancelButton)))
192 layout.setVerticalGroup(
193 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
194 .addGroup(layout.createSequentialGroup()
196 .addComponent(nameLabel)
197 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
198 .addComponent(inputTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
199 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
200 .addComponent(validationLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
201 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
202 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
203 .addComponent(cancelButton)
204 .addComponent(okButton))
205 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
211 private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {
217 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
218 this.changed =
false;
224 private javax.swing.JTextField inputTextField;
225 private javax.swing.JButton okButton;
226 private javax.swing.JLabel validationLabel;
static String getValidationMessage(String curName, String initialName, Set< String > currentHostsTrimmedUpper)
static Set< String > getSanitizedHostNames(Collection< Host > hosts)