1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-02 08:30:49 +00:00
plantuml/src/net/sourceforge/plantuml/svek/Shape.java

177 lines
4.3 KiB
Java
Raw Normal View History

2011-08-08 17:48:29 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* 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
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 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.
*
* [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;
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.posimo.Positionable;
public class Shape implements Positionable {
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;
private Cluster cluster;
private final boolean top;
public final Cluster getCluster() {
return cluster;
}
public final void setCluster(Cluster cluster) {
this.cluster = cluster;
}
public Shape(ShapeType type, double width, double height, ColorSequence colorSequence, boolean top) {
this.top = top;
this.type = type;
this.width = width;
this.height = height;
this.color = colorSequence.getValue();
this.uid = String.format("sh%04d", color);
}
public final ShapeType getType() {
return type;
}
public final double getWidth() {
return width;
}
public final double getHeight() {
return height;
}
public void appendShape(StringBuilder sb) {
// if (type == ShapeType.CIRCLE_IN_RECT) {
// sb.append("subgraph clusterlol" + uid + " {");
// DotStringFactory.println(sb);
// }
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);
// if (type == ShapeType.CIRCLE_IN_RECT) {
// sb.append("}");
// DotStringFactory.println(sb);
// }
}
private void appendShapeInternal(StringBuilder sb) {
if (type == ShapeType.RECTANGLE) {
sb.append("shape=rect");
} 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 void setMinX(double minX) {
this.minX = minX;
}
public final double getMinY() {
return minY;
}
public final void setMinY(double minY) {
this.minY = minY;
}
private IEntityImage image;
public void setImage(IEntityImage image) {
this.image = image;
}
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);
}
}