1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-21 09:32:20 +00:00
plantuml/src/net/sourceforge/plantuml/sequencediagram/teoz/CommunicationExoTile.java

218 lines
7.5 KiB
Java
Raw Normal View History

2015-04-07 18:26:58 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2019-01-16 18:34:41 +00:00
* (C) Copyright 2009-2020, Arnaud Roques
2015-04-07 18:26:58 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2015-04-07 18:26:58 +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
*
2015-04-07 18:26:58 +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.sequencediagram.teoz;
import java.awt.geom.Dimension2D;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.real.Real;
import net.sourceforge.plantuml.sequencediagram.Event;
import net.sourceforge.plantuml.sequencediagram.MessageExo;
2015-11-01 18:37:20 +00:00
import net.sourceforge.plantuml.sequencediagram.MessageExoType;
2015-04-07 18:26:58 +00:00
import net.sourceforge.plantuml.skin.Area;
2019-04-21 20:40:01 +00:00
import net.sourceforge.plantuml.skin.ArrowComponent;
2015-04-07 18:26:58 +00:00
import net.sourceforge.plantuml.skin.ArrowConfiguration;
2015-11-01 18:37:20 +00:00
import net.sourceforge.plantuml.skin.ArrowDecoration;
2015-04-07 18:26:58 +00:00
import net.sourceforge.plantuml.skin.Component;
import net.sourceforge.plantuml.skin.Context2D;
2015-11-01 18:37:20 +00:00
import net.sourceforge.plantuml.skin.rose.ComponentRoseArrow;
2019-03-01 22:16:29 +00:00
import net.sourceforge.plantuml.skin.rose.Rose;
2015-04-07 18:26:58 +00:00
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UTranslate;
public class CommunicationExoTile extends AbstractTile {
2015-04-07 18:26:58 +00:00
private final LivingSpace livingSpace;
private final MessageExo message;
2019-03-01 22:16:29 +00:00
private final Rose skin;
2015-04-07 18:26:58 +00:00
private final ISkinParam skinParam;
2015-05-31 18:56:03 +00:00
private final TileArguments tileArguments;
2015-05-03 15:36:36 +00:00
2015-04-07 18:26:58 +00:00
public Event getEvent() {
return message;
}
2019-03-01 22:16:29 +00:00
public CommunicationExoTile(LivingSpace livingSpace, MessageExo message, Rose skin, ISkinParam skinParam,
2015-05-31 18:56:03 +00:00
TileArguments tileArguments) {
super(tileArguments.getStringBounder());
2015-05-31 18:56:03 +00:00
this.tileArguments = tileArguments;
2015-04-07 18:26:58 +00:00
this.livingSpace = livingSpace;
this.message = message;
this.skin = skin;
this.skinParam = skinParam;
}
2019-07-14 20:09:26 +00:00
2019-03-01 22:16:29 +00:00
@Override
public double getContactPointRelative() {
return getComponent(getStringBounder()).getYPoint(getStringBounder());
2019-03-01 22:16:29 +00:00
}
2019-04-21 20:40:01 +00:00
private ArrowComponent getComponent(StringBounder stringBounder) {
2015-04-07 18:26:58 +00:00
ArrowConfiguration arrowConfiguration = message.getArrowConfiguration();
if (message.getType().getDirection() == -1) {
arrowConfiguration = arrowConfiguration.reverse();
}
2019-07-14 20:09:26 +00:00
final ArrowComponent comp = skin.createComponentArrow(message.getUsedStyles(), arrowConfiguration, skinParam,
message.getLabelNumbered());
2015-04-07 18:26:58 +00:00
return comp;
}
public void drawU(UGraphic ug) {
final StringBounder stringBounder = ug.getStringBounder();
final Component comp = getComponent(stringBounder);
final Dimension2D dim = comp.getPreferredDimension(stringBounder);
2015-05-31 18:56:03 +00:00
double x1 = getPoint1Value(stringBounder);
2015-07-11 09:32:49 +00:00
double x2 = getPoint2Value(stringBounder);
2015-05-31 18:56:03 +00:00
final int level = livingSpace.getLevelAt(this, EventsHistoryMode.IGNORE_FUTURE_DEACTIVATE);
if (level > 0) {
if (message.getType().isRightBorder()) {
x1 += CommunicationTile.LIVE_DELTA_SIZE * level;
} else {
2015-07-11 09:32:49 +00:00
x2 += CommunicationTile.LIVE_DELTA_SIZE * (level - 2);
2015-05-31 18:56:03 +00:00
}
}
2015-11-01 18:37:20 +00:00
final ArrowConfiguration arrowConfiguration = message.getArrowConfiguration();
final MessageExoType type = message.getType();
if (arrowConfiguration.getDecoration1() == ArrowDecoration.CIRCLE && type == MessageExoType.FROM_LEFT) {
x1 += ComponentRoseArrow.diamCircle / 2 + 2;
}
if (arrowConfiguration.getDecoration2() == ArrowDecoration.CIRCLE && type == MessageExoType.TO_LEFT) {
x1 += ComponentRoseArrow.diamCircle / 2 + 2;
}
if (arrowConfiguration.getDecoration2() == ArrowDecoration.CIRCLE && type == MessageExoType.TO_RIGHT) {
x2 -= ComponentRoseArrow.diamCircle / 2 + 2;
}
if (arrowConfiguration.getDecoration1() == ArrowDecoration.CIRCLE && type == MessageExoType.FROM_RIGHT) {
x2 -= ComponentRoseArrow.diamCircle / 2 + 2;
}
2015-04-07 18:26:58 +00:00
final Area area = new Area(x2 - x1, dim.getHeight());
2020-03-18 10:50:02 +00:00
ug = ug.apply(UTranslate.dx(x1));
2015-04-07 18:26:58 +00:00
comp.drawU(ug, area, (Context2D) ug);
}
2015-07-11 09:32:49 +00:00
private boolean isShortArrow() {
return message.isShortArrow();
}
public double getPreferredHeight() {
final Component comp = getComponent(getStringBounder());
final Dimension2D dim = comp.getPreferredDimension(getStringBounder());
2015-04-07 18:26:58 +00:00
return dim.getHeight();
}
2015-07-11 09:32:49 +00:00
private double getPreferredWidth(StringBounder stringBounder) {
final Component comp = getComponent(stringBounder);
final Dimension2D dim = comp.getPreferredDimension(stringBounder);
return dim.getWidth();
}
public void addConstraints() {
final Component comp = getComponent(getStringBounder());
final Dimension2D dim = comp.getPreferredDimension(getStringBounder());
2015-04-07 18:26:58 +00:00
final double width = dim.getWidth();
2015-07-11 09:32:49 +00:00
if (message.getType().isRightBorder()) {
2015-04-07 18:26:58 +00:00
} else {
livingSpace.getPosC(getStringBounder()).ensureBiggerThan(tileArguments.getOrigin().addFixed(width));
2015-04-07 18:26:58 +00:00
}
2015-07-11 09:32:49 +00:00
// final Real point1 = getPoint1(stringBounder);
// if (message.getType().isRightBorder()) {
// final Real point2 = point1.addFixed(width);
// } else {
// final Real point2 = getPoint2(stringBounder);
// if (point1.getCurrentValue() < point2.getCurrentValue()) {
// point2.ensureBiggerThan(point1.addFixed(width));
// } else {
// point1.ensureBiggerThan(point2.addFixed(width));
// }
// }
2015-04-07 18:26:58 +00:00
}
@Override
public void callbackY_internal(double y) {
final ArrowComponent comp = getComponent(getStringBounder());
final Dimension2D dim = comp.getPreferredDimension(getStringBounder());
final double arrowY = comp.getStartPoint(getStringBounder(), dim).getY();
2015-05-03 15:36:36 +00:00
livingSpace.addStepForLivebox(getEvent(), y + arrowY);
}
2015-04-07 18:26:58 +00:00
private Real getPoint1(final StringBounder stringBounder) {
if (message.getType().isRightBorder()) {
return livingSpace.getPosC(stringBounder);
}
2015-05-31 18:56:03 +00:00
return tileArguments.getOrigin();
}
private double getPoint1Value(final StringBounder stringBounder) {
if (message.getType().isRightBorder()) {
return livingSpace.getPosC(stringBounder).getCurrentValue();
}
2015-07-11 09:32:49 +00:00
if (isShortArrow()) {
return getPoint2Value(stringBounder) - getPreferredWidth(stringBounder);
}
return tileArguments.getBorder1();
2015-04-07 18:26:58 +00:00
}
2015-07-11 09:32:49 +00:00
private double getPoint2Value(final StringBounder stringBounder) {
2015-04-07 18:26:58 +00:00
if (message.getType().isRightBorder()) {
2015-07-11 09:32:49 +00:00
if (isShortArrow()) {
return getPoint1Value(stringBounder) + getPreferredWidth(stringBounder);
}
return tileArguments.getBorder2();
2015-04-07 18:26:58 +00:00
}
2015-07-11 09:32:49 +00:00
return livingSpace.getPosC(stringBounder).getCurrentValue();
2015-04-07 18:26:58 +00:00
}
public Real getMinX() {
return getPoint1(getStringBounder());
2015-04-07 18:26:58 +00:00
}
public Real getMaxX() {
final Component comp = getComponent(getStringBounder());
final Dimension2D dim = comp.getPreferredDimension(getStringBounder());
2015-07-11 09:32:49 +00:00
final double width = dim.getWidth();
return getPoint1(getStringBounder()).addFixed(width);
2015-04-07 18:26:58 +00:00
}
}