diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-06-10 14:51:44 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-06-10 14:51:44 +0200 |
commit | e7ee6778b020b555ce5e4a2e96d850b19ba02e35 (patch) | |
tree | cefbc3081e34f3bb5e2788709d6622e5ab8507a0 | |
parent | d940351fe4ce6c59718661e261d44d23a5c5fcd7 (diff) | |
download | JRummikub-e7ee6778b020b555ce5e4a2e96d850b19ba02e35.tar JRummikub-e7ee6778b020b555ce5e4a2e96d850b19ba02e35.zip |
Added load and network buttons to settings panel
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@395 72836036-5685-4462-b002-a69064685172
-rw-r--r-- | mock/jrummikub/view/MockSettingsPanel.java | 3 | ||||
-rw-r--r-- | src/jrummikub/view/ISettingsPanel.java | 4 | ||||
-rw-r--r-- | src/jrummikub/view/impl/PlayerPanel.java | 34 | ||||
-rw-r--r-- | src/jrummikub/view/impl/SettingsPanel.java | 50 | ||||
-rw-r--r-- | src/jrummikub/view/impl/View.java | 51 |
5 files changed, 96 insertions, 46 deletions
diff --git a/mock/jrummikub/view/MockSettingsPanel.java b/mock/jrummikub/view/MockSettingsPanel.java index 9c7debe..2e9bd1f 100644 --- a/mock/jrummikub/view/MockSettingsPanel.java +++ b/mock/jrummikub/view/MockSettingsPanel.java @@ -31,6 +31,8 @@ public class MockSettingsPanel implements ISettingsPanel { /** */ public MockEvent startGameEvent = new MockEvent(); /** */ + public MockEvent networkGameEvent = new MockEvent(); + /** */ public SettingsError error = SettingsError.NO_ERROR; /** */ public boolean startButtonEnabled = true; @@ -164,5 +166,4 @@ public class MockSettingsPanel implements ISettingsPanel { public IEvent1<Integer> getChangeTimeEvent() { return changeTimeEvent; } - } diff --git a/src/jrummikub/view/ISettingsPanel.java b/src/jrummikub/view/ISettingsPanel.java index b7ce6a4..09b0394 100644 --- a/src/jrummikub/view/ISettingsPanel.java +++ b/src/jrummikub/view/ISettingsPanel.java @@ -6,7 +6,6 @@ import java.util.Set; import jrummikub.control.turn.TurnControlFactory; import jrummikub.model.GameSettings; import jrummikub.model.StoneColor; -import jrummikub.util.Event1; import jrummikub.util.IEvent; import jrummikub.util.IEvent1; import jrummikub.util.IEvent2; @@ -170,7 +169,7 @@ public interface ISettingsPanel { * @return the event */ public IEvent1<Integer> getChangeJokerNumberEvent(); - + public IEvent1<Integer> getChangeTimeEvent(); /** @@ -194,5 +193,4 @@ public interface ISettingsPanel { /** Only computer players added */ COMPUTER_PLAYERS_ONLY_WARNING } - }
\ No newline at end of file diff --git a/src/jrummikub/view/impl/PlayerPanel.java b/src/jrummikub/view/impl/PlayerPanel.java index 5b17d38..f18f053 100644 --- a/src/jrummikub/view/impl/PlayerPanel.java +++ b/src/jrummikub/view/impl/PlayerPanel.java @@ -411,20 +411,9 @@ class PlayerPanel extends JPanel implements IPlayerPanel { smallFontSize = MAX_BUTTON_FONT_SIZE; } - handRowUpButton.setBounds(0, 0, handButtonWidth, getHeight() / 2); - handRowUpButton.setFont(handRowUpButton.getFont().deriveFont( - fontSize * 1.5f)); - handRowDownButton.setBounds(0, getHeight() / 2, handButtonWidth, - getHeight() / 2); - handRowDownButton.setFont(handRowDownButton.getFont().deriveFont( - fontSize * 1.5f)); + rescaleUpDownButtons(handButtonWidth, 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))); + rescaleTimeBar(x, y, width, firstLineHeight); endTurnButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR, buttonWidth, buttonHeight); @@ -440,5 +429,24 @@ class PlayerPanel extends JPanel implements IPlayerPanel { smallFontSize)); } + + 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))); + } + + private void rescaleUpDownButtons(int handButtonWidth, float fontSize) { + handRowUpButton.setBounds(0, 0, handButtonWidth, getHeight() / 2); + handRowUpButton.setFont(handRowUpButton.getFont().deriveFont( + fontSize * 1.5f)); + handRowDownButton.setBounds(0, getHeight() / 2, handButtonWidth, + getHeight() / 2); + handRowDownButton.setFont(handRowDownButton.getFont().deriveFont( + fontSize * 1.5f)); + } } } diff --git a/src/jrummikub/view/impl/SettingsPanel.java b/src/jrummikub/view/impl/SettingsPanel.java index 8864b7b..740cfc8 100644 --- a/src/jrummikub/view/impl/SettingsPanel.java +++ b/src/jrummikub/view/impl/SettingsPanel.java @@ -81,6 +81,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel { private Map<StoneColor, JToggleButton> colorButtons = new HashMap<StoneColor, JToggleButton>(); private Event startGameEvent = new Event(); + private Event loadGameEvent = new Event(); + private Event networkGameEvent = new Event(); private Event addPlayerEvent = new Event(); private Event1<Integer> removePlayerEvent = new Event1<Integer>(); private Event2<Integer, Color> changePlayerColorEvent = new Event2<Integer, Color>(); @@ -93,12 +95,20 @@ class SettingsPanel extends JPanel implements ISettingsPanel { private Event1<Integer> changeHighestValueEvent = new Event1<Integer>(); private Event1<Set<StoneColor>> changeStoneColorsEvent = new Event1<Set<StoneColor>>(); private Event1<Integer> changeTimeEvent = new Event1<Integer>(); - + @Override public IEvent getStartGameEvent() { return startGameEvent; } + IEvent getLoadGameEvent() { + return loadGameEvent; + } + + IEvent getNetworkGameEvent() { + return networkGameEvent; + } + @Override public IEvent getAddPlayerEvent() { return addPlayerEvent; @@ -138,7 +148,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel { public IEvent1<Integer> getChangeHighestValueEvent() { return changeHighestValueEvent; } - + @Override public IEvent1<Integer> getChangeJokerNumberEvent() { return changeJokerNumberEvent; @@ -318,7 +328,7 @@ class SettingsPanel extends JPanel implements ISettingsPanel { makeOptionLabel(4, "Jokeranzahl:"); jokerNumberSpinner = makeOptionSpinner(4, 1, 999, 1, changeJokerNumberEvent); - + makeOptionLabel(5, "Zeit für Spielzug:"); timeSpinner = makeOptionSpinner(5, 1, 999, 1, changeTimeEvent); @@ -431,17 +441,37 @@ class SettingsPanel extends JPanel implements ISettingsPanel { c.weighty = 0; add(errorMessageLabel, c); - startButton = new JButton("Spiel starten"); - startButton.addActionListener(new ActionListener() { + c.gridwidth = 1; + startButton = addButton("Spiel starten", startGameEvent, c); + + c.weightx = 0; + add(Box.createHorizontalStrut(10), c); + + c.weightx = 1; + addButton("Spiel laden...", loadGameEvent, c); + + c.weightx = 0; + add(Box.createHorizontalStrut(10), c); + + c.weightx = 1; + c.gridwidth = GridBagConstraints.REMAINDER; + addButton("Netzwerkspiel...", networkGameEvent, c); + + setBorder(new CompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder( + 10, 10, 10, 10))); + } + + private JButton addButton(String title, final Event event, + GridBagConstraints c) { + JButton button = new JButton(title); + button.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - startGameEvent.emit(); + event.emit(); } }); - add(startButton, c); - - setBorder(new CompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder( - 10, 10, 10, 10))); + add(button, c); + return button; } private class PlayerSettingsPanel extends JPanel { diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java index 8f67433..b54b4c9 100644 --- a/src/jrummikub/view/impl/View.java +++ b/src/jrummikub/view/impl/View.java @@ -29,6 +29,7 @@ import jrummikub.util.Event; import jrummikub.util.Event1; import jrummikub.util.IEvent; import jrummikub.util.IEvent1; +import jrummikub.util.IListener; import jrummikub.util.Pair; import jrummikub.view.IHandPanel; import jrummikub.view.IPlayerPanel; @@ -223,6 +224,37 @@ public class View extends JFrame implements IView { layeredPane.setLayout(null); add(layeredPane); + createMainLayer(); + + settingsPanel = new SettingsPanel(); + settingsPanel.setVisible(false); + + settingsPanel.getLoadGameEvent().add(new IListener() { + @Override + public void handle() { + load(); + } + }); + + layeredPane.setLayer(settingsPanel, JLayeredPane.POPUP_LAYER); + layeredPane.add(settingsPanel); + + scorePanel = new ScorePanel(); + scorePanel.setVisible(false); + layeredPane.setLayer(scorePanel, JLayeredPane.POPUP_LAYER); + layeredPane.add(scorePanel); + + addComponentListener(new ComponentAdapter() { + @Override + public void componentResized(ComponentEvent e) { + rescale(); + } + }); + + setVisible(true); + } + + private void createMainLayer() { mainLayer = new JPanel(); mainLayer.setLayout(null); layeredPane.add(mainLayer); @@ -246,25 +278,6 @@ public class View extends JFrame implements IView { winPanel = new WinPanel(); winPanel.setVisible(false); mainLayer.add(winPanel); - - settingsPanel = new SettingsPanel(); - settingsPanel.setVisible(false); - layeredPane.setLayer(settingsPanel, JLayeredPane.POPUP_LAYER); - layeredPane.add(settingsPanel); - - scorePanel = new ScorePanel(); - scorePanel.setVisible(false); - layeredPane.setLayer(scorePanel, JLayeredPane.POPUP_LAYER); - layeredPane.add(scorePanel); - - addComponentListener(new ComponentAdapter() { - @Override - public void componentResized(ComponentEvent e) { - rescale(); - } - }); - - setVisible(true); } @Override |