use of net.sf.latexdraw.view.jfx.ViewShape in project latexdraw by arnobl.
the class Hand method getViewShape.
private static Optional<ViewShape<?>> getViewShape(final Optional<Node> node) {
if (node.isPresent()) {
final Node value = node.get();
Node parent = value.getParent();
while (parent != null && !(parent instanceof ViewShape<?>)) {
parent = parent.getParent();
}
return Optional.ofNullable(getRealViewShape((ViewShape<?>) parent));
}
return Optional.empty();
}
use of net.sf.latexdraw.view.jfx.ViewShape in project latexdraw by arnobl.
the class DistributeShapes method distributeEq.
/**
* Distributes at equal distance between the shapes.
*/
private void distributeEq() {
final List<ViewShape<?>> sortedSh = new ArrayList<>();
final List<Double> mins = new ArrayList<>();
final List<Double> maxs = new ArrayList<>();
for (final ViewShape<?> view : views) {
final double coord = distribution == Distribution.HORIZ_EQ ? view.getBoundsInLocal().getMinX() : view.getBoundsInLocal().getMinY();
final OptionalInt res = IntStream.range(0, mins.size()).filter(index -> coord < mins.get(index)).findFirst();
if (res.isPresent()) {
final int i = res.getAsInt();
sortedSh.add(i, view);
mins.add(i, coord);
maxs.add(i, distribution == Distribution.HORIZ_EQ ? view.getBoundsInLocal().getMaxX() : view.getBoundsInLocal().getMaxY());
} else {
sortedSh.add(view);
mins.add(coord);
maxs.add(distribution == Distribution.HORIZ_EQ ? view.getBoundsInLocal().getMaxX() : view.getBoundsInLocal().getMaxY());
}
}
double gap = mins.get(mins.size() - 1) - maxs.get(0);
for (int i = 1, size = sortedSh.size() - 1; i < size; i++) {
gap -= maxs.get(i) - mins.get(i);
}
gap /= sortedSh.size() - 1;
final double finalGap = gap;
if (Distribution.isVertical(distribution)) {
IntStream.range(1, sortedSh.size() - 1).forEach(i -> ((IShape) sortedSh.get(i).getUserData()).translate(0d, sortedSh.get(i - 1).getBoundsInLocal().getMaxY() + finalGap - mins.get(i)));
} else {
IntStream.range(1, sortedSh.size() - 1).forEach(i -> ((IShape) sortedSh.get(i).getUserData()).translate(sortedSh.get(i - 1).getBoundsInLocal().getMaxX() + finalGap - mins.get(i), 0d));
}
}
use of net.sf.latexdraw.view.jfx.ViewShape in project latexdraw by arnobl.
the class DistributeShapes method distributeNotEq.
/**
* Distributes using bottom/top/left/right reference.
*/
private void distributeNotEq() {
final List<ViewShape<?>> sortedSh = new ArrayList<>();
final List<Double> centres = new ArrayList<>();
for (final ViewShape<?> view : views) {
double x = 0;
switch(distribution) {
case HORIZ_LEFT:
x = view.getBoundsInLocal().getMinX();
break;
case HORIZ_MID:
x = (view.getBoundsInLocal().getMinX() + view.getBoundsInLocal().getMaxX()) / 2d;
break;
case HORIZ_RIGHT:
x = view.getBoundsInLocal().getMaxX();
break;
case VERT_BOT:
x = view.getBoundsInLocal().getMaxY();
break;
case VERT_MID:
x = (view.getBoundsInLocal().getMinY() + view.getBoundsInLocal().getMaxY()) / 2d;
break;
case VERT_TOP:
x = view.getBoundsInLocal().getMinY();
break;
default:
}
final double finalX = x;
final OptionalInt res = IntStream.range(0, centres.size()).filter(index -> finalX < centres.get(index)).findFirst();
if (res.isPresent()) {
final int i = res.getAsInt();
sortedSh.add(i, view);
centres.add(i, x);
} else {
sortedSh.add(view);
centres.add(x);
}
}
final double gap = (centres.get(centres.size() - 1) - centres.get(0)) / (views.size() - 1);
if (Distribution.isVertical(distribution)) {
IntStream.range(1, sortedSh.size() - 1).forEach(i -> ((IShape) sortedSh.get(i).getUserData()).translate(0d, centres.get(0) + i * gap - centres.get(i)));
} else {
IntStream.range(1, sortedSh.size() - 1).forEach(i -> ((IShape) sortedSh.get(i).getUserData()).translate(centres.get(0) + i * gap - centres.get(i), 0d));
}
}
use of net.sf.latexdraw.view.jfx.ViewShape in project latexdraw by arnobl.
the class TestAlignShape method setUp.
@Override
@Before
public void setUp() {
super.setUp();
canvas = Mockito.mock(Canvas.class);
final IShapeFactory fac = ShapeFactory.INST;
shapes = fac.createGroup();
shapes.addShape(fac.createRectangle(fac.createPoint(10d, -2d), 6d, 6d));
shapes.addShape(fac.createRectangle(fac.createPoint(-5d, 20d), 12d, 15d));
shapes.addShape(fac.createRectangle(fac.createPoint(14d, 60d), 20d, 16d));
views = new Group();
IntStream.range(0, shapes.size()).forEach(i -> {
views.getChildren().add(ViewFactory.INSTANCE.createView(shapes.getShapeAt(i)).get());
Mockito.when(canvas.getViewFromShape(shapes.getShapeAt(i))).thenReturn(Optional.of((ViewShape<?>) views.getChildren().get(i)));
});
}
Aggregations