From 82d69635a890c0147804132434a0fc7d45e8425b Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 21 Jun 2011 21:24:26 +0200 Subject: Add "Waiting for players" message to GameOfferControl git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@557 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/view/ISettingsPanel.java | 39 +++--- src/jrummikub/view/impl/SettingsPanel.java | 191 ++++++++++++++--------------- 2 files changed, 112 insertions(+), 118 deletions(-) (limited to 'src/jrummikub/view') diff --git a/src/jrummikub/view/ISettingsPanel.java b/src/jrummikub/view/ISettingsPanel.java index c9df7a6..f5577e9 100644 --- a/src/jrummikub/view/ISettingsPanel.java +++ b/src/jrummikub/view/ISettingsPanel.java @@ -40,13 +40,13 @@ public interface ISettingsPanel { * Sets the settings mode according to the point of the game * * @param mode - * settings mode to be set (join, offer, network, default) + * settings mode to be set (join, offer, network, default) */ public void setSettingsMode(SettingsMode mode); /** - * 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 */ @@ -93,8 +93,8 @@ public interface ISettingsPanel { public IEvent1 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 */ @@ -135,7 +135,7 @@ public interface ISettingsPanel { * Sets an error to display * * @param error - * the kind of error + * the kind of error */ public void setError(SettingsError error); @@ -143,7 +143,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); @@ -151,7 +151,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); @@ -159,7 +159,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(List enable); @@ -168,7 +168,7 @@ public interface ISettingsPanel { * Sets the game settings to display * * @param gameSettings - * the settings + * the settings */ public void setGameSettings(GameSettings gameSettings); @@ -218,7 +218,7 @@ public interface ISettingsPanel { * Sets the types of players allowed at the given point in game * * @param choices - * list of types for each player + * list of types for each player */ public void setPlayerTypeChoices(List> choices); @@ -226,13 +226,13 @@ public interface ISettingsPanel { * Sets the names of players editable if allowed at the given point in game * * @param editable - * states if the players name is editable for each player + * states if the players name is editable for each player */ public void setPlayerNamesEditable(List editable); /** - * The offer new game event is emitted when a new game is started and - * looking for players + * The offer new game event is emitted when a new game is started and looking + * for players * * @return the event */ @@ -242,7 +242,7 @@ public interface ISettingsPanel { * Sets the player colors which can be chosen * * @param colors - * a Set of colors which are not taken yet + * a Set of colors which are not taken yet */ public void setPlayerColors(Set colors); @@ -273,12 +273,15 @@ public interface ISettingsPanel { /** threshold higher 100 */ TOO_HIGH_THRESHOLD_WARNING, /** Only computer players added */ - COMPUTER_PLAYERS_ONLY_WARNING + COMPUTER_PLAYERS_ONLY_WARNING, + + // info + /** no network players have joined */ + WAITING_FOR_PLAYERS } /** - * SettingsPanel can be used with different functions in different - * situations + * SettingsPanel can be used with different functions in different situations */ public enum SettingsMode { /** Local game settings */ diff --git a/src/jrummikub/view/impl/SettingsPanel.java b/src/jrummikub/view/impl/SettingsPanel.java index 7140bfc..7135fe8 100644 --- a/src/jrummikub/view/impl/SettingsPanel.java +++ b/src/jrummikub/view/impl/SettingsPanel.java @@ -253,37 +253,41 @@ class SettingsPanel extends JPanel implements ISettingsPanel { @Override public void setError(SettingsError error) { switch (error) { - case NO_ERROR: - errorMessageLabel.setText(" "); - break; - case DUPLICATE_PLAYER_NAME_ERROR: - errorMessageLabel - .setText("Jeder Spielername darf nur einmal verwendet werden."); - errorMessageLabel.setForeground(Color.RED); - break; - case NO_PLAYER_NAME_ERROR: - errorMessageLabel.setText("Jeder Spieler muss einen Namen haben."); - errorMessageLabel.setForeground(Color.RED); - break; - case NOT_ENOUGH_STONES_ERROR: - errorMessageLabel - .setText("Es gibt nicht genug Steine f\u00fcr die gew\u00e4hlte Spieleranzahl."); - errorMessageLabel.setForeground(Color.RED); - break; - case NOT_ENOUGH_COLORS_ERROR: - errorMessageLabel - .setText("Es m\u00fcssen mindestens drei Farben ausgew\u00e4hlt werden."); - errorMessageLabel.setForeground(Color.RED); - break; - case COMPUTER_PLAYERS_ONLY_WARNING: - errorMessageLabel.setText("Es gibt keinen menschlichen Spieler."); - errorMessageLabel.setForeground(Color.ORANGE.darker()); - break; - case TOO_HIGH_THRESHOLD_WARNING: - errorMessageLabel - .setText("Die gew\u00e4hlte Schranke ist m\u00f6glicherweise zu hoch"); - errorMessageLabel.setForeground(Color.ORANGE.darker()); - break; + case NO_ERROR: + errorMessageLabel.setText(" "); + break; + case DUPLICATE_PLAYER_NAME_ERROR: + errorMessageLabel + .setText("Jeder Spielername darf nur einmal verwendet werden."); + errorMessageLabel.setForeground(Color.RED); + break; + case NO_PLAYER_NAME_ERROR: + errorMessageLabel.setText("Jeder Spieler muss einen Namen haben."); + errorMessageLabel.setForeground(Color.RED); + break; + case NOT_ENOUGH_STONES_ERROR: + errorMessageLabel + .setText("Es gibt nicht genug Steine f\u00fcr die gew\u00e4hlte Spieleranzahl."); + errorMessageLabel.setForeground(Color.RED); + break; + case NOT_ENOUGH_COLORS_ERROR: + errorMessageLabel + .setText("Es m\u00fcssen mindestens drei Farben ausgew\u00e4hlt werden."); + errorMessageLabel.setForeground(Color.RED); + break; + case COMPUTER_PLAYERS_ONLY_WARNING: + errorMessageLabel.setText("Es gibt keinen menschlichen Spieler."); + errorMessageLabel.setForeground(Color.ORANGE.darker()); + break; + case TOO_HIGH_THRESHOLD_WARNING: + errorMessageLabel + .setText("Die gew\u00e4hlte Schranke ist m\u00f6glicherweise zu hoch"); + errorMessageLabel.setForeground(Color.ORANGE.darker()); + break; + case WAITING_FOR_PLAYERS: + errorMessageLabel.setText("Warte auf Spieler..."); + errorMessageLabel.setForeground(Color.BLACK); + break; } } @@ -328,8 +332,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel { @Override public void setGameSettings(GameSettings gameSettings) { - while (playerSettingsPanels.size() > gameSettings.getPlayerList() - .size()) { + while (playerSettingsPanels.size() > gameSettings.getPlayerList().size()) { removePlayerSettingsPanel(); } @@ -338,22 +341,19 @@ class SettingsPanel extends JPanel implements ISettingsPanel { if (i < playerTypeChoices.size()) { choices = playerTypeChoices.get(i); } - updatePlayerSettingsPanel(i, gameSettings.getPlayerList().get(i), - choices); + updatePlayerSettingsPanel(i, gameSettings.getPlayerList().get(i), choices); } setInitialSettingsValue(gameSettings); - initialMeldThresholdLabel.setText(gameSettings - .getInitialMeldThreshold() + " Punkte"); + initialMeldThresholdLabel.setText(gameSettings.getInitialMeldThreshold() + + " Punkte"); stoneSetNumberLabel.setText(Integer.toString(gameSettings .getStoneSetNumber())); - highestValueLabel.setText(Integer.toString(gameSettings - .getHighestValue())); + highestValueLabel.setText(Integer.toString(gameSettings.getHighestValue())); numberOfStonesDealtLabel.setText(Integer.toString(gameSettings .getNumberOfStonesDealt())); - jokerNumberLabel - .setText(Integer.toString(gameSettings.getJokerNumber())); + jokerNumberLabel.setText(Integer.toString(gameSettings.getJokerNumber())); timeLabel.setText(gameSettings.getTotalTime() + " Sekunden"); noLimitsLabel.setText(gameSettings.isNoLimits() ? "An" : "Aus"); seeHandSizeLabel.setText(gameSettings.getSeeHandSize() ? "An" : "Aus"); @@ -375,12 +375,11 @@ class SettingsPanel extends JPanel implements ISettingsPanel { } private void setInitialSettingsValue(GameSettings gameSettings) { - initialMeldThresholdSpinner.setValue(gameSettings - .getInitialMeldThreshold()); + initialMeldThresholdSpinner + .setValue(gameSettings.getInitialMeldThreshold()); stoneSetNumberSpinner.setValue(gameSettings.getStoneSetNumber()); highestValueSpinner.setValue(gameSettings.getHighestValue()); - numberOfStonesDealtSpinner.setValue(gameSettings - .getNumberOfStonesDealt()); + numberOfStonesDealtSpinner.setValue(gameSettings.getNumberOfStonesDealt()); jokerNumberSpinner.setValue(gameSettings.getJokerNumber()); timeSpinner.setValue(gameSettings.getTotalTime()); noLimitsBox.setSelected(gameSettings.isNoLimits()); @@ -399,8 +398,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { private void addPlayerSettingsPanel(int i, PlayerSettings settings, List choices) { - PlayerSettingsPanel panel = new PlayerSettingsPanel(i, settings, - choices, settingsMode != SettingsMode.NETWORK_OFFER + PlayerSettingsPanel panel = new PlayerSettingsPanel(i, settings, choices, + settingsMode != SettingsMode.NETWORK_OFFER && settingsMode != SettingsMode.NETWORK_JOIN); playerSettingsPanels.add(panel); playerSettingsViewport.add(panel, @@ -410,8 +409,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { } private void removePlayerSettingsPanel() { - PlayerSettingsPanel p = playerSettingsPanels - .remove(playerSettingsPanels.size() - 1); + PlayerSettingsPanel p = playerSettingsPanels.remove(playerSettingsPanels + .size() - 1); playerSettingsViewport.remove(p); } @@ -433,8 +432,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel { playerSettingsViewport.add(addPlayerPanel); addPlayerButton = new JButton("+"); - addPlayerButton - .setFont(addPlayerButton.getFont().deriveFont(Font.BOLD)); + addPlayerButton.setFont(addPlayerButton.getFont().deriveFont(Font.BOLD)); addPlayerButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { @@ -483,8 +481,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel { makeOptionLabel(row++, "H\u00f6chster Steinwert:"); highestValueLabel = new JLabel(); - highestValueSpinner = createOptionSpinner(3, 99, 1, - changeHighestValueEvent); + highestValueSpinner = createOptionSpinner(3, 99, 1, changeHighestValueEvent); makeOptionLabel(row++, "Anzahl Startsteine:"); numberOfStonesDealtLabel = new JLabel(); @@ -493,8 +490,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel { makeOptionLabel(row++, "Jokeranzahl:"); jokerNumberLabel = new JLabel(); - jokerNumberSpinner = createOptionSpinner(0, 999, 1, - changeJokerNumberEvent); + jokerNumberSpinner = createOptionSpinner(0, 999, 1, changeJokerNumberEvent); makeOptionLabel(row++, "Zeit f\u00fcr Spielzug:"); timeLabel = new JLabel(); @@ -655,8 +651,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { final Event1 targetEvent) { final JSpinner spinner = new JSpinner(); spinner.setModel(new SpinnerNumberModel(min, min, max, step)); - spinner.setPreferredSize(new Dimension(60, - spinner.getMinimumSize().height)); + spinner + .setPreferredSize(new Dimension(60, spinner.getMinimumSize().height)); spinner.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { @@ -717,8 +713,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { addDefaultButtons(); - setBorder(new CompoundBorder(new LineBorder(Color.BLACK), - new EmptyBorder(10, 10, 10, 10))); + setBorder(new CompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder( + 10, 10, 10, 10))); } void resetTabbedPane() { @@ -806,22 +802,22 @@ class SettingsPanel extends JPanel implements ISettingsPanel { buttonPanel.removeAll(); switch (mode) { - case DEFAULT: - addDefaultButtons(); - enableOptions(true); - break; - case NETWORK_SETUP: - addNetworkSetupButtons(); - enableOptions(true); - break; - case NETWORK_OFFER: - addNetworkOfferButtons(); - enableOptions(false); - break; - case NETWORK_JOIN: - addNetworkJoinButtons(); - enableOptions(false); - break; + case DEFAULT: + addDefaultButtons(); + enableOptions(true); + break; + case NETWORK_SETUP: + addNetworkSetupButtons(); + enableOptions(true); + break; + case NETWORK_OFFER: + addNetworkOfferButtons(); + enableOptions(false); + break; + case NETWORK_JOIN: + addNetworkJoinButtons(); + enableOptions(false); + break; } } @@ -846,8 +842,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel { private JLabel typeLabel; public void setSettings(PlayerSettings settings) { - if (nameField != null - && !nameField.getText().equals(settings.getName())) { + if (nameField != null && !nameField.getText().equals(settings.getName())) { nameField.setText(settings.getName()); } if (nameLabel != null) { @@ -864,8 +859,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { if (typeLabel != null) { typeLabel.setText(getTypeLabel(settings.getType())); } - colorButton.setIcon(ImageUtil.createColorIcon(settings.getColor(), - 16, 2)); + colorButton + .setIcon(ImageUtil.createColorIcon(settings.getColor(), 16, 2)); colorChangable = !((settingsMode == SettingsMode.NETWORK_JOIN | settingsMode == SettingsMode.NETWORK_OFFER) & settings .getType() != Type.HUMAN); @@ -919,13 +914,13 @@ class SettingsPanel extends JPanel implements ISettingsPanel { private String getTypeLabel(Type type) { switch (type) { - case COMPUTER: - return "Computer"; - case HUMAN: - return "Mensch"; - case NETWORK: - case VACANT: - return "Netzwerk"; + case COMPUTER: + return "Computer"; + case HUMAN: + return "Mensch"; + case NETWORK: + case VACANT: + return "Netzwerk"; } return null; @@ -959,8 +954,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel { c.gridy = 0; add(colorButton, c); - nameField.getDocument().addDocumentListener( - new NameChangeListener()); + nameField.getDocument().addDocumentListener(new NameChangeListener()); c2.gridy = 0; c2.weightx = 1; c2.fill = GridBagConstraints.HORIZONTAL; @@ -975,8 +969,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { }); playerType.setPreferredSize(new Dimension(120, playerType .getPreferredSize().height)); - playerType.setMinimumSize(new Dimension(120, playerType - .getMinimumSize().height)); + playerType.setMinimumSize(new Dimension(120, + playerType.getMinimumSize().height)); add(playerType, c); removeButton = new JButton("\u00d7"); @@ -1019,8 +1013,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { typeLabel.setBorder(new EmptyBorder(3, 7, 3, 7)); typeLabel.setPreferredSize(new Dimension(120, typeLabel .getPreferredSize().height)); - typeLabel.setMinimumSize(new Dimension(120, typeLabel - .getMinimumSize().height)); + typeLabel.setMinimumSize(new Dimension(120, + typeLabel.getMinimumSize().height)); add(typeLabel, c); } @@ -1028,9 +1022,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { public Dimension getPreferredSize() { Dimension preferredSize = super.getPreferredSize(); for (Component component : this.getComponents()) { - preferredSize.setSize( - preferredSize.width, - Math.max(preferredSize.height, + preferredSize + .setSize(preferredSize.width, Math.max(preferredSize.height, component.getPreferredSize().height)); } return preferredSize; @@ -1040,9 +1033,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { public Dimension getMaximumSize() { Dimension preferredSize = super.getPreferredSize(); for (Component component : this.getComponents()) { - preferredSize.setSize( - Integer.MAX_VALUE, - Math.max(preferredSize.height, + preferredSize + .setSize(Integer.MAX_VALUE, Math.max(preferredSize.height, component.getPreferredSize().height)); } return preferredSize; @@ -1076,8 +1068,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel { add(new ColorButton(c, menu)); } else { add(new JLabel(ImageUtil.createColorIcon( - UIManager.getColor("PopupMenu.background"), 16, - 0))); + UIManager.getColor("PopupMenu.background"), 16, 0))); } } -- cgit v1.2.3