summaryrefslogtreecommitdiff
path: root/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDiamondInside.java
diff options
context:
space:
mode:
authorAndrew Shadura <andrew@shadura.me>2015-07-21 14:52:03 +0200
committerAndrew Shadura <andrew@shadura.me>2015-07-21 14:52:03 +0200
commit26b872bb194ec7622997914bba53309a94b64d20 (patch)
treea79b966bf55dd61702b900b8ba40be4d2b3403db /src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDiamondInside.java
Imported Upstream version 8024
Diffstat (limited to 'src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDiamondInside.java')
-rw-r--r--src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDiamondInside.java161
1 files changed, 161 insertions, 0 deletions
diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDiamondInside.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDiamondInside.java
new file mode 100644
index 0000000..7374653
--- /dev/null
+++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDiamondInside.java
@@ -0,0 +1,161 @@
+/* ========================================================================
+ * PlantUML : a free UML diagram generator
+ * ========================================================================
+ *
+ * (C) Copyright 2009-2014, Arnaud Roques
+ *
+ * Project Info: http://plantuml.sourceforge.net
+ *
+ * This file is part of PlantUML.
+ *
+ * Licensed under The MIT License (Massachusetts Institute of Technology License)
+ *
+ * See http://opensource.org/licenses/MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+ * IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ *
+ * Original Author: Arnaud Roques
+ */
+package net.sourceforge.plantuml.activitydiagram3.ftile.vertical;
+
+import java.awt.geom.Dimension2D;
+import java.util.Collections;
+import java.util.Set;
+
+import net.sourceforge.plantuml.Dimension2DDouble;
+import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractFtile;
+import net.sourceforge.plantuml.activitydiagram3.ftile.Diamond;
+import net.sourceforge.plantuml.activitydiagram3.ftile.FtileGeometry;
+import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane;
+import net.sourceforge.plantuml.graphic.HtmlColor;
+import net.sourceforge.plantuml.graphic.StringBounder;
+import net.sourceforge.plantuml.graphic.TextBlock;
+import net.sourceforge.plantuml.graphic.TextBlockUtils;
+import net.sourceforge.plantuml.ugraphic.UChangeBackColor;
+import net.sourceforge.plantuml.ugraphic.UChangeColor;
+import net.sourceforge.plantuml.ugraphic.UGraphic;
+import net.sourceforge.plantuml.ugraphic.UStroke;
+import net.sourceforge.plantuml.ugraphic.UTranslate;
+
+public class FtileDiamondInside extends AbstractFtile {
+
+ private final HtmlColor backColor;
+ private final HtmlColor borderColor;
+ private final Swimlane swimlane;
+ private final TextBlock label;
+ private final TextBlock west;
+ private final TextBlock east;
+ private final TextBlock north;
+ private final TextBlock south;
+
+ public FtileDiamondInside(boolean shadowing, HtmlColor backColor, HtmlColor borderColor, Swimlane swimlane,
+ TextBlock label) {
+ this(shadowing, backColor, borderColor, swimlane, label, TextBlockUtils.empty(0, 0),
+ TextBlockUtils.empty(0, 0), TextBlockUtils.empty(0, 0), TextBlockUtils.empty(0, 0));
+ }
+
+ public FtileDiamondInside withNorth(TextBlock north) {
+ return new FtileDiamondInside(shadowing(), backColor, borderColor, swimlane, label, north, south, west, east);
+ }
+
+ public FtileDiamondInside withWest(TextBlock west) {
+ return new FtileDiamondInside(shadowing(), backColor, borderColor, swimlane, label, north, south, west, east);
+ }
+
+ public FtileDiamondInside withEast(TextBlock east) {
+ return new FtileDiamondInside(shadowing(), backColor, borderColor, swimlane, label, north, south, west, east);
+ }
+
+ public FtileDiamondInside withSouth(TextBlock south) {
+ return new FtileDiamondInside(shadowing(), backColor, borderColor, swimlane, label, north, south, west, east);
+ }
+
+ private FtileDiamondInside(boolean shadowing, HtmlColor backColor, HtmlColor borderColor, Swimlane swimlane,
+ TextBlock label, TextBlock north, TextBlock south, TextBlock west, TextBlock east) {
+ super(shadowing);
+ this.backColor = backColor;
+ this.swimlane = swimlane;
+ this.borderColor = borderColor;
+ this.label = label;
+ this.west = west;
+ this.east = east;
+ this.north = north;
+ this.south = south;
+ }
+
+ public Set<Swimlane> getSwimlanes() {
+ if (swimlane == null) {
+ return Collections.emptySet();
+ }
+ return Collections.singleton(swimlane);
+ }
+
+ public Swimlane getSwimlaneIn() {
+ return swimlane;
+ }
+
+ public Swimlane getSwimlaneOut() {
+ return swimlane;
+ }
+
+ public void drawU(UGraphic ug) {
+ final StringBounder stringBounder = ug.getStringBounder();
+ final Dimension2D dimLabel = label.calculateDimension(stringBounder);
+ final Dimension2D dimTotal = calculateDimensionAlone(stringBounder);
+ ug = ug.apply(new UChangeColor(borderColor)).apply(new UStroke(1.5)).apply(new UChangeBackColor(backColor));
+ ug.draw(Diamond.asPolygon(shadowing(), dimTotal.getWidth(), dimTotal.getHeight()));
+
+ north.drawU(ug.apply(new UTranslate(4 + dimTotal.getWidth() / 2, dimTotal.getHeight())));
+ south.drawU(ug.apply(new UTranslate(4 + dimTotal.getWidth() / 2, dimTotal.getHeight())));
+
+ final double lx = (dimTotal.getWidth() - dimLabel.getWidth()) / 2;
+ final double ly = (dimTotal.getHeight() - dimLabel.getHeight()) / 2;
+ label.drawU(ug.apply(new UTranslate(lx, ly)));
+
+ final Dimension2D dimWeat = west.calculateDimension(stringBounder);
+ west.drawU(ug.apply(new UTranslate(-dimWeat.getWidth(), -dimWeat.getHeight() + dimTotal.getHeight() / 2)));
+
+ final Dimension2D dimEast = east.calculateDimension(stringBounder);
+ east.drawU(ug.apply(new UTranslate(dimTotal.getWidth(), -dimEast.getHeight() + dimTotal.getHeight() / 2)));
+
+ }
+
+ public FtileGeometry calculateDimension(StringBounder stringBounder) {
+ Dimension2D dim = calculateDimensionAlone(stringBounder);
+ final Dimension2D dimNorth = north.calculateDimension(stringBounder);
+ final double northHeight = dimNorth.getHeight();
+ final double northWidth = dimNorth.getWidth();
+ dim = Dimension2DDouble.delta(dim, 0, northHeight);
+ return new FtileGeometry(dim, dim.getWidth() / 2, 0, dim.getHeight() - northHeight);
+ }
+
+ private FtileGeometry calculateDimensionAlone(StringBounder stringBounder) {
+ final Dimension2D dimLabel = label.calculateDimension(stringBounder);
+ final Dimension2D dim;
+ if (dimLabel.getWidth() == 0 || dimLabel.getHeight() == 0) {
+ dim = new Dimension2DDouble(Diamond.diamondHalfSize * 2, Diamond.diamondHalfSize * 2);
+ } else {
+ dim = Dimension2DDouble.delta(
+ Dimension2DDouble.atLeast(dimLabel, Diamond.diamondHalfSize * 2, Diamond.diamondHalfSize * 2),
+ Diamond.diamondHalfSize * 2, 0);
+ }
+ return new FtileGeometry(dim, dim.getWidth() / 2, 0, dim.getHeight());
+ }
+
+}