1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-09-27 14:39:02 +00:00

* Extract common functionality to UGraphicNo class

* Simplify subclass constructors
* Remove dpiFactor() methods which became redundant a while ago
This commit is contained in:
matthew16550 2021-09-19 22:33:09 +10:00
parent e1fe53457a
commit 8ec5a84040
8 changed files with 205 additions and 297 deletions

View File

@ -35,6 +35,8 @@
*/ */
package net.sourceforge.plantuml.activitydiagram3.ftile; package net.sourceforge.plantuml.activitydiagram3.ftile;
import static net.sourceforge.plantuml.utils.ObjectUtils.instanceOfAny;
import java.awt.geom.Line2D; import java.awt.geom.Line2D;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -46,36 +48,41 @@ import net.sourceforge.plantuml.ugraphic.UChange;
import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UGraphicNo; import net.sourceforge.plantuml.ugraphic.UGraphicNo;
import net.sourceforge.plantuml.ugraphic.ULine; import net.sourceforge.plantuml.ugraphic.ULine;
import net.sourceforge.plantuml.ugraphic.UParam;
import net.sourceforge.plantuml.ugraphic.UParamNull;
import net.sourceforge.plantuml.ugraphic.UPolygon; import net.sourceforge.plantuml.ugraphic.UPolygon;
import net.sourceforge.plantuml.ugraphic.URectangle; import net.sourceforge.plantuml.ugraphic.URectangle;
import net.sourceforge.plantuml.ugraphic.UShape; import net.sourceforge.plantuml.ugraphic.UShape;
import net.sourceforge.plantuml.ugraphic.UStroke; import net.sourceforge.plantuml.ugraphic.UStroke;
import net.sourceforge.plantuml.ugraphic.UTranslate; import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.color.ColorMapper;
import net.sourceforge.plantuml.ugraphic.color.HColor; import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorUtils; import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
public class CollisionDetector extends UGraphicNo implements UGraphic { public class CollisionDetector extends UGraphicNo {
@Override
public UGraphic apply(UChange change) { public UGraphic apply(UChange change) {
if (change instanceof UTranslate) { return new CollisionDetector(this, change);
return new CollisionDetector(stringBounder, translate.compose((UTranslate) change), this.context);
} else if (change instanceof UStroke) {
return new CollisionDetector(this);
} else if (change instanceof UBackground) {
return new CollisionDetector(this);
} else if (change instanceof HColor) {
return new CollisionDetector(this);
}
throw new UnsupportedOperationException();
} }
private final StringBounder stringBounder;
private final UTranslate translate;
private final Context context; private final Context context;
public CollisionDetector(StringBounder stringBounder) {
super(stringBounder);
this.context = new Context();
}
private CollisionDetector(CollisionDetector other, UChange change) {
super(other, change);
if (!instanceOfAny(change,
UBackground.class,
HColor.class,
UStroke.class,
UTranslate.class
)) {
throw new UnsupportedOperationException(change.getClass().toString());
}
this.context = other.context;
}
static class Context { static class Context {
private final List<MinMax> rectangles = new ArrayList<>(); private final List<MinMax> rectangles = new ArrayList<>();
private final List<Snake> snakes = new ArrayList<>(); private final List<Snake> snakes = new ArrayList<>();
@ -146,28 +153,6 @@ public class CollisionDetector extends UGraphicNo implements UGraphic {
return true; return true;
} }
public CollisionDetector(StringBounder stringBounder) {
this(stringBounder, new UTranslate(), new Context());
}
private CollisionDetector(StringBounder stringBounder, UTranslate translate, Context context) {
this.stringBounder = stringBounder;
this.translate = translate;
this.context = context;
}
private CollisionDetector(CollisionDetector other) {
this(other.stringBounder, other.translate, other.context);
}
public StringBounder getStringBounder() {
return stringBounder;
}
public UParam getParam() {
return new UParamNull();
}
public void draw(UShape shape) { public void draw(UShape shape) {
if (shape instanceof UPolygon) { if (shape instanceof UPolygon) {
drawPolygone((UPolygon) shape); drawPolygone((UPolygon) shape);
@ -182,24 +167,17 @@ public class CollisionDetector extends UGraphicNo implements UGraphic {
private void drawSnake(Snake shape) { private void drawSnake(Snake shape) {
if (context.manageSnakes) { if (context.manageSnakes) {
context.snakes.add(shape.translate(translate)); context.snakes.add(shape.translate(getTranslate()));
} }
} }
private void drawRectangle(URectangle shape) { private void drawRectangle(URectangle shape) {
context.rectangles.add(shape.getMinMax().translate(translate)); context.rectangles.add(shape.getMinMax().translate(getTranslate()));
} }
private void drawPolygone(UPolygon shape) { private void drawPolygone(UPolygon shape) {
context.rectangles.add(shape.getMinMax().translate(translate)); context.rectangles.add(shape.getMinMax().translate(getTranslate()));
}
public ColorMapper getColorMapper() {
throw new UnsupportedOperationException();
}
public void flushUg() {
} }
public void drawDebug(UGraphic ug) { public void drawDebug(UGraphic ug) {
@ -210,12 +188,4 @@ public class CollisionDetector extends UGraphicNo implements UGraphic {
this.context.manageSnakes = manageSnakes; this.context.manageSnakes = manageSnakes;
} }
public boolean matchesProperty(String propertyName) {
return false;
}
public double dpiFactor() {
return 1;
}
} }

View File

@ -35,38 +35,26 @@
*/ */
package net.sourceforge.plantuml.activitydiagram3.ftile; package net.sourceforge.plantuml.activitydiagram3.ftile;
import static net.sourceforge.plantuml.utils.ObjectUtils.instanceOfAny;
import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.ugraphic.MinMax; import net.sourceforge.plantuml.ugraphic.MinMax;
import net.sourceforge.plantuml.ugraphic.UBackground; import net.sourceforge.plantuml.ugraphic.UBackground;
import net.sourceforge.plantuml.ugraphic.UChange; import net.sourceforge.plantuml.ugraphic.UChange;
import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UGraphicNo; import net.sourceforge.plantuml.ugraphic.UGraphicNo;
import net.sourceforge.plantuml.ugraphic.UParam;
import net.sourceforge.plantuml.ugraphic.UParamNull;
import net.sourceforge.plantuml.ugraphic.URectangle; import net.sourceforge.plantuml.ugraphic.URectangle;
import net.sourceforge.plantuml.ugraphic.UShape; import net.sourceforge.plantuml.ugraphic.UShape;
import net.sourceforge.plantuml.ugraphic.UStroke; import net.sourceforge.plantuml.ugraphic.UStroke;
import net.sourceforge.plantuml.ugraphic.UTranslate; import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.color.ColorMapper;
import net.sourceforge.plantuml.ugraphic.color.HColor; import net.sourceforge.plantuml.ugraphic.color.HColor;
public class ZadBuilder extends UGraphicNo implements UGraphic { public class ZadBuilder extends UGraphicNo {
@Override
public UGraphic apply(UChange change) { public UGraphic apply(UChange change) {
if (change instanceof UTranslate) { return new ZadBuilder(this, change);
return new ZadBuilder(stringBounder, translate.compose((UTranslate) change), this.context);
} else if (change instanceof UStroke) {
return new ZadBuilder(this);
} else if (change instanceof UBackground) {
return new ZadBuilder(this);
} else if (change instanceof HColor) {
return new ZadBuilder(this);
}
throw new UnsupportedOperationException();
} }
private final StringBounder stringBounder;
private final UTranslate translate;
private final Context context; private final Context context;
static class Context { static class Context {
@ -74,25 +62,21 @@ public class ZadBuilder extends UGraphicNo implements UGraphic {
} }
public ZadBuilder(StringBounder stringBounder) { public ZadBuilder(StringBounder stringBounder) {
this(stringBounder, new UTranslate(), new Context()); super(stringBounder);
this.context = new Context();
} }
private ZadBuilder(StringBounder stringBounder, UTranslate translate, Context context) { private ZadBuilder(ZadBuilder other, UChange change) {
this.stringBounder = stringBounder; super(other, change);
this.translate = translate; if (!instanceOfAny(change,
this.context = context; UBackground.class,
} HColor.class,
UStroke.class,
private ZadBuilder(ZadBuilder other) { UTranslate.class
this(other.stringBounder, other.translate, other.context); )) {
} throw new UnsupportedOperationException(change.getClass().toString());
}
public StringBounder getStringBounder() { this.context = other.context;
return stringBounder;
}
public UParam getParam() {
return new UParamNull();
} }
public void draw(UShape shape) { public void draw(UShape shape) {
@ -102,26 +86,11 @@ public class ZadBuilder extends UGraphicNo implements UGraphic {
} }
private void drawRectangle(URectangle shape) { private void drawRectangle(URectangle shape) {
final MinMax area = shape.getMinMax().translate(translate); final MinMax area = shape.getMinMax().translate(getTranslate());
// System.err.println("ZadBuilder " + shape + " " + area); // System.err.println("ZadBuilder " + shape + " " + area);
context.zad.add(area); context.zad.add(area);
} }
public ColorMapper getColorMapper() {
throw new UnsupportedOperationException();
}
public void flushUg() {
}
public boolean matchesProperty(String propertyName) {
return false;
}
public double dpiFactor() {
return 1;
}
public Zad getZad() { public Zad getZad() {
return context.zad; return context.zad;
} }

View File

@ -35,6 +35,8 @@
*/ */
package net.sourceforge.plantuml.svek.image; package net.sourceforge.plantuml.svek.image;
import static net.sourceforge.plantuml.utils.ObjectUtils.instanceOfAny;
import java.awt.geom.Dimension2D; import java.awt.geom.Dimension2D;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.util.ArrayList; import java.util.ArrayList;
@ -50,8 +52,6 @@ import net.sourceforge.plantuml.ugraphic.UGraphicNo;
import net.sourceforge.plantuml.ugraphic.UHorizontalLine; import net.sourceforge.plantuml.ugraphic.UHorizontalLine;
import net.sourceforge.plantuml.ugraphic.UImage; import net.sourceforge.plantuml.ugraphic.UImage;
import net.sourceforge.plantuml.ugraphic.ULine; import net.sourceforge.plantuml.ugraphic.ULine;
import net.sourceforge.plantuml.ugraphic.UParam;
import net.sourceforge.plantuml.ugraphic.UParamNull;
import net.sourceforge.plantuml.ugraphic.UPath; import net.sourceforge.plantuml.ugraphic.UPath;
import net.sourceforge.plantuml.ugraphic.URectangle; import net.sourceforge.plantuml.ugraphic.URectangle;
import net.sourceforge.plantuml.ugraphic.UShape; import net.sourceforge.plantuml.ugraphic.UShape;
@ -71,48 +71,35 @@ public class Footprint {
} }
class MyUGraphic extends UGraphicNo implements UGraphic { class MyUGraphic extends UGraphicNo {
private final UTranslate translate;
private final List<Point2D.Double> all; private final List<Point2D.Double> all;
public double dpiFactor() {
return 1;
}
private MyUGraphic(List<Point2D.Double> all, UTranslate translate) {
this.all = all;
this.translate = translate;
}
public boolean matchesProperty(String propertyName) {
return false;
}
public MyUGraphic() { public MyUGraphic() {
this(new ArrayList<Point2D.Double>(), new UTranslate()); super(stringBounder);
this.all = new ArrayList<>();
}
private MyUGraphic(MyUGraphic other, UChange change) {
super(other, change);
if (!instanceOfAny(change,
UBackground.class,
HColor.class,
UStroke.class,
UTranslate.class
)) {
throw new UnsupportedOperationException(change.getClass().toString());
}
this.all = other.all;
} }
public UGraphic apply(UChange change) { public UGraphic apply(UChange change) {
if (change instanceof UTranslate) { return new MyUGraphic(this, change);
return new MyUGraphic(all, translate.compose((UTranslate) change));
} else if (change instanceof UStroke || change instanceof HColor || change instanceof UBackground) {
return new MyUGraphic(all, translate);
}
throw new UnsupportedOperationException();
}
public StringBounder getStringBounder() {
return stringBounder;
}
public UParam getParam() {
return new UParamNull();
} }
public void draw(UShape shape) { public void draw(UShape shape) {
final double x = translate.getDx(); final double x = getTranslate().getDx();
final double y = translate.getDy(); final double y = getTranslate().getDy();
if (shape instanceof UText) { if (shape instanceof UText) {
drawText(x, y, (UText) shape); drawText(x, y, (UText) shape);
} else if (shape instanceof UHorizontalLine) { } else if (shape instanceof UHorizontalLine) {
@ -142,7 +129,7 @@ public class Footprint {
} }
private void drawText(double x, double y, UText text) { private void drawText(double x, double y, UText text) {
final Dimension2D dim = stringBounder.calculateDimension(text.getFontConfiguration().getFont(), final Dimension2D dim = getStringBounder().calculateDimension(text.getFontConfiguration().getFont(),
text.getText()); text.getText());
y -= dim.getHeight() - 1.5; y -= dim.getHeight() - 1.5;
addPoint(x, y); addPoint(x, y);
@ -172,10 +159,6 @@ public class Footprint {
addPoint(x, y); addPoint(x, y);
addPoint(x + rect.getWidth(), y + rect.getHeight()); addPoint(x + rect.getWidth(), y + rect.getHeight());
} }
public void flushUg() {
}
} }
public ContainingEllipse getEllipse(UDrawable drawable, double alpha) { public ContainingEllipse getEllipse(UDrawable drawable, double alpha) {

View File

@ -35,6 +35,8 @@
*/ */
package net.sourceforge.plantuml.ugraphic; package net.sourceforge.plantuml.ugraphic;
import static net.sourceforge.plantuml.utils.ObjectUtils.instanceOfAny;
import java.awt.geom.Dimension2D; import java.awt.geom.Dimension2D;
import net.sourceforge.plantuml.activitydiagram3.ftile.CenteredText; import net.sourceforge.plantuml.activitydiagram3.ftile.CenteredText;
@ -46,66 +48,38 @@ import net.sourceforge.plantuml.ugraphic.color.ColorMapper;
import net.sourceforge.plantuml.ugraphic.color.ColorMapperIdentity; import net.sourceforge.plantuml.ugraphic.color.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.color.HColor; import net.sourceforge.plantuml.ugraphic.color.HColor;
public class LimitFinder extends UGraphicNo implements UGraphic { public class LimitFinder extends UGraphicNo {
public boolean matchesProperty(String propertyName) {
return false;
}
public double dpiFactor() {
return 1;
}
@Override
public UGraphic apply(UChange change) { public UGraphic apply(UChange change) {
if (change instanceof UTranslate) { return new LimitFinder(this, change);
return new LimitFinder(stringBounder, minmax, translate.compose((UTranslate) change), clip);
} else if (change instanceof UStroke) {
return new LimitFinder(this);
} else if (change instanceof UBackground) {
return new LimitFinder(this);
} else if (change instanceof HColor) {
return new LimitFinder(this);
} else if (change instanceof UHidden) {
return new LimitFinder(this);
} else if (change instanceof UAntiAliasing) {
return new LimitFinder(this);
} else if (change instanceof UScale) {
return new LimitFinder(this);
} else if (change instanceof UClip) {
final LimitFinder copy = new LimitFinder(this);
copy.clip = (UClip) change;
copy.clip = copy.clip.translate(translate);
return copy;
}
throw new UnsupportedOperationException(change.getClass().toString());
} }
private final StringBounder stringBounder;
private final UTranslate translate;
private final MinMaxMutable minmax; private final MinMaxMutable minmax;
private UClip clip; private final UClip clip;
public LimitFinder(StringBounder stringBounder, boolean initToZero) { public LimitFinder(StringBounder stringBounder, boolean initToZero) {
this(stringBounder, MinMaxMutable.getEmpty(initToZero), new UTranslate(), null); super(stringBounder);
this.minmax = MinMaxMutable.getEmpty(initToZero);
this.clip = null;
} }
private LimitFinder(StringBounder stringBounder, MinMaxMutable minmax, UTranslate translate, UClip clip) { private LimitFinder(LimitFinder other, UChange change) {
this.stringBounder = stringBounder; super(other, change);
this.minmax = minmax; if (!instanceOfAny(change,
this.translate = translate; UAntiAliasing.class,
this.clip = clip; UBackground.class,
} UClip.class,
HColor.class,
private LimitFinder(LimitFinder other) { UHidden.class,
this(other.stringBounder, other.minmax, other.translate, other.clip); UScale.class,
} UStroke.class,
UTranslate.class
public StringBounder getStringBounder() { )) {
return stringBounder; throw new UnsupportedOperationException(change.getClass().toString());
} }
this.clip = change instanceof UClip ? ((UClip) change).translate(getTranslate()) : other.clip;
public UParam getParam() { this.minmax = other.minmax;
return new UParamNull();
} }
private void addPoint(double x, double y) { private void addPoint(double x, double y) {
@ -115,8 +89,8 @@ public class LimitFinder extends UGraphicNo implements UGraphic {
} }
public void draw(UShape shape) { public void draw(UShape shape) {
final double x = translate.getDx(); final double x = getTranslate().getDx();
final double y = translate.getDy(); final double y = getTranslate().getDy();
if (shape instanceof UText) { if (shape instanceof UText) {
drawText(x, y, (UText) shape); drawText(x, y, (UText) shape);
} else if (shape instanceof ULine) { } else if (shape instanceof ULine) {
@ -208,7 +182,7 @@ public class LimitFinder extends UGraphicNo implements UGraphic {
} }
private void drawText(double x, double y, UText text) { private void drawText(double x, double y, UText text) {
final Dimension2D dim = stringBounder.calculateDimension(text.getFontConfiguration().getFont(), text.getText()); final Dimension2D dim = getStringBounder().calculateDimension(text.getFontConfiguration().getFont(), text.getText());
y -= dim.getHeight() - 1.5; y -= dim.getHeight() - 1.5;
addPoint(x, y); addPoint(x, y);
addPoint(x, y + dim.getHeight()); addPoint(x, y + dim.getHeight());
@ -243,7 +217,4 @@ public class LimitFinder extends UGraphicNo implements UGraphic {
return MinMax.fromMutable(minmax); return MinMax.fromMutable(minmax);
} }
public void flushUg() {
}
} }

View File

@ -35,75 +35,50 @@
*/ */
package net.sourceforge.plantuml.ugraphic; package net.sourceforge.plantuml.ugraphic;
import static net.sourceforge.plantuml.utils.ObjectUtils.instanceOfAny;
import java.awt.geom.Dimension2D; import java.awt.geom.Dimension2D;
import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.ugraphic.color.ColorMapper;
import net.sourceforge.plantuml.ugraphic.color.HColor; import net.sourceforge.plantuml.ugraphic.color.HColor;
public class TextLimitFinder extends UGraphicNo implements UGraphic { public class TextLimitFinder extends UGraphicNo {
public boolean matchesProperty(String propertyName) {
return false;
}
public double dpiFactor() {
return 1;
}
@Override
public UGraphic apply(UChange change) { public UGraphic apply(UChange change) {
if (change instanceof UTranslate) { return new TextLimitFinder(this, change);
return new TextLimitFinder(stringBounder, minmax, translate.compose((UTranslate) change));
} else if (change instanceof UStroke) {
return new TextLimitFinder(this);
} else if (change instanceof UBackground) {
return new TextLimitFinder(this);
} else if (change instanceof HColor) {
return new TextLimitFinder(this);
}
throw new UnsupportedOperationException();
} }
private final StringBounder stringBounder;
private final UTranslate translate;
private final MinMaxMutable minmax; private final MinMaxMutable minmax;
public TextLimitFinder(StringBounder stringBounder, boolean initToZero) { public TextLimitFinder(StringBounder stringBounder, boolean initToZero) {
this(stringBounder, MinMaxMutable.getEmpty(initToZero), new UTranslate()); super(stringBounder);
this.minmax = MinMaxMutable.getEmpty(initToZero);
} }
private TextLimitFinder(StringBounder stringBounder, MinMaxMutable minmax, UTranslate translate) { private TextLimitFinder(TextLimitFinder other, UChange change) {
this.stringBounder = stringBounder; super(other, change);
this.minmax = minmax; if (!instanceOfAny(change,
this.translate = translate; UBackground.class,
} HColor.class,
UStroke.class,
private TextLimitFinder(TextLimitFinder other) { UTranslate.class
this(other.stringBounder, other.minmax, other.translate); )) {
} throw new UnsupportedOperationException(change.getClass().toString());
}
public StringBounder getStringBounder() { this.minmax = other.minmax;
return stringBounder;
}
public UParam getParam() {
return new UParamNull();
} }
public void draw(UShape shape) { public void draw(UShape shape) {
if (shape instanceof UText) { if (shape instanceof UText) {
final double x = translate.getDx(); final double x = getTranslate().getDx();
final double y = translate.getDy(); final double y = getTranslate().getDy();
drawText(x, y, (UText) shape); drawText(x, y, (UText) shape);
} }
} }
public ColorMapper getColorMapper() {
throw new UnsupportedOperationException();
}
private void drawText(double x, double y, UText text) { private void drawText(double x, double y, UText text) {
final Dimension2D dim = stringBounder.calculateDimension(text.getFontConfiguration().getFont(), text.getText()); final Dimension2D dim = getStringBounder().calculateDimension(text.getFontConfiguration().getFont(), text.getText());
y -= dim.getHeight() - 1.5; y -= dim.getHeight() - 1.5;
minmax.addPoint(x, y); minmax.addPoint(x, y);
minmax.addPoint(x, y + dim.getHeight()); minmax.addPoint(x, y + dim.getHeight());
@ -127,7 +102,4 @@ public class TextLimitFinder extends UGraphicNo implements UGraphic {
return minmax.getMinY(); return minmax.getMinY();
} }
public void flushUg() {
}
} }

View File

@ -36,25 +36,80 @@
package net.sourceforge.plantuml.ugraphic; package net.sourceforge.plantuml.ugraphic;
import net.sourceforge.plantuml.Url; import net.sourceforge.plantuml.Url;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.ugraphic.color.ColorMapper;
import net.sourceforge.plantuml.ugraphic.color.HColor; import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorUtils; import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
public abstract class UGraphicNo { public abstract class UGraphicNo implements UGraphic {
private final StringBounder stringBounder;
private final UTranslate translate;
public UGraphicNo(StringBounder stringBounder) {
this.stringBounder = stringBounder;
this.translate = new UTranslate();
}
public UGraphicNo(UGraphicNo other, UChange change) {
this.stringBounder = other.stringBounder;
this.translate = change instanceof UTranslate ? other.translate.compose((UTranslate) change) : other.translate;
}
//
// Implement UGraphic
//
@Override
final public void startUrl(Url url) { final public void startUrl(Url url) {
} }
@Override
public void startGroup(UGroupType type, String ident) { public void startGroup(UGroupType type, String ident) {
} }
@Override
final public void closeUrl() { final public void closeUrl() {
} }
@Override
final public void closeGroup() { final public void closeGroup() {
} }
@Override
public ColorMapper getColorMapper() {
throw new UnsupportedOperationException();
}
@Override
public HColor getDefaultBackground() { public HColor getDefaultBackground() {
return HColorUtils.BLACK; return HColorUtils.BLACK;
} }
@Override
public UParam getParam() {
return new UParamNull();
}
@Override
public StringBounder getStringBounder() {
return stringBounder;
}
@Override
public void flushUg() {
}
@Override
public boolean matchesProperty(String propertyName) {
return false;
}
//
// Internal things
//
protected UTranslate getTranslate() {
return translate;
}
} }

View File

@ -35,6 +35,7 @@
*/ */
package net.sourceforge.plantuml.ugraphic.comp; package net.sourceforge.plantuml.ugraphic.comp;
import static net.sourceforge.plantuml.utils.ObjectUtils.instanceOfAny;
import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.ugraphic.TextLimitFinder; import net.sourceforge.plantuml.ugraphic.TextLimitFinder;
import net.sourceforge.plantuml.ugraphic.UBackground; import net.sourceforge.plantuml.ugraphic.UBackground;
@ -43,8 +44,6 @@ import net.sourceforge.plantuml.ugraphic.UEllipse;
import net.sourceforge.plantuml.ugraphic.UEmpty; import net.sourceforge.plantuml.ugraphic.UEmpty;
import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UGraphicNo; import net.sourceforge.plantuml.ugraphic.UGraphicNo;
import net.sourceforge.plantuml.ugraphic.UParam;
import net.sourceforge.plantuml.ugraphic.UParamNull;
import net.sourceforge.plantuml.ugraphic.UPath; import net.sourceforge.plantuml.ugraphic.UPath;
import net.sourceforge.plantuml.ugraphic.UPolygon; import net.sourceforge.plantuml.ugraphic.UPolygon;
import net.sourceforge.plantuml.ugraphic.URectangle; import net.sourceforge.plantuml.ugraphic.URectangle;
@ -57,61 +56,40 @@ import net.sourceforge.plantuml.ugraphic.color.ColorMapper;
import net.sourceforge.plantuml.ugraphic.color.ColorMapperIdentity; import net.sourceforge.plantuml.ugraphic.color.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.color.HColor; import net.sourceforge.plantuml.ugraphic.color.HColor;
public class SlotFinder extends UGraphicNo implements UGraphic { public class SlotFinder extends UGraphicNo {
public boolean matchesProperty(String propertyName) {
return false;
}
public double dpiFactor() {
return 1;
}
@Override
public UGraphic apply(UChange change) { public UGraphic apply(UChange change) {
if (change instanceof UTranslate) { return new SlotFinder(this, change);
return new SlotFinder(mode, stringBounder, slot, translate.compose((UTranslate) change));
} else if (change instanceof UStroke) {
return new SlotFinder(this);
} else if (change instanceof UBackground) {
return new SlotFinder(this);
} else if (change instanceof HColor) {
return new SlotFinder(this);
}
throw new UnsupportedOperationException();
} }
private final SlotSet slot; private final SlotSet slot;
private final StringBounder stringBounder;
private final UTranslate translate;
private final CompressionMode mode; private final CompressionMode mode;
public SlotFinder(CompressionMode mode, StringBounder stringBounder) { public SlotFinder(CompressionMode mode, StringBounder stringBounder) {
this(mode, stringBounder, new SlotSet(), new UTranslate()); super(stringBounder);
} this.slot = new SlotSet();
private SlotFinder(CompressionMode mode, StringBounder stringBounder, SlotSet slot, UTranslate translate) {
this.stringBounder = stringBounder;
this.slot = slot;
this.translate = translate;
this.mode = mode; this.mode = mode;
} }
private SlotFinder(SlotFinder other) { private SlotFinder(SlotFinder other, UChange change) {
this(other.mode, other.stringBounder, other.slot, other.translate); super(other, change);
} if (!instanceOfAny(change,
UBackground.class,
public StringBounder getStringBounder() { HColor.class,
return stringBounder; UStroke.class,
} UTranslate.class
)) {
public UParam getParam() { throw new UnsupportedOperationException(change.getClass().toString());
return new UParamNull(); }
this.mode = other.mode;
this.slot = other.slot;
} }
public void draw(UShape sh) { public void draw(UShape sh) {
final double x = translate.getDx(); final double x = getTranslate().getDx();
final double y = translate.getDy(); final double y = getTranslate().getDy();
if (sh instanceof UShapeIgnorableForCompression) { if (sh instanceof UShapeIgnorableForCompression) {
final UShapeIgnorableForCompression shape = (UShapeIgnorableForCompression) sh; final UShapeIgnorableForCompression shape = (UShapeIgnorableForCompression) sh;
if (shape.isIgnoreForCompressionOn(mode)) { if (shape.isIgnoreForCompressionOn(mode)) {
@ -154,7 +132,7 @@ public class SlotFinder extends UGraphicNo implements UGraphic {
} }
private void drawText(double x, double y, UText shape) { private void drawText(double x, double y, UText shape) {
final TextLimitFinder finder = new TextLimitFinder(stringBounder, false); final TextLimitFinder finder = new TextLimitFinder(getStringBounder(), false);
finder.apply(new UTranslate(x, y)).draw(shape); finder.apply(new UTranslate(x, y)).draw(shape);
if (mode == CompressionMode.ON_X) { if (mode == CompressionMode.ON_X) {
slot.addSlot(finder.getMinX(), finder.getMaxX()); slot.addSlot(finder.getMinX(), finder.getMaxX());
@ -198,7 +176,4 @@ public class SlotFinder extends UGraphicNo implements UGraphic {
return slot; return slot;
} }
public void flushUg() {
}
} }

View File

@ -0,0 +1,13 @@
package net.sourceforge.plantuml.utils;
public class ObjectUtils {
public static boolean instanceOfAny(Object object, Class<?>... classes) {
for (Class<?> c : classes) {
if (c.isInstance(object)) {
return true;
}
}
return false;
}
}