From 7899a38fe63a819d405a18e0139cea6ff95aac33 Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Tue, 21 Jun 2011 15:23:29 +0200 Subject: Noch mehr Kommentare, z.B. alle Methoden im Model und in der IView git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@547 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/server/DedicatedServer.java | 11 ++++++ src/jrummikub/view/ISettingsPanel.java | 9 ++++- src/jrummikub/view/ISidePanel.java | 28 ++++++++++++++ src/jrummikub/view/IStoneCollectionPanel.java | 1 + src/jrummikub/view/IView.java | 49 ++++++++++++++----------- src/jrummikub/view/impl/AbstractStonePanel.java | 39 ++++++++++++++------ src/jrummikub/view/impl/GameListPanel.java | 35 +++++++++++++++++- src/jrummikub/view/impl/HandPanel.java | 23 ++++++++++++ 8 files changed, 159 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/jrummikub/server/DedicatedServer.java b/src/jrummikub/server/DedicatedServer.java index a31c6f5..42345a6 100644 --- a/src/jrummikub/server/DedicatedServer.java +++ b/src/jrummikub/server/DedicatedServer.java @@ -18,6 +18,12 @@ public class DedicatedServer { String serverPassword; String hostName; + /** + * Creates a new dedicated server with the specified password + * + * @param serverPassword + * the password + */ public DedicatedServer(String serverPassword) { this.serverPassword = serverPassword; try { @@ -29,6 +35,11 @@ public class DedicatedServer { } + /** + * Getter for host name + * + * @return host name + */ public String getHostName() { return hostName; } diff --git a/src/jrummikub/view/ISettingsPanel.java b/src/jrummikub/view/ISettingsPanel.java index 26f5737..c9df7a6 100644 --- a/src/jrummikub/view/ISettingsPanel.java +++ b/src/jrummikub/view/ISettingsPanel.java @@ -231,7 +231,8 @@ public interface ISettingsPanel { public void setPlayerNamesEditable(List editable); /** - * Emitted when a new game is started and looking for players + * The offer new game event is emitted when a new game is started and + * looking for players * * @return the event */ @@ -245,6 +246,12 @@ public interface ISettingsPanel { */ public void setPlayerColors(Set colors); + /** + * The change see hand size event is emitted when the player chooses to see + * the other players hand sizes + * + * @return the event + */ public IEvent1 getChangeSeeHandSizeEvent(); /** diff --git a/src/jrummikub/view/ISidePanel.java b/src/jrummikub/view/ISidePanel.java index 9efea85..b78ff39 100644 --- a/src/jrummikub/view/ISidePanel.java +++ b/src/jrummikub/view/ISidePanel.java @@ -5,14 +5,42 @@ import java.util.List; import jrummikub.model.GameSettings; import jrummikub.model.IPlayer; +/** + * Side panel to show all players and relevant player information in round + * order, game settings and stone heap size + */ public interface ISidePanel { + /** + * Sets the game settings to top of side panel + * + * @param settings + * current game settings + */ public void setGameSettings(GameSettings settings); + /** + * Sets the total heap size for progress bar + * + * @param capacity + * total heap size + */ void setHeapCapacity(int capacity); + /** + * Sets the current heap size + * + * @param size + * number of stones in current heap + */ void setHeapSize(int size); + /** + * Sets the player information in order of turns + * + * @param players + * players in current game + */ void setPlayers(List players); } \ No newline at end of file diff --git a/src/jrummikub/view/IStoneCollectionPanel.java b/src/jrummikub/view/IStoneCollectionPanel.java index dfa15b1..be6c6a2 100644 --- a/src/jrummikub/view/IStoneCollectionPanel.java +++ b/src/jrummikub/view/IStoneCollectionPanel.java @@ -9,6 +9,7 @@ public interface IStoneCollectionPanel extends IStonePanel { * Hide stone collection * * @param enable + * see stone collection */ void setHidden(boolean enable); } diff --git a/src/jrummikub/view/IView.java b/src/jrummikub/view/IView.java index 5ef7060..8643781 100644 --- a/src/jrummikub/view/IView.java +++ b/src/jrummikub/view/IView.java @@ -57,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); @@ -65,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); @@ -102,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); @@ -110,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); @@ -119,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); @@ -143,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 */ @@ -217,7 +217,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); @@ -225,7 +225,7 @@ public interface IView { * Enable/disable pause mode * * @param enable - * true = enable + * true = enable */ public void enablePauseMode(boolean enable); @@ -233,7 +233,7 @@ public interface IView { * Show/hide game list panel * * @param show - * true = show + * true = show */ public void showGameListPanel(boolean show); @@ -241,7 +241,7 @@ public interface IView { * Show/hide side panel * * @param show - * true to show + * true to show */ void showSidePanel(boolean show); @@ -249,7 +249,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); @@ -257,7 +257,7 @@ public interface IView { * Show stone collection * * @param enable - * showing collection + * showing collection */ public void setStoneCollectionHidden(boolean enable); @@ -270,7 +270,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); @@ -283,7 +283,7 @@ public interface IView { * Enables/disables saving in menu bar * * @param enable - * saving possible + * saving possible */ public void enableSave(boolean enable); @@ -291,7 +291,7 @@ public interface IView { * Sets the quit warning panel visible * * @param show - * is visible + * is visible */ public void showQuitWarningPanel(boolean show); @@ -326,7 +326,7 @@ public interface IView { * Set the connect panel visible * * @param show - * is visible + * is visible */ public void showConnectPanel(boolean show); @@ -337,6 +337,13 @@ public interface IView { */ public IConnectPanel getConnectPanel(); + /** + * Sets the pause button if pausing should be possible in the current + * situation + * + * @param mayPause + * pausing possible + */ public void setMayPause(boolean mayPause); /** diff --git a/src/jrummikub/view/impl/AbstractStonePanel.java b/src/jrummikub/view/impl/AbstractStonePanel.java index ba3013c..6f8e06c 100644 --- a/src/jrummikub/view/impl/AbstractStonePanel.java +++ b/src/jrummikub/view/impl/AbstractStonePanel.java @@ -52,7 +52,7 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel, * Create a new StonePanel with a given scale factor * * @param scale - * the grid scale + * the grid scale */ public AbstractStonePanel(float scale) { super(true); // Set double buffered @@ -77,8 +77,9 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel, public void mouseMoved(MouseEvent e) { Insets insets = getInsets(); Pair trans = getTranslation(); - Position pos = stonePainter.calculatePosition(e.getX() - insets.left - - trans.getFirst(), e.getY() - insets.top - trans.getSecond()); + Position pos = stonePainter.calculatePosition(e.getX() + - insets.left - trans.getFirst(), e.getY() - insets.top + - trans.getSecond()); setHoveredStone(getStoneAt(pos)); @@ -91,15 +92,15 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel, * clickAt is called when a click has occurred * * @param p - * the point in component coordinates + * the point in component coordinates * @param clickCount - * the click count + * the click count * @param shift - * is shift down? + * is shift down? * @param control - * is control down? + * is control down? * @param alt - * is alt down? + * is alt down? */ protected void clickAt(Point p, int clickCount, boolean shift, boolean control, boolean alt) { @@ -132,6 +133,12 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel, event.emit(stone, control); } + /** + * Sets the stone over which the cursor hovers + * + * @param stone + * stone under cursor + */ private void setHoveredStone(Stone stone) { Stone oldStone = hoveredStone; hoveredStone = stone; @@ -153,7 +160,7 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel, * Overwrite this method to signal if special zone was clicked * * @param pos - * the clicked position + * the clicked position * * @return special zone clicked */ @@ -165,11 +172,18 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel, * Overwrite this method to signal if special zone was hovered * * @param pos - * the hovered position + * the hovered position */ protected void handleOtherMoveEvent(Position pos) { } + /** + * Gets the stone at the specified position + * + * @param pos + * position + * @return the stone + */ private Stone getStoneAt(Position pos) { for (Pair entry : stones) { Stone stone = entry.getFirst(); @@ -187,14 +201,15 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel, * Sets the list of stones that can be clicked on * * @param stones - * the stones and positions + * the stones and positions */ protected void setStones(Iterable> stones) { this.stones = stones; } /** - * Returns the translation in pixels the stones in this panel are painted with + * Returns the translation in pixels the stones in this panel are painted + * with * * @return the translation */ diff --git a/src/jrummikub/view/impl/GameListPanel.java b/src/jrummikub/view/impl/GameListPanel.java index d5328af..eebe3f5 100644 --- a/src/jrummikub/view/impl/GameListPanel.java +++ b/src/jrummikub/view/impl/GameListPanel.java @@ -49,6 +49,9 @@ class GameListPanel extends JPanel implements IGameListPanel { private List games = Collections.emptyList(); + /** + * Creates new game list panel + */ GameListPanel() { setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); @@ -70,10 +73,13 @@ class GameListPanel extends JPanel implements IGameListPanel { addButtons(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))); } + /** + * Creates the game list to be displayed in the panel + */ private void createGameList() { GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.BOTH; @@ -113,6 +119,12 @@ class GameListPanel extends JPanel implements IGameListPanel { JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), c); } + /** + * Adds all three buttons to the panel + * + * @param c + * constraints for button positioning + */ private void addButtons(GridBagConstraints c) { joinButton = new JButton("Beitreten"); c.gridwidth = 1; @@ -154,6 +166,9 @@ class GameListPanel extends JPanel implements IGameListPanel { }); } + /** + * Resets panel if all games have been removed from list + */ void reset() { games.clear(); } @@ -193,6 +208,9 @@ class GameListPanel extends JPanel implements IGameListPanel { return cancelEvent; } + /** + * Emits a join event if a user selects a game and dedides to join it + */ private void join() { Object data = gameList.getSelectedValue(); @@ -201,6 +219,13 @@ class GameListPanel extends JPanel implements IGameListPanel { } } + /** + * Counts the empty slots for network players in a game + * + * @param gameData + * of the game + * @return Pair of occupied spaces and vacant spaces + */ private static Pair getPlayerSlotCount(GameData gameData) { int total = gameData.getGameSettings().getPlayerList().size(); int occupied = total; @@ -214,11 +239,17 @@ class GameListPanel extends JPanel implements IGameListPanel { return new Pair(occupied, total); } + /** + * Class presenting the game data in a readable way + */ private static class GameDataCellRenderer extends JPanel implements ListCellRenderer { private static final long serialVersionUID = -892701906163443927L; JLabel hostLabel, playerCountLabel; + /** + * Create new game data cell renderer + */ GameDataCellRenderer() { setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); diff --git a/src/jrummikub/view/impl/HandPanel.java b/src/jrummikub/view/impl/HandPanel.java index c07bee0..ebe4f54 100644 --- a/src/jrummikub/view/impl/HandPanel.java +++ b/src/jrummikub/view/impl/HandPanel.java @@ -140,6 +140,9 @@ class HandPanel extends AbstractStonePanel implements IHandPanel { playerPanel.updateButtons(); } + /** + * Updates panel after visible row changed + */ void rowUp() { currentRow--; repaintAll = true; @@ -148,6 +151,9 @@ class HandPanel extends AbstractStonePanel implements IHandPanel { playerPanel.updateButtons(); } + /** + * Updates panel after visible row changed + */ void rowDown() { currentRow++; repaintAll = true; @@ -163,10 +169,20 @@ class HandPanel extends AbstractStonePanel implements IHandPanel { playerPanel.updateButtons(); } + /** + * Is there a higher row than the current row + * + * @return higher row present + */ boolean canRowUp() { return (currentRow > 0); } + /** + * Is there a lower row than the current row + * + * @return higher row present + */ boolean canRowDown() { return (currentRow < maxRow); } @@ -188,6 +204,13 @@ class HandPanel extends AbstractStonePanel implements IHandPanel { repaint(); } + /** + * Rescales the hand panel according to window size + * + * @param height + * of hand panel + * @return width of hand panel + */ int rescale(int height) { Insets insets = getInsets(); int size = (height - insets.top - insets.bottom) / HEIGHT; -- cgit v1.2.3