1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-03 17:10:49 +00:00
plantuml/src/net/sourceforge/plantuml/project/draw/TimeHeaderWeekly.java

168 lines
6.3 KiB
Java
Raw Normal View History

2020-02-18 21:24:31 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2023-02-22 18:43:48 +00:00
* (C) Copyright 2009-2024, Arnaud Roques
2020-02-18 21:24:31 +00:00
*
2023-02-22 18:43:48 +00:00
* Project Info: https://plantuml.com
2020-02-18 21:24: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
2020-02-18 21:24:31 +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.project.draw;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.UTranslate;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.drawing.UGraphic;
2023-11-27 17:41:15 +00:00
import net.sourceforge.plantuml.klimt.font.StringBounder;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.shape.TextBlock;
2022-08-18 16:55:09 +00:00
import net.sourceforge.plantuml.project.TimeHeaderParameters;
2020-03-18 10:50:02 +00:00
import net.sourceforge.plantuml.project.time.Day;
import net.sourceforge.plantuml.project.time.MonthYear;
2021-04-07 18:02:23 +00:00
import net.sourceforge.plantuml.project.time.WeekNumberStrategy;
2020-03-18 10:50:02 +00:00
import net.sourceforge.plantuml.project.timescale.TimeScaleCompressed;
2023-11-27 17:41:15 +00:00
import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.SName;
2020-02-18 21:24:31 +00:00
2021-03-19 16:58:09 +00:00
public class TimeHeaderWeekly extends TimeHeaderCalendar {
2020-11-21 17:33:24 +00:00
2021-04-07 18:02:23 +00:00
private final WeekNumberStrategy weekNumberStrategy;
private final boolean withCalendarDate;
2021-04-07 18:02:23 +00:00
2023-11-27 17:41:15 +00:00
@Override
public double getTimeHeaderHeight(StringBounder stringBounder) {
final double h1 = thParam.getStyle(SName.timeline, SName.month).value(PName.FontSize).asDouble();
final double h2 = thParam.getStyle(SName.timeline, SName.day).value(PName.FontSize).asDouble();
return h1 + h2 + 5;
}
@Override
public double getTimeFooterHeight(StringBounder stringBounder) {
final double h = thParam.getStyle(SName.timeline, SName.month).value(PName.FontSize).asDouble() + 4;
return h;
}
@Override
public double getFullHeaderHeight(StringBounder stringBounder) {
return getTimeHeaderHeight(stringBounder);
2020-11-21 17:33:24 +00:00
}
2023-11-27 17:41:15 +00:00
private double getH1(StringBounder stringBounder) {
final double h = thParam.getStyle(SName.timeline, SName.month).value(PName.FontSize).asDouble() + 4;
return h;
2020-02-18 21:24:31 +00:00
}
2023-11-27 17:41:15 +00:00
public TimeHeaderWeekly(StringBounder stringBounder, TimeHeaderParameters thParam,
WeekNumberStrategy weekNumberStrategy, boolean withCalendarDate) {
super(thParam, new TimeScaleCompressed(thParam.getCellWidth(stringBounder), thParam.getStartingDay(),
thParam.getScale()));
2021-04-07 18:02:23 +00:00
this.weekNumberStrategy = weekNumberStrategy;
this.withCalendarDate = withCalendarDate;
2020-02-18 21:24:31 +00:00
}
@Override
2020-11-21 17:33:24 +00:00
public void drawTimeHeader(final UGraphic ug, double totalHeightWithoutFooter) {
2021-03-18 21:38:00 +00:00
drawTextsBackground(ug, totalHeightWithoutFooter);
2020-11-21 17:33:24 +00:00
drawCalendar(ug, totalHeightWithoutFooter);
2020-02-18 21:24:31 +00:00
drawHline(ug, 0);
2023-11-27 17:41:15 +00:00
drawHline(ug, getH1(ug.getStringBounder()));
drawHline(ug, getFullHeaderHeight(ug.getStringBounder()));
2020-11-21 17:33:24 +00:00
}
2020-02-18 21:24:31 +00:00
2021-03-18 21:38:00 +00:00
@Override
public void drawTimeFooter(UGraphic ug) {
drawHline(ug, 0);
printMonths(ug);
2023-11-27 17:41:15 +00:00
drawHline(ug, getTimeFooterHeight(ug.getStringBounder()));
2021-03-18 21:38:00 +00:00
}
private void drawCalendar(final UGraphic ug, double totalHeightWithoutFooter) {
printDaysOfMonth(ug);
printVerticalSeparators(ug, totalHeightWithoutFooter);
2021-03-18 21:38:00 +00:00
printMonths(ug);
}
2020-03-18 10:50:02 +00:00
private void printMonths(final UGraphic ug) {
MonthYear last = null;
2020-02-18 21:24:31 +00:00
double lastChangeMonth = -1;
for (Day wink = getMin(); wink.compareTo(getMax()) < 0; wink = wink.increment()) {
2020-02-18 21:24:31 +00:00
final double x1 = getTimeScale().getStartingPosition(wink);
2020-09-30 20:57:58 +00:00
if (wink.monthYear().equals(last) == false) {
2023-11-27 17:41:15 +00:00
drawVline(ug.apply(getLineColor()), x1, 0, getH1(ug.getStringBounder()));
if (last != null)
2020-03-18 10:50:02 +00:00
printMonth(ug, last, lastChangeMonth, x1);
2020-03-18 10:50:02 +00:00
lastChangeMonth = x1;
2020-09-30 20:57:58 +00:00
last = wink.monthYear();
2020-02-18 21:24:31 +00:00
}
}
2023-11-27 17:41:15 +00:00
drawVline(ug.apply(getLineColor()), getTimeScale().getEndingPosition(getMax()), (double) 0,
getH1(ug.getStringBounder()));
final double x1 = getTimeScale().getStartingPosition(getMax().increment());
2023-11-27 17:41:15 +00:00
if (last != null && x1 > lastChangeMonth)
2020-03-18 10:50:02 +00:00
printMonth(ug, last, lastChangeMonth, x1);
2020-03-18 10:50:02 +00:00
}
2020-02-18 21:24:31 +00:00
@Override
protected void printVerticalSeparators(final UGraphic ug, double totalHeightWithoutFooter) {
for (Day wink = getMin(); wink.compareTo(getMax()) <= 0; wink = wink.increment())
if (wink.getDayOfWeek() == weekNumberStrategy.getFirstDayOfWeek())
2023-11-27 17:41:15 +00:00
drawVline(ug.apply(getLineColor()), getTimeScale().getStartingPosition(wink),
getH1(ug.getStringBounder()), totalHeightWithoutFooter);
2023-11-27 17:41:15 +00:00
drawVline(ug.apply(getLineColor()), getTimeScale().getEndingPosition(getMax()), getH1(ug.getStringBounder()),
totalHeightWithoutFooter);
super.printVerticalSeparators(ug, totalHeightWithoutFooter);
2020-03-18 10:50:02 +00:00
}
2020-02-18 21:24:31 +00:00
2020-03-18 10:50:02 +00:00
private void printDaysOfMonth(final UGraphic ug) {
for (Day wink = getMin(); wink.compareTo(getMax()) < 0; wink = wink.increment()) {
2021-04-07 18:02:23 +00:00
if (wink.getDayOfWeek() == weekNumberStrategy.getFirstDayOfWeek()) {
final String num;
if (withCalendarDate)
num = "" + wink.getDayOfMonth();
else
num = "" + wink.getWeekOfYear(weekNumberStrategy);
2023-11-27 17:41:15 +00:00
final TextBlock textBlock = getTextBlock(SName.day, num, false, openFontColor());
printLeft(ug.apply(UTranslate.dy(getH1(ug.getStringBounder()))), textBlock,
2020-03-18 10:50:02 +00:00
getTimeScale().getStartingPosition(wink) + 5);
}
}
2020-02-18 21:24:31 +00:00
}
2020-03-18 10:50:02 +00:00
private void printMonth(UGraphic ug, MonthYear monthYear, double start, double end) {
2023-11-27 17:41:15 +00:00
final TextBlock small = getTextBlock(SName.month, monthYear.shortName(locale()), true, openFontColor());
final TextBlock big = getTextBlock(SName.month, monthYear.shortNameYYYY(locale()), true, openFontColor());
2021-04-07 18:02:23 +00:00
printCentered(ug, false, start, end, small, big);
2020-02-18 21:24:31 +00:00
}
private void printLeft(UGraphic ug, TextBlock text, double start) {
2020-03-18 10:50:02 +00:00
text.drawU(ug.apply(UTranslate.dx(start)));
2020-02-18 21:24:31 +00:00
}
}