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

127 lines
4.5 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;
2020-03-18 10:50:02 +00:00
import net.sourceforge.plantuml.ISkinParam;
2018-01-04 22:32:45 +00:00
import net.sourceforge.plantuml.command.Position;
2017-02-01 18:55:51 +00:00
import net.sourceforge.plantuml.cucadiagram.Display;
2022-05-04 17:52:00 +00:00
import net.sourceforge.plantuml.cucadiagram.Stereotype;
2020-03-18 10:50:02 +00:00
import net.sourceforge.plantuml.graphic.FontConfiguration;
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
2017-02-01 18:55:51 +00:00
import net.sourceforge.plantuml.graphic.StringBounder;
2022-02-10 18:16:18 +00:00
import net.sourceforge.plantuml.graphic.SymbolContext;
2020-03-18 10:50:02 +00:00
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.graphic.UDrawable;
2017-03-12 17:22:02 +00:00
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.SName;
import net.sourceforge.plantuml.style.Style;
2022-05-04 17:52:00 +00:00
import net.sourceforge.plantuml.style.StyleSignature;
2022-03-01 18:11:51 +00:00
import net.sourceforge.plantuml.style.StyleSignatureBasic;
2022-02-10 18:16:18 +00:00
import net.sourceforge.plantuml.ugraphic.UStroke;
import net.sourceforge.plantuml.ugraphic.color.HColor;
2018-01-04 22:32:45 +00:00
2020-03-18 10:50:02 +00:00
public abstract class Player implements TimeProjected {
2017-11-20 16:10:36 +00:00
2020-03-18 10:50:02 +00:00
protected final ISkinParam skinParam;
protected final TimingRuler ruler;
2020-04-26 18:31:41 +00:00
private final boolean compact;
2020-03-18 10:50:02 +00:00
private final Display title;
protected int suggestedHeight;
2022-05-04 17:52:00 +00:00
protected final Stereotype stereotype;
2017-02-01 18:55:51 +00:00
2022-05-04 17:52:00 +00:00
public Player(String title, ISkinParam skinParam, TimingRuler ruler, boolean compact, Stereotype stereotype) {
this.stereotype = stereotype;
2020-03-18 10:50:02 +00:00
this.skinParam = skinParam;
2020-04-26 18:31:41 +00:00
this.compact = compact;
2020-03-18 10:50:02 +00:00
this.ruler = ruler;
this.title = Display.getWithNewlines(title);
}
2017-02-01 18:55:51 +00:00
2020-04-26 18:31:41 +00:00
public boolean isCompact() {
return compact;
}
2022-05-04 17:52:00 +00:00
protected abstract StyleSignature getStyleSignature();
2022-02-10 18:16:18 +00:00
final protected Style getStyle() {
return getStyleSignature().getMergedStyle(skinParam.getCurrentStyleBuilder());
}
2020-03-18 10:50:02 +00:00
final protected FontConfiguration getFontConfiguration() {
2022-05-04 17:52:00 +00:00
return FontConfiguration.create(skinParam, StyleSignatureBasic
.of(SName.root, SName.element, SName.timingDiagram).getMergedStyle(skinParam.getCurrentStyleBuilder()));
2022-02-10 18:16:18 +00:00
}
final protected UStroke getStroke() {
final Style style = getStyleSignature().getMergedStyle(skinParam.getCurrentStyleBuilder());
return style.getStroke();
}
final protected SymbolContext getContext() {
final Style style = getStyleSignature().getMergedStyle(skinParam.getCurrentStyleBuilder());
final HColor lineColor = style.value(PName.LineColor).asColor(skinParam.getThemeStyle(),
skinParam.getIHtmlColorSet());
final HColor backgroundColor = style.value(PName.BackGroundColor).asColor(skinParam.getThemeStyle(),
skinParam.getIHtmlColorSet());
return new SymbolContext(backgroundColor, lineColor).withStroke(getStroke());
2020-03-18 10:50:02 +00:00
}
2017-02-01 18:55:51 +00:00
2020-03-18 10:50:02 +00:00
final protected TextBlock getTitle() {
return title.create(getFontConfiguration(), HorizontalAlignment.LEFT, skinParam);
}
2017-02-01 18:55:51 +00:00
2020-03-18 10:50:02 +00:00
public abstract void addNote(TimeTick now, Display note, Position position);
2018-05-06 19:59:19 +00:00
2020-03-18 10:50:02 +00:00
public abstract void defineState(String stateCode, String label);
2017-02-01 18:55:51 +00:00
2020-03-18 10:50:02 +00:00
public abstract void setState(TimeTick now, String comment, Colors color, String... states);
2017-02-15 21:34:36 +00:00
2020-03-18 10:50:02 +00:00
public abstract void createConstraint(TimeTick tick1, TimeTick tick2, String message);
2018-01-04 22:32:45 +00:00
2020-04-26 18:31:41 +00:00
public abstract TextBlock getPart1(double fullAvailableWidth, double specialVSpace);
2020-03-18 10:50:02 +00:00
public abstract UDrawable getPart2();
public abstract double getFullHeight(StringBounder stringBounder);
2018-05-06 19:59:19 +00:00
public final void setHeight(int height) {
this.suggestedHeight = height;
}
2020-04-26 18:31:41 +00:00
2017-02-01 18:55:51 +00:00
}