1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-05-28 22:20:49 +00:00
plantuml/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileWithNoteOpale.java

254 lines
9.6 KiB
Java
Raw Normal View History

2013-12-10 19:36:50 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2019-01-16 18:34:41 +00:00
* (C) Copyright 2009-2020, Arnaud Roques
2013-12-10 19:36:50 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2013-12-10 19:36:50 +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:
*
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
*
2013-12-10 19:36: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.activitydiagram3.ftile.vcompact;
import java.awt.geom.Dimension2D;
import java.awt.geom.Point2D;
2016-07-04 19:06:50 +00:00
import java.util.Collection;
2016-12-14 21:01:03 +00:00
import java.util.Collections;
2017-05-10 19:51:15 +00:00
import java.util.HashSet;
2013-12-10 19:36:50 +00:00
import java.util.Set;
2019-02-09 21:56:24 +00:00
import net.sourceforge.plantuml.AlignmentParam;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.ColorParam;
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.Direction;
import net.sourceforge.plantuml.FontParam;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.ISkinParam;
2019-08-26 17:07:21 +00:00
import net.sourceforge.plantuml.SkinParam;
2016-07-04 19:06:50 +00:00
import net.sourceforge.plantuml.activitydiagram3.PositionedNote;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractFtile;
import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.activitydiagram3.ftile.FtileGeometry;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane;
2015-07-11 09:32:49 +00:00
import net.sourceforge.plantuml.creole.CreoleMode;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.creole.CreoleParser;
import net.sourceforge.plantuml.creole.Sheet;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.creole.SheetBlock1;
import net.sourceforge.plantuml.creole.SheetBlock2;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.creole.Stencil;
import net.sourceforge.plantuml.graphic.FontConfiguration;
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
import net.sourceforge.plantuml.graphic.HtmlColor;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.sequencediagram.NotePosition;
2016-05-19 18:41:37 +00:00
import net.sourceforge.plantuml.sequencediagram.NoteType;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.skin.rose.Rose;
2019-08-26 17:07:21 +00:00
import net.sourceforge.plantuml.style.PName;
import net.sourceforge.plantuml.style.SName;
import net.sourceforge.plantuml.style.Style;
import net.sourceforge.plantuml.style.StyleSignature;
import net.sourceforge.plantuml.style.Styleable;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.svek.image.Opale;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UStroke;
import net.sourceforge.plantuml.ugraphic.UTranslate;
2019-08-26 17:07:21 +00:00
public class FtileWithNoteOpale extends AbstractFtile implements Stencil, Styleable {
2013-12-10 19:36:50 +00:00
private final Ftile tile;
private final Opale opale;
2015-04-07 18:18:37 +00:00
// private final HtmlColor arrowColor;
2013-12-10 19:36:50 +00:00
private final NotePosition notePosition;
2015-04-07 18:18:37 +00:00
private final double suppSpace = 20;
2017-05-10 19:51:15 +00:00
private final Swimlane swimlaneNote;
2013-12-10 19:36:50 +00:00
2019-08-26 17:07:21 +00:00
public StyleSignature getDefaultStyleDefinition() {
return StyleSignature.of(SName.root, SName.element, SName.activityDiagram, SName.note);
}
2013-12-10 19:36:50 +00:00
public Set<Swimlane> getSwimlanes() {
2017-05-10 19:51:15 +00:00
if (swimlaneNote != null) {
final Set<Swimlane> result = new HashSet<Swimlane>(tile.getSwimlanes());
result.add(swimlaneNote);
return Collections.unmodifiableSet(result);
}
2013-12-10 19:36:50 +00:00
return tile.getSwimlanes();
}
public Swimlane getSwimlaneIn() {
return tile.getSwimlaneIn();
}
public Swimlane getSwimlaneOut() {
return tile.getSwimlaneOut();
}
2017-05-10 19:51:15 +00:00
2016-12-14 21:01:03 +00:00
@Override
public Collection<Ftile> getMyChildren() {
return Collections.singleton(tile);
}
2013-12-10 19:36:50 +00:00
2016-07-04 19:06:50 +00:00
public static Ftile create(Ftile tile, Collection<PositionedNote> notes, ISkinParam skinParam, boolean withLink) {
if (notes.size() > 1) {
return new FtileWithNotes(tile, notes, skinParam);
}
if (notes.size() == 0) {
throw new IllegalArgumentException();
}
return new FtileWithNoteOpale(tile, notes.iterator().next(), skinParam, withLink);
}
private FtileWithNoteOpale(Ftile tile, PositionedNote note, ISkinParam skinParam, boolean withLink) {
2016-06-19 14:16:41 +00:00
super(tile.skinParam());
2017-05-10 19:51:15 +00:00
this.swimlaneNote = note.getSwimlaneNote();
2016-07-04 19:06:50 +00:00
if (note.getColors() != null) {
skinParam = note.getColors().mute(skinParam);
}
2013-12-10 19:36:50 +00:00
this.tile = tile;
2016-07-04 19:06:50 +00:00
this.notePosition = note.getNotePosition();
if (note.getType() == NoteType.FLOATING_NOTE) {
2016-05-19 18:41:37 +00:00
withLink = false;
}
2013-12-10 19:36:50 +00:00
final Rose rose = new Rose();
2019-08-26 17:07:21 +00:00
final HtmlColor noteBackgroundColor;
final HtmlColor borderColor;
final FontConfiguration fc;
final double shadowing;
if (SkinParam.USE_STYLES()) {
final Style style = getDefaultStyleDefinition().getMergedStyle(skinParam.getCurrentStyleBuilder()).eventuallyOverride(note.getColors());
noteBackgroundColor = style.value(PName.BackGroundColor).asColor(getIHtmlColorSet());
borderColor = style.value(PName.LineColor).asColor(getIHtmlColorSet());
fc = style.getFontConfiguration(getIHtmlColorSet());
shadowing = style.value(PName.Shadowing).asDouble();
} else {
noteBackgroundColor = rose.getHtmlColor(skinParam, ColorParam.noteBackground);
borderColor = rose.getHtmlColor(skinParam, ColorParam.noteBorder);
fc = new FontConfiguration(skinParam, FontParam.NOTE, null);
shadowing = skinParam.shadowing(null) ? 4 : 0;
}
2013-12-10 19:36:50 +00:00
2019-08-26 17:07:21 +00:00
final HorizontalAlignment align = skinParam.getHorizontalAlignment(AlignmentParam.noteTextAlignment, null,
false);
2019-02-09 21:56:24 +00:00
final Sheet sheet = new CreoleParser(fc, align, skinParam, CreoleMode.FULL).createSheet(note.getDisplay());
final TextBlock text = new SheetBlock2(new SheetBlock1(sheet, skinParam.wrapWidth(), skinParam.getPadding()),
2017-05-10 19:51:15 +00:00
this, new UStroke(1));
2019-08-26 17:07:21 +00:00
opale = new Opale(shadowing, borderColor, noteBackgroundColor, text, withLink);
2013-12-10 19:36:50 +00:00
}
private UTranslate getTranslate(StringBounder stringBounder) {
final Dimension2D dimTotal = calculateDimensionInternal(stringBounder);
final Dimension2D dimNote = opale.calculateDimension(stringBounder);
2015-04-07 18:18:37 +00:00
final Dimension2D dimTile = tile.calculateDimension(stringBounder);
2013-12-10 19:36:50 +00:00
final double yForFtile = (dimTotal.getHeight() - dimTile.getHeight()) / 2;
2015-04-07 18:18:37 +00:00
final double marge;
if (notePosition == NotePosition.LEFT) {
marge = dimNote.getWidth() + suppSpace;
} else {
marge = 0;
}
2013-12-10 19:36:50 +00:00
return new UTranslate(marge, yForFtile);
}
2015-04-07 18:18:37 +00:00
private UTranslate getTranslateForOpale(UGraphic ug) {
final StringBounder stringBounder = ug.getStringBounder();
final Dimension2D dimTotal = calculateDimension(stringBounder);
final Dimension2D dimNote = opale.calculateDimension(stringBounder);
final double yForNote = (dimTotal.getHeight() - dimNote.getHeight()) / 2;
if (notePosition == NotePosition.LEFT) {
return new UTranslate(0, yForNote);
}
final double dx = dimTotal.getWidth() - dimNote.getWidth();
return new UTranslate(dx, yForNote);
}
public void drawU(UGraphic ug) {
2017-05-10 19:51:15 +00:00
final Swimlane intoSw;
if (ug instanceof UGraphicInterceptorOneSwimlane) {
intoSw = ((UGraphicInterceptorOneSwimlane) ug).getSwimlane();
} else {
intoSw = null;
}
2015-04-07 18:18:37 +00:00
final StringBounder stringBounder = ug.getStringBounder();
final Dimension2D dimNote = opale.calculateDimension(stringBounder);
if (notePosition == NotePosition.LEFT) {
final Direction strategy = Direction.RIGHT;
final Point2D pp1 = new Point2D.Double(dimNote.getWidth(), dimNote.getHeight() / 2);
final Point2D pp2 = new Point2D.Double(dimNote.getWidth() + suppSpace, dimNote.getHeight() / 2);
opale.setOpale(strategy, pp1, pp2);
} else {
final Direction strategy = Direction.LEFT;
final Point2D pp1 = new Point2D.Double(0, dimNote.getHeight() / 2);
final Point2D pp2 = new Point2D.Double(-suppSpace, dimNote.getHeight() / 2);
opale.setOpale(strategy, pp1, pp2);
}
2017-05-10 19:51:15 +00:00
if (swimlaneNote == null || intoSw == swimlaneNote) {
opale.drawU(ug.apply(getTranslateForOpale(ug)));
}
2015-04-07 18:18:37 +00:00
ug.apply(getTranslate(stringBounder)).draw(tile);
2013-12-10 19:36:50 +00:00
}
2017-11-20 16:10:36 +00:00
@Override
protected FtileGeometry calculateDimensionFtile(StringBounder stringBounder) {
2015-04-07 18:18:37 +00:00
final Dimension2D dimTotal = calculateDimensionInternal(stringBounder);
final FtileGeometry orig = tile.calculateDimension(stringBounder);
final UTranslate translate = getTranslate(stringBounder);
if (orig.hasPointOut()) {
return new FtileGeometry(dimTotal, orig.getLeft() + translate.getDx(), orig.getInY() + translate.getDy(),
orig.getOutY() + translate.getDy());
}
return new FtileGeometry(dimTotal, orig.getLeft() + translate.getDx(), orig.getInY() + translate.getDy());
2013-12-10 19:36:50 +00:00
}
private Dimension2D calculateDimensionInternal(StringBounder stringBounder) {
final Dimension2D dimNote = opale.calculateDimension(stringBounder);
2015-04-07 18:18:37 +00:00
final Dimension2D dimTile = tile.calculateDimension(stringBounder);
2013-12-10 19:36:50 +00:00
final double height = Math.max(dimNote.getHeight(), dimTile.getHeight());
2015-04-07 18:18:37 +00:00
return new Dimension2DDouble(dimTile.getWidth() + 1 * dimNote.getWidth() + suppSpace, height);
2013-12-10 19:36:50 +00:00
}
public double getStartingX(StringBounder stringBounder, double y) {
return -opale.getMarginX1();
}
public double getEndingX(StringBounder stringBounder, double y) {
return opale.calculateDimension(stringBounder).getWidth() - opale.getMarginX1();
}
}