summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl
diff options
context:
space:
mode:
authorIda Massow <massow@informatik.uni-luebeck.de>2011-06-19 22:27:21 +0200
committerIda Massow <massow@informatik.uni-luebeck.de>2011-06-19 22:27:21 +0200
commitfc6d3d46db69c639557462a49ccb16463df91617 (patch)
tree3d1021e1e806dfb2e9649d689d0fd7eaa6984dde /src/jrummikub/view/impl
parent45656861ab2e618938764f0c46f830184099a71d (diff)
downloadJRummikub-fc6d3d46db69c639557462a49ccb16463df91617.tar
JRummikub-fc6d3d46db69c639557462a49ccb16463df91617.zip
quit warnings funktionieren
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@492 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/view/impl')
-rw-r--r--src/jrummikub/view/impl/QuitWarningPanel.java95
-rw-r--r--src/jrummikub/view/impl/View.java60
2 files changed, 148 insertions, 7 deletions
diff --git a/src/jrummikub/view/impl/QuitWarningPanel.java b/src/jrummikub/view/impl/QuitWarningPanel.java
new file mode 100644
index 0000000..d7a304a
--- /dev/null
+++ b/src/jrummikub/view/impl/QuitWarningPanel.java
@@ -0,0 +1,95 @@
+package jrummikub.view.impl;
+
+import java.awt.Color;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.SwingConstants;
+import javax.swing.border.CompoundBorder;
+import javax.swing.border.EmptyBorder;
+import javax.swing.border.LineBorder;
+
+import jrummikub.util.Event;
+import jrummikub.view.IQuitWarningPanel;
+
+public class QuitWarningPanel extends JPanel implements IQuitWarningPanel {
+ private JPanel buttonPanel;
+ private JButton cancelButton;
+ private JButton quitButton;
+ private QuitMode quitMode;
+ private Event quitEvent = new Event();
+ private Event cancelEvent = new Event();
+ private JLabel messageLabel;
+
+ public QuitWarningPanel() {
+ setLayout(new GridBagLayout());
+
+ GridBagConstraints c = new GridBagConstraints();
+ c.gridx = 0;
+ c.gridy = 0;
+ c.weightx = 1;
+ c.weighty = 1;
+ c.fill = GridBagConstraints.BOTH;
+ c.gridwidth = 2;
+ c.anchor = GridBagConstraints.CENTER;
+
+ messageLabel = new JLabel();
+ messageLabel.setHorizontalAlignment(SwingConstants.CENTER);
+ add(messageLabel, c);
+
+ c.gridy = 1;
+ c.gridwidth = 1;
+ quitButton = createButton("Beenden", quitEvent);
+ cancelButton = createButton("Abbrechen", cancelEvent);
+ add(cancelButton, c);
+ c.gridx = 1;
+ add(quitButton, c);
+
+ setBorder(new CompoundBorder(new LineBorder(Color.BLACK),
+ new EmptyBorder(10, 10, 10, 10)));
+ }
+
+ private JButton createButton(String title, final Event event) {
+ JButton button = new JButton(title);
+ button.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ event.emit();
+ }
+ });
+ return button;
+ }
+
+ @Override
+ public void setMode(QuitMode mode) {
+ this.quitMode = mode;
+ switch (quitMode) {
+ case QUIT_PROCESS:
+ messageLabel
+ .setText("Beim Beenden geht das aktuelle Spiel verloren");
+ break;
+ case QUIT_GAME:
+ messageLabel.setText("Der aktuelle Spielstand geht verloren");
+ }
+ }
+
+ @Override
+ public QuitMode getQuitMode(){
+ return quitMode;
+ }
+
+ @Override
+ public Event getQuitEvent() {
+ return quitEvent;
+ }
+
+ @Override
+ public Event getCancelEvent() {
+ return cancelEvent;
+ }
+}
diff --git a/src/jrummikub/view/impl/View.java b/src/jrummikub/view/impl/View.java
index dee5352..042421f 100644
--- a/src/jrummikub/view/impl/View.java
+++ b/src/jrummikub/view/impl/View.java
@@ -6,6 +6,8 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
import java.io.File;
import java.util.Arrays;
import java.util.Collection;
@@ -37,6 +39,8 @@ import jrummikub.view.IGameListPanel;
import jrummikub.view.IHandPanel;
import jrummikub.view.ILoginPanel;
import jrummikub.view.IPlayerPanel;
+import jrummikub.view.IQuitWarningPanel;
+import jrummikub.view.IQuitWarningPanel.QuitMode;
import jrummikub.view.IScorePanel;
import jrummikub.view.ISettingsPanel;
import jrummikub.view.ISidePanel;
@@ -67,6 +71,7 @@ public class View extends JFrame implements IView {
private ScorePanel scorePanel;
private GameListPanel gameListPanel;
private SidePanel sidePanel;
+ private QuitWarningPanel quitWarningPanel;
private BottomPanelType bottomPanelType;
@@ -76,8 +81,10 @@ public class View extends JFrame implements IView {
private Event menuQuitEvent = new Event();
private Event networkGameEvent = new Event();
- private Event1<File> loadEvent = new Event1<File>();
+ private Event loadEvent = new Event();
+ private Event1<File> loadFileEvent = new Event1<File>();
private Event1<File> saveEvent = new Event1<File>();
+ private Event quitEvent = new Event();
private static int even(double d) {
return 2 * (int) (d / 2);
@@ -119,6 +126,11 @@ public class View extends JFrame implements IView {
}
@Override
+ public IQuitWarningPanel getQuitWarningPanel() {
+ return quitWarningPanel;
+ }
+
+ @Override
public IGameListPanel getGameListPanel() {
return gameListPanel;
}
@@ -134,7 +146,12 @@ public class View extends JFrame implements IView {
}
@Override
- public IEvent1<File> getLoadEvent() {
+ public IEvent1<File> getLoadFileEvent() {
+ return loadFileEvent;
+ }
+
+ @Override
+ public IEvent getLoadEvent(){
return loadEvent;
}
@@ -159,6 +176,11 @@ public class View extends JFrame implements IView {
}
@Override
+ public IEvent getQuitEvent() {
+ return quitEvent;
+ }
+
+ @Override
public void clearView() {
showScorePanel(false);
showSettingsPanel(false);
@@ -201,7 +223,8 @@ public class View extends JFrame implements IView {
loadItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- load();
+ File file = new File("");
+ loadEvent.emit();
}
});
gameMenu.add(loadItem);
@@ -238,10 +261,11 @@ public class View extends JFrame implements IView {
saveItem.setEnabled(enable);
}
- private void load() {
+ @Override
+ public void load() {
int returnVal = chooser.showOpenDialog(View.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
- loadEvent.emit(chooser.getSelectedFile());
+ loadFileEvent.emit(chooser.getSelectedFile());
}
}
@@ -261,7 +285,14 @@ public class View extends JFrame implements IView {
setSize(1000, 700);
setMinimumSize(new Dimension(750, 550));
- setDefaultCloseOperation(EXIT_ON_CLOSE);
+
+ setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
+ addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowClosing(WindowEvent e) {
+ quitEvent.emit();
+ }
+ });
createFileChooser();
createMenuBar();
@@ -289,6 +320,12 @@ public class View extends JFrame implements IView {
layeredPane.setLayer(gameListPanel, JLayeredPane.POPUP_LAYER);
layeredPane.add(gameListPanel);
+ quitWarningPanel = new QuitWarningPanel();
+ quitWarningPanel.setVisible(false);
+
+ layeredPane.setLayer(quitWarningPanel, JLayeredPane.POPUP_LAYER);
+ layeredPane.add(quitWarningPanel);
+
scorePanel = new ScorePanel();
scorePanel.setVisible(false);
layeredPane.setLayer(scorePanel, JLayeredPane.POPUP_LAYER);
@@ -346,6 +383,10 @@ public class View extends JFrame implements IView {
winPanel.setVisible(false);
mainLayer.add(winPanel);
+ quitWarningPanel = new QuitWarningPanel();
+ quitWarningPanel.setVisible(false);
+ mainLayer.add(quitWarningPanel);
+
sidePanel = new SidePanel();
sidePanel.setVisible(false);
mainLayer.add(sidePanel);
@@ -394,7 +435,8 @@ public class View extends JFrame implements IView {
rescaleSubpanel(scorePanel, 3 / 4.0, 1 / 2.0, 450, 300);
rescaleSubpanel(loginPanel, 1 / 3.0, 1 / 3.0, 200, 200);
rescaleSubpanel(gameListPanel, 1 / 2.0, 1 / 2.0, 475, 300);
- }
+ rescaleSubpanel(quitWarningPanel, 1 / 2.0, 1 / 6.0, 400, 150);
+}
private void rescaleSubpanel(JPanel sub, double widthFactor,
double heightFactor, int minWidth, int minHeight) {
@@ -454,6 +496,10 @@ public class View extends JFrame implements IView {
rescale();
}
+ public void showQuitWarningPanel(boolean show) {
+ quitWarningPanel.setVisible(show);
+ }
+
@Override
public void setCurrentPlayerName(String playerName) {
playerPanel.setCurrentPlayerName(playerName);