X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fgui%2FEditNodeDialog.java;h=3d46cf0c159135991ce2e4e79ca66cedf5eda736;hb=a2bc5cc3fa7c6d2324b1d9297d77eb79a237fb6e;hp=260466ebc0bace48f80adfe9eda8940238102eca;hpb=010e39aacf7769db05545c166edb222d212a3dae;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/gui/EditNodeDialog.java b/src/net/pterodactylus/jsite/gui/EditNodeDialog.java index 260466e..3d46cf0 100644 --- a/src/net/pterodactylus/jsite/gui/EditNodeDialog.java +++ b/src/net/pterodactylus/jsite/gui/EditNodeDialog.java @@ -25,8 +25,6 @@ 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; @@ -36,6 +34,7 @@ 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; @@ -45,7 +44,7 @@ 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$ */ @@ -89,7 +88,7 @@ public class EditNodeDialog extends JDialog implements I18nable { /** * Creates a new node edit dialog with the given parent. - * + * * @param parentDialog * The parent dialog of this dialog */ @@ -98,6 +97,7 @@ public class EditNodeDialog extends JDialog implements I18nable { initActions(); initComponents(); pack(); + setSize(getWidth() * 2, getHeight()); I18n.registerI18nable(this); SwingUtils.center(this); } @@ -108,7 +108,7 @@ public class EditNodeDialog extends JDialog implements I18nable { /** * Returns the user-given name of the node. - * + * * @return The user-given name of the node */ public String getNodeName() { @@ -117,7 +117,7 @@ public class EditNodeDialog extends JDialog implements I18nable { /** * Sets the user-given name of the node. - * + * * @param name * The name of the node */ @@ -128,7 +128,7 @@ public class EditNodeDialog extends JDialog implements I18nable { /** * Returns the hostname of the node. - * + * * @return The hostname of the node */ public String getNodeHostname() { @@ -137,7 +137,7 @@ public class EditNodeDialog extends JDialog implements I18nable { /** * Sets the hostname of the node. - * + * * @param hostname * The hostname of the node */ @@ -148,7 +148,7 @@ public class EditNodeDialog extends JDialog implements I18nable { /** * Returns the FCP port number of the node. - * + * * @return The FCP port number of the node */ public int getNodePort() { @@ -157,7 +157,7 @@ public class EditNodeDialog extends JDialog implements I18nable { /** * Sets the FCP port number of the node. - * + * * @param port * The FCP port number of the node */ @@ -168,7 +168,7 @@ public class EditNodeDialog extends JDialog implements I18nable { /** * Returns whether the dialog was cancelled. - * + * * @return true if the dialog was cancelled, * false if the user clicked “okay” */ @@ -246,65 +246,18 @@ public class EditNodeDialog extends JDialog implements I18nable { // /** - * Checks the name textfield for valid input. - * - * @return true if the name textfield seem okay, - * false if there is an error - */ - private boolean verifyName() { - return (nameTextField.getText().trim().length() != 0); - } - - /** - * Verifies the hostname textfield by resolving the given name. - * - * @return true if the hostname is not empty and can be - * resolved, false 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 - * 0 to 65535. - * - * @return true if the port number is okay, - * false 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; }