From b62babba458c703c4a7597bf4640a936227d734a Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 21 Jun 2011 03:52:25 +0200 Subject: Disable pause function in network mode git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@536 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/control/RoundControl.java | 11 ++- .../control/network/NetworkRoundControl.java | 2 +- .../control/network/NetworkTurnControl.java | 4 - .../control/turn/AbstractTurnControl.java | 6 ++ src/jrummikub/control/turn/ITurnControl.java | 10 ++- src/jrummikub/view/IView.java | 44 +++++------ src/jrummikub/view/impl/PlayerPanel.java | 35 ++++++--- src/jrummikub/view/impl/TablePanel.java | 8 -- src/jrummikub/view/impl/View.java | 86 +++++++++++----------- 9 files changed, 117 insertions(+), 89 deletions(-) (limited to 'src') diff --git a/src/jrummikub/control/RoundControl.java b/src/jrummikub/control/RoundControl.java index 71980e1..62a57cf 100644 --- a/src/jrummikub/control/RoundControl.java +++ b/src/jrummikub/control/RoundControl.java @@ -76,6 +76,11 @@ public class RoundControl { private Event1 endOfRoundEvent = new Event1(); protected List connections = new ArrayList(); private boolean roundFinished; + private boolean mayPause; + + public RoundControl(IRoundState roundState, IView view) { + this(roundState, view, true); + } /** * Create a new RoundControl using the given gameState and view @@ -85,9 +90,10 @@ public class RoundControl { * @param view * view used for user interaction */ - public RoundControl(IRoundState roundState, IView view) { + protected RoundControl(IRoundState roundState, IView view, boolean mayPause) { this.roundState = roundState; this.view = view; + this.mayPause = mayPause; } /** @@ -221,7 +227,8 @@ public class RoundControl { view.getPlayerPanel().setEndTurnMode(turnMode); } - turnControl.setup(new ITurnControl.TurnInfo(roundState, turnMode), + turnControl.setup( + new ITurnControl.TurnInfo(roundState, turnMode, mayPause), roundState.getGameSettings(), view); turnControl.getEndOfTurnEvent().add( new IListener2() { diff --git a/src/jrummikub/control/network/NetworkRoundControl.java b/src/jrummikub/control/network/NetworkRoundControl.java index afe6a6e..95b5885 100644 --- a/src/jrummikub/control/network/NetworkRoundControl.java +++ b/src/jrummikub/control/network/NetworkRoundControl.java @@ -15,7 +15,7 @@ public class NetworkRoundControl extends RoundControl { public NetworkRoundControl(IRoundState roundState, IView view, final IConnectionControl connectionControl, boolean startActive) { - super(roundState, view); + super(roundState, view, false); this.connectionControl = connectionControl; currentlyActive = startActive; diff --git a/src/jrummikub/control/network/NetworkTurnControl.java b/src/jrummikub/control/network/NetworkTurnControl.java index 35002f7..a884fda 100644 --- a/src/jrummikub/control/network/NetworkTurnControl.java +++ b/src/jrummikub/control/network/NetworkTurnControl.java @@ -53,8 +53,4 @@ public class NetworkTurnControl extends AbstractTurnControl { @Override protected void timeOut() { } - - @Override - protected void pauseTurn() { - } } diff --git a/src/jrummikub/control/turn/AbstractTurnControl.java b/src/jrummikub/control/turn/AbstractTurnControl.java index d64ee62..9bdd6e2 100644 --- a/src/jrummikub/control/turn/AbstractTurnControl.java +++ b/src/jrummikub/control/turn/AbstractTurnControl.java @@ -59,6 +59,10 @@ public abstract class AbstractTurnControl implements ITurnControl { } protected void pauseTurn() { + if (!turnInfo.isMayPause()) { + return; + } + timer.stopTimer(); view.enablePauseMode(true); } @@ -108,6 +112,8 @@ public abstract class AbstractTurnControl implements ITurnControl { resumeTurn(); } })); + + view.setMayPause(info.isMayPause()); } protected void cleanUp() { diff --git a/src/jrummikub/control/turn/ITurnControl.java b/src/jrummikub/control/turn/ITurnControl.java index 6994466..ab4d6ae 100644 --- a/src/jrummikub/control/turn/ITurnControl.java +++ b/src/jrummikub/control/turn/ITurnControl.java @@ -73,6 +73,8 @@ public interface ITurnControl { private TurnMode turnMode; + private boolean mayPause; + /** * Creates a new TurnInfo instance * @@ -81,7 +83,7 @@ public interface ITurnControl { * @param turnMode * the turn mode */ - public TurnInfo(IRoundState roundState, TurnMode turnMode) { + public TurnInfo(IRoundState roundState, TurnMode turnMode, boolean mayPause) { this.roundState = roundState; oldTable = roundState.getTable(); @@ -91,6 +93,8 @@ public interface ITurnControl { this.hand = (IHand) oldHand.clone(); this.turnMode = turnMode; + + this.mayPause = mayPause; } public IRoundState getRoundState() { @@ -150,5 +154,9 @@ public interface ITurnControl { public TurnMode getTurnMode() { return turnMode; } + + public boolean isMayPause() { + return mayPause; + } } } \ No newline at end of file diff --git a/src/jrummikub/view/IView.java b/src/jrummikub/view/IView.java index f03b153..b6c7163 100644 --- a/src/jrummikub/view/IView.java +++ b/src/jrummikub/view/IView.java @@ -57,7 +57,7 @@ public interface IView { * Sets the current player's name * * @param playerName - * the player name + * the player name */ public void setCurrentPlayerName(String playerName); @@ -65,7 +65,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 stones); @@ -102,7 +102,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); @@ -110,7 +110,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); @@ -119,16 +119,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); @@ -143,13 +143,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); /** - * 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 */ @@ -224,7 +224,7 @@ public interface IView { * Show/hide login panel * * @param show - * true = login panel is shown + * true = login panel is shown */ public void showLoginPanel(boolean show); @@ -232,7 +232,7 @@ public interface IView { * Enable/disable pause mode * * @param enable - * true = enable + * true = enable */ public void enablePauseMode(boolean enable); @@ -240,7 +240,7 @@ public interface IView { * Show/hide game list panel * * @param show - * true = show + * true = show */ public void showGameListPanel(boolean show); @@ -248,7 +248,7 @@ public interface IView { * Show/hide side panel * * @param show - * true to show + * true to show */ void showSidePanel(boolean show); @@ -256,7 +256,7 @@ public interface IView { * Is set if a player tried to lay out less than initial meld threshold * * @param points - * initial meld threshold + * initial meld threshold */ public void setInitialMeldError(int points); @@ -264,7 +264,7 @@ public interface IView { * Show stone collection * * @param enable - * showing collection + * showing collection */ public void setStoneCollectionHidden(boolean enable); @@ -277,7 +277,7 @@ public interface IView { * Set invalid sets to enable showing * * @param sets - * invalid sets on table + * invalid sets on table */ public void setInvalidStoneSets(Collection sets); @@ -290,7 +290,7 @@ public interface IView { * Enables/disables saving in menu bar * * @param enable - * saving possible + * saving possible */ public void enableSave(boolean enable); @@ -298,7 +298,7 @@ public interface IView { * Sets the quit warning panel visible * * @param show - * is visible + * is visible */ public void showQuitWarningPanel(boolean show); @@ -333,7 +333,7 @@ public interface IView { * Set the connect panel visible * * @param show - * is visible + * is visible */ public void showConnectPanel(boolean show); @@ -344,6 +344,8 @@ public interface IView { */ public IConnectPanel getConnectPanel(); + public void setMayPause(boolean mayPause); + /** * Different types of bottom panels */ diff --git a/src/jrummikub/view/impl/PlayerPanel.java b/src/jrummikub/view/impl/PlayerPanel.java index e557842..0e5639a 100644 --- a/src/jrummikub/view/impl/PlayerPanel.java +++ b/src/jrummikub/view/impl/PlayerPanel.java @@ -6,6 +6,7 @@ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ComponentAdapter; import java.awt.event.ComponentEvent; +import java.awt.event.ComponentListener; import java.text.DecimalFormat; import java.util.Collections; @@ -60,6 +61,10 @@ class PlayerPanel extends JPanel implements IPlayerPanel { private Event redealEvent = new Event(); private Event pauseEvent = new Event(); private int leftPanelWidth; + private boolean mayPause = true; + + private ComponentListener leftPanelResizeListener = new LeftPanelResizeListener(); + private ComponentListener rightPanelResizeListener = new RightPanelResizeListener(); HandPanel getHandPanel() { return hand; @@ -157,7 +162,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel { } }); - leftPanel.addComponentListener(new LeftPanelResizeListener()); + leftPanel.addComponentListener(leftPanelResizeListener); } private void createRightPanel() { @@ -188,7 +193,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel { createRightPanelButtons(); - rightPanel.addComponentListener(new RightPanelResizeListener()); + rightPanel.addComponentListener(rightPanelResizeListener); } private void createRightPanelButtons() { @@ -237,7 +242,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel { Insets insets = getInsets(); int x = insets.left, y = insets.top, width = getWidth() - insets.left - insets.right, height = getHeight() - insets.top - insets.bottom; - + int boardWidth = hand.rescale(height); int handButtonWidth = (int) (width * HAND_ROW_BUTTON_RATIO); int meanPanelWidth = (width - boardWidth) / 2; @@ -252,7 +257,7 @@ class PlayerPanel extends JPanel implements IPlayerPanel { leftPanel.validate(); rightPanel.validate(); } - + int getLeftPanelWidth() { return leftPanelWidth; } @@ -342,6 +347,11 @@ class PlayerPanel extends JPanel implements IPlayerPanel { hand.setEnabled(enable); } + void setMayPause(boolean mayPause) { + this.mayPause = mayPause; + rightPanelResizeListener.componentResized(null); + } + private class LeftPanelResizeListener extends ComponentAdapter { @Override public void componentResized(ComponentEvent e) { @@ -427,12 +437,17 @@ class PlayerPanel extends JPanel implements IPlayerPanel { } private void rescaleTimeBar(int x, int y, int width, int firstLineHeight) { - 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))); + if (mayPause) { + 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))); + } else { + timeBar.setBounds(x, y, width, firstLineHeight); + pauseButton.setBounds(0, 0, 0, 0); + } } private void rescaleUpDownButtons(int handButtonWidth, float fontSize) { diff --git a/src/jrummikub/view/impl/TablePanel.java b/src/jrummikub/view/impl/TablePanel.java index 563ad3b..4db1a52 100644 --- a/src/jrummikub/view/impl/TablePanel.java +++ b/src/jrummikub/view/impl/TablePanel.java @@ -123,22 +123,14 @@ class TablePanel extends AbstractStonePanel implements ITablePanel { void createPauseStoneSets() { pauseStoneSets = new ArrayList>(); - 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(new StoneSet(stoneCoffee1), - new Position(-4, 0))); pauseStoneSets.add(new Pair(new StoneSet(Arrays.asList( stoneP, stonea, stoneu, stones, stonee)), new Position(-2.5, 0))); - pauseStoneSets.add(new Pair(new StoneSet(stoneCoffee2), - new Position(3, 0))); } /** diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java index a9dc46f..69d0d25 100644 --- a/src/jrummikub/view/impl/View.java +++ b/src/jrummikub/view/impl/View.java @@ -193,8 +193,7 @@ public class View extends JFrame implements IView { showSettingsPanel(false); showLoginPanel(false); showGameListPanel(false); - getHandPanel().setStones( - Collections.> emptyList()); + getHandPanel().setStones(Collections.> emptyList()); getTablePanel().setStoneSets( Collections.> emptyList()); setSelectedStones(Collections. emptyList()); @@ -321,6 +320,7 @@ public class View extends JFrame implements IView { public void componentResized(ComponentEvent e) { rescale(); } + @Override public void componentMoved(ComponentEvent e) { quitWarningFrame.setLocationRelativeTo(View.this); @@ -355,10 +355,10 @@ public class View extends JFrame implements IView { quitWarningFrame.add(quitWarningPanel); quitWarningFrame.setAlwaysOnTop(true); quitWarningFrame.setUndecorated(true); - - //layeredPane.setLayer(quitWarningPanel, JLayeredPane.POPUP_LAYER); - //layeredPane.add(quitWarningPanel); - //quitWarningPanel.setVisible(true); + + // layeredPane.setLayer(quitWarningPanel, JLayeredPane.POPUP_LAYER); + // layeredPane.add(quitWarningPanel); + // quitWarningPanel.setVisible(true); scorePanel = new ScorePanel(); scorePanel.setVisible(false); layeredPane.setLayer(scorePanel, JLayeredPane.POPUP_LAYER); @@ -390,8 +390,7 @@ public class View extends JFrame implements IView { table = new TablePanel(); mainLayer.add(table); - table.setBorder(new MatteBorder(0, 0, TABLE_BORDER_WIDTH, 0, - Color.BLACK)); + table.setBorder(new MatteBorder(0, 0, TABLE_BORDER_WIDTH, 0, Color.BLACK)); playerPanel = new PlayerPanel(); mainLayer.add(playerPanel); @@ -411,9 +410,14 @@ public class View extends JFrame implements IView { sidePanel = new SidePanel(); sidePanel.setVisible(false); mainLayer.add(sidePanel); - sidePanel.setBorder(new CompoundBorder(new MatteBorder(0, 0, 0, 1, - Color.BLACK), new MatteBorder(0, 0, TABLE_BORDER_WIDTH, 0, - Color.GRAY))); + sidePanel + .setBorder(new CompoundBorder(new MatteBorder(0, 0, 0, 1, Color.BLACK), + new MatteBorder(0, 0, TABLE_BORDER_WIDTH, 0, Color.GRAY))); + } + + @Override + public void setMayPause(boolean mayPause) { + playerPanel.setMayPause(mayPause); } @Override @@ -525,15 +529,14 @@ public class View extends JFrame implements IView { public void showQuitWarningPanel(boolean show) { quitWarningFrame.setLocationRelativeTo(this); quitWarningFrame.setVisible(show); - + setEnabled(!show); - /*mainLayer.setEnabled(!show); - menuBar.setEnabled(!show); - settingsPanel.setEnabled(!show); - loginPanel.setEnabled(!show); - scorePanel.setEnabled(!show); - gameListPanel.setEnabled(!show); - connectPanel.setEnabled(!show);*/ + /* + * mainLayer.setEnabled(!show); menuBar.setEnabled(!show); + * settingsPanel.setEnabled(!show); loginPanel.setEnabled(!show); + * scorePanel.setEnabled(!show); gameListPanel.setEnabled(!show); + * connectPanel.setEnabled(!show); + */ } @Override @@ -597,24 +600,24 @@ public class View extends JFrame implements IView { @SuppressWarnings("unchecked") private List> createDecorationStones() { - Pair stoneJ = new Pair(new Stone( - -'J', StoneColor.BLACK), new Position(2.5f, 0)); - Pair stoneR = new Pair(new Stone( - -'R', StoneColor.ORANGE), new Position(3.5f, 0)); - Pair stoneu1 = new Pair(new Stone( - -'u', StoneColor.BLUE), new Position(4.5f, 0)); - Pair stonem1 = new Pair(new Stone( - -'m', StoneColor.RED), new Position(5.5f, 0)); - Pair stonem2 = new Pair(new Stone( - -'m', StoneColor.GREEN), new Position(6.5f, 0)); - Pair stonei = new Pair(new Stone( - -'i', StoneColor.VIOLET), new Position(7.5f, 0)); - Pair stonek = new Pair(new Stone( - -'k', StoneColor.AQUA), new Position(8.5f, 0)); - Pair stoneu2 = new Pair(new Stone( - -'u', StoneColor.GRAY), new Position(9.5f, 0)); - Pair stoneb = new Pair(new Stone( - -'b', StoneColor.BLACK), new Position(10.5f, 0)); + Pair stoneJ = new Pair(new Stone(-'J', + StoneColor.BLACK), new Position(2.5f, 0)); + Pair stoneR = new Pair(new Stone(-'R', + StoneColor.ORANGE), new Position(3.5f, 0)); + Pair stoneu1 = new Pair(new Stone(-'u', + StoneColor.BLUE), new Position(4.5f, 0)); + Pair stonem1 = new Pair(new Stone(-'m', + StoneColor.RED), new Position(5.5f, 0)); + Pair stonem2 = new Pair(new Stone(-'m', + StoneColor.GREEN), new Position(6.5f, 0)); + Pair stonei = new Pair(new Stone(-'i', + StoneColor.VIOLET), new Position(7.5f, 0)); + Pair stonek = new Pair(new Stone(-'k', + StoneColor.AQUA), new Position(8.5f, 0)); + Pair stoneu2 = new Pair(new Stone(-'u', + StoneColor.GRAY), new Position(9.5f, 0)); + Pair stoneb = new Pair(new Stone(-'b', + StoneColor.BLACK), new Position(10.5f, 0)); Pair stone1 = new Pair(new Stone( StoneColor.RED), new Position(2, 1)); @@ -629,9 +632,9 @@ public class View extends JFrame implements IView { Pair stone6 = new Pair(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 @@ -650,8 +653,7 @@ public class View extends JFrame implements IView { && type != BottomPanelType.WIN_PANEL && type != null); if (type == BottomPanelType.START_GAME_PANEL) { - table.setStoneSets(Collections - .> emptyList()); + table.setStoneSets(Collections.> emptyList()); playerPanel.getHandPanel().setStones(createDecorationStones()); } -- cgit v1.2.3