From: Joonas Lehtinen Date: Fri, 12 Jan 2007 13:50:21 +0000 (+0000) Subject: Removed not-well-working demos to fix #195 (they can be restored when we have time... X-Git-Tag: 6.7.0.beta1~6763 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0c6ebfaa849cd35696daee80bbb018cb57937fe4;p=vaadin-framework.git Removed not-well-working demos to fix #195 (they can be restored when we have time to polish them) svn changeset:250/svn branch:toolkit --- diff --git a/src/com/itmill/toolkit/demo/AjaxChat.java b/src/com/itmill/toolkit/demo/AjaxChat.java deleted file mode 100644 index efeb23b823..0000000000 --- a/src/com/itmill/toolkit/demo/AjaxChat.java +++ /dev/null @@ -1,179 +0,0 @@ -package com.itmill.toolkit.demo; - -import java.io.*; -import java.util.*; -import java.lang.ref.WeakReference; - -import com.itmill.toolkit.ui.*; -import com.itmill.toolkit.data.*; -import com.itmill.toolkit.demo.features.PropertyPanel; - -/** Chat example application. - * - *

This example application implements Internet chatroom with the - * following features: - *

- *

- * - * @see com.itmill.toolkit.Application - * @see com.itmill.toolkit.ui.FrameWindow - * @see com.itmill.toolkit.terminal.StreamResource - */ - -public class AjaxChat - extends com.itmill.toolkit.Application - implements Button.ClickListener { - - /** Login name / Alias for chat */ - private TextField loginName = new TextField("Your name?", ""); - - /** Login button */ - private Button loginButton = new Button("Enter chat"); - - /** Text to be said to discussion */ - private TextField sayText = new TextField(); - - /** Button for sending the sayTest to discussion */ - private Button say = new Button("Say"); - - private static Tree userlist = new Tree("Users"); - - private static Panel messagePane; - - private ProgressIndicator connectionstatus; - - private static int msgCount = 1; - - private static final int MSG_PER_PAGE = 10; - - private Window main = new Window("Ajax chat example", - new OrderedLayout(OrderedLayout.ORIENTATION_VERTICAL)); - - private Item userObject; - - private Button leaveButton; - - /** Initialize the chat application */ - public void init() { - setMainWindow(main); - - if(messagePane == null) { - messagePane = new Panel(); - messagePane.setCaption("Messages:"); - messagePane.addComponent(new ChatMessage("SERVER", "Chat started")); - } - - - // Initialize user interface - say.dependsOn(sayText); - say.addListener((Button.ClickListener) this); - Panel controls = - new Panel( - "", - new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL)); - controls.addComponent(sayText); - sayText.setColumns(40); - controls.addComponent(say); - controls.addComponent(loginName); - loginName.focus(); - controls.addComponent(loginButton); - loginButton.dependsOn(loginName); - loginButton.addListener(this); - leaveButton = new Button("Leave", this, "leave"); - controls.addComponent(leaveButton); - say.setVisible(false); - sayText.setVisible(false); - - this.connectionstatus = new ProgressIndicator(); - this.connectionstatus.setIndeterminate(true); - this.connectionstatus.setPollingInterval(2000); // check for new messages every 2 seconds - main.addComponent(this.connectionstatus); - main.addComponent(controls); - main.addComponent(messagePane); - main.addComponent(userlist); - - } - - /** Handle button actions for login, user listing and saying */ - public void buttonClick(Button.ClickEvent event) { - - // Say something in discussion - if (event.getSource() == say && sayText.toString().length() > 0) { - - // Say something to chatstream - say(sayText.toString()); - - // Clear the saytext field - sayText.setValue(""); - sayText.focus(); - } - - // Login to application - else if ( - event.getSource() == loginButton - && loginName.toString().length() > 0) { - - // Set user name - setUser(loginName.toString()); - //TODO remove elements older than ten posts - - userlist.addItem(loginName.toString()); - - // Hide logins controls - loginName.setVisible(false); - loginButton.setVisible(false); - - // Show say controls - say.setVisible(true); - sayText.setVisible(true); - sayText.focus(); - say("[Joining chat]"); - - } - } - - - /** Add message to messages table */ - private void say(String text) { - if(text != "") { - synchronized(messagePane) { - msgCount++; - messagePane.addComponent(new ChatMessage(this.loginName.toString(), text)); - if(msgCount > MSG_PER_PAGE) { - Label firstMessage = (Label) messagePane.getComponentIterator().next(); - messagePane.removeComponent(firstMessage); - } - } - } - } - - - - /** Leave the chat */ - public void leave() { - say("[Leaving chat]"); - userlist.removeItem(loginName.toString()); - this.loginName.setVisible(true); - this.loginButton.setVisible(true); - - this.sayText.setVisible(false); - this.say.setVisible(false); - this.leaveButton.setVisible(false); - } - - /** Make sure that everybody leaves the chat */ - public void finalize() { - leave(); - } - - private class ChatMessage extends Label { - ChatMessage(String s, String m) { - super( ""+(new Date()).toString()+ - "
"+ - s+": " + - m +"
"); - this.setContentMode(Label.CONTENT_XHTML); - } - } -} diff --git a/src/com/itmill/toolkit/demo/Chat.java b/src/com/itmill/toolkit/demo/Chat.java deleted file mode 100644 index a780dfce63..0000000000 --- a/src/com/itmill/toolkit/demo/Chat.java +++ /dev/null @@ -1,296 +0,0 @@ -package com.itmill.toolkit.demo; - -import java.io.*; -import java.util.*; -import java.lang.ref.WeakReference; - -import com.itmill.toolkit.terminal.StreamResource; -import com.itmill.toolkit.ui.*; - -/** Chat example application. - * - *

This example application implements Internet chatroom with the - * following features: - *

- *

- * - * @see com.itmill.toolkit.Application - * @see com.itmill.toolkit.ui.FrameWindow - * @see com.itmill.toolkit.terminal.StreamResource - */ - -public class Chat - extends com.itmill.toolkit.Application - implements StreamResource.StreamSource, Button.ClickListener { - - /** Linked list of Chat applications who participate the discussion */ - private static LinkedList chatters = new LinkedList(); - - /** Reference (to this application) stored in chatters list */ - private WeakReference listEntry = null; - - /** Writer for writing to open chat stream */ - private PrintWriter chatWriter = null; - - /** Login name / Alias for chat */ - private TextField loginName = new TextField("Your name?", ""); - - /** Login button */ - private Button loginButton = new Button("Enter chat"); - - /** Text to be said to discussion */ - private TextField sayText = new TextField(); - - /** Button for sending the sayTest to discussion */ - private Button say = new Button("Say"); - - /** Button for listing the people in the chatroom */ - private Button listUsers = new Button("List chatters"); - - /** Last time this chat application said something */ - private long idleSince = (new Date()).getTime(); - - /** framewindow for following the discussion and control */ - FrameWindow frames = new FrameWindow("Chat"); - - /** Last messages */ - private static LinkedList lastMessages = new LinkedList(); - - /** Initialize the chat application */ - public void init() { - - // Initialize user interface - say.dependsOn(sayText); - say.addListener((Button.ClickListener) this); - listUsers.addListener((Button.ClickListener) this); - StreamResource chatStream = - new StreamResource(this, "discussion.html", this); - chatStream.setBufferSize(1); - chatStream.setCacheTime(0); - frames.getFrameset().newFrame(chatStream, "chatDiscussion"); - Window controls = - new Window( - "", - new OrderedLayout(OrderedLayout.ORIENTATION_HORIZONTAL)); - controls.setName("chatControls"); - controls.addComponent(sayText); - sayText.setColumns(40); - controls.addComponent(say); - controls.addComponent(loginName); - loginName.focus(); - controls.addComponent(loginButton); - loginButton.dependsOn(loginName); - loginButton.addListener(this); - controls.addComponent(listUsers); - Button leaveButton = new Button("Leave", this, "leave"); - controls.addComponent(leaveButton); - say.setVisible(false); - sayText.setVisible(false); - frames.getFrameset().newFrame(controls).setAbsoluteSize(60); - frames.getFrameset().setVertical(true); - frames.setName("chatMain"); - setMainWindow(frames); - - // Register chat application - synchronized (chatters) { - chatters.add(listEntry = new WeakReference(this)); - } - } - - /** Handle button actions for login, user listing and saying */ - public void buttonClick(Button.ClickEvent event) { - - // Say something in discussion - if (event.getSource() == say && sayText.toString().length() > 0) { - - // Say something to chatstream - say("" + getUser() + ": " + sayText + "
"); - - // Clear the saytext field - sayText.setValue(""); - sayText.focus(); - } - - // List the users - else if (event.getSource() == listUsers) - listUsers(); - - // Login to application - else if ( - event.getSource() == loginButton - && loginName.toString().length() > 0) { - - // Set user name - setUser(loginName.toString()); - - // Hide logins controls - loginName.setVisible(false); - loginButton.setVisible(false); - - // Show say controls - say.setVisible(true); - sayText.setVisible(true); - sayText.focus(); - - // Announce discussion joining - say( - "" - + getUser() - + " joined the discussion (" - + (new Date()).toString() - + ")
"); - } - } - - /** List chatters to chat stream */ - private void listUsers() { - - // Compose userlist - StringBuffer userlist = new StringBuffer(); - userlist.append( - "
Chatters (" - + (new Date()) - + ")
\n"); - - // Print the user list to chatstream - printToStream(userlist.toString()); - } - - /** Print to chatstream and scroll the window */ - private void printToStream(String text) { - if (chatWriter != null) { - chatWriter.println(text); - chatWriter.println("\n"); - chatWriter.flush(); - } - } - - /** Say to all chat streams */ - private void say(String text) { - - // Get all the listeners - Object[] listener; - synchronized (chatters) { - listener = chatters.toArray(); - } - - // Put the saytext to listener streams - // Remove dead listeners - for (int i = 0; i < listener.length; i++) { - Chat c = (Chat) ((WeakReference) listener[i]).get(); - if (c != null) - c.printToStream(text); - else - chatters.remove(listener[i]); - } - - // Update idle time - idleSince = (new Date()).getTime(); - - // Update last messages - synchronized (lastMessages) { - lastMessages.addLast(text); - while (lastMessages.size() > 5) - lastMessages.removeFirst(); - } - } - - /** Open chat stream */ - public InputStream getStream() { - - // Close any existing streams - if (chatWriter != null) - chatWriter.close(); - - // Create piped stream - PipedOutputStream chatStream = new PipedOutputStream(); - chatWriter = new PrintWriter(chatStream); - InputStream is = null; - try { - is = new PipedInputStream(chatStream); - } catch (IOException ignored) { - chatWriter = null; - return null; - }; - - // Write headers - printToStream( - "Discussion " - + (new Date()) - + "" - + "\n"); - - // Print last messages - Object[] msgs; - synchronized (lastMessages) { - msgs = lastMessages.toArray(); - } - for (int i = 0; i < msgs.length; i++) - printToStream(msgs[i].toString()); - - // Allways list the users - listUsers(); - - return is; - } - - /** Leave the chat */ - public void leave() { - - // If we have been logged in, say goodbye - if (listEntry != null) { - if (getUser() != null) - say( - "" - + getUser() - + " left the chat (" - + (new Date()) - + ")
"); - - synchronized (chatters) { - chatters.remove(listEntry); - listEntry = null; - } - } - if (chatWriter != null) - chatWriter.close(); - - // Close the chat frames - if (frames != null) { - frames.getFrameset().removeAllFrames(); - Window restartWin = new Window(); - frames.getFrameset().newFrame(restartWin); - restartWin.addComponent(new Button("Restart chat", this, "close")); - frames = null; - } - } - - /** Make sure that everybody leaves the chat */ - public void finalize() { - leave(); - } - -} diff --git a/src/com/itmill/toolkit/demo/Login.java b/src/com/itmill/toolkit/demo/Login.java deleted file mode 100644 index 81064cca4e..0000000000 --- a/src/com/itmill/toolkit/demo/Login.java +++ /dev/null @@ -1,136 +0,0 @@ -package com.itmill.toolkit.demo; - -import com.itmill.toolkit.Application; -import com.itmill.toolkit.data.*; -import com.itmill.toolkit.ui.*; - -/**

Example application demonstrating simple user login.

- * - * @author IT Mill Ltd. - * @see com.itmill.toolkit.service.Application - * @see com.itmill.toolkit.ui.Window - * @see com.itmill.toolkit.ui.TextField - * @see com.itmill.toolkit.ui.Button - */ -public class Login - extends Application - implements Property.ValueChangeListener { - - /* Menu for navigating inside the application. */ - private Tree menu = new Tree(); - - /* Contents of the website */ - private String[][] pages = { { "Welcome", "Welcome to our website..." }, { - "Products", "Public product information." }, { - "Contact", "Public contact information." }, { - "CRM", "CRM Database requiring login." }, { - "Intranet", "Internal information database." } - }; - - /* Application layout */ - private GridLayout layout = new GridLayout(2, 1); - - /* Initialize the application */ - public void init() { - - // Create the main window of the application - Window main = new Window("Login example", layout); - setMainWindow(main); - - // Add menu and loginbox to the application - OrderedLayout l = new OrderedLayout(); - layout.addComponent(l, 0, 0); - l.addComponent(menu); - l.addComponent(new LoginBox()); - - // Setup menu - menu.setStyle("menu"); - menu.addListener(this); - menu.setImmediate(true); - addToMenu(new String[] {"Welcome","Products","Contact"}); - } - - // Overriding usetUser method is a simple way of updating application - // privileges when the user is changed - public void setUser(Object user) { - super.setUser(user); - if (user != null) - addToMenu(new String[] {"CRM","Intranet"}); - } - - public void addToMenu(String[] items) { - for (int i=0; i 0) - setUser(name); - loginName.setValue(""); - } - - // Update login status on application user change events - public void applicationUserChanged(Application.UserChangeEvent event) { - updateStatus(); - } - - // Update login status of the component by exposing correct components - private void updateStatus() { - statusLabel.setValue("User: " + getUser()); - if (getUser() != null) - setCompositionRoot(statusPanel); - else - setCompositionRoot(loginPanel); - } - } -} diff --git a/src/com/itmill/toolkit/demo/gogame/Board.java b/src/com/itmill/toolkit/demo/gogame/Board.java deleted file mode 100644 index db37d1262b..0000000000 --- a/src/com/itmill/toolkit/demo/gogame/Board.java +++ /dev/null @@ -1,107 +0,0 @@ -package com.itmill.toolkit.demo.gogame; - -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.StringTokenizer; - -import com.itmill.toolkit.terminal.PaintException; -import com.itmill.toolkit.terminal.PaintTarget; -import com.itmill.toolkit.ui.AbstractComponent; - -public class Board extends AbstractComponent implements Game.Listener { - - // The game. - private Game game; - - // Players color. - private boolean playerPlaysBlack; - - // Last played coordinates. - private int lastX = -1; - private int lastY = -1; - - /** Creates board for the specified game, assuming the player plays - * the specified color. - */ - public Board(Game game, boolean playerPlaysBlack) { - this.game = game; - this.playerPlaysBlack = playerPlaysBlack; - game.addGameListener(this); - } - - /** Called on variable change. If the 'move' variable is found, a stone - * is placed for the player accordingly. - */ - public void changeVariables(Object source, Map variables) { - if (variables.containsKey("move")) { - StringTokenizer st = - new StringTokenizer((String) variables.get("move"), ","); - try { - int i = Integer.valueOf(st.nextToken()).intValue(); - int j = Integer.valueOf(st.nextToken()).intValue(); - game.addStone(i, j, playerPlaysBlack); - } catch (NumberFormatException ignore) { - } catch (NoSuchElementException ignore) { - } - } - } - - /** Tag for XML output. - */ - public String getTag() { - return "goboard"; - } - - - /** Paint the board to XML. - */ - public void paintContent(PaintTarget target) throws PaintException { - target.addAttribute("xmlns", "GO Sample Namespace"); - target.addAttribute("whitename", game.getWhitePlayer()); - target.addAttribute("blackname", game.getBlackPlayer()); - target.addAttribute("moves", game.getMoves()); - target.addAttribute("whitescaptured", game.getCapturedWhiteStones()); - target.addAttribute("blackscaptured", game.getCapturedBlackStones()); - int[][] state = game.getState(); - for (int j = 0; j < state.length; j++) { - target.startTag("row"); - for (int i = 0; i < state.length; i++) { - target.startTag("col"); - if (state[i][j] == Game.EMPTY) - target.addAttribute("move", "" + i + "," + j); - else { - if (i == lastX && j == lastY) - target.addAttribute( - "stone", - state[i][j] == Game.BLACK - ? "black-last" - : "white-last"); - else - target.addAttribute( - "stone", - state[i][j] == Game.BLACK ? "black" : "white"); - } - target.endTag("col"); - } - target.endTag("row"); - } - - target.addVariable(this, "move", ""); - } - - /** Destructor. - */ - protected void finalize() throws Throwable { - super.finalize(); - if (game != null) - game.removeGameListener(this); - } - - /** Implementing the Game.Listener interface, called when a stone is added. - */ - public void stoneIsAdded(Game game, int i, int j, boolean isBlack) { - lastX = i; - lastY = j; - requestRepaint(); - } -} diff --git a/src/com/itmill/toolkit/demo/gogame/Game.java b/src/com/itmill/toolkit/demo/gogame/Game.java deleted file mode 100644 index 5e5a8d1fe2..0000000000 --- a/src/com/itmill/toolkit/demo/gogame/Game.java +++ /dev/null @@ -1,223 +0,0 @@ -package com.itmill.toolkit.demo.gogame; - -import java.util.Iterator; -import java.util.LinkedList; - -public class Game { - - // States for the positions on the game board. - /** Empty position. */ - public static final int EMPTY = 0; - /** Black stone. */ - public static final int BLACK = 1; - /** White stone */ - public static final int WHITE = 2; - - // Two-dimentionel array holding the current state of the game. - private int[][] state; - - // List of listeners listening to game events. - private LinkedList listeners = new LinkedList(); - - // Names of the players. - private String blackPlayer; - private String whitePlayer; - - // Number of moves made so far. - private int moves = 0; - - // Number of captured stones - private int captured[] = { 0, 0, 0 }; - - /** Creates a new game with the specified board size and player names. - */ - public Game(int boardSize, String blackPlayer, String whitePlayer) { - - // Assign player names. - this.blackPlayer = blackPlayer; - this.whitePlayer = whitePlayer; - - // Initialize board. - state = new int[boardSize][boardSize]; - for (int i = 0; i < boardSize; i++) - for (int j = 0; j < boardSize; j++) - state[i][j] = EMPTY; - } - - /** Gets the current state of the game as a two-dimentional array - * representing the board, with the states Game.EMPTY, Game.BLACK - * and Game.WHITE. - */ - public int[][] getState() { - return state; - } - - /** Adds a black or white stone to the specified position on the - * board. - */ - public void addStone(int i, int j, boolean isBlack) { - if (state[i][j] == EMPTY) { - state[i][j] = isBlack ? BLACK : WHITE; - moves++; - removeDeadStonesAround(i, j); - for (Iterator li = listeners.iterator(); li.hasNext();) - ((Game.Listener) li.next()).stoneIsAdded(this, i, j, isBlack); - } - } - - /** Adds a listener to the list of listeners - */ - public void addGameListener(Game.Listener listener) { - listeners.add(listener); - } - - /** Removes a listener from the list of listeners. - */ - public void removeGameListener(Game.Listener listener) { - listeners.remove(listener); - } - - /** Interface for implementing a listener listening to Go-game events. - */ - public interface Listener { - /** Called whenever a stone is added to the game. - */ - public void stoneIsAdded(Game game, int i, int j, boolean isBlack); - } - - /** This function returns the state of the game as a string. - */ - public String toString() { - return blackPlayer - + " (Black) vs. " - + whitePlayer - + " (White) (" - + state.length - + "x" - + state[0].length - + ", " - + moves - + " moves done" - + (captured[WHITE] > 0 - ? (", Black has captured " + captured[WHITE] + " stones") - : "") - + (captured[BLACK] > 0 - ? (", White has captured " + captured[BLACK] + " stones") - : "") - + ")"; - } - - /** Gets the black player's name. - */ - public String getBlackPlayer() { - return blackPlayer; - } - - /** Gets the number of moves so far. - */ - public int getMoves() { - return moves; - } - - /** Gets the white player's name. - */ - public String getWhitePlayer() { - return whitePlayer; - } - - /** Remove dead stones. Removes stones that are dead as - * defined by the rules of go. The state is only checked for - * the four stones surrounding the last stone added */ - private void removeDeadStonesAround(int lastx, int lasty) { - - // Remove possible victims of attack - removeIfDead(lastx - 1, lasty, lastx, lasty); - removeIfDead(lastx + 1, lasty, lastx, lasty); - removeIfDead(lastx, lasty + 1, lastx, lasty); - removeIfDead(lastx, lasty - 1, lastx, lasty); - - // Remove stones on suicide - removeIfDead(lastx, lasty, -1, -1); - } - - /** Remove area, if it is dead. This fairly complicated algorithm - * tests if area starting from (x,y) is dead and removes it in - * such case. The last stone (lastx,lasty) is always alive. */ - private void removeIfDead(int x, int y, int lastx, int lasty) { - - // Only check the stones on the board - int width = state.length; - int height = state[0].length; - if (x < 0 || y < 0 || x >= width || y >= width) - return; - - // Not dead if empty of same color than the last stone - int color = state[x][y]; - if (color == EMPTY - || (lastx >= 0 && lasty >= 0 && color == state[lastx][lasty])) - return; - - // Check areas by growing - int checked[][] = new int[state.length][state[0].length]; - checked[x][y] = color; - while (true) { - boolean stillGrowing = false; - for (int i = 0; i < width; i++) - for (int j = 0; j < height; j++) - for (int o = 0; o < 4; o++) - if (checked[i][j] == EMPTY) { - int nx = i; - int ny = j; - switch (o) { - case 0 : - nx++; - break; - case 1 : - nx--; - break; - case 2 : - ny++; - break; - case 3 : - ny--; - break; - } - if (nx >= 0 - && ny >= 0 - && nx < width - && ny < height - && checked[nx][ny] == color) { - checked[i][j] = state[i][j]; - if (checked[i][j] == color) - stillGrowing = true; - else if (checked[i][j] == EMPTY) - - // Freedom found - return; - } - - } - // If the area stops growing and no freedoms found, - // it is dead. Remove it - if (!stillGrowing) { - for (int i = 0; i < width; i++) - for (int j = 0; j < height; j++) - if (checked[i][j] == color) { - state[i][j] = EMPTY; - captured[color]++; - } - return; - } - } - } - - /** Get the number of white stones captures */ - public int getCapturedWhiteStones() { - return captured[WHITE]; - } - - /** Get the number of black stones captures */ - public int getCapturedBlackStones() { - return captured[BLACK]; - } -} diff --git a/src/com/itmill/toolkit/demo/gogame/Go.java b/src/com/itmill/toolkit/demo/gogame/Go.java deleted file mode 100644 index b87c9ecd72..0000000000 --- a/src/com/itmill/toolkit/demo/gogame/Go.java +++ /dev/null @@ -1,168 +0,0 @@ -package com.itmill.toolkit.demo.gogame; - -import com.itmill.toolkit.Application; -import com.itmill.toolkit.data.Item; -import com.itmill.toolkit.data.Property; -import com.itmill.toolkit.data.util.IndexedContainer; -import com.itmill.toolkit.event.*; -import com.itmill.toolkit.ui.*; - -/** The classic game 'Go' as an example for the IT Mill Toolkit. - * - * @author IT Mill Ltd. - * @see com.itmill.toolkit.Application - */ -public class Go - extends Application - implements Action.Handler, Property.ValueChangeListener { - - /* An IndexedContainer will hold the list of players - it can be - * displayed directly by the 'Table' ui component. */ - private static IndexedContainer players = new IndexedContainer(); - - // This action will be triggered when a player challenges another. - private static Action challengeAction = new Action("Challenge", null); - - // The players can have a current game. - static { - players.addContainerProperty("Current game", Game.class, null); - } - - // The layout - private CustomLayout layout = new CustomLayout("goroom"); - - // Label to be displayed in the login window. - private TextField loginName = new TextField("Who are you stranger?", ""); - - // Button for leaving the game - private Button leaveButton = new Button("Leave game", this, "close"); - - // Button for logging in - private Button loginButton = new Button("Enter game", this, "login"); - - - // A 'Table' ui component will be used to show the list of players. - private Table playersTable; - - // Our Go-board ('Board') component. - private Board board = null; - - /** The initialization method that is the only requirement for - * inheriting the com.itmill.toolkit.service.Application class. It will - * be automatically called by the framework when a user accesses the - * application. - * We'll initialize our components here. - */ - public void init() { - - // Use the GO theme that includes support for goboard component - // and goroom layout - setTheme("gogame"); - - // Initialize main window with created layout - addWindow(new Window("Game of GO",layout)); - - // Xreate a table for showing the players in the IndexedContainer 'players'. - playersTable = new Table("Players", players); - playersTable.setRowHeaderMode(Table.ROW_HEADER_MODE_ID); - playersTable.setColumnHeaderMode(Table.COLUMN_HEADER_MODE_ID); - playersTable.addActionHandler(this); - playersTable.setPageBufferingEnabled(false); - - // Add the Table and a Button to the main window. - layout.addComponent(playersTable,"players"); - layout.addComponent(leaveButton,"logoutbutton"); - - // Hide game components - leaveButton.setVisible(false); - playersTable.setVisible(false); - - // Add login functionality - layout.addComponent(loginName,"loginname"); - loginButton.dependsOn(loginName); - layout.addComponent(loginButton,"loginbutton"); - } - - /** This function is called when a player tries to log in. - */ - public void login() { - String name = loginName.toString(); - if (name.length() > 0 && !players.containsId(name)) { - - // Login successful - setUser(name); - - // Add user to player list. - Item user = players.addItem(name); - ((Property.ValueChangeNotifier) - user.getItemProperty("Current game")).addListener(this); - - // Update visible components - layout.removeComponent(loginName); - layout.removeComponent(loginButton); - leaveButton.setVisible(true); - playersTable.setVisible(true); - } - } - - // On logout, remove user from the player list - public void close() { - if (getUser() != null) { - - // Remove user from the player list. - players.removeItem(getUser()); - } - super.close(); - } - - - /** Implementing the Action.Handler interface - this function returns - * the available actions. - * @see com.itmill.toolkit.event.Action.Handler - */ - public Action[] getActions(Object target, Object source) { - Property p = players.getContainerProperty(target, "Current game"); - if (p != null && target != null && !target.equals(getUser())) { - Game game = (Game) p.getValue(); - if (game == null) { - return new Action[] { challengeAction }; - } - } - - return new Action[] { - }; - } - - /** Implementing the Action.Handler interface - this function handles - * the specified action. - * @see com.itmill.toolkit.event.Action.Handler - */ - public void handleAction(Action action, Object sender, Object target) { - if (action == challengeAction) { - Property p = players.getContainerProperty(target, "Current game"); - if (p != null && target != null && !target.equals(getUser())) { - Game game = (Game) p.getValue(); - if (game == null) { - game = new Game(9, (String) getUser(), (String) target); - p.setValue(game); - players.getContainerProperty(getUser(), "Current game").setValue( - game); - } - } - } - } - - /** Implementing the Property.ValueChangeListener interface - this function - * is called when a value change event occurs. - * @see com.itmill.toolkit.data.Property.ValueChangeListener - */ - public void valueChange(Property.ValueChangeEvent event) { - if (board != null) - layout.removeComponent(board); - Game game = (Game) event.getProperty().getValue(); - if (game != null) { - board = new Board(game, game.getBlackPlayer() == getUser()); - layout.addComponent(board,"board"); - } - } -} diff --git a/src/com/itmill/toolkit/demo/package.html b/src/com/itmill/toolkit/demo/package.html index a3368e0b28..d9bb6824f7 100644 --- a/src/com/itmill/toolkit/demo/package.html +++ b/src/com/itmill/toolkit/demo/package.html @@ -5,8 +5,6 @@ - -

Provides several fully functional IT Mill Toolkit example applications. These highlight certain aspects of the toolkit and how it can be used to produce simple, elegant yet powerful user interface driven @@ -20,11 +18,5 @@ demonstrates how to build a bit more complicated user interface and how the application can interact with the usern through that interface. - - - - - -