# HG changeset patch # User Jaroslav Tulach # Date 1284445837 -7200 # Node ID ac802aa234fc9414cdceb634e09d6ba8b008d1a7 # Parent 6427ae4c4ef2bcec06f64c9d7d3029ef59f08388 Login panel diff -r 6427ae4c4ef2 -r ac802aa234fc desktop/desktop-sample/pom.xml --- a/desktop/desktop-sample/pom.xml Mon Sep 13 21:08:27 2010 +0200 +++ b/desktop/desktop-sample/pom.xml Tue Sep 14 08:30:37 2010 +0200 @@ -97,6 +97,11 @@ jettison 1.2 + + org.netbeans.api + org-openide-dialogs + RELEASE691 + diff -r 6427ae4c4ef2 -r ac802aa234fc desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/LoginAction.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/LoginAction.java Tue Sep 14 08:30:37 2010 +0200 @@ -0,0 +1,34 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package cz.xelfi.quoridor.desktop.sample; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import org.openide.DialogDisplayer; +import org.openide.NotifyDescriptor; +import org.openide.util.NbBundle; + +public final class LoginAction implements ActionListener { + + @Override + public void actionPerformed(ActionEvent e) { + LoginPanel lp = new LoginPanel(); + NotifyDescriptor nd = new NotifyDescriptor( + lp, + NbBundle.getMessage(LoginAction.class, "LoginAction.title"), + NotifyDescriptor.OK_CANCEL_OPTION, + NotifyDescriptor.QUESTION_MESSAGE, null, null + ); + Object res = DialogDisplayer.getDefault().notify(nd); + if (res == NotifyDescriptor.OK_OPTION) { + if (!Quoridor.getDefault().login(lp.getLogin(), lp.getPassword())) { + nd = new NotifyDescriptor.Message( + NbBundle.getMessage(LoginAction.class, "LoginAction.fail") + ); + DialogDisplayer.getDefault().notify(nd); + } + } + } +} diff -r 6427ae4c4ef2 -r ac802aa234fc desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/LoginPanel.form --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/LoginPanel.form Tue Sep 14 08:30:37 2010 +0200 @@ -0,0 +1,82 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff -r 6427ae4c4ef2 -r ac802aa234fc desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/LoginPanel.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/LoginPanel.java Tue Sep 14 08:30:37 2010 +0200 @@ -0,0 +1,86 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package cz.xelfi.quoridor.desktop.sample; + +/** + * + * @author Jaroslav Tulach + */ +class LoginPanel extends javax.swing.JPanel { + + /** Creates new form LoginPanel */ + public LoginPanel() { + initComponents(); + } + + /** This method is called from within the constructor to + * initialize the form. + * WARNING: Do NOT modify this code. The content of this method is + * always regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + loginLabel = new javax.swing.JLabel(); + login = new javax.swing.JTextField(); + passwordLabel = new javax.swing.JLabel(); + password = new javax.swing.JPasswordField(); + + loginLabel.setText(org.openide.util.NbBundle.getMessage(LoginPanel.class, "LoginPanel.loginLabel.text")); // NOI18N + + login.setText(org.openide.util.NbBundle.getMessage(LoginPanel.class, "LoginPanel.login.text")); // NOI18N + + passwordLabel.setText(org.openide.util.NbBundle.getMessage(LoginPanel.class, "LoginPanel.passwordLabel.text")); // NOI18N + + password.setText(org.openide.util.NbBundle.getMessage(LoginPanel.class, "LoginPanel.password.text")); // NOI18N + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(loginLabel) + .addComponent(passwordLabel)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(password, javax.swing.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE) + .addComponent(login, javax.swing.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE)) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(loginLabel) + .addComponent(login, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(passwordLabel) + .addComponent(password, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + }// //GEN-END:initComponents + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JTextField login; + private javax.swing.JLabel loginLabel; + private javax.swing.JPasswordField password; + private javax.swing.JLabel passwordLabel; + // End of variables declaration//GEN-END:variables + + public String getLogin() { + return login.getText(); + } + + public String getPassword() { + return new String(password.getPassword()); + } +} diff -r 6427ae4c4ef2 -r ac802aa234fc desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/Quoridor.java --- a/desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/Quoridor.java Mon Sep 13 21:08:27 2010 +0200 +++ b/desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/Quoridor.java Tue Sep 14 08:30:37 2010 +0200 @@ -7,10 +7,13 @@ import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.GenericType; +import com.sun.jersey.api.client.UniformInterfaceException; import com.sun.jersey.api.client.WebResource; import cz.xelfi.quoridor.webidor.Game; import cz.xelfi.quoridor.webidor.GameId; import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.ws.rs.core.MediaType; import org.openide.util.Lookup; @@ -19,17 +22,28 @@ * @author Jaroslav Tulach */ abstract class Quoridor { + private static Quoridor q; public static Quoridor getDefault() { - Quoridor q = Lookup.getDefault().lookup(Quoridor.class); - return q == null ? new Impl() : q; + if (q != null) { + return q; + } + q = Lookup.getDefault().lookup(Quoridor.class); + if (q == null) { + q = new Impl(); + } + return q; } public abstract List listGames(); public abstract Game getGame(String id); + public abstract boolean login(String login, String password); + private static class Impl extends Quoridor { private final WebResource wr; + private String id = ""; + private static final Logger LOG = Logger.getLogger(Impl.class.getName()); public Impl() { Client c = new Client(); @@ -39,16 +53,30 @@ @Override public List listGames() { GenericType> gType = new GenericType>() {}; - List ids = wr.path("games").accept(MediaType.TEXT_XML).get(gType); + List ids = wr.path("games").queryParam("loginID", id). + accept(MediaType.TEXT_XML).get(gType); return ids; } @Override public Game getGame(String id) { - Game g = wr.path("games").path(id).accept(MediaType.TEXT_XML).get(Game.class); + Game g = wr.path("games").path(id).queryParam("loginID", id). + accept(MediaType.TEXT_XML).get(Game.class); return g; } + @Override + public boolean login(String login, String password) { + try { + id = wr.path("login").queryParam("name", login). + queryParam("password", password).put(String.class); + return id != null; + } catch (UniformInterfaceException ex) { + LOG.log(Level.INFO, "Cannot login", ex); + return false; + } + } + } } diff -r 6427ae4c4ef2 -r ac802aa234fc desktop/desktop-sample/src/main/resources/cz/xelfi/quoridor/desktop/layer.xml --- a/desktop/desktop-sample/src/main/resources/cz/xelfi/quoridor/desktop/layer.xml Mon Sep 13 21:08:27 2010 +0200 +++ b/desktop/desktop-sample/src/main/resources/cz/xelfi/quoridor/desktop/layer.xml Tue Sep 14 08:30:37 2010 +0200 @@ -11,9 +11,21 @@ + + + + + + + + + + + + diff -r 6427ae4c4ef2 -r ac802aa234fc desktop/desktop-sample/src/main/resources/cz/xelfi/quoridor/desktop/sample/Bundle.properties --- a/desktop/desktop-sample/src/main/resources/cz/xelfi/quoridor/desktop/sample/Bundle.properties Mon Sep 13 21:08:27 2010 +0200 +++ b/desktop/desktop-sample/src/main/resources/cz/xelfi/quoridor/desktop/sample/Bundle.properties Tue Sep 14 08:30:37 2010 +0200 @@ -1,9 +1,18 @@ CTL_Hello=Hello CTL_KukAction=Kuk CTL_KukTopComponent={0}/{1} +CTL_LoginAction=Login CTL_OpenGameAction=Open a game CTL_ShowGames=Show Games HINT_KukTopComponent=White {0} against black {1} KukTopComponent.jLabel1.text= KukTopComponent.jButton1.text= KukTopComponent.jButton2.text= + + +LoginPanel.login.text= +LoginPanel.loginLabel.text=Login: +LoginPanel.passwordLabel.text=Password: +LoginAction.title=Login to Quoridor +LoginAction.fail=Login failed. +LoginPanel.password.text=