use of io.github.interacto.jfx.interaction.library.Press 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().usingInteraction(Press::new).toProduce(i -> {
final PositionShape sh = (PositionShape) editing.createShapeInstance();
sh.setPosition(getAdaptedPoint(i.getSrcLocalPoint()));
return new AddShape(sh, canvas.getDrawing());
}).on(canvas).when(i -> i.getButton() == MouseButton.PRIMARY && (editing.getCurrentChoice() == EditionChoice.GRID || editing.getCurrentChoice() == EditionChoice.DOT || editing.getCurrentChoice() == EditionChoice.AXES)).bind();
// 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().usingInteraction(Press::new).toProduce(i -> new AddShape(ShapeFactory.INST.createText(ShapeFactory.INST.createPoint(textSetter.getPosition()), textSetter.getTextField().getText()), canvas.getDrawing())).on(canvas).when(i -> textSetter.isActivated() && !textSetter.getTextField().getText().isEmpty() && editing.getCurrentChoice() == EditionChoice.TEXT).bind();
}
Aggregations