Shows all current games desktop
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 13 Sep 2010 16:27:07 +0200
branchdesktop
changeset 2608ebffb5aa10e
parent 259 925ad0659349
child 261 cf7e6b8259e1
Shows all current games
desktop/application/pom.xml
desktop/desktop-sample/pom.xml
desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/KukTopComponent.java
desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/Quoridor.java
desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/ShowGames.java
desktop/desktop-sample/src/main/resources/cz/xelfi/quoridor/desktop/KukTopComponentSettings.xml
desktop/desktop-sample/src/main/resources/cz/xelfi/quoridor/desktop/KukTopComponentWstcref.xml
desktop/desktop-sample/src/main/resources/cz/xelfi/quoridor/desktop/layer.xml
desktop/desktop-sample/src/main/resources/cz/xelfi/quoridor/desktop/sample/Bundle.properties
     1.1 --- a/desktop/application/pom.xml	Sun Sep 12 21:21:09 2010 +0200
     1.2 +++ b/desktop/application/pom.xml	Mon Sep 13 16:27:07 2010 +0200
     1.3 @@ -39,6 +39,7 @@
     1.4              <plugin>
     1.5                  <groupId>org.codehaus.mojo</groupId>
     1.6                  <artifactId>nbm-maven-plugin</artifactId>
     1.7 +                <version>3.3-SNAPSHOT</version>
     1.8              </plugin>
     1.9          </plugins>
    1.10      </build>
     2.1 --- a/desktop/desktop-sample/pom.xml	Sun Sep 12 21:21:09 2010 +0200
     2.2 +++ b/desktop/desktop-sample/pom.xml	Mon Sep 13 16:27:07 2010 +0200
     2.3 @@ -50,24 +50,60 @@
     2.4              <artifactId>org-netbeans-modules-settings</artifactId> 
     2.5              <version>RELEASE691</version> 
     2.6          </dependency> 
     2.7 -        <!-- 
     2.8          <dependency> 
     2.9              <groupId>${project.groupId}</groupId> 
    2.10 -            <artifactId>quoridor</artifactId> 
    2.11 -            <version>${quoridorVersion}</version> 
    2.12 -        </dependency>--> 
    2.13 -        <dependency> 
    2.14 -            <groupId>${project.groupId}</groupId> 
    2.15 +            <artifactId>quoridor</artifactId>
    2.16 +            <version>${quoridorVersion}</version>
    2.17 +        </dependency>
    2.18 +        <dependency>
    2.19 +            <groupId>${project.groupId}</groupId>
    2.20              <artifactId>visidor</artifactId> 
    2.21              <version>${visidorVersion}</version> 
    2.22          </dependency> 
    2.23 -    </dependencies> 
    2.24 +        <dependency>
    2.25 +            <groupId>cz.xelfi.quoridor</groupId>
    2.26 +            <artifactId>wsdor</artifactId>
    2.27 +            <version>${wsdorVersion}</version>
    2.28 +        </dependency>
    2.29 +        <!-- jersey -->
    2.30 +        <dependency>
    2.31 +          <groupId>com.sun.jersey</groupId>
    2.32 +          <artifactId>jersey-client</artifactId>
    2.33 +          <version>${jerseyVersion}</version>
    2.34 +        </dependency>
    2.35 +        <dependency>
    2.36 +          <groupId>com.sun.jersey</groupId>
    2.37 +          <artifactId>jersey-core</artifactId>
    2.38 +          <version>${jerseyVersion}</version>
    2.39 +        </dependency>
    2.40 +        <dependency>
    2.41 +          <groupId>com.sun.jersey</groupId>
    2.42 +          <artifactId>jersey-json</artifactId>
    2.43 +          <version>${jerseyVersion}</version>
    2.44 +        </dependency>
    2.45 +        <dependency>
    2.46 +            <groupId>javax.ws.rs</groupId>
    2.47 +            <artifactId>jsr311-api</artifactId>
    2.48 +            <type>jar</type>
    2.49 +            <version>1.1.1</version>
    2.50 +        </dependency>
    2.51 +        <dependency>
    2.52 +          <groupId>com.sun.xml.bind</groupId>
    2.53 +          <artifactId>jaxb-impl</artifactId>
    2.54 +          <version>2.2.1.1</version>
    2.55 +        </dependency>
    2.56 +        <dependency>
    2.57 +          <groupId>org.codehaus.jettison</groupId>
    2.58 +          <artifactId>jettison</artifactId>
    2.59 +          <version>1.2</version>
    2.60 +        </dependency>
    2.61 +    </dependencies>
    2.62      <build> 
    2.63          <plugins> 
    2.64              <plugin> 
    2.65                  <groupId>org.codehaus.mojo</groupId> 
    2.66                  <artifactId>nbm-maven-plugin</artifactId> 
    2.67 -                <version>3.2</version> 
    2.68 +                <version>3.3-SNAPSHOT</version>
    2.69                  <extensions>true</extensions> 
    2.70                  <configuration> 
    2.71                      <useOSGiDependencies>true</useOSGiDependencies> 
     3.1 --- a/desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/KukTopComponent.java	Sun Sep 12 21:21:09 2010 +0200
     3.2 +++ b/desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/KukTopComponent.java	Mon Sep 13 16:27:07 2010 +0200
     3.3 @@ -10,7 +10,7 @@
     3.4  import org.netbeans.api.settings.ConvertAsProperties;
     3.5  
     3.6  /**
     3.7 - * Top component which displays something.
     3.8 + * Top component which displays the board.
     3.9   */
    3.10  @ConvertAsProperties(dtd = "-//cz.xelfi.quoridor.desktop.sample//Kuk//EN",
    3.11  autostore = false)
    3.12 @@ -20,13 +20,20 @@
    3.13  //    static final String ICON_PATH = "SET/PATH/TO/ICON/HERE";
    3.14      private static final String PREFERRED_ID = "KukTopComponent";
    3.15  
    3.16 +    private String id;
    3.17 +
    3.18      public KukTopComponent() {
    3.19          initComponents();
    3.20          
    3.21          setName(NbBundle.getMessage(KukTopComponent.class, "CTL_KukTopComponent"));
    3.22          setToolTipText(NbBundle.getMessage(KukTopComponent.class, "HINT_KukTopComponent"));
    3.23  //        setIcon(ImageUtilities.loadImage(ICON_PATH, true));
    3.24 -
    3.25 +        
    3.26 +    }
    3.27 +    
    3.28 +    public void setGameId(String id) {
    3.29 +        this.id = id;
    3.30 +        boardPane1.setBoard(Quoridor.getDefault().getGame(id).getBoard());
    3.31      }
    3.32  
    3.33      /** This method is called from within the constructor to
    3.34 @@ -84,12 +91,17 @@
    3.35          // better to version settings since initial version as advocated at
    3.36          // http://wiki.apidesign.org/wiki/PropertyFiles
    3.37          p.setProperty("version", "1.0");
    3.38 -        // TODO store your settings
    3.39 +        if (id != null) {
    3.40 +            p.setProperty("id", id);
    3.41 +        }
    3.42      }
    3.43  
    3.44      final void readProperties(java.util.Properties p) {
    3.45          String version = p.getProperty("version");
    3.46 -        // TODO read your settings according to their version
    3.47 +        String myId = p.getProperty("id");
    3.48 +        if (myId != null) {
    3.49 +            setGameId(myId);
    3.50 +        }
    3.51      }
    3.52  
    3.53      @Override
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/Quoridor.java	Mon Sep 13 16:27:07 2010 +0200
     4.3 @@ -0,0 +1,54 @@
     4.4 +/*
     4.5 + * To change this template, choose Tools | Templates
     4.6 + * and open the template in the editor.
     4.7 + */
     4.8 +
     4.9 +package cz.xelfi.quoridor.desktop.sample;
    4.10 +
    4.11 +import com.sun.jersey.api.client.Client;
    4.12 +import com.sun.jersey.api.client.GenericType;
    4.13 +import com.sun.jersey.api.client.WebResource;
    4.14 +import cz.xelfi.quoridor.webidor.Game;
    4.15 +import cz.xelfi.quoridor.webidor.GameId;
    4.16 +import java.util.List;
    4.17 +import javax.ws.rs.core.MediaType;
    4.18 +import org.openide.util.Lookup;
    4.19 +
    4.20 +/** Class that connects to the server and answers queries.
    4.21 + *
    4.22 + * @author Jaroslav Tulach
    4.23 + */
    4.24 +abstract class Quoridor {
    4.25 +
    4.26 +    public static Quoridor getDefault() {
    4.27 +        Quoridor q = Lookup.getDefault().lookup(Quoridor.class);
    4.28 +        return q == null ? new Impl() : q;
    4.29 +    }
    4.30 +
    4.31 +    public abstract List<GameId> listGames();
    4.32 +    public abstract Game getGame(String id);
    4.33 +
    4.34 +    private static class Impl extends Quoridor {
    4.35 +        private final WebResource wr;
    4.36 +
    4.37 +        public Impl() {
    4.38 +            Client c = new Client();
    4.39 +            wr = c.resource("http://quoridor.xelfi.cz/api/");
    4.40 +        }
    4.41 +
    4.42 +        @Override
    4.43 +        public List<GameId> listGames() {
    4.44 +            GenericType<List<GameId>> gType = new GenericType<List<GameId>>() {};
    4.45 +            List<GameId> ids = wr.path("games").accept(MediaType.TEXT_XML).get(gType);
    4.46 +            return ids;
    4.47 +        }
    4.48 +
    4.49 +
    4.50 +        @Override
    4.51 +        public Game getGame(String id) {
    4.52 +            Game g = wr.path("games").path(id).accept(MediaType.TEXT_XML).get(Game.class);
    4.53 +            return g;
    4.54 +        }
    4.55 +
    4.56 +    }
    4.57 +}
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/desktop/desktop-sample/src/main/java/cz/xelfi/quoridor/desktop/sample/ShowGames.java	Mon Sep 13 16:27:07 2010 +0200
     5.3 @@ -0,0 +1,22 @@
     5.4 +/*
     5.5 + * To change this template, choose Tools | Templates
     5.6 + * and open the template in the editor.
     5.7 + */
     5.8 +package cz.xelfi.quoridor.desktop.sample;
     5.9 +
    5.10 +import cz.xelfi.quoridor.webidor.GameId;
    5.11 +import java.awt.event.ActionEvent;
    5.12 +import java.awt.event.ActionListener;
    5.13 +
    5.14 +public final class ShowGames implements ActionListener {
    5.15 +
    5.16 +    @Override
    5.17 +    public void actionPerformed(ActionEvent e) {
    5.18 +        for (GameId gameId : Quoridor.getDefault().listGames()) {
    5.19 +            KukTopComponent tc = new KukTopComponent();
    5.20 +            tc.setGameId(gameId.getId());
    5.21 +            tc.setName(gameId.getWhite() + "/" + gameId.getBlack());
    5.22 +            tc.open();
    5.23 +        }
    5.24 +    }
    5.25 +}
     6.1 --- a/desktop/desktop-sample/src/main/resources/cz/xelfi/quoridor/desktop/KukTopComponentSettings.xml	Sun Sep 12 21:21:09 2010 +0200
     6.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.3 @@ -1,12 +0,0 @@
     6.4 -<?xml version="1.0" encoding="UTF-8"?>
     6.5 -<!--
     6.6 -To change this template, choose Tools | Templates
     6.7 -and open the template in the editor.
     6.8 --->
     6.9 -<!DOCTYPE settings PUBLIC "-//NetBeans//DTD Session settings 1.0//EN" "http://www.netbeans.org/dtds/sessionsettings-1_0.dtd">
    6.10 -<settings version="1.0">
    6.11 -    <module name="cz.xelfi.quoridor.desktop.sample" spec="1.0"/>
    6.12 -    <instanceof class="org.openide.windows.TopComponent"/>
    6.13 -    <instanceof class="cz.xelfi.quoridor.desktop.sample.KukTopComponent"/>
    6.14 -    <instance class="cz.xelfi.quoridor.desktop.sample.KukTopComponent" method="getDefault"/>
    6.15 -</settings>
     7.1 --- a/desktop/desktop-sample/src/main/resources/cz/xelfi/quoridor/desktop/KukTopComponentWstcref.xml	Sun Sep 12 21:21:09 2010 +0200
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,11 +0,0 @@
     7.4 -<?xml version="1.0" encoding="UTF-8"?>
     7.5 -<!--
     7.6 -To change this template, choose Tools | Templates
     7.7 -and open the template in the editor.
     7.8 --->
     7.9 -<!DOCTYPE tc-ref PUBLIC "-//NetBeans//DTD Top Component in Mode Properties 2.0//EN" "http://www.netbeans.org/dtds/tc-ref2_0.dtd">
    7.10 -<tc-ref version="2.0" >
    7.11 -    <module name="cz.xelfi.quoridor.desktop.sample" spec="1.0"/>
    7.12 -    <tc-id id="KukTopComponent"/>
    7.13 -    <state opened="true"/>
    7.14 -</tc-ref>
     8.1 --- a/desktop/desktop-sample/src/main/resources/cz/xelfi/quoridor/desktop/layer.xml	Sun Sep 12 21:21:09 2010 +0200
     8.2 +++ b/desktop/desktop-sample/src/main/resources/cz/xelfi/quoridor/desktop/layer.xml	Mon Sep 13 16:27:07 2010 +0200
     8.3 @@ -3,29 +3,29 @@
     8.4  <filesystem>
     8.5   
     8.6      <folder name="Actions">
     8.7 -        <folder name="Window">
     8.8 -            <file name="cz-xelfi-quoridor-desktop-sample-KukAction.instance">
     8.9 -                <attr name="component" methodvalue="cz.xelfi.quoridor.desktop.sample.KukTopComponent.findInstance"/>
    8.10 -                <attr name="displayName" bundlevalue="cz.xelfi.quoridor.desktop.sample.Bundle#CTL_KukAction"/>
    8.11 -                <attr name="instanceCreate" methodvalue="org.openide.windows.TopComponent.openAction"/>
    8.12 +        <folder name="Edit">
    8.13 +            <file name="cz-xelfi-quoridor-desktop-sample-ShowGames.instance">
    8.14 +                <attr name="delegate" newvalue="cz.xelfi.quoridor.desktop.sample.ShowGames"/>
    8.15 +                <attr name="displayName" bundlevalue="cz.xelfi.quoridor.desktop.sample.Bundle#CTL_ShowGames"/>
    8.16 +                <attr name="instanceCreate" methodvalue="org.openide.awt.Actions.alwaysEnabled"/>
    8.17 +                <attr name="noIconInMenu" boolvalue="false"/>
    8.18              </file>
    8.19          </folder>
    8.20      </folder>
    8.21      <folder name="Menu">
    8.22 -        <folder name="Window">
    8.23 -            <file name="KukAction.shadow">
    8.24 -                <attr name="originalFile" stringvalue="Actions/Window/cz-xelfi-quoridor-desktop-sample-KukAction.instance"/>
    8.25 +        <folder name="File">
    8.26 +            <file name="cz-xelfi-quoridor-desktop-sample-ShowGames.shadow">
    8.27 +                <attr name="originalFile" stringvalue="Actions/Edit/cz-xelfi-quoridor-desktop-sample-ShowGames.instance"/>
    8.28 +                <attr name="position" intvalue="1300"/>
    8.29              </file>
    8.30          </folder>
    8.31      </folder>
    8.32 -    <folder name="Windows2">
    8.33 -        <folder name="Components">
    8.34 -            <file name="KukTopComponent.settings" url="KukTopComponentSettings.xml"/>
    8.35 -        </folder>
    8.36 -        <folder name="Modes">
    8.37 -            <folder name="output">
    8.38 -                <file name="KukTopComponent.wstcref" url="KukTopComponentWstcref.xml"/>
    8.39 -            </folder>
    8.40 +    <folder name="Toolbars">
    8.41 +        <folder name="File">
    8.42 +            <file name="cz-xelfi-quoridor-desktop-sample-ShowGames.shadow">
    8.43 +                <attr name="originalFile" stringvalue="Actions/Edit/cz-xelfi-quoridor-desktop-sample-ShowGames.instance"/>
    8.44 +                <attr name="position" intvalue="1300"/>
    8.45 +            </file>
    8.46          </folder>
    8.47      </folder>
    8.48  </filesystem>
     9.1 --- a/desktop/desktop-sample/src/main/resources/cz/xelfi/quoridor/desktop/sample/Bundle.properties	Sun Sep 12 21:21:09 2010 +0200
     9.2 +++ b/desktop/desktop-sample/src/main/resources/cz/xelfi/quoridor/desktop/sample/Bundle.properties	Mon Sep 13 16:27:07 2010 +0200
     9.3 @@ -2,4 +2,5 @@
     9.4  CTL_KukAction=Kuk
     9.5  CTL_KukTopComponent=Kuk Window
     9.6  CTL_OpenGameAction=Open a game
     9.7 +CTL_ShowGames=Show Games
     9.8  HINT_KukTopComponent=This is a Kuk window