plantuml/src/net/sourceforge/plantuml/nwdiag/next/GridTextBlockSimple.java

143 lines
4.3 KiB
Java
Raw Normal View History

2018-11-26 18:46:50 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2023-02-22 18:43:48 +00:00
* (C) Copyright 2009-2024, Arnaud Roques
2018-11-26 18:46:50 +00:00
*
2023-02-22 18:43:48 +00:00
* Project Info: https://plantuml.com
2018-11-26 18:46:50 +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
2018-11-26 18:46:50 +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.nwdiag.next;
2018-11-26 18:46:50 +00:00
2023-02-22 18:43:48 +00:00
import net.atmp.InnerStrategy;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.UTranslate;
2023-02-26 18:51:17 +00:00
import net.sourceforge.plantuml.klimt.color.HColor;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.drawing.UGraphic;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.font.StringBounder;
2023-02-26 18:51:17 +00:00
import net.sourceforge.plantuml.klimt.geom.MagneticBorder;
import net.sourceforge.plantuml.klimt.geom.MagneticBorderNone;
2023-02-02 17:59:43 +00:00
import net.sourceforge.plantuml.klimt.geom.MinMax;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.geom.XDimension2D;
import net.sourceforge.plantuml.klimt.geom.XRectangle2D;
import net.sourceforge.plantuml.klimt.shape.TextBlock;
import net.sourceforge.plantuml.style.ISkinParam;
2018-11-26 18:46:50 +00:00
public class GridTextBlockSimple implements TextBlock {
2023-01-16 19:06:31 +00:00
public static final double MINIMUM_WIDTH = 70;
2020-12-19 21:21:54 +00:00
protected final NwArray data;
private final ISkinParam skinParam;
2018-11-26 18:46:50 +00:00
public GridTextBlockSimple(int lines, int cols, ISkinParam skinParam) {
this.skinParam = skinParam;
2020-12-19 21:21:54 +00:00
this.data = new NwArray(lines, cols);
2018-11-26 18:46:50 +00:00
}
2020-08-25 17:24:17 +00:00
protected void drawGrid(UGraphic ug) {
2018-11-26 18:46:50 +00:00
}
public void drawU(UGraphic ug) {
drawGrid(ug);
final StringBounder stringBounder = ug.getStringBounder();
double y = 0;
2020-12-19 21:21:54 +00:00
for (int i = 0; i < data.getNbLines(); i++) {
2018-11-26 18:46:50 +00:00
final double lineHeight = lineHeight(stringBounder, i);
double x = 0;
2020-12-19 21:21:54 +00:00
for (int j = 0; j < data.getNbCols(); j++) {
2018-11-26 18:46:50 +00:00
final double colWidth = colWidth(stringBounder, j);
2022-05-21 09:41:00 +00:00
if (data.get(i, j) != null)
2020-12-19 21:21:54 +00:00
data.get(i, j).drawMe(ug.apply(new UTranslate(x, y)), colWidth, lineHeight);
2022-05-21 09:41:00 +00:00
2018-11-26 18:46:50 +00:00
x += colWidth;
}
y += lineHeight;
}
}
protected double colWidth(StringBounder stringBounder, final int j) {
double width = 0;
2022-05-21 09:41:00 +00:00
for (int i = 0; i < data.getNbLines(); i++)
if (data.get(i, j) != null)
2020-12-19 21:21:54 +00:00
width = Math.max(width, data.get(i, j).naturalDimension(stringBounder).getWidth());
2022-05-21 09:41:00 +00:00
2018-11-26 18:46:50 +00:00
return width;
}
public double lineHeight(StringBounder stringBounder, final int i) {
2020-12-19 21:21:54 +00:00
double height = 50;
2022-05-21 09:41:00 +00:00
for (int j = 0; j < data.getNbCols(); j++)
if (data.get(i, j) != null)
2020-12-19 21:21:54 +00:00
height = Math.max(height, data.get(i, j).naturalDimension(stringBounder).getHeight());
2022-05-21 09:41:00 +00:00
2018-11-26 18:46:50 +00:00
return height;
}
2022-09-12 20:08:34 +00:00
public XDimension2D calculateDimension(StringBounder stringBounder) {
2022-05-21 09:41:00 +00:00
if (data.getNbLines() == 0)
2022-09-12 20:08:34 +00:00
return new XDimension2D(0, 0);
2022-05-21 09:41:00 +00:00
2018-11-26 18:46:50 +00:00
double height = 0;
2022-05-21 09:41:00 +00:00
for (int i = 0; i < data.getNbLines(); i++)
2018-11-26 18:46:50 +00:00
height += lineHeight(stringBounder, i);
2022-05-21 09:41:00 +00:00
2018-11-26 18:46:50 +00:00
double width = 0;
2022-05-21 09:41:00 +00:00
for (int j = 0; j < data.getNbCols(); j++)
2018-11-26 18:46:50 +00:00
width += colWidth(stringBounder, j);
2022-05-21 09:41:00 +00:00
2023-01-16 19:06:31 +00:00
return new XDimension2D(Math.max(MINIMUM_WIDTH, width), height);
2018-11-26 18:46:50 +00:00
}
2022-09-12 20:08:34 +00:00
public XRectangle2D getInnerPosition(String member, StringBounder stringBounder, InnerStrategy strategy) {
2018-11-26 18:46:50 +00:00
throw new UnsupportedOperationException("member=" + member + " " + getClass().toString());
}
public MinMax getMinMax(StringBounder stringBounder) {
throw new UnsupportedOperationException(getClass().toString());
}
2023-01-16 19:06:31 +00:00
public void add(int i, int j, NServerDraw value) {
2020-12-19 21:21:54 +00:00
data.set(i, j, value);
}
2022-05-21 09:41:00 +00:00
protected final ISkinParam getSkinParam() {
return skinParam;
2018-11-26 18:46:50 +00:00
}
2023-02-26 18:51:17 +00:00
@Override
public MagneticBorder getMagneticBorder() {
return new MagneticBorderNone();
}
@Override
public HColor getBackcolor() {
return null;
}
2018-11-26 18:46:50 +00:00
}