Cleaned up the MiCasa logon panel and services. It's all much more nicely

behaved now.


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1574 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Michael Bayne
2002-07-12 17:01:28 +00:00
parent 6064ab1750
commit 75edbad42f
5 changed files with 103 additions and 44 deletions
@@ -1,5 +1,5 @@
//
// $Id: ClientController.java,v 1.14 2002/05/21 04:47:48 mdb Exp $
// $Id: ClientController.java,v 1.15 2002/07/12 17:01:28 mdb Exp $
package com.threerings.micasa.client;
@@ -102,6 +102,9 @@ public class ClientController extends Controller
public void clientDidLogoff (Client client)
{
Log.info("Client did logoff [client=" + client + "].");
// reinstate the logon panel
_frame.setPanel(_logonPanel);
}
protected MiCasaContext _ctx;
@@ -1,5 +1,5 @@
//
// $Id: LogonPanel.java,v 1.4 2002/04/12 16:26:12 shaper Exp $
// $Id: LogonPanel.java,v 1.5 2002/07/12 17:01:28 mdb Exp $
package com.threerings.micasa.client;
@@ -21,61 +21,84 @@ import com.samskivert.swing.GroupLayout;
import com.samskivert.swing.HGroupLayout;
import com.samskivert.swing.VGroupLayout;
import com.threerings.util.MessageBundle;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.ClientObserver;
import com.threerings.presents.client.LogonException;
import com.threerings.presents.net.Credentials;
import com.threerings.presents.net.UsernamePasswordCreds;
import com.threerings.micasa.util.MiCasaContext;
public class LogonPanel
extends JPanel implements ActionListener
public class LogonPanel extends JPanel
implements ActionListener, ClientObserver
{
public LogonPanel (MiCasaContext ctx)
{
// keep this around for later
// keep these around for later
_ctx = ctx;
_msgs = _ctx.getMessageManager().getBundle("micasa");
GroupLayout gl = new VGroupLayout(GroupLayout.NONE);
gl.setOffAxisPolicy(GroupLayout.EQUALIZE);
setLayout(gl);
setLayout(new VGroupLayout());
// give ourselves a wee bit of a border
setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
// stick the logon components into a panel that will stretch them
// to a sensible width
JPanel box = new JPanel(
new VGroupLayout(VGroupLayout.NONE, VGroupLayout.STRETCH,
5, VGroupLayout.CENTER)) {
public Dimension getPreferredSize () {
Dimension psize = super.getPreferredSize();
psize.width = Math.max(psize.width, 300);
return psize;
}
};
add(box);
// try obtaining our title text from a system property
String tstr = null;
try {
tstr = System.getProperty("logon.title");
} catch (Throwable t) {
}
if (tstr == null) {
tstr = "Mi Casa!";
}
// create a big fat label
JLabel title = new JLabel("Mi Casa!");
JLabel title = new JLabel(tstr, JLabel.CENTER);
title.setFont(new Font("Helvetica", Font.BOLD, 24));
add(title);
box.add(title);
// create the username bar
JPanel bar = new JPanel(new HGroupLayout(GroupLayout.STRETCH));
bar.add(new JLabel("Username"), GroupLayout.FIXED);
bar.add(new JLabel(_msgs.get("m.username")), GroupLayout.FIXED);
_username = new JTextField();
_username.setActionCommand("skipToPassword");
_username.addActionListener(this);
bar.add(_username);
add(bar);
box.add(bar);
// create the password bar
bar = new JPanel(new HGroupLayout(GroupLayout.STRETCH));
bar.add(new JLabel("Password"), GroupLayout.FIXED);
bar.add(new JLabel(_msgs.get("m.password")), GroupLayout.FIXED);
_password = new JPasswordField();
_password.setActionCommand("logon");
_password.addActionListener(this);
bar.add(_password);
add(bar);
box.add(bar);
// create the logon button bar
gl = new HGroupLayout(GroupLayout.NONE);
HGroupLayout gl = new HGroupLayout(GroupLayout.NONE);
gl.setJustification(GroupLayout.RIGHT);
bar = new JPanel(gl);
_logon = new JButton("Logon");
_logon = new JButton(_msgs.get("m.logon"));
_logon.setActionCommand("logon");
_logon.addActionListener(this);
bar.add(_logon);
add(bar);
box.add(bar);
add(new JLabel("Status"));
box.add(new JLabel(_msgs.get("m.status")));
_status = new JTextArea() {
public Dimension getPreferredScrollableViewportSize ()
{
@@ -84,7 +107,10 @@ public class LogonPanel
};
_status.setEditable(false);
JScrollPane scroller = new JScrollPane(_status);
add(scroller);
box.add(scroller);
// we'll want to listen for logon failure
_ctx.getClient().addClientObserver(this);
// start with focus in the username field
_username.requestFocus();
@@ -104,6 +130,48 @@ public class LogonPanel
}
}
// documentation inherited from interface
public void clientDidLogon (Client client)
{
_status.append(_msgs.get("m.logon_success") + "\n");
}
// documentation inherited from interface
public void clientDidLogoff (Client client)
{
_status.append(_msgs.get("m.logged_off") + "\n");
setLogonEnabled(true);
}
// documentation inherited from interface
public void clientFailedToLogon (Client client, Exception cause)
{
String msg;
if (cause instanceof LogonException) {
msg = MessageBundle.compose("m.logon_failed", cause.getMessage());
} else {
msg = MessageBundle.tcompose("m.logon_failed", cause.getMessage());
}
_status.append(_msgs.xlate(msg) + "\n");
setLogonEnabled(true);
}
// documentation inherited from interface
public void clientConnectionFailed (Client client, Exception cause)
{
String msg = MessageBundle.tcompose("m.connection_failed",
cause.getMessage());
_status.append(_msgs.xlate(msg) + "\n");
setLogonEnabled(true);
}
// documentation inherited from interface
public boolean clientWillLogoff (Client client)
{
// no vetoing here
return true;
}
protected void logon ()
{
// disable further logon attempts until we hear back
@@ -112,7 +180,7 @@ public class LogonPanel
String username = _username.getText().trim();
String password = new String(_password.getPassword()).trim();
System.out.println("Logging on " + username + "/" + password);
_status.append(_msgs.get("m.logging_on") + "\n");
// configure the client with some credentials and logon
Credentials creds = new UsernamePasswordCreds(username, password);
@@ -128,13 +196,9 @@ public class LogonPanel
_logon.setEnabled(enabled);
}
protected void logonFailed (Exception cause)
{
_status.append("Logon failed: " + cause.getMessage() + "\n");
setLogonEnabled(true);
}
protected MiCasaContext _ctx;
protected MessageBundle _msgs;
protected JTextField _username;
protected JPasswordField _password;
protected JButton _logon;
@@ -1,5 +1,5 @@
//
// $Id: MiCasaApp.java,v 1.7 2002/05/21 04:47:48 mdb Exp $
// $Id: MiCasaApp.java,v 1.8 2002/07/12 17:01:28 mdb Exp $
package com.threerings.micasa.client;
@@ -7,7 +7,6 @@ import java.io.IOException;
import com.samskivert.swing.util.SwingUtil;
import com.threerings.presents.client.Client;
import com.threerings.presents.client.ClientAdapter;
import com.threerings.presents.net.Credentials;
import com.threerings.presents.net.UsernamePasswordCreds;
@@ -59,17 +58,6 @@ public class MiCasaApp
client.setServer(server, Client.DEFAULT_SERVER_PORT);
}
// we want to exit when we logged off or failed to log on
client.addClientObserver(new ClientAdapter() {
public void clientFailedToLogon (Client c, Exception cause) {
Log.info("Client failed to logon [cause=" + cause + "].");
System.exit(0);
}
public void clientDidLogoff (Client c) {
System.exit(0);
}
});
// configure the client with some credentials and logon
String username = System.getProperty("username");
if (username != null) {
@@ -1,5 +1,5 @@
//
// $Id: MiCasaClient.java,v 1.13 2002/05/21 04:47:48 mdb Exp $
// $Id: MiCasaClient.java,v 1.14 2002/07/12 17:01:28 mdb Exp $
package com.threerings.micasa.client;
@@ -57,6 +57,9 @@ public class MiCasaClient
// if we're logged on, log off
if (_client.loggedOn()) {
_client.logoff(true);
} else {
// otherwise get the heck out
System.exit(0);
}
}
});
@@ -1,5 +1,5 @@
//
// $Id: MiCasaFrame.java,v 1.5 2002/07/12 03:48:45 mdb Exp $
// $Id: MiCasaFrame.java,v 1.6 2002/07/12 17:01:28 mdb Exp $
package com.threerings.micasa.client;
@@ -44,7 +44,8 @@ public class MiCasaFrame
// add the new one
getContentPane().add(panel, BorderLayout.CENTER);
// swing doesn't properly repaint after adding/removing children
validate();
panel.revalidate();
repaint();
}
/**