package jetbrains.mps.lang.editor.diagram.runtime.jetpad.views; /*Generated by MPS */ import jetbrains.jetpad.projectional.view.GroupView; import jetbrains.jetpad.model.property.Property; import jetbrains.jetpad.values.Color; import jetbrains.jetpad.model.property.ValueProperty; import jetbrains.jetpad.geometry.Vector; import jetbrains.jetpad.projectional.view.LineView; import jetbrains.jetpad.mapper.Mapper; import jetbrains.jetpad.mapper.Synchronizers; public class CrossView extends GroupView { public Property<Color> color = new ValueProperty<Color>(Color.BLACK); public Property<Integer> segmentLength = new ValueProperty<Integer>(4); public Property<Integer> lineWidth = new ValueProperty<Integer>(3); public Property<Vector> centerLocation = new ValueProperty<Vector>(null); private final LineView myFirstLine = new NonFocusableLineView(); private final LineView mySecondLine = new NonFocusableLineView(); public CrossView() { children().add(myFirstLine); children().add(mySecondLine); new Mapper<CrossView, CrossView>(this, this) { @Override protected void registerSynchronizers(Mapper.SynchronizersConfiguration configuration) { super.registerSynchronizers(configuration); configuration.add(Synchronizers.forProperty(color, myFirstLine.color())); configuration.add(Synchronizers.forProperties(lineWidth, myFirstLine.width())); configuration.add(Synchronizers.forProperty(color, mySecondLine.color())); configuration.add(Synchronizers.forProperties(lineWidth, mySecondLine.width())); configuration.add(Synchronizers.forProperty(centerLocation, new Runnable() { public void run() { updateCross(centerLocation.get(), segmentLength.get()); } })); configuration.add(Synchronizers.forProperty(segmentLength, new Runnable() { public void run() { updateCross(centerLocation.get(), segmentLength.get()); } })); } }.attachRoot(); } private void updateCross(Vector position, int length) { if (position == null) { setVisible(false); return; } else { setVisible(true); } myFirstLine.start().set(new Vector(position.x - length, position.y - length)); myFirstLine.end().set(new Vector(position.x + length, position.y + length)); mySecondLine.start().set(new Vector(position.x + length, position.y - length)); mySecondLine.end().set(new Vector(position.x - length, position.y + length)); } private void setVisible(boolean isVisible) { visible().set(isVisible); myFirstLine.visible().set(isVisible); mySecondLine.visible().set(isVisible); } }