@Override public boolean contains(Location loc, AttributeSet attrs) { if (super.contains(loc, attrs)) { Direction facing = attrs.getValue(StdAttr.FACING); Location center = Location.create(0, 0).translate(facing, -20); return center.manhattanDistanceTo(loc) < 24; } else { return false; } }
@Override public boolean contains(Location loc, AttributeSet attrsBase) { GateAttributes attrs = (GateAttributes) attrsBase; if (super.contains(loc, attrs)) { if (attrs.negated == 0) { return true; } else { Direction facing = attrs.facing; Bounds bds = getOffsetBounds(attrsBase); int delt; if (facing == Direction.NORTH) { delt = loc.getY() - (bds.getY() + bds.getHeight()); } else if (facing == Direction.SOUTH) { delt = loc.getY() - bds.getY(); } else if (facing == Direction.WEST) { delt = loc.getX() - (bds.getX() + bds.getHeight()); } else { delt = loc.getX() - bds.getX(); } if (Math.abs(delt) > 5) { return true; } else { int inputs = attrs.inputs; for (int i = 1; i <= inputs; i++) { Location offs = getInputOffset(attrs, i); if (loc.manhattanDistanceTo(offs) <= 5) { return true; } } return false; } } } else { return false; } }
public void mouseDragged(MouseEvent e) { Location start = dragStart; if (start != null && start.manhattanDistanceTo(e.getX(), e.getY()) > 4) { hideCurrentPopup(); } }