From c6f70f227e759ddf9772696b6c94fc227a6d9e50 Mon Sep 17 00:00:00 2001 From: Derek DeMoro Date: Thu, 31 Aug 2006 00:26:25 +0000 Subject: [PATCH] Login settings are set. git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@5116 b35dd754-fafc-0310-a699-88a17e54d16e --- .../jivesoftware/AccountCreationWizard.java | 41 +++---- src/java/org/jivesoftware/LoginDialog.java | 13 +-- .../org/jivesoftware/LoginSettingDialog.java | 79 +++++++------- src/java/org/jivesoftware/resource/Res.java | 51 +++++++++ .../spark/ui/TranscriptWindow.java | 4 +- src/resources/i18n/spark_i18n_en.properties | 100 ++++++++++++------ 6 files changed, 187 insertions(+), 101 deletions(-) create mode 100644 src/java/org/jivesoftware/resource/Res.java diff --git a/src/java/org/jivesoftware/AccountCreationWizard.java b/src/java/org/jivesoftware/AccountCreationWizard.java index 781caa2a..67c807a8 100644 --- a/src/java/org/jivesoftware/AccountCreationWizard.java +++ b/src/java/org/jivesoftware/AccountCreationWizard.java @@ -10,6 +10,7 @@ package org.jivesoftware; +import org.jivesoftware.resource.Res; import org.jivesoftware.smack.AccountManager; import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.XMPPException; @@ -63,11 +64,11 @@ public class AccountCreationWizard extends JPanel { public AccountCreationWizard() { // Associate Mnemonics - ResourceUtils.resLabel(usernameLabel, usernameField, "&Username:"); - ResourceUtils.resLabel(passwordLabel, passwordField, "&Password:"); - ResourceUtils.resLabel(confirmPasswordLabel, confirmPasswordField, "&Confirm Password:"); - ResourceUtils.resLabel(serverLabel, serverField, "&Server:"); - ResourceUtils.resButton(createAccountButton, "&Create Account"); + ResourceUtils.resLabel(usernameLabel, usernameField, Res.getString("label.username") + ":"); + ResourceUtils.resLabel(passwordLabel, passwordField, Res.getString("label.password") + ":"); + ResourceUtils.resLabel(confirmPasswordLabel, confirmPasswordField, Res.getString("label.confirm.password") + ":"); + ResourceUtils.resLabel(serverLabel, serverField, Res.getString("label.server") + ":"); + ResourceUtils.resButton(createAccountButton, Res.getString("button.create.account")); setLayout(new GridBagLayout()); @@ -92,7 +93,7 @@ public class AccountCreationWizard extends JPanel { add(createAccountButton, new GridBagConstraints(2, 5, 1, 1, 1.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); - ResourceUtils.resButton(closeButton, "&Close"); + ResourceUtils.resButton(closeButton, Res.getString("button.close")); add(closeButton, new GridBagConstraints(3, 5, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); @@ -136,34 +137,34 @@ public class AccountCreationWizard extends JPanel { if (!ModelUtil.hasLength(getUsername())) { errors = true; usernameField.requestFocus(); - errorMessage = "Please specify a username for the account."; + errorMessage = Res.getString("message.username.error"); } else if (!ModelUtil.hasLength(getPassword())) { errors = true; - errorMessage = "Please specify a password for this account."; + errorMessage = Res.getString("message.password.error"); } else if (!ModelUtil.hasLength(getConfirmPassword())) { errors = true; - errorMessage = "Please specify a confirmation password."; + errorMessage = Res.getString("message.confirmation.password.error"); } else if (!ModelUtil.hasLength(getServer())) { errors = true; - errorMessage = "Please specify the server to create the account on."; + errorMessage = Res.getString("message.account.error"); } else if (!isPasswordValid()) { errors = true; - errorMessage = "The passwords do not match. Please confirm passwords."; + errorMessage = Res.getString("message.confirmation.password.error"); } if (errors) { - JOptionPane.showMessageDialog(this, errorMessage, "Account Creation Problem", JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(this, errorMessage, Res.getString("title.create.problem"), JOptionPane.ERROR_MESSAGE); return; } final Component ui = this; progressBar.setIndeterminate(true); progressBar.setStringPainted(true); - progressBar.setString("Registering with " + getServer() + ". Please wait..."); + progressBar.setString(Res.getString("message.registering", getServer())); progressBar.setVisible(true); final SwingWorker worker = new SwingWorker() { int errorCode; @@ -192,7 +193,7 @@ public class AccountCreationWizard extends JPanel { if (connection == null) { if (ui.isShowing()) { createAccountButton.setEnabled(true); - JOptionPane.showMessageDialog(ui, "Unable to connect to " + getServer() + ".", "Account Creation Problem", JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(ui, Res.getString("message.connection.failed", getServer()), Res.getString("title.create.problem"), JOptionPane.ERROR_MESSAGE); createAccountButton.setEnabled(true); } return; @@ -211,26 +212,26 @@ public class AccountCreationWizard extends JPanel { } private void accountCreationFailed(int errorCode) { - String message = "Unable to create account."; + String message = Res.getString("message.create.account"); if (errorCode == 409) { - message = "Account already exists. Please specify different username."; + message = Res.getString("message.already.exists"); usernameField.setText(""); usernameField.requestFocus(); } - JOptionPane.showMessageDialog(this, message, "Account Creation Problem", JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(this, message, Res.getString("title.create.problem"), JOptionPane.ERROR_MESSAGE); createAccountButton.setEnabled(true); } private void accountCreationSuccessful() { registered = true; - JOptionPane.showMessageDialog(this, "New Account has been created.", "Account Created", JOptionPane.INFORMATION_MESSAGE); + JOptionPane.showMessageDialog(this, Res.getString("message.account.created"), Res.getString("title.account.created"), JOptionPane.INFORMATION_MESSAGE); dialog.dispose(); } public void invoke(JFrame parent) { - dialog = new JDialog(parent, "Create New Account", true); + dialog = new JDialog(parent, Res.getString("title.create.new.account"), true); - TitlePanel titlePanel = new TitlePanel("Account Registration", "Register a new account to chat", null, true); + TitlePanel titlePanel = new TitlePanel(Res.getString("title.account.create.registration"), Res.getString("message.account.create"), null, true); dialog.getContentPane().setLayout(new BorderLayout()); dialog.getContentPane().add(titlePanel, BorderLayout.NORTH); dialog.getContentPane().add(this, BorderLayout.CENTER); diff --git a/src/java/org/jivesoftware/LoginDialog.java b/src/java/org/jivesoftware/LoginDialog.java index 7070fb48..8a0fe966 100644 --- a/src/java/org/jivesoftware/LoginDialog.java +++ b/src/java/org/jivesoftware/LoginDialog.java @@ -11,6 +11,7 @@ package org.jivesoftware; import org.jivesoftware.resource.Default; +import org.jivesoftware.resource.Res; import org.jivesoftware.resource.SparkRes; import org.jivesoftware.smack.Roster; import org.jivesoftware.smack.SmackConfiguration; @@ -191,10 +192,10 @@ public final class LoginDialog { LoginPanel() { //setBorder(BorderFactory.createTitledBorder("Sign In Now")); - ResourceUtils.resButton(savePasswordBox, "Save &Password"); - ResourceUtils.resButton(autoLoginBox, "&Auto Login"); - ResourceUtils.resLabel(serverLabel, serverField, "&Server:"); - ResourceUtils.resButton(createAccountButton, "&Accounts"); + ResourceUtils.resButton(savePasswordBox, Res.getString("checkbox.save.password")); + ResourceUtils.resButton(autoLoginBox, Res.getString("checkbox.auto.login")); + ResourceUtils.resLabel(serverLabel, serverField, Res.getString("label.server")); + ResourceUtils.resButton(createAccountButton, Res.getString("label.accounts")); savePasswordBox.setOpaque(false); autoLoginBox.setOpaque(false); @@ -294,7 +295,7 @@ public final class LoginDialog { ResourceUtils.resLabel(passwordLabel, passwordField, SparkRes.getString(SparkRes.LOGIN_DIALOG_PASSWORD)); ResourceUtils.resButton(quitButton, SparkRes.getString(SparkRes.LOGIN_DIALOG_QUIT)); ResourceUtils.resButton(loginButton, SparkRes.getString(SparkRes.LOGIN_DIALOG_LOGIN)); - ResourceUtils.resButton(connectionButton, "Ad&vanced"); + ResourceUtils.resButton(connectionButton, Res.getString("button.advanced")); // Load previous instances String userProp = localPref.getUsername(); @@ -484,7 +485,7 @@ public final class LoginDialog { boolean loginSuccessfull = login(); if (loginSuccessfull) { - progressBar.setText("Connecting. Please wait..."); + progressBar.setText(Res.getString("message.connecting.please.wait")); // Startup Spark startSpark(); diff --git a/src/java/org/jivesoftware/LoginSettingDialog.java b/src/java/org/jivesoftware/LoginSettingDialog.java index 33d0358e..e8b82c7a 100644 --- a/src/java/org/jivesoftware/LoginSettingDialog.java +++ b/src/java/org/jivesoftware/LoginSettingDialog.java @@ -11,6 +11,7 @@ package org.jivesoftware; +import org.jivesoftware.resource.Res; import org.jivesoftware.resource.SparkRes; import org.jivesoftware.spark.component.TitlePanel; import org.jivesoftware.spark.util.ModelUtil; @@ -18,17 +19,6 @@ import org.jivesoftware.spark.util.ResourceUtils; import org.jivesoftware.sparkimpl.settings.local.LocalPreferences; import org.jivesoftware.sparkimpl.settings.local.SettingsManager; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.GridBagConstraints; -import java.awt.GridBagLayout; -import java.awt.Insets; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.util.Properties; - import javax.swing.BorderFactory; import javax.swing.JCheckBox; import javax.swing.JComboBox; @@ -42,8 +32,21 @@ import javax.swing.JPasswordField; import javax.swing.JTabbedPane; import javax.swing.JTextField; +import java.awt.BorderLayout; +import java.awt.Component; +import java.awt.GridBagConstraints; +import java.awt.GridBagLayout; +import java.awt.Insets; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.Properties; + /** * Allows users to configure startup options. + * + * @author Derek DeMoro */ public class LoginSettingDialog implements PropertyChangeListener { private JOptionPane optionPane; @@ -104,17 +107,17 @@ public class LoginSettingDialog implements PropertyChangeListener { } final JPanel inputPanel = new JPanel(); - tabbedPane.addTab("General", inputPanel); - tabbedPane.addTab("Proxy", proxyPanel); + tabbedPane.addTab(Res.getString("tab.general"), inputPanel); + tabbedPane.addTab(Res.getString("tab.proxy"), proxyPanel); inputPanel.setLayout(new GridBagLayout()); - ResourceUtils.resLabel(portLabel, portField, "&Port:"); - ResourceUtils.resLabel(timeOutLabel, timeOutField, "&Response Timeout (sec):"); - ResourceUtils.resButton(autoLoginBox, "&Auto Login"); - ResourceUtils.resLabel(sslLabel, useSSLBox, "&Use OLD SSL port method"); - ResourceUtils.resLabel(xmppHostLabel, xmppHostField, "&Host:"); - ResourceUtils.resButton(autoDiscoverBox, "&Automatically discover host and port"); - ResourceUtils.resLabel(resourceLabel, resourceField, "&Resource:"); + ResourceUtils.resLabel(portLabel, portField, Res.getString("label.port")); + ResourceUtils.resLabel(timeOutLabel, timeOutField, Res.getString("label.response.timeout")); + ResourceUtils.resButton(autoLoginBox, Res.getString("label.auto.login")); + ResourceUtils.resLabel(sslLabel, useSSLBox, Res.getString("label.old.ssl")); + ResourceUtils.resLabel(xmppHostLabel, xmppHostField, Res.getString("label.host")); + ResourceUtils.resButton(autoDiscoverBox, Res.getString("checkbox.auto.discover.port")); + ResourceUtils.resLabel(resourceLabel, resourceField, Res.getString("label.resource")); inputPanel.add(autoDiscoverBox, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); @@ -129,7 +132,7 @@ public class LoginSettingDialog implements PropertyChangeListener { final JPanel connectionPanel = new JPanel(); connectionPanel.setLayout(new GridBagLayout()); - connectionPanel.setBorder(BorderFactory.createTitledBorder("Connection")); + connectionPanel.setBorder(BorderFactory.createTitledBorder(Res.getString("group.connection"))); connectionPanel.add(xmppHostLabel, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); connectionPanel.add(xmppHostField, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 200, 0)); @@ -157,13 +160,13 @@ public class LoginSettingDialog implements PropertyChangeListener { mainPanel.add(titlePanel, BorderLayout.NORTH); // The user should only be able to close this dialog. - Object[] options = {"Ok", "Cancel", "Use Default"}; + Object[] options = {Res.getString("ok"), Res.getString("cancel"), Res.getString("use.default")}; optionPane = new JOptionPane(tabbedPane, JOptionPane.PLAIN_MESSAGE, - JOptionPane.OK_CANCEL_OPTION, null, options, options[0]); + JOptionPane.OK_CANCEL_OPTION, null, options, options[0]); mainPanel.add(optionPane, BorderLayout.CENTER); - optionsDialog = new JDialog(owner, "Preference Window", true); + optionsDialog = new JDialog(owner, Res.getString("title.preferences"), true); optionsDialog.setContentPane(mainPanel); optionsDialog.pack(); @@ -187,10 +190,10 @@ public class LoginSettingDialog implements PropertyChangeListener { */ public void propertyChange(PropertyChangeEvent e) { String value = (String)optionPane.getValue(); - if ("Cancel".equals(value)) { + if (Res.getString("cancel").equals(value)) { optionsDialog.setVisible(false); } - else if ("Ok".equals(value)) { + else if (Res.getString("ok").equals(value)) { String timeOut = timeOutField.getText(); String port = portField.getText(); String resource = resourceField.getText(); @@ -201,8 +204,8 @@ public class LoginSettingDialog implements PropertyChangeListener { Integer.valueOf(timeOut); } catch (NumberFormatException numberFormatException) { - JOptionPane.showMessageDialog(optionsDialog, "You must supply a valid Time out value.", - "Invalid Time Out", JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(optionsDialog, Res.getString("message.supply.valid.timeout"), + Res.getString("title.error"), JOptionPane.ERROR_MESSAGE); timeOutField.requestFocus(); errors = true; } @@ -211,15 +214,15 @@ public class LoginSettingDialog implements PropertyChangeListener { Integer.valueOf(port); } catch (NumberFormatException numberFormatException) { - JOptionPane.showMessageDialog(optionsDialog, "You must supply a valid Port.", - "Invalid Port", JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(optionsDialog, Res.getString("message.supply.valid.port"), + Res.getString("title.error"), JOptionPane.ERROR_MESSAGE); portField.requestFocus(); errors = true; } if (!ModelUtil.hasLength(resource)) { - JOptionPane.showMessageDialog(optionsDialog, "You must supply a resource", - "Invalid Resource", JOptionPane.ERROR_MESSAGE); + JOptionPane.showMessageDialog(optionsDialog, Res.getString("message.supply.resource"), + Res.getString("title.error"), JOptionPane.ERROR_MESSAGE); resourceField.requestFocus(); errors = true; } @@ -269,12 +272,12 @@ public class LoginSettingDialog implements PropertyChangeListener { protocolBox.addItem("HTTP"); // Add ResourceUtils - ResourceUtils.resButton(useProxyBox, "&Use Proxy Server"); - ResourceUtils.resLabel(protocolLabel, protocolBox, "&Protocol:"); - ResourceUtils.resLabel(hostLabel, hostField, "&Host:"); - ResourceUtils.resLabel(portLabel, portField, "P&ort:"); - ResourceUtils.resLabel(usernameLabel, usernameField, "&Username:"); - ResourceUtils.resLabel(passwordLabel, passwordField, "P&assword:"); + ResourceUtils.resButton(useProxyBox, Res.getString("checkbox.use.proxy.server")); + ResourceUtils.resLabel(protocolLabel, protocolBox, Res.getString("label.protocol")); + ResourceUtils.resLabel(hostLabel, hostField, Res.getString("label.host")); + ResourceUtils.resLabel(portLabel, portField, Res.getString("label.port")); + ResourceUtils.resLabel(usernameLabel, usernameField, Res.getString("label.username")); + ResourceUtils.resLabel(passwordLabel, passwordField, Res.getString("label.password")); setLayout(new GridBagLayout()); add(useProxyBox, new GridBagConstraints(0, 0, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); diff --git a/src/java/org/jivesoftware/resource/Res.java b/src/java/org/jivesoftware/resource/Res.java new file mode 100644 index 00000000..3db61893 --- /dev/null +++ b/src/java/org/jivesoftware/resource/Res.java @@ -0,0 +1,51 @@ +/** + * $Revision$ + * $Date$ + * + * Copyright (C) 1999-2005 Jive Software. All rights reserved. + * This software is the proprietary information of Jive Software. Use is subject to license terms. + */ + +package org.jivesoftware.resource; + +import java.text.MessageFormat; +import java.util.PropertyResourceBundle; +import java.util.ResourceBundle; + +/** + * Use for Spark Internationalization. + * + * @author Derek DeMoro + */ +public class Res { + private static PropertyResourceBundle prb; + + private Res() { + + } + + static ClassLoader cl = Res.class.getClassLoader(); + + static { + prb = (PropertyResourceBundle)ResourceBundle.getBundle("i18n/spark_i18n"); + } + + public static final String getString(String propertyName) { + return prb.getString(propertyName); + } + + public static final String getString(String propertyName, Object... obj) { + String str = prb.getString(propertyName); + if (str == null) { + return null; + } + + + + return MessageFormat.format(str, obj); + } + + public static PropertyResourceBundle getBundle() { + return prb; + } +} diff --git a/src/java/org/jivesoftware/spark/ui/TranscriptWindow.java b/src/java/org/jivesoftware/spark/ui/TranscriptWindow.java index ad612b41..55b86f3b 100644 --- a/src/java/org/jivesoftware/spark/ui/TranscriptWindow.java +++ b/src/java/org/jivesoftware/spark/ui/TranscriptWindow.java @@ -428,7 +428,7 @@ public class TranscriptWindow extends ChatArea { // Agent color is always blue StyleConstants.setBold(styles, false); - StyleConstants.setForeground(styles, Color.LIGHT_GRAY); + StyleConstants.setForeground(styles, Color.GRAY); final Document doc = getDocument(); styles.removeAttribute("link"); @@ -437,7 +437,7 @@ public class TranscriptWindow extends ChatArea { // Reset Styles for message StyleConstants.setBold(styles, false); - setForeground(Color.LIGHT_GRAY); + setForeground(Color.gray); setText(message); setForeground(Color.BLACK); insertText("\n"); diff --git a/src/resources/i18n/spark_i18n_en.properties b/src/resources/i18n/spark_i18n_en.properties index 368a74ed..b5af32fa 100644 --- a/src/resources/i18n/spark_i18n_en.properties +++ b/src/resources/i18n/spark_i18n_en.properties @@ -1,39 +1,74 @@ # Spark -label.username = &Username: -label.password = &Password: -label.confirm.password = &Confirm Password: -label.server = &Server: -label.create.account = Create &Account: -label.close = C&lose: +ok = Ok +cancel = Cancel +use.default = Use Default + +button.create.account = &Create Account +button.close = C&lose +button.advanced = Ad&vanced + +checkbox.save.password = &Save Password +checkbox.auto.login = &Auto Login +checkbox.use.proxy.server = &Use Proxy Server +checkbox.auto.discover.port = &Automatically discover host and port + + +label.username = &Username +label.password = &Password +label.confirm.password = &Confirm Password +label.server = &Server +label.create.account = Create &Account +label.close = C&lose label.ok = OK label.cancel = Cancel label.use.default = Use Default +label.port = &Port +label.response.timeout = Response &Timeout +label.auto.login = &Auto Login +label.old.ssl = &Use OLD SSL port method +label.host = &Host +label.resource = &Resource +label.protocol = &Protocol +label.accounts = &Accounts + + +message.username.error = Specify a username for the account. +message.password.error = Specify a password for this account. +message.confirmation.password.error = Specify a confirmation password. +message.account.error = Specify the server to create the account on. +message.registering = Registering with {0}. Please wait... +message.connection.failed = Unable to connect to {0}. +message.create.account = Account could not be created. +message.already.exists = Account already exists. Please try a different username. +message.account.created = New account has been created. +message.account.create = Create a new chat account. +message.connecting.please.wait = Connecting. Please wait... +message.supply.valid.timeout = Supply a valid time out value. +message.supply.valid.port = Supply a valid port. +message.supply.resource = Supply a valid resource. + +title.passwords.no.match = Confirm passwords. +title.create.problem = Account Creation Problem +title.account.created = Account Created +title.create.new.account = Create New Account +title.account.create.registration = Account Registration +title.register.account = Register New Account +title.notification = Notification +title.advanced.connection.preferences = Advanced Connection Preferences +title.preferences = Preferences +title.error = Error + + + + +tab.general = General +tab.proxy = Proxy + + +group.connection = Connection -# Account Creation -account.create.username.error = Please specify a username for the account. -account.create.password.error = Please specify a password for this account. -account.create.confirmation.password.error = Please specify a confirmation password. -account.create.account.error = Please specify the server to create the account on. -account.create.passwords.no.match = The passwords do not match. Please confirm passwords. -account.create.problem = Account Creation Problem -account.create.registering = Registering with {0}. Please wait... -account.create.connection.failed = Unable to connect to {0}. -account.create.account = Unable to create account. -account.create.already.exists = Account already exists. Please try a different username. -account.create.created = A new account has been created. -account.create.created.title = Account Created -account.create.create.account = Create New Account -account.create.registration = Account Registration -account.create.register.account = Register a new account to chat -# Login Dialog -login.dialog.save.password = Save &Password -login.dialog.auto.login = &Auto Login -login.dialog.server = &Server: -login.dialog.accounts = &Accounts -login.dialog.advanced = Ad&vanced -login.dialog.connection = Connecting. Please wait... # Login Settings login.settings.general = General @@ -63,12 +98,7 @@ login.settings.password = P&assword: # org.jivesoftware.spark # org.jivesoftware.spark.component -recieved = Received: -error.title = An error has been detected. Please report to support@jivesoftware.com. -open = Open -hide = Hide -exit = Exit -status = Status + # org.jivesoftware.spark.component.borders