1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-07 10:50:53 +00:00
plantuml/src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingElse.java

140 lines
5.1 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2019-01-16 18:34:41 +00:00
* (C) Copyright 2009-2020, 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;
import java.awt.geom.Dimension2D;
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;
2019-09-14 18:12:04 +00:00
import net.sourceforge.plantuml.SkinParamBackcolored;
2020-12-01 21:39:27 +00:00
import net.sourceforge.plantuml.UseStyle;
2015-05-03 15:36:36 +00:00
import net.sourceforge.plantuml.graphic.FontConfiguration;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
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;
import net.sourceforge.plantuml.ugraphic.color.HColorBackground;
2020-04-19 16:04:39 +00:00
import net.sourceforge.plantuml.ugraphic.color.HColorNone;
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;
2011-04-19 16:50:40 +00:00
2021-05-06 21:23:05 +00:00
public ComponentRoseGroupingElse(Style style, HColor groupBorder, FontConfiguration smallFont, CharSequence comment,
2021-08-30 17:13:54 +00:00
ISkinSimple spriteContainer, HColor backgroundColor, double roundCorner) {
2019-07-14 20:09:26 +00:00
super(style, LineBreakStrategy.NONE, comment == null ? null : "[" + comment + "]", smallFont,
2017-03-15 19:13:31 +00:00
HorizontalAlignment.LEFT, 5, 5, 1, spriteContainer, null, null);
2021-08-30 17:13:54 +00:00
2020-12-01 21:39:27 +00:00
if (UseStyle.useBetaStyle()) {
2021-08-30 17:13:54 +00:00
this.roundCorner = style.value(PName.RoundCorner).asInt();
2019-09-14 18:12:04 +00:00
if (spriteContainer instanceof SkinParamBackcolored) {
style = style.eventuallyOverride(PName.BackGroundColor,
((SkinParamBackcolored) spriteContainer).getBackgroundColor());
2019-09-14 18:12:04 +00:00
}
2021-05-06 21:23:05 +00:00
this.groupBorder = style.value(PName.LineColor).asColor(spriteContainer.getThemeStyle(),
getIHtmlColorSet());
this.backgroundColor = style.value(PName.BackGroundColor).asColor(spriteContainer.getThemeStyle(),
getIHtmlColorSet());
2019-07-14 20:09:26 +00:00
} else {
2021-08-30 17:13:54 +00:00
this.roundCorner = roundCorner;
2019-07-14 20:09:26 +00:00
this.groupBorder = groupBorder;
this.backgroundColor = backgroundColor;
}
2010-11-15 20:35:36 +00:00
}
@Override
2013-12-10 19:36:50 +00:00
protected void drawBackgroundInternalU(UGraphic ug, Area area) {
2020-03-18 10:50:02 +00:00
if (backgroundColor instanceof HColorBackground) {
2017-03-15 19:13:31 +00:00
return;
}
2013-12-10 19:36:50 +00:00
final Dimension2D dimensionToUse = area.getDimensionToUse();
2021-08-30 17:13:54 +00:00
ug = ug.apply(new HColorNone()).apply(backgroundColor.bg());
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) {
final Dimension2D 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());
getTextBlock().drawU(ug.apply(new UTranslate(getMarginX1(), getMarginY())));
2010-11-15 20:35:36 +00:00
}
@Override
public double getPreferredHeight(StringBounder stringBounder) {
2013-12-10 19:36:50 +00:00
return getTextHeight(stringBounder);
2010-11-15 20:35:36 +00:00
}
@Override
public double getPreferredWidth(StringBounder stringBounder) {
return getTextWidth(stringBounder);
}
}