plantuml/src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingElse.java

128 lines
4.5 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, Arnaud Roques
2010-11-15 20:35:36 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2010-11-15 20:35:36 +00:00
*
2017-03-15 19:13:31 +00:00
* 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
*
2010-11-15 20:35:36 +00:00
* 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
2013-12-10 19:36:50 +00:00
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
2010-11-15 20:35:36 +00:00
* 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.rose;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.ISkinSimple;
2017-02-26 16:26:11 +00:00
import net.sourceforge.plantuml.LineBreakStrategy;
2022-09-12 20:08:34 +00:00
import net.sourceforge.plantuml.awt.geom.XDimension2D;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.skin.AbstractTextualComponent;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.skin.Area;
2016-06-19 14:16:41 +00:00
import net.sourceforge.plantuml.skin.ArrowConfiguration;
2019-07-14 20:09:26 +00:00
import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.Style;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.ULine;
2021-08-30 17:13:54 +00:00
import net.sourceforge.plantuml.ugraphic.UPath;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.ugraphic.URectangle;
2021-08-30 17:13:54 +00:00
import net.sourceforge.plantuml.ugraphic.UShape;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.ugraphic.UStroke;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.ugraphic.UTranslate;
2020-03-18 10:50:02 +00:00
import net.sourceforge.plantuml.ugraphic.color.HColor;
2022-08-19 16:34:21 +00:00
import net.sourceforge.plantuml.ugraphic.color.HColors;
2010-11-15 20:35:36 +00:00
public class ComponentRoseGroupingElse extends AbstractTextualComponent {
2020-03-18 10:50:02 +00:00
private final HColor groupBorder;
private final HColor backgroundColor;
2021-08-30 17:13:54 +00:00
private final double roundCorner;
2022-10-05 20:32:57 +00:00
private final boolean teoz;
2011-04-19 16:50:40 +00:00
2022-10-05 20:32:57 +00:00
public ComponentRoseGroupingElse(boolean teoz, Style style, CharSequence comment, ISkinSimple spriteContainer) {
2022-05-21 09:41:00 +00:00
super(style, LineBreakStrategy.NONE, 5, 5, 1, spriteContainer, comment == null ? null : "[" + comment + "]");
2021-08-30 17:13:54 +00:00
2022-10-05 20:32:57 +00:00
this.teoz = teoz;
2022-05-21 09:41:00 +00:00
this.roundCorner = style.value(PName.RoundCorner).asInt();
2022-09-18 17:08:06 +00:00
this.groupBorder = style.value(PName.LineColor).asColor(getIHtmlColorSet());
this.backgroundColor = style.value(PName.BackGroundColor).asColor(getIHtmlColorSet());
2010-11-15 20:35:36 +00:00
}
@Override
2013-12-10 19:36:50 +00:00
protected void drawBackgroundInternalU(UGraphic ug, Area area) {
2022-09-15 17:24:26 +00:00
if (backgroundColor.isTransparent())
2022-02-01 20:21:45 +00:00
return;
2022-09-12 20:08:34 +00:00
final XDimension2D dimensionToUse = area.getDimensionToUse();
2022-08-19 16:34:21 +00:00
ug = ug.apply(HColors.none()).apply(backgroundColor.bg());
2021-08-30 17:13:54 +00:00
final double width = dimensionToUse.getWidth();
final double height = dimensionToUse.getHeight();
final UShape rect;
if (roundCorner == 0) {
rect = new URectangle(width, height);
} else {
final UPath path = new UPath();
path.moveTo(0, 0);
path.lineTo(width, 0);
path.lineTo(width, height - roundCorner / 2);
path.arcTo(roundCorner / 2, roundCorner / 2, 0, 0, 1, width - roundCorner / 2, height);
path.lineTo(roundCorner / 2, height);
path.arcTo(roundCorner / 2, roundCorner / 2, 0, 0, 1, 0, height - roundCorner / 2);
path.lineTo(0, 0);
rect = path;
}
ug.draw(rect);
2013-12-10 19:36:50 +00:00
}
@Override
protected void drawInternalU(UGraphic ug, Area area) {
2022-09-12 20:08:34 +00:00
final XDimension2D dimensionToUse = area.getDimensionToUse();
2020-04-19 16:04:39 +00:00
ug = ArrowConfiguration.stroke(ug, 2, 2, 1).apply(groupBorder);
2020-03-18 10:50:02 +00:00
ug.apply(UTranslate.dy(1)).draw(ULine.hline(dimensionToUse.getWidth()));
2013-12-10 19:36:50 +00:00
ug = ug.apply(new UStroke());
2022-10-05 20:32:57 +00:00
if (teoz)
getTextBlock().drawU(ug.apply(new UTranslate(getMarginX1(), getMarginY() + 2)));
else
getTextBlock().drawU(ug.apply(new UTranslate(getMarginX1(), getMarginY())));
2010-11-15 20:35:36 +00:00
}
@Override
public double getPreferredHeight(StringBounder stringBounder) {
2022-10-05 20:32:57 +00:00
if (teoz)
return getTextHeight(stringBounder) + 16;
else
return getTextHeight(stringBounder);
2010-11-15 20:35:36 +00:00
}
@Override
public double getPreferredWidth(StringBounder stringBounder) {
return getTextWidth(stringBounder);
}
}