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:
parent
d940351fe4
commit
e7ee6778b0
5 changed files with 97 additions and 47 deletions
|
@ -31,6 +31,8 @@ public class MockSettingsPanel implements ISettingsPanel {
|
||||||
/** */
|
/** */
|
||||||
public MockEvent startGameEvent = new MockEvent();
|
public MockEvent startGameEvent = new MockEvent();
|
||||||
/** */
|
/** */
|
||||||
|
public MockEvent networkGameEvent = new MockEvent();
|
||||||
|
/** */
|
||||||
public SettingsError error = SettingsError.NO_ERROR;
|
public SettingsError error = SettingsError.NO_ERROR;
|
||||||
/** */
|
/** */
|
||||||
public boolean startButtonEnabled = true;
|
public boolean startButtonEnabled = true;
|
||||||
|
@ -164,5 +166,4 @@ public class MockSettingsPanel implements ISettingsPanel {
|
||||||
public IEvent1<Integer> getChangeTimeEvent() {
|
public IEvent1<Integer> getChangeTimeEvent() {
|
||||||
return changeTimeEvent;
|
return changeTimeEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@ import java.util.Set;
|
||||||
import jrummikub.control.turn.TurnControlFactory;
|
import jrummikub.control.turn.TurnControlFactory;
|
||||||
import jrummikub.model.GameSettings;
|
import jrummikub.model.GameSettings;
|
||||||
import jrummikub.model.StoneColor;
|
import jrummikub.model.StoneColor;
|
||||||
import jrummikub.util.Event1;
|
|
||||||
import jrummikub.util.IEvent;
|
import jrummikub.util.IEvent;
|
||||||
import jrummikub.util.IEvent1;
|
import jrummikub.util.IEvent1;
|
||||||
import jrummikub.util.IEvent2;
|
import jrummikub.util.IEvent2;
|
||||||
|
@ -194,5 +193,4 @@ public interface ISettingsPanel {
|
||||||
/** Only computer players added */
|
/** Only computer players added */
|
||||||
COMPUTER_PLAYERS_ONLY_WARNING
|
COMPUTER_PLAYERS_ONLY_WARNING
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -411,20 +411,9 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
smallFontSize = MAX_BUTTON_FONT_SIZE;
|
smallFontSize = MAX_BUTTON_FONT_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
handRowUpButton.setBounds(0, 0, handButtonWidth, getHeight() / 2);
|
rescaleUpDownButtons(handButtonWidth, fontSize);
|
||||||
handRowUpButton.setFont(handRowUpButton.getFont().deriveFont(
|
|
||||||
fontSize * 1.5f));
|
|
||||||
handRowDownButton.setBounds(0, getHeight() / 2, handButtonWidth,
|
|
||||||
getHeight() / 2);
|
|
||||||
handRowDownButton.setFont(handRowDownButton.getFont().deriveFont(
|
|
||||||
fontSize * 1.5f));
|
|
||||||
|
|
||||||
timeBar.setBounds(x, y, width - firstLineHeight - SIDE_PANEL_SEPARATOR,
|
rescaleTimeBar(x, y, width, firstLineHeight);
|
||||||
firstLineHeight);
|
|
||||||
pauseButton.setBounds(x + width - firstLineHeight, y, firstLineHeight,
|
|
||||||
firstLineHeight);
|
|
||||||
pauseButton.setIcon(ImageUtil
|
|
||||||
.createPauseIcon((int) (firstLineHeight * 0.5f)));
|
|
||||||
|
|
||||||
endTurnButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR,
|
endTurnButton.setBounds(x, y + firstLineHeight + SIDE_PANEL_SEPARATOR,
|
||||||
buttonWidth, buttonHeight);
|
buttonWidth, buttonHeight);
|
||||||
|
@ -440,5 +429,24 @@ class PlayerPanel extends JPanel implements IPlayerPanel {
|
||||||
smallFontSize));
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,6 +81,8 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
|
||||||
private Map<StoneColor, JToggleButton> colorButtons = new HashMap<StoneColor, JToggleButton>();
|
private Map<StoneColor, JToggleButton> colorButtons = new HashMap<StoneColor, JToggleButton>();
|
||||||
|
|
||||||
private Event startGameEvent = new Event();
|
private Event startGameEvent = new Event();
|
||||||
|
private Event loadGameEvent = new Event();
|
||||||
|
private Event networkGameEvent = new Event();
|
||||||
private Event addPlayerEvent = new Event();
|
private Event addPlayerEvent = new Event();
|
||||||
private Event1<Integer> removePlayerEvent = new Event1<Integer>();
|
private Event1<Integer> removePlayerEvent = new Event1<Integer>();
|
||||||
private Event2<Integer, Color> changePlayerColorEvent = new Event2<Integer, Color>();
|
private Event2<Integer, Color> changePlayerColorEvent = new Event2<Integer, Color>();
|
||||||
|
@ -99,6 +101,14 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
|
||||||
return startGameEvent;
|
return startGameEvent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IEvent getLoadGameEvent() {
|
||||||
|
return loadGameEvent;
|
||||||
|
}
|
||||||
|
|
||||||
|
IEvent getNetworkGameEvent() {
|
||||||
|
return networkGameEvent;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEvent getAddPlayerEvent() {
|
public IEvent getAddPlayerEvent() {
|
||||||
return addPlayerEvent;
|
return addPlayerEvent;
|
||||||
|
@ -431,19 +441,39 @@ class SettingsPanel extends JPanel implements ISettingsPanel {
|
||||||
c.weighty = 0;
|
c.weighty = 0;
|
||||||
add(errorMessageLabel, c);
|
add(errorMessageLabel, c);
|
||||||
|
|
||||||
startButton = new JButton("Spiel starten");
|
c.gridwidth = 1;
|
||||||
startButton.addActionListener(new ActionListener() {
|
startButton = addButton("Spiel starten", startGameEvent, c);
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
c.weightx = 0;
|
||||||
startGameEvent.emit();
|
add(Box.createHorizontalStrut(10), c);
|
||||||
}
|
|
||||||
});
|
c.weightx = 1;
|
||||||
add(startButton, c);
|
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(
|
setBorder(new CompoundBorder(new LineBorder(Color.BLACK), new EmptyBorder(
|
||||||
10, 10, 10, 10)));
|
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 class PlayerSettingsPanel extends JPanel {
|
||||||
private int playerNumber;
|
private int playerNumber;
|
||||||
private JButton colorButton;
|
private JButton colorButton;
|
||||||
|
|
|
@ -29,6 +29,7 @@ import jrummikub.util.Event;
|
||||||
import jrummikub.util.Event1;
|
import jrummikub.util.Event1;
|
||||||
import jrummikub.util.IEvent;
|
import jrummikub.util.IEvent;
|
||||||
import jrummikub.util.IEvent1;
|
import jrummikub.util.IEvent1;
|
||||||
|
import jrummikub.util.IListener;
|
||||||
import jrummikub.util.Pair;
|
import jrummikub.util.Pair;
|
||||||
import jrummikub.view.IHandPanel;
|
import jrummikub.view.IHandPanel;
|
||||||
import jrummikub.view.IPlayerPanel;
|
import jrummikub.view.IPlayerPanel;
|
||||||
|
@ -223,6 +224,37 @@ public class View extends JFrame implements IView {
|
||||||
layeredPane.setLayout(null);
|
layeredPane.setLayout(null);
|
||||||
add(layeredPane);
|
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 = new JPanel();
|
||||||
mainLayer.setLayout(null);
|
mainLayer.setLayout(null);
|
||||||
layeredPane.add(mainLayer);
|
layeredPane.add(mainLayer);
|
||||||
|
@ -246,25 +278,6 @@ public class View extends JFrame implements IView {
|
||||||
winPanel = new WinPanel();
|
winPanel = new WinPanel();
|
||||||
winPanel.setVisible(false);
|
winPanel.setVisible(false);
|
||||||
mainLayer.add(winPanel);
|
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
|
@Override
|
||||||
|
|
Reference in a new issue