use of net.sf.latexdraw.commands.shape.AddShape in project latexdraw by arnobl.
the class Pencil method bindDnDToDrawFreeHandShape.
/**
* Binds a DnD interaction to create shape.
*/
private void bindDnDToDrawFreeHandShape() {
nodeBinder(AddShape.class, new DnD(false, true)).on(canvas).map(i -> {
final IShape sh = createShapeInstance();
final IPoint pt = getAdaptedPoint(i.getSrcLocalPoint());
sh.getPoints().get(0).setPoint(pt.getX(), pt.getY());
return new AddShape(sh, canvas.getDrawing());
}).first((c, i) -> Platform.runLater(() -> canvas.requestFocus())).then((c, i) -> {
final IPoint last = c.getShape().get().getPtAt(-1);
final IPoint endPt = getAdaptedPoint(i.getEndLocalPt());
if (!MathUtils.INST.equalsDouble(last.getX(), endPt.getX(), 0.0001) && !MathUtils.INST.equalsDouble(last.getY(), endPt.getY(), 0.0001)) {
c.setShape(ShapeFactory.INST.createFreeHandFrom((IFreehand) c.getShape().get(), endPt));
}
canvas.setTempView(ViewFactory.INSTANCE.createView(c.getShape().orElse(null)).orElse(null));
}).endOrCancel((c, i) -> canvas.setTempView(null)).when(i -> i.getButton() == MouseButton.PRIMARY && currentChoice.get() == EditionChoice.FREE_HAND).strictStart().bind();
}
use of net.sf.latexdraw.commands.shape.AddShape in project latexdraw by arnobl.
the class EditingSelector method configureBindings.
@Override
protected void configureBindings() {
final ToggleButton[] nodes = button2EditingChoiceMap.keySet().toArray(new ToggleButton[button2EditingChoiceMap.size() + 1]);
nodes[nodes.length - 1] = handB;
toggleButtonBinder(AddShape.class).on(handB).map(i -> new AddShape(ShapeFactory.INST.createText(ShapeFactory.INST.createPoint(pencil.textSetter.getPosition()), pencil.textSetter.getTextField().getText()), canvas.getDrawing())).when(i -> pencil.textSetter.isActivated() && !pencil.textSetter.getTextField().getText().isEmpty()).bind();
toggleButtonBinder(ModifyPencilStyle.class).on(nodes).first((c, i) -> {
c.setEditingChoice(button2EditingChoiceMap.get(i.getWidget()));
c.setPencil(pencil);
}).bind();
toggleButtonBinder(ActivateInactivateInstruments.class).on(nodes).first((c, i) -> {
final ToggleButton button = i.getWidget();
c.setActivateFirst(false);
if (button != textB) {
c.addInstrumentToInactivate(pencil.textSetter);
}
/* Selection of the instruments to activate/deactivate. */
if (button == handB) {
final boolean noSelection = canvas.getDrawing().getSelection().isEmpty();
c.addInstrumentToActivate(hand);
if (!noSelection) {
c.addInstrumentToActivate(deleter);
}
c.addInstrumentToInactivate(pencil);
if (noSelection) {
c.addInstrumentToInactivate(metaShapeCustomiser);
c.addInstrumentToInactivate(border);
} else {
c.addInstrumentToActivate(metaShapeCustomiser);
c.addInstrumentToActivate(border);
}
} else {
c.addInstrumentToInactivate(hand);
c.addInstrumentToInactivate(border);
c.addInstrumentToInactivate(deleter);
c.addInstrumentToActivate(pencil);
c.addInstrumentToActivate(metaShapeCustomiser);
}
}).bind();
buttonBinder(ActivateInactivateInstruments.class).on(codeB).first(cmd -> cmd.addInstrumentToActivate(codeInserter)).bind();
}
use of net.sf.latexdraw.commands.shape.AddShape in project latexdraw by arnobl.
the class TextSetter method configureBindings.
@Override
protected void configureBindings() {
// Key Enter to validate the text.
keyNodeBinder(ModifyShapeProperty.class).on(textField).with(KeyCode.ENTER).map(i -> new ModifyShapeProperty(ShapeProperties.TEXT, ShapeFactory.INST.createGroup(text), textField.getText())).when(i -> !pencil.isActivated() && text != null && !textField.getText().isEmpty()).bind();
// Key Enter to validate the equation of a plot shape.
keyNodeBinder(ModifyShapeProperty.class).on(textField).with(KeyCode.ENTER).map(i -> new ModifyShapeProperty(ShapeProperties.PLOT_EQ, ShapeFactory.INST.createGroup(plot), textField.getText())).when(i -> !pencil.isActivated() && plot != null && checkValidPlotFct()).bind();
// Key Enter to add a text shape.
keyNodeBinder(AddShape.class).on(textField).with(KeyCode.ENTER).map(i -> {
text = (IText) pencil.createShapeInstance();
text.setPosition(ShapeFactory.INST.createPoint(position.getX(), position.getY()));
text.setText(textField.getText());
return new AddShape(text, canvas.getDrawing());
}).when(i -> pencil.isActivated() && pencil.getCurrentChoice() == EditionChoice.TEXT && !textField.getText().isEmpty()).bind();
// Key Enter to add a plot shape.
keyNodeBinder(AddShape.class).on(textField).with(KeyCode.ENTER).map(i -> {
plot = (IPlot) pencil.createShapeInstance();
plot.setPosition(ShapeFactory.INST.createPoint(position.getX(), position.getY() + textField.getHeight()));
plot.setPlotEquation(textField.getText());
return new AddShape(plot, canvas.getDrawing());
}).when(i -> pencil.isActivated() && pencil.getCurrentChoice() == EditionChoice.PLOT && checkValidPlotFct()).bind();
keyNodeBinder(ActivateInactivateInstruments.class).on(textField).map(i -> new ActivateInactivateInstruments(null, Collections.singletonList(this), false, false)).with(KeyCode.ENTER).when(i -> textField.isValidText() && !textField.getText().isEmpty()).bind();
keyNodeBinder(ActivateInactivateInstruments.class).on(textField).map(i -> new ActivateInactivateInstruments(null, Collections.singletonList(this), false, false)).with(KeyCode.ESCAPE).bind();
}
use of net.sf.latexdraw.commands.shape.AddShape in project latexdraw by arnobl.
the class Pencil method bindMultiClic2AddShape.
/**
* Binds a multi-click interaction to creates multi-point shapes.
*/
private void bindMultiClic2AddShape() {
final Function<MultiClick, AddShape> creation = i -> new AddShape(setInitialPtsShape(createShapeInstance(), i.getPoints().get(0)), canvas.getDrawing());
// Binding for polygons
nodeBinder(AddShape.class, new MultiClick(3)).on(canvas).map(creation).then((c, i) -> {
final IPoint currPoint = getAdaptedPoint(i.getCurrentPosition());
if (c.getShape().get().getNbPoints() == i.getPoints().size() && i.getCurrentButton() == MouseButton.PRIMARY) {
c.setShape(ShapeFactory.INST.createPolygonFrom((IPolygon) c.getShape().get(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
} else {
((IModifiablePointsShape) c.getShape().get()).setPoint(currPoint.getX(), currPoint.getY(), -1);
}
canvas.setTempView(ViewFactory.INSTANCE.createView(c.getShape().orElse(null)).orElse(null));
}).endOrCancel((c, i) -> canvas.setTempView(null)).bind().activationProperty().bind(currentChoice.isEqualTo(EditionChoice.POLYGON).and(activatedProp));
// Binding for polyline
nodeBinder(AddShape.class, new MultiClick()).on(canvas).map(creation).then((c, i) -> {
final IPoint currPoint = getAdaptedPoint(i.getCurrentPosition());
if (c.getShape().get().getNbPoints() == i.getPoints().size() && i.getCurrentButton() == MouseButton.PRIMARY) {
c.setShape(ShapeFactory.INST.createPolylineFrom((IPolyline) c.getShape().get(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
} else {
((IModifiablePointsShape) c.getShape().get()).setPoint(currPoint.getX(), currPoint.getY(), -1);
}
canvas.setTempView(ViewFactory.INSTANCE.createView(c.getShape().orElse(null)).orElse(null));
}).endOrCancel((c, i) -> canvas.setTempView(null)).bind().activationProperty().bind(currentChoice.isEqualTo(EditionChoice.LINES).and(activatedProp));
// Binding for bézier curves
nodeBinder(AddShape.class, new MultiClick()).on(canvas).map(creation).then((c, i) -> {
final IPoint currPoint = getAdaptedPoint(i.getCurrentPosition());
if (c.getShape().get().getNbPoints() == i.getPoints().size() && i.getCurrentButton() == MouseButton.PRIMARY) {
c.setShape(ShapeFactory.INST.createBezierCurveFrom((IBezierCurve) c.getShape().get(), ShapeFactory.INST.createPoint(currPoint.getX(), currPoint.getY())));
} else {
((IModifiablePointsShape) c.getShape().get()).setPoint(currPoint.getX(), currPoint.getY(), -1);
}
((IControlPointShape) c.getShape().get()).balance();
canvas.setTempView(ViewFactory.INSTANCE.createView(c.getShape().orElse(null)).orElse(null));
}).endOrCancel((c, i) -> canvas.setTempView(null)).bind().activationProperty().bind(currentChoice.isEqualTo(EditionChoice.BEZIER_CURVE).and(activatedProp));
}
use of net.sf.latexdraw.commands.shape.AddShape 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