From 74d8205f30732a8afd6aa45f859188b0a3d447e5 Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Mon, 20 Jun 2011 04:39:54 +0200 Subject: Kommentare, Kommentare git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@509 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/RoundControl.java | 7 +- .../control/network/GameOfferControl.java | 36 ++++---- src/jrummikub/control/network/NetworkControl.java | 17 ++-- src/jrummikub/control/turn/AIControl.java | 16 ++-- src/jrummikub/control/turn/ITurnControl.java | 22 +++-- src/jrummikub/model/GameSettings.java | 5 ++ src/jrummikub/model/IPlayer.java | 26 +++++- src/jrummikub/model/IStoneTray.java | 17 ++-- src/jrummikub/view/IConnectPanel.java | 15 ++++ src/jrummikub/view/IQuitWarningPanel.java | 27 ++++++ src/jrummikub/view/IView.java | 95 +++++++++++++++------- src/jrummikub/view/LoginError.java | 17 ++-- src/jrummikub/view/impl/ConnectPanel.java | 11 ++- src/jrummikub/view/impl/QuitWarningPanel.java | 14 +++- src/jrummikub/view/impl/View.java | 25 +++--- 15 files changed, 254 insertions(+), 96 deletions(-) (limited to 'src/jrummikub') diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java index 2936627..ba0fa2a 100644 --- a/src/jrummikub/control/RoundControl.java +++ b/src/jrummikub/control/RoundControl.java @@ -1,6 +1,6 @@ package jrummikub.control; -import static jrummikub.model.PlayerSettings.Type.*; +import static jrummikub.model.PlayerSettings.Type.HUMAN; import java.util.ArrayList; import java.util.Collections; @@ -64,6 +64,11 @@ public class RoundControl { this.view = view; } + /** + * Is emitted in network when a new turn starts + * + * @return the event + */ public IEvent1 getRoundStateUpdateEvent() { return roundStateUpdateEvent; } diff --git a/src/jrummikub/control/network/GameOfferControl.java b/src/jrummikub/control/network/GameOfferControl.java index 42e3b8b..b513170 100644 --- a/src/jrummikub/control/network/GameOfferControl.java +++ b/src/jrummikub/control/network/GameOfferControl.java @@ -36,6 +36,27 @@ public class GameOfferControl extends AbstractGameBeginControl { super(connectionControl, view, new GameData(UUID.randomUUID(), settings), SettingsMode.NETWORK_OFFER); + addConnectionControlListeners(connectionControl, settings); + + connections.add(view.getSettingsPanel().getStartGameEvent() + .add(new IListener() { + @Override + public void handle() { + List players = gameData.getGameSettings() + .getPlayerList(); + for (PlayerSettings s : players) { + if (s.getType() == Type.NETWORK) { + startGame(); + return; + } + } + } + })); + } + + private void addConnectionControlListeners( + final IConnectionControl connectionControl, + final GameSettings settings) { connections.add(connectionControl.getGameJoinEvent().add( new IListener1() { @Override @@ -71,21 +92,6 @@ public class GameOfferControl extends AbstractGameBeginControl { connectionControl.offerGame(gameData); } })); - - connections.add(view.getSettingsPanel().getStartGameEvent() - .add(new IListener() { - @Override - public void handle() { - List players = gameData.getGameSettings() - .getPlayerList(); - for (PlayerSettings s : players) { - if (s.getType() == Type.NETWORK) { - startGame(); - return; - } - } - } - })); } /** diff --git a/src/jrummikub/control/network/NetworkControl.java b/src/jrummikub/control/network/NetworkControl.java index 0d0fbe9..4c03923 100644 --- a/src/jrummikub/control/network/NetworkControl.java +++ b/src/jrummikub/control/network/NetworkControl.java @@ -57,11 +57,11 @@ public class NetworkControl { * Creates a new network control * * @param loginData - * user's login data + * user's login data * @param connectionControl - * current connection for events and messages + * current connection for events and messages * @param view - * for events and handlers + * for events and handlers */ public NetworkControl(final LoginData loginData, IConnectionControl connectionControl, SaveControl saveControl, @@ -108,7 +108,7 @@ public class NetworkControl { * Adds the listeners for connection control events * * @param view - * view for events + * view for events */ public void addConnectionControlListeners(final IView view) { connections.add(connectionControl.getGameOfferEvent().add( @@ -260,6 +260,12 @@ public class NetworkControl { return stopNetworkEvent; } + /** + * The back to login event is emitted when the player aborted the connecting + * process or when a connection error has occured and been acknowledged + * + * @return the event + */ public IEvent getBackToLoginEvent() { return backToLoginEvent; } @@ -293,7 +299,8 @@ public class NetworkControl { if (gameOfferControl != null) { return; } - gameOfferControl = new GameOfferControl(connectionControl, settings, view); + gameOfferControl = new GameOfferControl(connectionControl, settings, + view); gameOfferControl.getBackEvent().add(new IListener() { @Override public void handle() { diff --git a/src/jrummikub/control/turn/AIControl.java b/src/jrummikub/control/turn/AIControl.java index ba222ea..8bcf661 100644 --- a/src/jrummikub/control/turn/AIControl.java +++ b/src/jrummikub/control/turn/AIControl.java @@ -21,6 +21,9 @@ import jrummikub.util.Pair; */ public class AIControl extends AbstractTurnControl { private TurnLogic logic; + /** + * Does the AI control currently use an internal timer + */ public static boolean useBackgroundThread = true; long startTime; @@ -63,7 +66,7 @@ public class AIControl extends AbstractTurnControl { turnDone = true; super.cleanUp(); } - + @Override public void abortTurn() { aborted = true; @@ -160,8 +163,8 @@ public class AIControl extends AbstractTurnControl { for (StoneSet set : result) { turnInfo.getTable().drop( set, - new Position(10 * (Math.random() * 2 - 1), - 5 * (Math.random() * 2 - 1))); + new Position(10 * (Math.random() * 2 - 1), 5 * (Math + .random() * 2 - 1))); for (Stone stone : set) { turnInfo.getHand().pickUp(stone); } @@ -173,10 +176,11 @@ public class AIControl extends AbstractTurnControl { private void doNotMoveExistingSets(List result) { - outerLoop: for (Iterator> it = turnInfo.getTable() - .iterator(); it.hasNext();) { + outerLoop: for (Iterator> it = turnInfo + .getTable().iterator(); it.hasNext();) { Pair pair = it.next(); - setSearch: for (Iterator it2 = result.iterator(); it2.hasNext();) { + setSearch: for (Iterator it2 = result.iterator(); it2 + .hasNext();) { StoneSet set = it2.next(); if (set.getSize() != pair.getFirst().getSize()) { continue; diff --git a/src/jrummikub/control/turn/ITurnControl.java b/src/jrummikub/control/turn/ITurnControl.java index 1860d69..66bd065 100644 --- a/src/jrummikub/control/turn/ITurnControl.java +++ b/src/jrummikub/control/turn/ITurnControl.java @@ -16,12 +16,12 @@ public interface ITurnControl { * Start the turn * * @param info - * the current turn state + * the current turn state * * @param settings - * the game settings + * the game settings * @param view - * view for user interaction. + * view for user interaction. */ public void setup(TurnInfo info, GameSettings settings, IView view); @@ -49,10 +49,16 @@ public interface ITurnControl { */ public void abortTurn(); + /** + * Emitted in network when the table changes during player turn + * + * @return the event + */ public IEvent1 getTableUpdateEvent(); /** - * The TurnInfo class encapsulates all information concerning the current turn + * The TurnInfo class encapsulates all information concerning the current + * turn */ public class TurnInfo { private ITable table; @@ -64,13 +70,13 @@ public interface ITurnControl { * Creates a new TurnInfo instance * * @param table - * the current table + * the current table * @param hand - * the current player's hand + * the current player's hand * @param hasLaidOut - * has the player laid out yet? + * has the player laid out yet? * @param turnMode - * the turn mode + * the turn mode */ public TurnInfo(ITable table, IHand hand, boolean hasLaidOut, TurnMode turnMode) { diff --git a/src/jrummikub/model/GameSettings.java b/src/jrummikub/model/GameSettings.java index 55419a4..dfd391e 100644 --- a/src/jrummikub/model/GameSettings.java +++ b/src/jrummikub/model/GameSettings.java @@ -248,6 +248,11 @@ public class GameSettings implements Serializable { } + /** + * Calculate the total number of stones in game + * + * @return total number of stones + */ public int getTotalStones() { return getHighestValue() * getStoneSetNumber() * getStoneColors().size() + getJokerNumber(); diff --git a/src/jrummikub/model/IPlayer.java b/src/jrummikub/model/IPlayer.java index a72b002..a88d838 100644 --- a/src/jrummikub/model/IPlayer.java +++ b/src/jrummikub/model/IPlayer.java @@ -18,7 +18,7 @@ public interface IPlayer extends Serializable { * Set the current hand of the player * * @param hand - * the new hand + * the new hand */ public void setHand(IHand hand); @@ -40,16 +40,38 @@ public interface IPlayer extends Serializable { * Set if the player laid out * * @param laidOut - * the player laid out + * the player laid out * */ public void setLaidOut(boolean laidOut); + /** + * Getter for last turn invalid + * + * @return last turn invalid + */ public boolean wasLastTurnInvalid(); + /** + * Sets last turn invalid + * + * @param value + * last turn invalid + */ public void setLastTurnInvalid(boolean value); + /** + * Gets the number of stones put on table in player's last turn + * + * @return number of stones + */ public int getLastTurnStoneCount(); + /** + * Sets the number of stones out on the table in player's last turn + * + * @param value + * number of stones + */ public void setLastTurnStoneCount(int value); } \ No newline at end of file diff --git a/src/jrummikub/model/IStoneTray.java b/src/jrummikub/model/IStoneTray.java index 437ecda..17e7ae3 100644 --- a/src/jrummikub/model/IStoneTray.java +++ b/src/jrummikub/model/IStoneTray.java @@ -8,7 +8,7 @@ import jrummikub.util.Pair; * Interface for the {@link StoneTray} model * * @param - * Objects held by the IStoneTray + * Objects held by the IStoneTray */ public interface IStoneTray extends Iterable>, Cloneable, Serializable { @@ -17,9 +17,9 @@ public interface IStoneTray extends * Adds object to the tray * * @param object - * object to add to Hand + * object to add to Hand * @param position - * {@link Position} to put the object + * {@link Position} to put the object */ public void drop(E object, Position position); @@ -27,7 +27,7 @@ public interface IStoneTray extends * Returns the position of an object that is already on the tray * * @param object - * object whose position is requested + * object whose position is requested * @return position of the object or null when the object is not on the tray */ public Position getPosition(E object); @@ -36,7 +36,7 @@ public interface IStoneTray extends * Tries to pick up (remove) a given object * * @param object - * object to pick up + * object to pick up * @return true when the object was successfully removed */ public boolean pickUp(E object); @@ -55,6 +55,13 @@ public interface IStoneTray extends */ public int getSize(); + /** + * Search for an object within the stone tray + * + * @param object + * object to search for + * @return object found in stone tray + */ public boolean contains(E object); } \ No newline at end of file diff --git a/src/jrummikub/view/IConnectPanel.java b/src/jrummikub/view/IConnectPanel.java index 57d0aad..d09460e 100644 --- a/src/jrummikub/view/IConnectPanel.java +++ b/src/jrummikub/view/IConnectPanel.java @@ -2,10 +2,25 @@ package jrummikub.view; import jrummikub.util.IEvent; +/** + * Panel shown during connection process and showing errors + */ public interface IConnectPanel { + /** + * Show connection process while error = null, error else + * + * @param error + * the error to allow specific error messages + */ public void setMode(LoginError error); + /** + * Is emitted when the user wants to abort connecting or has acknowledged + * the error + * + * @return the event + */ public IEvent getCancelEvent(); } diff --git a/src/jrummikub/view/IQuitWarningPanel.java b/src/jrummikub/view/IQuitWarningPanel.java index b1f4123..34d9e07 100644 --- a/src/jrummikub/view/IQuitWarningPanel.java +++ b/src/jrummikub/view/IQuitWarningPanel.java @@ -2,8 +2,14 @@ package jrummikub.view; import jrummikub.util.IEvent; +/** + * Warning panel shown to if the emitted event would cancel the current game + */ public interface IQuitWarningPanel { + /** + * Enum summarizing the different events invoking the quit warning panel + */ public enum QuitMode { /** */ DEFAULT, @@ -13,12 +19,33 @@ public interface IQuitWarningPanel { QUIT_GAME } + /** + * Is emitted if the user is positive about quitting + * + * @return the event + */ public IEvent getQuitEvent(); + /** + * Is emitted if the user selected quit by mistake + * + * @return the event + */ public IEvent getCancelEvent(); + /** + * Sets the panel according to the event which invoked it + * + * @param mode + * the invoking event type + */ public void setMode(QuitMode mode); + /** + * Getter for quit mode + * + * @return the quit mode + */ public QuitMode getQuitMode(); } \ No newline at end of file diff --git a/src/jrummikub/view/IView.java b/src/jrummikub/view/IView.java index 9962062..f03b153 100644 --- a/src/jrummikub/view/IView.java +++ b/src/jrummikub/view/IView.java @@ -6,10 +6,8 @@ import java.util.Collection; import jrummikub.model.Stone; import jrummikub.model.StoneSet; -import jrummikub.util.Event; import jrummikub.util.IEvent; import jrummikub.util.IEvent1; -import jrummikub.view.IQuitWarningPanel.QuitMode; /** * The top-level view interface @@ -59,7 +57,7 @@ public interface IView { * Sets the current player's name * * @param playerName - * the player name + * the player name */ public void setCurrentPlayerName(String playerName); @@ -67,7 +65,7 @@ public interface IView { * Sets the stones that are to be painted selected * * @param stones - * the stones to be painted selected + * the stones to be painted selected */ public void setSelectedStones(Collection stones); @@ -104,7 +102,7 @@ public interface IView { * Shows or hides the game settings panel * * @param show - * specifies if the panel shall be shown or hidden + * specifies if the panel shall be shown or hidden */ public void showSettingsPanel(boolean show); @@ -112,7 +110,7 @@ public interface IView { * Shows or hides the score panel * * @param show - * specifies if the panel shall be shown or hidden + * specifies if the panel shall be shown or hidden */ public void showScorePanel(boolean show); @@ -121,16 +119,16 @@ public interface IView { * along with the name * * @param color - * the current player's color + * the current player's color */ public void setCurrentPlayerColor(Color color); /** - * Is used for the PlayerPanel to display if a player has laid out along with - * the name + * Is used for the PlayerPanel to display if a player has laid out along + * with the name * * @param hasLaidOut - * specifies if the current player has laid out or not + * specifies if the current player has laid out or not */ public void setCurrentPlayerHasLaidOut(boolean hasLaidOut); @@ -145,13 +143,13 @@ public interface IView { * Sets the bottom panels type * * @param type - * the type of the bottom panel + * the type of the bottom panel */ public void setBottomPanel(BottomPanelType type); /** - * The menu new game event is emitted when the user selects the new game menu - * entry + * The menu new game event is emitted when the user selects the new game + * menu entry * * @return the event */ @@ -226,7 +224,7 @@ public interface IView { * Show/hide login panel * * @param show - * true = login panel is shown + * true = login panel is shown */ public void showLoginPanel(boolean show); @@ -234,7 +232,7 @@ public interface IView { * Enable/disable pause mode * * @param enable - * true = enable + * true = enable */ public void enablePauseMode(boolean enable); @@ -242,7 +240,7 @@ public interface IView { * Show/hide game list panel * * @param show - * true = show + * true = show */ public void showGameListPanel(boolean show); @@ -250,7 +248,7 @@ public interface IView { * Show/hide side panel * * @param show - * true to show + * true to show */ void showSidePanel(boolean show); @@ -258,7 +256,7 @@ public interface IView { * Is set if a player tried to lay out less than initial meld threshold * * @param points - * initial meld threshold + * initial meld threshold */ public void setInitialMeldError(int points); @@ -266,7 +264,7 @@ public interface IView { * Show stone collection * * @param enable - * showing collection + * showing collection */ public void setStoneCollectionHidden(boolean enable); @@ -279,7 +277,7 @@ public interface IView { * Set invalid sets to enable showing * * @param sets - * invalid sets on table + * invalid sets on table */ public void setInvalidStoneSets(Collection sets); @@ -292,13 +290,60 @@ public interface IView { * Enables/disables saving in menu bar * * @param enable + * saving possible */ public void enableSave(boolean enable); + /** + * Sets the quit warning panel visible + * + * @param show + * is visible + */ public void showQuitWarningPanel(boolean show); + /** + * The quit event is emitted when the user wants to leave the application + * + * @return the event + */ public IEvent getQuitEvent(); + /** + * Getter for quit warning panel + * + * @return the panel + */ + public IQuitWarningPanel getQuitWarningPanel(); + + /** + * The load file event is emitted when the user chose to discard the current + * game to save another + * + * @return the event + */ + public IEvent1 getLoadFileEvent(); + + /** + * Loading a game + */ + public void load(); + + /** + * Set the connect panel visible + * + * @param show + * is visible + */ + public void showConnectPanel(boolean show); + + /** + * Getter for connect panel + * + * @return the panel + */ + public IConnectPanel getConnectPanel(); + /** * Different types of bottom panels */ @@ -316,14 +361,4 @@ public interface IView { /** */ WIN_PANEL } - - public IQuitWarningPanel getQuitWarningPanel(); - - public IEvent1 getLoadFileEvent(); - - public void load(); - - public void showConnectPanel(boolean show); - - public IConnectPanel getConnectPanel(); } diff --git a/src/jrummikub/view/LoginError.java b/src/jrummikub/view/LoginError.java index a67a395..7176693 100644 --- a/src/jrummikub/view/LoginError.java +++ b/src/jrummikub/view/LoginError.java @@ -1,18 +1,21 @@ package jrummikub.view; +/** + * Enum summarizing the different kinds of login errors + */ public enum LoginError { - /** */ + /** Error cannot be dissolved to a specific type */ UNKNOWN_ERROR, - /** */ + /** No answer from network */ TIMEOUT, - /** */ + /** Connection denied by server */ CONNECTION_REFUSED, - /** */ + /** Password or username incorrect */ AUTHENTICATION_FAILED, - /** */ + /** Username already occurs in the same channel */ RESOURCE_CONFLICT, - /** */ + /** Server not found */ UNKNOWN_HOST, - /** */ + /** Channel not found */ UNKNOWN_CHANNEL } diff --git a/src/jrummikub/view/impl/ConnectPanel.java b/src/jrummikub/view/impl/ConnectPanel.java index befa687..fc30bb0 100644 --- a/src/jrummikub/view/impl/ConnectPanel.java +++ b/src/jrummikub/view/impl/ConnectPanel.java @@ -21,13 +21,20 @@ import jrummikub.util.IEvent; import jrummikub.view.IConnectPanel; import jrummikub.view.LoginError; +/** + * Panel shown during network connecting process and showing errors + */ public class ConnectPanel extends JPanel implements IConnectPanel { + private static final long serialVersionUID = 1L; private JLabel messageLabel; private JProgressBar foobar; private JButton cancelButton; private Event cancelEvent = new Event(); + /** + * Creates new connection panel + */ public ConnectPanel() { setLayout(new GridBagLayout()); @@ -61,8 +68,8 @@ public class ConnectPanel extends JPanel implements IConnectPanel { }); add(cancelButton, c); - setBorder(new CompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder( - 10, 10, 10, 10))); + setBorder(new CompoundBorder(new LineBorder(Color.BLACK), + new EmptyBorder(10, 10, 10, 10))); } @Override diff --git a/src/jrummikub/view/impl/QuitWarningPanel.java b/src/jrummikub/view/impl/QuitWarningPanel.java index edc8947..f00ef8a 100644 --- a/src/jrummikub/view/impl/QuitWarningPanel.java +++ b/src/jrummikub/view/impl/QuitWarningPanel.java @@ -18,7 +18,11 @@ import jrummikub.util.Event; import jrummikub.util.IEvent; import jrummikub.view.IQuitWarningPanel; +/** + * Warning panel to inform users if their actions would end the current game + */ public class QuitWarningPanel extends JPanel implements IQuitWarningPanel { + private static final long serialVersionUID = 1L; private JButton cancelButton; private JButton quitButton; private QuitMode quitMode; @@ -26,6 +30,9 @@ public class QuitWarningPanel extends JPanel implements IQuitWarningPanel { private Event cancelEvent = new Event(); private JLabel messageLabel; + /** + * Creates new quit warning panel + */ public QuitWarningPanel() { setLayout(new GridBagLayout()); @@ -50,8 +57,8 @@ public class QuitWarningPanel extends JPanel implements IQuitWarningPanel { c.gridx = 1; add(quitButton, c); - setBorder(new CompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder( - 10, 10, 10, 10))); + setBorder(new CompoundBorder(new LineBorder(Color.BLACK), + new EmptyBorder(10, 10, 10, 10))); } private JButton createButton(String title, final Event event) { @@ -70,7 +77,8 @@ public class QuitWarningPanel extends JPanel implements IQuitWarningPanel { this.quitMode = mode; switch (quitMode) { case QUIT_PROCESS: - messageLabel.setText("Beim Beenden geht das aktuelle Spiel verloren"); + messageLabel + .setText("Beim Beenden geht das aktuelle Spiel verloren"); break; case QUIT_GAME: messageLabel.setText("Der aktuelle Spielstand geht verloren"); diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java index 94cb04f..5cc1a85 100644 --- a/src/jrummikub/view/impl/View.java +++ b/src/jrummikub/view/impl/View.java @@ -14,7 +14,6 @@ import java.util.Collection; import java.util.Collections; import java.util.List; -import javax.swing.JComponent; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLayeredPane; @@ -43,7 +42,6 @@ import jrummikub.view.IHandPanel; import jrummikub.view.ILoginPanel; import jrummikub.view.IPlayerPanel; import jrummikub.view.IQuitWarningPanel; -import jrummikub.view.IQuitWarningPanel.QuitMode; import jrummikub.view.IScorePanel; import jrummikub.view.ISettingsPanel; import jrummikub.view.ISidePanel; @@ -232,7 +230,6 @@ public class View extends JFrame implements IView { loadItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - File file = new File(""); loadEvent.emit(); } }); @@ -314,6 +311,19 @@ public class View extends JFrame implements IView { createSettingsPanel(); + createLayeredPane(); + + addComponentListener(new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + rescale(); + } + }); + + setVisible(true); + } + + private void createLayeredPane() { layeredPane.setLayer(settingsPanel, JLayeredPane.POPUP_LAYER); layeredPane.add(settingsPanel); @@ -341,15 +351,6 @@ public class View extends JFrame implements IView { scorePanel.setVisible(false); layeredPane.setLayer(scorePanel, JLayeredPane.POPUP_LAYER); layeredPane.add(scorePanel); - - addComponentListener(new ComponentAdapter() { - @Override - public void componentResized(ComponentEvent e) { - rescale(); - } - }); - - setVisible(true); } private void createSettingsPanel() { -- cgit v1.2.3