diff options
author | Ida Massow <massow@informatik.uni-luebeck.de> | 2011-06-21 15:23:29 +0200 |
---|---|---|
committer | Ida Massow <massow@informatik.uni-luebeck.de> | 2011-06-21 15:23:29 +0200 |
commit | 7899a38fe63a819d405a18e0139cea6ff95aac33 (patch) | |
tree | 559c4f4f80f0fad9548bb31673be9e89c70b72c5 /src/jrummikub/view/impl | |
parent | e4e66240bf864354715f3812f70444d7f7511dd2 (diff) | |
download | JRummikub-7899a38fe63a819d405a18e0139cea6ff95aac33.tar JRummikub-7899a38fe63a819d405a18e0139cea6ff95aac33.zip |
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
Diffstat (limited to 'src/jrummikub/view/impl')
-rw-r--r-- | src/jrummikub/view/impl/AbstractStonePanel.java | 39 | ||||
-rw-r--r-- | src/jrummikub/view/impl/GameListPanel.java | 35 | ||||
-rw-r--r-- | src/jrummikub/view/impl/HandPanel.java | 23 |
3 files changed, 83 insertions, 14 deletions
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<Integer, Integer> 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<Stone, Position> 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<Pair<Stone, Position>> 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<GameData> 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<Integer, Integer> 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<Integer, Integer>(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; |