1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-11-25 22:37:33 +00:00
This commit is contained in:
Arnaud Roques 2021-11-21 12:09:15 +01:00
parent 444709e815
commit 38877c5420
14 changed files with 344 additions and 148 deletions

View File

@ -204,4 +204,9 @@ public abstract class AbstractPSystem implements Diagram {
return ClockwiseTopRightBottomLeft.same(0);
}
@Override
public Display getTitleDisplay() {
return null;
}
}

View File

@ -39,6 +39,7 @@ import java.io.IOException;
import net.sourceforge.plantuml.anim.Animation;
import net.sourceforge.plantuml.anim.AnimationDecoder;
import net.sourceforge.plantuml.api.ApiStable;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.core.Diagram;
import net.sourceforge.plantuml.core.UmlSource;
@ -166,9 +167,8 @@ public abstract class TitledDiagram extends AbstractPSystem implements Diagram,
// }
final public void setTitle(DisplayPositioned title) {
if (title.isNull() || title.getDisplay().isWhite()) {
if (title.isNull() || title.getDisplay().isWhite())
return;
}
this.title = title;
}
@ -177,6 +177,14 @@ public abstract class TitledDiagram extends AbstractPSystem implements Diagram,
return title;
}
@Override
@ApiStable
final public Display getTitleDisplay() {
if (title == null)
return null;
return title.getDisplay();
}
final public void setMainFrame(Display mainFrame) {
this.mainFrame = mainFrame;
}

View File

@ -0,0 +1,15 @@
package net.sourceforge.plantuml.api;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* This indicates that an element will be stable over PlantUML version.
* Third party tools can then use it safely.
*/
@Retention(RetentionPolicy.SOURCE)
@Target({ ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.TYPE })
public @interface ApiStable {
}

View File

