-
Notifications
You must be signed in to change notification settings - Fork 32
/
AbstractPSystem.java
181 lines (156 loc) · 5.43 KB
/
AbstractPSystem.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009-2020, Arnaud Roques
*
* Project Info: https://plantuml.com
*
* If you like this project or if you find it useful, you can support us at:
*
* https://plantuml.com/patreon (only 1$ per month!)
* https://plantuml.com/paypal
*
* This file is part of PlantUML.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*
* Original Author: Arnaud Roques
*/
package net.sourceforge.plantuml;
import static net.sourceforge.plantuml.ugraphic.ImageBuilder.imageBuilder;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Objects;
import net.sourceforge.plantuml.command.BlocLines;
import net.sourceforge.plantuml.command.Command;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.ProtectedCommand;
import net.sourceforge.plantuml.core.Diagram;
import net.sourceforge.plantuml.core.ImageData;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.cucadiagram.Display;
import net.sourceforge.plantuml.cucadiagram.DisplayPositionned;
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
import net.sourceforge.plantuml.graphic.VerticalAlignment;
import net.sourceforge.plantuml.stats.StatsUtilsIncrement;
import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft;
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
import net.sourceforge.plantuml.ugraphic.color.NoSuchColorException;
import net.sourceforge.plantuml.version.License;
import net.sourceforge.plantuml.version.Version;
public abstract class AbstractPSystem implements Diagram {
private final UmlSource source;
private Scale scale;
public AbstractPSystem(UmlSource source) {
this.source = Objects.requireNonNull(source);
}
private String getVersion() {
final StringBuilder toAppend = new StringBuilder();
toAppend.append("PlantUML version ");
toAppend.append(Version.versionString());
toAppend.append("(" + Version.compileTimeString() + ")\n");
toAppend.append("(" + License.getCurrent() + " source distribution)\n");
for (String name : OptionPrint.interestingProperties()) {
toAppend.append(name);
toAppend.append(BackSlash.CHAR_NEWLINE);
}
return toAppend.toString();
}
final public String getMetadata() {
if (source == null) {
return getVersion();
}
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();
}
final public UmlSource getSource() {
return source;
}
final public long seed() {
if (source == null) {
return 42;
}
return getSource().seed();
}
public int getNbImages() {
return 1;
}
public DisplayPositionned getTitle() {
if (source == null) {
return DisplayPositionned.single(Display.empty(), HorizontalAlignment.CENTER, VerticalAlignment.TOP);
}
return DisplayPositionned.single(source.getTitle(), HorizontalAlignment.CENTER, VerticalAlignment.TOP);
}
public String getWarningOrError() {
return null;
}
public String checkFinalError() {
return null;
}
public void makeDiagramReady() {
}
public boolean isOk() {
return true;
}
public CommandExecutionResult executeCommand(Command cmd, BlocLines lines) {
cmd = new ProtectedCommand(cmd);
try {
return cmd.execute(this, lines);
} catch (NoSuchColorException e) {
return CommandExecutionResult.badColor();
}
}
public boolean hasUrl() {
return false;
}
final public ImageData exportDiagram(OutputStream os, int index, FileFormatOption fileFormatOption)
throws IOException {
final long now = System.currentTimeMillis();
try {
// if (this instanceof TitledDiagram) {
// final TitledDiagram titledDiagram = (TitledDiagram) this;
// final StyleBuilder styleBuilder = titledDiagram.getCurrentStyleBuilder();
// if (styleBuilder != null) {
// styleBuilder.printMe();
// }
// }
return exportDiagramNow(os, index, fileFormatOption);
} finally {
if (OptionFlags.getInstance().isEnableStats()) {
StatsUtilsIncrement.onceMoreGenerate(System.currentTimeMillis() - now, getClass(),
fileFormatOption.getFileFormat());
}
}
}
final public void setScale(Scale scale) {
this.scale = scale;
}
final public Scale getScale() {
return scale;
}
public ImageBuilder createImageBuilder(FileFormatOption fileFormatOption) throws IOException {
return imageBuilder(fileFormatOption);
}
// TODO "index" isnt really being used
protected abstract ImageData exportDiagramNow(OutputStream os, int index, FileFormatOption fileFormatOption)
throws IOException;
public ClockwiseTopRightBottomLeft getDefaultMargins() {
return ClockwiseTopRightBottomLeft.same(0);
}
}