plantuml/src/net/sourceforge/plantuml/svek/RoundedContainer.java

103 lines
3.5 KiB
Java
Raw Normal View History

2011-08-08 17:48:29 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, Arnaud Roques
2011-08-08 17:48:29 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2011-08-08 17:48:29 +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
*
2011-08-08 17:48:29 +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
2011-08-08 17:48:29 +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.svek;
2022-02-17 18:27:32 +00:00
import net.sourceforge.plantuml.awt.geom.Dimension2D;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.ULine;
2022-05-04 17:52:00 +00:00
import net.sourceforge.plantuml.ugraphic.UPath;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.ugraphic.URectangle;
2022-05-04 17:52:00 +00:00
import net.sourceforge.plantuml.ugraphic.UShape;
2011-08-08 17:48:29 +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-05-04 17:52:00 +00:00
import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
2011-08-08 17:48:29 +00:00
public final class RoundedContainer {
private final Dimension2D dim;
private final double titleHeight;
2013-12-10 19:36:50 +00:00
private final double attributeHeight;
2020-03-18 10:50:02 +00:00
private final HColor borderColor;
private final HColor backColor;
private final HColor imgBackcolor;
2015-04-07 18:18:37 +00:00
private final UStroke stroke;
2021-10-17 09:02:33 +00:00
private final double rounded;
private final double shadowing;
2011-08-08 17:48:29 +00:00
2020-03-18 10:50:02 +00:00
public RoundedContainer(Dimension2D dim, double titleHeight, double attributeHeight, HColor borderColor,
2021-10-17 09:02:33 +00:00
HColor backColor, HColor imgBackcolor, UStroke stroke, double rounded, double shadowing) {
2022-05-04 17:52:00 +00:00
if (dim.getWidth() == 0)
2018-10-21 19:44:14 +00:00
throw new IllegalArgumentException();
2022-05-04 17:52:00 +00:00
2021-10-17 09:02:33 +00:00
this.rounded = rounded;
2011-08-08 17:48:29 +00:00
this.dim = dim;
this.imgBackcolor = imgBackcolor;
this.titleHeight = titleHeight;
this.borderColor = borderColor;
this.backColor = backColor;
2013-12-10 19:36:50 +00:00
this.attributeHeight = attributeHeight;
2015-04-07 18:18:37 +00:00
this.stroke = stroke;
2021-10-17 09:02:33 +00:00
this.shadowing = shadowing;
2011-08-08 17:48:29 +00:00
}
2021-10-17 09:02:33 +00:00
public void drawU(UGraphic ug) {
2022-05-04 17:52:00 +00:00
ug = ug.apply(backColor.bg()).apply(borderColor).apply(stroke);
2021-10-17 09:02:33 +00:00
final URectangle rect = new URectangle(dim.getWidth(), dim.getHeight()).rounded(rounded);
2011-08-08 17:48:29 +00:00
2022-05-04 17:52:00 +00:00
if (shadowing > 0) {
rect.setDeltaShadow(shadowing);
ug.apply(HColorUtils.transparent().bg()).draw(rect);
rect.setDeltaShadow(0);
}
final double headerHeight = titleHeight + attributeHeight;
2011-08-08 17:48:29 +00:00
2022-05-04 17:52:00 +00:00
new RoundedNorth(dim.getWidth(), headerHeight, backColor, rounded).drawU(ug);
new RoundedSouth(dim.getWidth(), dim.getHeight() - headerHeight, imgBackcolor, rounded)
.drawU(ug.apply(UTranslate.dy(headerHeight)));
2015-04-07 18:18:37 +00:00
2022-05-04 17:52:00 +00:00
ug.apply(HColorUtils.transparent().bg()).draw(rect);
2011-08-08 17:48:29 +00:00
2022-05-04 17:52:00 +00:00
if (headerHeight > 0)
ug.apply(UTranslate.dy(headerHeight)).draw(ULine.hline(dim.getWidth()));
2013-12-10 19:36:50 +00:00
2022-05-04 17:52:00 +00:00
if (attributeHeight > 0)
ug.apply(UTranslate.dy(titleHeight)).draw(ULine.hline(dim.getWidth()));
2011-08-08 17:48:29 +00:00
2013-12-10 19:36:50 +00:00
}
2011-08-08 17:48:29 +00:00
}