summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl/TablePanel.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/view/impl/TablePanel.java')
-rw-r--r--src/jrummikub/view/impl/TablePanel.java104
1 files changed, 71 insertions, 33 deletions
diff --git a/src/jrummikub/view/impl/TablePanel.java b/src/jrummikub/view/impl/TablePanel.java
index 93509a6..5749890 100644
--- a/src/jrummikub/view/impl/TablePanel.java
+++ b/src/jrummikub/view/impl/TablePanel.java
@@ -11,6 +11,7 @@ import java.awt.geom.AffineTransform;
import java.awt.geom.Area;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@@ -20,6 +21,7 @@ import javax.swing.SwingUtilities;
import jrummikub.model.Position;
import jrummikub.model.Stone;
+import jrummikub.model.StoneColor;
import jrummikub.model.StoneSet;
import jrummikub.util.Event1;
import jrummikub.util.IListener1;
@@ -39,8 +41,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
private final static ImageIcon BRIGHT_BACKGROUND = new ImageIcon(
HandPanel.class.getResource("/jrummikub/resource/bright_felt.png"));
- private final static double MIN_VISIBLE_WIDTH = 15;
- private final static double MIN_VISIBLE_HEIGHT = 7.5f;
+ private final static double MIN_VISIBLE_WIDTH = 10;
+ private final static double MIN_VISIBLE_HEIGHT = 5;
private final static double HORIZONTAL_MARGIN = 1;
private final static double VERTICAL_MARGIN = 0.7f;
private final static double CONNECTOR_WIDTH = 0.25f;
@@ -49,8 +51,9 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
private StoneCollectionPanel stoneCollection;
- private Iterable<Pair<StoneSet, Position>> stoneSets = Collections
- .emptySet();
+ private Iterable<Pair<StoneSet, Position>> stoneSets = Collections.emptySet();
+ private List<Pair<StoneSet, Position>> pauseStoneSets;
+
private Collection<Stone> selectedStones = Collections.emptyList();
private Event1<StoneSet> leftConnectorClickEvent = new Event1<StoneSet>();
@@ -59,6 +62,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
private StoneSet leftHoveredConnector;
private StoneSet rightHoveredConnector;
+ private boolean pauseMode = false;
+
@Override
public Event1<StoneSet> getLeftConnectorClickEvent() {
return leftConnectorClickEvent;
@@ -99,7 +104,7 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
* Sets the currently selected stones
*
* @param stones
- * the selected stones
+ * the selected stones
*/
void setSelectedStones(Collection<Stone> stones) {
selectedStones = stones;
@@ -107,12 +112,35 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
repaint();
}
+ void createPauseStoneSets() {
+ pauseStoneSets = new ArrayList<Pair<StoneSet, Position>>();
+
+ Stone stoneCoffee1 = new Stone(-'\u2615', StoneColor.BLACK);
+
+ Stone stoneP = new Stone(-'P', StoneColor.BLACK);
+ Stone stonea = new Stone(-'a', StoneColor.ORANGE);
+ Stone stoneu = new Stone(-'u', StoneColor.BLUE);
+ Stone stones = new Stone(-'s', StoneColor.RED);
+ Stone stonee = new Stone(-'e', StoneColor.BLACK);
+
+ Stone stoneCoffee2 = new Stone(-'\u2615', StoneColor.RED);
+
+ pauseStoneSets.add(new Pair<StoneSet, Position>(new StoneSet(stoneCoffee1),
+ new Position(-4, 0)));
+ pauseStoneSets.add(new Pair<StoneSet, Position>(new StoneSet(Arrays.asList(
+ stoneP, stonea, stoneu, stones, stonee)), new Position(-2.5, 0)));
+ pauseStoneSets.add(new Pair<StoneSet, Position>(new StoneSet(stoneCoffee2),
+ new Position(3, 0)));
+ }
+
/**
* Creates a new Table instance
*/
TablePanel() {
setLayout(null);
+ createPauseStoneSets();
+
stoneCollection = new StoneCollectionPanel();
stoneCollection.getOtherClickEvent().add(new IListener1<Point>() {
@@ -138,7 +166,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
double minx = -MIN_VISIBLE_WIDTH / 2, maxx = MIN_VISIBLE_WIDTH / 2;
double miny = -MIN_VISIBLE_HEIGHT / 2, maxy = MIN_VISIBLE_HEIGHT / 2;
- for (Pair<StoneSet, Position> entry : stoneSets) {
+ for (Pair<StoneSet, Position> entry : (pauseMode ? pauseStoneSets
+ : stoneSets)) {
Position p = entry.getSecond();
StoneSet stoneSet = entry.getFirst();
@@ -156,19 +185,19 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
}
return new Rectangle2D.Double(minx - HORIZONTAL_MARGIN, miny
- - VERTICAL_MARGIN, maxx - minx + 2 * HORIZONTAL_MARGIN, maxy
- - miny + 2 * VERTICAL_MARGIN);
+ - VERTICAL_MARGIN, maxx - minx + 2 * HORIZONTAL_MARGIN, maxy - miny + 2
+ * VERTICAL_MARGIN);
}
private void rescale() {
Insets insets = getInsets();
int x = insets.left, y = insets.top, width = getWidth() - insets.left
- - insets.right, height = getHeight() - insets.top
- - insets.bottom;
+ - insets.right, height = getHeight() - insets.top - insets.bottom;
int collectionHeight = (int) (height * COLLECTION_RATIO);
- stoneCollection.setBounds(x, y + height - collectionHeight
- - COLLECTION_GAP, width, collectionHeight);
+ stoneCollection
+ .setBounds(x, y + height - collectionHeight - COLLECTION_GAP, width,
+ collectionHeight);
setScale();
@@ -205,8 +234,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
}
// right connector
- rect = new Rectangle2D.Double(x + stoneSet.getSize(), y,
- CONNECTOR_WIDTH, 1);
+ rect = new Rectangle2D.Double(x + stoneSet.getSize(), y, CONNECTOR_WIDTH,
+ 1);
if (rect.contains(pos.getX(), pos.getY())) {
rightConnectorClickEvent.emit(stoneSet);
return true;
@@ -237,8 +266,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
}
// right connector
- rect = new Rectangle2D.Double(x + stoneSet.getSize(), y,
- CONNECTOR_WIDTH, 1);
+ rect = new Rectangle2D.Double(x + stoneSet.getSize(), y, CONNECTOR_WIDTH,
+ 1);
if (rect.contains(pos.getX(), pos.getY())) {
rightHoveredConnector = stoneSet;
break;
@@ -260,10 +289,10 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
.getStoneHeight();
Rectangle2D extent = calculateTableExtent();
- return new Pair<Integer, Integer>(
- (int) (width / 2 - extent.getCenterX() * stoneWidth),
- (int) ((height * (1 - COLLECTION_RATIO)) / 2 - extent
- .getCenterY() * stoneHeight));
+ return new Pair<Integer, Integer>((int) (width / 2 - extent.getCenterX()
+ * stoneWidth),
+ (int) ((height * (1 - COLLECTION_RATIO)) / 2 - extent.getCenterY()
+ * stoneHeight));
}
private void paintStoneSet(Graphics2D g, StoneSet stoneSet, Position pos,
@@ -278,10 +307,9 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
// Left connector
- leftConnectorArea.add(new Area(new Rectangle2D.Double(Math.round(x
- * width)
- - (int) width * CONNECTOR_WIDTH + 1, Math.round(pos.getY()
- * height), (int) (width * CONNECTOR_WIDTH), height)));
+ leftConnectorArea.add(new Area(new Rectangle2D.Double(Math.round(x * width)
+ - (int) width * CONNECTOR_WIDTH + 1, Math.round(pos.getY() * height),
+ (int) (width * CONNECTOR_WIDTH), height)));
for (Stone stone : stoneSet) {
getStonePainter().paintStone(g, stone, new Position(x, pos.getY()),
@@ -290,8 +318,8 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
}
// Right connector
- rightConnectorArea.add(new Area(new Rectangle2D.Double(Math.round(x
- * width), Math.round(pos.getY() * height),
+ rightConnectorArea.add(new Area(new Rectangle2D.Double(Math
+ .round(x * width), Math.round(pos.getY() * height),
(int) (width * CONNECTOR_WIDTH), height)));
}
@@ -314,17 +342,21 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
Area connectorArea = new Area();
Area hoveredConnectorArea = new Area();
- for (Pair<StoneSet, Position> entry : stoneSets) {
- paintStoneSet(g, entry.getFirst(), entry.getSecond(),
- connectorArea, hoveredConnectorArea);
+ for (Pair<StoneSet, Position> entry : (pauseMode ? pauseStoneSets
+ : stoneSets)) {
+ paintStoneSet(g, entry.getFirst(), entry.getSecond(), connectorArea,
+ hoveredConnectorArea);
+ }
+
+ if (pauseMode) {
+ return;
}
g.setClip(connectorArea);
g.setTransform(oldTransform);
for (int x = 0; x < getWidth(); x += DARK_BACKGROUND.getIconWidth()) {
- for (int y = 0; y < getHeight(); y += DARK_BACKGROUND
- .getIconHeight()) {
+ for (int y = 0; y < getHeight(); y += DARK_BACKGROUND.getIconHeight()) {
DARK_BACKGROUND.paintIcon(this, g, x, y);
}
}
@@ -340,12 +372,18 @@ class TablePanel extends AbstractStonePanel implements ITablePanel {
g.setTransform(oldTransform);
for (int x = 0; x < getWidth(); x += BRIGHT_BACKGROUND.getIconWidth()) {
- for (int y = 0; y < getHeight(); y += BRIGHT_BACKGROUND
- .getIconHeight()) {
+ for (int y = 0; y < getHeight(); y += BRIGHT_BACKGROUND.getIconHeight()) {
BRIGHT_BACKGROUND.paintIcon(this, g, x, y);
}
}
g.setClip(oldClip);
}
+
+ void enablePauseMode(boolean enable) {
+ stoneCollection.enablePauseMode(enable);
+
+ pauseMode = enable;
+ repaint();
+ }
}