@ -6,7 +6,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.SOURCE)
@Target({ ElementType.CONSTRUCTOR, ElementType.METHOD })
@Target({ ElementType.CONSTRUCTOR, ElementType.METHOD, ElementType.TYPE })
public @interface ApiWarning {
String willBeRemoved() default "";

View File

@ -39,24 +39,27 @@ import java.io.IOException;
import java.io.OutputStream;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.api.ApiStable;
import net.sourceforge.plantuml.cucadiagram.Display;
/**
* Represents a single diagram. A Diagram could be a UML (sequence diagram, class diagram...) or an non-UML diagram.
* Represents a single diagram. A Diagram could be a UML (sequence diagram,
* class diagram...) or an non-UML diagram.
*
* @author Arnaud Roques
*/
@ApiStable
public interface Diagram {
/**
* Export the diagram as an image to some format. Note that a diagram could be drawn as several images (think about
* <code>new page</code> for sequence diagram for example).
* Export the diagram as an image to some format. Note that a diagram could be
* drawn as several images (think about <code>new page</code> for sequence
* diagram for example).
*
* @param os
* where to write the image
* @param num
* usually 0 (index of the image to be exported for this diagram).
* @param fileFormat
* file format to use
* @param os where to write the image
* @param num usually 0 (index of the image to be exported for this
* diagram).
* @param fileFormat file format to use
*
* @return a description of the generated image
*
@ -95,4 +98,6 @@ public interface Diagram {
*/
public boolean hasUrl();
public Display getTitleDisplay();
}

View File

@ -35,6 +35,8 @@
*/
package net.sourceforge.plantuml.cucadiagram;
import net.sourceforge.plantuml.api.ApiWarning;
/**
*
* There is a typo in this class name.
@ -44,6 +46,7 @@ package net.sourceforge.plantuml.cucadiagram;
*
*/
@Deprecated
@ApiWarning(willBeRemoved = "use DisplayPositioned instead")
public class DisplayPositionned {
public Display getDisplay() {

View File

@ -0,0 +1,129 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2020, Arnaud Roques
*
* Project Info: http://plantuml.com
*
* 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
*
* 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
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* 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.mindmap;
import net.sourceforge.plantuml.Direction;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.UDrawable;
import net.sourceforge.plantuml.style.StyleBuilder;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.color.HColor;
class Branch implements UDrawable {
private Idea root;
private Idea last;
private Finger finger;
void initRoot(StyleBuilder styleBuilder, HColor backColor, Display label, IdeaShape shape, String stereotype) {
root = new Idea(styleBuilder, backColor, label, shape, stereotype);
last = root;
}
void initFinger(ISkinParam skinParam, Direction direction) {
finger = FingerImpl.build(root, skinParam, direction);
}
Idea getParentOfLast(int nb) {
Idea result = last;
for (int i = 0; i < nb; i++) {
result = result.getParent();
}
return result;
}
CommandExecutionResult add(StyleBuilder styleBuilder, HColor backColor, int level, Display label, IdeaShape shape,
String stereotype) {
if (last == null)
return CommandExecutionResult.error("Check your indentation ?");
if (level == last.getLevel() + 1) {
final Idea newIdea = last.createIdea(styleBuilder, backColor, level, label, shape, stereotype);
last = newIdea;
return CommandExecutionResult.ok();
}
if (level <= last.getLevel()) {
final int diff = last.getLevel() - level + 1;
final Idea newIdea = getParentOfLast(diff).createIdea(styleBuilder, backColor, level, label, shape,
stereotype);
last = newIdea;
return CommandExecutionResult.ok();
}
return CommandExecutionResult.error("error42L");
}
public boolean hasFinger() {
return finger != null;
}
public void drawU(UGraphic ug) {
if (finger != null)
finger.drawU(ug);
}
public double getHalfThickness(StringBounder stringBounder) {
if (finger == null)
return 0;
return finger.getFullThickness(stringBounder) / 2;
}
public double getFullElongation(StringBounder stringBounder) {
if (finger == null)
return 0;
return finger.getFullElongation(stringBounder);
}
public boolean hasChildren() {
return root.hasChildren();
}
public boolean hasRoot() {
return root != null;
}
public void doNotDrawFirstPhalanx() {
finger.doNotDrawFirstPhalanx();
}
public double getX12(StringBounder stringBounder) {
if (finger == null)
return 0;
return finger.getFullElongation(stringBounder) + ((FingerImpl) finger).getX12();
}
}

View File

@ -0,0 +1,135 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2020, Arnaud Roques
*
* Project Info: http://plantuml.com
*
* 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
*
* 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
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
* 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.mindmap;
import java.awt.geom.Dimension2D;
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.Direction;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.UDrawable;
import net.sourceforge.plantuml.style.NoStyleAvailableException;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.color.HColor;
public class MindMap implements UDrawable {
private final Branch left = new Branch();
private final Branch right = new Branch();
private final ISkinParam skinParam;
public MindMap(ISkinParam skinParam) {
this.skinParam = skinParam;
}
private void computeFinger() {
if (this.left.hasFinger() == false && this.right.hasFinger() == false) {
if (this.left.hasChildren())
left.initFinger(skinParam, Direction.LEFT);
if (this.left.hasFinger() == false || this.right.hasChildren())
right.initFinger(skinParam, Direction.RIGHT);
if (this.left.hasFinger() && this.right.hasFinger())
this.left.doNotDrawFirstPhalanx();
}
}
Dimension2D calculateDimension(StringBounder stringBounder) {
this.computeFinger();
final double y1 = this.right.getHalfThickness(stringBounder);
final double y2 = this.left.getHalfThickness(stringBounder);
final double y = Math.max(y1, y2);
final double x = this.left.getFullElongation(stringBounder);
final double width = x + this.right.getFullElongation(stringBounder);
final double height = y
+ Math.max(this.left.getHalfThickness(stringBounder), this.right.getHalfThickness(stringBounder));
return new Dimension2DDouble(width, height);
}
@Override
public void drawU(UGraphic ug) {
if (this.left.hasRoot() == false && this.right.hasRoot() == false)
return;
this.computeFinger();
final StringBounder stringBounder = ug.getStringBounder();
final double y1 = this.right.getHalfThickness(stringBounder);
final double y2 = this.left.getHalfThickness(stringBounder);
final double y = Math.max(y1, y2);
final double x = this.left.getX12(stringBounder);
this.right.drawU(ug.apply(new UTranslate(x, y)));
this.left.drawU(ug.apply(new UTranslate(x, y)));
}
CommandExecutionResult addIdeaInternal(String stereotype, HColor backColor, int level, Display label,
IdeaShape shape, Direction direction) {
if (level == 0 && this.right.hasRoot())
return CommandExecutionResult.error(
"I don't know how to draw multi-root diagram. You should suggest an image so that the PlantUML team implements it :-)");
try {
if (this.left.hasRoot() == false && this.right.hasRoot() == false)
level = 0;
if (level == 0) {
this.right.initRoot(skinParam.getCurrentStyleBuilder(), backColor, label, shape, stereotype);
this.left.initRoot(skinParam.getCurrentStyleBuilder(), backColor, label, shape, stereotype);
return CommandExecutionResult.ok();
}
if (direction == Direction.LEFT)
return this.left.add(skinParam.getCurrentStyleBuilder(), backColor, level, label, shape, stereotype);
return this.right.add(skinParam.getCurrentStyleBuilder(), backColor, level, label, shape, stereotype);
} catch (NoStyleAvailableException e) {
// e.printStackTrace();
return CommandExecutionResult.error("General failure: no style available.");
}
}
}

View File

@ -40,7 +40,6 @@ import java.awt.geom.Rectangle2D;
import java.io.IOException;
import java.io.OutputStream;
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.Direction;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.UmlDiagram;
@ -52,18 +51,14 @@ import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.graphic.InnerStrategy;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.style.NoStyleAvailableException;
import net.sourceforge.plantuml.style.StyleBuilder;
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
import net.sourceforge.plantuml.ugraphic.MinMax;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.UTranslate;
import net.sourceforge.plantuml.ugraphic.color.HColor;
public class MindMapDiagram extends UmlDiagram {
private Branch left = new Branch();
private Branch right = new Branch();
private final MindMap mindmap;
private Direction defaultDirection = Direction.RIGHT;
@ -77,6 +72,7 @@ public class MindMapDiagram extends UmlDiagram {
public MindMapDiagram(UmlSource source) {
super(source, UmlDiagramType.MINDMAP);
this.mindmap = new MindMap(getSkinParam());
}
@Override
@ -90,7 +86,7 @@ public class MindMapDiagram extends UmlDiagram {
return new TextBlockBackcolored() {
public void drawU(UGraphic ug) {
drawMe(ug);
mindmap.drawU(ug);
}
public Rectangle2D getInnerPosition(String member, StringBounder stringBounder, InnerStrategy strategy) {
@ -98,19 +94,7 @@ public class MindMapDiagram extends UmlDiagram {
}
public Dimension2D calculateDimension(StringBounder stringBounder) {
computeFinger();
final double y1 = right.finger == null ? 0 : right.finger.getFullThickness(stringBounder) / 2;
final double y2 = left.finger == null ? 0 : left.finger.getFullThickness(stringBounder) / 2;
final double y = Math.max(y1, y2);
final double x = left.finger == null ? 0 : left.finger.getFullElongation(stringBounder);
final double width = right.finger == null ? x : x + right.finger.getFullElongation(stringBounder);
final double height = y
+ Math.max(left.finger == null ? 0 : left.finger.getFullThickness(stringBounder) / 2,
right.finger == null ? 0 : right.finger.getFullThickness(stringBounder) / 2);
return new Dimension2DDouble(width, height);
return mindmap.calculateDimension(stringBounder);
}
public MinMax getMinMax(StringBounder stringBounder) {
@ -123,41 +107,6 @@ public class MindMapDiagram extends UmlDiagram {
};
}
private void drawMe(UGraphic ug) {
if (left.root == null && right.root == null) {
return;
}
computeFinger();
final StringBounder stringBounder = ug.getStringBounder();
final double y1 = right.finger == null ? 0 : right.finger.getFullThickness(stringBounder) / 2;
final double y2 = left.finger == null ? 0 : left.finger.getFullThickness(stringBounder) / 2;
final double y = Math.max(y1, y2);
final double x = left.finger == null ? 0
: left.finger.getFullElongation(stringBounder) + ((FingerImpl) left.finger).getX12();
if (right.finger != null) {
right.finger.drawU(ug.apply(new UTranslate(x, y)));
}
if (left.finger != null) {
left.finger.drawU(ug.apply(new UTranslate(x, y)));
}
}
private void computeFinger() {
if (left.finger == null && right.finger == null) {
if (left.root.hasChildren()) {
left.finger = FingerImpl.build(left.root, getSkinParam(), Direction.LEFT);
}
if (left.finger == null || right.root.hasChildren()) {
right.finger = FingerImpl.build(right.root, getSkinParam(), Direction.RIGHT);
}
if (left.finger != null && right.finger != null) {
left.finger.doNotDrawFirstPhalanx();
}
}
}
public CommandExecutionResult addIdea(HColor backColor, int level, Display label, IdeaShape shape) {
return addIdea(backColor, level, label, shape, defaultDirection);
}
@ -168,78 +117,12 @@ public class MindMapDiagram extends UmlDiagram {
if (stereotype != null) {
label = label.removeEndingStereotype();
}
return addIdeaInternal(stereotype, backColor, level, label, shape, direction);
return mindmap.addIdeaInternal(stereotype, backColor, level, label, shape, direction);
}
public CommandExecutionResult addIdea(String stereotype, HColor backColor, int level, Display label,
IdeaShape shape) {
return addIdeaInternal(stereotype, backColor, level, label, shape, defaultDirection);
}
private CommandExecutionResult addIdeaInternal(String stereotype, HColor backColor, int level, Display label,
IdeaShape shape, Direction direction) {
try {
if (left.root == null && right.root == null) {
level = 0;
}
if (level == 0) {
if (this.right.root != null) {
return CommandExecutionResult.error(
"I don't know how to draw multi-root diagram. You should suggest an image so that the PlantUML team implements it :-)");
}
right.initRoot(getSkinParam().getCurrentStyleBuilder(), backColor, label, shape, stereotype);
left.initRoot(getSkinParam().getCurrentStyleBuilder(), backColor, label, shape, stereotype);
return CommandExecutionResult.ok();
}
if (direction == Direction.LEFT) {
return left.add(getSkinParam().getCurrentStyleBuilder(), backColor, level, label, shape, stereotype);
}
return right.add(getSkinParam().getCurrentStyleBuilder(), backColor, level, label, shape, stereotype);
} catch (NoStyleAvailableException e) {
// e.printStackTrace();
return CommandExecutionResult.error("General failure: no style available.");
}
}
static class Branch {
private Idea root;
private Idea last;
private Finger finger;
private void initRoot(StyleBuilder styleBuilder, HColor backColor, Display label, IdeaShape shape,
String stereotype) {
root = new Idea(styleBuilder, backColor, label, shape, stereotype);
last = root;
}
private Idea getParentOfLast(int nb) {
Idea result = last;
for (int i = 0; i < nb; i++) {
result = result.getParent();
}
return result;
}
private CommandExecutionResult add(StyleBuilder styleBuilder, HColor backColor, int level, Display label,
IdeaShape shape, String stereotype) {
if (last == null) {
return CommandExecutionResult.error("Check your indentation ?");
}
if (level == last.getLevel() + 1) {
final Idea newIdea = last.createIdea(styleBuilder, backColor, level, label, shape, stereotype);
last = newIdea;
return CommandExecutionResult.ok();
}
if (level <= last.getLevel()) {
final int diff = last.getLevel() - level + 1;
final Idea newIdea = getParentOfLast(diff).createIdea(styleBuilder, backColor, level, label, shape,
stereotype);
last = newIdea;
return CommandExecutionResult.ok();
}
return CommandExecutionResult.error("error42L");
}
return mindmap.addIdeaInternal(stereotype, backColor, level, label, shape, defaultDirection);
}
private String first;

View File

@ -48,6 +48,7 @@ import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.URLEncoder;
import java.util.Collections;
import java.util.Date;
import java.util.List;
@ -226,6 +227,12 @@ public class PicoWebServer implements Runnable {
write(out, "X-PlantUML-Diagram-Error-Line: " + (1 + err.getLineLocation().getPosition()));
}
}
if (system.getTitleDisplay() != null && system.getTitleDisplay().size() == 1) {
final String encode = URLEncoder.encode(system.getTitleDisplay().toString(), "UTF-8");
if (encode.length() < 256)
write(out, "X-PlantUML-Diagram-Title: " + encode);
}
write(out, "X-Patreon: Support us on https://plantuml.com/patreon");
write(out, "X-Donate: https://plantuml.com/paypal");
write(out, "X-Quote: " + StringUtils.rot(QuoteUtils.getSomeQuote()));

View File

@ -240,7 +240,7 @@ public final class GeneralImageBuilder {
return new EntityImageMap(leaf, skinParam, portionShower);
}
if (leaf.getLeafType() == LeafType.SYNCHRO_BAR || leaf.getLeafType() == LeafType.STATE_FORK_JOIN) {
return new EntityImageSynchroBar(leaf, skinParam);
return new EntityImageSynchroBar(leaf, skinParam, umlDiagramType.getStyleName());
}
if (leaf.getLeafType() == LeafType.ARC_CIRCLE) {
return new EntityImageArcCircle(leaf, skinParam);

View File

@ -130,15 +130,15 @@ public abstract class EntityImageStateCommon extends AbstractEntityImage {
final protected UGraphic applyColor(UGraphic ug) {
HColor classBorder = lineConfig.getColors().getColor(ColorType.LINE);
if (classBorder == null) {
HColor border = lineConfig.getColors().getColor(ColorType.LINE);
if (border == null) {
if (UseStyle.useBetaStyle())
classBorder = getStyleState().value(PName.LineColor).asColor(getSkinParam().getThemeStyle(),
border = getStyleState().value(PName.LineColor).asColor(getSkinParam().getThemeStyle(),
getSkinParam().getIHtmlColorSet());
else
classBorder = SkinParamUtils.getColor(getSkinParam(), getStereo(), ColorParam.stateBorder);
border = SkinParamUtils.getColor(getSkinParam(), getStereo(), ColorParam.stateBorder);
}
ug = ug.apply(getStroke()).apply(classBorder);
ug = ug.apply(getStroke()).apply(border);
HColor backcolor = getEntity().getColors().getColor(ColorType.BACK);
if (backcolor == null) {
if (UseStyle.useBetaStyle())

View File

@ -59,12 +59,17 @@ import net.sourceforge.plantuml.ugraphic.color.HColorNone;
public class EntityImageSynchroBar extends AbstractEntityImage {
public EntityImageSynchroBar(ILeaf entity, ISkinParam skinParam) {
// private final SName styleName;
public EntityImageSynchroBar(ILeaf entity, ISkinParam skinParam, SName styleName) {
super(entity, skinParam);
// this.styleName = styleName;
}
public StyleSignature getDefaultStyleDefinitionBar() {
return StyleSignature.of(SName.root, SName.element, SName.activityDiagram, SName.activityBar);
// return StyleSignature.of(SName.root, SName.element, styleName,
// SName.activityBar);
return StyleSignature.of(SName.root, SName.element, SName.activityBar);
}
public Dimension2D calculateDimension(StringBounder stringBounder) {
@ -83,8 +88,9 @@ public class EntityImageSynchroBar extends AbstractEntityImage {
}
HColor color = SkinParamUtils.getColor(getSkinParam(), getStereo(), ColorParam.activityBar);
if (UseStyle.useBetaStyle()) {
final Style style = getDefaultStyleDefinitionBar().getMergedStyle(getSkinParam().getCurrentStyleBuilder());
color = style.value(PName.LineColor).asColor(getSkinParam().getThemeStyle(),
final Style style = getDefaultStyleDefinitionBar().with(getEntity().getStereotype())
.getMergedStyle(getSkinParam().getCurrentStyleBuilder());
color = style.value(PName.BackGroundColor).asColor(getSkinParam().getThemeStyle(),
getSkinParam().getIHtmlColorSet());
shadowing = style.value(PName.Shadowing).asDouble();
}