From b69608a0d947ec1de15138a670939417c977775f Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 21 Jun 2011 05:20:56 +0200 Subject: Fixed quit warning in network mode git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@543 72836036-5685-4462-b002-a69064685172 --- mock/jrummikub/view/MockView.java | 7 ---- src/jrummikub/control/ApplicationControl.java | 11 +++--- src/jrummikub/control/network/NetworkControl.java | 45 +++++++++++++++++++---- src/jrummikub/view/IView.java | 7 ---- src/jrummikub/view/impl/View.java | 12 ++---- 5 files changed, 47 insertions(+), 35 deletions(-) diff --git a/mock/jrummikub/view/MockView.java b/mock/jrummikub/view/MockView.java index fe85652..3c2bee9 100644 --- a/mock/jrummikub/view/MockView.java +++ b/mock/jrummikub/view/MockView.java @@ -63,8 +63,6 @@ public class MockView implements IView { /** */ public MockEvent menuNewGameEvent = new MockEvent(); /** */ - public MockEvent menuQuitEvent = new MockEvent(); - /** */ public MockEvent loadEvent = new MockEvent(); /** */ public MockEvent1 saveEvent = new MockEvent1(); @@ -220,11 +218,6 @@ public class MockView implements IView { return menuNewGameEvent; } - @Override - public IEvent getMenuQuitEvent() { - return menuQuitEvent; - } - @Override public IEvent getLoadEvent() { return loadEvent; diff --git a/src/jrummikub/control/ApplicationControl.java b/src/jrummikub/control/ApplicationControl.java index 18d3ba9..752cb3c 100644 --- a/src/jrummikub/control/ApplicationControl.java +++ b/src/jrummikub/control/ApplicationControl.java @@ -56,9 +56,13 @@ public class ApplicationControl { }); } }); - IListener quitListener = new IListener() { + view.getQuitEvent().add(new IListener() { @Override public void handle() { + if (networkControl != null) { + return; + } + if (gameControl == null) { System.exit(0); } else { @@ -73,10 +77,7 @@ public class ApplicationControl { }); } } - }; - view.getMenuQuitEvent().add(quitListener); - - view.getQuitEvent().add(quitListener); + }); view.getQuitWarningPanel().getCancelEvent().add(new IListener() { @Override diff --git a/src/jrummikub/control/network/NetworkControl.java b/src/jrummikub/control/network/NetworkControl.java index 88f347c..b76c42a 100644 --- a/src/jrummikub/control/network/NetworkControl.java +++ b/src/jrummikub/control/network/NetworkControl.java @@ -17,6 +17,7 @@ import jrummikub.util.IEvent; import jrummikub.util.IListener; import jrummikub.util.IListener1; import jrummikub.util.LoginData; +import jrummikub.view.IQuitWarningPanel.QuitMode; import jrummikub.view.IView; import jrummikub.view.LoginError; @@ -27,6 +28,7 @@ public class NetworkControl { private IConnectionControl connectionControl; private IView view; private List connections = new ArrayList(); + Connection tempConnection; private Event stopNetworkEvent = new Event(); private Event backToLoginEvent = new Event(); @@ -57,11 +59,11 @@ public class NetworkControl { * Creates a new network control * * @param loginData - * user's login data + * user's login data * @param connectionControl - * current connection for events and messages + * current connection for events and messages * @param view - * for events and handlers + * for events and handlers */ public NetworkControl(final LoginData loginData, IConnectionControl connectionControl, SaveControl saveControl, @@ -73,6 +75,36 @@ public class NetworkControl { addConnectionSetupListeners(loginData, view); addConnectionControlListeners(view); + connections.add(view.getQuitEvent().add(new IListener() { + @Override + public void handle() { + if (gameControl == null) { + System.exit(0); + } else { + view.getQuitWarningPanel().setMode(QuitMode.QUIT_PROCESS); + view.showQuitWarningPanel(true); + tempConnection = view.getQuitWarningPanel().getQuitEvent() + .add(new IListener() { + @Override + public void handle() { + System.exit(0); + } + }); + } + } + })); + connections.add(view.getQuitWarningPanel().getCancelEvent() + .add(new IListener() { + @Override + public void handle() { + view.showQuitWarningPanel(false); + if (tempConnection != null) { + tempConnection.remove(); + tempConnection = null; + } + } + })); + connections.add(view.getGameListPanel().getJoinEvent() .add(new IListener1() { @Override @@ -108,7 +140,7 @@ public class NetworkControl { * Adds the listeners for connection control events * * @param view - * view for events + * view for events */ public void addConnectionControlListeners(final IView view) { connections.add(connectionControl.getGameOfferEvent().add( @@ -250,7 +282,7 @@ public class NetworkControl { gameJoinControl.abort(); gameJoinControl = null; } - if (gameControl != null) { + if (gameControl != null) { gameControl.abortGame(); gameControl = null; } @@ -306,8 +338,7 @@ public class NetworkControl { if (gameOfferControl != null) { return; } - gameOfferControl = new GameOfferControl(connectionControl, settings, - view); + gameOfferControl = new GameOfferControl(connectionControl, settings, view); gameOfferControl.getBackEvent().add(new IListener() { @Override public void handle() { diff --git a/src/jrummikub/view/IView.java b/src/jrummikub/view/IView.java index b6c7163..5ef7060 100644 --- a/src/jrummikub/view/IView.java +++ b/src/jrummikub/view/IView.java @@ -155,13 +155,6 @@ public interface IView { */ public IEvent getMenuNewGameEvent(); - /** - * The menu quit event is emitted when the user selects the quit menu entry - * - * @return the event - */ - public IEvent getMenuQuitEvent(); - /** * The load event is emitted when the user wants to load a previously saved * game state diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java index 06795aa..9a0bf9e 100644 --- a/src/jrummikub/view/impl/View.java +++ b/src/jrummikub/view/impl/View.java @@ -79,7 +79,6 @@ public class View extends JFrame implements IView { private JFileChooser chooser; private Event menuNewGameEvent = new Event(); - private Event menuQuitEvent = new Event(); private Event networkGameEvent = new Event(); private Event loadEvent = new Event(); @@ -147,11 +146,6 @@ public class View extends JFrame implements IView { return menuNewGameEvent; } - @Override - public IEvent getMenuQuitEvent() { - return menuQuitEvent; - } - @Override public IEvent1 getLoadFileEvent() { return loadFileEvent; @@ -246,7 +240,7 @@ public class View extends JFrame implements IView { gameMenu.addSeparator(); - gameMenu.add(createMenuItem("Beenden", menuQuitEvent)); + gameMenu.add(createMenuItem("Beenden", quitEvent)); setJMenuBar(menuBar); } @@ -503,11 +497,11 @@ public class View extends JFrame implements IView { @Override public void showLoginPanel(boolean show) { - loginPanel.setVisible(show); - if (show) { loginPanel.resetLoginPanel(); } + + loginPanel.setVisible(show); } @Override -- cgit v1.2.3