mirror of
https://github.com/octoleo/plantuml.git
synced 2024-11-26 14:56:28 +00:00
Merge pull request #519 from matthew16550/drawable
Add ImageBuilder.imageBuilder() & ImageBuilder.drawable(). Move ImageBuilder creation to CucaDiagram & SequenceDiagram classes.
This commit is contained in:
commit
49c9fba2ec
@ -65,10 +65,13 @@ import net.sourceforge.plantuml.statediagram.StateDiagram;
|
|||||||
import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft;
|
import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft;
|
||||||
import net.sourceforge.plantuml.svek.CucaDiagramFileMaker;
|
import net.sourceforge.plantuml.svek.CucaDiagramFileMaker;
|
||||||
import net.sourceforge.plantuml.svek.CucaDiagramFileMakerSvek;
|
import net.sourceforge.plantuml.svek.CucaDiagramFileMakerSvek;
|
||||||
|
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
|
||||||
import net.sourceforge.plantuml.ugraphic.color.ColorMapper;
|
import net.sourceforge.plantuml.ugraphic.color.ColorMapper;
|
||||||
import net.sourceforge.plantuml.xmi.CucaDiagramXmiMaker;
|
import net.sourceforge.plantuml.xmi.CucaDiagramXmiMaker;
|
||||||
import net.sourceforge.plantuml.xmlsc.StateDiagramScxmlMaker;
|
import net.sourceforge.plantuml.xmlsc.StateDiagramScxmlMaker;
|
||||||
|
|
||||||
|
import static net.sourceforge.plantuml.ugraphic.ImageBuilder.imageBuilder;
|
||||||
|
|
||||||
public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, PortionShower {
|
public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, PortionShower {
|
||||||
|
|
||||||
static private final boolean G1972 = false;
|
static private final boolean G1972 = false;
|
||||||
@ -620,6 +623,11 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy,
|
|||||||
maker.createFiles(suggestedFile);
|
maker.createFiles(suggestedFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ImageBuilder createImageBuilder(FileFormatOption fileFormatOption) {
|
||||||
|
return imageBuilder(fileFormatOption)
|
||||||
|
.styled(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ImageData exportDiagramInternal(OutputStream os, int index, FileFormatOption fileFormatOption)
|
protected ImageData exportDiagramInternal(OutputStream os, int index, FileFormatOption fileFormatOption)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
@ -42,7 +42,6 @@ import static gen.lib.cgraph.node__c.agnode;
|
|||||||
import static gen.lib.cgraph.subg__c.agsubg;
|
import static gen.lib.cgraph.subg__c.agsubg;
|
||||||
import static gen.lib.gvc.gvc__c.gvContext;
|
import static gen.lib.gvc.gvc__c.gvContext;
|
||||||
import static gen.lib.gvc.gvlayout__c.gvLayoutJobs;
|
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.Dimension2D;
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
@ -450,7 +449,8 @@ public class CucaDiagramFileMakerSmetana implements CucaDiagramFileMaker {
|
|||||||
|
|
||||||
// imageBuilder.setUDrawable(new Drawing(new YMirror(dim.getHeight())));
|
// imageBuilder.setUDrawable(new Drawing(new YMirror(dim.getHeight())));
|
||||||
final TextBlock drawable = new Drawing(new YMirror(minMax.getMaxY()), minMax);
|
final TextBlock drawable = new Drawing(new YMirror(minMax.getMaxY()), minMax);
|
||||||
return styledImageBuilder(diagram, drawable, 1, fileFormatOption)
|
return diagram.createImageBuilder(fileFormatOption)
|
||||||
|
.drawable(drawable)
|
||||||
.write(os);
|
.write(os);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
SmetanaDebug.printMe();
|
SmetanaDebug.printMe();
|
||||||
|
@ -67,8 +67,11 @@ import net.sourceforge.plantuml.sequencediagram.graphic.SequenceDiagramTxtMaker;
|
|||||||
import net.sourceforge.plantuml.sequencediagram.teoz.SequenceDiagramFileMakerTeoz;
|
import net.sourceforge.plantuml.sequencediagram.teoz.SequenceDiagramFileMakerTeoz;
|
||||||
import net.sourceforge.plantuml.skin.rose.Rose;
|
import net.sourceforge.plantuml.skin.rose.Rose;
|
||||||
import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft;
|
import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft;
|
||||||
|
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
|
||||||
import net.sourceforge.plantuml.ugraphic.color.HColor;
|
import net.sourceforge.plantuml.ugraphic.color.HColor;
|
||||||
|
|
||||||
|
import static net.sourceforge.plantuml.ugraphic.ImageBuilder.imageBuilder;
|
||||||
|
|
||||||
public class SequenceDiagram extends UmlDiagram {
|
public class SequenceDiagram extends UmlDiagram {
|
||||||
|
|
||||||
private final List<Participant> participantsList = new ArrayList<Participant>();
|
private final List<Participant> participantsList = new ArrayList<Participant>();
|
||||||
@ -244,6 +247,12 @@ public class SequenceDiagram extends UmlDiagram {
|
|||||||
return OptionFlags.FORCE_TEOZ || getPragma().useTeozLayout();
|
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
|
@Override
|
||||||
protected ImageData exportDiagramInternal(OutputStream os, int index, FileFormatOption fileFormat)
|
protected ImageData exportDiagramInternal(OutputStream os, int index, FileFormatOption fileFormat)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
@ -71,8 +71,6 @@ import net.sourceforge.plantuml.ugraphic.UGraphic;
|
|||||||
import net.sourceforge.plantuml.ugraphic.UTranslate;
|
import net.sourceforge.plantuml.ugraphic.UTranslate;
|
||||||
import net.sourceforge.plantuml.ugraphic.color.HColor;
|
import net.sourceforge.plantuml.ugraphic.color.HColor;
|
||||||
|
|
||||||
import static net.sourceforge.plantuml.ugraphic.ImageBuilder.styledImageBuilder;
|
|
||||||
|
|
||||||
public class SequenceDiagramFileMakerPuma2 implements FileMaker {
|
public class SequenceDiagramFileMakerPuma2 implements FileMaker {
|
||||||
|
|
||||||
private final SequenceDiagram diagram;
|
private final SequenceDiagram diagram;
|
||||||
@ -220,8 +218,8 @@ public class SequenceDiagramFileMakerPuma2 implements FileMaker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
return styledImageBuilder(diagram, drawable, index, fileFormatOption)
|
return diagram.createImageBuilder(fileFormatOption)
|
||||||
.annotations(false) // they are managed above
|
.drawable(drawable)
|
||||||
.write(os);
|
.write(os);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,8 +35,6 @@
|
|||||||
*/
|
*/
|
||||||
package net.sourceforge.plantuml.sequencediagram.teoz;
|
package net.sourceforge.plantuml.sequencediagram.teoz;
|
||||||
|
|
||||||
import static net.sourceforge.plantuml.ugraphic.ImageBuilder.styledImageBuilder;
|
|
||||||
|
|
||||||
import java.awt.geom.Dimension2D;
|
import java.awt.geom.Dimension2D;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
@ -139,8 +137,8 @@ public class SequenceDiagramFileMakerTeoz implements FileMaker {
|
|||||||
if (this.index != index) {
|
if (this.index != index) {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
return styledImageBuilder(diagram, new Foo(index), index, fileFormatOption) //
|
return diagram.createImageBuilder(fileFormatOption)
|
||||||
.annotations(false) // they are managed in drawInternal()
|
.drawable(new Foo(index))
|
||||||
.write(os);
|
.write(os);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,8 +120,9 @@ public final class CucaDiagramFileMakerSvek implements CucaDiagramFileMaker {
|
|||||||
// Sorry about this hack. There is a side effect in SvekResult::calculateDimension()
|
// Sorry about this hack. There is a side effect in SvekResult::calculateDimension()
|
||||||
result.calculateDimension(stringBounder); // Ensure text near the margins is not cut off
|
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)
|
.annotations(false) // backwards compatibility (AnnotatedWorker is used above)
|
||||||
|
.drawable(result)
|
||||||
.status(result instanceof GraphvizCrash ? 503 : 0)
|
.status(result instanceof GraphvizCrash ? 503 : 0)
|
||||||
.warningOrError(warningOrError)
|
.warningOrError(warningOrError)
|
||||||
.write(os);
|
.write(os);
|
||||||
|
@ -136,29 +136,31 @@ public class ImageBuilder {
|
|||||||
private boolean randomPixel;
|
private boolean randomPixel;
|
||||||
private String warningOrError;
|
private String warningOrError;
|
||||||
|
|
||||||
|
public static ImageBuilder imageBuilder(FileFormatOption fileFormatOption) {
|
||||||
|
return new ImageBuilder(fileFormatOption);
|
||||||
|
}
|
||||||
|
|
||||||
public static ImageBuilder plainImageBuilder(UDrawable drawable, FileFormatOption 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) {
|
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"
|
// TODO do something with "index"
|
||||||
public static ImageBuilder styledImageBuilder(TitledDiagram diagram, UDrawable drawable, int index,
|
public static ImageBuilder styledImageBuilder(TitledDiagram diagram, UDrawable drawable, int index,
|
||||||
FileFormatOption fileFormatOption) {
|
FileFormatOption fileFormatOption) {
|
||||||
return new ImageBuilder(drawable, fileFormatOption)
|
return imageBuilder(fileFormatOption)
|
||||||
|
.drawable(drawable)
|
||||||
.styled(diagram);
|
.styled(diagram);
|
||||||
}
|
}
|
||||||
|
|
||||||
private ImageBuilder(UDrawable drawable, FileFormatOption fileFormatOption) {
|
private ImageBuilder(FileFormatOption fileFormatOption) {
|
||||||
this.udrawable = drawable;
|
|
||||||
this.fileFormatOption = fileFormatOption;
|
this.fileFormatOption = fileFormatOption;
|
||||||
this.preserveAspectRatio = calculatePreserveAspectRatio(fileFormatOption, null);
|
this.preserveAspectRatio = calculatePreserveAspectRatio(fileFormatOption, null);
|
||||||
|
|
||||||
if (drawable instanceof TextBlockBackcolored) {
|
|
||||||
backcolor = ((TextBlockBackcolored) drawable).getBackcolor();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImageBuilder annotations(boolean annotations) {
|
public ImageBuilder annotations(boolean annotations) {
|
||||||
@ -180,6 +182,14 @@ public class ImageBuilder {
|
|||||||
return this;
|
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) {
|
public ImageBuilder margin(ClockwiseTopRightBottomLeft margin) {
|
||||||
this.margin = margin;
|
this.margin = margin;
|
||||||
return this;
|
return this;
|
||||||
@ -214,7 +224,7 @@ public class ImageBuilder {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ImageBuilder styled(TitledDiagram diagram) {
|
public ImageBuilder styled(TitledDiagram diagram) {
|
||||||
final ISkinParam skinParam = diagram.getSkinParam();
|
final ISkinParam skinParam = diagram.getSkinParam();
|
||||||
animation = diagram.getAnimation();
|
animation = diagram.getAnimation();
|
||||||
annotations = true;
|
annotations = true;
|
||||||
|
Loading…
Reference in New Issue
Block a user