From 56797840e2c16913627bfa57f2a49d1788443727 Mon Sep 17 00:00:00 2001 From: Ida Massow Date: Mon, 13 Jun 2011 18:22:57 +0200 Subject: =?UTF-8?q?Buttons=20im=20Settings=20panel=20sind=20richtig=20im?= =?UTF-8?q?=20netzwerk=20und=20au=C3=9Ferhalb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@421 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/view/ISettingsPanel.java | 5 ++ src/jrummikub/view/impl/SettingsPanel.java | 81 ++++++++++++++++++++++++------ 2 files changed, 70 insertions(+), 16 deletions(-) (limited to 'src/jrummikub/view') diff --git a/src/jrummikub/view/ISettingsPanel.java b/src/jrummikub/view/ISettingsPanel.java index e5a73ed..2e482f0 100644 --- a/src/jrummikub/view/ISettingsPanel.java +++ b/src/jrummikub/view/ISettingsPanel.java @@ -35,6 +35,8 @@ public interface ISettingsPanel { new Color(1.0f, 1.0f, 1.0f), // white }; + public void enableNetworkMode(boolean enable); + /** * The add player event is emitted when the user wants to add a player to * the player list @@ -198,6 +200,8 @@ public interface ISettingsPanel { */ public IEvent getSetVariantChildrenEvent(); + public IEvent getBackEvent(); + /** * Specifies the different kinds of settings errors that can be displayed */ @@ -219,4 +223,5 @@ public interface ISettingsPanel { /** Only computer players added */ COMPUTER_PLAYERS_ONLY_WARNING } + } \ No newline at end of file diff --git a/src/jrummikub/view/impl/SettingsPanel.java b/src/jrummikub/view/impl/SettingsPanel.java index cc34a35..bd410ac 100644 --- a/src/jrummikub/view/impl/SettingsPanel.java +++ b/src/jrummikub/view/impl/SettingsPanel.java @@ -47,7 +47,6 @@ import javax.swing.event.ChangeListener; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; -import jrummikub.control.turn.TurnControlFactory; import jrummikub.model.GameSettings; import jrummikub.model.PlayerSettings; import jrummikub.model.PlayerSettings.Type; @@ -82,6 +81,10 @@ class SettingsPanel extends JPanel implements ISettingsPanel { private JSpinner jokerNumberSpinner; private JSpinner timeSpinner; private JCheckBox noLimitsBox; + private JButton loadButton; + private JButton networkButton; + private JButton backButton; + private JPanel buttonPanel; private JPanel colorSelectionPanel; private Map colorButtons = new HashMap(); @@ -104,6 +107,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel { private Event1 changeNoLimitsEvent = new Event1(); private Event setVariantDefaultEvent = new Event(); private Event setVariantChildrenEvent = new Event(); + private Event backEvent = new Event(); @Override public IEvent getStartGameEvent() { @@ -193,6 +197,11 @@ class SettingsPanel extends JPanel implements ISettingsPanel { return setVariantChildrenEvent; } + @Override + public IEvent getBackEvent() { + return backEvent; + } + @Override public void setError(SettingsError error) { switch (error) { @@ -506,6 +515,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel { optionsPanel.add(label, c); } + // TODO wiederfinden SettingsPanel() { setLayout(new GridBagLayout()); @@ -531,21 +541,17 @@ class SettingsPanel extends JPanel implements ISettingsPanel { c.weighty = 0; add(errorMessageLabel, c); - c.gridwidth = 1; - startButton = addButton("Spiel starten", startGameEvent, c); - - c.weightx = 0; - add(Box.createHorizontalStrut(10), c); + buttonPanel = new JPanel(); + buttonPanel.setLayout(new GridBagLayout()); + add(buttonPanel, c); - c.weightx = 1; - addButton("Spiel laden...", loadGameEvent, c); + startButton = createButton("Spiel starten", startGameEvent); - c.weightx = 0; - add(Box.createHorizontalStrut(10), c); + loadButton = createButton("Spiel laden...", loadGameEvent); + networkButton = createButton("Netzwerkspiel...", networkGameEvent); + backButton = createButton("Zur\u00fcck", backEvent); - c.weightx = 1; - c.gridwidth = GridBagConstraints.REMAINDER; - addButton("Netzwerkspiel...", networkGameEvent, c); + addDefaultButtons(); setBorder(new CompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder(10, 10, 10, 10))); @@ -555,8 +561,43 @@ class SettingsPanel extends JPanel implements ISettingsPanel { tabbedPane.setSelectedIndex(0); } - private JButton addButton(String title, final Event event, - GridBagConstraints c) { + private void addDefaultButtons() { + buttonPanel.removeAll(); + GridBagConstraints c = new GridBagConstraints(); + c.fill = GridBagConstraints.BOTH; + c.gridwidth = 1; + c.weightx = 1; + c.weighty = 1; + + buttonPanel.add(startButton, c); + c.weightx = 0; + buttonPanel.add(Box.createHorizontalStrut(10), c); + c.weightx = 1; + buttonPanel.add(loadButton, c); + c.weightx = 0; + buttonPanel.add(Box.createHorizontalStrut(10), c); + c.weightx = 1; + c.gridwidth = GridBagConstraints.REMAINDER; + buttonPanel.add(networkButton, c); + } + + private void addNetworkButtons() { + buttonPanel.removeAll(); + GridBagConstraints c = new GridBagConstraints(); + c.fill = GridBagConstraints.BOTH; + c.gridwidth = 1; + c.weightx = 1; + c.weighty = 1; + + buttonPanel.add(startButton, c); + c.weightx = 0; + buttonPanel.add(Box.createHorizontalStrut(10), c); + c.weightx = 1; + c.gridwidth = GridBagConstraints.REMAINDER; + buttonPanel.add(backButton, c); + } + + private JButton createButton(String title, final Event event) { JButton button = new JButton(title); button.addActionListener(new ActionListener() { @Override @@ -564,10 +605,18 @@ class SettingsPanel extends JPanel implements ISettingsPanel { event.emit(); } }); - add(button, c); return button; } + @Override + public void enableNetworkMode(boolean enable) { + if (enable) { + addNetworkButtons(); + } else { + addDefaultButtons(); + } + } + private class PlayerSettingsPanel extends JPanel { private int playerNumber; private JButton colorButton; -- cgit v1.2.3