From 7cc8c823de644a510fcc434f39b53e5fffe66bfd Mon Sep 17 00:00:00 2001 From: Andrej Shadura Date: Tue, 10 Mar 2020 16:38:20 +0100 Subject: New upstream version 1.2020.2 --- .../plantuml/project/draw/ResourceDraw.java | 122 +++++++++++++ .../plantuml/project/draw/TaskDraw.java | 56 ++++++ .../plantuml/project/draw/TaskDrawRegular.java | 202 +++++++++++++++++++++ .../plantuml/project/draw/TaskDrawSeparator.java | 133 ++++++++++++++ .../plantuml/project/draw/TimeHeader.java | 113 ++++++++++++ .../plantuml/project/draw/TimeHeaderDaily.java | 188 +++++++++++++++++++ .../plantuml/project/draw/TimeHeaderSimple.java | 97 ++++++++++ .../plantuml/project/draw/TimeHeaderWeekly.java | 188 +++++++++++++++++++ 8 files changed, 1099 insertions(+) create mode 100644 src/net/sourceforge/plantuml/project/draw/ResourceDraw.java create mode 100644 src/net/sourceforge/plantuml/project/draw/TaskDraw.java create mode 100644 src/net/sourceforge/plantuml/project/draw/TaskDrawRegular.java create mode 100644 src/net/sourceforge/plantuml/project/draw/TaskDrawSeparator.java create mode 100644 src/net/sourceforge/plantuml/project/draw/TimeHeader.java create mode 100644 src/net/sourceforge/plantuml/project/draw/TimeHeaderDaily.java create mode 100644 src/net/sourceforge/plantuml/project/draw/TimeHeaderSimple.java create mode 100644 src/net/sourceforge/plantuml/project/draw/TimeHeaderWeekly.java (limited to 'src/net/sourceforge/plantuml/project/draw') diff --git a/src/net/sourceforge/plantuml/project/draw/ResourceDraw.java b/src/net/sourceforge/plantuml/project/draw/ResourceDraw.java new file mode 100644 index 0000000..e95c350 --- /dev/null +++ b/src/net/sourceforge/plantuml/project/draw/ResourceDraw.java @@ -0,0 +1,122 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2020, Arnaud Roques + * + * Project Info: http://plantuml.com + * + * 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 + * + * 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.project.draw; + +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.UDrawable; +import net.sourceforge.plantuml.project.GanttDiagram; +import net.sourceforge.plantuml.project.core.Resource; +import net.sourceforge.plantuml.project.core.Wink; +import net.sourceforge.plantuml.project.timescale.TimeScale; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class ResourceDraw implements UDrawable { + + private final Resource res; + private final TimeScale timeScale; + private final double y; + private final Wink min; + private final Wink max; + private final GanttDiagram gantt; + + public ResourceDraw(GanttDiagram gantt, Resource res, TimeScale timeScale, double y, Wink min, Wink max) { + this.res = res; + this.timeScale = timeScale; + this.y = y; + this.min = min; + this.max = max; + this.gantt = gantt; + } + + public void drawU(UGraphic ug) { + final TextBlock title = Display.getWithNewlines(res.getName()).create(getFontConfiguration(13), + HorizontalAlignment.LEFT, new SpriteContainerEmpty()); + title.drawU(ug); + final ULine line = new ULine(timeScale.getEndingPosition(max) - timeScale.getStartingPosition(min), 0); + ug.apply(new UChangeColor(HtmlColorUtils.BLACK)) + .apply(new UTranslate(0, title.calculateDimension(ug.getStringBounder()).getHeight())).draw(line); + for (Wink i = min; i.compareTo(max) <= 0; i = i.increment()) { + final int load = gantt.getLoadForResource(res, i); + if (load > 0) { + final FontConfiguration fontConfiguration = getFontConfiguration(9, load > 100 ? HtmlColorUtils.RED + : HtmlColorUtils.BLACK); + final TextBlock value = Display.getWithNewlines("" + load).create(fontConfiguration, + HorizontalAlignment.LEFT, new SpriteContainerEmpty()); + final double start = (timeScale.getStartingPosition(i) + timeScale.getEndingPosition(i)) / 2 + - value.calculateDimension(ug.getStringBounder()).getWidth() / 2; + value.drawU(ug.apply(new UTranslate(start, 16))); + } + + } + + } + + private FontConfiguration getFontConfiguration(int size) { + return getFontConfiguration(size, HtmlColorUtils.BLACK); + } + + private FontConfiguration getFontConfiguration(int size, HtmlColor color) { + final UFont font = UFont.serif(size); + return new FontConfiguration(font, color, color, false); + } + + // public void setColors(ComplementColors colors); + // + // public double getY(); + // + // public double getY(Direction direction); + // + // public void drawTitle(UGraphic ug); + + public double getHeight() { + return 16 * 2; + } + + public double getY() { + return y; + } + +} diff --git a/src/net/sourceforge/plantuml/project/draw/TaskDraw.java b/src/net/sourceforge/plantuml/project/draw/TaskDraw.java new file mode 100644 index 0000000..814c33b --- /dev/null +++ b/src/net/sourceforge/plantuml/project/draw/TaskDraw.java @@ -0,0 +1,56 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2020, Arnaud Roques + * + * Project Info: http://plantuml.com + * + * 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 + * + * 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.project.draw; + +import net.sourceforge.plantuml.Direction; +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.graphic.UDrawable; +import net.sourceforge.plantuml.project.lang.ComplementColors; +import net.sourceforge.plantuml.ugraphic.UGraphic; + +public interface TaskDraw extends UDrawable { + + public void setColorsAndCompletion(ComplementColors colors, int completion, Url url); + + public double getY(); + + public double getY(Direction direction); + + public void drawTitle(UGraphic ug); + + public double getHeight(); + +} diff --git a/src/net/sourceforge/plantuml/project/draw/TaskDrawRegular.java b/src/net/sourceforge/plantuml/project/draw/TaskDrawRegular.java new file mode 100644 index 0000000..d3e6063 --- /dev/null +++ b/src/net/sourceforge/plantuml/project/draw/TaskDrawRegular.java @@ -0,0 +1,202 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2020, Arnaud Roques + * + * Project Info: http://plantuml.com + * + * 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 + * + * 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.project.draw; + +import net.sourceforge.plantuml.Direction; +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorSetSimple; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.project.core.TaskImpl; +import net.sourceforge.plantuml.project.core.Wink; +import net.sourceforge.plantuml.project.lang.ComplementColors; +import net.sourceforge.plantuml.project.timescale.TimeScale; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UPolygon; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UShape; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class TaskDrawRegular implements TaskDraw { + + // private static final HtmlColor defaultColor = HtmlColorUtils.COL_84BE84; + private static final HtmlColor defaultColor = new HtmlColorSetSimple().getColorIfValid("GreenYellow"); + private final TaskImpl task; + private final TimeScale timeScale; + private final double y; + private ComplementColors colors; + private int completion = 100; + private Url url; + + private final double margin = 2; + + public TaskDrawRegular(TaskImpl task, TimeScale timeScale, double y) { + this.y = y; + this.task = task; + this.timeScale = timeScale; + } + + public void drawTitle(UGraphic ug) { + final TextBlock title = Display.getWithNewlines(task.getPrettyDisplay()).create(getFontConfiguration(), + HorizontalAlignment.LEFT, new SpriteContainerEmpty()); + final double titleHeight = title.calculateDimension(ug.getStringBounder()).getHeight(); + final double h = (margin + getShapeHeight() - titleHeight) / 2; + final double endingPosition; + if (isDiamond()) { + endingPosition = timeScale.getStartingPosition(task.getStart()) + getHeight(); + } else { + endingPosition = timeScale.getEndingPosition(task.getStart()); + } + title.drawU(ug.apply(new UTranslate(endingPosition, h))); + } + + private FontConfiguration getFontConfiguration() { + final UFont font = UFont.serif(11); + return new FontConfiguration(font, HtmlColorUtils.BLACK, HtmlColorUtils.BLACK, false); + } + + public void drawU(UGraphic ug1) { + final double start = timeScale.getStartingPosition(task.getStart()); + ug1 = applyColors(ug1); + UGraphic ug2 = ug1.apply(new UTranslate(start + margin, margin)); + drawShape(ug2); + } + + private UGraphic applyColors(UGraphic ug) { + if (colors != null && colors.isOk()) { + return colors.apply(ug); + } + if (isDiamond()) { + return ug.apply(new UChangeColor(HtmlColorUtils.BLACK)).apply(new UChangeBackColor(HtmlColorUtils.BLACK)); + } + return ug.apply(new UChangeColor(HtmlColorUtils.BLUE)).apply(new UChangeBackColor(defaultColor)); + } + + private void drawShape(UGraphic ug) { + if (isDiamond()) { + ug.draw(getDiamond()); + return; + } + final Wink instantStart = task.getStart(); + final Wink instantEnd = task.getEnd(); + final double start = timeScale.getStartingPosition(instantStart); + final double end = timeScale.getEndingPosition(instantEnd); + + final double fullLength = end - start - 2 * margin; + if (fullLength < 10) { + return; + } + if (url != null) { + ug.startUrl(url); + } + final URectangle full = new URectangle(fullLength, getShapeHeight(), 8, 8); + if (completion == 100) { + ug.draw(full); + } else { + final double partialLength = fullLength * completion / 100.; + ug.apply(new UChangeColor(HtmlColorUtils.WHITE)).apply(new UChangeBackColor(HtmlColorUtils.WHITE)) + .draw(full); + if (partialLength > 2) { + final URectangle partial = new URectangle(partialLength, getShapeHeight(), 8, 8); + ug.apply(new UChangeColor(null)).draw(partial); + } + if (partialLength > 10 && partialLength < fullLength - 10) { + final URectangle patch = new URectangle(8, getShapeHeight()); + ug.apply(new UChangeColor(null)).apply(new UTranslate(partialLength - 8, 0)).draw(patch); + } + ug.apply(new UChangeBackColor(null)).draw(full); + } + if (url != null) { + ug.closeAction(); + } + + } + + private double getShapeHeight() { + return getHeight() - 2 * margin; + } + + private boolean isDiamond() { + if (task.isDiamond()) { + final Wink instantStart = task.getStart(); + final Wink instantEnd = task.getEnd(); + return instantStart.compareTo(instantEnd) == 0; + } + return false; + } + + private UShape getDiamond() { + final double h = getHeight() - 2 * margin; + final UPolygon result = new UPolygon(); + result.addPoint(h / 2, 0); + result.addPoint(h, h / 2); + result.addPoint(h / 2, h); + result.addPoint(0, h / 2); + return result; + } + + public double getHeight() { + return 16; + } + + public double getY() { + return y; + } + + public double getY(Direction direction) { + if (direction == Direction.UP) { + return y; + } + if (direction == Direction.DOWN) { + return y + getHeight(); + } + return y + getHeight() / 2; + } + + public void setColorsAndCompletion(ComplementColors colors, int completion, Url url) { + this.colors = colors; + this.completion = completion; + this.url = url; + } +} diff --git a/src/net/sourceforge/plantuml/project/draw/TaskDrawSeparator.java b/src/net/sourceforge/plantuml/project/draw/TaskDrawSeparator.java new file mode 100644 index 0000000..6e88d95 --- /dev/null +++ b/src/net/sourceforge/plantuml/project/draw/TaskDrawSeparator.java @@ -0,0 +1,133 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2020, Arnaud Roques + * + * Project Info: http://plantuml.com + * + * 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 + * + * 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.project.draw; + +import net.sourceforge.plantuml.Direction; +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.project.core.TaskSeparator; +import net.sourceforge.plantuml.project.core.Wink; +import net.sourceforge.plantuml.project.lang.ComplementColors; +import net.sourceforge.plantuml.project.timescale.TimeScale; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class TaskDrawSeparator implements TaskDraw { + + private final TimeScale timeScale; + private final double y; + private final Wink min; + private final Wink max; + private final String name; + + public TaskDrawSeparator(TaskSeparator task, TimeScale timeScale, double y, Wink min, Wink max) { + this.name = task.getName(); + this.y = y; + this.timeScale = timeScale; + this.min = min; + this.max = max; + } + + public void drawTitle(UGraphic ug) { + getTitle().drawU(ug.apply(new UTranslate(MARGIN1, 0))); + } + + private TextBlock getTitle() { + if (name == null) { + return TextBlockUtils.empty(0, 0); + } + return Display.getWithNewlines(this.name).create(getFontConfiguration(), HorizontalAlignment.LEFT, + new SpriteContainerEmpty()); + } + + private FontConfiguration getFontConfiguration() { + final UFont font = UFont.serif(11); + return new FontConfiguration(font, HtmlColorUtils.BLACK, HtmlColorUtils.BLACK, false); + } + + private final static double MARGIN1 = 10; + private final static double MARGIN2 = 2; + + public void drawU(UGraphic ug) { + final double widthTitle = getTitle().calculateDimension(ug.getStringBounder()).getWidth(); + final double start = timeScale.getStartingPosition(min) + widthTitle; + final double end = timeScale.getEndingPosition(max); + + ug = ug.apply(new UChangeColor(HtmlColorUtils.BLACK)); + ug = ug.apply(new UTranslate(0, getHeight() / 2)); + + if (widthTitle == 0) { + final ULine line = new ULine(end - start, 0); + ug.draw(line); + } else { + final ULine line1 = new ULine(MARGIN1 - MARGIN2, 0); + final ULine line2 = new ULine(end - start - MARGIN1 - MARGIN2, 0); + ug.draw(line1); + ug.apply(new UTranslate(widthTitle + MARGIN1 + MARGIN2, 0)).draw(line2); + } + } + + public double getHeight() { + return 16; + } + + public double getY() { + return y; + } + + public double getY(Direction direction) { + if (direction == Direction.UP) { + return y; + } + if (direction == Direction.DOWN) { + return y + getHeight(); + } + return y + getHeight() / 2; + } + + public void setColorsAndCompletion(ComplementColors colors, int completion, Url url) { + } + +} diff --git a/src/net/sourceforge/plantuml/project/draw/TimeHeader.java b/src/net/sourceforge/plantuml/project/draw/TimeHeader.java new file mode 100644 index 0000000..982f9c8 --- /dev/null +++ b/src/net/sourceforge/plantuml/project/draw/TimeHeader.java @@ -0,0 +1,113 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2020, Arnaud Roques + * + * Project Info: http://plantuml.com + * + * 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 + * + * 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.project.draw; + +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.project.core.Wink; +import net.sourceforge.plantuml.project.timescale.TimeScale; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.UTranslate; +import sun.security.x509.AVA; + +public abstract class TimeHeader { + + private final TimeScale timeScale; + protected final Wink min; + protected final Wink max; + + public TimeHeader(Wink min, Wink max, TimeScale timeScale) { + this.timeScale = timeScale; + this.min = min; + this.max = max; + } + + public abstract void drawTimeHeader(final UGraphic ug, double totalHeight); + + public abstract double getFullHeaderHeight(); + + protected final void drawHline(UGraphic ug, double y) { + final double xmin = getTimeScale().getStartingPosition(min); + final double xmax = getTimeScale().getEndingPosition(max); + final ULine hline = new ULine(xmax - xmin, 0); + ug.apply(new UChangeColor(HtmlColorUtils.LIGHT_GRAY)).apply(new UTranslate(0, y)).draw(hline); + } + + final protected FontConfiguration getFontConfiguration(int size, boolean bold) { + UFont font = UFont.serif(size); + if (bold) { + font = font.bold(); + } + return new FontConfiguration(font, HtmlColorUtils.BLACK, HtmlColorUtils.BLACK, false); + } + + public final TimeScale getTimeScale() { + return timeScale; + } + + protected final TextBlock getTextBlock(final String text, int size, boolean bold) { + return Display.getWithNewlines(text).create(getFontConfiguration(size, bold), HorizontalAlignment.LEFT, + new SpriteContainerEmpty()); + } + + protected final void printCentered(UGraphic ug, TextBlock text, double start, double end) { + final double width = text.calculateDimension(ug.getStringBounder()).getWidth(); + final double available = end - start; + final double diff = Math.max(0, available - width); + text.drawU(ug.apply(new UTranslate(start + diff / 2, 0))); + } + + protected final void printCentered(UGraphic ug, double start, double end, TextBlock... texts) { + final double available = end - start; + for (int i = texts.length - 1; i >= 0; i--) { + final TextBlock text = texts[i]; + final double width = text.calculateDimension(ug.getStringBounder()).getWidth(); + if (i == 0 || width <= available) { + final double diff = Math.max(0, available - width); + text.drawU(ug.apply(new UTranslate(start + diff / 2, 0))); + return; + } + } + } + +} diff --git a/src/net/sourceforge/plantuml/project/draw/TimeHeaderDaily.java b/src/net/sourceforge/plantuml/project/draw/TimeHeaderDaily.java new file mode 100644 index 0000000..a0a819f --- /dev/null +++ b/src/net/sourceforge/plantuml/project/draw/TimeHeaderDaily.java @@ -0,0 +1,188 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2020, Arnaud Roques + * + * Project Info: http://plantuml.com + * + * 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 + * + * 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.project.draw; + +import java.util.Map; + +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorSetSimple; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.project.DayAsDate; +import net.sourceforge.plantuml.project.DayOfWeek; +import net.sourceforge.plantuml.project.GCalendar; +import net.sourceforge.plantuml.project.LoadPlanable; +import net.sourceforge.plantuml.project.core.Month; +import net.sourceforge.plantuml.project.core.Wink; +import net.sourceforge.plantuml.project.timescale.TimeScaleDaily; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class TimeHeaderDaily extends TimeHeader { + + private static final int Y_POS_WEEKDAY = 16; + private static final int Y_POS_NUMDAY = 28; + + private double getTimeHeaderHeight() { + return Y_POS_NUMDAY + 13; + } + + private final HtmlColor veryLightGray = new HtmlColorSetSimple().getColorIfValid("#E0E8E8"); + + private final GCalendar calendar; + private final LoadPlanable defaultPlan; + private final Map colorDays; + private final Map nameDays; + + public TimeHeaderDaily(GCalendar calendar, Wink min, Wink max, LoadPlanable defaultPlan, + Map colorDays, Map nameDays, DayAsDate printStart, + DayAsDate printEnd) { + super(min, max, new TimeScaleDaily(calendar, printStart)); + this.calendar = calendar; + this.defaultPlan = defaultPlan; + this.colorDays = colorDays; + this.nameDays = nameDays; + } + + @Override + public void drawTimeHeader(final UGraphic ug, double totalHeight) { + drawCalendar(ug, totalHeight); + drawHline(ug, 0); + drawHline(ug, getFullHeaderHeight()); + + } + + private void drawCalendar(final UGraphic ug, double totalHeight) { + Month lastMonth = null; + double lastChangeMonth = -1; + Wink wink = min; + while (wink.compareTo(max) <= 0) { + final DayAsDate day = calendar.toDayAsDate(wink); + final DayOfWeek dayOfWeek = day.getDayOfWeek(); + final boolean isWorkingDay = defaultPlan.getLoadAt(wink) > 0; + final String d1 = "" + day.getDayOfMonth(); + final TextBlock num = getTextBlock(d1, 10, false); + final double x1 = getTimeScale().getStartingPosition(wink); + final double x2 = getTimeScale().getEndingPosition(wink); + double startingY = getFullHeaderHeight(); + if (wink.compareTo(max.increment()) < 0) { + final TextBlock weekDay = getTextBlock(dayOfWeek.shortName(), 10, false); + + final URectangle rect = new URectangle(x2 - x1 - 1, totalHeight - getFullHeaderHeight()); + if (isWorkingDay) { + final HtmlColor back = colorDays.get(day); + if (back != null) { + ug.apply(new UChangeColor(null)).apply(new UChangeBackColor(back)) + .apply(new UTranslate(x1 + 1, getFullHeaderHeight())).draw(rect); + } + printCentered(ug.apply(new UTranslate(0, Y_POS_WEEKDAY)), weekDay, x1, x2); + printCentered(ug.apply(new UTranslate(0, Y_POS_NUMDAY)), num, x1, x2); + } else { + ug.apply(new UChangeColor(null)).apply(new UChangeBackColor(veryLightGray)) + .apply(new UTranslate(x1 + 1, getFullHeaderHeight())).draw(rect); + } + if (lastMonth != day.getMonth()) { + startingY = 0; + if (lastMonth != null) { + printMonth(ug, lastMonth, day.getYear(), lastChangeMonth, x1); + } + lastChangeMonth = x1; + lastMonth = day.getMonth(); + } + } + drawVbar(ug, x1, startingY, totalHeight); + wink = wink.increment(); + } + final DayAsDate day = calendar.toDayAsDate(max); + final double x1 = getTimeScale().getStartingPosition(wink); + drawVbar(ug, x1, Y_POS_WEEKDAY, totalHeight); + if (x1 > lastChangeMonth) { + printMonth(ug, lastMonth, day.getYear(), lastChangeMonth, x1); + } + + printNamedDays(ug); + + } + + private void printMonth(UGraphic ug, Month lastMonth, int year, double start, double end) { + final TextBlock tiny = getTextBlock(lastMonth.shortName(), 12, true); + final TextBlock small = getTextBlock(lastMonth.niceName(), 12, true); + final TextBlock big = getTextBlock(lastMonth.niceName() + " " + year, 12, true); + printCentered(ug, start, end, tiny, small, big); + } + + private void drawVbar(UGraphic ug, double x, double y1, double y2) { + final ULine vbar = new ULine(0, y2 - y1); + ug.apply(new UChangeColor(HtmlColorUtils.LIGHT_GRAY)).apply(new UTranslate(x, y1)).draw(vbar); + } + + private void printNamedDays(final UGraphic ug) { + if (nameDays.size() > 0) { + String last = null; + for (Wink wink = min; wink.compareTo(max.increment()) <= 0; wink = wink.increment()) { + final DayAsDate tmpday = calendar.toDayAsDate(wink); + final String name = nameDays.get(tmpday); + if (name != null && name.equals(last) == false) { + final double x1 = getTimeScale().getStartingPosition(wink); + final double x2 = getTimeScale().getEndingPosition(wink); + final TextBlock label = getTextBlock(name, 12, false); + final double h = label.calculateDimension(ug.getStringBounder()).getHeight(); + double y1 = getTimeHeaderHeight(); + double y2 = getFullHeaderHeight(); + label.drawU(ug.apply(new UTranslate(x1, Y_POS_NUMDAY + 11))); + } + last = name; + } + } + } + + @Override + public double getFullHeaderHeight() { + return getTimeHeaderHeight() + getHeaderNameDayHeight(); + } + + private double getHeaderNameDayHeight() { + if (nameDays.size() > 0) { + return 16; + } + return 0; + } + +} diff --git a/src/net/sourceforge/plantuml/project/draw/TimeHeaderSimple.java b/src/net/sourceforge/plantuml/project/draw/TimeHeaderSimple.java new file mode 100644 index 0000000..2d07d26 --- /dev/null +++ b/src/net/sourceforge/plantuml/project/draw/TimeHeaderSimple.java @@ -0,0 +1,97 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2020, Arnaud Roques + * + * Project Info: http://plantuml.com + * + * 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 + * + * 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.project.draw; + +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.project.core.Wink; +import net.sourceforge.plantuml.project.timescale.TimeScale; +import net.sourceforge.plantuml.project.timescale.TimeScaleWink; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class TimeHeaderSimple extends TimeHeader { + + public TimeHeaderSimple(Wink min, Wink max) { + super(min, max, new TimeScaleWink()); + } + + @Override + public void drawTimeHeader(final UGraphic ug, double totalHeight) { + final double xmin = getTimeScale().getStartingPosition(min); + final double xmax = getTimeScale().getEndingPosition(max); + drawSimpleDayCounter(ug, getTimeScale(), totalHeight); + ug.apply(new UChangeColor(HtmlColorUtils.LIGHT_GRAY)).draw(new ULine(xmax - xmin, 0)); + ug.apply(new UChangeColor(HtmlColorUtils.LIGHT_GRAY)).apply(new UTranslate(0, getFullHeaderHeight() - 3)) + .draw(new ULine(xmax - xmin, 0)); + + } + + private void drawSimpleDayCounter(final UGraphic ug, TimeScale timeScale, double totalHeight) { + final ULine vbar = new ULine(0, totalHeight); + for (Wink i = min; i.compareTo(max.increment()) <= 0; i = i.increment()) { + final TextBlock num = Display.getWithNewlines(i.toShortString()).create(getFontConfiguration(10, false), + HorizontalAlignment.LEFT, new SpriteContainerEmpty()); + final double x1 = timeScale.getStartingPosition(i); + final double x2 = timeScale.getEndingPosition(i); + final double width = num.calculateDimension(ug.getStringBounder()).getWidth(); + final double delta = (x2 - x1) - width; + if (i.compareTo(max.increment()) < 0) { + num.drawU(ug.apply(new UTranslate(x1 + delta / 2, 0))); + } + ug.apply(new UChangeColor(HtmlColorUtils.LIGHT_GRAY)).apply(new UTranslate(x1, 0)).draw(vbar); + } + } + + @Override + public double getFullHeaderHeight() { + return getTimeHeaderHeight() + getHeaderNameDayHeight(); + } + + private double getTimeHeaderHeight() { + return 16; + } + + private double getHeaderNameDayHeight() { + return 0; + } + +} diff --git a/src/net/sourceforge/plantuml/project/draw/TimeHeaderWeekly.java b/src/net/sourceforge/plantuml/project/draw/TimeHeaderWeekly.java new file mode 100644 index 0000000..d643351 --- /dev/null +++ b/src/net/sourceforge/plantuml/project/draw/TimeHeaderWeekly.java @@ -0,0 +1,188 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2020, Arnaud Roques + * + * Project Info: http://plantuml.com + * + * 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 + * + * 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.project.draw; + +import java.util.Map; + +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorSetSimple; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.project.DayAsDate; +import net.sourceforge.plantuml.project.DayOfWeek; +import net.sourceforge.plantuml.project.GCalendar; +import net.sourceforge.plantuml.project.LoadPlanable; +import net.sourceforge.plantuml.project.core.Month; +import net.sourceforge.plantuml.project.core.Wink; +import net.sourceforge.plantuml.project.timescale.TimeScaleWeekly; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class TimeHeaderWeekly extends TimeHeader { + + private static final int Y_POS_NUMDAY = 16; + + private double getTimeHeaderHeight() { + return Y_POS_NUMDAY + 13; + } + + private final HtmlColor veryLightGray = new HtmlColorSetSimple().getColorIfValid("#E0E8E8"); + + private final GCalendar calendar; + private final LoadPlanable defaultPlan; + private final Map colorDays; + private final Map nameDays; + + public TimeHeaderWeekly(GCalendar calendar, Wink min, Wink max, LoadPlanable defaultPlan, + Map colorDays, Map nameDays) { + super(min, max, new TimeScaleWeekly(calendar)); + this.calendar = calendar; + this.defaultPlan = defaultPlan; + this.colorDays = colorDays; + this.nameDays = nameDays; + } + + @Override + public void drawTimeHeader(final UGraphic ug, double totalHeight) { + drawCalendar(ug, totalHeight); + drawHline(ug, 0); + drawHline(ug, Y_POS_NUMDAY); + drawHline(ug, getFullHeaderHeight()); + + } + + private void drawCalendar(final UGraphic ug, double totalHeight) { + Month lastMonth = null; + double lastChangeMonth = -1; + Wink wink = min; + while (wink.compareTo(max) <= 0) { + final DayAsDate day = calendar.toDayAsDate(wink); + final DayOfWeek dayOfWeek = day.getDayOfWeek(); + final String d1 = "" + day.getDayOfMonth(); + final TextBlock num = getTextBlock(d1, 10, false); + final double x1 = getTimeScale().getStartingPosition(wink); + final double x2 = getTimeScale().getEndingPosition(wink); + double startingY = getFullHeaderHeight(); + if (wink.compareTo(max.increment()) < 0) { + if (dayOfWeek == DayOfWeek.MONDAY) { + printLeft(ug.apply(new UTranslate(0, Y_POS_NUMDAY)), num, x1 + 5); + } + if (lastMonth != day.getMonth()) { + startingY = Y_POS_NUMDAY; + drawVbar(ug, x1, 0, Y_POS_NUMDAY); + if (lastMonth != null) { + printMonth(ug, lastMonth, day.getYear(), lastChangeMonth, x1); + } + lastChangeMonth = x1; + lastMonth = day.getMonth(); + } + } + if (dayOfWeek == DayOfWeek.MONDAY) { + drawVbar(ug, x1, Y_POS_NUMDAY, totalHeight); + } + wink = wink.increment(); + } + final DayAsDate day = calendar.toDayAsDate(wink); + final double x1 = getTimeScale().getStartingPosition(wink); + if (x1 > lastChangeMonth) { + printMonth(ug, lastMonth, day.getYear(), lastChangeMonth, x1); + } + + printNamedDays(ug); + + } + + private void printMonth(UGraphic ug, Month lastMonth, int year, double start, double end) { + final TextBlock small = getTextBlock(lastMonth.shortName(), 12, true); + final TextBlock big = getTextBlock(lastMonth.shortName() + " " + year, 12, true); + printCentered(ug, start, end, small, big); + } + + private void drawVbar(UGraphic ug, double x, double y1, double y2) { + final ULine vbar = new ULine(0, y2 - y1); + ug.apply(new UChangeColor(HtmlColorUtils.LIGHT_GRAY)).apply(new UTranslate(x, y1)).draw(vbar); + } + + private void printNamedDays(final UGraphic ug) { +// if (nameDays.size() > 0) { +// String last = null; +// for (Wink wink = min; wink.compareTo(max.increment()) <= 0; wink = wink.increment()) { +// final DayAsDate tmpday = calendar.toDayAsDate(wink); +// final String name = nameDays.get(tmpday); +// if (name != null && name.equals(last) == false) { +// final double x1 = getTimeScale().getStartingPosition(wink); +// final double x2 = getTimeScale().getEndingPosition(wink); +// final TextBlock label = getTextBlock(name, 12, false); +// final double h = label.calculateDimension(ug.getStringBounder()).getHeight(); +// double y1 = getTimeHeaderHeight(); +// double y2 = getFullHeaderHeight(); +// label.drawU(ug.apply(new UTranslate(x1, Y_POS_NUMDAY + 11))); +// } +// last = name; +// } +// } + } + + private void printLeft(UGraphic ug, TextBlock text, double start) { + text.drawU(ug.apply(new UTranslate(start, 0))); + } + + @Override + public double getFullHeaderHeight() { + return getTimeHeaderHeight() + getHeaderNameDayHeight(); + } + + private double getHeaderNameDayHeight() { +// if (nameDays.size() > 0) { +// return 16; +// } + return 0; + } + +// private void drawCenter(final UGraphic ug, final TextBlock text, final double x1, final double x2) { +// final double width = text.calculateDimension(ug.getStringBounder()).getWidth(); +// final double delta = (x2 - x1) - width; +// if (delta < 0) { +// return; +// } +// text.drawU(ug.apply(new UTranslate(x1 + delta / 2, 0))); +// } +} -- cgit v1.2.3