0

I use UndoFX for the undo and redo functions to a rectangle shape. So far it is working fine for position, size and rotation, except the fillProperty color of the shape.

The problem is that i can't bind my shape with the ColorPicker component, i get infinite exceptions:

Rectangle.fill: A bound value cannot be set.

How can i use both undofx functions and binding?

colorField.valueProperty().setValue((Color) (currentSelected.getRect().fillProperty().getValue()));

currentSelected.getRect().fillProperty().bind(colorField.valueProperty());

previousSelected.getRect().fillProperty().unbind();
Senpai
  • 515
  • 6
  • 18
  • The [example from the library documentation](https://github.com/TomasMikula/UndoFX/blob/master/undofx-demos/src/main/java/org/fxmisc/undo/demo/CircleProperties.java#L180-L202) does exactly this; have the `redo` for the change in the color change the value of the color picker instead of the value of the circle's fill directly. The binding will ensure the circle's fill is updated. – James_D Jun 07 '16 at 01:56
  • @James_D I'm afraid this doesn't apply when there are more than one rectangle. @Senpai, make `currentSelected` an `ObservableValue` and then `bindBidirectional` between `colorField.valueProperty()` and `Val.selectVar(currentSelected, x -> x.getRect().fillProperty())` should do what you expect. – Tomas Mikula Jun 07 '16 at 03:19
  • Ah yes, didn't notice there were multiple rectangles there. Apologies. – James_D Jun 07 '16 at 03:22
  • @TomasMikula When trying to bindBidirectional: Type mismatch: cannot convert from Var to Property – Senpai Jun 07 '16 at 17:18
  • Ah, `Var` does extend `Property`, but `Rectangle#fillProperty()` is a `Paint`, while `ColorPicker#valueProperty()` is a `Color`. Try to `bindBidirectional` this instead: `Val.selectVar(currentSelected, x -> x.getRect().fillProperty()).mapBidirectional(paintToColor, Function.identity())`, where `Function paintToColor = p -> { if(p instanceof Color) return (Color) p; else return null; }` – Tomas Mikula Jun 07 '16 at 17:41

0 Answers0