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:
parent
a9cf0d8c8f
commit
fcef81715b
8 changed files with 111 additions and 8 deletions
|
@ -23,10 +23,10 @@ public interface IView {
|
||||||
public IPlayerPanel getPlayerPanel();
|
public IPlayerPanel getPlayerPanel();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the stones that are to be drawn selected
|
* Sets the stones that are to be painted selected
|
||||||
*
|
*
|
||||||
* @param stones
|
* @param stones
|
||||||
* the stones to be drawn selected
|
* the stones to be painted selected
|
||||||
*/
|
*/
|
||||||
public void setSelectedStones(Collection<Stone> stones);
|
public void setSelectedStones(Collection<Stone> stones);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,9 @@ import jrummikub.model.Position;
|
||||||
import jrummikub.model.Stone;
|
import jrummikub.model.Stone;
|
||||||
import jrummikub.view.IBoard;
|
import jrummikub.view.IBoard;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of the board
|
||||||
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
class Board extends StonePanel implements IBoard {
|
class Board extends StonePanel implements IBoard {
|
||||||
private final static int BOARD_HEIGHT = 2;
|
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 Map<Stone, Position> stones = Collections.emptyMap();
|
||||||
private Collection<Stone> selectedStones = Collections.emptyList();
|
private Collection<Stone> selectedStones = Collections.emptyList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Board instance
|
||||||
|
*/
|
||||||
Board() {
|
Board() {
|
||||||
setBorder(new MatteBorder(0, 1, 0, 1, Color.DARK_GRAY));
|
setBorder(new MatteBorder(0, 1, 0, 1, Color.DARK_GRAY));
|
||||||
|
|
||||||
|
@ -103,7 +109,13 @@ class Board extends StonePanel implements IBoard {
|
||||||
repaint();
|
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;
|
selectedStones = stones;
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,9 @@ import jrummikub.util.Event;
|
||||||
import jrummikub.util.IEvent;
|
import jrummikub.util.IEvent;
|
||||||
import jrummikub.view.IPlayerPanel;
|
import jrummikub.view.IPlayerPanel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of the player panel
|
||||||
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
class PlayerPanel extends JPanel implements IPlayerPanel {
|
class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
private final static int SIDE_PANEL_INSET = 15;
|
private final static int SIDE_PANEL_INSET = 15;
|
||||||
|
@ -31,7 +34,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
|
|
||||||
private Board board;
|
private Board board;
|
||||||
|
|
||||||
JPanel leftPanel, rightPanel;
|
private JPanel leftPanel, rightPanel;
|
||||||
|
|
||||||
private JLabel currentPlayerNameLabel;
|
private JLabel currentPlayerNameLabel;
|
||||||
private JButton sortByNumberButton;
|
private JButton sortByNumberButton;
|
||||||
|
@ -149,6 +152,9 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
rightPanel.validate();
|
rightPanel.validate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new PlayerPanel instance
|
||||||
|
*/
|
||||||
PlayerPanel() {
|
PlayerPanel() {
|
||||||
setLayout(null);
|
setLayout(null);
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,9 @@ import jrummikub.model.Position;
|
||||||
import jrummikub.model.Stone;
|
import jrummikub.model.Stone;
|
||||||
import jrummikub.view.IStoneCollection;
|
import jrummikub.view.IStoneCollection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of the stone collection (selection)
|
||||||
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
class StoneCollection extends StonePanel implements IStoneCollection {
|
class StoneCollection extends StonePanel implements IStoneCollection {
|
||||||
private final static int INSET = 7;
|
private final static int INSET = 7;
|
||||||
|
@ -20,6 +23,9 @@ class StoneCollection extends StonePanel implements IStoneCollection {
|
||||||
|
|
||||||
private Collection<Stone> selectedStones = Collections.emptyList();
|
private Collection<Stone> selectedStones = Collections.emptyList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new StoneCollection instance
|
||||||
|
*/
|
||||||
StoneCollection() {
|
StoneCollection() {
|
||||||
super(STONE_SCALE);
|
super(STONE_SCALE);
|
||||||
|
|
||||||
|
@ -28,6 +34,12 @@ class StoneCollection extends StonePanel implements IStoneCollection {
|
||||||
setBorder(new EmptyBorder(INSET, INSET, INSET, INSET));
|
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) {
|
void setSelectedStones(Collection<Stone> stones) {
|
||||||
selectedStones = stones;
|
selectedStones = stones;
|
||||||
|
|
||||||
|
@ -56,8 +68,7 @@ class StoneCollection extends StonePanel implements IStoneCollection {
|
||||||
float xpos = 0;
|
float xpos = 0;
|
||||||
|
|
||||||
for (Stone stone : selectedStones) {
|
for (Stone stone : selectedStones) {
|
||||||
getStonePainter().paintStone(g, stone, new Position(xpos, 0),
|
getStonePainter().paintStone(g, stone, new Position(xpos, 0), false);
|
||||||
false);
|
|
||||||
xpos++;
|
xpos++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,10 @@ import jrummikub.model.Position;
|
||||||
import jrummikub.model.Stone;
|
import jrummikub.model.Stone;
|
||||||
import jrummikub.model.StoneColor;
|
import jrummikub.model.StoneColor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The StonePainter paints stones and converts between pixel and grid
|
||||||
|
* coordinates
|
||||||
|
*/
|
||||||
class StonePainter {
|
class StonePainter {
|
||||||
private static final float ASPECT_RATIO = 0.75f;
|
private static final float ASPECT_RATIO = 0.75f;
|
||||||
private static final float DEFAULT_WIDTH = 40;
|
private static final float DEFAULT_WIDTH = 40;
|
||||||
|
@ -27,7 +31,13 @@ class StonePainter {
|
||||||
|
|
||||||
private static final float BRIGHTER_SCALE = 1.15f;
|
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;
|
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;
|
public static final float HEIGHT_SCALE = ASPECT_RATIO / DEFAULT_WIDTH;
|
||||||
|
|
||||||
private float scale;
|
private float scale;
|
||||||
|
@ -59,10 +69,19 @@ class StonePainter {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the new grid scale
|
||||||
|
*
|
||||||
|
* @param scale
|
||||||
|
* the new scale
|
||||||
|
*/
|
||||||
public void setScale(float scale) {
|
public void setScale(float scale) {
|
||||||
this.scale = scale;
|
this.scale = scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the current grid scale
|
||||||
|
*/
|
||||||
public float getScale() {
|
public float getScale() {
|
||||||
return scale;
|
return scale;
|
||||||
}
|
}
|
||||||
|
@ -81,14 +100,24 @@ class StonePainter {
|
||||||
return new Position(x / width, y / height);
|
return new Position(x / width, y / height);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the width of a stone in the current scale in pixels
|
||||||
|
*/
|
||||||
public int getStoneWidth() {
|
public int getStoneWidth() {
|
||||||
return even(DEFAULT_WIDTH * scale);
|
return even(DEFAULT_WIDTH * scale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the height of a stone in the current scale in pixels
|
||||||
|
*/
|
||||||
public int getStoneHeight() {
|
public int getStoneHeight() {
|
||||||
return (int) (DEFAULT_WIDTH * scale / ASPECT_RATIO);
|
return (int) (DEFAULT_WIDTH * scale / ASPECT_RATIO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param scale
|
||||||
|
* the scaling factor for the grid coordinates
|
||||||
|
*/
|
||||||
StonePainter(float scale) {
|
StonePainter(float scale) {
|
||||||
this.scale = scale;
|
this.scale = scale;
|
||||||
}
|
}
|
||||||
|
@ -208,6 +237,18 @@ class StonePainter {
|
||||||
-130, 170);
|
-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) {
|
public void paintStone(Graphics2D g, Stone stone, Position p, boolean selected) {
|
||||||
Color background = selected ? SELECTED_COLOR : BACKGROUND_COLOR;
|
Color background = selected ? SELECTED_COLOR : BACKGROUND_COLOR;
|
||||||
int width = getStoneWidth();
|
int width = getStoneWidth();
|
||||||
|
|
|
@ -10,6 +10,9 @@ import jrummikub.model.Position;
|
||||||
import jrummikub.util.Event2;
|
import jrummikub.util.Event2;
|
||||||
import jrummikub.view.IClickable;
|
import jrummikub.view.IClickable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for panels that draw stones
|
||||||
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
abstract class StonePanel extends JPanel implements IClickable {
|
abstract class StonePanel extends JPanel implements IClickable {
|
||||||
private StonePainter stonePainter;
|
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> rangeClickEvent = new Event2<Position, Boolean>();
|
||||||
private Event2<Position, Boolean> setClickEvent = new Event2<Position, Boolean>();
|
private Event2<Position, Boolean> setClickEvent = new Event2<Position, Boolean>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the stone painter
|
||||||
|
*/
|
||||||
protected StonePainter getStonePainter() {
|
protected StonePainter getStonePainter() {
|
||||||
return stonePainter;
|
return stonePainter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new StonePanel with default scale factor
|
||||||
|
*/
|
||||||
public StonePanel() {
|
public StonePanel() {
|
||||||
this(1);
|
this(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new StonePanel with a given scale factor
|
||||||
|
*
|
||||||
|
* @param scale
|
||||||
|
* the grid scale
|
||||||
|
*/
|
||||||
public StonePanel(float scale) {
|
public StonePanel(float scale) {
|
||||||
super(true); // Set double buffered
|
super(true); // Set double buffered
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,9 @@ import jrummikub.model.StoneSet;
|
||||||
import jrummikub.view.IStoneCollection;
|
import jrummikub.view.IStoneCollection;
|
||||||
import jrummikub.view.ITable;
|
import jrummikub.view.ITable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The implementation of the table
|
||||||
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
class Table extends StonePanel implements ITable {
|
class Table extends StonePanel implements ITable {
|
||||||
private final static ImageIcon background = new ImageIcon(
|
private final static ImageIcon background = new ImageIcon(
|
||||||
|
@ -61,7 +64,13 @@ class Table extends StonePanel implements ITable {
|
||||||
return stoneCollection;
|
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;
|
selectedStones = stones;
|
||||||
stoneCollection.setSelectedStones(stones);
|
stoneCollection.setSelectedStones(stones);
|
||||||
repaint();
|
repaint();
|
||||||
|
@ -80,6 +89,9 @@ class Table extends StonePanel implements ITable {
|
||||||
y + height - stoneCollection.getHeight() - COLLECTION_GAP);
|
y + height - stoneCollection.getHeight() - COLLECTION_GAP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new Table instance
|
||||||
|
*/
|
||||||
Table() {
|
Table() {
|
||||||
super(DEFAULT_SCALE);
|
super(DEFAULT_SCALE);
|
||||||
|
|
||||||
|
@ -119,7 +131,7 @@ class Table extends StonePanel implements ITable {
|
||||||
stoneCollection.addComponentListener(rescaleListener);
|
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();
|
float x = pos.getX();
|
||||||
int width = getStonePainter().getStoneWidth(), height = getStonePainter()
|
int width = getStonePainter().getStoneWidth(), height = getStonePainter()
|
||||||
.getStoneHeight();
|
.getStoneHeight();
|
||||||
|
|
|
@ -14,6 +14,9 @@ import jrummikub.view.IPlayerPanel;
|
||||||
import jrummikub.view.ITable;
|
import jrummikub.view.ITable;
|
||||||
import jrummikub.view.IView;
|
import jrummikub.view.IView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of the top-level view interface
|
||||||
|
*/
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class View extends JFrame implements IView {
|
public class View extends JFrame implements IView {
|
||||||
private Table table;
|
private Table table;
|
||||||
|
@ -35,6 +38,9 @@ public class View extends JFrame implements IView {
|
||||||
return playerPanel;
|
return playerPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new instance of the view
|
||||||
|
*/
|
||||||
public View() {
|
public View() {
|
||||||
super("JRummikub");
|
super("JRummikub");
|
||||||
setLayout(null);
|
setLayout(null);
|
||||||
|
|
Reference in a new issue