remove Id keyword
[jSite2.git] / src / net / pterodactylus / jsite / gui / EditNodeDialog.java
index a8597ef..5eecc98 100644 (file)
@@ -25,18 +25,17 @@ import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
 import java.awt.Insets;
 import java.awt.event.ActionEvent;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
 
 import javax.swing.BorderFactory;
 import javax.swing.JButton;
-import javax.swing.JCheckBox;
 import javax.swing.JDialog;
+import javax.swing.JFrame;
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JTextField;
 import javax.swing.border.EtchedBorder;
 
+import net.pterodactylus.jsite.core.Verifier;
 import net.pterodactylus.jsite.i18n.I18n;
 import net.pterodactylus.jsite.i18n.I18nable;
 import net.pterodactylus.jsite.i18n.gui.I18nAction;
@@ -48,7 +47,6 @@ import net.pterodactylus.util.swing.SwingUtils;
  * Dialog that lets the user edit the properties of a node.
  * 
  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- * @version $Id$
  */
 public class EditNodeDialog extends JDialog implements I18nable {
 
@@ -61,9 +59,6 @@ public class EditNodeDialog extends JDialog implements I18nable {
        /** The FNP port number of the node. */
        private int port;
 
-       /** Whether the node is on the same machine. */
-       private boolean sameMachine;
-
        /** Action of the okay button. */
        private I18nAction okayAction;
 
@@ -88,23 +83,21 @@ public class EditNodeDialog extends JDialog implements I18nable {
        /** The port textfield. */
        private JTextField portTextField;
 
-       /** The same machine checkbox. */
-       private JCheckBox sameMachineCheckBox;
-
        /** Whether the dialog was cancelled. */
        private boolean cancelled;
 
        /**
         * Creates a new node edit dialog with the given parent.
         * 
-        * @param parentDialog
-        *            The parent dialog of this dialog
+        * @param parentFrame
+        *            The parent frame of this dialog
         */
-       public EditNodeDialog(JDialog parentDialog) {
-               super(parentDialog, I18n.get("editNodeDialog.title") + " – jSite " + Version.getVersion(), true);
+       public EditNodeDialog(JFrame parentFrame) {
+               super(parentFrame, I18n.get("editNodeDialog.title") + " – jSite " + Version.getVersion(), true);
                initActions();
                initComponents();
                pack();
+               setSize(getWidth() * 2, getHeight());
                I18n.registerI18nable(this);
                SwingUtils.center(this);
        }
@@ -174,28 +167,6 @@ public class EditNodeDialog extends JDialog implements I18nable {
        }
 
        /**
-        * Returns whether the node is on the same machine as jSite.
-        * 
-        * @return <code>true</code> if the node is on the same machine as jSite,
-        *         <code>false</code> otherwise
-        */
-       public boolean isNodeOnSameMachine() {
-               return sameMachine;
-       }
-
-       /**
-        * Sets whether the node is on the same machine as jSite.
-        * 
-        * @param sameMachine
-        *            <code>true</code> if the node is on the same machine as
-        *            jSite, <code>false</code> otherwise
-        */
-       public void setNodeOnSameMachine(boolean sameMachine) {
-               this.sameMachine = sameMachine;
-               sameMachineCheckBox.setSelected(sameMachine);
-       }
-
-       /**
         * Returns whether the dialog was cancelled.
         * 
         * @return <code>true</code> if the dialog was cancelled,
@@ -257,23 +228,17 @@ public class EditNodeDialog extends JDialog implements I18nable {
 
                nameTextField = new JTextField();
                contentPanel.add(nameLabel = new I18nLabel("editNodeDialog.label.name", nameTextField), new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.LINE_END, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
-               contentPanel.add(nameTextField, new GridBagConstraints(1, 0, 1, 1, 10, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(0, 12, 0, 0), 0, 0));
+               contentPanel.add(nameTextField, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(0, 12, 0, 0), 0, 0));
 
                hostnameTextField = new JTextField();
                contentPanel.add(hostnameLabel = new I18nLabel("editNodeDialog.label.hostname", hostnameTextField), new GridBagConstraints(0, 1, 1, 1, 0, 0, GridBagConstraints.LINE_END, GridBagConstraints.NONE, new Insets(12, 0, 0, 0), 0, 0));
-               contentPanel.add(hostnameTextField, new GridBagConstraints(1, 1, 1, 1, 10, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(12, 12, 0, 0), 0, 0));
+               contentPanel.add(hostnameTextField, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(12, 12, 0, 0), 0, 0));
 
                portTextField = new JTextField();
                contentPanel.add(portLabel = new I18nLabel("editNodeDialog.label.port", portTextField), new GridBagConstraints(0, 2, 1, 1, 0, 0, GridBagConstraints.LINE_END, GridBagConstraints.NONE, new Insets(12, 0, 0, 0), 0, 0));
-               contentPanel.add(portTextField, new GridBagConstraints(1, 2, 1, 1, 1, 0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(12, 12, 0, 0), 0, 0));
-
-               sameMachineCheckBox = new JCheckBox(new I18nAction("editNodeDialog.checkbox.sameMachine") {
+               contentPanel.add(portTextField, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(12, 12, 0, 0), 0, 0));
 
-                       public void actionPerformed(ActionEvent e) {
-                               /* don't do anything. */
-                       }
-               });
-               contentPanel.add(sameMachineCheckBox, new GridBagConstraints(0, 3, 2, 1, 1, 1, GridBagConstraints.LINE_START, GridBagConstraints.NONE, new Insets(12, 0, 0, 0), 0, 0));
+               contentPanel.add(new JPanel(), new GridBagConstraints(0, 3, 2, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
        }
 
        //
@@ -281,65 +246,18 @@ public class EditNodeDialog extends JDialog implements I18nable {
        //
 
        /**
-        * Checks the name textfield for valid input.
-        * 
-        * @return <code>true</code> if the name textfield seem okay,
-        *         <code>false</code> if there is an error
-        */
-       private boolean verifyName() {
-               return (nameTextField.getText().trim().length() != 0);
-       }
-
-       /**
-        * Verifies the hostname textfield by resolving the given name.
-        * 
-        * @return <code>true</code> if the hostname is not empty and can be
-        *         resolved, <code>false</code> otherwise
-        */
-       private boolean verifyHostname() {
-               if (hostnameTextField.getText().trim().length() == 0) {
-                       return false;
-               }
-               try {
-                       InetAddress.getByName(hostnameTextField.getText().trim());
-                       return true;
-               } catch (UnknownHostException uhe1) {
-                       return false;
-               }
-       }
-
-       /**
-        * Verifies that the port number is numeric and in the range from
-        * <code>0</code> to <code>65535</code>.
-        * 
-        * @return <code>true</code> if the port number is okay,
-        *         <code>false</code> otherwise
-        */
-       private boolean verifyPort() {
-               try {
-                       int portNumber = Integer.valueOf(portTextField.getText().trim());
-                       if ((portNumber > 0) && (portNumber < 65536)) {
-                               return true;
-                       }
-               } catch (NumberFormatException nfe1) {
-                       /* ignore. */
-               }
-               return false;
-       }
-
-       /**
         * Confirms the node settings and closes the dialog.
         */
        private void confirm() {
-               if (!verifyName()) {
+               if (!Verifier.verifyNodeName(nameTextField.getText())) {
                        JOptionPane.showMessageDialog(this, I18n.get("editNodeDialog.error.name.message"), I18n.get("editNodeDialog.error.name.title"), JOptionPane.ERROR_MESSAGE);
                        return;
                }
-               if (!verifyHostname()) {
+               if (!Verifier.verifyHostname(hostnameTextField.getText())) {
                        JOptionPane.showMessageDialog(this, I18n.get("editNodeDialog.error.hostname.message"), I18n.get("editNodeDialog.error.hostname.title"), JOptionPane.ERROR_MESSAGE);
                        return;
                }
-               if (!verifyPort()) {
+               if (!Verifier.verifyPort(portTextField.getText())) {
                        JOptionPane.showMessageDialog(this, I18n.get("editNodeDialog.error.port.message"), I18n.get("editNodeDialog.error.port.title"), JOptionPane.ERROR_MESSAGE);
                        return;
                }
@@ -351,7 +269,6 @@ public class EditNodeDialog extends JDialog implements I18nable {
                        /* should not occur, the value was checked! */
                        assert false: "port number is invalid though it was checked!";
                }
-               sameMachine = sameMachineCheckBox.isSelected();
                cancelled = false;
                setVisible(false);
        }