1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-11 04:32:26 +00:00
plantuml/src/net/sourceforge/plantuml/project/draw/AbstractTaskDraw.java

195 lines
6.3 KiB
Java
Raw Normal View History

2017-02-26 16:26:11 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2023-02-22 18:43:48 +00:00
* (C) Copyright 2009-2024, Arnaud Roques
2017-02-26 16:26:11 +00:00
*
2023-02-22 18:43:48 +00:00
* Project Info: https://plantuml.com
2017-02-26 16:26:11 +00:00
*
2017-03-15 19:13:31 +00:00
* If you like this project or if you find it useful, you can support us at:
*
2023-02-22 18:43:48 +00:00
* https://plantuml.com/patreon (only 1$ per month!)
* https://plantuml.com/paypal
2017-03-15 19:13:31 +00:00
*
2017-02-26 16:26:11 +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
*
*
*/
2020-03-18 10:50:02 +00:00
package net.sourceforge.plantuml.project.draw;
2017-02-26 16:26:11 +00:00
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.color.HColor;
import net.sourceforge.plantuml.klimt.color.HColorSet;
import net.sourceforge.plantuml.klimt.color.HColors;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.creole.Display;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.font.FontConfiguration;
import net.sourceforge.plantuml.klimt.font.StringBounder;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.shape.TextBlock;
2020-08-25 17:24:17 +00:00
import net.sourceforge.plantuml.project.ToTaskDraw;
import net.sourceforge.plantuml.project.core.Task;
import net.sourceforge.plantuml.project.lang.CenterBorderColor;
2020-09-30 20:57:58 +00:00
import net.sourceforge.plantuml.project.time.Day;
2020-03-18 10:50:02 +00:00
import net.sourceforge.plantuml.project.timescale.TimeScale;
2021-06-27 16:50:40 +00:00
import net.sourceforge.plantuml.real.Real;
import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft;
2020-08-25 17:24:17 +00:00
import net.sourceforge.plantuml.style.PName;
2021-08-30 17:13:54 +00:00
import net.sourceforge.plantuml.style.SName;
2020-08-25 17:24:17 +00:00
import net.sourceforge.plantuml.style.Style;
2021-04-07 18:02:23 +00:00
import net.sourceforge.plantuml.style.StyleBuilder;
2023-12-11 17:34:23 +00:00
import net.sourceforge.plantuml.style.StyleSignature;
2022-03-01 18:11:51 +00:00
import net.sourceforge.plantuml.style.StyleSignatureBasic;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.url.Url;
2022-12-17 11:01:10 +00:00
import net.sourceforge.plantuml.utils.Direction;
2020-02-18 21:24:31 +00:00
2020-03-18 10:50:02 +00:00
public abstract class AbstractTaskDraw implements TaskDraw {
2017-02-26 16:26:11 +00:00
2021-07-25 10:41:36 +00:00
private CenterBorderColor colors;
2021-08-30 17:13:54 +00:00
private int completion = 100;
2020-08-25 17:24:17 +00:00
protected Url url;
protected Display note;
2020-03-18 10:50:02 +00:00
protected final TimeScale timeScale;
2021-06-27 16:50:40 +00:00
private Real y;
2020-03-18 10:50:02 +00:00
protected final String prettyDisplay;
2020-09-30 20:57:58 +00:00
protected final Day start;
2021-04-07 18:02:23 +00:00
private final StyleBuilder styleBuilder;
2020-08-25 17:24:17 +00:00
private final Task task;
private final ToTaskDraw toTaskDraw;
2017-02-26 16:26:11 +00:00
2020-09-30 20:57:58 +00:00
@Override
final public String toString() {
return super.toString() + " " + task;
}
2020-08-25 17:24:17 +00:00
final public void setColorsAndCompletion(CenterBorderColor colors, int completion, Url url, Display note) {
this.colors = colors;
this.completion = completion;
this.url = url;
this.note = note;
}
2023-12-11 17:34:23 +00:00
public AbstractTaskDraw(TimeScale timeScale, Real y, String prettyDisplay, Day start, Task task,
ToTaskDraw toTaskDraw, StyleBuilder styleBuilder) {
2020-03-18 10:50:02 +00:00
this.y = y;
2021-04-07 18:02:23 +00:00
this.styleBuilder = styleBuilder;
2020-08-25 17:24:17 +00:00
this.toTaskDraw = toTaskDraw;
2017-02-26 16:26:11 +00:00
this.start = start;
2020-03-18 10:50:02 +00:00
this.prettyDisplay = prettyDisplay;
this.timeScale = timeScale;
2020-08-25 17:24:17 +00:00
this.task = task;
}
2023-12-11 17:34:23 +00:00
abstract StyleSignature getStyleSignature();
2021-04-07 18:02:23 +00:00
2022-03-01 18:11:51 +00:00
private StyleSignatureBasic getStyleSignatureUnstarted() {
return StyleSignatureBasic.of(SName.root, SName.element, SName.ganttDiagram, SName.task, SName.unstarted);
2021-08-30 17:13:54 +00:00
}
2020-08-25 17:24:17 +00:00
final protected HColor getLineColor() {
2021-08-30 17:13:54 +00:00
final HColor unstarted = getStyleSignatureUnstarted().getMergedStyle(styleBuilder).value(PName.LineColor)
2022-09-18 17:08:06 +00:00
.asColor(getColorSet());
2023-02-22 18:43:48 +00:00
final HColor regular = getStyle().value(PName.LineColor).asColor(getColorSet());
2022-08-19 16:34:21 +00:00
return HColors.unlinear(unstarted, regular, completion);
2020-08-25 17:24:17 +00:00
}
final protected HColor getBackgroundColor() {
2021-08-30 17:13:54 +00:00
final HColor unstarted = getStyleSignatureUnstarted().getMergedStyle(styleBuilder).value(PName.BackGroundColor)
2022-09-18 17:08:06 +00:00
.asColor(getColorSet());
2023-02-22 18:43:48 +00:00
final HColor regular = getStyle().value(PName.BackGroundColor).asColor(getColorSet());
2022-08-19 16:34:21 +00:00
return HColors.unlinear(unstarted, regular, completion);
2017-02-26 16:26:11 +00:00
}
2020-08-25 17:24:17 +00:00
final protected FontConfiguration getFontConfiguration() {
2022-09-18 17:08:06 +00:00
return getStyle().getFontConfiguration(getColorSet());
2020-08-25 17:24:17 +00:00
}
2021-04-07 18:02:23 +00:00
final protected Style getStyle() {
return getStyleSignature().getMergedStyle(styleBuilder);
}
2021-05-06 21:23:05 +00:00
final public double getTitleWidth(StringBounder stringBounder) {
final Style style = getStyleSignature().getMergedStyle(getStyleBuilder());
final ClockwiseTopRightBottomLeft margin = style.getMargin();
return margin.getLeft() + getTitle().calculateDimension(stringBounder).getWidth() + margin.getRight();
}
protected abstract TextBlock getTitle();
2020-03-18 10:50:02 +00:00
abstract protected double getShapeHeight(StringBounder stringBounder);
2018-04-06 20:36:30 +00:00
final public double getFullHeightTask(StringBounder stringBounder) {
final Style style = getStyle();
final ClockwiseTopRightBottomLeft margin = style.getMargin();
return margin.getTop() + getShapeHeight(stringBounder) + margin.getBottom();
2017-02-26 16:26:11 +00:00
}
2022-08-24 16:46:33 +00:00
final public TaskDraw getTrueRow() {
2020-09-30 20:57:58 +00:00
return toTaskDraw.getTaskDraw(task.getRow());
}
2021-06-27 16:50:40 +00:00
@Override
final public Real getY(StringBounder stringBounder) {
2022-08-24 16:46:33 +00:00
if (task.getRow() == null)
2020-08-25 17:24:17 +00:00
return y;
2022-08-24 16:46:33 +00:00
2021-04-07 18:02:23 +00:00
return getTrueRow().getY(stringBounder);
2020-09-30 20:57:58 +00:00
}
2020-08-25 17:24:17 +00:00
public final Task getTask() {
return task;
}
2021-06-27 16:50:40 +00:00
@Override
2021-04-07 18:02:23 +00:00
public final double getY(StringBounder stringBounder, Direction direction) {
final Style style = getStyle();
final ClockwiseTopRightBottomLeft margin = style.getMargin();
final ClockwiseTopRightBottomLeft padding = style.getPadding();
2021-06-27 16:50:40 +00:00
final double y1 = margin.getTop() + getY(stringBounder).getCurrentValue();
final double y2 = y1 + getShapeHeight(stringBounder);
2022-08-24 16:46:33 +00:00
if (direction == Direction.UP)
return y1;
2022-08-24 16:46:33 +00:00
if (direction == Direction.DOWN)
return y2;
2022-08-24 16:46:33 +00:00
return (y1 + y2) / 2;
2021-04-07 18:02:23 +00:00
}
protected final StyleBuilder getStyleBuilder() {
return styleBuilder;
}
protected final HColorSet getColorSet() {
2022-08-18 16:55:09 +00:00
return toTaskDraw.getIHtmlColorSet();
2017-11-20 16:10:36 +00:00
}
2021-07-25 10:41:36 +00:00
protected CenterBorderColor getColors() {
return colors;
}
2021-08-30 17:13:54 +00:00
protected int getCompletion() {
return completion;
}
2017-02-26 16:26:11 +00:00
}