Version 6939

This commit is contained in:
Arnaud Roques 2011-08-08 19:48:29 +02:00
parent fe6831d641
commit df0e7faa11
387 changed files with 12627 additions and 6769 deletions

View File

@ -28,16 +28,18 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6302 $
* Revision $Revision: 6922 $
*
*/
package net.sourceforge.plantuml;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Properties;
@ -79,18 +81,19 @@ public abstract class AbstractPSystem implements PSystem {
final public void setSource(UmlSource source) {
this.source = source;
}
public int getNbImages() {
return 1;
}
public List<File> exportDiagrams(File suggestedFile, FileFormatOption fileFormat) throws IOException, InterruptedException {
public List<File> exportDiagrams(File suggestedFile, FileFormatOption fileFormat) throws IOException,
InterruptedException {
if (suggestedFile.exists() && suggestedFile.isDirectory()) {
throw new IllegalArgumentException("File is a directory " + suggestedFile);
}
OutputStream os = null;
try {
os = new FileOutputStream(suggestedFile);
os = new BufferedOutputStream(new FileOutputStream(suggestedFile));
this.exportDiagram(os, null, 0, fileFormat);
} finally {
if (os != null) {
@ -99,7 +102,12 @@ public abstract class AbstractPSystem implements PSystem {
}
return Arrays.asList(suggestedFile);
}
public List<? extends CharSequence> getTitle() {
if (source == null) {
return Collections.emptyList();
}
return source.getTitle();
}
}

View File

@ -0,0 +1,53 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* 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 Lesser 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.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6549 $
*
*/
package net.sourceforge.plantuml;
import net.sourceforge.plantuml.graphic.HorizontalAlignement;
public enum AlignParam {
SEQUENCE_MESSAGE_ALIGN(HorizontalAlignement.LEFT),
SEQUENCE_REFERENCE_ALIGN(HorizontalAlignement.CENTER);
private final HorizontalAlignement defaultValue;
private AlignParam(HorizontalAlignement defaultValue) {
this.defaultValue = defaultValue;
}
public final HorizontalAlignement getDefaultValue() {
return defaultValue;
}
}

View File

@ -52,10 +52,10 @@ final public class BlockUmlBuilder {
private final List<BlockUml> blocks = new ArrayList<BlockUml>();
private final Set<File> usedFiles = new HashSet<File>();
public BlockUmlBuilder(List<String> config, Defines defines, Reader reader) throws IOException {
public BlockUmlBuilder(List<String> config, Defines defines, Reader reader, File newCurrentDir) throws IOException {
Preprocessor includer = null;
try {
includer = new Preprocessor(new UncommentReadLine(new ReadLineReader(reader)), defines, usedFiles);
includer = new Preprocessor(new UncommentReadLine(new ReadLineReader(reader)), defines, usedFiles, newCurrentDir);
init(includer, config);
} finally {
if (includer != null) {

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6475 $
* Revision $Revision: 6549 $
*
*/
package net.sourceforge.plantuml;
@ -84,6 +84,8 @@ public enum ColorParam {
sequenceActorBorder,
sequenceGroupBorder,
sequenceGroupBackground(true),
sequenceReferenceBorder,
sequenceReferenceHeaderBackground(true),
sequenceReferenceBackground(true),
sequenceDividerBackground(true),
sequenceLifeLineBackground(true),

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4959 $
* Revision $Revision: 6843 $
*
*/
package net.sourceforge.plantuml;
@ -73,4 +73,31 @@ public class Dimension2DDouble extends Dimension2D {
return new Dimension2DDouble(dim.getWidth() + deltaWidth, dim.getHeight() + deltaHeight);
}
public static Dimension2D mergeTB(Dimension2D top, Dimension2D bottom) {
final double width = Math.max(top.getWidth(), bottom.getWidth());
final double height = top.getHeight() + bottom.getHeight();
return new Dimension2DDouble(width, height);
}
public static Dimension2D mergeTB(Dimension2D top1, Dimension2D top2, Dimension2D bottom) {
final double width = MathUtils.max(top1.getWidth(), top2.getWidth(), bottom.getWidth());
final double height = top1.getHeight() + top2.getHeight() + bottom.getHeight();
return new Dimension2DDouble(width, height);
}
public static Dimension2D atLeast(Dimension2D dim, double minWidth, double minHeight) {
double h = dim.getHeight();
double w = dim.getWidth();
if (w > minWidth && h > minHeight) {
return dim;
}
if (h < minHeight) {
h = minHeight;
}
if (w < minWidth) {
w = minWidth;
}
return new Dimension2DDouble(w, h);
}
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6070 $
* Revision $Revision: 6616 $
*
*/
package net.sourceforge.plantuml;
@ -60,14 +60,12 @@ public class DirWatcher {
}
public List<GeneratedImage> buildCreatedFiles() throws IOException, InterruptedException {
boolean error = false;
final List<GeneratedImage> result = new ArrayList<GeneratedImage>();
process(dir, result);
Collections.sort(result);
return Collections.unmodifiableList(result);
}
private void process(File dirToProcess, final List<GeneratedImage> result) throws IOException, InterruptedException {
for (File f : dirToProcess.listFiles()) {
for (File f : dir.listFiles()) {
if (error) {
continue;
}
if (f.isFile() == false) {
continue;
}
@ -83,10 +81,36 @@ public class DirWatcher {
files.add(f);
for (GeneratedImage g : sourceFileReader.getGeneratedImages()) {
result.add(g);
if (OptionFlags.getInstance().isFailOnError() && g.isError()) {
error = true;
}
}
modifieds.put(f, new FileWatcher(files));
}
}
Collections.sort(result);
return Collections.unmodifiableList(result);
}
public File getErrorFile() throws IOException, InterruptedException {
for (File f : dir.listFiles()) {
if (f.isFile() == false) {
continue;
}
if (fileToProcess(f.getName()) == false) {
continue;
}
final FileWatcher watcher = modifieds.get(f);
if (watcher == null || watcher.hasChanged()) {
final SourceFileReader sourceFileReader = new SourceFileReader(new Defines(), f, option.getOutputDir(),
option.getConfig(), option.getCharset(), option.getFileFormatOption());
if (sourceFileReader.hasError()) {
return f;
}
}
}
return null;
}
private boolean fileToProcess(String name) {

View File

@ -0,0 +1,122 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* 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 Lesser 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.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6070 $
*
*/
package net.sourceforge.plantuml;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import net.sourceforge.plantuml.preproc.Defines;
public class DirWatcher2 {
final private File dir;
final private Option option;
final private String pattern;
final private Map<File, FileWatcher> modifieds = new ConcurrentHashMap<File, FileWatcher>();
final private ExecutorService executorService;
public DirWatcher2(File dir, Option option, String pattern) {
this.dir = dir;
this.option = option;
this.pattern = pattern;
final int nb = Option.defaultNbThreads();
this.executorService = Executors.newFixedThreadPool(nb);
}
public Map<File, Future<List<GeneratedImage>>> buildCreatedFiles() throws IOException, InterruptedException {
final Map<File, Future<List<GeneratedImage>>> result = new TreeMap<File, Future<List<GeneratedImage>>>();
for (final File f : dir.listFiles()) {
if (f.isFile() == false) {
continue;
}
if (fileToProcess(f.getName()) == false) {
continue;
}
final FileWatcher watcher = modifieds.get(f);
if (watcher == null || watcher.hasChanged()) {
final SourceFileReader sourceFileReader = new SourceFileReader(new Defines(), f, option.getOutputDir(),
option.getConfig(), option.getCharset(), option.getFileFormatOption());
modifieds.put(f, new FileWatcher(Collections.singleton(f)));
final Future<List<GeneratedImage>> value = executorService.submit(new Callable<List<GeneratedImage>>() {
public List<GeneratedImage> call() throws Exception {
try {
final List<GeneratedImage> generatedImages = sourceFileReader.getGeneratedImages();
final Set<File> files = new HashSet<File>(sourceFileReader.getIncludedFiles());
files.add(f);
modifieds.put(f, new FileWatcher(files));
return Collections.unmodifiableList(generatedImages);
} catch (Exception e) {
e.printStackTrace();
return Collections.emptyList();
}
}
});
result.put(f, value);
}
}
return Collections.unmodifiableMap(result);
}
private boolean fileToProcess(String name) {
return name.matches(pattern);
}
public final File getDir() {
return dir;
}
public void cancel() {
executorService.shutdownNow();
}
public void waitEnd() throws InterruptedException {
executorService.shutdown();
executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
}
}

View File

@ -51,4 +51,17 @@ public enum Direction {
}
throw new IllegalStateException();
}
public static Direction fromChar(char c) {
if (c == '<') {
return Direction.LEFT;
}
if (c == '>') {
return Direction.RIGHT;
}
if (c == '^') {
return Direction.UP;
}
return Direction.DOWN;
}
}

View File

@ -28,22 +28,39 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6130 $
* Revision $Revision: 6671 $
*
*/
package net.sourceforge.plantuml;
public enum FileFormat {
PNG, SVG, EPS, EPS_VIA_SVG, ATXT, UTXT, DOT, XMI_STANDARD, XMI_STAR, XMI_ARGO;
PNG, SVG, EPS, EPS_TEXT, ATXT, UTXT, DOT, XMI_STANDARD, XMI_STAR, XMI_ARGO, PDF;
public String getFileSuffix() {
if (this == EPS_VIA_SVG) {
throw new UnsupportedOperationException("Not used anymore");
// return EPS.getFileSuffix();
}
if (name().startsWith("XMI")) {
return ".XMI";
}
if (this == EPS_TEXT) {
return EPS.getFileSuffix();
}
return "." + name().toLowerCase();
}
public boolean isEps() {
if (this == EPS) {
return true;
}
if (this == EPS_TEXT) {
return true;
}
return false;
}
public String changeName(String fileName, int cpt) {
if (cpt == 0) {
return fileName.replaceAll("\\.\\w+$", getFileSuffix());
}
return fileName.replaceAll("\\.\\w+$", "_" + String.format("%03d", cpt) + getFileSuffix());
}
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4929 $
* Revision $Revision: 6908 $
*
*/
package net.sourceforge.plantuml;
@ -40,7 +40,7 @@ public class FileSystem {
private final static FileSystem singleton = new FileSystem();
private File currentDir;
private final ThreadLocal<File> currentDir = new ThreadLocal<File>();
private FileSystem() {
reset();
@ -55,15 +55,19 @@ public class FileSystem {
throw new IllegalArgumentException();
}
Log.info("Setting current dir: " + dir);
this.currentDir = dir;
this.currentDir.set(dir);
}
public File getCurrentDir() {
return this.currentDir;
return this.currentDir.get();
}
public File getFile(String nameOrPath) throws IOException {
return new File(currentDir.getAbsoluteFile(), nameOrPath).getCanonicalFile();
final File dir = currentDir.get();
if (dir == null) {
return new File(nameOrPath).getCanonicalFile();
}
return new File(dir.getAbsoluteFile(), nameOrPath).getCanonicalFile();
}
public void reset() {

View File

@ -41,29 +41,14 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import net.sourceforge.plantuml.cucadiagram.dot.DrawFile;
import java.util.concurrent.atomic.AtomicInteger;
public class FileUtils {
private static final Collection<DrawFile> toDelete = new ArrayList<DrawFile>();
private static AtomicInteger counter;
public static void deleteOnExit(DrawFile file) {
if (toDelete.isEmpty()) {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
if (OptionFlags.getInstance().isKeepTmpFiles() == false) {
for (DrawFile f : toDelete) {
f.delete();
}
}
}
});
}
toDelete.add(file);
public static void resetCounter() {
counter = new AtomicInteger(0);
}
public static File getTmpDir() {
@ -90,7 +75,16 @@ public class FileUtils {
if (suffix.startsWith(".") == false) {
throw new IllegalArgumentException();
}
final File f = File.createTempFile(prefix, suffix);
if (prefix == null) {
throw new IllegalArgumentException();
}
final File f;
if (counter == null) {
f = File.createTempFile(prefix, suffix);
} else {
final String name = prefix + counter.addAndGet(1) + suffix;
f = new File(name);
}
Log.info("Creating temporary file: " + f);
if (OptionFlags.getInstance().isKeepTmpFiles() == false) {
f.deleteOnExit();
@ -112,4 +106,26 @@ public class FileUtils {
fis.close();
}
static public void copyToStream(File src, OutputStream os) throws IOException {
final InputStream fis = new BufferedInputStream(new FileInputStream(src));
final OutputStream fos = new BufferedOutputStream(os);
int lu;
while ((lu = fis.read()) != -1) {
fos.write(lu);
}
fos.close();
fis.close();
}
static public void copyToStream(InputStream is, OutputStream os) throws IOException {
final InputStream fis = new BufferedInputStream(is);
final OutputStream fos = new BufferedOutputStream(os);
int lu;
while ((lu = fis.read()) != -1) {
fos.write(lu);
}
fos.close();
fis.close();
}
}

View File

@ -43,11 +43,19 @@ public class FileWatcher {
private final Map<File, Long> modified2 = new HashMap<File, Long>();
public FileWatcher(Set<File> files) {
if (files.size() == 0) {
throw new IllegalArgumentException();
}
for (File f : files) {
modified2.put(f, f.lastModified());
}
}
@Override
public String toString() {
return modified2.toString();
}
public boolean hasChanged() {
for (Map.Entry<File, Long> ent : modified2.entrySet()) {
final long nowModified = ent.getKey().lastModified();

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6475 $
* Revision $Revision: 6866 $
*
*/
package net.sourceforge.plantuml;
@ -87,11 +87,17 @@ public enum FontParam {
this.defaultFamily = defaultFamily;
}
public final int getDefaultSize() {
public final int getDefaultSize(ISkinParam skinParam) {
if (OptionFlags.SVEK && this==CLASS_ATTRIBUTE) {
return 11;
}
return defaultSize;
}
public final int getDefaultFontStyle() {
public final int getDefaultFontStyle(ISkinParam skinParam) {
if (OptionFlags.SVEK && this==PACKAGE) {
return Font.BOLD;
}
return fontStyle;
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 3824 $
* Revision $Revision: 6615 $
*
*/
package net.sourceforge.plantuml;
@ -39,11 +39,10 @@ public class GeneratedImage implements Comparable<GeneratedImage> {
private final File pngFile;
private final String description;
private final PSystem system;
public GeneratedImage(File pngFile, String description) {
if (pngFile == null) {
throw new IllegalArgumentException();
}
public GeneratedImage(File pngFile, String description, PSystem system) {
this.system = system;
this.pngFile = pngFile;
this.description = description;
}
@ -56,6 +55,10 @@ public class GeneratedImage implements Comparable<GeneratedImage> {
return description;
}
public boolean isError() {
return system instanceof PSystemError;
}
@Override
public String toString() {
return pngFile.getAbsolutePath() + " " + description;

View File

@ -33,11 +33,12 @@
*/
package net.sourceforge.plantuml;
import java.awt.Font;
import net.sourceforge.plantuml.cucadiagram.dot.DotSplines;
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizLayoutStrategy;
import net.sourceforge.plantuml.graphic.HorizontalAlignement;
import net.sourceforge.plantuml.graphic.HtmlColor;
import net.sourceforge.plantuml.ugraphic.ColorMapper;
import net.sourceforge.plantuml.ugraphic.UFont;
public interface ISkinParam {
@ -47,15 +48,11 @@ public interface ISkinParam {
public HtmlColor getHtmlColor(ColorParam param, String stereotype);
public int getFontSize(FontParam param, String stereotype);
public String getFontFamily(FontParam param, String stereotype);
public HtmlColor getFontHtmlColor(FontParam param, String stereotype);
public int getFontStyle(FontParam param, String stereotype);
public Font getFont(FontParam fontParam, String stereotype);
public UFont getFont(FontParam fontParam, String stereotype);
public HorizontalAlignement getHorizontalAlignement(AlignParam param);
public int getCircledCharacterRadius();
@ -63,7 +60,7 @@ public interface ISkinParam {
public int classAttributeIconSize();
public boolean isMonochrome();
public ColorMapper getColorMapper();
public int getDpi();

View File

@ -0,0 +1,49 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* 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 Lesser 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.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4771 $
*
*/
package net.sourceforge.plantuml;
import java.io.IOException;
import java.util.List;
public interface ISourceFileReader {
public List<GeneratedImage> getGeneratedImages() throws IOException, InterruptedException;
public List<String> getEncodedUrl() throws IOException, InterruptedException;
public boolean hasError() throws IOException, InterruptedException;
}

View File

@ -104,6 +104,7 @@ public class LanguageDescriptor {
keyword.add("header");
keyword.add("center");
keyword.add("rotate");
keyword.add("ref");
preproc.add("!include");

View File

@ -28,25 +28,25 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 3824 $
* Revision $Revision: 6528 $
*
*/
package net.sourceforge.plantuml;
public abstract class Log {
private static long start = System.currentTimeMillis();
private static final long start = System.currentTimeMillis();
public static void debug(String s) {
public synchronized static void debug(String s) {
}
public static void info(String s) {
public synchronized static void info(String s) {
if (OptionFlags.getInstance().isVerbose()) {
System.out.println(format(s));
}
}
public static void error(String s) {
public synchronized static void error(String s) {
System.err.println(s);
}

View File

@ -0,0 +1,46 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* 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 Lesser 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.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6719 $
*
*/
package net.sourceforge.plantuml;
public class MathUtils {
public static double max(double a, double b) {
return Math.max(a, b);
}
public static double max(double a, double b, double c) {
return Math.max(Math.max(a, b), c);
}
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6448 $
* Revision $Revision: 6702 $
*
*/
package net.sourceforge.plantuml;
@ -57,9 +57,15 @@ public class Option {
private boolean decodeurl = false;
private boolean pipe = false;
private boolean syntax = false;
private boolean checkOnly = false;
private boolean pattern = false;
private boolean duration = false;
private int nbThreads = 0;
private int ftpPort = -1;
private File outputDir = null;
private File outputFile = null;
private final List<String> result = new ArrayList<String>();
public Option() {
@ -91,6 +97,8 @@ public class Option {
setFileFormat(FileFormat.XMI_STAR);
} else if (s.equalsIgnoreCase("-teps") || s.equalsIgnoreCase("-eps")) {
setFileFormat(FileFormat.EPS);
} else if (s.equalsIgnoreCase("-teps:text") || s.equalsIgnoreCase("-eps:text")) {
setFileFormat(FileFormat.EPS_TEXT);
} else if (s.equalsIgnoreCase("-tdot") || s.equalsIgnoreCase("-dot")) {
setFileFormat(FileFormat.DOT);
OptionFlags.getInstance().setKeepTmpFiles(true);
@ -98,12 +106,20 @@ public class Option {
setFileFormat(FileFormat.ATXT);
} else if (s.equalsIgnoreCase("-tutxt") || s.equalsIgnoreCase("-utxt")) {
setFileFormat(FileFormat.UTXT);
} else if (s.equalsIgnoreCase("-pdf") || s.equalsIgnoreCase("-tpdf")) {
setFileFormat(FileFormat.PDF);
} else if (s.equalsIgnoreCase("-output") || s.equalsIgnoreCase("-o")) {
i++;
if (i == arg.length) {
continue;
}
outputDir = new File(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i]));
} else if (s.equalsIgnoreCase("-ofile")) {
i++;
if (i == arg.length) {
continue;
}
outputFile = new File(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i]));
} else if (s.equalsIgnoreCase("-graphvizdot") || s.equalsIgnoreCase("-graphviz_dot")) {
i++;
if (i == arg.length) {
@ -128,6 +144,20 @@ public class Option {
continue;
}
excludes.add(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i]));
} else if (s.equalsIgnoreCase("-nbthread") || s.equalsIgnoreCase("-nbthreads")) {
i++;
if (i == arg.length) {
continue;
}
final String nb = arg[i];
if ("auto".equalsIgnoreCase(nb)) {
this.nbThreads = defaultNbThreads();
} else if (nb.matches("\\d+")) {
this.nbThreads = Integer.parseInt(nb);
}
} else if (s.equalsIgnoreCase("-checkonly")) {
this.checkOnly = true;
OptionFlags.getInstance().setFailOnError(true);
} else if (s.equalsIgnoreCase("-config")) {
i++;
if (i == arg.length) {
@ -153,10 +183,19 @@ public class Option {
} else if (s.equalsIgnoreCase("-syntax")) {
syntax = true;
OptionFlags.getInstance().setQuiet(true);
} else if (s.equalsIgnoreCase("-duration")) {
duration = true;
} else if (s.equalsIgnoreCase("-keepfiles") || s.equalsIgnoreCase("-keepfile")) {
OptionFlags.getInstance().setKeepTmpFiles(true);
} else if (s.equalsIgnoreCase("-metadata")) {
OptionFlags.getInstance().setMetadata(true);
} else if (s.equalsIgnoreCase("-logdata")) {
i++;
if (i == arg.length) {
continue;
}
OptionFlags.getInstance().setLogData(
new File(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i])));
} else if (s.equalsIgnoreCase("-word")) {
OptionFlags.getInstance().setWord(true);
OptionFlags.getInstance().setQuiet(true);
@ -184,12 +223,29 @@ public class Option {
OptionPrint.printLanguage();
} else if (s.equalsIgnoreCase("-gui")) {
OptionFlags.getInstance().setGui(true);
} else if (s.equalsIgnoreCase("-nosuggestengine")) {
OptionFlags.getInstance().setUseSuggestEngine(false);
} else if (s.equalsIgnoreCase("-failonerror")) {
OptionFlags.getInstance().setFailOnError(true);
} else if (s.equalsIgnoreCase("-printfonts")) {
OptionFlags.getInstance().setPrintFonts(true);
} else if (s.toLowerCase().startsWith("-ftp")) {
final int x = s.indexOf(':');
if (x == -1) {
this.ftpPort = 4242;
} else {
this.ftpPort = Integer.parseInt(s.substring(x + 1));
}
} else {
result.add(s);
}
}
}
public int getFtpPort() {
return ftpPort;
}
public void initConfig(String filename) throws IOException {
BufferedReader br = null;
try {
@ -298,4 +354,32 @@ public class Option {
return new FileFormatOption(getFileFormat());
}
public final boolean isDuration() {
return duration;
}
public final int getNbThreads() {
return nbThreads;
}
public final void setNbThreads(int nb) {
this.nbThreads = nb;
}
public static int defaultNbThreads() {
return Runtime.getRuntime().availableProcessors();
}
public final boolean isCheckOnly() {
return checkOnly;
}
public final void setCheckOnly(boolean checkOnly) {
this.checkOnly = checkOnly;
}
public final File getOutputFile() {
return outputFile;
}
}

View File

@ -28,26 +28,45 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6096 $
* Revision $Revision: 6922 $
*
*/
package net.sourceforge.plantuml;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.concurrent.atomic.AtomicBoolean;
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizUtils;
public class OptionFlags {
static public final boolean PBBACK = false;
static public final boolean SUGGEST = true;
static public final boolean GRAPHVIZCACHE = false;
static public final boolean SVEK = false;
void reset() {
reset(false);
}
private void reset(boolean exit) {
keepTmpFiles = false;
verbose = false;
metadata = false;
word = false;
systemExit = exit;
debugDot = false;
forceGd = false;
forceCairo = false;
quiet = false;
dotExecutable = null;
gui = false;
quiet = false;
checkDotError = false;
printFonts = false;
useSuggestEngine = true;
failOnError = false;
}
public boolean useJavaInsteadOfDot() {
@ -56,32 +75,36 @@ public class OptionFlags {
private static final OptionFlags singleton = new OptionFlags();
private boolean keepTmpFiles = false;
private boolean verbose = false;
private boolean metadata = false;
private boolean word = false;
private boolean systemExit = true;
private boolean debugDot = false;
private boolean forceGd = false;
private boolean forceCairo = false;
private String dotExecutable = null;
private boolean gui = false;
private boolean quiet = false;
private boolean checkDotError = false;
private boolean keepTmpFiles;
private boolean verbose;
private boolean metadata;
private boolean word;
private boolean systemExit;
private boolean debugDot;
private boolean forceGd;
private boolean forceCairo;
private String dotExecutable;
private boolean gui;
private boolean quiet;
private boolean checkDotError;
private boolean printFonts;
private boolean useSuggestEngine;
private boolean failOnError;
private File logData;
private OptionFlags() {
reset();
reset(true);
}
public static OptionFlags getInstance() {
return singleton;
}
public final boolean isKeepTmpFiles() {
public synchronized final boolean isKeepTmpFiles() {
return keepTmpFiles;
}
public final void setKeepTmpFiles(boolean keepTmpFiles) {
public synchronized final void setKeepTmpFiles(boolean keepTmpFiles) {
this.keepTmpFiles = keepTmpFiles;
}
@ -173,4 +196,89 @@ public class OptionFlags {
this.checkDotError = checkDotError;
}
private final AtomicBoolean logDataInitized = new AtomicBoolean(false);
public void logData(File file, PSystem system) {
if (system instanceof PSystemError == false) {
return;
}
synchronized (logDataInitized) {
if (logData == null && logDataInitized.get() == false) {
final String s = GraphvizUtils.getenvLogData();
if (s != null) {
setLogData(new File(s));
}
logDataInitized.set(true);
}
if (logData == null) {
return;
}
final PSystemError systemError = (PSystemError) system;
PrintStream ps = null;
try {
ps = new PrintStream(new FileOutputStream(logData, true));
ps.println("Start of " + file.getName());
ps.println(systemError.getDescription());
for (CharSequence t : systemError.getTitle()) {
ps.println(t);
}
systemError.print(ps);
for (String s : systemError.getSuggest()) {
ps.println(s);
}
ps.println("End of " + file.getName());
ps.println();
} catch (FileNotFoundException e) {
Log.error("Cannot open " + logData);
e.printStackTrace();
} finally {
if (ps != null) {
ps.close();
}
}
}
}
public final void setLogData(File logData) {
this.logData = logData;
logData.delete();
PrintStream ps = null;
try {
ps = new PrintStream(new FileOutputStream(logData));
ps.println();
} catch (FileNotFoundException e) {
Log.error("Cannot open " + logData);
e.printStackTrace();
} finally {
if (ps != null) {
ps.close();
}
}
}
public final boolean isPrintFonts() {
return printFonts;
}
public final void setPrintFonts(boolean printFonts) {
this.printFonts = printFonts;
}
public final boolean isUseSuggestEngine() {
return useSuggestEngine;
}
public final void setUseSuggestEngine(boolean useSuggestEngine) {
this.useSuggestEngine = useSuggestEngine;
}
public final boolean isFailOnError() {
return failOnError;
}
public final void setFailOnError(boolean failOnError) {
this.failOnError = failOnError;
}
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6448 $
* Revision $Revision: 6626 $
*
*/
package net.sourceforge.plantuml;
@ -88,12 +88,18 @@ public class OptionPrint {
System.err.println(" -h[elp]\t\tTo display this help message");
System.err.println(" -testdot\t\tTo test the installation of graphviz");
System.err.println(" -graphvizdot \"exe\"\tTo specify dot executable");
System.err.println(" -p[ipe]\t\tTo use stdin for PlantUML source and stdout for PNG/SVG generation");
System.err.println(" -p[ipe]\t\tTo use stdin for PlantUML source and stdout for PNG/SVG/EPS generation");
System.err.println(" -computeurl\t\tTo compute the encoded URL of a PlantUML source file");
System.err.println(" -decodeurl\t\tTo retrieve the PlantUML source from an encoded URL");
System.err.println(" -syntax\t\tTo report any syntax error from standard input without generating images");
System.err.println(" -language\t\tTo print the list of PlantUML keywords");
System.err.println(" -nosuggestengine\tTo disable the suggest engine when errors in diagrams");
System.err.println(" -checkonly\t\tTo check the syntax of files without generating images");
System.err.println(" -failonerror\tTo stop processing if syntax error in diagram occurs");
System.err.println(" -pattern\t\tTo print the list of Regular Expression used by PlantUML");
System.err.println(" -duration\t\tTo print the duration of complete diagrams processing");
System.err.println(" -nbthread N\tTo use (N) threads for processing");
System.err.println(" -nbthread auto\tTo use " + Option.defaultNbThreads() + " threads for processing");
System.err.println();
System.err.println("If needed, you can setup the environment variable GRAPHVIZ_DOT.");
exit();

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6302 $
* Revision $Revision: 6513 $
*
*/
package net.sourceforge.plantuml;

View File

@ -64,6 +64,31 @@ public class PSystemBuilder {
final public PSystem createPSystem(final List<String> strings) throws IOException, InterruptedException {
final List<PSystemFactory> factories = getAllFactories();
final UmlSource umlSource = new UmlSource(strings);
final DiagramType diagramType = umlSource.getDiagramType();
final List<PSystemError> errors = new ArrayList<PSystemError>();
for (PSystemFactory systemFactory : factories) {
if (diagramType != systemFactory.getDiagramType()) {
continue;
}
final PSystem sys = new PSystemSingleBuilder(umlSource, systemFactory).getPSystem();
if (isOk(sys)) {
return sys;
}
errors.add((PSystemError) sys);
}
final PSystemError err = merge(errors);
if (OptionFlags.getInstance().isQuiet() == false) {
err.print(System.err);
}
return err;
}
private List<PSystemFactory> getAllFactories() {
final List<PSystemFactory> factories = new ArrayList<PSystemFactory>();
factories.add(new SequenceDiagramFactory());
factories.add(new ClassDiagramFactory());
@ -89,27 +114,7 @@ public class PSystemBuilder {
factories.add(new PSystemPathFactory());
factories.add(new PSystemOregonFactory());
factories.add(new PSystemProjectFactory());
final UmlSource umlSource = new UmlSource(strings);
final DiagramType diagramType = umlSource.getDiagramType();
final List<PSystemError> errors = new ArrayList<PSystemError>();
for (PSystemFactory systemFactory : factories) {
if (diagramType != systemFactory.getDiagramType()) {
continue;
}
final PSystem sys = new PSystemSingleBuilder(umlSource, systemFactory).getPSystem();
if (isOk(sys)) {
return sys;
}
errors.add((PSystemError) sys);
}
final PSystemError err = merge(errors);
if (OptionFlags.getInstance().isQuiet() == false) {
err.print(System.err);
}
return err;
return factories;
}
private PSystemError merge(Collection<PSystemError> ps) {

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6453 $
* Revision $Revision: 6622 $
*/
package net.sourceforge.plantuml;
@ -76,24 +76,8 @@ public class PSystemError extends AbstractPSystem {
this(source, Collections.singletonList(singleError));
}
// public List<File> createFiles(File suggestedFile, FileFormatOption fileFormat) throws IOException,
// InterruptedException {
// if (suggestedFile.exists() && suggestedFile.isDirectory()) {
// throw new IllegalArgumentException("File is a directory " + suggestedFile);
// }
// OutputStream os = null;
// try {
// os = new FileOutputStream(suggestedFile);
// getPngError().writeImage(os, getMetadata(), fileFormat);
// } finally {
// if (os != null) {
// os.close();
// }
// }
// return Arrays.asList(suggestedFile);
// }
public void exportDiagram(OutputStream os, StringBuilder cmap, int index, FileFormatOption fileFormat) throws IOException {
public void exportDiagram(OutputStream os, StringBuilder cmap, int index, FileFormatOption fileFormat)
throws IOException {
getPngError().writeImage(os, getMetadata(), fileFormat);
}
@ -137,21 +121,36 @@ public class PSystemError extends AbstractPSystem {
htmlStrings.add(" <color:red>" + er);
plainStrings.add(" " + er);
}
boolean first = true;
for (String s : getSuggest()) {
if (first) {
htmlStrings.add(" <color:white><i>" + s);
} else {
htmlStrings.add("<color:white>" + StringUtils.hideComparatorCharacters(s));
}
first = false;
}
}
public List<String> getSuggest() {
boolean suggested = false;
for (ErrorUml er : printedErrors) {
if (er.hasSuggest()) {
suggested = true;
}
}
if (suggested) {
htmlStrings.add(" <color:white><i>Did you mean:");
for (ErrorUml er : printedErrors) {
if (er.hasSuggest()) {
htmlStrings.add("<color:white>"
+ StringUtils.hideComparatorCharacters(er.getSuggest().getSuggestedLine()));
}
if (suggested == false) {
return Collections.emptyList();
}
final List<String> result = new ArrayList<String>();
result.add("Did you mean:");
for (ErrorUml er : printedErrors) {
if (er.hasSuggest()) {
result.add(er.getSuggest().getSuggestedLine());
}
}
return Collections.unmodifiableList(result);
}
private Collection<ErrorUml> getErrors(ErrorUmlType type, List<ErrorUml> all) {
@ -192,8 +191,10 @@ public class PSystemError extends AbstractPSystem {
}
public void print(PrintStream ps) {
for (String s : plainStrings) {
ps.println(StringUtils.showComparatorCharacters(s));
synchronized (ps) {
for (String s : plainStrings) {
ps.println(StringUtils.showComparatorCharacters(s));
}
}
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6341 $
* Revision $Revision: 6750 $
*
*/
package net.sourceforge.plantuml;
@ -37,7 +37,7 @@ public interface PSystemFactory {
PSystem getSystem();
void reset();
void init(String startLine);
DiagramType getDiagramType();

View File

@ -53,6 +53,7 @@ final public class PSystemSingleBuilder {
private final Iterator<String> it;
private final UmlSource source;
private final String startLine;
private int nb = 0;
private AbstractPSystem sys;
@ -73,7 +74,8 @@ final public class PSystemSingleBuilder {
public PSystemSingleBuilder(UmlSource s, PSystemFactory systemFactory) throws IOException {
this.source = s;
it = s.iterator();
if (StartUtils.isArobaseStartDiagram(next()) == false) {
startLine = next();
if (StartUtils.isArobaseStartDiagram(startLine) == false) {
throw new UnsupportedOperationException();
}
@ -87,7 +89,7 @@ final public class PSystemSingleBuilder {
}
private void executeUmlBasic(PSystemBasicFactory systemFactory) throws IOException {
systemFactory.reset();
systemFactory.init(startLine);
while (hasNext()) {
final String s = next();
if (StartUtils.isArobaseEndDiagram(s)) {
@ -127,7 +129,7 @@ final public class PSystemSingleBuilder {
}
private void executeUmlCommand(PSystemCommandFactory systemFactory) throws IOException {
systemFactory.reset();
systemFactory.init(startLine);
while (hasNext()) {
final String s = next();
if (StartUtils.isArobaseEndDiagram(s)) {
@ -150,7 +152,7 @@ final public class PSystemSingleBuilder {
final CommandControl commandControl = systemFactory.isValid(Arrays.asList(s));
if (commandControl == CommandControl.NOT_OK) {
final ErrorUml err = new ErrorUml(ErrorUmlType.SYNTAX_ERROR, "Syntax Error?", nb - 1);
if (OptionFlags.SUGGEST) {
if (OptionFlags.getInstance().isUseSuggestEngine()) {
final SuggestEngine engine = new SuggestEngine(source, systemFactory);
final SuggestEngineResult result = engine.tryToSuggest();
if (result.getStatus() == SuggestEngineStatus.ONE_SUGGESTION) {

View File

@ -28,11 +28,12 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6234 $
* Revision $Revision: 6750 $
*
*/
package net.sourceforge.plantuml;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.io.BufferedReader;
import java.io.File;
@ -40,6 +41,11 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.swing.UIManager;
@ -49,21 +55,34 @@ import net.sourceforge.plantuml.code.Transcoder;
import net.sourceforge.plantuml.code.TranscoderUtil;
import net.sourceforge.plantuml.command.AbstractUmlSystemCommandFactory;
import net.sourceforge.plantuml.componentdiagram.ComponentDiagramFactory;
import net.sourceforge.plantuml.ftp.FtpServer;
import net.sourceforge.plantuml.objectdiagram.ObjectDiagramFactory;
import net.sourceforge.plantuml.png.MetadataTag;
import net.sourceforge.plantuml.preproc.Defines;
import net.sourceforge.plantuml.sequencediagram.SequenceDiagramFactory;
import net.sourceforge.plantuml.statediagram.StateDiagramFactory;
import net.sourceforge.plantuml.swing.MainWindow;
import net.sourceforge.plantuml.swing.MainWindow2;
import net.sourceforge.plantuml.usecasediagram.UsecaseDiagramFactory;
public class Run {
public static void main(String[] argsArray) throws IOException, InterruptedException {
final long start = System.currentTimeMillis();
final Option option = new Option(argsArray);
if (OptionFlags.getInstance().isVerbose()) {
Log.info("GraphicsEnvironment.isHeadless() " + GraphicsEnvironment.isHeadless());
}
if (OptionFlags.getInstance().isPrintFonts()) {
printFonts();
return;
}
if (option.getFtpPort() != -1) {
goFtp(option);
return;
}
boolean error = false;
if (option.isPattern()) {
managePattern();
} else if (OptionFlags.getInstance().isGui()) {
@ -71,12 +90,42 @@ public class Run {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception e) {
}
new MainWindow(option);
new MainWindow2(option);
} else if (option.isPipe() || option.isSyntax()) {
managePipe(option);
} else {
manageFiles(option);
error = manageAllFiles(option);
}
if (option.isDuration()) {
final long duration = System.currentTimeMillis() - start;
Log.error("Duration = " + (duration / 1000L) + " seconds");
}
if (error) {
Log.error("Some diagram description contains errors");
System.exit(1);
}
}
private static void goFtp(Option option) throws IOException {
final int ftpPort = option.getFtpPort();
System.err.println("ftpPort=" + ftpPort);
final FtpServer ftpServer = new FtpServer(ftpPort);
ftpServer.go();
}
static void printFonts() {
final Font fonts[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
for (Font f : fonts) {
System.out.println("f=" + f + "/" + f.getPSName() + "/" + f.getName() + "/" + f.getFontName() + "/"
+ f.getFamily());
}
final String name[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
for (String n : name) {
System.out.println("n=" + n);
}
}
private static void managePattern() {
@ -90,6 +139,7 @@ public class Run {
}
private static void printPattern(AbstractUmlSystemCommandFactory factory) {
factory.init(null);
System.out.println();
System.out.println(factory.getClass().getSimpleName().replaceAll("Factory", ""));
for (String s : factory.getDescription()) {
@ -146,30 +196,7 @@ public class Run {
}
}
private static void manageFile(File f, Option option) throws IOException, InterruptedException {
if (OptionFlags.getInstance().isMetadata()) {
System.out.println("------------------------");
System.out.println(f);
// new Metadata().readAndDisplayMetadata(f);
System.out.println();
System.out.println(new MetadataTag(f, "plantuml").getData());
System.out.println("------------------------");
} else {
final SourceFileReader sourceFileReader = new SourceFileReader(option.getDefaultDefines(), f,
option.getOutputDir(), option.getConfig(), option.getCharset(), option.getFileFormatOption());
if (option.isComputeurl()) {
final List<String> urls = sourceFileReader.getEncodedUrl();
for (String s : urls) {
System.out.println(s);
}
} else {
sourceFileReader.getGeneratedImages();
}
}
}
private static void manageFiles(Option option) throws IOException, InterruptedException {
private static boolean manageAllFiles(Option option) throws IOException, InterruptedException {
File lockFile = null;
try {
@ -179,7 +206,7 @@ public class Run {
javaIsRunningFile.delete();
lockFile = new File(dir, "javaumllock.tmp");
}
processArgs(option);
return processArgs(option);
} finally {
if (lockFile != null) {
lockFile.delete();
@ -188,7 +215,11 @@ public class Run {
}
private static void processArgs(Option option) throws IOException, InterruptedException {
private static boolean processArgs(Option option) throws IOException, InterruptedException {
if (option.isDecodeurl() == false && option.getNbThreads() > 0 && option.isCheckOnly() == false
&& OptionFlags.getInstance().isMetadata() == false) {
return multithread(option);
}
for (String s : option.getResult()) {
if (option.isDecodeurl()) {
final Transcoder transcoder = TranscoderUtil.getDefaultTranscoder();
@ -198,10 +229,90 @@ public class Run {
} else {
final FileGroup group = new FileGroup(s, option.getExcludes(), option);
for (File f : group.getFiles()) {
manageFile(f, option);
try {
final boolean error = manageFileInternal(f, option);
if (error) {
return true;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
return false;
}
private static boolean multithread(final Option option) throws InterruptedException {
Log.info("Using several threads: " + option.getNbThreads());
final ExecutorService executor = Executors.newFixedThreadPool(option.getNbThreads());
final AtomicBoolean errors = new AtomicBoolean(false);
for (String s : option.getResult()) {
final FileGroup group = new FileGroup(s, option.getExcludes(), option);
for (final File f : group.getFiles()) {
final Future<?> future = executor.submit(new Runnable() {
public void run() {
if (errors.get()) {
return;
}
try {
final boolean error = manageFileInternal(f, option);
if (error) {
errors.set(true);
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
});
}
}
executor.shutdown();
executor.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS);
return errors.get();
}
private static boolean manageFileInternal(File f, Option option) throws IOException, InterruptedException {
if (OptionFlags.getInstance().isMetadata()) {
System.out.println("------------------------");
System.out.println(f);
// new Metadata().readAndDisplayMetadata(f);
System.out.println();
System.out.println(new MetadataTag(f, "plantuml").getData());
System.out.println("------------------------");
return false;
}
final ISourceFileReader sourceFileReader;
if (option.getOutputFile() == null) {
sourceFileReader = new SourceFileReader(option.getDefaultDefines(), f, option.getOutputDir(), option
.getConfig(), option.getCharset(), option.getFileFormatOption());
} else {
sourceFileReader = new SourceFileReader2(option.getDefaultDefines(), f, option.getOutputFile(), option
.getConfig(), option.getCharset(), option.getFileFormatOption());
}
if (option.isComputeurl()) {
final List<String> urls = sourceFileReader.getEncodedUrl();
for (String s : urls) {
System.out.println(s);
}
return false;
} else if (option.isCheckOnly()) {
return sourceFileReader.hasError();
}
final List<GeneratedImage> result = sourceFileReader.getGeneratedImages();
if (OptionFlags.getInstance().isFailOnError()) {
for (GeneratedImage i : result) {
if (i.isError()) {
Log.error("Error in file: " + f.getCanonicalPath());
}
if (i.isError() && OptionFlags.getInstance().isFailOnError()) {
return true;
}
}
}
return false;
}
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6448 $
* Revision $Revision: 6866 $
*
*/
package net.sourceforge.plantuml;
@ -46,7 +46,12 @@ import java.util.regex.Pattern;
import net.sourceforge.plantuml.cucadiagram.dot.DotSplines;
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizLayoutStrategy;
import net.sourceforge.plantuml.graphic.HorizontalAlignement;
import net.sourceforge.plantuml.graphic.HtmlColor;
import net.sourceforge.plantuml.ugraphic.ColorMapper;
import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.ColorMapperMonochrome;
import net.sourceforge.plantuml.ugraphic.UFont;
public class SkinParam implements ISkinParam {
@ -74,7 +79,7 @@ public class SkinParam implements ISkinParam {
public HtmlColor getBackgroundColor() {
final HtmlColor result = getHtmlColor(ColorParam.background, null);
if (result == null) {
return HtmlColor.getColorIfValid("white");
return HtmlColor.WHITE;
}
return result;
}
@ -119,7 +124,7 @@ public class SkinParam implements ISkinParam {
}
}
public int getFontSize(FontParam param, String stereotype) {
private int getFontSize(FontParam param, String stereotype) {
if (stereotype != null) {
checkStereotype(stereotype);
final String value2 = getValue(param.name() + "fontsize" + stereotype);
@ -132,12 +137,12 @@ public class SkinParam implements ISkinParam {
value = getValue("defaultfontsize");
}
if (value == null || value.matches("\\d+") == false) {
return param.getDefaultSize();
return param.getDefaultSize(this);
}
return Integer.parseInt(value);
}
public String getFontFamily(FontParam param, String stereotype) {
private String getFontFamily(FontParam param, String stereotype) {
if (stereotype != null) {
checkStereotype(stereotype);
final String value2 = getValue(param.name() + "fontname" + stereotype);
@ -177,7 +182,7 @@ public class SkinParam implements ISkinParam {
return HtmlColor.getColorIfValid(value);
}
public int getFontStyle(FontParam param, String stereotype) {
private int getFontStyle(FontParam param, String stereotype) {
String value = null;
if (stereotype != null) {
checkStereotype(stereotype);
@ -190,7 +195,7 @@ public class SkinParam implements ISkinParam {
value = getValue("defaultfontstyle");
}
if (value == null) {
return param.getDefaultFontStyle();
return param.getDefaultFontStyle(this);
}
int result = Font.PLAIN;
if (value.toLowerCase().contains("bold")) {
@ -202,12 +207,12 @@ public class SkinParam implements ISkinParam {
return result;
}
public Font getFont(FontParam fontParam, String stereotype) {
public UFont getFont(FontParam fontParam, String stereotype) {
if (stereotype != null) {
checkStereotype(stereotype);
}
return new Font(getFontFamily(fontParam, stereotype), getFontStyle(fontParam, stereotype), getFontSize(
fontParam, stereotype));
return new UFont(getFontFamily(fontParam, stereotype), getFontStyle(fontParam, stereotype),
getFontSize(fontParam, stereotype));
}
public int getCircledCharacterRadius() {
@ -233,7 +238,7 @@ public class SkinParam implements ISkinParam {
return 10;
}
public boolean isMonochrome() {
private boolean isMonochrome() {
return "true".equals(getValue("monochrome"));
}
@ -312,4 +317,20 @@ public class SkinParam implements ISkinParam {
return GraphvizLayoutStrategy.DOT;
}
public HorizontalAlignement getHorizontalAlignement(AlignParam param) {
final String value = getValue(param.name());
final HorizontalAlignement result = HorizontalAlignement.fromString(value);
if (result == null) {
return param.getDefaultValue();
}
return result;
}
public ColorMapper getColorMapper() {
if (isMonochrome()) {
return new ColorMapperMonochrome();
}
return new ColorMapperIdentity();
}
}

View File

@ -33,11 +33,12 @@
*/
package net.sourceforge.plantuml;
import java.awt.Font;
import net.sourceforge.plantuml.cucadiagram.dot.DotSplines;
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizLayoutStrategy;
import net.sourceforge.plantuml.graphic.HorizontalAlignement;
import net.sourceforge.plantuml.graphic.HtmlColor;
import net.sourceforge.plantuml.ugraphic.ColorMapper;
import net.sourceforge.plantuml.ugraphic.UFont;
public class SkinParamBackcolored implements ISkinParam {
@ -67,26 +68,14 @@ public class SkinParamBackcolored implements ISkinParam {
return skinParam.getCircledCharacterRadius();
}
public Font getFont(FontParam fontParam, String stereotype) {
public UFont getFont(FontParam fontParam, String stereotype) {
return skinParam.getFont(fontParam, stereotype);
}
public String getFontFamily(FontParam param, String stereotype) {
return skinParam.getFontFamily(param, stereotype);
}
public HtmlColor getFontHtmlColor(FontParam param, String stereotype) {
return skinParam.getFontHtmlColor(param, stereotype);
}
public int getFontSize(FontParam param, String stereotype) {
return skinParam.getFontSize(param, stereotype);
}
public int getFontStyle(FontParam param, String stereotype) {
return skinParam.getFontStyle(param, stereotype);
}
public HtmlColor getHtmlColor(ColorParam param, String stereotype) {
if (param.isBackground() && backColorElement != null) {
return backColorElement;
@ -106,10 +95,6 @@ public class SkinParamBackcolored implements ISkinParam {
return skinParam.classAttributeIconSize();
}
public boolean isMonochrome() {
return skinParam.isMonochrome();
}
public int getDpi() {
return skinParam.getDpi();
}
@ -125,4 +110,13 @@ public class SkinParamBackcolored implements ISkinParam {
public GraphvizLayoutStrategy getStrategy() {
return skinParam.getStrategy();
}
public HorizontalAlignement getHorizontalAlignement(AlignParam param) {
return skinParam.getHorizontalAlignement(param);
}
public ColorMapper getColorMapper() {
return skinParam.getColorMapper();
}
}

View File

@ -0,0 +1,118 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* 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 Lesser 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.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4246 $
*
*/
package net.sourceforge.plantuml;
import net.sourceforge.plantuml.cucadiagram.dot.DotSplines;
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizLayoutStrategy;
import net.sourceforge.plantuml.graphic.HorizontalAlignement;
import net.sourceforge.plantuml.graphic.HtmlColor;
import net.sourceforge.plantuml.ugraphic.ColorMapper;
import net.sourceforge.plantuml.ugraphic.UFont;
public class SkinParamBackcoloredReference implements ISkinParam {
final private ISkinParam skinParam;
final private HtmlColor sequenceReferenceHeaderBackground;
final private HtmlColor sequenceReferenceBackground;
public SkinParamBackcoloredReference(ISkinParam skinParam, HtmlColor sequenceReferenceHeaderBackground,
HtmlColor sequenceReferenceBackground) {
this.skinParam = skinParam;
this.sequenceReferenceBackground = sequenceReferenceBackground;
this.sequenceReferenceHeaderBackground = sequenceReferenceHeaderBackground;
}
public HtmlColor getBackgroundColor() {
return skinParam.getBackgroundColor();
}
public int getCircledCharacterRadius() {
return skinParam.getCircledCharacterRadius();
}
public UFont getFont(FontParam fontParam, String stereotype) {
return skinParam.getFont(fontParam, stereotype);
}
public HtmlColor getFontHtmlColor(FontParam param, String stereotype) {
return skinParam.getFontHtmlColor(param, stereotype);
}
public HtmlColor getHtmlColor(ColorParam param, String stereotype) {
if (param == ColorParam.sequenceReferenceHeaderBackground && sequenceReferenceHeaderBackground != null) {
return sequenceReferenceHeaderBackground;
}
if (param == ColorParam.sequenceReferenceBackground && sequenceReferenceBackground != null) {
return sequenceReferenceBackground;
}
return skinParam.getHtmlColor(param, stereotype);
}
public String getValue(String key) {
return skinParam.getValue(key);
}
public boolean isClassCollapse() {
return skinParam.isClassCollapse();
}
public int classAttributeIconSize() {
return skinParam.classAttributeIconSize();
}
public int getDpi() {
return skinParam.getDpi();
}
public boolean useOctagonForActivity() {
return skinParam.useOctagonForActivity();
}
public DotSplines getDotSplines() {
return skinParam.getDotSplines();
}
public GraphvizLayoutStrategy getStrategy() {
return skinParam.getStrategy();
}
public HorizontalAlignement getHorizontalAlignement(AlignParam param) {
return skinParam.getHorizontalAlignement(param);
}
public ColorMapper getColorMapper() {
return skinParam.getColorMapper();
}
}

View File

@ -49,7 +49,7 @@ import net.sourceforge.plantuml.code.Transcoder;
import net.sourceforge.plantuml.code.TranscoderUtil;
import net.sourceforge.plantuml.preproc.Defines;
public class SourceFileReader {
public class SourceFileReader implements ISourceFileReader {
private final File file;
private final File outputDirectory;
@ -62,10 +62,12 @@ public class SourceFileReader {
}
public SourceFileReader(final File file, File outputDirectory) throws IOException {
this(new Defines(), file, outputDirectory, Collections.<String> emptyList(), null, new FileFormatOption(FileFormat.PNG));
this(new Defines(), file, outputDirectory, Collections.<String> emptyList(), null, new FileFormatOption(
FileFormat.PNG));
}
public SourceFileReader(final File file, File outputDirectory, FileFormatOption fileFormatOption) throws IOException {
public SourceFileReader(final File file, File outputDirectory, FileFormatOption fileFormatOption)
throws IOException {
this(new Defines(), file, outputDirectory, Collections.<String> emptyList(), null, fileFormatOption);
}
@ -86,8 +88,17 @@ public class SourceFileReader {
outputDirectory.mkdirs();
}
this.outputDirectory = outputDirectory;
builder = new BlockUmlBuilder(config, defines, getReader(charset));
builder = new BlockUmlBuilder(config, defines, getReader(charset), file.getAbsoluteFile().getParentFile());
}
public boolean hasError() throws IOException, InterruptedException {
for (final BlockUml b : builder.getBlockUmls()) {
if (b.getSystem() instanceof PSystemError) {
return true;
}
}
return false;
}
public List<GeneratedImage> getGeneratedImages() throws IOException, InterruptedException {
@ -100,15 +111,18 @@ public class SourceFileReader {
String newName = blockUml.getFilename();
if (newName == null) {
newName = changeName(file.getName(), cpt++, fileFormatOption.getFileFormat());
newName = fileFormatOption.getFileFormat().changeName(file.getName(), cpt++);
}
final File suggested = new File(outputDirectory, newName);
suggested.getParentFile().mkdirs();
for (File f : blockUml.getSystem().exportDiagrams(suggested, fileFormatOption)) {
final String desc = "[" + file.getName() + "] " + blockUml.getSystem().getDescription();
final GeneratedImage generatedImage = new GeneratedImage(f, desc);
final PSystem system = blockUml.getSystem();
OptionFlags.getInstance().logData(file, system);
for (File f : system.exportDiagrams(suggested, fileFormatOption)) {
final String desc = "[" + file.getName() + "] " + system.getDescription();
final GeneratedImage generatedImage = new GeneratedImage(f, desc, system);
result.add(generatedImage);
}
@ -130,13 +144,6 @@ public class SourceFileReader {
return Collections.unmodifiableList(result);
}
static String changeName(String name, int cpt, FileFormat fileFormat) {
if (cpt == 0) {
return name.replaceAll("\\.\\w+$", fileFormat.getFileSuffix());
}
return name.replaceAll("\\.\\w+$", "_" + String.format("%03d", cpt) + fileFormat.getFileSuffix());
}
private Reader getReader(String charset) throws FileNotFoundException, UnsupportedEncodingException {
if (charset == null) {
Log.info("Using default charset");
@ -149,10 +156,9 @@ public class SourceFileReader {
public final void setFileFormatOption(FileFormatOption fileFormatOption) {
this.fileFormatOption = fileFormatOption;
}
public final Set<File> getIncludedFiles() {
return builder.getIncludedFiles();
}
}

View File

@ -0,0 +1,134 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* 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 Lesser 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.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4771 $
*
*/
package net.sourceforge.plantuml;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import net.sourceforge.plantuml.code.Transcoder;
import net.sourceforge.plantuml.code.TranscoderUtil;
import net.sourceforge.plantuml.preproc.Defines;
public class SourceFileReader2 implements ISourceFileReader {
private final File file;
private final File outputFile;
private final BlockUmlBuilder builder;
private FileFormatOption fileFormatOption;
public SourceFileReader2(Defines defines, final File file, File outputFile, List<String> config,
String charset, FileFormatOption fileFormatOption) throws IOException {
this.file = file;
this.fileFormatOption = fileFormatOption;
this.outputFile = outputFile;
if (file.exists() == false) {
throw new IllegalArgumentException();
}
FileSystem.getInstance().setCurrentDir(file.getAbsoluteFile().getParentFile());
builder = new BlockUmlBuilder(config, defines, getReader(charset), file.getAbsoluteFile().getParentFile());
}
public boolean hasError() throws IOException, InterruptedException {
for (final BlockUml b : builder.getBlockUmls()) {
if (b.getSystem() instanceof PSystemError) {
return true;
}
}
return false;
}
public List<GeneratedImage> getGeneratedImages() throws IOException, InterruptedException {
Log.info("Reading file: " + file);
final List<GeneratedImage> result = new ArrayList<GeneratedImage>();
for (BlockUml blockUml : builder.getBlockUmls()) {
final File suggested = outputFile;
final PSystem system = blockUml.getSystem();
OptionFlags.getInstance().logData(file, system);
for (File f : system.exportDiagrams(suggested, fileFormatOption)) {
final String desc = "[" + file.getName() + "] " + system.getDescription();
final GeneratedImage generatedImage = new GeneratedImage(f, desc, system);
result.add(generatedImage);
}
}
Log.info("Number of image(s): " + result.size());
return Collections.unmodifiableList(result);
}
public List<String> getEncodedUrl() throws IOException, InterruptedException {
final List<String> result = new ArrayList<String>();
final Transcoder transcoder = TranscoderUtil.getDefaultTranscoder();
for (BlockUml blockUml : builder.getBlockUmls()) {
final String source = blockUml.getSystem().getSource().getPlainString();
final String encoded = transcoder.encode(source);
result.add(encoded);
}
return Collections.unmodifiableList(result);
}
private Reader getReader(String charset) throws FileNotFoundException, UnsupportedEncodingException {
if (charset == null) {
Log.info("Using default charset");
return new InputStreamReader(new FileInputStream(file));
}
Log.info("Using charset " + charset);
return new InputStreamReader(new FileInputStream(file), charset);
}
public final void setFileFormatOption(FileFormatOption fileFormatOption) {
this.fileFormatOption = fileFormatOption;
}
public final Set<File> getIncludedFiles() {
return builder.getIncludedFiles();
}
}

View File

@ -33,6 +33,7 @@
*/
package net.sourceforge.plantuml;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@ -55,7 +56,7 @@ public class SourceStringReader {
public SourceStringReader(Defines defines, String source, List<String> config) {
try {
final BlockUmlBuilder builder = new BlockUmlBuilder(config, defines, new StringReader(source));
final BlockUmlBuilder builder = new BlockUmlBuilder(config, defines, new StringReader(source), null);
this.blocks = builder.getBlockUmls();
} catch (IOException e) {
throw new IllegalStateException();
@ -67,7 +68,7 @@ public class SourceStringReader {
}
public String generateImage(File f) throws IOException {
final FileOutputStream os = new FileOutputStream(f);
final OutputStream os = new BufferedOutputStream(new FileOutputStream(f));
final String result = generateImage(os, 0);
os.close();
return result;
@ -100,7 +101,7 @@ public class SourceStringReader {
} catch (InterruptedException e) {
return null;
}
Log.error("numImage is too big = ");
Log.error("numImage is too big = " + numImage);
return null;
}

View File

@ -39,6 +39,6 @@ public interface SpecificBackcolorable {
public HtmlColor getSpecificBackColor();
public void setSpecificBackcolor(String specificBackcolor);
public void setSpecificBackcolor(HtmlColor specificBackcolor);
}

View File

@ -28,11 +28,12 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6110 $
* Revision $Revision: 6923 $
*
*/
package net.sourceforge.plantuml;
import java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
@ -79,7 +80,7 @@ public class StringUtils {
return Collections.unmodifiableList(result);
}
public static String getMergedLines(List<String> strings) {
public static String getMergedLines(List<? extends CharSequence> strings) {
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < strings.size(); i++) {
sb.append(strings.get(i));
@ -107,6 +108,10 @@ public class StringUtils {
return input != null && input.trim().length() > 0;
}
public static boolean isNotEmpty(List<? extends CharSequence> input) {
return input != null && input.size() > 0;
}
public static boolean isEmpty(String input) {
return input == null || input.trim().length() == 0;
}
@ -212,32 +217,6 @@ public class StringUtils {
return s;
}
// private static String cleanLineFromSource(String s) {
// if (s.startsWith("\uFEFF")) {
// s = s.substring(1);
// }
// if (s.startsWith("~~")) {
// s = s.substring("~~".length());
// }
// // if (s.startsWith(" * ")) {
// // s = s.substring(" * ".length());
// // }
// s = s.replaceFirst("^\\s+\\* ", "");
// if (s.equals(" *")) {
// s = "";
// }
// s = s.trim();
// while (s.startsWith(" ") || s.startsWith("/") || s.startsWith("\t") ||
// s.startsWith("%") || s.startsWith("/*")) {
// if (s.startsWith("/*")) {
// s = s.substring(2).trim();
// } else {
// s = s.substring(1).trim();
// }
// }
// return s;
// }
public static boolean isCJK(char c) {
final Character.UnicodeBlock block = Character.UnicodeBlock.of(c);
System.err.println(block);
@ -329,8 +308,7 @@ public class StringUtils {
public static String uncommentSource(String source) {
final StringReader sr = new StringReader(source);
final UncommentReadLine un = new UncommentReadLine(new ReadLineReader(
sr));
final UncommentReadLine un = new UncommentReadLine(new ReadLineReader(sr));
final StringBuilder sb = new StringBuilder();
String s = null;
try {
@ -359,6 +337,64 @@ public class StringUtils {
return false;
}
return true;
}
public static List<String> splitComma(String s) {
s = s.trim();
if (s.matches("([\\p{L}0-9_.]+|\"[^\"]+\")(\\s*,\\s*([\\p{L}0-9_.]+|\"[^\"]+\"))*") == false) {
throw new IllegalArgumentException();
}
final List<String> result = new ArrayList<String>();
final Pattern p = Pattern.compile("([\\p{L}0-9_.]+|\"[^\"]+\")");
final Matcher m = p.matcher(s);
while (m.find()) {
result.add(eventuallyRemoveStartingAndEndingDoubleQuote(m.group(0)));
}
return Collections.unmodifiableList(result);
}
public static String getAsHtml(Color color) {
if (color == null) {
throw new IllegalArgumentException();
}
return getAsHtml(color.getRGB());
}
public static String getAsHtml(int color) {
final int v = 0xFFFFFF & color;
String s = "000000" + Integer.toHexString(v).toUpperCase();
s = s.substring(s.length() - 6);
return "#" + s;
}
public static String getUid(String uid1, int uid2) {
return uid1 + String.format("%04d", uid2);
}
public static List<CharSequence> manageEmbededDiagrams(final List<String> strings) {
final List<CharSequence> result = new ArrayList<CharSequence>();
final Iterator<String> it = strings.iterator();
while (it.hasNext()) {
CharSequence s = it.next();
if (s.equals("{{")) {
final List<String> other = new ArrayList<String>();
other.add("@startuml");
while (it.hasNext()) {
String s2 = it.next();
if (s2.equals("}}")) {
break;
}
other.add(s2);
}
other.add("@enduml");
s = new EmbededDiagram(other);
}
result.add(s);
}
return result;
}
}

View File

@ -28,14 +28,16 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6382 $
* Revision $Revision: 6922 $
*
*/
package net.sourceforge.plantuml;
import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
@ -48,6 +50,7 @@ import java.util.List;
import net.sourceforge.plantuml.code.Compression;
import net.sourceforge.plantuml.code.CompressionZlib;
import net.sourceforge.plantuml.graphic.HorizontalAlignement;
import net.sourceforge.plantuml.pdf.PdfConverter;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
@ -64,7 +67,7 @@ public abstract class UmlDiagram extends AbstractPSystem implements PSystem {
private int minwidth = Integer.MAX_VALUE;
private List<String> title;
private List<? extends CharSequence> title;
private List<String> header;
private List<String> footer;
private HorizontalAlignement headerAlignement = HorizontalAlignement.RIGHT;
@ -74,11 +77,11 @@ public abstract class UmlDiagram extends AbstractPSystem implements PSystem {
private final SkinParam skinParam = new SkinParam();
final public void setTitle(List<String> strings) {
final public void setTitle(List<? extends CharSequence> strings) {
this.title = strings;
}
final public List<String> getTitle() {
final public List<? extends CharSequence> getTitle() {
return title;
}
@ -193,9 +196,24 @@ public abstract class UmlDiagram extends AbstractPSystem implements PSystem {
e.printStackTrace();
flashcodes = null;
}
if (fileFormatOption.getFileFormat() == FileFormat.PDF) {
exportDiagramInternalPdf(os, cmap, index, flashcodes);
return;
}
exportDiagramInternal(os, cmap, index, fileFormatOption, flashcodes);
}
private void exportDiagramInternalPdf(OutputStream os, StringBuilder cmap, int index, List<BufferedImage> flashcodes)
throws IOException {
final File svg = FileUtils.createTempFile("pdf", ".svf");
final File pdfFile = FileUtils.createTempFile("pdf", ".pdf");
final OutputStream fos = new BufferedOutputStream(new FileOutputStream(svg));
exportDiagram(fos, cmap, index, new FileFormatOption(FileFormat.SVG));
fos.close();
PdfConverter.convert(svg, pdfFile);
FileUtils.copyToStream(pdfFile, os);
}
protected abstract void exportDiagramInternal(OutputStream os, StringBuilder cmap, int index,
FileFormatOption fileFormatOption, List<BufferedImage> flashcodes) throws IOException;
@ -217,9 +235,6 @@ public abstract class UmlDiagram extends AbstractPSystem implements PSystem {
return name.replaceAll("(?i)\\.\\w{3}$", ".cmapx");
}
private List<BufferedImage> exportFlashcodeSimple(String s) throws IOException, WriterException {
final QRCodeWriter writer = new QRCodeWriter();
final int multiple = 1;
@ -298,7 +313,5 @@ public abstract class UmlDiagram extends AbstractPSystem implements PSystem {
}
return result;
}
}

View File

@ -34,9 +34,12 @@
package net.sourceforge.plantuml;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
final public class UmlSource {
@ -89,4 +92,16 @@ final public class UmlSource {
return true;
}
public List<String> getTitle() {
final Pattern p = Pattern.compile("(?i)^\\s*title\\s+(.+)$");
for (String s : source) {
final Matcher m = p.matcher(s);
final boolean ok = m.matches();
if (ok) {
return Arrays.asList(m.group(1));
}
}
return Collections.emptyList();
}
}

View File

@ -28,21 +28,23 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 3823 $
* Revision $Revision: 6644 $
*
*/
package net.sourceforge.plantuml;
import java.util.concurrent.atomic.AtomicInteger;
public class UniqueSequence {
private static int cpt = 1;
private static final AtomicInteger cpt = new AtomicInteger(1);
public static void reset() {
cpt = 1;
cpt.set(0);
}
public static int getValue() {
return cpt++;
return cpt.addAndGet(1);
}
}

View File

@ -51,6 +51,9 @@ public class CommandElse extends SingleLineCommand<ActivityDiagram> {
if (getSystem().getLastEntityConsulted() == null) {
return CommandExecutionResult.error("No if for this else");
}
if (getSystem().getCurrentContext() == null) {
return CommandExecutionResult.error("No if for this else");
}
final IEntity branch = getSystem().getCurrentContext().getBranch();
getSystem().setLastEntityConsulted(branch);

View File

@ -50,6 +50,9 @@ public class CommandEndif extends SingleLineCommand<ActivityDiagram> {
if (getSystem().getLastEntityConsulted() == null) {
return CommandExecutionResult.error("No if for this endif");
}
if (getSystem().getCurrentContext() == null) {
return CommandExecutionResult.error("No if for this endif");
}
getSystem().endif();
return CommandExecutionResult.ok();

View File

@ -50,6 +50,7 @@ import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.LinkDecor;
import net.sourceforge.plantuml.cucadiagram.LinkType;
import net.sourceforge.plantuml.cucadiagram.Stereotype;
import net.sourceforge.plantuml.graphic.HtmlColor;
public class CommandLinkActivity extends SingleLineCommand2<ActivityDiagram> {
@ -97,7 +98,7 @@ public class CommandLinkActivity extends SingleLineCommand2<ActivityDiagram> {
entity1.setStereotype(new Stereotype(arg2.get("STEREOTYPE").get(0)));
}
if (arg2.get("BACKCOLOR").get(0) != null) {
entity1.setSpecificBackcolor(arg2.get("BACKCOLOR").get(0));
entity1.setSpecificBackcolor(HtmlColor.getColorIfValid(arg2.get("BACKCOLOR").get(0)));
}
final IEntity entity2 = getEntity(getSystem(), arg2, false);
@ -105,7 +106,7 @@ public class CommandLinkActivity extends SingleLineCommand2<ActivityDiagram> {
return CommandExecutionResult.error("No such activity");
}
if (arg2.get("BACKCOLOR2").get(0) != null) {
entity2.setSpecificBackcolor(arg2.get("BACKCOLOR2").get(0));
entity2.setSpecificBackcolor(HtmlColor.getColorIfValid(arg2.get("BACKCOLOR2").get(0)));
}
if (arg2.get("STEREOTYPE2").get(0) != null) {
entity2.setStereotype(new Stereotype(arg2.get("STEREOTYPE2").get(0)));

View File

@ -52,6 +52,7 @@ import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.LinkDecor;
import net.sourceforge.plantuml.cucadiagram.LinkType;
import net.sourceforge.plantuml.cucadiagram.Stereotype;
import net.sourceforge.plantuml.graphic.HtmlColor;
public class CommandLinkLongActivity extends CommandMultilines2<ActivityDiagram> {
@ -91,7 +92,7 @@ public class CommandLinkLongActivity extends CommandMultilines2<ActivityDiagram>
entity1.setStereotype(new Stereotype(line0.get("STEREOTYPE").get(0)));
}
if (line0.get("BACKCOLOR").get(0)!=null) {
entity1.setSpecificBackcolor(line0.get("BACKCOLOR").get(0));
entity1.setSpecificBackcolor(HtmlColor.getColorIfValid(line0.get("BACKCOLOR").get(0)));
}
final StringBuilder sb = new StringBuilder();
@ -122,7 +123,7 @@ public class CommandLinkLongActivity extends CommandMultilines2<ActivityDiagram>
entity2.setStereotype(new Stereotype(lineLast.get(2)));
}
if (lineLast.get(3)!=null) {
entity2.setSpecificBackcolor(lineLast.get(3));
entity2.setSpecificBackcolor(HtmlColor.getColorIfValid(lineLast.get(3)));
}
if (entity1 == null || entity2 == null) {

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5751 $
* Revision $Revision: 6939 $
*
*/
package net.sourceforge.plantuml.activitydiagram.command;
@ -39,6 +39,7 @@ import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.activitydiagram.ActivityDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.CommandMultilines;
import net.sourceforge.plantuml.command.Position;
import net.sourceforge.plantuml.cucadiagram.Link;
public class CommandMultilinesNoteActivityLink extends CommandMultilines<ActivityDiagram> {
@ -50,13 +51,13 @@ public class CommandMultilinesNoteActivityLink extends CommandMultilines<Activit
public final CommandExecutionResult execute(List<String> lines) {
final List<String> strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1));
final String s = StringUtils.getMergedLines(strings);
// final String s = StringUtils.getMergedLines(strings);
final Link link = getSystem().getLastActivityLink();
if (link == null) {
return CommandExecutionResult.error("Nothing to note");
}
link.setNote(s);
link.addNote(strings, Position.BOTTOM);
return CommandExecutionResult.ok();
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4762 $
* Revision $Revision: 6939 $
*
*/
package net.sourceforge.plantuml.activitydiagram.command;
@ -37,6 +37,7 @@ import java.util.List;
import net.sourceforge.plantuml.activitydiagram.ActivityDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.Position;
import net.sourceforge.plantuml.command.SingleLineCommand;
import net.sourceforge.plantuml.cucadiagram.Link;
@ -52,7 +53,7 @@ public class CommandNoteOnActivityLink extends SingleLineCommand<ActivityDiagram
if (link == null) {
return CommandExecutionResult.error("No link defined");
}
link.setNote(arg.get(0));
link.addNote(arg.get(0), Position.BOTTOM);
return CommandExecutionResult.ok();
}

View File

@ -83,18 +83,19 @@ public class ActivityDiagram2 extends CucaDiagram {
return waitings.size() > 0;
}
public void newActivity(String display) {
public void newActivity(String display, Direction direction) {
if (waitings.size() == 0) {
throw new IllegalStateException();
}
final Entity act = createEntity(getAutoCode(), display, EntityType.ACTIVITY);
afterAdd(act);
afterAdd(act, direction);
}
private final Map<String, IEntity> bars = new HashMap<String, IEntity>();
public void bar(String bar) {
final Direction direction = Direction.DOWN;
if (bars.containsKey(bar)) {
final IEntity existingBar = bars.get(bar);
for (Iterator<IEntity> it = waitings.iterator(); it.hasNext();) {
@ -103,7 +104,7 @@ public class ActivityDiagram2 extends CucaDiagram {
it.remove();
}
}
afterAdd(existingBar);
afterAdd(existingBar, direction);
return;
}
@ -113,14 +114,26 @@ public class ActivityDiagram2 extends CucaDiagram {
label(bar);
final Entity act = createEntity(getAutoCode(), bar, EntityType.SYNCHRO_BAR);
bars.put(bar, act);
afterAdd(act);
afterAdd(act, direction);
}
private void afterAdd(final IEntity dest) {
private void afterAdd(final IEntity dest, Direction direction) {
for (IEntity last : this.waitings) {
// System.err.println("last=" + last);
// System.err.println("act=" + act);
this.addLink(new Link(last, dest, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), futureLabel, 2));
final Link link;
if (direction == Direction.DOWN) {
link = new Link(last, dest, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), futureLabel, 2);
} else if (direction == Direction.RIGHT) {
link = new Link(last, dest, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), futureLabel, 1);
} else if (direction == Direction.LEFT) {
link = new Link(dest, last, new LinkType(LinkDecor.NONE, LinkDecor.ARROW), futureLabel, 1);
} else if (direction == Direction.UP) {
link = new Link(dest, last, new LinkType(LinkDecor.NONE, LinkDecor.ARROW), futureLabel, 2);
} else {
throw new UnsupportedOperationException();
}
this.addLink(link);
futureLabel = null;
}
@ -239,12 +252,12 @@ public class ActivityDiagram2 extends CucaDiagram {
// currentContext.clearPendingsButFirst();
}
public void end() {
public void end(Direction direction) {
if (waitings.size() == 0) {
throw new IllegalStateException();
}
final IEntity act = getOrCreateEntity("end", EntityType.CIRCLE_END);
afterAdd(act);
afterAdd(act, direction);
}
}

View File

@ -59,6 +59,7 @@ public class ActivityDiagramFactory2 extends AbstractUmlSystemCommandFactory {
system = new ActivityDiagram2();
addCommonCommands(system);
addCommand(new CommandEnd2(system));
addCommand(new CommandStart2(system));
addCommand(new CommandNewActivity2(system));
addCommand(new CommandIf2(system));
@ -67,7 +68,6 @@ public class ActivityDiagramFactory2 extends AbstractUmlSystemCommandFactory {
addCommand(new CommandLabel2(system));
addCommand(new CommandGoto2(system));
addCommand(new CommandBar2(system));
addCommand(new CommandEnd2(system));
// addCommand(new CommandLinkActivity(system));
// addCommand(new CommandPartition(system));

View File

@ -35,6 +35,7 @@ package net.sourceforge.plantuml.activitydiagram2.command;
import java.util.Map;
import net.sourceforge.plantuml.Direction;
import net.sourceforge.plantuml.activitydiagram2.ActivityDiagram2;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand2;
@ -49,18 +50,23 @@ public class CommandEnd2 extends SingleLineCommand2<ActivityDiagram2> {
}
static RegexConcat getRegexConcat() {
return new RegexConcat(new RegexLeaf("^"),
new RegexLeaf("end"),
new RegexLeaf("$"));
return new RegexConcat(new RegexLeaf("^"), //
new RegexLeaf("direction", "([<>^])?\\s*"), //
new RegexLeaf("end"), //
new RegexLeaf("$"));
}
@Override
protected CommandExecutionResult executeArg(Map<String, RegexPartialMatch> arg) {
// if (getSystem().getLastEntityConsulted() == null) {
// return CommandExecutionResult.error("No if for this endif");
// }
getSystem().end();
// if (getSystem().getLastEntityConsulted() == null) {
// return CommandExecutionResult.error("No if for this endif");
// }
final String sdir = arg.get("direction").get(0);
Direction direction = Direction.DOWN;
if (sdir != null) {
direction = Direction.fromChar(sdir.charAt(0));
}
getSystem().end(direction);
return CommandExecutionResult.ok();
}

View File

@ -35,6 +35,8 @@ package net.sourceforge.plantuml.activitydiagram2.command;
import java.util.List;
import net.sourceforge.plantuml.Direction;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.activitydiagram2.ActivityDiagram2;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand;
@ -42,7 +44,7 @@ import net.sourceforge.plantuml.command.SingleLineCommand;
public class CommandNewActivity2 extends SingleLineCommand<ActivityDiagram2> {
public CommandNewActivity2(ActivityDiagram2 diagram) {
super(diagram, "(?i)^\\s*[-*]\\s*([^\"\\s].*)$");
super(diagram, "(?i)^\\s*([-*<>^])\\s*([^\"\\s].*|\\s*\"[^\"\\s].*\")$");
}
@Override
@ -55,8 +57,8 @@ public class CommandNewActivity2 extends SingleLineCommand<ActivityDiagram2> {
return CommandExecutionResult.error("Unreachable statement");
}
getSystem().newActivity(arg.get(0));
getSystem().newActivity(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(1).trim()),
Direction.fromChar(arg.get(0).charAt(0)));
return CommandExecutionResult.ok();
}
}

View File

@ -35,6 +35,7 @@ package net.sourceforge.plantuml.activitydiagram2.command;
import java.util.List;
import net.sourceforge.plantuml.Direction;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.activitydiagram2.ActivityDiagram2;
import net.sourceforge.plantuml.command.CommandExecutionResult;
@ -43,7 +44,7 @@ import net.sourceforge.plantuml.command.CommandMultilines;
public class CommandNewMultilinesActivity2 extends CommandMultilines<ActivityDiagram2> {
public CommandNewMultilinesActivity2(final ActivityDiagram2 system) {
super(system, "(?i)^\\s*[-*]\\s*\"\\s*.*$", "(?i)^.*\\s*\"\\s*$");
super(system, "(?i)^\\s*[-*<>^]\\s*\"\\s*.*$", "(?i)^.*\\s*\"\\s*$");
}
public final CommandExecutionResult execute(List<String> lines) {
@ -56,14 +57,15 @@ public class CommandNewMultilinesActivity2 extends CommandMultilines<ActivityDia
}
String s = StringUtils.getMergedLines(lines);
s = s.trim();
assert s.startsWith("-") || s.startsWith("*") ;
assert s.startsWith("-") || s.startsWith("*") || s.startsWith("<") || s.startsWith(">") || s.startsWith("^");
final Direction direction = Direction.fromChar(s.charAt(0));
s = s.substring(1);
s = s.trim();
assert s.startsWith("\"");
assert s.endsWith("\"");
s = s.substring(1, s.length() - 2);
s = s.substring(1, s.length() - 1);
getSystem().newActivity(s);
getSystem().newActivity(s, direction);
return CommandExecutionResult.ok();
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5877 $
* Revision $Revision: 6625 $
*
*/
package net.sourceforge.plantuml.ant;
@ -38,8 +38,12 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import net.sourceforge.plantuml.DirWatcher;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.GeneratedImage;
import net.sourceforge.plantuml.Option;
@ -71,6 +75,8 @@ public class PlantUmlTask extends Task {
private final Option option = new Option();
private List<FileSet> filesets = new ArrayList<FileSet>();
private List<FileList> filelists = new ArrayList<FileList>();
private AtomicInteger nbFiles = new AtomicInteger(0);
private ExecutorService executorService;
/**
* Add a set of files to touch
@ -94,14 +100,22 @@ public class PlantUmlTask extends Task {
try {
if (dir != null) {
processingSingleDirectory(new File(dir));
final File error = processingSingleDirectory(new File(dir));
checkError(error);
}
for (FileSet fileSet : filesets) {
manageFileSet(fileSet);
final File error = manageFileSet(fileSet);
checkError(error);
}
for (FileList fileList : filelists) {
manageFileList(fileList);
final File error = manageFileList(fileList);
checkError(error);
}
if (executorService != null) {
executorService.shutdown();
executorService.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
}
this.log("Nb images generated: " + nbFiles.get());
} catch (IOException e) {
e.printStackTrace();
throw new BuildException(e.toString());
@ -112,18 +126,29 @@ public class PlantUmlTask extends Task {
}
private void manageFileList(FileList fl) throws IOException, InterruptedException {
private void checkError(final File error) throws IOException {
if (error != null && OptionFlags.getInstance().isFailOnError()) {
this.log("Error in file " + error.getCanonicalPath());
throw new BuildException("Error in file " + error.getCanonicalPath());
}
}
private File manageFileList(FileList fl) throws IOException, InterruptedException {
final File fromDir = fl.getDir(getProject());
final String[] srcFiles = fl.getFiles(getProject());
for (String src : srcFiles) {
final File f = new File(fromDir, src);
processingSingleFile(f);
final boolean error = processingSingleFile(f);
if (error) {
return f;
}
}
return null;
}
private void manageFileSet(FileSet fs) throws IOException, InterruptedException {
private File manageFileSet(FileSet fs) throws IOException, InterruptedException {
final DirectoryScanner ds = fs.getDirectoryScanner(getProject());
final File fromDir = fs.getDir(getProject());
@ -132,37 +157,95 @@ public class PlantUmlTask extends Task {
for (String src : srcFiles) {
final File f = new File(fromDir, src);
processingSingleFile(f);
final boolean error = processingSingleFile(f);
if (error) {
return f;
}
}
for (String src : srcDirs) {
final File dir = new File(fromDir, src);
processingSingleDirectory(dir);
final File errorFile = processingSingleDirectory(dir);
if (errorFile != null) {
return errorFile;
}
}
return null;
}
private void processingSingleFile(final File f) throws IOException, InterruptedException {
this.log("Processing " + f.getAbsolutePath());
private boolean processingSingleFile(final File f) throws IOException, InterruptedException {
if (OptionFlags.getInstance().isVerbose()) {
this.log("Processing " + f.getAbsolutePath());
}
final SourceFileReader sourceFileReader = new SourceFileReader(new Defines(), f, option.getOutputDir(), option
.getConfig(), option.getCharset(), option.getFileFormatOption());
final Collection<GeneratedImage> result = sourceFileReader.getGeneratedImages();
for (GeneratedImage g : result) {
this.log(g + " " + g.getDescription());
if (option.isCheckOnly()) {
return sourceFileReader.hasError();
}
if (executorService == null) {
return doFile(f, sourceFileReader);
}
executorService.submit(new Callable<Boolean>() {
public Boolean call() throws Exception {
return doFile(f, sourceFileReader);
}
});
return false;
}
private void processingSingleDirectory(File f) throws IOException, InterruptedException {
if (f.exists() == false) {
final String s = "The file " + f.getAbsolutePath() + " does not exists.";
private boolean doFile(final File f, final SourceFileReader sourceFileReader) throws IOException,
InterruptedException {
final Collection<GeneratedImage> result = sourceFileReader.getGeneratedImages();
boolean error = false;
for (GeneratedImage g : result) {
if (OptionFlags.getInstance().isVerbose()) {
myLog(g + " " + g.getDescription());
}
nbFiles.addAndGet(1);
if (g.isError()) {
error = true;
}
}
if (error) {
myLog("Error: " + f.getCanonicalPath());
}
if (error && OptionFlags.getInstance().isFailOnError()) {
return true;
}
return false;
}
private synchronized void myLog(String s) {
this.log(s);
}
private File processingSingleDirectory(File dir) throws IOException, InterruptedException {
if (dir.exists() == false) {
final String s = "The file " + dir.getAbsolutePath() + " does not exists.";
this.log(s);
throw new BuildException(s);
}
final DirWatcher dirWatcher = new DirWatcher(f, option, Option.getPattern());
final Collection<GeneratedImage> result = dirWatcher.buildCreatedFiles();
for (GeneratedImage g : result) {
this.log(g + " " + g.getDescription());
for (File f : dir.listFiles()) {
if (f.isFile() == false) {
continue;
}
if (fileToProcess(f.getName()) == false) {
continue;
}
final boolean error = processingSingleFile(f);
if (error) {
return f;
}
}
return null;
}
private boolean fileToProcess(String name) {
return name.matches(Option.getPattern());
}
public void setDir(String s) {
@ -210,6 +293,12 @@ public class PlantUmlTask extends Task {
if ("eps".equalsIgnoreCase(s)) {
option.setFileFormat(FileFormat.EPS);
}
if ("pdf".equalsIgnoreCase(s)) {
option.setFileFormat(FileFormat.PDF);
}
if ("eps:text".equalsIgnoreCase(s)) {
option.setFileFormat(FileFormat.EPS_TEXT);
}
if ("svg".equalsIgnoreCase(s)) {
option.setFileFormat(FileFormat.SVG);
}
@ -237,4 +326,35 @@ public class PlantUmlTask extends Task {
}
}
public void setNbThread(String s) {
if (s != null && s.matches("\\d+")) {
option.setNbThreads(Integer.parseInt(s));
final int nbThreads = option.getNbThreads();
this.executorService = Executors.newFixedThreadPool(nbThreads);
}
if ("auto".equalsIgnoreCase(s)) {
option.setNbThreads(Option.defaultNbThreads());
final int nbThreads = option.getNbThreads();
this.executorService = Executors.newFixedThreadPool(nbThreads);
}
}
public void setNbThreads(String s) {
setNbThread(s);
}
public void setSuggestEngine(String s) {
OptionFlags.getInstance().setUseSuggestEngine("true".equalsIgnoreCase(s) || "yes".equalsIgnoreCase(s) || "on".equalsIgnoreCase(s));
}
public void setFailOnError(String s) {
OptionFlags.getInstance().setFailOnError("true".equalsIgnoreCase(s) || "yes".equalsIgnoreCase(s) || "on".equalsIgnoreCase(s));
}
public void setCheckOnly(String s) {
final boolean flag = "true".equalsIgnoreCase(s) || "yes".equalsIgnoreCase(s) || "on".equalsIgnoreCase(s);
option.setCheckOnly(true);
OptionFlags.getInstance().setFailOnError(flag);
}
}

View File

@ -1,241 +0,0 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* 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 Lesser 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.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5877 $
*
*/
package net.sourceforge.plantuml.ant;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import net.sourceforge.plantuml.DirWatcher;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.GeneratedImage;
import net.sourceforge.plantuml.Option;
import net.sourceforge.plantuml.OptionFlags;
import net.sourceforge.plantuml.SourceFileReader;
import net.sourceforge.plantuml.preproc.Defines;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.FileList;
import org.apache.tools.ant.types.FileSet;
// <?xml version="1.0"?>
//
// <project name="OwnTaskExample" default="main" basedir=".">
// <taskdef name="plot" classname="plot.PlotTask" classpath="build"/>
//
// <target name="main">
// <mytask message="Hello World! MyVeryOwnTask works!"/>
// </target>
// </project>
// Carriage Return in UTF-8 XML: &#13;
// Line Feed in UTF-8 XML: &#10;
public class PlantuTask extends Task {
private String dir = null;
private final Option option = new Option();
private List<FileSet> filesets = new ArrayList<FileSet>();
private List<FileList> filelists = new ArrayList<FileList>();
/**
* Add a set of files to touch
*/
public void addFileset(FileSet set) {
filesets.add(set);
}
/**
* Add a filelist to touch
*/
public void addFilelist(FileList list) {
filelists.add(list);
}
// The method executing the task
@Override
public void execute() throws BuildException {
this.log("Starting PlantUML");
try {
if (dir != null) {
processingSingleDirectory(new File(dir));
}
for (FileSet fileSet : filesets) {
manageFileSet(fileSet);
}
for (FileList fileList : filelists) {
manageFileList(fileList);
}
} catch (IOException e) {
e.printStackTrace();
throw new BuildException(e.toString());
} catch (InterruptedException e) {
e.printStackTrace();
throw new BuildException(e.toString());
}
}
private void manageFileList(FileList fl) throws IOException, InterruptedException {
final File fromDir = fl.getDir(getProject());
final String[] srcFiles = fl.getFiles(getProject());
for (String src : srcFiles) {
final File f = new File(fromDir, src);
processingSingleFile(f);
}
}
private void manageFileSet(FileSet fs) throws IOException, InterruptedException {
final DirectoryScanner ds = fs.getDirectoryScanner(getProject());
final File fromDir = fs.getDir(getProject());
final String[] srcFiles = ds.getIncludedFiles();
final String[] srcDirs = ds.getIncludedDirectories();
for (String src : srcFiles) {
final File f = new File(fromDir, src);
processingSingleFile(f);
}
for (String src : srcDirs) {
final File dir = new File(fromDir, src);
processingSingleDirectory(dir);
}
}
private void processingSingleFile(final File f) throws IOException, InterruptedException {
this.log("Processing " + f.getAbsolutePath());
final SourceFileReader sourceFileReader = new SourceFileReader(new Defines(), f, option.getOutputDir(), option
.getConfig(), option.getCharset(), option.getFileFormatOption());
final Collection<GeneratedImage> result = sourceFileReader.getGeneratedImages();
for (GeneratedImage g : result) {
this.log(g + " " + g.getDescription());
}
}
private void processingSingleDirectory(File f) throws IOException, InterruptedException {
if (f.exists() == false) {
final String s = "The file " + f.getAbsolutePath() + " does not exists.";
this.log(s);
throw new BuildException(s);
}
final DirWatcher dirWatcher = new DirWatcher(f, option, Option.getPattern());
final Collection<GeneratedImage> result = dirWatcher.buildCreatedFiles();
for (GeneratedImage g : result) {
this.log(g + " " + g.getDescription());
}
}
public void setDir(String s) {
this.dir = s;
}
public void setOutput(String s) {
option.setOutputDir(new File(s));
}
public void setCharset(String s) {
option.setCharset(s);
}
public void setConfig(String s) {
try {
option.initConfig(s);
} catch (IOException e) {
log("Error reading " + s);
}
}
public void setKeepTmpFiles(String s) {
if ("true".equalsIgnoreCase(s)) {
OptionFlags.getInstance().setKeepTmpFiles(true);
}
}
public void setVerbose(String s) {
if ("true".equalsIgnoreCase(s)) {
OptionFlags.getInstance().setVerbose(true);
}
}
public void setFormat(String s) {
if ("xmi".equalsIgnoreCase(s)) {
option.setFileFormat(FileFormat.XMI_STANDARD);
}
if ("xmi:argo".equalsIgnoreCase(s)) {
option.setFileFormat(FileFormat.XMI_ARGO);
}
if ("xmi:start".equalsIgnoreCase(s)) {
option.setFileFormat(FileFormat.XMI_STAR);
}
if ("eps".equalsIgnoreCase(s)) {
option.setFileFormat(FileFormat.EPS);
}
if ("svg".equalsIgnoreCase(s)) {
option.setFileFormat(FileFormat.SVG);
}
if ("txt".equalsIgnoreCase(s)) {
option.setFileFormat(FileFormat.ATXT);
}
if ("utxt".equalsIgnoreCase(s)) {
option.setFileFormat(FileFormat.UTXT);
}
}
public void setGraphvizDot(String s) {
OptionFlags.getInstance().setDotExecutable(s);
}
public void setForcegd(String s) {
if ("true".equalsIgnoreCase(s)) {
OptionFlags.getInstance().setForceGd(true);
}
}
public void setForcecairo(String s) {
if ("true".equalsIgnoreCase(s)) {
OptionFlags.getInstance().setForceCairo(true);
}
}
}

View File

@ -33,15 +33,15 @@
*/
package net.sourceforge.plantuml.asciiart;
import java.awt.Font;
import java.awt.geom.Dimension2D;
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.ugraphic.UFont;
public class TextStringBounder implements StringBounder {
public Dimension2D calculateDimension(Font font, String text) {
public Dimension2D calculateDimension(UFont font, String text) {
return new Dimension2DDouble(text.length(), 1);
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6451 $
* Revision $Revision: 6918 $
*
*/
package net.sourceforge.plantuml.classdiagram;
@ -36,6 +36,7 @@ package net.sourceforge.plantuml.classdiagram;
import net.sourceforge.plantuml.classdiagram.command.CommandAddMethod;
import net.sourceforge.plantuml.classdiagram.command.CommandCreateEntityClass2;
import net.sourceforge.plantuml.classdiagram.command.CommandCreateEntityClassMultilines2;
import net.sourceforge.plantuml.classdiagram.command.CommandDiamondAssociation;
import net.sourceforge.plantuml.classdiagram.command.CommandEndNamespace;
import net.sourceforge.plantuml.classdiagram.command.CommandHideShow;
import net.sourceforge.plantuml.classdiagram.command.CommandHideShow3;
@ -93,7 +94,9 @@ public class ClassDiagramFactory extends AbstractUmlSystemCommandFactory {
addCommand(new CommandMultilinesStandaloneNote(system));
// addCommand(new CommandCreateEntityClassMultilines(system));
addCommand(new CommandCreateEntityClassMultilines2(system));
addCommand(new CommandDiamondAssociation(system));
addCommand(new CommandHideShow3(system));
addCommand(new CommandHideShow(system));

View File

@ -27,36 +27,33 @@
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4826 $
*
* Revision $Revision: 5618 $
*
*/
package net.sourceforge.plantuml.eps;
package net.sourceforge.plantuml.classdiagram.command;
import java.io.File;
import java.util.List;
class InkscapeWindows extends AbstractInkscape {
import net.sourceforge.plantuml.classdiagram.ClassDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand;
import net.sourceforge.plantuml.cucadiagram.EntityType;
@Override
protected File specificExe() {
final File f1 = new File("C:\\Program Files\\Inkscape\\inkscape.exe");
if (f1.exists()) {
return f1;
}
public class CommandDiamondAssociation extends SingleLineCommand<ClassDiagram> {
final File f2 = new File("C:\\Program Files (x86)\\Inkscape\\inkscape.exe");
if (f2.exists()) {
return f2;
}
return null;
public CommandDiamondAssociation(ClassDiagram diagram) {
super(diagram, "(?i)^\\<\\>\\s*([\\p{L}0-9_.]+)$");
}
@Override
protected void appendFilePath(final StringBuilder sb, File file) {
sb.append('\"');
sb.append(file.getAbsolutePath());
sb.append('\"');
}
protected CommandExecutionResult executeArg(List<String> arg) {
final String code = arg.get(0);
if (getSystem().entityExist(code)) {
return CommandExecutionResult.error("Already existing : "+code);
}
getSystem().createEntity(code, null, EntityType.ASSOCIATION);
return CommandExecutionResult.ok();
}
}

View File

@ -74,9 +74,9 @@ final public class CommandLinkClass2 extends SingleLineCommand2<AbstractClassOrO
new RegexLeaf("\\s*"),
new RegexOr(
new RegexLeaf("LEFT_TO_RIGHT",
"(([-=.]+)(?:(left|right|up|down|le?|ri?|up?|do?)(?=[-=.]))?([-=.]*)(o +|[\\]>*+]|\\|[>\\]])?)"),
"(([-=.]+)(?:(left|right|up|down|le?|ri?|up?|do?)(?=[-=.]))?([-=.]*)(o +|[\\]>*+^]|\\|[>\\]])?)"),
new RegexLeaf("RIGHT_TO_LEFT",
"(( +o|[\\[<*+]|[<\\[]\\|)?([-=.]*)(left|right|up|down|le?|ri?|up?|do?)?([-=.]+))"),
"(( +o|[\\[<*+^]|[<\\[]\\|)?([-=.]*)(left|right|up|down|le?|ri?|up?|do?)?([-=.]+))"),
new RegexLeaf("NAV_AGREG_OR_COMPO_INV",
"(\\<([-=.]*)(left|right|up|down|le?|ri?|up?|do?[-=.]+)?([-=.]+)(o +|\\*))"),
new RegexLeaf("NAV_AGREG_OR_COMPO",
@ -428,6 +428,9 @@ final public class CommandLinkClass2 extends SingleLineCommand2<AbstractClassOrO
if (k.equals("<|") || k.equals("|>")) {
return new LinkType(LinkDecor.EXTENDS, LinkDecor.NONE);
}
if (k.equals("^")) {
return new LinkType(LinkDecor.EXTENDS, LinkDecor.NONE);
}
// return null;
throw new IllegalArgumentException(k);
}

View File

@ -1,242 +0,0 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* 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 Lesser 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.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5075 $
*
*/
package net.sourceforge.plantuml.classdiagram.command;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sourceforge.plantuml.UniqueSequence;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand;
import net.sourceforge.plantuml.cucadiagram.Entity;
import net.sourceforge.plantuml.cucadiagram.EntityType;
import net.sourceforge.plantuml.cucadiagram.Group;
import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.LinkDecor;
import net.sourceforge.plantuml.cucadiagram.LinkType;
import net.sourceforge.plantuml.objectdiagram.AbstractClassOrObjectDiagram;
final public class CommandLinkLollipop extends SingleLineCommand<AbstractClassOrObjectDiagram> {
private static final int OFFSET = 1;
private static final int FIRST_TYPE_AND_CLASS = 0 + OFFSET;
private static final int FIRST_TYPE = 1 + OFFSET;
private static final int FIRST_CLASS = 2 + OFFSET;
private static final int FIRST_LABEL = 3 + OFFSET;
private static final int LINK1 = 4 + OFFSET;
private static final int LINK2 = 5 + OFFSET;
private static final int SECOND_LABEL = 6 + OFFSET;
private static final int SECOND_TYPE_AND_CLASS = 7 + OFFSET;
private static final int SECOND_TYPE = 8 + OFFSET;
private static final int SECOND_CLASS = 9 + OFFSET;
private static final int LINK_LABEL = 10 + OFFSET;
private final Pattern patternAssociationPoint = Pattern
.compile("\\(\\s*(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s*,\\s*(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s*\\)");
private CommandLinkLollipop(AbstractClassOrObjectDiagram diagram) {
super(
diagram,
"(?i)^(?:@([\\d.])\\s+)?((?:(interface|enum|abstract\\s+class|abstract|class)\\s+)?(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)|\\(\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*,\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*\\))\\s*(?:\"([^\"]+)\")?\\s*"
// +
// "(?:(([-=.]+)([\\]>o*+]|\\|[>\\]])?)|(([\\[<o*+]|[<\\[]\\|)?([-=.]+))|(\\<([-=.]+)([o*]))|(([o*])([-=.]+)\\>))"
+ "(?:\\(\\)([-=.]+)|([-=.]+)\\(\\))"
+ "\\s*(?:\"([^\"]+)\")?\\s*((?:(interface|enum|abstract\\s+class|abstract|class)\\s+)?(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)|\\(\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*,\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*\\))\\s*(?::\\s*([^\"]+))?$");
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
if (arg.get(FIRST_TYPE_AND_CLASS).startsWith("(")) {
return executeArgSpecial1(arg);
}
if (arg.get(SECOND_TYPE_AND_CLASS).startsWith("(")) {
return executeArgSpecial2(arg);
}
if (getSystem().isGroup(arg.get(FIRST_CLASS)) && getSystem().isGroup(arg.get(SECOND_CLASS))) {
return executePackageLink(arg);
}
if (getSystem().isGroup(arg.get(FIRST_CLASS)) || getSystem().isGroup(arg.get(SECOND_CLASS))) {
return CommandExecutionResult.error("Package can be only linked to other package");
}
final Entity cl1;
final Entity cl2;
final Entity normalEntity;
final String suffix = "lol" + UniqueSequence.getValue();
if (arg.get(LINK1) != null) {
cl2 = (Entity) getSystem().getOrCreateClass(arg.get(SECOND_CLASS));
cl1 = getSystem().createEntity(cl2.getCode() + suffix, arg.get(FIRST_CLASS), EntityType.LOLLIPOP);
normalEntity = cl2;
} else {
assert arg.get(LINK2) != null;
cl1 = (Entity) getSystem().getOrCreateClass(arg.get(FIRST_CLASS));
cl2 = getSystem().createEntity(cl1.getCode() + suffix, arg.get(SECOND_CLASS), EntityType.LOLLIPOP);
normalEntity = cl1;
}
final LinkType linkType = getLinkType(arg);
final String queue = getQueue(arg);
int length = queue.length();
if (length == 1 && getSystem().getNbOfHozizontalLollipop(normalEntity) > 1) {
length++;
}
final Link link = new Link(cl1, cl2, linkType, arg.get(LINK_LABEL), length, arg.get(FIRST_LABEL), arg
.get(SECOND_LABEL), getSystem().getLabeldistance(), getSystem().getLabelangle());
getSystem().resetPragmaLabel();
addLink(link, arg.get(0));
return CommandExecutionResult.ok();
}
private String getQueue(List<String> arg) {
if (arg.get(LINK1) != null) {
return arg.get(LINK1);
}
if (arg.get(LINK2) != null) {
return arg.get(LINK2);
}
throw new IllegalArgumentException();
}
private LinkType getLinkType(List<String> arg) {
return new LinkType(LinkDecor.NONE, LinkDecor.NONE);
}
private void addLink(Link link, String arg0) {
getSystem().addLink(link);
if (arg0 == null) {
final LinkType type = link.getType();
// --|> highest
// --*, -->, --o normal
// ..*, ..>, ..o lowest
// if (type.isDashed() == false) {
// if (type.contains(LinkDecor.EXTENDS)) {
// link.setWeight(3);
// }
// if (type.contains(LinkDecor.ARROW) ||
// type.contains(LinkDecor.COMPOSITION)
// || type.contains(LinkDecor.AGREGATION)) {
// link.setWeight(2);
// }
// }
} else {
link.setWeight(Double.parseDouble(arg0));
}
}
private CommandExecutionResult executePackageLink(List<String> arg) {
final Group cl1 = getSystem().getGroup(arg.get(FIRST_CLASS));
final Group cl2 = getSystem().getGroup(arg.get(SECOND_CLASS));
final LinkType linkType = getLinkType(arg);
final String queue = getQueue(arg);
final Link link = new Link(cl1.getEntityCluster(), cl2.getEntityCluster(), linkType, arg.get(LINK_LABEL), queue
.length(), arg.get(FIRST_LABEL), arg.get(SECOND_LABEL), getSystem().getLabeldistance(), getSystem()
.getLabelangle());
getSystem().resetPragmaLabel();
addLink(link, arg.get(0));
return CommandExecutionResult.ok();
}
private CommandExecutionResult executeArgSpecial1(List<String> arg) {
final Matcher m = patternAssociationPoint.matcher(arg.get(FIRST_TYPE_AND_CLASS));
if (m.matches() == false) {
throw new IllegalStateException();
}
final String clName1 = m.group(1);
final String clName2 = m.group(2);
if (getSystem().entityExist(clName1) == false) {
return CommandExecutionResult.error("No class " + clName1);
}
if (getSystem().entityExist(clName2) == false) {
return CommandExecutionResult.error("No class " + clName2);
}
final IEntity entity1 = getSystem().getOrCreateClass(clName1);
final IEntity entity2 = getSystem().getOrCreateClass(clName2);
final Entity node = getSystem().createEntity(arg.get(FIRST_TYPE_AND_CLASS), "node",
EntityType.POINT_FOR_ASSOCIATION);
getSystem().insertBetween(entity1, entity2, node);
final IEntity cl2 = getSystem().getOrCreateClass(arg.get(SECOND_CLASS));
final LinkType linkType = getLinkType(arg);
final String queue = getQueue(arg);
final Link link = new Link(node, cl2, linkType, arg.get(LINK_LABEL), queue.length());
addLink(link, arg.get(0));
return CommandExecutionResult.ok();
}
private CommandExecutionResult executeArgSpecial2(List<String> arg) {
final Matcher m = patternAssociationPoint.matcher(arg.get(SECOND_TYPE_AND_CLASS));
if (m.matches() == false) {
throw new IllegalStateException();
}
final String clName1 = m.group(1);
final String clName2 = m.group(2);
if (getSystem().entityExist(clName1) == false) {
return CommandExecutionResult.error("No class " + clName1);
}
if (getSystem().entityExist(clName2) == false) {
return CommandExecutionResult.error("No class " + clName2);
}
final IEntity entity1 = getSystem().getOrCreateClass(clName1);
final IEntity entity2 = getSystem().getOrCreateClass(clName2);
final IEntity node = getSystem().createEntity(arg.get(SECOND_TYPE_AND_CLASS), "node",
EntityType.POINT_FOR_ASSOCIATION);
getSystem().insertBetween(entity1, entity2, node);
final IEntity cl1 = getSystem().getOrCreateClass(arg.get(FIRST_TYPE_AND_CLASS));
final LinkType linkType = getLinkType(arg);
final String queue = getQueue(arg);
final Link link = new Link(cl1, node, linkType, arg.get(LINK_LABEL), queue.length());
addLink(link, arg.get(0));
return CommandExecutionResult.ok();
}
}

View File

@ -96,7 +96,7 @@ public class CompressionZlib implements Compression {
final byte[] result = copyArray(tmp, resultLength);
return result;
} catch (DataFormatException e) {
e.printStackTrace();
// e.printStackTrace();
throw new IOException(e.toString());
}
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6486 $
* Revision $Revision: 6575 $
*
*/
package net.sourceforge.plantuml.command;
@ -45,6 +45,7 @@ import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.LinkDecor;
import net.sourceforge.plantuml.cucadiagram.LinkType;
import net.sourceforge.plantuml.graphic.HtmlColor;
import net.sourceforge.plantuml.sequencediagram.Note;
public abstract class AbstractCommandMultilinesNoteEntity extends CommandMultilines<AbstractEntityDiagram> {
@ -72,7 +73,7 @@ public abstract class AbstractCommandMultilinesNoteEntity extends CommandMultili
final String s = StringUtils.getMergedLines(strings);
final Entity note = getSystem().createEntity("GMN" + UniqueSequence.getValue(), s, EntityType.NOTE);
note.setSpecificBackcolor(line0.get(2));
note.setSpecificBackcolor(HtmlColor.getColorIfValid(line0.get(2)));
note.setUrl(url);
final Position position = Position.valueOf(pos.toUpperCase()).withRankdir(getSystem().getRankdir());

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6423 $
* Revision $Revision: 6750 $
*
*/
package net.sourceforge.plantuml.command;
@ -44,6 +44,7 @@ import net.sourceforge.plantuml.UmlDiagram;
public abstract class AbstractUmlSystemCommandFactory implements PSystemCommandFactory {
private final DiagramType type;
private List<Command> cmds;
protected AbstractUmlSystemCommandFactory() {
this(DiagramType.UML);
@ -51,14 +52,12 @@ public abstract class AbstractUmlSystemCommandFactory implements PSystemCommandF
protected AbstractUmlSystemCommandFactory(DiagramType type) {
this.type = type;
reset();
}
public String checkFinalError() {
return null;
}
private List<Command> cmds = new ArrayList<Command>();
final public CommandControl isValid(List<String> lines) {
for (Command cmd : cmds) {
@ -83,7 +82,7 @@ public abstract class AbstractUmlSystemCommandFactory implements PSystemCommandF
throw new IllegalArgumentException();
}
final public void reset() {
final public void init(String startLine) {
cmds = new ArrayList<Command>();
initCommands();
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4762 $
* Revision $Revision: 6575 $
*
*/
package net.sourceforge.plantuml.command;
@ -38,6 +38,7 @@ import java.util.List;
import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram;
import net.sourceforge.plantuml.cucadiagram.Entity;
import net.sourceforge.plantuml.cucadiagram.EntityType;
import net.sourceforge.plantuml.graphic.HtmlColor;
public class CommandCreateNote extends SingleLineCommand<AbstractEntityDiagram> {
@ -51,7 +52,7 @@ public class CommandCreateNote extends SingleLineCommand<AbstractEntityDiagram>
final String code = arg.get(1);
final Entity entity = getSystem().createEntity(code, display, EntityType.NOTE);
assert entity != null;
entity.setSpecificBackcolor(arg.get(2));
entity.setSpecificBackcolor(HtmlColor.getColorIfValid(arg.get(2)));
return CommandExecutionResult.ok();
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5751 $
* Revision $Revision: 6575 $
*
*/
package net.sourceforge.plantuml.command;
@ -38,6 +38,7 @@ import java.util.List;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram;
import net.sourceforge.plantuml.cucadiagram.EntityType;
import net.sourceforge.plantuml.graphic.HtmlColor;
public class CommandMultilinesStandaloneNote extends CommandMultilines<AbstractEntityDiagram> {
@ -54,7 +55,7 @@ public class CommandMultilinesStandaloneNote extends CommandMultilines<AbstractE
final EntityType type = EntityType.NOTE;
final String code = line0.get(1);
getSystem().createEntity(code, display, type).setSpecificBackcolor(line0.get(2));
getSystem().createEntity(code, display, type).setSpecificBackcolor(HtmlColor.getColorIfValid(line0.get(2)));
return CommandExecutionResult.ok();
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5752 $
* Revision $Revision: 6922 $
*
*/
package net.sourceforge.plantuml.command;
@ -47,7 +47,7 @@ public class CommandMultilinesTitle extends CommandMultilines<UmlDiagram> {
public CommandExecutionResult execute(List<String> lines) {
final List<String> strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1));
if (strings.size() > 0) {
getSystem().setTitle(strings);
getSystem().setTitle(StringUtils.manageEmbededDiagrams(strings));
return CommandExecutionResult.ok();
}
return CommandExecutionResult.error("No title defined");

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5616 $
* Revision $Revision: 6575 $
*
*/
package net.sourceforge.plantuml.command;
@ -43,6 +43,7 @@ import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.LinkDecor;
import net.sourceforge.plantuml.cucadiagram.LinkType;
import net.sourceforge.plantuml.graphic.HtmlColor;
final public class CommandNoteEntity extends SingleLineCommand<AbstractEntityDiagram> {
@ -58,7 +59,7 @@ final public class CommandNoteEntity extends SingleLineCommand<AbstractEntityDia
final String pos = arg.get(0);
final IEntity cl1 = getSystem().getOrCreateClass(arg.get(1));
final Entity note = getSystem().createEntity("GN" + UniqueSequence.getValue(), arg.get(3), EntityType.NOTE);
note.setSpecificBackcolor(arg.get(2));
note.setSpecificBackcolor(HtmlColor.getColorIfValid(arg.get(2)));
final Link link;
final Position position = Position.valueOf(pos.toUpperCase()).withRankdir(getSystem().getRankdir());

View File

@ -72,7 +72,7 @@ public class CommandCreateActorInComponent extends SingleLineCommand<ComponentDi
}
final String stereotype = arg.get(2);
final Entity entity = (Entity) getSystem().getOrCreateEntity(code, type);
entity.setDisplay(display);
entity.setDisplay2(display);
if (stereotype != null) {
entity.setStereotype(new Stereotype(stereotype, getSystem().getSkinParam().getCircledCharacterRadius(),

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5728 $
* Revision $Revision: 6923 $
*
*/
package net.sourceforge.plantuml.componentdiagram.command;
@ -75,7 +75,7 @@ public class CommandCreateCircleInterface extends SingleLineCommand<ComponentDia
final String stereotype = arg.get(2);
// final Entity entity = getSystem().createEntity(code, display, type);
final Entity entity = (Entity) getSystem().getOrCreateEntity(code, type);
entity.setDisplay(display);
entity.setDisplay2(display);
if (stereotype != null) {
entity.setStereotype(new Stereotype(stereotype, getSystem().getSkinParam().getCircledCharacterRadius(),
getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null)));

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5728 $
* Revision $Revision: 6923 $
*
*/
package net.sourceforge.plantuml.componentdiagram.command;
@ -75,7 +75,7 @@ public class CommandCreateComponent extends SingleLineCommand<ComponentDiagram>
final String stereotype = arg.get(2);
// final Entity entity = getSystem().createEntity(code, display, type);
final Entity entity = (Entity) getSystem().getOrCreateEntity(code, type);
entity.setDisplay(display);
entity.setDisplay2(display);
if (stereotype != null) {
entity.setStereotype(new Stereotype(stereotype, getSystem().getSkinParam().getCircledCharacterRadius(),
getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null)));

View File

@ -64,10 +64,9 @@ public class CommandLinkComponent2 extends SingleLineCommand2<ComponentDiagram>
new RegexOr(
//
new RegexLeaf("AR_TO_RIGHT",
"(([-=.]+)(?:(left|right|up|down|le?|ri?|up?|do?)(?=[-=.]))?([-=.]*)([\\]>]|\\|[>\\]])?)"),
// "(([-=.]+)(left|right|up|down|le?|ri?|up?|do?)?([-=.]*?\\.*)([\\]>]|\\|[>\\]])?)"),
"(([-=.]+)(?:(left|right|up|down|le?|ri?|up?|do?)(?=[-=.]))?([-=.]*)([\\]>^]|\\|[>\\]])?)"),
new RegexLeaf("AR_TO_LEFT",
"(([\\[<]|[<\\[]\\|)?([-=.]*)(left|right|up|down|le?|ri?|up?|do?)?([-=.]+))")),
"(([\\[<^]|[<\\[]\\|)?([-=.]*)(left|right|up|down|le?|ri?|up?|do?)?([-=.]+))")),
new RegexLeaf("\\s*"),//
getRegexGroup("G2"),//
new RegexLeaf("\\s*"),//
@ -179,6 +178,9 @@ public class CommandLinkComponent2 extends SingleLineCommand2<ComponentDiagram>
if (k.equals("<|") || k.equals("|>")) {
return new LinkType(LinkDecor.EXTENDS, LinkDecor.NONE);
}
if (k.equals("^")) {
return new LinkType(LinkDecor.EXTENDS, LinkDecor.NONE);
}
return null;
}

View File

@ -54,7 +54,7 @@ public class CommandCreateBlock extends SingleLineCommand<CompositeDiagram> {
display = code;
}
final Entity ent = (Entity) getSystem().getOrCreateClass(code);
ent.setDisplay(display);
ent.setDisplay2(display);
return CommandExecutionResult.ok();
}

View File

@ -28,16 +28,18 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6453 $
* Revision $Revision: 6892 $
*
*/
package net.sourceforge.plantuml.cucadiagram;
import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -55,14 +57,19 @@ import java.util.TreeMap;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.Log;
import net.sourceforge.plantuml.OptionFlags;
import net.sourceforge.plantuml.UmlDiagram;
import net.sourceforge.plantuml.UmlDiagramType;
import net.sourceforge.plantuml.cucadiagram.dot.CucaDiagramFileMaker;
import net.sourceforge.plantuml.cucadiagram.dot.CucaDiagramFileMakerBeta;
import net.sourceforge.plantuml.cucadiagram.dot.CucaDiagramPngMaker3;
import net.sourceforge.plantuml.cucadiagram.dot.CucaDiagramTxtMaker;
import net.sourceforge.plantuml.cucadiagram.dot.DrawFile;
import net.sourceforge.plantuml.cucadiagram.dot.ICucaDiagramFileMaker;
import net.sourceforge.plantuml.png.PngSplitter;
import net.sourceforge.plantuml.skin.VisibilityModifier;
import net.sourceforge.plantuml.svek.CucaDiagramFileMakerSvek;
import net.sourceforge.plantuml.ugraphic.ColorMapper;
import net.sourceforge.plantuml.xmi.CucaDiagramXmiMaker;
public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, PortionShower {
@ -70,7 +77,9 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy,
private int horizontalPages = 1;
private int verticalPages = 1;
private final Map<String, Entity> entities = new TreeMap<String, Entity>();
private final Map<String, Entity> entities = new LinkedHashMap<String, Entity>();
// private final Map<String, Entity> entities = new TreeMap<String,
// Entity>();
private final Map<IEntity, Integer> nbLinks = new HashMap<IEntity, Integer>();
private final List<Link> links = new ArrayList<Link>();
@ -149,6 +158,9 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy,
}
}
entities.put(proxy.getCode(), proxy);
// if (proxy.getImageFile() != null) {
// proxy.addSubImage(proxy.getImageFile());
// }
}
final public Collection<Group> getChildrenGroups(Group parent) {
@ -220,7 +232,10 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy,
}
final public Map<String, Entity> entities() {
return Collections.unmodifiableMap(entities);
if (OptionFlags.SVEK) {
return Collections.unmodifiableMap(entities);
}
return Collections.unmodifiableMap(new TreeMap<String, Entity>(entities));
}
final public void addLink(Link link) {
@ -275,6 +290,16 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy,
abstract protected List<String> getDotStrings();
final public String[] getDotStringSkek() {
final List<String> result = new ArrayList<String>();
for (String s : getDotStrings()) {
if (s.startsWith("nodesep") || s.startsWith("ranksep")) {
result.add(s);
}
}
return result.toArray(new String[result.size()]);
}
// final public List<File> createFiles(File suggestedFile, FileFormatOption
// fileFormatOption) throws IOException,
// InterruptedException {
@ -325,7 +350,7 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy,
final StringBuilder cmap = new StringBuilder();
OutputStream os = null;
try {
os = new FileOutputStream(suggestedFile);
os = new BufferedOutputStream(new FileOutputStream(suggestedFile));
this.exportDiagram(os, cmap, 0, fileFormat);
} finally {
if (os != null) {
@ -351,7 +376,11 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy,
FileFormatOption fileFormatOption, List<BufferedImage> flashcodes) throws IOException {
final FileFormat fileFormat = fileFormatOption.getFileFormat();
if (fileFormat == FileFormat.ATXT || fileFormat == FileFormat.UTXT) {
createFilesTxt(os, index, fileFormat);
try {
createFilesTxt(os, index, fileFormat);
} catch (Throwable t) {
t.printStackTrace(new PrintStream(os));
}
return;
}
@ -383,7 +412,12 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy,
}
return;
}
final CucaDiagramFileMaker maker = new CucaDiagramFileMaker(this, flashcodes);
final ICucaDiagramFileMaker maker;
if (OptionFlags.SVEK) {
maker = new CucaDiagramFileMakerSvek(this, flashcodes);
} else {
maker = new CucaDiagramFileMaker(this, flashcodes);
}
try {
final String cmapResult = maker.createFile(os, getDotStrings(), fileFormatOption);
if (cmapResult != null && cmap != null) {
@ -574,4 +608,45 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy,
public final Set<VisibilityModifier> getHides() {
return Collections.unmodifiableSet(hides);
}
public void clean() throws IOException {
for (Imaged entity : entities().values()) {
cleanTemporaryFiles(entity);
}
for (Imaged entity : getLinks()) {
cleanTemporaryFiles(entity);
}
for (Group g : groups.values()) {
final IEntity entity = g.getEntityCluster();
if (entity != null) {
cleanTemporaryFiles(entity);
}
}
for (DrawFile f : ensureDeletes) {
f.deleteDrawFile();
}
}
private void cleanTemporaryFiles(Imaged entity) {
if (entity.getImageFile() != null) {
entity.getImageFile().deleteDrawFile();
}
if (entity instanceof Entity) {
((Entity) entity).cleanSubImage();
}
}
private final Set<DrawFile> ensureDeletes = new HashSet<DrawFile>();
public void ensureDelete(DrawFile imageFile) {
if (imageFile == null) {
throw new IllegalArgumentException();
}
ensureDeletes.add(imageFile);
}
public ColorMapper getColorMapper() {
return getSkinParam().getColorMapper();
}
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6482 $
* Revision $Revision: 6923 $
*
*/
package net.sourceforge.plantuml.cucadiagram;
@ -36,20 +36,24 @@ package net.sourceforge.plantuml.cucadiagram;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.UniqueSequence;
import net.sourceforge.plantuml.Url;
import net.sourceforge.plantuml.cucadiagram.dot.DrawFile;
import net.sourceforge.plantuml.graphic.HtmlColor;
import net.sourceforge.plantuml.skin.VisibilityModifier;
import net.sourceforge.plantuml.svek.IEntityImage;
public class Entity implements IEntity {
private final String code;
private String display;
private List<? extends CharSequence> display2;
private final String uid;
private EntityType type;
@ -76,10 +80,15 @@ public class Entity implements IEntity {
}
public Entity(String code, String display, EntityType type, Group entityPackage, Set<VisibilityModifier> hides) {
this("cl" + UniqueSequence.getValue(), code, display, type, entityPackage, hides);
this("cl", UniqueSequence.getValue(), code, display, type, entityPackage, hides);
}
public Entity(String uid, String code, String display, EntityType type, Group entityPackage,
public Entity(String uid1, int uid2, String code, String display, EntityType type, Group entityPackage,
Set<VisibilityModifier> hides) {
this(uid1, uid2, code, StringUtils.getWithNewlines(display), type, entityPackage, hides);
}
public Entity(String uid1, int uid2, String code, List<? extends CharSequence> display, EntityType type, Group entityPackage,
Set<VisibilityModifier> hides) {
if (code == null || code.length() == 0) {
throw new IllegalArgumentException();
@ -88,10 +97,10 @@ public class Entity implements IEntity {
throw new IllegalArgumentException();
}
this.hides = hides;
this.uid = uid;
this.uid = StringUtils.getUid(uid1, uid2);
this.type = type;
this.code = code;
this.display = display;
this.display2 = display;
this.container = entityPackage;
if (entityPackage != null && type != EntityType.GROUP) {
entityPackage.addEntity(this);
@ -175,12 +184,16 @@ public class Entity implements IEntity {
return code;
}
public String getDisplay() {
return display;
public List<? extends CharSequence> getDisplay2() {
return display2;
}
public void setDisplay(String display) {
this.display = display;
public void setDisplay2(String display) {
this.display2 = StringUtils.getWithNewlines(display);
}
public void setDisplay2(List<? extends CharSequence> display) {
this.display2 = display;
}
public String getUid() {
@ -202,9 +215,9 @@ public class Entity implements IEntity {
@Override
public String toString() {
if (type == EntityType.GROUP) {
return display + "(" + getType() + ")" + this.container;
return display2 + "(" + getType() + ")" + this.container;
}
return display + "(" + getType() + ")";
return display2 + "(" + getType() + ") " + xposition + " " + getUid();
}
public void muteToCluster(Group newGroup) {
@ -234,8 +247,8 @@ public class Entity implements IEntity {
return specificBackcolor;
}
public void setSpecificBackcolor(String s) {
this.specificBackcolor = HtmlColor.getColorIfValid(s);
public void setSpecificBackcolor(HtmlColor color) {
this.specificBackcolor = color;
}
public final Url getUrl() {
@ -260,7 +273,7 @@ public class Entity implements IEntity {
return uid.equals(other.getUid());
}
private final List<DrawFile> subImages = new ArrayList<DrawFile>();
private final Set<DrawFile> subImages = new HashSet<DrawFile>();
public void addSubImage(DrawFile subImage) {
if (subImage == null) {
@ -269,6 +282,10 @@ public class Entity implements IEntity {
subImages.add(subImage);
}
public void addSubImage(Entity other) {
subImages.addAll(other.subImages);
}
public DrawFile getImageFile(File searched) throws IOException {
if (imageFile != null && imageFile.getPng().getCanonicalFile().equals(searched)) {
return imageFile;
@ -281,6 +298,12 @@ public class Entity implements IEntity {
return null;
}
public void cleanSubImage() {
for (DrawFile f : subImages) {
f.deleteDrawFile();
}
}
private boolean nearDecoration = false;
public final boolean hasNearDecoration() {
@ -291,4 +314,28 @@ public class Entity implements IEntity {
this.nearDecoration = nearDecoration;
}
public int compareTo(IEntity other) {
return getUid().compareTo(other.getUid());
}
private int xposition;
public int getXposition() {
return xposition;
}
public void setXposition(int pos) {
xposition = pos;
}
private IEntityImage svekImage;
public final IEntityImage getSvekImage() {
return svekImage;
}
public final void setSvekImage(IEntityImage svekImage) {
this.svekImage = svekImage;
}
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5190 $
* Revision $Revision: 6924 $
*
*/
package net.sourceforge.plantuml.cucadiagram;
@ -37,11 +37,11 @@ public enum EntityType {
EMPTY_PACKAGE,
ABSTRACT_CLASS, CLASS, INTERFACE, LOLLIPOP, ENUM, ACTOR, USECASE, COMPONENT, CIRCLE_INTERFACE, NOTE, OBJECT,
ABSTRACT_CLASS, CLASS, INTERFACE, LOLLIPOP, ENUM, ACTOR, USECASE, COMPONENT, CIRCLE_INTERFACE, NOTE, OBJECT, ASSOCIATION,
ACTIVITY, BRANCH, SYNCHRO_BAR, CIRCLE_START, CIRCLE_END, POINT_FOR_ASSOCIATION, ACTIVITY_CONCURRENT,
STATE, STATE_CONCURRENT,
STATE, STATE_CONCURRENT, PSEUDO_STATE,
BLOCK,

View File

@ -40,6 +40,7 @@ import java.util.List;
import net.sourceforge.plantuml.Url;
import net.sourceforge.plantuml.cucadiagram.dot.DrawFile;
import net.sourceforge.plantuml.graphic.HtmlColor;
import net.sourceforge.plantuml.svek.IEntityImage;
public abstract class EntityUtils {
@ -52,8 +53,8 @@ public abstract class EntityUtils {
return ent.getFieldsToDisplay();
}
public String getDisplay() {
return ent.getDisplay();
public List<? extends CharSequence> getDisplay2() {
return ent.getDisplay2();
}
public Group getParent() {
@ -92,7 +93,7 @@ public abstract class EntityUtils {
return ent.getSpecificBackColor();
}
public void setSpecificBackcolor(String specificBackcolor) {
public void setSpecificBackcolor(HtmlColor specificBackcolor) {
throw new UnsupportedOperationException();
}
@ -135,6 +136,22 @@ public abstract class EntityUtils {
ent.setNearDecoration(nearDecoration);
}
public int compareTo(IEntity other) {
return ent.compareTo(other);
}
public int getXposition() {
return ent.getXposition();
}
public void setXposition(int pos) {
ent.setXposition(pos);
}
public IEntityImage getSvekImage() {
return ent.getSvekImage();
}
};
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5743 $
* Revision $Revision: 6709 $
*
*/
package net.sourceforge.plantuml.cucadiagram;
@ -39,6 +39,7 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.UniqueSequence;
import net.sourceforge.plantuml.graphic.HtmlColor;
@ -163,7 +164,15 @@ public class Group {
}
public String getUid() {
return "cluster" + cpt;
return StringUtils.getUid(getUid1(), getUid2());
}
public String getUid1() {
return "cluster";
}
public int getUid2() {
return cpt;
}
public final HtmlColor getBackColor() {
@ -259,7 +268,7 @@ public class Group {
public final void setRankdir(Rankdir rankdir) {
this.rankdir = rankdir;
}
private String stereotype;
public final void setStereotype(String stereotype) {

View File

@ -40,37 +40,44 @@ import java.util.List;
import net.sourceforge.plantuml.SpecificBackcolorable;
import net.sourceforge.plantuml.Url;
import net.sourceforge.plantuml.cucadiagram.dot.DrawFile;
import net.sourceforge.plantuml.svek.IEntityImage;
public interface IEntity extends Imaged, SpecificBackcolorable {
public interface IEntity extends Imaged, SpecificBackcolorable, Comparable<IEntity> {
public Group getParent();
public String getDisplay();
public List<? extends CharSequence> getDisplay2();
public EntityType getType();
public String getUid();
public Url getUrl();
public List<Member> getFieldsToDisplay();
public Stereotype getStereotype();
public void setStereotype(Stereotype stereotype);
public List<Member> getMethodsToDisplay();
public String getCode();
public DrawFile getImageFile(File searched) throws IOException;
public boolean isTop();
public void setTop(boolean top);
public boolean hasNearDecoration();
public void setNearDecoration(boolean nearDecoration);
public int getXposition();
public void setXposition(int pos);
public IEntityImage getSvekImage();
}

View File

@ -28,17 +28,18 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6356 $
* Revision $Revision: 6939 $
*
*/
package net.sourceforge.plantuml.cucadiagram;
import java.awt.Color;
import java.awt.Font;
import java.awt.geom.Dimension2D;
import java.util.Arrays;
import java.util.List;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.UniqueSequence;
import net.sourceforge.plantuml.command.Position;
import net.sourceforge.plantuml.cucadiagram.dot.DrawFile;
import net.sourceforge.plantuml.graphic.FontConfiguration;
import net.sourceforge.plantuml.graphic.HorizontalAlignement;
@ -46,6 +47,7 @@ import net.sourceforge.plantuml.graphic.HtmlColor;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.graphic.TextBlockUtils;
import net.sourceforge.plantuml.ugraphic.UFont;
public class Link implements Imaged {
@ -60,7 +62,10 @@ public class Link implements Imaged {
final private String uid = "LNK" + UniqueSequence.getValue();
private DrawFile imageFile;
private String note;
private List<? extends CharSequence> note;
private Position notePosition;
private boolean invis = false;
private double weight = 1.0;
@ -69,6 +74,11 @@ public class Link implements Imaged {
private HtmlColor specificColor;
private boolean constraint = true;
private boolean inverted = false;
public final boolean isInverted() {
return inverted;
}
public Link(IEntity cl1, IEntity cl2, LinkType type, String label, int length) {
this(cl1, cl2, type, label, length, null, null, null, null, null);
@ -106,8 +116,14 @@ public class Link implements Imaged {
}
public Link getInv() {
return new Link(cl2, cl1, type.getInv(), label, length, qualifier2, qualifier1, labeldistance, labelangle,
specificColor);
// if (getLength() == 1) {
// final int x = cl1.getXposition();
// cl2.setXposition(x-1);
// }
final Link result = new Link(cl2, cl1, type.getInv(), label, length, qualifier2, qualifier1, labeldistance,
labelangle, specificColor);
result.inverted = true;
return result;
}
public Link getDashed() {
@ -222,12 +238,22 @@ public class Link implements Imaged {
this.weight = weight;
}
public final String getNote() {
public final List<? extends CharSequence> getNote() {
return note;
}
public final void setNote(String note) {
public final Position getNotePosition() {
return notePosition;
}
public final void addNote(List<? extends CharSequence> note, Position position) {
this.note = note;
this.notePosition = position;
}
public final void addNote(String n, Position position) {
this.note = StringUtils.getWithNewlines(n);
this.notePosition = position;
}
public DrawFile getImageFile() {
@ -291,22 +317,22 @@ public class Link implements Imaged {
return false;
}
public double getMarginDecors1(StringBounder stringBounder, Font fontQualif) {
public double getMarginDecors1(StringBounder stringBounder, UFont fontQualif) {
final double q = getQualifierMargin(stringBounder, fontQualif, qualifier1);
final LinkDecor decor = type.getDecor1();
return decor.getSize() + q;
}
public double getMarginDecors2(StringBounder stringBounder, Font fontQualif) {
public double getMarginDecors2(StringBounder stringBounder, UFont fontQualif) {
final double q = getQualifierMargin(stringBounder, fontQualif, qualifier2);
final LinkDecor decor = type.getDecor2();
return decor.getSize() + q;
}
private double getQualifierMargin(StringBounder stringBounder, Font fontQualif, String qualif) {
private double getQualifierMargin(StringBounder stringBounder, UFont fontQualif, String qualif) {
if (qualif != null) {
final TextBlock b = TextBlockUtils.create(Arrays.asList(qualif), new FontConfiguration(fontQualif,
Color.BLACK), HorizontalAlignement.LEFT);
HtmlColor.BLACK), HorizontalAlignement.LEFT);
final Dimension2D dim = b.calculateDimension(stringBounder);
return Math.max(dim.getWidth(), dim.getHeight());
}
@ -328,5 +354,4 @@ public class Link implements Imaged {
public final void setConstraint(boolean constraint) {
this.constraint = constraint;
}
}

View File

@ -35,12 +35,14 @@ package net.sourceforge.plantuml.cucadiagram;
public enum LinkDecor {
NONE(2), EXTENDS(30), COMPOSITION(15), AGREGATION(15), ARROW(10), PLUS(0), SQUARRE(30);
NONE(2, false), EXTENDS(30, false), COMPOSITION(15, true), AGREGATION(15, false), ARROW(10, true), PLUS(0, false), SQUARRE(30, false);
private final int size;
private final boolean fill;
private LinkDecor(int size) {
private LinkDecor(int size, boolean fill) {
this.size = size;
this.fill = fill;
}
public String getArrowDot() {
@ -64,5 +66,9 @@ public enum LinkDecor {
public int getSize() {
return size;
}
public boolean isFill() {
return fill;
}
}

View File

@ -33,6 +33,8 @@
*/
package net.sourceforge.plantuml.cucadiagram;
import net.sourceforge.plantuml.ugraphic.UStroke;
public class LinkType {
private final LinkDecor decor1;
@ -177,4 +179,16 @@ public class LinkType {
return new LinkType(LinkDecor.NONE, style, decor2);
}
public UStroke getStroke() {
if (style == LinkStyle.DASHED) {
return new UStroke(7, 7, 1);
}
if (style == LinkStyle.DOTTED) {
return new UStroke(1, 3, 1);
}
if (style == LinkStyle.BOLD) {
return new UStroke(2);
}
return new UStroke();
}
}

View File

@ -28,18 +28,20 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5982 $
* Revision $Revision: 6934 $
*
*/
package net.sourceforge.plantuml.cucadiagram;
import java.awt.Color;
import java.awt.Font;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.graphic.HtmlColor;
import net.sourceforge.plantuml.ugraphic.UFont;
public class Stereotype implements CharSequence {
@ -50,9 +52,9 @@ public class Stereotype implements CharSequence {
private final HtmlColor htmlColor;
private final char character;
private final double radius;
private final Font circledFont;
private final UFont circledFont;
public Stereotype(String label, double radius, Font circledFont) {
public Stereotype(String label, double radius, UFont circledFont) {
if (label == null) {
throw new IllegalArgumentException();
}
@ -86,11 +88,8 @@ public class Stereotype implements CharSequence {
this.circledFont = null;
}
public Color getColor() {
if (htmlColor == null) {
return null;
}
return htmlColor.getColor();
public HtmlColor getHtmlColor() {
return htmlColor;
}
public char getCharacter() {
@ -133,8 +132,21 @@ public class Stereotype implements CharSequence {
return radius;
}
public final Font getCircledFont() {
public final UFont getCircledFont() {
return circledFont;
}
public List<String> getLabels() {
if (label==null) {
return null;
}
final List<String> result = new ArrayList<String>();
final Pattern p = Pattern.compile("\\<\\<.*?\\>\\>");
final Matcher m = p.matcher(label);
while (m.find()) {
result.add(m.group());
}
return Collections.unmodifiableList(result);
}
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6104 $
* Revision $Revision: 6711 $
*
*/
package net.sourceforge.plantuml.cucadiagram.dot;
@ -37,6 +37,7 @@ import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.sourceforge.plantuml.FileFormat;
@ -80,7 +81,7 @@ abstract class AbstractGraphviz implements Graphviz {
abstract protected File specificDotExe();
final public void createPng(OutputStream os) throws IOException, InterruptedException {
final public void createFile(OutputStream os) throws IOException, InterruptedException {
if (dotString == null) {
throw new IllegalArgumentException();
}
@ -97,6 +98,8 @@ abstract class AbstractGraphviz implements Graphviz {
p = new ProcessRunner(cmd);
p.run(dotString.getBytes(), os);
Log.info("Ending process ok");
} catch (InterruptedException e) {
Log.error("Interrupted");
} catch (Throwable e) {
e.printStackTrace();
Log.error("Error: " + e);
@ -131,6 +134,11 @@ abstract class AbstractGraphviz implements Graphviz {
return executeCmd(cmd);
}
public String testFile(String dotfilename, String outfile) throws IOException, InterruptedException {
final String cmd = getCommandLine() + "-o" + outfile + " " + dotfilename;
return executeCmd(cmd);
}
private String executeCmd(final String cmd) throws IOException, InterruptedException {
final ProcessRunner p = new ProcessRunner(cmd);
p.run(null, null);
@ -188,4 +196,12 @@ abstract class AbstractGraphviz implements Graphviz {
}
}
public final String getDotString() {
return dotString;
}
public final List<String> getType() {
return Arrays.asList(type);
}
}

View File

@ -62,10 +62,11 @@ class AbstractGraphviz2 implements Graphviz {
this.strategy = strategy;
this.dotString = dotString;
this.type = type;
throw new UnsupportedOperationException("not used yet");
}
final public void createPng(OutputStream os) throws IOException, InterruptedException {
final public void createFile(OutputStream os) throws IOException, InterruptedException {
if (dotString == null) {
throw new IllegalArgumentException();
}
@ -181,4 +182,9 @@ class AbstractGraphviz2 implements Graphviz {
}
}
public String testFile(String filename, String outfile) throws IOException, InterruptedException {
throw new UnsupportedOperationException();
}
}

View File

@ -37,7 +37,8 @@ package net.sourceforge.plantuml.cucadiagram.dot;
enum BorderMode {
NO_BORDER,
NO_BORDER_CELLSPACING,
NO_BORDER_CELLSPACING_OLD,
NO_BORDER_CELLSPACING_NEW,
BORDER_1_WITH_COLOR,
BORDER_1_WITHOUT_COLOR;

View File

@ -28,21 +28,18 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6474 $
* Revision $Revision: 6939 $
*
*/
package net.sourceforge.plantuml.cucadiagram.dot;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.geom.Dimension2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
@ -59,7 +56,6 @@ import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import net.sourceforge.plantuml.ColorParam;
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.EmptyImageBuilder;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
@ -76,14 +72,13 @@ import net.sourceforge.plantuml.UniqueSequence;
import net.sourceforge.plantuml.cucadiagram.CucaDiagram;
import net.sourceforge.plantuml.cucadiagram.Entity;
import net.sourceforge.plantuml.cucadiagram.EntityType;
import net.sourceforge.plantuml.cucadiagram.Group;
import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.Imaged;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.Stereotype;
import net.sourceforge.plantuml.eps.EpsGraphics;
import net.sourceforge.plantuml.eps.EpsStrategy;
import net.sourceforge.plantuml.eps.EpsTitler;
import net.sourceforge.plantuml.eps.SvgToEpsConverter;
import net.sourceforge.plantuml.graphic.CircledCharacter;
import net.sourceforge.plantuml.graphic.GraphicStrings;
import net.sourceforge.plantuml.graphic.HorizontalAlignement;
@ -104,12 +99,14 @@ import net.sourceforge.plantuml.skin.SimpleContext2D;
import net.sourceforge.plantuml.skin.StickMan;
import net.sourceforge.plantuml.skin.rose.Rose;
import net.sourceforge.plantuml.statediagram.StateDiagram;
import net.sourceforge.plantuml.svg.SvgData;
import net.sourceforge.plantuml.svg.SvgTitler;
import net.sourceforge.plantuml.ugraphic.UFont;
import net.sourceforge.plantuml.ugraphic.eps.UGraphicEps;
import net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d;
import net.sourceforge.plantuml.ugraphic.svg.UGraphicSvg;
public final class CucaDiagramFileMaker {
public final class CucaDiagramFileMaker implements ICucaDiagramFileMaker {
private final CucaDiagram diagram;
private final List<BufferedImage> flashcodes;
@ -124,7 +121,7 @@ public final class CucaDiagramFileMaker {
}
public CucaDiagramFileMaker(CucaDiagram diagram, List<BufferedImage> flashcodes) throws IOException {
HtmlColor.setForceMonochrome(diagram.getSkinParam().isMonochrome());
// HtmlColor.setForceMonochrome(diagram.getSkinParam().isMonochrome());
this.diagram = diagram;
this.flashcodes = flashcodes;
if (diagram.getUmlDiagramType() == UmlDiagramType.CLASS || diagram.getUmlDiagramType() == UmlDiagramType.OBJECT) {
@ -156,8 +153,8 @@ public final class CucaDiagramFileMaker {
return createPng(os, dotStrings, fileFormatOption);
} else if (fileFormat == FileFormat.SVG) {
return createSvg(os, dotStrings, fileFormatOption);
} else if (fileFormat == FileFormat.EPS_VIA_SVG) {
return createEpsViaSvg(os, dotStrings, fileFormatOption);
} else if (fileFormat == FileFormat.EPS_TEXT) {
return createEps(os, dotStrings, fileFormatOption);
} else if (fileFormat == FileFormat.EPS) {
return createEps(os, dotStrings, fileFormatOption);
} else if (fileFormat == FileFormat.DOT) {
@ -168,17 +165,6 @@ public final class CucaDiagramFileMaker {
}
private String createEpsViaSvg(OutputStream os, List<String> dotStrings, FileFormatOption fileFormatOption)
throws IOException, InterruptedException {
final File svgTmp = FileUtils.createTempFile("svgtmp", ".svg");
final FileOutputStream svgOs = new FileOutputStream(svgTmp);
final String status = createSvg(svgOs, dotStrings, fileFormatOption);
svgOs.close();
final SvgToEpsConverter converter = new SvgToEpsConverter(svgTmp);
converter.createEps(os);
return status;
}
private double deltaY;
private String createSvg(OutputStream os, List<String> dotStrings, FileFormatOption fileFormatOption)
@ -187,27 +173,41 @@ public final class CucaDiagramFileMaker {
final StringBuilder cmap = new StringBuilder();
try {
deltaY = 0;
String svg = getSvgData(dotStrings, fileFormatOption, cmap);
String svg4 = getSvgData(dotStrings, fileFormatOption, cmap);
final Dimension2D dim = getDimensionSvg(svg);
if (dim != null) {
SvgData svgData = SvgData.fromGraphViz(svg4);
double supH = getTitleSvgHeight();
supH += getHeaderSvgHeight();
supH += getFooterSvgHeight();
if (svgData != null) {
svg = removeSvgXmlHeader(svg, dim.getWidth(), dim.getHeight() + supH);
final SvgTitler title = getTitleSvgTitler();
final SvgTitler header = getHeaderSvgTitler();
final SvgTitler footer = getFooterSvgTitler();
svg = addTitleSvg(svg, dim.getWidth(), dim.getHeight());
svg = addHeaderSvg(svg, dim.getWidth(), dim.getHeight());
svg = addFooterSvg(svg, dim.getWidth(), dim.getHeight());
svgData = title.addTitle(svgData);
svgData = header.addTitle(svgData);
svgData = footer.addTitle(svgData);
// double supH = getTitleSvgHeight(svg);
// supH += getHeaderSvgHeight(svg);
// supH += getFooterSvgHeight(svg);
//
// svg = removeSvgXmlHeader1(svg);
//
// svg = addTitleSvg(svg, dim.getWidth(), dim.getHeight());
// svg = addHeaderSvg(svg, dim.getWidth(), dim.getHeight());
// svg = addFooterSvg(svg, dim.getWidth(), dim.getHeight());
//
// svg = modifySvgXmlHeader(svg, dim.getWidth(), dim.getHeight()
// + supH, -50, 0);
// Image management
final Pattern pImage = Pattern.compile("(?i)<image\\W[^>]*>");
svg4 = svgData.getSvg();
boolean changed;
do {
changed = false;
final Matcher mImage = pImage.matcher(svg);
final Matcher mImage = pImage.matcher(svg4);
final StringBuffer sb = new StringBuffer();
while (mImage.find()) {
final String image = mImage.group(0);
@ -232,11 +232,11 @@ public final class CucaDiagramFileMaker {
}
}
mImage.appendTail(sb);
svg = sb.toString();
svg4 = sb.toString();
} while (changed);
}
os.write(svg.getBytes("UTF-8"));
os.write(svg4.getBytes("UTF-8"));
// final ByteArrayInputStream bais = new
// ByteArrayInputStream(baos.toByteArray());
@ -260,8 +260,7 @@ public final class CucaDiagramFileMaker {
//
// PngIO.write(im, os, diagram.getMetadata());
} finally {
// cleanTemporaryFiles(diagram.entities().values());
// cleanTemporaryFiles(diagram.getLinks());
clean();
}
if (cmap.length() > 0) {
return translateXY(cmap.toString(), 0, (int) Math.round(deltaY));
@ -319,53 +318,13 @@ public final class CucaDiagramFileMaker {
final Graphviz graphviz = GraphvizUtils.create(dotString, "svg");
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
graphviz.createPng(baos);
graphviz.createFile(baos);
baos.close();
dotMaker.clean();
return new String(baos.toByteArray(), "UTF-8").replace('\\', '/');
}
private static String removeSvgXmlHeader(String svg, double width, double height) {
final String newString = "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" style=\"width:"
+ Math.round(width) + ";height:" + Math.round(height) + ";\">";
svg = svg.replaceFirst("(?i)<svg[^>]*>", newString);
return svg;
}
private Dimension2D getDimensionSvg(String svg) {
final Pattern p = Pattern.compile("(?i)<polygon\\s+[^>]*points=\"([^\"]+)\"");
final Matcher m = p.matcher(svg);
if (m.find() == false) {
return null;
}
final String points = m.group(1);
final StringTokenizer st = new StringTokenizer(points, " ");
double minX = Double.MAX_VALUE;
double minY = Double.MAX_VALUE;
double maxX = -Double.MAX_VALUE;
double maxY = -Double.MAX_VALUE;
while (st.hasMoreTokens()) {
final String token = st.nextToken();
final StringTokenizer st2 = new StringTokenizer(token, ",");
final double x = Double.parseDouble(st2.nextToken().trim());
final double y = Double.parseDouble(st2.nextToken().trim());
if (x < minX) {
minX = x;
}
if (y < minY) {
minY = y;
}
if (x > maxX) {
maxX = x;
}
if (y > maxY) {
maxY = y;
}
}
return new Dimension2DDouble(maxX - minX, maxY - minY);
}
private DrawFile searchImageFile(File searched, Collection<? extends IEntity> entities) throws IOException {
for (IEntity ent : entities) {
final DrawFile df = ent.getImageFile(searched);
@ -409,7 +368,11 @@ public final class CucaDiagramFileMaker {
final double v1 = heightSvg / heightPng;
final double v2 = widthSvg / widthPng;
final double min = Math.min(v1, v2);
return "scale(" + min + " " + min + ")";
return "scale(" + format(min) + " " + format(min) + ")";
}
private static String format(double x) {
return EpsGraphics.format(x);
}
private static String getValue(String s, String param) {
@ -467,7 +430,7 @@ public final class CucaDiagramFileMaker {
new UnderlineTrick(im, new Color(Integer.parseInt("FEFECF", 16)), Color.BLACK).process();
}
final Color background = diagram.getSkinParam().getBackgroundColor().getColor();
final HtmlColor background = diagram.getSkinParam().getBackgroundColor();
supY = getTitlePngHeight(stringBounder);
supY += getHeaderPngHeight(stringBounder);
@ -484,12 +447,11 @@ public final class CucaDiagramFileMaker {
}
im = PngSizer.process(im, diagram.getMinwidth());
im = addFlashcode(im, background);
im = addFlashcode(im, diagram.getColorMapper().getMappedColor(background));
PngIO.write(im, os, diagram.getMetadata(), diagram.getDpi(fileFormatOption));
} finally {
cleanTemporaryFiles(diagram.entities().values());
cleanTemporaryFiles(diagram.getLinks());
clean();
}
if (cmap.length() > 0) {
@ -525,7 +487,7 @@ public final class CucaDiagramFileMaker {
final Graphviz graphviz = GraphvizUtils.create(dotString, "cmapx", getPngType());
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
graphviz.createPng(baos);
graphviz.createFile(baos);
baos.close();
final byte[] allData = baos.toByteArray();
@ -569,15 +531,12 @@ public final class CucaDiagramFileMaker {
final Graphviz graphviz = GraphvizUtils.create(dotString, getPngType());
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
graphviz.createPng(baos);
graphviz.createFile(baos);
baos.close();
final byte[] imageData = baos.toByteArray();
// final byte[] imageData = new byte[0];
Log.info("Reading " + imageData.length + " bytes from dot");
// File f = new File("dummy.png");
// FileOutputStream fos = new FileOutputStream(f);
// fos.write(imageData);
// fos.close();
return imageData;
}
@ -602,161 +561,131 @@ public final class CucaDiagramFileMaker {
errorResult.writeImage(os, fileFormat);
}
private BufferedImage addTitle(BufferedImage im, final Color background) {
final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.TITLE, null).getColor();
final String fontFamily = getSkinParam().getFontFamily(FontParam.TITLE, null);
final int fontSize = getSkinParam().getFontSize(FontParam.TITLE, null);
final PngTitler pngTitler = new PngTitler(titleColor, diagram.getTitle(), fontSize, fontFamily,
HorizontalAlignement.CENTER, VerticalPosition.TOP);
private BufferedImage addTitle(BufferedImage im, final HtmlColor background) {
final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.TITLE, null);
final UFont font = getSkinParam().getFont(FontParam.TITLE, null);
final String fontFamily = font.getFamily(null);
final int fontSize = font.getSize();
final PngTitler pngTitler = new PngTitler(diagram.getColorMapper(), titleColor, diagram.getTitle(), fontSize,
fontFamily, HorizontalAlignement.CENTER, VerticalPosition.TOP);
return pngTitler.processImage(im, background, 3);
}
private double getTitlePngHeight(StringBounder stringBounder) throws IOException {
final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.TITLE, null).getColor();
final String fontFamily = getSkinParam().getFontFamily(FontParam.TITLE, null);
final int fontSize = getSkinParam().getFontSize(FontParam.TITLE, null);
final PngTitler pngTitler = new PngTitler(titleColor, diagram.getTitle(), fontSize, fontFamily,
HorizontalAlignement.CENTER, VerticalPosition.TOP);
final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.TITLE, null);
final UFont font = getSkinParam().getFont(FontParam.TITLE, null);
final String fontFamily = font.getFamily(null);
final int fontSize = font.getSize();
final PngTitler pngTitler = new PngTitler(diagram.getColorMapper(), titleColor, diagram.getTitle(), fontSize,
fontFamily, HorizontalAlignement.CENTER, VerticalPosition.TOP);
return pngTitler.getOffsetY(stringBounder);
}
private double getOffsetX(StringBounder stringBounder, double imWidth) throws IOException {
final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.TITLE, null).getColor();
final String fontFamily = getSkinParam().getFontFamily(FontParam.TITLE, null);
final int fontSize = getSkinParam().getFontSize(FontParam.TITLE, null);
final PngTitler pngTitler = new PngTitler(titleColor, diagram.getTitle(), fontSize, fontFamily,
HorizontalAlignement.CENTER, VerticalPosition.TOP);
final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.TITLE, null);
final UFont font = getSkinParam().getFont(FontParam.TITLE, null);
final String fontFamily = font.getFamily(null);
final int fontSize = font.getSize();
final PngTitler pngTitler = new PngTitler(diagram.getColorMapper(), titleColor, diagram.getTitle(), fontSize,
fontFamily, HorizontalAlignement.CENTER, VerticalPosition.TOP);
return pngTitler.getOffsetX(imWidth, stringBounder);
}
private String addTitleSvg(String svg, double width, double height) throws IOException {
final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.TITLE, null).getColor();
final String fontFamily = getSkinParam().getFontFamily(FontParam.TITLE, null);
final int fontSize = getSkinParam().getFontSize(FontParam.TITLE, null);
private SvgTitler getTitleSvgTitler() throws IOException {
final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.TITLE, null);
final UFont font = getSkinParam().getFont(FontParam.TITLE, null);
final String fontFamily = font.getFamily(null);
final int fontSize = font.getSize();
final SvgTitler svgTitler = new SvgTitler(titleColor, diagram.getTitle(), fontSize, fontFamily,
return new SvgTitler(diagram.getColorMapper(), titleColor, diagram.getTitle(), fontSize, fontFamily,
HorizontalAlignement.CENTER, VerticalPosition.TOP, 3);
this.deltaY += svgTitler.getHeight();
return svgTitler.addTitleSvg(svg, width, height);
}
private double getTitleSvgHeight() throws IOException {
final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.TITLE, null).getColor();
final String fontFamily = getSkinParam().getFontFamily(FontParam.TITLE, null);
final int fontSize = getSkinParam().getFontSize(FontParam.TITLE, null);
final SvgTitler svgTitler = new SvgTitler(titleColor, diagram.getTitle(), fontSize, fontFamily,
HorizontalAlignement.CENTER, VerticalPosition.TOP, 3);
return svgTitler.getHeight();
private SvgTitler getHeaderSvgTitler() throws IOException {
final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.HEADER, null);
final UFont font = getSkinParam().getFont(FontParam.HEADER, null);
final String fontFamily = font.getFamily(null);
final int fontSize = font.getSize();
return new SvgTitler(diagram.getColorMapper(), titleColor, diagram.getHeader(), fontSize, fontFamily, diagram
.getHeaderAlignement(), VerticalPosition.TOP, 3);
}
private String addTitleEps(String eps) throws IOException {
final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.TITLE, null).getColor();
final String fontFamily = getSkinParam().getFontFamily(FontParam.TITLE, null);
final int fontSize = getSkinParam().getFontSize(FontParam.TITLE, null);
private SvgTitler getFooterSvgTitler() throws IOException {
final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.FOOTER, null);
final UFont font = getSkinParam().getFont(FontParam.FOOTER, null);
final String fontFamily = font.getFamily(null);
final int fontSize = font.getSize();
return new SvgTitler(diagram.getColorMapper(), titleColor, diagram.getFooter(), fontSize, fontFamily, diagram
.getFooterAlignement(), VerticalPosition.BOTTOM, 3);
}
final EpsTitler epsTitler = new EpsTitler(titleColor, diagram.getTitle(), fontSize, fontFamily,
HorizontalAlignement.CENTER, VerticalPosition.TOP, 3);
private String addTitleEps(EpsStrategy epsStrategy, String eps) throws IOException {
final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.TITLE, null);
final UFont font = getSkinParam().getFont(FontParam.TITLE, null);
final String fontFamily = font.getFamily(null);
final int fontSize = font.getSize();
final EpsTitler epsTitler = new EpsTitler(diagram.getColorMapper(), epsStrategy, titleColor,
diagram.getTitle(), fontSize, fontFamily, HorizontalAlignement.CENTER, VerticalPosition.TOP, 3);
this.deltaY += epsTitler.getHeight();
return epsTitler.addTitleEps(eps);
}
private String addFooterEps(String eps) throws IOException {
final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.FOOTER, null).getColor();
final String fontFamily = getSkinParam().getFontFamily(FontParam.FOOTER, null);
final int fontSize = getSkinParam().getFontSize(FontParam.FOOTER, null);
final EpsTitler epsTitler = new EpsTitler(titleColor, diagram.getFooter(), fontSize, fontFamily, diagram
.getFooterAlignement(), VerticalPosition.BOTTOM, 3);
private String addFooterEps(EpsStrategy epsStrategy, String eps) throws IOException {
final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.FOOTER, null);
final UFont font = getSkinParam().getFont(FontParam.FOOTER, null);
final String fontFamily = font.getFamily(null);
final int fontSize = font.getSize();
final EpsTitler epsTitler = new EpsTitler(diagram.getColorMapper(), epsStrategy, titleColor, diagram
.getFooter(), fontSize, fontFamily, diagram.getFooterAlignement(), VerticalPosition.BOTTOM, 3);
return epsTitler.addTitleEps(eps);
}
private String addHeaderEps(String eps) throws IOException {
final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.HEADER, null).getColor();
final String fontFamily = getSkinParam().getFontFamily(FontParam.HEADER, null);
final int fontSize = getSkinParam().getFontSize(FontParam.HEADER, null);
final EpsTitler epsTitler = new EpsTitler(titleColor, diagram.getHeader(), fontSize, fontFamily, diagram
.getHeaderAlignement(), VerticalPosition.TOP, 3);
private String addHeaderEps(EpsStrategy epsStrategy, String eps) throws IOException {
final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.HEADER, null);
final UFont font = getSkinParam().getFont(FontParam.HEADER, null);
final String fontFamily = font.getFamily(null);
final int fontSize = font.getSize();
final EpsTitler epsTitler = new EpsTitler(diagram.getColorMapper(), epsStrategy, titleColor, diagram
.getHeader(), fontSize, fontFamily, diagram.getHeaderAlignement(), VerticalPosition.TOP, 3);
this.deltaY += epsTitler.getHeight();
return epsTitler.addTitleEps(eps);
}
private String addHeaderSvg(String svg, double width, double height) throws IOException {
final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.HEADER, null).getColor();
final String fontFamily = getSkinParam().getFontFamily(FontParam.HEADER, null);
final int fontSize = getSkinParam().getFontSize(FontParam.HEADER, null);
final SvgTitler svgTitler = new SvgTitler(titleColor, diagram.getHeader(), fontSize, fontFamily, diagram
.getHeaderAlignement(), VerticalPosition.TOP, 3);
this.deltaY += svgTitler.getHeight();
return svgTitler.addTitleSvg(svg, width, height);
}
private double getHeaderSvgHeight() throws IOException {
final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.HEADER, null).getColor();
final String fontFamily = getSkinParam().getFontFamily(FontParam.HEADER, null);
final int fontSize = getSkinParam().getFontSize(FontParam.HEADER, null);
final SvgTitler svgTitler = new SvgTitler(titleColor, diagram.getHeader(), fontSize, fontFamily, diagram
.getHeaderAlignement(), VerticalPosition.TOP, 3);
return svgTitler.getHeight();
}
private String addFooterSvg(String svg, double width, double height) throws IOException {
final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.FOOTER, null).getColor();
final String fontFamily = getSkinParam().getFontFamily(FontParam.FOOTER, null);
final int fontSize = getSkinParam().getFontSize(FontParam.FOOTER, null);
final SvgTitler svgTitler = new SvgTitler(titleColor, diagram.getFooter(), fontSize, fontFamily, diagram
.getFooterAlignement(), VerticalPosition.BOTTOM, 3);
return svgTitler.addTitleSvg(svg, width, height + deltaY);
}
private double getFooterSvgHeight() throws IOException {
final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.FOOTER, null).getColor();
final String fontFamily = getSkinParam().getFontFamily(FontParam.FOOTER, null);
final int fontSize = getSkinParam().getFontSize(FontParam.FOOTER, null);
final SvgTitler svgTitler = new SvgTitler(titleColor, diagram.getFooter(), fontSize, fontFamily, diagram
.getFooterAlignement(), VerticalPosition.BOTTOM, 3);
return svgTitler.getHeight();
}
private BufferedImage addFooter(BufferedImage im, final Color background) {
final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.FOOTER, null).getColor();
final String fontFamily = getSkinParam().getFontFamily(FontParam.FOOTER, null);
final int fontSize = getSkinParam().getFontSize(FontParam.FOOTER, null);
final PngTitler pngTitler = new PngTitler(titleColor, diagram.getFooter(), fontSize, fontFamily, diagram
.getFooterAlignement(), VerticalPosition.BOTTOM);
private BufferedImage addFooter(BufferedImage im, final HtmlColor background) {
final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.FOOTER, null);
final UFont font = getSkinParam().getFont(FontParam.FOOTER, null);
final String fontFamily = font.getFamily(null);
final int fontSize = font.getSize();
final PngTitler pngTitler = new PngTitler(diagram.getColorMapper(), titleColor, diagram.getFooter(), fontSize,
fontFamily, diagram.getFooterAlignement(), VerticalPosition.BOTTOM);
return pngTitler.processImage(im, background, 3);
}
private BufferedImage addHeader(BufferedImage im, final Color background) throws IOException {
final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.HEADER, null).getColor();
final String fontFamily = getSkinParam().getFontFamily(FontParam.HEADER, null);
final int fontSize = getSkinParam().getFontSize(FontParam.HEADER, null);
final PngTitler pngTitler = new PngTitler(titleColor, diagram.getHeader(), fontSize, fontFamily, diagram
.getHeaderAlignement(), VerticalPosition.TOP);
private BufferedImage addHeader(BufferedImage im, final HtmlColor background) throws IOException {
final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.HEADER, null);
final UFont font = getSkinParam().getFont(FontParam.HEADER, null);
final String fontFamily = font.getFamily(null);
final int fontSize = font.getSize();
final PngTitler pngTitler = new PngTitler(diagram.getColorMapper(), titleColor, diagram.getHeader(), fontSize,
fontFamily, diagram.getHeaderAlignement(), VerticalPosition.TOP);
return pngTitler.processImage(im, background, 3);
}
private double getHeaderPngHeight(StringBounder stringBounder) throws IOException {
final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.HEADER, null).getColor();
final String fontFamily = getSkinParam().getFontFamily(FontParam.HEADER, null);
final int fontSize = getSkinParam().getFontSize(FontParam.HEADER, null);
final PngTitler pngTitler = new PngTitler(titleColor, diagram.getHeader(), fontSize, fontFamily, diagram
.getHeaderAlignement(), VerticalPosition.TOP);
final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.HEADER, null);
final UFont font = getSkinParam().getFont(FontParam.HEADER, null);
final String fontFamily = font.getFamily(null);
final int fontSize = font.getSize();
final PngTitler pngTitler = new PngTitler(diagram.getColorMapper(), titleColor, diagram.getHeader(), fontSize,
fontFamily, diagram.getHeaderAlignement(), VerticalPosition.TOP);
return pngTitler.getOffsetY(stringBounder);
}
private void cleanTemporaryFiles(final Collection<? extends Imaged> imageFiles) throws IOException {
if (OptionFlags.getInstance().isKeepTmpFiles() == false) {
for (Imaged entity : imageFiles) {
if (entity.getImageFile() != null) {
entity.getImageFile().delete();
}
}
}
}
DrawFile createImage(Entity entity, double dpiFactor, int dpi) throws IOException {
DrawFile createImage(Entity entity, FileFormatOption option) throws IOException {
final double dpiFactor = diagram.getDpiFactor(option);
if (entity.getType() == EntityType.NOTE) {
return createImageForNote(entity.getDisplay(), entity.getSpecificBackColor(), dpiFactor, dpi);
return createImageForNote(entity.getDisplay2(), entity.getSpecificBackColor(), option, entity.getParent());
}
if (entity.getType() == EntityType.ACTOR) {
return createImageForActor(entity, dpiFactor);
@ -771,54 +700,24 @@ public final class CucaDiagramFileMaker {
return null;
}
private DrawFile createImageForNoteOld2(String display, HtmlColor backColor, double dpiFactor, int dpi)
throws IOException {
final File fPng = FileUtils.createTempFile("plantumlB", ".png");
private DrawFile createImageForNote(List<? extends CharSequence> display2, HtmlColor noteBackColor, final FileFormatOption option,
Group parent) throws IOException {
final Rose skin = new Rose();
final ISkinParam skinParam = new SkinParamBackcolored(getSkinParam(), backColor);
final ISkinParam skinParam = new SkinParamBackcolored(getSkinParam(), noteBackColor);
final Component comp = skin
.createComponent(ComponentType.NOTE, skinParam, StringUtils.getWithNewlines(display));
.createComponent(ComponentType.NOTE, skinParam, display2);
final double dpiFactor = diagram.getDpiFactor(option);
final int width = (int) (comp.getPreferredWidth(stringBounder) * dpiFactor);
final int height = (int) (comp.getPreferredHeight(stringBounder) * dpiFactor);
final Color background = diagram.getSkinParam().getBackgroundColor().getColor();
final EmptyImageBuilder builder = new EmptyImageBuilder(width, height, background);
final BufferedImage im = builder.getBufferedImage();
final Graphics2D g2d = builder.getGraphics2D();
comp.drawU(new UGraphicG2d(g2d, null, dpiFactor), new Dimension(width, height), new SimpleContext2D(false));
PngIO.write(im, fPng, dpi);
g2d.dispose();
final UGraphicSvg ug = new UGraphicSvg(true);
comp.drawU(ug, new Dimension(width, height), new SimpleContext2D(false));
final File fEps = FileUtils.createTempFile("plantumlB", ".eps");
final PrintWriter pw = new PrintWriter(fEps);
final UGraphicEps uEps = new UGraphicEps(EpsStrategy.getDefault());
comp.drawU(uEps, new Dimension(width, height), new SimpleContext2D(false));
pw.print(uEps.getEPSCode());
pw.close();
return DrawFile.createFromFile(fPng, getSvg(ug), fEps);
}
private DrawFile createImageForNote(String display, HtmlColor backColor, final double dpiFactor, final int dpi)
throws IOException {
final Rose skin = new Rose();
final ISkinParam skinParam = new SkinParamBackcolored(getSkinParam(), backColor);
final Component comp = skin
.createComponent(ComponentType.NOTE, skinParam, StringUtils.getWithNewlines(display));
final int width = (int) (comp.getPreferredWidth(stringBounder) * dpiFactor);
final int height = (int) (comp.getPreferredHeight(stringBounder) * dpiFactor);
final Color background = diagram.getSkinParam().getBackgroundColor().getColor();
final int dpi = diagram.getDpi(option);
HtmlColor backgroundColor = diagram.getSkinParam().getBackgroundColor();
if (parent != null && parent.getBackColor() != null) {
backgroundColor = parent.getBackColor();
}
final Color background = diagram.getColorMapper().getMappedColor(backgroundColor);
final Lazy<File> lpng = new Lazy<File>() {
@ -828,8 +727,8 @@ public final class CucaDiagramFileMaker {
final BufferedImage im = builder.getBufferedImage();
final Graphics2D g2d = builder.getGraphics2D();
comp.drawU(new UGraphicG2d(g2d, null, dpiFactor), new Dimension(width, height), new SimpleContext2D(
false));
comp.drawU(new UGraphicG2d(diagram.getColorMapper(), g2d, null, dpiFactor),
new Dimension(width, height), new SimpleContext2D(false));
PngIO.write(im, fPng, dpi);
g2d.dispose();
return fPng;
@ -838,7 +737,7 @@ public final class CucaDiagramFileMaker {
final Lazy<String> lsvg = new Lazy<String>() {
public String getNow() throws IOException {
final UGraphicSvg ug = new UGraphicSvg(true);
final UGraphicSvg ug = new UGraphicSvg(getSkinParam().getColorMapper(), true);
comp.drawU(ug, new Dimension(width, height), new SimpleContext2D(false));
return getSvg(ug);
}
@ -848,7 +747,8 @@ public final class CucaDiagramFileMaker {
public File getNow() throws IOException {
final File fEps = FileUtils.createTempFile("plantumlB", ".eps");
final PrintWriter pw = new PrintWriter(fEps);
final UGraphicEps uEps = new UGraphicEps(EpsStrategy.getDefault());
final UGraphicEps uEps = new UGraphicEps(getSkinParam().getColorMapper(), getEpsStrategy(option
.getFileFormat()));
comp.drawU(uEps, new Dimension(width, height), new SimpleContext2D(false));
pw.print(uEps.getEPSCode());
pw.close();
@ -875,23 +775,24 @@ public final class CucaDiagramFileMaker {
private DrawFile createImageForCircleInterface(Entity entity, final double dpiFactor) throws IOException {
final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel();
final Color interfaceBackground = rose.getHtmlColor(getSkinParam(), ColorParam.componentInterfaceBackground,
stereo).getColor();
final Color interfaceBorder = rose.getHtmlColor(getSkinParam(), ColorParam.componentInterfaceBorder, stereo)
.getColor();
final Color background = rose.getHtmlColor(getSkinParam(), ColorParam.background, stereo).getColor();
final HtmlColor interfaceBackground = rose.getHtmlColor(getSkinParam(),
ColorParam.componentInterfaceBackground, stereo);
final HtmlColor interfaceBorder = rose
.getHtmlColor(getSkinParam(), ColorParam.componentInterfaceBorder, stereo);
final HtmlColor background = rose.getHtmlColor(getSkinParam(), ColorParam.background, stereo);
final CircleInterface circleInterface = new CircleInterface(interfaceBackground, interfaceBorder);
final Lazy<File> lpng = new Lazy<File>() {
public File getNow() throws IOException {
final EmptyImageBuilder builder = new EmptyImageBuilder(circleInterface.getPreferredWidth(null)
* dpiFactor, circleInterface.getPreferredHeight(null) * dpiFactor, background);
* dpiFactor, circleInterface.getPreferredHeight(null) * dpiFactor, diagram.getColorMapper()
.getMappedColor(background));
final BufferedImage im = builder.getBufferedImage();
final Graphics2D g2d = builder.getGraphics2D();
circleInterface.drawU(new UGraphicG2d(g2d, null, 1.0));
circleInterface.drawU(new UGraphicG2d(diagram.getColorMapper(), g2d, null, 1.0));
final File png = FileUtils.createTempFile("circleinterface", ".png");
ImageIO.write(im, "png", png);
@ -902,14 +803,14 @@ public final class CucaDiagramFileMaker {
final Lazy<File> leps = new Lazy<File>() {
public File getNow() throws IOException {
final File epsFile = FileUtils.createTempFile("circleinterface", ".eps");
UGraphicEps.copyEpsToFile(circleInterface, epsFile);
UGraphicEps.copyEpsToFile(getSkinParam().getColorMapper(), circleInterface, epsFile);
return epsFile;
}
};
final Lazy<String> lsvg = new Lazy<String>() {
public String getNow() throws IOException {
return UGraphicG2d.getSvgString(circleInterface);
return UGraphicG2d.getSvgString(getSkinParam().getColorMapper(), circleInterface);
}
};
@ -922,21 +823,21 @@ public final class CucaDiagramFileMaker {
private DrawFile createImageForActor(Entity entity, final double dpiFactor) throws IOException {
final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel();
final Color actorBackground = rose.getHtmlColor(getSkinParam(), ColorParam.usecaseActorBackground, stereo)
.getColor();
final Color actorBorder = rose.getHtmlColor(getSkinParam(), ColorParam.usecaseActorBorder, stereo).getColor();
final Color background = rose.getHtmlColor(getSkinParam(), ColorParam.background, stereo).getColor();
final HtmlColor actorBackground = rose.getHtmlColor(getSkinParam(), ColorParam.usecaseActorBackground, stereo);
final HtmlColor actorBorder = rose.getHtmlColor(getSkinParam(), ColorParam.usecaseActorBorder, stereo);
final HtmlColor background = rose.getHtmlColor(getSkinParam(), ColorParam.background, stereo);
final StickMan stickMan = new StickMan(actorBackground, actorBorder);
final Lazy<File> lpng = new Lazy<File>() {
public File getNow() throws IOException {
final EmptyImageBuilder builder = new EmptyImageBuilder(stickMan.getPreferredWidth(null) * dpiFactor,
stickMan.getPreferredHeight(null) * dpiFactor, background);
stickMan.getPreferredHeight(null) * dpiFactor, diagram.getColorMapper().getMappedColor(
background));
final BufferedImage im = builder.getBufferedImage();
final Graphics2D g2d = builder.getGraphics2D();
stickMan.drawU(new UGraphicG2d(g2d, null, dpiFactor));
stickMan.drawU(new UGraphicG2d(diagram.getColorMapper(), g2d, null, dpiFactor));
final File png = FileUtils.createTempFile("actor", ".png");
ImageIO.write(im, "png", png);
@ -946,14 +847,14 @@ public final class CucaDiagramFileMaker {
final Lazy<File> leps = new Lazy<File>() {
public File getNow() throws IOException {
final File epsFile = FileUtils.createTempFile("actor", ".eps");
UGraphicEps.copyEpsToFile(stickMan, epsFile);
UGraphicEps.copyEpsToFile(getSkinParam().getColorMapper(), stickMan, epsFile);
return epsFile;
}
};
final Lazy<String> lsvg = new Lazy<String>() {
public String getNow() throws IOException {
return UGraphicG2d.getSvgString(stickMan);
return UGraphicG2d.getSvgString(getSkinParam().getColorMapper(), stickMan);
}
};
@ -966,24 +867,31 @@ public final class CucaDiagramFileMaker {
private DrawFile createImageForCircleCharacter(Entity entity, double dpiFactor) throws IOException {
final Stereotype stereotype = entity.getStereotype();
if (stereotype == null || stereotype.getColor() == null) {
if (stereotype == null || stereotype.getHtmlColor() == null) {
return null;
}
final String stereo = stereotype.getLabel();
final Color classBorder = rose.getHtmlColor(getSkinParam(), ColorParam.classBorder, stereo).getColor();
final Color classBackground = rose.getHtmlColor(getSkinParam(), ColorParam.classBackground, stereo).getColor();
final Font font = diagram.getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, stereo);
final HtmlColor classBorder = rose.getHtmlColor(getSkinParam(), ColorParam.classBorder, stereo);
final HtmlColor classBackground = rose.getHtmlColor(getSkinParam(), ColorParam.classBackground, stereo);
final UFont font = diagram.getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, stereo);
final CircledCharacter circledCharacter = new CircledCharacter(stereotype.getCharacter(), getSkinParam()
.getCircledCharacterRadius(), font, stereotype.getColor(), classBorder, Color.BLACK);
return circledCharacter.generateCircleCharacter(classBackground, dpiFactor);
.getCircledCharacterRadius(), font, stereotype.getHtmlColor(), classBorder, HtmlColor.BLACK);
return circledCharacter.generateCircleCharacter(diagram.getColorMapper(), classBackground, dpiFactor);
}
private ISkinParam getSkinParam() {
return diagram.getSkinParam();
}
private EpsStrategy getEpsStrategy(FileFormat format) {
if (format == FileFormat.EPS_TEXT) {
return EpsStrategy.WITH_MACRO_AND_TEXT;
}
return EpsStrategy.getDefault2();
}
private String createEps(OutputStream os, List<String> dotStrings, FileFormatOption fileFormatOption)
throws IOException, InterruptedException {
@ -1000,7 +908,7 @@ public final class CucaDiagramFileMaker {
final Graphviz graphviz = GraphvizUtils.create(dotString, "eps");
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
graphviz.createPng(baos);
graphviz.createFile(baos);
baos.close();
dotMaker.clean();
@ -1013,13 +921,13 @@ public final class CucaDiagramFileMaker {
}
if (diagram.getTitle() != null) {
eps = addTitleEps(eps);
eps = addTitleEps(getEpsStrategy(fileFormatOption.getFileFormat()), eps);
}
if (diagram.getFooter() != null) {
eps = addFooterEps(eps);
eps = addFooterEps(getEpsStrategy(fileFormatOption.getFileFormat()), eps);
}
if (diagram.getHeader() != null) {
eps = addHeaderEps(eps);
eps = addHeaderEps(getEpsStrategy(fileFormatOption.getFileFormat()), eps);
}
os.write(eps.getBytes("UTF-8"));
@ -1064,16 +972,24 @@ public final class CucaDiagramFileMaker {
// svg = sb.toString();
} finally {
// cleanTemporaryFiles(diagram.entities().values());
// cleanTemporaryFiles(diagram.getLinks());
clean();
}
return null;
}
private void clean() throws IOException {
if (OptionFlags.getInstance().isKeepTmpFiles() == false) {
diagram.clean();
if (staticFilesMap != null) {
staticFilesMap.clean();
}
}
}
private GraphvizMaker populateImagesAndCreateGraphvizMaker(List<String> dotStrings,
FileFormatOption fileFormatOption) throws IOException, InterruptedException {
populateImages(diagram.getDpiFactor(fileFormatOption), diagram.getDpi(fileFormatOption));
populateImagesLink(diagram.getDpiFactor(fileFormatOption), diagram.getDpi(fileFormatOption));
populateImages(fileFormatOption);
populateImagesLink(fileFormatOption);
final GraphvizMaker dotMaker = createDotMaker(dotStrings, fileFormatOption);
return dotMaker;
}
@ -1087,7 +1003,7 @@ public final class CucaDiagramFileMaker {
new CucaDiagramSimplifier(diagram, dotStrings, fileFormat);
}
final DotData dotData = new DotData(null, diagram.getLinks(), diagram.entities(), diagram.getUmlDiagramType(),
diagram.getSkinParam(), diagram.getRankdir(), diagram, diagram);
diagram.getSkinParam(), diagram.getRankdir(), diagram, diagram, diagram.getColorMapper());
dotData.setDpi(diagram.getDpi(fileFormatOption));
@ -1106,22 +1022,22 @@ public final class CucaDiagramFileMaker {
// return new DotMaker(dotData, dotStrings, fileFormat);
}
private void populateImages(double dpiFactor, int dpi) throws IOException {
private void populateImages(FileFormatOption option) throws IOException {
for (Entity entity : diagram.entities().values()) {
final DrawFile f = createImage(entity, dpiFactor, dpi);
final DrawFile f = createImage(entity, option);
if (f != null) {
entity.setImageFile(f);
}
}
}
private void populateImagesLink(double dpiFactor, int dpi) throws IOException {
private void populateImagesLink(FileFormatOption option) throws IOException {
for (Link link : diagram.getLinks()) {
final String note = link.getNote();
final List<? extends CharSequence> note = link.getNote();
if (note == null) {
continue;
}
final DrawFile f = createImageForNote(note, null, dpiFactor, dpi);
final DrawFile f = createImageForNote(note, null, option, null);
if (f != null) {
link.setImageFile(f);
}
@ -1137,7 +1053,7 @@ public final class CucaDiagramFileMaker {
sb.append(s);
sb.append("\n");
s = st.nextToken();
if (s.equalsIgnoreCase("grestore") == false) {
if (s.equalsIgnoreCase("grestore") == false && st.hasMoreTokens()) {
s = st.nextToken();
if (s.equalsIgnoreCase("grestore") == false) {
throw new IllegalStateException();

View File

@ -37,6 +37,7 @@ import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Dimension2D;
import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@ -69,7 +70,7 @@ public final class CucaDiagramFileMakerBeta {
InterruptedException {
OutputStream os = null;
try {
os = new FileOutputStream(suggested);
os = new BufferedOutputStream(new FileOutputStream(suggested));
createFile(os, dotStrings, fileFormat);
} finally {
if (os != null) {
@ -105,11 +106,11 @@ public final class CucaDiagramFileMakerBeta {
private void createPng(OutputStream os, List<String> dotStrings) throws IOException, InterruptedException {
final Color background = diagram.getSkinParam().getBackgroundColor().getColor();
final Color background = diagram.getColorMapper().getMappedColor(diagram.getSkinParam().getBackgroundColor());
EmptyImageBuilder builder = new EmptyImageBuilder(10, 10, background);
BufferedImage im = builder.getBufferedImage();
Graphics2D g2d = builder.getGraphics2D();
UGraphicG2d ug = new UGraphicG2d(g2d, im, 1.0);
UGraphicG2d ug = new UGraphicG2d(diagram.getColorMapper(), g2d, im, 1.0);
final PlayField playField = new PlayField(diagram.getSkinParam());
final Collection<IEntity> entities = getFirstLevelEntities();
@ -126,7 +127,7 @@ public final class CucaDiagramFileMakerBeta {
im = builder.getBufferedImage();
g2d = builder.getGraphics2D();
g2d.translate(10, 0);
ug = new UGraphicG2d(g2d, im, 1.0);
ug = new UGraphicG2d(diagram.getColorMapper(), g2d, im, 1.0);
playField.drawInternal(ug);

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5872 $
* Revision $Revision: 6710 $
*
*/
package net.sourceforge.plantuml.cucadiagram.dot;
@ -37,6 +37,7 @@ import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.geom.Dimension2D;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@ -169,7 +170,7 @@ public final class CucaDiagramPngMaker2 {
public List<File> createPng(File pngFile) throws IOException {
OutputStream os = null;
try {
os = new FileOutputStream(pngFile);
os = new BufferedOutputStream(new FileOutputStream(pngFile));
createPng(os);
} finally {
if (os != null) {

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5872 $
* Revision $Revision: 6710 $
*
*/
package net.sourceforge.plantuml.cucadiagram.dot;
@ -37,6 +37,7 @@ import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.geom.Dimension2D;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@ -148,7 +149,7 @@ public final class CucaDiagramPngMaker3 {
public List<File> createPng(File pngFile) throws IOException {
OutputStream os = null;
try {
os = new FileOutputStream(pngFile);
os = new BufferedOutputStream(new FileOutputStream(pngFile));
createPng(os);
} finally {
if (os != null) {

View File

@ -28,15 +28,17 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6169 $
* Revision $Revision: 6710 $
*
*/
package net.sourceforge.plantuml.cucadiagram.dot;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@ -83,7 +85,8 @@ public final class CucaDiagramSimplifier {
} else {
throw new IllegalStateException();
}
final Entity proxy = new Entity("#" + g.getCode(), g.getDisplay(), type, g.getParent(), diagram.getHides());
final Entity proxy = new Entity("#" + g.getCode(), g.getDisplay(), type, g.getParent(),
diagram.getHides());
if (type == EntityType.STATE) {
manageBackColorForState(diagram, g, proxy);
}
@ -92,6 +95,17 @@ public final class CucaDiagramSimplifier {
}
computeImageGroup(g, proxy, dotStrings);
diagram.overideGroup(g, proxy);
if (proxy.getImageFile() != null) {
diagram.ensureDelete(proxy.getImageFile());
}
// final IEntity entityCluster = g.getEntityCluster();
// if (entityCluster != null && entityCluster.getImageFile() != null) {
// proxy.addSubImage(entityCluster.getImageFile());
// }
// if (entityCluster != null) {
// proxy.addSubImage((Entity) entityCluster);
// }
for (IEntity sub : g.entities().values()) {
final DrawFile subImage = sub.getImageFile();
@ -106,36 +120,16 @@ public final class CucaDiagramSimplifier {
} while (changed);
}
private void manageBackColorForState(CucaDiagram diagram, Group g, final Entity proxy) {
if (OptionFlags.PBBACK == false) {
return;
}
if (g.getBackColor() != null) {
proxy.setSpecificBackcolor(g.getBackColor().getAsHtml());
return;
}
assert g.getBackColor() == null;
if (g.getStereotype() != null) {
proxy.setStereotype(new Stereotype(g.getStereotype()));
}
//PBBACK
final Rose rose = new Rose();
final HtmlColor back = rose.getHtmlColor(diagram.getSkinParam(), ColorParam.stateBackground, g.getStereotype());
// final HtmlColor back = diagram.getSkinParam().getHtmlColor(ColorParam.stateBackground, g.getStereotype());
// if (back != null) {
// proxy.setSpecificBackcolor(back.getAsHtml());
// }
assert g.getBackColor() == null;
g.setBackColor(back);
}
private void computeImageGroup(final Group group, final Entity entity, List<String> dotStrings) throws IOException,
FileNotFoundException, InterruptedException {
if (group.entities().size()==0) {
return;
}
final GroupPngMaker maker = new GroupPngMaker(diagram, group, fileFormat);
final File f = FileUtils.createTempFile("inner", ".png");
FileOutputStream fos = null;
OutputStream fos = null;
try {
fos = new FileOutputStream(f);
fos = new BufferedOutputStream(new FileOutputStream(f));
maker.createPng(fos, dotStrings);
final String svg = maker.createSvg(dotStrings);
// final Pattern pImage = Pattern.compile("(?i)<image\\W[^>]*>");
@ -151,4 +145,27 @@ public final class CucaDiagramSimplifier {
}
}
private void manageBackColorForState(CucaDiagram diagram, Group g, final Entity proxy) {
if (OptionFlags.PBBACK == false) {
return;
}
if (g.getBackColor() != null) {
proxy.setSpecificBackcolor(g.getBackColor());
return;
}
assert g.getBackColor() == null;
if (g.getStereotype() != null) {
proxy.setStereotype(new Stereotype(g.getStereotype()));
}
// PBBACK
final Rose rose = new Rose();
final HtmlColor back = rose.getHtmlColor(diagram.getSkinParam(), ColorParam.stateBackground, g.getStereotype());
// final HtmlColor back = diagram.getSkinParam().getHtmlColor(ColorParam.stateBackground, g.getStereotype());
// if (back != null) {
// proxy.setSpecificBackcolor(back.getAsHtml());
// }
assert g.getBackColor() == null;
g.setBackColor(back);
}
}

View File

@ -0,0 +1,115 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* 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 Lesser 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.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6710 $
*
*/
package net.sourceforge.plantuml.cucadiagram.dot;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import net.sourceforge.plantuml.cucadiagram.CucaDiagram;
import net.sourceforge.plantuml.cucadiagram.Entity;
import net.sourceforge.plantuml.cucadiagram.EntityType;
import net.sourceforge.plantuml.cucadiagram.Group;
import net.sourceforge.plantuml.cucadiagram.GroupType;
import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.Member;
import net.sourceforge.plantuml.svek.GroupPngMaker2;
public final class CucaDiagramSimplifier2 {
private final CucaDiagram diagram;
public CucaDiagramSimplifier2(CucaDiagram diagram, List<String> dotStrings) throws IOException, InterruptedException {
this.diagram = diagram;
boolean changed;
do {
changed = false;
final Collection<Group> groups = new ArrayList<Group>(diagram.getGroups());
for (Group g : groups) {
if (diagram.isAutarkic(g)) {
final EntityType type;
if (g.getType() == GroupType.CONCURRENT_STATE) {
type = EntityType.STATE_CONCURRENT;
} else if (g.getType() == GroupType.STATE) {
type = EntityType.STATE;
} else if (g.getType() == GroupType.INNER_ACTIVITY) {
type = EntityType.ACTIVITY;
} else if (g.getType() == GroupType.CONCURRENT_ACTIVITY) {
type = EntityType.ACTIVITY_CONCURRENT;
} else {
throw new IllegalStateException();
}
final Entity proxy = new Entity("#" + g.getCode(), g.getDisplay(), type, g.getParent(), diagram
.getHides());
// if (type == EntityType.STATE) {
// manageBackColorForState(diagram, g, proxy);
// }
for (Member field : g.getEntityCluster().getFieldsToDisplay()) {
proxy.addField(field);
}
computeImageGroup(g, proxy, dotStrings);
diagram.overideGroup(g, proxy);
if (proxy.getImageFile() != null) {
diagram.ensureDelete(proxy.getImageFile());
}
// final IEntity entityCluster = g.getEntityCluster();
// if (entityCluster != null && entityCluster.getImageFile()
// != null) {
// proxy.addSubImage(entityCluster.getImageFile());
// }
// if (entityCluster != null) {
// proxy.addSubImage((Entity) entityCluster);
// }
for (IEntity sub : g.entities().values()) {
final DrawFile subImage = sub.getImageFile();
if (subImage != null) {
proxy.addSubImage(subImage);
}
}
changed = true;
}
}
} while (changed);
}
private void computeImageGroup(Group g, Entity proxy, List<String> dotStrings) throws IOException, InterruptedException {
final GroupPngMaker2 maker = new GroupPngMaker2(diagram, g);
proxy.setSvekImage(maker.getImage());
}
}

View File

@ -122,7 +122,7 @@ public final class CucaDiagramTxtMaker {
final int w = getWidth(ent);
final int h = getHeight(ent);
ug.getCharArea().drawBoxSimple(0, 0, w, h);
ug.getCharArea().drawStringsLR(StringUtils.getWithNewlines(ent.getDisplay()), 1, 1);
ug.getCharArea().drawStringsLR(ent.getDisplay2(), 1, 1);
int y = 2;
ug.getCharArea().drawHLine('-', y, 1, w - 1);
y++;
@ -150,7 +150,7 @@ public final class CucaDiagramTxtMaker {
}
private int getHeight(Entity entity) {
int result = StringUtils.getHeight(StringUtils.getWithNewlines(entity.getDisplay()));
int result = StringUtils.getHeight(entity.getDisplay2());
for (Member att : entity.getMethodsToDisplay()) {
result += StringUtils.getHeight(StringUtils.getWithNewlines(att.getDisplayWithVisibilityChar()));
}
@ -161,7 +161,7 @@ public final class CucaDiagramTxtMaker {
}
private int getWidth(Entity entity) {
int result = StringUtils.getWidth(StringUtils.getWithNewlines(entity.getDisplay()));
int result = StringUtils.getWidth(entity.getDisplay2());
for (Member att : entity.getMethodsToDisplay()) {
final int w = StringUtils.getWidth(StringUtils.getWithNewlines(att.getDisplayWithVisibilityChar()));
if (w > result) {

View File

@ -43,6 +43,7 @@ import javax.imageio.ImageIO;
import net.sourceforge.plantuml.ColorParam;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.cucadiagram.EntityPortion;
import net.sourceforge.plantuml.cucadiagram.EntityType;
import net.sourceforge.plantuml.cucadiagram.Group;
@ -51,17 +52,16 @@ import net.sourceforge.plantuml.cucadiagram.Member;
import net.sourceforge.plantuml.cucadiagram.Stereotype;
import net.sourceforge.plantuml.graphic.HtmlColor;
import net.sourceforge.plantuml.skin.rose.Rose;
import net.sourceforge.plantuml.ugraphic.ColorMapper;
abstract class DotCommon {
private final DotData data;
private final FileFormat fileFormat;
private boolean underline;
private final Rose rose = new Rose();
DotCommon(FileFormat fileFormat, DotData data) {
this.fileFormat = fileFormat;
this.data = data;
@ -74,6 +74,10 @@ abstract class DotCommon {
return entity.getStereotype();
}
protected final ColorMapper getColorMapper() {
return data.getColorMapper();
}
protected final boolean isThereLabel(final Stereotype stereotype) {
return stereotype != null && stereotype.getLabel() != null;
}
@ -87,11 +91,12 @@ abstract class DotCommon {
final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel();
if (isThereLabel(stereotype)) {
sb.append("<BR ALIGN=\"LEFT\"/>");
sb.append(manageHtmlIB(stereotype.getLabel(), classes ? FontParam.CLASS_STEREOTYPE
: FontParam.OBJECT_STEREOTYPE, stereo));
sb.append("<BR/>");
for (String st : stereotype.getLabels()) {
sb.append(manageHtmlIB(st, classes ? FontParam.CLASS_STEREOTYPE : FontParam.OBJECT_STEREOTYPE, stereo));
sb.append("<BR/>");
}
}
String display = entity.getDisplay();
String display = StringUtils.getMergedLines(entity.getDisplay2());
final boolean italic = entity.getType() == EntityType.ABSTRACT_CLASS
|| entity.getType() == EntityType.INTERFACE;
if (italic) {
@ -102,11 +107,11 @@ abstract class DotCommon {
protected final String manageHtmlIB(String s, FontParam param, String stereotype) {
s = unicode(s);
final int fontSize = data.getSkinParam().getFontSize(param, stereotype);
final int style = data.getSkinParam().getFontStyle(param, stereotype);
final String fontFamily = data.getSkinParam().getFontFamily(param, stereotype);
final DotExpression dotExpression = new DotExpression(s, fontSize, getFontHtmlColor(param, stereotype),
fontFamily, style, fileFormat);
final int fontSize = data.getSkinParam().getFont(param, stereotype).getSize();
final int style = data.getSkinParam().getFont(param, stereotype).getStyle();
final String fontFamily = data.getSkinParam().getFont(param, stereotype).getFamily(null);
final DotExpression dotExpression = new DotExpression(getColorMapper(), s, fontSize, getFontHtmlColor(param,
stereotype), fontFamily, style, fileFormat);
final String result = dotExpression.getDotHtml();
if (dotExpression.isUnderline()) {
underline = true;
@ -121,7 +126,8 @@ abstract class DotCommon {
static String unicode(String s) {
final StringBuilder result = new StringBuilder();
for (char c : s.toCharArray()) {
if (c > 127 || c == '&') {
if (c > 127 || c == '&' || c == '|') {
// if (c > 127 || c == '&') {
final int i = c;
result.append("&#" + i + ";");
} else {
@ -157,7 +163,7 @@ abstract class DotCommon {
// "\" HEIGHT=\"" + h + "\">";
return "<TD FIXEDSIZE=\"TRUE\" WIDTH=\"" + w + "\" HEIGHT=\"" + h + "\">";
}
public final boolean isUnderline() {
return underline;
}
@ -216,7 +222,7 @@ abstract class DotCommon {
}
protected final int getLonguestHeader(IEntity entity) {
int result = entity.getDisplay().length();
int result = StringUtils.getMergedLines(entity.getDisplay2()).length();
final Stereotype stereotype = getStereotype(entity);
if (isThereLabel(stereotype)) {
final int size = stereotype.getLabel().length();
@ -228,7 +234,11 @@ abstract class DotCommon {
}
protected final String getColorString(ColorParam colorParam, String stereotype) {
return "\"" + rose.getHtmlColor(getData().getSkinParam(), colorParam, stereotype).getAsHtml() + "\"";
return "\"" + getAsHtml(rose.getHtmlColor(getData().getSkinParam(), colorParam, stereotype)) + "\"";
}
protected final String getAsHtml(HtmlColor htmlColor) {
return StringUtils.getAsHtml(getColorMapper().getMappedColor(htmlColor));
}
protected final int getLongestFieldOrAttribute(IEntity entity) {
@ -258,7 +268,7 @@ abstract class DotCommon {
}
return prefix + manageHtmlIB(att.getDisplay(withVisibilityChar), param, null);
}
final protected String getBackColorAroundEntity(IEntity entity) {
String backColor = getSpecificBackColor(entity);
if (backColor == null) {
@ -275,9 +285,9 @@ abstract class DotCommon {
if (parent.getBackColor() == null) {
return null;
}
return "\"" + parent.getBackColor().getAsHtml() + "\"";
return "\"" + getAsHtml(parent.getBackColor()) + "\"";
}
final protected void appendImageAsTD(StringBuilder sb, String circleAbsolutePath) throws IOException {
if (circleAbsolutePath.endsWith(".png")) {
if (getData().getDpi() == 96) {
@ -294,8 +304,4 @@ abstract class DotCommon {
}
}
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6222 $
* Revision $Revision: 6577 $
*
*/
package net.sourceforge.plantuml.cucadiagram.dot;
@ -53,6 +53,7 @@ import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.PortionShower;
import net.sourceforge.plantuml.cucadiagram.Rankdir;
import net.sourceforge.plantuml.skin.VisibilityModifier;
import net.sourceforge.plantuml.ugraphic.ColorMapper;
final public class DotData implements PortionShower {
@ -68,11 +69,13 @@ final public class DotData implements PortionShower {
private StaticFilesMap staticFilesMap;
private boolean visibilityModifierPresent;
private final ColorMapper colorMapper;
public DotData(Group topParent, List<Link> links, Map<String, ? extends IEntity> entities,
UmlDiagramType umlDiagramType, ISkinParam skinParam, Rankdir rankdir, GroupHierarchy groupHierarchy,
PortionShower portionShower) {
PortionShower portionShower, ColorMapper colorMapper) {
this.topParent = topParent;
this.colorMapper = colorMapper;
this.links = links;
this.entities = entities;
this.umlDiagramType = umlDiagramType;
@ -83,12 +86,13 @@ final public class DotData implements PortionShower {
}
public DotData(Group topParent, List<Link> links, Map<String, ? extends IEntity> entities,
UmlDiagramType umlDiagramType, ISkinParam skinParam, Rankdir rankdir, GroupHierarchy groupHierarchy) {
UmlDiagramType umlDiagramType, ISkinParam skinParam, Rankdir rankdir, GroupHierarchy groupHierarchy,
ColorMapper colorMapper) {
this(topParent, links, entities, umlDiagramType, skinParam, rankdir, groupHierarchy, new PortionShower() {
public boolean showPortion(EntityPortion portion, IEntity entity) {
return true;
}
});
}, colorMapper);
}
public boolean hasUrl() {
@ -106,18 +110,16 @@ final public class DotData implements PortionShower {
checkObjectOrClassDiagram();
return staticFilesMap.getStaticFiles(stereo).getVisibilityImages(visibilityModifier);
}
public boolean isThereVisibilityImages() {
return visibilityModifierPresent;
}
public void setVisibilityModifierPresent(boolean b) {
checkObjectOrClassDiagram();
this.visibilityModifierPresent = b;
}
public void setStaticImagesMap(StaticFilesMap staticFilesMap) {
checkObjectOrClassDiagram();
this.staticFilesMap = staticFilesMap;
@ -251,7 +253,7 @@ final public class DotData implements PortionShower {
public final int getDpi() {
return dpi;
}
public double getDpiFactor() {
if (dpi == 96) {
return 1.0;
@ -262,7 +264,7 @@ final public class DotData implements PortionShower {
public final void setDpi(int dpi) {
this.dpi = dpi;
}
private boolean hideEmptyDescription = false;
public final void setHideEmptyDescription(boolean hideEmptyDescription) {
@ -272,7 +274,9 @@ final public class DotData implements PortionShower {
public final boolean isHideEmptyDescription() {
return hideEmptyDescription;
}
public final ColorMapper getColorMapper() {
return colorMapper;
}
}

View File

@ -28,12 +28,11 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5705 $
* Revision $Revision: 6932 $
*
*/
package net.sourceforge.plantuml.cucadiagram.dot;
import java.awt.Color;
import java.awt.Font;
import java.io.File;
import java.io.IOException;
@ -44,6 +43,7 @@ import java.util.List;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileSystem;
import net.sourceforge.plantuml.Log;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.graphic.FontChange;
import net.sourceforge.plantuml.graphic.FontConfiguration;
import net.sourceforge.plantuml.graphic.FontStyle;
@ -52,12 +52,14 @@ import net.sourceforge.plantuml.graphic.HtmlCommand;
import net.sourceforge.plantuml.graphic.Img;
import net.sourceforge.plantuml.graphic.Splitter;
import net.sourceforge.plantuml.graphic.Text;
import net.sourceforge.plantuml.ugraphic.ColorMapper;
import net.sourceforge.plantuml.ugraphic.UFont;
final class DotExpression {
public final class DotExpression {
private final StringBuilder sb = new StringBuilder();
private final Font normalFont;
private final UFont normalFont;
private FontConfiguration fontConfiguration;
@ -67,15 +69,19 @@ final class DotExpression {
private final FileFormat fileFormat;
private final ColorMapper colorMapper;
private boolean hasImg;
DotExpression(String html, int defaultFontSize, HtmlColor color, String fontFamily, int style, FileFormat fileFormat) {
public DotExpression(ColorMapper colorMapper, String html, int defaultFontSize, HtmlColor color, String fontFamily,
int style, FileFormat fileFormat) {
if (html.contains("\n")) {
throw new IllegalArgumentException(html);
}
this.colorMapper = colorMapper;
this.fontFamily = fontFamily;
this.normalFont = new Font("SansSerif", Font.PLAIN, defaultFontSize);
this.fontConfiguration = new FontConfiguration(normalFont, color.getColor());
this.normalFont = new UFont("SansSerif", Font.PLAIN, defaultFontSize);
this.fontConfiguration = new FontConfiguration(normalFont, color);
this.fileFormat = fileFormat;
if ((style & Font.ITALIC) != 0) {
@ -190,8 +196,8 @@ final class DotExpression {
sb.append("\" ");
appendFontWithFamily(sb);
final Color col = fontConfiguration.getColor();
sb.append(" COLOR=\"").append(HtmlColor.getAsHtml(col)).append("\"");
final HtmlColor col = fontConfiguration.getColor();
sb.append(" COLOR=\"").append(StringUtils.getAsHtml(colorMapper.getMappedColor(col))).append("\"");
sb.append(">");
return sb.toString();
}

View File

@ -28,20 +28,21 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6482 $
* Revision $Revision: 6939 $
*
*/
package net.sourceforge.plantuml.cucadiagram.dot;
import java.awt.Color;
import java.awt.Font;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import net.sourceforge.plantuml.ColorParam;
@ -54,6 +55,7 @@ import net.sourceforge.plantuml.SignatureUtils;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.UmlDiagramType;
import net.sourceforge.plantuml.Url;
import net.sourceforge.plantuml.command.Position;
import net.sourceforge.plantuml.cucadiagram.Entity;
import net.sourceforge.plantuml.cucadiagram.EntityType;
import net.sourceforge.plantuml.cucadiagram.Group;
@ -70,6 +72,7 @@ import net.sourceforge.plantuml.graphic.HtmlColor;
import net.sourceforge.plantuml.graphic.TextBlock;
import net.sourceforge.plantuml.graphic.TextBlockUtils;
import net.sourceforge.plantuml.skin.UDrawable;
import net.sourceforge.plantuml.ugraphic.UFont;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.eps.UGraphicEps;
@ -88,6 +91,8 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
// http://www.graphviz.org/bugs/b2114.html
private static final boolean TURN_AROUND_B2114 = false;
private static final boolean NOLABEL = false;
private final Set<String> hasAlreadyOneIncommingArrowLenghtOne;
final private Set<String> rankMin = new HashSet<String>();
@ -148,7 +153,7 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
for (String s : dotStrings) {
sb.append(s);
}
sb.append("bgcolor=\"" + getData().getSkinParam().getBackgroundColor().getAsHtml() + "\";");
sb.append("bgcolor=\"" + getAsHtml(getData().getSkinParam().getBackgroundColor()) + "\";");
if (huge) {
sb.append("size=\"400,400;\"");
} else {
@ -200,8 +205,8 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
private void printGroups(StringBuilder sb, Group parent) throws IOException {
for (Group g : getData().getGroupHierarchy().getChildrenGroups(parent)) {
if (getData().isEmpty(g) && g.getType() == GroupType.PACKAGE) {
final IEntity folder = new Entity(g.getUid(), g.getCode(), g.getDisplay(), EntityType.EMPTY_PACKAGE,
null, null);
final IEntity folder = new Entity(g.getUid1(), g.getUid2(), g.getCode(), g.getDisplay(),
EntityType.EMPTY_PACKAGE, null, null);
printEntity(sb, folder);
} else {
printGroup(sb, g);
@ -228,8 +233,9 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
sb.append("subgraph " + g.getUid() + " {");
// sb.append("margin=10;");
sb.append("fontsize=\"" + getData().getSkinParam().getFontSize(getFontParamForGroup(), stereo) + "\";");
final String fontFamily = getData().getSkinParam().getFontFamily(getFontParamForGroup(), stereo);
final UFont font = getData().getSkinParam().getFont(getFontParamForGroup(), stereo);
sb.append("fontsize=\"" + font.getSize() + "\";");
final String fontFamily = font.getFamily(null);
if (fontFamily != null) {
sb.append("fontname=\"" + fontFamily + "\";");
}
@ -237,11 +243,11 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
if (g.getDisplay() != null) {
sb.append("label=<" + manageHtmlIB(g.getDisplay(), getFontParamForGroup(), stereo) + ">;");
}
final String fontColor = getData().getSkinParam().getFontHtmlColor(getFontParamForGroup(), stereo).getAsHtml();
final String fontColor = getAsHtml(getData().getSkinParam().getFontHtmlColor(getFontParamForGroup(), stereo));
sb.append("fontcolor=\"" + fontColor + "\";");
if (getGroupBackColor(g) != null) {
sb.append("fillcolor=\"" + getGroupBackColor(g).getAsHtml() + "\";");
sb.append("fillcolor=\"" + getAsHtml(getGroupBackColor(g)) + "\";");
}
if (g.getType() == GroupType.STATE) {
@ -344,8 +350,9 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
}
// sb.append(g.getUid() + "min->" + g.getUid() + "max;");
sb.append("fontsize=\"" + getData().getSkinParam().getFontSize(getFontParamForGroup(), null) + "\";");
final String fontFamily = getData().getSkinParam().getFontFamily(getFontParamForGroup(), null);
final UFont font = getData().getSkinParam().getFont(getFontParamForGroup(), null);
sb.append("fontsize=\"" + font.getSize() + "\";");
final String fontFamily = font.getFamily(null);
if (fontFamily != null) {
sb.append("fontname=\"" + fontFamily + "\";");
}
@ -363,11 +370,11 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
sb.append("label=<" + label + ">;");
}
final String fontColor = getData().getSkinParam().getFontHtmlColor(getFontParamForGroup(), null).getAsHtml();
final String fontColor = getAsHtml(getData().getSkinParam().getFontHtmlColor(getFontParamForGroup(), null));
sb.append("fontcolor=\"" + fontColor + "\";");
final HtmlColor groupBackColor = getGroupBackColor(g);
if (groupBackColor != null) {
sb.append("fillcolor=\"" + groupBackColor.getAsHtml() + "\";");
sb.append("fillcolor=\"" + getAsHtml(groupBackColor) + "\";");
}
if (g.getType() == GroupType.STATE) {
sb.append("color=" + getColorString(ColorParam.stateBorder, null) + ";");
@ -537,12 +544,16 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
boolean hasLabel = false;
if (link.getLabel() != null) {
if (link.getLabel() != null && noteLink != null) {
decoration.append("label=<"
+ getHtmlForLinkNote(noteLink.getPngOrEps(fileFormat), manageHtmlIB(link.getLabel(),
getArrowFontParam(), null), link.getNotePosition()) + ">,");
hasLabel = true;
} else if (link.getLabel() != null) {
decoration.append("label=<" + manageHtmlIB(link.getLabel(), getArrowFontParam(), null) + ">,");
hasLabel = true;
} else if (noteLink != null) {
decoration
.append("label=<" + getHtmlForLinkNote(noteLink.getPngOrEps(fileFormat == FileFormat.EPS)) + ">,");
decoration.append("label=<" + getHtmlForLinkNote(noteLink.getPngOrEps(fileFormat)) + ">,");
hasLabel = true;
}
@ -633,14 +644,15 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
if (link.getSpecificColor() == null) {
decoration.append(getColorString(getArrowColorParam(), null));
} else {
decoration.append("\"" + link.getSpecificColor().getAsHtml() + "\"");
decoration.append("\"" + getAsHtml(link.getSpecificColor()) + "\"");
}
decoration.append(",");
decoration.append("fontcolor=" + getFontColorString(getArrowFontParam(), null) + ",");
decoration.append("fontsize=\"" + getData().getSkinParam().getFontSize(getArrowFontParam(), null) + "\",");
final UFont font = getData().getSkinParam().getFont(getArrowFontParam(), null);
decoration.append("fontsize=\"" + font.getSize() + "\",");
final String fontName = getData().getSkinParam().getFontFamily(getArrowFontParam(), null);
final String fontName = font.getFamily(null);
if (fontName != null) {
decoration.append("fontname=\"" + fontName + "\",");
}
@ -666,13 +678,41 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
private String getHtmlForLinkNote(File image) {
final String circleInterfaceAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(image);
final StringBuilder sb = new StringBuilder("<TABLE BORDER=\"0\" CELLBORDER=\"0\" CELLSPACING=\"0\">");
final StringBuilder sb = new StringBuilder();
sb.append("<TABLE BORDER=\"0\" CELLBORDER=\"0\" CELLSPACING=\"0\">");
sb.append("<TR><TD><IMG SRC=\"" + circleInterfaceAbsolutePath + "\"/></TD></TR>");
sb.append("</TABLE>");
return sb.toString();
}
private String getHtmlForLinkNote(File image, String labelHtml, Position position) {
final String imagePath = StringUtils.getPlateformDependentAbsolutePath(image);
final StringBuilder sb = new StringBuilder();
sb.append("<TABLE BORDER=\"0\" CELLBORDER=\"0\" CELLSPACING=\"1\" CELLPADDING=\"0\">");
switch (position) {
case TOP:
sb.append("<TR><TD><IMG SRC=\"" + imagePath + "\"/></TD></TR>");
sb.append("<TR><TD>" + labelHtml + "</TD></TR>");
break;
case RIGHT:
sb.append("<TR><TD><IMG SRC=\"" + imagePath + "\"/></TD>");
sb.append("<TD>" + labelHtml + "</TD></TR>");
break;
case LEFT:
sb.append("<TR><TD>" + labelHtml + "</TD>");
sb.append("<TD><IMG SRC=\"" + imagePath + "\"/></TD></TR>");
break;
default:
sb.append("<TR><TD>" + labelHtml + "</TD></TR>");
sb.append("<TR><TD><IMG SRC=\"" + imagePath + "\"/></TD></TR>");
break;
}
sb.append("</TABLE>");
return sb.toString();
}
private FontParam getArrowFontParam() {
if (getData().getUmlDiagramType() == UmlDiagramType.CLASS) {
return FontParam.CLASS_ARROW;
@ -708,7 +748,7 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
}
private String getFontColorString(FontParam fontParam, String stereotype) {
return "\"" + getFontHtmlColor(fontParam, stereotype).getAsHtml() + "\"";
return "\"" + getAsHtml(getFontHtmlColor(fontParam, stereotype)) + "\"";
}
private void eventuallySameRank(StringBuilder sb, Group entityPackage, Link link) {
@ -727,7 +767,62 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
private boolean MODE_LOLLIPOP_BETA = false;
private void printEntities(StringBuilder sb, Collection<? extends IEntity> entities) throws IOException {
class EntityComparator implements Comparator<IEntity> {
public int compare(IEntity e1, IEntity e2) {
final int xpos1 = e1.getXposition();
final int xpos2 = e2.getXposition();
if (xpos1 < xpos2) {
return -1;
}
if (xpos1 > xpos2) {
return 1;
}
return e1.compareTo(e2);
}
}
class EntityComparator2 implements Comparator<IEntity> {
private final Map<IEntity, Integer> map;
public EntityComparator2(Map<IEntity, Integer> map) {
this.map = map;
}
public int compare(IEntity e1, IEntity e2) {
final Integer b1 = map.get(e1);
final Integer b2 = map.get(e2);
final int cmp = b1.compareTo(b2);
if (cmp != 0) {
return -cmp;
}
return e1.compareTo(e2);
}
}
private Map<IEntity, Integer> getMap(Collection<? extends IEntity> entities2) {
final Map<IEntity, Integer> map = new HashMap<IEntity, Integer>();
for (IEntity ent : entities2) {
map.put(ent, Integer.valueOf(0));
}
for (Link link : getData().getLinks()) {
if (link.isConstraint() == false) {
map.put(link.getEntity2(), Integer.valueOf(1));
} else if (link.getLength() == 1 && link.isInverted()) {
// map.put(link.getEntity2(), true);
map.put(link.getEntity1(), Integer.valueOf(1));
}
}
return map;
}
private void printEntities(StringBuilder sb, Collection<? extends IEntity> entities2) throws IOException {
final List<IEntity> entities = new ArrayList<IEntity>(entities2);
// Collections.sort(entities, new EntityComparator());
// if (getData().getUmlDiagramType() == UmlDiagramType.ACTIVITY) {
Collections.sort(entities, new EntityComparator2(getMap(entities2)));
// }
// Collections.sort(entities);
final Set<IEntity> lollipops = new HashSet<IEntity>();
final Set<IEntity> lollipopsFriends = new HashSet<IEntity>();
for (IEntity entity : entities) {
@ -806,7 +901,8 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
final String color1 = getColorString(ColorParam.classBackground, null);
final String color2 = getColorString(ColorParam.classBorder, null);
final String colorBack = getColorString(ColorParam.background, null);
final String labelLo = manageHtmlIB(entity.getDisplay(), FontParam.CLASS_ATTRIBUTE, null);
final String labelLo = manageHtmlIB(StringUtils.getMergedLines(entity.getDisplay2()),
FontParam.CLASS_ATTRIBUTE, null);
sb.append(entity.getUid() + " [fillcolor=" + color1 + ",color=" + color2 + ",style=\"filled\","
+ "shape=circle,width=0.12,height=0.12,label=\"\"];");
sb.append(entity.getUid() + " -> " + entity.getUid() + "[color=" + colorBack
@ -818,11 +914,11 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
}
static final boolean MODE_MARGIN = true;
static public final boolean MODE_BRANCHE_CLUSTER = true;
static public final boolean MODE_BRANCHE_CLUSTER = false;
private void printEntity(StringBuilder sb, IEntity entity) throws IOException {
final EntityType type = entity.getType();
final String label = getLabel(entity);
final String label = NOLABEL ? "label=\"" + entity.getUid() + "\"" : getLabel(entity);
if (type == EntityType.GROUP) {
return;
}
@ -865,11 +961,10 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
if (file == null) {
throw new IllegalStateException("No file for NOTE");
}
if (file.getPngOrEps(fileFormat == FileFormat.EPS).exists() == false) {
if (file.getPngOrEps(fileFormat).exists() == false) {
throw new IllegalStateException();
}
final String absolutePath = StringUtils.getPlateformDependentAbsolutePath(file
.getPngOrEps(fileFormat == FileFormat.EPS));
final String absolutePath = StringUtils.getPlateformDependentAbsolutePath(file.getPngOrEps(fileFormat));
sb.append(entity.getUid() + " [margin=0,pad=0," + label + ",shape=none,image=\"" + absolutePath + "\"");
} else if (type == EntityType.ACTIVITY) {
String shape = "octagon";
@ -882,7 +977,9 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
} else if (type == EntityType.BRANCH) {
if (MODE_BRANCHE_CLUSTER) {
sb.append("subgraph cluster" + entity.getUid() + "br {");
sb.append("label=<" + manageHtmlIB(entity.getDisplay(), FontParam.ACTIVITY, null) + ">;");
sb.append("label=<"
+ manageHtmlIB(StringUtils.getMergedLines(entity.getDisplay2()), FontParam.ACTIVITY, null)
+ ">;");
sb.append("color=" + getColorString(ColorParam.background, null) + ";");
}
sb.append(entity.getUid() + " [fillcolor=" + getBackColorOfEntity(entity) + ",color="
@ -896,6 +993,10 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
// "[taillabel=\"" + entity.getDisplay()
// + "\",arrowtail=none,arrowhead=none,color=\"white\"];");
// }
} else if (type == EntityType.ASSOCIATION) {
sb.append(entity.getUid() + " [fillcolor=" + getColorString(ColorParam.classBackground, stereo) + ",color="
+ getColorString(ColorParam.classBorder, stereo)
+ ",style=\"filled\",shape=diamond,height=.25,width=.25,label=\"\"");
} else if (type == EntityType.SYNCHRO_BAR) {
final String color = getColorString(ColorParam.activityBar, null);
sb.append(entity.getUid() + " [fillcolor=" + color + ",color=" + color + ",style=\"filled\","
@ -908,6 +1009,9 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
final String color = getColorString(getEndColorParam(), null);
sb.append(entity.getUid() + " [fillcolor=" + color + ",color=" + color + ",style=\"filled\","
+ "shape=doublecircle,width=.13,height=.13,label=\"\"");
} else if (type == EntityType.PSEUDO_STATE) {
final String color = getColorString(getStartColorParam(), null);
sb.append(entity.getUid() + " [color=" + color + "," + "shape=circle,width=.01,height=.01," + label);
} else if (type == EntityType.POINT_FOR_ASSOCIATION) {
sb
.append(entity.getUid() + " [width=.05,shape=point,color="
@ -1023,7 +1127,7 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
final DrawFile drawFile = entity.getImageFile();
if (drawFile != null) {
final String path = StringUtils.getPlateformDependentAbsolutePath(drawFile.getPng());
final String bgcolor = "\"" + getData().getSkinParam().getBackgroundColor().getAsHtml() + "\"";
final String bgcolor = "\"" + getAsHtml(getData().getSkinParam().getBackgroundColor()) + "\"";
final StringBuilder sb = new StringBuilder("label=<");
sb.append("<TABLE BORDER=\"0\" CELLBORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\">");
sb.append("<TR>");
@ -1044,17 +1148,19 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
return "label=" + getLabelForState(entity);
} else if (entity.getType() == EntityType.BRANCH) {
return "label=\"\"";
} else if (entity.getType() == EntityType.PSEUDO_STATE) {
return "label=\"H\"";
}
return "label=\"" + entity.getDisplay() + "\"";
return "label=\"" + StringUtils.getMergedLines(entity.getDisplay2()) + "\"";
}
private String getSimpleLabelAsHtml(IEntity entity, FontParam param, String stereotype) {
return "<" + manageHtmlIB(entity.getDisplay(), param, stereotype) + ">";
return "<" + manageHtmlIB(StringUtils.getMergedLines(entity.getDisplay2()), param, stereotype) + ">";
}
private String getBackColorOfEntity(IEntity entity) {
if (entity.getSpecificBackColor() != null) {
return "\"" + entity.getSpecificBackColor().getAsHtml() + "\"";
return "\"" + getAsHtml(entity.getSpecificBackColor()) + "\"";
}
final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel();
if (entity.getType() == EntityType.STATE || entity.getType() == EntityType.STATE_CONCURRENT) {
@ -1075,7 +1181,9 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
final StringBuilder sb = new StringBuilder("<{<TABLE BGCOLOR=" + stateBgcolor
+ " BORDER=\"0\" CELLBORDER=\"0\" CELLSPACING=\"0\">");
sb.append("<TR><TD>" + manageHtmlIB(entity.getDisplay(), FontParam.STATE, stereotype) + "</TD></TR>");
sb.append("<TR><TD>"
+ manageHtmlIB(StringUtils.getMergedLines(entity.getDisplay2()), FontParam.STATE, stereotype)
+ "</TD></TR>");
sb.append("</TABLE>");
if (entity.getFieldsToDisplay().size() > 0) {
@ -1093,7 +1201,7 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
if (OptionFlags.PBBACK) {
bgcolor = stateBgcolor;
} else {
bgcolor = "\"" + getData().getSkinParam().getBackgroundColor().getAsHtml() + "\"";
bgcolor = "\"" + getAsHtml(getData().getSkinParam().getBackgroundColor()) + "\"";
}
// PBBACK
@ -1124,7 +1232,9 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
sb.append("<TR><TD>" + manageHtmlIB(stereotype.getLabel(), FontParam.USECASE_STEREOTYPE, stereo)
+ "</TD></TR>");
}
sb.append("<TR><TD>" + manageHtmlIB(entity.getDisplay(), FontParam.USECASE, stereo) + "</TD></TR>");
sb.append("<TR><TD>"
+ manageHtmlIB(StringUtils.getMergedLines(entity.getDisplay2()), FontParam.USECASE, stereo)
+ "</TD></TR>");
sb.append("</TABLE>>");
return sb.toString();
}
@ -1140,7 +1250,9 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
sb.append("<TR><TD>" + manageHtmlIB(stereotype.getLabel(), FontParam.COMPONENT_STEREOTYPE, stereo)
+ "</TD></TR>");
}
sb.append("<TR><TD>" + manageHtmlIB(entity.getDisplay(), FontParam.COMPONENT, stereo) + "</TD></TR>");
sb.append("<TR><TD>"
+ manageHtmlIB(StringUtils.getMergedLines(entity.getDisplay2()), FontParam.COMPONENT, stereo)
+ "</TD></TR>");
sb.append("</TABLE>>");
return sb.toString();
}
@ -1150,11 +1262,10 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
if (file == null) {
throw new IllegalStateException("No file for NOTE");
}
if (file.getPngOrEps(fileFormat == FileFormat.EPS).exists() == false) {
if (file.getPngOrEps(fileFormat).exists() == false) {
throw new IllegalStateException();
}
final String absolutePath = StringUtils.getPlateformDependentAbsolutePath(file
.getPngOrEps(fileFormat == FileFormat.EPS));
final String absolutePath = StringUtils.getPlateformDependentAbsolutePath(file.getPngOrEps(fileFormat));
final StringBuilder sb = new StringBuilder("<<TABLE BORDER=\"0\" CELLBORDER=\"0\" CELLSPACING=\"0\">");
sb.append("<TR>");
@ -1166,7 +1277,7 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
private String getLabelForActor(IEntity entity) throws IOException {
final String actorAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(entity.getImageFile()
.getPngOrEps(fileFormat == FileFormat.EPS));
.getPngOrEps(fileFormat));
final Stereotype stereotype = getStereotype(entity);
final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel();
@ -1182,7 +1293,9 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
addTdImageBugB1983(sb, actorAbsolutePath);
sb.append("</TR>");
}
sb.append("<TR><TD>" + manageHtmlIB(entity.getDisplay(), FontParam.USECASE_ACTOR, stereo) + "</TD></TR>");
sb.append("<TR><TD>"
+ manageHtmlIB(StringUtils.getMergedLines(entity.getDisplay2()), FontParam.USECASE_ACTOR, stereo)
+ "</TD></TR>");
sb.append("</TABLE>>");
return sb.toString();
@ -1190,7 +1303,7 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
private String getLabelForCircleInterface(IEntity entity) throws IOException {
final String circleInterfaceAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(entity.getImageFile()
.getPngOrEps(fileFormat == FileFormat.EPS));
.getPngOrEps(fileFormat));
final Stereotype stereotype = getStereotype(entity);
final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel();
@ -1206,7 +1319,9 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
addTdImageBugB1983(sb, circleInterfaceAbsolutePath);
}
sb.append("</TR>");
sb.append("<TR><TD>" + manageHtmlIB(entity.getDisplay(), FontParam.COMPONENT, stereo) + "</TD></TR>");
sb.append("<TR><TD>"
+ manageHtmlIB(StringUtils.getMergedLines(entity.getDisplay2()), FontParam.COMPONENT, stereo)
+ "</TD></TR>");
sb.append("</TABLE>>");
return sb.toString();
@ -1215,7 +1330,7 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
private String getLabelForLollipop(IEntity entity) throws IOException {
final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel();
final String circleInterfaceAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(getData()
.getStaticImages(EntityType.LOLLIPOP, stereo).getPngOrEps(fileFormat == FileFormat.EPS));
.getStaticImages(EntityType.LOLLIPOP, stereo).getPngOrEps(fileFormat));
final Stereotype stereotype = getStereotype(entity);
final StringBuilder sb = new StringBuilder("<<TABLE BORDER=\"0\" CELLBORDER=\"0\" CELLSPACING=\"0\">");
@ -1229,7 +1344,8 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
addTdImageBugB1983(sb, circleInterfaceAbsolutePath);
}
sb.append("</TR>");
sb.append("<TR><TD>" + manageHtmlIB(entity.getDisplay(), FontParam.CLASS, null) + "</TD></TR>");
sb.append("<TR><TD>" + manageHtmlIB(StringUtils.getMergedLines(entity.getDisplay2()), FontParam.CLASS, null)
+ "</TD></TR>");
sb.append("</TABLE>>");
return sb.toString();
@ -1247,8 +1363,7 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
LabelBuilder builder = new LabelBuilderClassOld(getFileFormat(), getData(), entity);
if (MODE_LOLLIPOP_BETA) {
final DrawFile cFile = getData().getStaticImages(entity.getType(), null);
final String northPath = StringUtils.getPlateformDependentAbsolutePath(cFile
.getPngOrEps(getFileFormat() == FileFormat.EPS));
final String northPath = StringUtils.getPlateformDependentAbsolutePath(cFile.getPngOrEps(getFileFormat()));
final String southPath = northPath;
final String eastPath = northPath;
final String westPath = northPath;
@ -1281,12 +1396,12 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
}
texts.add(s);
}
final Font font = getData().getSkinParam().getFont(FontParam.CLASS_ATTRIBUTE, null);
final Color color = getFontHtmlColor(FontParam.CLASS_ATTRIBUTE, null).getColor();
final UFont font = getData().getSkinParam().getFont(FontParam.CLASS_ATTRIBUTE, null);
final HtmlColor color = getFontHtmlColor(FontParam.CLASS_ATTRIBUTE, null);
final TextBlock text = TextBlockUtils.create(texts, new FontConfiguration(font, color),
HorizontalAlignement.LEFT);
final File feps = FileUtils.createTempFile("member", ".eps");
UGraphicEps.copyEpsToFile(new UDrawable() {
UGraphicEps.copyEpsToFile(getData().getColorMapper(), new UDrawable() {
public void drawU(UGraphic ug) {
text.drawU(ug, 0, 0);
}
@ -1356,7 +1471,7 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
return false;
}
public static final String getLastDotSignature() {
private static final String getLastDotSignature() {
return lastDotSignature;
}
@ -1377,4 +1492,8 @@ final public class DotMaker extends DotCommon implements GraphvizMaker {
}
}
public static final boolean isJunit() {
return isJunit;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -36,98 +36,212 @@ package net.sourceforge.plantuml.cucadiagram.dot;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import javax.imageio.ImageIO;
import net.sourceforge.plantuml.FileUtils;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.Log;
import net.sourceforge.plantuml.OptionFlags;
public class DrawFile {
private static final Map<Object, DrawFile> cache = new HashMap<Object, DrawFile>();
private static final Collection<DrawFile> toDelete = new HashSet<DrawFile>();
private final LazyFile png2;
private final LazyCached<String> svg2;
private final LazyFile eps2;
private final String toStringValue;
private final boolean cached;
private final AtomicInteger useCounter = new AtomicInteger(0);
private final AtomicInteger totalUse = new AtomicInteger(0);
private final AtomicBoolean useable = new AtomicBoolean(true);
private int widthPng = -1;
private int heightPng = -1;
static {
addHook();
}
public static boolean isCacheClean() {
synchronized (toDelete) {
for (DrawFile f : toDelete) {
if (f.useCounter.get() != 0) {
Log.error("Remaining " + f);
return false;
}
}
for (DrawFile f : cache.values()) {
if (f.useCounter.get() != 0) {
Log.error("Remaining " + f);
return false;
}
}
}
return true;
}
public static DrawFile create(Lazy<File> png, Lazy<String> svg, Lazy<File> eps, Object signature) {
DrawFile result = null;
if (signature != null) {
result = cache.get(signature);
}
if (result == null) {
result = new DrawFile(png, svg, eps);
synchronized (toDelete) {
if (signature != null) {
cache.put(signature, result);
Log.info("DrawFile cache size = " + cache.size());
result = cache.get(signature);
}
FileUtils.deleteOnExit(result);
if (result == null) {
result = new DrawFile(png, svg, eps, signature == null ? null : signature.toString(), signature != null);
if (signature != null) {
cache.put(signature, result);
Log.info("DrawFile cache size = " + cache.size());
}
deleteOnExit(result);
}
result.useCounter.addAndGet(1);
result.totalUse.addAndGet(1);
// checkCacheSize();
}
return result;
}
private static void checkCacheSize() {
int min = Integer.MAX_VALUE;
for (DrawFile f : cache.values()) {
final int score = f.totalUse.get();
if (score < min) {
min = score;
}
}
for (final Iterator<DrawFile> it = cache.values().iterator(); it.hasNext();) {
final DrawFile f = it.next();
if (f.useCounter.get() == 0 && f.totalUse.get() == min) {
it.remove();
}
}
}
@Override
public String toString() {
if (toStringValue == null) {
return super.toString() + " " + useCounter.get() + " " + totalUse.get();
}
return toStringValue + " " + useCounter.get() + " " + totalUse.get();
}
public static DrawFile createFromFile(File fPng, String svg, File fEps) {
final DrawFile result = new DrawFile(fPng, svg, fEps);
FileUtils.deleteOnExit(result);
final DrawFile result = new DrawFile(fPng, svg, fEps, fPng.getName(), false);
result.useCounter.addAndGet(1);
deleteOnExit(result);
return result;
}
private DrawFile(Lazy<File> png, Lazy<String> svg, Lazy<File> eps) {
private static void deleteOnExit(DrawFile file) {
synchronized (toDelete) {
toDelete.add(file);
}
}
private DrawFile(Lazy<File> png, Lazy<String> svg, Lazy<File> eps, String signature, boolean cached) {
this.png2 = new LazyFile(png);
this.svg2 = new LazyCached<String>(svg);
this.eps2 = new LazyFile(eps);
this.toStringValue = signature;
this.cached = cached;
}
private DrawFile(File fPng, String svg, File fEps) {
this(new Unlazy<File>(fPng), new Unlazy<String>(svg), new Unlazy<File>(fEps));
private DrawFile(File fPng, String svg, File fEps, String signature, boolean cached) {
this(new Unlazy<File>(fPng), new Unlazy<String>(svg), new Unlazy<File>(fEps), signature, cached);
// if (svg.contains("\\")) {
// System.err.println("svg="+svg);
// throw new IllegalArgumentException();
// }
}
public File getPngOrEps(boolean isEps) throws IOException {
if (isEps) {
public File getPngOrEps(FileFormat format) throws IOException {
checkUseable();
if (format.isEps()) {
if (eps2 == null) {
throw new UnsupportedOperationException("No eps for " + getPng().getAbsolutePath());
}
return getEps();
} else {
return getPng();
}
return getPng();
}
private void checkUseable() {
if (useable.get() == false) {
throw new IllegalStateException("Useable false");
}
}
public File getPng() throws IOException {
public synchronized File getPng() throws IOException {
checkUseable();
return png2.getNow();
}
public String getSvg() throws IOException {
public synchronized String getSvg() throws IOException {
checkUseable();
return svg2.getNow();
}
public File getEps() throws IOException {
public synchronized File getEps() throws IOException {
checkUseable();
return eps2.getNow();
}
private void initSize() throws IOException {
private synchronized void initSize() throws IOException {
checkUseable();
final BufferedImage im = ImageIO.read(getPng());
widthPng = im.getWidth();
heightPng = im.getHeight();
}
public void delete() {
Thread.yield();
public synchronized void deleteDrawFile() {
if (useable.get() == false) {
return;
}
// checkUseable();
final int count = useCounter.addAndGet(-1);
if (count == 0) {
if (cached && isCacheTooBig() == false) {
return;
}
synchronized (toDelete) {
deleteNow();
if (cached) {
final boolean removedCache = cache.values().remove(this);
if (removedCache == false) {
Log.error("Not found in cache " + this);
}
}
final boolean removedToDelete = toDelete.remove(this);
if (removedToDelete == false) {
Log.error("Not found in delete list " + this);
}
}
}
}
private static boolean isCacheTooBig() {
return true;
}
private synchronized void deleteNow() {
useable.set(false);
if (png2 != null && png2.isLoaded()) {
try {
Log.info("Deleting temporary file " + getPng());
final boolean ok = getPng().delete();
Log.info("Deleting temporary file " + png2.getNow());
final boolean ok = png2.getNow().delete();
if (ok == false) {
Log.error("Cannot delete: " + getPng());
Log.error("Cannot delete: " + png2.getNow());
}
} catch (IOException e) {
e.printStackTrace();
@ -136,20 +250,20 @@ public class DrawFile {
}
if (eps2 != null && eps2.isLoaded()) {
try {
Log.info("Deleting temporary file " + getEps());
final boolean ok2 = getEps().delete();
Log.info("Deleting temporary file " + eps2.getNow());
final boolean ok2 = eps2.getNow().delete();
if (ok2 == false) {
Log.error("Cannot delete: " + getEps());
Log.error("Cannot delete: " + eps2.getNow());
}
} catch (IOException e) {
e.printStackTrace();
Log.error("Problem deleting EPS file");
}
}
}
public final int getWidthPng() throws IOException {
checkUseable();
if (widthPng == -1) {
initSize();
}
@ -157,18 +271,30 @@ public class DrawFile {
}
public final int getHeightPng() throws IOException {
checkUseable();
if (widthPng == -1) {
initSize();
}
return heightPng;
}
// @Override
// public String toString() {
// if (svg == null) {
// return getPng().toString();
// }
// return png + " " + svg.length();
// }
private static void addHook() {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
if (OptionFlags.getInstance().isKeepTmpFiles() == false) {
synchronized (toDelete) {
for (DrawFile f : toDelete) {
final int cnt = f.useCounter.get();
if (cnt != 0) {
Log.info("Warning: useCounter " + cnt + " for " + f);
}
f.deleteNow();
}
}
}
}
});
}
}

View File

@ -43,12 +43,13 @@ import javax.imageio.ImageIO;
import net.sourceforge.plantuml.EmptyImageBuilder;
import net.sourceforge.plantuml.FileUtils;
import net.sourceforge.plantuml.skin.UDrawable;
import net.sourceforge.plantuml.ugraphic.ColorMapper;
import net.sourceforge.plantuml.ugraphic.eps.UGraphicEps;
import net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d;
public class DrawFileFactory {
public static DrawFile create(final UDrawable drawable, final double width, final double height,
public static DrawFile create(final ColorMapper colorMapper, final UDrawable drawable, final double width, final double height,
final double dpiFactor, final Color backgground, Object signature) {
final Lazy<File> lpng = new Lazy<File>() {
@ -57,7 +58,7 @@ public class DrawFileFactory {
final EmptyImageBuilder builder = new EmptyImageBuilder(width * dpiFactor, height * dpiFactor,
backgground);
final BufferedImage im = builder.getBufferedImage();
drawable.drawU(new UGraphicG2d(builder.getGraphics2D(), im, dpiFactor));
drawable.drawU(new UGraphicG2d(colorMapper, builder.getGraphics2D(), im, dpiFactor));
ImageIO.write(im, "png", png);
return png;
}
@ -66,14 +67,14 @@ public class DrawFileFactory {
final Lazy<File> leps = new Lazy<File>() {
public File getNow() throws IOException {
final File eps = FileUtils.createTempFile("visi", ".eps");
UGraphicEps.copyEpsToFile(drawable, eps);
UGraphicEps.copyEpsToFile(colorMapper, drawable, eps);
return eps;
}
};
final Lazy<String> lsvg = new Lazy<String>() {
public String getNow() throws IOException {
return UGraphicG2d.getSvgString(drawable);
return UGraphicG2d.getSvgString(colorMapper, drawable);
}
};

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4826 $
* Revision $Revision: 6711 $
*
*/
package net.sourceforge.plantuml.cucadiagram.dot;
@ -39,9 +39,11 @@ import java.io.OutputStream;
public interface Graphviz {
void createPng(OutputStream os) throws IOException, InterruptedException;
void createFile(OutputStream os) throws IOException, InterruptedException;
File getDotExe();
String dotVersion() throws IOException, InterruptedException;
String testFile(String dotfilename, String outfile) throws IOException, InterruptedException;
}

View File

@ -0,0 +1,113 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* 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 Lesser 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.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6711 $
*
*/
package net.sourceforge.plantuml.cucadiagram.dot;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.List;
import net.sourceforge.plantuml.FileUtils;
import net.sourceforge.plantuml.Log;
import net.sourceforge.plantuml.SignatureUtils;
public class GraphvizCached implements Graphviz {
private final AbstractGraphviz graphviz;
public GraphvizCached(AbstractGraphviz graphviz) {
this.graphviz = graphviz;
}
public void createFile(OutputStream os) throws IOException, InterruptedException {
final File f = getCachedFile();
if (f.exists()) {
Log.info("Using " + f);
FileUtils.copyToStream(f, os);
return;
}
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
graphviz.createFile(baos);
baos.close();
final byte data[] = baos.toByteArray();
Log.info("Creating " + f);
final OutputStream fos = new BufferedOutputStream(new FileOutputStream(f));
fos.write(data);
fos.close();
final InputStream is = new ByteArrayInputStream(data);
FileUtils.copyToStream(is, os);
is.close();
}
private File getCachedFile() throws FileNotFoundException {
final String dot = graphviz.getDotString();
final List<String> types = graphviz.getType();
final String sign = SignatureUtils.getSignature(dot + types);
final File source = new File("__graphviz", sign + ".txt");
source.getParentFile().mkdirs();
final PrintWriter pw = new PrintWriter(source);
pw.println(types.toString());
pw.println(dot);
pw.close();
final File result = new File("__graphviz", sign);
result.getParentFile().mkdirs();
return result;
}
public String dotVersion() throws IOException, InterruptedException {
return graphviz.dotVersion();
}
public File getDotExe() {
return graphviz.getDotExe();
}
public String testFile(String dotfilename, String outfile) throws IOException, InterruptedException {
return graphviz.testFile(dotfilename, outfile);
}
}

View File

@ -28,23 +28,28 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 6200 $
* Revision $Revision: 6713 $
*
*/
package net.sourceforge.plantuml.cucadiagram.dot;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import net.sourceforge.plantuml.OptionFlags;
import net.sourceforge.plantuml.StringUtils;
public class GraphvizUtils {
private static final String TMP_TEST_FILENAME = "testdottmp42";
private static int DOT_VERSION_LIMIT = 226;
private static boolean isWindows() {
@ -53,15 +58,22 @@ public class GraphvizUtils {
@Deprecated
public static Graphviz create(String dotString, String... type) {
final AbstractGraphviz result;
if (isWindows()) {
return new GraphvizWindows(dotString, type);
result = new GraphvizWindows(dotString, type);
} else {
result = new GraphvizLinux(dotString, type);
}
return new GraphvizLinux(dotString, type);
if (OptionFlags.GRAPHVIZCACHE && DotMaker.isJunit()) {
return new GraphvizCached(result);
}
return result;
}
public static Graphviz create2(GraphvizLayoutStrategy strategy, String dotString, String... type) {
return new AbstractGraphviz2(getOS(), strategy, dotString, type);
}
// public static Graphviz create2(GraphvizLayoutStrategy strategy, String
// dotString, String... type) {
// return new AbstractGraphviz2(getOS(), strategy, dotString, type);
// }
static public File getDotExe() {
return create(null, "png").getDotExe();
@ -75,6 +87,14 @@ public class GraphvizUtils {
return System.getenv("GRAPHVIZ_DOT");
}
public static String getenvLogData() {
final String env = System.getProperty("PLANTUML_LOGDATA");
if (StringUtils.isNotEmpty(env)) {
return env;
}
return System.getenv("PLANTUML_LOGDATA");
}
private static String dotVersion = null;
public static String dotVersion() throws IOException, InterruptedException {
@ -154,10 +174,16 @@ public class GraphvizUtils {
result.add(bold + "Warning : Your dot installation seems old");
result.add(bold + "Some diagrams may have issues");
} else {
result.add(bold + "Installation seems OK");
String err = getTestCreateSimpleFile();
if (err == null) {
result.add(bold + "Installation seems OK. PNG generation OK");
} else {
result.add(red + err);
}
}
}
} catch (Exception e) {
result.add(red + e.toString());
e.printStackTrace();
}
} else {
@ -166,7 +192,36 @@ public class GraphvizUtils {
return Collections.unmodifiableList(result);
}
static String getTestCreateSimpleFile() throws IOException, InterruptedException {
final Graphviz graphviz = GraphvizUtils.create("", "png");
final File f = new File(TMP_TEST_FILENAME + ".dot");
final File fout = new File(TMP_TEST_FILENAME + ".png");
f.delete();
fout.delete();
try {
final PrintWriter pw = new PrintWriter(f);
pw.println("digraph foo { test; }");
pw.close();
graphviz.testFile(f.getName(), fout.getName());
f.delete();
if (fout.exists() == false) {
return "Error: dot cannot generated PNG file. Check you dot installation.";
}
if (fout.length() == 0) {
return "Error: dot generates empty PNG file. Check you dot installation.";
}
try {
ImageIO.read(fout);
} catch (IOException e) {
return "Error: dot generates unreadable PNG file. Check you dot installation.";
}
return null;
} finally {
fout.delete();
}
}
public static OS getOS() {
if (isWindows()) {
return new OSWindows();

Some files were not shown because too many files have changed in this diff Show More