summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-04-29 16:25:30 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-04-29 16:25:30 +0200
commit839e020f4bbd85a76a970cf7c56538a82e1075b6 (patch)
tree4240f28ea3467539f2f2ddbe83c1c0fb34f135b2 /src/jrummikub/view
parent5a0be3261a52f6a0849941283487d08212a35983 (diff)
downloadJRummikub-839e020f4bbd85a76a970cf7c56538a82e1075b6.tar
JRummikub-839e020f4bbd85a76a970cf7c56538a82e1075b6.zip
Added Event handling to buttons
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@16 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/view')
-rw-r--r--src/jrummikub/view/IPlayerPanel.java6
-rw-r--r--src/jrummikub/view/PlayerPanel.java42
-rw-r--r--src/jrummikub/view/View.java19
3 files changed, 67 insertions, 0 deletions
diff --git a/src/jrummikub/view/IPlayerPanel.java b/src/jrummikub/view/IPlayerPanel.java
index 3330804..79c15a4 100644
--- a/src/jrummikub/view/IPlayerPanel.java
+++ b/src/jrummikub/view/IPlayerPanel.java
@@ -1,8 +1,14 @@
package jrummikub.view;
+import jrummikub.util.IEvent;
+
public interface IPlayerPanel {
public IBoard getBoard();
public void setCurrentPlayerName(String playerName);
public void setTimeLeft(int time);
+
+ public IEvent getSortByNumberEvent();
+ public IEvent getSortByColorEvent();
+ public IEvent getEndTurnEvent();
} \ No newline at end of file
diff --git a/src/jrummikub/view/PlayerPanel.java b/src/jrummikub/view/PlayerPanel.java
index e9ffff3..385499e 100644
--- a/src/jrummikub/view/PlayerPanel.java
+++ b/src/jrummikub/view/PlayerPanel.java
@@ -5,6 +5,8 @@ import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import javax.swing.JButton;
@@ -12,6 +14,9 @@ import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
+import jrummikub.util.Event;
+import jrummikub.util.IEvent;
+
@SuppressWarnings("serial")
public class PlayerPanel extends JPanel implements IPlayerPanel {
private final static DecimalFormat secondFormat = new DecimalFormat("00");
@@ -24,6 +29,10 @@ public class PlayerPanel extends JPanel implements IPlayerPanel {
private JProgressBar timeBar;
private JButton endTurnButton;
+ private Event sortByNumberEvent = new Event();
+ private Event sortByColorEvent = new Event();
+ private Event endTurnEvent = new Event();
+
@Override
public IBoard getBoard() {
@@ -42,6 +51,21 @@ public class PlayerPanel extends JPanel implements IPlayerPanel {
timeBar.setString(Integer.toString(time/60) + ":" + secondFormat.format(time%60));
}
+ @Override
+ public IEvent getSortByNumberEvent() {
+ return sortByNumberEvent;
+ }
+
+ @Override
+ public IEvent getSortByColorEvent() {
+ return sortByColorEvent;
+ }
+
+ @Override
+ public IEvent getEndTurnEvent() {
+ return endTurnEvent;
+ }
+
JPanel createLeftPanel() {
JPanel panel = new JPanel();
@@ -67,6 +91,12 @@ public class PlayerPanel extends JPanel implements IPlayerPanel {
sortByNumberButton = new JButton("<html><center>Sort by<br>number");
sortByNumberButton.setPreferredSize(new Dimension(85, 50));
+ sortByNumberButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ sortByNumberEvent.fire();
+ }});
+
c.gridwidth = GridBagConstraints.RELATIVE;
c.gridheight = GridBagConstraints.REMAINDER;
c.insets = new Insets(15, 0, 20, 5);
@@ -75,6 +105,12 @@ public class PlayerPanel extends JPanel implements IPlayerPanel {
sortByColorButton = new JButton("<html><center>Sort by<br>color");
sortByColorButton.setPreferredSize(new Dimension(85, 50));
+ sortByColorButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ sortByColorEvent.fire();
+ }});
+
c.gridwidth = GridBagConstraints.REMAINDER;
c.insets = new Insets(15, 5, 20, 0);
layout.setConstraints(sortByColorButton, c);
@@ -103,6 +139,12 @@ public class PlayerPanel extends JPanel implements IPlayerPanel {
endTurnButton = new JButton("End turn");
endTurnButton.setPreferredSize(new Dimension(180, 50));
+ endTurnButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent arg0) {
+ endTurnEvent.fire();
+ }});
+
c.gridheight = GridBagConstraints.REMAINDER;
c.insets = new Insets(15, 0, 20, 0);
layout.setConstraints(endTurnButton, c);
diff --git a/src/jrummikub/view/View.java b/src/jrummikub/view/View.java
index 65e26b5..8589e8f 100644
--- a/src/jrummikub/view/View.java
+++ b/src/jrummikub/view/View.java
@@ -7,6 +7,8 @@ import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.UIManager;
+import jrummikub.util.IListener;
+
@SuppressWarnings("serial")
public class View extends JFrame implements IView {
private Table table;
@@ -45,6 +47,7 @@ public class View extends JFrame implements IView {
* @param args
*/
public static void main(String[] args) {
+ // FIXME Only test main for GUI preview
String nativeLF = UIManager.getSystemLookAndFeelClassName();
try {
@@ -60,6 +63,22 @@ public class View extends JFrame implements IView {
view.getTable().setTopPlayerName("Player 3");
view.getTable().setRightPlayerName("Player 4");
+ view.getPlayerPanel().getSortByNumberEvent().add(new IListener() {
+ @Override
+ public void fire() {
+ System.out.println("'Sort by number' fired");
+ }});
+ view.getPlayerPanel().getSortByColorEvent().add(new IListener() {
+ @Override
+ public void fire() {
+ System.out.println("'Sort by color' fired");
+ }});
+ view.getPlayerPanel().getEndTurnEvent().add(new IListener() {
+ @Override
+ public void fire() {
+ System.out.println("'End turn' fired");
+ }});
+
view.setVisible(true);
}
}