Handle clicks on table
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@34 72836036-5685-4462-b002-a69064685172
This commit is contained in:
parent
7b80311556
commit
1b15b71a54
4 changed files with 58 additions and 50 deletions
|
@ -71,6 +71,14 @@ public class JRummikub {
|
||||||
|
|
||||||
}});
|
}});
|
||||||
|
|
||||||
|
view.getTable().getClickEvent().add(new IListener1<Position>(){
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fire(Position value) {
|
||||||
|
System.out.println("Table clicked at "+value);
|
||||||
|
|
||||||
|
}});
|
||||||
|
|
||||||
//stoneSets on the table
|
//stoneSets on the table
|
||||||
Map<StoneSet, Position> stoneSets = new HashMap<StoneSet, Position>();
|
Map<StoneSet, Position> stoneSets = new HashMap<StoneSet, Position>();
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,12 @@ import java.util.Map;
|
||||||
|
|
||||||
import jrummikub.model.Position;
|
import jrummikub.model.Position;
|
||||||
import jrummikub.model.StoneSet;
|
import jrummikub.model.StoneSet;
|
||||||
|
import jrummikub.util.IEvent1;
|
||||||
|
|
||||||
public interface ITable {
|
public interface ITable {
|
||||||
public void setLeftPlayerName(String playerName);
|
public void setLeftPlayerName(String playerName);
|
||||||
public void setTopPlayerName(String playerName);
|
public void setTopPlayerName(String playerName);
|
||||||
public void setRightPlayerName(String playerName);
|
public void setRightPlayerName(String playerName);
|
||||||
void setStoneSets(Map<StoneSet, Position> stoneSets);
|
public void setStoneSets(Map<StoneSet, Position> stoneSets);
|
||||||
|
public IEvent1<Position> getClickEvent();
|
||||||
}
|
}
|
|
@ -5,8 +5,8 @@ import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.RenderingHints;
|
import java.awt.RenderingHints;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseEvent;
|
||||||
import java.awt.event.MouseListener;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@ import javax.swing.JPanel;
|
||||||
import jrummikub.model.Position;
|
import jrummikub.model.Position;
|
||||||
import jrummikub.model.Stone;
|
import jrummikub.model.Stone;
|
||||||
import jrummikub.util.Event1;
|
import jrummikub.util.Event1;
|
||||||
import jrummikub.util.IEvent;
|
|
||||||
import jrummikub.util.IEvent1;
|
import jrummikub.util.IEvent1;
|
||||||
import jrummikub.view.IBoard;
|
import jrummikub.view.IBoard;
|
||||||
|
|
||||||
|
@ -30,43 +29,19 @@ public class Board extends JPanel implements IBoard {
|
||||||
private Event1<Position> clickEvent = new Event1<Position>();
|
private Event1<Position> clickEvent = new Event1<Position>();
|
||||||
|
|
||||||
Board() {
|
Board() {
|
||||||
super(true);
|
super(true); // set double buffered
|
||||||
|
|
||||||
setBorder(new CustomBorder(Color.DARK_GRAY, 0, 1, 0, 1));
|
setBorder(new CustomBorder(Color.DARK_GRAY, 0, 1, 0, 1));
|
||||||
|
|
||||||
addMouseListener(new MouseListener(){
|
addMouseListener(new MouseAdapter() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void mouseClicked(MouseEvent e) {
|
public void mouseClicked(MouseEvent e) {
|
||||||
Insets insets = getInsets();
|
Insets insets = getInsets();
|
||||||
|
|
||||||
clickEvent.fire(stonePainter.calculatePosition(e.getX()-insets.left, e.getY()-insets.top));
|
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
|
@Override
|
||||||
|
|
|
@ -4,7 +4,10 @@ import java.awt.BorderLayout;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Insets;
|
||||||
import java.awt.RenderingHints;
|
import java.awt.RenderingHints;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -13,13 +16,15 @@ import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
|
||||||
import jrummikub.model.Position;
|
import jrummikub.model.Position;
|
||||||
import jrummikub.model.Stone;
|
|
||||||
import jrummikub.model.StoneSet;
|
import jrummikub.model.StoneSet;
|
||||||
|
import jrummikub.util.Event1;
|
||||||
|
import jrummikub.util.IEvent1;
|
||||||
import jrummikub.view.ITable;
|
import jrummikub.view.ITable;
|
||||||
|
|
||||||
@SuppressWarnings("serial")
|
@SuppressWarnings("serial")
|
||||||
public class Table extends JPanel implements ITable {
|
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 JLabel leftPlayerLabel, topPlayerLabel, rightPlayerLabel;
|
||||||
private JPanel innerPanel;
|
private JPanel innerPanel;
|
||||||
|
@ -28,6 +33,9 @@ public class Table extends JPanel implements ITable {
|
||||||
|
|
||||||
private Map<StoneSet, Position> stoneSets = Collections.emptyMap();
|
private Map<StoneSet, Position> stoneSets = Collections.emptyMap();
|
||||||
|
|
||||||
|
private Event1<Position> clickEvent = new Event1<Position>();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setLeftPlayerName(String playerName) {
|
public void setLeftPlayerName(String playerName) {
|
||||||
leftPlayerLabel.setText(playerName);
|
leftPlayerLabel.setText(playerName);
|
||||||
|
@ -48,6 +56,11 @@ public class Table extends JPanel implements ITable {
|
||||||
this.stoneSets = stoneSets;
|
this.stoneSets = stoneSets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IEvent1<Position> getClickEvent() {
|
||||||
|
return clickEvent;
|
||||||
|
}
|
||||||
|
|
||||||
Table() {
|
Table() {
|
||||||
super(true); // set double buffered
|
super(true); // set double buffered
|
||||||
setLayout(new BorderLayout());
|
setLayout(new BorderLayout());
|
||||||
|
@ -69,6 +82,16 @@ public class Table extends JPanel implements ITable {
|
||||||
innerPanel = new JPanel();
|
innerPanel = new JPanel();
|
||||||
innerPanel.setOpaque(false);
|
innerPanel.setOpaque(false);
|
||||||
add(innerPanel, BorderLayout.CENTER);
|
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
|
@Override
|
||||||
|
|
Reference in a new issue