From 36da8c8a179faab8e52c66130c4031027e06db6b Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 30 Apr 2011 17:56:10 +0200 Subject: Added clickEvent to Board git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@30 72836036-5685-4462-b002-a69064685172 --- src/jrummikub/view/impl/Board.java | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'src/jrummikub/view/impl/Board.java') diff --git a/src/jrummikub/view/impl/Board.java b/src/jrummikub/view/impl/Board.java index 2e02f75..b227760 100644 --- a/src/jrummikub/view/impl/Board.java +++ b/src/jrummikub/view/impl/Board.java @@ -5,6 +5,8 @@ import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Insets; import java.awt.RenderingHints; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; import java.util.Collections; import java.util.Map; @@ -13,6 +15,9 @@ 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; @SuppressWarnings("serial") @@ -21,11 +26,52 @@ public class Board extends JPanel implements IBoard { private Map stones = Collections.emptyMap(); private StonePainter stonePainter = new StonePainter(StonePainter.BOARD_SCALE); + + private Event1 clickEvent = new Event1(); Board() { super(true); setBorder(new CustomBorder(Color.DARK_GRAY, 0, 1, 0, 1)); + + addMouseListener(new MouseListener(){ + + @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 + + } + + @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 getClickEvent() { + return clickEvent; } @Override -- cgit v1.2.3