summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view
diff options
context:
space:
mode:
authorJannis Harder <harder@informatik.uni-luebeck.de>2011-06-22 01:08:54 +0200
committerJannis Harder <harder@informatik.uni-luebeck.de>2011-06-22 01:08:54 +0200
commit63013dc82cc8718e40e9557cfd83991e72d72dae (patch)
treedaea331d0adaa9de3bbfe509e4895b164681efb2 /src/jrummikub/view
parent8c6bf9781f0d1ebab406e403b0b8865f7b06b536 (diff)
downloadJRummikub-63013dc82cc8718e40e9557cfd83991e72d72dae.tar
JRummikub-63013dc82cc8718e40e9557cfd83991e72d72dae.zip
Integrated dedicated server
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@563 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/view')
-rw-r--r--src/jrummikub/view/ILoginPanel.java31
-rw-r--r--src/jrummikub/view/IView.java8
-rw-r--r--src/jrummikub/view/impl/LoginPanel.java73
-rw-r--r--src/jrummikub/view/impl/View.java68
4 files changed, 139 insertions, 41 deletions
diff --git a/src/jrummikub/view/ILoginPanel.java b/src/jrummikub/view/ILoginPanel.java
index 34978aa..6a18502 100644
--- a/src/jrummikub/view/ILoginPanel.java
+++ b/src/jrummikub/view/ILoginPanel.java
@@ -24,4 +24,35 @@ public interface ILoginPanel {
*/
public IEvent getCancelEvent();
+ /**
+ * Emitted when the user presses the use dedicated server button
+ *
+ * @return the event
+ */
+ IEvent1<String> getUseDedicatedServerEvent();
+
+ /**
+ * Set the server info in the login panel
+ *
+ * @param server
+ * the server's hostname
+ */
+ void setServer(String server);
+
+ /**
+ * Set the channel to use
+ *
+ * @param channel
+ * channel to use
+ */
+ void setChannel(String channel);
+
+ /**
+ * Sets whether the dedicated server is running
+ *
+ * @param running
+ * whether the dedicated server is running
+ */
+ void setDedicatedServerRunning(boolean running);
+
} \ No newline at end of file
diff --git a/src/jrummikub/view/IView.java b/src/jrummikub/view/IView.java
index 6394ee0..91a2e23 100644
--- a/src/jrummikub/view/IView.java
+++ b/src/jrummikub/view/IView.java
@@ -285,6 +285,14 @@ public interface IView {
public void showLoadingError();
/**
+ * Show an error message when the server couldn't be started
+ *
+ * @param alreadyRunning
+ * true when the server is already running on this machine
+ */
+ public void showServerStartupError(boolean alreadyRunning);
+
+ /**
* Enables/disables saving in menu bar
*
* @param enable
diff --git a/src/jrummikub/view/impl/LoginPanel.java b/src/jrummikub/view/impl/LoginPanel.java
index 43c7550..1ea49da 100644
--- a/src/jrummikub/view/impl/LoginPanel.java
+++ b/src/jrummikub/view/impl/LoginPanel.java
@@ -1,6 +1,7 @@
package jrummikub.view.impl;
import java.awt.Color;
+import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
@@ -27,11 +28,13 @@ import jrummikub.view.ILoginPanel;
class LoginPanel extends JPanel implements ILoginPanel {
private Event1<LoginData> loginEvent = new Event1<LoginData>();
private Event cancelEvent = new Event();
+ private Event1<String> useDedicatedServer = new Event1<String>();
private JTextField userNameField;
private JTextField serverNameField;
private JTextField passwordField;
private JTextField channelNameField;
-
+ private JButton startDedicatedServerButton;
+
LoginPanel() {
setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
@@ -40,21 +43,18 @@ class LoginPanel extends JPanel implements ILoginPanel {
c.weightx = 1;
c.weighty = 1;
- ActionListener loginAction = new ActionListener() {
+ ActionListener loginAction = createInputFields();
+
+ c.weighty = 0;
+ add(startDedicatedServerButton, c);
+ startDedicatedServerButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
- login();
+ useDedicatedServer.emit(passwordField.getText());
}
- };
-
- userNameField = addInputRow("Benutzername:", new JTextField());
- userNameField.addActionListener(loginAction);
- serverNameField = addInputRow("Server:", new JTextField());
- serverNameField.addActionListener(loginAction);
- passwordField = addInputRow("Passwort:", new JPasswordField());
- passwordField.addActionListener(loginAction);
- channelNameField = addInputRow("Channel:", new JTextField());
- channelNameField.addActionListener(loginAction);
+ });
+
+ c.weighty = 1;
add(Box.createVerticalGlue(), c);
c.gridwidth = 1;
@@ -81,7 +81,30 @@ class LoginPanel extends JPanel implements ILoginPanel {
10, 10, 10, 10)));
}
+ private ActionListener createInputFields() {
+ ActionListener loginAction = new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ login();
+ }
+ };
+
+ userNameField = addInputRow("Benutzername:", new JTextField());
+ userNameField.addActionListener(loginAction);
+ serverNameField = addInputRow("Server:", new JTextField());
+ serverNameField.addActionListener(loginAction);
+ passwordField = addInputRow("Passwort:", new JPasswordField());
+ passwordField.addActionListener(loginAction);
+ channelNameField = addInputRow("Channel:", new JTextField());
+ channelNameField.addActionListener(loginAction);
+ startDedicatedServerButton = new JButton("Dedizierten Server starten");
+ // this fixes some strange layouting bug
+ startDedicatedServerButton.setPreferredSize(new Dimension(500,10));
+ return loginAction;
+ }
+
void resetLoginPanel() {
+ // TODO leer machen
userNameField.setText("test1");
serverNameField.setText("universe-factory.net");
passwordField.setText("");
@@ -98,15 +121,22 @@ class LoginPanel extends JPanel implements ILoginPanel {
return cancelEvent;
}
+ @Override
+ public IEvent1<String> getUseDedicatedServerEvent() {
+ return useDedicatedServer;
+ }
+
private JTextField addInputRow(String label, JTextField textField) {
GridBagConstraints c = new GridBagConstraints();
- c.fill = GridBagConstraints.BOTH;
+ c.fill = GridBagConstraints.HORIZONTAL;
c.gridwidth = 1;
c.weightx = 1;
c.weighty = 0;
add(new JLabel(label), c);
+ c.weightx = 1;
+ c.fill = GridBagConstraints.HORIZONTAL;
c.gridwidth = GridBagConstraints.REMAINDER;
add(textField, c);
return textField;
@@ -116,4 +146,19 @@ class LoginPanel extends JPanel implements ILoginPanel {
loginEvent.emit(new LoginData(userNameField.getText(), serverNameField
.getText(), passwordField.getText(), channelNameField.getText()));
}
+
+ @Override
+ public void setServer(String server) {
+ serverNameField.setText(server);
+ }
+
+ @Override
+ public void setChannel(String channel) {
+ channelNameField.setText(channel);
+ }
+
+ @Override
+ public void setDedicatedServerRunning(boolean running) {
+ startDedicatedServerButton.setText(running ? "Dedizierten Server nutzen" : "Dedizierten Server starten");
+ }
}
diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java
index 2829b1b..15142e3 100644
--- a/src/jrummikub/view/impl/View.java
+++ b/src/jrummikub/view/impl/View.java
@@ -187,7 +187,8 @@ public class View extends JFrame implements IView {
showSettingsPanel(false);
showLoginPanel(false);
showGameListPanel(false);
- getHandPanel().setStones(Collections.<Pair<Stone, Position>> emptyList());
+ getHandPanel().setStones(
+ Collections.<Pair<Stone, Position>> emptyList());
getTablePanel().setStoneSets(
Collections.<Pair<StoneSet, Position>> emptyList());
setSelectedStones(Collections.<Stone> emptyList());
@@ -199,6 +200,17 @@ public class View extends JFrame implements IView {
"Fehler", JOptionPane.ERROR_MESSAGE);
}
+ @Override
+ public void showServerStartupError(boolean alreadyRunning) {
+ JOptionPane
+ .showMessageDialog(
+ this,
+ alreadyRunning ? "Ein XMPP-Server l\u00e4ft bereits auf diesem Computer"
+ : "Der Server konnte nicht gestartet werden",
+ "Fehler", JOptionPane.ERROR_MESSAGE);
+
+ }
+
private void createFileChooser() {
chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
@@ -384,7 +396,8 @@ public class View extends JFrame implements IView {
table = new TablePanel();
mainLayer.add(table);
- table.setBorder(new MatteBorder(0, 0, TABLE_BORDER_WIDTH, 0, Color.BLACK));
+ table.setBorder(new MatteBorder(0, 0, TABLE_BORDER_WIDTH, 0,
+ Color.BLACK));
playerPanel = new PlayerPanel();
mainLayer.add(playerPanel);
@@ -404,9 +417,9 @@ public class View extends JFrame implements IView {
sidePanel = new SidePanel();
sidePanel.setVisible(false);
mainLayer.add(sidePanel);
- sidePanel
- .setBorder(new CompoundBorder(new MatteBorder(0, 0, 0, 1, Color.BLACK),
- new MatteBorder(0, 0, TABLE_BORDER_WIDTH, 0, Color.GRAY)));
+ sidePanel.setBorder(new CompoundBorder(new MatteBorder(0, 0, 0, 1,
+ Color.BLACK), new MatteBorder(0, 0, TABLE_BORDER_WIDTH, 0,
+ Color.GRAY)));
}
@Override
@@ -599,24 +612,24 @@ public class View extends JFrame implements IView {
@SuppressWarnings("unchecked")
private List<Pair<Stone, Position>> createDecorationStones() {
- Pair<Stone, Position> stoneJ = new Pair<Stone, Position>(new Stone(-'J',
- StoneColor.BLACK), new Position(2.5f, 0));
- Pair<Stone, Position> stoneR = new Pair<Stone, Position>(new Stone(-'R',
- StoneColor.ORANGE), new Position(3.5f, 0));
- Pair<Stone, Position> stoneu1 = new Pair<Stone, Position>(new Stone(-'u',
- StoneColor.BLUE), new Position(4.5f, 0));
- Pair<Stone, Position> stonem1 = new Pair<Stone, Position>(new Stone(-'m',
- StoneColor.RED), new Position(5.5f, 0));
- Pair<Stone, Position> stonem2 = new Pair<Stone, Position>(new Stone(-'m',
- StoneColor.GREEN), new Position(6.5f, 0));
- Pair<Stone, Position> stonei = new Pair<Stone, Position>(new Stone(-'i',
- StoneColor.VIOLET), new Position(7.5f, 0));
- Pair<Stone, Position> stonek = new Pair<Stone, Position>(new Stone(-'k',
- StoneColor.AQUA), new Position(8.5f, 0));
- Pair<Stone, Position> stoneu2 = new Pair<Stone, Position>(new Stone(-'u',
- StoneColor.GRAY), new Position(9.5f, 0));
- Pair<Stone, Position> stoneb = new Pair<Stone, Position>(new Stone(-'b',
- StoneColor.BLACK), new Position(10.5f, 0));
+ Pair<Stone, Position> stoneJ = new Pair<Stone, Position>(new Stone(
+ -'J', StoneColor.BLACK), new Position(2.5f, 0));
+ Pair<Stone, Position> stoneR = new Pair<Stone, Position>(new Stone(
+ -'R', StoneColor.ORANGE), new Position(3.5f, 0));
+ Pair<Stone, Position> stoneu1 = new Pair<Stone, Position>(new Stone(
+ -'u', StoneColor.BLUE), new Position(4.5f, 0));
+ Pair<Stone, Position> stonem1 = new Pair<Stone, Position>(new Stone(
+ -'m', StoneColor.RED), new Position(5.5f, 0));
+ Pair<Stone, Position> stonem2 = new Pair<Stone, Position>(new Stone(
+ -'m', StoneColor.GREEN), new Position(6.5f, 0));
+ Pair<Stone, Position> stonei = new Pair<Stone, Position>(new Stone(
+ -'i', StoneColor.VIOLET), new Position(7.5f, 0));
+ Pair<Stone, Position> stonek = new Pair<Stone, Position>(new Stone(
+ -'k', StoneColor.AQUA), new Position(8.5f, 0));
+ Pair<Stone, Position> stoneu2 = new Pair<Stone, Position>(new Stone(
+ -'u', StoneColor.GRAY), new Position(9.5f, 0));
+ Pair<Stone, Position> stoneb = new Pair<Stone, Position>(new Stone(
+ -'b', StoneColor.BLACK), new Position(10.5f, 0));
Pair<Stone, Position> stone1 = new Pair<Stone, Position>(new Stone(
StoneColor.RED), new Position(2, 1));
@@ -631,9 +644,9 @@ public class View extends JFrame implements IView {
Pair<Stone, Position> stone6 = new Pair<Stone, Position>(new Stone(
StoneColor.BLACK), new Position(11, 1));
- return Arrays
- .asList(stoneJ, stoneR, stoneu1, stonem1, stonem2, stonei, stonek,
- stoneu2, stoneb, stone1, stone2, stone3, stone4, stone5, stone6);
+ return Arrays.asList(stoneJ, stoneR, stoneu1, stonem1, stonem2, stonei,
+ stonek, stoneu2, stoneb, stone1, stone2, stone3, stone4,
+ stone5, stone6);
}
@Override
@@ -655,7 +668,8 @@ public class View extends JFrame implements IView {
&& (!showWinPanel) && type != null);
if (type == BottomPanelType.START_GAME_PANEL) {
- table.setStoneSets(Collections.<Pair<StoneSet, Position>> emptyList());
+ table.setStoneSets(Collections
+ .<Pair<StoneSet, Position>> emptyList());
playerPanel.getHandPanel().setStones(createDecorationStones());
}