diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-04-30 21:50:25 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2011-04-30 21:50:25 +0200 |
commit | 1b15b71a54932a28343917aeeade66d9fc17a550 (patch) | |
tree | 12f3c4058a0a2e2afad5a02542ab70c825ce27db /src/jrummikub/view | |
parent | 7b80311556c1a98167b09541af0daf0afdab989e (diff) | |
download | JRummikub-1b15b71a54932a28343917aeeade66d9fc17a550.tar JRummikub-1b15b71a54932a28343917aeeade66d9fc17a550.zip |
Handle clicks on table
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@34 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/view')
-rw-r--r-- | src/jrummikub/view/ITable.java | 4 | ||||
-rw-r--r-- | src/jrummikub/view/impl/Board.java | 39 | ||||
-rw-r--r-- | src/jrummikub/view/impl/Table.java | 57 |
3 files changed, 50 insertions, 50 deletions
diff --git a/src/jrummikub/view/ITable.java b/src/jrummikub/view/ITable.java index ce508bd..9781f78 100644 --- a/src/jrummikub/view/ITable.java +++ b/src/jrummikub/view/ITable.java @@ -4,10 +4,12 @@ import java.util.Map; import jrummikub.model.Position; import jrummikub.model.StoneSet; +import jrummikub.util.IEvent1; public interface ITable { public void setLeftPlayerName(String playerName); public void setTopPlayerName(String playerName); public void setRightPlayerName(String playerName); - void setStoneSets(Map<StoneSet, Position> stoneSets); + public void setStoneSets(Map<StoneSet, Position> stoneSets); + public IEvent1<Position> getClickEvent(); }
\ No newline at end of file diff --git a/src/jrummikub/view/impl/Board.java b/src/jrummikub/view/impl/Board.java index b227760..b8bd206 100644 --- a/src/jrummikub/view/impl/Board.java +++ b/src/jrummikub/view/impl/Board.java @@ -5,8 +5,8 @@ import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Insets; import java.awt.RenderingHints; +import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; import java.util.Collections; import java.util.Map; @@ -16,7 +16,6 @@ import javax.swing.JPanel; import jrummikub.model.Position; import jrummikub.model.Stone; import jrummikub.util.Event1; -import jrummikub.util.IEvent; import jrummikub.util.IEvent1; import jrummikub.view.IBoard; @@ -30,45 +29,21 @@ public class Board extends JPanel implements IBoard { private Event1<Position> clickEvent = new Event1<Position>(); Board() { - super(true); + super(true); // set double buffered setBorder(new CustomBorder(Color.DARK_GRAY, 0, 1, 0, 1)); - - addMouseListener(new MouseListener(){ + addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { Insets insets = getInsets(); - - clickEvent.fire(stonePainter.calculatePosition(e.getX()-insets.left, e.getY()-insets.top)); - - } - @Override - public void mouseEntered(MouseEvent e) { - // TODO Auto-generated method stub - + clickEvent.fire(stonePainter.calculatePosition(e.getX() - insets.left, + e.getY() - insets.top)); } - - @Override - public void mouseExited(MouseEvent e) { - // TODO Auto-generated method stub - - } - - @Override - public void mousePressed(MouseEvent e) { - // TODO Auto-generated method stub - - } - - @Override - public void mouseReleased(MouseEvent e) { - // TODO Auto-generated method stub - - }}); + }); } - + @Override public IEvent1<Position> getClickEvent() { return clickEvent; diff --git a/src/jrummikub/view/impl/Table.java b/src/jrummikub/view/impl/Table.java index f7460e2..23ce19d 100644 --- a/src/jrummikub/view/impl/Table.java +++ b/src/jrummikub/view/impl/Table.java @@ -4,7 +4,10 @@ import java.awt.BorderLayout; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; +import java.awt.Insets; import java.awt.RenderingHints; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.util.Collections; import java.util.Map; @@ -13,21 +16,26 @@ import javax.swing.JLabel; import javax.swing.JPanel; import jrummikub.model.Position; -import jrummikub.model.Stone; import jrummikub.model.StoneSet; +import jrummikub.util.Event1; +import jrummikub.util.IEvent1; import jrummikub.view.ITable; @SuppressWarnings("serial") public class Table extends JPanel implements ITable { - private final static ImageIcon background = new ImageIcon(Board.class.getResource("/jrummikub/resource/felt.png")); - + private final static ImageIcon background = new ImageIcon( + Board.class.getResource("/jrummikub/resource/felt.png")); + private JLabel leftPlayerLabel, topPlayerLabel, rightPlayerLabel; private JPanel innerPanel; - + private StonePainter stonePainter = new StonePainter(1); - + private Map<StoneSet, Position> stoneSets = Collections.emptyMap(); - + + private Event1<Position> clickEvent = new Event1<Position>(); + + @Override public void setLeftPlayerName(String playerName) { leftPlayerLabel.setText(playerName); @@ -42,45 +50,60 @@ public class Table extends JPanel implements ITable { public void setRightPlayerName(String playerName) { rightPlayerLabel.setText(playerName); } - + @Override public void setStoneSets(Map<StoneSet, Position> stoneSets) { this.stoneSets = stoneSets; } + @Override + public IEvent1<Position> getClickEvent() { + return clickEvent; + } + Table() { super(true); // set double buffered setLayout(new BorderLayout()); - + leftPlayerLabel = new JLabel(); leftPlayerLabel.setForeground(Color.WHITE); add(leftPlayerLabel, BorderLayout.WEST); - + topPlayerLabel = new JLabel(); topPlayerLabel.setHorizontalAlignment(JLabel.CENTER); topPlayerLabel.setHorizontalTextPosition(JLabel.CENTER); topPlayerLabel.setForeground(Color.WHITE); add(topPlayerLabel, BorderLayout.NORTH); - + rightPlayerLabel = new JLabel(); rightPlayerLabel.setForeground(Color.WHITE); add(rightPlayerLabel, BorderLayout.EAST); - + innerPanel = new JPanel(); innerPanel.setOpaque(false); add(innerPanel, BorderLayout.CENTER); + + addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + Insets insets = getInsets(); + + clickEvent.fire(stonePainter.calculatePosition(e.getX() - insets.left, + e.getY() - insets.top)); + } + }); } - + @Override protected void paintComponent(Graphics g1) { - Graphics2D g = (Graphics2D)g1; - - for(int x = 0; x < getWidth(); x += background.getIconWidth()) { - for(int y = 0; y < getHeight(); y += background.getIconHeight()) { + Graphics2D g = (Graphics2D) g1; + + for (int x = 0; x < getWidth(); x += background.getIconWidth()) { + for (int y = 0; y < getHeight(); y += background.getIconHeight()) { background.paintIcon(this, g, x, y); } } - + g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |