File size: 11,434 Bytes
eb67da4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2023, 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.svek.image;
import java.awt.geom.Rectangle2D;
import java.util.EnumMap;
import java.util.Map;
import net.sourceforge.plantuml.ColorParam;
import net.sourceforge.plantuml.CornerParam;
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.LineConfigurable;
import net.sourceforge.plantuml.LineParam;
import net.sourceforge.plantuml.SkinParamUtils;
import net.sourceforge.plantuml.Url;
import net.sourceforge.plantuml.UseStyle;
import net.sourceforge.plantuml.awt.geom.Dimension2D;
import net.sourceforge.plantuml.creole.Stencil;
import net.sourceforge.plantuml.cucadiagram.EntityPortion;
import net.sourceforge.plantuml.cucadiagram.ILeaf;
import net.sourceforge.plantuml.cucadiagram.LeafType;
import net.sourceforge.plantuml.cucadiagram.PortionShower;
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizVersion;
import net.sourceforge.plantuml.graphic.InnerStrategy;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.graphic.color.ColorType;
import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.SName;
import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.style.StyleSignatureBasic;
import net.sourceforge.plantuml.svek.AbstractEntityImage;
import net.sourceforge.plantuml.svek.Margins;
import net.sourceforge.plantuml.svek.Ports;
import net.sourceforge.plantuml.svek.ShapeType;
import net.sourceforge.plantuml.svek.WithPorts;
import net.sourceforge.plantuml.ugraphic.Shadowable;
import net.sourceforge.plantuml.ugraphic.UComment;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UGraphicStencil;
import net.sourceforge.plantuml.ugraphic.UGroupType;
import net.sourceforge.plantuml.ugraphic.URectangle;
import net.sourceforge.plantuml.ugraphic.UStroke;
import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorNone;
public class EntityImageClass extends AbstractEntityImage implements Stencil, WithPorts {
final private TextBlock body;
final private Margins shield;
final private EntityImageClassHeader header;
final private Url url;
final private double roundCorner;
final private LeafType leafType;
final private LineConfigurable lineConfig;
public EntityImageClass(GraphvizVersion version, ILeaf entity, ISkinParam skinParam, PortionShower portionShower) {
super(entity, entity.getColors().mute(skinParam));
this.leafType = entity.getLeafType();
this.lineConfig = entity;
if (UseStyle.useBetaStyle())
this.roundCorner = getStyle().value(PName.RoundCorner).asDouble();
else
this.roundCorner = getSkinParam().getRoundCorner(CornerParam.DEFAULT, null);
this.shield = version != null && version.useShield() && entity.hasNearDecoration() ? Margins.uniform(16)
: Margins.NONE;
final boolean showMethods = portionShower.showPortion(EntityPortion.METHOD, entity);
final boolean showFields = portionShower.showPortion(EntityPortion.FIELD, entity);
this.body = entity.getBodier().getBody(FontParam.CLASS_ATTRIBUTE, getSkinParam(), showMethods, showFields,
entity.getStereotype(), getStyle(), null);
this.header = new EntityImageClassHeader(entity, getSkinParam(), portionShower);
this.url = entity.getUrl99();
}
public Dimension2D calculateDimension(StringBounder stringBounder) {
final Dimension2D dimHeader = header.calculateDimension(stringBounder);
final Dimension2D dimBody = body == null ? new Dimension2DDouble(0, 0) : body.calculateDimension(stringBounder);
double width = Math.max(dimBody.getWidth(), dimHeader.getWidth());
if (width < getSkinParam().minClassWidth())
width = getSkinParam().minClassWidth();
final double height = dimBody.getHeight() + dimHeader.getHeight();
return new Dimension2DDouble(width, height);
}
@Override
public Rectangle2D getInnerPosition(String member, StringBounder stringBounder, InnerStrategy strategy) {
final Rectangle2D result = body.getInnerPosition(member, stringBounder, strategy);
if (result == null)
return result;
final Dimension2D dimHeader = header.calculateDimension(stringBounder);
final UTranslate translate = UTranslate.dy(dimHeader.getHeight());
return translate.apply(result);
}
final public void drawU(UGraphic ug) {
ug.draw(new UComment("class " + getEntity().getCodeGetName()));
if (url != null)
ug.startUrl(url);
final Map<UGroupType, String> typeIDent = new EnumMap<>(UGroupType.class);
typeIDent.put(UGroupType.CLASS, "elem " + getEntity().getCode() + " selected");
typeIDent.put(UGroupType.ID, "elem_" + getEntity().getCode());
ug.startGroup(typeIDent);
drawInternal(ug);
ug.closeGroup();
if (url != null)
ug.closeUrl();
}
private Style getStyle() {
return StyleSignatureBasic.of(SName.root, SName.element, SName.classDiagram, SName.class_) //
.withTOBECHANGED(getEntity().getStereotype()) //
.with(getEntity().getStereostyles()) //
.getMergedStyle(getSkinParam().getCurrentStyleBuilder());
}
private Style getStyleHeader() {
return StyleSignatureBasic.of(SName.root, SName.element, SName.classDiagram, SName.class_, SName.header) //
.withTOBECHANGED(getEntity().getStereotype()) //
.with(getEntity().getStereostyles()) //
.getMergedStyle(getSkinParam().getCurrentStyleBuilder());
}
private void drawInternal(UGraphic ug) {
final StringBounder stringBounder = ug.getStringBounder();
final Dimension2D dimTotal = calculateDimension(stringBounder);
final Dimension2D dimHeader = header.calculateDimension(stringBounder);
final double widthTotal = dimTotal.getWidth();
final double heightTotal = dimTotal.getHeight();
final Shadowable rect = new URectangle(widthTotal, heightTotal).rounded(roundCorner)
.withCommentAndCodeLine(getEntity().getCodeGetName(), getEntity().getCodeLine());
double shadow = 0;
HColor classBorder = lineConfig.getColors().getColor(ColorType.LINE);
HColor headerBackcolor = getEntity().getColors().getColor(ColorType.HEADER);
HColor backcolor = getEntity().getColors().getColor(ColorType.BACK);
if (UseStyle.useBetaStyle()) {
shadow = getStyle().value(PName.Shadowing).asDouble();
if (classBorder == null)
classBorder = getStyle().value(PName.LineColor).asColor(getSkinParam().getThemeStyle(),
getSkinParam().getIHtmlColorSet());
if (headerBackcolor == null)
headerBackcolor = backcolor == null ? getStyleHeader().value(PName.BackGroundColor)
.asColor(getSkinParam().getThemeStyle(), getSkinParam().getIHtmlColorSet()) : backcolor;
if (backcolor == null)
backcolor = getStyle().value(PName.BackGroundColor).asColor(getSkinParam().getThemeStyle(),
getSkinParam().getIHtmlColorSet());
} else {
if (getSkinParam().shadowing(getEntity().getStereotype()))
shadow = 4;
if (classBorder == null)
classBorder = SkinParamUtils.getColor(getSkinParam(), getStereo(), ColorParam.classBorder);
if (backcolor == null)
if (leafType == LeafType.ENUM)
backcolor = SkinParamUtils.getColor(getSkinParam(), getStereo(), ColorParam.enumBackground,
ColorParam.classBackground);
else
backcolor = SkinParamUtils.getColor(getSkinParam(), getStereo(), ColorParam.classBackground);
if (headerBackcolor == null)
headerBackcolor = getSkinParam().getHtmlColor(ColorParam.classHeaderBackground, getStereo(), false);
}
rect.setDeltaShadow(shadow);
ug = ug.apply(classBorder);
ug = ug.apply(backcolor.bg());
final UStroke stroke = getStroke();
UGraphic ugHeader = ug;
if (roundCorner == 0 && headerBackcolor != null && backcolor.equals(headerBackcolor) == false) {
ug.apply(stroke).draw(rect);
final Shadowable rect2 = new URectangle(widthTotal, dimHeader.getHeight());
rect2.setDeltaShadow(0);
ugHeader = ugHeader.apply(headerBackcolor.bg());
ugHeader.apply(stroke).draw(rect2);
} else if (roundCorner != 0 && headerBackcolor != null && backcolor.equals(headerBackcolor) == false) {
ug.apply(stroke).draw(rect);
final Shadowable rect2 = new URectangle(widthTotal, dimHeader.getHeight()).rounded(roundCorner);
final URectangle rect3 = new URectangle(widthTotal, roundCorner / 2);
rect2.setDeltaShadow(0);
rect3.setDeltaShadow(0);
ugHeader = ugHeader.apply(headerBackcolor.bg()).apply(headerBackcolor);
ugHeader.apply(stroke).draw(rect2);
ugHeader.apply(stroke).apply(UTranslate.dy(dimHeader.getHeight() - rect3.getHeight())).draw(rect3);
rect.setDeltaShadow(0);
ug.apply(stroke).apply(new HColorNone().bg()).draw(rect);
} else {
ug.apply(stroke).draw(rect);
}
header.drawU(ugHeader, dimTotal.getWidth(), dimHeader.getHeight());
if (body != null) {
final UGraphic ug2 = UGraphicStencil.create(ug, this, stroke);
final UTranslate translate = UTranslate.dy(dimHeader.getHeight());
body.drawU(ug2.apply(translate));
}
}
@Override
public Ports getPorts(StringBounder stringBounder) {
final Dimension2D dimHeader = header.calculateDimension(stringBounder);
if (body instanceof WithPorts)
return ((WithPorts) body).getPorts(stringBounder).translateY(dimHeader.getHeight());
return new Ports();
}
private UStroke getStroke() {
if (UseStyle.useBetaStyle())
return getStyle().getStroke();
UStroke stroke = lineConfig.getColors().getSpecificLineStroke();
if (stroke == null)
stroke = getSkinParam().getThickness(LineParam.classBorder, getStereo());
if (stroke == null)
stroke = new UStroke(1.5);
return stroke;
}
public ShapeType getShapeType() {
if (((ILeaf) getEntity()).getPortShortNames().size() > 0) {
return ShapeType.RECTANGLE_HTML_FOR_PORTS;
}
return ShapeType.RECTANGLE;
}
@Override
public Margins getShield(StringBounder stringBounder) {
return shield;
}
public double getStartingX(StringBounder stringBounder, double y) {
return 0;
}
public double getEndingX(StringBounder stringBounder, double y) {
return calculateDimension(stringBounder).getWidth();
}
}
|