# HG changeset patch # User Jaroslav Tulach # Date 1284388027 -7200 # Node ID 8ebffb5aa10ec8a1241a6323f120f5389bc8803c # Parent 925ad06593492396a0c858ccea25b1644f127a66 Shows all current games diff -r 925ad0659349 -r 8ebffb5aa10e desktop/application/pom.xml --- a/desktop/application/pom.xml Sun Sep 12 21:21:09 2010 +0200 +++ b/desktop/application/pom.xml Mon Sep 13 16:27:07 2010 +0200 @@ -39,6 +39,7 @@ org.codehaus.mojo nbm-maven-plugin + 3.3-SNAPSHOT diff -r 925ad0659349 -r 8ebffb5aa10e desktop/desktop-sample/pom.xml --- a/desktop/desktop-sample/pom.xml Sun Sep 12 21:21:09 2010 +0200 +++ b/desktop/desktop-sample/pom.xml Mon Sep 13 16:27:07 2010 +0200 @@ -50,24 +50,60 @@ org-netbeans-modules-settings RELEASE691 - - - ${project.groupId} + quoridor + ${quoridorVersion} + + + ${project.groupId} visidor ${visidorVersion} - + + cz.xelfi.quoridor + wsdor + ${wsdorVersion} + + + + com.sun.jersey + jersey-client + ${jerseyVersion} + + + com.sun.jersey + jersey-core + ${jerseyVersion} + + + com.sun.jersey + jersey-json + ${jerseyVersion} + + + javax.ws.rs + jsr311-api + jar + 1.1.1 + + + com.sun.xml.bind + jaxb-impl + 2.2.1.1 + + + org.codehaus.jettison + jettison + 1.2 + + org.codehaus.mojo nbm-maven-plugin - 3.2 + 3.3-SNAPSHOT true true diff -r 925ad0659349 -r 8ebffb5aa10e desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/KukTopComponent.java --- a/desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/KukTopComponent.java Sun Sep 12 21:21:09 2010 +0200 +++ b/desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/KukTopComponent.java Mon Sep 13 16:27:07 2010 +0200 @@ -10,7 +10,7 @@ import org.netbeans.api.settings.ConvertAsProperties; /** - * Top component which displays something. + * Top component which displays the board. */ @ConvertAsProperties(dtd = "-//cz.xelfi.quoridor.desktop.sample//Kuk//EN", autostore = false) @@ -20,13 +20,20 @@ // static final String ICON_PATH = "SET/PATH/TO/ICON/HERE"; private static final String PREFERRED_ID = "KukTopComponent"; + private String id; + public KukTopComponent() { initComponents(); setName(NbBundle.getMessage(KukTopComponent.class, "CTL_KukTopComponent")); setToolTipText(NbBundle.getMessage(KukTopComponent.class, "HINT_KukTopComponent")); // setIcon(ImageUtilities.loadImage(ICON_PATH, true)); - + + } + + public void setGameId(String id) { + this.id = id; + boardPane1.setBoard(Quoridor.getDefault().getGame(id).getBoard()); } /** This method is called from within the constructor to @@ -84,12 +91,17 @@ // better to version settings since initial version as advocated at // http://wiki.apidesign.org/wiki/PropertyFiles p.setProperty("version", "1.0"); - // TODO store your settings + if (id != null) { + p.setProperty("id", id); + } } final void readProperties(java.util.Properties p) { String version = p.getProperty("version"); - // TODO read your settings according to their version + String myId = p.getProperty("id"); + if (myId != null) { + setGameId(myId); + } } @Override diff -r 925ad0659349 -r 8ebffb5aa10e desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/Quoridor.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/Quoridor.java Mon Sep 13 16:27:07 2010 +0200 @@ -0,0 +1,54 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package cz.xelfi.quoridor.desktop.sample; + +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.GenericType; +import com.sun.jersey.api.client.WebResource; +import cz.xelfi.quoridor.webidor.Game; +import cz.xelfi.quoridor.webidor.GameId; +import java.util.List; +import javax.ws.rs.core.MediaType; +import org.openide.util.Lookup; + +/** Class that connects to the server and answers queries. + * + * @author Jaroslav Tulach + */ +abstract class Quoridor { + + public static Quoridor getDefault() { + Quoridor q = Lookup.getDefault().lookup(Quoridor.class); + return q == null ? new Impl() : q; + } + + public abstract List listGames(); + public abstract Game getGame(String id); + + private static class Impl extends Quoridor { + private final WebResource wr; + + public Impl() { + Client c = new Client(); + wr = c.resource("http://quoridor.xelfi.cz/api/"); + } + + @Override + public List listGames() { + GenericType> gType = new GenericType>() {}; + List ids = wr.path("games").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); + return g; + } + + } +} diff -r 925ad0659349 -r 8ebffb5aa10e desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/ShowGames.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/ShowGames.java Mon Sep 13 16:27:07 2010 +0200 @@ -0,0 +1,22 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package cz.xelfi.quoridor.desktop.sample; + +import cz.xelfi.quoridor.webidor.GameId; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +public final class ShowGames implements ActionListener { + + @Override + public void actionPerformed(ActionEvent e) { + for (GameId gameId : Quoridor.getDefault().listGames()) { + KukTopComponent tc = new KukTopComponent(); + tc.setGameId(gameId.getId()); + tc.setName(gameId.getWhite() + "/" + gameId.getBlack()); + tc.open(); + } + } +} diff -r 925ad0659349 -r 8ebffb5aa10e desktop/desktop-sample/src/main/resources/cz/xelfi/quoridor/desktop/KukTopComponentSettings.xml --- a/desktop/desktop-sample/src/main/resources/cz/xelfi/quoridor/desktop/KukTopComponentSettings.xml Sun Sep 12 21:21:09 2010 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ - - - - - - - - - diff -r 925ad0659349 -r 8ebffb5aa10e desktop/desktop-sample/src/main/resources/cz/xelfi/quoridor/desktop/KukTopComponentWstcref.xml --- a/desktop/desktop-sample/src/main/resources/cz/xelfi/quoridor/desktop/KukTopComponentWstcref.xml Sun Sep 12 21:21:09 2010 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ - - - - - - - - diff -r 925ad0659349 -r 8ebffb5aa10e 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 Sun Sep 12 21:21:09 2010 +0200 +++ b/desktop/desktop-sample/src/main/resources/cz/xelfi/quoridor/desktop/layer.xml Mon Sep 13 16:27:07 2010 +0200 @@ -3,29 +3,29 @@ - - - - - + + + + + + - - - + + + + - - - - - - - - + + + + + + diff -r 925ad0659349 -r 8ebffb5aa10e 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 Sun Sep 12 21:21:09 2010 +0200 +++ b/desktop/desktop-sample/src/main/resources/cz/xelfi/quoridor/desktop/sample/Bundle.properties Mon Sep 13 16:27:07 2010 +0200 @@ -2,4 +2,5 @@ CTL_KukAction=Kuk CTL_KukTopComponent=Kuk Window CTL_OpenGameAction=Open a game +CTL_ShowGames=Show Games HINT_KukTopComponent=This is a Kuk window