use of net.sf.latexdraw.models.interfaces.shape.IPositionShape in project latexdraw by arnobl.
the class Pencil method bindPressToAddShape.
/**
* Binds a press interaction to add a shape.
*/
private void bindPressToAddShape() {
// Add axes, grids, or dots
nodeBinder(AddShape.class, new Press()).on(canvas).map(i -> {
final IPositionShape sh = (IPositionShape) createShapeInstance();
sh.setPosition(getAdaptedPoint(i.getSrcLocalPoint()));
return new AddShape(sh, canvas.getDrawing());
}).when(i -> i.getButton() == MouseButton.PRIMARY).bind().activationProperty().bind(activatedProp.and(currentChoice.isEqualTo(EditionChoice.GRID).or(currentChoice.isEqualTo(EditionChoice.DOT)).or(currentChoice.isEqualTo(EditionChoice.AXES))));
// When a user starts to type a text using the text setter and then he clicks somewhere else in the canvas,
// the text typed must be added (if possible to the canvas) before starting typing a new text.
nodeBinder(AddShape.class, new Press()).on(canvas).map(i -> new AddShape(ShapeFactory.INST.createText(ShapeFactory.INST.createPoint(textSetter.getPosition()), textSetter.getTextField().getText()), canvas.getDrawing())).when(i -> textSetter.isActivated() && !textSetter.getTextField().getText().isEmpty()).bind().activationProperty().bind(currentChoice.isEqualTo(EditionChoice.TEXT).and(activatedProp));
}
Aggregations