1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-02 16:40:49 +00:00
plantuml/src/net/sourceforge/plantuml/cucadiagram/LinkType.java

258 lines
7.0 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2016-01-09 12:15:40 +00:00
* (C) Copyright 2009-2017, Arnaud Roques
2010-11-15 20:35:36 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://plantuml.com
2010-11-15 20:35:36 +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
*
2010-11-15 20:35:36 +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-15 20:35:36 +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
*
*
*/
package net.sourceforge.plantuml.cucadiagram;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.ugraphic.UStroke;
2010-11-15 20:35:36 +00:00
public class LinkType {
2013-12-10 19:36:50 +00:00
private final LinkHat hat1;
2010-11-15 20:35:36 +00:00
private final LinkDecor decor1;
private final LinkStyle style;
private final LinkDecor decor2;
2013-12-10 19:36:50 +00:00
private final LinkHat hat2;
private final LinkMiddleDecor middleDecor;
2010-11-15 20:35:36 +00:00
public LinkType(LinkDecor decor1, LinkDecor decor2) {
2013-12-10 19:36:50 +00:00
this(LinkHat.NONE, decor1, decor2, LinkHat.NONE);
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
public LinkType(LinkHat hat1, LinkDecor decor1, LinkDecor decor2, LinkHat hat2) {
this(hat1, decor1, LinkStyle.NORMAL, LinkMiddleDecor.NONE, decor2, hat2);
2010-11-15 20:35:36 +00:00
}
2016-01-30 12:20:07 +00:00
public LinkType withoutDecors1() {
return new LinkType(hat1, LinkDecor.NONE, style, middleDecor, decor2, hat2);
}
public LinkType withoutDecors2() {
return new LinkType(hat1, decor1, style, middleDecor, LinkDecor.NONE, hat2);
}
2013-12-10 19:36:50 +00:00
// public boolean contains(LinkDecor decors) {
// return decor1 == decors || decor2 == decors;
// }
2010-11-15 20:35:36 +00:00
@Override
public String toString() {
return decor1 + "-" + style + "-" + decor2;
}
@Override
public int hashCode() {
return toString().hashCode();
}
@Override
public boolean equals(Object obj) {
final LinkType other = (LinkType) obj;
return this.decor1 == other.decor1 && this.decor2 == other.decor2 && this.style == other.style;
}
2013-12-10 19:36:50 +00:00
private LinkType(LinkHat hat1, LinkDecor decor1, LinkStyle style, LinkMiddleDecor middleDecor, LinkDecor decor2,
LinkHat hat2) {
2010-11-15 20:35:36 +00:00
this.decor1 = decor1;
this.style = style;
this.decor2 = decor2;
2013-12-10 19:36:50 +00:00
this.middleDecor = middleDecor;
this.hat1 = hat1;
this.hat2 = hat2;
2010-11-15 20:35:36 +00:00
}
public boolean isDashed() {
return style == LinkStyle.DASHED;
}
2011-03-20 21:40:07 +00:00
public boolean isDotted() {
return style == LinkStyle.DOTTED;
}
public boolean isBold() {
return style == LinkStyle.BOLD;
}
2013-12-10 19:36:50 +00:00
public boolean isInvisible() {
return style == LinkStyle.INVISIBLE;
}
2010-11-15 20:35:36 +00:00
public LinkType getDashed() {
2013-12-10 19:36:50 +00:00
return new LinkType(hat1, decor1, LinkStyle.DASHED, middleDecor, decor2, hat2);
2010-11-15 20:35:36 +00:00
}
2011-03-20 21:40:07 +00:00
public LinkType getDotted() {
2013-12-10 19:36:50 +00:00
return new LinkType(hat1, decor1, LinkStyle.DOTTED, middleDecor, decor2, hat2);
2011-03-20 21:40:07 +00:00
}
public LinkType getBold() {
2013-12-10 19:36:50 +00:00
return new LinkType(hat1, decor1, LinkStyle.BOLD, middleDecor, decor2, hat2);
2011-03-20 21:40:07 +00:00
}
2010-11-15 20:35:36 +00:00
public LinkType getInterfaceProvider() {
2013-12-10 19:36:50 +00:00
return new LinkType(hat1, decor1, LinkStyle.__toremove_INTERFACE_PROVIDER, middleDecor, decor2, hat2);
2010-11-15 20:35:36 +00:00
}
public LinkType getInterfaceUser() {
2013-12-10 19:36:50 +00:00
return new LinkType(hat1, decor1, LinkStyle.__toremove_INTERFACE_USER, middleDecor, decor2, hat2);
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
public LinkType getInversed() {
return new LinkType(hat2, decor2, style, middleDecor, decor1, hat1);
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
public LinkType withMiddleCircle() {
return new LinkType(hat1, decor1, style, LinkMiddleDecor.CIRCLE, decor2, hat2);
}
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
public LinkType withMiddleCircleCircled() {
return new LinkType(hat1, decor1, style, LinkMiddleDecor.CIRCLE_CIRCLED, decor2, hat2);
}
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
public LinkType withMiddleCircleCircled1() {
return new LinkType(hat1, decor1, style, LinkMiddleDecor.CIRCLE_CIRCLED1, decor2, hat2);
}
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
public LinkType withMiddleCircleCircled2() {
return new LinkType(hat1, decor1, style, LinkMiddleDecor.CIRCLE_CIRCLED2, decor2, hat2);
}
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
public LinkType getInvisible() {
return new LinkType(hat1, decor1, LinkStyle.INVISIBLE, middleDecor, decor2, hat2);
2010-11-15 20:35:36 +00:00
}
2011-09-07 20:41:58 +00:00
public String getSpecificDecorationSvek() {
final StringBuilder sb = new StringBuilder();
2013-12-10 19:36:50 +00:00
final boolean isEmpty1 = decor1 == LinkDecor.NONE && hat1 == LinkHat.NONE;
final boolean isEmpty2 = decor2 == LinkDecor.NONE && hat2 == LinkHat.NONE;
if (isEmpty1 && isEmpty2) {
sb.append("arrowtail=none");
sb.append(",arrowhead=none");
} else if (isEmpty1 == false && isEmpty2 == false) {
2011-09-07 20:41:58 +00:00
sb.append("dir=both,");
2013-12-10 19:36:50 +00:00
sb.append("arrowtail=empty");
sb.append(",arrowhead=empty");
} else if (isEmpty1 && isEmpty2 == false) {
sb.append("arrowtail=empty");
sb.append(",arrowhead=none");
sb.append(",dir=back");
2017-02-15 21:34:36 +00:00
// } else if (isEmpty1 == false && isEmpty2) {
// sb.append("arrowtail=none");
// sb.append(",arrowhead=empty");
2011-09-07 20:41:58 +00:00
}
2013-12-10 19:36:50 +00:00
final double arrowsize = Math.max(decor1.getArrowSize(), decor2.getArrowSize());
if (arrowsize > 0) {
2017-02-15 21:34:36 +00:00
if (sb.length() > 0) {
sb.append(",");
}
sb.append("arrowsize=" + arrowsize);
2011-09-07 20:41:58 +00:00
}
return sb.toString();
}
2010-11-15 20:35:36 +00:00
public final LinkDecor getDecor1() {
return decor1;
}
public final LinkStyle getStyle() {
return style;
}
public final LinkDecor getDecor2() {
return decor2;
}
2017-04-05 17:37:42 +00:00
public boolean isExtendsOrAggregationOrCompositionOrPlus() {
return isExtends() || isAggregationOrComposition() || isPlus();
2010-11-15 20:35:36 +00:00
}
private boolean isExtends() {
return decor1 == LinkDecor.EXTENDS || decor2 == LinkDecor.EXTENDS;
}
private boolean isPlus() {
return decor1 == LinkDecor.PLUS || decor2 == LinkDecor.PLUS;
}
2017-04-05 17:37:42 +00:00
private boolean isAggregationOrComposition() {
2010-11-15 20:35:36 +00:00
return decor1 == LinkDecor.AGREGATION || decor2 == LinkDecor.AGREGATION || decor1 == LinkDecor.COMPOSITION
|| decor2 == LinkDecor.COMPOSITION;
}
2011-01-09 19:00:05 +00:00
public LinkType getPart1() {
2013-12-10 19:36:50 +00:00
return new LinkType(hat1, decor1, style, middleDecor, LinkDecor.NONE, LinkHat.NONE);
2011-01-09 19:00:05 +00:00
}
public LinkType getPart2() {
2013-12-10 19:36:50 +00:00
return new LinkType(LinkHat.NONE, LinkDecor.NONE, style, middleDecor, decor2, hat2);
2011-01-09 19:00:05 +00:00
}
2011-08-08 17:48:29 +00:00
public UStroke getStroke() {
if (style == LinkStyle.DASHED) {
return new UStroke(7, 7, 1);
}
if (style == LinkStyle.DOTTED) {
return new UStroke(1, 3, 1);
}
if (style == LinkStyle.BOLD) {
return new UStroke(2);
}
return new UStroke();
}
2013-12-10 19:36:50 +00:00
public LinkMiddleDecor getMiddleDecor() {
return middleDecor;
}
public LinkHat getHat1() {
return hat1;
}
public LinkHat getHat2() {
return hat2;
}
2015-04-07 18:18:37 +00:00
public LinkType withLollipopInterfaceEye2() {
return new LinkType(hat1, LinkDecor.NONE, style, middleDecor, decor2, hat2);
}
public LinkType withLollipopInterfaceEye1() {
return new LinkType(hat1, decor1, style, middleDecor, LinkDecor.NONE, hat2);
}
2010-11-15 20:35:36 +00:00
}