net.sourceforge.plantuml.skin.rose.ComponentRoseSelfArrow Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of plantuml-gplv2 Show documentation
Show all versions of plantuml-gplv2 Show documentation
PlantUML is a component that allows to quickly write diagrams from text.
// THIS FILE HAS BEEN GENERATED BY A PREPROCESSOR.
/* +=======================================================================
* |
* | PlantUML : a free UML diagram generator
* |
* +=======================================================================
*
* (C) Copyright 2009-2024, Arnaud Roques
*
* Project Info: https://plantuml.com
*
* If you like this project or if you find it useful, you can support us at:
*
* https://plantuml.com/patreon (only 1$ per month!)
* https://plantuml.com/liberapay (only 1€ per month!)
* https://plantuml.com/paypal
*
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License V2.
*
* THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE PUBLIC
* LICENSE ("AGREEMENT"). [GNU General Public License V2]
*
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
*
* You may obtain a copy of the License at
*
* https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* PlantUML can occasionally display sponsored or advertising messages. Those
* messages are usually generated on welcome or error images and never on
* functional diagrams.
* See https://plantuml.com/professional if you want to remove them
*
* Images (whatever their format : PNG, SVG, EPS...) generated by running PlantUML
* are owned by the author of their corresponding sources code (that is, their
* textual description in PlantUML language). Those images are not covered by
* this GPL v2 license.
*
* The generated images can then be used without any reference to the GPL v2 license.
* It is not even necessary to stipulate that they have been generated with PlantUML,
* although this will be appreciated by the PlantUML team.
*
* There is an exception : if the textual description in PlantUML language is also covered
* by any license, then the generated images are logically covered
* by the very same license.
*
* This is the IGY distribution (Install GraphViz by Yourself).
* You have to install GraphViz and to setup the GRAPHVIZ_DOT environment variable
* (see https://plantuml.com/graphviz-dot )
*
* Icons provided by OpenIconic : https://useiconic.com/open
* Archimate sprites provided by Archi : http://www.archimatetool.com
* Stdlib AWS provided by https://github.com/milo-minderbinder/AWS-PlantUML
* Stdlib Icons provided https://github.com/tupadr3/plantuml-icon-font-sprites
* ASCIIMathML (c) Peter Jipsen http://www.chapman.edu/~jipsen
* ASCIIMathML (c) David Lippman http://www.pierce.ctc.edu/dlippman
* CafeUndZopfli ported by Eugene Klyuchnikov https://github.com/eustas/CafeUndZopfli
* Brotli (c) by the Brotli Authors https://github.com/google/brotli
* Themes (c) by Brett Schwarz https://github.com/bschwarz/puml-themes
* Twemoji (c) by Twitter at https://twemoji.twitter.com/
*
*/
package net.sourceforge.plantuml.skin.rose;
import net.sourceforge.plantuml.klimt.LineBreakStrategy;
import net.sourceforge.plantuml.klimt.UStroke;
import net.sourceforge.plantuml.klimt.UTranslate;
import net.sourceforge.plantuml.klimt.creole.Display;
import net.sourceforge.plantuml.klimt.drawing.UGraphic;
import net.sourceforge.plantuml.klimt.font.StringBounder;
import net.sourceforge.plantuml.klimt.geom.XDimension2D;
import net.sourceforge.plantuml.klimt.geom.XPoint2D;
import net.sourceforge.plantuml.klimt.shape.UEllipse;
import net.sourceforge.plantuml.klimt.shape.ULine;
import net.sourceforge.plantuml.klimt.shape.UPolygon;
import net.sourceforge.plantuml.skin.Area;
import net.sourceforge.plantuml.skin.ArrowConfiguration;
import net.sourceforge.plantuml.skin.ArrowDecoration;
import net.sourceforge.plantuml.skin.ArrowHead;
import net.sourceforge.plantuml.skin.ArrowPart;
import net.sourceforge.plantuml.style.ISkinSimple;
import net.sourceforge.plantuml.style.Style;
public class ComponentRoseSelfArrow extends AbstractComponentRoseArrow {
private final double arrowWidth = 45;
private final boolean niceArrow;
public ComponentRoseSelfArrow(Style style, Display stringsToDisplay, ArrowConfiguration arrowConfiguration,
ISkinSimple spriteContainer, LineBreakStrategy maxMessageSize, boolean niceArrow) {
super(style, stringsToDisplay, arrowConfiguration, spriteContainer, maxMessageSize);
this.niceArrow = niceArrow;
}
@Override
protected void drawInternalU(UGraphic ug, Area area) {
if (getArrowConfiguration().isHidden()) {
return;
}
final StringBounder stringBounder = ug.getStringBounder();
final double textHeight = getTextHeight(stringBounder);
ug = ug.apply(getForegroundColor());
final double xRight = arrowWidth - 3;
final UGraphic ug2 = getArrowConfiguration().applyStroke(ug);
double x1 = area.getDeltaX1() < 0 ? area.getDeltaX1() : 0;
double x2 = area.getDeltaX1() > 0 ? -area.getDeltaX1() : 0 + 1;
final double arrowHeight = getArrowOnlyHeight(stringBounder);
final UEllipse circle = UEllipse.build(ComponentRoseArrow.diamCircle, ComponentRoseArrow.diamCircle);
if (getArrowConfiguration().getDecoration1() == ArrowDecoration.CIRCLE) {
ug2.apply(UStroke.withThickness(ComponentRoseArrow.thinCircle)).apply(getForegroundColor())
.apply(new UTranslate(x1 + 1 - ComponentRoseArrow.diamCircle / 2 - ComponentRoseArrow.thinCircle,
textHeight - ComponentRoseArrow.diamCircle / 2 - ComponentRoseArrow.thinCircle / 2))
.draw(circle);
x1 += ComponentRoseArrow.diamCircle / 2;
}
if (getArrowConfiguration().getDecoration2() == ArrowDecoration.CIRCLE) {
ug2.apply(UStroke.withThickness(ComponentRoseArrow.thinCircle)).apply(getForegroundColor()).apply(new UTranslate(
x2 - ComponentRoseArrow.diamCircle / 2 - ComponentRoseArrow.thinCircle,
textHeight + arrowHeight - ComponentRoseArrow.diamCircle / 2 - ComponentRoseArrow.thinCircle / 2))
.draw(circle);
x2 += ComponentRoseArrow.diamCircle / 2;
}
final boolean hasStartingCrossX = getArrowConfiguration().getDressing1().getHead() == ArrowHead.CROSSX;
if (hasStartingCrossX)
x1 += 2 * ComponentRoseArrow.spaceCrossX;
final boolean hasFinalCrossX = getArrowConfiguration().getDressing2().getHead() == ArrowHead.CROSSX;
if (hasFinalCrossX)
x2 += 2 * ComponentRoseArrow.spaceCrossX;
if (getArrowConfiguration().isReverseDefine()) {
ug2.apply(new UTranslate(-xRight, textHeight)).draw(ULine.hline(xRight - x1));
ug2.apply(new UTranslate(-xRight, textHeight)).draw(ULine.vline(arrowHeight));
ug2.apply(new UTranslate(-xRight, textHeight + arrowHeight)).draw(ULine.hline(xRight - x2));
final UPolygon polygon = getPolygon().translate(0, textHeight + arrowHeight);
ug.apply(getForegroundColor().bg()).apply(UTranslate.dx(x2)).draw(polygon);
} else {
ug2.apply(new UTranslate(x1, textHeight)).draw(ULine.hline(xRight - x1));
ug2.apply(new UTranslate(xRight, textHeight)).draw(ULine.vline(arrowHeight));
ug2.apply(new UTranslate(x2, textHeight + arrowHeight)).draw(ULine.hline(xRight - x2));
if (hasStartingCrossX) {
ug.apply(UStroke.withThickness(2))
.apply(new UTranslate(ComponentRoseArrow.spaceCrossX, textHeight - getArrowDeltaX() / 2))
.draw(new ULine(getArrowDeltaX(), getArrowDeltaX()));
ug.apply(UStroke.withThickness(2))
.apply(new UTranslate(ComponentRoseArrow.spaceCrossX, textHeight + getArrowDeltaX() / 2))
.draw(new ULine(getArrowDeltaX(), -getArrowDeltaX()));
} else if (getArrowConfiguration().getDressing1().getHead() == ArrowHead.NORMAL) {
final UPolygon polygon = getPolygon().translate(0, textHeight);
ug.apply(getForegroundColor().bg()).apply(UTranslate.dx(x1)).draw(polygon);
}
if (hasFinalCrossX) {
ug.apply(UStroke.withThickness(2))
.apply(new UTranslate(ComponentRoseArrow.spaceCrossX,
textHeight - getArrowDeltaX() / 2 + arrowHeight))
.draw(new ULine(getArrowDeltaX(), getArrowDeltaX()));
ug.apply(UStroke.withThickness(2))
.apply(new UTranslate(ComponentRoseArrow.spaceCrossX,
textHeight + getArrowDeltaX() / 2 + arrowHeight))
.draw(new ULine(getArrowDeltaX(), -getArrowDeltaX()));
} else if (getArrowConfiguration().isAsync()) {
if (getArrowConfiguration().getPart() != ArrowPart.BOTTOM_PART) {
getArrowConfiguration().applyThicknessOnly(ug).apply(new UTranslate(x2, textHeight + arrowHeight))
.draw(new ULine(getArrowDeltaX(), -getArrowDeltaY()));
}
if (getArrowConfiguration().getPart() != ArrowPart.TOP_PART) {
getArrowConfiguration().applyThicknessOnly(ug).apply(new UTranslate(x2, textHeight + arrowHeight))
.draw(new ULine(getArrowDeltaX(), getArrowDeltaY()));
}
} else if (getArrowConfiguration().getDressing2().getHead() == ArrowHead.NORMAL) {
final UPolygon polygon = getPolygon().translate(0, textHeight + arrowHeight);
ug.apply(getForegroundColor().bg()).apply(UTranslate.dx(x2)).draw(polygon);
}
}
if (getArrowConfiguration().isReverseDefine())
getTextBlock().drawU(ug.apply(UTranslate.dx(-getPureTextWidth(stringBounder))));
else
getTextBlock().drawU(ug.apply(UTranslate.dx(getMarginX1())));
}
private UPolygon getPolygon() {
final UPolygon polygon = new UPolygon();
final double direction = getArrowConfiguration().isReverseDefine() ? -1 : 1;
final double x = direction * getArrowDeltaX();
if (getArrowConfiguration().getPart() == ArrowPart.TOP_PART) {
polygon.addPoint(x, -getArrowDeltaY());
polygon.addPoint(0, 0);
polygon.addPoint(x, 0);
} else if (getArrowConfiguration().getPart() == ArrowPart.BOTTOM_PART) {
polygon.addPoint(x, 0);
polygon.addPoint(0, 0);
polygon.addPoint(x, getArrowDeltaY());
} else {
polygon.addPoint(x, -getArrowDeltaY());
polygon.addPoint(0, 0);
polygon.addPoint(x, getArrowDeltaY());
if (niceArrow) {
polygon.addPoint(x - direction * 4, 0);
}
}
return polygon;
}
public XPoint2D getStartPoint(StringBounder stringBounder, XDimension2D dimensionToUse) {
final double textHeight = getTextHeight(stringBounder);
return new XPoint2D(getPaddingX(), textHeight + getPaddingY());
}
public XPoint2D getEndPoint(StringBounder stringBounder, XDimension2D dimensionToUse) {
final double textHeight = getTextHeight(stringBounder);
final double textAndArrowHeight = textHeight + getArrowOnlyHeight(stringBounder);
return new XPoint2D(getPaddingX(), textAndArrowHeight + getPaddingY());
}
@Override
public double getYPoint(StringBounder stringBounder) {
final double textHeight = getTextHeight(stringBounder);
final double textAndArrowHeight = textHeight + getArrowOnlyHeight(stringBounder);
return (textHeight + textAndArrowHeight) / 2 + getPaddingX();
}
@Override
public double getPreferredHeight(StringBounder stringBounder) {
return getTextHeight(stringBounder) + getArrowDeltaY() + getArrowOnlyHeight(stringBounder) + 2 * getPaddingY();
}
private double getArrowOnlyHeight(StringBounder stringBounder) {
return 13;
}
@Override
public double getPreferredWidth(StringBounder stringBounder) {
return Math.max(getTextWidth(stringBounder), arrowWidth);
}
public double getPosArrow(StringBounder stringBounder) {
throw new UnsupportedOperationException();
}
}