1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-05-31 23:50:49 +00:00

Add ImageBuilder.imageBuilder() & ImageBuilder.drawable(). Move ImageBuilder creation to CucaDiagram & SequenceDiagram classes.

This commit is contained in:
matthew16550 2021-04-03 11:49:34 +11:00
parent 33ba37318c
commit af3dbd1cdb
7 changed files with 45 additions and 21 deletions

View File

@ -65,10 +65,13 @@ import net.sourceforge.plantuml.statediagram.StateDiagram;
import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft;
import net.sourceforge.plantuml.svek.CucaDiagramFileMaker;
import net.sourceforge.plantuml.svek.CucaDiagramFileMakerSvek;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
import net.sourceforge.plantuml.ugraphic.color.ColorMapper;
import net.sourceforge.plantuml.xmi.CucaDiagramXmiMaker;
import net.sourceforge.plantuml.xmlsc.StateDiagramScxmlMaker;
import static net.sourceforge.plantuml.ugraphic.ImageBuilder.imageBuilder;
public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, PortionShower {
static private final boolean G1972 = false;
@ -620,6 +623,11 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy,
maker.createFiles(suggestedFile);
}
public ImageBuilder createImageBuilder(FileFormatOption fileFormatOption) {
return imageBuilder(fileFormatOption)
.styled(this);
}
@Override
protected ImageData exportDiagramInternal(OutputStream os, int index, FileFormatOption fileFormatOption)
throws IOException {

View File

@ -42,7 +42,6 @@ import static gen.lib.cgraph.node__c.agnode;
import static gen.lib.cgraph.subg__c.agsubg;
import static gen.lib.gvc.gvc__c.gvContext;
import static gen.lib.gvc.gvlayout__c.gvLayoutJobs;
import static net.sourceforge.plantuml.ugraphic.ImageBuilder.styledImageBuilder;
import java.awt.geom.Dimension2D;
import java.awt.geom.Point2D;
@ -450,7 +449,8 @@ public class CucaDiagramFileMakerSmetana implements CucaDiagramFileMaker {
// imageBuilder.setUDrawable(new Drawing(new YMirror(dim.getHeight())));
final TextBlock drawable = new Drawing(new YMirror(minMax.getMaxY()), minMax);
return styledImageBuilder(diagram, drawable, 1, fileFormatOption)
return diagram.createImageBuilder(fileFormatOption)
.drawable(drawable)
.write(os);
} catch (Throwable e) {
SmetanaDebug.printMe();

View File

@ -67,8 +67,11 @@ import net.sourceforge.plantuml.sequencediagram.graphic.SequenceDiagramTxtMaker;
import net.sourceforge.plantuml.sequencediagram.teoz.SequenceDiagramFileMakerTeoz;
import net.sourceforge.plantuml.skin.rose.Rose;
import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import static net.sourceforge.plantuml.ugraphic.ImageBuilder.imageBuilder;
public class SequenceDiagram extends UmlDiagram {
private final List<Participant> participantsList = new ArrayList<Participant>();
@ -244,6 +247,12 @@ public class SequenceDiagram extends UmlDiagram {
return OptionFlags.FORCE_TEOZ || getPragma().useTeozLayout();
}
public ImageBuilder createImageBuilder(FileFormatOption fileFormatOption) {
return imageBuilder(fileFormatOption)
.styled(this)
.annotations(false); // they are managed in the SequenceDiagramFileMaker* classes
}
@Override
protected ImageData exportDiagramInternal(OutputStream os, int index, FileFormatOption fileFormat)
throws IOException {

View File

@ -71,8 +71,6 @@ import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import static net.sourceforge.plantuml.ugraphic.ImageBuilder.styledImageBuilder;
public class SequenceDiagramFileMakerPuma2 implements FileMaker {
private final SequenceDiagram diagram;
@ -220,8 +218,8 @@ public class SequenceDiagramFileMakerPuma2 implements FileMaker {
}
};
return styledImageBuilder(diagram, drawable, index, fileFormatOption)
.annotations(false) // they are managed above
return diagram.createImageBuilder(fileFormatOption)
.drawable(drawable)
.write(os);
}

View File

@ -35,8 +35,6 @@
*/
package net.sourceforge.plantuml.sequencediagram.teoz;
import static net.sourceforge.plantuml.ugraphic.ImageBuilder.styledImageBuilder;
import java.awt.geom.Dimension2D;
import java.io.IOException;
import java.io.OutputStream;
@ -139,8 +137,8 @@ public class SequenceDiagramFileMakerTeoz implements FileMaker {
if (this.index != index) {
throw new IllegalStateException();
}
return styledImageBuilder(diagram, new Foo(index), index, fileFormatOption) //
.annotations(false) // they are managed in drawInternal()
return diagram.createImageBuilder(fileFormatOption)
.drawable(new Foo(index))
.write(os);
}

View File

@ -120,8 +120,9 @@ public final class CucaDiagramFileMakerSvek implements CucaDiagramFileMaker {
// Sorry about this hack. There is a side effect in SvekResult::calculateDimension()
result.calculateDimension(stringBounder); // Ensure text near the margins is not cut off
return styledImageBuilder(diagram, result, 1, fileFormatOption)
return diagram.createImageBuilder(fileFormatOption)
.annotations(false) // backwards compatibility (AnnotatedWorker is used above)
.drawable(result)
.status(result instanceof GraphvizCrash ? 503 : 0)
.warningOrError(warningOrError)
.write(os);

View File

@ -136,29 +136,31 @@ public class ImageBuilder {
private boolean randomPixel;
private String warningOrError;
public static ImageBuilder imageBuilder(FileFormatOption fileFormatOption) {
return new ImageBuilder(fileFormatOption);
}
public static ImageBuilder plainImageBuilder(UDrawable drawable, FileFormatOption fileFormatOption) {
return new ImageBuilder(drawable, fileFormatOption);
return imageBuilder(fileFormatOption)
.drawable(drawable);
}
public static ImageBuilder plainPngBuilder(UDrawable drawable) {
return plainImageBuilder(drawable, new FileFormatOption(FileFormat.PNG));
return imageBuilder(new FileFormatOption(FileFormat.PNG))
.drawable(drawable);
}
// TODO do something with "index"
public static ImageBuilder styledImageBuilder(TitledDiagram diagram, UDrawable drawable, int index,
FileFormatOption fileFormatOption) {
return new ImageBuilder(drawable, fileFormatOption)
return imageBuilder(fileFormatOption)
.drawable(drawable)
.styled(diagram);
}
private ImageBuilder(UDrawable drawable, FileFormatOption fileFormatOption) {
this.udrawable = drawable;
private ImageBuilder(FileFormatOption fileFormatOption) {
this.fileFormatOption = fileFormatOption;
this.preserveAspectRatio = calculatePreserveAspectRatio(fileFormatOption, null);
if (drawable instanceof TextBlockBackcolored) {
backcolor = ((TextBlockBackcolored) drawable).getBackcolor();
}
}
public ImageBuilder annotations(boolean annotations) {
@ -180,6 +182,14 @@ public class ImageBuilder {
return this;
}
public ImageBuilder drawable(UDrawable drawable) {
this.udrawable = drawable;
if (backcolor == null && drawable instanceof TextBlockBackcolored) {
backcolor = ((TextBlockBackcolored) drawable).getBackcolor();
}
return this;
}
public ImageBuilder margin(ClockwiseTopRightBottomLeft margin) {
this.margin = margin;
return this;
@ -214,7 +224,7 @@ public class ImageBuilder {
return this;
}
private ImageBuilder styled(TitledDiagram diagram) {
public ImageBuilder styled(TitledDiagram diagram) {
final ISkinParam skinParam = diagram.getSkinParam();
animation = diagram.getAnimation();
annotations = true;