diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-05-02 05:12:53 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-05-02 05:12:53 +0200 |
commit | fcef81715bff95ac04176dd3d93bb44e1b625087 (patch) | |
tree | e02dcb3d31185afe5943680e1e4549f4ce66775c /src/jrummikub/view | |
parent | a9cf0d8c8fb5b489f07e4cc408cc5edf413ce26e (diff) | |
download | JRummikub-fcef81715bff95ac04176dd3d93bb44e1b625087.tar JRummikub-fcef81715bff95ac04176dd3d93bb44e1b625087.zip |
Add JavaDoc to view implementation
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@66 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/view')
-rw-r--r-- | src/jrummikub/view/IView.java | 4 | ||||
-rw-r--r-- | src/jrummikub/view/impl/Board.java | 14 | ||||
-rw-r--r-- | src/jrummikub/view/impl/PlayerPanel.java | 8 | ||||
-rw-r--r-- | src/jrummikub/view/impl/StoneCollection.java | 15 | ||||
-rw-r--r-- | src/jrummikub/view/impl/StonePainter.java | 41 | ||||
-rw-r--r-- | src/jrummikub/view/impl/StonePanel.java | 15 | ||||
-rw-r--r-- | src/jrummikub/view/impl/Table.java | 16 | ||||
-rw-r--r-- | src/jrummikub/view/impl/View.java | 6 |
8 files changed, 111 insertions, 8 deletions
diff --git a/src/jrummikub/view/IView.java b/src/jrummikub/view/IView.java index 25ebb32..cb4ab3e 100644 --- a/src/jrummikub/view/IView.java +++ b/src/jrummikub/view/IView.java @@ -23,10 +23,10 @@ public interface IView { public IPlayerPanel getPlayerPanel(); /** - * Sets the stones that are to be drawn selected + * Sets the stones that are to be painted selected * * @param stones - * the stones to be drawn selected + * the stones to be painted selected */ public void setSelectedStones(Collection<Stone> stones); } diff --git a/src/jrummikub/view/impl/Board.java b/src/jrummikub/view/impl/Board.java index b6d92a8..94571e0 100644 --- a/src/jrummikub/view/impl/Board.java +++ b/src/jrummikub/view/impl/Board.java @@ -20,6 +20,9 @@ import jrummikub.model.Position; import jrummikub.model.Stone; import jrummikub.view.IBoard; +/** + * Implementation of the board + */ @SuppressWarnings("serial") class Board extends StonePanel implements IBoard { private final static int BOARD_HEIGHT = 2; @@ -39,6 +42,9 @@ class Board extends StonePanel implements IBoard { private Map<Stone, Position> stones = Collections.emptyMap(); private Collection<Stone> selectedStones = Collections.emptyList(); + /** + * Creates a new Board instance + */ Board() { setBorder(new MatteBorder(0, 1, 0, 1, Color.DARK_GRAY)); @@ -103,7 +109,13 @@ class Board extends StonePanel implements IBoard { repaint(); } - public void setSelectedStones(Collection<Stone> stones) { + /** + * Sets the stones that are to be painted selected + * + * @param stones + * the selected stones + */ + void setSelectedStones(Collection<Stone> stones) { selectedStones = stones; repaint(); } diff --git a/src/jrummikub/view/impl/PlayerPanel.java b/src/jrummikub/view/impl/PlayerPanel.java index 1d62aab..309982e 100644 --- a/src/jrummikub/view/impl/PlayerPanel.java +++ b/src/jrummikub/view/impl/PlayerPanel.java @@ -19,6 +19,9 @@ import jrummikub.util.Event; import jrummikub.util.IEvent; import jrummikub.view.IPlayerPanel; +/** + * Implementation of the player panel + */ @SuppressWarnings("serial") class PlayerPanel extends JPanel implements IPlayerPanel { private final static int SIDE_PANEL_INSET = 15; @@ -31,7 +34,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel { private Board board; - JPanel leftPanel, rightPanel; + private JPanel leftPanel, rightPanel; private JLabel currentPlayerNameLabel; private JButton sortByNumberButton; @@ -149,6 +152,9 @@ class PlayerPanel extends JPanel implements IPlayerPanel { rightPanel.validate(); } + /** + * Creates a new PlayerPanel instance + */ PlayerPanel() { setLayout(null); diff --git a/src/jrummikub/view/impl/StoneCollection.java b/src/jrummikub/view/impl/StoneCollection.java index 95813da..a374dd2 100644 --- a/src/jrummikub/view/impl/StoneCollection.java +++ b/src/jrummikub/view/impl/StoneCollection.java @@ -13,6 +13,9 @@ import jrummikub.model.Position; import jrummikub.model.Stone; import jrummikub.view.IStoneCollection; +/** + * Implementation of the stone collection (selection) + */ @SuppressWarnings("serial") class StoneCollection extends StonePanel implements IStoneCollection { private final static int INSET = 7; @@ -20,6 +23,9 @@ class StoneCollection extends StonePanel implements IStoneCollection { private Collection<Stone> selectedStones = Collections.emptyList(); + /** + * Creates a new StoneCollection instance + */ StoneCollection() { super(STONE_SCALE); @@ -28,6 +34,12 @@ class StoneCollection extends StonePanel implements IStoneCollection { setBorder(new EmptyBorder(INSET, INSET, INSET, INSET)); } + /** + * Sets the stones to be shown in the collection + * + * @param stones + * the selected stones + */ void setSelectedStones(Collection<Stone> stones) { selectedStones = stones; @@ -56,8 +68,7 @@ class StoneCollection extends StonePanel implements IStoneCollection { float xpos = 0; for (Stone stone : selectedStones) { - getStonePainter().paintStone(g, stone, new Position(xpos, 0), - false); + getStonePainter().paintStone(g, stone, new Position(xpos, 0), false); xpos++; } } diff --git a/src/jrummikub/view/impl/StonePainter.java b/src/jrummikub/view/impl/StonePainter.java index ab523a7..47c0e9b 100644 --- a/src/jrummikub/view/impl/StonePainter.java +++ b/src/jrummikub/view/impl/StonePainter.java @@ -14,6 +14,10 @@ import jrummikub.model.Position; import jrummikub.model.Stone; import jrummikub.model.StoneColor; +/** + * The StonePainter paints stones and converts between pixel and grid + * coordinates + */ class StonePainter { private static final float ASPECT_RATIO = 0.75f; private static final float DEFAULT_WIDTH = 40; @@ -27,7 +31,13 @@ class StonePainter { private static final float BRIGHTER_SCALE = 1.15f; + /** + * The width of one pixel in the scale of 1.0 + */ public static final float WIDTH_SCALE = 1 / DEFAULT_WIDTH; + /** + * The height of one pixel in the scale of 1.0 + */ public static final float HEIGHT_SCALE = ASPECT_RATIO / DEFAULT_WIDTH; private float scale; @@ -59,10 +69,19 @@ class StonePainter { return null; } + /** + * Sets the new grid scale + * + * @param scale + * the new scale + */ public void setScale(float scale) { this.scale = scale; } + /** + * @return the current grid scale + */ public float getScale() { return scale; } @@ -81,14 +100,24 @@ class StonePainter { return new Position(x / width, y / height); } + /** + * @return the width of a stone in the current scale in pixels + */ public int getStoneWidth() { return even(DEFAULT_WIDTH * scale); } + /** + * @return the height of a stone in the current scale in pixels + */ public int getStoneHeight() { return (int) (DEFAULT_WIDTH * scale / ASPECT_RATIO); } + /** + * @param scale + * the scaling factor for the grid coordinates + */ StonePainter(float scale) { this.scale = scale; } @@ -208,6 +237,18 @@ class StonePainter { -130, 170); } + /** + * Paints a stone + * + * @param g + * the graphics context to paint the stone on + * @param stone + * the stone to paint + * @param p + * the position of the stone + * @param selected + * if selected is true the stone will be painted darker + */ public void paintStone(Graphics2D g, Stone stone, Position p, boolean selected) { Color background = selected ? SELECTED_COLOR : BACKGROUND_COLOR; int width = getStoneWidth(); diff --git a/src/jrummikub/view/impl/StonePanel.java b/src/jrummikub/view/impl/StonePanel.java index d5d56a9..9e84349 100644 --- a/src/jrummikub/view/impl/StonePanel.java +++ b/src/jrummikub/view/impl/StonePanel.java @@ -10,6 +10,9 @@ import jrummikub.model.Position; import jrummikub.util.Event2; import jrummikub.view.IClickable; +/** + * Base class for panels that draw stones + */ @SuppressWarnings("serial") abstract class StonePanel extends JPanel implements IClickable { private StonePainter stonePainter; @@ -18,14 +21,26 @@ abstract class StonePanel extends JPanel implements IClickable { private Event2<Position, Boolean> rangeClickEvent = new Event2<Position, Boolean>(); private Event2<Position, Boolean> setClickEvent = new Event2<Position, Boolean>(); + /** + * @return the stone painter + */ protected StonePainter getStonePainter() { return stonePainter; } + /** + * Create a new StonePanel with default scale factor + */ public StonePanel() { this(1); } + /** + * Create a new StonePanel with a given scale factor + * + * @param scale + * the grid scale + */ public StonePanel(float scale) { super(true); // Set double buffered diff --git a/src/jrummikub/view/impl/Table.java b/src/jrummikub/view/impl/Table.java index 67bf124..1d78ac1 100644 --- a/src/jrummikub/view/impl/Table.java +++ b/src/jrummikub/view/impl/Table.java @@ -21,6 +21,9 @@ import jrummikub.model.StoneSet; import jrummikub.view.IStoneCollection; import jrummikub.view.ITable; +/** + * The implementation of the table + */ @SuppressWarnings("serial") class Table extends StonePanel implements ITable { private final static ImageIcon background = new ImageIcon( @@ -61,7 +64,13 @@ class Table extends StonePanel implements ITable { return stoneCollection; } - public void setSelectedStones(Collection<Stone> stones) { + /** + * Sets the currently selected stones + * + * @param stones + * the selected stones + */ + void setSelectedStones(Collection<Stone> stones) { selectedStones = stones; stoneCollection.setSelectedStones(stones); repaint(); @@ -80,6 +89,9 @@ class Table extends StonePanel implements ITable { y + height - stoneCollection.getHeight() - COLLECTION_GAP); } + /** + * Creates a new Table instance + */ Table() { super(DEFAULT_SCALE); @@ -119,7 +131,7 @@ class Table extends StonePanel implements ITable { stoneCollection.addComponentListener(rescaleListener); } - public void paintStoneSet(Graphics2D g, StoneSet stoneSet, Position pos) { + private void paintStoneSet(Graphics2D g, StoneSet stoneSet, Position pos) { float x = pos.getX(); int width = getStonePainter().getStoneWidth(), height = getStonePainter() .getStoneHeight(); diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java index 2d09b05..482f692 100644 --- a/src/jrummikub/view/impl/View.java +++ b/src/jrummikub/view/impl/View.java @@ -14,6 +14,9 @@ import jrummikub.view.IPlayerPanel; import jrummikub.view.ITable; import jrummikub.view.IView; +/** + * Implementation of the top-level view interface + */ @SuppressWarnings("serial") public class View extends JFrame implements IView { private Table table; @@ -35,6 +38,9 @@ public class View extends JFrame implements IView { return playerPanel; } + /** + * Create a new instance of the view + */ public View() { super("JRummikub"); setLayout(null); |