X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fgui%2FEditNodeDialog.java;h=3d46cf0c159135991ce2e4e79ca66cedf5eda736;hb=a2bc5cc3fa7c6d2324b1d9297d77eb79a237fb6e;hp=2ad2b4b2135bd22da4abfcc9c28e92973237afb5;hpb=6223be7f836ab24df6dc48dd755c9ae550b23fdf;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/gui/EditNodeDialog.java b/src/net/pterodactylus/jsite/gui/EditNodeDialog.java index 2ad2b4b..3d46cf0 100644 --- a/src/net/pterodactylus/jsite/gui/EditNodeDialog.java +++ b/src/net/pterodactylus/jsite/gui/EditNodeDialog.java @@ -25,22 +25,20 @@ 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.Action; import javax.swing.BorderFactory; import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComponent; import javax.swing.JDialog; -import javax.swing.JLabel; 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; +import net.pterodactylus.jsite.i18n.gui.I18nLabel; import net.pterodactylus.jsite.main.Version; import net.pterodactylus.util.swing.SwingUtils; @@ -50,7 +48,7 @@ import net.pterodactylus.util.swing.SwingUtils; * @author David ‘Bombe’ Roden <bombe@freenetproject.org> * @version $Id$ */ -public class EditNodeDialog extends JDialog { +public class EditNodeDialog extends JDialog implements I18nable { /** The user-given name of the node. */ private String name; @@ -61,27 +59,30 @@ public class EditNodeDialog extends JDialog { /** 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 Action okayAction; + private I18nAction okayAction; /** Action of the cancel button. */ - private Action cancelAction; + private I18nAction cancelAction; + + /** The name label. */ + private I18nLabel nameLabel; /** The name textfield. */ private JTextField nameTextField; + /** The hostname label. */ + private I18nLabel hostnameLabel; + /** The hostname textfield. */ private JTextField hostnameTextField; + /** The port label. */ + private I18nLabel portLabel; + /** The port textfield. */ private JTextField portTextField; - /** The same machine checkbox. */ - private JCheckBox sameMachineCheckBox; - /** Whether the dialog was cancelled. */ private boolean cancelled; @@ -96,6 +97,8 @@ public class EditNodeDialog extends JDialog { initActions(); initComponents(); pack(); + setSize(getWidth() * 2, getHeight()); + I18n.registerI18nable(this); SwingUtils.center(this); } @@ -164,28 +167,6 @@ public class EditNodeDialog extends JDialog { } /** - * Returns whether the node is on the same machine as jSite. - * - * @return true if the node is on the same machine as jSite, - * false otherwise - */ - public boolean isNodeOnSameMachine() { - return sameMachine; - } - - /** - * Sets whether the node is on the same machine as jSite. - * - * @param sameMachine - * true if the node is on the same machine as - * jSite, false otherwise - */ - public void setNodeOnSameMachine(boolean sameMachine) { - this.sameMachine = sameMachine; - sameMachineCheckBox.setSelected(sameMachine); - } - - /** * Returns whether the dialog was cancelled. * * @return true if the dialog was cancelled, @@ -246,41 +227,18 @@ public class EditNodeDialog extends JDialog { contentPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), BorderFactory.createEmptyBorder(12, 12, 12, 12))); nameTextField = new JTextField(); - contentPanel.add(createLabel(I18n.get("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, 1, 0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(0, 12, 0, 0), 0, 0)); + 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, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(0, 12, 0, 0), 0, 0)); hostnameTextField = new JTextField(); - contentPanel.add(createLabel(I18n.get("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, 1, 0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(12, 12, 0, 0), 0, 0)); + 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, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(12, 12, 0, 0), 0, 0)); portTextField = new JTextField(); - contentPanel.add(createLabel(I18n.get("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)); + 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, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.HORIZONTAL, new Insets(12, 12, 0, 0), 0, 0)); - sameMachineCheckBox = new JCheckBox(new I18nAction("editNodeDialog.checkbox.sameMachine") { - - 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)); - } - - /** - * Creates a label whose name and mnemonic are initialized from the given - * i18n property. - * - * @param i18nBasename - * The i18n property basename of the label - * @param labelFor - * The component this label describes - * @return The created label - */ - private JLabel createLabel(String i18nBasename, JComponent labelFor) { - JLabel label = new JLabel(I18n.get(i18nBasename + ".name")); - label.setDisplayedMnemonic(I18n.getKey(i18nBasename + ".mnemonic")); - label.setLabelFor(labelFor); - return label; + 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)); } // @@ -288,65 +246,18 @@ public class EditNodeDialog extends JDialog { // /** - * 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; } @@ -358,7 +269,6 @@ public class EditNodeDialog extends JDialog { /* should not occur, the value was checked! */ assert false: "port number is invalid though it was checked!"; } - sameMachine = sameMachineCheckBox.isSelected(); cancelled = false; setVisible(false); } @@ -371,4 +281,21 @@ public class EditNodeDialog extends JDialog { setVisible(false); } + // + // INTERFACE I18nable + // + + /** + * {@inheritDoc} + */ + public void updateI18n() { + okayAction.updateI18n(); + cancelAction.updateI18n(); + nameLabel.updateI18n(); + hostnameLabel.updateI18n(); + portLabel.updateI18n(); + setTitle(I18n.get("editNodeDialog.title") + " – jSite " + Version.getVersion()); + SwingUtils.repackCentered(this); + } + }