net.sourceforge.plantuml.svek.UGraphicForSnake Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plantuml-mit Show documentation
Show all versions of plantuml-mit Show documentation
PlantUML is a component that allows to quickly write diagrams from text.
// THIS FILE HAS BEEN GENERATED BY A PREPROCESSOR.
package net.sourceforge.plantuml.svek;
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.plantuml.activitydiagram3.ftile.Snake;
import net.sourceforge.plantuml.klimt.UChange;
import net.sourceforge.plantuml.klimt.UShape;
import net.sourceforge.plantuml.klimt.UTranslate;
import net.sourceforge.plantuml.klimt.drawing.UGraphic;
import net.sourceforge.plantuml.klimt.drawing.UGraphicDelegator;
public class UGraphicForSnake extends UGraphicDelegator {
private final double dx;
private final double dy;
private final List snakes;
@Override
public String toString() {
return "UGraphicForSnake " + getUg();
}
public UTranslate getTranslation() {
return new UTranslate(dx, dy);
}
static class PendingSnake {
private Snake snake;
private final UGraphic ug;
private final double dx;
private final double dy;
private PendingSnake(Snake snake, UGraphic ug, double dx, double dy) {
this.snake = snake;
this.ug = ug;
this.dx = dx;
this.dy = dy;
}
void drawInternal() {
snake.drawInternal(ug);
}
void removeEndDecorationIfTouches(List snakes) {
for (PendingSnake other : snakes) {
if (moved().touches(other.moved())) {
this.snake = this.snake.withoutEndDecoration();
return;
}
}
}
private Snake moved() {
return snake.move(dx, dy);
}
@Override
public String toString() {
return "dx=" + dx + " dy=" + dy + " " + snake.move(dx, dy).toString();
}
public PendingSnake merge(PendingSnake newItem) {
// if (snake.isMergeable() == false || newItem.snake.isMergeable() == false) {
// return null;
// }
final Snake s1 = snake.move(dx, dy);
final Snake s2 = newItem.snake.move(newItem.dx, newItem.dy);
final Snake merge = s1.merge(s2, ug.getStringBounder());
if (merge == null) {
return null;
}
return new PendingSnake(merge.move(-dx, -dy), ug, dx, dy);
}
}
public UGraphicForSnake(UGraphic ug) {
this(ug, 0, 0, new ArrayList());
}
private UGraphicForSnake(UGraphic ug, double dx, double dy, List snakes) {
super(ug);
this.dx = dx;
this.dy = dy;
this.snakes = snakes;
}
public void draw(UShape shape) {
if (shape instanceof Snake) {
final Snake snake = (Snake) shape;
addPendingSnake(snake);
} else {
getUg().draw(shape);
}
}
private void addPendingSnake(final Snake snake) {
final PendingSnake newItem = new PendingSnake(snake, getUg(), dx, dy);
for (int pos = 0; pos < snakes.size(); pos++) {
final PendingSnake merge = snakes.get(pos).merge(newItem);
if (merge != null) {
snakes.set(pos, merge);
return;
}
}
snakes.add(newItem);
}
@Override
public void flushUg() {
for (PendingSnake snake : snakes) {
snake.removeEndDecorationIfTouches(snakes);
snake.drawInternal();
}
snakes.clear();
}
public UGraphic apply(UChange change) {
double newdx = dx;
double newdy = dy;
if (change instanceof UTranslate) {
newdx += ((UTranslate) change).getDx();
newdy += ((UTranslate) change).getDy();
}
return new UGraphicForSnake(getUg().apply(change), newdx, newdy, snakes);
}
}