/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2017, 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.skin.bluemodern;
import java.awt.geom.Dimension2D;
import java.awt.geom.Point2D;
import net.sourceforge.plantuml.ISkinSimple;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.graphic.FontConfiguration;
import net.sourceforge.plantuml.graphic.HtmlColor;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.skin.Area;
import net.sourceforge.plantuml.skin.ArrowConfiguration;
import net.sourceforge.plantuml.skin.ArrowPart;
import net.sourceforge.plantuml.ugraphic.UChangeBackColor;
import net.sourceforge.plantuml.ugraphic.UChangeColor;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.ULine;
import net.sourceforge.plantuml.ugraphic.UPolygon;
import net.sourceforge.plantuml.ugraphic.UStroke;
import net.sourceforge.plantuml.ugraphic.UTranslate;
public class ComponentBlueModernSelfArrow extends AbstractComponentBlueModernArrow {
private final double arrowWidth = 45;
public ComponentBlueModernSelfArrow(HtmlColor foregroundColor, FontConfiguration font, Display stringsToDisplay,
ArrowConfiguration arrowConfiguration, ISkinSimple spriteContainer) {
super(foregroundColor, font, stringsToDisplay, arrowConfiguration, spriteContainer);
}
@Override
protected void drawInternalU(UGraphic ug, Area area) {
if (getArrowConfiguration().isHidden()) {
return;
}
final StringBounder stringBounder = ug.getStringBounder();
final int textHeight = (int) getTextHeight(stringBounder);
ug = ug.apply(new UChangeBackColor(getForegroundColor())).apply(new UChangeColor(getForegroundColor()));
final double x2 = arrowWidth - 3;
if (getArrowConfiguration().isDotted()) {
ug = ArrowConfiguration.stroke(ug, 5, 2, 1);
} else {
ug = ug.apply(new UStroke(2));
}
ug.apply(new UTranslate(0, textHeight)).draw(new ULine(x2, 0));
final int textAndArrowHeight = (int) (textHeight + getArrowOnlyHeight(stringBounder));
ug.apply(new UTranslate(x2, textHeight)).draw(new ULine(0, textAndArrowHeight - textHeight));
ug.apply(new UTranslate(x2, textAndArrowHeight)).draw(new ULine(2 - x2, 0));
ug = ug.apply(new UStroke());
final int delta = (int) getArrowOnlyHeight(stringBounder);
if (getArrowConfiguration().isAsync()) {
if (getArrowConfiguration().getPart() != ArrowPart.BOTTOM_PART) {
ug.apply(new UStroke(1.5))
.apply(new UTranslate(getArrowDeltaX2(), textHeight - getArrowDeltaY2() + delta))
.draw(new ULine(-getArrowDeltaX2(), getArrowDeltaY2()));
}
if (getArrowConfiguration().getPart() != ArrowPart.TOP_PART) {
ug.apply(new UStroke(1.5))
.apply(new UTranslate(getArrowDeltaX2(), textHeight + getArrowDeltaY2() + delta))
.draw(new ULine(-getArrowDeltaX2(), -getArrowDeltaY2()));
}
} else {
final UPolygon polygon = getPolygon(textHeight, delta);
ug.draw(polygon);
}
getTextBlock().drawU(ug.apply(new UTranslate(getMarginX1(), 0)));
}
private UPolygon getPolygon(final int textHeight, final int delta) {
final UPolygon polygon = new UPolygon();
if (getArrowConfiguration().getPart() == ArrowPart.TOP_PART) {
polygon.addPoint(getArrowDeltaX(), textHeight - getArrowDeltaY() + delta);
polygon.addPoint(0, textHeight + delta);
polygon.addPoint(getArrowDeltaX(), textHeight + delta);
} else if (getArrowConfiguration().getPart() == ArrowPart.BOTTOM_PART) {
polygon.addPoint(getArrowDeltaX(), textHeight + delta);
polygon.addPoint(0, textHeight + delta);
polygon.addPoint(getArrowDeltaX(), textHeight + getArrowDeltaY() + delta);
} else {
polygon.addPoint(getArrowDeltaX(), textHeight - getArrowDeltaY() + delta);
polygon.addPoint(0, textHeight + delta);
polygon.addPoint(getArrowDeltaX(), textHeight + getArrowDeltaY() + delta);
}
return polygon;
}
@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 Point2D getStartPoint(StringBounder stringBounder, Dimension2D dimensionToUse) {
final int textHeight = (int) getTextHeight(stringBounder);
return new Point2D.Double(getPaddingX(), textHeight + getPaddingY());
}
public Point2D getEndPoint(StringBounder stringBounder, Dimension2D dimensionToUse) {
final int textHeight = (int) getTextHeight(stringBounder);
final int textAndArrowHeight = (int) (textHeight + getArrowOnlyHeight(stringBounder));
return new Point2D.Double(getPaddingX(), textAndArrowHeight + getPaddingY());
}
}
Ads help maintain this website.