Add JavaDoc to view implementation

git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@66 72836036-5685-4462-b002-a69064685172
This commit is contained in:
Matthias Schiffer 2011-05-02 05:12:53 +02:00
parent a9cf0d8c8f
commit fcef81715b
8 changed files with 111 additions and 8 deletions

View file

@ -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);
}

View file

@ -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();
}

View file

@ -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);

View file

@ -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++;
}
}

View file

@ -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();

View file

@ -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

View file

@ -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();

View file

@ -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);