1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-09-22 03:59:03 +00:00
plantuml/src/net/sourceforge/plantuml/ugraphic/AbstractCommonUGraphic.java

188 lines
4.7 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2019-01-16 18:34:41 +00:00
* (C) Copyright 2009-2020, 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.ugraphic;
2020-05-17 21:15:50 +00:00
import net.sourceforge.plantuml.Url;
2020-03-18 10:50:02 +00:00
import net.sourceforge.plantuml.ugraphic.color.ColorMapper;
import net.sourceforge.plantuml.ugraphic.color.ColorMapperTransparentWrapper;
import net.sourceforge.plantuml.ugraphic.color.HColor;
2020-04-19 16:04:39 +00:00
import net.sourceforge.plantuml.ugraphic.color.HColorNone;
2013-12-10 19:36:50 +00:00
2010-11-15 20:35:36 +00:00
public abstract class AbstractCommonUGraphic implements UGraphic {
2013-12-10 19:36:50 +00:00
private UStroke stroke = new UStroke();
private UPattern pattern = UPattern.FULL;
private boolean hidden = false;
2020-03-18 10:50:02 +00:00
private HColor backColor = null;
private HColor color = null;
2020-01-12 22:13:17 +00:00
private boolean enlargeClip = false;
2013-12-10 19:36:50 +00:00
private UTranslate translate = new UTranslate();
2011-08-08 17:48:29 +00:00
private final ColorMapper colorMapper;
2013-12-10 19:36:50 +00:00
private UClip clip;
2015-04-07 18:18:37 +00:00
private double scale = 1;
2013-12-10 19:36:50 +00:00
2018-06-12 20:50:45 +00:00
public double dpiFactor() {
return 1;
}
2013-12-10 19:36:50 +00:00
public UGraphic apply(UChange change) {
2020-04-19 16:04:39 +00:00
if (change == null) {
throw new IllegalArgumentException();
}
2013-12-10 19:36:50 +00:00
final AbstractCommonUGraphic copy = copyUGraphic();
if (change instanceof UTranslate) {
2015-04-07 18:18:37 +00:00
copy.translate = ((UTranslate) change).scaled(scale).compose(copy.translate);
2013-12-10 19:36:50 +00:00
} else if (change instanceof UClip) {
copy.clip = (UClip) change;
copy.clip = copy.clip.translate(getTranslateX(), getTranslateY());
} else if (change instanceof UStroke) {
copy.stroke = (UStroke) change;
} else if (change instanceof UPattern) {
copy.pattern = (UPattern) change;
} else if (change instanceof UHidden) {
copy.hidden = change == UHidden.HIDDEN;
2020-04-19 16:04:39 +00:00
} else if (change instanceof UBackground) {
copy.backColor = ((UBackground) change).getBackColor();
} else if (change instanceof HColorNone) {
copy.color = null;
} else if (change instanceof HColor) {
copy.color = (HColor) change;
2015-04-07 18:18:37 +00:00
} else if (change instanceof UScale) {
final double factor = ((UScale) change).getScale();
copy.scale = scale * factor;
2013-12-10 19:36:50 +00:00
}
return copy;
}
final public UClip getClip() {
2020-01-12 22:13:17 +00:00
if (enlargeClip && clip != null) {
return clip.enlarge(1);
}
2013-12-10 19:36:50 +00:00
return clip;
}
2011-08-08 17:48:29 +00:00
2020-01-12 22:13:17 +00:00
final public void enlargeClip() {
this.enlargeClip = true;
}
2011-08-08 17:48:29 +00:00
public AbstractCommonUGraphic(ColorMapper colorMapper) {
this.colorMapper = colorMapper;
}
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
protected AbstractCommonUGraphic(AbstractCommonUGraphic other) {
2020-01-12 22:13:17 +00:00
this.enlargeClip = other.enlargeClip;
2013-12-10 19:36:50 +00:00
this.colorMapper = other.colorMapper;
this.translate = other.translate;
this.clip = other.clip;
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
this.stroke = other.stroke;
this.pattern = other.pattern;
this.hidden = other.hidden;
this.color = other.color;
this.backColor = other.backColor;
2015-04-07 18:18:37 +00:00
this.scale = other.scale;
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
protected abstract AbstractCommonUGraphic copyUGraphic();
final public UParam getParam() {
return new UParam() {
public boolean isHidden() {
return hidden;
}
public UStroke getStroke() {
return stroke;
}
2020-03-18 10:50:02 +00:00
public HColor getColor() {
2013-12-10 19:36:50 +00:00
return color;
}
2020-03-18 10:50:02 +00:00
public HColor getBackcolor() {
2013-12-10 19:36:50 +00:00
return backColor;
}
public UPattern getPattern() {
return pattern;
}
2015-04-07 18:18:37 +00:00
public double getScale() {
return scale;
}
2013-12-10 19:36:50 +00:00
};
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
final protected double getTranslateX() {
return translate.getDx();
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
final protected double getTranslateY() {
return translate.getDy();
2010-11-15 20:35:36 +00:00
}
2011-08-08 17:48:29 +00:00
final public ColorMapper getColorMapper() {
2013-12-10 19:36:50 +00:00
return new ColorMapperTransparentWrapper(colorMapper);
2011-08-08 17:48:29 +00:00
}
2015-04-07 18:18:37 +00:00
2020-05-17 21:15:50 +00:00
final public void flushUg() {
}
public void startUrl(Url url) {
}
public void closeUrl() {
}
public void startGroup(String groupId) {
}
public void startGroupWithClass(String groupClasses) {
}
2020-05-17 21:15:50 +00:00
public void closeGroup() {
2015-04-07 18:18:37 +00:00
}
2018-06-12 20:50:45 +00:00
2016-12-01 20:29:25 +00:00
public boolean matchesProperty(String propertyName) {
2015-04-07 18:18:37 +00:00
return false;
2013-12-10 19:36:50 +00:00
}
2010-11-15 20:35:36 +00:00
}