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

336 lines
14 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;
2018-07-27 21:56:46 +00:00
import net.sourceforge.plantuml.AlignmentParam;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.ColorParam;
import net.sourceforge.plantuml.ISkinParam;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.LineParam;
2017-02-26 16:26:11 +00:00
import net.sourceforge.plantuml.PaddingParam;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.cucadiagram.Display;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.cucadiagram.Stereotype;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
2022-08-30 19:15:53 +00:00
import net.sourceforge.plantuml.graphic.color.Colors;
2021-06-27 16:50:40 +00:00
import net.sourceforge.plantuml.sequencediagram.NotePosition;
2019-04-21 20:40:01 +00:00
import net.sourceforge.plantuml.skin.ArrowComponent;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.skin.ArrowConfiguration;
import net.sourceforge.plantuml.skin.ArrowDirection;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.skin.Component;
import net.sourceforge.plantuml.skin.ComponentType;
2019-09-14 18:12:04 +00:00
import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.SName;
2019-07-14 20:09:26 +00:00
import net.sourceforge.plantuml.style.Style;
2022-03-01 18:11:51 +00:00
import net.sourceforge.plantuml.style.StyleSignatureBasic;
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;
2010-11-15 20:35:36 +00:00
2019-03-01 22:16:29 +00:00
public class Rose {
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
final private double paddingX = 5;
2019-09-22 17:20:16 +00:00
final public static double paddingY = 5;
2010-11-15 20:35:36 +00:00
2020-03-18 10:50:02 +00:00
public HColor getHtmlColor(ISkinParam skin, ColorParam color) {
2019-01-16 18:34:41 +00:00
return getHtmlColor(skin, null, color);
2011-01-05 18:23:06 +00:00
}
2020-03-18 10:50:02 +00:00
public HColor getHtmlColor(ISkinParam skin, Stereotype stereotype, ColorParam... colorParams) {
2019-01-16 18:34:41 +00:00
for (ColorParam param : colorParams) {
2020-03-18 10:50:02 +00:00
final HColor result = skin.getHtmlColor(param, stereotype, false);
2022-05-21 09:41:00 +00:00
if (result != null)
2019-01-16 18:34:41 +00:00
return result;
2022-05-21 09:41:00 +00:00
2010-11-15 20:35:36 +00:00
}
2019-01-16 18:34:41 +00:00
return colorParams[0].getDefaultValue();
2010-11-15 20:35:36 +00:00
}
2021-06-27 16:50:40 +00:00
private void checkRose() {
// Quite ugly, but we want to ensure that TextSkin overrides those methods
if (this.getClass() != Rose.class)
throw new IllegalStateException("" + this.getClass());
}
public Component createComponentNote(Style[] styles, ComponentType type, ISkinParam param, Display stringsToDisplay,
2022-08-30 19:15:53 +00:00
Colors colors) {
checkRose();
return createComponentNote(styles, type, param, stringsToDisplay, colors, null);
}
public Component createComponentNote(Style[] styles, ComponentType type, ISkinParam param, Display stringsToDisplay,
Colors colors, NotePosition notePosition) {
2021-06-27 16:50:40 +00:00
checkRose();
final HorizontalAlignment textAlign;
final HorizontalAlignment position;
if (notePosition == NotePosition.OVER_SEVERAL) {
textAlign = param.getHorizontalAlignment(AlignmentParam.noteTextAlignment, null, false,
HorizontalAlignment.LEFT);
if (textAlign == param.getHorizontalAlignment(AlignmentParam.noteTextAlignment, null, false,
HorizontalAlignment.CENTER))
// Which means we use default
position = textAlign;
else
position = HorizontalAlignment.CENTER;
} else {
textAlign = param.getHorizontalAlignment(AlignmentParam.noteTextAlignment, null, false, null);
position = textAlign;
}
2022-05-21 09:41:00 +00:00
if (type == ComponentType.NOTE)
return new ComponentRoseNote(styles == null ? null : styles[0], stringsToDisplay, paddingX, paddingY, param,
2022-08-30 19:15:53 +00:00
textAlign, position, colors);
2022-05-21 09:41:00 +00:00
if (type == ComponentType.NOTE_HEXAGONAL)
2022-08-30 19:15:53 +00:00
return new ComponentRoseNoteHexagonal(styles == null ? null : styles[0], stringsToDisplay, param, colors);
2022-05-21 09:41:00 +00:00
if (type == ComponentType.NOTE_BOX)
2022-08-30 19:15:53 +00:00
return new ComponentRoseNoteBox(styles == null ? null : styles[0], stringsToDisplay, param, colors);
2021-06-27 16:50:40 +00:00
throw new UnsupportedOperationException(type.toString());
}
2019-07-14 20:09:26 +00:00
public Component createComponent(Style[] styles, ComponentType type, ArrowConfiguration config, ISkinParam param,
2013-12-10 19:36:50 +00:00
Display stringsToDisplay) {
2021-06-27 16:50:40 +00:00
checkRose();
2010-11-15 20:35:36 +00:00
2020-03-18 10:50:02 +00:00
final Stereotype stereotype = stringsToDisplay == null ? null : stringsToDisplay.getStereotypeIfAny();
2022-05-21 09:41:00 +00:00
if (type.isArrow())
2019-07-14 20:09:26 +00:00
return createComponentArrow(null, config, param, stringsToDisplay);
2022-05-21 09:41:00 +00:00
2017-02-26 16:26:11 +00:00
final double padding = param.getPadding(PaddingParam.PARTICIPANT);
2022-05-21 09:41:00 +00:00
if (type == ComponentType.PARTICIPANT_HEAD)
2019-07-14 20:09:26 +00:00
return new ComponentRoseParticipant(styles == null ? null : styles[0], styles == null ? null : styles[1],
2022-05-21 09:41:00 +00:00
stringsToDisplay, param, param.minClassWidth(), false, padding);
if (type == ComponentType.PARTICIPANT_TAIL)
2019-07-14 20:09:26 +00:00
return new ComponentRoseParticipant(styles == null ? null : styles[0], styles == null ? null : styles[1],
2022-05-21 09:41:00 +00:00
stringsToDisplay, param, param.minClassWidth(), false, padding);
if (type == ComponentType.COLLECTIONS_HEAD)
2019-07-14 20:09:26 +00:00
return new ComponentRoseParticipant(styles == null ? null : styles[0], styles == null ? null : styles[1],
2022-05-21 09:41:00 +00:00
stringsToDisplay, param, param.minClassWidth(), true, padding);
if (type == ComponentType.COLLECTIONS_TAIL)
2019-07-14 20:09:26 +00:00
return new ComponentRoseParticipant(styles == null ? null : styles[0], styles == null ? null : styles[1],
2022-05-21 09:41:00 +00:00
stringsToDisplay, param, param.minClassWidth(), true, padding);
if (type == ComponentType.PARTICIPANT_LINE)
2022-09-18 17:08:06 +00:00
return new ComponentRoseLine(styles == null ? null : styles[0], false, param.getIHtmlColorSet());
2022-05-21 09:41:00 +00:00
if (type == ComponentType.CONTINUE_LINE)
2022-09-18 17:08:06 +00:00
return new ComponentRoseLine(styles == null ? null : styles[0], true, param.getIHtmlColorSet());
2022-05-21 09:41:00 +00:00
if (type == ComponentType.ACTOR_HEAD)
2020-06-21 20:31:45 +00:00
return new ComponentRoseActor(param.actorStyle(), styles == null ? null : styles[0],
2022-05-21 09:41:00 +00:00
styles == null ? null : styles[1], stringsToDisplay, true, param);
if (type == ComponentType.ACTOR_TAIL)
2020-06-21 20:31:45 +00:00
return new ComponentRoseActor(param.actorStyle(), styles == null ? null : styles[0],
2022-05-21 09:41:00 +00:00
styles == null ? null : styles[1], stringsToDisplay, false, param);
if (type == ComponentType.BOUNDARY_HEAD)
2019-07-14 20:09:26 +00:00
return new ComponentRoseBoundary(styles == null ? null : styles[0], styles == null ? null : styles[1],
2022-05-21 09:41:00 +00:00
stringsToDisplay, true, param);
if (type == ComponentType.BOUNDARY_TAIL)
2019-07-14 20:09:26 +00:00
return new ComponentRoseBoundary(styles == null ? null : styles[0], styles == null ? null : styles[1],
2022-05-21 09:41:00 +00:00
stringsToDisplay, false, param);
if (type == ComponentType.CONTROL_HEAD)
2019-07-14 20:09:26 +00:00
return new ComponentRoseControl(styles == null ? null : styles[0], styles == null ? null : styles[1],
2022-05-21 09:41:00 +00:00
stringsToDisplay, true, param);
if (type == ComponentType.CONTROL_TAIL)
2019-07-14 20:09:26 +00:00
return new ComponentRoseControl(styles == null ? null : styles[0], styles == null ? null : styles[1],
2022-05-21 09:41:00 +00:00
stringsToDisplay, false, param);
if (type == ComponentType.ENTITY_HEAD)
2019-07-14 20:09:26 +00:00
return new ComponentRoseEntity(styles == null ? null : styles[0], styles == null ? null : styles[1],
2022-05-21 09:41:00 +00:00
stringsToDisplay, true, param);
if (type == ComponentType.ENTITY_TAIL)
2019-07-14 20:09:26 +00:00
return new ComponentRoseEntity(styles == null ? null : styles[0], styles == null ? null : styles[1],
2022-05-21 09:41:00 +00:00
stringsToDisplay, false, param);
if (type == ComponentType.QUEUE_HEAD)
2019-07-14 20:09:26 +00:00
return new ComponentRoseQueue(styles == null ? null : styles[0], styles == null ? null : styles[1],
2022-05-21 09:41:00 +00:00
stringsToDisplay, true, param);
if (type == ComponentType.QUEUE_TAIL)
2019-07-14 20:09:26 +00:00
return new ComponentRoseQueue(styles == null ? null : styles[0], styles == null ? null : styles[1],
2022-05-21 09:41:00 +00:00
stringsToDisplay, false, param);
if (type == ComponentType.DATABASE_HEAD)
2019-07-14 20:09:26 +00:00
return new ComponentRoseDatabase(styles == null ? null : styles[0], styles == null ? null : styles[1],
2022-05-21 09:41:00 +00:00
stringsToDisplay, true, param);
if (type == ComponentType.DATABASE_TAIL)
2019-07-14 20:09:26 +00:00
return new ComponentRoseDatabase(styles == null ? null : styles[0], styles == null ? null : styles[1],
2022-05-21 09:41:00 +00:00
stringsToDisplay, false, param);
if (type == ComponentType.NOTE)
2021-06-27 16:50:40 +00:00
throw new UnsupportedOperationException();
2022-05-21 09:41:00 +00:00
if (type == ComponentType.NOTE_HEXAGONAL)
2021-06-27 16:50:40 +00:00
throw new UnsupportedOperationException();
2022-05-21 09:41:00 +00:00
if (type == ComponentType.NOTE_BOX)
2021-06-27 16:50:40 +00:00
throw new UnsupportedOperationException();
2022-05-21 09:41:00 +00:00
if (type == ComponentType.GROUPING_HEADER)
2020-03-18 10:50:02 +00:00
return new ComponentRoseGroupingHeader(styles == null ? null : styles[0], styles == null ? null : styles[1],
2022-05-21 09:41:00 +00:00
stringsToDisplay, param);
2022-10-05 20:32:57 +00:00
if (type == ComponentType.GROUPING_ELSE_LEGACY)
return new ComponentRoseGroupingElse(false, styles == null ? null : styles[0], stringsToDisplay.get(0), param);
if (type == ComponentType.GROUPING_ELSE_TEOZ)
return new ComponentRoseGroupingElse(true, styles == null ? null : styles[0], stringsToDisplay.get(0), param);
2022-05-21 09:41:00 +00:00
if (type == ComponentType.GROUPING_SPACE)
2013-12-10 19:36:50 +00:00
return new ComponentRoseGroupingSpace(7);
2022-05-21 09:41:00 +00:00
if (type == ComponentType.ALIVE_BOX_CLOSE_CLOSE)
2022-09-18 17:08:06 +00:00
return new ComponentRoseActiveLine(styles == null ? null : styles[0], true, true, param.getIHtmlColorSet());
2022-05-21 09:41:00 +00:00
if (type == ComponentType.ALIVE_BOX_CLOSE_OPEN)
2022-10-05 20:32:57 +00:00
return new ComponentRoseActiveLine(styles == null ? null : styles[0], true, false,
param.getIHtmlColorSet());
2022-05-21 09:41:00 +00:00
2011-01-29 15:09:35 +00:00
if (type == ComponentType.ALIVE_BOX_OPEN_CLOSE) {
2022-10-05 20:32:57 +00:00
return new ComponentRoseActiveLine(styles == null ? null : styles[0], false, true,
param.getIHtmlColorSet());
2011-01-29 15:09:35 +00:00
}
2022-05-21 09:41:00 +00:00
if (type == ComponentType.ALIVE_BOX_OPEN_OPEN)
2022-10-05 20:32:57 +00:00
return new ComponentRoseActiveLine(styles == null ? null : styles[0], false, false,
param.getIHtmlColorSet());
2022-05-21 09:41:00 +00:00
if (type == ComponentType.DELAY_LINE)
2020-03-18 10:50:02 +00:00
return new ComponentRoseDelayLine(null, getHtmlColor(param, stereotype, ColorParam.sequenceLifeLineBorder));
2022-05-21 09:41:00 +00:00
if (type == ComponentType.DELAY_TEXT)
return new ComponentRoseDelayText(styles == null ? null : styles[0], stringsToDisplay, param);
if (type == ComponentType.DESTROY)
2022-02-12 17:27:51 +00:00
return new ComponentRoseDestroy(styles == null ? null : styles[0],
getHtmlColor(param, stereotype, ColorParam.sequenceLifeLineBorder), param);
2022-05-21 09:41:00 +00:00
if (type == ComponentType.NEWPAGE)
2019-04-21 20:40:01 +00:00
throw new UnsupportedOperationException();
2022-05-21 09:41:00 +00:00
if (type == ComponentType.DIVIDER)
return new ComponentRoseDivider(styles == null ? null : styles[0], stringsToDisplay, param);
if (type == ComponentType.REFERENCE)
2019-08-26 17:07:21 +00:00
return new ComponentRoseReference(styles == null ? null : styles[0], styles == null ? null : styles[1],
2022-05-21 09:41:00 +00:00
stringsToDisplay, param, getHtmlColor(param, stereotype, ColorParam.sequenceReferenceBackground));
if (type == ComponentType.ENGLOBER)
return new ComponentRoseEnglober(styles == null ? null : styles[0], stringsToDisplay, param);
2013-12-10 19:36:50 +00:00
2021-06-27 16:50:40 +00:00
throw new UnsupportedOperationException();
2010-11-15 20:35:36 +00:00
}
2021-06-27 16:50:40 +00:00
public Component createComponentNewPage(ISkinParam param) {
checkRose();
2019-07-14 20:09:26 +00:00
return new ComponentRoseNewpage(null, getHtmlColor(param, ColorParam.sequenceNewpageSeparator));
2019-04-21 20:40:01 +00:00
}
2019-07-14 20:09:26 +00:00
public ArrowComponent createComponentArrow(Style[] styles, ArrowConfiguration config, ISkinParam param,
Display stringsToDisplay) {
2021-06-27 16:50:40 +00:00
checkRose();
2022-05-21 09:41:00 +00:00
if (config.getArrowDirection() == ArrowDirection.SELF)
return new ComponentRoseSelfArrow(styles == null ? null : styles[0], stringsToDisplay, config, param,
param.maxMessageSize(), param.strictUmlStyle() == false);
2019-09-14 18:12:04 +00:00
final ArrowDirection arrowDirection = config.getArrowDirection();
2022-05-21 09:41:00 +00:00
final StyleSignatureBasic signature = StyleSignatureBasic.of(SName.root, SName.element, SName.sequenceDiagram,
SName.arrow);
final Style textStyle = signature.getMergedStyle(param.getCurrentStyleBuilder());
final String value = textStyle.value(PName.HorizontalAlignment).asString();
HorizontalAlignment messageHorizontalAlignment = textStyle.getHorizontalAlignment();
if ("first".equalsIgnoreCase(value)) {
final boolean isReverseDefine = config.isReverseDefine();
if (arrowDirection == ArrowDirection.RIGHT_TO_LEFT_REVERSE) {
if (isReverseDefine)
2019-09-14 18:12:04 +00:00
messageHorizontalAlignment = HorizontalAlignment.LEFT;
2022-05-21 09:41:00 +00:00
else
2019-09-14 18:12:04 +00:00
messageHorizontalAlignment = HorizontalAlignment.RIGHT;
2022-05-21 09:41:00 +00:00
} else {
if (isReverseDefine)
2019-09-14 18:12:04 +00:00
messageHorizontalAlignment = HorizontalAlignment.RIGHT;
2022-05-21 09:41:00 +00:00
else
2019-09-14 18:12:04 +00:00
messageHorizontalAlignment = HorizontalAlignment.LEFT;
2022-05-21 09:41:00 +00:00
2019-09-14 18:12:04 +00:00
}
2022-05-21 09:41:00 +00:00
} else if ("direction".equalsIgnoreCase(value)) {
if (arrowDirection == ArrowDirection.LEFT_TO_RIGHT_NORMAL)
messageHorizontalAlignment = HorizontalAlignment.LEFT;
else if (arrowDirection == ArrowDirection.RIGHT_TO_LEFT_REVERSE)
messageHorizontalAlignment = HorizontalAlignment.RIGHT;
else if (arrowDirection == ArrowDirection.BOTH_DIRECTION)
messageHorizontalAlignment = HorizontalAlignment.CENTER;
2019-03-01 22:16:29 +00:00
2022-05-21 09:41:00 +00:00
} else if ("reversedirection".equalsIgnoreCase(value)) {
if (arrowDirection == ArrowDirection.LEFT_TO_RIGHT_NORMAL)
messageHorizontalAlignment = HorizontalAlignment.RIGHT;
else if (arrowDirection == ArrowDirection.RIGHT_TO_LEFT_REVERSE)
messageHorizontalAlignment = HorizontalAlignment.LEFT;
else if (arrowDirection == ArrowDirection.BOTH_DIRECTION)
messageHorizontalAlignment = HorizontalAlignment.CENTER;
2015-05-03 15:36:36 +00:00
2016-11-04 21:39:29 +00:00
}
2022-05-21 09:41:00 +00:00
return new ComponentRoseArrow(styles == null ? null : styles[0], stringsToDisplay, config,
messageHorizontalAlignment, param, param.maxMessageSize(), param.strictUmlStyle() == false,
param.responseMessageBelowArrow());
2015-05-03 15:36:36 +00:00
}
2013-12-10 19:36:50 +00:00
static public UStroke getStroke(ISkinParam param, LineParam lineParam, double defaultValue) {
2015-04-07 18:18:37 +00:00
final UStroke result = param.getThickness(lineParam, null);
2022-05-21 09:41:00 +00:00
if (result == null)
2013-12-10 19:36:50 +00:00
return new UStroke(defaultValue);
2022-05-21 09:41:00 +00:00
2013-12-10 19:36:50 +00:00
return result;
}
2010-11-15 20:35:36 +00:00
}