1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-16 15:12:24 +00:00
plantuml/src/net/sourceforge/plantuml/skin/rose/Rose.java

307 lines
15 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2015-04-07 18:18:37 +00:00
* (C) Copyright 2009-2014, Arnaud Roques
2010-11-15 20:35:36 +00:00
*
* Project Info: http://plantuml.sourceforge.net
*
* 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.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
2015-09-06 17:28:59 +00:00
* Revision $Revision: 16778 $
2010-11-15 20:35:36 +00:00
*
*/
package net.sourceforge.plantuml.skin.rose;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.AlignParam;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.ColorParam;
import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.ISkinParam;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.LineParam;
import net.sourceforge.plantuml.cucadiagram.Display;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.cucadiagram.Stereotype;
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.HtmlColor;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.graphic.HtmlColorUtils;
2015-05-03 15:36:36 +00:00
import net.sourceforge.plantuml.graphic.SymbolContext;
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;
import net.sourceforge.plantuml.skin.Skin;
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;
2010-11-15 20:35:36 +00:00
public class Rose implements Skin {
2013-12-10 19:36:50 +00:00
final private double paddingX = 5;
final private double paddingY = 5;
2010-11-15 20:35:36 +00:00
2011-08-08 17:48:29 +00:00
public HtmlColor getFontColor(ISkinParam skin, FontParam fontParam) {
return skin.getFontHtmlColor(fontParam, null);
2010-11-15 20:35:36 +00:00
}
2011-01-11 07:42:49 +00:00
2010-11-15 20:35:36 +00:00
public HtmlColor getHtmlColor(ISkinParam param, ColorParam color) {
2011-01-05 18:23:06 +00:00
return getHtmlColor(param, color, null);
}
2015-04-07 18:18:37 +00:00
public HtmlColor getHtmlColor(ISkinParam param, ColorParam color, Stereotype stereotype) {
2013-12-10 19:36:50 +00:00
HtmlColor result = param.getHtmlColor(color, stereotype, false);
2010-11-15 20:35:36 +00:00
if (result == null) {
2015-04-07 18:18:37 +00:00
result = color.getDefaultValue();
2010-11-15 20:35:36 +00:00
if (result == null) {
throw new IllegalArgumentException();
}
}
return result;
}
2015-05-03 15:36:36 +00:00
private FontConfiguration getUFont2(ISkinParam param, FontParam fontParam) {
2015-04-20 19:45:13 +00:00
final UFont font = param.getFont(fontParam, null, false);
final HtmlColor fontColor = getFontColor(param, fontParam);
2015-05-03 15:36:36 +00:00
return new FontConfiguration(font, fontColor, param.getHyperlinkColor(), param.useUnderlineForHyperlink());
2015-04-20 19:45:13 +00:00
}
2013-12-10 19:36:50 +00:00
public Component createComponent(ComponentType type, ArrowConfiguration config, ISkinParam param,
Display stringsToDisplay) {
2015-04-07 18:18:37 +00:00
final UFont fontGrouping = param.getFont(FontParam.SEQUENCE_GROUP, null, false);
2010-11-15 20:35:36 +00:00
2015-04-07 18:18:37 +00:00
final UFont newFontForStereotype = param.getFont(FontParam.SEQUENCE_STEREOTYPE, null, false);
2010-11-15 20:35:36 +00:00
2011-01-11 07:42:49 +00:00
if (type.isArrow()) {
2013-12-10 19:36:50 +00:00
// if (param.maxMessageSize() > 0) {
// final FontConfiguration fc = new FontConfiguration(fontArrow, HtmlColorUtils.BLACK);
// stringsToDisplay = DisplayUtils.breakLines(stringsToDisplay, fc, param, param.maxMessageSize());
// }
final HtmlColor sequenceArrow = config.getColor() == null ? getHtmlColor(param, ColorParam.sequenceArrow)
: config.getColor();
if (config.getArrowDirection() == ArrowDirection.SELF) {
2015-04-20 19:45:13 +00:00
return new ComponentRoseSelfArrow(sequenceArrow, getUFont2(param, FontParam.SEQUENCE_ARROW),
stringsToDisplay, config, param, param.maxMessageSize(), param.strictUmlStyle() == false);
2011-01-11 07:42:49 +00:00
}
2013-12-10 19:36:50 +00:00
final HorizontalAlignment messageHorizontalAlignment = param
.getHorizontalAlignment(AlignParam.SEQUENCE_MESSAGE_ALIGN);
final HorizontalAlignment textHorizontalAlignment = param
.getHorizontalAlignment(AlignParam.SEQUENCE_MESSAGETEXT_ALIGN);
2015-04-20 19:45:13 +00:00
return new ComponentRoseArrow(sequenceArrow, getUFont2(param, FontParam.SEQUENCE_ARROW), stringsToDisplay,
config, messageHorizontalAlignment, param, textHorizontalAlignment, param.maxMessageSize(),
param.strictUmlStyle() == false);
2010-11-15 20:35:36 +00:00
}
if (type == ComponentType.PARTICIPANT_HEAD) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseParticipant(getSymbolContext(param, ColorParam.participantBorder), getUFont2(param,
FontParam.PARTICIPANT), stringsToDisplay, param, param.getRoundCorner(), newFontForStereotype,
getFontColor(param, FontParam.SEQUENCE_STEREOTYPE));
2010-11-15 20:35:36 +00:00
}
if (type == ComponentType.PARTICIPANT_TAIL) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseParticipant(getSymbolContext(param, ColorParam.participantBorder), getUFont2(param,
FontParam.PARTICIPANT), stringsToDisplay, param, param.getRoundCorner(), newFontForStereotype,
getFontColor(param, FontParam.SEQUENCE_STEREOTYPE));
2010-11-15 20:35:36 +00:00
}
if (type == ComponentType.PARTICIPANT_LINE) {
2011-08-08 17:48:29 +00:00
final HtmlColor borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder);
2013-12-10 19:36:50 +00:00
return new ComponentRoseLine(borderColor, false, getStroke(param, LineParam.sequenceLifeLineBorder, 1));
2011-01-23 19:36:52 +00:00
}
if (type == ComponentType.CONTINUE_LINE) {
2011-08-08 17:48:29 +00:00
final HtmlColor borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder);
2013-12-10 19:36:50 +00:00
return new ComponentRoseLine(borderColor, true, getStroke(param, LineParam.sequenceLifeLineBorder, 1.5));
2010-11-15 20:35:36 +00:00
}
if (type == ComponentType.ACTOR_HEAD) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseActor(getSymbolContext(param, ColorParam.actorBorder), getUFont2(param,
FontParam.ACTOR), stringsToDisplay, true, param, newFontForStereotype, getFontColor(param,
2015-04-20 19:45:13 +00:00
FontParam.SEQUENCE_STEREOTYPE));
2010-11-15 20:35:36 +00:00
}
if (type == ComponentType.ACTOR_TAIL) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseActor(getSymbolContext(param, ColorParam.actorBorder), getUFont2(param,
FontParam.ACTOR), stringsToDisplay, false, param, newFontForStereotype, getFontColor(param,
2015-04-20 19:45:13 +00:00
FontParam.SEQUENCE_STEREOTYPE));
2013-12-10 19:36:50 +00:00
}
if (type == ComponentType.BOUNDARY_HEAD) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseBoundary(getSymbolContext(param, ColorParam.actorBorder), getUFont2(param,
FontParam.ACTOR), stringsToDisplay, true, param, newFontForStereotype, getFontColor(param,
2015-04-20 19:45:13 +00:00
FontParam.SEQUENCE_STEREOTYPE));
2013-12-10 19:36:50 +00:00
}
if (type == ComponentType.BOUNDARY_TAIL) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseBoundary(getSymbolContext(param, ColorParam.actorBorder), getUFont2(param,
FontParam.ACTOR), stringsToDisplay, false, param, newFontForStereotype, getFontColor(param,
2015-04-20 19:45:13 +00:00
FontParam.SEQUENCE_STEREOTYPE));
2013-12-10 19:36:50 +00:00
}
if (type == ComponentType.CONTROL_HEAD) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseControl(getSymbolContext(param, ColorParam.actorBorder), getUFont2(param,
FontParam.ACTOR), stringsToDisplay, true, param, newFontForStereotype, getFontColor(param,
FontParam.SEQUENCE_STEREOTYPE));
2013-12-10 19:36:50 +00:00
}
if (type == ComponentType.CONTROL_TAIL) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseControl(getSymbolContext(param, ColorParam.actorBorder), getUFont2(param,
FontParam.ACTOR), stringsToDisplay, false, param, newFontForStereotype, getFontColor(param,
FontParam.SEQUENCE_STEREOTYPE));
2013-12-10 19:36:50 +00:00
}
if (type == ComponentType.ENTITY_HEAD) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseEntity(getSymbolContext(param, ColorParam.actorBorder), getUFont2(param,
FontParam.ACTOR), stringsToDisplay, true, param, newFontForStereotype, getFontColor(param,
FontParam.SEQUENCE_STEREOTYPE));
2013-12-10 19:36:50 +00:00
}
if (type == ComponentType.ENTITY_TAIL) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseEntity(getSymbolContext(param, ColorParam.actorBorder), getUFont2(param,
FontParam.ACTOR), stringsToDisplay, false, param, newFontForStereotype, getFontColor(param,
FontParam.SEQUENCE_STEREOTYPE));
2013-12-10 19:36:50 +00:00
}
if (type == ComponentType.DATABASE_HEAD) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseDatabase(getSymbolContext(param, ColorParam.actorBorder), getUFont2(param,
FontParam.ACTOR), stringsToDisplay, true, param, newFontForStereotype, getFontColor(param,
FontParam.SEQUENCE_STEREOTYPE));
2013-12-10 19:36:50 +00:00
}
if (type == ComponentType.DATABASE_TAIL) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseDatabase(getSymbolContext(param, ColorParam.actorBorder), getUFont2(param,
FontParam.ACTOR), stringsToDisplay, false, param, newFontForStereotype, getFontColor(param,
FontParam.SEQUENCE_STEREOTYPE));
2010-11-15 20:35:36 +00:00
}
if (type == ComponentType.NOTE) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseNote(getSymbolContext(param, ColorParam.noteBorder), getUFont2(param,
FontParam.NOTE), stringsToDisplay, paddingX, paddingY, param);
2010-11-15 20:35:36 +00:00
}
2011-09-07 20:41:58 +00:00
if (type == ComponentType.NOTE_HEXAGONAL) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseNoteHexagonal(getSymbolContext(param, ColorParam.noteBorder), getUFont2(param,
FontParam.NOTE), stringsToDisplay, param);
2011-09-07 20:41:58 +00:00
}
if (type == ComponentType.NOTE_BOX) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseNoteBox(getSymbolContext(param, ColorParam.noteBorder), getUFont2(param,
FontParam.NOTE), stringsToDisplay, param);
2011-09-07 20:41:58 +00:00
}
2010-11-15 20:35:36 +00:00
if (type == ComponentType.GROUPING_HEADER) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseGroupingHeader(param.getBackgroundColor(), getSymbolContext(param,
ColorParam.sequenceGroupBorder), getUFont2(param, FontParam.SEQUENCE_GROUP_HEADER), fontGrouping,
stringsToDisplay, param);
2010-11-15 20:35:36 +00:00
}
if (type == ComponentType.GROUPING_ELSE) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseGroupingElse(getHtmlColor(param, ColorParam.sequenceGroupBorder), getUFont2(param,
FontParam.SEQUENCE_GROUP), stringsToDisplay.get(0), param, param.getBackgroundColor());
2013-12-10 19:36:50 +00:00
}
if (type == ComponentType.GROUPING_SPACE) {
return new ComponentRoseGroupingSpace(7);
2010-11-15 20:35:36 +00:00
}
2011-01-29 15:09:35 +00:00
if (type == ComponentType.ALIVE_BOX_CLOSE_CLOSE) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseActiveLine(getSymbolContext(param, ColorParam.sequenceLifeLineBorder), true, true);
2011-01-29 15:09:35 +00:00
}
if (type == ComponentType.ALIVE_BOX_CLOSE_OPEN) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseActiveLine(getSymbolContext(param, ColorParam.sequenceLifeLineBorder), true, false);
2011-01-29 15:09:35 +00:00
}
if (type == ComponentType.ALIVE_BOX_OPEN_CLOSE) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseActiveLine(getSymbolContext(param, ColorParam.sequenceLifeLineBorder), false, true);
2011-01-29 15:09:35 +00:00
}
if (type == ComponentType.ALIVE_BOX_OPEN_OPEN) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseActiveLine(getSymbolContext(param, ColorParam.sequenceLifeLineBorder), false, false);
2010-11-15 20:35:36 +00:00
}
2011-01-12 19:06:53 +00:00
if (type == ComponentType.DELAY_LINE) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseDelayLine(getHtmlColor(param, ColorParam.sequenceLifeLineBorder));
2011-01-12 19:06:53 +00:00
}
if (type == ComponentType.DELAY_TEXT) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseDelayText(getUFont2(param, FontParam.SEQUENCE_DELAY), stringsToDisplay, param);
2011-01-12 19:06:53 +00:00
}
2010-11-15 20:35:36 +00:00
if (type == ComponentType.DESTROY) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseDestroy(getHtmlColor(param, ColorParam.sequenceLifeLineBorder));
2010-11-15 20:35:36 +00:00
}
if (type == ComponentType.NEWPAGE) {
2011-04-19 16:50:40 +00:00
return new ComponentRoseNewpage(getFontColor(param, FontParam.SEQUENCE_GROUP));
2010-11-15 20:35:36 +00:00
}
if (type == ComponentType.DIVIDER) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseDivider(getUFont2(param, FontParam.SEQUENCE_DIVIDER), getHtmlColor(param,
ColorParam.sequenceDividerBackground), stringsToDisplay, param, deltaShadow(param) > 0, getStroke(
2015-09-06 17:28:59 +00:00
param, LineParam.sequenceDividerBorder, 2), getHtmlColor(param, ColorParam.sequenceDividerBorder));
2010-11-15 20:35:36 +00:00
}
2011-04-19 16:50:40 +00:00
if (type == ComponentType.REFERENCE) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseReference(getUFont2(param, FontParam.SEQUENCE_REFERENCE), getSymbolContext(param,
ColorParam.sequenceReferenceBorder), getUFont2(param, FontParam.SEQUENCE_GROUP_HEADER),
stringsToDisplay, param.getHorizontalAlignment(AlignParam.SEQUENCE_REFERENCE_ALIGN), param,
getHtmlColor(param, ColorParam.sequenceReferenceBackground));
2011-04-19 16:50:40 +00:00
}
2010-11-15 20:35:36 +00:00
if (type == ComponentType.TITLE) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseTitle(getUFont2(param, FontParam.SEQUENCE_TITLE), stringsToDisplay, param);
2010-11-15 20:35:36 +00:00
}
if (type == ComponentType.SIGNATURE) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseTitle(fontGrouping.toFont2(HtmlColorUtils.BLACK, param.useUnderlineForHyperlink(),
param.getHyperlinkColor()), Display.create("This skin was created ", "in April 2009."), param);
2010-11-15 20:35:36 +00:00
}
if (type == ComponentType.ENGLOBER) {
2015-05-03 15:36:36 +00:00
return new ComponentRoseEnglober(getSymbolContext(param, ColorParam.sequenceBoxBorder), stringsToDisplay,
getUFont2(param, FontParam.SEQUENCE_BOX), param);
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
2010-11-15 20:35:36 +00:00
return null;
}
2015-05-03 15:36:36 +00:00
private double deltaShadow(ISkinParam param) {
return param.shadowing() ? 4.0 : 0;
}
private SymbolContext getSymbolContext(ISkinParam param, ColorParam color) {
if (color == ColorParam.participantBorder) {
return new SymbolContext(getHtmlColor(param, ColorParam.participantBackground), getHtmlColor(param,
ColorParam.participantBorder)).withStroke(
getStroke(param, LineParam.sequenceParticipantBorder, 1.5)).withDeltaShadow(deltaShadow(param));
}
if (color == ColorParam.actorBorder) {
return new SymbolContext(getHtmlColor(param, ColorParam.actorBackground), getHtmlColor(param,
ColorParam.actorBorder)).withStroke(getStroke(param, LineParam.sequenceActorBorder, 2))
.withDeltaShadow(deltaShadow(param));
}
if (color == ColorParam.sequenceLifeLineBorder) {
return new SymbolContext(getHtmlColor(param, ColorParam.sequenceLifeLineBackground), getHtmlColor(param,
ColorParam.sequenceLifeLineBorder)).withDeltaShadow(deltaShadow(param));
}
if (color == ColorParam.noteBorder) {
return new SymbolContext(getHtmlColor(param, ColorParam.noteBackground), getHtmlColor(param,
ColorParam.noteBorder)).withStroke(getStroke(param, LineParam.noteBorder, 1)).withDeltaShadow(
deltaShadow(param));
}
if (color == ColorParam.sequenceGroupBorder) {
return new SymbolContext(getHtmlColor(param, ColorParam.sequenceGroupBackground), getHtmlColor(param,
ColorParam.sequenceGroupBorder)).withStroke(getStroke(param, LineParam.sequenceGroupBorder, 2))
.withDeltaShadow(deltaShadow(param));
}
if (color == ColorParam.sequenceBoxBorder) {
return new SymbolContext(getHtmlColor(param, ColorParam.sequenceBoxBackground), getHtmlColor(param,
ColorParam.sequenceBoxBorder));
}
if (color == ColorParam.sequenceReferenceBorder) {
return new SymbolContext(getHtmlColor(param, ColorParam.sequenceReferenceHeaderBackground), getHtmlColor(
param, ColorParam.sequenceReferenceBorder)).withStroke(
getStroke(param, LineParam.sequenceReferenceBorder, 2)).withDeltaShadow(deltaShadow(param));
}
throw new IllegalArgumentException();
}
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);
2013-12-10 19:36:50 +00:00
if (result == null) {
return new UStroke(defaultValue);
}
return result;
}
2010-11-15 20:35:36 +00:00
public Object getProtocolVersion() {
return 1;
}
}