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
This commit is contained in:
Matthias Schiffer 2011-06-10 14:51:44 +02:00
parent d940351fe4
commit e7ee6778b0
5 changed files with 97 additions and 47 deletions

View file

@ -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;
}
}

View file

@ -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;
@ -194,5 +193,4 @@ public interface ISettingsPanel {
/** Only computer players added */
COMPUTER_PLAYERS_ONLY_WARNING
}
}

View file

@ -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));
}
}
}

View file

@ -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>();
@ -99,6 +101,14 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
return startGameEvent;
}
IEvent getLoadGameEvent() {
return loadGameEvent;
}
IEvent getNetworkGameEvent() {
return networkGameEvent;
}
@Override
public IEvent getAddPlayerEvent() {
return addPlayerEvent;
@ -431,19 +441,39 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
c.weighty = 0;
add(errorMessageLabel, c);
startButton = new JButton("Spiel starten");
startButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
startGameEvent.emit();
}
});
add(startButton, c);
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) {
event.emit();
}
});
add(button, c);
return button;
}
private class PlayerSettingsPanel extends JPanel {
private int playerNumber;
private JButton colorButton;

View file

@ -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