package jrummikub.view.impl; import java.awt.Insets; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JPanel; import jrummikub.model.Position; import jrummikub.util.Event2; import jrummikub.view.IClickable; @SuppressWarnings("serial") abstract class StonePanel extends JPanel implements IClickable { private StonePainter stonePainter; private Event2 clickEvent = new Event2(); private Event2 rangeClickEvent = new Event2(); private Event2 setClickEvent = new Event2(); protected StonePainter getStonePainter() { return stonePainter; } public StonePanel() { this(1); } public StonePanel(float scale) { super(true); // Set double buffered stonePainter = new StonePainter(scale); addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { Insets insets = getInsets(); Event2 event = clickEvent; if (e.isShiftDown()) event = rangeClickEvent; else if (e.getClickCount() >= 2) event = setClickEvent; event.fire( stonePainter.calculatePosition(e.getX() - insets.left, e.getY() - insets.top), e.isControlDown()); } }); } @Override public Event2 getClickEvent() { return clickEvent; } @Override public Event2 getRangeClickEvent() { return rangeClickEvent; } @Override public Event2 getSetClickEvent() { return setClickEvent; } }