diff options
Diffstat (limited to 'src/jrummikub/view/impl/AbstractStonePanel.java')
-rw-r--r-- | src/jrummikub/view/impl/AbstractStonePanel.java | 57 |
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; |