package jetbrains.mps.lang.editor.diagram.runtime.jetpad.views; /*Generated by MPS */ import jetbrains.jetpad.model.property.Property; import jetbrains.jetpad.values.Color; import jetbrains.jetpad.model.property.ValueProperty; import jetbrains.jetpad.mapper.Mapper; import jetbrains.jetpad.mapper.Synchronizers; import jetbrains.jetpad.mapper.MapperFactory; import jetbrains.jetpad.projectional.view.View; import jetbrains.jetpad.projectional.view.PolyLineView; import jetbrains.jetpad.geometry.Rectangle; import jetbrains.jetpad.geometry.Vector; public class SelectionFrameView extends AbstractExternalFrameView { public Property<Color> color = new ValueProperty<Color>(Color.BLACK); public Property<Integer> lineWidth = new ValueProperty<Integer>(1); public SelectionFrameView() { new Mapper<SelectionFrameView, SelectionFrameView>(this, this) { @Override protected void registerSynchronizers(Mapper.SynchronizersConfiguration configuration) { super.registerSynchronizers(configuration); configuration.add(Synchronizers.forConstantRole(this, SelectionFrameView.this, children(), new MapperFactory<SelectionFrameView, View>() { public Mapper<? extends SelectionFrameView, ? extends View> createMapper(SelectionFrameView selectionView) { return new Mapper<SelectionFrameView, PolyLineView>(selectionView, new NonFocusablePolyLineView()) { @Override protected void registerSynchronizers(Mapper.SynchronizersConfiguration configuration) { super.registerSynchronizers(configuration); configuration.add(Synchronizers.forProperty(color, getTarget().color())); configuration.add(Synchronizers.forProperties(lineWidth, getTarget().width())); configuration.add(Synchronizers.forProperty(frameRectangle, new Runnable() { public void run() { updateBorderView(getTarget(), frameRectangle.get()); } })); } }; } })); } }.attachRoot(); } public void setLineWidth(int width) { lineWidth.set(width); frameWidth.set(AbstractExternalFrameView.getHalfWidth(width)); } private void updateBorderView(PolyLineView polyLine, Rectangle frameBounds) { Vector topLeft = frameBounds.origin; Vector bottomRight = topLeft.add(frameBounds.dimension); polyLine.points.clear(); polyLine.points.add(new Vector(topLeft.x, topLeft.y)); polyLine.points.add(new Vector(bottomRight.x, topLeft.y)); polyLine.points.add(new Vector(bottomRight.x, bottomRight.y)); polyLine.points.add(new Vector(topLeft.x, bottomRight.y)); polyLine.points.add(new Vector(topLeft.x, topLeft.y)); } }