1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-02 00:20:49 +00:00
plantuml/src/net/sourceforge/plantuml/graphic/Rainbow.java

145 lines
4.0 KiB
Java
Raw Normal View History

2016-05-11 21:31:47 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2019-01-16 18:34:41 +00:00
* (C) Copyright 2009-2020, Arnaud Roques
2016-05-11 21:31:47 +00:00
*
* Project Info: http://plantuml.com
*
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
*
2016-05-11 21:31:47 +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
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
*
* Original Author: Arnaud Roques
*
*
*/
package net.sourceforge.plantuml.graphic;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
2019-08-26 17:07:21 +00:00
import net.sourceforge.plantuml.ColorParam;
2016-05-11 21:31:47 +00:00
import net.sourceforge.plantuml.ISkinParam;
2019-08-26 17:07:21 +00:00
import net.sourceforge.plantuml.SkinParam;
import net.sourceforge.plantuml.skin.rose.Rose;
import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.Style;
2020-03-18 10:50:02 +00:00
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorSet;
2016-05-11 21:31:47 +00:00
public class Rainbow {
2019-08-26 17:07:21 +00:00
private final static Rose rose = new Rose();
2016-05-11 21:31:47 +00:00
private final List<HtmlColorAndStyle> colors = new ArrayList<HtmlColorAndStyle>();
private final int colorArrowSeparationSpace;
private Rainbow(int colorArrowSeparationSpace) {
this.colorArrowSeparationSpace = colorArrowSeparationSpace;
}
2018-12-22 11:11:40 +00:00
2016-05-31 19:41:55 +00:00
@Override
public String toString() {
return colors.toString();
}
2016-05-11 21:31:47 +00:00
public static Rainbow none() {
return new Rainbow(0);
}
2020-04-26 18:31:41 +00:00
public static Rainbow fromColor(HColor arrowColor, HColor arrowHeadColor) {
if (arrowColor == null) {
2019-08-26 17:07:21 +00:00
return Rainbow.none();
}
2020-04-26 18:31:41 +00:00
return Rainbow.build(new HtmlColorAndStyle(arrowColor, arrowHeadColor));
2019-08-26 17:07:21 +00:00
}
public static Rainbow build(ISkinParam skinParam) {
if (SkinParam.USE_STYLES()) {
throw new IllegalStateException();
}
2020-04-26 18:31:41 +00:00
final HColor arrow = rose.getHtmlColor(skinParam, ColorParam.arrow);
final HColor arrowHead = rose.getHtmlColor(skinParam, null, ColorParam.arrowHead, ColorParam.arrow);
return fromColor(arrow, arrowHead);
2019-08-26 17:07:21 +00:00
}
2020-03-18 10:50:02 +00:00
public static Rainbow build(Style style, HColorSet set) {
final HColor color = style.value(PName.LineColor).asColor(set);
2020-04-26 18:31:41 +00:00
return fromColor(color, null);
2019-08-26 17:07:21 +00:00
}
2016-05-11 21:31:47 +00:00
public Rainbow withDefault(Rainbow defaultColor) {
if (this.size() == 0) {
return defaultColor;
}
return this;
}
public static Rainbow build(HtmlColorAndStyle color) {
if (color == null) {
throw new IllegalArgumentException();
}
final Rainbow result = new Rainbow(0);
result.colors.add(color);
return result;
}
2018-12-22 11:11:40 +00:00
2016-05-11 21:31:47 +00:00
public static Rainbow build(ISkinParam skinParam, String colorString, int colorArrowSeparationSpace) {
if (colorString == null) {
return Rainbow.none();
}
final Rainbow result = new Rainbow(colorArrowSeparationSpace);
for (String s : colorString.split(";")) {
result.colors.add(HtmlColorAndStyle.build(skinParam, s));
}
return result;
}
2018-12-22 11:11:40 +00:00
public boolean isInvisible() {
for (HtmlColorAndStyle style : colors) {
if (style.getStyle().isInvisible()) {
return true;
}
}
return false;
}
2016-05-11 21:31:47 +00:00
public List<HtmlColorAndStyle> getColors() {
return Collections.unmodifiableList(colors);
}
2020-03-18 10:50:02 +00:00
public HColor getColor() {
2020-04-26 18:31:41 +00:00
return colors.get(0).getArrowColor();
2016-05-11 21:31:47 +00:00
}
public int getColorArrowSeparationSpace() {
return colorArrowSeparationSpace;
}
public int size() {
return colors.size();
}
}