plantuml/src/net/sourceforge/plantuml/timingdiagram/ChangeState.java

126 lines
3.6 KiB
Java
Raw Normal View History

2017-02-01 18:55:51 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, Arnaud Roques
2017-02-01 18:55:51 +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
*
2017-02-01 18:55:51 +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.timingdiagram;
2022-02-10 18:16:18 +00:00
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.UseStyle;
2017-03-12 17:22:02 +00:00
import net.sourceforge.plantuml.graphic.SymbolContext;
import net.sourceforge.plantuml.graphic.color.ColorType;
import net.sourceforge.plantuml.graphic.color.Colors;
2022-02-10 18:16:18 +00:00
import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.Style;
2017-03-12 17:22:02 +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.HColorUtils;
2017-03-12 17:22:02 +00:00
2017-02-01 18:55:51 +00:00
public class ChangeState implements Comparable<ChangeState> {
private final TimeTick when;
2019-03-01 22:16:29 +00:00
private final String[] states;
2017-02-15 21:34:36 +00:00
private final String comment;
2017-03-12 17:22:02 +00:00
private final Colors colors;
2017-02-01 18:55:51 +00:00
2019-03-01 22:16:29 +00:00
public ChangeState(TimeTick when, String comment, Colors colors, String... states) {
2022-05-04 17:52:00 +00:00
if (states.length == 0)
2019-03-01 22:16:29 +00:00
throw new IllegalArgumentException();
2022-05-04 17:52:00 +00:00
2017-02-01 18:55:51 +00:00
this.when = when;
2019-03-01 22:16:29 +00:00
this.states = states;
2017-02-15 21:34:36 +00:00
this.comment = comment;
2017-03-12 17:22:02 +00:00
this.colors = colors;
2017-02-01 18:55:51 +00:00
}
public int compareTo(ChangeState other) {
return this.when.compareTo(other.when);
}
public final TimeTick getWhen() {
return when;
}
2019-03-01 22:16:29 +00:00
public final String[] getStates() {
return states;
}
2017-02-01 18:55:51 +00:00
public final String getState() {
2019-03-01 22:16:29 +00:00
return states[0];
2017-02-01 18:55:51 +00:00
}
2017-02-15 21:34:36 +00:00
public String getComment() {
return comment;
}
2022-02-10 18:16:18 +00:00
public final HColor getBackColor(ISkinParam skinParam, Style style) {
2022-05-04 17:52:00 +00:00
if (colors == null || colors.getColor(ColorType.BACK) == null)
2022-02-10 18:16:18 +00:00
return style.value(PName.BackGroundColor).asColor(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet());
2022-05-04 17:52:00 +00:00
2017-03-12 17:22:02 +00:00
return colors.getColor(ColorType.BACK);
}
2022-02-10 18:16:18 +00:00
private final HColor getLineColor(ISkinParam skinParam, Style style) {
2022-05-04 17:52:00 +00:00
if (colors == null || colors.getColor(ColorType.LINE) == null)
2022-02-10 18:16:18 +00:00
return style.value(PName.LineColor).asColor(skinParam.getThemeStyle(), skinParam.getIHtmlColorSet());
2022-05-04 17:52:00 +00:00
2017-03-12 17:22:02 +00:00
return colors.getColor(ColorType.LINE);
}
2022-05-04 17:52:00 +00:00
private UStroke getStroke(Style style) {
return style.getStroke();
}
2022-02-10 18:16:18 +00:00
public SymbolContext getContext(ISkinParam skinParam, Style style) {
return new SymbolContext(getBackColor(skinParam, style), getLineColor(skinParam, style))
2022-05-04 17:52:00 +00:00
.withStroke(getStroke(style));
2017-03-12 17:22:02 +00:00
}
2017-04-05 17:37:42 +00:00
public final boolean isBlank() {
2019-03-01 22:16:29 +00:00
return states[0].equals("{...}");
2017-04-05 17:37:42 +00:00
}
public final boolean isCompletelyHidden() {
2019-03-01 22:16:29 +00:00
return states[0].equals("{hidden}");
2017-03-12 17:22:02 +00:00
}
2019-03-01 22:16:29 +00:00
public final boolean isFlat() {
return states[0].equals("{-}");
}
// public final boolean isUnknown() {
// return states[0].equals("{?}");
// }
2017-02-01 18:55:51 +00:00
}