X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fgui%2FEditNodeDialog.java;h=3f0694de9a73593972f4ce3ebde01268968b3245;hb=cf6712386e8d0dbd16bd13e4f11430ebefe04b35;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..3f0694d 100644 --- a/src/net/pterodactylus/jsite/gui/EditNodeDialog.java +++ b/src/net/pterodactylus/jsite/gui/EditNodeDialog.java @@ -28,29 +28,29 @@ 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.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; /** * 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 { +public class EditNodeDialog extends JDialog implements I18nable { /** The user-given name of the node. */ private String name; @@ -65,29 +65,41 @@ public class EditNodeDialog extends JDialog { 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; + /** The same machine action. */ + private I18nAction sameMachineAction; + /** 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 */ @@ -96,6 +108,7 @@ public class EditNodeDialog extends JDialog { initActions(); initComponents(); pack(); + I18n.registerI18nable(this); SwingUtils.center(this); } @@ -105,7 +118,7 @@ public class EditNodeDialog extends JDialog { /** * Returns the user-given name of the node. - * + * * @return The user-given name of the node */ public String getNodeName() { @@ -114,7 +127,7 @@ public class EditNodeDialog extends JDialog { /** * Sets the user-given name of the node. - * + * * @param name * The name of the node */ @@ -125,7 +138,7 @@ public class EditNodeDialog extends JDialog { /** * Returns the hostname of the node. - * + * * @return The hostname of the node */ public String getNodeHostname() { @@ -134,7 +147,7 @@ public class EditNodeDialog extends JDialog { /** * Sets the hostname of the node. - * + * * @param hostname * The hostname of the node */ @@ -145,7 +158,7 @@ public class EditNodeDialog extends JDialog { /** * Returns the FCP port number of the node. - * + * * @return The FCP port number of the node */ public int getNodePort() { @@ -154,7 +167,7 @@ public class EditNodeDialog extends JDialog { /** * Sets the FCP port number of the node. - * + * * @param port * The FCP port number of the node */ @@ -165,7 +178,7 @@ 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 */ @@ -175,7 +188,7 @@ public class EditNodeDialog extends JDialog { /** * 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 @@ -187,7 +200,7 @@ public class EditNodeDialog extends JDialog { /** * Returns whether the dialog was cancelled. - * + * * @return true if the dialog was cancelled, * false if the user clicked “okay” */ @@ -223,6 +236,12 @@ public class EditNodeDialog extends JDialog { cancel(); } }; + sameMachineAction = new I18nAction("editNodeDialog.checkbox.sameMachine") { + + public void actionPerformed(ActionEvent e) { + /* don't do anything. */ + } + }; } /** @@ -246,41 +265,21 @@ 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)); - - sameMachineCheckBox = new JCheckBox(new I18nAction("editNodeDialog.checkbox.sameMachine") { + 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)); - 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)); - } + sameMachineCheckBox = new JCheckBox(sameMachineAction); + contentPanel.add(sameMachineCheckBox, new GridBagConstraints(0, 3, 2, 1, 1.0, 0.0, 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, 4, 2, 1, 1.0, 1.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); } // @@ -289,7 +288,7 @@ 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 */ @@ -299,7 +298,7 @@ public class EditNodeDialog extends JDialog { /** * Verifies the hostname textfield by resolving the given name. - * + * * @return true if the hostname is not empty and can be * resolved, false otherwise */ @@ -318,7 +317,7 @@ public class EditNodeDialog extends JDialog { /** * 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 */ @@ -371,4 +370,22 @@ public class EditNodeDialog extends JDialog { setVisible(false); } + // + // INTERFACE I18nable + // + + /** + * {@inheritDoc} + */ + public void updateI18n() { + okayAction.updateI18n(); + cancelAction.updateI18n(); + nameLabel.updateI18n(); + hostnameLabel.updateI18n(); + portLabel.updateI18n(); + sameMachineAction.updateI18n(); + setTitle(I18n.get("editNodeDialog.title") + " – jSite " + Version.getVersion()); + SwingUtils.repackCentered(this); + } + }