1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-21 09:32:20 +00:00
plantuml/src/net/sourceforge/plantuml/skin/rose/Rose.java

287 lines
15 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* 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
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 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.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
2011-04-19 16:50:40 +00:00
* Revision $Revision: 6476 $
2010-11-15 20:35:36 +00:00
*
*/
package net.sourceforge.plantuml.skin.rose;
import java.awt.Color;
import java.awt.Font;
import java.util.Arrays;
import java.util.EnumMap;
import java.util.List;
import java.util.Map;
import net.sourceforge.plantuml.ColorParam;
import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.graphic.HtmlColor;
import net.sourceforge.plantuml.skin.Component;
import net.sourceforge.plantuml.skin.ComponentType;
import net.sourceforge.plantuml.skin.Skin;
public class Rose implements Skin {
private final Map<ColorParam, HtmlColor> defaultsColor = new EnumMap<ColorParam, HtmlColor>(ColorParam.class);
public Rose() {
2011-01-23 19:36:52 +00:00
defaultsColor.put(ColorParam.background, HtmlColor.getColorIfValid("white"));
defaultsColor.put(ColorParam.sequenceArrow, HtmlColor.getColorIfValid("#A80036"));
defaultsColor.put(ColorParam.usecaseArrow, HtmlColor.getColorIfValid("#A80036"));
defaultsColor.put(ColorParam.classArrow, HtmlColor.getColorIfValid("#A80036"));
defaultsColor.put(ColorParam.objectArrow, HtmlColor.getColorIfValid("#A80036"));
defaultsColor.put(ColorParam.activityArrow, HtmlColor.getColorIfValid("#A80036"));
defaultsColor.put(ColorParam.componentArrow, HtmlColor.getColorIfValid("#A80036"));
defaultsColor.put(ColorParam.stateArrow, HtmlColor.getColorIfValid("#A80036"));
defaultsColor.put(ColorParam.sequenceLifeLineBackground, HtmlColor.getColorIfValid("white"));
defaultsColor.put(ColorParam.sequenceLifeLineBorder, HtmlColor.getColorIfValid("#A80036"));
defaultsColor.put(ColorParam.sequenceGroupBackground, HtmlColor.getColorIfValid("#EEEEEE"));
2011-04-19 16:50:40 +00:00
defaultsColor.put(ColorParam.sequenceGroupBorder, HtmlColor.getColorIfValid("black"));
2011-01-23 19:36:52 +00:00
defaultsColor.put(ColorParam.sequenceDividerBackground, HtmlColor.getColorIfValid("#EEEEEE"));
2011-04-19 16:50:40 +00:00
defaultsColor.put(ColorParam.sequenceReferenceBackground, HtmlColor.getColorIfValid("#EEEEEE"));
defaultsColor.put(ColorParam.sequenceBoxBorder, HtmlColor.getColorIfValid("#A80036"));
defaultsColor.put(ColorParam.sequenceBoxBackground, HtmlColor.getColorIfValid("#DDDDDD"));
2011-01-23 19:36:52 +00:00
defaultsColor.put(ColorParam.noteBackground, HtmlColor.getColorIfValid("#FBFB77"));
defaultsColor.put(ColorParam.noteBorder, HtmlColor.getColorIfValid("#A80036"));
defaultsColor.put(ColorParam.activityBackground, HtmlColor.getColorIfValid("#FEFECE"));
defaultsColor.put(ColorParam.activityBorder, HtmlColor.getColorIfValid("#A80036"));
defaultsColor.put(ColorParam.activityStart, HtmlColor.getColorIfValid("black"));
defaultsColor.put(ColorParam.activityEnd, HtmlColor.getColorIfValid("black"));
defaultsColor.put(ColorParam.activityBar, HtmlColor.getColorIfValid("black"));
defaultsColor.put(ColorParam.stateBackground, HtmlColor.getColorIfValid("#FEFECE"));
defaultsColor.put(ColorParam.stateBorder, HtmlColor.getColorIfValid("#A80036"));
defaultsColor.put(ColorParam.stateStart, HtmlColor.getColorIfValid("black"));
defaultsColor.put(ColorParam.stateEnd, HtmlColor.getColorIfValid("black"));
defaultsColor.put(ColorParam.usecaseBackground, HtmlColor.getColorIfValid("#FEFECE"));
defaultsColor.put(ColorParam.usecaseBorder, HtmlColor.getColorIfValid("#A80036"));
defaultsColor.put(ColorParam.componentBackground, HtmlColor.getColorIfValid("#FEFECE"));
defaultsColor.put(ColorParam.componentBorder, HtmlColor.getColorIfValid("#A80036"));
defaultsColor.put(ColorParam.componentInterfaceBackground, HtmlColor.getColorIfValid("#FEFECE"));
defaultsColor.put(ColorParam.componentInterfaceBorder, HtmlColor.getColorIfValid("#A80036"));
defaultsColor.put(ColorParam.usecaseActorBackground, HtmlColor.getColorIfValid("#FEFECE"));
defaultsColor.put(ColorParam.usecaseActorBorder, HtmlColor.getColorIfValid("#A80036"));
defaultsColor.put(ColorParam.sequenceActorBackground, HtmlColor.getColorIfValid("#FEFECE"));
defaultsColor.put(ColorParam.sequenceActorBorder, HtmlColor.getColorIfValid("#A80036"));
defaultsColor.put(ColorParam.sequenceParticipantBackground, HtmlColor.getColorIfValid("#FEFECE"));
defaultsColor.put(ColorParam.sequenceParticipantBorder, HtmlColor.getColorIfValid("#A80036"));
defaultsColor.put(ColorParam.classBackground, HtmlColor.getColorIfValid("#FEFECE"));
defaultsColor.put(ColorParam.classBorder, HtmlColor.getColorIfValid("#A80036"));
defaultsColor.put(ColorParam.objectBackground, HtmlColor.getColorIfValid("#FEFECE"));
defaultsColor.put(ColorParam.objectBorder, HtmlColor.getColorIfValid("#A80036"));
defaultsColor.put(ColorParam.stereotypeCBackground, HtmlColor.getColorIfValid("#ADD1B2"));
defaultsColor.put(ColorParam.stereotypeABackground, HtmlColor.getColorIfValid("#A9DCDF"));
defaultsColor.put(ColorParam.stereotypeIBackground, HtmlColor.getColorIfValid("#B4A7E5"));
defaultsColor.put(ColorParam.stereotypeEBackground, HtmlColor.getColorIfValid("#EB937F"));
defaultsColor.put(ColorParam.packageBackground, HtmlColor.getColorIfValid("#FEFECE"));
defaultsColor.put(ColorParam.packageBorder, HtmlColor.getColorIfValid("black"));
defaultsColor.put(ColorParam.iconPrivate, HtmlColor.getColorIfValid("#C82930"));
defaultsColor.put(ColorParam.iconPrivateBackground, HtmlColor.getColorIfValid("#F24D5C"));
defaultsColor.put(ColorParam.iconProtected, HtmlColor.getColorIfValid("#B38D22"));
defaultsColor.put(ColorParam.iconProtectedBackground, HtmlColor.getColorIfValid("#FFFF44"));
defaultsColor.put(ColorParam.iconPackage, HtmlColor.getColorIfValid("#1963A0"));
defaultsColor.put(ColorParam.iconPackageBackground, HtmlColor.getColorIfValid("#4177AF"));
defaultsColor.put(ColorParam.iconPublic, HtmlColor.getColorIfValid("#038048"));
defaultsColor.put(ColorParam.iconPublicBackground, HtmlColor.getColorIfValid("#84BE84"));
2010-11-15 20:35:36 +00:00
}
public Color getFontColor(ISkinParam skin, FontParam fontParam) {
2011-01-05 18:23:06 +00:00
return skin.getFontHtmlColor(fontParam, null).getColor();
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);
}
public HtmlColor getHtmlColor(ISkinParam param, ColorParam color, String stereotype) {
HtmlColor result = param.getHtmlColor(color, stereotype);
2010-11-15 20:35:36 +00:00
if (result == null) {
result = defaultsColor.get(color);
if (result == null) {
throw new IllegalArgumentException();
}
}
return result;
}
public Component createComponent(ComponentType type, ISkinParam param, List<? extends CharSequence> stringsToDisplay) {
final Color background = param.getBackgroundColor().getColor();
2011-04-19 16:50:40 +00:00
final Color groupBorder = getHtmlColor(param, ColorParam.sequenceGroupBorder).getColor();
final Color groupBackground = getHtmlColor(param, ColorParam.sequenceGroupBackground).getColor();
2010-11-15 20:35:36 +00:00
final Color sequenceDividerBackground = getHtmlColor(param, ColorParam.sequenceDividerBackground).getColor();
2011-04-19 16:50:40 +00:00
final Color sequenceReferenceBackground = getHtmlColor(param, ColorParam.sequenceReferenceBackground)
.getColor();
2010-11-15 20:35:36 +00:00
final Color lifeLineBackgroundColor = getHtmlColor(param, ColorParam.sequenceLifeLineBackground).getColor();
final Color sequenceArrow = getHtmlColor(param, ColorParam.sequenceArrow).getColor();
final Color sequenceActorBackground = getHtmlColor(param, ColorParam.sequenceActorBackground).getColor();
final Color sequenceParticipantBackground = getHtmlColor(param, ColorParam.sequenceParticipantBackground)
.getColor();
// final Color borderColor = getHtmlColor(param,
// ColorParam.border).getColor();
2011-01-05 18:23:06 +00:00
final Font fontArrow = param.getFont(FontParam.SEQUENCE_ARROW, null);
2011-04-19 16:50:40 +00:00
final Font fontGrouping = param.getFont(FontParam.SEQUENCE_GROUP, null);
2011-01-05 18:23:06 +00:00
final Font fontParticipant = param.getFont(FontParam.SEQUENCE_PARTICIPANT, null);
final Font fontActor = param.getFont(FontParam.SEQUENCE_ACTOR, null);
2010-11-15 20:35:36 +00:00
2011-01-11 07:42:49 +00:00
if (type.isArrow()) {
if (type.getArrowConfiguration().isSelfArrow()) {
return new ComponentRoseSelfArrow(sequenceArrow, getFontColor(param, FontParam.SEQUENCE_ARROW),
fontArrow, stringsToDisplay, type.getArrowConfiguration());
}
2010-11-15 20:35:36 +00:00
return new ComponentRoseArrow(sequenceArrow, getFontColor(param, FontParam.SEQUENCE_ARROW), fontArrow,
2011-01-11 07:42:49 +00:00
stringsToDisplay, type.getArrowConfiguration());
2010-11-15 20:35:36 +00:00
}
if (type == ComponentType.PARTICIPANT_HEAD) {
final Color borderColor = getHtmlColor(param, ColorParam.sequenceParticipantBorder).getColor();
return new ComponentRoseParticipant(sequenceParticipantBackground, borderColor, getFontColor(param,
FontParam.SEQUENCE_PARTICIPANT), fontParticipant, stringsToDisplay);
}
if (type == ComponentType.PARTICIPANT_TAIL) {
final Color borderColor = getHtmlColor(param, ColorParam.sequenceParticipantBorder).getColor();
return new ComponentRoseParticipant(sequenceParticipantBackground, borderColor, getFontColor(param,
FontParam.SEQUENCE_PARTICIPANT), fontParticipant, stringsToDisplay);
}
if (type == ComponentType.PARTICIPANT_LINE) {
final Color borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder).getColor();
2011-01-23 19:36:52 +00:00
return new ComponentRoseLine(borderColor, false);
}
if (type == ComponentType.CONTINUE_LINE) {
final Color borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder).getColor();
return new ComponentRoseLine(borderColor, true);
2010-11-15 20:35:36 +00:00
}
if (type == ComponentType.ACTOR_HEAD) {
final Color borderColor = getHtmlColor(param, ColorParam.sequenceActorBorder).getColor();
return new ComponentRoseActor(sequenceActorBackground, borderColor, getFontColor(param,
FontParam.SEQUENCE_ACTOR), fontActor, stringsToDisplay, true);
}
if (type == ComponentType.ACTOR_TAIL) {
final Color borderColor = getHtmlColor(param, ColorParam.sequenceActorBorder).getColor();
return new ComponentRoseActor(sequenceActorBackground, borderColor, getFontColor(param,
FontParam.SEQUENCE_ACTOR), fontActor, stringsToDisplay, false);
}
if (type == ComponentType.NOTE) {
final Color noteBackgroundColor = getHtmlColor(param, ColorParam.noteBackground).getColor();
final Color borderColor = getHtmlColor(param, ColorParam.noteBorder).getColor();
2011-01-05 18:23:06 +00:00
final Font fontNote = param.getFont(FontParam.NOTE, null);
2010-11-15 20:35:36 +00:00
return new ComponentRoseNote(noteBackgroundColor, borderColor, getFontColor(param, FontParam.NOTE),
fontNote, stringsToDisplay);
}
if (type == ComponentType.GROUPING_HEADER) {
2011-04-19 16:50:40 +00:00
final Font fontGroupingHeader = param.getFont(FontParam.SEQUENCE_GROUP_HEADER, null);
return new ComponentRoseGroupingHeader(getFontColor(param, FontParam.SEQUENCE_GROUP_HEADER), background,
groupBackground, groupBorder, fontGroupingHeader, fontGrouping, stringsToDisplay);
2010-11-15 20:35:36 +00:00
}
if (type == ComponentType.GROUPING_BODY) {
2011-04-19 16:50:40 +00:00
return new ComponentRoseGroupingBody(background, groupBorder);
2010-11-15 20:35:36 +00:00
}
if (type == ComponentType.GROUPING_TAIL) {
2011-04-19 16:50:40 +00:00
return new ComponentRoseGroupingTail(getFontColor(param, FontParam.SEQUENCE_GROUP), groupBorder);
2010-11-15 20:35:36 +00:00
}
if (type == ComponentType.GROUPING_ELSE) {
2011-04-19 16:50:40 +00:00
return new ComponentRoseGroupingElse(getFontColor(param, FontParam.SEQUENCE_GROUP), groupBorder,
fontGrouping, stringsToDisplay.get(0));
2010-11-15 20:35:36 +00:00
}
2011-01-29 15:09:35 +00:00
if (type == ComponentType.ALIVE_BOX_CLOSE_CLOSE) {
2010-11-15 20:35:36 +00:00
final Color borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder).getColor();
2011-01-29 15:09:35 +00:00
return new ComponentRoseActiveLine(borderColor, lifeLineBackgroundColor, true, true);
}
if (type == ComponentType.ALIVE_BOX_CLOSE_OPEN) {
final Color borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder).getColor();
return new ComponentRoseActiveLine(borderColor, lifeLineBackgroundColor, true, false);
}
if (type == ComponentType.ALIVE_BOX_OPEN_CLOSE) {
final Color borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder).getColor();
return new ComponentRoseActiveLine(borderColor, lifeLineBackgroundColor, false, true);
}
if (type == ComponentType.ALIVE_BOX_OPEN_OPEN) {
final Color borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder).getColor();
return new ComponentRoseActiveLine(borderColor, lifeLineBackgroundColor, false, false);
2010-11-15 20:35:36 +00:00
}
2011-01-12 19:06:53 +00:00
if (type == ComponentType.DELAY_LINE) {
2011-01-23 19:36:52 +00:00
final Color borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder).getColor();
2011-04-19 16:50:40 +00:00
// final Color borderColor = getFontColor(param,
// FontParam.SEQUENCE_DELAY);
2011-01-12 19:06:53 +00:00
return new ComponentRoseDelayLine(borderColor);
}
if (type == ComponentType.DELAY_TEXT) {
return new ComponentRoseDelayText(getFontColor(param, FontParam.SEQUENCE_DELAY), param.getFont(
FontParam.SEQUENCE_DELAY, null), stringsToDisplay);
}
2010-11-15 20:35:36 +00:00
if (type == ComponentType.DESTROY) {
final Color borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder).getColor();
return new ComponentRoseDestroy(borderColor);
}
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) {
2011-01-11 07:42:49 +00:00
return new ComponentRoseDivider(getFontColor(param, FontParam.SEQUENCE_DIVIDER), param.getFont(
FontParam.SEQUENCE_DIVIDER, null), sequenceDividerBackground, stringsToDisplay);
2010-11-15 20:35:36 +00:00
}
2011-04-19 16:50:40 +00:00
if (type == ComponentType.REFERENCE) {
return new ComponentRoseReference(getFontColor(param, FontParam.SEQUENCE_REFERENCE), param.getFont(
FontParam.SEQUENCE_REFERENCE, null), sequenceReferenceBackground, stringsToDisplay);
}
2010-11-15 20:35:36 +00:00
if (type == ComponentType.TITLE) {
2011-01-11 07:42:49 +00:00
return new ComponentRoseTitle(getFontColor(param, FontParam.SEQUENCE_TITLE), param.getFont(
FontParam.SEQUENCE_TITLE, null), stringsToDisplay);
2010-11-15 20:35:36 +00:00
}
if (type == ComponentType.SIGNATURE) {
return new ComponentRoseTitle(Color.BLACK, fontGrouping, Arrays.asList("This skin was created ",
"in April 2009."));
}
if (type == ComponentType.ENGLOBER) {
2011-04-19 16:50:40 +00:00
final Color borderColor = getHtmlColor(param, ColorParam.sequenceBoxBorder).getColor();
final Color backColor = getHtmlColor(param, ColorParam.sequenceBoxBackground).getColor();
2010-11-15 20:35:36 +00:00
return new ComponentRoseEnglober(borderColor, backColor, stringsToDisplay, getFontColor(param,
2011-04-19 16:50:40 +00:00
FontParam.SEQUENCE_BOX), param.getFont(FontParam.SEQUENCE_BOX, null));
2010-11-15 20:35:36 +00:00
}
return null;
}
public Object getProtocolVersion() {
return 1;
}
}