2011-08-08 17:48:29 +00:00
|
|
|
/* ========================================================================
|
|
|
|
* PlantUML : a free UML diagram generator
|
|
|
|
* ========================================================================
|
|
|
|
*
|
2015-04-07 18:18:37 +00:00
|
|
|
* (C) Copyright 2009-2014, Arnaud Roques
|
2011-08-08 17:48:29 +00:00
|
|
|
*
|
|
|
|
* Project Info: http://plantuml.sourceforge.net
|
|
|
|
*
|
|
|
|
* 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
|
2011-08-08 17:48:29 +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.
|
|
|
|
*
|
|
|
|
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
|
|
|
|
* in the United States and other countries.]
|
|
|
|
*
|
|
|
|
* Original Author: Arnaud Roques
|
|
|
|
*
|
|
|
|
* Revision $Revision: 4236 $
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package net.sourceforge.plantuml.svek;
|
|
|
|
|
|
|
|
import java.awt.geom.Dimension2D;
|
|
|
|
import java.awt.geom.Point2D;
|
2015-04-07 18:18:37 +00:00
|
|
|
import java.util.List;
|
2011-08-08 17:48:29 +00:00
|
|
|
|
|
|
|
import net.sourceforge.plantuml.Dimension2DDouble;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.Hideable;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.EntityPosition;
|
|
|
|
import net.sourceforge.plantuml.graphic.StringBounder;
|
2011-08-08 17:48:29 +00:00
|
|
|
import net.sourceforge.plantuml.posimo.Positionable;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.svek.image.EntityImageStateBorder;
|
2015-04-07 18:18:37 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.Shadowable;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UPolygon;
|
|
|
|
import net.sourceforge.plantuml.StringUtils;
|
2011-08-08 17:48:29 +00:00
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
public class Shape implements Positionable, IShapePseudo, Hideable {
|
2011-08-08 17:48:29 +00:00
|
|
|
|
|
|
|
private final ShapeType type;
|
|
|
|
private final double width;
|
|
|
|
private final double height;
|
|
|
|
|
|
|
|
private final String uid;
|
|
|
|
private final int color;
|
|
|
|
|
|
|
|
private double minX;
|
|
|
|
private double minY;
|
2011-09-07 20:41:58 +00:00
|
|
|
private final int shield;
|
2011-08-08 17:48:29 +00:00
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
private final EntityPosition entityPosition;
|
|
|
|
private final IEntityImage image;
|
|
|
|
|
|
|
|
public EntityPosition getEntityPosition() {
|
|
|
|
return entityPosition;
|
|
|
|
}
|
|
|
|
|
2011-08-08 17:48:29 +00:00
|
|
|
private Cluster cluster;
|
|
|
|
|
|
|
|
private final boolean top;
|
|
|
|
|
|
|
|
public final Cluster getCluster() {
|
|
|
|
return cluster;
|
|
|
|
}
|
|
|
|
|
|
|
|
public final void setCluster(Cluster cluster) {
|
|
|
|
this.cluster = cluster;
|
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
public Shape(IEntityImage image, ShapeType type, double width, double height, ColorSequence colorSequence,
|
|
|
|
boolean top, int shield, EntityPosition entityPosition) {
|
|
|
|
this.entityPosition = entityPosition;
|
2011-09-08 10:42:27 +00:00
|
|
|
this.image = image;
|
2011-08-08 17:48:29 +00:00
|
|
|
this.top = top;
|
|
|
|
this.type = type;
|
|
|
|
this.width = width;
|
|
|
|
this.height = height;
|
|
|
|
this.color = colorSequence.getValue();
|
|
|
|
this.uid = String.format("sh%04d", color);
|
2011-09-07 20:41:58 +00:00
|
|
|
this.shield = shield;
|
|
|
|
if (shield > 0 && type != ShapeType.RECTANGLE) {
|
|
|
|
throw new IllegalArgumentException();
|
|
|
|
}
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public final ShapeType getType() {
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
public final double getWidth() {
|
|
|
|
return width;
|
|
|
|
}
|
|
|
|
|
|
|
|
public final double getHeight() {
|
|
|
|
return height;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void appendShape(StringBuilder sb) {
|
2011-09-07 20:41:58 +00:00
|
|
|
if (type == ShapeType.RECTANGLE && shield > 0) {
|
|
|
|
appendHtml(sb);
|
|
|
|
return;
|
|
|
|
}
|
2011-08-08 17:48:29 +00:00
|
|
|
sb.append(uid);
|
|
|
|
sb.append(" [");
|
|
|
|
appendShapeInternal(sb);
|
|
|
|
sb.append(",");
|
|
|
|
sb.append("label=\"\"");
|
|
|
|
sb.append(",");
|
|
|
|
sb.append("width=" + SvekUtils.pixelToInches(getWidth()));
|
|
|
|
sb.append(",");
|
|
|
|
sb.append("height=" + SvekUtils.pixelToInches(getHeight()));
|
|
|
|
sb.append(",");
|
|
|
|
sb.append("color=\"" + StringUtils.getAsHtml(color) + "\"");
|
|
|
|
sb.append("];");
|
|
|
|
SvekUtils.println(sb);
|
|
|
|
}
|
|
|
|
|
2011-09-07 20:41:58 +00:00
|
|
|
private void appendHtml(StringBuilder sb) {
|
|
|
|
sb.append(uid);
|
|
|
|
sb.append(" [");
|
|
|
|
sb.append("shape=plaintext,");
|
|
|
|
sb.append("label=<");
|
|
|
|
appendLabelHtml(sb);
|
|
|
|
sb.append(">");
|
|
|
|
sb.append("];");
|
|
|
|
SvekUtils.println(sb);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private void appendLabelHtml(StringBuilder sb) {
|
2013-12-10 19:36:50 +00:00
|
|
|
// Log.println("shield=" + shield);
|
2011-09-07 20:41:58 +00:00
|
|
|
sb.append("<TABLE BORDER=\"0\" CELLBORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\">");
|
|
|
|
sb.append("<TR>");
|
|
|
|
appendTd(sb);
|
|
|
|
appendTd(sb, shield, shield);
|
|
|
|
appendTd(sb);
|
|
|
|
sb.append("</TR>");
|
|
|
|
sb.append("<TR>");
|
|
|
|
appendTd(sb, shield, shield);
|
|
|
|
sb.append("<TD BGCOLOR=\"" + StringUtils.getAsHtml(color) + "\"");
|
|
|
|
sb.append(" FIXEDSIZE=\"TRUE\" WIDTH=\"" + getWidth() + "\" HEIGHT=\"" + getHeight() + "\"");
|
|
|
|
sb.append(" PORT=\"h\">");
|
|
|
|
sb.append("</TD>");
|
|
|
|
appendTd(sb, shield, shield);
|
|
|
|
sb.append("</TR>");
|
|
|
|
sb.append("<TR>");
|
|
|
|
appendTd(sb);
|
|
|
|
appendTd(sb, shield, shield);
|
|
|
|
appendTd(sb);
|
|
|
|
sb.append("</TR>");
|
|
|
|
sb.append("</TABLE>");
|
|
|
|
}
|
|
|
|
|
|
|
|
private void appendTd(StringBuilder sb, int w, int h) {
|
|
|
|
sb.append("<TD");
|
|
|
|
sb.append(" FIXEDSIZE=\"TRUE\" WIDTH=\"" + w + "\" HEIGHT=\"" + h + "\"");
|
|
|
|
sb.append(">");
|
|
|
|
sb.append("</TD>");
|
|
|
|
}
|
|
|
|
|
|
|
|
private void appendTd(StringBuilder sb) {
|
|
|
|
sb.append("<TD>");
|
|
|
|
sb.append("</TD>");
|
|
|
|
}
|
|
|
|
|
2011-08-08 17:48:29 +00:00
|
|
|
private void appendShapeInternal(StringBuilder sb) {
|
2011-09-07 20:41:58 +00:00
|
|
|
if (type == ShapeType.RECTANGLE && shield > 0) {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
} else if (type == ShapeType.RECTANGLE) {
|
2011-08-08 17:48:29 +00:00
|
|
|
sb.append("shape=rect");
|
2015-04-07 18:18:37 +00:00
|
|
|
} else if (type == ShapeType.OCTAGON) {
|
|
|
|
sb.append("shape=octagon");
|
2011-08-08 17:48:29 +00:00
|
|
|
} else if (type == ShapeType.DIAMOND) {
|
|
|
|
sb.append("shape=diamond");
|
|
|
|
} else if (type == ShapeType.CIRCLE) {
|
|
|
|
sb.append("shape=circle");
|
|
|
|
} else if (type == ShapeType.CIRCLE_IN_RECT) {
|
|
|
|
sb.append("shape=circle");
|
|
|
|
} else if (type == ShapeType.OVAL) {
|
|
|
|
sb.append("shape=ellipse");
|
|
|
|
} else if (type == ShapeType.ROUND_RECTANGLE) {
|
|
|
|
sb.append("shape=rect,style=rounded");
|
|
|
|
} else {
|
|
|
|
throw new IllegalStateException(type.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public final String getUid() {
|
|
|
|
if (uid == null) {
|
|
|
|
throw new IllegalStateException();
|
|
|
|
}
|
|
|
|
return uid;
|
|
|
|
}
|
|
|
|
|
|
|
|
public final double getMinX() {
|
|
|
|
return minX;
|
|
|
|
}
|
|
|
|
|
|
|
|
public final double getMinY() {
|
|
|
|
return minY;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IEntityImage getImage() {
|
|
|
|
return image;
|
|
|
|
}
|
|
|
|
|
|
|
|
public final boolean isTop() {
|
|
|
|
return top;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Point2D getPosition() {
|
|
|
|
return new Point2D.Double(minX, minY);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Dimension2D getSize() {
|
|
|
|
return new Dimension2DDouble(width, height);
|
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
public ClusterPosition getClusterPosition() {
|
|
|
|
return new ClusterPosition(minX, minY, minX + width, minY + height);
|
|
|
|
}
|
2011-09-07 20:41:58 +00:00
|
|
|
|
|
|
|
public boolean isShielded() {
|
|
|
|
return shield > 0;
|
|
|
|
}
|
|
|
|
|
2011-09-08 10:42:27 +00:00
|
|
|
public void moveSvek(double deltaX, double deltaY) {
|
|
|
|
this.minX += deltaX;
|
|
|
|
this.minY += deltaY;
|
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
public double getMaxWidthFromLabelForEntryExit(StringBounder stringBounder) {
|
|
|
|
final EntityImageStateBorder im = (EntityImageStateBorder) image;
|
|
|
|
return im.getMaxWidthFromLabelForEntryExit(stringBounder);
|
2011-09-08 10:42:27 +00:00
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
|
|
|
|
public boolean isHidden() {
|
|
|
|
return image.isHidden();
|
2011-09-08 10:42:27 +00:00
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
|
2015-04-07 18:18:37 +00:00
|
|
|
private Shadowable octagon;
|
|
|
|
|
|
|
|
public void setOctagon(double minX, double minY, List<Point2D.Double> points) {
|
|
|
|
this.octagon = new UPolygon(points).translate(-minX, -minY);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Shadowable getOctagon() {
|
|
|
|
return octagon;
|
|
|
|
}
|
|
|
|
|
2011-08-08 17:48:29 +00:00
|
|
|
}
|