plantuml/src/net/sourceforge/plantuml/SkinParam.java

1235 lines
35 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
2022-08-17 17:34:24 +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:
2022-08-17 17:34:24 +00:00
*
2017-03-15 19:13:31 +00:00
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
2022-08-17 17:34:24 +00:00
*
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;
import java.awt.Font;
2019-07-14 20:09:26 +00:00
import java.io.IOException;
2019-09-22 17:20:16 +00:00
import java.io.InputStream;
2017-10-07 09:46:53 +00:00
import java.util.ArrayList;
2022-11-04 17:36:03 +00:00
import java.util.Arrays;
2010-11-15 20:35:36 +00:00
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
2021-11-16 17:47:07 +00:00
import java.util.LinkedHashMap;
2017-10-07 09:46:53 +00:00
import java.util.List;
2010-11-15 20:35:36 +00:00
import java.util.Map;
2020-12-06 21:43:09 +00:00
import java.util.Map.Entry;
2021-05-09 21:14:40 +00:00
import java.util.Objects;
2010-11-15 20:35:36 +00:00
import java.util.Set;
import java.util.TreeSet;
2022-09-14 18:12:03 +00:00
import java.util.regex.Pattern;
2010-11-15 20:35:36 +00:00
2022-11-30 17:41:17 +00:00
import net.sourceforge.plantuml.activitydiagram3.ftile.Arrows;
import net.sourceforge.plantuml.activitydiagram3.ftile.ArrowsRegular;
import net.sourceforge.plantuml.activitydiagram3.ftile.ArrowsTriangle;
2016-05-31 19:41:55 +00:00
import net.sourceforge.plantuml.command.regex.Matcher2;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.command.regex.MyPattern;
2016-05-31 19:41:55 +00:00
import net.sourceforge.plantuml.command.regex.Pattern2;
2022-11-04 17:36:03 +00:00
import net.sourceforge.plantuml.creole.CreoleMode;
2020-05-17 21:15:50 +00:00
import net.sourceforge.plantuml.creole.Parser;
2022-11-04 17:36:03 +00:00
import net.sourceforge.plantuml.creole.SheetBuilder;
import net.sourceforge.plantuml.creole.legacy.CreoleParser;
2017-11-20 16:10:36 +00:00
import net.sourceforge.plantuml.cucadiagram.LinkStyle;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.cucadiagram.Rankdir;
import net.sourceforge.plantuml.cucadiagram.Stereotype;
2011-03-26 12:37:27 +00:00
import net.sourceforge.plantuml.cucadiagram.dot.DotSplines;
2022-11-04 17:36:03 +00:00
import net.sourceforge.plantuml.graphic.FontConfiguration;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
2015-09-28 20:42:17 +00:00
import net.sourceforge.plantuml.graphic.color.Colors;
2022-08-17 17:34:24 +00:00
import net.sourceforge.plantuml.log.Logme;
2019-12-10 21:45:49 +00:00
import net.sourceforge.plantuml.skin.ActorStyle;
2016-11-04 21:39:29 +00:00
import net.sourceforge.plantuml.skin.ArrowDirection;
2019-07-14 20:09:26 +00:00
import net.sourceforge.plantuml.skin.Padder;
2019-08-26 17:07:21 +00:00
import net.sourceforge.plantuml.sprite.Sprite;
import net.sourceforge.plantuml.sprite.SpriteImage;
2019-07-14 20:09:26 +00:00
import net.sourceforge.plantuml.style.FromSkinparamToStyle;
import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.style.StyleBuilder;
import net.sourceforge.plantuml.style.StyleLoader;
2022-12-17 11:01:10 +00:00
import net.sourceforge.plantuml.style.parser.StyleParser;
2023-01-09 19:13:37 +00:00
import net.sourceforge.plantuml.style.parser.StyleParsingException;
2019-06-26 19:24:49 +00:00
import net.sourceforge.plantuml.svek.ConditionEndStyle;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.svek.ConditionStyle;
import net.sourceforge.plantuml.svek.PackageStyle;
2021-01-10 20:52:19 +00:00
import net.sourceforge.plantuml.svg.LengthAdjust;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.ugraphic.UFont;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.ugraphic.UStroke;
2020-03-18 10:50:02 +00:00
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorSet;
2022-08-19 16:34:21 +00:00
import net.sourceforge.plantuml.ugraphic.color.HColors;
2021-02-02 10:12:15 +00:00
import net.sourceforge.plantuml.ugraphic.color.NoSuchColorException;
2022-12-17 11:01:10 +00:00
import net.sourceforge.plantuml.utils.BlocLines;
2010-11-15 20:35:36 +00:00
public class SkinParam implements ISkinParam {
// TODO not clear whether SkinParam or ImageBuilder is responsible for defaults
public static final String DEFAULT_PRESERVE_ASPECT_RATIO = "none";
2019-08-26 17:07:21 +00:00
// private String skin = "debug.skin";
private String skin = "plantuml.skin";
2020-12-01 21:39:27 +00:00
private StyleBuilder styleBuilder;
2022-09-18 17:08:06 +00:00
private SkinParam(UmlDiagramType type) {
2019-08-26 17:07:21 +00:00
this.type = type;
}
2022-10-18 20:57:44 +00:00
@Override
2019-08-26 17:07:21 +00:00
public StyleBuilder getCurrentStyleBuilder() {
2022-10-18 20:57:44 +00:00
if (styleBuilder == null)
2019-08-26 17:07:21 +00:00
try {
this.styleBuilder = getCurrentStyleBuilderInternal();
2023-01-09 19:13:37 +00:00
} catch (StyleParsingException e) {
Logme.error(e);
2019-08-26 17:07:21 +00:00
} catch (IOException e) {
2022-08-17 17:34:24 +00:00
Logme.error(e);
2019-08-26 17:07:21 +00:00
}
2022-10-18 20:57:44 +00:00
2019-08-26 17:07:21 +00:00
return styleBuilder;
}
2022-10-18 20:57:44 +00:00
@Override
2019-08-26 17:07:21 +00:00
public void muteStyle(Style modifiedStyle) {
2022-04-10 19:24:55 +00:00
styleBuilder = getCurrentStyleBuilder().muteStyle(modifiedStyle);
2019-08-26 17:07:21 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2019-08-26 17:07:21 +00:00
public String getDefaultSkin() {
return skin;
}
2022-10-18 20:57:44 +00:00
@Override
2019-08-26 17:07:21 +00:00
public void setDefaultSkin(String newSkin) {
this.skin = newSkin;
}
2023-01-09 19:13:37 +00:00
public StyleBuilder getCurrentStyleBuilderInternal() throws IOException, StyleParsingException {
2019-08-26 17:07:21 +00:00
final StyleLoader tmp = new StyleLoader(this);
StyleBuilder result = tmp.loadSkin(this.getDefaultSkin());
2022-02-10 18:16:18 +00:00
if (result == null)
2019-08-26 17:07:21 +00:00
result = tmp.loadSkin("plantuml.skin");
2022-02-10 18:16:18 +00:00
2019-08-26 17:07:21 +00:00
return result;
2019-07-14 20:09:26 +00:00
}
public static int zeroMargin(int defaultValue) {
return defaultValue;
}
2016-04-04 19:05:10 +00:00
private static final String stereoPatternString = "\\<\\<(.*?)\\>\\>";
2016-05-31 19:41:55 +00:00
private static final Pattern2 stereoPattern = MyPattern.cmpile(stereoPatternString);
2016-04-04 19:05:10 +00:00
2010-11-15 20:35:36 +00:00
private final Map<String, String> params = new HashMap<String, String>();
2021-11-16 17:47:07 +00:00
private final Map<String, String> paramsPendingForStyleMigration = new LinkedHashMap<String, String>();
2020-12-06 21:43:09 +00:00
private final Map<String, String> svgCharSizes = new HashMap<String, String>();
2015-04-07 18:18:37 +00:00
private Rankdir rankdir = Rankdir.TOP_TO_BOTTOM;
2017-02-15 21:34:36 +00:00
private final UmlDiagramType type;
2018-12-22 11:11:40 +00:00
private boolean useVizJs;
2010-11-15 20:35:36 +00:00
2022-10-18 20:57:44 +00:00
@Override
2022-09-20 20:35:41 +00:00
public void copyAllFrom(Map<String, String> other) {
this.params.putAll(other);
2019-03-01 22:16:29 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2019-03-01 22:16:29 +00:00
public Map<String, String> values() {
return Collections.unmodifiableMap(params);
}
2010-11-15 20:35:36 +00:00
public void setParam(String key, String value) {
2017-10-07 09:46:53 +00:00
for (String key2 : cleanForKey(key)) {
params.put(key2, StringUtils.trin(value));
2022-04-10 19:24:55 +00:00
applyPendingStyleMigration();
final FromSkinparamToStyle convertor = new FromSkinparamToStyle(key2);
convertor.convertNow(value, getCurrentStyleBuilder());
for (Style style : convertor.getStyles())
muteStyle(style);
2017-10-07 09:46:53 +00:00
}
2019-09-22 17:20:16 +00:00
if ("style".equalsIgnoreCase(key) && "strictuml".equalsIgnoreCase(value)) {
2022-04-10 19:24:55 +00:00
final InputStream internalIs = StyleLoader.class.getResourceAsStream("/skin/strictuml.skin");
final StyleBuilder styleBuilder = this.getCurrentStyleBuilder();
try {
final BlocLines lines = BlocLines.load(internalIs, null);
2022-12-17 11:01:10 +00:00
for (Style modifiedStyle : StyleParser.parse(lines, styleBuilder))
2022-04-10 19:24:55 +00:00
this.muteStyle(modifiedStyle);
2022-02-10 18:16:18 +00:00
2023-01-09 19:13:37 +00:00
} catch (StyleParsingException e) {
Logme.error(e);
2022-04-10 19:24:55 +00:00
} catch (IOException e) {
2022-08-17 17:34:24 +00:00
Logme.error(e);
2019-09-22 17:20:16 +00:00
}
}
2011-01-05 18:23:06 +00:00
}
public void applyPendingStyleMigration() {
2021-11-16 17:47:07 +00:00
for (Entry<String, String> ent : paramsPendingForStyleMigration.entrySet()) {
2022-02-15 18:29:18 +00:00
final FromSkinparamToStyle convertor = new FromSkinparamToStyle(ent.getKey());
convertor.convertNow(ent.getValue(), getCurrentStyleBuilder());
2021-11-16 17:47:07 +00:00
for (Style style : convertor.getStyles())
muteStyle(style);
}
paramsPendingForStyleMigration.clear();
}
2022-09-18 17:08:06 +00:00
public static SkinParam create(UmlDiagramType type) {
return new SkinParam(type);
2017-02-15 21:34:36 +00:00
}
2022-09-18 17:08:06 +00:00
public static SkinParam noShadowing(UmlDiagramType type) {
final SkinParam result = new SkinParam(type);
2015-04-07 18:18:37 +00:00
result.setParam("shadowing", "false");
return result;
2011-09-07 20:41:58 +00:00
}
2017-11-20 16:10:36 +00:00
private final Map<String, List<String>> cacheCleanForKey = new HashMap<String, List<String>>();
List<String> cleanForKey(String key) {
List<String> result = cacheCleanForKey.get(key);
if (result == null) {
result = cleanForKeySlow(key);
cacheCleanForKey.put(key, result);
}
return result;
}
2022-09-14 18:12:03 +00:00
private static final Pattern patternCleanUnderscoreDot = Pattern.compile("_|\\.");
private static final Pattern patternCleanSequence = Pattern.compile("sequence(participant|actor)");
2022-09-18 17:08:06 +00:00
private static final Pattern patternCleanArrow = Pattern
.compile("(activity|class|component|object|sequence|state|usecase)arrow");
2022-09-14 18:12:03 +00:00
private static final Pattern patternCleanAlign = Pattern.compile("align$");
2017-11-20 16:10:36 +00:00
List<String> cleanForKeySlow(String key) {
2015-05-31 18:56:03 +00:00
key = StringUtils.trin(StringUtils.goLowerCase(key));
2022-09-14 18:12:03 +00:00
key = patternCleanUnderscoreDot.matcher(key).replaceAll("");
key = patternCleanSequence.matcher(key).replaceAll("$1");
key = patternCleanArrow.matcher(key).replaceAll("arrow");
key = patternCleanAlign.matcher(key).replaceAll("alignment");
2017-10-07 09:46:53 +00:00
final Matcher2 mm = stereoPattern.matcher(key);
2021-05-14 08:42:57 +00:00
final List<String> result = new ArrayList<>();
2017-10-07 09:46:53 +00:00
while (mm.find()) {
final String s = mm.group(1);
result.add(key.replaceAll(stereoPatternString, "") + "<<" + s + ">>");
}
2022-02-10 18:16:18 +00:00
if (result.size() == 0)
2017-10-07 09:46:53 +00:00
result.add(key);
2022-02-10 18:16:18 +00:00
2017-11-20 16:10:36 +00:00
return Collections.unmodifiableList(result);
2010-11-15 20:35:36 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2020-03-18 10:50:02 +00:00
public HColor getHyperlinkColor() {
final HColor result = getHtmlColor(ColorParam.hyperlink, null, false);
2022-02-10 18:16:18 +00:00
if (result == null)
2022-08-19 16:34:21 +00:00
return HColors.BLUE;
2022-02-10 18:16:18 +00:00
2015-04-07 18:18:37 +00:00
return result;
}
2022-10-18 20:57:44 +00:00
@Override
public HColor getBackgroundColor() {
2020-03-18 10:50:02 +00:00
final HColor result = getHtmlColor(ColorParam.background, null, false);
2022-08-19 16:34:21 +00:00
return result != null ? result : HColors.WHITE;
2010-11-15 20:35:36 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2010-11-15 20:35:36 +00:00
public String getValue(String key) {
2022-04-10 19:24:55 +00:00
applyPendingStyleMigration();
2017-10-07 09:46:53 +00:00
for (String key2 : cleanForKey(key)) {
final String result = params.get(key2);
2022-02-10 18:16:18 +00:00
if (result != null)
2017-10-07 09:46:53 +00:00
return result;
2022-02-10 18:16:18 +00:00
2017-10-07 09:46:53 +00:00
}
return null;
2010-11-15 20:35:36 +00:00
}
public String getValue(String key, String defaultValue) {
final String result = getValue(key);
return result == null ? defaultValue : result;
}
private boolean valueIs(String key, String expected) {
return expected.equalsIgnoreCase(getValue(key));
}
private boolean isTrue(String key) {
return valueIs(key, "true");
}
2010-11-15 20:35:36 +00:00
static String humanName(String key) {
final StringBuilder sb = new StringBuilder();
boolean upper = true;
for (int i = 0; i < key.length(); i++) {
final char c = key.charAt(i);
if (c == '_') {
upper = true;
} else {
2015-04-07 18:18:37 +00:00
sb.append(upper ? StringUtils.goUpperCase(c) : StringUtils.goLowerCase(c));
2010-11-15 20:35:36 +00:00
upper = false;
}
}
return sb.toString();
}
2022-10-18 20:57:44 +00:00
@Override
2020-03-18 10:50:02 +00:00
public HColor getHtmlColor(ColorParam param, Stereotype stereotype, boolean clickable) {
2011-01-05 18:23:06 +00:00
if (stereotype != null) {
checkStereotype(stereotype);
2016-03-06 16:47:34 +00:00
for (String s : stereotype.getMultipleLabels()) {
final String value2 = getValue(param.name() + "color" + "<<" + s + ">>");
2022-09-18 17:08:06 +00:00
if (value2 != null && getIHtmlColorSet().getColorOrWhite(value2) != null)
return getIHtmlColorSet().getColorOrWhite(value2);
2022-02-10 18:16:18 +00:00
2011-01-05 18:23:06 +00:00
}
}
2013-12-10 19:36:50 +00:00
final String value = getValue(getParamName(param, clickable));
2022-08-23 16:39:27 +00:00
if (value == null)
2010-11-15 20:35:36 +00:00
return null;
2022-08-23 16:39:27 +00:00
2020-04-26 18:31:41 +00:00
if ((param == ColorParam.background || param == ColorParam.arrowHead)
2022-08-23 16:39:27 +00:00
&& (value.equalsIgnoreCase("transparent") || value.equalsIgnoreCase("none")))
2022-08-19 16:34:21 +00:00
return HColors.transparent();
2022-08-23 16:39:27 +00:00
if (param == ColorParam.background)
2022-09-18 17:08:06 +00:00
return getIHtmlColorSet().getColorOrWhite(value);
2022-08-23 16:39:27 +00:00
2020-03-18 10:50:02 +00:00
assert param != ColorParam.background;
2022-08-23 16:39:27 +00:00
2022-09-18 17:08:06 +00:00
return getIHtmlColorSet().getColorOrWhite(value);
2013-12-10 19:36:50 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2018-03-09 21:37:34 +00:00
public char getCircledCharacter(Stereotype stereotype) {
2021-06-27 16:50:40 +00:00
final String value2 = getValue(
"spotchar" + Objects.requireNonNull(stereotype).getLabel(Guillemet.DOUBLE_COMPARATOR));
2022-02-10 18:16:18 +00:00
if (value2 != null && value2.length() > 0)
2018-03-09 21:37:34 +00:00
return value2.charAt(0);
2022-02-10 18:16:18 +00:00
2018-03-09 21:37:34 +00:00
return 0;
}
2022-10-18 20:57:44 +00:00
@Override
2021-02-02 10:12:15 +00:00
public Colors getColors(ColorParam param, Stereotype stereotype) throws NoSuchColorException {
2015-09-28 20:42:17 +00:00
if (stereotype != null) {
checkStereotype(stereotype);
2019-03-29 22:14:07 +00:00
final String value2 = getValue(param.name() + "color" + stereotype.getLabel(Guillemet.DOUBLE_COMPARATOR));
2022-02-10 18:16:18 +00:00
if (value2 != null)
2022-09-18 17:08:06 +00:00
return new Colors(value2, getIHtmlColorSet(), param.getColorType());
2022-02-10 18:16:18 +00:00
2015-09-28 20:42:17 +00:00
}
final String value = getValue(getParamName(param, false));
2022-02-10 18:16:18 +00:00
if (value == null)
2015-09-28 20:42:17 +00:00
return Colors.empty();
2022-02-10 18:16:18 +00:00
2022-09-18 17:08:06 +00:00
return new Colors(value, getIHtmlColorSet(), param.getColorType());
2015-09-28 20:42:17 +00:00
}
2013-12-10 19:36:50 +00:00
private String getParamName(ColorParam param, boolean clickable) {
String n = param.name();
2022-02-10 18:16:18 +00:00
if (clickable && n.endsWith("Background"))
2013-12-10 19:36:50 +00:00
n = n.replaceAll("Background", "ClickableBackground");
2022-02-10 18:16:18 +00:00
else if (clickable && n.endsWith("Border"))
2013-12-10 19:36:50 +00:00
n = n.replaceAll("Border", "ClickableBorder");
2022-02-10 18:16:18 +00:00
2013-12-10 19:36:50 +00:00
return n + "color";
2010-11-15 20:35:36 +00:00
}
2015-04-07 18:18:37 +00:00
private void checkStereotype(Stereotype stereotype) {
2020-03-18 10:50:02 +00:00
// if (stereotype.startsWith("<<") == false || stereotype.endsWith(">>") ==
// false) {
2015-04-07 18:18:37 +00:00
// throw new IllegalArgumentException();
// }
2011-01-05 18:23:06 +00:00
}
2016-01-09 12:15:40 +00:00
private int getFontSize(Stereotype stereotype, FontParam... param) {
2011-01-05 18:23:06 +00:00
if (stereotype != null) {
checkStereotype(stereotype);
2019-03-29 22:14:07 +00:00
final String value2 = getFirstValueNonNullWithSuffix(
"fontsize" + stereotype.getLabel(Guillemet.DOUBLE_COMPARATOR), param);
2022-02-10 18:16:18 +00:00
if (value2 != null && value2.matches("\\d+"))
2011-01-05 18:23:06 +00:00
return Integer.parseInt(value2);
2022-02-10 18:16:18 +00:00
2011-01-05 18:23:06 +00:00
}
2016-01-09 12:15:40 +00:00
String value = getFirstValueNonNullWithSuffix("fontsize", param);
2022-02-10 18:16:18 +00:00
if (value == null || value.matches("\\d+") == false)
2010-11-15 20:35:36 +00:00
value = getValue("defaultfontsize");
2022-02-10 18:16:18 +00:00
if (value == null || value.matches("\\d+") == false)
2016-01-09 12:15:40 +00:00
return param[0].getDefaultSize(this);
2022-02-10 18:16:18 +00:00
2010-11-15 20:35:36 +00:00
return Integer.parseInt(value);
}
2016-01-09 12:15:40 +00:00
private String getFontFamily(Stereotype stereotype, FontParam... param) {
2011-01-05 18:23:06 +00:00
if (stereotype != null) {
checkStereotype(stereotype);
2019-03-29 22:14:07 +00:00
final String value2 = getFirstValueNonNullWithSuffix(
"fontname" + stereotype.getLabel(Guillemet.DOUBLE_COMPARATOR), param);
2022-02-10 18:16:18 +00:00
if (value2 != null)
2011-01-05 18:23:06 +00:00
return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(value2);
2022-02-10 18:16:18 +00:00
2011-01-05 18:23:06 +00:00
}
2010-11-15 20:35:36 +00:00
// Times, Helvetica, Courier or Symbol
2016-01-09 12:15:40 +00:00
String value = getFirstValueNonNullWithSuffix("fontname", param);
2022-02-10 18:16:18 +00:00
if (value != null)
2011-01-05 18:23:06 +00:00
return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(value);
2022-02-10 18:16:18 +00:00
2016-01-09 12:15:40 +00:00
if (param[0] != FontParam.CIRCLED_CHARACTER) {
2010-11-15 20:35:36 +00:00
value = getValue("defaultfontname");
2022-02-10 18:16:18 +00:00
if (value != null)
2011-01-05 18:23:06 +00:00
return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(value);
2022-02-10 18:16:18 +00:00
2010-11-15 20:35:36 +00:00
}
2016-01-09 12:15:40 +00:00
return param[0].getDefaultFamily();
2010-11-15 20:35:36 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2020-03-18 10:50:02 +00:00
public HColor getFontHtmlColor(Stereotype stereotype, FontParam... param) {
2011-01-05 18:23:06 +00:00
String value = null;
if (stereotype != null) {
checkStereotype(stereotype);
2019-03-29 22:14:07 +00:00
value = getFirstValueNonNullWithSuffix("fontcolor" + stereotype.getLabel(Guillemet.DOUBLE_COMPARATOR),
param);
2011-01-05 18:23:06 +00:00
}
2022-02-10 18:16:18 +00:00
if (value == null)
2016-01-09 12:15:40 +00:00
value = getFirstValueNonNullWithSuffix("fontcolor", param);
2022-02-10 18:16:18 +00:00
if (value == null)
2010-11-15 20:35:36 +00:00
value = getValue("defaultfontcolor");
2022-02-10 18:16:18 +00:00
if (value == null)
2016-01-09 12:15:40 +00:00
value = param[0].getDefaultColor();
2022-02-10 18:16:18 +00:00
if (value == null)
2021-02-02 10:12:15 +00:00
return null;
2022-02-10 18:16:18 +00:00
2022-09-18 17:08:06 +00:00
return getIHtmlColorSet().getColorOrWhite(value);
2010-11-15 20:35:36 +00:00
}
2016-01-09 12:15:40 +00:00
private String getFirstValueNonNullWithSuffix(String suffix, FontParam... param) {
for (FontParam p : param) {
final String v = getValue(p.name() + suffix);
2022-02-10 18:16:18 +00:00
if (v != null)
2016-01-09 12:15:40 +00:00
return v;
2022-02-10 18:16:18 +00:00
2016-01-09 12:15:40 +00:00
}
return null;
}
private int getFontStyle(Stereotype stereotype, boolean inPackageTitle, FontParam... param) {
2011-01-05 18:23:06 +00:00
String value = null;
if (stereotype != null) {
checkStereotype(stereotype);
2019-03-29 22:14:07 +00:00
value = getFirstValueNonNullWithSuffix("fontstyle" + stereotype.getLabel(Guillemet.DOUBLE_COMPARATOR),
param);
2011-01-05 18:23:06 +00:00
}
2022-02-10 18:16:18 +00:00
if (value == null)
2016-01-09 12:15:40 +00:00
value = getFirstValueNonNullWithSuffix("fontstyle", param);
2022-02-10 18:16:18 +00:00
if (value == null)
2010-11-15 20:35:36 +00:00
value = getValue("defaultfontstyle");
2022-02-10 18:16:18 +00:00
if (value == null)
2016-01-09 12:15:40 +00:00
return param[0].getDefaultFontStyle(this, inPackageTitle);
2022-02-10 18:16:18 +00:00
2010-11-15 20:35:36 +00:00
int result = Font.PLAIN;
2022-02-10 18:16:18 +00:00
if (StringUtils.goLowerCase(value).contains("bold"))
2010-11-15 20:35:36 +00:00
result = result | Font.BOLD;
2022-02-10 18:16:18 +00:00
if (StringUtils.goLowerCase(value).contains("italic"))
2010-11-15 20:35:36 +00:00
result = result | Font.ITALIC;
2022-02-10 18:16:18 +00:00
2010-11-15 20:35:36 +00:00
return result;
}
2022-10-18 20:57:44 +00:00
@Override
2016-01-09 12:15:40 +00:00
public UFont getFont(Stereotype stereotype, boolean inPackageTitle, FontParam... fontParam) {
2022-02-10 18:16:18 +00:00
if (stereotype != null)
2011-01-05 18:23:06 +00:00
checkStereotype(stereotype);
2022-02-10 18:16:18 +00:00
2016-01-09 12:15:40 +00:00
final String fontFamily = getFontFamily(stereotype, fontParam);
final int fontStyle = getFontStyle(stereotype, inPackageTitle, fontParam);
final int fontSize = getFontSize(stereotype, fontParam);
2015-04-07 18:18:37 +00:00
return new UFont(fontFamily, fontStyle, fontSize);
2010-11-15 20:35:36 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2010-11-15 20:35:36 +00:00
public int getCircledCharacterRadius() {
2021-03-29 04:50:53 +00:00
final int value = getAsInt("circledCharacterRadius", -1);
return value == -1 ? getFontSize(null, FontParam.CIRCLED_CHARACTER) / 3 + 6 : value;
2010-11-15 20:35:36 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2010-11-15 20:35:36 +00:00
public int classAttributeIconSize() {
2021-03-29 04:50:53 +00:00
return getAsInt("classAttributeIconSize", 10);
2010-11-15 20:35:36 +00:00
}
public static Collection<String> getPossibleValues() {
2021-05-14 08:42:57 +00:00
final Set<String> result = new TreeSet<>();
2010-11-15 20:35:36 +00:00
result.add("Monochrome");
2011-04-19 16:50:40 +00:00
// result.add("BackgroundColor");
2010-11-15 20:35:36 +00:00
result.add("CircledCharacterRadius");
result.add("ClassAttributeIconSize");
result.add("DefaultFontName");
result.add("DefaultFontStyle");
result.add("DefaultFontSize");
result.add("DefaultFontColor");
2016-09-29 19:51:18 +00:00
result.add("MinClassWidth");
result.add("MinClassWidth");
result.add("Dpi");
result.add("DefaultTextAlignment");
result.add("Shadowing");
result.add("NoteShadowing");
result.add("Handwritten");
result.add("CircledCharacterRadius");
result.add("ClassAttributeIconSize");
result.add("Linetype");
result.add("PackageStyle");
result.add("ComponentStyle");
result.add("StereotypePosition");
result.add("Nodesep");
result.add("Ranksep");
result.add("RoundCorner");
2016-11-04 21:39:29 +00:00
result.add("TitleBorderRoundCorner");
2016-09-29 19:51:18 +00:00
result.add("MaxMessageSize");
result.add("Style");
result.add("SequenceParticipant");
result.add("ConditionStyle");
2019-06-26 19:24:49 +00:00
result.add("ConditionEndStyle");
2016-09-29 19:51:18 +00:00
result.add("SameClassWidth");
result.add("HyperlinkUnderline");
result.add("Padding");
2018-09-23 12:15:14 +00:00
result.add("BoxPadding");
2018-11-26 18:46:22 +00:00
result.add("ParticipantPadding");
2016-09-29 19:51:18 +00:00
result.add("Guillemet");
result.add("SvglinkTarget");
result.add("DefaultMonospacedFontName");
result.add("TabSize");
result.add("MaxAsciiMessageLength");
result.add("ColorArrowSeparationSpace");
2018-05-01 17:26:04 +00:00
result.add("ResponseMessageBelowArrow");
result.add("GenericDisplay");
result.add("PathHoverColor");
result.add("SwimlaneWidth");
result.add("PageBorderColor");
result.add("PageExternalColor");
result.add("PageMargin");
2018-07-27 21:56:46 +00:00
result.add("WrapWidth");
result.add("SwimlaneWidth");
result.add("SwimlaneWrapTitleWidth");
2018-11-26 18:46:22 +00:00
result.add("FixCircleLabelOverlapping");
2019-03-01 22:16:29 +00:00
result.add("LifelineStrategy");
2018-05-01 17:26:04 +00:00
2010-11-15 20:35:36 +00:00
for (FontParam p : EnumSet.allOf(FontParam.class)) {
final String h = humanName(p.name());
result.add(h + "FontStyle");
result.add(h + "FontName");
result.add(h + "FontSize");
result.add(h + "FontColor");
}
2011-04-19 16:50:40 +00:00
for (ColorParam p : EnumSet.allOf(ColorParam.class)) {
final String h = capitalize(p.name());
result.add(h + "Color");
}
2015-04-07 18:18:37 +00:00
for (LineParam p : EnumSet.allOf(LineParam.class)) {
final String h = capitalize(p.name());
result.add(h + "Thickness");
}
2018-07-27 21:56:46 +00:00
for (AlignmentParam p : EnumSet.allOf(AlignmentParam.class)) {
final String h = capitalize(p.name());
result.add(h);
}
2010-11-15 20:35:36 +00:00
return Collections.unmodifiableSet(result);
}
2011-04-19 16:50:40 +00:00
private static String capitalize(String name) {
2015-04-07 18:18:37 +00:00
return StringUtils.goUpperCase(name.substring(0, 1)) + name.substring(1);
2011-04-19 16:50:40 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2011-01-05 18:23:06 +00:00
public int getDpi() {
2022-01-19 21:35:53 +00:00
final int defaultValue = 96;
final int dpi = getAsInt("dpi", defaultValue);
if (dpi <= 0)
return defaultValue;
return dpi;
2011-01-05 18:23:06 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2011-03-26 12:37:27 +00:00
public DotSplines getDotSplines() {
final String value = getValue("linetype");
2022-02-10 18:16:18 +00:00
if ("polyline".equalsIgnoreCase(value))
2011-03-26 12:37:27 +00:00
return DotSplines.POLYLINE;
2022-02-10 18:16:18 +00:00
if ("ortho".equalsIgnoreCase(value))
2011-03-26 12:37:27 +00:00
return DotSplines.ORTHO;
2022-02-10 18:16:18 +00:00
2011-03-26 12:37:27 +00:00
return DotSplines.SPLINES;
2011-02-23 21:14:39 +00:00
}
2011-04-19 16:50:40 +00:00
2022-10-18 20:57:44 +00:00
@Override
2018-11-26 18:46:22 +00:00
public HorizontalAlignment getHorizontalAlignment(AlignmentParam param, ArrowDirection arrowDirection,
2021-06-27 16:50:40 +00:00
boolean isReverseDefine, HorizontalAlignment overrideDefault) {
2013-12-10 19:36:50 +00:00
final String value;
switch (param) {
2018-07-27 21:56:46 +00:00
case sequenceMessageAlignment:
value = getArg(getValue(AlignmentParam.sequenceMessageAlignment.name()), 0);
2013-12-10 19:36:50 +00:00
break;
2018-07-27 21:56:46 +00:00
case sequenceMessageTextAlignment:
value = getArg(getValue(AlignmentParam.sequenceMessageAlignment.name()), 1);
2013-12-10 19:36:50 +00:00
break;
default:
value = getValue(param.name());
}
2018-11-26 18:46:22 +00:00
if ("first".equalsIgnoreCase(value)) {
if (arrowDirection == ArrowDirection.RIGHT_TO_LEFT_REVERSE) {
2022-02-10 18:16:18 +00:00
if (isReverseDefine)
2018-11-26 18:46:22 +00:00
return HorizontalAlignment.LEFT;
2022-02-10 18:16:18 +00:00
2018-11-26 18:46:22 +00:00
return HorizontalAlignment.RIGHT;
} else {
2022-02-10 18:16:18 +00:00
if (isReverseDefine)
2018-11-26 18:46:22 +00:00
return HorizontalAlignment.RIGHT;
2022-02-10 18:16:18 +00:00
2018-11-26 18:46:22 +00:00
return HorizontalAlignment.LEFT;
}
}
2016-11-04 21:39:29 +00:00
if ("direction".equalsIgnoreCase(value)) {
2022-02-10 18:16:18 +00:00
if (arrowDirection == ArrowDirection.LEFT_TO_RIGHT_NORMAL)
2016-11-04 21:39:29 +00:00
return HorizontalAlignment.LEFT;
2022-02-10 18:16:18 +00:00
if (arrowDirection == ArrowDirection.RIGHT_TO_LEFT_REVERSE)
2016-11-04 21:39:29 +00:00
return HorizontalAlignment.RIGHT;
2022-02-10 18:16:18 +00:00
if (arrowDirection == ArrowDirection.BOTH_DIRECTION)
2018-07-27 21:56:46 +00:00
return HorizontalAlignment.CENTER;
2022-02-10 18:16:18 +00:00
2016-11-04 21:39:29 +00:00
}
if ("reversedirection".equalsIgnoreCase(value)) {
2022-02-10 18:16:18 +00:00
if (arrowDirection == ArrowDirection.LEFT_TO_RIGHT_NORMAL)
2016-11-04 21:39:29 +00:00
return HorizontalAlignment.RIGHT;
2022-02-10 18:16:18 +00:00
if (arrowDirection == ArrowDirection.RIGHT_TO_LEFT_REVERSE)
2016-11-04 21:39:29 +00:00
return HorizontalAlignment.LEFT;
2022-02-10 18:16:18 +00:00
if (arrowDirection == ArrowDirection.BOTH_DIRECTION)
2018-07-27 21:56:46 +00:00
return HorizontalAlignment.CENTER;
2022-02-10 18:16:18 +00:00
2016-11-04 21:39:29 +00:00
}
2013-12-10 19:36:50 +00:00
final HorizontalAlignment result = HorizontalAlignment.fromString(value);
2022-02-10 18:16:18 +00:00
if (result == null && param == AlignmentParam.noteTextAlignment)
2021-06-27 16:50:40 +00:00
return getDefaultTextAlignment(overrideDefault == null ? HorizontalAlignment.LEFT : overrideDefault);
2022-02-10 18:16:18 +00:00
else if (result == null && param == AlignmentParam.stateMessageAlignment)
2019-06-26 19:24:49 +00:00
return getDefaultTextAlignment(HorizontalAlignment.CENTER);
2022-02-10 18:16:18 +00:00
else if (result == null)
2011-08-08 17:48:29 +00:00
return param.getDefaultValue();
2022-02-10 18:16:18 +00:00
2011-08-08 17:48:29 +00:00
return result;
}
2022-10-18 20:57:44 +00:00
@Override
2016-07-04 19:06:50 +00:00
public HorizontalAlignment getDefaultTextAlignment(HorizontalAlignment defaultValue) {
2015-04-07 18:18:37 +00:00
final String value = getValue("defaulttextalignment");
final HorizontalAlignment result = HorizontalAlignment.fromString(value);
2022-02-10 18:16:18 +00:00
if (result == null)
2016-07-04 19:06:50 +00:00
return defaultValue;
2022-02-10 18:16:18 +00:00
2015-04-07 18:18:37 +00:00
return result;
}
2022-10-18 20:57:44 +00:00
@Override
2019-05-24 19:59:31 +00:00
public HorizontalAlignment getStereotypeAlignment() {
final String value = getValue("stereotypealignment");
final HorizontalAlignment result = HorizontalAlignment.fromString(value);
2022-02-10 18:16:18 +00:00
if (result == null)
2019-05-24 19:59:31 +00:00
return HorizontalAlignment.CENTER;
2022-02-10 18:16:18 +00:00
2019-05-24 19:59:31 +00:00
return result;
}
2013-12-10 19:36:50 +00:00
private String getArg(String value, int i) {
2022-02-10 18:16:18 +00:00
if (value == null)
2013-12-10 19:36:50 +00:00
return null;
2022-02-10 18:16:18 +00:00
2013-12-10 19:36:50 +00:00
final String[] split = value.split(":");
2022-02-10 18:16:18 +00:00
if (i >= split.length)
2013-12-10 19:36:50 +00:00
return split[0];
2022-02-10 18:16:18 +00:00
2013-12-10 19:36:50 +00:00
return split[i];
}
2022-10-18 20:57:44 +00:00
@Override
2018-09-23 12:15:14 +00:00
public boolean shadowing(Stereotype stereotype) {
if (stereotype != null) {
checkStereotype(stereotype);
2019-03-29 22:14:07 +00:00
final String value2 = getValue("shadowing" + stereotype.getLabel(Guillemet.DOUBLE_COMPARATOR));
2022-02-10 18:16:18 +00:00
if (value2 != null)
2018-09-23 12:15:14 +00:00
return value2.equalsIgnoreCase("true");
2022-02-10 18:16:18 +00:00
2018-09-23 12:15:14 +00:00
}
2013-12-10 19:36:50 +00:00
final String value = getValue("shadowing");
2022-02-10 18:16:18 +00:00
if ("false".equalsIgnoreCase(value))
2015-05-03 15:36:36 +00:00
return false;
2022-02-10 18:16:18 +00:00
if ("true".equalsIgnoreCase(value))
2015-05-03 15:36:36 +00:00
return true;
2022-02-10 18:16:18 +00:00
if (strictUmlStyle())
2015-05-03 15:36:36 +00:00
return false;
2022-02-10 18:16:18 +00:00
2015-05-03 15:36:36 +00:00
return true;
}
2022-10-18 20:57:44 +00:00
@Override
2015-11-01 18:37:20 +00:00
public boolean shadowingForNote(Stereotype stereotype) {
if (stereotype != null) {
checkStereotype(stereotype);
2019-03-29 22:14:07 +00:00
final String value2 = getValue("note" + "shadowing" + stereotype.getLabel(Guillemet.DOUBLE_COMPARATOR));
2022-02-10 18:16:18 +00:00
if (value2 != null)
2015-11-01 18:37:20 +00:00
return value2.equalsIgnoreCase("true");
2022-02-10 18:16:18 +00:00
2015-11-01 18:37:20 +00:00
}
final String value2 = getValue("note" + "shadowing");
2022-02-10 18:16:18 +00:00
if (value2 != null)
2015-11-01 18:37:20 +00:00
return value2.equalsIgnoreCase("true");
2022-02-10 18:16:18 +00:00
2018-09-23 12:15:14 +00:00
return shadowing(stereotype);
2015-11-01 18:37:20 +00:00
}
2013-12-10 19:36:50 +00:00
private final Map<String, Sprite> sprites = new HashMap<String, Sprite>();
2022-10-18 20:57:44 +00:00
@Override
2019-08-26 17:07:21 +00:00
public Collection<String> getAllSpriteNames() {
2021-05-14 08:42:57 +00:00
return Collections.unmodifiableCollection(new TreeSet<>(sprites.keySet()));
2019-08-26 17:07:21 +00:00
}
2013-12-10 19:36:50 +00:00
public void addSprite(String name, Sprite sprite) {
sprites.put(name, sprite);
}
2022-10-18 20:57:44 +00:00
@Override
2013-12-10 19:36:50 +00:00
public Sprite getSprite(String name) {
2016-01-09 12:15:40 +00:00
Sprite result = sprites.get(name);
2022-02-10 18:16:18 +00:00
if (result == null)
2016-01-09 12:15:40 +00:00
result = SpriteImage.fromInternal(name);
2022-02-10 18:16:18 +00:00
2016-01-09 12:15:40 +00:00
return result;
2013-12-10 19:36:50 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2020-06-21 20:31:45 +00:00
public PackageStyle packageStyle() {
final String value = getValue("packageStyle");
final PackageStyle p = PackageStyle.fromString(value);
2022-02-10 18:16:18 +00:00
if (p == null)
2020-06-21 20:31:45 +00:00
return PackageStyle.FOLDER;
2022-02-10 18:16:18 +00:00
2020-06-21 20:31:45 +00:00
return p;
}
2022-10-18 20:57:44 +00:00
@Override
2020-06-14 20:35:42 +00:00
public ComponentStyle componentStyle() {
2022-02-10 18:16:18 +00:00
if (strictUmlStyle())
2020-06-14 20:35:42 +00:00
return ComponentStyle.UML2;
2022-02-10 18:16:18 +00:00
2013-12-10 19:36:50 +00:00
final String value = getValue("componentstyle");
2020-06-21 20:31:45 +00:00
if ("uml1".equalsIgnoreCase(value))
return ComponentStyle.UML1;
2020-06-14 20:35:42 +00:00
if ("uml2".equalsIgnoreCase(value))
return ComponentStyle.UML2;
if ("rectangle".equalsIgnoreCase(value))
return ComponentStyle.RECTANGLE;
2020-06-21 20:31:45 +00:00
return ComponentStyle.UML2;
2013-12-10 19:36:50 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2013-12-10 19:36:50 +00:00
public boolean stereotypePositionTop() {
return !valueIs("stereotypePosition", "bottom");
2011-09-08 10:42:27 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2015-04-07 18:18:37 +00:00
public boolean useSwimlanes(UmlDiagramType type) {
2022-02-10 18:16:18 +00:00
if (type != UmlDiagramType.ACTIVITY)
2013-12-10 19:36:50 +00:00
return false;
2022-02-10 18:16:18 +00:00
return swimlanes();
}
2021-05-06 21:23:05 +00:00
public boolean swimlanes() {
return isTrue("swimlane") || isTrue("swimlanes");
2013-12-10 19:36:50 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2013-12-10 19:36:50 +00:00
public double getNodesep() {
2021-03-29 04:50:53 +00:00
// TODO strange, this returns a double but only accepts integer values
return getAsInt("nodesep", 0);
2013-12-10 19:36:50 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2013-12-10 19:36:50 +00:00
public double getRanksep() {
2021-03-29 04:50:53 +00:00
// TODO strange, this returns a double but only accepts integer values
return getAsInt("ranksep", 0);
2013-12-10 19:36:50 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2018-04-06 20:36:30 +00:00
public double getDiagonalCorner(CornerParam param, Stereotype stereotype) {
final String key = param.getDiagonalKey();
Double result = getCornerInternal(key, param, stereotype);
2022-02-10 18:16:18 +00:00
if (result != null)
2018-01-28 22:08:15 +00:00
return result;
2022-02-10 18:16:18 +00:00
2018-04-06 20:36:30 +00:00
result = getCornerInternal(key, param, null);
2022-02-10 18:16:18 +00:00
if (result != null)
2018-01-28 22:08:15 +00:00
return result;
2022-02-10 18:16:18 +00:00
if (param == CornerParam.DEFAULT)
2018-01-28 22:08:15 +00:00
return 0;
2022-02-10 18:16:18 +00:00
2018-04-06 20:36:30 +00:00
return getDiagonalCorner(CornerParam.DEFAULT, stereotype);
2018-01-28 22:08:15 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2018-04-06 20:36:30 +00:00
public double getRoundCorner(CornerParam param, Stereotype stereotype) {
final String key = param.getRoundKey();
Double result = getCornerInternal(key, param, stereotype);
2022-02-10 18:16:18 +00:00
if (result != null)
2018-04-06 20:36:30 +00:00
return result;
2022-02-10 18:16:18 +00:00
2018-04-06 20:36:30 +00:00
result = getCornerInternal(key, param, null);
2022-02-10 18:16:18 +00:00
if (result != null)
2018-04-06 20:36:30 +00:00
return result;
2022-02-10 18:16:18 +00:00
if (param == CornerParam.DEFAULT)
2018-04-06 20:36:30 +00:00
return 0;
2022-02-10 18:16:18 +00:00
2018-04-06 20:36:30 +00:00
return getRoundCorner(CornerParam.DEFAULT, stereotype);
}
private Double getCornerInternal(String key, CornerParam param, Stereotype stereotype) {
2022-02-10 18:16:18 +00:00
if (stereotype != null)
2019-03-29 22:14:07 +00:00
key += stereotype.getLabel(Guillemet.DOUBLE_COMPARATOR);
2022-02-10 18:16:18 +00:00
2016-12-14 21:01:03 +00:00
final String value = getValue(key);
2022-02-10 18:16:18 +00:00
if (value != null && value.matches("\\d+"))
2013-12-10 19:36:50 +00:00
return Double.parseDouble(value);
2022-02-10 18:16:18 +00:00
2018-01-28 22:08:15 +00:00
return null;
2013-12-10 19:36:50 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2015-04-07 18:18:37 +00:00
public UStroke getThickness(LineParam param, Stereotype stereotype) {
2017-11-20 16:10:36 +00:00
LinkStyle style = null;
2015-04-07 18:18:37 +00:00
if (stereotype != null) {
checkStereotype(stereotype);
2017-11-20 16:10:36 +00:00
2020-03-18 10:50:02 +00:00
final String styleValue = getValue(
param.name() + "style" + stereotype.getLabel(Guillemet.DOUBLE_COMPARATOR));
2022-02-10 18:16:18 +00:00
if (styleValue != null)
2017-11-20 16:10:36 +00:00
style = LinkStyle.fromString2(styleValue);
2020-03-18 10:50:02 +00:00
final String value2 = getValue(
param.name() + "thickness" + stereotype.getLabel(Guillemet.DOUBLE_COMPARATOR));
2015-04-07 18:18:37 +00:00
if (value2 != null && value2.matches("[\\d.]+")) {
2022-02-10 18:16:18 +00:00
if (style == null)
2017-11-20 16:10:36 +00:00
style = LinkStyle.NORMAL();
2022-02-10 18:16:18 +00:00
2017-11-20 16:10:36 +00:00
return style.goThickness(Double.parseDouble(value2)).getStroke3();
2015-04-07 18:18:37 +00:00
}
}
2013-12-10 19:36:50 +00:00
final String value = getValue(param.name() + "thickness");
if (value != null && value.matches("[\\d.]+")) {
2022-02-10 18:16:18 +00:00
if (style == null)
2017-11-20 16:10:36 +00:00
style = LinkStyle.NORMAL();
2022-02-10 18:16:18 +00:00
2017-11-20 16:10:36 +00:00
return style.goThickness(Double.parseDouble(value)).getStroke3();
}
if (style == null) {
final String styleValue = getValue(param.name() + "style");
2022-02-10 18:16:18 +00:00
if (styleValue != null)
2017-11-20 16:10:36 +00:00
style = LinkStyle.fromString2(styleValue);
2022-02-10 18:16:18 +00:00
2017-11-20 16:10:36 +00:00
}
2022-02-10 18:16:18 +00:00
if (style != null && style.isNormal() == false)
2017-11-20 16:10:36 +00:00
return style.getStroke3();
2022-02-10 18:16:18 +00:00
2013-12-10 19:36:50 +00:00
return null;
}
2022-10-18 20:57:44 +00:00
@Override
2017-02-26 16:26:11 +00:00
public LineBreakStrategy maxMessageSize() {
2018-03-09 21:37:34 +00:00
String value = getValue("wrapmessagewidth");
2022-02-10 18:16:18 +00:00
if (value == null)
2018-03-09 21:37:34 +00:00
value = getValue("maxmessagesize");
2022-02-10 18:16:18 +00:00
2018-03-09 21:37:34 +00:00
return new LineBreakStrategy(value);
}
2022-10-18 20:57:44 +00:00
@Override
2018-07-27 21:56:46 +00:00
public LineBreakStrategy swimlaneWrapTitleWidth() {
final String value = getValue("swimlanewraptitlewidth");
return new LineBreakStrategy(value);
}
2022-10-18 20:57:44 +00:00
@Override
2013-12-10 19:36:50 +00:00
public boolean strictUmlStyle() {
return valueIs("style", "strictuml");
2013-12-10 19:36:50 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2013-12-10 19:36:50 +00:00
public boolean forceSequenceParticipantUnderlined() {
return valueIs("sequenceParticipant", "underline");
2013-12-10 19:36:50 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2013-12-10 19:36:50 +00:00
public ConditionStyle getConditionStyle() {
final String value = getValue("conditionStyle");
final ConditionStyle p = ConditionStyle.fromString(value);
2022-02-10 18:16:18 +00:00
if (p == null)
2020-12-06 21:43:09 +00:00
return ConditionStyle.INSIDE_HEXAGON;
2022-02-10 18:16:18 +00:00
2013-12-10 19:36:50 +00:00
return p;
}
2022-10-18 20:57:44 +00:00
@Override
2019-06-26 19:24:49 +00:00
public ConditionEndStyle getConditionEndStyle() {
final String value = getValue("conditionEndStyle");
final ConditionEndStyle p = ConditionEndStyle.fromString(value);
2022-02-10 18:16:18 +00:00
if (p == null)
2019-06-26 19:24:49 +00:00
return ConditionEndStyle.DIAMOND;
2022-02-10 18:16:18 +00:00
2019-06-26 19:24:49 +00:00
return p;
}
2022-10-18 20:57:44 +00:00
@Override
2013-12-10 19:36:50 +00:00
public boolean sameClassWidth() {
return isTrue("sameclasswidth");
2013-12-10 19:36:50 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2015-04-07 18:18:37 +00:00
public final Rankdir getRankdir() {
return rankdir;
}
public final void setRankdir(Rankdir rankdir) {
this.rankdir = rankdir;
}
2022-10-18 20:57:44 +00:00
@Override
2015-04-07 18:18:37 +00:00
public boolean useOctagonForActivity(Stereotype stereotype) {
String value = getValue("activityshape");
if (stereotype != null) {
checkStereotype(stereotype);
2019-03-29 22:14:07 +00:00
final String value2 = getValue("activityshape" + stereotype.getLabel(Guillemet.DOUBLE_COMPARATOR));
2022-02-10 18:16:18 +00:00
if (value2 != null)
2015-04-07 18:18:37 +00:00
value = value2;
2022-02-10 18:16:18 +00:00
2015-04-07 18:18:37 +00:00
}
2022-02-10 18:16:18 +00:00
if ("roundedbox".equalsIgnoreCase(value))
2015-04-07 18:18:37 +00:00
return false;
2022-02-10 18:16:18 +00:00
if ("octagon".equalsIgnoreCase(value))
2015-04-07 18:18:37 +00:00
return true;
2022-02-10 18:16:18 +00:00
2015-04-07 18:18:37 +00:00
return false;
}
2020-03-18 10:50:02 +00:00
private final HColorSet htmlColorSet = HColorSet.instance();
2015-04-07 18:18:37 +00:00
2022-10-18 20:57:44 +00:00
@Override
2020-03-18 10:50:02 +00:00
public HColorSet getIHtmlColorSet() {
2015-04-07 18:18:37 +00:00
return htmlColorSet;
}
2022-10-18 20:57:44 +00:00
@Override
2022-10-05 20:32:57 +00:00
public UStroke useUnderlineForHyperlink() {
if (valueIs("hyperlinkunderline", "false") == false)
return new UStroke();
return null;
2015-04-07 18:18:37 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2015-04-07 18:18:37 +00:00
public int groupInheritance() {
2021-03-29 04:50:53 +00:00
final int value = getAsInt("groupinheritance", Integer.MAX_VALUE);
return value <= 1 ? Integer.MAX_VALUE : value;
2015-04-07 18:18:37 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2019-03-29 22:14:07 +00:00
public Guillemet guillemet() {
2015-04-07 18:18:37 +00:00
final String value = getValue("guillemet");
2019-03-29 22:14:07 +00:00
return Guillemet.GUILLEMET.fromDescription(value);
2015-04-07 18:18:37 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2015-04-07 18:18:37 +00:00
public boolean handwritten() {
return isTrue("handwritten");
2015-04-07 18:18:37 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2015-05-31 18:56:03 +00:00
public String getSvgLinkTarget() {
return getValue("svglinktarget", "_top");
2015-05-31 18:56:03 +00:00
}
2019-12-10 21:45:49 +00:00
2022-10-18 20:57:44 +00:00
@Override
2019-11-03 17:40:03 +00:00
public String getPreserveAspectRatio() {
return getValue("preserveaspectratio", DEFAULT_PRESERVE_ASPECT_RATIO);
2019-11-03 17:40:03 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2015-09-06 17:28:59 +00:00
public String getMonospacedFamily() {
return getValue("defaultMonospacedFontName", Parser.MONOSPACED);
2015-09-06 17:28:59 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2015-09-28 20:42:17 +00:00
public int getTabSize() {
2021-03-29 04:50:53 +00:00
return getAsInt("tabsize", 8);
2015-09-28 20:42:17 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2016-02-07 21:13:01 +00:00
public int maxAsciiMessageLength() {
2021-03-29 04:50:53 +00:00
return getAsInt("maxasciimessagelength", -1);
2016-02-07 21:13:01 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2016-05-11 21:31:47 +00:00
public int colorArrowSeparationSpace() {
2021-03-29 04:50:53 +00:00
return getAsInt("colorarrowseparationspace", 0);
2016-05-11 21:31:47 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2016-11-04 21:39:29 +00:00
public SplitParam getSplitParam() {
final String border = getValue("pageBorderColor");
final String external = getValue("pageExternalColor");
2022-09-18 17:08:06 +00:00
final HColor borderColor = border == null ? null : getIHtmlColorSet().getColorOrWhite(border);
final HColor externalColor = external == null ? null : getIHtmlColorSet().getColorOrWhite(external);
2021-03-29 04:50:53 +00:00
int margin = getAsInt("pageMargin", 0);
2021-02-02 10:12:15 +00:00
return new SplitParam(borderColor, externalColor, margin);
2016-11-04 21:39:29 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2016-12-01 20:29:25 +00:00
public int swimlaneWidth() {
final String value = getValue("swimlanewidth");
2022-02-10 18:16:18 +00:00
if ("same".equalsIgnoreCase(value))
2018-07-27 21:56:46 +00:00
return SWIMLANE_WIDTH_SAME;
2022-02-10 18:16:18 +00:00
if (value != null && value.matches("\\d+"))
2016-12-01 20:29:25 +00:00
return Integer.parseInt(value);
2022-02-10 18:16:18 +00:00
2016-12-01 20:29:25 +00:00
return 0;
}
2022-10-18 20:57:44 +00:00
@Override
2017-02-15 21:34:36 +00:00
public UmlDiagramType getUmlDiagramType() {
return type;
}
2022-10-18 20:57:44 +00:00
@Override
2020-06-21 20:31:45 +00:00
public HColor hoverPathColor() {
2017-02-15 21:34:36 +00:00
final String value = getValue("pathhovercolor");
2022-02-10 18:16:18 +00:00
if (value == null)
2017-02-15 21:34:36 +00:00
return null;
2022-02-10 18:16:18 +00:00
2022-09-18 17:08:06 +00:00
return getIHtmlColorSet().getColorOrWhite(value);
2017-02-15 21:34:36 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2017-02-26 16:26:11 +00:00
public double getPadding() {
2019-07-14 20:09:26 +00:00
final String name = "padding";
return getAsDouble(name);
2017-02-26 16:26:11 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2017-02-26 16:26:11 +00:00
public double getPadding(PaddingParam param) {
2019-07-14 20:09:26 +00:00
final String name = param.getSkinName();
return getAsDouble(name);
}
private double getAsDouble(final String name) {
final String value = getValue(name);
2022-02-10 18:16:18 +00:00
if (value != null && value.matches("\\d+(\\.\\d+)?"))
2017-02-26 16:26:11 +00:00
return Double.parseDouble(value);
2022-02-10 18:16:18 +00:00
2017-02-26 16:26:11 +00:00
return 0;
}
2021-03-29 04:50:53 +00:00
private int getAsInt(String key, int defaultValue) {
final String value = getValue(key);
2022-02-10 18:16:18 +00:00
if (value != null && value.matches("\\d+"))
2021-03-29 04:50:53 +00:00
return Integer.parseInt(value);
2022-02-10 18:16:18 +00:00
2021-03-29 04:50:53 +00:00
return defaultValue;
}
2022-10-18 20:57:44 +00:00
@Override
2017-06-05 11:27:21 +00:00
public boolean useRankSame() {
return false;
}
2022-10-18 20:57:44 +00:00
@Override
2017-09-03 16:59:24 +00:00
public boolean displayGenericWithOldFashion() {
return valueIs("genericDisplay", "old");
2017-09-03 16:59:24 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2018-03-09 21:37:34 +00:00
public boolean responseMessageBelowArrow() {
return isTrue("responsemessagebelowarrow");
2018-03-09 21:37:34 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2017-10-07 09:46:53 +00:00
public TikzFontDistortion getTikzFontDistortion() {
final String value = getValue("tikzFont");
return TikzFontDistortion.fromValue(value);
}
2022-10-18 20:57:44 +00:00
@Override
2018-03-09 21:37:34 +00:00
public boolean svgDimensionStyle() {
return !valueIs("svgdimensionstyle", "false");
2018-03-09 21:37:34 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2018-08-26 12:09:50 +00:00
public boolean fixCircleLabelOverlapping() {
return isTrue("fixcirclelabeloverlapping");
2018-08-26 12:09:50 +00:00
}
2022-10-18 20:57:44 +00:00
@Override
2018-12-22 11:11:40 +00:00
public void setUseVizJs(boolean useVizJs) {
this.useVizJs = useVizJs;
}
2022-10-18 20:57:44 +00:00
@Override
2018-12-22 11:11:40 +00:00
public boolean isUseVizJs() {
return useVizJs;
}
2022-10-18 20:57:44 +00:00
@Override
2020-06-21 20:31:45 +00:00
public Padder sequenceDiagramPadder() {
2019-07-14 20:09:26 +00:00
final double padding = getAsDouble("SequenceMessagePadding");
final double margin = getAsDouble("SequenceMessageMargin");
final String borderColor = getValue("SequenceMessageBorderColor");
final String backgroundColor = getValue("SequenceMessageBackGroundColor");
2022-02-10 18:16:18 +00:00
if (padding == 0 && margin == 0 && borderColor == null && backgroundColor == null)
2019-07-14 20:09:26 +00:00
return Padder.NONE;
2022-02-10 18:16:18 +00:00
2022-09-18 17:08:06 +00:00
final HColor border = borderColor == null ? null : getIHtmlColorSet().getColorOrWhite(borderColor);
final HColor background = backgroundColor == null ? null : getIHtmlColorSet().getColorOrWhite(backgroundColor);
2019-07-14 20:09:26 +00:00
final double roundCorner = getRoundCorner(CornerParam.DEFAULT, null);
return Padder.NONE.withMargin(margin).withPadding(padding).withBackgroundColor(background)
.withBorderColor(border).withRoundCorner(roundCorner);
}
2022-10-18 20:57:44 +00:00
@Override
2020-06-21 20:31:45 +00:00
public ActorStyle actorStyle() {
2019-12-10 21:45:49 +00:00
final String value = getValue("actorstyle");
2022-02-10 18:16:18 +00:00
if ("awesome".equalsIgnoreCase(value))
2019-12-10 21:45:49 +00:00
return ActorStyle.AWESOME;
2022-02-10 18:16:18 +00:00
if ("hollow".equalsIgnoreCase(value))
return ActorStyle.HOLLOW;
2022-02-10 18:16:18 +00:00
2019-12-10 21:45:49 +00:00
return ActorStyle.STICKMAN;
}
2022-10-18 20:57:44 +00:00
@Override
2020-12-06 21:43:09 +00:00
public void setSvgSize(String origin, String sizeToUse) {
svgCharSizes.put(StringUtils.manageUnicodeNotationUplus(origin),
StringUtils.manageUnicodeNotationUplus(sizeToUse));
}
2022-10-18 20:57:44 +00:00
@Override
2020-12-06 21:43:09 +00:00
public String transformStringForSizeHack(String s) {
2022-02-10 18:16:18 +00:00
for (Entry<String, String> ent : svgCharSizes.entrySet())
2020-12-06 21:43:09 +00:00
s = s.replace(ent.getKey(), ent.getValue());
2022-02-10 18:16:18 +00:00
2020-12-06 21:43:09 +00:00
return s;
}
2022-10-18 20:57:44 +00:00
@Override
2021-01-10 20:52:19 +00:00
public LengthAdjust getlengthAdjust() {
final String value = getValue("lengthAdjust");
2022-02-10 18:16:18 +00:00
if ("spacingAndGlyphs".equalsIgnoreCase(value))
2021-01-10 20:52:19 +00:00
return LengthAdjust.SPACING_AND_GLYPHS;
2022-02-10 18:16:18 +00:00
if ("spacing".equalsIgnoreCase(value))
2021-01-10 20:52:19 +00:00
return LengthAdjust.SPACING;
2022-02-10 18:16:18 +00:00
if ("none".equalsIgnoreCase(value))
2021-01-10 20:52:19 +00:00
return LengthAdjust.NONE;
2022-02-10 18:16:18 +00:00
2021-01-10 20:52:19 +00:00
return LengthAdjust.defaultValue();
}
2022-10-18 20:57:44 +00:00
private double paramSameClassWidth;
public void setParamSameClassWidth(double width) {
this.paramSameClassWidth = width;
}
@Override
public final double getParamSameClassWidth() {
return paramSameClassWidth;
}
2022-11-04 17:36:03 +00:00
@Override
public SheetBuilder sheet(FontConfiguration fontConfiguration, HorizontalAlignment horizontalAlignment,
CreoleMode creoleMode) {
final FontConfiguration stereotype = fontConfiguration.forceFont(null, null);
return sheet(fontConfiguration, horizontalAlignment, creoleMode, stereotype);
}
private final Map<Object, CreoleParser> cache = new HashMap<>();
@Override
public SheetBuilder sheet(FontConfiguration fontConfiguration, HorizontalAlignment horizontalAlignment,
CreoleMode creoleMode, FontConfiguration stereo) {
final Object key = Arrays.asList(horizontalAlignment, creoleMode, fontConfiguration, stereo);
CreoleParser result = cache.get(key);
if (result == null) {
result = new CreoleParser(fontConfiguration, horizontalAlignment, this, creoleMode, stereo);
cache.put(key, result);
}
return result;
}
2022-11-30 17:41:17 +00:00
@Override
public Arrows arrows() {
if (strictUmlStyle())
return new ArrowsTriangle();
return new ArrowsRegular();
}
2010-11-15 20:35:36 +00:00
}