diff options
Diffstat (limited to 'src/jrummikub/view/impl/GameListPanel.java')
-rw-r--r-- | src/jrummikub/view/impl/GameListPanel.java | 35 |
1 files changed, 33 insertions, 2 deletions
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(); |