summaryrefslogtreecommitdiffstats
path: root/src/jrummikub/view/impl/AbstractStonePanel.java
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-05-06 04:33:13 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-05-06 04:33:13 +0200
commit4390c766303610c3a20b158d54d1c5bef64475a6 (patch)
tree17327bbec227ce9a8eb16d750145809b012dd347 /src/jrummikub/view/impl/AbstractStonePanel.java
parent706406ed6ffe788794268a4ab4e05403cf482dfa (diff)
downloadJRummikub-4390c766303610c3a20b158d54d1c5bef64475a6.tar
JRummikub-4390c766303610c3a20b158d54d1c5bef64475a6.zip
Handle click events next to the collection as click events for the table
git-svn-id: svn://sunsvr01.isp.uni-luebeck.de/swproj13/trunk@168 72836036-5685-4462-b002-a69064685172
Diffstat (limited to 'src/jrummikub/view/impl/AbstractStonePanel.java')
-rw-r--r--src/jrummikub/view/impl/AbstractStonePanel.java57
1 files changed, 36 insertions, 21 deletions
diff --git a/src/jrummikub/view/impl/AbstractStonePanel.java b/src/jrummikub/view/impl/AbstractStonePanel.java
index fd3862b..82bc7b7 100644
--- a/src/jrummikub/view/impl/AbstractStonePanel.java
+++ b/src/jrummikub/view/impl/AbstractStonePanel.java
@@ -1,6 +1,7 @@
package jrummikub.view.impl;
import java.awt.Insets;
+import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
@@ -61,27 +62,8 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel,
addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
- Insets insets = getInsets();
- Pair<Integer, Integer> trans = getTranslation();
- Position pos = stonePainter.calculatePosition(e.getX() - insets.left
- - trans.getFirst(), e.getY() - insets.top - trans.getSecond());
- Stone stone = getStoneAt(pos);
-
- if (stone == null) {
- if (!handleOtherClickEvent(pos))
- clickEvent.emit(pos);
-
- return;
- }
-
- Event2<Stone, Boolean> event = stoneClickEvent;
-
- if (e.isShiftDown())
- event = rangeClickEvent;
- else if (e.getClickCount() >= 2)
- event = setClickEvent;
-
- event.emit(stone, e.isControlDown());
+ clickAt(e.getPoint(), e.getClickCount(), e.isShiftDown(),
+ e.isControlDown());
}
@Override
@@ -103,6 +85,39 @@ abstract class AbstractStonePanel extends JPanel implements IStonePanel,
});
}
+ /**
+ * clickAt is called when a click has occured
+ *
+ * @param p the point in component coordinates
+ * @param clickCount the click count
+ * @param shift is shift down?
+ * @param control is control down?
+ */
+ protected void clickAt(Point p, int clickCount, boolean shift, boolean control) {
+ Insets insets = getInsets();
+ Pair<Integer, Integer> trans = getTranslation();
+ Position pos = stonePainter.calculatePosition(
+ p.x - insets.left - trans.getFirst(),
+ p.y - insets.top - trans.getSecond());
+ Stone stone = getStoneAt(pos);
+
+ if (stone == null) {
+ if (!handleOtherClickEvent(pos))
+ clickEvent.emit(pos);
+
+ return;
+ }
+
+ Event2<Stone, Boolean> event = stoneClickEvent;
+
+ if (shift)
+ event = rangeClickEvent;
+ else if (clickCount >= 2)
+ event = setClickEvent;
+
+ event.emit(stone, control);
+ }
+
private void setHoveredStone(Stone stone) {
Stone oldStone = hoveredStone;
hoveredStone = stone;