1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-13 21:52:27 +00:00
plantuml/src/net/sourceforge/plantuml/AbstractPSystem.java

224 lines
6.5 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, 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;
import static net.sourceforge.plantuml.ugraphic.ImageBuilder.imageBuilder;
2016-12-01 20:29:25 +00:00
import java.io.IOException;
import java.io.OutputStream;
2021-05-23 15:35:13 +00:00
import java.util.Objects;
2016-12-01 20:29:25 +00:00
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.command.Command;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.ProtectedCommand;
import net.sourceforge.plantuml.core.Diagram;
2016-12-01 20:29:25 +00:00
import net.sourceforge.plantuml.core.ImageData;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.cucadiagram.Display;
2021-11-09 17:47:19 +00:00
import net.sourceforge.plantuml.cucadiagram.DisplayPositioned;
import net.sourceforge.plantuml.cucadiagram.DisplayPositionned;
2016-01-30 12:20:07 +00:00
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
import net.sourceforge.plantuml.graphic.VerticalAlignment;
2016-12-01 20:29:25 +00:00
import net.sourceforge.plantuml.stats.StatsUtilsIncrement;
import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
2022-09-20 20:35:41 +00:00
import net.sourceforge.plantuml.ugraphic.color.ColorMapper;
2021-02-02 10:12:15 +00:00
import net.sourceforge.plantuml.ugraphic.color.NoSuchColorException;
2022-12-17 11:01:10 +00:00
import net.sourceforge.plantuml.utils.BlocLines;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.version.License;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.version.Version;
2013-12-10 19:36:50 +00:00
public abstract class AbstractPSystem implements Diagram {
2010-11-15 20:35:36 +00:00
2021-05-23 15:35:13 +00:00
private final UmlSource source;
2018-01-28 22:08:15 +00:00
private Scale scale;
private int splitPagesHorizontal = 1;
private int splitPagesVertical = 1;
2010-11-15 20:35:36 +00:00
2021-05-23 15:35:13 +00:00
public AbstractPSystem(UmlSource source) {
this.source = Objects.requireNonNull(source);
}
2010-11-15 20:35:36 +00:00
private String getVersion() {
final StringBuilder toAppend = new StringBuilder();
toAppend.append("PlantUML version ");
2013-12-10 19:36:50 +00:00
toAppend.append(Version.versionString());
2015-04-07 18:18:37 +00:00
toAppend.append("(" + Version.compileTimeString() + ")\n");
2013-12-10 19:36:50 +00:00
toAppend.append("(" + License.getCurrent() + " source distribution)\n");
// ::comment when WASM
2016-09-29 19:51:18 +00:00
for (String name : OptionPrint.interestingProperties()) {
2016-11-18 21:12:09 +00:00
toAppend.append(name);
2017-06-05 11:27:21 +00:00
toAppend.append(BackSlash.CHAR_NEWLINE);
2016-09-29 19:51:18 +00:00
}
// ::done
2010-11-15 20:35:36 +00:00
return toAppend.toString();
}
final public String getMetadata() {
if (source == null) {
return getVersion();
}
2020-05-17 21:15:50 +00:00
final String rawString = source.getRawString();
final String plainString = source.getPlainString();
if (rawString != null && rawString.equals(plainString)) {
return rawString + BackSlash.NEWLINE + getVersion();
}
return rawString + BackSlash.NEWLINE + plainString + BackSlash.NEWLINE + getVersion();
2010-11-15 20:35:36 +00:00
}
final public UmlSource getSource() {
return source;
}
2017-04-19 18:30:16 +00:00
final public long seed() {
if (source == null) {
return 42;
}
return getSource().seed();
}
2010-11-15 20:35:36 +00:00
public int getNbImages() {
return 1;
}
2011-08-08 17:48:29 +00:00
@Override
public int getSplitPagesHorizontal() {
return splitPagesHorizontal;
}
public void setSplitPagesHorizontal(int splitPagesHorizontal) {
this.splitPagesHorizontal = splitPagesHorizontal;
}
@Override
public int getSplitPagesVertical() {
return splitPagesVertical;
}
public void setSplitPagesVertical(int splitPagesVertical) {
this.splitPagesVertical = splitPagesVertical;
}
public DisplayPositionned getTitle() {
2011-08-08 17:48:29 +00:00
if (source == null) {
2021-11-09 17:47:19 +00:00
return DisplayPositioned.single(Display.empty(), HorizontalAlignment.CENTER, VerticalAlignment.TOP);
2011-08-08 17:48:29 +00:00
}
2021-11-09 17:47:19 +00:00
return DisplayPositioned.single(source.getTitle(), HorizontalAlignment.CENTER, VerticalAlignment.TOP);
2011-08-08 17:48:29 +00:00
}
2013-12-10 19:36:50 +00:00
public String getWarningOrError() {
return null;
}
2016-09-29 19:51:18 +00:00
2016-05-31 19:41:55 +00:00
public String checkFinalError() {
return null;
}
2013-12-10 19:36:50 +00:00
public void makeDiagramReady() {
}
public boolean isOk() {
return true;
}
2015-06-20 10:54:49 +00:00
public CommandExecutionResult executeCommand(Command cmd, BlocLines lines) {
2013-12-10 19:36:50 +00:00
cmd = new ProtectedCommand(cmd);
2021-02-02 10:12:15 +00:00
try {
return cmd.execute(this, lines);
} catch (NoSuchColorException e) {
return CommandExecutionResult.badColor();
}
2013-12-10 19:36:50 +00:00
}
2016-01-30 12:20:07 +00:00
2013-12-10 19:36:50 +00:00
public boolean hasUrl() {
return false;
}
2016-12-01 20:29:25 +00:00
final public ImageData exportDiagram(OutputStream os, int index, FileFormatOption fileFormatOption)
throws IOException {
final long now = System.currentTimeMillis();
try {
2021-05-03 20:11:48 +00:00
// if (this instanceof TitledDiagram) {
// final TitledDiagram titledDiagram = (TitledDiagram) this;
// final StyleBuilder styleBuilder = titledDiagram.getCurrentStyleBuilder();
// if (styleBuilder != null) {
// styleBuilder.printMe();
// }
// }
2021-03-23 13:06:33 +00:00
return exportDiagramNow(os, index, fileFormatOption);
2016-12-01 20:29:25 +00:00
} finally {
// ::comment when WASM
if (OptionFlags.getInstance().isEnableStats())
2016-12-14 21:01:03 +00:00
StatsUtilsIncrement.onceMoreGenerate(System.currentTimeMillis() - now, getClass(),
fileFormatOption.getFileFormat());
// ::done
2016-12-01 20:29:25 +00:00
}
}
2018-01-28 22:08:15 +00:00
final public void setScale(Scale scale) {
this.scale = scale;
}
final public Scale getScale() {
return scale;
}
public ImageBuilder createImageBuilder(FileFormatOption fileFormatOption) throws IOException {
2022-09-20 20:35:41 +00:00
final ColorMapper init = fileFormatOption.getColorMapper();
final ColorMapper newColorMappter = muteColorMapper(init);
return imageBuilder(fileFormatOption.withColorMapper(newColorMappter));
}
protected ColorMapper muteColorMapper(ColorMapper init) {
return init;
}
// TODO "index" isnt really being used
2021-05-03 20:11:48 +00:00
protected abstract ImageData exportDiagramNow(OutputStream os, int index, FileFormatOption fileFormatOption)
throws IOException;
2016-12-01 20:29:25 +00:00
public ClockwiseTopRightBottomLeft getDefaultMargins() {
return ClockwiseTopRightBottomLeft.same(0);
}
2022-09-20 20:35:41 +00:00
2021-11-21 11:09:15 +00:00
@Override
public Display getTitleDisplay() {
return null;
}
2010-11-15 20:35:36 +00:00
}