From 63013dc82cc8718e40e9557cfd83991e72d72dae Mon Sep 17 00:00:00 2001 From: Jannis Harder Date: Wed, 22 Jun 2011 01:08:54 +0200 Subject: Integrated dedicated server git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@563 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/view/ILoginPanel.java | 31 ++++++++++++++ src/jrummikub/view/IView.java | 8 ++++ src/jrummikub/view/impl/LoginPanel.java | 73 ++++++++++++++++++++++++++------- src/jrummikub/view/impl/View.java | 68 ++++++++++++++++++------------ 4 files changed, 139 insertions(+), 41 deletions(-) (limited to 'src/jrummikub/view') 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 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 @@ -284,6 +284,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 * 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 loginEvent = new Event1(); private Event cancelEvent = new Event(); + private Event1 useDedicatedServer = new Event1(); 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 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.> emptyList()); + getHandPanel().setStones( + Collections.> emptyList()); getTablePanel().setStoneSets( Collections.> emptyList()); setSelectedStones(Collections. 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> createDecorationStones() { - Pair stoneJ = new Pair(new Stone(-'J', - StoneColor.BLACK), new Position(2.5f, 0)); - Pair stoneR = new Pair(new Stone(-'R', - StoneColor.ORANGE), new Position(3.5f, 0)); - Pair stoneu1 = new Pair(new Stone(-'u', - StoneColor.BLUE), new Position(4.5f, 0)); - Pair stonem1 = new Pair(new Stone(-'m', - StoneColor.RED), new Position(5.5f, 0)); - Pair stonem2 = new Pair(new Stone(-'m', - StoneColor.GREEN), new Position(6.5f, 0)); - Pair stonei = new Pair(new Stone(-'i', - StoneColor.VIOLET), new Position(7.5f, 0)); - Pair stonek = new Pair(new Stone(-'k', - StoneColor.AQUA), new Position(8.5f, 0)); - Pair stoneu2 = new Pair(new Stone(-'u', - StoneColor.GRAY), new Position(9.5f, 0)); - Pair stoneb = new Pair(new Stone(-'b', - StoneColor.BLACK), new Position(10.5f, 0)); + Pair stoneJ = new Pair(new Stone( + -'J', StoneColor.BLACK), new Position(2.5f, 0)); + Pair stoneR = new Pair(new Stone( + -'R', StoneColor.ORANGE), new Position(3.5f, 0)); + Pair stoneu1 = new Pair(new Stone( + -'u', StoneColor.BLUE), new Position(4.5f, 0)); + Pair stonem1 = new Pair(new Stone( + -'m', StoneColor.RED), new Position(5.5f, 0)); + Pair stonem2 = new Pair(new Stone( + -'m', StoneColor.GREEN), new Position(6.5f, 0)); + Pair stonei = new Pair(new Stone( + -'i', StoneColor.VIOLET), new Position(7.5f, 0)); + Pair stonek = new Pair(new Stone( + -'k', StoneColor.AQUA), new Position(8.5f, 0)); + Pair stoneu2 = new Pair(new Stone( + -'u', StoneColor.GRAY), new Position(9.5f, 0)); + Pair stoneb = new Pair(new Stone( + -'b', StoneColor.BLACK), new Position(10.5f, 0)); Pair stone1 = new Pair(new Stone( StoneColor.RED), new Position(2, 1)); @@ -631,9 +644,9 @@ public class View extends JFrame implements IView { Pair stone6 = new Pair(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.> emptyList()); + table.setStoneSets(Collections + .> emptyList()); playerPanel.getHandPanel().setStones(createDecorationStones()); } -- cgit v1.2.3