diff options
40 files changed, 642 insertions, 425 deletions
diff --git a/mock/jrummikub/view/MockPlayerPanel.java b/mock/jrummikub/view/MockPlayerPanel.java index b69c109..497e445 100644 --- a/mock/jrummikub/view/MockPlayerPanel.java +++ b/mock/jrummikub/view/MockPlayerPanel.java @@ -17,6 +17,8 @@ public class MockPlayerPanel implements IPlayerPanel { /** */ public MockEvent sortByRunsEvent = new MockEvent(); /** */ + public MockEvent pauseEvent = new MockEvent(); + /** */ public TurnMode turnMode; @Override @@ -49,5 +51,4 @@ public class MockPlayerPanel implements IPlayerPanel { public void setEndTurnMode(TurnMode turnMode) { this.turnMode = turnMode; } - } diff --git a/mock/jrummikub/view/MockView.java b/mock/jrummikub/view/MockView.java index b816ea9..fd7b896 100644 --- a/mock/jrummikub/view/MockView.java +++ b/mock/jrummikub/view/MockView.java @@ -49,6 +49,10 @@ public class MockView implements IView { public MockEvent1<File> loadEvent = new MockEvent1<File>(); /** */ public MockEvent1<File> saveEvent = new MockEvent1<File>(); + /** */ + public MockEvent pauseEvent = new MockEvent(); + /** */ + public MockEvent endPauseEvent = new MockEvent(); @Override public MockTablePanel getTablePanel() { @@ -157,4 +161,20 @@ public class MockView implements IView { @Override public void clearView() { } + + @Override + public void enablePauseMode(boolean enable) { + // TODO Auto-generated method stub + + } + + @Override + public IEvent getPauseEvent() { + return pauseEvent; + } + + @Override + public IEvent getEndPauseEvent() { + return endPauseEvent; + } } diff --git a/src/jrummikub/control/ApplicationControl.java b/src/jrummikub/control/ApplicationControl.java index e4ddb55..e00952d 100644 --- a/src/jrummikub/control/ApplicationControl.java +++ b/src/jrummikub/control/ApplicationControl.java @@ -22,7 +22,7 @@ public class ApplicationControl { * Creates a new application control * * @param view - * the view to use + * the view to use */ public ApplicationControl(IView view) { this.view = view; @@ -51,14 +51,13 @@ public class ApplicationControl { new IListener3<GameSettings, GameState, IRoundState>() { @Override - public void handle(GameSettings settings, - GameState gameState, IRoundState roundState) { + public void handle(GameSettings settings, GameState gameState, + IRoundState roundState) { settingsControl.abort(); - if (gameControl != null){ + if (gameControl != null) { gameControl.abortGame(); } - gameControl = new GameControl(settings, - saveControl, view); + gameControl = new GameControl(settings, saveControl, view); addGameControlListeners(gameControl); gameControl.continueGame(gameState, roundState); @@ -70,8 +69,7 @@ public class ApplicationControl { public void handle(GameSettings settings) { saveControl.setGameSettings(settings); - gameControl = new GameControl(settings, - saveControl, view); + gameControl = new GameControl(settings, saveControl, view); addGameControlListeners(gameControl); gameControl.startGame(); diff --git a/src/jrummikub/control/GameControl.java b/src/jrummikub/control/GameControl.java index 194d0de..e00f136 100644 --- a/src/jrummikub/control/GameControl.java +++ b/src/jrummikub/control/GameControl.java @@ -33,11 +33,11 @@ public class GameControl { * Constructor * * @param gameSettings - * the game settings + * the game settings * @param saveControl - * the save control + * the save control * @param view - * the view + * the view */ public GameControl(GameSettings gameSettings, SaveControl saveControl, IView view) { @@ -174,8 +174,7 @@ public class GameControl { view.getScorePanel().setPlayers(gameSettings.getPlayerList()); view.getScorePanel().setScores(gameState.getScores()); - view.getScorePanel().setAccumulatedScore( - gameState.getAccumulatedScore()); + view.getScorePanel().setAccumulatedScore(gameState.getAccumulatedScore()); view.getScorePanel().update(); view.showScorePanel(true); } diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java index e1009af..5371b0c 100644 --- a/src/jrummikub/control/RoundControl.java +++ b/src/jrummikub/control/RoundControl.java @@ -47,9 +47,9 @@ public class RoundControl { * Create a new RoundControl using the given gameState and view * * @param roundState - * initial round state + * initial round state * @param view - * view used for user interaction + * view used for user interaction */ public RoundControl(IRoundState roundState, IView view) { this.roundState = roundState; @@ -102,12 +102,11 @@ public class RoundControl { : BottomPanelType.COMPUTER_HAND_PANEL); view.getTablePanel().setStoneSets(clonedTable.clone()); - view.setCurrentPlayerName(roundState.getActivePlayer() - .getPlayerSettings().getName()); - view.setCurrentPlayerColor(roundState.getActivePlayer() - .getPlayerSettings().getColor()); - view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer() - .getLaidOut()); + view.setCurrentPlayerName(roundState.getActivePlayer().getPlayerSettings() + .getName()); + view.setCurrentPlayerColor(roundState.getActivePlayer().getPlayerSettings() + .getColor()); + view.setCurrentPlayerHasLaidOut(roundState.getActivePlayer().getLaidOut()); if (!isHuman) startTurn(); @@ -132,11 +131,11 @@ public class RoundControl { view.getPlayerPanel().setEndTurnMode(turnMode); } turnControl = TurnControlFactory.getFactory( - roundState.getActivePlayer().getPlayerSettings() - .getTurnControlType()).create(); + roundState.getActivePlayer().getPlayerSettings().getTurnControlType()) + .create(); turnControl.setup(new ITurnControl.TurnInfo(clonedTable, clonedHand, - roundState.getActivePlayer().getLaidOut(), turnMode), - roundState.getGameSettings(), view); + roundState.getActivePlayer().getLaidOut(), turnMode), roundState + .getGameSettings(), view); turnControl.getEndOfTurnEvent().add(new IListener() { @Override public void handle() { @@ -156,10 +155,8 @@ public class RoundControl { void deal() { for (int i = 0; i < roundState.getPlayerCount(); i++) { IHand hand = roundState.getNthNextPlayer(i).getHand(); - for (int j = 0; j < roundState.getGameSettings() - .getNumberOfStonesDealt(); j++) { - hand.drop(roundState.getGameHeap().drawStone(), new Position(0, - 0)); + for (int j = 0; j < roundState.getGameSettings().getNumberOfStonesDealt(); j++) { + hand.drop(roundState.getGameHeap().drawStone(), new Position(0, 0)); } } } @@ -170,13 +167,11 @@ public class RoundControl { int totalValue = 0; for (StoneSet set : newSets) { - totalValue += set.classify(roundState.getGameSettings()) - .getSecond(); + totalValue += set.classify(roundState.getGameSettings()).getSecond(); } return totalValue == 0 - || totalValue >= roundState.getGameSettings() - .getInitialMeldThreshold(); + || totalValue >= roundState.getGameSettings().getInitialMeldThreshold(); } private void endOfTurn() { @@ -216,8 +211,7 @@ public class RoundControl { } if (!roundState.getActivePlayer().getLaidOut()) { // Player touched forbidden stones - if (!tableSetDifference(clonedTable, roundState.getTable()) - .isEmpty()) { + if (!tableSetDifference(clonedTable, roundState.getTable()).isEmpty()) { rejectMove(); return; } @@ -226,8 +220,7 @@ public class RoundControl { return; } } - Set<Stone> tableDiff = tableDifference(roundState.getTable(), - clonedTable); + Set<Stone> tableDiff = tableDifference(roundState.getTable(), clonedTable); roundState.setTable(clonedTable); @@ -243,8 +236,7 @@ public class RoundControl { } private void rejectMove() { - Set<Stone> tableDiff = tableDifference(roundState.getTable(), - clonedTable); + Set<Stone> tableDiff = tableDifference(roundState.getTable(), clonedTable); // deal penalty, reset roundState.getGameHeap().putBack(tableDiff); dealPenalty(tableDiff.size()); @@ -338,12 +330,10 @@ public class RoundControl { stonePoints = playerHand.isInitialMeldPossible(roundState .getGameSettings()) ? 200 : 100; } else { - stonePoints = playerHand.getStonePoints(roundState - .getGameSettings()); + stonePoints = playerHand.getStonePoints(roundState.getGameSettings()); } - bestScore = updateBestScore(bestScore, -stonePoints, - playerHand.getSize()); + bestScore = updateBestScore(bestScore, -stonePoints, playerHand.getSize()); points.add(-stonePoints); pointSum += stonePoints; diff --git a/src/jrummikub/control/SaveControl.java b/src/jrummikub/control/SaveControl.java index e0589e6..1412199 100644 --- a/src/jrummikub/control/SaveControl.java +++ b/src/jrummikub/control/SaveControl.java @@ -27,7 +27,7 @@ public class SaveControl { * Creates a new SaveControl * * @param view - * the view to use + * the view to use */ public SaveControl(IView view) { view.getSaveEvent().add(new IListener1<File>() { @@ -53,7 +53,7 @@ public class SaveControl { * Sets the current game settings * * @param gameSettings - * the game settings + * the game settings */ public void setGameSettings(GameSettings gameSettings) { this.gameSettings = gameSettings; @@ -63,7 +63,7 @@ public class SaveControl { * Sets the current game state * * @param gameState - * the game state + * the game state */ public void setGameState(GameState gameState) { this.gameState = gameState; @@ -73,7 +73,7 @@ public class SaveControl { * Sets the current round state * * @param roundState - * the round state + * the round state */ public void setRoundState(IRoundState roundState) { this.roundState = roundState; @@ -110,8 +110,8 @@ public class SaveControl { return; } try { - ObjectOutputStream stream = new ObjectOutputStream( - new FileOutputStream(file)); + ObjectOutputStream stream = new ObjectOutputStream(new FileOutputStream( + file)); stream.writeObject(gameSettings); stream.writeObject(gameState); diff --git a/src/jrummikub/control/TurnTimer.java b/src/jrummikub/control/TurnTimer.java index 17bdf0f..77c5b55 100644 --- a/src/jrummikub/control/TurnTimer.java +++ b/src/jrummikub/control/TurnTimer.java @@ -22,7 +22,7 @@ public class TurnTimer implements ActionListener, ITurnTimer { * Create a new timer using a given view to display the current time left * * @param view - * view to display + * view to display */ public TurnTimer(IView view) { this.view = view; diff --git a/src/jrummikub/control/turn/AbstractTurnControl.java b/src/jrummikub/control/turn/AbstractTurnControl.java index ae1e155..84c478a 100644 --- a/src/jrummikub/control/turn/AbstractTurnControl.java +++ b/src/jrummikub/control/turn/AbstractTurnControl.java @@ -16,7 +16,6 @@ import jrummikub.view.IView; * Abstract base class for TurnControls */ public abstract class AbstractTurnControl implements ITurnControl { - protected Event endOfTurnEvent = new Event(); protected Event redealEvent = new Event(); protected TurnInfo turnInfo; @@ -24,8 +23,7 @@ public abstract class AbstractTurnControl implements ITurnControl { protected IView view; protected ITurnTimer timer; protected List<Connection> connections = new ArrayList<Connection>(); - - + @Override public IEvent getEndOfTurnEvent() { return endOfTurnEvent; @@ -35,7 +33,17 @@ public abstract class AbstractTurnControl implements ITurnControl { public IEvent getRedealEvent() { return redealEvent; } - + + private void pauseTurn() { + timer.stopTimer(); + view.enablePauseMode(true); + } + + private void resumeTurn() { + timer.startTimer(); + view.enablePauseMode(false); + } + protected abstract void timeOut(); @Override @@ -52,15 +60,27 @@ public abstract class AbstractTurnControl implements ITurnControl { timeOut(); } })); + connections.add(view.getPauseEvent().add(new IListener() { + @Override + public void handle() { + pauseTurn(); + } + })); + connections.add(view.getEndPauseEvent().add(new IListener() { + @Override + public void handle() { + resumeTurn(); + } + })); } - + protected void cleanUp() { timer.stopTimer(); for (Connection c : connections) { c.remove(); } } - + public void abortTurn() { cleanUp(); } diff --git a/src/jrummikub/control/turn/BaseAIControl.java b/src/jrummikub/control/turn/BaseAIControl.java index 43ade18..11519c3 100644 --- a/src/jrummikub/control/turn/BaseAIControl.java +++ b/src/jrummikub/control/turn/BaseAIControl.java @@ -36,7 +36,7 @@ public class BaseAIControl extends AbstractTurnControl { timer.startTimer(); computeThread.start(); } - + protected void timeOut() { cleanUp(); endOfTurnEvent.emit(); @@ -49,15 +49,15 @@ public class BaseAIControl extends AbstractTurnControl { private void compute() { switch (turnInfo.getTurnMode()) { - case MAY_REDEAL: - emitRedeal(); - break; - case INSPECT_ONLY: - emitEndOfTurn(); - break; - case NORMAL_TURN: - turn(); - break; + case MAY_REDEAL: + emitRedeal(); + break; + case INSPECT_ONLY: + emitEndOfTurn(); + break; + case NORMAL_TURN: + turn(); + break; } } @@ -111,8 +111,10 @@ public class BaseAIControl extends AbstractTurnControl { for (Stone stone : set) { handStones.add(pickUpMatchingStone(stone)); } - turnInfo.getTable().drop(new StoneSet(handStones), new Position( - (float) Math.random() * 30 - 15, (float) Math.random() * 6 - 3)); + turnInfo.getTable().drop( + new StoneSet(handStones), + new Position((float) Math.random() * 30 - 15, + (float) Math.random() * 6 - 3)); } emitEndOfTurn(); diff --git a/src/jrummikub/control/turn/HumanTurnControl.java b/src/jrummikub/control/turn/HumanTurnControl.java index 02541d2..2ab7b21 100644 --- a/src/jrummikub/control/turn/HumanTurnControl.java +++ b/src/jrummikub/control/turn/HumanTurnControl.java @@ -48,7 +48,7 @@ public class HumanTurnControl extends AbstractTurnControl { HumanTurnControl(ITurnTimer testTimer) { this.timer = testTimer; } - + protected void timeOut() { endOfTurn(false); } @@ -97,13 +97,12 @@ public class HumanTurnControl extends AbstractTurnControl { } })); - connections.add(view.getPlayerPanel().getRedealEvent() - .add(new IListener() { - @Override - public void handle() { - endOfTurn(true); - } - })); + connections.add(view.getPlayerPanel().getRedealEvent().add(new IListener() { + @Override + public void handle() { + endOfTurn(true); + } + })); } private void addHandPanelHandlers() { @@ -304,8 +303,10 @@ public class HumanTurnControl extends AbstractTurnControl { } pickUpSelectedStones(); - turnInfo.getTable().drop(new StoneSet(selectedStones), new Position(position.getX() - - selectedStones.size() * 0.5f, position.getY() - 0.5f)); + turnInfo.getTable().drop( + new StoneSet(selectedStones), + new Position(position.getX() - selectedStones.size() * 0.5f, position + .getY() - 0.5f)); selectedStones.clear(); view.getTablePanel().setStoneSets(turnInfo.getTable()); @@ -421,15 +422,14 @@ public class HumanTurnControl extends AbstractTurnControl { turnInfo.getTable().drop(joinedSet, newPos); } else { StoneSet joinedSet = new StoneSet(selectedStones).join(newSet); - turnInfo.getTable().drop(joinedSet, new Position(newPos.getX() - - selectedStones.size(), newPos.getY())); + turnInfo.getTable().drop(joinedSet, + new Position(newPos.getX() - selectedStones.size(), newPos.getY())); } } else { turnInfo.getTable().drop( new StoneSet(selectedStones), - new Position(pos.getX() - + (set.getSize() - selectedStones.size()) * 0.5f, - pos.getY())); + new Position(pos.getX() + (set.getSize() - selectedStones.size()) + * 0.5f, pos.getY())); } selectedStones.clear(); @@ -521,8 +521,7 @@ public class HumanTurnControl extends AbstractTurnControl { static class HandStonePositionComparator implements Comparator<Pair<Stone, Position>> { @Override - public int compare(Pair<Stone, Position> pair1, - Pair<Stone, Position> pair2) { + public int compare(Pair<Stone, Position> pair1, Pair<Stone, Position> pair2) { Position pos1 = pair1.getSecond(), pos2 = pair2.getSecond(); if (pos1.getY() < pos2.getY()) { return -1; diff --git a/src/jrummikub/control/turn/ITurnControl.java b/src/jrummikub/control/turn/ITurnControl.java index 5a3d550..63290d5 100644 --- a/src/jrummikub/control/turn/ITurnControl.java +++ b/src/jrummikub/control/turn/ITurnControl.java @@ -44,6 +44,11 @@ public interface ITurnControl { public void startTurn(); /** + * Abort the turn + */ + public void abortTurn(); + + /** * The TurnInfo class encapsulates all information concerning the current turn */ public class TurnInfo { @@ -108,9 +113,4 @@ public interface ITurnControl { return turnMode; } } - - /** - * Abort the turn - */ - public void abortTurn(); }
\ No newline at end of file diff --git a/src/jrummikub/control/turn/TurnControlFactory.java b/src/jrummikub/control/turn/TurnControlFactory.java index 95396aa..b42f7ff 100644 --- a/src/jrummikub/control/turn/TurnControlFactory.java +++ b/src/jrummikub/control/turn/TurnControlFactory.java @@ -32,10 +32,10 @@ public abstract class TurnControlFactory { */ static public TurnControlFactory getFactory(Type type) { switch (type) { - case HUMAN: - return HumanTurnControl.getFactory(); - case COMPUTER: - return BaseAIControl.getFactory(); + case HUMAN: + return HumanTurnControl.getFactory(); + case COMPUTER: + return BaseAIControl.getFactory(); } return null; } diff --git a/src/jrummikub/model/IPlayer.java b/src/jrummikub/model/IPlayer.java index 25471b8..9df3741 100644 --- a/src/jrummikub/model/IPlayer.java +++ b/src/jrummikub/model/IPlayer.java @@ -17,7 +17,8 @@ public interface IPlayer extends Serializable { /** * Set the current hand of the player * - * @param hand the new hand + * @param hand + * the new hand */ public void setHand(IHand hand); @@ -39,7 +40,7 @@ public interface IPlayer extends Serializable { * Set if the player laid out * * @param laidOut - * the player laid out + * the player laid out * */ void setLaidOut(boolean laidOut); diff --git a/src/jrummikub/model/IStoneTray.java b/src/jrummikub/model/IStoneTray.java index d286484..d411c9e 100644 --- a/src/jrummikub/model/IStoneTray.java +++ b/src/jrummikub/model/IStoneTray.java @@ -8,7 +8,7 @@ import jrummikub.util.Pair; * Interface for the {@link StoneTray} model
*
* @param <E>
- * Objects held by the IStoneTray
+ * Objects held by the IStoneTray
*/
public interface IStoneTray<E extends Sizeable> extends
Iterable<Pair<E, Position>>, Cloneable, Serializable {
@@ -17,9 +17,9 @@ public interface IStoneTray<E extends Sizeable> extends * Adds object to the tray
*
* @param object
- * object to add to Hand
+ * object to add to Hand
* @param position
- * {@link Position} to put the object
+ * {@link Position} to put the object
*/
public void drop(E object, Position position);
@@ -27,7 +27,7 @@ public interface IStoneTray<E extends Sizeable> extends * Returns the position of an object that is already on the tray
*
* @param object
- * object whose position is requested
+ * object whose position is requested
* @return position of the object or null when the object is not on the tray
*/
public Position getPosition(E object);
@@ -36,7 +36,7 @@ public interface IStoneTray<E extends Sizeable> extends * Tries to pick up (remove) a given object
*
* @param object
- * object to pick up
+ * object to pick up
* @return true when the object was successfully removed
*/
public boolean pickUp(E object);
diff --git a/src/jrummikub/model/StoneHeap.java b/src/jrummikub/model/StoneHeap.java index d49bede..2f08767 100644 --- a/src/jrummikub/model/StoneHeap.java +++ b/src/jrummikub/model/StoneHeap.java @@ -14,7 +14,7 @@ import java.util.Random; public class StoneHeap implements Serializable { private static final long serialVersionUID = -5247740086907775125L; - + ArrayList<Stone> heap; private Random generator = new Random(); diff --git a/src/jrummikub/model/StoneSet.java b/src/jrummikub/model/StoneSet.java index 1bb0823..5412a3a 100644 --- a/src/jrummikub/model/StoneSet.java +++ b/src/jrummikub/model/StoneSet.java @@ -14,7 +14,7 @@ import static jrummikub.model.StoneSet.Type.*; /** Class managing {@link Stone}s joined together to form sets */ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable { private static final long serialVersionUID = -3852631195648599398L; - + static final float VERTICAL_BORDER = 0.5f; static final float HORIZONTAL_BORDER = 0.125f; private ArrayList<Stone> stones; @@ -23,7 +23,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable { * Create a new single stone stone set * * @param stone - * single stone of the set + * single stone of the set */ public StoneSet(Stone stone) { stones = new ArrayList<Stone>(Collections.singletonList(stone)); @@ -33,7 +33,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable { * Create a stone set from a list of stones * * @param stones - * list of stones to build a set of + * list of stones to build a set of */ public StoneSet(List<Stone> stones) { this.stones = new ArrayList<Stone>(stones); @@ -53,7 +53,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable { * Test for rule conflict within the StoneSet * * @param settings - * GameSettings + * GameSettings * * @return true when the set is valid according to the rules */ @@ -62,11 +62,11 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable { } /** - * Test for rule conflict within the StoneSet and determine whether the set - * is a group or a run + * Test for rule conflict within the StoneSet and determine whether the set is + * a group or a run * * @param settings - * GameSettings + * GameSettings * * @return GROUP or RUN for valid sets, INVALID otherwise */ @@ -87,14 +87,10 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable { if (stones.size() > settings.getHighestValue()) { return new Pair<Type, Integer>(INVALID, 0); } else if (stones.size() > settings.getStoneColors().size()) { - return new Pair<Type, Integer>( - RUN, - (settings.getHighestValue() * (settings - .getHighestValue() + 1)) - / 2 + return new Pair<Type, Integer>(RUN, + (settings.getHighestValue() * (settings.getHighestValue() + 1)) / 2 - (stones.size() - settings.getHighestValue()) - * (stones.size() - settings.getHighestValue() - 1) - / 2); + * (stones.size() - settings.getHighestValue() - 1) / 2); } else { return new Pair<Type, Integer>(GROUP, stones.size() * settings.getHighestValue()); @@ -117,7 +113,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable { * Test for rule conflict within the StoneSet, assuming we have a run * * @param referencePosition - * position of stone used as reference (any non-joker stone) + * position of stone used as reference (any non-joker stone) * @param settings */ private int isValidRun(int referencePosition, GameSettings settings) { @@ -177,7 +173,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable { * Stone Sets * * @param position - * Splitting {@link Position} + * Splitting {@link Position} * @return A pair of StoneSets, one for each split part */ public Pair<StoneSet, StoneSet> splitAt(int position) { @@ -187,8 +183,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable { return new Pair<StoneSet, StoneSet>(this, null); } StoneSet firstSet = new StoneSet(stones.subList(0, position)); - StoneSet secondSet = new StoneSet(stones.subList(position, - stones.size())); + StoneSet secondSet = new StoneSet(stones.subList(position, stones.size())); return new Pair<StoneSet, StoneSet>(firstSet, secondSet); } @@ -196,7 +191,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable { * Joins StoneSet to another StoneSet and returns the resulting new StoneSet * * @param other - * StoneSet to be joined to active StoneSet + * StoneSet to be joined to active StoneSet * @return the combined StoneSet */ public StoneSet join(StoneSet other) { @@ -219,7 +214,7 @@ public class StoneSet implements Iterable<Stone>, Sizeable, Serializable { * Returns the i-th stone of the set (starting with 0) * * @param i - * number of the stone to return + * number of the stone to return * @return the i-th stone */ public Stone get(int i) { diff --git a/src/jrummikub/model/StoneTray.java b/src/jrummikub/model/StoneTray.java index 8806b1c..aaedaad 100644 --- a/src/jrummikub/model/StoneTray.java +++ b/src/jrummikub/model/StoneTray.java @@ -11,11 +11,11 @@ import jrummikub.util.Pair; * or {@link StoneSet}s. * * @param <E> - * Type of positioned objects (must implement Sizeable) + * Type of positioned objects (must implement Sizeable) */ public class StoneTray<E extends Sizeable> implements IStoneTray<E> { private static final long serialVersionUID = -6329309928640027222L; - + protected HashMap<E, Pair<E, Position>> objects = new HashMap<E, Pair<E, Position>>(); /** Possible move directions in case of overlapping Stones/Sets */ @@ -52,8 +52,7 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> { if (currentObject == object) continue; Position currentPosition = getPosition(currentObject); - if (!objectsOverlap(object, position, currentObject, - currentPosition)) { + if (!objectsOverlap(object, position, currentObject, currentPosition)) { continue; } // Object would be placed inside the current object @@ -63,22 +62,23 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> { Position newPosition = null; // Move object to avoid overlap switch (newDirection) { - case TOP: - newPosition = new Position(currentPosition.getX(), - position.getY() - currentObject.getHeight()); - break; - case BOTTOM: - newPosition = new Position(currentPosition.getX(), - position.getY() + object.getHeight()); - break; - case LEFT: - newPosition = new Position(position.getX() - - currentObject.getWidth(), currentPosition.getY()); - break; - case RIGHT: - newPosition = new Position(position.getX() + object.getWidth(), - currentPosition.getY()); - break; + case TOP: + newPosition = new Position(currentPosition.getX(), position.getY() + - currentObject.getHeight()); + break; + case BOTTOM: + newPosition = new Position(currentPosition.getX(), position.getY() + + object.getHeight()); + break; + case LEFT: + newPosition = new Position( + position.getX() - currentObject.getWidth(), + currentPosition.getY()); + break; + case RIGHT: + newPosition = new Position(position.getX() + object.getWidth(), + currentPosition.getY()); + break; } objects.remove(currentObject); @@ -87,14 +87,14 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> { } /** - * Checks whether the object may be placed on the given position, computes - * new position if not + * Checks whether the object may be placed on the given position, computes new + * position if not * * @param object - * to be dropped + * to be dropped * @param dir * @param pos - * the object is dropped at + * the object is dropped at * @return null if the drop is valid, new position otherwise */ protected Pair<Position, Direction> fixInvalidDrop(E object, Position pos, @@ -122,15 +122,13 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> { if (lessOrEqual(position1.getX() + object1.getWidth(), position2.getX())) { return false; } - if (lessOrEqual(position1.getY() + object1.getHeight(), - position2.getY())) { + if (lessOrEqual(position1.getY() + object1.getHeight(), position2.getY())) { return false; } if (lessOrEqual(position2.getX() + object2.getWidth(), position1.getX())) { return false; } - if (lessOrEqual(position2.getY() + object2.getHeight(), - position1.getY())) { + if (lessOrEqual(position2.getY() + object2.getHeight(), position1.getY())) { return false; } return true; @@ -171,15 +169,13 @@ public class StoneTray<E extends Sizeable> implements IStoneTray<E> { double blockingRight = blocking.getSecond().getX() + blocking.getFirst().getWidth(); double overlapRight = Math.min(objectRight, blockingRight); - double overlapLeft = Math.max(position.getX(), blocking.getSecond() - .getX()); + double overlapLeft = Math.max(position.getX(), blocking.getSecond().getX()); double overlapX = overlapRight - overlapLeft; double objectBottom = position.getY() + object.getHeight(); double blockingBottom = blocking.getSecond().getY() + blocking.getFirst().getHeight(); double overlapBottom = Math.min(objectBottom, blockingBottom); - double overlapTop = Math.max(position.getY(), blocking.getSecond() - .getY()); + double overlapTop = Math.max(position.getY(), blocking.getSecond().getY()); double overlapY = overlapBottom - overlapTop; // vertical or horizontal Shift // TODO magic factor diff --git a/src/jrummikub/util/Event3.java b/src/jrummikub/util/Event3.java index a309111..f500495 100644 --- a/src/jrummikub/util/Event3.java +++ b/src/jrummikub/util/Event3.java @@ -6,9 +6,9 @@ import java.util.HashSet; * Simple single parameter event generator * * @param <T1> - * type of the first event parameter + * type of the first event parameter * @param <T2> - * type of the second event parameter + * type of the second event parameter */ public class Event3<T1, T2, T3> implements IEvent3<T1, T2, T3> { private HashSet<IListener3<T1, T2, T3>> listeners = new HashSet<IListener3<T1, T2, T3>>(); @@ -34,9 +34,9 @@ public class Event3<T1, T2, T3> implements IEvent3<T1, T2, T3> { * Generate a single event * * @param value1 - * the first event parameter + * the first event parameter * @param value2 - * the second event parameter + * the second event parameter */ public void emit(T1 value1, T2 value2, T3 value3) { for (IListener3<T1, T2, T3> listener : listeners) { diff --git a/src/jrummikub/util/IEvent.java b/src/jrummikub/util/IEvent.java index b8d418c..907bf8e 100644 --- a/src/jrummikub/util/IEvent.java +++ b/src/jrummikub/util/IEvent.java @@ -6,7 +6,7 @@ public interface IEvent { * Start to publish all events to a given listener * * @param listener - * target listener + * target listener * @return a connection to remove the listener */ public Connection add(IListener listener); @@ -15,7 +15,7 @@ public interface IEvent { * Stop publishing events to a given listener * * @param listener - * target listener + * target listener */ public void remove(IListener listener); } diff --git a/src/jrummikub/util/IEvent1.java b/src/jrummikub/util/IEvent1.java index 9508d05..dfb5e1c 100644 --- a/src/jrummikub/util/IEvent1.java +++ b/src/jrummikub/util/IEvent1.java @@ -4,14 +4,14 @@ package jrummikub.util; * Interface for classes that can generate events having a single parameter * * @param <T> - * type of the event parameter + * type of the event parameter */ public interface IEvent1<T> { /** * Start to publish all events to a given listener * * @param listener - * target listener + * target listener * @return a connection to remove the listener */ public Connection add(IListener1<T> listener); @@ -20,7 +20,7 @@ public interface IEvent1<T> { * Stop publishing events to a given listener * * @param listener - * target listener + * target listener */ public void remove(IListener1<T> listener); } diff --git a/src/jrummikub/util/IEvent3.java b/src/jrummikub/util/IEvent3.java index fd04364..47ef1cd 100644 --- a/src/jrummikub/util/IEvent3.java +++ b/src/jrummikub/util/IEvent3.java @@ -4,16 +4,16 @@ package jrummikub.util; * Interface for classes that can generate events having a two parameters * * @param <T1> - * type of the first event parameter + * type of the first event parameter * @param <T2> - * type of the second event parameter + * type of the second event parameter */ public interface IEvent3<T1, T2, T3> { /** * Start to publish all events to a given listener * * @param listener - * target listener + * target listener * @return a connection to remove the listener */ public Connection add(IListener3<T1, T2, T3> listener); @@ -22,7 +22,7 @@ public interface IEvent3<T1, T2, T3> { * Stop publishing events to a given listener * * @param listener - * target listener + * target listener */ public void remove(IListener3<T1, T2, T3> listener); } diff --git a/src/jrummikub/util/IListener.java b/src/jrummikub/util/IListener.java index f805452..eb56848 100644 --- a/src/jrummikub/util/IListener.java +++ b/src/jrummikub/util/IListener.java @@ -4,6 +4,6 @@ package jrummikub.util; * Interface for classes that can receive parameterless events */ public interface IListener { - /** This method is called whenever a class we're listening to emits an event */ - public void handle(); + /** This method is called whenever a class we're listening to emits an event */ + public void handle(); } diff --git a/src/jrummikub/util/IListener1.java b/src/jrummikub/util/IListener1.java index 5a01569..9534e7a 100644 --- a/src/jrummikub/util/IListener1.java +++ b/src/jrummikub/util/IListener1.java @@ -5,14 +5,14 @@ package jrummikub.util; * parameter * * @param <T> - * type of the event parameter + * type of the event parameter */ public interface IListener1<T> { /** * This method is called whenever a class we're listening to emits an event * * @param value - * the event parameter + * the event parameter */ - public void handle(T value); + public void handle(T value); } diff --git a/src/jrummikub/util/IListener2.java b/src/jrummikub/util/IListener2.java index dd571a3..7d3a837 100644 --- a/src/jrummikub/util/IListener2.java +++ b/src/jrummikub/util/IListener2.java @@ -5,18 +5,18 @@ package jrummikub.util; * parameters * * @param <T1> - * type of the first event parameter + * type of the first event parameter * @param <T2> - * type of the first event parameter + * type of the first event parameter */ public interface IListener2<T1, T2> { /** * This method is called whenever a class we're listening to emits an event * * @param value1 - * the first event parameter + * the first event parameter * @param value2 - * the second event parameter + * the second event parameter */ - public void handle(T1 value1, T2 value2); + public void handle(T1 value1, T2 value2); } diff --git a/src/jrummikub/util/IListener3.java b/src/jrummikub/util/IListener3.java index ae1d6ce..a4f8474 100644 --- a/src/jrummikub/util/IListener3.java +++ b/src/jrummikub/util/IListener3.java @@ -5,18 +5,18 @@ package jrummikub.util; * parameters * * @param <T1> - * type of the first event parameter + * type of the first event parameter * @param <T2> - * type of the first event parameter + * type of the first event parameter */ public interface IListener3<T1, T2, T3> { /** * This method is called whenever a class we're listening to emits an event * * @param value1 - * the first event parameter + * the first event parameter * @param value2 - * the second event parameter + * the second event parameter */ public void handle(T1 value1, T2 value2, T3 value3); } diff --git a/src/jrummikub/view/IClickable.java b/src/jrummikub/view/IClickable.java index 4f44b5e..0d3eec3 100644 --- a/src/jrummikub/view/IClickable.java +++ b/src/jrummikub/view/IClickable.java @@ -7,12 +7,12 @@ import jrummikub.util.IEvent1; * An interface for view elements that can emit click events */ public interface IClickable { - /** - * the click event is emitted when the player clicks on the table/hand/etc. - * - * @return the event; the first parameter is the position of the click in grid - * coordinates, the second is true when the player wants to add stones - * to his selection instead of replacing them - */ - public IEvent1<Position> getClickEvent(); + /** + * the click event is emitted when the player clicks on the table/hand/etc. + * + * @return the event; the first parameter is the position of the click in grid + * coordinates, the second is true when the player wants to add stones + * to his selection instead of replacing them + */ + public IEvent1<Position> getClickEvent(); } diff --git a/src/jrummikub/view/IHandPanel.java b/src/jrummikub/view/IHandPanel.java index ea08f86..54896dc 100644 --- a/src/jrummikub/view/IHandPanel.java +++ b/src/jrummikub/view/IHandPanel.java @@ -12,7 +12,7 @@ public interface IHandPanel extends IStonePanel, IClickable { * Set the player's stones to display on the board * * @param stones - * the stones + * the stones */ public void setStones(Iterable<Pair<Stone, Position>> stones); diff --git a/src/jrummikub/view/IScorePanel.java b/src/jrummikub/view/IScorePanel.java index 22e27fe..b423115 100644 --- a/src/jrummikub/view/IScorePanel.java +++ b/src/jrummikub/view/IScorePanel.java @@ -11,7 +11,7 @@ public interface IScorePanel { * Sets the scores of the played rounds * * @param scores - * the round scores + * the round scores */ public void setScores(Iterable<Score> scores); @@ -19,7 +19,7 @@ public interface IScorePanel { * Sets the accumulated scores to display * * @param accumulatedScore - * the accumulated score + * the accumulated score */ public void setAccumulatedScore(Score accumulatedScore); @@ -27,7 +27,7 @@ public interface IScorePanel { * Sets the player list to display * * @param players - * the player list + * the player list */ void setPlayers(Iterable<PlayerSettings> players); diff --git a/src/jrummikub/view/ISettingsPanel.java b/src/jrummikub/view/ISettingsPanel.java index e76a3a2..a67d8b7 100644 --- a/src/jrummikub/view/ISettingsPanel.java +++ b/src/jrummikub/view/ISettingsPanel.java @@ -36,8 +36,8 @@ public interface ISettingsPanel { }; /** - * The add player event is emitted when the user wants to add a player to - * the player list + * The add player event is emitted when the user wants to add a player to the + * player list * * @return the event */ @@ -84,8 +84,8 @@ public interface ISettingsPanel { public IEvent1<Integer> getChangeInitialMeldThresholdEvent(); /** - * The change StoneSet number event is emitted when the user wants to use - * more or less than 2 StoneSets per color + * The change StoneSet number event is emitted when the user wants to use more + * or less than 2 StoneSets per color * * @return number of SoneSets */ @@ -126,7 +126,7 @@ public interface ISettingsPanel { * Sets an error to display * * @param error - * the kind of error + * the kind of error */ public void setError(SettingsError error); @@ -134,7 +134,7 @@ public interface ISettingsPanel { * Enables or disables the start game button * * @param enable - * specifies if the button is to be enabled or disabled + * specifies if the button is to be enabled or disabled */ public void enableStartGameButton(boolean enable); @@ -142,7 +142,7 @@ public interface ISettingsPanel { * Enables or disables the add player button * * @param enable - * specifies if the button is to be enabled or disabled + * specifies if the button is to be enabled or disabled */ public void enableAddPlayerButton(boolean enable); @@ -150,7 +150,7 @@ public interface ISettingsPanel { * Enables or disables the remove player buttons * * @param enable - * specifies if the buttons are to be enabled or disabled + * specifies if the buttons are to be enabled or disabled */ public void enableRemovePlayerButtons(boolean enable); @@ -159,7 +159,7 @@ public interface ISettingsPanel { * Sets the game settings to display * * @param gameSettings - * the settings + * the settings */ public void setGameSettings(GameSettings gameSettings); diff --git a/src/jrummikub/view/IView.java b/src/jrummikub/view/IView.java index 797c704..0ee2753 100644 --- a/src/jrummikub/view/IView.java +++ b/src/jrummikub/view/IView.java @@ -49,7 +49,7 @@ public interface IView { * Sets the current player's name * * @param playerName - * the player name + * the player name */ public void setCurrentPlayerName(String playerName); @@ -57,7 +57,7 @@ public interface IView { * Sets the stones that are to be painted selected * * @param stones - * the stones to be painted selected + * the stones to be painted selected */ public void setSelectedStones(Collection<Stone> stones); @@ -86,7 +86,7 @@ public interface IView { * Shows or hides the game settings panel * * @param show - * specifies if the panel shall be shown or hidden + * specifies if the panel shall be shown or hidden */ public void showSettingsPanel(boolean show); @@ -94,7 +94,7 @@ public interface IView { * Shows or hides the score panel * * @param show - * specifies if the panel shall be shown or hidden + * specifies if the panel shall be shown or hidden */ public void showScorePanel(boolean show); @@ -103,16 +103,16 @@ public interface IView { * along with the name * * @param color - * the current player's color + * the current player's color */ public void setCurrentPlayerColor(Color color); /** - * Is used for the PlayerPanel to display if a player has laid out along - * with the name + * Is used for the PlayerPanel to display if a player has laid out along with + * the name * * @param hasLaidOut - * specifies if the current player has laid out or not + * specifies if the current player has laid out or not */ public void setCurrentPlayerHasLaidOut(boolean hasLaidOut); @@ -127,29 +127,13 @@ public interface IView { * Sets the bottom panels type * * @param type - * the type of the bottom panel + * the type of the bottom panel */ public void setBottomPanel(BottomPanelType type); /** - * Different types of bottom panels - */ - public enum BottomPanelType { - /** */ - START_GAME_PANEL, - /** */ - START_TURN_PANEL, - /** */ - HUMAN_HAND_PANEL, - /** */ - COMPUTER_HAND_PANEL, - /** */ - WIN_PANEL - } - - /** - * The menu new game event is emitted when the user selects the new game - * menu entry + * The menu new game event is emitted when the user selects the new game menu + * entry * * @return the event */ @@ -178,5 +162,27 @@ public interface IView { */ public IEvent1<File> getSaveEvent(); + public IEvent getPauseEvent(); + + public IEvent getEndPauseEvent(); + public void clearView(); + + void enablePauseMode(boolean enable); + + /** + * Different types of bottom panels + */ + public enum BottomPanelType { + /** */ + START_GAME_PANEL, + /** */ + START_TURN_PANEL, + /** */ + HUMAN_HAND_PANEL, + /** */ + COMPUTER_HAND_PANEL, + /** */ + WIN_PANEL + } } 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)); } } |