2010-11-25 21:12:39 +00:00
|
|
|
/* ========================================================================
|
|
|
|
* PlantUML : a free UML diagram generator
|
|
|
|
* ========================================================================
|
|
|
|
*
|
2023-02-22 18:43:48 +00:00
|
|
|
* (C) Copyright 2009-2024, Arnaud Roques
|
2010-11-25 21:12:39 +00:00
|
|
|
*
|
2023-02-22 18:43:48 +00:00
|
|
|
* Project Info: https://plantuml.com
|
2010-11-25 21:12:39 +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
|
|
|
*
|
2010-11-25 21:12:39 +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
|
2013-12-10 19:36:50 +00:00
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
2010-11-25 21:12:39 +00:00
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2023-02-22 18:43:48 +00:00
|
|
|
package net.sourceforge.plantuml.klimt.geom;
|
2010-11-25 21:12:39 +00:00
|
|
|
|
|
|
|
import java.util.Map;
|
2017-04-05 17:37:42 +00:00
|
|
|
import java.util.Map.Entry;
|
|
|
|
import java.util.Set;
|
2010-11-25 21:12:39 +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-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-22 18:43:48 +00:00
|
|
|
import net.sourceforge.plantuml.klimt.shape.TextBlock;
|
2010-11-25 21:12:39 +00:00
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
public class ULayoutGroup {
|
2023-03-08 20:49:44 +00:00
|
|
|
// ::remove file when __HAXE__
|
2010-11-25 21:12:39 +00:00
|
|
|
|
|
|
|
private final PlacementStrategy placementStrategy;
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
public ULayoutGroup(PlacementStrategy placementStrategy) {
|
2010-11-25 21:12:39 +00:00
|
|
|
this.placementStrategy = placementStrategy;
|
|
|
|
}
|
|
|
|
|
2015-06-07 10:23:10 +00:00
|
|
|
public void drawU(UGraphic ug, double width, double height) {
|
2022-09-12 20:08:34 +00:00
|
|
|
for (Map.Entry<TextBlock, XPoint2D> ent : placementStrategy.getPositions(width, height).entrySet()) {
|
2010-11-25 21:12:39 +00:00
|
|
|
final TextBlock block = ent.getKey();
|
2022-09-12 20:08:34 +00:00
|
|
|
final XPoint2D pos = ent.getValue();
|
2023-03-04 09:34:43 +00:00
|
|
|
block.drawU(ug.apply(UTranslate.point(pos)));
|
2010-11-25 21:12:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void add(TextBlock block) {
|
|
|
|
placementStrategy.add(block);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-09-12 20:08:34 +00:00
|
|
|
public XRectangle2D getInnerPosition(String member, double width, double height, StringBounder stringBounder) {
|
|
|
|
final Set<Entry<TextBlock, XPoint2D>> all = placementStrategy.getPositions(width, height).entrySet();
|
|
|
|
XRectangle2D result = tryOne(all, member, stringBounder, InnerStrategy.STRICT);
|
2022-07-29 12:43:01 +00:00
|
|
|
if (result == null)
|
2017-04-05 17:37:42 +00:00
|
|
|
result = tryOne(all, member, stringBounder, InnerStrategy.LAZZY);
|
2022-07-29 12:43:01 +00:00
|
|
|
|
2017-04-05 17:37:42 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-09-12 20:08:34 +00:00
|
|
|
private XRectangle2D tryOne(final Set<Entry<TextBlock, XPoint2D>> all, String member, StringBounder stringBounder,
|
2017-04-05 17:37:42 +00:00
|
|
|
InnerStrategy mode) {
|
2022-09-12 20:08:34 +00:00
|
|
|
for (Map.Entry<TextBlock, XPoint2D> ent : all) {
|
2015-06-07 10:23:10 +00:00
|
|
|
final TextBlock block = ent.getKey();
|
2022-09-12 20:08:34 +00:00
|
|
|
final XRectangle2D result = block.getInnerPosition(member, stringBounder, mode);
|
2015-06-07 10:23:10 +00:00
|
|
|
if (result != null) {
|
2023-03-04 09:34:43 +00:00
|
|
|
final UTranslate translate = UTranslate.point(ent.getValue());
|
2015-06-07 10:23:10 +00:00
|
|
|
return translate.apply(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2010-11-25 21:12:39 +00:00
|
|
|
}
|