summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl
diff options
context:
space:
mode:
Diffstat (limited to 'src/jrummikub/view/impl')
-rw-r--r--src/jrummikub/view/impl/HandPanel.java13
-rw-r--r--src/jrummikub/view/impl/ImageUtil.java16
-rw-r--r--src/jrummikub/view/impl/PausePanel.java95
-rw-r--r--src/jrummikub/view/impl/PlayerPanel.java146
-rw-r--r--src/jrummikub/view/impl/StartTurnPanel.java12
-rw-r--r--src/jrummikub/view/impl/StoneCollectionPanel.java11
-rw-r--r--src/jrummikub/view/impl/StonePainter.java86
-rw-r--r--src/jrummikub/view/impl/TablePanel.java104
-rw-r--r--src/jrummikub/view/impl/View.java87
-rw-r--r--src/jrummikub/view/impl/WinPanel.java10
10 files changed, 385 insertions, 195 deletions
diff --git a/src/jrummikub/view/impl/HandPanel.java b/src/jrummikub/view/impl/HandPanel.java
index 1851ed9..75d424a 100644
--- a/src/jrummikub/view/impl/HandPanel.java
+++ b/src/jrummikub/view/impl/HandPanel.java
@@ -37,8 +37,8 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
HandPanel.class.getResource("/jrummikub/resource/dark_wood.png"));
BACKGROUND = new BufferedImage(image.getIconWidth(), image.getIconHeight(),
BufferedImage.TYPE_INT_RGB);
- DARK_BACKGROUND = new BufferedImage(darkImage.getIconWidth(), darkImage.getIconHeight(),
- BufferedImage.TYPE_INT_RGB);
+ DARK_BACKGROUND = new BufferedImage(darkImage.getIconWidth(),
+ darkImage.getIconHeight(), BufferedImage.TYPE_INT_RGB);
image.paintIcon(null, BACKGROUND.createGraphics(), 0, 0);
darkImage.paintIcon(null, DARK_BACKGROUND.createGraphics(), 0, 0);
@@ -54,6 +54,7 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
private boolean repaintAll = true;
private Collection<Stone> selectedStones = Collections.emptyList();
+
/**
* Creates a new Board instance
*/
@@ -92,9 +93,9 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
int size = height / HEIGHT;
-
- BufferedImage background = isEnabled() ? scaledBackground : scaledDarkBackground ;
-
+ BufferedImage background = isEnabled() ? scaledBackground
+ : scaledDarkBackground;
+
if (repaintAll) {
if (background.getHeight() != size) {
if (!isEnabled()) {
@@ -104,7 +105,7 @@ class HandPanel extends AbstractStonePanel implements IHandPanel {
}
background = isEnabled() ? scaledBackground : scaledDarkBackground;
}
-
+
for (int i = 0; i < HEIGHT; ++i) {
for (int xpos = -size * i / 3; xpos < width; xpos += size) {
g.drawImage(background, xpos, size * i, null);
diff --git a/src/jrummikub/view/impl/ImageUtil.java b/src/jrummikub/view/impl/ImageUtil.java
index 0254343..6af816e 100644
--- a/src/jrummikub/view/impl/ImageUtil.java
+++ b/src/jrummikub/view/impl/ImageUtil.java
@@ -19,7 +19,21 @@ class ImageUtil {
g.fillRect(0, 0, size, size);
g.setColor(c);
- g.fillRect(border, border, size - 2*border, size - 2*border);
+ g.fillRect(border, border, size - 2 * border, size - 2 * border);
+
+ return new ImageIcon(image);
+ }
+
+ static ImageIcon createPauseIcon(int size) {
+ BufferedImage image = new BufferedImage(size, size,
+ BufferedImage.TYPE_INT_ARGB);
+
+ Graphics2D g = image.createGraphics();
+
+ g.setColor(Color.BLACK);
+ int barWidth = (int) (size * 0.425f);
+ g.fillRect(0, 0, barWidth, size);
+ g.fillRect(size - barWidth, 0, barWidth, size);
return new ImageIcon(image);
}
diff --git a/src/jrummikub/view/impl/PausePanel.java b/src/jrummikub/view/impl/PausePanel.java
new file mode 100644
index 0000000..60e7038
--- /dev/null
+++ b/src/jrummikub/view/impl/PausePanel.java
@@ -0,0 +1,95 @@
+package jrummikub.view.impl;
+
+import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.border.EmptyBorder;
+
+import jrummikub.util.Event;
+import jrummikub.util.IEvent;
+
+/**
+ * A panel that is displayed before a player's turn
+ */
+@SuppressWarnings("serial")
+class PausePanel extends JPanel {
+ private final static int PANEL_INSET = 15;
+ private final static int PANEL_SEPARATOR = 10;
+ private final static float PANEL_FIRST_LINE_HEIGHT = 0.375f;
+ private final static int PANEL_MAX_WIDTH = 180;
+ private final static float MAX_BUTTON_FONT_SIZE = 12;
+
+ private JLabel pauseLabel;
+ private JButton endPauseButton;
+
+ private Event endPauseEvent = new Event();
+
+ /**
+ * Creates a new StartTurnPanel
+ */
+ PausePanel() {
+ setLayout(null);
+ setBorder(new EmptyBorder(PANEL_INSET, PANEL_INSET, PANEL_INSET,
+ PANEL_INSET));
+
+ pauseLabel = new JLabel();
+ pauseLabel.setHorizontalAlignment(JLabel.CENTER);
+ pauseLabel.setHorizontalTextPosition(JLabel.CENTER);
+ pauseLabel.setVerticalAlignment(JLabel.CENTER);
+ pauseLabel.setVerticalTextPosition(JLabel.CENTER);
+ add(pauseLabel);
+
+ endPauseButton = new JButton("Spiel fortsetzen");
+ endPauseButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ endPauseEvent.emit();
+ }
+ });
+ add(endPauseButton);
+
+ addComponentListener(new ComponentAdapter() {
+ @Override
+ public void componentResized(ComponentEvent e) {
+ rescale();
+ }
+ });
+ }
+
+ void setCurrentPlayerName(String playerName) {
+ pauseLabel.setText("Der Zug von " + playerName + " ist pausiert.");
+ }
+
+ IEvent getEndPauseEvent() {
+ return endPauseEvent;
+ }
+
+ 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;
+
+ if (width > PANEL_MAX_WIDTH) {
+ x += (width - PANEL_MAX_WIDTH) / 4;
+ width = width / 2 + PANEL_MAX_WIDTH / 2;
+ }
+
+ int firstLineHeight = (int) ((height - PANEL_SEPARATOR) * PANEL_FIRST_LINE_HEIGHT);
+ int buttonWidth = width;
+ int buttonHeight = height - PANEL_SEPARATOR - firstLineHeight;
+ float fontSize = (float) Math.sqrt(buttonWidth * buttonHeight) / 5;
+ if (fontSize > MAX_BUTTON_FONT_SIZE)
+ fontSize = MAX_BUTTON_FONT_SIZE;
+
+ pauseLabel.setBounds(x, y, width, firstLineHeight);
+ endPauseButton.setBounds(x, y + firstLineHeight + PANEL_SEPARATOR,
+ buttonWidth, buttonHeight);
+ endPauseButton.setFont(endPauseButton.getFont().deriveFont(fontSize));
+ }
+}
diff --git a/src/jrummikub/view/impl/PlayerPanel.java b/src/jrummikub/view/impl/PlayerPanel.java
index dcd22ed..d69323f 100644
--- a/src/jrummikub/view/impl/PlayerPanel.java
+++ b/src/jrummikub/view/impl/PlayerPanel.java
@@ -53,11 +53,13 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
private JButton endTurnButton;
private JButton keepStonesButton;
private JButton redealButton;
+ private JButton pauseButton;
private Event sortByGroupsEvent = new Event();
private Event sortByRunsEvent = new Event();
private Event endTurnEvent = new Event();
private Event redealEvent = new Event();
+ private Event pauseEvent = new Event();
HandPanel getHandPanel() {
return hand;
@@ -117,6 +119,10 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
return redealEvent;
}
+ IEvent getPauseEvent() {
+ return pauseEvent;
+ }
+
private void createLeftPanel() {
leftPanel = new JPanel();
leftPanel.setLayout(null);
@@ -206,6 +212,13 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
redealEvent.emit();
}
});
+
+ pauseButton = createButton(rightPanel, null, new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ pauseEvent.emit();
+ }
+ });
}
private JButton createButton(JPanel panel, String caption,
@@ -271,6 +284,67 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
hand.addComponentListener(rescaleListener);
}
+ @Override
+ public void setEndTurnMode(TurnMode turnMode) {
+
+ switch (turnMode) {
+ case MAY_REDEAL:
+ endTurnButton.setVisible(false);
+ keepStonesButton.setVisible(true);
+ redealButton.setVisible(true);
+ break;
+ case INSPECT_ONLY:
+ endTurnButton.setText("N\u00e4chster Spieler");
+ endTurnButton.setVisible(true);
+ keepStonesButton.setVisible(false);
+ redealButton.setVisible(false);
+ break;
+ case NORMAL_TURN:
+ endTurnButton.setText("Zug beenden");
+ endTurnButton.setVisible(true);
+ keepStonesButton.setVisible(false);
+ redealButton.setVisible(false);
+ break;
+ }
+ }
+
+ void showButtons(boolean show) {
+ currentPlayerNameLabel.setVisible(show);
+ hasLaidOutLabel.setVisible(show);
+ sortByGroupsButton.setVisible(show);
+ sortByRunsButton.setVisible(show);
+ timeBar.setVisible(show);
+ pauseButton.setVisible(show);
+
+ if (!show) {
+ handRowDownButton.setForeground(Color.GRAY);
+ handRowDownButton.setEnabled(false);
+ handRowUpButton.setForeground(Color.GRAY);
+ handRowUpButton.setEnabled(false);
+ endTurnButton.setVisible(false);
+ redealButton.setVisible(false);
+ keepStonesButton.setVisible(false);
+ }
+ }
+
+ void enableButtons(boolean enable) {
+ sortByGroupsButton.setEnabled(enable);
+ sortByRunsButton.setEnabled(enable);
+ if (!enable) {
+ setEndTurnMode(TurnMode.NORMAL_TURN);
+ endTurnButton.setText("<html><center>Computer denkt nach");
+ hand.setStones(Collections.<Pair<Stone, Position>> emptyList());
+ handRowDownButton.setForeground(Color.GRAY);
+ handRowDownButton.setEnabled(false);
+ handRowUpButton.setForeground(Color.GRAY);
+ handRowUpButton.setEnabled(false);
+ }
+ endTurnButton.setEnabled(enable);
+ redealButton.setEnabled(enable);
+ keepStonesButton.setEnabled(enable);
+ hand.setEnabled(enable);
+ }
+
private class LeftPanelResizeListener extends ComponentAdapter {
@Override
public void componentResized(ComponentEvent e) {
@@ -341,10 +415,16 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
fontSize * 1.5f));
handRowDownButton.setBounds(0, getHeight() / 2, handButtonWidth,
getHeight() / 2);
- handRowDownButton.setFont(handRowDownButton.getFont().deriveFont(
- fontSize * 1.5f));
+ handRowDownButton.setFont(handRowDownButton.getFont()
+ .deriveFont(fontSize));
+
+ timeBar.setBounds(x, y, width - firstLineHeight - SIDE_PANEL_SEPARATOR,
+ firstLineHeight);
+ pauseButton.setBounds(x + width - firstLineHeight, y, firstLineHeight,
+ firstLineHeight);
+ pauseButton.setIcon(ImageUtil
+ .createPauseIcon((int) (firstLineHeight * 0.5f)));
- timeBar.setBounds(x, y, width, firstLineHeight);
endTurnButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR,
buttonWidth, buttonHeight);
endTurnButton.setFont(endTurnButton.getFont().deriveFont(fontSize));
@@ -360,64 +440,4 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
}
}
-
- @Override
- public void setEndTurnMode(TurnMode turnMode) {
-
- switch (turnMode) {
- case MAY_REDEAL:
- endTurnButton.setVisible(false);
- keepStonesButton.setVisible(true);
- redealButton.setVisible(true);
- break;
- case INSPECT_ONLY:
- endTurnButton.setText("N\u00e4chster Spieler");
- endTurnButton.setVisible(true);
- keepStonesButton.setVisible(false);
- redealButton.setVisible(false);
- break;
- case NORMAL_TURN:
- endTurnButton.setText("Zug beenden");
- endTurnButton.setVisible(true);
- keepStonesButton.setVisible(false);
- redealButton.setVisible(false);
- break;
- }
- }
-
- void showButtons(boolean show) {
- currentPlayerNameLabel.setVisible(show);
- hasLaidOutLabel.setVisible(show);
- sortByGroupsButton.setVisible(show);
- sortByRunsButton.setVisible(show);
- timeBar.setVisible(show);
-
- if (!show) {
- handRowDownButton.setForeground(Color.GRAY);
- handRowDownButton.setEnabled(false);
- handRowUpButton.setForeground(Color.GRAY);
- handRowUpButton.setEnabled(false);
- endTurnButton.setVisible(false);
- redealButton.setVisible(false);
- keepStonesButton.setVisible(false);
- }
- }
-
- void enableButtons(boolean enable) {
- sortByGroupsButton.setEnabled(enable);
- sortByRunsButton.setEnabled(enable);
- if (!enable) {
- setEndTurnMode(TurnMode.NORMAL_TURN);
- endTurnButton.setText("<html><center>Computer denkt nach");
- hand.setStones(Collections.<Pair<Stone, Position>> emptyList());
- handRowDownButton.setForeground(Color.GRAY);
- handRowDownButton.setEnabled(false);
- handRowUpButton.setForeground(Color.GRAY);
- handRowUpButton.setEnabled(false);
- }
- endTurnButton.setEnabled(enable);
- redealButton.setEnabled(enable);
- keepStonesButton.setEnabled(enable);
- hand.setEnabled(enable);
- }
}
diff --git a/src/jrummikub/view/impl/StartTurnPanel.java b/src/jrummikub/view/impl/StartTurnPanel.java
index 871a615..10cd8a0 100644
--- a/src/jrummikub/view/impl/StartTurnPanel.java
+++ b/src/jrummikub/view/impl/StartTurnPanel.java
@@ -62,22 +62,10 @@ class StartTurnPanel extends JPanel {
});
}
- /**
- * Sets the current player name
- *
- * @param playerName
- * the player name
- */
void setCurrentPlayerName(String playerName) {
startTurnLabel.setText(playerName + " ist jetzt an der Reihe.");
}
- /**
- * The start turn event is emitted when the current player has clicked the
- * start turn button
- *
- * @return the event
- */
IEvent getStartTurnEvent() {
return startTurnEvent;
}
diff --git a/src/jrummikub/view/impl/StoneCollectionPanel.java b/src/jrummikub/view/impl/StoneCollectionPanel.java
index 3bd57ea..c742522 100644
--- a/src/jrummikub/view/impl/StoneCollectionPanel.java
+++ b/src/jrummikub/view/impl/StoneCollectionPanel.java
@@ -37,6 +37,8 @@ class StoneCollectionPanel extends AbstractStonePanel implements
private Event1<Point> otherClickEvent = new Event1<Point>();
+ private boolean pauseMode = false;
+
/**
* Creates a new StoneCollection instance
*/
@@ -121,6 +123,10 @@ class StoneCollectionPanel extends AbstractStonePanel implements
}
}
+ if (pauseMode) {
+ return;
+ }
+
int inset = (int) (getHeight() * INSET_RATIO);
int width = getStonePainter().getStoneWidth() * selectedStones.size() + 2
* inset, height = getHeight();
@@ -148,4 +154,9 @@ class StoneCollectionPanel extends AbstractStonePanel implements
}
}
}
+
+ void enablePauseMode(boolean enable) {
+ pauseMode = enable;
+ repaint();
+ }
}
diff --git a/src/jrummikub/view/impl/StonePainter.java b/src/jrummikub/view/impl/StonePainter.java
index ea52387..298f9ac 100644
--- a/src/jrummikub/view/impl/StonePainter.java
+++ b/src/jrummikub/view/impl/StonePainter.java
@@ -60,8 +60,7 @@ class StonePainter {
int g = (int) (color.getGreen() * BRIGHTER_SCALE);
int b = (int) (color.getBlue() * BRIGHTER_SCALE);
- return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255
- : b);
+ return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255 : b);
}
private static Color hover(Color color) {
@@ -69,28 +68,27 @@ class StonePainter {
int g = (int) (color.getGreen() * HOVER_RATIO + 255 * (1 - HOVER_RATIO));
int b = (int) (color.getBlue() * HOVER_RATIO + 255 * (1 - HOVER_RATIO));
- return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255
- : b);
+ return new Color(r > 255 ? 255 : r, g > 255 ? 255 : g, b > 255 ? 255 : b);
}
public static Color getColor(StoneColor color) {
switch (color) {
- case BLACK:
- return new Color(0.0f, 0.0f, 0.0f);
- case BLUE:
- return new Color(0.0f, 0.0f, 1.0f);
- case ORANGE:
- return new Color(1.0f, 0.4f, 0.0f);
- case RED:
- return new Color(0.9f, 0.0f, 0.25f);
- case AQUA:
- return new Color(0.0f, 0.85f, 0.75f);
- case GREEN:
- return new Color(0.0f, 0.65f, 0.0f);
- case VIOLET:
- return new Color(0.75f, 0.325f, 0.75f);
- case GRAY:
- return new Color(0.5f, 0.5f, 0.5f);
+ case BLACK:
+ return new Color(0.0f, 0.0f, 0.0f);
+ case BLUE:
+ return new Color(0.0f, 0.0f, 1.0f);
+ case ORANGE:
+ return new Color(1.0f, 0.4f, 0.0f);
+ case RED:
+ return new Color(0.9f, 0.0f, 0.25f);
+ case AQUA:
+ return new Color(0.0f, 0.85f, 0.75f);
+ case GREEN:
+ return new Color(0.0f, 0.65f, 0.0f);
+ case VIOLET:
+ return new Color(0.75f, 0.325f, 0.75f);
+ case GRAY:
+ return new Color(0.5f, 0.5f, 0.5f);
}
return null;
@@ -100,7 +98,7 @@ class StonePainter {
* Sets the new grid scale
*
* @param scale
- * the new scale
+ * the new scale
*/
public void setScale(double scale) {
this.scale = scale;
@@ -114,9 +112,9 @@ class StonePainter {
/**
* @param x
- * x position in screen coordinates
+ * x position in screen coordinates
* @param y
- * y position in screen coordinates
+ * y position in screen coordinates
* @return position in grid coordinates
*/
public Position calculatePosition(int x, int y) {
@@ -211,21 +209,19 @@ class StonePainter {
defaultStones.put(color, new HashMap<Integer, BufferedImage>());
selectedStones.put(color, new HashMap<Integer, BufferedImage>());
hoveredStones.put(color, new HashMap<Integer, BufferedImage>());
- hoveredSelectedStones.put(color,
- new HashMap<Integer, BufferedImage>());
+ hoveredSelectedStones.put(color, new HashMap<Integer, BufferedImage>());
}
}
/**
* @param scale
- * the scaling factor for the grid coordinates
+ * the scaling factor for the grid coordinates
*/
StonePainter(double scale) {
setScale(scale);
}
- private void paintStoneBackground(Graphics2D g, Rectangle r,
- Color background) {
+ private void paintStoneBackground(Graphics2D g, Rectangle r, Color background) {
// Paint background
g.setColor(background);
g.fillRect(r.x, r.y, r.width, r.height);
@@ -326,9 +322,8 @@ class StonePainter {
pos + (fm.getAscent() - fm.getDescent()) / 2 + 1);
}
g.setColor(color);
- g.drawString(value,
- (int) (r.x + r.width / 2 - stringRect.getWidth() / 2), pos
- + (fm.getAscent() - fm.getDescent()) / 2);
+ g.drawString(value, (int) (r.x + r.width / 2 - stringRect.getWidth() / 2),
+ pos + (fm.getAscent() - fm.getDescent()) / 2);
}
private void paintCircle(Graphics2D g, Rectangle r, Color background) {
@@ -337,42 +332,41 @@ class StonePainter {
// Paint circle
g.setColor(background.darker());
- g.drawArc(r.x + r.width / 2 - size / 2, pos - size / 2, size, size, 50,
- 170);
+ g.drawArc(r.x + r.width / 2 - size / 2, pos - size / 2, size, size, 50, 170);
g.setColor(brighter(background));
- g.drawArc((int) (r.x + r.width / 2 - size / 2), pos - size / 2, size,
- size, -130, 170);
+ g.drawArc((int) (r.x + r.width / 2 - size / 2), pos - size / 2, size, size,
+ -130, 170);
}
/**
* Paints a stone
*
* @param g
- * the graphics context to paint the stone on
+ * the graphics context to paint the stone on
* @param stone
- * the stone to paint
+ * the stone to paint
* @param p
- * the position of the stone
+ * the position of the stone
* @param selected
- * if selected is true the stone will be painted darker
+ * if selected is true the stone will be painted darker
* @param hovered
- * if hovered is true the stone will be painted brighter
+ * if hovered is true the stone will be painted brighter
*/
public void paintStone(Graphics2D g, Stone stone, Position p,
boolean selected, boolean hovered) {
int width = getStoneWidth();
int height = getStoneHeight();
- int x = (int) Math.round(p.getX() * width), y = (int) Math.round(p
- .getY() * height);
+ int x = (int) Math.round(p.getX() * width), y = (int) Math.round(p.getY()
+ * height);
if (stone.isJoker()) {
- g.drawImage(getStoneImage(stone.getColor(), 0, selected, hovered),
- x, y, null);
+ g.drawImage(getStoneImage(stone.getColor(), 0, selected, hovered), x, y,
+ null);
} else {
g.drawImage(
- getStoneImage(stone.getColor(), stone.getValue(), selected,
- hovered), x, y, null);
+ getStoneImage(stone.getColor(), stone.getValue(), selected, hovered),
+ x, y, null);
}
}
}
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();
+ }
}
diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java
index a6e5efe..8f67433 100644
--- a/src/jrummikub/view/impl/View.java
+++ b/src/jrummikub/view/impl/View.java
@@ -53,10 +53,13 @@ public class View extends JFrame implements IView {
private TablePanel table;
private PlayerPanel playerPanel;
private StartTurnPanel startTurnPanel;
+ private PausePanel pausePanel;
private WinPanel winPanel;
private SettingsPanel settingsPanel;
private ScorePanel scorePanel;
+ private BottomPanelType bottomPanelType;
+
private JFileChooser chooser;
private Event menuNewGameEvent = new Event();
@@ -115,11 +118,20 @@ public class View extends JFrame implements IView {
}
@Override
+ public IEvent getPauseEvent() {
+ return playerPanel.getPauseEvent();
+ }
+
+ @Override
+ public IEvent getEndPauseEvent() {
+ return pausePanel.getEndPauseEvent();
+ }
+
+ @Override
public void clearView() {
showScorePanel(false);
showSettingsPanel(false);
- getHandPanel().setStones(
- Collections.<Pair<Stone, Position>> emptyList());
+ getHandPanel().setStones(Collections.<Pair<Stone, Position>> emptyList());
getTablePanel().setStoneSets(
Collections.<Pair<StoneSet, Position>> emptyList());
setSelectedStones(Collections.<Stone> emptyList());
@@ -219,14 +231,18 @@ public class View extends JFrame implements IView {
mainLayer.add(table);
playerPanel = new PlayerPanel();
- playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0,
- 0, Color.BLACK));
+ playerPanel.setBorder(new MatteBorder(PLAYER_PANEL_BORDER_WIDTH, 0, 0, 0,
+ Color.BLACK));
mainLayer.add(playerPanel);
startTurnPanel = new StartTurnPanel();
startTurnPanel.setVisible(false);
mainLayer.add(startTurnPanel);
+ pausePanel = new PausePanel();
+ pausePanel.setVisible(false);
+ mainLayer.add(pausePanel);
+
winPanel = new WinPanel();
winPanel.setVisible(false);
mainLayer.add(winPanel);
@@ -251,6 +267,14 @@ public class View extends JFrame implements IView {
setVisible(true);
}
+ @Override
+ public void enablePauseMode(boolean enable) {
+ table.enablePauseMode(enable);
+
+ doSetBottomPanel(enable ? null : bottomPanelType);
+ pausePanel.setVisible(enable);
+ }
+
private void rescale() {
int width = getContentPane().getWidth(), height = getContentPane()
.getHeight();
@@ -270,6 +294,7 @@ public class View extends JFrame implements IView {
table.validate();
playerPanel.setBounds(0, tableHeight, width, playerPanelHeight);
startTurnPanel.setBounds(0, tableHeight, width, playerPanelHeight);
+ pausePanel.setBounds(0, tableHeight, width, playerPanelHeight);
winPanel.setBounds(0, tableHeight, width, playerPanelHeight);
settingsPanel.setBounds(width / 4, height / 4, width / 2, height / 2);
scorePanel.setBounds(width / 8, height / 4, width * 3 / 4, height / 2);
@@ -295,6 +320,7 @@ public class View extends JFrame implements IView {
public void setCurrentPlayerName(String playerName) {
playerPanel.setCurrentPlayerName(playerName);
startTurnPanel.setCurrentPlayerName(playerName);
+ pausePanel.setCurrentPlayerName(playerName);
}
@Override
@@ -329,24 +355,24 @@ public class View extends JFrame implements IView {
@SuppressWarnings("unchecked")
private List<Pair<Stone, Position>> createDecorationStones() {
- Pair<Stone, Position> stoneJ = new Pair<Stone, Position>(new Stone(
- -'J', StoneColor.BLACK), new Position(2.5f, 0));
- Pair<Stone, Position> stoneR = new Pair<Stone, Position>(new Stone(
- -'R', StoneColor.ORANGE), new Position(3.5f, 0));
- Pair<Stone, Position> stoneu1 = new Pair<Stone, Position>(new Stone(
- -'u', StoneColor.BLUE), new Position(4.5f, 0));
- Pair<Stone, Position> stonem1 = new Pair<Stone, Position>(new Stone(
- -'m', StoneColor.RED), new Position(5.5f, 0));
- Pair<Stone, Position> stonem2 = new Pair<Stone, Position>(new Stone(
- -'m', StoneColor.GREEN), new Position(6.5f, 0));
- Pair<Stone, Position> stonei = new Pair<Stone, Position>(new Stone(
- -'i', StoneColor.VIOLET), new Position(7.5f, 0));
- Pair<Stone, Position> stonek = new Pair<Stone, Position>(new Stone(
- -'k', StoneColor.AQUA), new Position(8.5f, 0));
- Pair<Stone, Position> stoneu2 = new Pair<Stone, Position>(new Stone(
- -'u', StoneColor.GRAY), new Position(9.5f, 0));
- Pair<Stone, Position> stoneb = new Pair<Stone, Position>(new Stone(
- -'b', StoneColor.BLACK), new Position(10.5f, 0));
+ Pair<Stone, Position> stoneJ = new Pair<Stone, Position>(new Stone(-'J',
+ StoneColor.BLACK), new Position(2.5f, 0));
+ Pair<Stone, Position> stoneR = new Pair<Stone, Position>(new Stone(-'R',
+ StoneColor.ORANGE), new Position(3.5f, 0));
+ Pair<Stone, Position> stoneu1 = new Pair<Stone, Position>(new Stone(-'u',
+ StoneColor.BLUE), new Position(4.5f, 0));
+ Pair<Stone, Position> stonem1 = new Pair<Stone, Position>(new Stone(-'m',
+ StoneColor.RED), new Position(5.5f, 0));
+ Pair<Stone, Position> stonem2 = new Pair<Stone, Position>(new Stone(-'m',
+ StoneColor.GREEN), new Position(6.5f, 0));
+ Pair<Stone, Position> stonei = new Pair<Stone, Position>(new Stone(-'i',
+ StoneColor.VIOLET), new Position(7.5f, 0));
+ Pair<Stone, Position> stonek = new Pair<Stone, Position>(new Stone(-'k',
+ StoneColor.AQUA), new Position(8.5f, 0));
+ Pair<Stone, Position> stoneu2 = new Pair<Stone, Position>(new Stone(-'u',
+ StoneColor.GRAY), new Position(9.5f, 0));
+ Pair<Stone, Position> stoneb = new Pair<Stone, Position>(new Stone(-'b',
+ StoneColor.BLACK), new Position(10.5f, 0));
Pair<Stone, Position> stone1 = new Pair<Stone, Position>(new Stone(
StoneColor.RED), new Position(2, 1));
@@ -361,21 +387,26 @@ public class View extends JFrame implements IView {
Pair<Stone, Position> stone6 = new Pair<Stone, Position>(new Stone(
StoneColor.BLACK), new Position(11, 1));
- return Arrays.asList(stoneJ, stoneR, stoneu1, stonem1, stonem2, stonei,
- stonek, stoneu2, stoneb, stone1, stone2, stone3, stone4,
- stone5, stone6);
+ return Arrays
+ .asList(stoneJ, stoneR, stoneu1, stonem1, stonem2, stonei, stonek,
+ stoneu2, stoneb, stone1, stone2, stone3, stone4, stone5, stone6);
}
@Override
public void setBottomPanel(BottomPanelType type) {
+ bottomPanelType = type;
+
+ doSetBottomPanel(type);
+ }
+
+ private void doSetBottomPanel(BottomPanelType type) {
startTurnPanel.setVisible(type == BottomPanelType.START_TURN_PANEL);
winPanel.setVisible(type == BottomPanelType.WIN_PANEL);
playerPanel.setVisible(type != BottomPanelType.START_TURN_PANEL
- && type != BottomPanelType.WIN_PANEL);
+ && type != BottomPanelType.WIN_PANEL && type != null);
if (type == BottomPanelType.START_GAME_PANEL) {
- table.setStoneSets(Collections
- .<Pair<StoneSet, Position>> emptyList());
+ table.setStoneSets(Collections.<Pair<StoneSet, Position>> emptyList());
playerPanel.getHandPanel().setStones(createDecorationStones());
}
diff --git a/src/jrummikub/view/impl/WinPanel.java b/src/jrummikub/view/impl/WinPanel.java
index ff6f68a..2134a8e 100644
--- a/src/jrummikub/view/impl/WinPanel.java
+++ b/src/jrummikub/view/impl/WinPanel.java
@@ -101,8 +101,7 @@ class WinPanel extends JPanel {
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;
if (width > PANEL_MAX_WIDTH) {
x += (width - PANEL_MAX_WIDTH) / 4;
@@ -118,14 +117,13 @@ class WinPanel extends JPanel {
newRoundButton.setBounds(x, y, buttonWidth, buttonHeight);
newRoundButton.setFont(newRoundButton.getFont().deriveFont(fontSize));
- newGameButton.setBounds(x + buttonWidth + PANEL_SEPARATOR, y,
- buttonWidth, buttonHeight);
+ newGameButton.setBounds(x + buttonWidth + PANEL_SEPARATOR, y, buttonWidth,
+ buttonHeight);
newGameButton.setFont(newGameButton.getFont().deriveFont(fontSize));
endProgramButton.setBounds(x + 2 * (buttonWidth + PANEL_SEPARATOR), y,
buttonWidth, buttonHeight);
- endProgramButton.setFont(endProgramButton.getFont()
- .deriveFont(fontSize));
+ endProgramButton.setFont(endProgramButton.getFont().deriveFont(fontSize));
}
}