1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-05-31 15:40:48 +00:00
plantuml/src/net/sourceforge/plantuml/nwdiag/VerticalLine.java
2020-08-25 19:24:17 +02:00

97 lines
2.6 KiB
Java

/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2020, Arnaud Roques
*
* Project Info: http://plantuml.com
*
* If you like this project or if you find it useful, you can support us at:
*
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
*
*/
package net.sourceforge.plantuml.nwdiag;
import java.util.TreeSet;
import net.sourceforge.plantuml.graphic.UDrawable;
import net.sourceforge.plantuml.ugraphic.UEllipse;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.ULine;
import net.sourceforge.plantuml.ugraphic.UTranslate;
public class VerticalLine implements UDrawable {
private final double y1;
private final double y2;
private final TreeSet<Double> skip;
public VerticalLine(double y1, double y2, TreeSet<Double> skip) {
this.y1 = Math.min(y1, y2);
this.y2 = Math.max(y1, y2);
this.skip = skip;
}
public void drawU(UGraphic ug) {
boolean drawn = false;
double current = y1;
for (Double step : skip) {
if (step < y1) {
continue;
}
assert step >= y1;
drawn = true;
if (step == y2) {
drawVLine(ug, current, y2);
} else {
drawVLine(ug, current, Math.min(y2, step - 3));
if (y2 > step) {
drawArc(ug, step - 3);
}
}
current = step + 9;
if (current >= y2) {
break;
}
}
if (drawn == false) {
drawVLine(ug, y1, y2);
}
}
private void drawArc(UGraphic ug, double y) {
final UEllipse arc = new UEllipse(11, 11, 90, -180);
ug.apply(new UTranslate(-5, y)).draw(arc);
}
private void drawVLine(UGraphic ug, double start, double end) {
final ULine line = ULine.vline(end - start);
ug.apply(UTranslate.dy(start)).draw(line);
}
}