diff --git a/src/net/sourceforge/plantuml/AbstractPSystem.java b/src/net/sourceforge/plantuml/AbstractPSystem.java index d071c4e5b..27eb16ad9 100644 --- a/src/net/sourceforge/plantuml/AbstractPSystem.java +++ b/src/net/sourceforge/plantuml/AbstractPSystem.java @@ -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 exportDiagrams(File suggestedFile, FileFormatOption fileFormat) throws IOException, InterruptedException { + + public List 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 getTitle() { + if (source == null) { + return Collections.emptyList(); + } + return source.getTitle(); + } + } diff --git a/src/net/sourceforge/plantuml/AlignParam.java b/src/net/sourceforge/plantuml/AlignParam.java new file mode 100644 index 000000000..a3d372dc6 --- /dev/null +++ b/src/net/sourceforge/plantuml/AlignParam.java @@ -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; + } +} diff --git a/src/net/sourceforge/plantuml/BlockUmlBuilder.java b/src/net/sourceforge/plantuml/BlockUmlBuilder.java index 724cf59b2..68f5aa11d 100644 --- a/src/net/sourceforge/plantuml/BlockUmlBuilder.java +++ b/src/net/sourceforge/plantuml/BlockUmlBuilder.java @@ -52,10 +52,10 @@ final public class BlockUmlBuilder { private final List blocks = new ArrayList(); private final Set usedFiles = new HashSet(); - public BlockUmlBuilder(List config, Defines defines, Reader reader) throws IOException { + public BlockUmlBuilder(List 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) { diff --git a/src/net/sourceforge/plantuml/ColorParam.java b/src/net/sourceforge/plantuml/ColorParam.java index b89060580..bc5d63b35 100644 --- a/src/net/sourceforge/plantuml/ColorParam.java +++ b/src/net/sourceforge/plantuml/ColorParam.java @@ -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), diff --git a/src/net/sourceforge/plantuml/Dimension2DDouble.java b/src/net/sourceforge/plantuml/Dimension2DDouble.java index 5535193b3..0e81d6d06 100644 --- a/src/net/sourceforge/plantuml/Dimension2DDouble.java +++ b/src/net/sourceforge/plantuml/Dimension2DDouble.java @@ -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); + } + } diff --git a/src/net/sourceforge/plantuml/DirWatcher.java b/src/net/sourceforge/plantuml/DirWatcher.java index 48d8aca46..a3e55edb2 100644 --- a/src/net/sourceforge/plantuml/DirWatcher.java +++ b/src/net/sourceforge/plantuml/DirWatcher.java @@ -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 buildCreatedFiles() throws IOException, InterruptedException { + boolean error = false; final List result = new ArrayList(); - process(dir, result); - Collections.sort(result); - return Collections.unmodifiableList(result); - } - - private void process(File dirToProcess, final List 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) { diff --git a/src/net/sourceforge/plantuml/DirWatcher2.java b/src/net/sourceforge/plantuml/DirWatcher2.java new file mode 100644 index 000000000..be676b45c --- /dev/null +++ b/src/net/sourceforge/plantuml/DirWatcher2.java @@ -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 modifieds = new ConcurrentHashMap(); + 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>> buildCreatedFiles() throws IOException, InterruptedException { + final Map>> result = new TreeMap>>(); + 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> value = executorService.submit(new Callable>() { + public List call() throws Exception { + try { + final List generatedImages = sourceFileReader.getGeneratedImages(); + final Set files = new HashSet(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); + } + +} diff --git a/src/net/sourceforge/plantuml/Direction.java b/src/net/sourceforge/plantuml/Direction.java index 67c829f5b..f09e4bab5 100644 --- a/src/net/sourceforge/plantuml/Direction.java +++ b/src/net/sourceforge/plantuml/Direction.java @@ -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; + } } diff --git a/src/net/sourceforge/plantuml/FileFormat.java b/src/net/sourceforge/plantuml/FileFormat.java index d8390e686..dd4dc9de6 100644 --- a/src/net/sourceforge/plantuml/FileFormat.java +++ b/src/net/sourceforge/plantuml/FileFormat.java @@ -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()); + } + } diff --git a/src/net/sourceforge/plantuml/FileSystem.java b/src/net/sourceforge/plantuml/FileSystem.java index 62e5757bd..184182149 100644 --- a/src/net/sourceforge/plantuml/FileSystem.java +++ b/src/net/sourceforge/plantuml/FileSystem.java @@ -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 currentDir = new ThreadLocal(); 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() { diff --git a/src/net/sourceforge/plantuml/FileUtils.java b/src/net/sourceforge/plantuml/FileUtils.java index 263f7c990..467b35644 100644 --- a/src/net/sourceforge/plantuml/FileUtils.java +++ b/src/net/sourceforge/plantuml/FileUtils.java @@ -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 toDelete = new ArrayList(); + 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(); + } + } diff --git a/src/net/sourceforge/plantuml/FileWatcher.java b/src/net/sourceforge/plantuml/FileWatcher.java index 010b62015..ea2ef21c8 100644 --- a/src/net/sourceforge/plantuml/FileWatcher.java +++ b/src/net/sourceforge/plantuml/FileWatcher.java @@ -43,11 +43,19 @@ public class FileWatcher { private final Map modified2 = new HashMap(); public FileWatcher(Set 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 ent : modified2.entrySet()) { final long nowModified = ent.getKey().lastModified(); diff --git a/src/net/sourceforge/plantuml/FontParam.java b/src/net/sourceforge/plantuml/FontParam.java index 8773e1ec9..89e24b2fb 100644 --- a/src/net/sourceforge/plantuml/FontParam.java +++ b/src/net/sourceforge/plantuml/FontParam.java @@ -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; } diff --git a/src/net/sourceforge/plantuml/GeneratedImage.java b/src/net/sourceforge/plantuml/GeneratedImage.java index b7343ace2..dd086a6f7 100644 --- a/src/net/sourceforge/plantuml/GeneratedImage.java +++ b/src/net/sourceforge/plantuml/GeneratedImage.java @@ -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 { 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 { return description; } + public boolean isError() { + return system instanceof PSystemError; + } + @Override public String toString() { return pngFile.getAbsolutePath() + " " + description; diff --git a/src/net/sourceforge/plantuml/ISkinParam.java b/src/net/sourceforge/plantuml/ISkinParam.java index e2552dec2..39b0b4d17 100644 --- a/src/net/sourceforge/plantuml/ISkinParam.java +++ b/src/net/sourceforge/plantuml/ISkinParam.java @@ -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(); diff --git a/src/net/sourceforge/plantuml/ISourceFileReader.java b/src/net/sourceforge/plantuml/ISourceFileReader.java new file mode 100644 index 000000000..cebb2a2a9 --- /dev/null +++ b/src/net/sourceforge/plantuml/ISourceFileReader.java @@ -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 getGeneratedImages() throws IOException, InterruptedException; + + public List getEncodedUrl() throws IOException, InterruptedException; + + public boolean hasError() throws IOException, InterruptedException; + + + +} diff --git a/src/net/sourceforge/plantuml/LanguageDescriptor.java b/src/net/sourceforge/plantuml/LanguageDescriptor.java index c9e02dd91..f8eb075eb 100644 --- a/src/net/sourceforge/plantuml/LanguageDescriptor.java +++ b/src/net/sourceforge/plantuml/LanguageDescriptor.java @@ -104,6 +104,7 @@ public class LanguageDescriptor { keyword.add("header"); keyword.add("center"); keyword.add("rotate"); + keyword.add("ref"); preproc.add("!include"); diff --git a/src/net/sourceforge/plantuml/Log.java b/src/net/sourceforge/plantuml/Log.java index 3396b32ad..7cb8809ee 100644 --- a/src/net/sourceforge/plantuml/Log.java +++ b/src/net/sourceforge/plantuml/Log.java @@ -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); } diff --git a/src/net/sourceforge/plantuml/MathUtils.java b/src/net/sourceforge/plantuml/MathUtils.java new file mode 100644 index 000000000..8bbc8077a --- /dev/null +++ b/src/net/sourceforge/plantuml/MathUtils.java @@ -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); + } + +} diff --git a/src/net/sourceforge/plantuml/Option.java b/src/net/sourceforge/plantuml/Option.java index ab9e910fb..39b105da1 100644 --- a/src/net/sourceforge/plantuml/Option.java +++ b/src/net/sourceforge/plantuml/Option.java @@ -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 result = new ArrayList(); 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; + } + } diff --git a/src/net/sourceforge/plantuml/OptionFlags.java b/src/net/sourceforge/plantuml/OptionFlags.java index d6a2fafbc..9c2f8890f 100644 --- a/src/net/sourceforge/plantuml/OptionFlags.java +++ b/src/net/sourceforge/plantuml/OptionFlags.java @@ -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; + } + } diff --git a/src/net/sourceforge/plantuml/OptionPrint.java b/src/net/sourceforge/plantuml/OptionPrint.java index d217b2fd0..b8360e3a1 100644 --- a/src/net/sourceforge/plantuml/OptionPrint.java +++ b/src/net/sourceforge/plantuml/OptionPrint.java @@ -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(); diff --git a/src/net/sourceforge/plantuml/PSystem.java b/src/net/sourceforge/plantuml/PSystem.java index 86140bf75..d8021a7dd 100644 --- a/src/net/sourceforge/plantuml/PSystem.java +++ b/src/net/sourceforge/plantuml/PSystem.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6302 $ + * Revision $Revision: 6513 $ * */ package net.sourceforge.plantuml; diff --git a/src/net/sourceforge/plantuml/PSystemBuilder.java b/src/net/sourceforge/plantuml/PSystemBuilder.java index dca80fc64..96804d942 100644 --- a/src/net/sourceforge/plantuml/PSystemBuilder.java +++ b/src/net/sourceforge/plantuml/PSystemBuilder.java @@ -64,6 +64,31 @@ public class PSystemBuilder { final public PSystem createPSystem(final List strings) throws IOException, InterruptedException { + final List factories = getAllFactories(); + + final UmlSource umlSource = new UmlSource(strings); + final DiagramType diagramType = umlSource.getDiagramType(); + final List errors = new ArrayList(); + 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 getAllFactories() { final List factories = new ArrayList(); 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 errors = new ArrayList(); - 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 ps) { diff --git a/src/net/sourceforge/plantuml/PSystemError.java b/src/net/sourceforge/plantuml/PSystemError.java index 658794385..c08dfc348 100644 --- a/src/net/sourceforge/plantuml/PSystemError.java +++ b/src/net/sourceforge/plantuml/PSystemError.java @@ -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 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(" " + er); plainStrings.add(" " + er); } + boolean first = true; + for (String s : getSuggest()) { + if (first) { + htmlStrings.add(" " + s); + } else { + htmlStrings.add("" + StringUtils.hideComparatorCharacters(s)); + } + first = false; + } + } + + public List getSuggest() { boolean suggested = false; for (ErrorUml er : printedErrors) { if (er.hasSuggest()) { suggested = true; } } - if (suggested) { - htmlStrings.add(" Did you mean:"); - for (ErrorUml er : printedErrors) { - if (er.hasSuggest()) { - htmlStrings.add("" - + StringUtils.hideComparatorCharacters(er.getSuggest().getSuggestedLine())); - } + if (suggested == false) { + return Collections.emptyList(); + } + final List result = new ArrayList(); + result.add("Did you mean:"); + for (ErrorUml er : printedErrors) { + if (er.hasSuggest()) { + result.add(er.getSuggest().getSuggestedLine()); } } + return Collections.unmodifiableList(result); + } private Collection getErrors(ErrorUmlType type, List 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)); + } } } diff --git a/src/net/sourceforge/plantuml/PSystemFactory.java b/src/net/sourceforge/plantuml/PSystemFactory.java index b17f70f5b..bc659c5e8 100644 --- a/src/net/sourceforge/plantuml/PSystemFactory.java +++ b/src/net/sourceforge/plantuml/PSystemFactory.java @@ -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(); diff --git a/src/net/sourceforge/plantuml/PSystemSingleBuilder.java b/src/net/sourceforge/plantuml/PSystemSingleBuilder.java index 7a378a591..ddc555fe2 100644 --- a/src/net/sourceforge/plantuml/PSystemSingleBuilder.java +++ b/src/net/sourceforge/plantuml/PSystemSingleBuilder.java @@ -53,6 +53,7 @@ final public class PSystemSingleBuilder { private final Iterator 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) { diff --git a/src/net/sourceforge/plantuml/Run.java b/src/net/sourceforge/plantuml/Run.java index 6279210bb..f8c25319c 100644 --- a/src/net/sourceforge/plantuml/Run.java +++ b/src/net/sourceforge/plantuml/Run.java @@ -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 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 urls = sourceFileReader.getEncodedUrl(); + for (String s : urls) { + System.out.println(s); + } + return false; + } else if (option.isCheckOnly()) { + return sourceFileReader.hasError(); + } + final List 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; } } diff --git a/src/net/sourceforge/plantuml/SkinParam.java b/src/net/sourceforge/plantuml/SkinParam.java index 1388bb693..f0f64fe3f 100644 --- a/src/net/sourceforge/plantuml/SkinParam.java +++ b/src/net/sourceforge/plantuml/SkinParam.java @@ -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(); + } + } diff --git a/src/net/sourceforge/plantuml/SkinParamBackcolored.java b/src/net/sourceforge/plantuml/SkinParamBackcolored.java index bb077968e..4e21590c5 100644 --- a/src/net/sourceforge/plantuml/SkinParamBackcolored.java +++ b/src/net/sourceforge/plantuml/SkinParamBackcolored.java @@ -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(); + } + } diff --git a/src/net/sourceforge/plantuml/SkinParamBackcoloredReference.java b/src/net/sourceforge/plantuml/SkinParamBackcoloredReference.java new file mode 100644 index 000000000..b47af959a --- /dev/null +++ b/src/net/sourceforge/plantuml/SkinParamBackcoloredReference.java @@ -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(); + } + +} diff --git a/src/net/sourceforge/plantuml/SourceFileReader.java b/src/net/sourceforge/plantuml/SourceFileReader.java index 48805214c..9ee570a85 100644 --- a/src/net/sourceforge/plantuml/SourceFileReader.java +++ b/src/net/sourceforge/plantuml/SourceFileReader.java @@ -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. emptyList(), null, new FileFormatOption(FileFormat.PNG)); + this(new Defines(), file, outputDirectory, Collections. 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. 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 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 getIncludedFiles() { return builder.getIncludedFiles(); } - } diff --git a/src/net/sourceforge/plantuml/SourceFileReader2.java b/src/net/sourceforge/plantuml/SourceFileReader2.java new file mode 100644 index 000000000..32a9a0705 --- /dev/null +++ b/src/net/sourceforge/plantuml/SourceFileReader2.java @@ -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 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 getGeneratedImages() throws IOException, InterruptedException { + Log.info("Reading file: " + file); + + final List result = new ArrayList(); + + 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 getEncodedUrl() throws IOException, InterruptedException { + final List result = new ArrayList(); + 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 getIncludedFiles() { + return builder.getIncludedFiles(); + } + +} diff --git a/src/net/sourceforge/plantuml/SourceStringReader.java b/src/net/sourceforge/plantuml/SourceStringReader.java index 6d247ff0a..92517e5df 100644 --- a/src/net/sourceforge/plantuml/SourceStringReader.java +++ b/src/net/sourceforge/plantuml/SourceStringReader.java @@ -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 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; } diff --git a/src/net/sourceforge/plantuml/SpecificBackcolorable.java b/src/net/sourceforge/plantuml/SpecificBackcolorable.java index 5c7e6ec50..18f96a647 100644 --- a/src/net/sourceforge/plantuml/SpecificBackcolorable.java +++ b/src/net/sourceforge/plantuml/SpecificBackcolorable.java @@ -39,6 +39,6 @@ public interface SpecificBackcolorable { public HtmlColor getSpecificBackColor(); - public void setSpecificBackcolor(String specificBackcolor); + public void setSpecificBackcolor(HtmlColor specificBackcolor); } \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/StringUtils.java b/src/net/sourceforge/plantuml/StringUtils.java index e55b2bd44..f58a8fa9a 100644 --- a/src/net/sourceforge/plantuml/StringUtils.java +++ b/src/net/sourceforge/plantuml/StringUtils.java @@ -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 strings) { + public static String getMergedLines(List 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 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 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 result = new ArrayList(); + 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 manageEmbededDiagrams(final List strings) { + final List result = new ArrayList(); + final Iterator it = strings.iterator(); + while (it.hasNext()) { + CharSequence s = it.next(); + if (s.equals("{{")) { + final List other = new ArrayList(); + 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; + } + + + } diff --git a/src/net/sourceforge/plantuml/UmlDiagram.java b/src/net/sourceforge/plantuml/UmlDiagram.java index bca870381..b961eaed1 100644 --- a/src/net/sourceforge/plantuml/UmlDiagram.java +++ b/src/net/sourceforge/plantuml/UmlDiagram.java @@ -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 title; + private List title; private List header; private List 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 strings) { + final public void setTitle(List strings) { this.title = strings; } - final public List getTitle() { + final public List 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 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 flashcodes) throws IOException; @@ -217,9 +235,6 @@ public abstract class UmlDiagram extends AbstractPSystem implements PSystem { return name.replaceAll("(?i)\\.\\w{3}$", ".cmapx"); } - - - private List 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; } - - } diff --git a/src/net/sourceforge/plantuml/UmlSource.java b/src/net/sourceforge/plantuml/UmlSource.java index ec9f12186..0e947ead0 100644 --- a/src/net/sourceforge/plantuml/UmlSource.java +++ b/src/net/sourceforge/plantuml/UmlSource.java @@ -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 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(); + } + } diff --git a/src/net/sourceforge/plantuml/UniqueSequence.java b/src/net/sourceforge/plantuml/UniqueSequence.java index 50c329fd4..646181448 100644 --- a/src/net/sourceforge/plantuml/UniqueSequence.java +++ b/src/net/sourceforge/plantuml/UniqueSequence.java @@ -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); } } diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandElse.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandElse.java index 98719cd95..cbfbbffe7 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandElse.java +++ b/src/net/sourceforge/plantuml/activitydiagram/command/CommandElse.java @@ -51,6 +51,9 @@ public class CommandElse extends SingleLineCommand { 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); diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandEndif.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandEndif.java index ae51eec5b..e75aa0528 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandEndif.java +++ b/src/net/sourceforge/plantuml/activitydiagram/command/CommandEndif.java @@ -50,6 +50,9 @@ public class CommandEndif extends SingleLineCommand { 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(); diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkActivity.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkActivity.java index 3a34fe133..c421cdfa1 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkActivity.java +++ b/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkActivity.java @@ -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 { @@ -97,7 +98,7 @@ public class CommandLinkActivity extends SingleLineCommand2 { 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 { 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))); diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkLongActivity.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkLongActivity.java index f6bd37c58..1f2e0fe46 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkLongActivity.java +++ b/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkLongActivity.java @@ -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 { @@ -91,7 +92,7 @@ public class CommandLinkLongActivity extends CommandMultilines2 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 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) { diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandMultilinesNoteActivityLink.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandMultilinesNoteActivityLink.java index 6b888f863..151cdf976 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandMultilinesNoteActivityLink.java +++ b/src/net/sourceforge/plantuml/activitydiagram/command/CommandMultilinesNoteActivityLink.java @@ -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 { @@ -50,13 +51,13 @@ public class CommandMultilinesNoteActivityLink extends CommandMultilines lines) { final List 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(); } diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandNoteOnActivityLink.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandNoteOnActivityLink.java index 924cf7878..d8cf0c2c4 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandNoteOnActivityLink.java +++ b/src/net/sourceforge/plantuml/activitydiagram/command/CommandNoteOnActivityLink.java @@ -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 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 bars = new HashMap(); public void bar(String bar) { + final Direction direction = Direction.DOWN; if (bars.containsKey(bar)) { final IEntity existingBar = bars.get(bar); for (Iterator 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); } } diff --git a/src/net/sourceforge/plantuml/activitydiagram2/ActivityDiagramFactory2.java b/src/net/sourceforge/plantuml/activitydiagram2/ActivityDiagramFactory2.java index 5df1311e4..0200ba310 100644 --- a/src/net/sourceforge/plantuml/activitydiagram2/ActivityDiagramFactory2.java +++ b/src/net/sourceforge/plantuml/activitydiagram2/ActivityDiagramFactory2.java @@ -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)); diff --git a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandEnd2.java b/src/net/sourceforge/plantuml/activitydiagram2/command/CommandEnd2.java index 59510be43..8bb9fa327 100644 --- a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandEnd2.java +++ b/src/net/sourceforge/plantuml/activitydiagram2/command/CommandEnd2.java @@ -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 { } 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 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(); } diff --git a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandNewActivity2.java b/src/net/sourceforge/plantuml/activitydiagram2/command/CommandNewActivity2.java index c5820d995..975b6648c 100644 --- a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandNewActivity2.java +++ b/src/net/sourceforge/plantuml/activitydiagram2/command/CommandNewActivity2.java @@ -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 { 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 { 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(); } - } diff --git a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandNewMultilinesActivity2.java b/src/net/sourceforge/plantuml/activitydiagram2/command/CommandNewMultilinesActivity2.java index 33e9eea79..d28819668 100644 --- a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandNewMultilinesActivity2.java +++ b/src/net/sourceforge/plantuml/activitydiagram2/command/CommandNewMultilinesActivity2.java @@ -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 { 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 lines) { @@ -56,14 +57,15 @@ public class CommandNewMultilinesActivity2 extends CommandMultilines") || 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(); } diff --git a/src/net/sourceforge/plantuml/ant/PlantUmlTask.java b/src/net/sourceforge/plantuml/ant/PlantUmlTask.java index ac803e3c3..b850b99d4 100644 --- a/src/net/sourceforge/plantuml/ant/PlantUmlTask.java +++ b/src/net/sourceforge/plantuml/ant/PlantUmlTask.java @@ -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 filesets = new ArrayList(); private List filelists = new ArrayList(); + 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 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() { + 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 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 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); + } + } diff --git a/src/net/sourceforge/plantuml/ant/PlantuTask.java b/src/net/sourceforge/plantuml/ant/PlantuTask.java deleted file mode 100644 index 2a8593379..000000000 --- a/src/net/sourceforge/plantuml/ant/PlantuTask.java +++ /dev/null @@ -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; - -// -// -// -// -// -// -// -// -// - -// Carriage Return in UTF-8 XML: -// Line Feed in UTF-8 XML: -public class PlantuTask extends Task { - - private String dir = null; - private final Option option = new Option(); - private List filesets = new ArrayList(); - private List filelists = new ArrayList(); - - /** - * 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 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 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); - } - } - - -} diff --git a/src/net/sourceforge/plantuml/asciiart/TextStringBounder.java b/src/net/sourceforge/plantuml/asciiart/TextStringBounder.java index 407d6e753..cdf202e66 100644 --- a/src/net/sourceforge/plantuml/asciiart/TextStringBounder.java +++ b/src/net/sourceforge/plantuml/asciiart/TextStringBounder.java @@ -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); } diff --git a/src/net/sourceforge/plantuml/classdiagram/ClassDiagramFactory.java b/src/net/sourceforge/plantuml/classdiagram/ClassDiagramFactory.java index 105b770f7..f61d24a84 100644 --- a/src/net/sourceforge/plantuml/classdiagram/ClassDiagramFactory.java +++ b/src/net/sourceforge/plantuml/classdiagram/ClassDiagramFactory.java @@ -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)); diff --git a/src/net/sourceforge/plantuml/eps/InkscapeWindows.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandDiamondAssociation.java similarity index 59% rename from src/net/sourceforge/plantuml/eps/InkscapeWindows.java rename to src/net/sourceforge/plantuml/classdiagram/command/CommandDiamondAssociation.java index 9a68cd51d..4a6c2cfa8 100644 --- a/src/net/sourceforge/plantuml/eps/InkscapeWindows.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandDiamondAssociation.java @@ -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 { - 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 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(); + } } diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass2.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass2.java index dafb02342..71e2c5233 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass2.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass2.java @@ -74,9 +74,9 @@ final public class CommandLinkClass2 extends SingleLineCommand2*+]|\\|[>\\]])?)"), + "(([-=.]+)(?:(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")) { return new LinkType(LinkDecor.EXTENDS, LinkDecor.NONE); } + if (k.equals("^")) { + return new LinkType(LinkDecor.EXTENDS, LinkDecor.NONE); + } // return null; throw new IllegalArgumentException(k); } diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkLollipop.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkLollipop.java deleted file mode 100644 index 606094695..000000000 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkLollipop.java +++ /dev/null @@ -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 { - - 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*+]|\\|[>\\]])?)|(([\\[))" - + "(?:\\(\\)([-=.]+)|([-=.]+)\\(\\))" - + "\\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 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 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 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 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 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 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(); - } - -} diff --git a/src/net/sourceforge/plantuml/code/CompressionZlib.java b/src/net/sourceforge/plantuml/code/CompressionZlib.java index 29b6b8535..d3d06266b 100644 --- a/src/net/sourceforge/plantuml/code/CompressionZlib.java +++ b/src/net/sourceforge/plantuml/code/CompressionZlib.java @@ -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()); } } diff --git a/src/net/sourceforge/plantuml/command/AbstractCommandMultilinesNoteEntity.java b/src/net/sourceforge/plantuml/command/AbstractCommandMultilinesNoteEntity.java index d5fb44f21..ebc46658f 100644 --- a/src/net/sourceforge/plantuml/command/AbstractCommandMultilinesNoteEntity.java +++ b/src/net/sourceforge/plantuml/command/AbstractCommandMultilinesNoteEntity.java @@ -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 { @@ -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()); diff --git a/src/net/sourceforge/plantuml/command/AbstractUmlSystemCommandFactory.java b/src/net/sourceforge/plantuml/command/AbstractUmlSystemCommandFactory.java index ed172a0cb..1f33d5cb7 100644 --- a/src/net/sourceforge/plantuml/command/AbstractUmlSystemCommandFactory.java +++ b/src/net/sourceforge/plantuml/command/AbstractUmlSystemCommandFactory.java @@ -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 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 cmds = new ArrayList(); final public CommandControl isValid(List 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(); initCommands(); } diff --git a/src/net/sourceforge/plantuml/command/CommandCreateNote.java b/src/net/sourceforge/plantuml/command/CommandCreateNote.java index bd1a43b50..1a4463c2b 100644 --- a/src/net/sourceforge/plantuml/command/CommandCreateNote.java +++ b/src/net/sourceforge/plantuml/command/CommandCreateNote.java @@ -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 { @@ -51,7 +52,7 @@ public class CommandCreateNote extends SingleLineCommand 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(); } diff --git a/src/net/sourceforge/plantuml/command/CommandMultilinesStandaloneNote.java b/src/net/sourceforge/plantuml/command/CommandMultilinesStandaloneNote.java index 8ee643f4f..11f6a3ba8 100644 --- a/src/net/sourceforge/plantuml/command/CommandMultilinesStandaloneNote.java +++ b/src/net/sourceforge/plantuml/command/CommandMultilinesStandaloneNote.java @@ -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 { @@ -54,7 +55,7 @@ public class CommandMultilinesStandaloneNote extends CommandMultilines { public CommandExecutionResult execute(List lines) { final List 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"); diff --git a/src/net/sourceforge/plantuml/command/CommandNoteEntity.java b/src/net/sourceforge/plantuml/command/CommandNoteEntity.java index bc3db1894..10af25337 100644 --- a/src/net/sourceforge/plantuml/command/CommandNoteEntity.java +++ b/src/net/sourceforge/plantuml/command/CommandNoteEntity.java @@ -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 { @@ -58,7 +59,7 @@ final public class CommandNoteEntity extends SingleLineCommand 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))); diff --git a/src/net/sourceforge/plantuml/componentdiagram/command/CommandLinkComponent2.java b/src/net/sourceforge/plantuml/componentdiagram/command/CommandLinkComponent2.java index 214e3f010..86edb5198 100644 --- a/src/net/sourceforge/plantuml/componentdiagram/command/CommandLinkComponent2.java +++ b/src/net/sourceforge/plantuml/componentdiagram/command/CommandLinkComponent2.java @@ -64,10 +64,9 @@ public class CommandLinkComponent2 extends SingleLineCommand2 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 if (k.equals("<|") || k.equals("|>")) { return new LinkType(LinkDecor.EXTENDS, LinkDecor.NONE); } + if (k.equals("^")) { + return new LinkType(LinkDecor.EXTENDS, LinkDecor.NONE); + } return null; } diff --git a/src/net/sourceforge/plantuml/compositediagram/command/CommandCreateBlock.java b/src/net/sourceforge/plantuml/compositediagram/command/CommandCreateBlock.java index 804e03b80..ee60dad84 100644 --- a/src/net/sourceforge/plantuml/compositediagram/command/CommandCreateBlock.java +++ b/src/net/sourceforge/plantuml/compositediagram/command/CommandCreateBlock.java @@ -54,7 +54,7 @@ public class CommandCreateBlock extends SingleLineCommand { display = code; } final Entity ent = (Entity) getSystem().getOrCreateClass(code); - ent.setDisplay(display); + ent.setDisplay2(display); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/cucadiagram/CucaDiagram.java b/src/net/sourceforge/plantuml/cucadiagram/CucaDiagram.java index c693899b3..1a7900a5f 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/CucaDiagram.java +++ b/src/net/sourceforge/plantuml/cucadiagram/CucaDiagram.java @@ -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 entities = new TreeMap(); + private final Map entities = new LinkedHashMap(); + // private final Map entities = new TreeMap(); private final Map nbLinks = new HashMap(); private final List links = new ArrayList(); @@ -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 getChildrenGroups(Group parent) { @@ -220,7 +232,10 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, } final public Map entities() { - return Collections.unmodifiableMap(entities); + if (OptionFlags.SVEK) { + return Collections.unmodifiableMap(entities); + } + return Collections.unmodifiableMap(new TreeMap(entities)); } final public void addLink(Link link) { @@ -275,6 +290,16 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, abstract protected List getDotStrings(); + final public String[] getDotStringSkek() { + final List result = new ArrayList(); + for (String s : getDotStrings()) { + if (s.startsWith("nodesep") || s.startsWith("ranksep")) { + result.add(s); + } + } + return result.toArray(new String[result.size()]); + } + // final public List 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 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 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 ensureDeletes = new HashSet(); + + public void ensureDelete(DrawFile imageFile) { + if (imageFile == null) { + throw new IllegalArgumentException(); + } + ensureDeletes.add(imageFile); + } + + public ColorMapper getColorMapper() { + return getSkinParam().getColorMapper(); + } + } diff --git a/src/net/sourceforge/plantuml/cucadiagram/Entity.java b/src/net/sourceforge/plantuml/cucadiagram/Entity.java index 031a4a30b..e2b5e1cab 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/Entity.java +++ b/src/net/sourceforge/plantuml/cucadiagram/Entity.java @@ -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 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 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 hides) { + this(uid1, uid2, code, StringUtils.getWithNewlines(display), type, entityPackage, hides); + } + + public Entity(String uid1, int uid2, String code, List display, EntityType type, Group entityPackage, Set 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 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 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 subImages = new ArrayList(); + private final Set subImages = new HashSet(); 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; + } + } diff --git a/src/net/sourceforge/plantuml/cucadiagram/EntityType.java b/src/net/sourceforge/plantuml/cucadiagram/EntityType.java index e0c41098e..8e8dd6308 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/EntityType.java +++ b/src/net/sourceforge/plantuml/cucadiagram/EntityType.java @@ -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, diff --git a/src/net/sourceforge/plantuml/cucadiagram/EntityUtils.java b/src/net/sourceforge/plantuml/cucadiagram/EntityUtils.java index fc46589a6..b98fce0d8 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/EntityUtils.java +++ b/src/net/sourceforge/plantuml/cucadiagram/EntityUtils.java @@ -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 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(); + } + }; } diff --git a/src/net/sourceforge/plantuml/cucadiagram/Group.java b/src/net/sourceforge/plantuml/cucadiagram/Group.java index 2be4798c0..45183fb85 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/Group.java +++ b/src/net/sourceforge/plantuml/cucadiagram/Group.java @@ -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) { diff --git a/src/net/sourceforge/plantuml/cucadiagram/IEntity.java b/src/net/sourceforge/plantuml/cucadiagram/IEntity.java index cf124dd4e..80d5f66f2 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/IEntity.java +++ b/src/net/sourceforge/plantuml/cucadiagram/IEntity.java @@ -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 { public Group getParent(); - - public String getDisplay(); - + + public List getDisplay2(); + public EntityType getType(); public String getUid(); - + public Url getUrl(); - + public List getFieldsToDisplay(); - + public Stereotype getStereotype(); public void setStereotype(Stereotype stereotype); - + public List 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(); + } diff --git a/src/net/sourceforge/plantuml/cucadiagram/Link.java b/src/net/sourceforge/plantuml/cucadiagram/Link.java index 15ca31596..6de36e27e 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/Link.java +++ b/src/net/sourceforge/plantuml/cucadiagram/Link.java @@ -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 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 getNote() { return note; } - public final void setNote(String note) { + public final Position getNotePosition() { + return notePosition; + } + + public final void addNote(List 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; } - } diff --git a/src/net/sourceforge/plantuml/cucadiagram/LinkDecor.java b/src/net/sourceforge/plantuml/cucadiagram/LinkDecor.java index db6297592..e2ad08d4c 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/LinkDecor.java +++ b/src/net/sourceforge/plantuml/cucadiagram/LinkDecor.java @@ -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; + } } diff --git a/src/net/sourceforge/plantuml/cucadiagram/LinkType.java b/src/net/sourceforge/plantuml/cucadiagram/LinkType.java index 108e228fc..3bb8508f8 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/LinkType.java +++ b/src/net/sourceforge/plantuml/cucadiagram/LinkType.java @@ -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(); + } } diff --git a/src/net/sourceforge/plantuml/cucadiagram/Stereotype.java b/src/net/sourceforge/plantuml/cucadiagram/Stereotype.java index 8be7fab3f..4c6a0d911 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/Stereotype.java +++ b/src/net/sourceforge/plantuml/cucadiagram/Stereotype.java @@ -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 getLabels() { + if (label==null) { + return null; + } + final List result = new ArrayList(); + final Pattern p = Pattern.compile("\\<\\<.*?\\>\\>"); + final Matcher m = p.matcher(label); + while (m.find()) { + result.add(m.group()); + } + return Collections.unmodifiableList(result); + } + } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/AbstractGraphviz.java b/src/net/sourceforge/plantuml/cucadiagram/dot/AbstractGraphviz.java index 0174c1416..374ee3b03 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/AbstractGraphviz.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/AbstractGraphviz.java @@ -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 getType() { + return Arrays.asList(type); + } + } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/AbstractGraphviz2.java b/src/net/sourceforge/plantuml/cucadiagram/dot/AbstractGraphviz2.java index 151d7a40a..bf8b1d4d2 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/AbstractGraphviz2.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/AbstractGraphviz2.java @@ -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(); + } + } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/BorderMode.java b/src/net/sourceforge/plantuml/cucadiagram/dot/BorderMode.java index 05720bcae..01faf183f 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/BorderMode.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/BorderMode.java @@ -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; diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramFileMaker.java b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramFileMaker.java index d7c4786df..7ef7031c6 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramFileMaker.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramFileMaker.java @@ -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 flashcodes; @@ -124,7 +121,7 @@ public final class CucaDiagramFileMaker { } public CucaDiagramFileMaker(CucaDiagram diagram, List 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 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 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)]*>"); + + 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 = svg.replaceFirst("(?i)]*>", newString); - return svg; - } - - private Dimension2D getDimensionSvg(String svg) { - final Pattern p = Pattern.compile("(?i)]*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 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 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 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 lpng = new Lazy() { @@ -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 lsvg = new Lazy() { 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 lpng = new Lazy() { 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 leps = new Lazy() { 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 lsvg = new Lazy() { 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 lpng = new Lazy() { 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 leps = new Lazy() { 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 lsvg = new Lazy() { 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 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 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 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(); diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramFileMakerBeta.java b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramFileMakerBeta.java index 4ed0f6c63..cb03b1947 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramFileMakerBeta.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramFileMakerBeta.java @@ -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 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 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); diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramPngMaker2.java b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramPngMaker2.java index aac00e324..d7d88c9e2 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramPngMaker2.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramPngMaker2.java @@ -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 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) { diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramPngMaker3.java b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramPngMaker3.java index 309c1063b..99b86b4fc 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramPngMaker3.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramPngMaker3.java @@ -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 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) { diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramSimplifier.java b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramSimplifier.java index e8d34a507..cfa087781 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramSimplifier.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramSimplifier.java @@ -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 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)]*>"); @@ -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); + } + } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramSimplifier2.java b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramSimplifier2.java new file mode 100644 index 000000000..ad65edf52 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramSimplifier2.java @@ -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 dotStrings) throws IOException, InterruptedException { + this.diagram = diagram; + boolean changed; + do { + changed = false; + final Collection groups = new ArrayList(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 dotStrings) throws IOException, InterruptedException { + final GroupPngMaker2 maker = new GroupPngMaker2(diagram, g); + proxy.setSvekImage(maker.getImage()); + } + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramTxtMaker.java b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramTxtMaker.java index 1464b4f05..f03579682 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramTxtMaker.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramTxtMaker.java @@ -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) { diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/DotCommon.java b/src/net/sourceforge/plantuml/cucadiagram/dot/DotCommon.java index bf6f1cd43..8ea72c7ed 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/DotCommon.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/DotCommon.java @@ -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("
"); - sb.append(manageHtmlIB(stereotype.getLabel(), classes ? FontParam.CLASS_STEREOTYPE - : FontParam.OBJECT_STEREOTYPE, stereo)); - sb.append("
"); + for (String st : stereotype.getLabels()) { + sb.append(manageHtmlIB(st, classes ? FontParam.CLASS_STEREOTYPE : FontParam.OBJECT_STEREOTYPE, stereo)); + sb.append("
"); + } } - 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 ""; } - + 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 { } } - - - - } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/DotData.java b/src/net/sourceforge/plantuml/cucadiagram/dot/DotData.java index b4cd9d912..54504c285 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/DotData.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/DotData.java @@ -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 links, Map 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 links, Map 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; + } } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/DotExpression.java b/src/net/sourceforge/plantuml/cucadiagram/dot/DotExpression.java index c1f0c1250..c5a63225e 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/DotExpression.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/DotExpression.java @@ -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(); } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/DotMaker.java b/src/net/sourceforge/plantuml/cucadiagram/dot/DotMaker.java index 70dd05cec..c7c1f6749 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/DotMaker.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/DotMaker.java @@ -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 hasAlreadyOneIncommingArrowLenghtOne; final private Set rankMin = new HashSet(); @@ -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(""); + final StringBuilder sb = new StringBuilder(); + sb.append("
"); sb.append(""); sb.append("
"); 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(""); + switch (position) { + case TOP: + sb.append(""); + sb.append(""); + break; + case RIGHT: + sb.append(""); + sb.append(""); + break; + case LEFT: + sb.append(""); + sb.append(""); + break; + default: + sb.append(""); + sb.append(""); + break; + } + sb.append("
" + labelHtml + "
" + labelHtml + "
" + labelHtml + "
" + labelHtml + "
"); + 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 entities) throws IOException { + class EntityComparator implements Comparator { + 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 { + private final Map map; + + public EntityComparator2(Map 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 getMap(Collection entities2) { + final Map map = new HashMap(); + 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 entities2) throws IOException { + final List entities = new ArrayList(entities2); + // Collections.sort(entities, new EntityComparator()); + // if (getData().getUmlDiagramType() == UmlDiagramType.ACTIVITY) { + Collections.sort(entities, new EntityComparator2(getMap(entities2))); + // } + // Collections.sort(entities); final Set lollipops = new HashSet(); final Set lollipopsFriends = new HashSet(); 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(""); sb.append(""); @@ -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("<{
"); - sb.append(""); + sb.append(""); sb.append("
" + manageHtmlIB(entity.getDisplay(), FontParam.STATE, stereotype) + "
" + + manageHtmlIB(StringUtils.getMergedLines(entity.getDisplay2()), FontParam.STATE, stereotype) + + "
"); 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("" + manageHtmlIB(stereotype.getLabel(), FontParam.USECASE_STEREOTYPE, stereo) + ""); } - sb.append("" + manageHtmlIB(entity.getDisplay(), FontParam.USECASE, stereo) + ""); + sb.append("" + + manageHtmlIB(StringUtils.getMergedLines(entity.getDisplay2()), FontParam.USECASE, stereo) + + ""); sb.append(">"); return sb.toString(); } @@ -1140,7 +1250,9 @@ final public class DotMaker extends DotCommon implements GraphvizMaker { sb.append("" + manageHtmlIB(stereotype.getLabel(), FontParam.COMPONENT_STEREOTYPE, stereo) + ""); } - sb.append("" + manageHtmlIB(entity.getDisplay(), FontParam.COMPONENT, stereo) + ""); + sb.append("" + + manageHtmlIB(StringUtils.getMergedLines(entity.getDisplay2()), FontParam.COMPONENT, stereo) + + ""); sb.append(">"); 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("<"); sb.append(""); @@ -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(""); } - sb.append(""); + sb.append(""); sb.append("
" + manageHtmlIB(entity.getDisplay(), FontParam.USECASE_ACTOR, stereo) + "
" + + manageHtmlIB(StringUtils.getMergedLines(entity.getDisplay2()), FontParam.USECASE_ACTOR, stereo) + + "
>"); 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(""); - sb.append("" + manageHtmlIB(entity.getDisplay(), FontParam.COMPONENT, stereo) + ""); + sb.append("" + + manageHtmlIB(StringUtils.getMergedLines(entity.getDisplay2()), FontParam.COMPONENT, stereo) + + ""); sb.append(">"); 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("<"); @@ -1229,7 +1344,8 @@ final public class DotMaker extends DotCommon implements GraphvizMaker { addTdImageBugB1983(sb, circleInterfaceAbsolutePath); } sb.append(""); - sb.append(""); + sb.append(""); sb.append("
" + manageHtmlIB(entity.getDisplay(), FontParam.CLASS, null) + "
" + manageHtmlIB(StringUtils.getMergedLines(entity.getDisplay2()), FontParam.CLASS, null) + + "
>"); 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; + } + } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/DotMaker2.java b/src/net/sourceforge/plantuml/cucadiagram/dot/DotMaker2.java deleted file mode 100644 index ab2328eac..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/DotMaker2.java +++ /dev/null @@ -1,1819 +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: 6230 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.awt.Color; -import java.awt.Font; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import javax.imageio.ImageIO; - -import net.sourceforge.plantuml.ColorParam; -import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.FileUtils; -import net.sourceforge.plantuml.FontParam; -import net.sourceforge.plantuml.Log; -import net.sourceforge.plantuml.OptionFlags; -import net.sourceforge.plantuml.SignatureUtils; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.UmlDiagramType; -import net.sourceforge.plantuml.cucadiagram.Entity; -import net.sourceforge.plantuml.cucadiagram.EntityPortion; -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.Link; -import net.sourceforge.plantuml.cucadiagram.LinkType; -import net.sourceforge.plantuml.cucadiagram.Member; -import net.sourceforge.plantuml.cucadiagram.Rankdir; -import net.sourceforge.plantuml.cucadiagram.Stereotype; -import net.sourceforge.plantuml.graphic.FontConfiguration; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; -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.skin.VisibilityModifier; -import net.sourceforge.plantuml.skin.rose.Rose; -import net.sourceforge.plantuml.ugraphic.UGraphic; -import net.sourceforge.plantuml.ugraphic.eps.UGraphicEps; - -final public class DotMaker2 implements GraphvizMaker { - - private final DotData data; - - private static boolean isJunit = false; - - private final List dotStrings; - private boolean underline = false; - private final Rose rose = new Rose(); - - private static String lastDotSignature; - - private final FileFormat fileFormat; - - private final boolean isVisibilityModifierPresent; - - // http://www.graphviz.org/bugs/b2114.html - private static final boolean TURN_AROUND_B2114 = false; - - private final Set hasAlreadyOneIncommingArrowLenghtOne; - - final private Set rankMin = new HashSet(); - - public static void goJunit() { - isJunit = true; - } - - public DotMaker2(DotData data, List dotStrings, FileFormat fileFormat) { - this.data = data; - this.dotStrings = dotStrings; - this.fileFormat = fileFormat; - if (data.getSkinParam().classAttributeIconSize() > 0) { - this.isVisibilityModifierPresent = data.isThereVisibilityImages(); - } else { - this.isVisibilityModifierPresent = false; - } - this.hasAlreadyOneIncommingArrowLenghtOne = TURN_AROUND_B2114 ? new HashSet() : null; - } - - public String createDotString() throws IOException { - - final StringBuilder sb = new StringBuilder(); - - initPrintWriter(sb); - printGroups(sb, null); - printEntities(sb, getUnpackagedEntities()); - printLinks(sb, data.getLinks()); - printRanking(sb); - sb.append("}"); - - // System.err.println(sb); - if (isJunit) { - lastDotSignature = SignatureUtils.getSignatureWithoutImgSrc(sb.toString()); - } - return sb.toString(); - } - - private void printRanking(StringBuilder sb) { - if (rankMin.size() == 0) { - return; - } - sb.append("{ rank = min;"); - for (String id : rankMin) { - sb.append(id); - sb.append(";"); - } - sb.append("}"); - - } - - private void initPrintWriter(StringBuilder sb) { - - Log.info("Entities = " + data.getEntities().size()); - final boolean huge = data.getEntities().size() > 800; - - sb.append("digraph unix {"); - // if (isJunit == false) { - for (String s : dotStrings) { - sb.append(s); - } - // } - sb.append("bgcolor=\"" + data.getSkinParam().getBackgroundColor().getAsHtml() + "\";"); - if (huge) { - sb.append("size=\"400,400;\""); - } else { - sb.append("ratio=auto;"); - // sb.append("concentrate=true;"); - } - // sb.append("ordering=out;"); - sb.append("compound=true;"); - final DotSplines dotSplines = data.getSkinParam().getDotSplines(); - final GraphvizLayoutStrategy strategy = data.getSkinParam().getStrategy(); - if (dotSplines == DotSplines.ORTHO) { - sb.append("splines=ortho;"); - } else if (dotSplines == DotSplines.POLYLINE) { - sb.append("splines=polyline;"); - } else if (strategy != GraphvizLayoutStrategy.DOT) { - sb.append("splines=true;"); - } - - // if (strategy == GraphvizLayoutStrategy.NEATO) { - // sb.append("overlap=false;"); - // } - if (strategy != GraphvizLayoutStrategy.DOT) { - sb.append("layout=" + strategy.name().toLowerCase() + ";"); - sb.append("overlap=false;"); - } - - sb.append("remincross=true;"); - sb.append("searchsize=500;"); - if (data.getRankdir() == Rankdir.LEFT_TO_RIGHT) { - sb.append("rankdir=LR;"); - } - - if (data.getDpi() != 96) { - sb.append("dpi=" + data.getDpi() + ";"); - sb.append("imagescale=both;"); - } - } - - private Collection getUnpackagedEntities() { - final List result = new ArrayList(); - for (IEntity ent : data.getEntities().values()) { - if (ent.getParent() == data.getTopParent()) { - result.add(ent); - } - } - return result; - } - - private void printGroups(StringBuilder sb, Group parent) throws IOException { - for (Group g : data.getGroupHierarchy().getChildrenGroups(parent)) { - if (data.isEmpty(g) && g.getType() == GroupType.PACKAGE) { - final IEntity folder = new Entity(g.getUid(), g.getCode(), g.getDisplay(), EntityType.EMPTY_PACKAGE, - null, null); - printEntity(sb, folder); - } else { - printGroup(sb, g); - } - } - } - - private void printGroup(StringBuilder sb, Group g) throws IOException { - if (g.getType() == GroupType.CONCURRENT_STATE) { - return; - } - - if (isSpecialGroup(g)) { - printGroupSpecial(sb, g); - } else { - printGroupNormal(sb, g); - } - } - - private void printGroupNormal(StringBuilder sb, Group g) throws IOException { - - final String stereo = g.getStereotype(); - - sb.append("subgraph " + g.getUid() + " {"); - // sb.append("margin=10;"); - - sb.append("fontsize=\"" + data.getSkinParam().getFontSize(getFontParamForGroup(), stereo) + "\";"); - final String fontFamily = data.getSkinParam().getFontFamily(getFontParamForGroup(), stereo); - if (fontFamily != null) { - sb.append("fontname=\"" + fontFamily + "\";"); - } - - if (g.getDisplay() != null) { - sb.append("label=<" + manageHtmlIB(g.getDisplay(), getFontParamForGroup(), stereo) + ">;"); - } - final String fontColor = data.getSkinParam().getFontHtmlColor(getFontParamForGroup(), stereo).getAsHtml(); - sb.append("fontcolor=\"" + fontColor + "\";"); - - if (getGroupBackColor(g) != null) { - sb.append("fillcolor=\"" + getGroupBackColor(g).getAsHtml() + "\";"); - } - - if (g.getType() == GroupType.STATE) { - sb.append("color=" + getColorString(ColorParam.stateBorder, stereo) + ";"); - } else { - sb.append("color=" + getColorString(ColorParam.packageBorder, stereo) + ";"); - } - sb.append("style=\"" + getStyle(g) + "\";"); - - printGroups(sb, g); - - this.printEntities(sb, g.entities().values()); - for (Link link : data.getLinks()) { - eventuallySameRank(sb, g, link); - } - sb.append("}"); - } - - private HtmlColor getGroupBackColor(Group g) { - HtmlColor value = g.getBackColor(); - if (value == null) { - value = data.getSkinParam().getHtmlColor(ColorParam.packageBackground, null); - // value = rose.getHtmlColor(this.data.getSkinParam(), - // ColorParam.packageBackground); - } - return value; - } - - private void printGroupSpecial(StringBuilder sb, Group g) throws IOException { - - sb.append("subgraph " + g.getUid() + "a {"); - if (OptionFlags.getInstance().isDebugDot()) { - sb.append("style=dotted;"); - sb.append("label=\"a\";"); - } else { - sb.append("style=invis;"); - sb.append("label=\"\";"); - } - - sb.append("subgraph " + g.getUid() + "v {"); - sb.append("style=solid;"); - // sb.append("margin=10;"); - - final List autolinks = data.getAutoLinks(g); - final List toEdgeLinks = data.getToEdgeLinks(g); - final List fromEdgeLinks = data.getFromEdgeLinks(g); - final boolean autoLabel = autolinks.size() == 1; - - final List nodesHiddenUidOut = getNodesHiddenUidOut(g); - final List nodesHiddenUidIn = getNodesHiddenUidIn(g); - final List nodesHiddenUid = new ArrayList(nodesHiddenUidOut); - nodesHiddenUid.addAll(nodesHiddenUidIn); - for (Link link : nodesHiddenUid) { - final String uid = getHiddenNodeUid(g, link); - // sb.append("subgraph " + g.getUid() + "k" + uid + " {"); - if (OptionFlags.getInstance().isDebugDot()) { - sb.append("style=dotted;"); - sb.append("label=\"k" + uid + "\";"); - } else { - sb.append("style=invis;"); - sb.append("label=\"\";"); - } - if (OptionFlags.getInstance().isDebugDot()) { - sb.append(uid + ";"); - } else { - sb.append(uid + " [shape=point,width=.01,style=invis,label=\"\"];"); - } - // sb.append("}"); // end of k - } - - for (int j = 1; j < nodesHiddenUidOut.size(); j++) { - for (int i = 0; i < j; i++) { - final Link linki = nodesHiddenUidOut.get(i); - final Link linkj = nodesHiddenUidOut.get(j); - if (linki.getEntity2() != linkj.getEntity2()) { - continue; - } - final String uidi = getHiddenNodeUid(g, linki); - final String uidj = getHiddenNodeUid(g, linkj); - if (OptionFlags.getInstance().isDebugDot()) { - sb.append(uidi + "->" + uidj + ";"); - } else { - sb.append(uidi + "->" + uidj + " [style=invis,arrowtail=none,arrowhead=none];"); - } - - } - } - - if (autoLabel /* || toEdgeLinks.size() > 0 || fromEdgeLinks.size() > 0 */) { - if (OptionFlags.getInstance().isDebugDot()) { - sb.append(g.getUid() + "lmin;"); - sb.append(g.getUid() + "lmax;"); - sb.append(g.getUid() + "lmin->" + g.getUid() + "lmax [minlen=2]; "); - } else { - sb.append(g.getUid() + "lmin [shape=point,width=.01,style=invis,label=\"\"];"); - sb.append(g.getUid() + "lmax [shape=point,width=.01,style=invis,label=\"\"];"); - sb.append(g.getUid() + "lmin->" + g.getUid() - + "lmax [minlen=2,style=invis,arrowtail=none,arrowhead=none]; "); - } - } - // sb.append(g.getUid() + "min->" + g.getUid() + "max;"); - - sb.append("fontsize=\"" + data.getSkinParam().getFontSize(getFontParamForGroup(), null) + "\";"); - final String fontFamily = data.getSkinParam().getFontFamily(getFontParamForGroup(), null); - if (fontFamily != null) { - sb.append("fontname=\"" + fontFamily + "\";"); - } - - if (g.getDisplay() != null) { - final StringBuilder label = new StringBuilder(manageHtmlIB(g.getDisplay(), getFontParamForGroup(), null)); - if (g.getEntityCluster().getFieldsToDisplay().size() > 0) { - label.append("
"); - for (Member att : g.getEntityCluster().getFieldsToDisplay()) { - label.append(manageHtmlIB(" " + att.getDisplayWithVisibilityChar() + " ", - FontParam.STATE_ATTRIBUTE, null)); - label.append("
"); - } - } - sb.append("label=<" + label + ">;"); - } - - final String fontColor = data.getSkinParam().getFontHtmlColor(getFontParamForGroup(), null).getAsHtml(); - sb.append("fontcolor=\"" + fontColor + "\";"); - final HtmlColor groupBackColor = getGroupBackColor(g); - if (groupBackColor != null) { - sb.append("fillcolor=\"" + groupBackColor.getAsHtml() + "\";"); - } - if (g.getType() == GroupType.STATE) { - sb.append("color=" + getColorString(ColorParam.stateBorder, null) + ";"); - } else { - sb.append("color=" + getColorString(ColorParam.packageBorder, null) + ";"); - } - sb.append("style=\"" + getStyle(g) + "\";"); - - sb.append("subgraph " + g.getUid() + "i {"); - sb.append("label=\"i\";"); - if (OptionFlags.getInstance().isDebugDot()) { - sb.append("style=dotted;"); - sb.append("label=\"i\";"); - } else { - - if (groupBackColor == null) { - sb.append("style=invis;"); - } else { - final String colorBack = getColorString(ColorParam.background, null); - sb.append("fillcolor=" + colorBack + ";"); - sb.append("color=" + colorBack + ";"); - sb.append("style=\"filled,rounded\";"); - } - sb.append("label=\"\";"); - - } - - printGroups(sb, g); - - this.printEntities(sb, g.entities().values()); - for (Link link : data.getLinks()) { - eventuallySameRank(sb, g, link); - } - - for (int i = 0; i < fromEdgeLinks.size(); i++) { - if (OptionFlags.getInstance().isDebugDot()) { - sb.append("eds" + i + ";"); - } else { - sb.append("eds" + i + " [shape=point,width=.01,style=invis,label=\"\"];"); - } - sb.append("eds" + i + " ->" + fromEdgeLinks.get(i).getEntity2().getUid() - + " [minlen=2,style=invis,arrowtail=none,arrowhead=none]; "); - - } - - sb.append("}"); // end of i - sb.append("}"); // end of v - - if (autoLabel) { - sb.append("subgraph " + g.getUid() + "l {"); - if (OptionFlags.getInstance().isDebugDot()) { - sb.append("style=dotted;"); - sb.append("label=\"l\";"); - } else { - sb.append("style=invis;"); - sb.append("label=\"\";"); - } - final String decorationColor = ",color=" + getColorString(getArrowColorParam(), null); - - sb.append(g.getUid() + "lab0 [shape=point,width=.01,label=\"\"" + decorationColor + "]"); - String autolabel = autolinks.get(0).getLabel(); - if (autolabel == null) { - autolabel = ""; - } - sb.append(g.getUid() + "lab1 [label=<" + manageHtmlIB(autolabel, getArrowFontParam(), null) - + ">,shape=plaintext,margin=0];"); - sb.append(g.getUid() + "lab0 -> " + g.getUid() + "lab1 [minlen=0,style=invis];"); - sb.append("}"); // end of l - - sb.append(g.getUid() + "lmin -> " + g.getUid() + "lab0 [ltail=" + g.getUid() - + "v,arrowtail=none,arrowhead=none" + decorationColor + "];"); - sb.append(g.getUid() + "lab0 -> " + g.getUid() + "lmax [lhead=" + g.getUid() - + "v,arrowtail=none,arrowhead=open" + decorationColor + "];"); - } - - for (int i = 0; i < fromEdgeLinks.size(); i++) { - sb.append("subgraph " + g.getUid() + "ed" + i + " {"); - if (OptionFlags.getInstance().isDebugDot()) { - sb.append("style=dotted;"); - sb.append("label=\"ed" + i + "\";"); - } else { - sb.append("style=invis;"); - sb.append("label=\"\";"); - } - final String decorationColor = ",color=" + getColorString(getArrowColorParam(), null); - String label = fromEdgeLinks.get(i).getLabel(); - if (label == null) { - label = ""; - } - - sb.append(g.getUid() + "fedge" + i + " [shape=point,width=.01,label=\"\"" + decorationColor + "]"); - sb.append("}"); // end of ed - sb.append("eds" + i + " -> " + g.getUid() + "fedge" + i + " [ltail=" + g.getUid() - + "v,arrowtail=none,arrowhead=none" + decorationColor + "];"); - sb.append(g.getUid() + "fedge" + i + " -> " + fromEdgeLinks.get(i).getEntity2().getUid() - + "[arrowtail=none,arrowhead=open" + decorationColor); - sb.append(",label=<" + manageHtmlIB(label, getArrowFontParam(), null) + ">];"); - - } - sb.append("}"); // end of a - } - - private FontParam getFontParamForGroup() { - if (data.getUmlDiagramType() == UmlDiagramType.STATE) { - return FontParam.STATE; - } - return FontParam.PACKAGE; - } - - private String getStyle(Group g) { - final StringBuilder sb = new StringBuilder(); - if (g.isBold()) { - sb.append("bold"); - } else if (g.isDashed()) { - sb.append("dashed"); - } else { - sb.append("solid"); - - } - if (getGroupBackColor(g) != null) { - sb.append(",filled"); - } - if (g.isRounded()) { - sb.append(",rounded"); - } - return sb.toString(); - } - - private void printLinks(StringBuilder sb, List links) throws IOException { - for (Link link : appendPhantomLink(links)) { - final IEntity entity1 = link.getEntity1(); - final IEntity entity2 = link.getEntity2(); - if (entity1 == entity2 && entity1.getType() == EntityType.GROUP) { - continue; - } - if (entity1.getType() == EntityType.GROUP && entity2.getParent() == entity1.getParent()) { - continue; - } - if (entity2.getType() == EntityType.GROUP && entity1.getParent() == entity2.getParent()) { - continue; - } - if (entity1.getType() == EntityType.LOLLIPOP || entity2.getType() == EntityType.LOLLIPOP) { - continue; - } - // System.err.println("outing " + link); - printLink(sb, link); - } - } - - private void printLink(StringBuilder sb, Link link) throws IOException { - final StringBuilder decoration = getLinkDecoration(link); - - if (link.getWeight() > 1) { - decoration.append("weight=" + link.getWeight() + ","); - } - if (link.getLabeldistance() != null) { - decoration.append("labeldistance=" + link.getLabeldistance() + ","); - } - if (link.getLabelangle() != null) { - decoration.append("labelangle=" + link.getLabelangle() + ","); - } - - final DrawFile noteLink = link.getImageFile(); - - boolean hasLabel = false; - - 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)) + ">,"); - hasLabel = true; - } - - if (link.getQualifier1() != null) { - decoration.append("taillabel=<" + manageHtmlIB(link.getQualifier1(), getArrowFontParam(), null) + ">,"); - } - if (link.getQualifier2() != null) { - decoration.append("headlabel=<" + manageHtmlIB(link.getQualifier2(), getArrowFontParam(), null) + ">,"); - } - final int len = link.getLength(); - String uid1 = link.getEntity1().getUid(); - String uid2 = link.getEntity2().getUid(); - LinkType typeToDraw = link.getType(); - if (TURN_AROUND_B2114 && len == 1 && hasAlreadyOneIncommingArrowLenghtOne.contains(uid2) && hasLabel) { - typeToDraw = typeToDraw.getInv(); - } - if (TURN_AROUND_B2114 && len == 1) { - hasAlreadyOneIncommingArrowLenghtOne.add(uid2); - } - decoration.append(typeToDraw.getSpecificDecoration()); - if (link.isInvis()) { - decoration.append(",style=invis"); - } - - // if (len == 1) { - // decoration.append(",constraint=false"); - // } - final String lenString = len >= 3 ? ",minlen=" + (len - 1) : ""; - - if (link.getEntity1().getType() == EntityType.GROUP) { - uid1 = getHiddenNodeUid(link.getEntity1().getParent(), link); - decoration.append(",ltail=" + link.getEntity1().getParent().getUid() + "v"); - } - if (link.getEntity2().getType() == EntityType.GROUP) { - uid2 = getHiddenNodeUid(link.getEntity2().getParent(), link); - decoration.append(",lhead=" + link.getEntity2().getParent().getUid() + "v"); - } - - sb.append(uid1 + ":here -> " + uid2 + ":here"); - sb.append(decoration); - sb.append(lenString + "];"); - eventuallySameRank(sb, data.getTopParent(), link); - } - - private List getNodesHiddenUidOut(Group g) { - final List result = new ArrayList(); - for (Link link : data.getLinks()) { - if (link.getEntity1().getParent() == link.getEntity2().getParent()) { - continue; - } - if (link.getEntity1().getType() == EntityType.GROUP && link.getEntity1().getParent() == g) { - result.add(link); - } - } - return Collections.unmodifiableList(result); - } - - private List getNodesHiddenUidIn(Group g) { - final List result = new ArrayList(); - for (Link link : data.getLinks()) { - if (link.getEntity1().getParent() == link.getEntity2().getParent()) { - continue; - } - if (link.getEntity2().getType() == EntityType.GROUP && link.getEntity2().getParent() == g) { - result.add(link); - } - } - return Collections.unmodifiableList(result); - } - - private String getHiddenNodeUid(Group g, Link link) { - if (data.isEmpty(g) && g.getType() == GroupType.PACKAGE) { - return g.getUid(); - } - return g.getUid() + "_" + link.getUid(); - } - - private StringBuilder getLinkDecoration(Link link) { - final StringBuilder decoration = new StringBuilder("[color="); - if (link.getSpecificColor() == null) { - decoration.append(getColorString(getArrowColorParam(), null)); - } else { - decoration.append("\"" + link.getSpecificColor().getAsHtml() + "\""); - } - decoration.append(","); - - decoration.append("fontcolor=" + getFontColorString(getArrowFontParam(), null) + ","); - decoration.append("fontsize=\"" + data.getSkinParam().getFontSize(getArrowFontParam(), null) + "\","); - - final String fontName = data.getSkinParam().getFontFamily(getArrowFontParam(), null); - if (fontName != null) { - decoration.append("fontname=\"" + fontName + "\","); - } - return decoration; - } - - private List appendPhantomLink(List links) { - final List result = new ArrayList(links); - for (Link link : links) { - if (link.getLength() != 1) { - continue; - } - final DrawFile noteLink = link.getImageFile(); - if (noteLink == null) { - continue; - } - final Link phantom = new Link(link.getEntity1(), link.getEntity2(), link.getType(), null, link.getLength()); - phantom.setInvis(true); - result.add(phantom); - } - return result; - } - - private String getHtmlForLinkNote(File image) { - final String circleInterfaceAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(image); - final StringBuilder sb = new StringBuilder(""); - sb.append(""); - sb.append("
"); - return sb.toString(); - - } - - private FontParam getArrowFontParam() { - if (data.getUmlDiagramType() == UmlDiagramType.CLASS) { - return FontParam.CLASS_ARROW; - } else if (data.getUmlDiagramType() == UmlDiagramType.OBJECT) { - return FontParam.OBJECT_ARROW; - } else if (data.getUmlDiagramType() == UmlDiagramType.USECASE) { - return FontParam.USECASE_ARROW; - } else if (data.getUmlDiagramType() == UmlDiagramType.ACTIVITY) { - return FontParam.ACTIVITY_ARROW; - } else if (data.getUmlDiagramType() == UmlDiagramType.COMPONENT) { - return FontParam.COMPONENT_ARROW; - } else if (data.getUmlDiagramType() == UmlDiagramType.STATE) { - return FontParam.STATE_ARROW; - } - throw new IllegalStateException(); - } - - private ColorParam getArrowColorParam() { - if (data.getUmlDiagramType() == UmlDiagramType.CLASS) { - return ColorParam.classArrow; - } else if (data.getUmlDiagramType() == UmlDiagramType.OBJECT) { - return ColorParam.objectArrow; - } else if (data.getUmlDiagramType() == UmlDiagramType.USECASE) { - return ColorParam.usecaseArrow; - } else if (data.getUmlDiagramType() == UmlDiagramType.ACTIVITY) { - return ColorParam.activityArrow; - } else if (data.getUmlDiagramType() == UmlDiagramType.COMPONENT) { - return ColorParam.componentArrow; - } else if (data.getUmlDiagramType() == UmlDiagramType.STATE) { - return ColorParam.stateArrow; - } - throw new IllegalStateException(); - } - - private String getColorString(ColorParam colorParam, String stereotype) { - return "\"" + rose.getHtmlColor(data.getSkinParam(), colorParam, stereotype).getAsHtml() + "\""; - } - - private String getFontColorString(FontParam fontParam, String stereotype) { - return "\"" + getFontHtmlColor(fontParam, stereotype).getAsHtml() + "\""; - } - - private HtmlColor getFontHtmlColor(FontParam fontParam, String stereotype) { - return data.getSkinParam().getFontHtmlColor(fontParam, stereotype); - } - - private void eventuallySameRank(StringBuilder sb, Group entityPackage, Link link) { - final int len = link.getLength(); - if (len == 1 && link.getEntity1().getParent() == entityPackage - && link.getEntity2().getParent() == entityPackage) { - if (link.getEntity1().getType() == EntityType.GROUP) { - throw new IllegalArgumentException(); - } - if (link.getEntity2().getType() == EntityType.GROUP) { - throw new IllegalArgumentException(); - } - sb.append("{rank=same; " + link.getEntity1().getUid() + "; " + link.getEntity2().getUid() + "}"); - } - } - - private void printEntities(StringBuilder sb, Collection entities) throws IOException { - final Set lollipops = new HashSet(); - final Set lollipopsFriends = new HashSet(); - for (IEntity entity : entities) { - if (entity.getType() == EntityType.LOLLIPOP) { - lollipops.add(entity); - lollipopsFriends.add(getConnectedToLollipop(entity)); - } - } - for (IEntity entity : entities) { - if (lollipops.contains(entity) || lollipopsFriends.contains(entity)) { - continue; - } - printEntity(sb, entity); - } - - for (IEntity ent : lollipopsFriends) { - sb.append("subgraph cluster" + ent.getUid() + "lol {"); - sb.append("style=invis;"); - sb.append("label=\"\";"); - printEntity(sb, ent); - for (IEntity lollipop : getAllLollipop(ent)) { - final Link link = getLinkLollipop(lollipop, ent); - final String headOrTail = getHeadOrTail(lollipop, link); - printEntity(sb, lollipop, headOrTail); - printLink(sb, link); - } - sb.append("}"); - } - - } - - private Collection getAllLollipop(IEntity entity) { - final Collection result = new ArrayList(); - for (IEntity lollipop : data.getAllLinkedDirectedTo(entity)) { - if (lollipop.getType() == EntityType.LOLLIPOP) { - result.add(lollipop); - } - } - return result; - } - - private IEntity getConnectedToLollipop(IEntity lollipop) { - assert lollipop.getType() == EntityType.LOLLIPOP; - final Collection linked = data.getAllLinkedDirectedTo(lollipop); - if (linked.size() != 1) { - throw new IllegalStateException("size=" + linked.size()); - } - return linked.iterator().next(); - } - - private Link getLinkLollipop(IEntity lollipop, IEntity ent) { - assert lollipop.getType() == EntityType.LOLLIPOP; - for (Link link : data.getLinks()) { - if (link.isBetween(lollipop, ent)) { - return link; - } - } - throw new IllegalArgumentException(); - } - - private void printEntity(StringBuilder sb, IEntity entity, String headOrTail) throws IOException { - final EntityType type = entity.getType(); - if (type == EntityType.LOLLIPOP) { - 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); - 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 - + ",arrowtail=none,arrowhead=none," + headOrTail + "=<" + labelLo + ">];"); - } else { - throw new IllegalStateException(type.toString() + " " + data.getUmlDiagramType()); - } - - } - - private void printEntity(StringBuilder sb, IEntity entity) throws IOException { - final EntityType type = entity.getType(); - final String label = getLabel(entity); - if (type == EntityType.GROUP) { - return; - } - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - if (type == EntityType.ABSTRACT_CLASS || type == EntityType.CLASS || type == EntityType.INTERFACE - || type == EntityType.ENUM) { - String dec = " [fontcolor=" + getFontColorString(FontParam.CLASS, stereo) + ",margin=0,fillcolor=" - + getColorString(ColorParam.background, stereo) + ",color=" - + getColorString(ColorParam.background, stereo) + ",style=filled,shape=box," + label; - if (this.data.hasUrl() && entity.getUrl() != null) { - dec += ",URL=\"" + entity.getUrl() + "\""; - } - dec += "];"; - sb.append(entity.getUid() + dec); - } else if (type == EntityType.OBJECT) { - sb.append(entity.getUid() + " [fontcolor=" + getFontColorString(FontParam.CLASS, stereo) - + ",margin=0,fillcolor=" + getColorString(ColorParam.classBackground, stereo) + ",color=" - + getColorString(ColorParam.classBorder, stereo) + ",style=filled,shape=record," + label + "];"); - } else if (type == EntityType.USECASE) { - sb.append(entity.getUid() + " [fontcolor=" + getFontColorString(FontParam.USECASE, stereo) + ",fillcolor=" - + getColorString(ColorParam.usecaseBackground, stereo) + ",color=" - + getColorString(ColorParam.usecaseBorder, stereo) + ",style=filled," + label + "];"); - } else if (type == EntityType.ACTOR) { - sb.append(entity.getUid() + " [fontcolor=" + getFontColorString(FontParam.USECASE_ACTOR, stereo) - + ",margin=0,shape=plaintext," + label + "];"); - } else if (type == EntityType.CIRCLE_INTERFACE) { - sb.append(entity.getUid() + " [margin=0,shape=plaintext," + label + "];"); - } else if (type == EntityType.COMPONENT) { - sb.append(entity.getUid() + " [margin=0.2,fontcolor=" + getFontColorString(FontParam.COMPONENT, stereo) - + ",fillcolor=" + getColorString(ColorParam.componentBackground, stereo) + ",color=" - + getColorString(ColorParam.componentBorder, stereo) + ",style=filled,shape=component," + label - + "];"); - } else if (type == EntityType.NOTE && data.getDpi() != 96) { - sb.append(entity.getUid() + " [margin=0,pad=0,shape=plaintext,label=" + getLabelForNoteDpi(entity) + "];"); - } else if (type == EntityType.NOTE) { - final DrawFile file = entity.getImageFile(); - if (file == null) { - throw new IllegalStateException("No file for NOTE"); - } - if (file.getPngOrEps(fileFormat == FileFormat.EPS).exists() == false) { - throw new IllegalStateException(); - } - final String absolutePath = StringUtils.getPlateformDependentAbsolutePath(file - .getPngOrEps(fileFormat == FileFormat.EPS)); - sb.append(entity.getUid() + " [margin=0,pad=0," + label + ",shape=none,image=\"" + absolutePath + "\"];"); - } else if (type == EntityType.ACTIVITY) { - String shape = "octagon"; - if (data.getSkinParam().useOctagonForActivity() == false || entity.getImageFile() != null) { - shape = "rect"; - } - sb.append(entity.getUid() + " [fontcolor=" + getFontColorString(FontParam.ACTIVITY, stereo) + ",fillcolor=" - + getBackColorOfEntity(entity) + ",color=" + getColorString(ColorParam.activityBorder, stereo) - + ",style=\"rounded,filled\",shape=" + shape + "," + label + "];"); - } else if (type == EntityType.BRANCH) { - sb.append(entity.getUid() + " [fillcolor=" + getBackColorOfEntity(entity) + ",color=" - + getColorString(ColorParam.activityBorder, stereo) - + ",style=\"filled\",shape=diamond,height=.25,width=.25,label=\"\"];"); - // if (StringUtils.isNotEmpty(entity.getDisplay())) { - // sb.append(entity.getUid() + "->" + entity.getUid() + - // "[taillabel=\"" + entity.getDisplay() - // + "\",arrowtail=none,arrowhead=none,color=\"white\"];"); - // } - } else if (type == EntityType.SYNCHRO_BAR) { - final String color = getColorString(ColorParam.activityBar, null); - sb.append(entity.getUid() + " [fillcolor=" + color + ",color=" + color + ",style=\"filled\"," - + "shape=rect,height=.08,width=1.30,label=\"\"];"); - } else if (type == EntityType.CIRCLE_START) { - final String color = getColorString(getStartColorParam(), null); - sb.append(entity.getUid() + " [fillcolor=" + color + ",color=" + color + ",style=\"filled\"," - + "shape=circle,width=.20,height=.20,label=\"\"];"); - } else if (type == EntityType.CIRCLE_END) { - 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.POINT_FOR_ASSOCIATION) { - sb.append(entity.getUid() + " [width=.05,shape=point,color=" + getColorString(ColorParam.classBorder, null) - + "];"); - } else if (type == EntityType.STATE) { - sb.append(entity.getUid() + " [color=" + getColorString(ColorParam.stateBorder, stereo) - + ",shape=record,style=\"rounded,filled\",color=" + getColorString(ColorParam.stateBorder, stereo)); - if (entity.getImageFile() == null) { - sb.append(",fillcolor=" + getBackColorOfEntity(entity)); - } else { - sb.append(",fillcolor=" + getBackColorOfEntity(entity)); - // sb.append(",fillcolor=\"" + - // data.getSkinParam().getBackgroundColor().getAsHtml() + "\""); - } - sb.append("," + label + "];"); - } else if (type == EntityType.STATE_CONCURRENT) { - final DrawFile file = entity.getImageFile(); - if (file == null) { - throw new IllegalStateException(); - } - if (file.getPng().exists() == false) { - throw new IllegalStateException(); - } - final String absolutePath = StringUtils.getPlateformDependentAbsolutePath(file.getPng()); - sb.append(entity.getUid() + " [margin=1,pad=1," + label + ",style=dashed,shape=box,image=\"" + absolutePath - + "\"];"); - } else if (type == EntityType.ACTIVITY_CONCURRENT) { - final DrawFile file = entity.getImageFile(); - if (file == null) { - throw new IllegalStateException(); - } - if (file.getPng().exists() == false) { - throw new IllegalStateException(); - } - final String absolutePath = StringUtils.getPlateformDependentAbsolutePath(file.getPng()); - sb.append(entity.getUid() + " [margin=0,pad=0," + label + ",style=dashed,shape=box,image=\"" + absolutePath - + "\"];"); - } else if (type == EntityType.EMPTY_PACKAGE) { - sb.append(entity.getUid() + " [margin=0.2,fontcolor=" + getFontColorString(FontParam.PACKAGE, null) - + ",fillcolor=" + getColorString(ColorParam.packageBackground, null) + ",color=" - + getColorString(ColorParam.packageBorder, null) + ",style=filled,shape=tab," + label + "];"); - } else { - throw new IllegalStateException(type.toString() + " " + data.getUmlDiagramType()); - } - - if (entity.isTop()) { - rankMin.add(entity.getUid()); - } - - } - - private ColorParam getEndColorParam() { - if (data.getUmlDiagramType() == UmlDiagramType.ACTIVITY) { - return ColorParam.activityEnd; - } - if (data.getUmlDiagramType() == UmlDiagramType.STATE) { - return ColorParam.stateEnd; - } - throw new IllegalStateException(data.getUmlDiagramType().toString()); - } - - private ColorParam getStartColorParam() { - if (data.getUmlDiagramType() == UmlDiagramType.ACTIVITY) { - return ColorParam.activityStart; - } - if (data.getUmlDiagramType() == UmlDiagramType.STATE) { - return ColorParam.stateStart; - } - throw new IllegalStateException(data.getUmlDiagramType().toString()); - } - - private String getHeadOrTail(IEntity lollipop, Link link) { - assert lollipop.getType() == EntityType.LOLLIPOP; - if (link.getLength() > 1 && link.getEntity1() == lollipop) { - return "taillabel"; - } - return "headlabel"; - } - - private String getLabel(IEntity entity) throws IOException { - if (entity.getType() == EntityType.ABSTRACT_CLASS || entity.getType() == EntityType.CLASS - || entity.getType() == EntityType.INTERFACE || entity.getType() == EntityType.ENUM) { - return "label=" + getLabelForClassOrInterfaceOrEnum(entity); - } else if (entity.getType() == EntityType.LOLLIPOP) { - return "label=" + getLabelForLollipop(entity); - } else if (entity.getType() == EntityType.OBJECT) { - return "label=" + getLabelForObject(entity); - } else if (entity.getType() == EntityType.ACTOR) { - return "label=" + getLabelForActor(entity); - } else if (entity.getType() == EntityType.CIRCLE_INTERFACE) { - return "label=" + getLabelForCircleInterface(entity); - } else if (entity.getType() == EntityType.NOTE) { - return "label=\"\""; - } else if (entity.getType() == EntityType.STATE_CONCURRENT) { - return "label=\"\""; - } else if (entity.getType() == EntityType.ACTIVITY_CONCURRENT) { - return "label=\"\""; - } else if (entity.getType() == EntityType.COMPONENT) { - return "label=" + getLabelForComponent(entity); - } else if (entity.getType() == EntityType.ACTIVITY) { - final DrawFile drawFile = entity.getImageFile(); - if (drawFile != null) { - final String path = StringUtils.getPlateformDependentAbsolutePath(drawFile.getPng()); - final String bgcolor = "\"" + data.getSkinParam().getBackgroundColor().getAsHtml() + "\""; - final StringBuilder sb = new StringBuilder("label=<"); - sb.append(""); - sb.append(""); - sb.append(""); - sb.append("
"); - sb.append("
"); - sb.append(">"); - return sb.toString(); - } - final String stereotype = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - return "label=" + getSimpleLabelAsHtml(entity, FontParam.ACTIVITY, stereotype); - } else if (entity.getType() == EntityType.EMPTY_PACKAGE) { - return "label=" + getSimpleLabelAsHtml(entity, getFontParamForGroup(), null); - } else if (entity.getType() == EntityType.USECASE) { - return "label=" + getLabelForUsecase(entity); - } else if (entity.getType() == EntityType.STATE) { - return "label=" + getLabelForState(entity); - } - return "label=\"" + entity.getDisplay() + "\""; - } - - private String getSimpleLabelAsHtml(IEntity entity, FontParam param, String stereotype) { - return "<" + manageHtmlIB(entity.getDisplay(), param, stereotype) + ">"; - } - - private String getBackColorOfEntity(IEntity entity) { - if (entity.getSpecificBackColor() != null) { - return "\"" + entity.getSpecificBackColor().getAsHtml() + "\""; - } - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - if (entity.getType() == EntityType.STATE || entity.getType() == EntityType.STATE_CONCURRENT) { - return getColorString(ColorParam.stateBackground, stereo); - } - if (entity.getType() == EntityType.ACTIVITY || entity.getType() == EntityType.ACTIVITY_CONCURRENT - || entity.getType() == EntityType.BRANCH) { - return getColorString(ColorParam.activityBackground, stereo); - } - throw new IllegalArgumentException(entity.getType().toString()); - } - - private String getLabelForState(IEntity entity) throws IOException { - final DrawFile cFile = entity.getImageFile(); - final String stateBgcolor = getBackColorOfEntity(entity); - - final String stereotype = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - - final StringBuilder sb = new StringBuilder("<{"); - sb.append(""); - sb.append("
" + manageHtmlIB(entity.getDisplay(), FontParam.STATE, stereotype) + "
"); - - if (entity.getFieldsToDisplay().size() > 0) { - sb.append("|"); - for (Member att : entity.getFieldsToDisplay()) { - sb.append(manageHtmlIB(att.getDisplayWithVisibilityChar(), FontParam.STATE_ATTRIBUTE, stereotype)); - sb.append("
"); - } - } - - if (cFile != null) { - sb.append("|"); - final String path = StringUtils.getPlateformDependentAbsolutePath(cFile.getPng()); - final String bgcolor; - if (OptionFlags.PBBACK) { - bgcolor = stateBgcolor; - } else { - bgcolor = "\"" + data.getSkinParam().getBackgroundColor().getAsHtml() + "\""; - } - // PBBACK - - sb.append(""); - sb.append(""); - sb.append(""); - sb.append("
"); - sb.append("
"); - } - - if (data.isHideEmptyDescription() == false && entity.getFieldsToDisplay().size() == 0 && cFile == null) { - sb.append("|"); - } - - sb.append("}>"); - - return sb.toString(); - } - - private String getLabelForUsecase(IEntity entity) { - final Stereotype stereotype = getStereotype(entity); - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - if (stereotype == null) { - return getSimpleLabelAsHtml(entity, FontParam.USECASE, stereo); - } - final StringBuilder sb = new StringBuilder("<"); - if (isThereLabel(stereotype)) { - sb.append(""); - } - sb.append(""); - sb.append("
" + manageHtmlIB(stereotype.getLabel(), FontParam.USECASE_STEREOTYPE, stereo) - + "
" + manageHtmlIB(entity.getDisplay(), FontParam.USECASE, stereo) + "
>"); - return sb.toString(); - } - - private String getLabelForComponent(IEntity entity) { - final Stereotype stereotype = getStereotype(entity); - if (stereotype == null) { - return getSimpleLabelAsHtml(entity, FontParam.COMPONENT, null); - } - final String stereo = stereotype.getLabel(); - final StringBuilder sb = new StringBuilder("<"); - if (isThereLabel(stereotype)) { - sb.append(""); - } - sb.append(""); - sb.append("
" + manageHtmlIB(stereotype.getLabel(), FontParam.COMPONENT_STEREOTYPE, stereo) - + "
" + manageHtmlIB(entity.getDisplay(), FontParam.COMPONENT, stereo) + "
>"); - return sb.toString(); - } - - private String getLabelForNoteDpi(IEntity entity) throws IOException { - final DrawFile file = entity.getImageFile(); - if (file == null) { - throw new IllegalStateException("No file for NOTE"); - } - if (file.getPngOrEps(fileFormat == FileFormat.EPS).exists() == false) { - throw new IllegalStateException(); - } - final String absolutePath = StringUtils.getPlateformDependentAbsolutePath(file - .getPngOrEps(fileFormat == FileFormat.EPS)); - - final StringBuilder sb = new StringBuilder("<"); - sb.append(""); - addTdImageBugB1983(sb, absolutePath); - sb.append(""); - sb.append("
>"); - return sb.toString(); - } - - private void addTdImageBugB1983(final StringBuilder sb, final String absolutePath) throws IOException { - // http://www.graphviz.org/bugs/b1983.html - final BufferedImage im = ImageIO.read(new File(absolutePath)); - final int height = im.getHeight(); - final int width = im.getWidth(); - final double f = 1.0 / data.getDpiFactor(); - final int w = (int) (width * f); - final int h = (int) (height * f); - final int w2 = (int) (width * getMagicFactorForImageDpi()); - final int h2 = (int) (height * getMagicFactorForImageDpi()); - sb.append(getTdHeaderForDpi(w, h)); - sb.append(""); - sb.append(""); - sb.append(getTdHeaderForDpi(w2, h2)); - sb.append(""); - sb.append(""); - sb.append(""); - sb.append("
"); - sb.append(""); - } - - private double getMagicFactorForImageDpi() { - return 10500 / 100000.0; - } - - private String getLabelForActor(IEntity entity) throws IOException { - final String actorAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(entity.getImageFile() - .getPngOrEps(fileFormat == FileFormat.EPS)); - final Stereotype stereotype = getStereotype(entity); - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - - final StringBuilder sb = new StringBuilder("<"); - if (isThereLabel(stereotype)) { - sb.append(""); - } - if (data.getDpi() == 96) { - sb.append(""); - } else { - sb.append(""); - addTdImageBugB1983(sb, actorAbsolutePath); - sb.append(""); - } - sb.append(""); - sb.append("
" + manageHtmlIB(stereotype.getLabel(), FontParam.USECASE_ACTOR_STEREOTYPE, stereo) - + "
" + manageHtmlIB(entity.getDisplay(), FontParam.USECASE_ACTOR, stereo) + "
>"); - return sb.toString(); - - } - - private String getLabelForCircleInterface(IEntity entity) throws IOException { - final String circleInterfaceAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(entity.getImageFile() - .getPngOrEps(fileFormat == FileFormat.EPS)); - final Stereotype stereotype = getStereotype(entity); - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - - final StringBuilder sb = new StringBuilder("<"); - if (isThereLabel(stereotype)) { - sb.append(""); - } - sb.append(""); - if (data.getDpi() == 96) { - sb.append(""); - } else { - addTdImageBugB1983(sb, circleInterfaceAbsolutePath); - } - sb.append(""); - sb.append(""); - sb.append("
" + manageHtmlIB(stereotype.getLabel(), FontParam.COMPONENT_STEREOTYPE, stereo) - + "
" + manageHtmlIB(entity.getDisplay(), FontParam.COMPONENT, stereo) + "
>"); - return sb.toString(); - - } - - private String getLabelForLollipop(IEntity entity) throws IOException { - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - final String circleInterfaceAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(data.getStaticImages( - EntityType.LOLLIPOP, stereo).getPngOrEps(fileFormat == FileFormat.EPS)); - final Stereotype stereotype = getStereotype(entity); - - final StringBuilder sb = new StringBuilder("<"); - if (isThereLabel(stereotype)) { - sb.append(""); - } - sb.append(""); - if (data.getDpi() == 96) { - sb.append(""); - } else { - addTdImageBugB1983(sb, circleInterfaceAbsolutePath); - } - sb.append(""); - sb.append(""); - sb.append("
" + manageHtmlIB(stereotype.getLabel(), FontParam.CLASS, null) + "
" + manageHtmlIB(entity.getDisplay(), FontParam.CLASS, null) + "
>"); - return sb.toString(); - - } - - private String getLabelForClassOrInterfaceOrEnum(IEntity entity) throws IOException { - if (isVisibilityModifierPresent) { - return getLabelForClassOrInterfaceOrEnumWithVisibilityImage(entity); - } - return getLabelForClassOrInterfaceOrEnumOld(entity); - - } - - private String getLabelForClassOrInterfaceOrEnumOld(IEntity entity) throws IOException { - - if (entity != null) { - final StringBuilder sb = new StringBuilder("<"); - sb.append(""); - sb.append(""); - sb.append(""); - sb.append("
B1
"); - sb.append(">"); - - return sb.toString(); - } - - DrawFile cFile = entity.getImageFile(); - if (cFile == null) { - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - cFile = data.getStaticImages(entity.getType(), stereo); - } - if (cFile == null) { - throw new IllegalStateException(); - } - final String circleAbsolutePath; - if (data.showPortion(EntityPortion.CIRCLED_CHARACTER, entity)) { - circleAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(cFile - .getPngOrEps(fileFormat == FileFormat.EPS)); - } else { - circleAbsolutePath = null; - } - - final StringBuilder sb = new StringBuilder("<"); - - final boolean showFields = data.showPortion(EntityPortion.FIELD, entity); - final boolean showMethods = data.showPortion(EntityPortion.METHOD, entity); - - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - - if (showFields == false && showMethods == false) { - sb.append(getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(entity, circleAbsolutePath, 1, true, 1)); - } else { - sb.append(""); - sb.append(""); - - if (showFields) { - // if (fileFormat == FileFormat.EPS) { - // sb.append(addFieldsEps(entity.fields2(), true)); - // } else { - final boolean hasStatic = hasStatic(entity.getFieldsToDisplay()); - sb.append(""); - // } - } - if (showMethods) { - // if (fileFormat == FileFormat.EPS) { - // sb.append(addFieldsEps(entity.methods2(), true)); - // } else { - final boolean hasStatic = hasStatic(entity.getMethodsToDisplay()); - sb.append(""); - // } - } - sb.append("
"); - final int longuestFieldOrAttribute = getLongestFieldOrAttribute(entity); - final int longuestHeader = getLonguestHeader(entity); - final int spring = computeSpring(longuestHeader, longuestFieldOrAttribute, 30); - - sb.append(getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(entity, circleAbsolutePath, spring, true, 0)); - - sb.append("
"); - for (Member att : entity.getFieldsToDisplay()) { - sb.append(manageHtmlIBspecial(att, FontParam.CLASS_ATTRIBUTE, hasStatic, getColorString( - ColorParam.classBackground, stereo), true)); - sb.append("
"); - } - sb.append("
"); - for (Member att : entity.getMethodsToDisplay()) { - sb.append(manageHtmlIBspecial(att, FontParam.CLASS_ATTRIBUTE, hasStatic, getColorString( - ColorParam.classBackground, stereo), true)); - sb.append("
"); - } - sb.append("
"); - } - sb.append(">"); - - return sb.toString(); - } - - final private List fileToClean = new ArrayList(); - - private String addFieldsEps(List members, boolean withVisibilityChar) throws IOException { - final List texts = new ArrayList(); - for (Member att : members) { - String s = att.getDisplay(withVisibilityChar); - if (att.isAbstract()) { - s = "" + s + ""; - } - if (att.isStatic()) { - s = "" + s + ""; - } - texts.add(s); - } - final Font font = data.getSkinParam().getFont(FontParam.CLASS_ATTRIBUTE, null); - final Color color = getFontHtmlColor(FontParam.CLASS_ATTRIBUTE, null).getColor(); - final TextBlock text = TextBlockUtils.create(texts, new FontConfiguration(font, color), - HorizontalAlignement.LEFT); - final File feps = FileUtils.createTempFile("member", ".eps"); - UGraphicEps.copyEpsToFile(new UDrawable() { - public void drawU(UGraphic ug) { - text.drawU(ug, 0, 0); - } - }, feps); - fileToClean.add(feps); - - final String path = StringUtils.getPlateformDependentAbsolutePath(feps); - - return "" + "" - + "" + "" + "
" + "
"; - } - - private boolean hasStatic(Collection attributes) { - for (Member att : attributes) { - if (att.isStatic()) { - return true; - } - } - return false; - } - - private String getLabelForClassOrInterfaceOrEnumWithVisibilityImage(IEntity entity) throws IOException { - DrawFile cFile = entity.getImageFile(); - if (cFile == null) { - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - cFile = data.getStaticImages(entity.getType(), stereo); - } - if (cFile == null) { - throw new IllegalStateException(); - } - final String circleAbsolutePath; - if (data.showPortion(EntityPortion.CIRCLED_CHARACTER, entity)) { - circleAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(cFile - .getPngOrEps(fileFormat == FileFormat.EPS)); - } else { - circleAbsolutePath = null; - } - - final boolean showFields = data.showPortion(EntityPortion.FIELD, entity); - final boolean showMethods = data.showPortion(EntityPortion.METHOD, entity); - - final StringBuilder sb = new StringBuilder("<"); - if (showFields == false && showMethods == false) { - sb.append(getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(entity, circleAbsolutePath, 1, true, 1)); - } else { - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - final int longuestHeader = getLonguestHeader(entity); - final int spring = computeSpring(longuestHeader, getLongestFieldOrAttribute(entity), 30); - final int springField = computeSpring(getLongestField(entity), Math.max(longuestHeader, - getLongestMethods(entity)), 30); - final int springMethod = computeSpring(getLongestMethods(entity), Math.max(longuestHeader, - getLongestField(entity)), 30); - - sb.append(""); - sb.append(""); - - if (showFields) { - sb.append(""); - } - if (showMethods) { - sb.append(""); - } - sb.append("
"); - - sb.append(getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(entity, circleAbsolutePath, spring, true, 0)); - sb.append("
"); - if (entity.getFieldsToDisplay().size() > 0) { - buildTableVisibility(entity, true, sb, springField); - } - sb.append("
"); - if (entity.getMethodsToDisplay().size() > 0) { - buildTableVisibility(entity, false, sb, springMethod); - } - sb.append("
"); - } - sb.append(">"); - - return sb.toString(); - - } - - private int computeSpring(final int current, final int maximum, int maxSpring) { - if (maximum <= current) { - return 0; - } - final int spring = maximum - current; - if (spring > maxSpring) { - return maxSpring; - } - return spring; - } - - private void buildTableVisibility(IEntity entity, boolean isField, final StringBuilder sb, int spring) - throws IOException { - sb.append(""); - - final boolean hasStatic = hasStatic(entity.getMethodsToDisplay()); - final boolean dpiNormal = data.getDpi() == 96; - for (Member att : isField ? entity.getFieldsToDisplay() : entity.getMethodsToDisplay()) { - sb.append(""); - if (dpiNormal) { - sb.append(""); - } - sb.append(""); - for (int i = 0; i < spring; i++) { - sb.append(""); - } - sb.append(""); - } - sb.append("
"); - } - String s = att.getDisplayWithVisibilityChar(); - final VisibilityModifier visibilityModifier = VisibilityModifier - .getVisibilityModifier(s.charAt(0), isField); - if (visibilityModifier != null) { - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - final String modifierFile = StringUtils.getPlateformDependentAbsolutePath(data.getVisibilityImages( - visibilityModifier, stereo).getPngOrEps(fileFormat == FileFormat.EPS)); - if (dpiNormal) { - sb.append(""); - } else { - addTdImageBugB1983(sb, modifierFile); - } - s = s.substring(1); - } - if (dpiNormal) { - sb.append(""); - sb.append(manageHtmlIBspecial(att, FontParam.CLASS_ATTRIBUTE, hasStatic, getColorString( - ColorParam.classBackground, null), false)); - sb.append("
"); - } - - private int getLonguestHeader(IEntity entity) { - int result = entity.getDisplay().length(); - final Stereotype stereotype = getStereotype(entity); - if (isThereLabel(stereotype)) { - final int size = stereotype.getLabel().length(); - if (size > result) { - result = size; - } - } - return result; - } - - private int getLongestFieldOrAttribute(IEntity entity) { - return Math.max(getLongestField(entity), getLongestMethods(entity)); - } - - private int getLongestMethods(IEntity entity) { - int result = 0; - for (Member att : entity.getMethodsToDisplay()) { - final int size = att.getDisplayWithVisibilityChar().length(); - if (size > result) { - result = size; - } - } - return result; - - } - - private int getLongestField(IEntity entity) { - int result = 0; - for (Member att : entity.getFieldsToDisplay()) { - final int size = att.getDisplayWithVisibilityChar().length(); - if (size > result) { - result = size; - } - } - return result; - } - - private String getLabelForObject(IEntity entity) throws IOException { - if (isVisibilityModifierPresent) { - return getLabelForObjectWithVisibilityImage(entity); - } - return getLabelForObjectOld(entity); - } - - private String getLabelForObjectWithVisibilityImage(IEntity entity) throws IOException { - - final int longuestHeader = getLonguestHeader(entity); - final int spring = computeSpring(longuestHeader, getLongestFieldOrAttribute(entity), 30); - final int springField = computeSpring(getLongestField(entity), Math.max(longuestHeader, - getLongestMethods(entity)), 30); - - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - - final StringBuilder sb = new StringBuilder("<"); - sb.append(""); - sb.append(""); - sb.append("
"); - - sb.append(getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(entity, null, spring, false, 0)); - - sb.append("
"); - - if (entity.getFieldsToDisplay().size() == 0) { - sb.append(manageHtmlIB(" ", FontParam.OBJECT_ATTRIBUTE, stereo)); - } else { - buildTableVisibility(entity, true, sb, springField); - } - - sb.append("
>"); - - return sb.toString(); - - } - - private String getLabelForObjectOld(IEntity entity) throws IOException { - - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - - final StringBuilder sb = new StringBuilder("<"); - sb.append(""); - sb.append(""); - sb.append("
"); - - final int longuestFieldOrAttribute = getLongestFieldOrAttribute(entity); - final int longuestHeader = getLonguestHeader(entity); - final int spring = computeSpring(longuestHeader, longuestFieldOrAttribute, 30); - - sb.append(getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(entity, null, spring, false, 0)); - - sb.append("
"); - - if (entity.getFieldsToDisplay().size() == 0) { - sb.append(manageHtmlIB(" ", FontParam.OBJECT_ATTRIBUTE, stereo)); - } else { - for (Member att : entity.getFieldsToDisplay()) { - sb.append(manageHtmlIB(att.getDisplayWithVisibilityChar(), FontParam.OBJECT_ATTRIBUTE, stereo)); - sb.append("
"); - } - } - - sb.append("
>"); - - return sb.toString(); - } - - private String getWitdh55() { - if (data.getDpi() == 96) { - return "WIDTH=\"55\""; - } - return "WIDTH=\"55\""; - } - - private 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 String result = dotExpression.getDotHtml(); - if (dotExpression.isUnderline()) { - underline = true; - } - return result; - } - - private String manageHtmlIBspecial(Member att, FontParam param, boolean hasStatic, String backColor, - boolean withVisibilityChar) { - String prefix = ""; - if (hasStatic) { - prefix = "_"; - } - if (att.isAbstract()) { - return prefix + manageHtmlIB("" + att.getDisplay(withVisibilityChar), param, null); - } - if (att.isStatic()) { - return manageHtmlIB("" + att.getDisplay(withVisibilityChar), param, null); - } - return prefix + manageHtmlIB(att.getDisplay(withVisibilityChar), param, null); - } - - private String manageSpace(int size) { - final DotExpression dotExpression = new DotExpression(" ", size, HtmlColor.getColorIfValid("white"), null, - Font.PLAIN, fileFormat); - final String result = dotExpression.getDotHtml(); - return result; - } - - static String unicode(String s) { - final StringBuilder result = new StringBuilder(); - for (char c : s.toCharArray()) { - if (c > 127 || c == '&') { - final int i = c; - result.append("&#" + i + ";"); - } else { - result.append(c); - } - } - return result.toString(); - } - - private String getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnumNoSpring(IEntity entity, - final String circleAbsolutePath, int cellSpacing, boolean classes) throws IOException { - final StringBuilder sb = new StringBuilder(); - sb.append(""); - sb.append(""); - if (circleAbsolutePath == null) { - sb.append(""); - } else { - addTdImageBugB1983(sb, circleAbsolutePath); - - } - sb.append("
"); - } else { - if (data.getDpi() == 96) { - sb.append(""); - sb.append(""); - } - - appendLabelAndStereotype(entity, sb, classes); - sb.append("
"); - return sb.toString(); - } - - private String getTdHeaderForDpi(final double w, final double h) { - // return ""; - return ""; - } - - private String getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(IEntity entity, final String circleAbsolutePath, - int spring, boolean classes, int border) throws IOException { - if (spring == 0) { - return getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnumNoSpring(entity, circleAbsolutePath, 0, classes); - } - final StringBuilder sb = new StringBuilder(); - - sb - .append(""); - sb.append(""); - - for (int i = 0; i < spring; i++) { - sb.append(""); - } - - if (circleAbsolutePath != null) { - if (circleAbsolutePath.endsWith(".png")) { - if (data.getDpi() == 96) { - final BufferedImage im = ImageIO.read(new File(circleAbsolutePath)); - final int height = im.getHeight(); - final int width = im.getWidth(); - sb.append(""); - } else { - addTdImageBugB1983(sb, circleAbsolutePath); - } - } else if (circleAbsolutePath.endsWith(".eps")) { - sb.append(""); - } - } - - sb.append(""); - - for (int i = 0; i < spring; i++) { - sb.append(""); - } - sb.append("
"); - appendLabelAndStereotype(entity, sb, classes); - sb.append("
"); - return sb.toString(); - } - - private void appendLabelAndStereotype(IEntity entity, final StringBuilder sb, boolean classes) { - final Stereotype stereotype = getStereotype(entity); - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - if (isThereLabel(stereotype)) { - sb.append("
"); - sb.append(manageHtmlIB(stereotype.getLabel(), classes ? FontParam.CLASS_STEREOTYPE - : FontParam.OBJECT_STEREOTYPE, stereo)); - sb.append("
"); - } - String display = entity.getDisplay(); - final boolean italic = entity.getType() == EntityType.ABSTRACT_CLASS - || entity.getType() == EntityType.INTERFACE; - if (italic) { - display = "" + display; - } - sb.append(manageHtmlIB(display, classes ? FontParam.CLASS : FontParam.OBJECT, stereo)); - } - - private String getHtmlHeaderTableForClassOrInterfaceOrEnumNew(Entity entity, final String circleAbsolutePath) { - final StringBuilder sb = new StringBuilder(); - sb.append(""); - sb.append("
"); - - appendLabelAndStereotype(entity, sb, true); - sb.append("
"); - return sb.toString(); - } - - private boolean isThereLabel(final Stereotype stereotype) { - return stereotype != null && stereotype.getLabel() != null; - } - - private Stereotype getStereotype(IEntity entity) { - if (data.showPortion(EntityPortion.STEREOTYPE, entity) == false) { - return null; - } - return entity.getStereotype(); - } - - public final boolean isUnderline() { - return underline; - } - - private boolean workAroundDotBug() { - for (Link link : data.getLinks()) { - if (link.getLength() != 1) { - return false; - } - } - if (data.getUmlDiagramType() == UmlDiagramType.CLASS && allEntitiesAreClasses(data.getEntities().values())) { - return true; - } - for (IEntity ent : data.getEntities().values()) { - if (data.getAllLinkedTo(ent).size() == 0) { - return true; - } - } - return false; - } - - private boolean allEntitiesAreClasses(Collection entities) { - for (IEntity ent : entities) { - if (ent.getType() != EntityType.CLASS && ent.getType() != EntityType.ABSTRACT_CLASS - && ent.getType() != EntityType.INTERFACE && ent.getType() != EntityType.ENUM) { - return false; - } - } - return true; - } - - private boolean isSpecialGroup(Group g) { - if (g.getType() == GroupType.STATE) { - return true; - } - if (g.getType() == GroupType.CONCURRENT_STATE) { - throw new IllegalStateException(); - } - if (data.isThereLink(g)) { - return true; - } - return false; - } - - public static final String getLastDotSignature() { - return lastDotSignature; - } - - public static final void reset() { - lastDotSignature = null; - } - - public void clean() { - if (OptionFlags.getInstance().isKeepTmpFiles()) { - return; - } - for (File f : fileToClean) { - Log.info("Deleting temporary file " + f); - final boolean ok = f.delete(); - if (ok == false) { - Log.error("Cannot delete: " + f); - } - } - } - -} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/DotMakerOk.java b/src/net/sourceforge/plantuml/cucadiagram/dot/DotMakerOk.java deleted file mode 100644 index c9d88ef67..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/DotMakerOk.java +++ /dev/null @@ -1,1813 +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: 6295 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.awt.Color; -import java.awt.Font; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import javax.imageio.ImageIO; - -import net.sourceforge.plantuml.ColorParam; -import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.FileUtils; -import net.sourceforge.plantuml.FontParam; -import net.sourceforge.plantuml.Log; -import net.sourceforge.plantuml.OptionFlags; -import net.sourceforge.plantuml.SignatureUtils; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.UmlDiagramType; -import net.sourceforge.plantuml.cucadiagram.Entity; -import net.sourceforge.plantuml.cucadiagram.EntityPortion; -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.Link; -import net.sourceforge.plantuml.cucadiagram.LinkType; -import net.sourceforge.plantuml.cucadiagram.Member; -import net.sourceforge.plantuml.cucadiagram.Rankdir; -import net.sourceforge.plantuml.cucadiagram.Stereotype; -import net.sourceforge.plantuml.graphic.FontConfiguration; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; -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.skin.VisibilityModifier; -import net.sourceforge.plantuml.skin.rose.Rose; -import net.sourceforge.plantuml.ugraphic.UGraphic; -import net.sourceforge.plantuml.ugraphic.eps.UGraphicEps; - -final public class DotMakerOk implements GraphvizMaker { - - private final DotData data; - - private static boolean isJunit = false; - - private final List dotStrings; - private boolean underline = false; - private final Rose rose = new Rose(); - - private static String lastDotSignature; - - private final FileFormat fileFormat; - - private final boolean isVisibilityModifierPresent; - - // http://www.graphviz.org/bugs/b2114.html - private static final boolean TURN_AROUND_B2114 = false; - - private final Set hasAlreadyOneIncommingArrowLenghtOne; - - final private Set rankMin = new HashSet(); - - public static void goJunit() { - isJunit = true; - } - - public DotMakerOk(DotData data, List dotStrings, FileFormat fileFormat) { - this.data = data; - this.dotStrings = dotStrings; - this.fileFormat = fileFormat; - if (data.getSkinParam().classAttributeIconSize() > 0) { - this.isVisibilityModifierPresent = data.isThereVisibilityImages(); - } else { - this.isVisibilityModifierPresent = false; - } - this.hasAlreadyOneIncommingArrowLenghtOne = TURN_AROUND_B2114 ? new HashSet() : null; - } - - public String createDotString() throws IOException { - - final StringBuilder sb = new StringBuilder(); - - initPrintWriter(sb); - printGroups(sb, null); - printEntities(sb, getUnpackagedEntities()); - printLinks(sb, data.getLinks()); - printRanking(sb); - sb.append("}"); - - // System.err.println(sb); - if (isJunit) { - lastDotSignature = SignatureUtils.getSignatureWithoutImgSrc(sb.toString()); - } - return sb.toString(); - } - - private void printRanking(StringBuilder sb) { - if (rankMin.size() == 0) { - return; - } - sb.append("{ rank = min;"); - for (String id : rankMin) { - sb.append(id); - sb.append(";"); - } - sb.append("}"); - - } - - private void initPrintWriter(StringBuilder sb) { - - Log.info("Entities = " + data.getEntities().size()); - final boolean huge = data.getEntities().size() > 800; - - sb.append("digraph unix {"); - // if (isJunit == false) { - for (String s : dotStrings) { - sb.append(s); - } - // } - sb.append("bgcolor=\"" + data.getSkinParam().getBackgroundColor().getAsHtml() + "\";"); - if (huge) { - sb.append("size=\"400,400;\""); - } else { - sb.append("ratio=auto;"); - // sb.append("concentrate=true;"); - } - // sb.append("ordering=out;"); - sb.append("compound=true;"); - final DotSplines dotSplines = data.getSkinParam().getDotSplines(); - final GraphvizLayoutStrategy strategy = data.getSkinParam().getStrategy(); - if (dotSplines == DotSplines.ORTHO) { - sb.append("splines=ortho;"); - } else if (dotSplines == DotSplines.POLYLINE) { - sb.append("splines=polyline;"); - } else if (strategy != GraphvizLayoutStrategy.DOT) { - sb.append("splines=true;"); - } - - // if (strategy == GraphvizLayoutStrategy.NEATO) { - // sb.append("overlap=false;"); - // } - if (strategy != GraphvizLayoutStrategy.DOT) { - sb.append("layout=" + strategy.name().toLowerCase() + ";"); - sb.append("overlap=false;"); - } - - sb.append("remincross=true;"); - sb.append("searchsize=500;"); - if (data.getRankdir() == Rankdir.LEFT_TO_RIGHT) { - sb.append("rankdir=LR;"); - } - - if (data.getDpi() != 96) { - sb.append("dpi=" + data.getDpi() + ";"); - sb.append("imagescale=both;"); - } - } - - private Collection getUnpackagedEntities() { - final List result = new ArrayList(); - for (IEntity ent : data.getEntities().values()) { - if (ent.getParent() == data.getTopParent()) { - result.add(ent); - } - } - return result; - } - - private void printGroups(StringBuilder sb, Group parent) throws IOException { - for (Group g : data.getGroupHierarchy().getChildrenGroups(parent)) { - if (data.isEmpty(g) && g.getType() == GroupType.PACKAGE) { - final IEntity folder = new Entity(g.getUid(), g.getCode(), g.getDisplay(), EntityType.EMPTY_PACKAGE, - null, null); - printEntity(sb, folder); - } else { - printGroup(sb, g); - } - } - } - - private void printGroup(StringBuilder sb, Group g) throws IOException { - if (g.getType() == GroupType.CONCURRENT_STATE) { - return; - } - - if (isSpecialGroup(g)) { - printGroupSpecial(sb, g); - } else { - printGroupNormal(sb, g); - } - } - - private void printGroupNormal(StringBuilder sb, Group g) throws IOException { - - final String stereo = g.getStereotype(); - - sb.append("subgraph " + g.getUid() + " {"); - // sb.append("margin=10;"); - - sb.append("fontsize=\"" + data.getSkinParam().getFontSize(getFontParamForGroup(), stereo) + "\";"); - final String fontFamily = data.getSkinParam().getFontFamily(getFontParamForGroup(), stereo); - if (fontFamily != null) { - sb.append("fontname=\"" + fontFamily + "\";"); - } - - if (g.getDisplay() != null) { - sb.append("label=<" + manageHtmlIB(g.getDisplay(), getFontParamForGroup(), stereo) + ">;"); - } - final String fontColor = data.getSkinParam().getFontHtmlColor(getFontParamForGroup(), stereo).getAsHtml(); - sb.append("fontcolor=\"" + fontColor + "\";"); - - if (getGroupBackColor(g) != null) { - sb.append("fillcolor=\"" + getGroupBackColor(g).getAsHtml() + "\";"); - } - - if (g.getType() == GroupType.STATE) { - sb.append("color=" + getColorString(ColorParam.stateBorder, stereo) + ";"); - } else { - sb.append("color=" + getColorString(ColorParam.packageBorder, stereo) + ";"); - } - sb.append("style=\"" + getStyle(g) + "\";"); - - printGroups(sb, g); - - this.printEntities(sb, g.entities().values()); - for (Link link : data.getLinks()) { - eventuallySameRank(sb, g, link); - } - sb.append("}"); - } - - private HtmlColor getGroupBackColor(Group g) { - HtmlColor value = g.getBackColor(); - if (value == null) { - value = data.getSkinParam().getHtmlColor(ColorParam.packageBackground, null); - // value = rose.getHtmlColor(this.data.getSkinParam(), - // ColorParam.packageBackground); - } - return value; - } - - private void printGroupSpecial(StringBuilder sb, Group g) throws IOException { - - sb.append("subgraph " + g.getUid() + "a {"); - if (OptionFlags.getInstance().isDebugDot()) { - sb.append("style=dotted;"); - sb.append("label=\"a\";"); - } else { - sb.append("style=invis;"); - sb.append("label=\"\";"); - } - - sb.append("subgraph " + g.getUid() + "v {"); - sb.append("style=solid;"); - // sb.append("margin=10;"); - - final List autolinks = data.getAutoLinks(g); - final List toEdgeLinks = data.getToEdgeLinks(g); - final List fromEdgeLinks = data.getFromEdgeLinks(g); - final boolean autoLabel = autolinks.size() == 1; - - final List nodesHiddenUidOut = getNodesHiddenUidOut(g); - final List nodesHiddenUidIn = getNodesHiddenUidIn(g); - final List nodesHiddenUid = new ArrayList(nodesHiddenUidOut); - nodesHiddenUid.addAll(nodesHiddenUidIn); - for (Link link : nodesHiddenUid) { - final String uid = getHiddenNodeUid(g, link); - // sb.append("subgraph " + g.getUid() + "k" + uid + " {"); - if (OptionFlags.getInstance().isDebugDot()) { - sb.append("style=dotted;"); - sb.append("label=\"k" + uid + "\";"); - } else { - sb.append("style=invis;"); - sb.append("label=\"\";"); - } - if (OptionFlags.getInstance().isDebugDot()) { - sb.append(uid + ";"); - } else { - sb.append(uid + " [shape=point,width=.01,style=invis,label=\"\"];"); - } - // sb.append("}"); // end of k - } - - for (int j = 1; j < nodesHiddenUidOut.size(); j++) { - for (int i = 0; i < j; i++) { - final Link linki = nodesHiddenUidOut.get(i); - final Link linkj = nodesHiddenUidOut.get(j); - if (linki.getEntity2() != linkj.getEntity2()) { - continue; - } - final String uidi = getHiddenNodeUid(g, linki); - final String uidj = getHiddenNodeUid(g, linkj); - if (OptionFlags.getInstance().isDebugDot()) { - sb.append(uidi + "->" + uidj + ";"); - } else { - sb.append(uidi + "->" + uidj + " [style=invis,arrowtail=none,arrowhead=none];"); - } - - } - } - - if (autoLabel /* || toEdgeLinks.size() > 0 || fromEdgeLinks.size() > 0 */) { - if (OptionFlags.getInstance().isDebugDot()) { - sb.append(g.getUid() + "lmin;"); - sb.append(g.getUid() + "lmax;"); - sb.append(g.getUid() + "lmin->" + g.getUid() + "lmax [minlen=2]; "); - } else { - sb.append(g.getUid() + "lmin [shape=point,width=.01,style=invis,label=\"\"];"); - sb.append(g.getUid() + "lmax [shape=point,width=.01,style=invis,label=\"\"];"); - sb.append(g.getUid() + "lmin->" + g.getUid() - + "lmax [minlen=2,style=invis,arrowtail=none,arrowhead=none]; "); - } - } - // sb.append(g.getUid() + "min->" + g.getUid() + "max;"); - - sb.append("fontsize=\"" + data.getSkinParam().getFontSize(getFontParamForGroup(), null) + "\";"); - final String fontFamily = data.getSkinParam().getFontFamily(getFontParamForGroup(), null); - if (fontFamily != null) { - sb.append("fontname=\"" + fontFamily + "\";"); - } - - if (g.getDisplay() != null) { - final StringBuilder label = new StringBuilder(manageHtmlIB(g.getDisplay(), getFontParamForGroup(), null)); - if (g.getEntityCluster().getFieldsToDisplay().size() > 0) { - label.append("
"); - for (Member att : g.getEntityCluster().getFieldsToDisplay()) { - label.append(manageHtmlIB(" " + att.getDisplayWithVisibilityChar() + " ", - FontParam.STATE_ATTRIBUTE, null)); - label.append("
"); - } - } - sb.append("label=<" + label + ">;"); - } - - final String fontColor = data.getSkinParam().getFontHtmlColor(getFontParamForGroup(), null).getAsHtml(); - sb.append("fontcolor=\"" + fontColor + "\";"); - final HtmlColor groupBackColor = getGroupBackColor(g); - if (groupBackColor != null) { - sb.append("fillcolor=\"" + groupBackColor.getAsHtml() + "\";"); - } - if (g.getType() == GroupType.STATE) { - sb.append("color=" + getColorString(ColorParam.stateBorder, null) + ";"); - } else { - sb.append("color=" + getColorString(ColorParam.packageBorder, null) + ";"); - } - sb.append("style=\"" + getStyle(g) + "\";"); - - sb.append("subgraph " + g.getUid() + "i {"); - sb.append("label=\"i\";"); - if (OptionFlags.getInstance().isDebugDot()) { - sb.append("style=dotted;"); - sb.append("label=\"i\";"); - } else { - - if (groupBackColor == null) { - sb.append("style=invis;"); - } else { - final String colorBack = getColorString(ColorParam.background, null); - sb.append("fillcolor=" + colorBack + ";"); - sb.append("color=" + colorBack + ";"); - sb.append("style=\"filled,rounded\";"); - } - sb.append("label=\"\";"); - - } - - printGroups(sb, g); - - this.printEntities(sb, g.entities().values()); - for (Link link : data.getLinks()) { - eventuallySameRank(sb, g, link); - } - - for (int i = 0; i < fromEdgeLinks.size(); i++) { - if (OptionFlags.getInstance().isDebugDot()) { - sb.append("eds" + i + ";"); - } else { - sb.append("eds" + i + " [shape=point,width=.01,style=invis,label=\"\"];"); - } - sb.append("eds" + i + " ->" + fromEdgeLinks.get(i).getEntity2().getUid() - + " [minlen=2,style=invis,arrowtail=none,arrowhead=none]; "); - - } - - sb.append("}"); // end of i - sb.append("}"); // end of v - - if (autoLabel) { - sb.append("subgraph " + g.getUid() + "l {"); - if (OptionFlags.getInstance().isDebugDot()) { - sb.append("style=dotted;"); - sb.append("label=\"l\";"); - } else { - sb.append("style=invis;"); - sb.append("label=\"\";"); - } - final String decorationColor = ",color=" + getColorString(getArrowColorParam(), null); - - sb.append(g.getUid() + "lab0 [shape=point,width=.01,label=\"\"" + decorationColor + "]"); - String autolabel = autolinks.get(0).getLabel(); - if (autolabel == null) { - autolabel = ""; - } - sb.append(g.getUid() + "lab1 [label=<" + manageHtmlIB(autolabel, getArrowFontParam(), null) - + ">,shape=plaintext,margin=0];"); - sb.append(g.getUid() + "lab0 -> " + g.getUid() + "lab1 [minlen=0,style=invis];"); - sb.append("}"); // end of l - - sb.append(g.getUid() + "lmin -> " + g.getUid() + "lab0 [ltail=" + g.getUid() - + "v,arrowtail=none,arrowhead=none" + decorationColor + "];"); - sb.append(g.getUid() + "lab0 -> " + g.getUid() + "lmax [lhead=" + g.getUid() - + "v,arrowtail=none,arrowhead=open" + decorationColor + "];"); - } - - for (int i = 0; i < fromEdgeLinks.size(); i++) { - sb.append("subgraph " + g.getUid() + "ed" + i + " {"); - if (OptionFlags.getInstance().isDebugDot()) { - sb.append("style=dotted;"); - sb.append("label=\"ed" + i + "\";"); - } else { - sb.append("style=invis;"); - sb.append("label=\"\";"); - } - final String decorationColor = ",color=" + getColorString(getArrowColorParam(), null); - String label = fromEdgeLinks.get(i).getLabel(); - if (label == null) { - label = ""; - } - - sb.append(g.getUid() + "fedge" + i + " [shape=point,width=.01,label=\"\"" + decorationColor + "]"); - sb.append("}"); // end of ed - sb.append("eds" + i + " -> " + g.getUid() + "fedge" + i + " [ltail=" + g.getUid() - + "v,arrowtail=none,arrowhead=none" + decorationColor + "];"); - sb.append(g.getUid() + "fedge" + i + " -> " + fromEdgeLinks.get(i).getEntity2().getUid() - + "[arrowtail=none,arrowhead=open" + decorationColor); - sb.append(",label=<" + manageHtmlIB(label, getArrowFontParam(), null) + ">];"); - - } - sb.append("}"); // end of a - } - - private FontParam getFontParamForGroup() { - if (data.getUmlDiagramType() == UmlDiagramType.STATE) { - return FontParam.STATE; - } - return FontParam.PACKAGE; - } - - private String getStyle(Group g) { - final StringBuilder sb = new StringBuilder(); - if (g.isBold()) { - sb.append("bold"); - } else if (g.isDashed()) { - sb.append("dashed"); - } else { - sb.append("solid"); - - } - if (getGroupBackColor(g) != null) { - sb.append(",filled"); - } - if (g.isRounded()) { - sb.append(",rounded"); - } - return sb.toString(); - } - - private void printLinks(StringBuilder sb, List links) throws IOException { - for (Link link : appendPhantomLink(links)) { - final IEntity entity1 = link.getEntity1(); - final IEntity entity2 = link.getEntity2(); - if (entity1 == entity2 && entity1.getType() == EntityType.GROUP) { - continue; - } - if (entity1.getType() == EntityType.GROUP && entity2.getParent() == entity1.getParent()) { - continue; - } - if (entity2.getType() == EntityType.GROUP && entity1.getParent() == entity2.getParent()) { - continue; - } - if (entity1.getType() == EntityType.LOLLIPOP || entity2.getType() == EntityType.LOLLIPOP) { - continue; - } - // System.err.println("outing " + link); - printLink(sb, link); - } - } - - private void printLink(StringBuilder sb, Link link) throws IOException { - -// if (link.isConstraint()==false) { -// return; -// } - - final StringBuilder decoration = getLinkDecoration(link); - - if (link.getWeight() > 1) { - decoration.append("weight=" + link.getWeight() + ","); - } - if (link.getLabeldistance() != null) { - decoration.append("labeldistance=" + link.getLabeldistance() + ","); - } - if (link.getLabelangle() != null) { - decoration.append("labelangle=" + link.getLabelangle() + ","); - } - if (link.isConstraint() == false) { - decoration.append("constraint=false,"); - } - - final DrawFile noteLink = link.getImageFile(); - - boolean hasLabel = false; - - 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)) + ">,"); - hasLabel = true; - } - - if (link.getQualifier1() != null) { - decoration.append("taillabel=<" + manageHtmlIB(link.getQualifier1(), getArrowFontParam(), null) + ">,"); - } - if (link.getQualifier2() != null) { - decoration.append("headlabel=<" + manageHtmlIB(link.getQualifier2(), getArrowFontParam(), null) + ">,"); - } - final int len = link.getLength(); - String uid1 = link.getEntity1().getUid(); - String uid2 = link.getEntity2().getUid(); - LinkType typeToDraw = link.getType(); - if (TURN_AROUND_B2114 && len == 1 && hasAlreadyOneIncommingArrowLenghtOne.contains(uid2) && hasLabel) { - typeToDraw = typeToDraw.getInv(); - } - if (TURN_AROUND_B2114 && len == 1) { - hasAlreadyOneIncommingArrowLenghtOne.add(uid2); - } - decoration.append(typeToDraw.getSpecificDecoration()); - if (link.isInvis()) { - decoration.append(",style=invis"); - } - - // if (len == 1) { - // decoration.append(",constraint=false"); - // } - final String lenString = len >= 3 ? ",minlen=" + (len - 1) : ""; - - if (link.getEntity1().getType() == EntityType.GROUP) { - uid1 = getHiddenNodeUid(link.getEntity1().getParent(), link); - decoration.append(",ltail=" + link.getEntity1().getParent().getUid() + "v"); - } - if (link.getEntity2().getType() == EntityType.GROUP) { - uid2 = getHiddenNodeUid(link.getEntity2().getParent(), link); - decoration.append(",lhead=" + link.getEntity2().getParent().getUid() + "v"); - } - - sb.append(uid1 + " -> " + uid2); - sb.append(decoration); - sb.append(lenString + "];"); - eventuallySameRank(sb, data.getTopParent(), link); - } - - private List getNodesHiddenUidOut(Group g) { - final List result = new ArrayList(); - for (Link link : data.getLinks()) { - if (link.getEntity1().getParent() == link.getEntity2().getParent()) { - continue; - } - if (link.getEntity1().getType() == EntityType.GROUP && link.getEntity1().getParent() == g) { - result.add(link); - } - } - return Collections.unmodifiableList(result); - } - - private List getNodesHiddenUidIn(Group g) { - final List result = new ArrayList(); - for (Link link : data.getLinks()) { - if (link.getEntity1().getParent() == link.getEntity2().getParent()) { - continue; - } - if (link.getEntity2().getType() == EntityType.GROUP && link.getEntity2().getParent() == g) { - result.add(link); - } - } - return Collections.unmodifiableList(result); - } - - private String getHiddenNodeUid(Group g, Link link) { - if (data.isEmpty(g) && g.getType() == GroupType.PACKAGE) { - return g.getUid(); - } - return g.getUid() + "_" + link.getUid(); - } - - private StringBuilder getLinkDecoration(Link link) { - final StringBuilder decoration = new StringBuilder("[color="); - if (link.getSpecificColor() == null) { - decoration.append(getColorString(getArrowColorParam(), null)); - } else { - decoration.append("\"" + link.getSpecificColor().getAsHtml() + "\""); - } - decoration.append(","); - - decoration.append("fontcolor=" + getFontColorString(getArrowFontParam(), null) + ","); - decoration.append("fontsize=\"" + data.getSkinParam().getFontSize(getArrowFontParam(), null) + "\","); - - final String fontName = data.getSkinParam().getFontFamily(getArrowFontParam(), null); - if (fontName != null) { - decoration.append("fontname=\"" + fontName + "\","); - } - return decoration; - } - - private List appendPhantomLink(List links) { - final List result = new ArrayList(links); - for (Link link : links) { - if (link.getLength() != 1) { - continue; - } - final DrawFile noteLink = link.getImageFile(); - if (noteLink == null) { - continue; - } - final Link phantom = new Link(link.getEntity1(), link.getEntity2(), link.getType(), null, link.getLength()); - phantom.setInvis(true); - result.add(phantom); - } - return result; - } - - private String getHtmlForLinkNote(File image) { - final String circleInterfaceAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(image); - final StringBuilder sb = new StringBuilder(""); - sb.append(""); - sb.append("
"); - return sb.toString(); - - } - - private FontParam getArrowFontParam() { - if (data.getUmlDiagramType() == UmlDiagramType.CLASS) { - return FontParam.CLASS_ARROW; - } else if (data.getUmlDiagramType() == UmlDiagramType.OBJECT) { - return FontParam.OBJECT_ARROW; - } else if (data.getUmlDiagramType() == UmlDiagramType.USECASE) { - return FontParam.USECASE_ARROW; - } else if (data.getUmlDiagramType() == UmlDiagramType.ACTIVITY) { - return FontParam.ACTIVITY_ARROW; - } else if (data.getUmlDiagramType() == UmlDiagramType.COMPONENT) { - return FontParam.COMPONENT_ARROW; - } else if (data.getUmlDiagramType() == UmlDiagramType.STATE) { - return FontParam.STATE_ARROW; - } - throw new IllegalStateException(); - } - - private ColorParam getArrowColorParam() { - if (data.getUmlDiagramType() == UmlDiagramType.CLASS) { - return ColorParam.classArrow; - } else if (data.getUmlDiagramType() == UmlDiagramType.OBJECT) { - return ColorParam.objectArrow; - } else if (data.getUmlDiagramType() == UmlDiagramType.USECASE) { - return ColorParam.usecaseArrow; - } else if (data.getUmlDiagramType() == UmlDiagramType.ACTIVITY) { - return ColorParam.activityArrow; - } else if (data.getUmlDiagramType() == UmlDiagramType.COMPONENT) { - return ColorParam.componentArrow; - } else if (data.getUmlDiagramType() == UmlDiagramType.STATE) { - return ColorParam.stateArrow; - } - throw new IllegalStateException(); - } - - private String getColorString(ColorParam colorParam, String stereotype) { - return "\"" + rose.getHtmlColor(data.getSkinParam(), colorParam, stereotype).getAsHtml() + "\""; - } - - private String getFontColorString(FontParam fontParam, String stereotype) { - return "\"" + getFontHtmlColor(fontParam, stereotype).getAsHtml() + "\""; - } - - private HtmlColor getFontHtmlColor(FontParam fontParam, String stereotype) { - return data.getSkinParam().getFontHtmlColor(fontParam, stereotype); - } - - private void eventuallySameRank(StringBuilder sb, Group entityPackage, Link link) { - final int len = link.getLength(); - if (len == 1 && link.getEntity1().getParent() == entityPackage - && link.getEntity2().getParent() == entityPackage) { - if (link.getEntity1().getType() == EntityType.GROUP) { - throw new IllegalArgumentException(); - } - if (link.getEntity2().getType() == EntityType.GROUP) { - throw new IllegalArgumentException(); - } - sb.append("{rank=same; " + link.getEntity1().getUid() + "; " + link.getEntity2().getUid() + "}"); - } - } - - private void printEntities(StringBuilder sb, Collection entities) throws IOException { - final Set lollipops = new HashSet(); - final Set lollipopsFriends = new HashSet(); - for (IEntity entity : entities) { - if (entity.getType() == EntityType.LOLLIPOP) { - lollipops.add(entity); - lollipopsFriends.add(getConnectedToLollipop(entity)); - } - } - for (IEntity entity : entities) { - if (lollipops.contains(entity) || lollipopsFriends.contains(entity)) { - continue; - } - printEntity(sb, entity); - } - - for (IEntity ent : lollipopsFriends) { - sb.append("subgraph cluster" + ent.getUid() + "lol {"); - sb.append("style=invis;"); - sb.append("label=\"\";"); - printEntity(sb, ent); - for (IEntity lollipop : getAllLollipop(ent)) { - final Link link = getLinkLollipop(lollipop, ent); - final String headOrTail = getHeadOrTail(lollipop, link); - printEntity(sb, lollipop, headOrTail); - printLink(sb, link); - } - sb.append("}"); - } - - } - - private Collection getAllLollipop(IEntity entity) { - final Collection result = new ArrayList(); - for (IEntity lollipop : data.getAllLinkedDirectedTo(entity)) { - if (lollipop.getType() == EntityType.LOLLIPOP) { - result.add(lollipop); - } - } - return result; - } - - private IEntity getConnectedToLollipop(IEntity lollipop) { - assert lollipop.getType() == EntityType.LOLLIPOP; - final Collection linked = data.getAllLinkedDirectedTo(lollipop); - if (linked.size() != 1) { - throw new IllegalStateException("size=" + linked.size()); - } - return linked.iterator().next(); - } - - private Link getLinkLollipop(IEntity lollipop, IEntity ent) { - assert lollipop.getType() == EntityType.LOLLIPOP; - for (Link link : data.getLinks()) { - if (link.isBetween(lollipop, ent)) { - return link; - } - } - throw new IllegalArgumentException(); - } - - private void printEntity(StringBuilder sb, IEntity entity, String headOrTail) throws IOException { - final EntityType type = entity.getType(); - if (type == EntityType.LOLLIPOP) { - 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); - 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 - + ",arrowtail=none,arrowhead=none," + headOrTail + "=<" + labelLo + ">];"); - } else { - throw new IllegalStateException(type.toString() + " " + data.getUmlDiagramType()); - } - - } - - private void printEntity(StringBuilder sb, IEntity entity) throws IOException { - final EntityType type = entity.getType(); - final String label = getLabel(entity); - if (type == EntityType.GROUP) { - return; - } - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - if (type == EntityType.ABSTRACT_CLASS || type == EntityType.CLASS || type == EntityType.INTERFACE - || type == EntityType.ENUM) { - String dec = " [fontcolor=" + getFontColorString(FontParam.CLASS, stereo) + ",margin=0,fillcolor=" - + getColorString(ColorParam.classBackground, stereo) + ",color=" - + getColorString(ColorParam.classBorder, stereo) + ",style=filled,shape=box," + label; - if (this.data.hasUrl() && entity.getUrl() != null) { - dec += ",URL=\"" + entity.getUrl() + "\""; - } - dec += "];"; - sb.append(entity.getUid() + dec); - } else if (type == EntityType.OBJECT) { - sb.append(entity.getUid() + " [fontcolor=" + getFontColorString(FontParam.CLASS, stereo) - + ",margin=0,fillcolor=" + getColorString(ColorParam.classBackground, stereo) + ",color=" - + getColorString(ColorParam.classBorder, stereo) + ",style=filled,shape=record," + label + "];"); - } else if (type == EntityType.USECASE) { - sb.append(entity.getUid() + " [fontcolor=" + getFontColorString(FontParam.USECASE, stereo) + ",fillcolor=" - + getColorString(ColorParam.usecaseBackground, stereo) + ",color=" - + getColorString(ColorParam.usecaseBorder, stereo) + ",style=filled," + label + "];"); - } else if (type == EntityType.ACTOR) { - sb.append(entity.getUid() + " [fontcolor=" + getFontColorString(FontParam.USECASE_ACTOR, stereo) - + ",margin=0,shape=plaintext," + label + "];"); - } else if (type == EntityType.CIRCLE_INTERFACE) { - sb.append(entity.getUid() + " [margin=0,shape=plaintext," + label + "];"); - } else if (type == EntityType.COMPONENT) { - sb.append(entity.getUid() + " [margin=0.2,fontcolor=" + getFontColorString(FontParam.COMPONENT, stereo) - + ",fillcolor=" + getColorString(ColorParam.componentBackground, stereo) + ",color=" - + getColorString(ColorParam.componentBorder, stereo) + ",style=filled,shape=component," + label - + "];"); - } else if (type == EntityType.NOTE && data.getDpi() != 96) { - sb.append(entity.getUid() + " [margin=0,pad=0,shape=plaintext,label=" + getLabelForNoteDpi(entity) + "];"); - } else if (type == EntityType.NOTE) { - final DrawFile file = entity.getImageFile(); - if (file == null) { - throw new IllegalStateException("No file for NOTE"); - } - if (file.getPngOrEps(fileFormat == FileFormat.EPS).exists() == false) { - throw new IllegalStateException(); - } - final String absolutePath = StringUtils.getPlateformDependentAbsolutePath(file - .getPngOrEps(fileFormat == FileFormat.EPS)); - sb.append(entity.getUid() + " [margin=0,pad=0," + label + ",shape=none,image=\"" + absolutePath + "\"];"); - } else if (type == EntityType.ACTIVITY) { - String shape = "octagon"; - if (data.getSkinParam().useOctagonForActivity() == false || entity.getImageFile() != null) { - shape = "rect"; - } - sb.append(entity.getUid() + " [fontcolor=" + getFontColorString(FontParam.ACTIVITY, stereo) + ",fillcolor=" - + getBackColorOfEntity(entity) + ",color=" + getColorString(ColorParam.activityBorder, stereo) - + ",style=\"rounded,filled\",shape=" + shape + "," + label + "];"); - } else if (type == EntityType.BRANCH) { - sb.append(entity.getUid() + " [fillcolor=" + getBackColorOfEntity(entity) + ",color=" - + getColorString(ColorParam.activityBorder, stereo) - + ",style=\"filled\",shape=diamond,height=.25,width=.25,label=\"\"];"); - // if (StringUtils.isNotEmpty(entity.getDisplay())) { - // sb.append(entity.getUid() + "->" + entity.getUid() + - // "[taillabel=\"" + entity.getDisplay() - // + "\",arrowtail=none,arrowhead=none,color=\"white\"];"); - // } - } else if (type == EntityType.SYNCHRO_BAR) { - final String color = getColorString(ColorParam.activityBar, null); - sb.append(entity.getUid() + " [fillcolor=" + color + ",color=" + color + ",style=\"filled\"," - + "shape=rect,height=.08,width=1.30,label=\"\"];"); - } else if (type == EntityType.CIRCLE_START) { - final String color = getColorString(getStartColorParam(), null); - sb.append(entity.getUid() + " [fillcolor=" + color + ",color=" + color + ",style=\"filled\"," - + "shape=circle,width=.20,height=.20,label=\"\"];"); - } else if (type == EntityType.CIRCLE_END) { - 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.POINT_FOR_ASSOCIATION) { - sb.append(entity.getUid() + " [width=.05,shape=point,color=" + getColorString(ColorParam.classBorder, null) - + "];"); - } else if (type == EntityType.STATE) { - sb.append(entity.getUid() + " [color=" + getColorString(ColorParam.stateBorder, stereo) - + ",shape=record,style=\"rounded,filled\",color=" + getColorString(ColorParam.stateBorder, stereo)); - if (entity.getImageFile() == null) { - sb.append(",fillcolor=" + getBackColorOfEntity(entity)); - } else { - sb.append(",fillcolor=" + getBackColorOfEntity(entity)); - // sb.append(",fillcolor=\"" + - // data.getSkinParam().getBackgroundColor().getAsHtml() + "\""); - } - sb.append("," + label + "];"); - } else if (type == EntityType.STATE_CONCURRENT) { - final DrawFile file = entity.getImageFile(); - if (file == null) { - throw new IllegalStateException(); - } - if (file.getPng().exists() == false) { - throw new IllegalStateException(); - } - final String absolutePath = StringUtils.getPlateformDependentAbsolutePath(file.getPng()); - sb.append(entity.getUid() + " [margin=1,pad=1," + label + ",style=dashed,shape=box,image=\"" + absolutePath - + "\"];"); - } else if (type == EntityType.ACTIVITY_CONCURRENT) { - final DrawFile file = entity.getImageFile(); - if (file == null) { - throw new IllegalStateException(); - } - if (file.getPng().exists() == false) { - throw new IllegalStateException(); - } - final String absolutePath = StringUtils.getPlateformDependentAbsolutePath(file.getPng()); - sb.append(entity.getUid() + " [margin=0,pad=0," + label + ",style=dashed,shape=box,image=\"" + absolutePath - + "\"];"); - } else if (type == EntityType.EMPTY_PACKAGE) { - sb.append(entity.getUid() + " [margin=0.2,fontcolor=" + getFontColorString(FontParam.PACKAGE, null) - + ",fillcolor=" + getColorString(ColorParam.packageBackground, null) + ",color=" - + getColorString(ColorParam.packageBorder, null) + ",style=filled,shape=tab," + label + "];"); - } else { - throw new IllegalStateException(type.toString() + " " + data.getUmlDiagramType()); - } - - if (entity.isTop()) { - rankMin.add(entity.getUid()); - } - - } - - private ColorParam getEndColorParam() { - if (data.getUmlDiagramType() == UmlDiagramType.ACTIVITY) { - return ColorParam.activityEnd; - } - if (data.getUmlDiagramType() == UmlDiagramType.STATE) { - return ColorParam.stateEnd; - } - throw new IllegalStateException(data.getUmlDiagramType().toString()); - } - - private ColorParam getStartColorParam() { - if (data.getUmlDiagramType() == UmlDiagramType.ACTIVITY) { - return ColorParam.activityStart; - } - if (data.getUmlDiagramType() == UmlDiagramType.STATE) { - return ColorParam.stateStart; - } - throw new IllegalStateException(data.getUmlDiagramType().toString()); - } - - private String getHeadOrTail(IEntity lollipop, Link link) { - assert lollipop.getType() == EntityType.LOLLIPOP; - if (link.getLength() > 1 && link.getEntity1() == lollipop) { - return "taillabel"; - } - return "headlabel"; - } - - private String getLabel(IEntity entity) throws IOException { - if (entity.getType() == EntityType.ABSTRACT_CLASS || entity.getType() == EntityType.CLASS - || entity.getType() == EntityType.INTERFACE || entity.getType() == EntityType.ENUM) { - return "label=" + getLabelForClassOrInterfaceOrEnum(entity); - } else if (entity.getType() == EntityType.LOLLIPOP) { - return "label=" + getLabelForLollipop(entity); - } else if (entity.getType() == EntityType.OBJECT) { - return "label=" + getLabelForObject(entity); - } else if (entity.getType() == EntityType.ACTOR) { - return "label=" + getLabelForActor(entity); - } else if (entity.getType() == EntityType.CIRCLE_INTERFACE) { - return "label=" + getLabelForCircleInterface(entity); - } else if (entity.getType() == EntityType.NOTE) { - return "label=\"\""; - } else if (entity.getType() == EntityType.STATE_CONCURRENT) { - return "label=\"\""; - } else if (entity.getType() == EntityType.ACTIVITY_CONCURRENT) { - return "label=\"\""; - } else if (entity.getType() == EntityType.COMPONENT) { - return "label=" + getLabelForComponent(entity); - } else if (entity.getType() == EntityType.ACTIVITY) { - final DrawFile drawFile = entity.getImageFile(); - if (drawFile != null) { - final String path = StringUtils.getPlateformDependentAbsolutePath(drawFile.getPng()); - final String bgcolor = "\"" + data.getSkinParam().getBackgroundColor().getAsHtml() + "\""; - final StringBuilder sb = new StringBuilder("label=<"); - sb.append(""); - sb.append(""); - sb.append(""); - sb.append("
"); - sb.append("
"); - sb.append(">"); - return sb.toString(); - } - final String stereotype = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - return "label=" + getSimpleLabelAsHtml(entity, FontParam.ACTIVITY, stereotype); - } else if (entity.getType() == EntityType.EMPTY_PACKAGE) { - return "label=" + getSimpleLabelAsHtml(entity, getFontParamForGroup(), null); - } else if (entity.getType() == EntityType.USECASE) { - return "label=" + getLabelForUsecase(entity); - } else if (entity.getType() == EntityType.STATE) { - return "label=" + getLabelForState(entity); - } - return "label=\"" + entity.getDisplay() + "\""; - } - - private String getSimpleLabelAsHtml(IEntity entity, FontParam param, String stereotype) { - return "<" + manageHtmlIB(entity.getDisplay(), param, stereotype) + ">"; - } - - private String getBackColorOfEntity(IEntity entity) { - if (entity.getSpecificBackColor() != null) { - return "\"" + entity.getSpecificBackColor().getAsHtml() + "\""; - } - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - if (entity.getType() == EntityType.STATE || entity.getType() == EntityType.STATE_CONCURRENT) { - return getColorString(ColorParam.stateBackground, stereo); - } - if (entity.getType() == EntityType.ACTIVITY || entity.getType() == EntityType.ACTIVITY_CONCURRENT - || entity.getType() == EntityType.BRANCH) { - return getColorString(ColorParam.activityBackground, stereo); - } - throw new IllegalArgumentException(entity.getType().toString()); - } - - private String getLabelForState(IEntity entity) throws IOException { - final DrawFile cFile = entity.getImageFile(); - final String stateBgcolor = getBackColorOfEntity(entity); - - final String stereotype = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - - final StringBuilder sb = new StringBuilder("<{"); - sb.append(""); - sb.append("
" + manageHtmlIB(entity.getDisplay(), FontParam.STATE, stereotype) + "
"); - - if (entity.getFieldsToDisplay().size() > 0) { - sb.append("|"); - for (Member att : entity.getFieldsToDisplay()) { - sb.append(manageHtmlIB(att.getDisplayWithVisibilityChar(), FontParam.STATE_ATTRIBUTE, stereotype)); - sb.append("
"); - } - } - - if (cFile != null) { - sb.append("|"); - final String path = StringUtils.getPlateformDependentAbsolutePath(cFile.getPng()); - final String bgcolor; - if (OptionFlags.PBBACK) { - bgcolor = stateBgcolor; - } else { - bgcolor = "\"" + data.getSkinParam().getBackgroundColor().getAsHtml() + "\""; - } - // PBBACK - - sb.append(""); - sb.append(""); - sb.append(""); - sb.append("
"); - sb.append("
"); - } - - if (data.isHideEmptyDescription() == false && entity.getFieldsToDisplay().size() == 0 && cFile == null) { - sb.append("|"); - } - - sb.append("}>"); - - return sb.toString(); - } - - private String getLabelForUsecase(IEntity entity) { - final Stereotype stereotype = getStereotype(entity); - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - if (stereotype == null) { - return getSimpleLabelAsHtml(entity, FontParam.USECASE, stereo); - } - final StringBuilder sb = new StringBuilder("<"); - if (isThereLabel(stereotype)) { - sb.append(""); - } - sb.append(""); - sb.append("
" + manageHtmlIB(stereotype.getLabel(), FontParam.USECASE_STEREOTYPE, stereo) - + "
" + manageHtmlIB(entity.getDisplay(), FontParam.USECASE, stereo) + "
>"); - return sb.toString(); - } - - private String getLabelForComponent(IEntity entity) { - final Stereotype stereotype = getStereotype(entity); - if (stereotype == null) { - return getSimpleLabelAsHtml(entity, FontParam.COMPONENT, null); - } - final String stereo = stereotype.getLabel(); - final StringBuilder sb = new StringBuilder("<"); - if (isThereLabel(stereotype)) { - sb.append(""); - } - sb.append(""); - sb.append("
" + manageHtmlIB(stereotype.getLabel(), FontParam.COMPONENT_STEREOTYPE, stereo) - + "
" + manageHtmlIB(entity.getDisplay(), FontParam.COMPONENT, stereo) + "
>"); - return sb.toString(); - } - - private String getLabelForNoteDpi(IEntity entity) throws IOException { - final DrawFile file = entity.getImageFile(); - if (file == null) { - throw new IllegalStateException("No file for NOTE"); - } - if (file.getPngOrEps(fileFormat == FileFormat.EPS).exists() == false) { - throw new IllegalStateException(); - } - final String absolutePath = StringUtils.getPlateformDependentAbsolutePath(file - .getPngOrEps(fileFormat == FileFormat.EPS)); - - final StringBuilder sb = new StringBuilder("<"); - sb.append(""); - addTdImageBugB1983(sb, absolutePath); - sb.append(""); - sb.append("
>"); - return sb.toString(); - } - - private void addTdImageBugB1983(final StringBuilder sb, final String absolutePath) throws IOException { - // http://www.graphviz.org/bugs/b1983.html - final BufferedImage im = ImageIO.read(new File(absolutePath)); - final int height = im.getHeight(); - final int width = im.getWidth(); - final double f = 1.0 / data.getDpiFactor(); - final int w = (int) (width * f); - final int h = (int) (height * f); - final int w2 = (int) (width * getMagicFactorForImageDpi()); - final int h2 = (int) (height * getMagicFactorForImageDpi()); - sb.append(getTdHeaderForDpi(w, h)); - sb.append(""); - sb.append(""); - sb.append(getTdHeaderForDpi(w2, h2)); - sb.append(""); - sb.append(""); - sb.append(""); - sb.append("
"); - sb.append(""); - } - - private double getMagicFactorForImageDpi() { - return 10500 / 100000.0; - } - - private String getLabelForActor(IEntity entity) throws IOException { - final String actorAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(entity.getImageFile() - .getPngOrEps(fileFormat == FileFormat.EPS)); - final Stereotype stereotype = getStereotype(entity); - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - - final StringBuilder sb = new StringBuilder("<"); - if (isThereLabel(stereotype)) { - sb.append(""); - } - if (data.getDpi() == 96) { - sb.append(""); - } else { - sb.append(""); - addTdImageBugB1983(sb, actorAbsolutePath); - sb.append(""); - } - sb.append(""); - sb.append("
" + manageHtmlIB(stereotype.getLabel(), FontParam.USECASE_ACTOR_STEREOTYPE, stereo) - + "
" + manageHtmlIB(entity.getDisplay(), FontParam.USECASE_ACTOR, stereo) + "
>"); - return sb.toString(); - - } - - private String getLabelForCircleInterface(IEntity entity) throws IOException { - final String circleInterfaceAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(entity.getImageFile() - .getPngOrEps(fileFormat == FileFormat.EPS)); - final Stereotype stereotype = getStereotype(entity); - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - - final StringBuilder sb = new StringBuilder("<"); - if (isThereLabel(stereotype)) { - sb.append(""); - } - sb.append(""); - if (data.getDpi() == 96) { - sb.append(""); - } else { - addTdImageBugB1983(sb, circleInterfaceAbsolutePath); - } - sb.append(""); - sb.append(""); - sb.append("
" + manageHtmlIB(stereotype.getLabel(), FontParam.COMPONENT_STEREOTYPE, stereo) - + "
" + manageHtmlIB(entity.getDisplay(), FontParam.COMPONENT, stereo) + "
>"); - return sb.toString(); - - } - - private String getLabelForLollipop(IEntity entity) throws IOException { - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - final String circleInterfaceAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(data.getStaticImages( - EntityType.LOLLIPOP, stereo).getPngOrEps(fileFormat == FileFormat.EPS)); - final Stereotype stereotype = getStereotype(entity); - - final StringBuilder sb = new StringBuilder("<"); - if (isThereLabel(stereotype)) { - sb.append(""); - } - sb.append(""); - if (data.getDpi() == 96) { - sb.append(""); - } else { - addTdImageBugB1983(sb, circleInterfaceAbsolutePath); - } - sb.append(""); - sb.append(""); - sb.append("
" + manageHtmlIB(stereotype.getLabel(), FontParam.CLASS, null) + "
" + manageHtmlIB(entity.getDisplay(), FontParam.CLASS, null) + "
>"); - return sb.toString(); - - } - - private String getLabelForClassOrInterfaceOrEnum(IEntity entity) throws IOException { - if (isVisibilityModifierPresent) { - return getLabelForClassOrInterfaceOrEnumWithVisibilityImage(entity); - } - return getLabelForClassOrInterfaceOrEnumOld(entity); - - } - - private String getLabelForClassOrInterfaceOrEnumOld(IEntity entity) throws IOException { - DrawFile cFile = entity.getImageFile(); - if (cFile == null) { - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - cFile = data.getStaticImages(entity.getType(), stereo); - } - if (cFile == null) { - throw new IllegalStateException(); - } - final String circleAbsolutePath; - if (data.showPortion(EntityPortion.CIRCLED_CHARACTER, entity)) { - circleAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(cFile - .getPngOrEps(fileFormat == FileFormat.EPS)); - } else { - circleAbsolutePath = null; - } - - final StringBuilder sb = new StringBuilder("<"); - - final boolean showFields = data.showPortion(EntityPortion.FIELD, entity); - final boolean showMethods = data.showPortion(EntityPortion.METHOD, entity); - - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - - if (showFields == false && showMethods == false) { - sb.append(getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(entity, circleAbsolutePath, 1, true, 1)); - } else { - sb.append(""); - sb.append(""); - - if (showFields) { - // if (fileFormat == FileFormat.EPS) { - // sb.append(addFieldsEps(entity.fields2(), true)); - // } else { - final boolean hasStatic = hasStatic(entity.getFieldsToDisplay()); - sb.append(""); - // } - } - if (showMethods) { - // if (fileFormat == FileFormat.EPS) { - // sb.append(addFieldsEps(entity.methods2(), true)); - // } else { - final boolean hasStatic = hasStatic(entity.getMethodsToDisplay()); - sb.append(""); - // } - } - sb.append("
"); - final int longuestFieldOrAttribute = getLongestFieldOrAttribute(entity); - final int longuestHeader = getLonguestHeader(entity); - final int spring = computeSpring(longuestHeader, longuestFieldOrAttribute, 30); - - sb.append(getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(entity, circleAbsolutePath, spring, true, 0)); - - sb.append("
"); - for (Member att : entity.getFieldsToDisplay()) { - sb.append(manageHtmlIBspecial(att, FontParam.CLASS_ATTRIBUTE, hasStatic, getColorString( - ColorParam.classBackground, stereo), true)); - sb.append("
"); - } - sb.append("
"); - for (Member att : entity.getMethodsToDisplay()) { - sb.append(manageHtmlIBspecial(att, FontParam.CLASS_ATTRIBUTE, hasStatic, getColorString( - ColorParam.classBackground, stereo), true)); - sb.append("
"); - } - sb.append("
"); - } - sb.append(">"); - - return sb.toString(); - } - - final private List fileToClean = new ArrayList(); - - private String addFieldsEps(List members, boolean withVisibilityChar) throws IOException { - final List texts = new ArrayList(); - for (Member att : members) { - String s = att.getDisplay(withVisibilityChar); - if (att.isAbstract()) { - s = "" + s + ""; - } - if (att.isStatic()) { - s = "" + s + ""; - } - texts.add(s); - } - final Font font = data.getSkinParam().getFont(FontParam.CLASS_ATTRIBUTE, null); - final Color color = getFontHtmlColor(FontParam.CLASS_ATTRIBUTE, null).getColor(); - final TextBlock text = TextBlockUtils.create(texts, new FontConfiguration(font, color), - HorizontalAlignement.LEFT); - final File feps = FileUtils.createTempFile("member", ".eps"); - UGraphicEps.copyEpsToFile(new UDrawable() { - public void drawU(UGraphic ug) { - text.drawU(ug, 0, 0); - } - }, feps); - fileToClean.add(feps); - - final String path = StringUtils.getPlateformDependentAbsolutePath(feps); - - return "" + "" - + "" + "" + "
" + "
"; - } - - private boolean hasStatic(Collection attributes) { - for (Member att : attributes) { - if (att.isStatic()) { - return true; - } - } - return false; - } - - private String getLabelForClassOrInterfaceOrEnumWithVisibilityImage(IEntity entity) throws IOException { - DrawFile cFile = entity.getImageFile(); - if (cFile == null) { - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - cFile = data.getStaticImages(entity.getType(), stereo); - } - if (cFile == null) { - throw new IllegalStateException(); - } - final String circleAbsolutePath; - if (data.showPortion(EntityPortion.CIRCLED_CHARACTER, entity)) { - circleAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(cFile - .getPngOrEps(fileFormat == FileFormat.EPS)); - } else { - circleAbsolutePath = null; - } - - final boolean showFields = data.showPortion(EntityPortion.FIELD, entity); - final boolean showMethods = data.showPortion(EntityPortion.METHOD, entity); - - final StringBuilder sb = new StringBuilder("<"); - if (showFields == false && showMethods == false) { - sb.append(getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(entity, circleAbsolutePath, 1, true, 1)); - } else { - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - final int longuestHeader = getLonguestHeader(entity); - final int spring = computeSpring(longuestHeader, getLongestFieldOrAttribute(entity), 30); - final int springField = computeSpring(getLongestField(entity), Math.max(longuestHeader, - getLongestMethods(entity)), 30); - final int springMethod = computeSpring(getLongestMethods(entity), Math.max(longuestHeader, - getLongestField(entity)), 30); - - sb.append(""); - sb.append(""); - - if (showFields) { - sb.append(""); - } - if (showMethods) { - sb.append(""); - } - sb.append("
"); - - sb.append(getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(entity, circleAbsolutePath, spring, true, 0)); - sb.append("
"); - if (entity.getFieldsToDisplay().size() > 0) { - buildTableVisibility(entity, true, sb, springField); - } - sb.append("
"); - if (entity.getMethodsToDisplay().size() > 0) { - buildTableVisibility(entity, false, sb, springMethod); - } - sb.append("
"); - } - sb.append(">"); - - return sb.toString(); - - } - - private int computeSpring(final int current, final int maximum, int maxSpring) { - if (maximum <= current) { - return 0; - } - final int spring = maximum - current; - if (spring > maxSpring) { - return maxSpring; - } - return spring; - } - - private void buildTableVisibility(IEntity entity, boolean isField, final StringBuilder sb, int spring) - throws IOException { - sb.append(""); - - final boolean hasStatic = hasStatic(entity.getMethodsToDisplay()); - final boolean dpiNormal = data.getDpi() == 96; - for (Member att : isField ? entity.getFieldsToDisplay() : entity.getMethodsToDisplay()) { - sb.append(""); - if (dpiNormal) { - sb.append(""); - } - sb.append(""); - for (int i = 0; i < spring; i++) { - sb.append(""); - } - sb.append(""); - } - sb.append("
"); - } - String s = att.getDisplayWithVisibilityChar(); - final VisibilityModifier visibilityModifier = VisibilityModifier - .getVisibilityModifier(s.charAt(0), isField); - if (visibilityModifier != null) { - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - final String modifierFile = StringUtils.getPlateformDependentAbsolutePath(data.getVisibilityImages( - visibilityModifier, stereo).getPngOrEps(fileFormat == FileFormat.EPS)); - if (dpiNormal) { - sb.append(""); - } else { - addTdImageBugB1983(sb, modifierFile); - } - s = s.substring(1); - } - if (dpiNormal) { - sb.append(""); - sb.append(manageHtmlIBspecial(att, FontParam.CLASS_ATTRIBUTE, hasStatic, getColorString( - ColorParam.classBackground, null), false)); - sb.append("
"); - } - - private int getLonguestHeader(IEntity entity) { - int result = entity.getDisplay().length(); - final Stereotype stereotype = getStereotype(entity); - if (isThereLabel(stereotype)) { - final int size = stereotype.getLabel().length(); - if (size > result) { - result = size; - } - } - return result; - } - - private int getLongestFieldOrAttribute(IEntity entity) { - return Math.max(getLongestField(entity), getLongestMethods(entity)); - } - - private int getLongestMethods(IEntity entity) { - int result = 0; - for (Member att : entity.getMethodsToDisplay()) { - final int size = att.getDisplayWithVisibilityChar().length(); - if (size > result) { - result = size; - } - } - return result; - - } - - private int getLongestField(IEntity entity) { - int result = 0; - for (Member att : entity.getFieldsToDisplay()) { - final int size = att.getDisplayWithVisibilityChar().length(); - if (size > result) { - result = size; - } - } - return result; - } - - private String getLabelForObject(IEntity entity) throws IOException { - if (isVisibilityModifierPresent) { - return getLabelForObjectWithVisibilityImage(entity); - } - return getLabelForObjectOld(entity); - } - - private String getLabelForObjectWithVisibilityImage(IEntity entity) throws IOException { - - final int longuestHeader = getLonguestHeader(entity); - final int spring = computeSpring(longuestHeader, getLongestFieldOrAttribute(entity), 30); - final int springField = computeSpring(getLongestField(entity), Math.max(longuestHeader, - getLongestMethods(entity)), 30); - - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - - final StringBuilder sb = new StringBuilder("<"); - sb.append(""); - sb.append(""); - sb.append("
"); - - sb.append(getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(entity, null, spring, false, 0)); - - sb.append("
"); - - if (entity.getFieldsToDisplay().size() == 0) { - sb.append(manageHtmlIB(" ", FontParam.OBJECT_ATTRIBUTE, stereo)); - } else { - buildTableVisibility(entity, true, sb, springField); - } - - sb.append("
>"); - - return sb.toString(); - - } - - private String getLabelForObjectOld(IEntity entity) throws IOException { - - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - - final StringBuilder sb = new StringBuilder("<"); - sb.append(""); - sb.append(""); - sb.append("
"); - - final int longuestFieldOrAttribute = getLongestFieldOrAttribute(entity); - final int longuestHeader = getLonguestHeader(entity); - final int spring = computeSpring(longuestHeader, longuestFieldOrAttribute, 30); - - sb.append(getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(entity, null, spring, false, 0)); - - sb.append("
"); - - if (entity.getFieldsToDisplay().size() == 0) { - sb.append(manageHtmlIB(" ", FontParam.OBJECT_ATTRIBUTE, stereo)); - } else { - for (Member att : entity.getFieldsToDisplay()) { - sb.append(manageHtmlIB(att.getDisplayWithVisibilityChar(), FontParam.OBJECT_ATTRIBUTE, stereo)); - sb.append("
"); - } - } - - sb.append("
>"); - - return sb.toString(); - } - - private String getWitdh55() { - if (data.getDpi() == 96) { - return "WIDTH=\"55\""; - } - return "WIDTH=\"55\""; - } - - private 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 String result = dotExpression.getDotHtml(); - if (dotExpression.isUnderline()) { - underline = true; - } - return result; - } - - private String manageHtmlIBspecial(Member att, FontParam param, boolean hasStatic, String backColor, - boolean withVisibilityChar) { - String prefix = ""; - if (hasStatic) { - prefix = "_"; - } - if (att.isAbstract()) { - return prefix + manageHtmlIB("" + att.getDisplay(withVisibilityChar), param, null); - } - if (att.isStatic()) { - return manageHtmlIB("" + att.getDisplay(withVisibilityChar), param, null); - } - return prefix + manageHtmlIB(att.getDisplay(withVisibilityChar), param, null); - } - - private String manageSpace(int size) { - final DotExpression dotExpression = new DotExpression(" ", size, HtmlColor.getColorIfValid("white"), null, - Font.PLAIN, fileFormat); - final String result = dotExpression.getDotHtml(); - return result; - } - - static String unicode(String s) { - final StringBuilder result = new StringBuilder(); - for (char c : s.toCharArray()) { - if (c > 127 || c == '&') { - final int i = c; - result.append("&#" + i + ";"); - } else { - result.append(c); - } - } - return result.toString(); - } - - private String getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnumNoSpring(IEntity entity, - final String circleAbsolutePath, int cellSpacing, boolean classes) throws IOException { - final StringBuilder sb = new StringBuilder(); - sb.append(""); - sb.append(""); - if (circleAbsolutePath == null) { - sb.append(""); - } else { - addTdImageBugB1983(sb, circleAbsolutePath); - - } - sb.append("
"); - } else { - if (data.getDpi() == 96) { - sb.append(""); - sb.append(""); - } - - appendLabelAndStereotype(entity, sb, classes); - sb.append("
"); - return sb.toString(); - } - - private String getTdHeaderForDpi(final double w, final double h) { - // return ""; - return ""; - } - - private String getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(IEntity entity, final String circleAbsolutePath, - int spring, boolean classes, int border) throws IOException { - if (spring == 0) { - return getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnumNoSpring(entity, circleAbsolutePath, 0, classes); - } - final StringBuilder sb = new StringBuilder(); - - sb - .append(""); - sb.append(""); - - for (int i = 0; i < spring; i++) { - sb.append(""); - } - - if (circleAbsolutePath != null) { - if (circleAbsolutePath.endsWith(".png")) { - if (data.getDpi() == 96) { - final BufferedImage im = ImageIO.read(new File(circleAbsolutePath)); - final int height = im.getHeight(); - final int width = im.getWidth(); - sb.append(""); - } else { - addTdImageBugB1983(sb, circleAbsolutePath); - } - } else if (circleAbsolutePath.endsWith(".eps")) { - sb.append(""); - } - } - - sb.append(""); - - for (int i = 0; i < spring; i++) { - sb.append(""); - } - sb.append("
"); - appendLabelAndStereotype(entity, sb, classes); - sb.append("
"); - return sb.toString(); - } - - private void appendLabelAndStereotype(IEntity entity, final StringBuilder sb, boolean classes) { - final Stereotype stereotype = getStereotype(entity); - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - if (isThereLabel(stereotype)) { - sb.append("
"); - sb.append(manageHtmlIB(stereotype.getLabel(), classes ? FontParam.CLASS_STEREOTYPE - : FontParam.OBJECT_STEREOTYPE, stereo)); - sb.append("
"); - } - String display = entity.getDisplay(); - final boolean italic = entity.getType() == EntityType.ABSTRACT_CLASS - || entity.getType() == EntityType.INTERFACE; - if (italic) { - display = "" + display; - } - sb.append(manageHtmlIB(display, classes ? FontParam.CLASS : FontParam.OBJECT, stereo)); - } - - private String getHtmlHeaderTableForClassOrInterfaceOrEnumNew(Entity entity, final String circleAbsolutePath) { - final StringBuilder sb = new StringBuilder(); - sb.append(""); - sb.append("
"); - - appendLabelAndStereotype(entity, sb, true); - sb.append("
"); - return sb.toString(); - } - - private boolean isThereLabel(final Stereotype stereotype) { - return stereotype != null && stereotype.getLabel() != null; - } - - private Stereotype getStereotype(IEntity entity) { - if (data.showPortion(EntityPortion.STEREOTYPE, entity) == false) { - return null; - } - return entity.getStereotype(); - } - - public final boolean isUnderline() { - return underline; - } - - private boolean workAroundDotBug() { - for (Link link : data.getLinks()) { - if (link.getLength() != 1) { - return false; - } - } - if (data.getUmlDiagramType() == UmlDiagramType.CLASS && allEntitiesAreClasses(data.getEntities().values())) { - return true; - } - for (IEntity ent : data.getEntities().values()) { - if (data.getAllLinkedTo(ent).size() == 0) { - return true; - } - } - return false; - } - - private boolean allEntitiesAreClasses(Collection entities) { - for (IEntity ent : entities) { - if (ent.getType() != EntityType.CLASS && ent.getType() != EntityType.ABSTRACT_CLASS - && ent.getType() != EntityType.INTERFACE && ent.getType() != EntityType.ENUM) { - return false; - } - } - return true; - } - - private boolean isSpecialGroup(Group g) { - if (g.getType() == GroupType.STATE) { - return true; - } - if (g.getType() == GroupType.CONCURRENT_STATE) { - throw new IllegalStateException(); - } - if (data.isThereLink(g)) { - return true; - } - return false; - } - - public static final String getLastDotSignature() { - return lastDotSignature; - } - - public static final void reset() { - lastDotSignature = null; - } - - public void clean() { - if (OptionFlags.getInstance().isKeepTmpFiles()) { - return; - } - for (File f : fileToClean) { - Log.info("Deleting temporary file " + f); - final boolean ok = f.delete(); - if (ok == false) { - Log.error("Cannot delete: " + f); - } - } - } - -} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/DrawFile.java b/src/net/sourceforge/plantuml/cucadiagram/dot/DrawFile.java index 66135fa15..4b74fe045 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/DrawFile.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/DrawFile.java @@ -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 cache = new HashMap(); + private static final Collection toDelete = new HashSet(); private final LazyFile png2; private final LazyCached 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 png, Lazy svg, Lazy 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 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 png, Lazy svg, Lazy eps) { + private static void deleteOnExit(DrawFile file) { + synchronized (toDelete) { + toDelete.add(file); + } + } + + private DrawFile(Lazy png, Lazy svg, Lazy eps, String signature, boolean cached) { this.png2 = new LazyFile(png); this.svg2 = new LazyCached(svg); this.eps2 = new LazyFile(eps); + this.toStringValue = signature; + this.cached = cached; } - private DrawFile(File fPng, String svg, File fEps) { - this(new Unlazy(fPng), new Unlazy(svg), new Unlazy(fEps)); + private DrawFile(File fPng, String svg, File fEps, String signature, boolean cached) { + this(new Unlazy(fPng), new Unlazy(svg), new Unlazy(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(); + } + } + } + } + }); + } } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/DrawFileFactory.java b/src/net/sourceforge/plantuml/cucadiagram/dot/DrawFileFactory.java index d42f6a474..132a1e089 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/DrawFileFactory.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/DrawFileFactory.java @@ -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 lpng = new Lazy() { @@ -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 leps = new Lazy() { 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 lsvg = new Lazy() { public String getNow() throws IOException { - return UGraphicG2d.getSvgString(drawable); + return UGraphicG2d.getSvgString(colorMapper, drawable); } }; diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/Graphviz.java b/src/net/sourceforge/plantuml/cucadiagram/dot/Graphviz.java index 098bc2ae7..d12a20570 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/Graphviz.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/Graphviz.java @@ -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; } \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizCached.java b/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizCached.java new file mode 100644 index 000000000..7465e7293 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizCached.java @@ -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 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); + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizUtils.java b/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizUtils.java index 7ef787bc3..733f23e3f 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizUtils.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizUtils.java @@ -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(); diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/GroupPngMaker.java b/src/net/sourceforge/plantuml/cucadiagram/dot/GroupPngMaker.java index 01b11e333..adcc2017c 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/GroupPngMaker.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/GroupPngMaker.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6453 $ + * Revision $Revision: 6711 $ * */ package net.sourceforge.plantuml.cucadiagram.dot; @@ -105,7 +105,7 @@ public final class GroupPngMaker { final Graphviz graphviz = GraphvizUtils.create(dotString, "png"); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - graphviz.createPng(baos); + graphviz.createFile(baos); baos.close(); final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); @@ -139,7 +139,7 @@ public final class GroupPngMaker { final Graphviz graphviz = GraphvizUtils.create(dotString, "svg"); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - graphviz.createPng(baos); + graphviz.createFile(baos); baos.close(); String svg = new String(baos.toByteArray(), "UTF-8"); @@ -207,9 +207,9 @@ public final class GroupPngMaker { ISkinParam skinParam = diagram.getSkinParam(); if (OptionFlags.PBBACK && group.getBackColor() != null) { skinParam = new SkinParamBackcolored(skinParam, null, group.getBackColor()); - } + } final DotData dotData = new DotData(group, links, group.entities(), diagram.getUmlDiagramType(), skinParam, - group.getRankdir(), new InnerGroupHierarchy()); + group.getRankdir(), new InnerGroupHierarchy(), diagram.getColorMapper()); // dotData.putAllImages(images); // dotData.putAllStaticImages(staticImages); // dotData.putAllImagesLink(imagesLink); diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/ICucaDiagramFileMaker.java b/src/net/sourceforge/plantuml/cucadiagram/dot/ICucaDiagramFileMaker.java new file mode 100644 index 000000000..6f587a202 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/ICucaDiagramFileMaker.java @@ -0,0 +1,45 @@ +/* ======================================================================== + * 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.IOException; +import java.io.OutputStream; +import java.util.List; + +import net.sourceforge.plantuml.FileFormatOption; + +public interface ICucaDiagramFileMaker { + public String createFile(OutputStream os, List dotStrings, FileFormatOption fileFormatOption) + throws IOException, InterruptedException; +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderClassOld.java b/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderClassOld.java index 5481a43ea..a99c22ef1 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderClassOld.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderClassOld.java @@ -45,6 +45,8 @@ import net.sourceforge.plantuml.cucadiagram.Member; class LabelBuilderClassOld extends LabelBuilderObjectOrClass implements LabelBuilder { + private BorderMode mode = BorderMode.NO_BORDER_CELLSPACING_OLD; + LabelBuilderClassOld(FileFormat fileFormat, DotData data, IEntity entity) { super(fileFormat, data, entity); } @@ -60,8 +62,7 @@ class LabelBuilderClassOld extends LabelBuilderObjectOrClass implements LabelBui } final String circleAbsolutePath; if (getData().showPortion(EntityPortion.CIRCLED_CHARACTER, getEntity())) { - circleAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(cFile - .getPngOrEps(getFileFormat() == FileFormat.EPS)); + circleAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(cFile.getPngOrEps(getFileFormat())); } else { circleAbsolutePath = null; } @@ -74,7 +75,8 @@ class LabelBuilderClassOld extends LabelBuilderObjectOrClass implements LabelBui final String stereo = getEntity().getStereotype() == null ? null : getEntity().getStereotype().getLabel(); if (showFields == false && showMethods == false) { - sb.append(getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(getEntity(), circleAbsolutePath, 1, true, BorderMode.NO_BORDER_CELLSPACING)); + sb.append(getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(getEntity(), circleAbsolutePath, 1, true, + mode)); } else { sb.append(""); @@ -110,8 +112,8 @@ class LabelBuilderClassOld extends LabelBuilderObjectOrClass implements LabelBui final boolean hasStatic = hasStatic(getEntity().getMethodsToDisplay()); sb.append(""); @@ -122,4 +124,8 @@ class LabelBuilderClassOld extends LabelBuilderObjectOrClass implements LabelBui // sb.append(">"); } + public void patch() { + mode = BorderMode.NO_BORDER_CELLSPACING_NEW; + } + } \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderClassWithVisibilityImage.java b/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderClassWithVisibilityImage.java index 8c8398501..7a4302727 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderClassWithVisibilityImage.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderClassWithVisibilityImage.java @@ -58,8 +58,7 @@ class LabelBuilderClassWithVisibilityImage extends LabelBuilderObjectOrClass imp } final String circleAbsolutePath; if (getData().showPortion(EntityPortion.CIRCLED_CHARACTER, getEntity())) { - circleAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(cFile - .getPngOrEps(getFileFormat() == FileFormat.EPS)); + circleAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(cFile.getPngOrEps(getFileFormat())); } else { circleAbsolutePath = null; } @@ -69,15 +68,16 @@ class LabelBuilderClassWithVisibilityImage extends LabelBuilderObjectOrClass imp // sb.append("<"); if (showFields == false && showMethods == false) { - sb.append(getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(getEntity(), circleAbsolutePath, 1, true, BorderMode.NO_BORDER_CELLSPACING)); + sb.append(getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(getEntity(), circleAbsolutePath, 1, true, + BorderMode.NO_BORDER_CELLSPACING_OLD)); } else { final String stereo = getEntity().getStereotype() == null ? null : getEntity().getStereotype().getLabel(); final int longuestHeader = getLonguestHeader(getEntity()); final int spring = computeSpring(longuestHeader, getLongestFieldOrAttribute(getEntity()), 30); - final int springField = computeSpring(getLongestField(getEntity()), - Math.max(longuestHeader, getLongestMethods(getEntity())), 30); - final int springMethod = computeSpring(getLongestMethods(getEntity()), - Math.max(longuestHeader, getLongestField(getEntity())), 30); + final int springField = computeSpring(getLongestField(getEntity()), Math.max(longuestHeader, + getLongestMethods(getEntity())), 30); + final int springMethod = computeSpring(getLongestMethods(getEntity()), Math.max(longuestHeader, + getLongestField(getEntity())), 30); sb.append("
"); for (Member att : getEntity().getFieldsToDisplay()) { - sb.append(manageHtmlIBspecial(att, FontParam.CLASS_ATTRIBUTE, hasStatic, - getColorString(ColorParam.classBackground, stereo), true)); + sb.append(manageHtmlIBspecial(att, FontParam.CLASS_ATTRIBUTE, hasStatic, getColorString( + ColorParam.classBackground, stereo), true)); sb.append("
"); } sb.append("
"); for (Member att : getEntity().getMethodsToDisplay()) { - sb.append(manageHtmlIBspecial(att, FontParam.CLASS_ATTRIBUTE, hasStatic, - getColorString(ColorParam.classBackground, stereo), true)); + sb.append(manageHtmlIBspecial(att, FontParam.CLASS_ATTRIBUTE, hasStatic, getColorString( + ColorParam.classBackground, stereo), true)); sb.append("
"); } sb.append("
"); - } else if (borderMode == BorderMode.NO_BORDER_CELLSPACING) { + } else if (borderMode == BorderMode.NO_BORDER_CELLSPACING_OLD) { sb.append("
"); + } else if (borderMode == BorderMode.NO_BORDER_CELLSPACING_NEW) { + final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); + sb.append("
"); } else if (borderMode == BorderMode.BORDER_1_WITHOUT_COLOR) { sb.append("
"); diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderTableNineDecorator.java b/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderTableNineDecorator.java index 1efd6e42f..8e8bd88e8 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderTableNineDecorator.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderTableNineDecorator.java @@ -45,6 +45,9 @@ class LabelBuilderTableNineDecorator extends LabelBuilderObjectOrClass implement LabelBuilderTableNineDecorator(FileFormat fileFormat, DotData data, IEntity entity, LabelBuilder builder) { super(fileFormat, data, entity); this.builder = builder; + if (builder instanceof LabelBuilderClassOld) { + ((LabelBuilderClassOld)builder).patch(); + } } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderTableVisibility.java b/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderTableVisibility.java index d7989528f..b493cd27a 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderTableVisibility.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderTableVisibility.java @@ -71,9 +71,8 @@ class LabelBuilderTableVisibility extends DotCommon implements LabelBuilder { .getVisibilityModifier(s.charAt(0), isField); if (visibilityModifier != null) { final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - final String modifierFile = StringUtils - .getPlateformDependentAbsolutePath(getData().getVisibilityImages(visibilityModifier, stereo) - .getPngOrEps(getFileFormat() == FileFormat.EPS)); + final String modifierFile = StringUtils.getPlateformDependentAbsolutePath(getData() + .getVisibilityImages(visibilityModifier, stereo).getPngOrEps(getFileFormat())); if (dpiNormal) { sb.append(""); } else { diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/PlayField.java b/src/net/sourceforge/plantuml/cucadiagram/dot/PlayField.java index 004ba1c8c..41878a4e1 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/PlayField.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/PlayField.java @@ -33,8 +33,6 @@ */ package net.sourceforge.plantuml.cucadiagram.dot; -import java.awt.Color; -import java.awt.Font; import java.awt.geom.Dimension2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; @@ -59,6 +57,7 @@ import net.sourceforge.plantuml.cucadiagram.Link; import net.sourceforge.plantuml.cucadiagram.LinkType; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; @@ -77,6 +76,7 @@ import net.sourceforge.plantuml.posimo.Path; import net.sourceforge.plantuml.posimo.PathDrawerInterface; import net.sourceforge.plantuml.posimo.PositionableUtils; import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.URectangle; @@ -93,7 +93,7 @@ public final class PlayField { private final Map frames = new HashMap(); final private double marginLabel = 6; - final private Font fontQualif; + final private UFont fontQualif; public PlayField(ISkinParam skinParam) { this.skinParam = skinParam; @@ -117,7 +117,7 @@ public final class PlayField { // final IEntityImageBlock title = createClusterTitle(); // final Frame frame = new Frame(StringUtils.getWithNewlines(ent.getDisplay()), Color.BLACK, skinParam // .getFont(FontParam.CLASS), rose.getHtmlColor(skinParam, ColorParam.classBorder).getColor()); - final Frame frame = new Frame(StringUtils.getWithNewlines(ent.getDisplay()), skinParam); + final Frame frame = new Frame(ent.getDisplay2(), skinParam); frames.put(ent, frame); // final Dimension2D dimTitle = // title.getDimension(stringBounder); @@ -228,13 +228,13 @@ public final class PlayField { final LinkType type = ent.getValue().getType(); final PathDrawerInterface pathDrawer = PathDrawerInterface.create(skinParam, type); final Path p = ent.getKey(); - ug.getParam().setColor(rose.getHtmlColor(skinParam, ColorParam.classBorder).getColor()); + ug.getParam().setColor(rose.getHtmlColor(skinParam, ColorParam.classBorder)); // pathDrawer.drawPathBefore(ug, PositionableUtils.addMargin(p // .getStart(), -marginDecorator, -marginDecorator), // PositionableUtils.addMargin(p.getEnd(), -marginDecorator, // -marginDecorator), p); if (p.getLabel() != null) { - ug.getParam().setColor(Color.BLACK); + ug.getParam().setColor(HtmlColor.BLACK); drawLabel(ug, p); } } @@ -250,7 +250,7 @@ public final class PlayField { final LinkType type = link.getType(); final PathDrawerInterface pathDrawer = PathDrawerInterface.create(skinParam, type); final Path p = ent.getKey(); - ug.getParam().setColor(rose.getHtmlColor(skinParam, ColorParam.classBorder).getColor()); + ug.getParam().setColor(rose.getHtmlColor(skinParam, ColorParam.classBorder)); // pathDrawer.drawPathAfter(ug, PositionableUtils.addMargin(p // .getStart(), -marginDecorator, -marginDecorator), // PositionableUtils.addMargin(p.getEnd(), -marginDecorator, @@ -261,7 +261,7 @@ public final class PlayField { final String qual1 = link.getQualifier1(); if (qual1 != null) { final TextBlock b = TextBlockUtils.create(Arrays.asList(qual1), new FontConfiguration(fontQualif, - skinParam.getFontHtmlColor(FontParam.CLASS_ARROW, null).getColor()), HorizontalAlignement.LEFT); + skinParam.getFontHtmlColor(FontParam.CLASS_ARROW, null)), HorizontalAlignement.LEFT); final Point2D pos = p.getDotPath().getStartPoint(); b.drawU(ug, pos.getX(), pos.getY()); } @@ -269,7 +269,7 @@ public final class PlayField { final String qual2 = link.getQualifier2(); if (qual2 != null) { final TextBlock b = TextBlockUtils.create(Arrays.asList(qual2), new FontConfiguration(fontQualif, - skinParam.getFontHtmlColor(FontParam.CLASS_ARROW, null).getColor()), HorizontalAlignement.LEFT); + skinParam.getFontHtmlColor(FontParam.CLASS_ARROW, null)), HorizontalAlignement.LEFT); final Point2D pos = p.getDotPath().getEndPoint(); b.drawU(ug, pos.getX(), pos.getY()); } @@ -297,7 +297,7 @@ public final class PlayField { final Label label = p.getLabel(); final Point2D pos = label.getPosition(); if (OptionFlags.getInstance().isDebugDot()) { - ug.getParam().setColor(Color.GREEN); + ug.getParam().setColor(HtmlColor.GREEN); ug.getParam().setBackcolor(null); final Dimension2D dim = label.getSize(); ug.draw(pos.getX(), pos.getY(), new URectangle(dim.getWidth(), dim.getHeight())); diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/StaticFiles.java b/src/net/sourceforge/plantuml/cucadiagram/dot/StaticFiles.java index 6e0904883..29d75683d 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/StaticFiles.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/StaticFiles.java @@ -28,13 +28,11 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5823 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.cucadiagram.dot; -import java.awt.Color; -import java.awt.Font; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.File; @@ -53,56 +51,57 @@ import net.sourceforge.plantuml.FontParam; import net.sourceforge.plantuml.ISkinParam; import net.sourceforge.plantuml.cucadiagram.EntityType; import net.sourceforge.plantuml.graphic.CircledCharacter; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.skin.CircleInterface; import net.sourceforge.plantuml.skin.UDrawable; import net.sourceforge.plantuml.skin.VisibilityModifier; import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.eps.UGraphicEps; import net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d; public class StaticFiles { - private final Color interfaceBorder; - private final Color classborder; - private final Color classBackground; - private final Color interfaceBackground; - private final Color background; + private final HtmlColor interfaceBorder; + private final HtmlColor classborder; + private final HtmlColor classBackground; + private final HtmlColor interfaceBackground; + private final HtmlColor background; - final private Font circledFont; + final private UFont circledFont; final private double radius; private final Map staticImages = new EnumMap(EntityType.class); private final Map visibilityImages = new EnumMap( VisibilityModifier.class); - private final Map foregroundColor = new EnumMap( + private final Map foregroundColor = new EnumMap( VisibilityModifier.class); - private final Map backgroundColor = new EnumMap( + private final Map backgroundColor = new EnumMap( VisibilityModifier.class); private final double dpiFactor; + private final ColorMapper colorMapper; public StaticFiles(ISkinParam param, String stereotype, double dpiFactor) throws IOException { + this.colorMapper = param.getColorMapper(); final Rose rose = new Rose(); this.dpiFactor = dpiFactor; radius = param.getCircledCharacterRadius(); circledFont = param.getFont(FontParam.CIRCLED_CHARACTER, stereotype); - classborder = rose.getHtmlColor(param, ColorParam.classBorder, stereotype).getColor(); - interfaceBorder = rose.getHtmlColor(param, ColorParam.componentInterfaceBorder, stereotype).getColor(); - interfaceBackground = rose.getHtmlColor(param, ColorParam.componentInterfaceBackground, stereotype).getColor(); - classBackground = rose.getHtmlColor(param, ColorParam.classBackground, stereotype).getColor(); - final Color stereotypeCBackground = rose.getHtmlColor(param, ColorParam.stereotypeCBackground, stereotype) - .getColor(); - final Color stereotypeABackground = rose.getHtmlColor(param, ColorParam.stereotypeABackground, stereotype) - .getColor(); - final Color stereotypeIBackground = rose.getHtmlColor(param, ColorParam.stereotypeIBackground, stereotype) - .getColor(); - final Color stereotypeEBackground = rose.getHtmlColor(param, ColorParam.stereotypeEBackground, stereotype) - .getColor(); + classborder = rose.getHtmlColor(param, ColorParam.classBorder, stereotype); + interfaceBorder = rose.getHtmlColor(param, ColorParam.componentInterfaceBorder, stereotype); + interfaceBackground = rose.getHtmlColor(param, ColorParam.componentInterfaceBackground, stereotype); + classBackground = rose.getHtmlColor(param, ColorParam.classBackground, stereotype); + final HtmlColor stereotypeCBackground = rose.getHtmlColor(param, ColorParam.stereotypeCBackground, stereotype); + final HtmlColor stereotypeABackground = rose.getHtmlColor(param, ColorParam.stereotypeABackground, stereotype); + final HtmlColor stereotypeIBackground = rose.getHtmlColor(param, ColorParam.stereotypeIBackground, stereotype); + final HtmlColor stereotypeEBackground = rose.getHtmlColor(param, ColorParam.stereotypeEBackground, stereotype); - background = param.getBackgroundColor().getColor(); + background = param.getBackgroundColor(); final File dir = FileUtils.getTmpDir(); staticImages.put(EntityType.LOLLIPOP, getLollipop()); @@ -114,14 +113,14 @@ public class StaticFiles { if (param.classAttributeIconSize() > 0) { for (VisibilityModifier modifier : EnumSet.allOf(VisibilityModifier.class)) { - final Color back = modifier.getBackground() == null ? null : rose.getHtmlColor(param, - modifier.getBackground(), stereotype).getColor(); - final Color fore = rose.getHtmlColor(param, modifier.getForeground(), stereotype).getColor(); + final HtmlColor back = modifier.getBackground() == null ? null : rose.getHtmlColor(param, + modifier.getBackground(), stereotype); + final HtmlColor fore = rose.getHtmlColor(param, modifier.getForeground(), stereotype); backgroundColor.put(modifier, back); foregroundColor.put(modifier, fore); - visibilityImages.put(modifier, getVisibilityModifier(modifier, dir, param.classAttributeIconSize(), - dpiFactor)); + visibilityImages.put(modifier, + getVisibilityModifier(modifier, dir, param.classAttributeIconSize(), dpiFactor)); } } } @@ -134,12 +133,12 @@ public class StaticFiles { public File getNow() throws IOException { final EmptyImageBuilder builder = new EmptyImageBuilder(circleInterface.getPreferredWidth(null), - circleInterface.getPreferredHeight(null), background); + circleInterface.getPreferredHeight(null), colorMapper.getMappedColor(background)); final BufferedImage im = builder.getBufferedImage(); final Graphics2D g2d = builder.getGraphics2D(); - circleInterface.drawU(new UGraphicG2d(g2d, null, dpiFactor)); + circleInterface.drawU(new UGraphicG2d(colorMapper, g2d, null, dpiFactor)); final File result = FileUtils.createTempFile("lollipop", ".png"); ImageIO.write(im, "png", result); @@ -150,14 +149,14 @@ public class StaticFiles { final Lazy leps = new Lazy() { public File getNow() throws IOException { final File epsFile = FileUtils.createTempFile("lollipop", ".eps"); - UGraphicEps.copyEpsToFile(circleInterface, epsFile); + UGraphicEps.copyEpsToFile(colorMapper, circleInterface, epsFile); return epsFile; } }; final Lazy lsvg = new Lazy() { public String getNow() throws IOException { - return UGraphicG2d.getSvgString(circleInterface); + return UGraphicG2d.getSvgString(colorMapper, circleInterface); } }; @@ -167,10 +166,10 @@ public class StaticFiles { } - private DrawFile getCircledCharacter(char c, Color background) throws IOException { + private DrawFile getCircledCharacter(char c, HtmlColor background) throws IOException { final CircledCharacter circledCharacter = new CircledCharacter(c, radius, circledFont, background, classborder, - Color.BLACK); - return circledCharacter.generateCircleCharacter(classBackground, dpiFactor); + HtmlColor.BLACK); + return circledCharacter.generateCircleCharacter(colorMapper, classBackground, dpiFactor); } public DrawFile getStaticImages(EntityType type) { @@ -200,16 +199,16 @@ public class StaticFiles { private DrawFile getVisibilityModifier(final VisibilityModifier modifier, final File dir, final int size, final double dpiFactor) throws IOException { - final UDrawable drawable = modifier.getUDrawable(size, foregroundColor.get(modifier), backgroundColor - .get(modifier)); + final UDrawable drawable = modifier.getUDrawable(size, foregroundColor.get(modifier), + backgroundColor.get(modifier)); final Lazy lpng = new Lazy() { public File getNow() throws IOException { final File png = FileUtils.createTempFile("visi", ".png"); final EmptyImageBuilder builder = new EmptyImageBuilder(size * dpiFactor, size * dpiFactor, - classBackground); + colorMapper.getMappedColor(classBackground)); 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; } @@ -218,21 +217,30 @@ public class StaticFiles { final Lazy leps = new Lazy() { 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 lsvg = new Lazy() { public String getNow() throws IOException { - return UGraphicG2d.getSvgString(drawable); + return UGraphicG2d.getSvgString(colorMapper, drawable); } }; - final Object signature = Arrays.asList("visi", modifier, foregroundColor.get(modifier), backgroundColor - .get(modifier), size, classBackground); + final Object signature = Arrays.asList("visi", modifier, foregroundColor.get(modifier), + backgroundColor.get(modifier), size, classBackground); return DrawFile.create(lpng, lsvg, leps, signature); } + public void clean() { + for (DrawFile f : staticImages.values()) { + f.deleteDrawFile(); + } + for (DrawFile f : visibilityImages.values()) { + f.deleteDrawFile(); + } + } + } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/StaticFilesMap.java b/src/net/sourceforge/plantuml/cucadiagram/dot/StaticFilesMap.java index 5560e8c36..81489af85 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/StaticFilesMap.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/StaticFilesMap.java @@ -69,4 +69,10 @@ public class StaticFilesMap { return null; } + public void clean() { + for (StaticFiles staticFiles : map.values()) { + staticFiles.clean(); + } + } + } diff --git a/src/net/sourceforge/plantuml/directdot/DotText.java b/src/net/sourceforge/plantuml/directdot/DotText.java new file mode 100644 index 000000000..1d3fb507b --- /dev/null +++ b/src/net/sourceforge/plantuml/directdot/DotText.java @@ -0,0 +1,103 @@ +/* ======================================================================== + * 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: 6780 $ + * + */ +package net.sourceforge.plantuml.directdot; + +import java.awt.Font; +import java.util.List; + +import net.sourceforge.plantuml.FileFormat; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.cucadiagram.dot.DotExpression; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity; + +public class DotText { + + private final HtmlColor background; + + private final HtmlColor textcolor; + + private final List strings; + + private final ColorMapper colorMapper = new ColorMapperIdentity(); + + public DotText(List strings, HtmlColor textcolor, HtmlColor background) { + this.strings = strings; + this.textcolor = textcolor; + this.background = background; + } + + public void generateDot(StringBuilder sb) { + + sb.append("digraph unix {\n"); + sb.append("bgcolor=\"" + getAsHtml(background) + "\";"); + sb.append("foo ["); + sb.append("shape=box;"); + + final StringBuilder html = new StringBuilder(); + if (strings.size() == 1) { + appendOneLine(html, strings.get(0)); + } else { + html.append("
"); + for (String s : strings) { + html.append(""); + html.append(""); + html.append(""); + } + html.append("
"); + appendOneLine(html, s); + html.append("
"); + } + + sb.append("label=<"); + sb.append(html); + sb.append(">"); + + sb.append("]"); + sb.append("}"); + + } + + private void appendOneLine(final StringBuilder html, String s) { + final DotExpression dotExpression = new DotExpression(colorMapper, s, 14, textcolor, "Times-Roman", Font.PLAIN, + FileFormat.PNG); + html.append(dotExpression.getDotHtml()); + } + + protected final String getAsHtml(HtmlColor htmlColor) { + return StringUtils.getAsHtml(colorMapper.getMappedColor(htmlColor)); + } + +} diff --git a/src/net/sourceforge/plantuml/directdot/PSystemDot.java b/src/net/sourceforge/plantuml/directdot/PSystemDot.java index 874c0ac76..78b4691d8 100644 --- a/src/net/sourceforge/plantuml/directdot/PSystemDot.java +++ b/src/net/sourceforge/plantuml/directdot/PSystemDot.java @@ -56,7 +56,7 @@ public class PSystemDot extends AbstractPSystem { throws IOException { final Graphviz graphviz = GraphvizUtils.create(data, fileFormatOption.getFileFormat().name().toLowerCase()); try { - graphviz.createPng(os); + graphviz.createFile(os); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); diff --git a/src/net/sourceforge/plantuml/directdot/PSystemDotFactory.java b/src/net/sourceforge/plantuml/directdot/PSystemDotFactory.java index c7673aa5a..cdbc43013 100644 --- a/src/net/sourceforge/plantuml/directdot/PSystemDotFactory.java +++ b/src/net/sourceforge/plantuml/directdot/PSystemDotFactory.java @@ -44,10 +44,9 @@ public class PSystemDotFactory implements PSystemBasicFactory { public PSystemDotFactory(DiagramType diagramType) { this.diagramType = diagramType; - reset(); } - public void reset() { + public void init(String startLine) { data = null; first = true; } diff --git a/src/net/sourceforge/plantuml/ditaa/PSystemDitaa.java b/src/net/sourceforge/plantuml/ditaa/PSystemDitaa.java index c370196c6..3fac7b986 100644 --- a/src/net/sourceforge/plantuml/ditaa/PSystemDitaa.java +++ b/src/net/sourceforge/plantuml/ditaa/PSystemDitaa.java @@ -42,6 +42,7 @@ import net.sourceforge.plantuml.AbstractPSystem; import net.sourceforge.plantuml.FileFormatOption; import org.stathissideris.ascii2image.core.ConversionOptions; +import org.stathissideris.ascii2image.core.ProcessingOptions; import org.stathissideris.ascii2image.graphics.BitmapRenderer; import org.stathissideris.ascii2image.graphics.Diagram; import org.stathissideris.ascii2image.text.TextGrid; @@ -49,9 +50,11 @@ import org.stathissideris.ascii2image.text.TextGrid; public class PSystemDitaa extends AbstractPSystem { private final TextGrid grid = new TextGrid(); - - public PSystemDitaa(String data) throws UnsupportedEncodingException { + private final ProcessingOptions processingOptions = new ProcessingOptions(); + + public PSystemDitaa(String data, boolean performSeparationOfCommonEdges) throws UnsupportedEncodingException { grid.initialiseWithText(data, null); + processingOptions.setPerformSeparationOfCommonEdges(performSeparationOfCommonEdges); } public String getDescription() { @@ -62,7 +65,7 @@ public class PSystemDitaa extends AbstractPSystem { throws IOException { final ConversionOptions options = new ConversionOptions(); - final Diagram diagram = new Diagram(grid, options); + final Diagram diagram = new Diagram(grid, options, processingOptions); final BufferedImage image = (BufferedImage) new BitmapRenderer().renderToImage(diagram, options.renderingOptions); ImageIO.write(image, "png", os); diff --git a/src/net/sourceforge/plantuml/ditaa/PSystemDitaaFactory.java b/src/net/sourceforge/plantuml/ditaa/PSystemDitaaFactory.java index 71d18a0a4..1b8032c0a 100644 --- a/src/net/sourceforge/plantuml/ditaa/PSystemDitaaFactory.java +++ b/src/net/sourceforge/plantuml/ditaa/PSystemDitaaFactory.java @@ -40,15 +40,21 @@ public class PSystemDitaaFactory implements PSystemBasicFactory { private StringBuilder data; private boolean first; + // -E,--no-separation + private boolean performSeparationOfCommonEdges; + private final DiagramType diagramType; public PSystemDitaaFactory(DiagramType diagramType) { this.diagramType = diagramType; - reset(); } - public void reset() { + public void init(String startLine) { data = null; + performSeparationOfCommonEdges = true; + if (startLine != null && (startLine.contains("-E") || startLine.contains("--no-separation"))) { + performSeparationOfCommonEdges = false; + } if (diagramType == DiagramType.UML) { first = true; } else if (diagramType == DiagramType.DITAA) { @@ -60,8 +66,11 @@ public class PSystemDitaaFactory implements PSystemBasicFactory { } public boolean executeLine(String line) { - if (first && line.equals("ditaa")) { + if (first && (line.equals("ditaa") || line.startsWith("ditaa("))) { data = new StringBuilder(); + if (line.contains("-E") || line.contains("--no-separation")) { + performSeparationOfCommonEdges = false; + } return true; } first = false; @@ -75,7 +84,7 @@ public class PSystemDitaaFactory implements PSystemBasicFactory { public PSystemDitaa getSystem() { try { - return new PSystemDitaa(data.toString()); + return new PSystemDitaa(data.toString(), performSeparationOfCommonEdges); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return null; diff --git a/src/net/sourceforge/plantuml/eggs/GraphicsPath.java b/src/net/sourceforge/plantuml/eggs/GraphicsPath.java index be52ce32b..48a4e0e4c 100644 --- a/src/net/sourceforge/plantuml/eggs/GraphicsPath.java +++ b/src/net/sourceforge/plantuml/eggs/GraphicsPath.java @@ -40,19 +40,23 @@ import java.io.IOException; import java.io.OutputStream; import net.sourceforge.plantuml.EmptyImageBuilder; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.png.PngIO; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UMotif; import net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d; public class GraphicsPath { private final String path; + private final ColorMapper colorMapper; // private final Font numberFont = new Font("SansSerif", Font.BOLD, 20); // private final Font font = new Font("SansSerif", Font.PLAIN, 11); - public GraphicsPath(String path) { + public GraphicsPath(ColorMapper colorMapper, String path) { this.path = path; + this.colorMapper = colorMapper; } public void writeImage(OutputStream os) throws IOException { @@ -66,8 +70,8 @@ public class GraphicsPath { final BufferedImage im = builder.getBufferedImage(); final Graphics2D g2d = builder.getGraphics2D(); - final UGraphicG2d ug = new UGraphicG2d(g2d, im, 1.0); - ug.getParam().setColor(Color.BLACK); + final UGraphicG2d ug = new UGraphicG2d(colorMapper, g2d, im, 1.0); + ug.getParam().setColor(HtmlColor.BLACK); final UMotif motif = new UMotif(path); motif.drawHorizontal(ug, 20, 20, 1); diff --git a/src/net/sourceforge/plantuml/eggs/PSystemEgg.java b/src/net/sourceforge/plantuml/eggs/PSystemEgg.java index 3e66acfd3..d86d1fdd2 100644 --- a/src/net/sourceforge/plantuml/eggs/PSystemEgg.java +++ b/src/net/sourceforge/plantuml/eggs/PSystemEgg.java @@ -28,12 +28,11 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6453 $ + * Revision $Revision: 6710 $ * */ package net.sourceforge.plantuml.eggs; -import java.awt.Color; import java.awt.Font; import java.io.IOException; import java.io.OutputStream; @@ -44,6 +43,8 @@ import java.util.StringTokenizer; import net.sourceforge.plantuml.AbstractPSystem; import net.sourceforge.plantuml.FileFormatOption; import net.sourceforge.plantuml.graphic.GraphicStrings; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.ugraphic.UFont; public class PSystemEgg extends AbstractPSystem { @@ -56,26 +57,13 @@ public class PSystemEgg extends AbstractPSystem { } } -// public List createFiles(File suggestedFile, FileFormatOption fileFormat) throws IOException, InterruptedException { -// OutputStream os = null; -// try { -// os = new FileOutputStream(suggestedFile); -// getGraphicStrings().writeImage(os, fileFormat); -// } finally { -// if (os != null) { -// os.close(); -// } -// } -// return Arrays.asList(suggestedFile); -// } - public void exportDiagram(OutputStream os, StringBuilder cmap, int index, FileFormatOption fileFormat) throws IOException { getGraphicStrings().writeImage(os, fileFormat); } private GraphicStrings getGraphicStrings() throws IOException { - final Font font = new Font("SansSerif", Font.PLAIN, 12); - return new GraphicStrings(strings, font, Color.BLACK, Color.WHITE, false); + final UFont font = new UFont("SansSerif", Font.PLAIN, 12); + return new GraphicStrings(strings, font, HtmlColor.BLACK, HtmlColor.WHITE, false); } public String getDescription() { diff --git a/src/net/sourceforge/plantuml/eggs/PSystemEggFactory.java b/src/net/sourceforge/plantuml/eggs/PSystemEggFactory.java index 86a73b560..95396b14e 100644 --- a/src/net/sourceforge/plantuml/eggs/PSystemEggFactory.java +++ b/src/net/sourceforge/plantuml/eggs/PSystemEggFactory.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6341 $ + * Revision $Revision: 6750 $ * */ package net.sourceforge.plantuml.eggs; @@ -44,11 +44,7 @@ public class PSystemEggFactory implements PSystemBasicFactory { private PSystemEgg system; - public PSystemEggFactory() { - reset(); - } - - public void reset() { + public void init(String startLine) { } final static private List all = Arrays diff --git a/src/net/sourceforge/plantuml/eggs/PSystemLost.java b/src/net/sourceforge/plantuml/eggs/PSystemLost.java index 77f247c1b..509cbb55d 100644 --- a/src/net/sourceforge/plantuml/eggs/PSystemLost.java +++ b/src/net/sourceforge/plantuml/eggs/PSystemLost.java @@ -33,7 +33,6 @@ */ package net.sourceforge.plantuml.eggs; -import java.awt.Color; import java.awt.Font; import java.io.IOException; import java.io.OutputStream; @@ -43,6 +42,8 @@ import java.util.List; import net.sourceforge.plantuml.AbstractPSystem; import net.sourceforge.plantuml.FileFormatOption; import net.sourceforge.plantuml.graphic.GraphicStrings; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.ugraphic.UFont; public class PSystemLost extends AbstractPSystem { @@ -52,26 +53,13 @@ public class PSystemLost extends AbstractPSystem { strings.add("Thank you for choosing Oceanic Airlines."); } -// public List createFiles(File suggestedFile, FileFormatOption fileFormat) throws IOException, InterruptedException { -// OutputStream os = null; -// try { -// os = new FileOutputStream(suggestedFile); -// getGraphicStrings().writeImage(os, fileFormat); -// } finally { -// if (os != null) { -// os.close(); -// } -// } -// return Arrays.asList(suggestedFile); -// } - public void exportDiagram(OutputStream os, StringBuilder cmap, int index, FileFormatOption fileFormat) throws IOException { getGraphicStrings().writeImage(os, fileFormat); } private GraphicStrings getGraphicStrings() throws IOException { - final Font font = new Font("SansSerif", Font.PLAIN, 12); - return new GraphicStrings(strings, font, Color.BLACK, Color.WHITE, null, null, false); + final UFont font = new UFont("SansSerif", Font.PLAIN, 12); + return new GraphicStrings(strings, font, HtmlColor.BLACK, HtmlColor.WHITE, null, null, false); } public String getDescription() { diff --git a/src/net/sourceforge/plantuml/eggs/PSystemLostFactory.java b/src/net/sourceforge/plantuml/eggs/PSystemLostFactory.java index 741f117e2..4bef187bf 100644 --- a/src/net/sourceforge/plantuml/eggs/PSystemLostFactory.java +++ b/src/net/sourceforge/plantuml/eggs/PSystemLostFactory.java @@ -40,11 +40,7 @@ public class PSystemLostFactory implements PSystemBasicFactory { private PSystemLost system; - public PSystemLostFactory() { - reset(); - } - - public void reset() { + public void init(String startLine) { } public boolean executeLine(String line) { diff --git a/src/net/sourceforge/plantuml/eggs/PSystemPath.java b/src/net/sourceforge/plantuml/eggs/PSystemPath.java index d7e0ad090..9375b9744 100644 --- a/src/net/sourceforge/plantuml/eggs/PSystemPath.java +++ b/src/net/sourceforge/plantuml/eggs/PSystemPath.java @@ -38,29 +38,17 @@ import java.io.OutputStream; import net.sourceforge.plantuml.AbstractPSystem; import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity; public class PSystemPath extends AbstractPSystem { private final GraphicsPath path; public PSystemPath(String s) { - this.path = new GraphicsPath(s); + this.path = new GraphicsPath(new ColorMapperIdentity(), s); } -// public List createFiles(File suggestedFile, FileFormatOption fileFormat) throws IOException, InterruptedException { -// OutputStream os = null; -// try { -// os = new FileOutputStream(suggestedFile); -// path.writeImage(os); -// } finally { -// if (os != null) { -// os.close(); -// } -// } -// return Arrays.asList(suggestedFile); -// } - public void exportDiagram(OutputStream os, StringBuilder cmap, int index, FileFormatOption fileFormat) throws IOException { path.writeImage(os); } diff --git a/src/net/sourceforge/plantuml/eggs/PSystemPathFactory.java b/src/net/sourceforge/plantuml/eggs/PSystemPathFactory.java index 3d501b12d..58c314d82 100644 --- a/src/net/sourceforge/plantuml/eggs/PSystemPathFactory.java +++ b/src/net/sourceforge/plantuml/eggs/PSystemPathFactory.java @@ -43,11 +43,7 @@ public class PSystemPathFactory implements PSystemBasicFactory { private PSystemPath system; - public PSystemPathFactory() { - reset(); - } - - public void reset() { + public void init(String startLine) { } final private static Pattern p = Pattern diff --git a/src/net/sourceforge/plantuml/eggs/PSystemRIP.java b/src/net/sourceforge/plantuml/eggs/PSystemRIP.java index c013e490a..84302bc0d 100644 --- a/src/net/sourceforge/plantuml/eggs/PSystemRIP.java +++ b/src/net/sourceforge/plantuml/eggs/PSystemRIP.java @@ -33,7 +33,6 @@ */ package net.sourceforge.plantuml.eggs; -import java.awt.Color; import java.awt.Font; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; @@ -49,6 +48,8 @@ import net.sourceforge.plantuml.AbstractPSystem; import net.sourceforge.plantuml.FileFormatOption; import net.sourceforge.plantuml.graphic.GraphicPosition; import net.sourceforge.plantuml.graphic.GraphicStrings; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.ugraphic.UFont; public class PSystemRIP extends AbstractPSystem { @@ -72,26 +73,13 @@ public class PSystemRIP extends AbstractPSystem { is.close(); } -// public List createFiles(File suggestedFile, FileFormatOption fileFormat) throws IOException, InterruptedException { -// OutputStream os = null; -// try { -// os = new FileOutputStream(suggestedFile); -// getGraphicStrings().writeImage(os, fileFormat); -// } finally { -// if (os != null) { -// os.close(); -// } -// } -// return Arrays.asList(suggestedFile); -// } - public void exportDiagram(OutputStream os, StringBuilder cmap, int index, FileFormatOption fileFormat) throws IOException { getGraphicStrings().writeImage(os, fileFormat); } private GraphicStrings getGraphicStrings() throws IOException { - final Font font = new Font("SansSerif", Font.PLAIN, 12); - return new GraphicStrings(strings, font, Color.BLACK, Color.WHITE, image, GraphicPosition.BOTTOM, false); + final UFont font = new UFont("SansSerif", Font.PLAIN, 12); + return new GraphicStrings(strings, font, HtmlColor.BLACK, HtmlColor.WHITE, image, GraphicPosition.BOTTOM, false); } public String getDescription() { diff --git a/src/net/sourceforge/plantuml/eggs/PSystemRIPFactory.java b/src/net/sourceforge/plantuml/eggs/PSystemRIPFactory.java index abc8982ce..215bd70e9 100644 --- a/src/net/sourceforge/plantuml/eggs/PSystemRIPFactory.java +++ b/src/net/sourceforge/plantuml/eggs/PSystemRIPFactory.java @@ -43,11 +43,7 @@ public class PSystemRIPFactory implements PSystemBasicFactory { private PSystemRIP system; - public PSystemRIPFactory() { - reset(); - } - - public void reset() { + public void init(String startLine) { } public boolean executeLine(String line) { diff --git a/src/net/sourceforge/plantuml/eps/AbstractInkscape.java b/src/net/sourceforge/plantuml/eps/AbstractInkscape.java deleted file mode 100644 index 6b00bdd7a..000000000 --- a/src/net/sourceforge/plantuml/eps/AbstractInkscape.java +++ /dev/null @@ -1,93 +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: 4826 $ - * - */ -package net.sourceforge.plantuml.eps; - -import java.io.File; -import java.io.IOException; - -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.cucadiagram.dot.ProcessRunner; - -abstract class AbstractInkscape implements Inkscape { - - abstract protected File specificExe(); - - AbstractInkscape() { - throw new UnsupportedOperationException("Not used anymore"); - } - - final public void createEps(File svg, File eps) throws IOException, InterruptedException { - final StringBuilder cmd = new StringBuilder(); - appendFilePath(cmd, searchDotExe()); - cmd.append(" -E "); - appendFilePath(cmd, eps); - cmd.append(" "); - appendFilePath(cmd, svg); - eps.delete(); - if (eps.exists()) { - throw new IOException("Cannot delete " + eps); - } - String result = executeCmd(cmd.toString()); - if (eps.exists() == false) { - throw new IOException("File not created " + eps); - } - } - - private File searchDotExe() { - final String getenv = InkscapeUtils.getenvInkscape(); - if (getenv == null) { - return specificExe(); - } - return new File(getenv); - } - - abstract protected void appendFilePath(final StringBuilder sb, File file); - - private String executeCmd(final String cmd) throws IOException, InterruptedException { - final ProcessRunner p = new ProcessRunner(cmd); - p.run(null, null); - final StringBuilder sb = new StringBuilder(); - if (StringUtils.isNotEmpty(p.getOut())) { - sb.append(p.getOut()); - } - if (StringUtils.isNotEmpty(p.getError())) { - if (sb.length() > 0) { - sb.append(' '); - } - sb.append(p.getError()); - } - return sb.toString().replace('\n', ' ').trim(); - } - -} diff --git a/src/net/sourceforge/plantuml/eps/EpsGraphics.java b/src/net/sourceforge/plantuml/eps/EpsGraphics.java index 5a8d77343..22749490a 100644 --- a/src/net/sourceforge/plantuml/eps/EpsGraphics.java +++ b/src/net/sourceforge/plantuml/eps/EpsGraphics.java @@ -40,6 +40,7 @@ import java.util.Date; import java.util.Locale; import java.util.StringTokenizer; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UGradient; public class EpsGraphics { @@ -103,6 +104,9 @@ public class EpsGraphics { if (y > maxY) { maxY = (int) (y + 1); } + if (urlArea != null) { + urlArea.ensureVisible((int) Math.round(x), (int) Math.round(y)); + } } protected final Color getColor() { @@ -121,6 +125,7 @@ public class EpsGraphics { header.append("gsave\n"); header.append("0 " + maxY + " translate\n"); header.append("1 -1 scale\n"); + if (setcolorgradientUsed) { header.append(setcolorgradient.getPostStringDefinition()); } @@ -179,6 +184,24 @@ public class EpsGraphics { private double dashVisible = 0; private double dashSpace = 0; + public void newpathDot(boolean dashed) { + checkCloseDone(); + append(strokeWidth + " setlinewidth", true); + appendColor(color); + + if (dashed) { + append("[9 9] 0 setdash", true); + } + append("newpath", true); + } + + public void closepathDot(boolean dashed) { + append("stroke", true); + if (dashed) { + append("[] 0 setdash", true); + } + } + public void epsLine(double x1, double y1, double x2, double y2) { ensureVisible(x1, y1); ensureVisible(x2, y2); @@ -285,7 +308,16 @@ public class EpsGraphics { } } - public void epsRectangle(double x, double y, double width, double height, double rx, double ry, UGradient gr) { + public void epsUrlLink(int x, int y, int width, int height, String url) { + append("[ /Rect [ " + x + " " + y + " " + (x + width) + " " + (y + height) + " ]", true); + append("/Border [ 0 0 0 ]", true); + append("/Action << /Subtype /URI /URI (" + url + ") >>", true); + append("/Subtype /Link", true); + append("/ANN pdfmark", true); + } + + public void epsRectangle(double x, double y, double width, double height, double rx, double ry, UGradient gr, + ColorMapper mapper) { checkCloseDone(); ensureVisible(x, y); ensureVisible(x + width, y + height); @@ -293,8 +325,8 @@ public class EpsGraphics { if (rx == 0 && ry == 0) { simplerectUsed = true; - appendColorShort(gr.getColor1()); - appendColorShort(gr.getColor2()); + appendColorShort(mapper.getMappedColor(gr.getColor1())); + appendColorShort(mapper.getMappedColor(gr.getColor2())); append(format(width) + " " + format(height) + " " + format(x) + " " + format(y), true); append("100 -1 1 {", true); append("100 div", true); @@ -316,8 +348,8 @@ public class EpsGraphics { append("initclip", true); } else { roundrectUsed = true; - appendColorShort(gr.getColor1()); - appendColorShort(gr.getColor2()); + appendColorShort(mapper.getMappedColor(gr.getColor1())); + appendColorShort(mapper.getMappedColor(gr.getColor2())); append(format(width) + " " + format(height) + " " + format(x) + " " + format(y) + " " + format((rx + ry) / 2), true); append("100 -1 1 {", true); @@ -423,6 +455,24 @@ public class EpsGraphics { body.append(s + "\n"); } + // final public void linetoNoMacro(double x1, double y1) { + // append(format(x1) + " " + format(y1) + " lineto", true); + // ensureVisible(x1, y1); + // } + // + final public void movetoNoMacro(double x1, double y1) { + append(format(x1) + " " + format(y1) + " moveto", true); + ensureVisible(x1, y1); + } + + final public void curvetoNoMacro(double x1, double y1, double x2, double y2, double x3, double y3) { + append(format(x1) + " " + format(y1) + " " + format(x2) + " " + format(y2) + " " + format(x3) + " " + + format(y3) + " curveto", true); + ensureVisible(x1, y1); + ensureVisible(x2, y2); + ensureVisible(x3, y3); + } + // FONT public void moveto(double x1, double y1) { append(format(x1) + " " + format(y1) + " moveto", true); @@ -529,4 +579,47 @@ public class EpsGraphics { return dashSpace; } + static class UrlArea { + private final String url; + private int xmin = Integer.MAX_VALUE; + private int xmax = Integer.MIN_VALUE; + private int ymin = Integer.MAX_VALUE; + private int ymax = Integer.MIN_VALUE; + + UrlArea(String url) { + this.url = url; + } + + void ensureVisible(int x, int y) { + if (x < xmin) { + xmin = x; + } + if (x > xmax) { + xmax = x; + } + if (y < ymin) { + ymin = y; + } + if (y > ymax) { + ymax = y; + } + } + } + + private UrlArea urlArea; + + public void closeLink() { + if (urlArea != null && urlArea.xmin != Integer.MAX_VALUE) { + final int width = urlArea.xmax - urlArea.xmin; + final int height = urlArea.ymax - urlArea.ymin; + assert width >= 0 && height >= 0; + epsUrlLink(urlArea.xmin, urlArea.ymin, width, height, urlArea.url); + } + this.urlArea = null; + } + + public void openLink(String url) { + this.urlArea = new UrlArea(url); + } + } diff --git a/src/net/sourceforge/plantuml/eps/EpsGraphicsMacroAndText.java b/src/net/sourceforge/plantuml/eps/EpsGraphicsMacroAndText.java new file mode 100644 index 000000000..240aad4d2 --- /dev/null +++ b/src/net/sourceforge/plantuml/eps/EpsGraphicsMacroAndText.java @@ -0,0 +1,103 @@ +/* ======================================================================== + * 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: 4207 $ + * + */ +package net.sourceforge.plantuml.eps; + +import java.io.UnsupportedEncodingException; + +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UFontContext; + +public class EpsGraphicsMacroAndText extends EpsGraphicsMacro { + + public void drawText(String text, FontConfiguration fontConfiguration, double x, double y) { + append(format(x) + " " + format(y) + " moveto", true); + appendColor(getColor()); + final UFont font = fontConfiguration.getFont(); + final int size = font.getSize(); + append("/" + getPSName(fontConfiguration) + " findfont " + size + " scalefont setfont", true); + append("1 -1 scale", true); + append("(" + getTextAsEps(text) + ") show", true); + append("1 -1 scale", true); + } + + private String getPSName(FontConfiguration fontConfiguration) { + final UFont font = fontConfiguration.getFont(); + final StringBuilder sb = new StringBuilder(font.getFamily(UFontContext.EPS)); + // final int style = fontConfiguration.getFont().getStyle(); + // final boolean bold = (style & Font.BOLD) != 0 || fontConfiguration.containsStyle(FontStyle.BOLD); + // final boolean italic = (style & Font.ITALIC) != 0 || fontConfiguration.containsStyle(FontStyle.ITALIC); + // if (bold && italic) { + // sb.append("-BoldItalic"); + // } else if (bold) { + // sb.append("-Bold"); + // } else if (italic) { + // sb.append("-Italic"); + // } + return sb.toString(); + } + + private String getTextAsEps(String text) { + final StringBuilder sb = new StringBuilder(); + for (int i = 0; i < text.length(); i++) { + final char c = text.charAt(i); + if (c == '\\') { + sb.append("\\\\"); + } else if (c == '(') { + sb.append("\\("); + } else if (c == ')') { + sb.append("\\)"); + } else if (c < ' ') { + sb.append("?"); + } else if (c >= ' ' && c <= 127) { + sb.append(c); + } else { + final String s = "" + c; + try { + final byte b[] = s.getBytes("ISO-8859-1"); + if (b.length == 1) { + final int code = (b[0] & 0xFF); + sb.append("\\" + Integer.toOctalString(code)); + } else { + sb.append('?'); + } + } catch (UnsupportedEncodingException e) { + sb.append('?'); + } + } + } + return sb.toString(); + } + +} diff --git a/src/net/sourceforge/plantuml/eps/EpsStrategy.java b/src/net/sourceforge/plantuml/eps/EpsStrategy.java index c2be93028..c90f85e63 100644 --- a/src/net/sourceforge/plantuml/eps/EpsStrategy.java +++ b/src/net/sourceforge/plantuml/eps/EpsStrategy.java @@ -35,7 +35,7 @@ package net.sourceforge.plantuml.eps; public enum EpsStrategy { - VERY_SIMPLE, WITH_MACRO; + VERY_SIMPLE, WITH_MACRO, WITH_MACRO_AND_TEXT; public EpsGraphics creatEpsGraphics() { if (this == VERY_SIMPLE) { @@ -44,10 +44,13 @@ public enum EpsStrategy { if (this == WITH_MACRO) { return new EpsGraphicsMacro(); } + if (this == WITH_MACRO_AND_TEXT) { + return new EpsGraphicsMacroAndText(); + } throw new IllegalArgumentException(); } - public static EpsStrategy getDefault() { + public static EpsStrategy getDefault2() { return WITH_MACRO; } diff --git a/src/net/sourceforge/plantuml/eps/EpsTitler.java b/src/net/sourceforge/plantuml/eps/EpsTitler.java index 95f85b8e6..9013c170b 100644 --- a/src/net/sourceforge/plantuml/eps/EpsTitler.java +++ b/src/net/sourceforge/plantuml/eps/EpsTitler.java @@ -33,7 +33,6 @@ */ package net.sourceforge.plantuml.eps; -import java.awt.Color; import java.awt.Font; import java.awt.geom.Dimension2D; import java.io.IOException; @@ -42,35 +41,36 @@ import java.util.StringTokenizer; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; import net.sourceforge.plantuml.graphic.VerticalPosition; +import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.eps.UGraphicEps; public final class EpsTitler { - private final Color textColor; - private final List text; - // private final int fontSize; - // private final String fontFamily; + private final List text; private final HorizontalAlignement horizontalAlignement; private final VerticalPosition verticalPosition; private final int margin; private final TextBlock textBloc; + private final EpsStrategy epsStrategy; + private final ColorMapper colorMapper; - public EpsTitler(Color textColor, List text, int fontSize, String fontFamily, + public EpsTitler(ColorMapper colorMapper, EpsStrategy epsStrategy, HtmlColor textColor, List text, int fontSize, String fontFamily, HorizontalAlignement horizontalAlignement, VerticalPosition verticalPosition, int margin) { - this.textColor = textColor; this.text = text; - // this.fontSize = fontSize; - // this.fontFamily = fontFamily; + this.colorMapper = colorMapper; + this.epsStrategy = epsStrategy; this.horizontalAlignement = horizontalAlignement; this.verticalPosition = verticalPosition; this.margin = margin; if (text == null || text.size() == 0) { textBloc = null; } else { - final Font normalFont = new Font(fontFamily, Font.PLAIN, fontSize); + final UFont normalFont = new UFont(fontFamily, Font.PLAIN, fontSize); textBloc = TextBlockUtils.create(text, new FontConfiguration(normalFont, textColor), HorizontalAlignement.LEFT); } @@ -80,8 +80,7 @@ public final class EpsTitler { if (textBloc == null) { return 0; } - return textBloc.calculateDimension(new UGraphicEps(EpsStrategy.getDefault()).getStringBounder()).getHeight() - + margin; + return textBloc.calculateDimension(new UGraphicEps(colorMapper, epsStrategy).getStringBounder()).getHeight() + margin; } public String addTitleEps(String eps) throws IOException { @@ -104,7 +103,7 @@ public final class EpsTitler { final double width = x2 - x1; final double height = y2 - y1; - final UGraphicEps uGraphicEps = new UGraphicEps(EpsStrategy.getDefault()); + final UGraphicEps uGraphicEps = new UGraphicEps(colorMapper, epsStrategy); final Dimension2D dimText = textBloc.calculateDimension(uGraphicEps.getStringBounder()); final double xpos; diff --git a/src/net/sourceforge/plantuml/eps/SvgToEpsConverter.java b/src/net/sourceforge/plantuml/eps/SvgToEpsConverter.java deleted file mode 100644 index 9973a17c1..000000000 --- a/src/net/sourceforge/plantuml/eps/SvgToEpsConverter.java +++ /dev/null @@ -1,89 +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: 4207 $ - * - */ -package net.sourceforge.plantuml.eps; - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintWriter; - -import net.sourceforge.plantuml.FileUtils; -import net.sourceforge.plantuml.OptionFlags; - -public class SvgToEpsConverter { - - private final Inkscape inkscape; - private final File svgFile; - - public SvgToEpsConverter(String svg) throws IOException { - if (svg == null) { - throw new IllegalArgumentException(); - } - this.inkscape = InkscapeUtils.create(); - this.svgFile = FileUtils.createTempFile("convert", ".svg"); - final PrintWriter pw = new PrintWriter(svgFile); - pw.println(svg); - pw.close(); - } - - public SvgToEpsConverter(File svgFile) { - if (svgFile == null) { - throw new IllegalArgumentException(); - } - this.inkscape = InkscapeUtils.create(); - this.svgFile = svgFile; - } - - public void createEps(File epsFile) throws IOException, InterruptedException { - inkscape.createEps(svgFile, epsFile); - } - - - public void createEps(OutputStream os) throws IOException, InterruptedException { - final File epsFile = FileUtils.createTempFile("eps", ".eps"); - createEps(epsFile); - int read; - final InputStream is = new FileInputStream(epsFile); - while ((read = is.read()) != -1) { - os.write(read); - } - is.close(); - if (OptionFlags.getInstance().isKeepTmpFiles() == false) { - epsFile.delete(); - } - } - -} diff --git a/src/net/sourceforge/plantuml/ftp/FtpConnexion.java b/src/net/sourceforge/plantuml/ftp/FtpConnexion.java new file mode 100644 index 000000000..cffe3ad61 --- /dev/null +++ b/src/net/sourceforge/plantuml/ftp/FtpConnexion.java @@ -0,0 +1,124 @@ +/* ======================================================================== + * 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: 3830 $ + * + */ +package net.sourceforge.plantuml.ftp; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.sourceforge.plantuml.FileFormat; +import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.SourceStringReader; + +public class FtpConnexion { + + private final String user; + private final Map incoming = new HashMap(); + private final Map outgoing = new HashMap(); + + public FtpConnexion(String user) { + this.user = user; + } + + public synchronized void addIncoming(String fileName, String data) { + if (fileName.startsWith("/")) { + throw new IllegalArgumentException(); + } + incoming.put(fileName, data); + } + + public void removeOutgoing(String fileName) { + outgoing.remove(fileName); + } + + + public synchronized Collection getFiles() { + final List result = new ArrayList(incoming.keySet()); + result.addAll(outgoing.keySet()); + return Collections.unmodifiableCollection(result); + } + + public synchronized byte[] getData(String fileName) { + if (fileName.startsWith("/")) { + throw new IllegalArgumentException(); + } + final String data = incoming.get(fileName); + if (data != null) { + return data.getBytes(); + } + final byte data2[] = outgoing.get(fileName); + if (data2 != null) { + return data2; + } + return new byte[0]; + } + + public synchronized int getSize(String fileName) { + if (fileName.startsWith("/")) { + throw new IllegalArgumentException(); + } + final String data = incoming.get(fileName); + if (data != null) { + return data.length(); + } + final byte data2[] = outgoing.get(fileName); + if (data2 != null) { + return data2.length; + } + return 0; + } + + public void processImage(String fileName) throws IOException { + if (fileName.startsWith("/")) { + throw new IllegalArgumentException(); + } + final SourceStringReader sourceStringReader = new SourceStringReader(incoming.get(fileName)); + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + final FileFormat format = FileFormat.PNG; + final String pngFileName = format.changeName(fileName, 0); + final String ok = sourceStringReader.generateImage(baos, new FileFormatOption(format)); + if (ok != null) { + synchronized (this) { + outgoing.put(pngFileName, baos.toByteArray()); + } + } + } + + +} diff --git a/src/net/sourceforge/plantuml/ftp/FtpLoop.java b/src/net/sourceforge/plantuml/ftp/FtpLoop.java new file mode 100644 index 000000000..d79185d57 --- /dev/null +++ b/src/net/sourceforge/plantuml/ftp/FtpLoop.java @@ -0,0 +1,299 @@ +/* ======================================================================== + * 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: 3830 $ + * + */ +package net.sourceforge.plantuml.ftp; + +// server + +// FtpServer.java +import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.UnknownHostException; +import java.util.Collection; +import java.util.StringTokenizer; + +import net.sourceforge.plantuml.FileFormat; +import net.sourceforge.plantuml.FileUtils; + +class FtpLoop implements Runnable { + enum Mode { + ACTIF, PASSIF + }; + + final private Socket incoming; + final private FtpServer ftpServer; + final private BufferedReader br; + final private PrintWriter pw; + + private FtpConnexion connexion; + private String ipClient = null; + private int port = -1; + private Mode mode; + + public FtpLoop(Socket socket, FtpServer ftpServer) throws IOException { + this.incoming = socket; + this.ftpServer = ftpServer; + this.br = new BufferedReader(new InputStreamReader(incoming.getInputStream())); + this.pw = new PrintWriter(incoming.getOutputStream(), true); + } + + // http://www.ncftp.com/libncftp/doc/ftp_overview.html + // http://www.nsftools.com/tips/RawFTP.htm + // http://www.commentcamarche.net/contents/internet/ftp.php3 + // http://en.wikipedia.org/wiki/List_of_FTP_server_return_codes + // http://www.freefire.org/articles/ftpexample.php + // http://forum.hardware.fr/hfr/Programmation/VB-VBA-VBS/transfert-sujet_59989_1.htm + // http://www.excel-downloads.com/forum/104130-telechargement-ftp-via-vba.html + // http://www.pcreview.co.uk/forums/ftp-vba-macro-t949945.html + private void runInternal() throws IOException, InterruptedException { + localLog("Starting Loop"); + myOut("220 PlantUML"); + while (true) { + final String s = br.readLine(); + localLog("s=" + s); + if (s == null) { + pw.close(); + br.close(); + return; + } + final boolean finish = manage(s); + if (finish) { + return; + } + } + } + + private boolean manage(final String cmd) throws UnknownHostException, IOException, InterruptedException { + final String upper = cmd.toUpperCase(); + if (upper.startsWith("USER")) { + myOut("331 Password required"); + final String user = cmd.substring("USER ".length()); + connexion = ftpServer.getFtpConnexion(user); + } else if (upper.startsWith("PASS")) { + myOut("230 Logged in."); + } else if (upper.startsWith("PWD")) { + // myOut("/"); + // myOut("200 OK /"); + myOut("257 \"/\" is current directory."); + } else if (upper.startsWith("CWD")) { + final String dir = cmd.substring("CWD ".length()); + myOut("250 \"" + dir + "\" is new working directory.."); + } else if (upper.startsWith("TYPE")) { + myOut("200 Command okay."); + // localLog("type=" + s); + } else if (upper.startsWith("PORT")) { + mode = Mode.ACTIF; + final StringTokenizer st = new StringTokenizer(cmd, " ,"); + st.nextToken(); + ipClient = st.nextToken() + "." + st.nextToken() + "." + st.nextToken() + "." + st.nextToken(); + port = Integer.parseInt(st.nextToken()) * 256 + Integer.parseInt(st.nextToken()); + // localLog("ipClient=" + ipClient); + // localLog("port=" + port); + + myOut("200 Command okay."); + } else if (upper.startsWith("LIST")) { + if (mode == Mode.ACTIF) { + listActif(); + } else { + listPassif(); + } + } else if (upper.startsWith("STOR")) { + if (mode == Mode.ACTIF) { + storActif(cmd); + } else { + storPassif(cmd); + } + } else if (upper.startsWith("PASV")) { + mode = Mode.PASSIF; + port = ftpServer.getFreePort(); + final int p1 = port / 256; + final int p2 = port % 256; + assert port == p1 * 256 + p2; + localLog("adr=" + incoming.getInetAddress().getHostAddress()); + final String ipServer = ftpServer.getIpServer(); + localLog("server=" + ipServer); + myOut("227 Entering Passive Mode (" + ipServer.replace('.', ',') + "," + p1 + "," + p2 + ")."); + ipClient = ipServer; + } else if (upper.startsWith("RETR")) { + if (mode == Mode.ACTIF) { + retrActif(cmd); + } else { + retrPassif(cmd); + } + } else if (upper.startsWith("QUIT")) { + return true; + } else if (upper.startsWith("SYST")) { + myOut("215 UNIX Type: L8."); + } else { + myOut("502 Command not implemented."); + } + return false; + } + + private void localLog(String s) { + } + + private void retr(final String fileName, Socket soc) throws UnknownHostException, IOException, InterruptedException { + final OutputStream os = soc.getOutputStream(); + byte[] data = null; + do { + data = connexion.getData(fileName); + if (data.length == 0) { + Thread.sleep(200L); + } + } while (data.length == 0); + + os.write(data); + os.flush(); + os.close(); + soc.close(); + myOut("226 Transfer complete."); + } + + private void retrPassif(final String s) throws UnknownHostException, IOException, InterruptedException { + String fileName = s.substring("STOR ".length()); + fileName = removeStartingsSlash(fileName); + myOut("150 Opening"); + final ServerSocket ss = new ServerSocket(port); + final Socket incoming = ss.accept(); + retr(fileName, incoming); + ss.close(); + } + + private void retrActif(final String s) throws UnknownHostException, IOException, InterruptedException { + String fileName = s.substring("STOR ".length()); + fileName = removeStartingsSlash(fileName); + myOut("150 Opening"); + final Socket soc = new Socket(ipClient, port); + retr(fileName, soc); + } + + private void storActif(final String s) throws IOException { + final String fileName = removeStartingsSlash(s.substring("STOR ".length())); + myOut("150 FILE: " + fileName); + final Socket soc = new Socket(ipClient, port); + stor(fileName, soc); + } + + private void storPassif(final String s) throws IOException { + final String fileName = removeStartingsSlash(s.substring("STOR ".length())); + myOut("150 FILE: " + fileName); + final ServerSocket ss = new ServerSocket(port); + final Socket incoming = ss.accept(); + stor(fileName, incoming); + ss.close(); + } + + private String removeStartingsSlash(String fileName) { + while (fileName.startsWith("/")) { + fileName = fileName.substring(1); + } + return fileName; + } + + private void stor(String fileName, Socket socket) throws UnknownHostException, IOException { + final InputStream is = socket.getInputStream(); + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + FileUtils.copyToStream(is, baos); + myOut("226 Transfer complete."); + final String data = new String(baos.toByteArray()); + final FileFormat format = FileFormat.PNG; + final String pngFileName = format.changeName(fileName, 0); + connexion.removeOutgoing(pngFileName); + connexion.addIncoming(fileName, data); + + ftpServer.processImage(connexion, fileName); + } + + private void listActif() throws UnknownHostException, IOException { + myOut("150 Opening ASCII mode data"); + final Socket soc = new Socket(ipClient, port); + list(soc); + } + + private void listPassif() throws UnknownHostException, IOException { + myOut("150 Opening ASCII mode data"); + final ServerSocket ss = new ServerSocket(port); + final Socket incoming = ss.accept(); + list(incoming); + ss.close(); + } + + private void list(final Socket soc) throws IOException { + final PrintWriter listing = new PrintWriter(soc.getOutputStream(), true); + final Collection files = connexion.getFiles(); + if (files.size() > 0) { + int total = 0; + for (String n : files) { + total += (connexion.getSize(n) + 511) / 512; + } + listing.println("total " + total); + // localLog(total); + for (String n : files) { + final String ls = String.format("%10s %4d %-8s %-8s %8d %3s %2s %5s %s", "-rw-rw-r--", 1, "plantuml", + "plantuml", connexion.getSize(n), "Sep", 28, 2006, n); + listing.println(ls); + // localLog(ls); + } + } + listing.flush(); + listing.close(); + soc.close(); + myOut("226 Listing completed."); + } + + private void myOut(String s) { + if (s.indexOf('\t') != -1) { + throw new IllegalArgumentException(); + } + pw.println(s); + pw.flush(); + } + + public void run() { + try { + runInternal(); + } catch (Throwable t) { + t.printStackTrace(); + } + + } + +} diff --git a/src/net/sourceforge/plantuml/ftp/FtpServer.java b/src/net/sourceforge/plantuml/ftp/FtpServer.java new file mode 100644 index 000000000..1df71a931 --- /dev/null +++ b/src/net/sourceforge/plantuml/ftp/FtpServer.java @@ -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: 3830 $ + * + */ +package net.sourceforge.plantuml.ftp; + +// server + +// FtpServer.java +import java.io.IOException; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.Map; +import java.util.TreeMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +public class FtpServer { + + private final Map datas = new TreeMap(); + private final ExecutorService exeImage = Executors.newFixedThreadPool(2); + + private final int listenPort; + + private int portFree = 10042; + private String ip; + + public FtpServer(int listenPort) { + this.listenPort = listenPort; + } + + public synchronized int getFreePort() { + portFree++; + System.err.println("port=" + portFree); + return portFree; + } + + public void go() throws IOException { + final ServerSocket s = new ServerSocket(listenPort); + final ExecutorService exe = Executors.newCachedThreadPool(); + while (true) { + final Socket incoming = s.accept(); + ip = incoming.getLocalAddress().getHostAddress(); + System.out.println("New Client Connected from " + incoming.getInetAddress().getHostName() + "... "); + exe.submit(new FtpLoop(incoming, this)); + } + } + + public String getIpServer() { + return ip; + } + + + public synchronized FtpConnexion getFtpConnexion(String user) { + if (user == null) { + throw new IllegalArgumentException(); + } + FtpConnexion data = datas.get(user); + if (data == null) { + data = new FtpConnexion(user); + datas.put(user, data); + } + return data; + } + + public static void main(String[] args) throws IOException { + System.out.println("****************************** ************************************************** "); + System.out.println("****************************** FTP SERVER***********************************"); + + System.out.println("****************************** ************************************************** "); + System.out.println("Server Started..."); + System.out.println("Waiting for connections..."); + System.out.println(" "); + new FtpServer(100).go(); + } + + public void processImage(final FtpConnexion connexion, final String name) { + exeImage.submit(new Runnable() { + public void run() { + try { + connexion.processImage(name); + } catch (IOException e) { + e.printStackTrace(); + } + } + }); + } + +} diff --git a/src/net/sourceforge/plantuml/graph/AbstractEntityImage.java b/src/net/sourceforge/plantuml/graph/AbstractEntityImage.java index 689d0b6f6..7fd1de0f9 100644 --- a/src/net/sourceforge/plantuml/graph/AbstractEntityImage.java +++ b/src/net/sourceforge/plantuml/graph/AbstractEntityImage.java @@ -28,33 +28,36 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3831 $ + * Revision $Revision: 6591 $ * */ package net.sourceforge.plantuml.graph; -import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.cucadiagram.Entity; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.ugraphic.UFont; abstract class AbstractEntityImage { private final Entity entity; - final private Color red = new Color(Integer.parseInt("A80036", 16)); - final private Color yellow = new Color(Integer.parseInt("FEFECE", 16)); - private final Color yellowNote = new Color(Integer.parseInt("FBFB77", 16)); + final private HtmlColor red = HtmlColor.getColorIfValid("#A80036"); + + final private HtmlColor yellow = HtmlColor.getColorIfValid("#FEFECE"); + private final HtmlColor yellowNote = HtmlColor.getColorIfValid("#FBFB77"); - final private Font font14 = new Font("SansSerif", Font.PLAIN, 14); - final private Font font17 = new Font("Courier", Font.BOLD, 17); - final private Color green = new Color(Integer.parseInt("ADD1B2", 16)); - final private Color violet = new Color(Integer.parseInt("B4A7E5", 16)); - final private Color blue = new Color(Integer.parseInt("A9DCDF", 16)); - final private Color rose = new Color(Integer.parseInt("EB937F", 16)); + final private UFont font14 = new UFont("SansSerif", Font.PLAIN, 14); + final private UFont font17 = new UFont("Courier", Font.BOLD, 17); + final private HtmlColor green = HtmlColor.getColorIfValid("#ADD1B2"); + final private HtmlColor violet = HtmlColor.getColorIfValid("#B4A7E5"); + final private HtmlColor blue = HtmlColor.getColorIfValid("#A9DCDF"); + final private HtmlColor rose = HtmlColor.getColorIfValid("#EB937F"); public AbstractEntityImage(Entity entity) { if (entity == null) { @@ -65,45 +68,45 @@ abstract class AbstractEntityImage { public abstract Dimension2D getDimension(StringBounder stringBounder); - public abstract void draw(Graphics2D g2d); + public abstract void draw(ColorMapper colorMapper, Graphics2D g2d); protected final Entity getEntity() { return entity; } - protected final Color getRed() { + protected final HtmlColor getRed() { return red; } - protected final Color getYellow() { + protected final HtmlColor getYellow() { return yellow; } - protected final Font getFont17() { + protected final UFont getFont17() { return font17; } - protected final Font getFont14() { + protected final UFont getFont14() { return font14; } - protected final Color getGreen() { + protected final HtmlColor getGreen() { return green; } - protected final Color getViolet() { + protected final HtmlColor getViolet() { return violet; } - protected final Color getBlue() { + protected final HtmlColor getBlue() { return blue; } - protected final Color getRose() { + protected final HtmlColor getRose() { return rose; } - protected final Color getYellowNote() { + protected final HtmlColor getYellowNote() { return yellowNote; } } diff --git a/src/net/sourceforge/plantuml/graph/Elastane.java b/src/net/sourceforge/plantuml/graph/Elastane.java index 3cc93d6d8..7d398aa4b 100644 --- a/src/net/sourceforge/plantuml/graph/Elastane.java +++ b/src/net/sourceforge/plantuml/graph/Elastane.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6009 $ + * Revision $Revision: 6591 $ * */ package net.sourceforge.plantuml.graph; @@ -59,9 +59,12 @@ import net.sourceforge.plantuml.geom.PolylineBreakeable; import net.sourceforge.plantuml.geom.XMoveable; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounderUtils; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity; +import net.sourceforge.plantuml.ugraphic.UFont; public class Elastane { @@ -266,9 +269,9 @@ public class Elastane { if (label != null) { final Point2DInt center = polyline.getFirst().getCenter(); final TextBlock textBlock = TextBlockUtils.create(Arrays.asList(label), - new FontConfiguration(g2d.getFont(), Color.BLACK), HorizontalAlignement.LEFT); + new FontConfiguration(UFont.getCurrentFont(g2d), HtmlColor.BLACK), HorizontalAlignement.LEFT); final Dimension2D dim = textBlock.calculateDimension(StringBounderUtils.asStringBounder(g2d)); - textBlock.drawTOBEREMOVED(g2d, center.getXint() - dim.getWidth() / 2, + textBlock.drawTOBEREMOVED(new ColorMapperIdentity(), g2d, center.getXint() - dim.getWidth() / 2, center.getYint() - dim.getHeight() / 2); } @@ -283,7 +286,7 @@ public class Elastane { assert image != null; final Box box = ent.getValue(); g2d.translate(box.getX(), box.getY()); - image.draw(g2d); + image.draw(new ColorMapperIdentity(), g2d); g2d.translate(-box.getX(), -box.getY()); } g2d.setTransform(at); diff --git a/src/net/sourceforge/plantuml/graph/EntityImageActivity.java b/src/net/sourceforge/plantuml/graph/EntityImageActivity.java index 611f574d9..036df725a 100644 --- a/src/net/sourceforge/plantuml/graph/EntityImageActivity.java +++ b/src/net/sourceforge/plantuml/graph/EntityImageActivity.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6009 $ + * Revision $Revision: 6923 $ * */ package net.sourceforge.plantuml.graph; @@ -43,10 +43,12 @@ import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.cucadiagram.Entity; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounderUtils; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.ColorMapper; class EntityImageActivity extends AbstractEntityImage { @@ -57,8 +59,8 @@ class EntityImageActivity extends AbstractEntityImage { public EntityImageActivity(Entity entity) { super(entity); - this.text = TextBlockUtils.create(StringUtils.getWithNewlines(entity.getDisplay()), new FontConfiguration( - getFont14(), Color.BLACK), HorizontalAlignement.CENTER); + this.text = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( + getFont14(), HtmlColor.BLACK), HorizontalAlignement.CENTER); } @Override @@ -68,7 +70,7 @@ class EntityImageActivity extends AbstractEntityImage { } @Override - public void draw(Graphics2D g2d) { + public void draw(ColorMapper colorMapper, Graphics2D g2d) { final Dimension2D dimTotal = getDimension(StringBounderUtils.asStringBounder(g2d)); final int width = (int) dimTotal.getWidth(); @@ -87,15 +89,15 @@ class EntityImageActivity extends AbstractEntityImage { p.addPoint(xMargin * 2, height); p.addPoint(0, height - 2 * yMargin); - g2d.setColor(getYellow()); + g2d.setColor(colorMapper.getMappedColor(getYellow())); g2d.fill(p); // g2d.fillRect(0, 0, width, height); - g2d.setColor(getRed()); + g2d.setColor(colorMapper.getMappedColor(getRed())); g2d.draw(p); // g2d.drawRect(0, 0, width - 1, height - 1); g2d.setColor(Color.BLACK); - text.drawTOBEREMOVED(g2d, xMargin, yMargin); + text.drawTOBEREMOVED(colorMapper, g2d, xMargin, yMargin); } } diff --git a/src/net/sourceforge/plantuml/graph/EntityImageActivityBar.java b/src/net/sourceforge/plantuml/graph/EntityImageActivityBar.java index aafb2ca30..c79a12b4e 100644 --- a/src/net/sourceforge/plantuml/graph/EntityImageActivityBar.java +++ b/src/net/sourceforge/plantuml/graph/EntityImageActivityBar.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3831 $ + * Revision $Revision: 6577 $ * */ package net.sourceforge.plantuml.graph; @@ -40,6 +40,7 @@ import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.cucadiagram.Entity; import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.ColorMapper; class EntityImageActivityBar extends AbstractEntityImage { @@ -56,7 +57,7 @@ class EntityImageActivityBar extends AbstractEntityImage { } @Override - public void draw(Graphics2D g2d) { + public void draw(ColorMapper colorMapper, Graphics2D g2d) { g2d.setColor(Color.BLACK); g2d.fillRect(0, 0, width, height); } diff --git a/src/net/sourceforge/plantuml/graph/EntityImageActivityBranch.java b/src/net/sourceforge/plantuml/graph/EntityImageActivityBranch.java index ce06033b5..818b7ed59 100644 --- a/src/net/sourceforge/plantuml/graph/EntityImageActivityBranch.java +++ b/src/net/sourceforge/plantuml/graph/EntityImageActivityBranch.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3831 $ + * Revision $Revision: 6577 $ * */ package net.sourceforge.plantuml.graph; @@ -40,6 +40,7 @@ import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.cucadiagram.Entity; import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.ColorMapper; class EntityImageActivityBranch extends AbstractEntityImage { @@ -55,16 +56,16 @@ class EntityImageActivityBranch extends AbstractEntityImage { } @Override - public void draw(Graphics2D g2d) { + public void draw(ColorMapper colorMapper, Graphics2D g2d) { final Polygon p = new Polygon(); p.addPoint(size, 0); p.addPoint(size * 2, size); p.addPoint(size, size * 2); p.addPoint(0, size); - g2d.setColor(getYellow()); + g2d.setColor(colorMapper.getMappedColor(getYellow())); g2d.fill(p); - g2d.setColor(getRed()); + g2d.setColor(colorMapper.getMappedColor(getRed())); g2d.draw(p); } } diff --git a/src/net/sourceforge/plantuml/graph/EntityImageActivityCircle.java b/src/net/sourceforge/plantuml/graph/EntityImageActivityCircle.java index 10912dd57..42ebffa3e 100644 --- a/src/net/sourceforge/plantuml/graph/EntityImageActivityCircle.java +++ b/src/net/sourceforge/plantuml/graph/EntityImageActivityCircle.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3831 $ + * Revision $Revision: 6577 $ * */ package net.sourceforge.plantuml.graph; @@ -40,6 +40,7 @@ import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.cucadiagram.Entity; import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.ColorMapper; class EntityImageActivityCircle extends AbstractEntityImage { @@ -58,7 +59,7 @@ class EntityImageActivityCircle extends AbstractEntityImage { } @Override - public void draw(Graphics2D g2d) { + public void draw(ColorMapper colorMapper, Graphics2D g2d) { g2d.setColor(Color.BLACK); final int delta = diameterExternal - diameterInternal + 1; g2d.drawOval(0, 0, diameterExternal, diameterExternal); diff --git a/src/net/sourceforge/plantuml/graph/EntityImageActor.java b/src/net/sourceforge/plantuml/graph/EntityImageActor.java index bbf4b4987..cb3ebc8d4 100644 --- a/src/net/sourceforge/plantuml/graph/EntityImageActor.java +++ b/src/net/sourceforge/plantuml/graph/EntityImageActor.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6009 $ + * Revision $Revision: 6923 $ * */ package net.sourceforge.plantuml.graph; @@ -43,11 +43,13 @@ import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.cucadiagram.Entity; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounderUtils; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; import net.sourceforge.plantuml.skin.StickMan; +import net.sourceforge.plantuml.ugraphic.ColorMapper; class EntityImageActor extends AbstractEntityImage { @@ -56,8 +58,8 @@ class EntityImageActor extends AbstractEntityImage { public EntityImageActor(Entity entity) { super(entity); - this.name = TextBlockUtils.create(StringUtils.getWithNewlines(entity.getDisplay()), new FontConfiguration( - getFont14(), Color.BLACK), HorizontalAlignement.CENTER); + this.name = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( + getFont14(), HtmlColor.BLACK), HorizontalAlignement.CENTER); this.stickman = new StickMan(getYellow(), getRed()); } @@ -70,7 +72,7 @@ class EntityImageActor extends AbstractEntityImage { } @Override - public void draw(Graphics2D g2d) { + public void draw(ColorMapper colorMapper, Graphics2D g2d) { final Dimension2D dimTotal = getDimension(StringBounderUtils.asStringBounder(g2d)); final Dimension2D nameDim = name.calculateDimension(StringBounderUtils.asStringBounder(g2d)); @@ -87,6 +89,6 @@ class EntityImageActor extends AbstractEntityImage { g2d.translate(-manX, 0); g2d.setColor(Color.BLACK); - name.drawTOBEREMOVED(g2d, (dimTotal.getWidth() - nameDim.getWidth()) / 2, manHeight); + name.drawTOBEREMOVED(colorMapper, g2d, (dimTotal.getWidth() - nameDim.getWidth()) / 2, manHeight); } } diff --git a/src/net/sourceforge/plantuml/graph/EntityImageCircleInterface.java b/src/net/sourceforge/plantuml/graph/EntityImageCircleInterface.java index 8b44f8471..1e72506af 100644 --- a/src/net/sourceforge/plantuml/graph/EntityImageCircleInterface.java +++ b/src/net/sourceforge/plantuml/graph/EntityImageCircleInterface.java @@ -28,12 +28,11 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6009 $ + * Revision $Revision: 6923 $ * */ package net.sourceforge.plantuml.graph; -import java.awt.Color; import java.awt.Graphics2D; import java.awt.geom.Dimension2D; @@ -42,10 +41,12 @@ import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.cucadiagram.Entity; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +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.skin.CircleInterface; +import net.sourceforge.plantuml.ugraphic.ColorMapper; class EntityImageCircleInterface extends AbstractEntityImage { @@ -54,8 +55,8 @@ class EntityImageCircleInterface extends AbstractEntityImage { public EntityImageCircleInterface(Entity entity) { super(entity); - this.name = TextBlockUtils.create(StringUtils.getWithNewlines(entity.getDisplay()), new FontConfiguration( - getFont14(), Color.BLACK), HorizontalAlignement.CENTER); + this.name = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( + getFont14(), HtmlColor.BLACK), HorizontalAlignement.CENTER); this.circleInterface = new CircleInterface(getYellow(), getRed()); } @@ -68,7 +69,7 @@ class EntityImageCircleInterface extends AbstractEntityImage { } @Override - public void draw(Graphics2D g2d) { + public void draw(ColorMapper colorMapper, Graphics2D g2d) { throw new UnsupportedOperationException(); // final Dimension2D dimTotal = getDimension(StringBounderUtils.asStringBounder(g2d)); // final Dimension2D nameDim = name.calculateDimension(StringBounderUtils.asStringBounder(g2d)); diff --git a/src/net/sourceforge/plantuml/graph/EntityImageClass.java b/src/net/sourceforge/plantuml/graph/EntityImageClass.java index 00d1417c7..c9d4e762e 100644 --- a/src/net/sourceforge/plantuml/graph/EntityImageClass.java +++ b/src/net/sourceforge/plantuml/graph/EntityImageClass.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6168 $ + * Revision $Revision: 6923 $ * */ package net.sourceforge.plantuml.graph; @@ -44,10 +44,13 @@ import net.sourceforge.plantuml.cucadiagram.EntityType; import net.sourceforge.plantuml.graphic.CircledCharacter; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounderUtils; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity; class EntityImageClass extends AbstractEntityImage { @@ -61,8 +64,8 @@ class EntityImageClass extends AbstractEntityImage { public EntityImageClass(Entity entity) { super(entity); - this.name = TextBlockUtils.create(StringUtils.getWithNewlines(entity.getDisplay()), new FontConfiguration( - getFont14(), Color.BLACK), HorizontalAlignement.CENTER); + this.name = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( + getFont14(), HtmlColor.BLACK), HorizontalAlignement.CENTER); this.methods = new MethodsOrFieldsArea(entity.getMethodsToDisplay(), getFont14()); this.fields = new MethodsOrFieldsArea(entity.getFieldsToDisplay(), getFont14()); @@ -78,16 +81,16 @@ class EntityImageClass extends AbstractEntityImage { // } final double radius = 10; if (entity.getType() == EntityType.ABSTRACT_CLASS) { - return new CircledCharacter('A', radius, getFont17(), getBlue(), getRed(), Color.BLACK); + return new CircledCharacter('A', radius, getFont17(), getBlue(), getRed(), HtmlColor.BLACK); } if (entity.getType() == EntityType.CLASS) { - return new CircledCharacter('C', radius, getFont17(), getGreen(), getRed(), Color.BLACK); + return new CircledCharacter('C', radius, getFont17(), getGreen(), getRed(), HtmlColor.BLACK); } if (entity.getType() == EntityType.INTERFACE) { - return new CircledCharacter('I', radius, getFont17(), getViolet(), getRed(), Color.BLACK); + return new CircledCharacter('I', radius, getFont17(), getViolet(), getRed(), HtmlColor.BLACK); } if (entity.getType() == EntityType.ENUM) { - return new CircledCharacter('E', radius, getFont17(), getRose(), getRed(), Color.BLACK); + return new CircledCharacter('E', radius, getFont17(), getRose(), getRed(), HtmlColor.BLACK); } assert false; return null; @@ -121,17 +124,17 @@ class EntityImageClass extends AbstractEntityImage { } @Override - public void draw(Graphics2D g2d) { + public void draw(ColorMapper colorMapper, Graphics2D g2d) { final Dimension2D dimTotal = getDimension(StringBounderUtils.asStringBounder(g2d)); final Dimension2D dimName = getNameDimension(StringBounderUtils.asStringBounder(g2d)); final Dimension2D dimFields = fields.calculateDimension(StringBounderUtils.asStringBounder(g2d)); final int width = (int) dimTotal.getWidth(); final int height = (int) dimTotal.getHeight(); - g2d.setColor(getYellow()); + g2d.setColor(colorMapper.getMappedColor(getYellow())); g2d.fillRect(0, 0, width, height); - g2d.setColor(getRed()); + g2d.setColor(colorMapper.getMappedColor(getRed())); g2d.drawRect(0, 0, width - 1, height - 1); final double line1 = dimName.getHeight() + 2 * yMargin; @@ -142,12 +145,12 @@ class EntityImageClass extends AbstractEntityImage { final double circledWidth = getCircledWidth(StringBounderUtils.asStringBounder(g2d)); g2d.setColor(Color.BLACK); - name.drawTOBEREMOVED(g2d, xMargin + circledWidth, yMargin); - fields.drawTOBEREMOVED(g2d, xMargin, line1 + yMargin); - methods.drawTOBEREMOVED(g2d, xMargin, line2 + yMargin); + name.drawTOBEREMOVED(colorMapper, g2d, xMargin + circledWidth, yMargin); + fields.drawTOBEREMOVED(colorMapper, g2d, xMargin, line1 + yMargin); + methods.drawTOBEREMOVED(colorMapper, g2d, xMargin, line2 + yMargin); if (circledCharacter != null) { - circledCharacter.draw(g2d, xMargin, yMargin, 1.0); + circledCharacter.draw(new ColorMapperIdentity(), g2d, xMargin, yMargin, 1.0); } } diff --git a/src/net/sourceforge/plantuml/graph/EntityImageComponent.java b/src/net/sourceforge/plantuml/graph/EntityImageComponent.java index c88faa8c3..778f44347 100644 --- a/src/net/sourceforge/plantuml/graph/EntityImageComponent.java +++ b/src/net/sourceforge/plantuml/graph/EntityImageComponent.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6009 $ + * Revision $Revision: 6923 $ * */ package net.sourceforge.plantuml.graph; @@ -45,10 +45,12 @@ import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.cucadiagram.Entity; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounderUtils; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.ColorMapper; class EntityImageComponent extends AbstractEntityImage { @@ -57,8 +59,8 @@ class EntityImageComponent extends AbstractEntityImage { public EntityImageComponent(Entity entity) { super(entity); - this.name = TextBlockUtils.create(StringUtils.getWithNewlines(entity.getDisplay()), new FontConfiguration( - getFont14(), Color.BLACK), HorizontalAlignement.CENTER); + this.name = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( + getFont14(), HtmlColor.BLACK), HorizontalAlignement.CENTER); } @Override @@ -67,28 +69,28 @@ class EntityImageComponent extends AbstractEntityImage { return Dimension2DDouble.delta(nameDim, 20, 14); } - private void drawRect(Graphics2D g2d, double x, double y, double width, double height) { + private void drawRect(ColorMapper colorMapper, Graphics2D g2d, double x, double y, double width, double height) { g2d.setStroke(new BasicStroke(thickness)); final Shape head = new Rectangle2D.Double(x, y, width, height); - g2d.setColor(getYellow()); + g2d.setColor(colorMapper.getMappedColor(getYellow())); g2d.fill(head); - g2d.setColor(getRed()); + g2d.setColor(colorMapper.getMappedColor(getRed())); g2d.draw(head); g2d.setStroke(new BasicStroke()); } @Override - public void draw(Graphics2D g2d) { + public void draw(ColorMapper colorMapper, Graphics2D g2d) { final Dimension2D dimTotal = getDimension(StringBounderUtils.asStringBounder(g2d)); final Dimension2D nameDim = name.calculateDimension(StringBounderUtils.asStringBounder(g2d)); - drawRect(g2d, 6, 0, dimTotal.getWidth(), dimTotal.getHeight()); - drawRect(g2d, 0, 7, 12, 6); - drawRect(g2d, 0, dimTotal.getHeight() - 7 - 6, 12, 6); + drawRect(colorMapper, g2d, 6, 0, dimTotal.getWidth(), dimTotal.getHeight()); + drawRect(colorMapper, g2d, 0, 7, 12, 6); + drawRect(colorMapper, g2d, 0, dimTotal.getHeight() - 7 - 6, 12, 6); g2d.setColor(Color.BLACK); - name.drawTOBEREMOVED(g2d, 6 + (dimTotal.getWidth() - nameDim.getWidth()) / 2, + name.drawTOBEREMOVED(colorMapper, g2d, 6 + (dimTotal.getWidth() - nameDim.getWidth()) / 2, (dimTotal.getHeight() - nameDim.getHeight()) / 2); } } diff --git a/src/net/sourceforge/plantuml/graph/EntityImageDefault.java b/src/net/sourceforge/plantuml/graph/EntityImageDefault.java index 88f426c45..447f3dfc3 100644 --- a/src/net/sourceforge/plantuml/graph/EntityImageDefault.java +++ b/src/net/sourceforge/plantuml/graph/EntityImageDefault.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6009 $ + * Revision $Revision: 6923 $ * */ package net.sourceforge.plantuml.graph; @@ -42,10 +42,12 @@ import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.cucadiagram.Entity; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounderUtils; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.ColorMapper; class EntityImageDefault extends AbstractEntityImage { @@ -53,8 +55,8 @@ class EntityImageDefault extends AbstractEntityImage { public EntityImageDefault(Entity entity) { super(entity); - this.textBlock = TextBlockUtils.create(Arrays.asList(entity.getDisplay()), new FontConfiguration(getFont14(), - Color.BLACK), HorizontalAlignement.CENTER); + this.textBlock = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration(getFont14(), + HtmlColor.BLACK), HorizontalAlignement.CENTER); } @Override @@ -64,12 +66,12 @@ class EntityImageDefault extends AbstractEntityImage { } @Override - public void draw(Graphics2D g2d) { + public void draw(ColorMapper colorMapper, Graphics2D g2d) { final Dimension2D dim = textBlock.calculateDimension(StringBounderUtils.asStringBounder(g2d)); final int width = (int) dim.getWidth(); final int height = (int) dim.getHeight(); g2d.setColor(Color.BLACK); g2d.drawRect(0, 0, width, height); - textBlock.drawTOBEREMOVED(g2d, 0, 0); + textBlock.drawTOBEREMOVED(colorMapper, g2d, 0, 0); } } diff --git a/src/net/sourceforge/plantuml/graph/EntityImageNote.java b/src/net/sourceforge/plantuml/graph/EntityImageNote.java index faffe8bd7..211e36f54 100644 --- a/src/net/sourceforge/plantuml/graph/EntityImageNote.java +++ b/src/net/sourceforge/plantuml/graph/EntityImageNote.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6009 $ + * Revision $Revision: 6923 $ * */ package net.sourceforge.plantuml.graph; @@ -43,10 +43,12 @@ import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.cucadiagram.Entity; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounderUtils; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.ColorMapper; class EntityImageNote extends AbstractEntityImage { @@ -57,8 +59,8 @@ class EntityImageNote extends AbstractEntityImage { public EntityImageNote(Entity entity) { super(entity); - this.text = TextBlockUtils.create(StringUtils.getWithNewlines(entity.getDisplay()), new FontConfiguration( - getFont14(), Color.BLACK), HorizontalAlignement.CENTER); + this.text = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( + getFont14(), HtmlColor.BLACK), HorizontalAlignement.CENTER); } @Override @@ -68,7 +70,7 @@ class EntityImageNote extends AbstractEntityImage { } @Override - public void draw(Graphics2D g2d) { + public void draw(ColorMapper colorMapper, Graphics2D g2d) { final Dimension2D dimTotal = getDimension(StringBounderUtils.asStringBounder(g2d)); final int width = (int) dimTotal.getWidth(); @@ -81,16 +83,16 @@ class EntityImageNote extends AbstractEntityImage { p.addPoint(width, height); p.addPoint(0, height); - g2d.setColor(getYellowNote()); + g2d.setColor(colorMapper.getMappedColor(getYellowNote())); g2d.fill(p); - g2d.setColor(getRed()); + g2d.setColor(colorMapper.getMappedColor(getRed())); g2d.draw(p); g2d.drawLine(width - xMargin, 0, width - xMargin, yMargin); g2d.drawLine(width - xMargin, yMargin, width, yMargin); g2d.setColor(Color.BLACK); - text.drawTOBEREMOVED(g2d, xMargin, yMargin); + text.drawTOBEREMOVED(colorMapper, g2d, xMargin, yMargin); } } diff --git a/src/net/sourceforge/plantuml/graph/EntityImageUsecase.java b/src/net/sourceforge/plantuml/graph/EntityImageUsecase.java index bc8721496..94b8efd16 100644 --- a/src/net/sourceforge/plantuml/graph/EntityImageUsecase.java +++ b/src/net/sourceforge/plantuml/graph/EntityImageUsecase.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6009 $ + * Revision $Revision: 6923 $ * */ package net.sourceforge.plantuml.graph; @@ -46,10 +46,12 @@ import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.cucadiagram.Entity; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounderUtils; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.ColorMapper; class EntityImageUsecase extends AbstractEntityImage { @@ -57,8 +59,8 @@ class EntityImageUsecase extends AbstractEntityImage { public EntityImageUsecase(Entity entity) { super(entity); - this.name = TextBlockUtils.create(StringUtils.getWithNewlines(entity.getDisplay()), new FontConfiguration( - getFont14(), Color.BLACK), HorizontalAlignement.CENTER); + this.name = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( + getFont14(), HtmlColor.BLACK), HorizontalAlignement.CENTER); } @Override @@ -75,7 +77,7 @@ class EntityImageUsecase extends AbstractEntityImage { } @Override - public void draw(Graphics2D g2d) { + public void draw(ColorMapper colorMapper, Graphics2D g2d) { final Dimension2D dimTotal = getDimension(StringBounderUtils.asStringBounder(g2d)); // Shape ellipse = new Ellipse2D.Double(0, 0, dimTotal.getWidth(), @@ -87,10 +89,10 @@ class EntityImageUsecase extends AbstractEntityImage { ellipse.append(new QuadCurve2D.Double(w / 2, 0, w, 0, w, h / 2), true); ellipse.append(new QuadCurve2D.Double(w, h / 2, w, h, w / 2, h), true); ellipse.append(new QuadCurve2D.Double(w / 2, h, 0, h, 0, h / 2), true); - g2d.setColor(getYellow()); + g2d.setColor(colorMapper.getMappedColor(getYellow())); g2d.fill(ellipse); - g2d.setColor(getRed()); + g2d.setColor(colorMapper.getMappedColor(getRed())); g2d.draw(ellipse); final Dimension2D nameDim = name.calculateDimension(StringBounderUtils.asStringBounder(g2d)); @@ -100,6 +102,6 @@ class EntityImageUsecase extends AbstractEntityImage { // g2d.draw(rect); g2d.setColor(Color.BLACK); - name.drawTOBEREMOVED(g2d, posx, posy); + name.drawTOBEREMOVED(colorMapper, g2d, posx, posy); } } diff --git a/src/net/sourceforge/plantuml/graph/Graph3.java b/src/net/sourceforge/plantuml/graph/Graph3.java index 908bbab6f..891a4f357 100644 --- a/src/net/sourceforge/plantuml/graph/Graph3.java +++ b/src/net/sourceforge/plantuml/graph/Graph3.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 6577 $ * */ package net.sourceforge.plantuml.graph; @@ -63,6 +63,7 @@ import net.sourceforge.plantuml.geom.kinetic.Path; import net.sourceforge.plantuml.geom.kinetic.Point2DCharge; import net.sourceforge.plantuml.geom.kinetic.World; import net.sourceforge.plantuml.graphic.StringBounderUtils; +import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity; public class Graph3 { @@ -436,7 +437,7 @@ public class Graph3 { final double width = image.getDimension(StringBounderUtils.asStringBounder(g2d)).getWidth(); final double height = image.getDimension(StringBounderUtils.asStringBounder(g2d)).getHeight(); g2d.translate(frame.getX() - width / 2, frame.getY() - height / 2); - image.draw(g2d); + image.draw(new ColorMapperIdentity(), g2d); g2d.translate(-frame.getX() + width / 2, -frame.getY() + height / 2); } @@ -466,7 +467,7 @@ public class Graph3 { final int width = (int) (image.getDimension(StringBounderUtils.asStringBounder(g2d)).getWidth()); final int height = (int) (image.getDimension(StringBounderUtils.asStringBounder(g2d)).getHeight()); g2d.translate(p.getXint() - width / 2, p.getYint() - height / 2); - image.draw(g2d); + image.draw(new ColorMapperIdentity(), g2d); g2d.translate(-p.getXint() + width / 2, -p.getYint() + height / 2); // g2d.fillOval(p.getXint() - 2, p.getYint() - 2, 5, 5); // g2d.drawRect(p.getXint() - 4, p.getYint() - 4, 8, 8); diff --git a/src/net/sourceforge/plantuml/graph/Graph4.java b/src/net/sourceforge/plantuml/graph/Graph4.java index 3ce2d2bd5..a9bc6b7d4 100644 --- a/src/net/sourceforge/plantuml/graph/Graph4.java +++ b/src/net/sourceforge/plantuml/graph/Graph4.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 6577 $ * */ package net.sourceforge.plantuml.graph; @@ -58,6 +58,7 @@ import net.sourceforge.plantuml.graph2.CubicCurveFactory; import net.sourceforge.plantuml.graph2.MyCurve; import net.sourceforge.plantuml.graph2.RectanglesCollection; import net.sourceforge.plantuml.graphic.StringBounderUtils; +import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity; public class Graph4 { @@ -197,7 +198,7 @@ public class Graph4 { final Frame frame = frames.get(nodePoint); final AbstractEntityImage image = getImage(nodePoint.getNode()); g2d.translate(frame.getX(), frame.getY()); - image.draw(g2d); + image.draw(new ColorMapperIdentity(), g2d); g2d.translate(-frame.getX(), -frame.getY()); } diff --git a/src/net/sourceforge/plantuml/graph/Graph5.java b/src/net/sourceforge/plantuml/graph/Graph5.java index ddc4a7eeb..edfab375b 100644 --- a/src/net/sourceforge/plantuml/graph/Graph5.java +++ b/src/net/sourceforge/plantuml/graph/Graph5.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 6577 $ * */ package net.sourceforge.plantuml.graph; @@ -53,6 +53,7 @@ import net.sourceforge.plantuml.graph2.InflationTransform2; import net.sourceforge.plantuml.graph2.Plan; import net.sourceforge.plantuml.graph2.Polyline2; import net.sourceforge.plantuml.graphic.StringBounderUtils; +import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity; public class Graph5 { @@ -138,7 +139,7 @@ public class Graph5 { final double x = pos.getX() - image.getDimension(StringBounderUtils.asStringBounder(g2d)).getWidth() / 2; final double y = pos.getY() - image.getDimension(StringBounderUtils.asStringBounder(g2d)).getHeight() / 2; g2d.translate(x, y); - image.draw(g2d); + image.draw(new ColorMapperIdentity(), g2d); g2d.translate(-x, -y); } diff --git a/src/net/sourceforge/plantuml/graph/MethodsOrFieldsArea.java b/src/net/sourceforge/plantuml/graph/MethodsOrFieldsArea.java index 4c7151c7c..787f4f338 100644 --- a/src/net/sourceforge/plantuml/graph/MethodsOrFieldsArea.java +++ b/src/net/sourceforge/plantuml/graph/MethodsOrFieldsArea.java @@ -28,13 +28,11 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6009 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.graph; -import java.awt.Color; -import java.awt.Font; import java.awt.Graphics2D; import java.awt.geom.Dimension2D; import java.util.ArrayList; @@ -45,19 +43,22 @@ import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.cucadiagram.Member; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounderUtils; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; import net.sourceforge.plantuml.skin.VisibilityModifier; +import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; public class MethodsOrFieldsArea { - private final Font font; + private final UFont font; private final List strings = new ArrayList(); - public MethodsOrFieldsArea(List attributes, Font font) { + public MethodsOrFieldsArea(List attributes, UFont font) { this.font = font; for (Member att : attributes) { this.strings.add(att.getDisplayWithoutVisibilityChar()); @@ -81,14 +82,14 @@ public class MethodsOrFieldsArea { } private TextBlock createTextBlock(String s) { - return TextBlockUtils.create(Arrays.asList(s), new FontConfiguration(font, Color.BLACK), + return TextBlockUtils.create(Arrays.asList(s), new FontConfiguration(font, HtmlColor.BLACK), HorizontalAlignement.LEFT); } - public void drawTOBEREMOVED(Graphics2D g2d, double x, double y) { + public void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { for (String s : strings) { final TextBlock bloc = createTextBlock(s); - bloc.drawTOBEREMOVED(g2d, x, y); + bloc.drawTOBEREMOVED(colorMapper, g2d, x, y); y += bloc.calculateDimension(StringBounderUtils.asStringBounder(g2d)).getHeight(); } } diff --git a/src/net/sourceforge/plantuml/graph/MethodsOrFieldsArea2.java b/src/net/sourceforge/plantuml/graph/MethodsOrFieldsArea2.java index 331328beb..1e14f3013 100644 --- a/src/net/sourceforge/plantuml/graph/MethodsOrFieldsArea2.java +++ b/src/net/sourceforge/plantuml/graph/MethodsOrFieldsArea2.java @@ -33,8 +33,6 @@ */ package net.sourceforge.plantuml.graph; -import java.awt.Color; -import java.awt.Font; import java.awt.Graphics2D; import java.awt.geom.Dimension2D; import java.util.ArrayList; @@ -47,22 +45,25 @@ import net.sourceforge.plantuml.ISkinParam; import net.sourceforge.plantuml.cucadiagram.Member; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +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.skin.VisibilityModifier; import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.PlacementStrategyVisibility; import net.sourceforge.plantuml.ugraphic.PlacementStrategyY1Y2Left; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UGroup; public class MethodsOrFieldsArea2 { - private final Font font; + private final UFont font; private final List members = new ArrayList(); private final ISkinParam skinParam; - private final Color color; + private final HtmlColor color; private final Rose rose = new Rose(); public MethodsOrFieldsArea2(List attributes, FontParam fontParam, ISkinParam skinParam) { @@ -138,7 +139,7 @@ public class MethodsOrFieldsArea2 { public void drawU(UGraphic ug, double x, double y) { } - public void drawTOBEREMOVED(Graphics2D g2d, double x, double y) { + public void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { throw new UnsupportedOperationException(); } @@ -147,9 +148,9 @@ public class MethodsOrFieldsArea2 { } }; } - final Color back = modifier.getBackground() == null ? null : rose.getHtmlColor(skinParam, - modifier.getBackground()).getColor(); - final Color fore = rose.getHtmlColor(skinParam, modifier.getForeground()).getColor(); + final HtmlColor back = modifier.getBackground() == null ? null : rose.getHtmlColor(skinParam, + modifier.getBackground()); + final HtmlColor fore = rose.getHtmlColor(skinParam, modifier.getForeground()); final TextBlock uBlock = modifier.getUBlock(skinParam.getCircledCharacterRadius(), fore, back); return uBlock; diff --git a/src/net/sourceforge/plantuml/graphic/AddStyle.java b/src/net/sourceforge/plantuml/graphic/AddStyle.java index 89281c569..35e248479 100644 --- a/src/net/sourceforge/plantuml/graphic/AddStyle.java +++ b/src/net/sourceforge/plantuml/graphic/AddStyle.java @@ -28,19 +28,18 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5506 $ + * Revision $Revision: 6570 $ * */ package net.sourceforge.plantuml.graphic; -import java.awt.Color; class AddStyle implements FontChange { private final FontStyle style; - private final Color extendedColor; + private final HtmlColor extendedColor; - AddStyle(FontStyle style, Color extendedColor) { + AddStyle(FontStyle style, HtmlColor extendedColor) { this.style = style; this.extendedColor = extendedColor; } diff --git a/src/net/sourceforge/plantuml/graphic/CircledCharacter.java b/src/net/sourceforge/plantuml/graphic/CircledCharacter.java index 1ddff1409..989bea296 100644 --- a/src/net/sourceforge/plantuml/graphic/CircledCharacter.java +++ b/src/net/sourceforge/plantuml/graphic/CircledCharacter.java @@ -28,13 +28,11 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5804 $ + * Revision $Revision: 6780 $ * */ package net.sourceforge.plantuml.graphic; -import java.awt.Color; -import java.awt.Font; import java.awt.Graphics2D; import java.awt.Shape; import java.awt.font.FontRenderContext; @@ -54,7 +52,9 @@ import net.sourceforge.plantuml.FileUtils; import net.sourceforge.plantuml.cucadiagram.dot.DrawFile; import net.sourceforge.plantuml.cucadiagram.dot.Lazy; import net.sourceforge.plantuml.skin.UDrawable; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UEllipse; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UPath; import net.sourceforge.plantuml.ugraphic.USegmentType; @@ -64,13 +64,14 @@ import net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d; public class CircledCharacter implements UDrawable, TextBlock { private final String c; - private final Font font; - private final Color innerCircle; - private final Color circle; - private final Color fontColor; + private final UFont font; + private final HtmlColor innerCircle; + private final HtmlColor circle; + private final HtmlColor fontColor; private final double radius; - public CircledCharacter(char c, double radius, Font font, Color innerCircle, Color circle, Color fontColor) { + public CircledCharacter(char c, double radius, UFont font, HtmlColor innerCircle, HtmlColor circle, + HtmlColor fontColor) { this.c = "" + c; this.radius = radius; this.font = font; @@ -79,8 +80,8 @@ public class CircledCharacter implements UDrawable, TextBlock { this.fontColor = fontColor; } - public void draw(Graphics2D g2d, int x, int y, double dpiFactor) { - drawU(new UGraphicG2d(g2d, null, 1.0), x, y); + public void draw(ColorMapper colorMapper, Graphics2D g2d, int x, int y, double dpiFactor) { + drawU(new UGraphicG2d(colorMapper, g2d, null, 1.0), x, y); } public void drawU(UGraphic ug, double x, double y) { @@ -88,12 +89,11 @@ public class CircledCharacter implements UDrawable, TextBlock { if (circle != null) { ug.getParam().setColor(circle); } - ug.getParam().setBackcolor(innerCircle); - ug.draw(x, y, new UEllipse(radius * 2, radius * 2)); ug.getParam().setColor(fontColor); ug.centerChar(x + radius, y + radius, c.charAt(0), font); + ug.getParam().setBackcolor(null); } @@ -110,7 +110,7 @@ public class CircledCharacter implements UDrawable, TextBlock { } private PathIterator getPathIteratorCharacter(FontRenderContext frc) { - final TextLayout textLayout = new TextLayout(c, font, frc); + final TextLayout textLayout = new TextLayout(c, font.getFont(), frc); final Shape s = textLayout.getOutline(null); return s.getPathIterator(null); } @@ -134,22 +134,24 @@ public class CircledCharacter implements UDrawable, TextBlock { return new Dimension2DDouble(getPreferredWidth(stringBounder), getPreferredHeight(stringBounder)); } - public void drawTOBEREMOVED(Graphics2D g2d, double x, double y) { + public void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { throw new UnsupportedOperationException(); } - public DrawFile generateCircleCharacter(final Color background, final double dpiFactor) throws IOException { + public DrawFile generateCircleCharacter(final ColorMapper colorMapper, final HtmlColor background, + final double dpiFactor) throws IOException { final Lazy lpng = new Lazy() { public File getNow() throws IOException { final File png = FileUtils.createTempFile("circle", ".png"); - final EmptyImageBuilder builder = new EmptyImageBuilder((int)(60 * dpiFactor), (int)(60 * dpiFactor), background, dpiFactor); + final EmptyImageBuilder builder = new EmptyImageBuilder((int) (60 * dpiFactor), (int) (60 * dpiFactor), + colorMapper.getMappedColor(background), dpiFactor); BufferedImage im = builder.getBufferedImage(); final Graphics2D g2d = builder.getGraphics2D(); final StringBounder stringBounder = StringBounderUtils.asStringBounder(g2d); - draw(g2d, 0, 0, dpiFactor); + draw(colorMapper, g2d, 0, 0, dpiFactor); im = im.getSubimage(0, 0, (int) (getPreferredWidth(stringBounder) * dpiFactor) + 5, (int) (getPreferredHeight(stringBounder) * dpiFactor) + 1); @@ -161,14 +163,14 @@ public class CircledCharacter implements UDrawable, TextBlock { final Lazy leps = new Lazy() { public File getNow() throws IOException { final File epsFile = FileUtils.createTempFile("circle", ".eps"); - UGraphicEps.copyEpsToFile(CircledCharacter.this, epsFile); + UGraphicEps.copyEpsToFile(colorMapper, CircledCharacter.this, epsFile); return epsFile; } }; final Lazy lsvg = new Lazy() { public String getNow() throws IOException { - return UGraphicG2d.getSvgString(CircledCharacter.this); + return UGraphicG2d.getSvgString(colorMapper, CircledCharacter.this); } }; diff --git a/src/net/sourceforge/plantuml/graphic/EmbededSystemLine.java b/src/net/sourceforge/plantuml/graphic/EmbededSystemLine.java index 4e4599a78..b998694dd 100644 --- a/src/net/sourceforge/plantuml/graphic/EmbededSystemLine.java +++ b/src/net/sourceforge/plantuml/graphic/EmbededSystemLine.java @@ -49,6 +49,7 @@ import net.sourceforge.plantuml.EmbededDiagram; import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.FileFormatOption; import net.sourceforge.plantuml.PSystem; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UImage; import net.sourceforge.plantuml.ugraphic.UShape; @@ -73,7 +74,7 @@ class EmbededSystemLine implements Line { return new Dimension2DDouble(42, 42); } - public void draw(Graphics2D g2d, double x, double y) { + public void draw(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { throw new UnsupportedOperationException(); } diff --git a/src/net/sourceforge/plantuml/graphic/FontConfiguration.java b/src/net/sourceforge/plantuml/graphic/FontConfiguration.java index a9f97962f..21b7233d2 100644 --- a/src/net/sourceforge/plantuml/graphic/FontConfiguration.java +++ b/src/net/sourceforge/plantuml/graphic/FontConfiguration.java @@ -28,35 +28,50 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5506 $ + * Revision $Revision: 6837 $ * */ package net.sourceforge.plantuml.graphic; -import java.awt.Color; -import java.awt.Font; import java.util.EnumSet; +import net.sourceforge.plantuml.ugraphic.UFont; + public class FontConfiguration { private final EnumSet styles; - private final Font currentFont; - private final Font motherFont; - private final Color motherColor; - private final Color currentColor; - private final Color extendedColor; + private final UFont currentFont; + private final UFont motherFont; + private final HtmlColor motherColor; + private final HtmlColor currentColor; + private final HtmlColor extendedColor; - public FontConfiguration(Font font, Color color) { - this(EnumSet.noneOf(FontStyle.class), font, color, font, color, null); + public FontConfiguration(UFont font, HtmlColor color) { + this(getStyles(font), font, color, font, color, null); } - + + private static EnumSet getStyles(UFont font) { + final boolean bold = font.isBold(); + final boolean italic = font.isItalic(); + if (bold && italic) { + return EnumSet.of(FontStyle.ITALIC, FontStyle.BOLD); + } + if (bold) { + return EnumSet.of(FontStyle.BOLD); + } + if (italic) { + return EnumSet.of(FontStyle.ITALIC); + } + return EnumSet.noneOf(FontStyle.class); + } + @Override public String toString() { - return styles.toString()+" "+currentColor; + return styles.toString() + " " + currentColor; } - private FontConfiguration(EnumSet styles, Font motherFont, Color motherColor, Font currentFont, - Color currentColor, Color extendedColor) { + private FontConfiguration(EnumSet styles, UFont motherFont, HtmlColor motherColor, UFont currentFont, + HtmlColor currentColor, HtmlColor extendedColor) { this.styles = styles; this.currentFont = currentFont; this.motherFont = motherFont; @@ -66,15 +81,16 @@ public class FontConfiguration { } FontConfiguration changeColor(HtmlColor htmlColor) { - return new FontConfiguration(styles, motherFont, motherColor, currentFont, htmlColor.getColor(), extendedColor); + return new FontConfiguration(styles, motherFont, motherColor, currentFont, htmlColor, extendedColor); } - FontConfiguration changeExtendedColor(Color newExtendedColor) { + FontConfiguration changeExtendedColor(HtmlColor newExtendedColor) { return new FontConfiguration(styles, motherFont, motherColor, currentFont, currentColor, newExtendedColor); } FontConfiguration changeSize(float size) { - return new FontConfiguration(styles, motherFont, motherColor, currentFont.deriveFont(size), currentColor, extendedColor); + return new FontConfiguration(styles, motherFont, motherColor, currentFont.deriveSize(size), currentColor, + extendedColor); } public FontConfiguration resetFont() { @@ -87,25 +103,29 @@ public class FontConfiguration { return new FontConfiguration(r, motherFont, motherColor, currentFont, currentColor, extendedColor); } + public FontConfiguration italic() { + return add(FontStyle.ITALIC); + } + FontConfiguration remove(FontStyle style) { final EnumSet r = styles.clone(); r.remove(style); return new FontConfiguration(r, motherFont, motherColor, currentFont, currentColor, extendedColor); } - public Font getFont() { - Font result = currentFont; + public UFont getFont() { + UFont result = currentFont; for (FontStyle style : styles) { result = style.mutateFont(result); } return result; } - public Color getColor() { + public HtmlColor getColor() { return currentColor; } - - public Color getExtendedColor() { + + public HtmlColor getExtendedColor() { return extendedColor; } diff --git a/src/net/sourceforge/plantuml/graphic/FontStyle.java b/src/net/sourceforge/plantuml/graphic/FontStyle.java index 1c3d59068..397cc62c0 100644 --- a/src/net/sourceforge/plantuml/graphic/FontStyle.java +++ b/src/net/sourceforge/plantuml/graphic/FontStyle.java @@ -28,26 +28,27 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6000 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.graphic; -import java.awt.Color; import java.awt.Font; import java.util.EnumSet; import java.util.regex.Matcher; import java.util.regex.Pattern; +import net.sourceforge.plantuml.ugraphic.UFont; + public enum FontStyle { PLAIN, ITALIC, BOLD, UNDERLINE, STRIKE, WAVE, BACKCOLOR; - public Font mutateFont(Font font) { + public UFont mutateFont(UFont font) { if (this == ITALIC) { - return font.deriveFont(font.getStyle() | Font.ITALIC); + return font.deriveStyle(font.getStyle() | Font.ITALIC); } if (this == BOLD) { - return font.deriveFont(font.getStyle() | Font.BOLD); + return font.deriveStyle(font.getStyle() | Font.BOLD); } return font; } @@ -74,14 +75,14 @@ public enum FontStyle { return null; } - Color getExtendedColor(String s) { + HtmlColor getExtendedColor(String s) { final Matcher m = Pattern.compile(getActivationPattern()).matcher(s); if (m.find() == false || m.groupCount() != 1) { return null; } final String color = m.group(1); if (color!= null && HtmlColor.isValid(color)) { - return HtmlColor.getColorIfValid(color).getColor(); + return HtmlColor.getColorIfValid(color); } return null; } diff --git a/src/net/sourceforge/plantuml/graphic/GraphicStrings.java b/src/net/sourceforge/plantuml/graphic/GraphicStrings.java index 523a0f5b7..c6b983607 100644 --- a/src/net/sourceforge/plantuml/graphic/GraphicStrings.java +++ b/src/net/sourceforge/plantuml/graphic/GraphicStrings.java @@ -28,12 +28,11 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6009 $ + * Revision $Revision: 6937 $ * */ package net.sourceforge.plantuml.graphic; -import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.RenderingHints; @@ -48,20 +47,29 @@ import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.EmptyImageBuilder; import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.directdot.DotText; +import net.sourceforge.plantuml.eps.EpsStrategy; import net.sourceforge.plantuml.png.PngIO; +import net.sourceforge.plantuml.svek.IEntityImage; +import net.sourceforge.plantuml.svek.ShapeType; +import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UImage; +import net.sourceforge.plantuml.ugraphic.eps.UGraphicEps; import net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d; import net.sourceforge.plantuml.ugraphic.svg.UGraphicSvg; import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt; -public class GraphicStrings { +public class GraphicStrings implements IEntityImage { - private final Color background; + private final HtmlColor background; - private final Font font; + private final UFont font; - private final Color green; + private final HtmlColor green; private final List strings; @@ -71,21 +79,24 @@ public class GraphicStrings { private final boolean disableTextAliasing; + private final ColorMapper colorMapper = new ColorMapperIdentity(); + public GraphicStrings(List strings) { - this(strings, new Font("SansSerif", Font.BOLD, 14), new Color(Integer.parseInt("33FF02", 16)), Color.BLACK, + this(strings, new UFont("SansSerif", Font.BOLD, 14), HtmlColor.getColorIfValid("#33FF02"), HtmlColor.BLACK, null, null, false); } public GraphicStrings(List strings, BufferedImage image) { - this(strings, new Font("SansSerif", Font.BOLD, 14), new Color(Integer.parseInt("33FF02", 16)), Color.BLACK, + this(strings, new UFont("SansSerif", Font.BOLD, 14), HtmlColor.getColorIfValid("#33FF02"), HtmlColor.BLACK, image, null, false); } - public GraphicStrings(List strings, Font font, Color green, Color background, boolean disableTextAliasing) { + public GraphicStrings(List strings, UFont font, HtmlColor green, HtmlColor background, + boolean disableTextAliasing) { this(strings, font, green, background, null, null, disableTextAliasing); } - public GraphicStrings(List strings, Font font, Color green, Color background, BufferedImage image, + public GraphicStrings(List strings, UFont font, HtmlColor green, HtmlColor background, BufferedImage image, GraphicPosition position, boolean disableTextAliasing) { this.strings = strings; this.font = font; @@ -105,34 +116,44 @@ public class GraphicStrings { if (fileFormat == FileFormat.PNG) { final BufferedImage im = createImage(); PngIO.write(im, os, metadata, 96); - } else if (fileFormat == FileFormat.SVG || fileFormat == FileFormat.EPS_VIA_SVG) { - final UGraphicSvg svg = new UGraphicSvg(HtmlColor.getAsHtml(background), false); + } else if (fileFormat == FileFormat.SVG) { + final UGraphicSvg svg = new UGraphicSvg(colorMapper, StringUtils.getAsHtml(colorMapper + .getMappedColor(background)), false); drawU(svg); svg.createXml(os); } else if (fileFormat == FileFormat.ATXT || fileFormat == FileFormat.UTXT) { final UGraphicTxt txt = new UGraphicTxt(); drawU(txt); txt.getCharArea().print(new PrintStream(os)); + } else if (fileFormat == FileFormat.EPS) { + final UGraphicEps ug = new UGraphicEps(colorMapper, EpsStrategy.getDefault2()); + drawU(ug); + os.write(ug.getEPSCode().getBytes()); + } else if (fileFormat == FileFormat.DOT) { + final DotText dotText = new DotText(strings, HtmlColor.getColorIfValid("#33FF02"), HtmlColor.BLACK); + final StringBuilder sb = new StringBuilder(); + dotText.generateDot(sb); + os.write(sb.toString().getBytes()); } else { throw new UnsupportedOperationException(); } } private BufferedImage createImage() { - EmptyImageBuilder builder = new EmptyImageBuilder(10, 10, background); + EmptyImageBuilder builder = new EmptyImageBuilder(10, 10, colorMapper.getMappedColor(background)); // BufferedImage im = builder.getBufferedImage(); Graphics2D g2d = builder.getGraphics2D(); - final Dimension2D size = drawU(new UGraphicG2d(g2d, null, 1.0)); + final Dimension2D size = drawU(new UGraphicG2d(colorMapper, g2d, null, 1.0)); g2d.dispose(); - builder = new EmptyImageBuilder(size.getWidth(), size.getHeight(), background); + builder = new EmptyImageBuilder(size.getWidth(), size.getHeight(), colorMapper.getMappedColor(background)); final BufferedImage im = builder.getBufferedImage(); g2d = builder.getGraphics2D(); if (disableTextAliasing) { g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } - drawU(new UGraphicG2d(g2d, null, 1.0)); + drawU(new UGraphicG2d(colorMapper, g2d, null, 1.0)); g2d.dispose(); return im; } @@ -154,4 +175,22 @@ public class GraphicStrings { return size; } + public void drawU(UGraphic ug, double theoricalPosition, double theoricalPosition2) { + drawU(ug); + } + + public Dimension2D getDimension(StringBounder stringBounder) { + final TextBlock textBlock = TextBlockUtils.create(strings, new FontConfiguration(font, green), + HorizontalAlignement.LEFT); + return textBlock.calculateDimension(stringBounder); + } + + public ShapeType getShapeType() { + return ShapeType.RECTANGLE; + } + + public HtmlColor getBackcolor() { + return background; + } + } diff --git a/src/net/sourceforge/plantuml/graphic/HorizontalAlignement.java b/src/net/sourceforge/plantuml/graphic/HorizontalAlignement.java index 1012b815e..3715c4d28 100644 --- a/src/net/sourceforge/plantuml/graphic/HorizontalAlignement.java +++ b/src/net/sourceforge/plantuml/graphic/HorizontalAlignement.java @@ -28,13 +28,26 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3834 $ + * Revision $Revision: 6557 $ * */ package net.sourceforge.plantuml.graphic; public enum HorizontalAlignement { - LEFT, CENTER, RIGHT + LEFT, CENTER, RIGHT; + + public static HorizontalAlignement fromString(String s) { + if (LEFT.name().equalsIgnoreCase(s)) { + return LEFT; + } + if (CENTER.name().equalsIgnoreCase(s)) { + return CENTER; + } + if (RIGHT.name().equalsIgnoreCase(s)) { + return RIGHT; + } + return null; + } } \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/HtmlColor.java b/src/net/sourceforge/plantuml/graphic/HtmlColor.java index e72f67ce8..2d01f97bf 100644 --- a/src/net/sourceforge/plantuml/graphic/HtmlColor.java +++ b/src/net/sourceforge/plantuml/graphic/HtmlColor.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5983 $ + * Revision $Revision: 6577 $ * */ package net.sourceforge.plantuml.graphic; @@ -41,6 +41,7 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; +import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.ugraphic.ColorChangerMonochrome; public class HtmlColor { @@ -207,6 +208,15 @@ public class HtmlColor { } private final Color color; + private final boolean monochrome; + + public static final HtmlColor BLACK = HtmlColor.getColorIfValid("black"); + public static final HtmlColor WHITE = HtmlColor.getColorIfValid("white"); + public static final HtmlColor RED = HtmlColor.getColorIfValid("#FF0000"); + public static final HtmlColor GREEN = HtmlColor.getColorIfValid("#00FF00"); + public static final HtmlColor BLUE = HtmlColor.getColorIfValid("#0000FF"); + public static final HtmlColor GRAY = HtmlColor.getColorIfValid("#808080"); + public static final HtmlColor LIGHT_GRAY = HtmlColor.getColorIfValid("#C0C0C0"); private HtmlColor(String s) { if (s.matches("#[0-9A-Fa-f]{6}")) { @@ -219,12 +229,14 @@ public class HtmlColor { } color = new Color(Integer.parseInt(value.substring(1), 16)); } + monochrome = false; assert isValid(s); } -// private HtmlColor(Color c) { -// this.color = c; -// } + private HtmlColor(Color c, boolean monochrome) { + this.color = c; + this.monochrome = monochrome; + } static public boolean isValid(String s) { if (s.matches("#[0-9A-Fa-f]{6}")) { @@ -245,16 +257,6 @@ public class HtmlColor { return new HtmlColor(s); } - public static String getAsHtml(Color color) { - if (color == null) { - throw new IllegalArgumentException(); - } - final int v = 0xFFFFFF & color.getRGB(); - String s = "000000" + Integer.toHexString(v).toUpperCase(); - s = s.substring(s.length() - 6); - return "#" + s; - } - static private String removeFirstDieseAndToLowercase(String s) { s = s.toLowerCase(); if (s.startsWith("#")) { @@ -263,32 +265,17 @@ public class HtmlColor { return s; } - public String getAsHtml() { - return getAsHtml(getColor()); - } - - public Color getColor() { - if (forceMonochrome) { - return new ColorChangerMonochrome().getChangedColor(color); - } + public Color getColor999() { return color; } - @Override - public String toString() { - return super.toString() + " " + getAsHtml(); + public HtmlColor asMonochrome() { + if (monochrome) { + throw new IllegalStateException(); + } + return new HtmlColor(new ColorChangerMonochrome().getChangedColor(color), true); } - private static boolean forceMonochrome = false; - - public static final boolean isForceMonochrome() { - return forceMonochrome; - } - - public static final void setForceMonochrome(boolean forceMonochrome) { - HtmlColor.forceMonochrome = forceMonochrome; - } - public static Collection names() { return Collections.unmodifiableSet(names); } diff --git a/src/net/sourceforge/plantuml/graphic/Line.java b/src/net/sourceforge/plantuml/graphic/Line.java index cc3e44bb5..fdb3d6693 100644 --- a/src/net/sourceforge/plantuml/graphic/Line.java +++ b/src/net/sourceforge/plantuml/graphic/Line.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3834 $ + * Revision $Revision: 6577 $ * */ package net.sourceforge.plantuml.graphic; @@ -36,13 +36,14 @@ package net.sourceforge.plantuml.graphic; import java.awt.Graphics2D; import java.awt.geom.Dimension2D; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UGraphic; interface Line { Dimension2D calculateDimension(StringBounder stringBounder); - void draw(Graphics2D g2d, double x, double y); + void draw(ColorMapper colorMapper, Graphics2D g2d, double x, double y); void drawU(UGraphic ug, double x, double y); diff --git a/src/net/sourceforge/plantuml/graphic/SingleLine.java b/src/net/sourceforge/plantuml/graphic/SingleLine.java index f71ce0dc2..80ac7bb0b 100644 --- a/src/net/sourceforge/plantuml/graphic/SingleLine.java +++ b/src/net/sourceforge/plantuml/graphic/SingleLine.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6353 $ + * Revision $Revision: 6577 $ * */ package net.sourceforge.plantuml.graphic; @@ -39,6 +39,7 @@ import java.util.ArrayList; import java.util.List; import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UGraphic; class SingleLine implements Line { @@ -104,13 +105,13 @@ class SingleLine implements Line { return result; } - public void draw(Graphics2D g2d, double x, double y) { + public void draw(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { final double deltaY = maxDeltaY(g2d); for (Tile b : blocs) { if (b instanceof TileImage) { - b.draw(g2d, x, y); + b.draw(colorMapper, g2d, x, y); } else { - b.draw(g2d, x, y + deltaY); + b.draw(colorMapper, g2d, x, y + deltaY); } x += b.calculateDimension(StringBounderUtils.asStringBounder(g2d)).getWidth(); } diff --git a/src/net/sourceforge/plantuml/graphic/StringBounder.java b/src/net/sourceforge/plantuml/graphic/StringBounder.java index 38eb39f70..3b9cbc64c 100644 --- a/src/net/sourceforge/plantuml/graphic/StringBounder.java +++ b/src/net/sourceforge/plantuml/graphic/StringBounder.java @@ -28,16 +28,17 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4987 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.graphic; -import java.awt.Font; import java.awt.geom.Dimension2D; +import net.sourceforge.plantuml.ugraphic.UFont; + public interface StringBounder { - public Dimension2D calculateDimension(Font font, String text); + public Dimension2D calculateDimension(UFont font, String text); } diff --git a/src/net/sourceforge/plantuml/graphic/StringBounderUtils.java b/src/net/sourceforge/plantuml/graphic/StringBounderUtils.java index bfdb4d4d8..126e86e03 100644 --- a/src/net/sourceforge/plantuml/graphic/StringBounderUtils.java +++ b/src/net/sourceforge/plantuml/graphic/StringBounderUtils.java @@ -28,39 +28,39 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4110 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.graphic; -import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics2D; import java.awt.geom.Dimension2D; import java.awt.geom.Rectangle2D; import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ugraphic.UFont; public class StringBounderUtils { public static StringBounder asStringBounder(final Graphics2D g2d) { return new StringBounder() { - public Dimension2D calculateDimension(Font font, String text) { - final FontMetrics fm = g2d.getFontMetrics(font); + public Dimension2D calculateDimension(UFont font, String text) { + final FontMetrics fm = g2d.getFontMetrics(font.getFont()); final Rectangle2D rect = fm.getStringBounds(text, g2d); return new Dimension2DDouble(rect.getWidth(), rect.getHeight()); } - public double getFontDescent(Font font) { - final FontMetrics fm = g2d.getFontMetrics(font); - return fm.getDescent(); - } - - public double getFontAscent(Font font) { - final FontMetrics fm = g2d.getFontMetrics(font); - return fm.getAscent(); - } +// public double getFontDescent(Font font) { +// final FontMetrics fm = g2d.getFontMetrics(font); +// return fm.getDescent(); +// } +// +// public double getFontAscent(Font font) { +// final FontMetrics fm = g2d.getFontMetrics(font); +// return fm.getAscent(); +// } // public UnusedSpace getUnusedSpace(Font font, char c) { // //return new UnusedSpace(7, 6, 0, 2); diff --git a/src/net/sourceforge/plantuml/graphic/TextBlock.java b/src/net/sourceforge/plantuml/graphic/TextBlock.java index 427a72da2..e0032860a 100644 --- a/src/net/sourceforge/plantuml/graphic/TextBlock.java +++ b/src/net/sourceforge/plantuml/graphic/TextBlock.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4125 $ + * Revision $Revision: 6577 $ * */ package net.sourceforge.plantuml.graphic; @@ -36,13 +36,14 @@ package net.sourceforge.plantuml.graphic; import java.awt.Graphics2D; import java.awt.geom.Dimension2D; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UGraphic; public interface TextBlock { Dimension2D calculateDimension(StringBounder stringBounder); - void drawTOBEREMOVED(Graphics2D g2d, double x, double y); + void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y); void drawU(UGraphic ug, double x, double y); diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockEmpty.java b/src/net/sourceforge/plantuml/graphic/TextBlockEmpty.java index f457cc48a..a8ff7ecd4 100644 --- a/src/net/sourceforge/plantuml/graphic/TextBlockEmpty.java +++ b/src/net/sourceforge/plantuml/graphic/TextBlockEmpty.java @@ -37,6 +37,7 @@ import java.awt.Graphics2D; import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UGraphic; public class TextBlockEmpty implements TextBlock { @@ -45,7 +46,7 @@ public class TextBlockEmpty implements TextBlock { return new Dimension2DDouble(0, 0); } - public void drawTOBEREMOVED(Graphics2D g2d, double x, double y) { + public void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { } public void drawU(UGraphic ug, double x, double y) { diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockSimple.java b/src/net/sourceforge/plantuml/graphic/TextBlockSimple.java index a9ffeabef..c6d84a17d 100644 --- a/src/net/sourceforge/plantuml/graphic/TextBlockSimple.java +++ b/src/net/sourceforge/plantuml/graphic/TextBlockSimple.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6353 $ + * Revision $Revision: 6936 $ * */ package net.sourceforge.plantuml.graphic; @@ -36,11 +36,13 @@ package net.sourceforge.plantuml.graphic; import java.awt.Graphics2D; import java.awt.geom.Dimension2D; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.EmbededDiagram; import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UGraphic; class TextBlockSimple implements TextBlock { @@ -51,7 +53,7 @@ class TextBlockSimple implements TextBlock { HorizontalAlignement horizontalAlignement) { for (CharSequence s : texts) { if (s instanceof Stereotype) { - lines.add(createLineForStereotype(fontConfiguration, (Stereotype) s, horizontalAlignement)); + lines.addAll(createLinesForStereotype(fontConfiguration, (Stereotype) s, horizontalAlignement)); } else if (s instanceof EmbededDiagram) { lines.add(new EmbededSystemLine((EmbededDiagram) s)); } else { @@ -60,10 +62,14 @@ class TextBlockSimple implements TextBlock { } } - private SingleLine createLineForStereotype(FontConfiguration fontConfiguration, Stereotype s, + private List createLinesForStereotype(FontConfiguration fontConfiguration, Stereotype s, HorizontalAlignement horizontalAlignement) { assert s.getLabel() != null; - return new SingleLine(s.getLabel(), fontConfiguration.add(FontStyle.ITALIC), horizontalAlignement); + final List result = new ArrayList(); + for (String st : s.getLabels()) { + result.add(new SingleLine(st, fontConfiguration.add(FontStyle.ITALIC), horizontalAlignement)); + } + return Collections.unmodifiableList(result); } public Dimension2D calculateDimension(StringBounder stringBounder) { @@ -81,7 +87,7 @@ class TextBlockSimple implements TextBlock { return new Dimension2DDouble(width, height); } - public void drawTOBEREMOVED(Graphics2D g2d, double x, double y) { + public void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { final Dimension2D dimText = getTextDimension(StringBounderUtils.asStringBounder(g2d)); for (Line line : lines) { @@ -92,7 +98,7 @@ class TextBlockSimple implements TextBlock { - line.calculateDimension(StringBounderUtils.asStringBounder(g2d)).getWidth(); deltaX = diff / 2.0; } - line.draw(g2d, x + deltaX, y); + line.draw(colorMapper, g2d, x + deltaX, y); y += line.calculateDimension(StringBounderUtils.asStringBounder(g2d)).getHeight(); } } diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockSpotted.java b/src/net/sourceforge/plantuml/graphic/TextBlockSpotted.java index 12ddd5466..863b23634 100644 --- a/src/net/sourceforge/plantuml/graphic/TextBlockSpotted.java +++ b/src/net/sourceforge/plantuml/graphic/TextBlockSpotted.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6009 $ + * Revision $Revision: 6577 $ * */ package net.sourceforge.plantuml.graphic; @@ -38,6 +38,7 @@ import java.awt.geom.Dimension2D; import java.util.List; import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UGraphic; class TextBlockSpotted extends TextBlockSimple { @@ -65,7 +66,7 @@ class TextBlockSpotted extends TextBlockSimple { } @Override - public void drawTOBEREMOVED(Graphics2D g2d, double x, double y) { + public void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { // final AffineTransform at = g2d.getTransform(); // final StringBounder stringBounder = StringBounderUtils.asStringBounder(g2d); // diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockUtils.java b/src/net/sourceforge/plantuml/graphic/TextBlockUtils.java index 09dbcb6c6..4656ada92 100644 --- a/src/net/sourceforge/plantuml/graphic/TextBlockUtils.java +++ b/src/net/sourceforge/plantuml/graphic/TextBlockUtils.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6009 $ + * Revision $Revision: 6570 $ * */ package net.sourceforge.plantuml.graphic; @@ -64,7 +64,7 @@ public class TextBlockUtils { final Stereotype stereotype = (Stereotype) texts.get(0); if (stereotype.isSpotted()) { final CircledCharacter circledCharacter = new CircledCharacter(stereotype.getCharacter(), - stereotype.getRadius(), stereotype.getCircledFont(), stereotype.getColor(), null, + stereotype.getRadius(), stereotype.getCircledFont(), stereotype.getHtmlColor(), null, fontConfiguration.getColor()); if (stereotype.getLabel() == null) { return new TextBlockSpotted(circledCharacter, texts.subList(1, texts.size()), fontConfiguration, diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockWithNumber.java b/src/net/sourceforge/plantuml/graphic/TextBlockWithNumber.java index d915b3d74..1b539ec0e 100644 --- a/src/net/sourceforge/plantuml/graphic/TextBlockWithNumber.java +++ b/src/net/sourceforge/plantuml/graphic/TextBlockWithNumber.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6009 $ + * Revision $Revision: 6577 $ * */ package net.sourceforge.plantuml.graphic; @@ -39,6 +39,7 @@ import java.util.Arrays; import java.util.List; import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UGraphic; class TextBlockWithNumber extends TextBlockSimple { @@ -66,14 +67,14 @@ class TextBlockWithNumber extends TextBlockSimple { } @Override - public void drawTOBEREMOVED(Graphics2D g2d, double x, double y) { + public void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { final StringBounder stringBounder = StringBounderUtils.asStringBounder(g2d); final double heightNum = numText.calculateDimension(stringBounder).getHeight(); final double deltaY = calculateDimension(stringBounder).getHeight() - heightNum; - numText.drawTOBEREMOVED(g2d, x, y + deltaY / 2.0); - super.drawTOBEREMOVED(g2d, x + getNumberWithAndMargin(stringBounder), y); + numText.drawTOBEREMOVED(colorMapper, g2d, x, y + deltaY / 2.0); + super.drawTOBEREMOVED(colorMapper, g2d, x + getNumberWithAndMargin(stringBounder), y); } @Override diff --git a/src/net/sourceforge/plantuml/graphic/Tile.java b/src/net/sourceforge/plantuml/graphic/Tile.java index 75684b789..f60af7065 100644 --- a/src/net/sourceforge/plantuml/graphic/Tile.java +++ b/src/net/sourceforge/plantuml/graphic/Tile.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3834 $ + * Revision $Revision: 6577 $ * */ package net.sourceforge.plantuml.graphic; @@ -36,14 +36,15 @@ package net.sourceforge.plantuml.graphic; import java.awt.Graphics2D; import java.awt.geom.Dimension2D; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UGraphic; interface Tile { Dimension2D calculateDimension(StringBounder stringBounder); - void draw(Graphics2D g2d, double x, double y); - + void draw(ColorMapper colorMapper, Graphics2D g2d, double x, double y); + void drawU(UGraphic ug, double x, double y); } \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/TileImage.java b/src/net/sourceforge/plantuml/graphic/TileImage.java index a6af2bca6..a03cd3014 100644 --- a/src/net/sourceforge/plantuml/graphic/TileImage.java +++ b/src/net/sourceforge/plantuml/graphic/TileImage.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3932 $ + * Revision $Revision: 6577 $ * */ package net.sourceforge.plantuml.graphic; @@ -38,6 +38,7 @@ import java.awt.geom.Dimension2D; import java.awt.image.BufferedImage; import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UImage; @@ -55,7 +56,7 @@ class TileImage implements Tile { return new Dimension2DDouble(image.getWidth(), image.getHeight() + 2 * vspace); } - public void draw(Graphics2D g2d, double x, double y) { + public void draw(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { g2d.drawImage(image, (int) x, (int) y + vspace, null); } diff --git a/src/net/sourceforge/plantuml/graphic/TileText.java b/src/net/sourceforge/plantuml/graphic/TileText.java index d69a03b8a..2d7839b71 100644 --- a/src/net/sourceforge/plantuml/graphic/TileText.java +++ b/src/net/sourceforge/plantuml/graphic/TileText.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5757 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.graphic; @@ -41,6 +41,7 @@ import java.util.StringTokenizer; import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.Log; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UText; @@ -70,10 +71,10 @@ class TileText implements Tile { return fontConfiguration.getFont().getSize2D(); } - public void draw(Graphics2D g2d, double x, double y) { + public void draw(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { // TO be removed - g2d.setFont(fontConfiguration.getFont()); - g2d.setPaint(fontConfiguration.getColor()); + g2d.setFont(fontConfiguration.getFont().getFont()); + g2d.setPaint(colorMapper.getMappedColor(fontConfiguration.getColor())); g2d.drawString(text, (float) x, (float) y); if (fontConfiguration.containsStyle(FontStyle.UNDERLINE)) { @@ -85,7 +86,7 @@ class TileText implements Tile { } if (fontConfiguration.containsStyle(FontStyle.STRIKE)) { final Dimension2D dim = calculateDimension(StringBounderUtils.asStringBounder(g2d)); - final FontMetrics fm = g2d.getFontMetrics(fontConfiguration.getFont()); + final FontMetrics fm = g2d.getFontMetrics(fontConfiguration.getFont().getFont()); final int ypos = (int) (y - fm.getDescent() - 0.5); g2d.setStroke(new BasicStroke((float) 1.5)); g2d.drawLine((int) x, ypos, (int) (x + dim.getWidth()), ypos); diff --git a/src/net/sourceforge/plantuml/graphic/UnusedSpace.java b/src/net/sourceforge/plantuml/graphic/UnusedSpace.java index 265a09693..e37f3872a 100644 --- a/src/net/sourceforge/plantuml/graphic/UnusedSpace.java +++ b/src/net/sourceforge/plantuml/graphic/UnusedSpace.java @@ -33,7 +33,6 @@ */ package net.sourceforge.plantuml.graphic; -import java.awt.Font; import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.util.ArrayList; @@ -42,6 +41,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import net.sourceforge.plantuml.ugraphic.UFont; + public class UnusedSpace { static class Point { @@ -69,7 +70,7 @@ public class UnusedSpace { final private static Map cache = new HashMap(); - public static UnusedSpace getUnusedSpace(Font font, char c) { + public static UnusedSpace getUnusedSpace(UFont font, char c) { final Object key = Arrays.asList(font, c); UnusedSpace result = cache.get(key); if (result == null) { @@ -79,10 +80,10 @@ public class UnusedSpace { return result; } - private UnusedSpace(Font font, char c) { + private UnusedSpace(UFont font, char c) { final BufferedImage im = new BufferedImage(2 * HALF_SIZE, 2 * HALF_SIZE, BufferedImage.TYPE_INT_RGB); final Graphics2D g2d = im.createGraphics(); - g2d.setFont(font); + g2d.setFont(font.getFont()); g2d.drawString("" + c, HALF_SIZE, HALF_SIZE); int minI = Integer.MAX_VALUE; diff --git a/src/net/sourceforge/plantuml/objectdiagram/AbstractClassOrObjectDiagram.java b/src/net/sourceforge/plantuml/objectdiagram/AbstractClassOrObjectDiagram.java index ef0e853bf..c8f134b03 100644 --- a/src/net/sourceforge/plantuml/objectdiagram/AbstractClassOrObjectDiagram.java +++ b/src/net/sourceforge/plantuml/objectdiagram/AbstractClassOrObjectDiagram.java @@ -168,7 +168,10 @@ public abstract class AbstractClassOrObjectDiagram extends AbstractEntityDiagram addLink(pointToEntity2); int length = 1; - if (existingLink.getLength() == 1) { + if (existingLink.getLength() == 1 && entity1 != entity2) { + length = 2; + } + if (existingLink.getLength() == 2 && entity1 == entity2) { length = 2; } diff --git a/src/net/sourceforge/plantuml/oregon/PSystemOregon.java b/src/net/sourceforge/plantuml/oregon/PSystemOregon.java index 86b637505..a0bb35f29 100644 --- a/src/net/sourceforge/plantuml/oregon/PSystemOregon.java +++ b/src/net/sourceforge/plantuml/oregon/PSystemOregon.java @@ -33,7 +33,6 @@ */ package net.sourceforge.plantuml.oregon; -import java.awt.Color; import java.awt.Font; import java.io.IOException; import java.io.OutputStream; @@ -41,6 +40,8 @@ import java.io.OutputStream; import net.sourceforge.plantuml.AbstractPSystem; import net.sourceforge.plantuml.FileFormatOption; import net.sourceforge.plantuml.graphic.GraphicStrings; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.ugraphic.UFont; public class PSystemOregon extends AbstractPSystem { @@ -58,26 +59,13 @@ public class PSystemOregon extends AbstractPSystem { } } -// public List createFiles(File suggestedFile, FileFormatOption fileFormat) throws IOException, InterruptedException { -// OutputStream os = null; -// try { -// os = new FileOutputStream(suggestedFile); -// getGraphicStrings().writeImage(os, fileFormat); -// } finally { -// if (os != null) { -// os.close(); -// } -// } -// return Arrays.asList(suggestedFile); -// } - public void exportDiagram(OutputStream os, StringBuilder cmap, int index, FileFormatOption fileFormat) throws IOException { getGraphicStrings().writeImage(os, fileFormat); } private GraphicStrings getGraphicStrings() throws IOException { - final Font font = new Font("Monospaced", Font.PLAIN, 14); - return new GraphicStrings(screen.getLines(), font, Color.GREEN, Color.BLACK, true); + final UFont font = new UFont("Monospaced", Font.PLAIN, 14); + return new GraphicStrings(screen.getLines(), font, HtmlColor.GREEN, HtmlColor.BLACK, true); } public String getDescription() { diff --git a/src/net/sourceforge/plantuml/oregon/PSystemOregonFactory.java b/src/net/sourceforge/plantuml/oregon/PSystemOregonFactory.java index 65538adca..0233b90f1 100644 --- a/src/net/sourceforge/plantuml/oregon/PSystemOregonFactory.java +++ b/src/net/sourceforge/plantuml/oregon/PSystemOregonFactory.java @@ -44,11 +44,7 @@ public class PSystemOregonFactory implements PSystemBasicFactory { private PSystemOregon system; private List inputs; - public PSystemOregonFactory() { - reset(); - } - - public void reset() { + public void init(String startLine) { inputs = null; } diff --git a/src/net/sourceforge/plantuml/pdf/PdfConverter.java b/src/net/sourceforge/plantuml/pdf/PdfConverter.java new file mode 100644 index 000000000..c51fe371d --- /dev/null +++ b/src/net/sourceforge/plantuml/pdf/PdfConverter.java @@ -0,0 +1,76 @@ +/* ======================================================================== + * 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: 6600 $ + * + */ +package net.sourceforge.plantuml.pdf; +import java.io.File; +import java.lang.reflect.Method; + +public class PdfConverter { + + public static void convert(File svgFile, File pdfFile) { + + if (svgFile.exists() == false) { + throw new IllegalArgumentException(); + } + pdfFile.delete(); + if (pdfFile.exists()) { + throw new IllegalStateException(); + } + + try { + final Class clSVGConverter = Class.forName("org.apache.batik.apps.rasterizer.SVGConverter"); + + final Object converter = clSVGConverter.newInstance(); + + final Class clDestinationType = Class.forName("org.apache.batik.apps.rasterizer.DestinationType"); + final Object pdf = clDestinationType.getField("PDF").get(null); + final Method setDestinationType = clSVGConverter.getMethod("setDestinationType", clDestinationType); + + setDestinationType.invoke(converter, pdf); + + final String[] path = new String[] { svgFile.getAbsolutePath() }; + final Method setSources = clSVGConverter.getMethod("setSources", path.getClass()); + setSources.invoke(converter, new Object[] { path }); + final Method setDst = clSVGConverter.getMethod("setDst", pdfFile.getClass()); + setDst.invoke(converter, new Object[] { pdfFile }); + final Method execute = clSVGConverter.getMethod("execute"); + execute.invoke(converter); + } catch (Exception e) { + e.printStackTrace(); + throw new UnsupportedOperationException(); + } + if (pdfFile.exists() == false) { + throw new IllegalStateException(); + } + } +} diff --git a/src/net/sourceforge/plantuml/png/PngIO.java b/src/net/sourceforge/plantuml/png/PngIO.java index e5573f14d..7178f24f9 100644 --- a/src/net/sourceforge/plantuml/png/PngIO.java +++ b/src/net/sourceforge/plantuml/png/PngIO.java @@ -28,12 +28,13 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5872 $ + * Revision $Revision: 6710 $ * */ package net.sourceforge.plantuml.png; import java.awt.image.RenderedImage; +import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -58,7 +59,7 @@ public class PngIO { public static void write(RenderedImage image, File file, String metadata, int dpi) throws IOException { OutputStream os = null; try { - os = new FileOutputStream(file); + os = new BufferedOutputStream(new FileOutputStream(file)); write(image, os, metadata, dpi); } finally { if (os != null) { diff --git a/src/net/sourceforge/plantuml/png/PngTitler.java b/src/net/sourceforge/plantuml/png/PngTitler.java index 17ae8774a..7a735c750 100644 --- a/src/net/sourceforge/plantuml/png/PngTitler.java +++ b/src/net/sourceforge/plantuml/png/PngTitler.java @@ -28,12 +28,11 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6471 $ + * Revision $Revision: 6922 $ * */ package net.sourceforge.plantuml.png; -import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.RenderingHints; @@ -43,25 +42,30 @@ import java.util.List; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounderUtils; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; import net.sourceforge.plantuml.graphic.VerticalPosition; +import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d; public class PngTitler { - private final Color textColor; - private final List text; + private final HtmlColor textColor; + private final List text; private final int fontSize; private final String fontFamily; private final HorizontalAlignement horizontalAlignement; private final VerticalPosition verticalPosition; + private final ColorMapper colorMapper; - public PngTitler(Color textColor, List text, int fontSize, String fontFamily, + public PngTitler(ColorMapper colorMapper, HtmlColor textColor, List text, int fontSize, String fontFamily, HorizontalAlignement horizontalAlignement, VerticalPosition verticalPosition) { this.textColor = textColor; + this.colorMapper = colorMapper; this.text = text; this.fontSize = fontSize; this.fontFamily = fontFamily; @@ -70,9 +74,9 @@ public class PngTitler { } - public BufferedImage processImage(BufferedImage im, Color background, int margin) { + public BufferedImage processImage(BufferedImage im, HtmlColor background, int margin) { if (text != null && text.size() > 0) { - im = addTitle(im, background, textColor, text, fontSize, fontFamily, horizontalAlignement, + im = addTitle(colorMapper, im, background, textColor, text, fontSize, fontFamily, horizontalAlignement, verticalPosition, margin); } return im; @@ -91,15 +95,15 @@ public class PngTitler { if (text == null || text.size() == 0) { return null; } - final Font normalFont = new Font(fontFamily, Font.PLAIN, fontSize); + final UFont normalFont = new UFont(fontFamily, Font.PLAIN, fontSize); return TextBlockUtils.create(text, new FontConfiguration(normalFont, textColor), horizontalAlignement); } - static private BufferedImage addTitle(BufferedImage im, Color background, Color textColor, List text, + static private BufferedImage addTitle(ColorMapper colorMapper, BufferedImage im, HtmlColor background, HtmlColor textColor, List text, int fontSize, String fontFamily, HorizontalAlignement horizontalAlignement, VerticalPosition verticalPosition, int margin) { - final Font normalFont = new Font(fontFamily, Font.PLAIN, fontSize); + final UFont normalFont = new UFont(fontFamily, Font.PLAIN, fontSize); final Graphics2D oldg2d = im.createGraphics(); final TextBlock textBloc = TextBlockUtils.create(text, new FontConfiguration(normalFont, textColor), horizontalAlignement); @@ -113,7 +117,7 @@ public class PngTitler { final Graphics2D g2d = newIm.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); - g2d.setColor(background); + g2d.setColor(colorMapper.getMappedColor(background)); g2d.fillRect(0, 0, newIm.getWidth(), newIm.getHeight()); final double xText; if (horizontalAlignement == HorizontalAlignement.LEFT) { @@ -139,7 +143,7 @@ public class PngTitler { } g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); - textBloc.drawU(new UGraphicG2d(g2d, null, 1.0), xText, yText); + textBloc.drawU(new UGraphicG2d(colorMapper, g2d, null, 1.0), xText, yText); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); final double delta2 = (width - im.getWidth()) / 2; diff --git a/src/net/sourceforge/plantuml/posimo/AbstractEntityImage2.java b/src/net/sourceforge/plantuml/posimo/AbstractEntityImage2.java index c88c6fb81..7d957d7d5 100644 --- a/src/net/sourceforge/plantuml/posimo/AbstractEntityImage2.java +++ b/src/net/sourceforge/plantuml/posimo/AbstractEntityImage2.java @@ -33,16 +33,16 @@ */ package net.sourceforge.plantuml.posimo; -import java.awt.Color; -import java.awt.Font; import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.ColorParam; import net.sourceforge.plantuml.FontParam; import net.sourceforge.plantuml.ISkinParam; import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.ugraphic.UFont; abstract class AbstractEntityImage2 implements IEntityImageBlock { @@ -65,16 +65,16 @@ abstract class AbstractEntityImage2 implements IEntityImageBlock { return entity; } - protected Font getFont(FontParam fontParam) { + protected UFont getFont(FontParam fontParam) { return skinParam.getFont(fontParam, null); } - protected Color getFontColor(FontParam fontParam) { - return skinParam.getFontHtmlColor(fontParam, null).getColor(); + protected HtmlColor getFontColor(FontParam fontParam) { + return skinParam.getFontHtmlColor(fontParam, null); } - protected final Color getColor(ColorParam colorParam) { - return rose.getHtmlColor(skinParam, colorParam).getColor(); + protected final HtmlColor getColor(ColorParam colorParam) { + return rose.getHtmlColor(skinParam, colorParam); } protected final ISkinParam getSkinParam() { diff --git a/src/net/sourceforge/plantuml/posimo/BezierUtils.java b/src/net/sourceforge/plantuml/posimo/BezierUtils.java index d64bb2a92..38ec41460 100644 --- a/src/net/sourceforge/plantuml/posimo/BezierUtils.java +++ b/src/net/sourceforge/plantuml/posimo/BezierUtils.java @@ -33,10 +33,15 @@ */ package net.sourceforge.plantuml.posimo; +import java.awt.Dimension; +import java.awt.Point; +import java.awt.Rectangle; import java.awt.Shape; import java.awt.geom.CubicCurve2D; +import java.awt.geom.Dimension2D; import java.awt.geom.Line2D; import java.awt.geom.Point2D; +import java.awt.geom.Rectangle2D; public class BezierUtils { @@ -146,7 +151,7 @@ public class BezierUtils { final boolean contains1 = shape.contains(copy.x1, copy.y1); final boolean contains2 = shape.contains(copy.x2, copy.y2); if (contains1 ^ contains2 == false) { - //return new Point2D.Double(orig.x2, orig.y2); + // return new Point2D.Double(orig.x2, orig.y2); throw new IllegalArgumentException(); } while (true) { @@ -172,4 +177,18 @@ public class BezierUtils { } } + static public Rectangle2D toRectangle(Positionable p) { + final Point2D point = p.getPosition(); + final Dimension2D dim = p.getSize(); + return new Rectangle2D.Double(point.getX(), point.getY(), dim.getWidth(), dim.getHeight()); + } + + static public boolean intersect(Positionable p1, Positionable p2) { + return toRectangle(p1).intersects(toRectangle(p2)); + } + + static public Point2D.Double getCenter(Positionable p) { + return new Point2D.Double(toRectangle(p).getCenterX(), toRectangle(p).getCenterY()); + } + } diff --git a/src/net/sourceforge/plantuml/posimo/DotPath.java b/src/net/sourceforge/plantuml/posimo/DotPath.java index 0f4181fcb..8c7c01601 100644 --- a/src/net/sourceforge/plantuml/posimo/DotPath.java +++ b/src/net/sourceforge/plantuml/posimo/DotPath.java @@ -48,6 +48,9 @@ import java.util.Map; import java.util.StringTokenizer; import net.sourceforge.plantuml.asciiart.BasicCharArea; +import net.sourceforge.plantuml.eps.EpsGraphics; +import net.sourceforge.plantuml.ugraphic.UPath; +import net.sourceforge.plantuml.ugraphic.USegmentType; import net.sourceforge.plantuml.ugraphic.UShape; public class DotPath implements UShape { @@ -98,6 +101,30 @@ public class DotPath implements UShape { return result; } + public double getMinDist(Point2D ref) { + double result = Double.MAX_VALUE; + for (CubicCurve2D.Double c : beziers) { + final double d1 = ref.distance(c.x1, c.y1); + if (d1 < result) { + result = d1; + } + final double d2 = ref.distance(c.x2, c.y2); + if (d2 < result) { + result = d2; + } + final double d3 = ref.distance(c.ctrlx1, c.ctrly1); + if (d3 < result) { + result = d3; + } + final double d4 = ref.distance(c.ctrlx2, c.ctrly2); + if (d4 < result) { + result = d4; + } + } + return result; + + } + public DotPath() { this(new ArrayList()); } @@ -164,7 +191,6 @@ public class DotPath implements UShape { return new DotPath(copy); } - private DotPath(List beziers) { this.beziers.addAll(beziers); // this.print = super.toString(); @@ -239,6 +265,45 @@ public class DotPath implements UShape { g2d.draw(p); } + public void drawOk(EpsGraphics eps, double x, double y) { + boolean first = true; + for (CubicCurve2D.Double bez : beziers) { + bez = new CubicCurve2D.Double(x + bez.x1, y + bez.y1, x + bez.ctrlx1, y + bez.ctrly1, x + bez.ctrlx2, y + + bez.ctrly2, x + bez.x2, y + bez.y2); + eps.epsLine(bez.x1, bez.y1, bez.x2, bez.y2); + } + } + + public void draw(EpsGraphics eps, double x, double y) { + eps.newpathDot(true); + boolean first = true; + for (CubicCurve2D.Double bez : beziers) { + bez = new CubicCurve2D.Double(x + bez.x1, y + bez.y1, x + bez.ctrlx1, y + bez.ctrly1, x + bez.ctrlx2, y + + bez.ctrly2, x + bez.x2, y + bez.y2); + if (first) { + eps.movetoNoMacro(bez.x1, bez.y1); + first = false; + } + eps.curvetoNoMacro(bez.ctrlx1, bez.ctrly1, bez.ctrlx2, bez.ctrly2, bez.x2, bez.y2); + } + eps.closepathDot(true); + } + + public UPath toUPath() { + final UPath result = new UPath(); + boolean start = true; + for (CubicCurve2D.Double bez : beziers) { + if (start) { + result.add(new double[] { bez.x1, bez.y1 }, USegmentType.SEG_MOVETO); + start = false; + } + result.add(new double[] { bez.ctrlx1, bez.ctrly1, bez.ctrlx2, bez.ctrly2, bez.x2, bez.y2 }, + USegmentType.SEG_CUBICTO); + + } + return result; + } + public Point2D getFrontierIntersection(Shape shape, Rectangle2D... notIn) { final List all = new ArrayList(beziers); for (int i = 0; i < 8; i++) { @@ -326,9 +391,10 @@ public class DotPath implements UShape { } else if (bez.y1 == bez.y2) { area.drawHLine('-', (int) (bez.y1 / pixelYPerChar), (int) (bez.x1 / pixelXPerChar), (int) (bez.x2 / pixelXPerChar)); - } else { - throw new UnsupportedOperationException("bez=" + toString(bez)); - } + } /* + * else { throw new UnsupportedOperationException("bez=" + + * toString(bez)); } + */ } } diff --git a/src/net/sourceforge/plantuml/posimo/EntityImageBlock.java b/src/net/sourceforge/plantuml/posimo/EntityImageBlock.java index 1084c86cf..39cfce59d 100644 --- a/src/net/sourceforge/plantuml/posimo/EntityImageBlock.java +++ b/src/net/sourceforge/plantuml/posimo/EntityImageBlock.java @@ -33,7 +33,6 @@ */ package net.sourceforge.plantuml.posimo; -import java.awt.Color; import java.awt.geom.Dimension2D; import java.io.IOException; import java.util.ArrayList; @@ -50,10 +49,12 @@ import net.sourceforge.plantuml.cucadiagram.Link; import net.sourceforge.plantuml.cucadiagram.dot.PlayField; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +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.skin.rose.Rose; +import net.sourceforge.plantuml.svek.ShapeType; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UGraphicUtils; import net.sourceforge.plantuml.ugraphic.URectangle; @@ -77,9 +78,9 @@ public class EntityImageBlock implements IEntityImageBlock { this.rose = rose; this.links = links; - if (StringUtils.isNotEmpty(entity.getDisplay())) { - this.name = TextBlockUtils.create(StringUtils.getWithNewlines(entity.getDisplay()), new FontConfiguration( - param.getFont(titleParam, null), Color.BLACK), HorizontalAlignement.CENTER); + if (StringUtils.isNotEmpty(entity.getDisplay2())) { + this.name = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( + param.getFont(titleParam, null), HtmlColor.BLACK), HorizontalAlignement.CENTER); } else { this.name = null; } @@ -140,7 +141,7 @@ public class EntityImageBlock implements IEntityImageBlock { // this.frame = new Frame(StringUtils.getWithNewlines(entity.getDisplay()), Color.BLACK, param // .getFont(FontParam.CLASS), rose.getHtmlColor(param, ColorParam.classBorder).getColor()); - this.frame = new Frame(StringUtils.getWithNewlines(entity.getDisplay()), param); + this.frame = new Frame(entity.getDisplay2(), param); } @@ -154,17 +155,17 @@ public class EntityImageBlock implements IEntityImageBlock { // if (entity.getParent() == null) { if (entity.getType() != EntityType.GROUP) { - ug.getParam().setBackcolor(rose.getHtmlColor(param, ColorParam.classBackground).getColor()); - ug.getParam().setColor(rose.getHtmlColor(param, ColorParam.classBorder).getColor()); + ug.getParam().setBackcolor(rose.getHtmlColor(param, ColorParam.classBackground)); + ug.getParam().setColor(rose.getHtmlColor(param, ColorParam.classBorder)); ug.draw(xTheoricalPosition - marginWidth, yTheoricalPosition - marginHeight, rect); // name.drawU(ug, xTheoricalPosition + margin, yTheoricalPosition + margin); name.drawU(ug, xTheoricalPosition + 0, yTheoricalPosition + 0); } else { // final Frame frame = new Frame(StringUtils.getWithNewlines(entity.getDisplay()), Color.BLACK, param // .getFont(FontParam.CLASS), rose.getHtmlColor(param, ColorParam.classBorder).getColor()); - final Frame frame = new Frame(StringUtils.getWithNewlines(entity.getDisplay()), param); + final Frame frame = new Frame(entity.getDisplay2(), param); - ug.getParam().setBackcolor(rose.getHtmlColor(param, ColorParam.background).getColor()); + ug.getParam().setBackcolor(rose.getHtmlColor(param, ColorParam.background)); ug.getParam().setColor(null); ug.draw(xTheoricalPosition - marginWidth, yTheoricalPosition - marginWidth, rect); @@ -183,4 +184,9 @@ public class EntityImageBlock implements IEntityImageBlock { yTheoricalPosition + 0 + frame.getPreferredHeight(ug.getStringBounder()))); } } + + public ShapeType getShapeType() { + return ShapeType.RECTANGLE; + } + } diff --git a/src/net/sourceforge/plantuml/posimo/EntityImageClass2.java b/src/net/sourceforge/plantuml/posimo/EntityImageClass2.java index 195572a4c..17e813805 100644 --- a/src/net/sourceforge/plantuml/posimo/EntityImageClass2.java +++ b/src/net/sourceforge/plantuml/posimo/EntityImageClass2.java @@ -33,8 +33,6 @@ */ package net.sourceforge.plantuml.posimo; -import java.awt.Color; -import java.awt.Font; import java.awt.geom.Dimension2D; import java.util.Collection; @@ -51,11 +49,13 @@ import net.sourceforge.plantuml.graph.MethodsOrFieldsArea2; import net.sourceforge.plantuml.graphic.CircledCharacter; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +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.PlacementStrategyX1Y2Y3; import net.sourceforge.plantuml.ugraphic.PlacementStrategyY1Y2; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UGroup; import net.sourceforge.plantuml.ugraphic.ULine; @@ -71,8 +71,8 @@ public class EntityImageClass2 extends AbstractEntityImage2 { public EntityImageClass2(IEntity entity, ISkinParam skinParam, Collection links) { super(entity, skinParam); - this.name = TextBlockUtils.create(StringUtils.getWithNewlines(entity.getDisplay()), new FontConfiguration( - getFont(FontParam.CLASS), Color.BLACK), HorizontalAlignement.CENTER); + this.name = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( + getFont(FontParam.CLASS), HtmlColor.BLACK), HorizontalAlignement.CENTER); final Stereotype stereotype = entity.getStereotype(); if (stereotype == null || stereotype.getLabel() == null) { this.stereo = null; @@ -91,10 +91,10 @@ public class EntityImageClass2 extends AbstractEntityImage2 { private CircledCharacter getCircledCharacter(IEntity entity) { final Stereotype stereotype = entity.getStereotype(); if (stereotype != null && stereotype.getCharacter() != 0) { - final Color classBorder = getColor(ColorParam.classBorder); - final Font font = getFont(FontParam.CIRCLED_CHARACTER); + final HtmlColor classBorder = getColor(ColorParam.classBorder); + final UFont font = getFont(FontParam.CIRCLED_CHARACTER); return new CircledCharacter(stereotype.getCharacter(), getSkinParam().getCircledCharacterRadius(), font, - stereotype.getColor(), classBorder, getFontColor(FontParam.CIRCLED_CHARACTER)); + stereotype.getHtmlColor(), classBorder, getFontColor(FontParam.CIRCLED_CHARACTER)); } if (entity.getType() == EntityType.ABSTRACT_CLASS) { return new CircledCharacter('A', getSkinParam().getCircledCharacterRadius(), @@ -128,9 +128,8 @@ public class EntityImageClass2 extends AbstractEntityImage2 { final Dimension2D dimTitle = getTitleDimension(stringBounder); final Dimension2D dimMethods = methods.calculateDimension(stringBounder); final Dimension2D dimFields = fields.calculateDimension(stringBounder); - final double width = Math.max( - Math.max(dimMethods.getWidth() + 2 * xMarginFieldsOrMethod, dimFields.getWidth() + 2 - * xMarginFieldsOrMethod), dimTitle.getWidth() + 2 * xMarginCircle); + final double width = Math.max(Math.max(dimMethods.getWidth() + 2 * xMarginFieldsOrMethod, dimFields.getWidth() + + 2 * xMarginFieldsOrMethod), dimTitle.getWidth() + 2 * xMarginCircle); final double height = getMethodOrFieldHeight(dimMethods) + getMethodOrFieldHeight(dimFields) + dimTitle.getHeight(); return new Dimension2DDouble(width, height); @@ -152,8 +151,8 @@ public class EntityImageClass2 extends AbstractEntityImage2 { if (circledCharacter == null) { return nameAndStereo; } - return new Dimension2DDouble(nameAndStereo.getWidth() + getCircledWidth(stringBounder), Math.max( - nameAndStereo.getHeight(), circledCharacter.getPreferredHeight(stringBounder) + 2 * yMarginCircle)); + return new Dimension2DDouble(nameAndStereo.getWidth() + getCircledWidth(stringBounder), Math.max(nameAndStereo + .getHeight(), circledCharacter.getPreferredHeight(stringBounder) + 2 * yMarginCircle)); } private Dimension2D getNameAndSteretypeDimension(StringBounder stringBounder) { diff --git a/src/net/sourceforge/plantuml/posimo/EntityImageNote2.java b/src/net/sourceforge/plantuml/posimo/EntityImageNote2.java index 5e88c9580..3b63d3893 100644 --- a/src/net/sourceforge/plantuml/posimo/EntityImageNote2.java +++ b/src/net/sourceforge/plantuml/posimo/EntityImageNote2.java @@ -52,26 +52,24 @@ public class EntityImageNote2 extends AbstractEntityImage2 { private final Component comp; - public EntityImageNote2(IEntity entity, ISkinParam skinParam, - Collection links) { + public EntityImageNote2(IEntity entity, ISkinParam skinParam, Collection links) { super(entity, skinParam); final Rose skin = new Rose(); - comp = skin.createComponent(ComponentType.NOTE, skinParam, StringUtils - .getWithNewlines(entity.getDisplay())); + comp = skin.createComponent(ComponentType.NOTE, skinParam, entity.getDisplay2()); } @Override public Dimension2D getDimension(StringBounder stringBounder) { - final double height = comp.getPreferredHeight(stringBounder); - final double width = comp.getPreferredWidth(stringBounder); + final double height = comp.getPreferredHeight(stringBounder); + final double width = comp.getPreferredWidth(stringBounder); return new Dimension2DDouble(width, height); } - public void drawU(UGraphic ug, double xTheoricalPosition, - double yTheoricalPosition, double marginWidth, double marginHeight) { + public void drawU(UGraphic ug, double xTheoricalPosition, double yTheoricalPosition, double marginWidth, + double marginHeight) { final double dx = ug.getTranslateX(); final double dy = ug.getTranslateY(); ug.translate(xTheoricalPosition, yTheoricalPosition); diff --git a/src/net/sourceforge/plantuml/posimo/Frame.java b/src/net/sourceforge/plantuml/posimo/Frame.java index 6195531cf..e44eee959 100644 --- a/src/net/sourceforge/plantuml/posimo/Frame.java +++ b/src/net/sourceforge/plantuml/posimo/Frame.java @@ -33,8 +33,6 @@ */ package net.sourceforge.plantuml.posimo; -import java.awt.Color; -import java.awt.Font; import java.awt.geom.Dimension2D; import java.util.List; @@ -43,12 +41,14 @@ import net.sourceforge.plantuml.FontParam; import net.sourceforge.plantuml.ISkinParam; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +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.skin.Component; import net.sourceforge.plantuml.skin.Context2D; import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UPolygon; import net.sourceforge.plantuml.ugraphic.URectangle; @@ -56,7 +56,7 @@ import net.sourceforge.plantuml.ugraphic.UStroke; public class Frame implements Component { - private final List name; + private final List name; private final ISkinParam skinParam; private final Rose rose = new Rose(); @@ -64,7 +64,7 @@ public class Frame implements Component { // private final Color lineColor; // private final Font font; - public Frame(List name, ISkinParam skinParam) { + public Frame(List name, ISkinParam skinParam) { this.name = name; this.skinParam = skinParam; // this.textColor = textColor; @@ -73,7 +73,7 @@ public class Frame implements Component { } public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) { - final Color lineColor = rose.getHtmlColor(skinParam, ColorParam.packageBorder).getColor(); + final HtmlColor lineColor = rose.getHtmlColor(skinParam, ColorParam.packageBorder); ug.getParam().setColor(lineColor); ug.getParam().setBackcolor(null); ug.getParam().setStroke(new UStroke(1.4)); @@ -115,8 +115,8 @@ public class Frame implements Component { } private TextBlock createTextBloc() { - final Font font = skinParam.getFont(FontParam.PACKAGE, null); - final Color textColor = skinParam.getFontHtmlColor(FontParam.PACKAGE, null).getColor(); + final UFont font = skinParam.getFont(FontParam.PACKAGE, null); + final HtmlColor textColor = skinParam.getFontHtmlColor(FontParam.PACKAGE, null); final TextBlock bloc = TextBlockUtils.create(name, new FontConfiguration(font, textColor), HorizontalAlignement.LEFT); return bloc; diff --git a/src/net/sourceforge/plantuml/posimo/GraphvizSolverB.java b/src/net/sourceforge/plantuml/posimo/GraphvizSolverB.java index 6bbe4bca7..6c53c82e0 100644 --- a/src/net/sourceforge/plantuml/posimo/GraphvizSolverB.java +++ b/src/net/sourceforge/plantuml/posimo/GraphvizSolverB.java @@ -35,6 +35,7 @@ package net.sourceforge.plantuml.posimo; import java.awt.geom.Dimension2D; import java.awt.geom.Point2D; +import java.io.BufferedOutputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; @@ -101,7 +102,7 @@ public class GraphvizSolverB { final Graphviz graphviz = GraphvizUtils.create(dotString, "svg"); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - graphviz.createPng(baos); + graphviz.createFile(baos); baos.close(); final byte[] result = baos.toByteArray(); final String s = new String(result, "UTF-8"); @@ -170,15 +171,11 @@ public class GraphvizSolverB { p.setLabelPosition(x, y); minMax.manage(x, y); } - } - - System.err.println("minMax=" + minMax); - return new Dimension2DDouble(width, height); } - private List extractPointsList(final String svg, final int starting) { + static private List extractPointsList(final String svg, final int starting) { final String pointsString = "points=\""; final int p2 = svg.indexOf(pointsString, starting); final int p3 = svg.indexOf("\"", p2 + pointsString.length()); @@ -187,7 +184,7 @@ public class GraphvizSolverB { return pointsList; } - private double getMaxX(List points) { + static private double getMaxX(List points) { double result = points.get(0).x; for (int i = 1; i < points.size(); i++) { if (points.get(i).x > result) { @@ -197,7 +194,7 @@ public class GraphvizSolverB { return result; } - private double getMinX(List points) { + static private double getMinX(List points) { double result = points.get(0).x; for (int i = 1; i < points.size(); i++) { if (points.get(i).x < result) { @@ -207,7 +204,7 @@ public class GraphvizSolverB { return result; } - private double getMaxY(List points) { + static private double getMaxY(List points) { double result = points.get(0).y; for (int i = 1; i < points.size(); i++) { if (points.get(i).y > result) { @@ -217,7 +214,7 @@ public class GraphvizSolverB { return result; } - private double getMinY(List points) { + static private double getMinY(List points) { double result = points.get(0).y; for (int i = 1; i < points.size(); i++) { if (points.get(i).y < result) { @@ -227,7 +224,7 @@ public class GraphvizSolverB { return result; } - private List getPoints(String points) { + static private List getPoints(String points) { final List result = new ArrayList(); final StringTokenizer st = new StringTokenizer(points, " "); while (st.hasMoreTokens()) { @@ -242,8 +239,8 @@ public class GraphvizSolverB { private void exportPng(final String dotString, File f) throws IOException, InterruptedException { final Graphviz graphviz = GraphvizUtils.create(dotString, "png"); - final OutputStream os = new FileOutputStream(f); - graphviz.createPng(os); + final OutputStream os = new BufferedOutputStream(new FileOutputStream(f)); + graphviz.createFile(os); os.close(); } diff --git a/src/net/sourceforge/plantuml/posimo/IEntityImageBlock.java b/src/net/sourceforge/plantuml/posimo/IEntityImageBlock.java index 616786129..564317d19 100644 --- a/src/net/sourceforge/plantuml/posimo/IEntityImageBlock.java +++ b/src/net/sourceforge/plantuml/posimo/IEntityImageBlock.java @@ -44,5 +44,4 @@ public interface IEntityImageBlock { void drawU(UGraphic ug, double xTheoricalPosition, double yTheoricalPosition, double marginWidth, double marginHeight); - } \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/posimo/LabelImage.java b/src/net/sourceforge/plantuml/posimo/LabelImage.java index 0990209b6..529171d36 100644 --- a/src/net/sourceforge/plantuml/posimo/LabelImage.java +++ b/src/net/sourceforge/plantuml/posimo/LabelImage.java @@ -33,7 +33,6 @@ */ package net.sourceforge.plantuml.posimo; -import java.awt.Color; import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.FontParam; @@ -42,6 +41,7 @@ import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.cucadiagram.Link; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; @@ -63,7 +63,7 @@ public class LabelImage { this.param = param; this.rose = rose; this.name = TextBlockUtils.create(StringUtils.getWithNewlines(link.getLabel()), - new FontConfiguration(param.getFont(FontParam.CLASS, null), Color.BLACK), HorizontalAlignement.CENTER); + new FontConfiguration(param.getFont(FontParam.CLASS, null), HtmlColor.BLACK), HorizontalAlignement.CENTER); } public Dimension2D getDimension(StringBounder stringBounder) { diff --git a/src/net/sourceforge/plantuml/posimo/PathDrawerInterface.java b/src/net/sourceforge/plantuml/posimo/PathDrawerInterface.java index 5f640d075..69c88775e 100644 --- a/src/net/sourceforge/plantuml/posimo/PathDrawerInterface.java +++ b/src/net/sourceforge/plantuml/posimo/PathDrawerInterface.java @@ -128,13 +128,13 @@ public class PathDrawerInterface implements PathDrawer { final Map all = dotPath.somePoints(); final Point2D p = getFarest(outPoint, inPoint, all.keySet()); - ug.getParam().setBackcolor(rose.getHtmlColor(param, ColorParam.background).getColor()); - ug.getParam().setColor(rose.getHtmlColor(param, ColorParam.classBorder).getColor()); + ug.getParam().setBackcolor(rose.getHtmlColor(param, ColorParam.background)); + ug.getParam().setColor(rose.getHtmlColor(param, ColorParam.classBorder)); decor.drawDecor(ug, p, all.get(p)); } - ug.getParam().setColor(rose.getHtmlColor(param, ColorParam.classBorder).getColor()); + ug.getParam().setColor(rose.getHtmlColor(param, ColorParam.classBorder)); if (linkType.isDashed()) { goDash(ug); } @@ -165,18 +165,18 @@ public class PathDrawerInterface implements PathDrawer { } else if (decor == LinkDecor.EXTENDS) { middle1 = drawExtends(ug, position.getX(), position.getY(), theta); } else if (decor == LinkDecor.AGREGATION) { - ug.getParam().setBackcolor(rose.getHtmlColor(param, ColorParam.background).getColor()); - ug.getParam().setColor(rose.getHtmlColor(param, ColorParam.classBorder).getColor()); + ug.getParam().setBackcolor(rose.getHtmlColor(param, ColorParam.background)); + ug.getParam().setColor(rose.getHtmlColor(param, ColorParam.classBorder)); middle1 = drawDiamond(ug, position.getX(), position.getY(), theta); } else if (decor == LinkDecor.COMPOSITION) { - ug.getParam().setBackcolor(rose.getHtmlColor(param, ColorParam.classBorder).getColor()); + ug.getParam().setBackcolor(rose.getHtmlColor(param, ColorParam.classBorder)); ug.getParam().setColor(null); middle1 = drawDiamond(ug, position.getX(), position.getY(), theta); } else if (decor == LinkDecor.NONE) { middle1 = position; } else if (decor == LinkDecor.ARROW) { - ug.getParam().setBackcolor(rose.getHtmlColor(param, ColorParam.classBorder).getColor()); - ug.getParam().setColor(rose.getHtmlColor(param, ColorParam.classBorder).getColor()); + ug.getParam().setBackcolor(rose.getHtmlColor(param, ColorParam.classBorder)); + ug.getParam().setColor(rose.getHtmlColor(param, ColorParam.classBorder)); middle1 = drawArrow(ug, position.getX(), position.getY(), theta); } return middle1; @@ -209,8 +209,8 @@ public class PathDrawerInterface implements PathDrawer { } private Point2D drawSquare(UGraphic ug, double centerX, double centerY) { - ug.getParam().setBackcolor(rose.getHtmlColor(param, ColorParam.classBackground).getColor()); - ug.getParam().setColor(rose.getHtmlColor(param, ColorParam.classBorder).getColor()); + ug.getParam().setBackcolor(rose.getHtmlColor(param, ColorParam.classBackground)); + ug.getParam().setColor(rose.getHtmlColor(param, ColorParam.classBorder)); final double width = 10; final double height = 10; ug.draw(centerX - width / 2, centerY - height / 2, new URectangle(width, height)); @@ -218,8 +218,8 @@ public class PathDrawerInterface implements PathDrawer { } Point2D drawExtends(UGraphic ug, double x, double y, double theta) { - ug.getParam().setBackcolor(rose.getHtmlColor(param, ColorParam.background).getColor()); - ug.getParam().setColor(rose.getHtmlColor(param, ColorParam.classBorder).getColor()); + ug.getParam().setBackcolor(rose.getHtmlColor(param, ColorParam.background)); + ug.getParam().setColor(rose.getHtmlColor(param, ColorParam.classBorder)); final double width = 18; final double height = 26; diff --git a/src/net/sourceforge/plantuml/postit/PostIt.java b/src/net/sourceforge/plantuml/postit/PostIt.java index 3a17d596d..a8879ee1a 100644 --- a/src/net/sourceforge/plantuml/postit/PostIt.java +++ b/src/net/sourceforge/plantuml/postit/PostIt.java @@ -33,8 +33,6 @@ */ package net.sourceforge.plantuml.postit; -import java.awt.Color; -import java.awt.Font; import java.awt.geom.Dimension2D; import java.util.Collections; import java.util.List; @@ -47,6 +45,7 @@ import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.Component; import net.sourceforge.plantuml.skin.SimpleContext2D; import net.sourceforge.plantuml.skin.rose.ComponentRoseNote; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; public class PostIt { @@ -102,12 +101,12 @@ public class PostIt { } private Component getComponent() { - final Color noteBackgroundColor = HtmlColor.getColorIfValid("#FBFB77").getColor(); - final Color borderColor = HtmlColor.getColorIfValid("#A80036").getColor(); + final HtmlColor noteBackgroundColor = HtmlColor.getColorIfValid("#FBFB77"); + final HtmlColor borderColor = HtmlColor.getColorIfValid("#A80036"); final SkinParam param = new SkinParam(); - final Font fontNote = param.getFont(FontParam.NOTE, null); - final ComponentRoseNote note = new ComponentRoseNote(noteBackgroundColor, borderColor, Color.BLACK, fontNote, + final UFont fontNote = param.getFont(FontParam.NOTE, null); + final ComponentRoseNote note = new ComponentRoseNote(noteBackgroundColor, borderColor, HtmlColor.BLACK, fontNote, text); return note; } diff --git a/src/net/sourceforge/plantuml/postit/PostItDiagram.java b/src/net/sourceforge/plantuml/postit/PostItDiagram.java index dfbb8f29d..98f535900 100644 --- a/src/net/sourceforge/plantuml/postit/PostItDiagram.java +++ b/src/net/sourceforge/plantuml/postit/PostItDiagram.java @@ -49,6 +49,7 @@ import net.sourceforge.plantuml.UmlDiagram; import net.sourceforge.plantuml.UmlDiagramType; import net.sourceforge.plantuml.png.PngIO; import net.sourceforge.plantuml.sequencediagram.graphic.SequenceDiagramFileMaker; +import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.eps.UGraphicEps; import net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d; @@ -66,7 +67,8 @@ public class PostItDiagram extends UmlDiagram { } @Override - final protected void exportDiagramInternal(OutputStream os, StringBuilder cmap, int index, FileFormatOption fileFormatOption, List flashcodes) throws IOException { + final protected void exportDiagramInternal(OutputStream os, StringBuilder cmap, int index, + FileFormatOption fileFormatOption, List flashcodes) throws IOException { final UGraphic ug = createImage(fileFormatOption); drawU(ug); if (ug instanceof UGraphicG2d) { @@ -81,20 +83,6 @@ public class PostItDiagram extends UmlDiagram { } } -// public List createFiles(File suggestedFile, FileFormatOption fileFormatOption) throws IOException, -// InterruptedException { -// OutputStream os = null; -// try { -// os = new FileOutputStream(suggestedFile); -// createFile(os, 0, fileFormatOption); -// } finally { -// if (os != null) { -// os.close(); -// } -// } -// return Arrays.asList(suggestedFile); -// } - public String getDescription() { return "Board of post-it"; } @@ -122,7 +110,8 @@ public class PostItDiagram extends UmlDiagram { } private UGraphic createImage(FileFormatOption fileFormatOption) { - final Color backColor = this.getSkinParam().getBackgroundColor().getColor(); + final Color backColor = getSkinParam().getColorMapper() + .getMappedColor(this.getSkinParam().getBackgroundColor()); final FileFormat fileFormat = fileFormatOption.getFileFormat(); if (fileFormat == FileFormat.PNG) { final double height = getDefaultArea().heightWhenWidthIs(width, @@ -131,7 +120,7 @@ public class PostItDiagram extends UmlDiagram { final Graphics2D graphics2D = builder.getGraphics2D(); final double dpiFactor = this.getDpiFactor(fileFormatOption); - return new UGraphicG2d(graphics2D, builder.getBufferedImage(), dpiFactor); + return new UGraphicG2d(new ColorMapperIdentity(), graphics2D, builder.getBufferedImage(), dpiFactor); } throw new UnsupportedOperationException(); } diff --git a/src/net/sourceforge/plantuml/preproc/Preprocessor.java b/src/net/sourceforge/plantuml/preproc/Preprocessor.java index c2a497e21..b9560cdc7 100644 --- a/src/net/sourceforge/plantuml/preproc/Preprocessor.java +++ b/src/net/sourceforge/plantuml/preproc/Preprocessor.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6107 $ + * Revision $Revision: 6502 $ * */ package net.sourceforge.plantuml.preproc; @@ -48,9 +48,9 @@ public class Preprocessor implements ReadLine { private final PreprocessorInclude rawSource; private final IfManager source; - public Preprocessor(ReadLine reader, Defines defines, Set filesUsed) { + public Preprocessor(ReadLine reader, Defines defines, Set filesUsed, File newCurrentDir) { this.defines = defines; - this.rawSource = new PreprocessorInclude(reader, filesUsed); + this.rawSource = new PreprocessorInclude(reader, filesUsed, newCurrentDir); this.source = new IfManager(rawSource, defines); } diff --git a/src/net/sourceforge/plantuml/preproc/PreprocessorInclude.java b/src/net/sourceforge/plantuml/preproc/PreprocessorInclude.java index 4bcafb16c..cece337cf 100644 --- a/src/net/sourceforge/plantuml/preproc/PreprocessorInclude.java +++ b/src/net/sourceforge/plantuml/preproc/PreprocessorInclude.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6338 $ + * Revision $Revision: 6502 $ * */ package net.sourceforge.plantuml.preproc; @@ -51,11 +51,24 @@ class PreprocessorInclude implements ReadLine { private PreprocessorInclude included = null; + private final File oldCurrentDir; private final Set filesUsed; - public PreprocessorInclude(ReadLine reader, Set filesUsed) { + public PreprocessorInclude(ReadLine reader, Set filesUsed, File newCurrentDir) { this.reader2 = reader; this.filesUsed = filesUsed; + if (newCurrentDir == null) { + oldCurrentDir = null; + } else { + oldCurrentDir = FileSystem.getInstance().getCurrentDir(); + FileSystem.getInstance().setCurrentDir(newCurrentDir); + } + } + + private void restoreCurrentDir() { + if (oldCurrentDir != null) { + FileSystem.getInstance().setCurrentDir(oldCurrentDir); + } } public String readLine() throws IOException { @@ -94,7 +107,7 @@ class PreprocessorInclude implements ReadLine { final File f = FileSystem.getInstance().getFile(fileName); if (f.exists()) { filesUsed.add(f); - included = new PreprocessorInclude(getReaderInclude(f, suf), filesUsed); + included = new PreprocessorInclude(getReaderInclude(f, suf), filesUsed, f.getParentFile()); } else { return "Cannot include " + f.getAbsolutePath(); } @@ -117,6 +130,7 @@ class PreprocessorInclude implements ReadLine { } public void close() throws IOException { + restoreCurrentDir(); reader2.close(); } diff --git a/src/net/sourceforge/plantuml/printskin/PrintSkin.java b/src/net/sourceforge/plantuml/printskin/PrintSkin.java index 237722650..487646e58 100644 --- a/src/net/sourceforge/plantuml/printskin/PrintSkin.java +++ b/src/net/sourceforge/plantuml/printskin/PrintSkin.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6453 $ + * Revision $Revision: 6591 $ * */ package net.sourceforge.plantuml.printskin; @@ -49,6 +49,7 @@ import net.sourceforge.plantuml.FileFormatOption; import net.sourceforge.plantuml.SkinParam; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; import net.sourceforge.plantuml.png.PngIO; @@ -57,13 +58,15 @@ import net.sourceforge.plantuml.skin.ComponentType; import net.sourceforge.plantuml.skin.SimpleContext2D; import net.sourceforge.plantuml.skin.Skin; import net.sourceforge.plantuml.skin.SkinUtils; +import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.URectangle; import net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d; class PrintSkin extends AbstractPSystem { - private static final Font FONT1 = new Font("SansSerif", Font.PLAIN, 10); + private static final UFont FONT1 = new UFont("SansSerif", Font.PLAIN, 10); final private Skin skin; final private List toPrint; @@ -93,7 +96,7 @@ class PrintSkin extends AbstractPSystem { final BufferedImage im = builder.getBufferedImage(); final Graphics2D g2d = builder.getGraphics2D(); - ug = new UGraphicG2d(g2d, null, 1.0); + ug = new UGraphicG2d(new ColorMapperIdentity(), g2d, null, 1.0); for (ComponentType type : ComponentType.all()) { printComponent(type); @@ -126,8 +129,8 @@ class PrintSkin extends AbstractPSystem { if (width == 0) { width = 42; } - ug.getParam().setColor(Color.LIGHT_GRAY); - ug.getParam().setBackcolor(Color.LIGHT_GRAY); + ug.getParam().setColor(HtmlColor.LIGHT_GRAY); + ug.getParam().setBackcolor(HtmlColor.LIGHT_GRAY); ug.draw(xpos - 1, ypos - 1, new URectangle(width + 2, height + 2)); // g2d.drawRect((int) xpos - 1, (int) ypos - 1, (int) width + 2, (int) height + 2); @@ -143,7 +146,7 @@ class PrintSkin extends AbstractPSystem { } private void println(String s) { - final TextBlock textBlock = TextBlockUtils.create(Arrays.asList(s), new FontConfiguration(FONT1, Color.BLACK), + final TextBlock textBlock = TextBlockUtils.create(Arrays.asList(s), new FontConfiguration(FONT1, HtmlColor.BLACK), HorizontalAlignement.LEFT); textBlock.drawU(ug, xpos, ypos); ypos += textBlock.calculateDimension(ug.getStringBounder()).getHeight(); diff --git a/src/net/sourceforge/plantuml/printskin/PrintSkinFactory.java b/src/net/sourceforge/plantuml/printskin/PrintSkinFactory.java index d68a0ef23..b60b4b24e 100644 --- a/src/net/sourceforge/plantuml/printskin/PrintSkinFactory.java +++ b/src/net/sourceforge/plantuml/printskin/PrintSkinFactory.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6341 $ + * Revision $Revision: 6750 $ * */ package net.sourceforge.plantuml.printskin; @@ -44,13 +44,7 @@ public class PrintSkinFactory implements PSystemBasicFactory { private PrintSkin system; - // private List cmds; - - public PrintSkinFactory() { - reset(); - } - - public void reset() { + public void init(String startLine) { } public PrintSkin getSystem() { diff --git a/src/net/sourceforge/plantuml/project/PSystemProject.java b/src/net/sourceforge/plantuml/project/PSystemProject.java index 9952ccac2..b3627e948 100644 --- a/src/net/sourceforge/plantuml/project/PSystemProject.java +++ b/src/net/sourceforge/plantuml/project/PSystemProject.java @@ -43,10 +43,13 @@ import net.sourceforge.plantuml.AbstractPSystem; import net.sourceforge.plantuml.EmptyImageBuilder; import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.eps.EpsStrategy; import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.png.PngIO; import net.sourceforge.plantuml.project.graphic.GanttDiagram; +import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity; import net.sourceforge.plantuml.ugraphic.eps.UGraphicEps; import net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d; import net.sourceforge.plantuml.ugraphic.svg.UGraphicSvg; @@ -55,6 +58,7 @@ public class PSystemProject extends AbstractPSystem { private final Project project = new Project(); private final Color background = Color.WHITE; + private final ColorMapper colorMapper = new ColorMapperIdentity(); public int getNbImages() { return 1; @@ -72,11 +76,15 @@ public class PSystemProject extends AbstractPSystem { final BufferedImage im = createImage(diagram); PngIO.write(im, os, getMetadata(), 96); } else if (fileFormat == FileFormat.SVG) { - final UGraphicSvg svg = new UGraphicSvg(HtmlColor.getAsHtml(background), false); + final UGraphicSvg svg = new UGraphicSvg(colorMapper, StringUtils.getAsHtml(background), false); diagram.draw(svg, 0, 0); svg.createXml(os); } else if (fileFormat == FileFormat.EPS) { - final UGraphicEps eps = new UGraphicEps(EpsStrategy.getDefault()); + final UGraphicEps eps = new UGraphicEps(colorMapper, EpsStrategy.getDefault2()); + diagram.draw(eps, 0, 0); + os.write(eps.getEPSCode().getBytes()); + } else if (fileFormat == FileFormat.EPS_TEXT) { + final UGraphicEps eps = new UGraphicEps(colorMapper, EpsStrategy.WITH_MACRO_AND_TEXT); diagram.draw(eps, 0, 0); os.write(eps.getEPSCode().getBytes()); } else { @@ -87,7 +95,7 @@ public class PSystemProject extends AbstractPSystem { private BufferedImage createImage(GanttDiagram diagram) { EmptyImageBuilder builder = new EmptyImageBuilder(10, 10, background); Graphics2D g2d = builder.getGraphics2D(); - UGraphicG2d ug = new UGraphicG2d(g2d, null, 1.0); + UGraphicG2d ug = new UGraphicG2d(colorMapper, g2d, null, 1.0); final double height = diagram.getHeight(ug.getStringBounder()); final double width = diagram.getWidth(ug.getStringBounder()); @@ -98,7 +106,7 @@ public class PSystemProject extends AbstractPSystem { final BufferedImage im = builder.getBufferedImage(); g2d = builder.getGraphics2D(); - ug = new UGraphicG2d(g2d, im, 1.0); + ug = new UGraphicG2d(colorMapper, g2d, im, 1.0); diagram.draw(ug, 0, 0); g2d.dispose(); return im; diff --git a/src/net/sourceforge/plantuml/project/graphic/GanttDiagram.java b/src/net/sourceforge/plantuml/project/graphic/GanttDiagram.java index f06868959..5dfe6624e 100644 --- a/src/net/sourceforge/plantuml/project/graphic/GanttDiagram.java +++ b/src/net/sourceforge/plantuml/project/graphic/GanttDiagram.java @@ -33,10 +33,10 @@ */ package net.sourceforge.plantuml.project.graphic; -import java.awt.Color; import java.util.Map; import java.util.SortedMap; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.project.Instant; import net.sourceforge.plantuml.project.Item; @@ -89,22 +89,22 @@ public class GanttDiagram { } else { rect = new URectangle(x2 - x1, 3); } - ug.getParam().setColor(Color.GREEN); - ug.getParam().setBackcolor(Color.GRAY); + ug.getParam().setColor(HtmlColor.GREEN); + ug.getParam().setBackcolor(HtmlColor.GRAY); ug.draw(x0start + x1, yitem, rect); } drawGrid(ug, x + x0start, y + timeScaleHeight, pos); - ug.getParam().setColor(Color.BLACK); + ug.getParam().setColor(HtmlColor.BLACK); ug.getParam().setBackcolor(null); timeScale.draw(ug, x + x0start, y); itemHeader.draw(ug, x, y + timeScaleHeight); } - private final Color lightGray = new Color(200, 200, 200); + private final HtmlColor lightGray = HtmlColor.getColorIfValid("#C8C8C8"); private void drawGrid(UGraphic ug, double x, double y, SortedMap pos) { final ULine line = new ULine(0, itemHeader.getHeight(ug.getStringBounder())); @@ -114,7 +114,7 @@ public class GanttDiagram { if (last == null || last.next(null).equals(ent.getKey())) { ug.getParam().setColor(lightGray); } else { - ug.getParam().setColor(Color.BLACK); + ug.getParam().setColor(HtmlColor.BLACK); } ug.draw(x + xcur, y, line); last = ent.getKey(); diff --git a/src/net/sourceforge/plantuml/project/graphic/ItemHeader.java b/src/net/sourceforge/plantuml/project/graphic/ItemHeader.java index b9b85f0c4..7af9fa67c 100644 --- a/src/net/sourceforge/plantuml/project/graphic/ItemHeader.java +++ b/src/net/sourceforge/plantuml/project/graphic/ItemHeader.java @@ -33,27 +33,28 @@ */ package net.sourceforge.plantuml.project.graphic; -import java.awt.Color; import java.awt.Font; import java.awt.geom.Dimension2D; import java.util.Arrays; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +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.project.Item; import net.sourceforge.plantuml.project.Project; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.ULine; import net.sourceforge.plantuml.ugraphic.URectangle; class ItemHeader { - private final Font font = new Font("Serif", Font.PLAIN, 9); + private final UFont font = new UFont("Serif", Font.PLAIN, 9); private final Project project; - private final FontConfiguration fontConfig = new FontConfiguration(font, Color.BLACK); + private final FontConfiguration fontConfig = new FontConfiguration(font, HtmlColor.BLACK); public ItemHeader(Project project) { this.project = project; @@ -63,7 +64,7 @@ class ItemHeader { final StringBounder stringBounder = ug.getStringBounder(); - ug.getParam().setColor(Color.BLACK); + ug.getParam().setColor(HtmlColor.BLACK); ug.draw(x, y, new URectangle(getWidth(stringBounder), getHeight(stringBounder))); for (Item it : project.getValidItems()) { diff --git a/src/net/sourceforge/plantuml/project/graphic/TimeScale.java b/src/net/sourceforge/plantuml/project/graphic/TimeScale.java index 0c5c5a451..7b69a396d 100644 --- a/src/net/sourceforge/plantuml/project/graphic/TimeScale.java +++ b/src/net/sourceforge/plantuml/project/graphic/TimeScale.java @@ -33,7 +33,6 @@ */ package net.sourceforge.plantuml.project.graphic; -import java.awt.Color; import java.awt.Font; import java.awt.geom.Dimension2D; import java.util.Arrays; @@ -43,6 +42,7 @@ import java.util.TreeMap; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; @@ -50,15 +50,16 @@ import net.sourceforge.plantuml.project.Day; import net.sourceforge.plantuml.project.Instant; import net.sourceforge.plantuml.project.Month; import net.sourceforge.plantuml.project.Project; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.ULine; import net.sourceforge.plantuml.ugraphic.URectangle; class TimeScale { - private final Font font = new Font("Serif", Font.PLAIN, 9); + private final UFont font = new UFont("Serif", Font.PLAIN, 9); private final Project project; - private final FontConfiguration fontConfig = new FontConfiguration(font, Color.BLACK); + private final FontConfiguration fontConfig = new FontConfiguration(font, HtmlColor.BLACK); public TimeScale(Project project) { this.project = project; @@ -71,7 +72,7 @@ class TimeScale { final double caseHeight = getCaseHeight(stringBounder); final int nb = getNbCase(); - ug.getParam().setColor(Color.BLACK); + ug.getParam().setColor(HtmlColor.BLACK); ug.draw(x, y, new URectangle(nb * caseWidth, monthHeight)); final Instant end = project.getEnd(); diff --git a/src/net/sourceforge/plantuml/sequencediagram/InGroupableList.java b/src/net/sourceforge/plantuml/sequencediagram/InGroupableList.java index de4e5a22b..57788048f 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/InGroupableList.java +++ b/src/net/sourceforge/plantuml/sequencediagram/InGroupableList.java @@ -69,6 +69,8 @@ public class InGroupableList implements InGroupable { public void addInGroupable(InGroupable in) { this.inGroupables.add(in); + cacheMin = null; + cacheMax = null; } public boolean isEmpty() { @@ -89,7 +91,7 @@ public class InGroupableList implements InGroupable { return sb.toString(); } - private InGroupable getMin(StringBounder stringBounder) { + private InGroupable getMinSlow(StringBounder stringBounder) { InGroupable result = null; for (InGroupable in : inGroupables) { if (result == null || in.getMinX(stringBounder) < result.getMinX(stringBounder)) { @@ -99,7 +101,7 @@ public class InGroupableList implements InGroupable { return result; } - private InGroupable getMax(StringBounder stringBounder) { + private InGroupable getMaxSlow(StringBounder stringBounder) { InGroupable result = null; for (InGroupable in : inGroupables) { if (result == null || in.getMaxX(stringBounder) > result.getMaxX(stringBounder)) { @@ -109,6 +111,26 @@ public class InGroupableList implements InGroupable { return result; } + + private InGroupable cacheMin = null; + private InGroupable cacheMax = null; + + private InGroupable getMin(StringBounder stringBounder) { + if (cacheMin == null) { + cacheMin = getMinSlow(stringBounder); + } + assert cacheMin == getMinSlow(stringBounder); + return cacheMin; + } + + private InGroupable getMax(StringBounder stringBounder) { + if (cacheMax == null) { + cacheMax = getMaxSlow(stringBounder); + } + assert cacheMax == getMaxSlow(stringBounder); + return cacheMax; + } + public void setMinWidth(double minWidth) { this.minWidth = minWidth; } diff --git a/src/net/sourceforge/plantuml/sequencediagram/Note.java b/src/net/sourceforge/plantuml/sequencediagram/Note.java index ed253611d..59c3888d0 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/Note.java +++ b/src/net/sourceforge/plantuml/sequencediagram/Note.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6486 $ + * Revision $Revision: 6575 $ * */ package net.sourceforge.plantuml.sequencediagram; @@ -108,8 +108,8 @@ public class Note implements Event, SpecificBackcolorable { return specificBackcolor; } - public void setSpecificBackcolor(String s) { - this.specificBackcolor = HtmlColor.getColorIfValid(s); + public void setSpecificBackcolor(HtmlColor color) { + this.specificBackcolor = color; } public boolean dealWith(Participant someone) { diff --git a/src/net/sourceforge/plantuml/sequencediagram/Participant.java b/src/net/sourceforge/plantuml/sequencediagram/Participant.java index 4fc454a05..3dfca07c7 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/Participant.java +++ b/src/net/sourceforge/plantuml/sequencediagram/Participant.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6482 $ + * Revision $Revision: 6575 $ * */ package net.sourceforge.plantuml.sequencediagram; @@ -119,8 +119,8 @@ public class Participant implements SpecificBackcolorable { return specificBackcolor; } - public void setSpecificBackcolor(String s) { - this.specificBackcolor = HtmlColor.getColorIfValid(s); + public void setSpecificBackcolor(HtmlColor color) { + this.specificBackcolor = color; } private Url url; diff --git a/src/net/sourceforge/plantuml/sequencediagram/Reference.java b/src/net/sourceforge/plantuml/sequencediagram/Reference.java index 4d88f566a..7cad27f34 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/Reference.java +++ b/src/net/sourceforge/plantuml/sequencediagram/Reference.java @@ -33,37 +33,32 @@ */ package net.sourceforge.plantuml.sequencediagram; +import java.util.Collections; +import java.util.Iterator; import java.util.List; import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.graphic.HtmlColor; public class Reference implements Event { - private final Participant p; - private final Participant p2; + private final List participants; private final Url url; + private final HtmlColor backColorGeneral; + private final HtmlColor backColorElement; private final List strings; - // public Reference(Participant p, List strings) { - // this.p = p; - // this.p2 = null; - // this.strings = strings; - // } - // - public Reference(Participant p, Participant p2, Url url, List strings) { - this.p = p; - this.p2 = p2; + public Reference(List participants, Url url, List strings, HtmlColor backColorGeneral, HtmlColor backColorElement) { + this.participants = participants; this.url = url; this.strings = strings; + this.backColorGeneral = backColorGeneral; + this.backColorElement = backColorElement; } - public Participant getParticipant() { - return p; - } - - public Participant getParticipant2() { - return p2; + public List getParticipant() { + return Collections.unmodifiableList(participants); } public List getStrings() { @@ -71,7 +66,7 @@ public class Reference implements Event { } public boolean dealWith(Participant someone) { - return p == someone || p2 == someone; + return participants.contains(someone); } public final Url getUrl() { @@ -80,6 +75,22 @@ public class Reference implements Event { @Override public String toString() { - return p.getCode() + "-" + p2.getCode(); + final StringBuilder sb = new StringBuilder(); + for (final Iterator it = participants.iterator(); it.hasNext();) { + sb.append(it.next().getCode()); + if (it.hasNext()) { + sb.append("-"); + } + + } + return sb.toString(); + } + + public final HtmlColor getBackColorGeneral() { + return backColorGeneral; + } + + public final HtmlColor getBackColorElement() { + return backColorElement; } } diff --git a/src/net/sourceforge/plantuml/sequencediagram/SequenceDiagram.java b/src/net/sourceforge/plantuml/sequencediagram/SequenceDiagram.java index b0b3623cf..c62071dec 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/SequenceDiagram.java +++ b/src/net/sourceforge/plantuml/sequencediagram/SequenceDiagram.java @@ -32,10 +32,13 @@ package net.sourceforge.plantuml.sequencediagram; 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; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Arrays; @@ -51,6 +54,7 @@ import net.sourceforge.plantuml.Log; import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.UmlDiagram; import net.sourceforge.plantuml.UmlDiagramType; +import net.sourceforge.plantuml.directdot.DotText; import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.sequencediagram.graphic.FileMaker; import net.sourceforge.plantuml.sequencediagram.graphic.SequenceDiagramFileMaker; @@ -167,21 +171,19 @@ public class SequenceDiagram extends UmlDiagram { return new SequenceDiagramFileMaker(this, skin, fileFormatOption, flashcodes); } - // public List exportDiagrams(File suggestedFile, FileFormatOption - // fileFormat) throws IOException { - // return - // getSequenceDiagramPngMaker(fileFormat).createManyRRMV(suggestedFile); - // } - public List exportDiagrams(File suggestedFile, FileFormatOption fileFormat) throws IOException { + if (fileFormat.getFileFormat() == FileFormat.DOT) { + return exportDot(suggestedFile); + } + final List result = new ArrayList(); final int nbImages = getNbImages(); for (int i = 0; i < nbImages; i++) { final File f = SequenceDiagramFileMaker.computeFilename(suggestedFile, i, fileFormat.getFileFormat()); Log.info("Creating file: " + f); - final FileOutputStream fos = new FileOutputStream(f); + final OutputStream fos = new BufferedOutputStream(new FileOutputStream(f)); final StringBuilder cmap = new StringBuilder(); try { exportDiagram(fos, cmap, i, fileFormat); @@ -197,12 +199,24 @@ public class SequenceDiagram extends UmlDiagram { return result; } + private List exportDot(File suggestedFile) throws IOException { + final PrintWriter pw = new PrintWriter(suggestedFile); + final List printed = Arrays + .asList("Error: Sequence diagrams do not use Dot/Graphviz : they cannot be generated as DOT files."); + final DotText dotText = new DotText(printed, HtmlColor.getColorIfValid("#33FF02"), HtmlColor.BLACK); + final StringBuilder sb = new StringBuilder(); + dotText.generateDot(sb); + pw.println(sb); + pw.close(); + return Arrays.asList(suggestedFile); + } + @Override protected void exportDiagramInternal(OutputStream os, StringBuilder cmap, int index, FileFormatOption fileFormat, List flashcodes) throws IOException { final FileMaker sequenceDiagramPngMaker = getSequenceDiagramPngMaker(fileFormat, flashcodes); sequenceDiagramPngMaker.createOne(os, index); - if (this.hasUrl() && fileFormat.getFileFormat() == FileFormat.PNG) { + if (cmap != null && this.hasUrl() && fileFormat.getFileFormat() == FileFormat.PNG) { sequenceDiagramPngMaker.appendCmap(cmap); } } diff --git a/src/net/sourceforge/plantuml/sequencediagram/SequenceDiagramFactory.java b/src/net/sourceforge/plantuml/sequencediagram/SequenceDiagramFactory.java index 4f2091146..843a130b3 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/SequenceDiagramFactory.java +++ b/src/net/sourceforge/plantuml/sequencediagram/SequenceDiagramFactory.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6475 $ + * Revision $Revision: 6494 $ * */ package net.sourceforge.plantuml.sequencediagram; @@ -60,6 +60,7 @@ import net.sourceforge.plantuml.sequencediagram.command.CommandNoteSequence; import net.sourceforge.plantuml.sequencediagram.command.CommandParticipantA; import net.sourceforge.plantuml.sequencediagram.command.CommandParticipantA2; import net.sourceforge.plantuml.sequencediagram.command.CommandParticipantA3; +import net.sourceforge.plantuml.sequencediagram.command.CommandReferenceMultilinesOverSeveral; import net.sourceforge.plantuml.sequencediagram.command.CommandReferenceOverSeveral; import net.sourceforge.plantuml.sequencediagram.command.CommandSkin; import net.sourceforge.plantuml.sequencediagram.command.CommandUrl; @@ -101,6 +102,7 @@ public class SequenceDiagramFactory extends AbstractUmlSystemCommandFactory { addCommand(new CommandAutoNewpage(system)); addCommand(new CommandDivider(system)); addCommand(new CommandReferenceOverSeveral(system)); + addCommand(new CommandReferenceMultilinesOverSeveral(system)); addCommand(new CommandSkin(system)); addCommand(new CommandAutonumber(system)); addCommand(new CommandAutoactivate(system)); diff --git a/src/net/sourceforge/plantuml/sequencediagram/command/CommandAutonumber.java b/src/net/sourceforge/plantuml/sequencediagram/command/CommandAutonumber.java index 38f902e24..31960047a 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/command/CommandAutonumber.java +++ b/src/net/sourceforge/plantuml/sequencediagram/command/CommandAutonumber.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4762 $ + * Revision $Revision: 6529 $ * */ package net.sourceforge.plantuml.sequencediagram.command; @@ -58,7 +58,12 @@ public class CommandAutonumber extends SingleLineCommand { } final String df = arg.get(2) == null ? "0" : arg.get(2); - final DecimalFormat decimalFormat = new DecimalFormat(df); + final DecimalFormat decimalFormat; + try { + decimalFormat = new DecimalFormat(df); + } catch (IllegalArgumentException e) { + return CommandExecutionResult.error("Error in pattern : " + df); + } getSystem().goAutonumber(start, inc, decimalFormat); return CommandExecutionResult.ok(); diff --git a/src/net/sourceforge/plantuml/sequencediagram/command/CommandGrouping.java b/src/net/sourceforge/plantuml/sequencediagram/command/CommandGrouping.java index 8cf13b3bc..150ec7064 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/command/CommandGrouping.java +++ b/src/net/sourceforge/plantuml/sequencediagram/command/CommandGrouping.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5533 $ + * Revision $Revision: 6551 $ * */ package net.sourceforge.plantuml.sequencediagram.command; @@ -53,14 +53,14 @@ public class CommandGrouping extends SingleLineCommand { @Override protected CommandExecutionResult executeArg(List arg) { final String type = arg.get(0).toLowerCase(); - final HtmlColor colorElement = HtmlColor.getColorIfValid(arg.get(1)); - final HtmlColor colorGeneral = HtmlColor.getColorIfValid(arg.get(2)); + final HtmlColor backColorElement = HtmlColor.getColorIfValid(arg.get(1)); + final HtmlColor backColorGeneral = HtmlColor.getColorIfValid(arg.get(2)); String comment = arg.get(3); if ("group".equals(type) && StringUtils.isEmpty(comment)) { comment = "group"; } final boolean result = getSystem().grouping(type, comment, - GroupingType.getType(type), colorGeneral, colorElement); + GroupingType.getType(type), backColorGeneral, backColorElement); if (result == false) { return CommandExecutionResult.error("Cannot create group"); } diff --git a/src/net/sourceforge/plantuml/sequencediagram/command/CommandMultilinesNote.java b/src/net/sourceforge/plantuml/sequencediagram/command/CommandMultilinesNote.java index 7094ae333..81f9aca56 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/command/CommandMultilinesNote.java +++ b/src/net/sourceforge/plantuml/sequencediagram/command/CommandMultilinesNote.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5884 $ + * Revision $Revision: 6575 $ * */ package net.sourceforge.plantuml.sequencediagram.command; @@ -38,6 +38,7 @@ import java.util.List; import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.CommandMultilines; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.sequencediagram.Note; import net.sourceforge.plantuml.sequencediagram.NotePosition; import net.sourceforge.plantuml.sequencediagram.Participant; @@ -58,7 +59,7 @@ public class CommandMultilinesNote extends CommandMultilines { final List strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1)); if (strings.size() > 0) { final Note note = new Note(p, position, strings); - note.setSpecificBackcolor(line0.get(2)); + note.setSpecificBackcolor(HtmlColor.getColorIfValid(line0.get(2))); getSystem().addNote(note); } diff --git a/src/net/sourceforge/plantuml/sequencediagram/command/CommandMultilinesNoteOnArrow.java b/src/net/sourceforge/plantuml/sequencediagram/command/CommandMultilinesNoteOnArrow.java index 9ec21d567..2eef2f3db 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/command/CommandMultilinesNoteOnArrow.java +++ b/src/net/sourceforge/plantuml/sequencediagram/command/CommandMultilinesNoteOnArrow.java @@ -28,16 +28,13 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6485 $ + * Revision $Revision: 6921 $ * */ package net.sourceforge.plantuml.sequencediagram.command; -import java.util.ArrayList; -import java.util.Iterator; import java.util.List; -import net.sourceforge.plantuml.EmbededDiagram; import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.CommandMultilines; @@ -57,25 +54,8 @@ public class CommandMultilinesNoteOnArrow extends CommandMultilines strings = new ArrayList(); - final Iterator it = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1)).iterator(); - while (it.hasNext()) { - CharSequence s = it.next(); - if (s.equals("{{")) { - final List other = new ArrayList(); - other.add("@startuml"); - while (it.hasNext()) { - String s2 = it.next(); - if (s2.equals("}}")) { - break; - } - other.add(s2); - } - other.add("@enduml"); - s = new EmbededDiagram(other); - } - strings.add(s); - } + final List in = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1)); + final List strings = StringUtils.manageEmbededDiagrams(in); m.setNote(strings, position, line0.get(1), null); } diff --git a/src/net/sourceforge/plantuml/sequencediagram/command/CommandMultilinesNoteOverSeveral.java b/src/net/sourceforge/plantuml/sequencediagram/command/CommandMultilinesNoteOverSeveral.java index 3a2fb84ea..ae1270bae 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/command/CommandMultilinesNoteOverSeveral.java +++ b/src/net/sourceforge/plantuml/sequencediagram/command/CommandMultilinesNoteOverSeveral.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5884 $ + * Revision $Revision: 6575 $ * */ package net.sourceforge.plantuml.sequencediagram.command; @@ -38,6 +38,7 @@ import java.util.List; import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.CommandMultilines; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.sequencediagram.Note; import net.sourceforge.plantuml.sequencediagram.Participant; import net.sourceforge.plantuml.sequencediagram.SequenceDiagram; @@ -57,7 +58,7 @@ public class CommandMultilinesNoteOverSeveral extends CommandMultilines strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1)); if (strings.size() > 0) { final Note note = new Note(p1, p2, strings); - note.setSpecificBackcolor(line0.get(2)); + note.setSpecificBackcolor(HtmlColor.getColorIfValid(line0.get(2))); getSystem().addNote(note); } return CommandExecutionResult.ok(); diff --git a/src/net/sourceforge/plantuml/sequencediagram/command/CommandNoteOverSeveral.java b/src/net/sourceforge/plantuml/sequencediagram/command/CommandNoteOverSeveral.java index 3541a8301..6d3f1e77d 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/command/CommandNoteOverSeveral.java +++ b/src/net/sourceforge/plantuml/sequencediagram/command/CommandNoteOverSeveral.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5884 $ + * Revision $Revision: 6575 $ * */ package net.sourceforge.plantuml.sequencediagram.command; @@ -38,6 +38,7 @@ import java.util.List; import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.SingleLineCommand; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.sequencediagram.Note; import net.sourceforge.plantuml.sequencediagram.Participant; import net.sourceforge.plantuml.sequencediagram.SequenceDiagram; @@ -54,7 +55,7 @@ public class CommandNoteOverSeveral extends SingleLineCommand { final Participant p2 = getSystem().getOrCreateParticipant(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(1))); final List strings = StringUtils.getWithNewlines(arg.get(3)); final Note note = new Note(p1, p2, strings); - note.setSpecificBackcolor(arg.get(2)); + note.setSpecificBackcolor(HtmlColor.getColorIfValid(arg.get(2))); getSystem().addNote(note); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/sequencediagram/command/CommandNoteSequence.java b/src/net/sourceforge/plantuml/sequencediagram/command/CommandNoteSequence.java index 67ff06894..e7c32cbeb 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/command/CommandNoteSequence.java +++ b/src/net/sourceforge/plantuml/sequencediagram/command/CommandNoteSequence.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5884 $ + * Revision $Revision: 6575 $ * */ package net.sourceforge.plantuml.sequencediagram.command; @@ -38,6 +38,7 @@ import java.util.List; import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.SingleLineCommand; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.sequencediagram.Note; import net.sourceforge.plantuml.sequencediagram.NotePosition; import net.sourceforge.plantuml.sequencediagram.Participant; @@ -57,7 +58,7 @@ public class CommandNoteSequence extends SingleLineCommand { final List strings = StringUtils.getWithNewlines(arg.get(3)); final Note note = new Note(p, position, strings); - note.setSpecificBackcolor(arg.get(2)); + note.setSpecificBackcolor(HtmlColor.getColorIfValid(arg.get(2))); getSystem().addNote(note); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/sequencediagram/command/CommandParticipant.java b/src/net/sourceforge/plantuml/sequencediagram/command/CommandParticipant.java index 2fa1feb77..fc93f7e37 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/command/CommandParticipant.java +++ b/src/net/sourceforge/plantuml/sequencediagram/command/CommandParticipant.java @@ -43,6 +43,7 @@ import net.sourceforge.plantuml.command.SingleLineCommand2; import net.sourceforge.plantuml.command.regex.RegexConcat; import net.sourceforge.plantuml.command.regex.RegexPartialMatch; import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.sequencediagram.Participant; import net.sourceforge.plantuml.sequencediagram.ParticipantType; import net.sourceforge.plantuml.sequencediagram.SequenceDiagram; @@ -78,7 +79,7 @@ public abstract class CommandParticipant extends SingleLineCommand2 { + + public CommandReferenceMultilinesOverSeveral(final SequenceDiagram sequenceDiagram) { + super( + sequenceDiagram, + "(?i)^ref(#\\w+)?\\s+over\\s+((?:[\\p{L}0-9_.]+|\"[^\"]+\")(?:\\s*,\\s*(?:[\\p{L}0-9_.]+|\"[^\"]+\"))*)\\s*(#\\w+)?$", + "(?i)^end ?(ref)?$"); + } + + public CommandExecutionResult execute(List lines) { + final List line0 = StringUtils.getSplit(getStartingPattern(), lines.get(0).trim()); + final HtmlColor backColorElement = HtmlColor.getColorIfValid(line0.get(0)); + // final HtmlColor backColorGeneral = HtmlColor.getColorIfValid(line0.get(1)); + final HtmlColor backColorGeneral = null; + + final List participants = StringUtils.splitComma(line0.get(1)); + final List p = new ArrayList(); + for (String s : participants) { + p.add(getSystem().getOrCreateParticipant(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(s))); + } + + List strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1)); + + Url u = null; + if (strings.size() > 0) { + u = Note.extractUrl(strings.get(0)); + } + if (u != null) { + strings = strings.subList(1, strings.size()); + } + + final Reference ref = new Reference(p, u, strings, backColorGeneral, backColorElement); + getSystem().addReference(ref); + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/sequencediagram/command/CommandReferenceOverSeveral.java b/src/net/sourceforge/plantuml/sequencediagram/command/CommandReferenceOverSeveral.java index 0a923f166..f4ad76c84 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/command/CommandReferenceOverSeveral.java +++ b/src/net/sourceforge/plantuml/sequencediagram/command/CommandReferenceOverSeveral.java @@ -33,6 +33,7 @@ */ package net.sourceforge.plantuml.sequencediagram.command; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -43,6 +44,7 @@ import net.sourceforge.plantuml.command.SingleLineCommand2; import net.sourceforge.plantuml.command.regex.RegexConcat; import net.sourceforge.plantuml.command.regex.RegexLeaf; import net.sourceforge.plantuml.command.regex.RegexPartialMatch; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.sequencediagram.Participant; import net.sourceforge.plantuml.sequencediagram.Reference; import net.sourceforge.plantuml.sequencediagram.SequenceDiagram; @@ -55,10 +57,8 @@ public class CommandReferenceOverSeveral extends SingleLineCommand2 arg) { - final String s1 = arg.get("P1").get(0); - final String s2 = arg.get("P2").get(0); + final HtmlColor backColorElement = HtmlColor.getColorIfValid(arg.get("REF").get(0)); + // final HtmlColor backColorGeneral = HtmlColor.getColorIfValid(arg.get("REF").get(1)); + final HtmlColor backColorGeneral = null; + + final List participants = StringUtils.splitComma(arg.get("PARTS").get(0)); final String url = arg.get("URL").get(0); final String title = arg.get("URL").get(1); - final String text = arg.get("TEXT").get(0); - final Participant p1 = getSystem().getOrCreateParticipant( - StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(s1)); - final Participant p2 = getSystem().getOrCreateParticipant( - StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(s2)); + final String text = arg.get("TEXT").get(0).trim(); + + final List p = new ArrayList(); + for (String s : participants) { + p.add(getSystem().getOrCreateParticipant(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(s))); + } + final List strings = StringUtils.getWithNewlines(text); Url u = null; @@ -83,7 +88,7 @@ public class CommandReferenceOverSeveral extends SingleLineCommand2\n"); } + + Participant getFirst(Collection someParticipants) { + final List list = new ArrayList(participants.keySet()); + int min = -1; + for (Participant p : someParticipants) { + final int n = list.indexOf(p); + assert n != -1; + if (min == -1 || min > n) { + min = n; + } + } + return list.get(min); + } + + Participant getLast(Collection someParticipants) { + final List list = new ArrayList(participants.keySet()); + int max = -1; + for (Participant p : someParticipants) { + final int n = list.indexOf(p); + assert n != -1; + if (max == -1 || max < n) { + max = n; + } + } + return list.get(max); + } + + } diff --git a/src/net/sourceforge/plantuml/sequencediagram/graphic/DrawableSetInitializer.java b/src/net/sourceforge/plantuml/sequencediagram/graphic/DrawableSetInitializer.java index ec696961c..7779d2813 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/graphic/DrawableSetInitializer.java +++ b/src/net/sourceforge/plantuml/sequencediagram/graphic/DrawableSetInitializer.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6485 $ + * Revision $Revision: 6665 $ * */ package net.sourceforge.plantuml.sequencediagram.graphic; @@ -41,6 +41,7 @@ import java.util.List; import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.ISkinParam; import net.sourceforge.plantuml.SkinParamBackcolored; +import net.sourceforge.plantuml.SkinParamBackcoloredReference; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.sequencediagram.Delay; import net.sourceforge.plantuml.sequencediagram.Divider; @@ -48,6 +49,7 @@ import net.sourceforge.plantuml.sequencediagram.Event; import net.sourceforge.plantuml.sequencediagram.GroupingLeaf; import net.sourceforge.plantuml.sequencediagram.GroupingStart; import net.sourceforge.plantuml.sequencediagram.GroupingType; +import net.sourceforge.plantuml.sequencediagram.InGroupable; import net.sourceforge.plantuml.sequencediagram.InGroupableList; import net.sourceforge.plantuml.sequencediagram.LifeEvent; import net.sourceforge.plantuml.sequencediagram.LifeEventType; @@ -420,17 +422,41 @@ class DrawableSetInitializer { } private void prepareReference(StringBounder stringBounder, Reference reference) { - final LivingParticipantBox p1 = drawableSet.getLivingParticipantBox(reference.getParticipant()); - final LivingParticipantBox p2 = drawableSet.getLivingParticipantBox(reference.getParticipant2()); - final GraphicalReference graphicalReference = new GraphicalReference(freeY, drawableSet.getSkin() - .createComponent(ComponentType.REFERENCE, drawableSet.getSkinParam(), reference.getStrings()), p1, p2, - reference.getUrl()); + final LivingParticipantBox p1 = drawableSet.getLivingParticipantBox(drawableSet.getFirst(reference + .getParticipant())); + final LivingParticipantBox p2 = drawableSet.getLivingParticipantBox(drawableSet.getLast(reference + .getParticipant())); + final ISkinParam skinParam = new SkinParamBackcoloredReference(drawableSet.getSkinParam(), reference + .getBackColorElement(), reference.getBackColorGeneral()); + final List strings = new ArrayList(); + strings.add("ref"); + strings.addAll(reference.getStrings()); + final Component comp = drawableSet.getSkin().createComponent(ComponentType.REFERENCE, skinParam, strings); + final GraphicalReference graphicalReference = new GraphicalReference(freeY, comp, p1, p2, reference.getUrl()); + + final ParticipantBox pbox1 = p1.getParticipantBox(); + final ParticipantBox pbox2 = p2.getParticipantBox(); final double width = graphicalReference.getPreferredWidth(stringBounder) - - p1.getParticipantBox().getPreferredWidth(stringBounder) / 2 - - p2.getParticipantBox().getPreferredWidth(stringBounder) / 2; + - pbox1.getPreferredWidth(stringBounder) / 2 - pbox2.getPreferredWidth(stringBounder) / 2; - constraintSet.getConstraint(p1.getParticipantBox(), p2.getParticipantBox()).ensureValue(width); + final Constraint constraint; + if (p1 == p2) { + constraint = constraintSet.getConstraintAfter(pbox1); + } else { + constraint = constraintSet.getConstraint(pbox1, pbox2); + } + constraint.ensureValue(width); + + if (inGroupableLists != null) { + for (InGroupableList groupingStructure : inGroupableLists) { + groupingStructure.addInGroupable(graphicalReference); + groupingStructure.addInGroupable(p1); + if (p1 != p2) { + groupingStructure.addInGroupable(p2); + } + } + } freeY += graphicalReference.getPreferredHeight(stringBounder); drawableSet.addEvent(reference, graphicalReference); diff --git a/src/net/sourceforge/plantuml/sequencediagram/graphic/LifeLine.java b/src/net/sourceforge/plantuml/sequencediagram/graphic/LifeLine.java index b48430400..dc3773bf4 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/graphic/LifeLine.java +++ b/src/net/sourceforge/plantuml/sequencediagram/graphic/LifeLine.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6054 $ + * Revision $Revision: 6698 $ * */ package net.sourceforge.plantuml.sequencediagram.graphic; @@ -71,6 +71,7 @@ class LifeLine { private final double nominalPreferredWidth; private final List events = new ArrayList(); + private final Stairs stairs = new Stairs(); private int maxLevel = 0; public LifeLine(Pushable participant, double nominalPreferredWidth) { @@ -89,6 +90,11 @@ class LifeLine { } } events.add(new Variation(type, y, backcolor)); + final int currentLevel = type.apply(stairs.getLastValue()); + stairs.addStep(y, currentLevel); + assert getLevel(y) == stairs.getValue(y); + assert currentLevel == stairs.getValue(y); + assert getLevel(y) == currentLevel; maxLevel = Math.max(getLevel(y), maxLevel); } @@ -112,22 +118,23 @@ class LifeLine { } int getLevel(double y) { - int level = 0; - for (Variation ev : events) { - if (ev.y > y) { - return level; - } - if (ev.type == LifeSegmentVariation.LARGER) { - level++; - } else { - level--; - if (level < 0) { - level = 0; - } - } - } - assert level >= 0; - return level; +// int level = 0; +// for (Variation ev : events) { +// if (ev.y > y) { +// return level; +// } +// if (ev.type == LifeSegmentVariation.LARGER) { +// level++; +// } else { +// level--; +// if (level < 0) { +// level = 0; +// } +// } +// } +// assert level >= 0; +// return level; + return stairs.getValue(y); } public int getMaxLevel() { diff --git a/src/net/sourceforge/plantuml/sequencediagram/graphic/LifeSegmentVariation.java b/src/net/sourceforge/plantuml/sequencediagram/graphic/LifeSegmentVariation.java index 329d04399..431343ea9 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/graphic/LifeSegmentVariation.java +++ b/src/net/sourceforge/plantuml/sequencediagram/graphic/LifeSegmentVariation.java @@ -28,12 +28,23 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3836 $ + * Revision $Revision: 6696 $ * */ package net.sourceforge.plantuml.sequencediagram.graphic; enum LifeSegmentVariation { - LARGER, SMALLER + LARGER, SMALLER; + + public int apply(int v) { + if (this == LARGER) { + return v + 1; + } + assert this == SMALLER; + if (v == 0) { + return 0; + } + return v - 1; + } } diff --git a/src/net/sourceforge/plantuml/sequencediagram/graphic/Page.java b/src/net/sourceforge/plantuml/sequencediagram/graphic/Page.java index 5d28dee5b..c56b2ee2d 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/graphic/Page.java +++ b/src/net/sourceforge/plantuml/sequencediagram/graphic/Page.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4822 $ + * Revision $Revision: 6922 $ * */ package net.sourceforge.plantuml.sequencediagram.graphic; @@ -42,7 +42,7 @@ public final class Page { private final double newpage2; private final double tailHeight; private final double signatureHeight; - private final List title; + private final List title; @Override public String toString() { @@ -50,7 +50,7 @@ public final class Page { } public Page(double headerHeight, double newpage1, double newpage2, double tailHeight, - double signatureHeight, List title) { + double signatureHeight, List title) { if (headerHeight < 0) { throw new IllegalArgumentException(); } @@ -114,7 +114,7 @@ public final class Page { return headerHeight; } - public final List getTitle() { + public final List getTitle() { return title; } diff --git a/src/net/sourceforge/plantuml/sequencediagram/graphic/PageSplitter.java b/src/net/sourceforge/plantuml/sequencediagram/graphic/PageSplitter.java index 2345789f0..bf27b7ffc 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/graphic/PageSplitter.java +++ b/src/net/sourceforge/plantuml/sequencediagram/graphic/PageSplitter.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4935 $ + * Revision $Revision: 6922 $ * */ package net.sourceforge.plantuml.sequencediagram.graphic; @@ -49,10 +49,10 @@ class PageSplitter { private final double tailHeight; private final double signatureHeight; private final double newpageHeight; - private final List diagramTitle; + private final List diagramTitle; PageSplitter(double fullHeight, double headerHeight, Map newpages, double tailHeight, - double signatureHeight, double newpageHeight, List diagramTitle) { + double signatureHeight, double newpageHeight, List diagramTitle) { this.fullHeight = fullHeight; this.diagramTitle = diagramTitle; this.titles = new ArrayList>(); diff --git a/src/net/sourceforge/plantuml/sequencediagram/graphic/SequenceDiagramFileMaker.java b/src/net/sourceforge/plantuml/sequencediagram/graphic/SequenceDiagramFileMaker.java index 15fdb51a4..13d207e70 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/graphic/SequenceDiagramFileMaker.java +++ b/src/net/sourceforge/plantuml/sequencediagram/graphic/SequenceDiagramFileMaker.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6466 $ + * Revision $Revision: 6922 $ * */ package net.sourceforge.plantuml.sequencediagram.graphic; @@ -52,6 +52,7 @@ import net.sourceforge.plantuml.EmptyImageBuilder; import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.FileFormatOption; import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.eps.EpsStrategy; import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; @@ -91,15 +92,13 @@ public class SequenceDiagramFileMaker implements FileMaker { private final List pages; private final FileFormatOption fileFormatOption; private final List flashcodes; - + private int offsetX; private int offsetY; - - public SequenceDiagramFileMaker(SequenceDiagram sequenceDiagram, Skin skin, FileFormatOption fileFormatOption, List flashcodes) { - HtmlColor.setForceMonochrome(sequenceDiagram.getSkinParam().isMonochrome()); + // HtmlColor.setForceMonochrome(sequenceDiagram.getSkinParam().isMonochrome()); this.flashcodes = flashcodes; this.diagram = sequenceDiagram; this.fileFormatOption = fileFormatOption; @@ -145,19 +144,19 @@ public class SequenceDiagramFileMaker implements FileMaker { } private PageSplitter create(DrawableSet drawableSet, Map positions, boolean showFootbox, - List title) { + List title) { final double headerHeight = drawableSet.getHeadHeight(dummyStringBounder); final double tailHeight = drawableSet.getTailHeight(dummyStringBounder, showFootbox); final double signatureHeight = 0; - final double newpageHeight = drawableSet.getSkin().createComponent(ComponentType.NEWPAGE, - drawableSet.getSkinParam(), Arrays.asList("")).getPreferredHeight(dummyStringBounder); + final double newpageHeight = drawableSet.getSkin() + .createComponent(ComponentType.NEWPAGE, drawableSet.getSkinParam(), Arrays.asList("")) + .getPreferredHeight(dummyStringBounder); return new PageSplitter(fullDimension.getHeight(), headerHeight, positions, tailHeight, signatureHeight, newpageHeight, title); } - public void createOne(OutputStream os, int index) throws IOException { final UGraphic createImage = createImage((int) fullDimension.getWidth(), pages.get(index), index); if (createImage instanceof UGraphicG2d) { @@ -207,7 +206,7 @@ public class SequenceDiagramFileMaker implements FileMaker { } return area.getHeight() * getScale(area.getWidth(), area.getHeight()) * dpiFactor; } - + private UGraphic createImage(final int diagramWidth, final Page page, final int indice) { double delta = 0; if (indice > 0) { @@ -224,16 +223,17 @@ public class SequenceDiagramFileMaker implements FileMaker { if (page.getTitle() != null) { compTitle = drawableSet.getSkin().createComponent(ComponentType.TITLE, drawableSet.getSkinParam(), page.getTitle()); - area.setTitleArea(compTitle.getPreferredWidth(dummyStringBounder), compTitle - .getPreferredHeight(dummyStringBounder)); + area.setTitleArea(compTitle.getPreferredWidth(dummyStringBounder), + compTitle.getPreferredHeight(dummyStringBounder)); } addFooter2(area); addHeader2(area); - + offsetX = (int) Math.round(area.getSequenceAreaX()); offsetY = (int) Math.round(area.getSequenceAreaY()); - final Color backColor = diagram.getSkinParam().getBackgroundColor().getColor(); + final Color backColor = diagram.getSkinParam().getColorMapper() + .getMappedColor(diagram.getSkinParam().getBackgroundColor()); final UGraphic ug; final FileFormat fileFormat = fileFormatOption.getFileFormat(); final double dpiFactor = diagram.getDpiFactor(fileFormatOption); @@ -263,15 +263,18 @@ public class SequenceDiagramFileMaker implements FileMaker { final AffineTransform scale = graphics2D.getTransform(); scale.scale(getScale(area.getWidth(), area.getHeight()), getScale(area.getWidth(), area.getHeight())); graphics2D.setTransform(scale); - ug = new UGraphicG2d(graphics2D, builder.getBufferedImage(), dpiFactor); + ug = new UGraphicG2d(diagram.getSkinParam().getColorMapper(), graphics2D, builder.getBufferedImage(), + dpiFactor); } else if (fileFormat == FileFormat.SVG) { if (backColor.equals(Color.WHITE)) { - ug = new UGraphicSvg(false); + ug = new UGraphicSvg(diagram.getSkinParam().getColorMapper(), false); } else { - ug = new UGraphicSvg(HtmlColor.getAsHtml(backColor), false); + ug = new UGraphicSvg(diagram.getSkinParam().getColorMapper(), StringUtils.getAsHtml(backColor), false); } } else if (fileFormat == FileFormat.EPS) { - ug = new UGraphicEps(EpsStrategy.getDefault()); + ug = new UGraphicEps(diagram.getSkinParam().getColorMapper(), EpsStrategy.getDefault2()); + } else if (fileFormat == FileFormat.EPS_TEXT) { + ug = new UGraphicEps(diagram.getSkinParam().getColorMapper(), EpsStrategy.WITH_MACRO_AND_TEXT); } else { throw new UnsupportedOperationException(); } @@ -308,18 +311,18 @@ public class SequenceDiagramFileMaker implements FileMaker { } final File dir = pngFile.getParentFile(); String name = pngFile.getName(); - name = name.replaceAll("\\" + fileFormat.getFileSuffix() + "$", "_" + String.format("%03d", i) - + fileFormat.getFileSuffix()); + name = name.replaceAll("\\" + fileFormat.getFileSuffix() + "$", + "_" + String.format("%03d", i) + fileFormat.getFileSuffix()); return new File(dir, name); } private void addFooter2(SequenceDiagramArea area) { - final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.FOOTER, null).getColor(); - final String fontFamily = diagram.getSkinParam().getFontFamily(FontParam.FOOTER, null); - final int fontSize = diagram.getSkinParam().getFontSize(FontParam.FOOTER, null); - final PngTitler pngTitler = new PngTitler(titleColor, diagram.getFooter(), fontSize, fontFamily, diagram - .getFooterAlignement(), VerticalPosition.BOTTOM); + final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.FOOTER, null); + final String fontFamily = diagram.getSkinParam().getFont(FontParam.FOOTER, null).getFamily(null); + final int fontSize = diagram.getSkinParam().getFont(FontParam.FOOTER, null).getSize(); + final PngTitler pngTitler = new PngTitler(diagram.getSkinParam().getColorMapper(), titleColor, + diagram.getFooter(), fontSize, fontFamily, diagram.getFooterAlignement(), VerticalPosition.BOTTOM); final Dimension2D dim = pngTitler.getTextDimension(dummyStringBounder); if (dim != null) { area.setFooterArea(dim.getWidth(), dim.getHeight(), 3); @@ -327,11 +330,11 @@ public class SequenceDiagramFileMaker implements FileMaker { } private void addHeader2(SequenceDiagramArea area) { - final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.HEADER, null).getColor(); - final String fontFamily = diagram.getSkinParam().getFontFamily(FontParam.HEADER, null); - final int fontSize = diagram.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 String fontFamily = diagram.getSkinParam().getFont(FontParam.HEADER, null).getFamily(null); + final int fontSize = diagram.getSkinParam().getFont(FontParam.HEADER, null).getSize(); + final PngTitler pngTitler = new PngTitler(diagram.getSkinParam().getColorMapper(), titleColor, + diagram.getHeader(), fontSize, fontFamily, diagram.getHeaderAlignement(), VerticalPosition.TOP); final Dimension2D dim = pngTitler.getTextDimension(dummyStringBounder); if (dim != null) { area.setHeaderArea(dim.getWidth(), dim.getHeight(), 3); @@ -339,11 +342,11 @@ public class SequenceDiagramFileMaker implements FileMaker { } private void addFooter3(SequenceDiagramArea area, UGraphic ug) { - final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.FOOTER, null).getColor(); - final String fontFamily = diagram.getSkinParam().getFontFamily(FontParam.FOOTER, null); - final int fontSize = diagram.getSkinParam().getFontSize(FontParam.FOOTER, null); - final PngTitler pngTitler = new PngTitler(titleColor, diagram.getFooter(), fontSize, fontFamily, diagram - .getFooterAlignement(), VerticalPosition.BOTTOM); + final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.FOOTER, null); + final String fontFamily = diagram.getSkinParam().getFont(FontParam.FOOTER, null).getFamily(null); + final int fontSize = diagram.getSkinParam().getFont(FontParam.FOOTER, null).getSize(); + final PngTitler pngTitler = new PngTitler(diagram.getSkinParam().getColorMapper(), titleColor, + diagram.getFooter(), fontSize, fontFamily, diagram.getFooterAlignement(), VerticalPosition.BOTTOM); final TextBlock text = pngTitler.getTextBlock(); if (text == null) { return; @@ -352,11 +355,11 @@ public class SequenceDiagramFileMaker implements FileMaker { } private void addHeader3(SequenceDiagramArea area, UGraphic ug) { - final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.HEADER, null).getColor(); - final String fontFamily = diagram.getSkinParam().getFontFamily(FontParam.HEADER, null); - final int fontSize = diagram.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 String fontFamily = diagram.getSkinParam().getFont(FontParam.HEADER, null).getFamily(null); + final int fontSize = diagram.getSkinParam().getFont(FontParam.HEADER, null).getSize(); + final PngTitler pngTitler = new PngTitler(diagram.getSkinParam().getColorMapper(), titleColor, + diagram.getHeader(), fontSize, fontFamily, diagram.getHeaderAlignement(), VerticalPosition.TOP); final TextBlock text = pngTitler.getTextBlock(); if (text == null) { return; diff --git a/src/net/sourceforge/plantuml/sequencediagram/graphic/Stairs.java b/src/net/sourceforge/plantuml/sequencediagram/graphic/Stairs.java new file mode 100644 index 000000000..efaa0db9a --- /dev/null +++ b/src/net/sourceforge/plantuml/sequencediagram/graphic/Stairs.java @@ -0,0 +1,95 @@ +/* ======================================================================== + * 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: 6054 $ + * + */ +package net.sourceforge.plantuml.sequencediagram.graphic; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +class Stairs { + + private final List ys = new ArrayList(); + private final List values = new ArrayList(); + private final Map cache = new HashMap(); + + public void addStep(double y, int value) { + assert ys.size() == values.size(); + if (ys.size() > 0) { + final double lastY = ys.get(ys.size() - 1); + if (y < lastY) { + throw new IllegalArgumentException(); + } + if (lastY == y) { + values.set(ys.size() - 1, value); + cache.clear(); + return; + } + } + ys.add(y); + values.add(value); + cache.clear(); + } + + public int getValue(double y) { + Integer result = cache.get(y); + if (result == null) { + result = getValueSlow(y); + cache.put(y, result); + } + return result; + } + + private int getValueSlow(double y) { + final int idx = Collections.binarySearch(ys, y); + if (idx >= 0) { + return values.get(idx); + } + final int insertPoint = -idx - 1; + if (insertPoint == 0) { + return 0; + } + return values.get(insertPoint - 1); + } + + public int getLastValue() { + final int size = values.size(); + if (size == 0) { + return 0; + } + return values.get(size - 1); + } + +} diff --git a/src/net/sourceforge/plantuml/sequencediagram/graphic/Step1Message.java b/src/net/sourceforge/plantuml/sequencediagram/graphic/Step1Message.java index 5bdc3ac2f..cc6e093a2 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/graphic/Step1Message.java +++ b/src/net/sourceforge/plantuml/sequencediagram/graphic/Step1Message.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6485 $ + * Revision $Revision: 6665 $ * */ package net.sourceforge.plantuml.sequencediagram.graphic; @@ -116,6 +116,7 @@ class Step1Message extends Step1Abstract { afterMessage(getStringBounder(), lifeEvent, arrowYEndLevel + marginActivateAndDeactive - delta1); } + assert graphic instanceof InGroupable; if (groupingStructures != null && graphic instanceof InGroupable) { for (InGroupableList groupingStructure : groupingStructures) { groupingStructure.addInGroupable((InGroupable) graphic); diff --git a/src/net/sourceforge/plantuml/skin/AbstractTextualComponent.java b/src/net/sourceforge/plantuml/skin/AbstractTextualComponent.java index b9bdb19d4..b90cdc481 100644 --- a/src/net/sourceforge/plantuml/skin/AbstractTextualComponent.java +++ b/src/net/sourceforge/plantuml/skin/AbstractTextualComponent.java @@ -28,23 +28,23 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6009 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.skin; -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.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockEmpty; import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.UFont; public abstract class AbstractTextualComponent extends AbstractComponent { @@ -56,16 +56,16 @@ public abstract class AbstractTextualComponent extends AbstractComponent { private final TextBlock textBlock; - private final Font font; - private final Color fontColor; + private final UFont font; + private final HtmlColor fontColor; - public AbstractTextualComponent(CharSequence label, Color fontColor, Font font, + public AbstractTextualComponent(CharSequence label, HtmlColor fontColor, UFont font, HorizontalAlignement horizontalAlignement, int marginX1, int marginX2, int marginY) { this(Arrays.asList(label == null ? "" : label), fontColor, font, horizontalAlignement, marginX1, marginX2, marginY); } - public AbstractTextualComponent(List strings, Color fontColor, Font font, + public AbstractTextualComponent(List strings, HtmlColor fontColor, UFont font, HorizontalAlignement horizontalAlignement, int marginX1, int marginX2, int marginY) { this.font = font; this.fontColor = fontColor; @@ -127,11 +127,11 @@ public abstract class AbstractTextualComponent extends AbstractComponent { return marginY; } - final protected Font getFont() { + final protected UFont getFont() { return font; } - protected Color getFontColor() { + protected HtmlColor getFontColor() { return fontColor; } diff --git a/src/net/sourceforge/plantuml/skin/CircleInterface.java b/src/net/sourceforge/plantuml/skin/CircleInterface.java index 1aaf23eb0..54676d324 100644 --- a/src/net/sourceforge/plantuml/skin/CircleInterface.java +++ b/src/net/sourceforge/plantuml/skin/CircleInterface.java @@ -28,13 +28,12 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5343 $ + * Revision $Revision: 6576 $ * */ package net.sourceforge.plantuml.skin; -import java.awt.Color; - +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.ugraphic.UEllipse; import net.sourceforge.plantuml.ugraphic.UGraphic; @@ -44,14 +43,14 @@ public class CircleInterface implements UDrawable { private final float thickness; private final double headDiam; - private final Color backgroundColor; - private final Color foregroundColor; + private final HtmlColor backgroundColor; + private final HtmlColor foregroundColor; - public CircleInterface(Color backgroundColor, Color foregroundColor) { + public CircleInterface(HtmlColor backgroundColor, HtmlColor foregroundColor) { this(backgroundColor, foregroundColor, 16, 2); } - public CircleInterface(Color backgroundColor, Color foregroundColor, double headDiam, float thickness) { + public CircleInterface(HtmlColor backgroundColor, HtmlColor foregroundColor, double headDiam, float thickness) { this.backgroundColor = backgroundColor; this.foregroundColor = foregroundColor; this.headDiam = headDiam; diff --git a/src/net/sourceforge/plantuml/skin/GrayComponent.java b/src/net/sourceforge/plantuml/skin/GrayComponent.java index 6123f9ca8..297057067 100644 --- a/src/net/sourceforge/plantuml/skin/GrayComponent.java +++ b/src/net/sourceforge/plantuml/skin/GrayComponent.java @@ -28,12 +28,11 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6009 $ + * Revision $Revision: 6591 $ * */ package net.sourceforge.plantuml.skin; -import java.awt.Color; import java.awt.Font; import java.awt.geom.Dimension2D; import java.util.ArrayList; @@ -41,15 +40,17 @@ import java.util.List; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +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; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.URectangle; class GrayComponent extends AbstractComponent { - private static final Font NORMAL = new Font("SansSerif", Font.PLAIN, 7); + private static final UFont NORMAL = new UFont("SansSerif", Font.PLAIN, 7); private final ComponentType type; @@ -60,8 +61,8 @@ class GrayComponent extends AbstractComponent { @Override protected void drawInternalU(UGraphic ug, Dimension2D dimensionToUse) { final StringBounder stringBounder = ug.getStringBounder(); - ug.getParam().setBackcolor(Color.LIGHT_GRAY); - ug.getParam().setColor(Color.BLACK); + ug.getParam().setBackcolor(HtmlColor.LIGHT_GRAY); + ug.getParam().setColor(HtmlColor.BLACK); ug.draw(0, 0, new URectangle(getPreferredWidth(stringBounder), getPreferredHeight(stringBounder))); final String n = type.name(); @@ -71,7 +72,7 @@ class GrayComponent extends AbstractComponent { strings.add(n.substring(i, Math.min(i + split, n.length()))); } - final TextBlock textBlock = TextBlockUtils.create(strings, new FontConfiguration(NORMAL, Color.BLACK), + final TextBlock textBlock = TextBlockUtils.create(strings, new FontConfiguration(NORMAL, HtmlColor.BLACK), HorizontalAlignement.LEFT); textBlock.drawU(ug, 0, 0); } diff --git a/src/net/sourceforge/plantuml/skin/StickMan.java b/src/net/sourceforge/plantuml/skin/StickMan.java index 3c85e4242..e11e827f7 100644 --- a/src/net/sourceforge/plantuml/skin/StickMan.java +++ b/src/net/sourceforge/plantuml/skin/StickMan.java @@ -28,20 +28,21 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4189 $ + * Revision $Revision: 6577 $ * */ package net.sourceforge.plantuml.skin; import java.awt.BasicStroke; -import java.awt.Color; import java.awt.Graphics2D; import java.awt.Shape; import java.awt.geom.Ellipse2D; import java.awt.geom.Line2D; import java.awt.geom.Rectangle2D; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UEllipse; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.ULine; @@ -58,15 +59,15 @@ public class StickMan implements UDrawable { private final double legsY = 15; private final double headDiam = 16; - private final Color backgroundColor; - private final Color foregroundColor; + private final HtmlColor backgroundColor; + private final HtmlColor foregroundColor; - public StickMan(Color backgroundColor, Color foregroundColor) { + public StickMan(HtmlColor backgroundColor, HtmlColor foregroundColor) { this.backgroundColor = backgroundColor; this.foregroundColor = foregroundColor; } - public void draw(Graphics2D g2d) { + public void draw(ColorMapper colorMapper, Graphics2D g2d) { g2d.setStroke(new BasicStroke(thickness)); @@ -87,10 +88,10 @@ public class StickMan implements UDrawable { final Shape legs1 = new Line2D.Double(centerX, y, centerX - legsX, y + legsY); final Shape legs2 = new Line2D.Double(centerX, y, centerX + legsX, y + legsY); - g2d.setColor(backgroundColor); + g2d.setColor(colorMapper.getMappedColor(backgroundColor)); g2d.fill(head); - g2d.setColor(foregroundColor); + g2d.setColor(colorMapper.getMappedColor(foregroundColor)); g2d.draw(head); g2d.draw(body); g2d.draw(arms); diff --git a/src/net/sourceforge/plantuml/skin/VisibilityModifier.java b/src/net/sourceforge/plantuml/skin/VisibilityModifier.java index f271a9275..a54e58798 100644 --- a/src/net/sourceforge/plantuml/skin/VisibilityModifier.java +++ b/src/net/sourceforge/plantuml/skin/VisibilityModifier.java @@ -33,14 +33,15 @@ */ package net.sourceforge.plantuml.skin; -import java.awt.Color; import java.awt.Graphics2D; import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.ColorParam; import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UEllipse; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UPolygon; @@ -63,7 +64,7 @@ public enum VisibilityModifier { this.backgroundParam = background; } - public UDrawable getUDrawable(final int size, final Color foregroundColor, final Color backgoundColor) { + public UDrawable getUDrawable(final int size, final HtmlColor foregroundColor, final HtmlColor backgoundColor) { return new UDrawable() { public void drawU(UGraphic ug) { drawInternal(ug, size, foregroundColor, backgoundColor); @@ -71,14 +72,14 @@ public enum VisibilityModifier { }; } - public TextBlock getUBlock(final int size, final Color foregroundColor, final Color backgoundColor) { + public TextBlock getUBlock(final int size, final HtmlColor foregroundColor, final HtmlColor backgoundColor) { return new TextBlock() { public Dimension2D calculateDimension(StringBounder stringBounder) { return new Dimension2DDouble(size + 1, size + 1); } - public void drawTOBEREMOVED(Graphics2D g2d, double x, double y) { + public void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { throw new UnsupportedOperationException(); } @@ -92,7 +93,7 @@ public enum VisibilityModifier { }; } - private void drawInternal(UGraphic ug, int size, final Color foregroundColor, final Color backgoundColor) { + private void drawInternal(UGraphic ug, int size, final HtmlColor foregroundColor, final HtmlColor backgoundColor) { ug.getParam().setBackcolor(backgoundColor); ug.getParam().setColor(foregroundColor); size = ensureEven(size); diff --git a/src/net/sourceforge/plantuml/skin/bluemodern/AbstractComponentBlueModernArrow.java b/src/net/sourceforge/plantuml/skin/bluemodern/AbstractComponentBlueModernArrow.java index b1de16ae3..5170e1d2f 100644 --- a/src/net/sourceforge/plantuml/skin/bluemodern/AbstractComponentBlueModernArrow.java +++ b/src/net/sourceforge/plantuml/skin/bluemodern/AbstractComponentBlueModernArrow.java @@ -28,18 +28,18 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5944 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.skin.bluemodern; -import java.awt.Color; -import java.awt.Font; import java.util.List; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.skin.AbstractTextualComponent; import net.sourceforge.plantuml.skin.ArrowConfiguration; +import net.sourceforge.plantuml.ugraphic.UFont; public abstract class AbstractComponentBlueModernArrow extends AbstractTextualComponent { @@ -49,16 +49,16 @@ public abstract class AbstractComponentBlueModernArrow extends AbstractTextualCo private final int arrowDeltaX2 = 10; private final int arrowDeltaY2 = 5; private final ArrowConfiguration arrowConfiguration; - private final Color foregroundColor; + private final HtmlColor foregroundColor; - public AbstractComponentBlueModernArrow(Color foregroundColor, Color fontColor, Font font, + public AbstractComponentBlueModernArrow(HtmlColor foregroundColor, HtmlColor fontColor, UFont font, List stringsToDisplay, ArrowConfiguration arrowConfiguration) { super(stringsToDisplay, fontColor, font, HorizontalAlignement.LEFT, 17, 17, 2); this.arrowConfiguration = arrowConfiguration; this.foregroundColor = foregroundColor; } - protected final Color getForegroundColor() { + protected final HtmlColor getForegroundColor() { return foregroundColor; } diff --git a/src/net/sourceforge/plantuml/skin/bluemodern/BlueModern.java b/src/net/sourceforge/plantuml/skin/bluemodern/BlueModern.java index e955d2728..34986ac1b 100644 --- a/src/net/sourceforge/plantuml/skin/bluemodern/BlueModern.java +++ b/src/net/sourceforge/plantuml/skin/bluemodern/BlueModern.java @@ -28,56 +28,59 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6448 $ + * Revision $Revision: 6602 $ * */ package net.sourceforge.plantuml.skin.bluemodern; -import java.awt.Color; import java.awt.Font; import java.util.Arrays; import java.util.List; import net.sourceforge.plantuml.FontParam; import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.skin.Component; import net.sourceforge.plantuml.skin.ComponentType; import net.sourceforge.plantuml.skin.Skin; import net.sourceforge.plantuml.skin.rose.ComponentRoseDestroy; import net.sourceforge.plantuml.skin.rose.ComponentRoseGroupingElse; +import net.sourceforge.plantuml.skin.rose.ComponentRoseReference; import net.sourceforge.plantuml.skin.rose.ComponentRoseTitle; +import net.sourceforge.plantuml.ugraphic.UFont; public class BlueModern implements Skin { - private final Font bigFont = new Font("SansSerif", Font.BOLD, 20); - private final Font participantFont = new Font("SansSerif", Font.PLAIN, 17); - private final Font normalFont = new Font("SansSerif", Font.PLAIN, 13); - private final Font smallFont = new Font("SansSerif", Font.BOLD, 11); + private final UFont bigFont = new UFont("SansSerif", Font.BOLD, 20); + private final UFont participantFont = new UFont("SansSerif", Font.PLAIN, 17); + private final UFont normalFont = new UFont("SansSerif", Font.PLAIN, 13); + private final UFont smallFont = new UFont("SansSerif", Font.BOLD, 11); - private final Color blue1 = new Color(Integer.parseInt("527BC6", 16)); - private final Color blue2 = new Color(Integer.parseInt("D1DBEF", 16)); - private final Color blue3 = new Color(Integer.parseInt("D7E0F2", 16)); + private final HtmlColor blue1 = HtmlColor.getColorIfValid("#527BC6"); + private final HtmlColor blue2 = HtmlColor.getColorIfValid("#D1DBEF"); + private final HtmlColor blue3 = HtmlColor.getColorIfValid("#D7E0F2"); - private final Color red = new Color(Integer.parseInt("A80036", 16)); + private final HtmlColor red = HtmlColor.getColorIfValid("#A80036"); - private final Color lineColor = new Color(Integer.parseInt("989898", 16)); - private final Color borderGroupColor = new Color(Integer.parseInt("BBBBBB", 16)); + private final HtmlColor lineColor = HtmlColor.getColorIfValid("#989898"); + private final HtmlColor borderGroupColor = HtmlColor.getColorIfValid("#BBBBBB"); public Component createComponent(ComponentType type, ISkinParam param, List stringsToDisplay) { if (type.isArrow()) { if (type.getArrowConfiguration().isSelfArrow()) { - return new ComponentBlueModernSelfArrow(Color.BLACK, Color.BLACK, normalFont, stringsToDisplay, + return new ComponentBlueModernSelfArrow(HtmlColor.BLACK, HtmlColor.BLACK, normalFont, stringsToDisplay, type.getArrowConfiguration()); } - return new ComponentBlueModernArrow(Color.BLACK, Color.BLACK, normalFont, stringsToDisplay, + return new ComponentBlueModernArrow(HtmlColor.BLACK, HtmlColor.BLACK, normalFont, stringsToDisplay, type.getArrowConfiguration()); } if (type == ComponentType.PARTICIPANT_HEAD) { - return new ComponentBlueModernParticipant(blue1, blue2, Color.WHITE, participantFont, stringsToDisplay); + return new ComponentBlueModernParticipant(blue1, blue2, HtmlColor.WHITE, participantFont, stringsToDisplay); } if (type == ComponentType.PARTICIPANT_TAIL) { - return new ComponentBlueModernParticipant(blue1, blue2, Color.WHITE, participantFont, stringsToDisplay); + return new ComponentBlueModernParticipant(blue1, blue2, HtmlColor.WHITE, participantFont, stringsToDisplay); } if (type == ComponentType.PARTICIPANT_LINE) { return new ComponentBlueModernLine(lineColor); @@ -92,7 +95,8 @@ public class BlueModern implements Skin { return new ComponentBlueModernActor(blue2, blue1, blue1, participantFont, stringsToDisplay, false); } if (type == ComponentType.NOTE) { - return new ComponentBlueModernNote(Color.WHITE, Color.BLACK, Color.BLACK, normalFont, stringsToDisplay); + return new ComponentBlueModernNote(HtmlColor.WHITE, HtmlColor.BLACK, HtmlColor.BLACK, normalFont, + stringsToDisplay); } if (type == ComponentType.ALIVE_BOX_CLOSE_CLOSE) { return new ComponentBlueModernActiveLine(blue1, true, true); @@ -110,15 +114,15 @@ public class BlueModern implements Skin { return new ComponentBlueModernDelayLine(lineColor); } if (type == ComponentType.DELAY_TEXT) { - return new ComponentBlueModernDelayText(Color.BLACK, param.getFont(FontParam.SEQUENCE_DELAY, null), + return new ComponentBlueModernDelayText(HtmlColor.BLACK, param.getFont(FontParam.SEQUENCE_DELAY, null), stringsToDisplay); } if (type == ComponentType.DESTROY) { return new ComponentRoseDestroy(red); } if (type == ComponentType.GROUPING_HEADER) { - return new ComponentBlueModernGroupingHeader(blue1, blue3, borderGroupColor, Color.WHITE, Color.BLACK, - normalFont, smallFont, stringsToDisplay); + return new ComponentBlueModernGroupingHeader(blue1, blue3, borderGroupColor, HtmlColor.WHITE, + HtmlColor.BLACK, normalFont, smallFont, stringsToDisplay); } if (type == ComponentType.GROUPING_BODY) { return new ComponentBlueModernGroupingBody(blue3, borderGroupColor); @@ -127,23 +131,28 @@ public class BlueModern implements Skin { return new ComponentBlueModernGroupingTail(borderGroupColor); } if (type == ComponentType.GROUPING_ELSE) { - return new ComponentRoseGroupingElse(Color.BLACK, Color.BLACK, smallFont, stringsToDisplay.get(0)); + return new ComponentRoseGroupingElse(HtmlColor.BLACK, HtmlColor.BLACK, smallFont, stringsToDisplay.get(0)); } if (type == ComponentType.TITLE) { - return new ComponentRoseTitle(Color.BLACK, bigFont, stringsToDisplay); + return new ComponentRoseTitle(HtmlColor.BLACK, bigFont, stringsToDisplay); + } + if (type == ComponentType.REFERENCE) { + return new ComponentRoseReference(HtmlColor.BLACK, HtmlColor.WHITE, normalFont, borderGroupColor, + blue1, blue3, normalFont, stringsToDisplay, HorizontalAlignement.CENTER); } if (type == ComponentType.NEWPAGE) { return new ComponentBlueModernNewpage(blue1); } if (type == ComponentType.DIVIDER) { - return new ComponentBlueModernDivider(Color.BLACK, normalFont, blue2, blue1, Color.BLACK, stringsToDisplay); + return new ComponentBlueModernDivider(HtmlColor.BLACK, normalFont, blue2, blue1, HtmlColor.BLACK, + stringsToDisplay); } if (type == ComponentType.SIGNATURE) { - return new ComponentRoseTitle(Color.BLACK, smallFont, Arrays.asList("This skin was created ", + return new ComponentRoseTitle(HtmlColor.BLACK, smallFont, Arrays.asList("This skin was created ", "in April 2009.")); } if (type == ComponentType.ENGLOBER) { - return new ComponentBlueModernEnglober(blue1, blue3, stringsToDisplay, Color.BLACK, param.getFont( + return new ComponentBlueModernEnglober(blue1, blue3, stringsToDisplay, HtmlColor.BLACK, param.getFont( FontParam.SEQUENCE_BOX, null)); } diff --git a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernActiveLine.java b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernActiveLine.java index 0b1ab7411..5e9a9cf4a 100644 --- a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernActiveLine.java +++ b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernActiveLine.java @@ -28,14 +28,14 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6053 $ + * Revision $Revision: 6576 $ * */ package net.sourceforge.plantuml.skin.bluemodern; -import java.awt.Color; import java.awt.geom.Dimension2D; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.AbstractComponent; import net.sourceforge.plantuml.ugraphic.UGraphic; @@ -44,9 +44,9 @@ import net.sourceforge.plantuml.ugraphic.URectangle; public class ComponentBlueModernActiveLine extends AbstractComponent { private final int shadowview = 3; - private final Color foregroundColor; + private final HtmlColor foregroundColor; - public ComponentBlueModernActiveLine(Color foregroundColor, boolean closeUp, boolean closeDown) { + public ComponentBlueModernActiveLine(HtmlColor foregroundColor, boolean closeUp, boolean closeDown) { this.foregroundColor = foregroundColor; } diff --git a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernActor.java b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernActor.java index 3f4f5db0e..9fc612c8e 100644 --- a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernActor.java +++ b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernActor.java @@ -28,21 +28,21 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4738 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.skin.bluemodern; -import java.awt.Color; -import java.awt.Font; import java.awt.geom.Dimension2D; import java.util.List; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.skin.AbstractTextualComponent; import net.sourceforge.plantuml.skin.StickMan; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; public class ComponentBlueModernActor extends AbstractTextualComponent { @@ -50,7 +50,7 @@ public class ComponentBlueModernActor extends AbstractTextualComponent { private final StickMan stickman; private final boolean head; - public ComponentBlueModernActor(Color backgroundColor, Color foregroundColor, Color fontColor, Font font, + public ComponentBlueModernActor(HtmlColor backgroundColor, HtmlColor foregroundColor, HtmlColor fontColor, UFont font, List stringsToDisplay, boolean head) { super(stringsToDisplay, fontColor, font, HorizontalAlignement.LEFT, 3, 3, 0); this.head = head; diff --git a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernArrow.java b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernArrow.java index 0d223c9cc..f8c92a3af 100644 --- a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernArrow.java +++ b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernArrow.java @@ -28,20 +28,20 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5945 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.skin.bluemodern; -import java.awt.Color; -import java.awt.Font; import java.awt.Graphics2D; import java.awt.geom.Dimension2D; import java.util.List; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.ArrowConfiguration; import net.sourceforge.plantuml.skin.ArrowPart; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.ULine; import net.sourceforge.plantuml.ugraphic.UPolygon; @@ -49,7 +49,7 @@ import net.sourceforge.plantuml.ugraphic.UStroke; public class ComponentBlueModernArrow extends AbstractComponentBlueModernArrow { - public ComponentBlueModernArrow(Color foregroundColor, Color fontColor, Font font, + public ComponentBlueModernArrow(HtmlColor foregroundColor, HtmlColor fontColor, UFont font, List stringsToDisplay, ArrowConfiguration arrowConfiguration) { super(foregroundColor, fontColor, font, stringsToDisplay, arrowConfiguration); } diff --git a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernDelayLine.java b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernDelayLine.java index 0f10e5290..fde26c9b4 100644 --- a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernDelayLine.java +++ b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernDelayLine.java @@ -33,9 +33,9 @@ */ package net.sourceforge.plantuml.skin.bluemodern; -import java.awt.Color; import java.awt.geom.Dimension2D; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.AbstractComponent; import net.sourceforge.plantuml.ugraphic.UGraphic; @@ -44,9 +44,9 @@ import net.sourceforge.plantuml.ugraphic.UStroke; public class ComponentBlueModernDelayLine extends AbstractComponent { - private final Color color; + private final HtmlColor color; - public ComponentBlueModernDelayLine(Color color) { + public ComponentBlueModernDelayLine(HtmlColor color) { this.color = color; } diff --git a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernDelayText.java b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernDelayText.java index 7a990fea9..055d13f53 100644 --- a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernDelayText.java +++ b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernDelayText.java @@ -33,20 +33,20 @@ */ package net.sourceforge.plantuml.skin.bluemodern; -import java.awt.Color; -import java.awt.Font; import java.awt.geom.Dimension2D; import java.util.List; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.skin.AbstractTextualComponent; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; public class ComponentBlueModernDelayText extends AbstractTextualComponent { - public ComponentBlueModernDelayText(Color fontColor, Font font, List stringsToDisplay) { + public ComponentBlueModernDelayText(HtmlColor fontColor, UFont font, List stringsToDisplay) { super(stringsToDisplay, fontColor, font, HorizontalAlignement.CENTER, 4, 4, 4); } diff --git a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernDivider.java b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernDivider.java index d65f56ae2..ddd024621 100644 --- a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernDivider.java +++ b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernDivider.java @@ -33,15 +33,15 @@ */ package net.sourceforge.plantuml.skin.bluemodern; -import java.awt.Color; -import java.awt.Font; import java.awt.geom.Dimension2D; import java.util.List; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.skin.AbstractTextualComponent; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.ULine; import net.sourceforge.plantuml.ugraphic.URectangle; @@ -49,12 +49,12 @@ import net.sourceforge.plantuml.ugraphic.UStroke; public class ComponentBlueModernDivider extends AbstractTextualComponent { - private final Color background1; - private final Color background2; - private final Color borderColor; + private final HtmlColor background1; + private final HtmlColor background2; + private final HtmlColor borderColor; - public ComponentBlueModernDivider(Color fontColor, Font font, Color background1, Color background2, - Color borderColor, List stringsToDisplay) { + public ComponentBlueModernDivider(HtmlColor fontColor, UFont font, HtmlColor background1, HtmlColor background2, + HtmlColor borderColor, List stringsToDisplay) { super(stringsToDisplay, fontColor, font, HorizontalAlignement.CENTER, 4, 4, 4); this.background1 = background1; this.background2 = background2; @@ -72,15 +72,14 @@ public class ComponentBlueModernDivider extends AbstractTextualComponent { final double xpos = (dimensionToUse.getWidth() - textWidth - deltaX) / 2; final double ypos = (dimensionToUse.getHeight() - textHeight) / 2; - ug.getParam().setColor(Color.BLACK); - ug.getParam().setBackcolor(Color.BLACK); - + ug.getParam().setColor(HtmlColor.BLACK); + ug.getParam().setBackcolor(HtmlColor.BLACK); + ug.getParam().setStroke(new UStroke(2)); ug.draw(0, dimensionToUse.getHeight() / 2 - 1, new ULine(dimensionToUse.getWidth(), 0)); ug.draw(0, dimensionToUse.getHeight() / 2 + 2, new ULine(dimensionToUse.getWidth(), 0)); - final FillRoundShape shape = new FillRoundShape(textWidth + deltaX, textHeight, background1, background2, 5); ug.translate(xpos, ypos); shape.drawU(ug); diff --git a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernEnglober.java b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernEnglober.java index c983f8ebc..fd1ea95e3 100644 --- a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernEnglober.java +++ b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernEnglober.java @@ -33,25 +33,25 @@ */ package net.sourceforge.plantuml.skin.bluemodern; -import java.awt.Color; -import java.awt.Font; import java.awt.geom.Dimension2D; import java.util.List; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.AbstractTextualComponent; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.URectangle; import net.sourceforge.plantuml.ugraphic.UStroke; public class ComponentBlueModernEnglober extends AbstractTextualComponent { - private final Color borderColor; - private final Color backColor; + private final HtmlColor borderColor; + private final HtmlColor backColor; - public ComponentBlueModernEnglober(Color borderColor, Color backColor, List strings, - Color fontColor, Font font) { + public ComponentBlueModernEnglober(HtmlColor borderColor, HtmlColor backColor, List strings, + HtmlColor fontColor, UFont font) { super(strings, fontColor, font, HorizontalAlignement.CENTER, 4, 4, 1); this.borderColor = borderColor; this.backColor = backColor; diff --git a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernGroupingBody.java b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernGroupingBody.java index 02eb0486a..2226326e2 100644 --- a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernGroupingBody.java +++ b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernGroupingBody.java @@ -28,14 +28,14 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4167 $ + * Revision $Revision: 6576 $ * */ package net.sourceforge.plantuml.skin.bluemodern; -import java.awt.Color; import java.awt.geom.Dimension2D; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.AbstractComponent; import net.sourceforge.plantuml.ugraphic.UGraphic; @@ -45,10 +45,10 @@ import net.sourceforge.plantuml.ugraphic.UStroke; public class ComponentBlueModernGroupingBody extends AbstractComponent { - private final Color foregroundColor; - private final Color generalBackgroundColor; + private final HtmlColor foregroundColor; + private final HtmlColor generalBackgroundColor; - public ComponentBlueModernGroupingBody(Color generalBackgroundColor, Color foregroundColor) { + public ComponentBlueModernGroupingBody(HtmlColor generalBackgroundColor, HtmlColor foregroundColor) { this.foregroundColor = foregroundColor; this.generalBackgroundColor = generalBackgroundColor; } diff --git a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernGroupingHeader.java b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernGroupingHeader.java index 67c6b1668..2c730cfe1 100644 --- a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernGroupingHeader.java +++ b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernGroupingHeader.java @@ -28,23 +28,23 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6009 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.skin.bluemodern; -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.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +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.skin.AbstractTextualComponent; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.ULine; import net.sourceforge.plantuml.ugraphic.UPolygon; @@ -58,12 +58,12 @@ public class ComponentBlueModernGroupingHeader extends AbstractTextualComponent private final TextBlock commentTextBlock; - private final Color headerBackgroundColor; - private final Color generalBackgroundColor; - private final Color borderColor; + private final HtmlColor headerBackgroundColor; + private final HtmlColor generalBackgroundColor; + private final HtmlColor borderColor; - public ComponentBlueModernGroupingHeader(Color headerBackgroundColor, Color generalBackgroundColor, - Color borderColor, Color fontColor1, Color fontColor2, Font bigFont, Font smallFont, + public ComponentBlueModernGroupingHeader(HtmlColor headerBackgroundColor, HtmlColor generalBackgroundColor, + HtmlColor borderColor, HtmlColor fontColor1, HtmlColor fontColor2, UFont bigFont, UFont smallFont, List strings) { super(strings.get(0), fontColor1, bigFont, HorizontalAlignement.LEFT, 15, 30, 1); this.headerBackgroundColor = headerBackgroundColor; diff --git a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernGroupingTail.java b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernGroupingTail.java index 7adb25051..3751ac580 100644 --- a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernGroupingTail.java +++ b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernGroupingTail.java @@ -28,14 +28,14 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4167 $ + * Revision $Revision: 6576 $ * */ package net.sourceforge.plantuml.skin.bluemodern; -import java.awt.Color; import java.awt.geom.Dimension2D; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.AbstractComponent; import net.sourceforge.plantuml.ugraphic.UGraphic; @@ -44,9 +44,9 @@ import net.sourceforge.plantuml.ugraphic.UStroke; public class ComponentBlueModernGroupingTail extends AbstractComponent { - private final Color foregroundColor; + private final HtmlColor foregroundColor; - public ComponentBlueModernGroupingTail(Color foregroundColor) { + public ComponentBlueModernGroupingTail(HtmlColor foregroundColor) { this.foregroundColor = foregroundColor; } diff --git a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernLine.java b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernLine.java index e2fabf046..f151e27ec 100644 --- a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernLine.java +++ b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernLine.java @@ -28,14 +28,14 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4169 $ + * Revision $Revision: 6576 $ * */ package net.sourceforge.plantuml.skin.bluemodern; -import java.awt.Color; import java.awt.geom.Dimension2D; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.AbstractComponent; import net.sourceforge.plantuml.ugraphic.UGraphic; @@ -44,9 +44,9 @@ import net.sourceforge.plantuml.ugraphic.UStroke; public class ComponentBlueModernLine extends AbstractComponent { - private final Color color; + private final HtmlColor color; - public ComponentBlueModernLine(Color color) { + public ComponentBlueModernLine(HtmlColor color) { this.color = color; } diff --git a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernNewpage.java b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernNewpage.java index 883778280..b94211af3 100644 --- a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernNewpage.java +++ b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernNewpage.java @@ -28,14 +28,14 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4167 $ + * Revision $Revision: 6576 $ * */ package net.sourceforge.plantuml.skin.bluemodern; -import java.awt.Color; import java.awt.geom.Dimension2D; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.AbstractComponent; import net.sourceforge.plantuml.ugraphic.UGraphic; @@ -44,9 +44,9 @@ import net.sourceforge.plantuml.ugraphic.UStroke; public class ComponentBlueModernNewpage extends AbstractComponent { - private final Color foregroundColor; + private final HtmlColor foregroundColor; - public ComponentBlueModernNewpage(Color foregroundColor) { + public ComponentBlueModernNewpage(HtmlColor foregroundColor) { this.foregroundColor = foregroundColor; } diff --git a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernNote.java b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernNote.java index e6b3696d0..64fe9c934 100644 --- a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernNote.java +++ b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernNote.java @@ -28,19 +28,19 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4169 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.skin.bluemodern; -import java.awt.Color; -import java.awt.Font; import java.awt.geom.Dimension2D; import java.util.List; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.AbstractTextualComponent; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.ULine; import net.sourceforge.plantuml.ugraphic.UPolygon; @@ -49,10 +49,10 @@ final public class ComponentBlueModernNote extends AbstractTextualComponent { private final int shadowview = 4; private final int cornersize = 10; - private final Color back; - private final Color foregroundColor; + private final HtmlColor back; + private final HtmlColor foregroundColor; - public ComponentBlueModernNote(Color back, Color foregroundColor, Color fontColor, Font font, + public ComponentBlueModernNote(HtmlColor back, HtmlColor foregroundColor, HtmlColor fontColor, UFont font, List strings) { super(strings, fontColor, font, HorizontalAlignement.LEFT, 6, 15, 5); this.back = back; diff --git a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernParticipant.java b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernParticipant.java index 762e770a5..068d882f3 100644 --- a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernParticipant.java +++ b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernParticipant.java @@ -28,28 +28,28 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4738 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.skin.bluemodern; -import java.awt.Color; -import java.awt.Font; import java.awt.geom.Dimension2D; import java.util.List; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.AbstractTextualComponent; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; public class ComponentBlueModernParticipant extends AbstractTextualComponent { private final int shadowview = 3; - private final Color blue1; - private final Color blue2; + private final HtmlColor blue1; + private final HtmlColor blue2; - public ComponentBlueModernParticipant(Color blue1, Color blue2, Color fontColor, Font font, + public ComponentBlueModernParticipant(HtmlColor blue1, HtmlColor blue2, HtmlColor fontColor, UFont font, List stringsToDisplay) { super(stringsToDisplay, fontColor, font, HorizontalAlignement.CENTER, 7, 7, 7); this.blue1 = blue1; diff --git a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernSelfArrow.java b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernSelfArrow.java index 3c3dce6df..21e314cdf 100644 --- a/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernSelfArrow.java +++ b/src/net/sourceforge/plantuml/skin/bluemodern/ComponentBlueModernSelfArrow.java @@ -28,19 +28,19 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6242 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.skin.bluemodern; -import java.awt.Color; -import java.awt.Font; import java.awt.geom.Dimension2D; import java.util.List; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.ArrowConfiguration; import net.sourceforge.plantuml.skin.ArrowPart; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.ULine; import net.sourceforge.plantuml.ugraphic.UPolygon; @@ -50,7 +50,7 @@ public class ComponentBlueModernSelfArrow extends AbstractComponentBlueModernArr private final double arrowWidth = 45; - public ComponentBlueModernSelfArrow(Color foregroundColor, Color colorFont, Font font, + public ComponentBlueModernSelfArrow(HtmlColor foregroundColor, HtmlColor colorFont, UFont font, List stringsToDisplay, ArrowConfiguration arrowConfiguration) { super(foregroundColor, colorFont, font, stringsToDisplay, arrowConfiguration); } diff --git a/src/net/sourceforge/plantuml/skin/bluemodern/FillRoundShape.java b/src/net/sourceforge/plantuml/skin/bluemodern/FillRoundShape.java index 76fe10576..72f71e931 100644 --- a/src/net/sourceforge/plantuml/skin/bluemodern/FillRoundShape.java +++ b/src/net/sourceforge/plantuml/skin/bluemodern/FillRoundShape.java @@ -28,16 +28,17 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3914 $ + * Revision $Revision: 6576 $ * */ package net.sourceforge.plantuml.skin.bluemodern; -import java.awt.Color; import java.awt.GradientPaint; import java.awt.Graphics2D; import java.awt.geom.RoundRectangle2D; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UGradient; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.URectangle; @@ -47,10 +48,10 @@ public class FillRoundShape { final private double width; final private double height; final private double corner; - final private Color c1; - final private Color c2; + final private HtmlColor c1; + final private HtmlColor c2; - public FillRoundShape(double width, double height, Color c1, Color c2, double corner) { + public FillRoundShape(double width, double height, HtmlColor c1, HtmlColor c2, double corner) { this.width = width; this.height = height; this.c1 = c1; @@ -59,8 +60,9 @@ public class FillRoundShape { } - public void draw(Graphics2D g2d) { - final GradientPaint paint = new GradientPaint(0, 0, c1, (float) width, (float) height, c2); + public void draw(ColorMapper mapper, Graphics2D g2d) { + final GradientPaint paint = new GradientPaint(0, 0, mapper.getMappedColor(c1), (float) width, (float) height, + mapper.getMappedColor(c2)); final RoundRectangle2D r = new RoundRectangle2D.Double(0, 0, width, height, corner * 2, corner * 2); g2d.setPaint(paint); g2d.fill(r); diff --git a/src/net/sourceforge/plantuml/skin/bluemodern/ShadowShape.java b/src/net/sourceforge/plantuml/skin/bluemodern/ShadowShape.java index 7fc3ea595..d3909e503 100644 --- a/src/net/sourceforge/plantuml/skin/bluemodern/ShadowShape.java +++ b/src/net/sourceforge/plantuml/skin/bluemodern/ShadowShape.java @@ -28,17 +28,17 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3837 $ + * Revision $Revision: 6576 $ * */ package net.sourceforge.plantuml.skin.bluemodern; -import java.awt.Color; +import net.sourceforge.plantuml.graphic.HtmlColor; public class ShadowShape extends FillRoundShape { public ShadowShape(double width, double height, double corner) { - super(width, height, Color.LIGHT_GRAY, Color.GRAY, corner); + super(width, height, HtmlColor.LIGHT_GRAY, HtmlColor.GRAY, corner); } diff --git a/src/net/sourceforge/plantuml/skin/rose/AbstractComponentRoseArrow.java b/src/net/sourceforge/plantuml/skin/rose/AbstractComponentRoseArrow.java index da8ccf790..4db521dc7 100644 --- a/src/net/sourceforge/plantuml/skin/rose/AbstractComponentRoseArrow.java +++ b/src/net/sourceforge/plantuml/skin/rose/AbstractComponentRoseArrow.java @@ -28,19 +28,19 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5922 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.skin.rose; -import java.awt.Color; -import java.awt.Font; import java.util.List; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.skin.AbstractTextualComponent; import net.sourceforge.plantuml.skin.ArrowComponent; import net.sourceforge.plantuml.skin.ArrowConfiguration; +import net.sourceforge.plantuml.ugraphic.UFont; public abstract class AbstractComponentRoseArrow extends AbstractTextualComponent implements ArrowComponent { @@ -48,17 +48,17 @@ public abstract class AbstractComponentRoseArrow extends AbstractTextualComponen private final int arrowDeltaY = 4; // private final boolean dotted; // private final boolean full; - private final Color foregroundColor; + private final HtmlColor foregroundColor; private final ArrowConfiguration arrowConfiguration; - public AbstractComponentRoseArrow(Color foregroundColor, Color fontColor, Font font, + public AbstractComponentRoseArrow(HtmlColor foregroundColor, HtmlColor fontColor, UFont font, List stringsToDisplay, ArrowConfiguration arrowConfiguration) { super(stringsToDisplay, fontColor, font, HorizontalAlignement.LEFT, 7, 7, 2); this.arrowConfiguration = arrowConfiguration; this.foregroundColor = foregroundColor; } - protected final Color getForegroundColor() { + protected final HtmlColor getForegroundColor() { return foregroundColor; } diff --git a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseActiveLine.java b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseActiveLine.java index 249ecf791..a0adda978 100644 --- a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseActiveLine.java +++ b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseActiveLine.java @@ -28,14 +28,14 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6046 $ + * Revision $Revision: 6576 $ * */ package net.sourceforge.plantuml.skin.rose; -import java.awt.Color; import java.awt.geom.Dimension2D; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.AbstractComponent; import net.sourceforge.plantuml.ugraphic.UGraphic; @@ -44,12 +44,12 @@ import net.sourceforge.plantuml.ugraphic.URectangle; public class ComponentRoseActiveLine extends AbstractComponent { - private final Color foregroundColor; - private final Color lifeLineBackground; + private final HtmlColor foregroundColor; + private final HtmlColor lifeLineBackground; private final boolean closeUp; private final boolean closeDown; - public ComponentRoseActiveLine(Color foregroundColor, Color lifeLineBackground, boolean closeUp, boolean closeDown) { + public ComponentRoseActiveLine(HtmlColor foregroundColor, HtmlColor lifeLineBackground, boolean closeUp, boolean closeDown) { this.foregroundColor = foregroundColor; this.lifeLineBackground = lifeLineBackground; this.closeUp = closeUp; diff --git a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseActor.java b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseActor.java index 5ae8b45af..005868770 100644 --- a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseActor.java +++ b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseActor.java @@ -28,21 +28,21 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4738 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.skin.rose; -import java.awt.Color; -import java.awt.Font; import java.awt.geom.Dimension2D; import java.util.List; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.skin.AbstractTextualComponent; import net.sourceforge.plantuml.skin.StickMan; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; public class ComponentRoseActor extends AbstractTextualComponent { @@ -50,7 +50,7 @@ public class ComponentRoseActor extends AbstractTextualComponent { private final StickMan stickman; private final boolean head; - public ComponentRoseActor(Color yellow, Color red, Color fontColor, Font font, + public ComponentRoseActor(HtmlColor yellow, HtmlColor red, HtmlColor fontColor, UFont font, List stringsToDisplay, boolean head) { super(stringsToDisplay, fontColor, font, HorizontalAlignement.LEFT, 3, 3, 0); this.head = head; diff --git a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseArrow.java b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseArrow.java index 938919bd2..f5ab985ee 100644 --- a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseArrow.java +++ b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseArrow.java @@ -28,20 +28,21 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5937 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.skin.rose; -import java.awt.Color; -import java.awt.Font; import java.awt.geom.Dimension2D; import java.awt.geom.Point2D; import java.util.List; +import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.ArrowConfiguration; import net.sourceforge.plantuml.skin.ArrowPart; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.ULine; import net.sourceforge.plantuml.ugraphic.UPolygon; @@ -49,9 +50,13 @@ import net.sourceforge.plantuml.ugraphic.UStroke; public class ComponentRoseArrow extends AbstractComponentRoseArrow { - public ComponentRoseArrow(Color foregroundColor, Color fontColor, Font font, - List stringsToDisplay, ArrowConfiguration arrowConfiguration) { + private final HorizontalAlignement messagePosition; + + public ComponentRoseArrow(HtmlColor foregroundColor, HtmlColor fontColor, UFont font, + List stringsToDisplay, ArrowConfiguration arrowConfiguration, + HorizontalAlignement messagePosition) { super(foregroundColor, fontColor, font, stringsToDisplay, arrowConfiguration); + this.messagePosition = messagePosition; } @Override @@ -101,7 +106,17 @@ public class ComponentRoseArrow extends AbstractComponentRoseArrow { ug.getParam().setBackcolor(null); } } - getTextBlock().drawU(ug, getMarginX1(), 0); + final double textPos; + if (messagePosition == HorizontalAlignement.CENTER) { + final double textWidth = getTextBlock().calculateDimension(stringBounder).getWidth(); + textPos = (dimensionToUse.getWidth() - textWidth) / 2; + } else if (messagePosition == HorizontalAlignement.RIGHT) { + final double textWidth = getTextBlock().calculateDimension(stringBounder).getWidth(); + textPos = dimensionToUse.getWidth() - textWidth - getMarginX2(); + } else { + textPos = getMarginX1(); + } + getTextBlock().drawU(ug, textPos, 0); } private UPolygon getPolygonNormal(final int textHeight, final int x2) { diff --git a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseDelayLine.java b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseDelayLine.java index 0f9b8195e..aec812fc7 100644 --- a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseDelayLine.java +++ b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseDelayLine.java @@ -33,9 +33,9 @@ */ package net.sourceforge.plantuml.skin.rose; -import java.awt.Color; import java.awt.geom.Dimension2D; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.AbstractComponent; import net.sourceforge.plantuml.ugraphic.UGraphic; @@ -44,9 +44,9 @@ import net.sourceforge.plantuml.ugraphic.UStroke; public class ComponentRoseDelayLine extends AbstractComponent { - private final Color color; + private final HtmlColor color; - public ComponentRoseDelayLine(Color color) { + public ComponentRoseDelayLine(HtmlColor color) { this.color = color; } diff --git a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseDelayText.java b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseDelayText.java index 4a384f837..233254680 100644 --- a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseDelayText.java +++ b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseDelayText.java @@ -33,20 +33,20 @@ */ package net.sourceforge.plantuml.skin.rose; -import java.awt.Color; -import java.awt.Font; import java.awt.geom.Dimension2D; import java.util.List; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.skin.AbstractTextualComponent; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; public class ComponentRoseDelayText extends AbstractTextualComponent { - public ComponentRoseDelayText(Color fontColor, Font font, List stringsToDisplay) { + public ComponentRoseDelayText(HtmlColor fontColor, UFont font, List stringsToDisplay) { super(stringsToDisplay, fontColor, font, HorizontalAlignement.CENTER, 4, 4, 4); } diff --git a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseDestroy.java b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseDestroy.java index 79998d5dc..8f34ef953 100644 --- a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseDestroy.java +++ b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseDestroy.java @@ -28,14 +28,14 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4169 $ + * Revision $Revision: 6576 $ * */ package net.sourceforge.plantuml.skin.rose; -import java.awt.Color; import java.awt.geom.Dimension2D; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.AbstractComponent; import net.sourceforge.plantuml.ugraphic.UGraphic; @@ -44,9 +44,9 @@ import net.sourceforge.plantuml.ugraphic.UStroke; public class ComponentRoseDestroy extends AbstractComponent { - private final Color foregroundColor; + private final HtmlColor foregroundColor; - public ComponentRoseDestroy(Color foregroundColor) { + public ComponentRoseDestroy(HtmlColor foregroundColor) { this.foregroundColor = foregroundColor; } diff --git a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseDivider.java b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseDivider.java index 2fdd2a4bc..52aed2a1b 100644 --- a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseDivider.java +++ b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseDivider.java @@ -33,15 +33,15 @@ */ package net.sourceforge.plantuml.skin.rose; -import java.awt.Color; -import java.awt.Font; import java.awt.geom.Dimension2D; import java.util.List; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.skin.AbstractTextualComponent; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.ULine; import net.sourceforge.plantuml.ugraphic.URectangle; @@ -50,9 +50,9 @@ import net.sourceforge.plantuml.ugraphic.UStroke; public class ComponentRoseDivider extends AbstractTextualComponent { // private final int outMargin = 5; - private final Color background; + private final HtmlColor background; - public ComponentRoseDivider(Color fontColor, Font font, Color background, + public ComponentRoseDivider(HtmlColor fontColor, UFont font, HtmlColor background, List stringsToDisplay) { super(stringsToDisplay, fontColor, font, HorizontalAlignement.CENTER, 4, 4, 4); this.background = background; @@ -69,11 +69,11 @@ public class ComponentRoseDivider extends AbstractTextualComponent { final double xpos = (dimensionToUse.getWidth() - textWidth - deltaX) / 2; final double ypos = (dimensionToUse.getHeight() - textHeight) / 2; - ug.getParam().setColor(Color.BLACK); + ug.getParam().setColor(HtmlColor.BLACK); ug.draw(0, dimensionToUse.getHeight() / 2 - 1, new ULine(dimensionToUse.getWidth(), 0)); ug.draw(0, dimensionToUse.getHeight() / 2 + 2, new ULine(dimensionToUse.getWidth(), 0)); - ug.getParam().setColor(Color.BLACK); + ug.getParam().setColor(HtmlColor.BLACK); ug.getParam().setBackcolor(background); ug.getParam().setStroke(new UStroke(2)); diff --git a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseEnglober.java b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseEnglober.java index bd7578efd..4d1cb48ca 100644 --- a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseEnglober.java +++ b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseEnglober.java @@ -33,23 +33,23 @@ */ package net.sourceforge.plantuml.skin.rose; -import java.awt.Color; -import java.awt.Font; import java.awt.geom.Dimension2D; import java.util.List; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.AbstractTextualComponent; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.URectangle; public class ComponentRoseEnglober extends AbstractTextualComponent { - private final Color borderColor; - private final Color backColor; + private final HtmlColor borderColor; + private final HtmlColor backColor; - public ComponentRoseEnglober(Color borderColor, Color backColor, List strings, Color fontColor, Font font) { + public ComponentRoseEnglober(HtmlColor borderColor, HtmlColor backColor, List strings, HtmlColor fontColor, UFont font) { super(strings, fontColor, font, HorizontalAlignement.CENTER, 3, 3, 1); this.borderColor = borderColor; this.backColor = backColor; diff --git a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingBody.java b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingBody.java index ecca2cf64..ca5598e3f 100644 --- a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingBody.java +++ b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingBody.java @@ -28,14 +28,14 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4258 $ + * Revision $Revision: 6576 $ * */ package net.sourceforge.plantuml.skin.rose; -import java.awt.Color; import java.awt.geom.Dimension2D; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.AbstractComponent; import net.sourceforge.plantuml.ugraphic.UGraphic; @@ -45,10 +45,10 @@ import net.sourceforge.plantuml.ugraphic.UStroke; public class ComponentRoseGroupingBody extends AbstractComponent { - private final Color foregroundColor; - private final Color background; + private final HtmlColor foregroundColor; + private final HtmlColor background; - public ComponentRoseGroupingBody(Color background, Color foregroundColor) { + public ComponentRoseGroupingBody(HtmlColor background, HtmlColor foregroundColor) { this.foregroundColor = foregroundColor; this.background = background; diff --git a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingElse.java b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingElse.java index d1d983b6f..5e6e49970 100644 --- a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingElse.java +++ b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingElse.java @@ -28,27 +28,27 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6404 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.skin.rose; -import java.awt.Color; -import java.awt.Font; import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.AbstractTextualComponent; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.ULine; import net.sourceforge.plantuml.ugraphic.UStroke; public class ComponentRoseGroupingElse extends AbstractTextualComponent { - private final Color groupBorder; + private final HtmlColor groupBorder; - public ComponentRoseGroupingElse(Color fontColor, Color groupBorder, Font smallFont, CharSequence comment) { + public ComponentRoseGroupingElse(HtmlColor fontColor, HtmlColor groupBorder, UFont smallFont, CharSequence comment) { super(comment == null ? null : "[" + comment + "]", fontColor, smallFont, HorizontalAlignement.LEFT, 5, 5, 1); this.groupBorder = groupBorder; } diff --git a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingHeader.java b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingHeader.java index f28a05a41..058b2a8e4 100644 --- a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingHeader.java +++ b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingHeader.java @@ -28,23 +28,23 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6403 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.skin.rose; -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.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +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.skin.AbstractTextualComponent; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.ULine; import net.sourceforge.plantuml.ugraphic.UPolygon; @@ -58,12 +58,12 @@ public class ComponentRoseGroupingHeader extends AbstractTextualComponent { private final TextBlock commentTextBlock; - private final Color groupBackground; - private final Color groupBorder; - private final Color background; + private final HtmlColor groupBackground; + private final HtmlColor groupBorder; + private final HtmlColor background; - public ComponentRoseGroupingHeader(Color fontColor, Color background, Color groupBackground, Color groupBorder, Font bigFont, - Font smallFont, List strings) { + public ComponentRoseGroupingHeader(HtmlColor fontColor, HtmlColor background, HtmlColor groupBackground, HtmlColor groupBorder, UFont bigFont, + UFont smallFont, List strings) { super(strings.get(0), fontColor, bigFont, HorizontalAlignement.LEFT, 15, 30, 1); this.groupBackground = groupBackground; this.groupBorder = groupBorder; @@ -127,7 +127,7 @@ public class ComponentRoseGroupingHeader extends AbstractTextualComponent { ug.getParam().setStroke(new UStroke(2)); ug.getParam().setColor(groupBorder); - ug.getParam().setBackcolor(this.groupBackground); + ug.getParam().setBackcolor(groupBackground); ug.draw(0, 0, polygon); final double heightWithoutPadding = dimensionToUse.getHeight() - getPaddingY(); diff --git a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingTail.java b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingTail.java index 2c198905b..c4236595b 100644 --- a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingTail.java +++ b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingTail.java @@ -28,14 +28,14 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6404 $ + * Revision $Revision: 6576 $ * */ package net.sourceforge.plantuml.skin.rose; -import java.awt.Color; import java.awt.geom.Dimension2D; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.AbstractComponent; import net.sourceforge.plantuml.ugraphic.UGraphic; @@ -44,10 +44,10 @@ import net.sourceforge.plantuml.ugraphic.UStroke; public class ComponentRoseGroupingTail extends AbstractComponent { - private final Color foregroundColor; - private final Color groupBorder; + private final HtmlColor foregroundColor; + private final HtmlColor groupBorder; - public ComponentRoseGroupingTail(Color foregroundColor, Color groupBorder) { + public ComponentRoseGroupingTail(HtmlColor foregroundColor,HtmlColor groupBorder) { this.foregroundColor = foregroundColor; this.groupBorder = groupBorder; } diff --git a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseLine.java b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseLine.java index 0acc4b341..1f7483bb7 100644 --- a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseLine.java +++ b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseLine.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6008 $ + * Revision $Revision: 6576 $ * */ package net.sourceforge.plantuml.skin.rose; @@ -36,6 +36,7 @@ package net.sourceforge.plantuml.skin.rose; import java.awt.Color; import java.awt.geom.Dimension2D; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.AbstractComponent; import net.sourceforge.plantuml.ugraphic.UGraphic; @@ -44,10 +45,10 @@ import net.sourceforge.plantuml.ugraphic.UStroke; public class ComponentRoseLine extends AbstractComponent { - private final Color color; + private final HtmlColor color; private final boolean continueLine; - public ComponentRoseLine(Color color, boolean continueLine) { + public ComponentRoseLine(HtmlColor color, boolean continueLine) { this.color = color; this.continueLine = continueLine; } diff --git a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseNewpage.java b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseNewpage.java index efc0b1382..10ba53626 100644 --- a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseNewpage.java +++ b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseNewpage.java @@ -28,14 +28,14 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5937 $ + * Revision $Revision: 6576 $ * */ package net.sourceforge.plantuml.skin.rose; -import java.awt.Color; import java.awt.geom.Dimension2D; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.AbstractComponent; import net.sourceforge.plantuml.ugraphic.UGraphic; @@ -44,9 +44,9 @@ import net.sourceforge.plantuml.ugraphic.UStroke; public class ComponentRoseNewpage extends AbstractComponent { - private final Color foregroundColor; + private final HtmlColor foregroundColor; - public ComponentRoseNewpage(Color foregroundColor) { + public ComponentRoseNewpage(HtmlColor foregroundColor) { this.foregroundColor = foregroundColor; } diff --git a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseNote.java b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseNote.java index 0f81fe149..d2590cb4c 100644 --- a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseNote.java +++ b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseNote.java @@ -28,19 +28,19 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4167 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.skin.rose; -import java.awt.Color; -import java.awt.Font; import java.awt.geom.Dimension2D; import java.util.List; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.AbstractTextualComponent; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.ULine; import net.sourceforge.plantuml.ugraphic.UPolygon; @@ -48,10 +48,10 @@ import net.sourceforge.plantuml.ugraphic.UPolygon; final public class ComponentRoseNote extends AbstractTextualComponent { private final int cornersize = 10; - private final Color back; - private final Color foregroundColor; + private final HtmlColor back; + private final HtmlColor foregroundColor; - public ComponentRoseNote(Color back, Color foregroundColor, Color fontColor, Font font, + public ComponentRoseNote(HtmlColor back, HtmlColor foregroundColor, HtmlColor fontColor, UFont font, List strings) { super(strings, fontColor, font, HorizontalAlignement.LEFT, 6, 15, 5); this.back = back; diff --git a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseParticipant.java b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseParticipant.java index 39527e4b5..a0ef60519 100644 --- a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseParticipant.java +++ b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseParticipant.java @@ -28,29 +28,29 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4738 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.skin.rose; -import java.awt.Color; -import java.awt.Font; import java.awt.geom.Dimension2D; import java.util.List; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.skin.AbstractTextualComponent; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.URectangle; public class ComponentRoseParticipant extends AbstractTextualComponent { - private final Color back; - private final Color foregroundColor; + private final HtmlColor back; + private final HtmlColor foregroundColor; - public ComponentRoseParticipant(Color back, Color foregroundColor, Color fontColor, Font font, + public ComponentRoseParticipant(HtmlColor back, HtmlColor foregroundColor, HtmlColor fontColor, UFont font, List stringsToDisplay) { super(stringsToDisplay, fontColor, font, HorizontalAlignement.CENTER, 7, 7, 7); this.back = back; diff --git a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseReference.java b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseReference.java index 0e1225cc5..b4694a664 100644 --- a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseReference.java +++ b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseReference.java @@ -33,64 +33,108 @@ */ package net.sourceforge.plantuml.skin.rose; -import java.awt.Color; -import java.awt.Font; import java.awt.geom.Dimension2D; import java.util.List; +import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +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.skin.AbstractTextualComponent; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; -import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.UPolygon; import net.sourceforge.plantuml.ugraphic.URectangle; -import net.sourceforge.plantuml.ugraphic.UShape; import net.sourceforge.plantuml.ugraphic.UStroke; public class ComponentRoseReference extends AbstractTextualComponent { - // private final int outMargin = 5; - private final Color background; + private final HtmlColor backgroundHeader; + private final HtmlColor borderColor; + private final HtmlColor background; + private final int cornersize = 10; + private final TextBlock textHeader; + private final double heightFooter = 5; + private final double xMargin = 2; + private final HorizontalAlignement position; - public ComponentRoseReference(Color fontColor, Font font, Color background, - List stringsToDisplay) { - super(stringsToDisplay, fontColor, font, HorizontalAlignement.CENTER, 4, 4, 4); + public ComponentRoseReference(HtmlColor fontColor, HtmlColor fontHeaderColor, UFont font, HtmlColor borderColor, + HtmlColor backgroundHeader, HtmlColor background, UFont header, + List stringsToDisplay, HorizontalAlignement position) { + super(stringsToDisplay.subList(1, stringsToDisplay.size()), fontColor, font, HorizontalAlignement.LEFT, 4, 4, 4); + this.position = position; + this.backgroundHeader = backgroundHeader; this.background = background; + this.borderColor = borderColor; + + textHeader = TextBlockUtils.create(stringsToDisplay.subList(0, 1), new FontConfiguration(header, + fontHeaderColor), HorizontalAlignement.LEFT); + } @Override protected void drawInternalU(UGraphic ug, Dimension2D dimensionToUse) { - final TextBlock textBlock = getTextBlock(); final StringBounder stringBounder = ug.getStringBounder(); - final double textWidth = getTextWidth(stringBounder); - final double textHeight = getTextHeight(stringBounder); + final int textHeaderWidth = (int) (getHeaderWidth(stringBounder)); + final int textHeaderHeight = (int) (getHeaderHeight(stringBounder)); - ug.getParam().setColor(getFontColor()); + ug.getParam().setStroke(new UStroke(2)); + final URectangle rect = new URectangle(dimensionToUse.getWidth() - xMargin * 2, dimensionToUse.getHeight() + - heightFooter); + ug.getParam().setColor(borderColor); ug.getParam().setBackcolor(background); + ug.draw(xMargin, 0, rect); + + final UPolygon polygon = new UPolygon(); + polygon.addPoint(0, 0); + polygon.addPoint(textHeaderWidth, 0); + + polygon.addPoint(textHeaderWidth, textHeaderHeight - cornersize); + polygon.addPoint(textHeaderWidth - cornersize, textHeaderHeight); + + polygon.addPoint(0, textHeaderHeight); + polygon.addPoint(0, 0); + + ug.getParam().setColor(borderColor); + ug.getParam().setBackcolor(backgroundHeader); + ug.draw(xMargin, 0, polygon); - ug.getParam().setStroke(new UStroke(5, 5, 1)); - ug.draw(1, 1, new URectangle(dimensionToUse.getWidth() - 2, dimensionToUse.getHeight() - 2)); ug.getParam().setStroke(new UStroke()); - final UShape box = new URectangle(8, 8); - ug.draw(5, 5, box); - final ULine lineH = new ULine(4, 0); - final ULine lineV = new ULine(0, 4); - ug.draw(5 + 2, 5 + 4, lineH); - ug.draw(5 + 4, 5 + 2, lineV); + textHeader.drawU(ug, 15, 2); + final double textPos; + if (position == HorizontalAlignement.CENTER) { + final double textWidth = getTextBlock().calculateDimension(stringBounder).getWidth(); + textPos = (dimensionToUse.getWidth() - textWidth) / 2; + } else if (position == HorizontalAlignement.RIGHT) { + final double textWidth = getTextBlock().calculateDimension(stringBounder).getWidth(); + textPos = dimensionToUse.getWidth() - textWidth - getMarginX2() - xMargin; + } else { + textPos = getMarginX1() + xMargin; + } + getTextBlock().drawU(ug, textPos, getMarginY() + textHeaderHeight); + } - textBlock.drawU(ug, 20, getMarginY()); + private double getHeaderHeight(StringBounder stringBounder) { + final Dimension2D headerDim = textHeader.calculateDimension(stringBounder); + return headerDim.getHeight() + 2 * 1; + } + + private double getHeaderWidth(StringBounder stringBounder) { + final Dimension2D headerDim = textHeader.calculateDimension(stringBounder); + return headerDim.getWidth() + 30 + 15; } @Override public double getPreferredHeight(StringBounder stringBounder) { - return getTextHeight(stringBounder) + 0; + return getTextHeight(stringBounder) + getHeaderHeight(stringBounder) + heightFooter; } @Override public double getPreferredWidth(StringBounder stringBounder) { - return getTextWidth(stringBounder) + 26; + return Math.max(getTextWidth(stringBounder), getHeaderWidth(stringBounder)) + xMargin * 2; } } diff --git a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseSelfArrow.java b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseSelfArrow.java index 975746124..94db6297f 100644 --- a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseSelfArrow.java +++ b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseSelfArrow.java @@ -28,20 +28,20 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6242 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.skin.rose; -import java.awt.Color; -import java.awt.Font; import java.awt.geom.Dimension2D; import java.awt.geom.Point2D; import java.util.List; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.skin.ArrowConfiguration; import net.sourceforge.plantuml.skin.ArrowPart; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.ULine; import net.sourceforge.plantuml.ugraphic.UPolygon; @@ -51,7 +51,7 @@ public class ComponentRoseSelfArrow extends AbstractComponentRoseArrow { private final double arrowWidth = 45; - public ComponentRoseSelfArrow(Color foregroundColor, Color colorFont, Font font, + public ComponentRoseSelfArrow(HtmlColor foregroundColor, HtmlColor colorFont, UFont font, List stringsToDisplay, ArrowConfiguration arrowConfiguration) { super(foregroundColor, colorFont, font, stringsToDisplay, arrowConfiguration); } diff --git a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseTitle.java b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseTitle.java index 10af118d5..85be3d983 100644 --- a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseTitle.java +++ b/src/net/sourceforge/plantuml/skin/rose/ComponentRoseTitle.java @@ -28,27 +28,27 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4167 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.skin.rose; -import java.awt.Color; -import java.awt.Font; import java.awt.geom.Dimension2D; import java.util.List; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.skin.AbstractTextualComponent; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; public class ComponentRoseTitle extends AbstractTextualComponent { private final int outMargin = 5; - public ComponentRoseTitle(Color fontColor, Font font, List stringsToDisplay) { + public ComponentRoseTitle(HtmlColor fontColor, UFont font, List stringsToDisplay) { super(stringsToDisplay, fontColor, font, HorizontalAlignement.CENTER, 7, 7, 7); } diff --git a/src/net/sourceforge/plantuml/skin/rose/Rose.java b/src/net/sourceforge/plantuml/skin/rose/Rose.java index d873518c6..3deb6e38c 100644 --- a/src/net/sourceforge/plantuml/skin/rose/Rose.java +++ b/src/net/sourceforge/plantuml/skin/rose/Rose.java @@ -28,18 +28,17 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6476 $ + * Revision $Revision: 6602 $ * */ package net.sourceforge.plantuml.skin.rose; -import java.awt.Color; -import java.awt.Font; import java.util.Arrays; import java.util.EnumMap; import java.util.List; import java.util.Map; +import net.sourceforge.plantuml.AlignParam; import net.sourceforge.plantuml.ColorParam; import net.sourceforge.plantuml.FontParam; import net.sourceforge.plantuml.ISkinParam; @@ -47,6 +46,7 @@ import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.skin.Component; import net.sourceforge.plantuml.skin.ComponentType; import net.sourceforge.plantuml.skin.Skin; +import net.sourceforge.plantuml.ugraphic.UFont; public class Rose implements Skin { @@ -66,9 +66,11 @@ public class Rose implements Skin { defaultsColor.put(ColorParam.sequenceLifeLineBackground, HtmlColor.getColorIfValid("white")); defaultsColor.put(ColorParam.sequenceLifeLineBorder, HtmlColor.getColorIfValid("#A80036")); defaultsColor.put(ColorParam.sequenceGroupBackground, HtmlColor.getColorIfValid("#EEEEEE")); - defaultsColor.put(ColorParam.sequenceGroupBorder, HtmlColor.getColorIfValid("black")); + defaultsColor.put(ColorParam.sequenceGroupBorder, HtmlColor.BLACK); defaultsColor.put(ColorParam.sequenceDividerBackground, HtmlColor.getColorIfValid("#EEEEEE")); - defaultsColor.put(ColorParam.sequenceReferenceBackground, HtmlColor.getColorIfValid("#EEEEEE")); + defaultsColor.put(ColorParam.sequenceReferenceBorder, HtmlColor.BLACK); + defaultsColor.put(ColorParam.sequenceReferenceBackground, HtmlColor.getColorIfValid("white")); + defaultsColor.put(ColorParam.sequenceReferenceHeaderBackground, HtmlColor.getColorIfValid("#EEEEEE")); defaultsColor.put(ColorParam.sequenceBoxBorder, HtmlColor.getColorIfValid("#A80036")); defaultsColor.put(ColorParam.sequenceBoxBackground, HtmlColor.getColorIfValid("#DDDDDD")); @@ -77,14 +79,14 @@ public class Rose implements Skin { defaultsColor.put(ColorParam.activityBackground, HtmlColor.getColorIfValid("#FEFECE")); defaultsColor.put(ColorParam.activityBorder, HtmlColor.getColorIfValid("#A80036")); - defaultsColor.put(ColorParam.activityStart, HtmlColor.getColorIfValid("black")); - defaultsColor.put(ColorParam.activityEnd, HtmlColor.getColorIfValid("black")); - defaultsColor.put(ColorParam.activityBar, HtmlColor.getColorIfValid("black")); + defaultsColor.put(ColorParam.activityStart, HtmlColor.BLACK); + defaultsColor.put(ColorParam.activityEnd, HtmlColor.BLACK); + defaultsColor.put(ColorParam.activityBar, HtmlColor.BLACK); defaultsColor.put(ColorParam.stateBackground, HtmlColor.getColorIfValid("#FEFECE")); defaultsColor.put(ColorParam.stateBorder, HtmlColor.getColorIfValid("#A80036")); - defaultsColor.put(ColorParam.stateStart, HtmlColor.getColorIfValid("black")); - defaultsColor.put(ColorParam.stateEnd, HtmlColor.getColorIfValid("black")); + defaultsColor.put(ColorParam.stateStart, HtmlColor.BLACK); + defaultsColor.put(ColorParam.stateEnd, HtmlColor.BLACK); defaultsColor.put(ColorParam.usecaseBackground, HtmlColor.getColorIfValid("#FEFECE")); defaultsColor.put(ColorParam.usecaseBorder, HtmlColor.getColorIfValid("#A80036")); @@ -111,7 +113,7 @@ public class Rose implements Skin { defaultsColor.put(ColorParam.stereotypeEBackground, HtmlColor.getColorIfValid("#EB937F")); defaultsColor.put(ColorParam.packageBackground, HtmlColor.getColorIfValid("#FEFECE")); - defaultsColor.put(ColorParam.packageBorder, HtmlColor.getColorIfValid("black")); + defaultsColor.put(ColorParam.packageBorder, HtmlColor.BLACK); defaultsColor.put(ColorParam.iconPrivate, HtmlColor.getColorIfValid("#C82930")); defaultsColor.put(ColorParam.iconPrivateBackground, HtmlColor.getColorIfValid("#F24D5C")); @@ -123,8 +125,8 @@ public class Rose implements Skin { defaultsColor.put(ColorParam.iconPublicBackground, HtmlColor.getColorIfValid("#84BE84")); } - public Color getFontColor(ISkinParam skin, FontParam fontParam) { - return skin.getFontHtmlColor(fontParam, null).getColor(); + public HtmlColor getFontColor(ISkinParam skin, FontParam fontParam) { + return skin.getFontHtmlColor(fontParam, null); } public HtmlColor getHtmlColor(ISkinParam param, ColorParam color) { @@ -143,24 +145,25 @@ public class Rose implements Skin { } public Component createComponent(ComponentType type, ISkinParam param, List stringsToDisplay) { - final Color background = param.getBackgroundColor().getColor(); - final Color groupBorder = getHtmlColor(param, ColorParam.sequenceGroupBorder).getColor(); - final Color groupBackground = getHtmlColor(param, ColorParam.sequenceGroupBackground).getColor(); - final Color sequenceDividerBackground = getHtmlColor(param, ColorParam.sequenceDividerBackground).getColor(); - final Color sequenceReferenceBackground = getHtmlColor(param, ColorParam.sequenceReferenceBackground) - .getColor(); - final Color lifeLineBackgroundColor = getHtmlColor(param, ColorParam.sequenceLifeLineBackground).getColor(); - final Color sequenceArrow = getHtmlColor(param, ColorParam.sequenceArrow).getColor(); - final Color sequenceActorBackground = getHtmlColor(param, ColorParam.sequenceActorBackground).getColor(); - final Color sequenceParticipantBackground = getHtmlColor(param, ColorParam.sequenceParticipantBackground) - .getColor(); + final HtmlColor background = param.getBackgroundColor(); + final HtmlColor groupBorder = getHtmlColor(param, ColorParam.sequenceGroupBorder); + final HtmlColor groupBackground = getHtmlColor(param, ColorParam.sequenceGroupBackground); + final HtmlColor sequenceDividerBackground = getHtmlColor(param, ColorParam.sequenceDividerBackground); + final HtmlColor sequenceReferenceBackground = getHtmlColor(param, ColorParam.sequenceReferenceBackground); + final HtmlColor sequenceReferenceHeaderBackground = getHtmlColor(param, + ColorParam.sequenceReferenceHeaderBackground); + final HtmlColor sequenceReferenceBorder = getHtmlColor(param, ColorParam.sequenceReferenceBorder); + final HtmlColor lifeLineBackgroundColor = getHtmlColor(param, ColorParam.sequenceLifeLineBackground); + final HtmlColor sequenceArrow = getHtmlColor(param, ColorParam.sequenceArrow); + final HtmlColor sequenceActorBackground = getHtmlColor(param, ColorParam.sequenceActorBackground); + final HtmlColor sequenceParticipantBackground = getHtmlColor(param, ColorParam.sequenceParticipantBackground); // final Color borderColor = getHtmlColor(param, // ColorParam.border).getColor(); - final Font fontArrow = param.getFont(FontParam.SEQUENCE_ARROW, null); - final Font fontGrouping = param.getFont(FontParam.SEQUENCE_GROUP, null); - final Font fontParticipant = param.getFont(FontParam.SEQUENCE_PARTICIPANT, null); - final Font fontActor = param.getFont(FontParam.SEQUENCE_ACTOR, null); + final UFont fontArrow = param.getFont(FontParam.SEQUENCE_ARROW, null); + final UFont fontGrouping = param.getFont(FontParam.SEQUENCE_GROUP, null); + final UFont fontParticipant = param.getFont(FontParam.SEQUENCE_PARTICIPANT, null); + final UFont fontActor = param.getFont(FontParam.SEQUENCE_ACTOR, null); if (type.isArrow()) { if (type.getArrowConfiguration().isSelfArrow()) { @@ -168,46 +171,47 @@ public class Rose implements Skin { fontArrow, stringsToDisplay, type.getArrowConfiguration()); } return new ComponentRoseArrow(sequenceArrow, getFontColor(param, FontParam.SEQUENCE_ARROW), fontArrow, - stringsToDisplay, type.getArrowConfiguration()); + stringsToDisplay, type.getArrowConfiguration(), + param.getHorizontalAlignement(AlignParam.SEQUENCE_MESSAGE_ALIGN)); } if (type == ComponentType.PARTICIPANT_HEAD) { - final Color borderColor = getHtmlColor(param, ColorParam.sequenceParticipantBorder).getColor(); + final HtmlColor borderColor = getHtmlColor(param, ColorParam.sequenceParticipantBorder); return new ComponentRoseParticipant(sequenceParticipantBackground, borderColor, getFontColor(param, FontParam.SEQUENCE_PARTICIPANT), fontParticipant, stringsToDisplay); } if (type == ComponentType.PARTICIPANT_TAIL) { - final Color borderColor = getHtmlColor(param, ColorParam.sequenceParticipantBorder).getColor(); + final HtmlColor borderColor = getHtmlColor(param, ColorParam.sequenceParticipantBorder); return new ComponentRoseParticipant(sequenceParticipantBackground, borderColor, getFontColor(param, FontParam.SEQUENCE_PARTICIPANT), fontParticipant, stringsToDisplay); } if (type == ComponentType.PARTICIPANT_LINE) { - final Color borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder).getColor(); + final HtmlColor borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder); return new ComponentRoseLine(borderColor, false); } if (type == ComponentType.CONTINUE_LINE) { - final Color borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder).getColor(); + final HtmlColor borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder); return new ComponentRoseLine(borderColor, true); } if (type == ComponentType.ACTOR_HEAD) { - final Color borderColor = getHtmlColor(param, ColorParam.sequenceActorBorder).getColor(); + final HtmlColor borderColor = getHtmlColor(param, ColorParam.sequenceActorBorder); return new ComponentRoseActor(sequenceActorBackground, borderColor, getFontColor(param, FontParam.SEQUENCE_ACTOR), fontActor, stringsToDisplay, true); } if (type == ComponentType.ACTOR_TAIL) { - final Color borderColor = getHtmlColor(param, ColorParam.sequenceActorBorder).getColor(); + final HtmlColor borderColor = getHtmlColor(param, ColorParam.sequenceActorBorder); return new ComponentRoseActor(sequenceActorBackground, borderColor, getFontColor(param, FontParam.SEQUENCE_ACTOR), fontActor, stringsToDisplay, false); } if (type == ComponentType.NOTE) { - final Color noteBackgroundColor = getHtmlColor(param, ColorParam.noteBackground).getColor(); - final Color borderColor = getHtmlColor(param, ColorParam.noteBorder).getColor(); - final Font fontNote = param.getFont(FontParam.NOTE, null); + final HtmlColor noteBackgroundColor = getHtmlColor(param, ColorParam.noteBackground); + final HtmlColor borderColor = getHtmlColor(param, ColorParam.noteBorder); + final UFont fontNote = param.getFont(FontParam.NOTE, null); return new ComponentRoseNote(noteBackgroundColor, borderColor, getFontColor(param, FontParam.NOTE), fontNote, stringsToDisplay); } if (type == ComponentType.GROUPING_HEADER) { - final Font fontGroupingHeader = param.getFont(FontParam.SEQUENCE_GROUP_HEADER, null); + final UFont fontGroupingHeader = param.getFont(FontParam.SEQUENCE_GROUP_HEADER, null); return new ComponentRoseGroupingHeader(getFontColor(param, FontParam.SEQUENCE_GROUP_HEADER), background, groupBackground, groupBorder, fontGroupingHeader, fontGrouping, stringsToDisplay); } @@ -222,25 +226,23 @@ public class Rose implements Skin { fontGrouping, stringsToDisplay.get(0)); } if (type == ComponentType.ALIVE_BOX_CLOSE_CLOSE) { - final Color borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder).getColor(); + final HtmlColor borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder); return new ComponentRoseActiveLine(borderColor, lifeLineBackgroundColor, true, true); } if (type == ComponentType.ALIVE_BOX_CLOSE_OPEN) { - final Color borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder).getColor(); + final HtmlColor borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder); return new ComponentRoseActiveLine(borderColor, lifeLineBackgroundColor, true, false); } if (type == ComponentType.ALIVE_BOX_OPEN_CLOSE) { - final Color borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder).getColor(); + final HtmlColor borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder); return new ComponentRoseActiveLine(borderColor, lifeLineBackgroundColor, false, true); } if (type == ComponentType.ALIVE_BOX_OPEN_OPEN) { - final Color borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder).getColor(); + final HtmlColor borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder); return new ComponentRoseActiveLine(borderColor, lifeLineBackgroundColor, false, false); } if (type == ComponentType.DELAY_LINE) { - final Color borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder).getColor(); - // final Color borderColor = getFontColor(param, - // FontParam.SEQUENCE_DELAY); + final HtmlColor borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder); return new ComponentRoseDelayLine(borderColor); } if (type == ComponentType.DELAY_TEXT) { @@ -248,7 +250,7 @@ public class Rose implements Skin { FontParam.SEQUENCE_DELAY, null), stringsToDisplay); } if (type == ComponentType.DESTROY) { - final Color borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder).getColor(); + final HtmlColor borderColor = getHtmlColor(param, ColorParam.sequenceLifeLineBorder); return new ComponentRoseDestroy(borderColor); } if (type == ComponentType.NEWPAGE) { @@ -259,20 +261,28 @@ public class Rose implements Skin { FontParam.SEQUENCE_DIVIDER, null), sequenceDividerBackground, stringsToDisplay); } if (type == ComponentType.REFERENCE) { - return new ComponentRoseReference(getFontColor(param, FontParam.SEQUENCE_REFERENCE), param.getFont( - FontParam.SEQUENCE_REFERENCE, null), sequenceReferenceBackground, stringsToDisplay); + final HtmlColor sequenceReferenceBackground2 = getHtmlColor(param, ColorParam.sequenceReferenceBackground); + final HtmlColor sequenceReferenceHeaderBackground2 = getHtmlColor(param, + ColorParam.sequenceReferenceHeaderBackground); + + final UFont fontGroupingHeader = param.getFont(FontParam.SEQUENCE_GROUP_HEADER, null); + return new ComponentRoseReference(getFontColor(param, FontParam.SEQUENCE_REFERENCE), getFontColor(param, + FontParam.SEQUENCE_GROUP), param.getFont(FontParam.SEQUENCE_REFERENCE, null), + sequenceReferenceBorder, sequenceReferenceHeaderBackground, sequenceReferenceBackground, + fontGroupingHeader, stringsToDisplay, + param.getHorizontalAlignement(AlignParam.SEQUENCE_REFERENCE_ALIGN)); } if (type == ComponentType.TITLE) { return new ComponentRoseTitle(getFontColor(param, FontParam.SEQUENCE_TITLE), param.getFont( FontParam.SEQUENCE_TITLE, null), stringsToDisplay); } if (type == ComponentType.SIGNATURE) { - return new ComponentRoseTitle(Color.BLACK, fontGrouping, Arrays.asList("This skin was created ", + return new ComponentRoseTitle(HtmlColor.BLACK, fontGrouping, Arrays.asList("This skin was created ", "in April 2009.")); } if (type == ComponentType.ENGLOBER) { - final Color borderColor = getHtmlColor(param, ColorParam.sequenceBoxBorder).getColor(); - final Color backColor = getHtmlColor(param, ColorParam.sequenceBoxBackground).getColor(); + final HtmlColor borderColor = getHtmlColor(param, ColorParam.sequenceBoxBorder); + final HtmlColor backColor = getHtmlColor(param, ColorParam.sequenceBoxBackground); return new ComponentRoseEnglober(borderColor, backColor, stringsToDisplay, getFontColor(param, FontParam.SEQUENCE_BOX), param.getFont(FontParam.SEQUENCE_BOX, null)); } diff --git a/src/net/sourceforge/plantuml/statediagram/StateDiagram.java b/src/net/sourceforge/plantuml/statediagram/StateDiagram.java index 7ec96c3cf..c2e4bcba6 100644 --- a/src/net/sourceforge/plantuml/statediagram/StateDiagram.java +++ b/src/net/sourceforge/plantuml/statediagram/StateDiagram.java @@ -28,11 +28,13 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6221 $ + * Revision $Revision: 6927 $ * */ package net.sourceforge.plantuml.statediagram; +import java.util.List; + import net.sourceforge.plantuml.UmlDiagramType; import net.sourceforge.plantuml.UniqueSequence; import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram; @@ -40,6 +42,7 @@ 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.Link; public class StateDiagram extends AbstractEntityDiagram { @@ -71,6 +74,21 @@ public class StateDiagram extends AbstractEntityDiagram { return getOrCreateEntity("*end*" + p.getCode(), EntityType.CIRCLE_END); } + public IEntity getHistorical() { + final Group g = getCurrentGroup(); + if (g == null) { + return getOrCreateEntity("*historical", EntityType.PSEUDO_STATE); + } + return getOrCreateEntity("*historical*" + g.getCode(), EntityType.PSEUDO_STATE); + } + + public IEntity getHistorical(String codeGroup) { + final Group g = getOrCreateGroup(codeGroup, null, null, GroupType.STATE, null); + final IEntity result = getOrCreateEntity("*historical*" + g.getCode(), EntityType.PSEUDO_STATE); + endGroup(); + return result; + } + public boolean concurrentState() { final Group cur = getCurrentGroup(); if (cur != null && cur.getType() == GroupType.CONCURRENT_STATE) { @@ -102,7 +120,7 @@ public class StateDiagram extends AbstractEntityDiagram { public UmlDiagramType getUmlDiagramType() { return UmlDiagramType.STATE; } - + private boolean hideEmptyDescription = false; public final void setHideEmptyDescription(boolean hideEmptyDescription) { @@ -113,13 +131,24 @@ public class StateDiagram extends AbstractEntityDiagram { return hideEmptyDescription; } -// @Override -// final protected List getDotStrings() { -// return Arrays.asList("nodesep=1.95;", "ranksep=1.8;", "edge [fontsize=11,labelfontsize=11];", -// "node [fontsize=11,height=.35,width=.55];"); -// } + final public Link getLastStateLink() { + final List links = getLinks(); + for (int i = links.size() - 1; i >= 0; i--) { + final Link link = links.get(i); + if (link.getEntity1().getType() != EntityType.NOTE && link.getEntity2().getType() != EntityType.NOTE) { + return link; + } + } + return null; + } - - + + + // @Override + // final protected List getDotStrings() { + // return Arrays.asList("nodesep=1.95;", "ranksep=1.8;", "edge + // [fontsize=11,labelfontsize=11];", + // "node [fontsize=11,height=.35,width=.55];"); + // } } diff --git a/src/net/sourceforge/plantuml/statediagram/StateDiagramFactory.java b/src/net/sourceforge/plantuml/statediagram/StateDiagramFactory.java index 6e853d12a..74a991beb 100644 --- a/src/net/sourceforge/plantuml/statediagram/StateDiagramFactory.java +++ b/src/net/sourceforge/plantuml/statediagram/StateDiagramFactory.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6396 $ + * Revision $Revision: 6931 $ * */ package net.sourceforge.plantuml.statediagram; @@ -46,6 +46,8 @@ import net.sourceforge.plantuml.statediagram.command.CommandCreateState2; import net.sourceforge.plantuml.statediagram.command.CommandEndState; import net.sourceforge.plantuml.statediagram.command.CommandHideEmptyDescription; import net.sourceforge.plantuml.statediagram.command.CommandLinkState2; +import net.sourceforge.plantuml.statediagram.command.CommandMultilinesNoteOnStateLink; +import net.sourceforge.plantuml.statediagram.command.CommandNoteOnStateLink; import net.sourceforge.plantuml.usecasediagram.command.CommandRankDirUsecase; public class StateDiagramFactory extends AbstractUmlSystemCommandFactory { @@ -63,7 +65,7 @@ public class StateDiagramFactory extends AbstractUmlSystemCommandFactory { addCommand(new CommandRankDirUsecase(system)); addCommand(new CommandCreateState(system)); addCommand(new CommandCreateState2(system)); - //addCommand(new CommandLinkState(system)); + // addCommand(new CommandLinkState(system)); addCommand(new CommandLinkState2(system)); addCommand(new CommandCreatePackageState(system)); addCommand(new CommandCreatePackageState2(system)); @@ -74,6 +76,8 @@ public class StateDiagramFactory extends AbstractUmlSystemCommandFactory { addCommand(new CommandHideEmptyDescription(system)); addCommand(new CommandNoteEntity(system)); + addCommand(new CommandNoteOnStateLink(system)); + addCommand(new CommandMultilinesNoteOnStateLink(system)); addCommand(new CommandUrl(system)); addCommonCommands(system); } diff --git a/src/net/sourceforge/plantuml/statediagram/command/CommandCreateState.java b/src/net/sourceforge/plantuml/statediagram/command/CommandCreateState.java index 5679fa6b1..19d77a8da 100644 --- a/src/net/sourceforge/plantuml/statediagram/command/CommandCreateState.java +++ b/src/net/sourceforge/plantuml/statediagram/command/CommandCreateState.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5727 $ + * Revision $Revision: 6923 $ * */ package net.sourceforge.plantuml.statediagram.command; @@ -39,6 +39,7 @@ import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.SingleLineCommand; import net.sourceforge.plantuml.cucadiagram.Entity; import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.statediagram.StateDiagram; public class CommandCreateState extends SingleLineCommand { @@ -55,14 +56,14 @@ public class CommandCreateState extends SingleLineCommand { display = code; } final Entity ent = (Entity) getSystem().getOrCreateClass(code); - ent.setDisplay(display); + ent.setDisplay2(display); final String stereotype = arg.get(2); if (stereotype != null) { ent.setStereotype(new Stereotype(stereotype)); } if (arg.get(3)!=null) { - ent.setSpecificBackcolor(arg.get(3)); + ent.setSpecificBackcolor(HtmlColor.getColorIfValid(arg.get(3))); } return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/statediagram/command/CommandCreateState2.java b/src/net/sourceforge/plantuml/statediagram/command/CommandCreateState2.java index e331ddc22..fe5e83c2c 100644 --- a/src/net/sourceforge/plantuml/statediagram/command/CommandCreateState2.java +++ b/src/net/sourceforge/plantuml/statediagram/command/CommandCreateState2.java @@ -39,6 +39,7 @@ import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.SingleLineCommand; import net.sourceforge.plantuml.cucadiagram.Entity; import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.statediagram.StateDiagram; public class CommandCreateState2 extends SingleLineCommand { @@ -52,14 +53,14 @@ public class CommandCreateState2 extends SingleLineCommand { final String code = arg.get(0); final String display = arg.get(1); final Entity ent = (Entity) getSystem().getOrCreateClass(code); - ent.setDisplay(display); + ent.setDisplay2(display); final String stereotype = arg.get(2); if (stereotype != null) { ent.setStereotype(new Stereotype(stereotype)); } if (arg.get(3) != null) { - ent.setSpecificBackcolor(arg.get(3)); + ent.setSpecificBackcolor(HtmlColor.getColorIfValid(arg.get(3))); } return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/statediagram/command/CommandLinkState2.java b/src/net/sourceforge/plantuml/statediagram/command/CommandLinkState2.java index e41d04527..56d2a705b 100644 --- a/src/net/sourceforge/plantuml/statediagram/command/CommandLinkState2.java +++ b/src/net/sourceforge/plantuml/statediagram/command/CommandLinkState2.java @@ -48,6 +48,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; import net.sourceforge.plantuml.statediagram.StateDiagram; public class CommandLinkState2 extends SingleLineCommand2 { @@ -61,7 +62,8 @@ public class CommandLinkState2 extends SingleLineCommand2 { new RegexLeaf("^"), // getStatePattern("ENT1"), // new RegexLeaf("\\s*"), // - new RegexLeaf("ARROW", + new RegexLeaf( + "ARROW", "((-+)(left|right|up|down|le?|ri?|up?|do?)?(?:\\[((?:#\\w+|dotted|dashed|bold)(?:,#\\w+|,dotted|,dashed|,bold)*)\\])?(-*)\\>)"), new RegexLeaf("\\s*"), // getStatePattern("ENT2"), // @@ -71,7 +73,8 @@ public class CommandLinkState2 extends SingleLineCommand2 { } private static RegexLeaf getStatePattern(String name) { - return new RegexLeaf(name, "([\\p{L}0-9_.]+|\\[\\*\\])\\s*(\\<\\<.*\\>\\>)?\\s*(#\\w+)?"); + return new RegexLeaf(name, + "([\\p{L}0-9_.]+|[\\p{L}0-9_.]+\\[H\\]|\\[\\*\\]|\\[H\\])\\s*(\\<\\<.*\\>\\>)?\\s*(#\\w+)?"); } @Override @@ -86,13 +89,13 @@ public class CommandLinkState2 extends SingleLineCommand2 { cl1.setStereotype(new Stereotype(arg.get("ENT1").get(1))); } if (arg.get("ENT1").get(2) != null) { - cl1.setSpecificBackcolor(arg.get("ENT1").get(2)); + cl1.setSpecificBackcolor(HtmlColor.getColorIfValid(arg.get("ENT1").get(2))); } if (arg.get("ENT2").get(1) != null) { cl2.setStereotype(new Stereotype(arg.get("ENT2").get(1))); } if (arg.get("ENT2").get(2) != null) { - cl2.setSpecificBackcolor(arg.get("ENT2").get(2)); + cl2.setSpecificBackcolor(HtmlColor.getColorIfValid(arg.get("ENT2").get(2))); } String queue = arg.get("ARROW").get(1) + arg.get("ARROW").get(4); @@ -139,6 +142,12 @@ public class CommandLinkState2 extends SingleLineCommand2 { if (code.startsWith("[*]")) { return getSystem().getStart(); } + if (code.equalsIgnoreCase("[H]")) { + return getSystem().getHistorical(); + } + if (code.endsWith("[H]")) { + return getSystem().getHistorical(code.substring(0, code.length() - 3)); + } return getSystem().getOrCreateClass(code); } @@ -146,6 +155,9 @@ public class CommandLinkState2 extends SingleLineCommand2 { if (code.startsWith("[*]")) { return getSystem().getEnd(); } + if (code.endsWith("[H]")) { + return getSystem().getHistorical(code.substring(0, code.length() - 3)); + } return getSystem().getOrCreateClass(code); } diff --git a/src/net/sourceforge/plantuml/statediagram/command/CommandMultilinesNoteOnStateLink.java b/src/net/sourceforge/plantuml/statediagram/command/CommandMultilinesNoteOnStateLink.java new file mode 100644 index 000000000..2d6e78f22 --- /dev/null +++ b/src/net/sourceforge/plantuml/statediagram/command/CommandMultilinesNoteOnStateLink.java @@ -0,0 +1,76 @@ +/* ======================================================================== + * 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: 6922 $ + * + */ +package net.sourceforge.plantuml.statediagram.command; + +import java.util.List; +import java.util.regex.Matcher; + +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.CommandMultilines; +import net.sourceforge.plantuml.command.Position; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.statediagram.StateDiagram; + +public class CommandMultilinesNoteOnStateLink extends CommandMultilines { + + public CommandMultilinesNoteOnStateLink(final StateDiagram diagram) { + super(diagram, "(?i)^note\\s+(right|left|top|bottom)?\\s*on\\s+link$", "(?i)^end ?note$"); + } + + public CommandExecutionResult execute(List lines) { + final List strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1)); + if (strings.size() > 0) { + final List n = StringUtils.manageEmbededDiagrams(strings); + + final Link link = getSystem().getLastStateLink(); + if (link == null) { + return CommandExecutionResult.error("No link defined"); + } + Position position = Position.BOTTOM; + final Matcher m = getStartingPattern().matcher(lines.get(0)); + if (m.find()) { + final String pos = m.group(1); + if (pos != null) { + position = Position.valueOf(pos.toUpperCase()); + } + } + + link.addNote(n, position); + return CommandExecutionResult.ok(); + } + return CommandExecutionResult.error("No note defined"); + } + +} diff --git a/src/net/sourceforge/plantuml/statediagram/command/CommandNoteOnStateLink.java b/src/net/sourceforge/plantuml/statediagram/command/CommandNoteOnStateLink.java new file mode 100644 index 000000000..981089786 --- /dev/null +++ b/src/net/sourceforge/plantuml/statediagram/command/CommandNoteOnStateLink.java @@ -0,0 +1,65 @@ +/* ======================================================================== + * 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: 6923 $ + * + */ +package net.sourceforge.plantuml.statediagram.command; + +import java.util.List; + +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.Position; +import net.sourceforge.plantuml.command.SingleLineCommand; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.statediagram.StateDiagram; + +public class CommandNoteOnStateLink extends SingleLineCommand { + + public CommandNoteOnStateLink(StateDiagram diagram) { + super(diagram, "(?i)^note\\s+(right|left|top|bottom)?\\s*on\\s+link\\s*:\\s*(.*)$"); + } + + @Override + protected CommandExecutionResult executeArg(List arg) { + final Link link = getSystem().getLastStateLink(); + if (link == null) { + return CommandExecutionResult.error("No link defined"); + } + Position position = Position.BOTTOM; + if (arg.get(0) != null) { + position = Position.valueOf(arg.get(0).toUpperCase()); + } + + link.addNote(arg.get(1), position); + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java b/src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java index c8f3e39f3..0f12b6328 100644 --- a/src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java +++ b/src/net/sourceforge/plantuml/sudoku/GraphicsSudoku.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6009 $ + * Revision $Revision: 6591 $ * */ package net.sourceforge.plantuml.sudoku; @@ -46,15 +46,18 @@ import java.util.List; import net.sourceforge.plantuml.EmptyImageBuilder; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; import net.sourceforge.plantuml.png.PngIO; +import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity; +import net.sourceforge.plantuml.ugraphic.UFont; public class GraphicsSudoku { private final ISudoku sudoku; - private final Font numberFont = new Font("SansSerif", Font.BOLD, 20); - private final Font font = new Font("SansSerif", Font.PLAIN, 11); + private final UFont numberFont = new UFont("SansSerif", Font.BOLD, 20); + private final UFont font = new UFont("SansSerif", Font.PLAIN, 11); public GraphicsSudoku(ISudoku sudoku) { this.sudoku = sudoku; @@ -92,8 +95,9 @@ public class GraphicsSudoku { final int num = sudoku.getGiven(x, y); if (num > 0) { final TextBlock text = TextBlockUtils.create(Arrays.asList("" + num), new FontConfiguration( - numberFont, Color.BLACK), HorizontalAlignement.CENTER); - text.drawTOBEREMOVED(g2d, numberxOffset + x * cellWidth, numberyOffset + y * cellHeight); + numberFont, HtmlColor.BLACK), HorizontalAlignement.CENTER); + text.drawTOBEREMOVED(new ColorMapperIdentity(), g2d, numberxOffset + x * cellWidth, numberyOffset + + y * cellHeight); } } } @@ -114,9 +118,9 @@ public class GraphicsSudoku { texts.add("http://plantuml.sourceforge.net"); texts.add("Seed " + Long.toString(sudoku.getSeed(), 36)); texts.add("Difficulty " + sudoku.getRatting()); - final TextBlock textBlock = TextBlockUtils.create(texts, new FontConfiguration(font, Color.BLACK), + final TextBlock textBlock = TextBlockUtils.create(texts, new FontConfiguration(font, HtmlColor.BLACK), HorizontalAlignement.LEFT); - textBlock.drawTOBEREMOVED(g2d, 0, 0); + textBlock.drawTOBEREMOVED(new ColorMapperIdentity(), g2d, 0, 0); g2d.dispose(); return im; diff --git a/src/net/sourceforge/plantuml/sudoku/PSystemSudoku.java b/src/net/sourceforge/plantuml/sudoku/PSystemSudoku.java index c4a0e4e82..61a02c3ed 100644 --- a/src/net/sourceforge/plantuml/sudoku/PSystemSudoku.java +++ b/src/net/sourceforge/plantuml/sudoku/PSystemSudoku.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6453 $ + * Revision $Revision: 6710 $ * */ package net.sourceforge.plantuml.sudoku; @@ -43,19 +43,6 @@ public class PSystemSudoku extends AbstractPSystem { final private ISudoku sudoku; -// public List createFiles(File suggestedFile, FileFormatOption fileFormat) throws IOException, InterruptedException { -// OutputStream os = null; -// try { -// os = new FileOutputStream(suggestedFile); -// new GraphicsSudoku(sudoku).writeImage(os); -// } finally { -// if (os != null) { -// os.close(); -// } -// } -// return Arrays.asList(suggestedFile); -// } - public void exportDiagram(OutputStream os, StringBuilder cmap, int index, FileFormatOption fileFormat) throws IOException { new GraphicsSudoku(sudoku).writeImage(os); } diff --git a/src/net/sourceforge/plantuml/sudoku/PSystemSudokuFactory.java b/src/net/sourceforge/plantuml/sudoku/PSystemSudokuFactory.java index 23b26e4e8..93205300e 100644 --- a/src/net/sourceforge/plantuml/sudoku/PSystemSudokuFactory.java +++ b/src/net/sourceforge/plantuml/sudoku/PSystemSudokuFactory.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6341 $ + * Revision $Revision: 6750 $ * */ package net.sourceforge.plantuml.sudoku; @@ -43,11 +43,7 @@ public class PSystemSudokuFactory implements PSystemBasicFactory { private PSystemSudoku system; - public PSystemSudokuFactory() { - reset(); - } - - public void reset() { + public void init(String startLine) { } public PSystemSudoku getSystem() { diff --git a/src/net/sourceforge/plantuml/suggest/SuggestEngine.java b/src/net/sourceforge/plantuml/suggest/SuggestEngine.java index c99a1334e..f2bb61a3a 100644 --- a/src/net/sourceforge/plantuml/suggest/SuggestEngine.java +++ b/src/net/sourceforge/plantuml/suggest/SuggestEngine.java @@ -52,6 +52,7 @@ final public class SuggestEngine { private final PSystemCommandFactory systemFactory; private final Iterator it; + private final String startLine; // private int nb = 0; private String current = ""; private String previous = ""; @@ -59,7 +60,8 @@ final public class SuggestEngine { public SuggestEngine(UmlSource source, PSystemCommandFactory systemFactory) { this.systemFactory = systemFactory; this.it = source.iterator(); - if (StartUtils.isArobaseStartDiagram(next()) == false) { + startLine = next(); + if (StartUtils.isArobaseStartDiagram(startLine) == false) { throw new UnsupportedOperationException(); } } @@ -80,7 +82,7 @@ final public class SuggestEngine { } private SuggestEngineResult executeUmlCommand() throws IOException { - systemFactory.reset(); + systemFactory.init(startLine); while (hasNext()) { final String s = next(); if (StartUtils.isArobaseEndDiagram(s)) { diff --git a/src/net/sourceforge/plantuml/svek/AbstractEntityImage.java b/src/net/sourceforge/plantuml/svek/AbstractEntityImage.java new file mode 100644 index 000000000..517fe85bb --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/AbstractEntityImage.java @@ -0,0 +1,112 @@ +/* ======================================================================== + * 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: 3831 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.ugraphic.UFont; + +abstract class AbstractEntityImage implements IEntityImage { + + private final IEntity entity; + private final ISkinParam skinParam; + // private final String stereoLabel; + + private final Rose rose = new Rose(); + + public AbstractEntityImage(IEntity entity, ISkinParam skinParam) { + if (entity == null) { + throw new IllegalArgumentException("entity null"); + } + this.entity = entity; + this.skinParam = skinParam; + + // final Stereotype stereotype = entity.getStereotype(); + // if (stereotype == null) { + // stereoLabel = null; + // } else { + // stereoLabel = stereotype.getLabel(); + // } + } + + public abstract Dimension2D getDimension(StringBounder stringBounder); + + protected final IEntity getEntity() { + return entity; + } + + protected final UFont getFontOld(FontParam fontParam) { + return skinParam.getFont(fontParam, null); + } + + protected final UFont getFont(FontParam fontParam, Stereotype stereo) { + final String s = stereo == null ? null : stereo.getLabel(); + return skinParam.getFont(fontParam, s); + } + + protected final HtmlColor getFontColor(FontParam fontParam, Stereotype stereo) { + final String s = stereo == null ? null : stereo.getLabel(); + return skinParam.getFontHtmlColor(fontParam, s); + } + + protected final HtmlColor getColor(ColorParam colorParam, Stereotype stereo) { + final String s = stereo == null ? null : stereo.getLabel(); + return rose.getHtmlColor(skinParam, colorParam, s); + } + +// protected final HtmlColor getColorOld(ColorParam colorParam) { +// return rose.getHtmlColor(skinParam, colorParam); +// } + + protected final ISkinParam getSkinParam() { + return skinParam; + } + + public final HtmlColor getBackcolor() { + return null; + } + + protected final Stereotype getStereo() { + return entity.getStereotype(); + } + +} diff --git a/src/net/sourceforge/plantuml/svek/ArithmeticStrategy.java b/src/net/sourceforge/plantuml/svek/ArithmeticStrategy.java new file mode 100644 index 000000000..24d04ec43 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/ArithmeticStrategy.java @@ -0,0 +1,42 @@ +/* ======================================================================== + * 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: 4236 $ + * + */ +package net.sourceforge.plantuml.svek; + +public interface ArithmeticStrategy { + + void eat(double v); + + double getResult(); + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/eps/InkscapeUtils.java b/src/net/sourceforge/plantuml/svek/ArithmeticStrategyMax.java similarity index 71% rename from src/net/sourceforge/plantuml/eps/InkscapeUtils.java rename to src/net/sourceforge/plantuml/svek/ArithmeticStrategyMax.java index b38bd3f2c..84c30e7af 100644 --- a/src/net/sourceforge/plantuml/eps/InkscapeUtils.java +++ b/src/net/sourceforge/plantuml/svek/ArithmeticStrategyMax.java @@ -27,33 +27,24 @@ * in the United States and other countries.] * * Original Author: Arnaud Roques - * - * Revision $Revision: 4826 $ * + * Revision $Revision: 4236 $ + * */ -package net.sourceforge.plantuml.eps; +package net.sourceforge.plantuml.svek; -import java.io.File; +public class ArithmeticStrategyMax implements ArithmeticStrategy { -public class InkscapeUtils { + private double max; - private static boolean isWindows() { - return File.separatorChar == '\\'; - } - - public static Inkscape create() { - if (isWindows()) { - return new InkscapeWindows(); + public void eat(double v) { + if (v > max) { + max = v; } - return new InkscapeLinux(); } - public static String getenvInkscape() { - final String env = System.getProperty("INKSCAPE"); - if (env != null) { - return env; - } - return System.getenv("INKSCAPE"); + public double getResult() { + return max; } -} +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/svek/ArithmeticStrategySum.java b/src/net/sourceforge/plantuml/svek/ArithmeticStrategySum.java new file mode 100644 index 000000000..96154f677 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/ArithmeticStrategySum.java @@ -0,0 +1,48 @@ +/* ======================================================================== + * 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: 4236 $ + * + */ +package net.sourceforge.plantuml.svek; + +public class ArithmeticStrategySum implements ArithmeticStrategy { + + private double sum; + + public void eat(double v) { + sum += v; + } + + public double getResult() { + return sum; + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/svek/Cluster.java b/src/net/sourceforge/plantuml/svek/Cluster.java new file mode 100644 index 000000000..8402a2ac5 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/Cluster.java @@ -0,0 +1,365 @@ +/* ======================================================================== + * 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: 4236 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.OptionFlags; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.UmlDiagramType; +import net.sourceforge.plantuml.cucadiagram.Group; +import net.sourceforge.plantuml.cucadiagram.dot.DotData; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UShape; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public class Cluster { + + private final Cluster parent; + private final Group group; + private final List shapes = new ArrayList(); + private final List children = new ArrayList(); + private final boolean special; + private final int color; + private final int colorTitle; + + public Cluster(ColorSequence colorSequence) { + this(null, null, false, colorSequence); + } + + private int getUid2() { + return group.getUid2(); + } + + private Cluster(Cluster parent, Group group, boolean special, ColorSequence colorSequence) { + this.parent = parent; + this.group = group; + this.special = special; + this.color = colorSequence.getValue(); + this.colorTitle = colorSequence.getValue(); + } + + @Override + public String toString() { + return super.toString() + " " + group; + } + + public final Cluster getParent() { + return parent; + } + + public void addShape(Shape sh) { + this.shapes.add(sh); + sh.setCluster(this); + } + + public final List getShapes() { + return Collections.unmodifiableList(shapes); + } + + private List getShapesOrdered(Collection lines) { + final List all = new ArrayList(shapes); + final List firsts = new ArrayList(); + final Set tops = new HashSet(); + final Map shs = new HashMap(); + + for (final Iterator it = all.iterator(); it.hasNext();) { + final Shape sh = it.next(); + shs.put(sh.getUid(), sh); + if (sh.isTop()) { + firsts.add(sh); + tops.add(sh.getUid()); + it.remove(); + } + } + + for (Line l : lines) { + if (tops.contains(l.getStartUid())) { + final Shape sh = shs.get(l.getEndUid()); + all.remove(sh); + firsts.add(0, sh); + } + if (l.isInverted()) { + final Shape sh = shs.get(l.getStartUid()); + all.remove(sh); + firsts.add(0, sh); + } + } + + all.addAll(0, firsts); + return all; + } + + public final List getChildren() { + return Collections.unmodifiableList(children); + } + + private int titleWidth; + private int titleHeight; + private TextBlock title; + + public Cluster createChild(Group g, int titleWidth, int titleHeight, TextBlock title, boolean special, + ColorSequence colorSequence) { + final Cluster child = new Cluster(this, g, special, colorSequence); + child.titleWidth = titleWidth; + child.titleHeight = titleHeight; + child.title = title; + this.children.add(child); + return child; + } + + public final Group getGroup() { + return group; + } + + public final int getTitleWidth() { + return titleWidth; + } + + public final int getTitleHeight() { + return titleHeight; + } + + private double xTitle; + private double yTitle; + + public void setTitlePosition(double x, double y) { + this.xTitle = x; + this.yTitle = y; + } + + public void drawU(UGraphic ug, double x, double y, HtmlColor borderColor, DotData dotData) { + final boolean isState = dotData.getUmlDiagramType() == UmlDiagramType.STATE; + if (isState) { + drawUState(ug, x, y, borderColor, dotData); + return; + } + final UShape rect = new URectangle(maxX - minX, maxY - minY); + HtmlColor stateBack = getBackColor(); + if (stateBack == null) { + stateBack = dotData.getSkinParam().getHtmlColor(ColorParam.packageBackground, group.getStereotype()); + } + ug.getParam().setBackcolor(stateBack); + ug.getParam().setColor(borderColor); + ug.getParam().setStroke(new UStroke(2)); + ug.draw(x + minX, y + minY, rect); + ug.getParam().setStroke(new UStroke()); + if (title != null) { + title.drawU(ug, x + xTitle, y + yTitle); + } + } + + private HtmlColor getColor(DotData dotData, ColorParam colorParam, String stereo) { + return new Rose().getHtmlColor(dotData.getSkinParam(), colorParam, stereo); + } + + private void drawUState(UGraphic ug, double x, double y, HtmlColor borderColor, DotData dotData) { + + final Dimension2D total = new Dimension2DDouble(maxX - minX, maxY - minY); + final double suppY = title.calculateDimension(ug.getStringBounder()).getHeight() + EntityImageState.MARGIN + + EntityImageState.MARGIN_LINE; + HtmlColor stateBack = getBackColor(); + if (stateBack == null) { + stateBack = getColor(dotData, ColorParam.stateBackground, group.getStereotype()); + } + final HtmlColor background = getColor(dotData, ColorParam.background, null); + final RoundedContainer r = new RoundedContainer(total, suppY, borderColor, stateBack, background); + r.drawU(ug, x + minX, y + minY); + + title.drawU(ug, x + xTitle, y + yTitle); + + } + + private double minX; + private double minY; + private double maxX; + private double maxY; + + public void setPosition(double minX, double minY, double maxX, double maxY) { + this.minX = minX; + this.maxX = maxX; + this.minY = minY; + this.maxY = maxY; + + } + + public boolean isSpecial() { + return special; + } + + public void printCluster(StringBuilder sb, Collection lines) { + System.err.println("Cluster::printCluster " + this); + + final Set rankSame = new HashSet(); + for (Line l : lines) { + final String startUid = l.getStartUid(); + final String endUid = l.getEndUid(); + if (isInCluster(startUid) && isInCluster(endUid)) { + final String same = l.rankSame(); + if (same != null) { + rankSame.add(same); + } + } + } + + for (Shape sh : getShapesOrdered(lines)) { + sh.appendShape(sb); + } + + for (String same : rankSame) { + sb.append(same); + SvekUtils.println(sb); + } + + for (Cluster child : getChildren()) { + child.printInternal(sb, lines); + } + } + + public void fillRankMin(Set rankMin) { + for (Shape sh : getShapes()) { + if (sh.isTop()) { + rankMin.add(sh.getUid()); + } + } + + for (Cluster child : getChildren()) { + child.fillRankMin(rankMin); + } + } + + private boolean isInCluster(String uid) { + for (Shape sh : shapes) { + if (sh.getUid().equals(uid)) { + return true; + } + } + return false; + } + + public String getClusterId() { + return "cluster" + color; + } + + public String getSpecialPointId() { + return "za" + getUid2(); + } + + private void printInternal(StringBuilder sb, Collection lines) { + if (isSpecial()) { + subgraphCluster(sb, "a"); + } + sb.append("subgraph " + getClusterId() + " {"); + sb.append("style=solid;"); + sb.append("color=\"" + StringUtils.getAsHtml(color) + "\";"); + + final int titleWidth = getTitleWidth(); + final int titleHeight = getTitleHeight(); + if (titleHeight > 0 && titleWidth > 0) { + sb.append("label=<"); + Line.appendTable(sb, titleWidth, titleHeight, colorTitle); + sb.append(">;"); + } + SvekUtils.println(sb); + + if (isSpecial()) { + // subgraphCluster(sb, "za"); + if (OptionFlags.getInstance().isDebugDot()) { + sb.append(getSpecialPointId() + ";"); + } else { + sb.append(getSpecialPointId() + " [shape=point,width=.01,label=\"\"];"); + } + // sb.append("}"); + subgraphCluster(sb, "i"); + } + printCluster(sb, lines); + if (isSpecial()) { + sb.append("}"); + // subgraphCluster(sb, "zb"); + // if (OptionFlags.getInstance().isDebugDot()) { + // sb.append("zb" + child.getUid2() + ";"); + // } else { + // sb.append("zb" + child.getUid2() + " + // [shape=point,width=.01,label=\"\"];"); + // } + // sb.append("}"); + } + sb.append("}"); + if (this.isSpecial()) { + // a + sb.append("}"); + } + SvekUtils.println(sb); + } + + private void subgraphCluster(StringBuilder sb, String id) { + final String uid = getClusterId() + id; + sb.append("subgraph " + uid + " {"); + if (OptionFlags.getInstance().isDebugDot()) { + sb.append("style=dotted;"); + sb.append("label=\"" + id + "\";"); + } else { + sb.append("style=invis;"); + sb.append("label=\"\";"); + } + } + + public int getColor() { + return color; + } + + public int getTitleColor() { + return colorTitle; + } + + private final HtmlColor getBackColor() { + return group.getBackColor(); + } + +} diff --git a/src/net/sourceforge/plantuml/svek/ColorSequence.java b/src/net/sourceforge/plantuml/svek/ColorSequence.java new file mode 100644 index 000000000..b3a04aba5 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/ColorSequence.java @@ -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: 6644 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.util.concurrent.atomic.AtomicInteger; + +public class ColorSequence { + + private final AtomicInteger cpt = new AtomicInteger(1); + + public int getValue() { + return cpt.addAndGet(1); + } + +} diff --git a/src/net/sourceforge/plantuml/svek/CucaDiagramFileMakerSvek.java b/src/net/sourceforge/plantuml/svek/CucaDiagramFileMakerSvek.java new file mode 100644 index 000000000..3b6b55815 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/CucaDiagramFileMakerSvek.java @@ -0,0 +1,218 @@ +/* ======================================================================== + * 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.svek; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.Dimension2D; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.OutputStream; +import java.util.List; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.EmptyImageBuilder; +import net.sourceforge.plantuml.FileFormat; +import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.UmlDiagramType; +import net.sourceforge.plantuml.cucadiagram.CucaDiagram; +import net.sourceforge.plantuml.cucadiagram.dot.CucaDiagramSimplifier2; +import net.sourceforge.plantuml.cucadiagram.dot.DotData; +import net.sourceforge.plantuml.cucadiagram.dot.ICucaDiagramFileMaker; +import net.sourceforge.plantuml.eps.EpsStrategy; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.StringBounderUtils; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.graphic.VerticalPosition; +import net.sourceforge.plantuml.png.PngIO; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.eps.UGraphicEps; +import net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d; +import net.sourceforge.plantuml.ugraphic.svg.UGraphicSvg; + +public final class CucaDiagramFileMakerSvek implements ICucaDiagramFileMaker { + + private final CucaDiagram diagram; + private final List flashcodes; + + static private final StringBounder stringBounder; + + static { + final EmptyImageBuilder builder = new EmptyImageBuilder(10, 10, Color.WHITE); + stringBounder = StringBounderUtils.asStringBounder(builder.getGraphics2D()); + } + + public CucaDiagramFileMakerSvek(CucaDiagram diagram, List flashcodes) throws IOException { + this.diagram = diagram; + this.flashcodes = flashcodes; + } + + public String createFile(OutputStream os, List dotStrings, FileFormatOption fileFormatOption) + throws IOException { + + try { + createFileInternal(os, dotStrings, fileFormatOption); + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + return "svek"; + + } + + private void createFileInternal(OutputStream os, List dotStrings, FileFormatOption fileFormatOption) + throws IOException, InterruptedException { + if (diagram.getUmlDiagramType() == UmlDiagramType.STATE + || diagram.getUmlDiagramType() == UmlDiagramType.ACTIVITY) { + new CucaDiagramSimplifier2(diagram, dotStrings); + } + + final DotData dotData = new DotData(null, diagram.getLinks(), diagram.entities(), diagram.getUmlDiagramType(), + diagram.getSkinParam(), diagram.getRankdir(), diagram, diagram, diagram.getColorMapper()); + final CucaDiagramFileMakerSvek2 skek2 = new CucaDiagramFileMakerSvek2(dotData); + + IEntityImage result = skek2.createFile(((CucaDiagram) diagram).getDotStringSkek()); + result = addTitle(result); + result = addHeaderAndFooter(result); + + final Dimension2D dim = Dimension2DDouble.delta(result.getDimension(stringBounder), 10); + + final FileFormat fileFormat = fileFormatOption.getFileFormat(); + if (fileFormat == FileFormat.PNG) { + createPng(os, fileFormatOption, result, dim); + } else if (fileFormat == FileFormat.SVG) { + createSvg(os, fileFormatOption, result, dim); + } else if (fileFormat == FileFormat.EPS) { + createEps(os, fileFormatOption, result, dim); + } else { + throw new UnsupportedOperationException(fileFormat.toString()); + } + + } + + private IEntityImage addHeaderAndFooter(IEntityImage original) { + final List footer = diagram.getFooter(); + final List header = diagram.getHeader(); + if (footer == null && header == null) { + return original; + } + final TextBlock textFooter = footer == null ? null : TextBlockUtils.create(footer, new FontConfiguration( + getFont(FontParam.FOOTER), getFontColor(FontParam.FOOTER, null)), diagram.getFooterAlignement()); + final TextBlock textHeader = header == null ? null : TextBlockUtils.create(header, new FontConfiguration( + getFont(FontParam.HEADER), getFontColor(FontParam.HEADER, null)), diagram.getHeaderAlignement()); + + return new DecorateEntityImage(original, textHeader, diagram.getHeaderAlignement(), textFooter, diagram + .getFooterAlignement()); + } + + private IEntityImage addTitle(IEntityImage original) { + final List title = diagram.getTitle(); + if (title == null) { + return original; + } + final TextBlock text = TextBlockUtils.create(title, new FontConfiguration(getFont(FontParam.TITLE), + getFontColor(FontParam.TITLE, null)), HorizontalAlignement.CENTER); + + return new DecorateEntityImage(original, text, HorizontalAlignement.CENTER); + } + + private final UFont getFont(FontParam fontParam) { + final ISkinParam skinParam = diagram.getSkinParam(); + return skinParam.getFont(fontParam, null); + } + + private final HtmlColor getFontColor(FontParam fontParam, String stereo) { + final ISkinParam skinParam = diagram.getSkinParam(); + return skinParam.getFontHtmlColor(fontParam, stereo); + } + + private void createPng(OutputStream os, FileFormatOption fileFormatOption, final IEntityImage result, + final Dimension2D dim) throws IOException { + Color backColor = Color.WHITE; + if (result.getBackcolor() != null) { + backColor = diagram.getSkinParam().getColorMapper().getMappedColor(result.getBackcolor()); + } + + final EmptyImageBuilder builder = new EmptyImageBuilder((int) dim.getWidth(), (int) dim.getHeight(), backColor); + final Graphics2D graphics2D = builder.getGraphics2D(); + + final UGraphic ug = new UGraphicG2d(diagram.getSkinParam().getColorMapper(), graphics2D, builder + .getBufferedImage(), 1.0); + result.drawU(ug, 0, 0); + + final BufferedImage im = ((UGraphicG2d) ug).getBufferedImage(); + PngIO.write(im, os, diagram.getMetadata(), diagram.getDpi(fileFormatOption)); + } + + private void createSvg(OutputStream os, FileFormatOption fileFormatOption, final IEntityImage result, + final Dimension2D dim) throws IOException { + + Color backColor = Color.WHITE; + if (result.getBackcolor() != null) { + backColor = diagram.getSkinParam().getColorMapper().getMappedColor(result.getBackcolor()); + } + final UGraphicSvg ug; + if (backColor.equals(Color.WHITE)) { + ug = new UGraphicSvg(diagram.getSkinParam().getColorMapper(), false); + } else { + ug = new UGraphicSvg(diagram.getSkinParam().getColorMapper(), StringUtils.getAsHtml(backColor), false); + } + + result.drawU(ug, 0, 0); + + ug.createXml(os); + + } + + private void createEps(OutputStream os, FileFormatOption fileFormatOption, final IEntityImage result, + final Dimension2D dim) throws IOException { + + final UGraphicEps ug = new UGraphicEps(diagram.getSkinParam().getColorMapper(), EpsStrategy.getDefault2()); + + result.drawU(ug, 0, 0); + os.write(ug.getEPSCode().getBytes()); + + } + +} diff --git a/src/net/sourceforge/plantuml/svek/CucaDiagramFileMakerSvek2.java b/src/net/sourceforge/plantuml/svek/CucaDiagramFileMakerSvek2.java new file mode 100644 index 000000000..138d1a929 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/CucaDiagramFileMakerSvek2.java @@ -0,0 +1,385 @@ +/* ======================================================================== + * 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.svek; + +import java.awt.Color; +import java.awt.geom.Dimension2D; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.EmptyImageBuilder; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.UmlDiagramType; +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.Link; +import net.sourceforge.plantuml.cucadiagram.dot.DotData; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.GraphicStrings; +import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.StringBounderUtils; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.ugraphic.UFont; + +public final class CucaDiagramFileMakerSvek2 { + + private final ColorSequence colorSequence = new ColorSequence(); + + private final DotData dotData; + + static private final StringBounder stringBounder; + + static { + final EmptyImageBuilder builder = new EmptyImageBuilder(10, 10, Color.WHITE); + stringBounder = StringBounderUtils.asStringBounder(builder.getGraphics2D()); + } + + public CucaDiagramFileMakerSvek2(DotData dotData) { + this.dotData = dotData; + } + + protected UFont getFont(FontParam fontParam) { + return getData().getSkinParam().getFont(fontParam, null); + } + + private IEntityImage createEntityImageBlock(DotData dotData, IEntity ent) { + if (ent.getType() == EntityType.CLASS || ent.getType() == EntityType.ABSTRACT_CLASS + || ent.getType() == EntityType.INTERFACE || ent.getType() == EntityType.ENUM) { + return new EntityImageClass(ent, dotData.getSkinParam(), dotData); + } + if (ent.getType() == EntityType.NOTE) { + return new EntityImageNote(ent, dotData.getSkinParam()); + } + if (ent.getType() == EntityType.ACTIVITY) { + return new EntityImageActivity(ent, dotData.getSkinParam()); + } + if (ent.getType() == EntityType.STATE) { + return new EntityImageState(ent, dotData.getSkinParam()); + } + if (ent.getType() == EntityType.CIRCLE_START) { + return new EntityImageCircleStart(ent, dotData.getSkinParam()); + } + if (ent.getType() == EntityType.CIRCLE_END) { + return new EntityImageCircleEnd(ent, dotData.getSkinParam()); + } + if (ent.getType() == EntityType.USECASE) { + return new EntityImageUseCase(ent, dotData.getSkinParam()); + } + if (ent.getType() == EntityType.BRANCH) { + return new EntityImageBranch(ent, dotData.getSkinParam()); + } + if (ent.getType() == EntityType.LOLLIPOP) { + return new EntityImageLollipopInterface(ent, dotData.getSkinParam()); + } + if (ent.getType() == EntityType.ACTOR) { + return new EntityImageActor(ent, dotData.getSkinParam()); + } + if (ent.getType() == EntityType.COMPONENT) { + return new EntityImageComponent(ent, dotData.getSkinParam()); + } + if (ent.getType() == EntityType.OBJECT) { + return new EntityImageObject(ent, dotData.getSkinParam()); + } + if (ent.getType() == EntityType.SYNCHRO_BAR) { + return new EntityImageSynchroBar(ent, dotData.getSkinParam()); + } + if (ent.getType() == EntityType.CIRCLE_INTERFACE) { + return new EntityImageCircleInterface(ent, dotData.getSkinParam()); + } + if (ent.getType() == EntityType.POINT_FOR_ASSOCIATION) { + return new EntityImageAssociationPoint(ent, dotData.getSkinParam()); + } + if (ent.getType() == EntityType.GROUP) { + return new EntityImageGroup(ent, dotData.getSkinParam()); + } + if (ent.getType() == EntityType.EMPTY_PACKAGE) { + return new EntityImageEmptyPackage(ent, dotData.getSkinParam()); + } + throw new UnsupportedOperationException(ent.getType().toString()); + } + + private DotStringFactory dotStringFactory; + private Map shapeMap; + + private String getShapeUid(IEntity ent) { + final Shape result = shapeMap.get(ent); + if (result == null && ent.getType() == EntityType.GROUP) { + for (IEntity i : shapeMap.keySet()) { + if (ent.getParent().getCode().equals(i.getCode())) { + return shapeMap.get(i).getUid(); + } + } + if (result == null) { + return "za" + ent.getParent().getUid2(); + } + } + return result.getUid(); + } + + public IEntityImage createFile(String... dotStrings) throws IOException, InterruptedException { + + dotStringFactory = new DotStringFactory(colorSequence, stringBounder, dotData.getUmlDiagramType()); + shapeMap = new HashMap(); + + printGroups(null); + printEntities(getUnpackagedEntities()); + + final Map lineMap = new HashMap(); + + for (Link link : dotData.getLinks()) { + final String shapeUid1 = getShapeUid(link.getEntity1()); + final String shapeUid2 = getShapeUid(link.getEntity2()); + + String ltail = null; + if (shapeUid1.startsWith("za")) { + ltail = getCluster(link.getEntity1().getParent()).getClusterId(); + } + String lhead = null; + if (shapeUid2.startsWith("za")) { + lhead = getCluster(link.getEntity2().getParent()).getClusterId(); + } + final FontConfiguration labelFont = new FontConfiguration(dotData.getSkinParam().getFont( + FontParam.ACTIVITY_ARROW, null), HtmlColor.BLACK); + + final Line line = new Line(shapeUid1, shapeUid2, link, colorSequence, ltail, lhead, dotData.getSkinParam(), + stringBounder, labelFont); + dotStringFactory.addLine(line); + lineMap.put(link, line); + } + + if (dotStringFactory.illegalDotExe()) { + return error(dotStringFactory.getDotExe()); + } + + final Dimension2D dim = Dimension2DDouble.delta(dotStringFactory.solve(dotStrings), 10); + final HtmlColor border; + if (getData().getUmlDiagramType() == UmlDiagramType.STATE) { + border = getColor(ColorParam.stateBorder, null); + } else { + border = getColor(ColorParam.packageBorder, null); + } + return new SvekResult(dim, dotData, dotStringFactory, border); + + } + + protected final HtmlColor getColor(ColorParam colorParam, String stereo) { + return new Rose().getHtmlColor(dotData.getSkinParam(), colorParam, stereo); + } + + private Cluster getCluster(Group g) { + for (Cluster cl : dotStringFactory.getAllSubCluster()) { + if (cl.getGroup() == g) { + return cl; + } + } + throw new IllegalArgumentException(g.toString()); + } + + private IEntityImage error(File dotExe) { + + final List msg = new ArrayList(); + msg.add("Dot Executable: " + dotExe); + if (dotExe != null) { + if (dotExe.exists() == false) { + msg.add("File does not exist"); + } else if (dotExe.isDirectory()) { + msg.add("It should be an executable, not a directory"); + } else if (dotExe.isFile() == false) { + msg.add("Not a valid file"); + } else if (dotExe.canRead() == false) { + msg.add("File cannot be read"); + } + } + msg.add("Cannot find Graphviz. You should try"); + msg.add(" "); + msg.add("@startuml"); + msg.add("testdot"); + msg.add("@enduml"); + msg.add(" "); + msg.add(" or "); + msg.add(" "); + msg.add("java -jar plantuml.jar -testdot"); + return new GraphicStrings(msg); + } + + private void printEntities(Collection entities2) { + for (IEntity ent : entities2) { + printEntity(ent); + } + } + + private void printEntity(IEntity ent) { + + final IEntityImage image; + if (ent.getSvekImage() == null) { + image = createEntityImageBlock(dotData, ent); + } else { + image = ent.getSvekImage(); + } + final Dimension2D dim = image.getDimension(stringBounder); + final Shape shape = new Shape(image.getShapeType(), dim.getWidth(), dim.getHeight(), colorSequence, ent.isTop()); + dotStringFactory.addShape(shape); + shape.setImage(image); + shapeMap.put(ent, shape); + } + + private Collection getUnpackagedEntities() { + final List result = new ArrayList(); + for (IEntity ent : dotData.getEntities().values()) { + if (ent.getParent() == dotData.getTopParent()) { + result.add(ent); + } + } + return result; + } + + private void printGroups(Group parent) throws IOException { + for (Group g : dotData.getGroupHierarchy().getChildrenGroups(parent)) { + if (dotData.isEmpty(g) && g.getType() == GroupType.PACKAGE) { + final IEntity folder = new Entity(g.getUid1(), g.getUid2(), g.getCode(), g.getDisplay(), + EntityType.EMPTY_PACKAGE, null, null); + printEntity(folder); + } else { + printGroup(g); + } + } + } + + private void printGroup(Group g) throws IOException { + if (g.getType() == GroupType.CONCURRENT_STATE) { + return; + } + // final String stereo = g.getStereotype(); + + int titleWidth = 0; + int titleHeight = 0; + + final String label = g.getDisplay(); + TextBlock title = null; + if (label != null) { + final UFont font = getFont(g.getType() == GroupType.STATE ? FontParam.STATE : FontParam.PACKAGE); + title = TextBlockUtils.create(StringUtils.getWithNewlines(label), new FontConfiguration(font, + HtmlColor.BLACK), HorizontalAlignement.CENTER); + final Dimension2D dimLabel = title.calculateDimension(stringBounder); + titleWidth = (int) dimLabel.getWidth(); + titleHeight = (int) dimLabel.getHeight(); + } + + dotStringFactory.openCluster(g, titleWidth, titleHeight, title, isSpecialGroup(g)); + this.printEntities(g.entities().values()); + + // sb.append("subgraph " + g.getUid() + " {"); + // + // 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 + "\";"); + // } + // + // if (g.getDisplay() != null) { + // sb.append("label=<" + manageHtmlIB(g.getDisplay(), + // getFontParamForGroup(), stereo) + ">;"); + // } + // final String fontColor = + // getAsHtml(getData().getSkinParam().getFontHtmlColor(getFontParamForGroup(), + // stereo)); + // sb.append("fontcolor=\"" + fontColor + "\";"); + // + // if (getGroupBackColor(g) != null) { + // sb.append("fillcolor=\"" + getAsHtml(getGroupBackColor(g)) + "\";"); + // } + // + // if (g.getType() == GroupType.STATE) { + // sb.append("color=" + getColorString(ColorParam.stateBorder, stereo) + + // ";"); + // } else { + // sb.append("color=" + getColorString(ColorParam.packageBorder, stereo) + // + ";"); + // } + // sb.append("style=\"" + getStyle(g) + "\";"); + // + printGroups(g); + // + // this.printEntities(sb, g.entities().values()); + // for (Link link : getData().getLinks()) { + // eventuallySameRank(sb, g, link); + // } + // sb.append("}"); + + dotStringFactory.closeCluster(); + } + + private boolean isSpecialGroup(Group g) { + if (g.getType() == GroupType.STATE) { + return true; + } + if (g.getType() == GroupType.CONCURRENT_STATE) { + throw new IllegalStateException(); + } + if (getData().isThereLink(g)) { + return true; + } + return false; + } + + private DotData getData() { + return dotData; + } + + private HtmlColor getGroupBackColor(Group g) { + HtmlColor value = g.getBackColor(); + if (value == null) { + value = getData().getSkinParam().getHtmlColor(ColorParam.packageBackground, null); + } + return value; + } + +} diff --git a/src/net/sourceforge/plantuml/svek/DecorateEntityImage.java b/src/net/sourceforge/plantuml/svek/DecorateEntityImage.java new file mode 100644 index 000000000..519e4937f --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/DecorateEntityImage.java @@ -0,0 +1,124 @@ +/* ======================================================================== + * 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: 4236 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.ugraphic.UGraphic; + +public class DecorateEntityImage implements IEntityImage { + + private final IEntityImage original; + private final HorizontalAlignement horizontal1; + private final TextBlock text1; + private final HorizontalAlignement horizontal2; + private final TextBlock text2; + + public DecorateEntityImage(IEntityImage original, TextBlock text, HorizontalAlignement horizontal) { + this(original, text, horizontal, null, null); + } + + public DecorateEntityImage(IEntityImage original, TextBlock text1, HorizontalAlignement horizontal1, + TextBlock text2, HorizontalAlignement horizontal2) { + this.original = original; + this.horizontal1 = horizontal1; + this.text1 = text1; + this.horizontal2 = horizontal2; + this.text2 = text2; + } + + public void drawU(UGraphic ug, double x, double y) { + final StringBounder stringBounder = ug.getStringBounder(); + final Dimension2D dimOriginal = original.getDimension(stringBounder); + final Dimension2D dimText1 = getTextDim(text1, stringBounder); + final Dimension2D dimText2 = getTextDim(text2, stringBounder); + final Dimension2D dimTotal = getDimension(stringBounder); + + final double yText1 = y; + final double yImage = yText1 + dimText1.getHeight(); + final double yText2 = yImage + dimOriginal.getHeight(); + + final double xImage = (dimTotal.getWidth() - dimOriginal.getWidth()) / 2; + + if (text1 != null) { + final double xText1 = getTextX(dimText1, dimTotal, horizontal1); + text1.drawU(ug, xText1, yText1); + } + original.drawU(ug, xImage, yImage); + if (text2 != null) { + final double xText2 = getTextX(dimText2, dimTotal, horizontal2); + text2.drawU(ug, xText2, yText2); + } + } + + private Dimension2D getTextDim(TextBlock text, StringBounder stringBounder) { + if (text == null) { + return new Dimension2DDouble(0, 0); + } + return text.calculateDimension(stringBounder); + } + + private double getTextX(final Dimension2D dimText, final Dimension2D dimTotal, HorizontalAlignement h) { + if (h == HorizontalAlignement.CENTER) { + return (dimTotal.getWidth() - dimText.getWidth()) / 2; + } else if (h == HorizontalAlignement.LEFT) { + return 0; + } else if (h == HorizontalAlignement.RIGHT) { + return dimTotal.getWidth() - dimText.getWidth(); + } else { + throw new IllegalStateException(); + } + } + + public HtmlColor getBackcolor() { + return original.getBackcolor(); + } + + public Dimension2D getDimension(StringBounder stringBounder) { + final Dimension2D dimOriginal = original.getDimension(stringBounder); + final Dimension2D dimText = Dimension2DDouble.mergeTB(getTextDim(text1, stringBounder), getTextDim(text2, + stringBounder)); + return Dimension2DDouble.mergeTB(dimOriginal, dimText); + } + + public ShapeType getShapeType() { + return ShapeType.RECTANGLE; + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/svek/DotStringFactory.java b/src/net/sourceforge/plantuml/svek/DotStringFactory.java new file mode 100644 index 000000000..0c34d80a2 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/DotStringFactory.java @@ -0,0 +1,321 @@ +/* ======================================================================== + * 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: 4236 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.UmlDiagramType; +import net.sourceforge.plantuml.cucadiagram.Group; +import net.sourceforge.plantuml.cucadiagram.dot.Graphviz; +import net.sourceforge.plantuml.cucadiagram.dot.GraphvizUtils; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; + +public class DotStringFactory { + + private final List allShapes = new ArrayList(); + private final List allCluster = new ArrayList(); + + final private Set rankMin = new HashSet(); + + private final ColorSequence colorSequence; + private final Cluster root; + private final List lines = new ArrayList(); + private Cluster current; + private final UmlDiagramType type; + + private final StringBounder stringBounder; + + public DotStringFactory(ColorSequence colorSequence, StringBounder stringBounder, UmlDiagramType type) { + this.colorSequence = colorSequence; + this.type = type; + this.stringBounder = stringBounder; + this.root = new Cluster(colorSequence); + this.current = root; + } + + public void addShape(Shape shape) { + allShapes.add(shape); + current.addShape(shape); + } + + private void printMinRanking(StringBuilder sb) { + if (rankMin.size() == 0) { + return; + } + sb.append("{ rank = min;"); + for (String id : rankMin) { + sb.append(id); + sb.append(";"); + } + sb.append("}"); + + } + + private double getHorizontalDzeta() { + double max = 0; + for (Line l : lines) { + final double c = l.getHorizontalDzeta(stringBounder); + if (c > max) { + max = c; + } + } + return max / 10; + } + + private double getVerticalDzeta() { + double max = 0; + for (Line l : lines) { + final double c = l.getVerticalDzeta(stringBounder); + if (c > max) { + max = c; + } + } + return max / 10; + } + + public String createDotString(String... dotStrings) { + final StringBuilder sb = new StringBuilder(); + + double nodesep = getHorizontalDzeta(); + if (nodesep < getMinNodeSep()) { + nodesep = getMinNodeSep(); + } + final String nodesepInches = SvekUtils.pixelToInches(nodesep); + System.err.println("nodesep=" + nodesepInches); + double ranksep = getVerticalDzeta(); + if (ranksep < getMinRankSep()) { + ranksep = getMinRankSep(); + } + final String ranksepInches = SvekUtils.pixelToInches(ranksep); + System.err.println("ranksep=" + ranksepInches); + sb.append("digraph unix {"); + SvekUtils.println(sb); + + for (String s : dotStrings) { + if (s.startsWith("ranksep")) { + sb.append("ranksep=" + ranksepInches + ";"); + } else if (s.startsWith("nodesep")) { + sb.append("nodesep=" + nodesepInches + ";"); + } else { + sb.append(s); + } + SvekUtils.println(sb); + } + sb.append("remincross=true;"); + SvekUtils.println(sb); + sb.append("searchsize=500;"); + SvekUtils.println(sb); + sb.append("compound=true;"); + SvekUtils.println(sb); + + root.fillRankMin(rankMin); + root.printCluster(sb, lines); + printMinRanking(sb); + + for (Line line : lines) { + line.appendLine(sb); + } + SvekUtils.println(sb); + sb.append("}"); + + return sb.toString(); + } + + private int getMinRankSep() { + if (type == UmlDiagramType.ACTIVITY) { + return 29; + } + return 60; + } + + private int getMinNodeSep() { + if (type == UmlDiagramType.ACTIVITY) { + return 15; + } + return 25; + } + + String getSVG(String... dotStrings) throws IOException, InterruptedException { + final String dotString = createDotString(dotStrings); + System.err.println("dotString=" + dotString); + + final Graphviz graphviz = GraphvizUtils.create(dotString, "svg"); + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + graphviz.createFile(baos); + baos.close(); + final byte[] result = baos.toByteArray(); + final String s = new String(result, "UTF-8"); + + SvekUtils.traceSvgString(s); + + return s; + } + + public boolean illegalDotExe() { + final Graphviz graphviz = GraphvizUtils.create(null, "svg"); + final File dotExe = graphviz.getDotExe(); + return dotExe == null || dotExe.isFile() == false || dotExe.canRead() == false; + } + + public File getDotExe() { + final Graphviz graphviz = GraphvizUtils.create(null, "svg"); + return graphviz.getDotExe(); + } + + public Dimension2D solve(String... dotStrings) throws IOException, InterruptedException { + final String svg = getSVG(dotStrings); + + final Pattern pGraph = Pattern.compile("(?m)\\" + sh.getUid() + ""); + if (sh.getType() == ShapeType.RECTANGLE || sh.getType() == ShapeType.DIAMOND) { + final List points = SvekUtils.extractPointsList(svg, idx, fullHeight); + final double minX = SvekUtils.getMinX(points); + final double minY = SvekUtils.getMinY(points); + sh.setMinX(minX); + sh.setMinY(minY); + } else if (sh.getType() == ShapeType.ROUND_RECTANGLE) { + idx = svg.indexOf("points=\"", idx + 1); + final List points = SvekUtils.extractPointsList(svg, idx, fullHeight); + for (int i = 0; i < 3; i++) { + idx = svg.indexOf("points=\"", idx + 1); + points.addAll(SvekUtils.extractPointsList(svg, idx, fullHeight)); + } + final double minX = SvekUtils.getMinX(points); + final double minY = SvekUtils.getMinY(points); + sh.setMinX(minX); + sh.setMinY(minY); + } else if (sh.getType() == ShapeType.CIRCLE || sh.getType() == ShapeType.CIRCLE_IN_RECT + || sh.getType() == ShapeType.OVAL) { + final double cx = SvekUtils.getValue(svg, idx, "cx"); + final double cy = SvekUtils.getValue(svg, idx, "cy") + fullHeight; + final double rx = SvekUtils.getValue(svg, idx, "rx"); + final double ry = SvekUtils.getValue(svg, idx, "ry"); + sh.setMinX(cx - rx); + sh.setMinY(cy - ry); + } else { + throw new IllegalStateException(sh.getType().toString() + " " + sh.getUid()); + } + } + + for (Cluster cluster : allCluster) { + final String key = "=\"" + StringUtils.getAsHtml(cluster.getColor()).toLowerCase() + "\""; + int idx = svg.indexOf(key); + if (idx == -1) { + throw new IllegalStateException(key); + } + final List points = SvekUtils.extractPointsList(svg, idx, fullHeight); + final double minX = SvekUtils.getMinX(points); + final double minY = SvekUtils.getMinY(points); + final double maxX = SvekUtils.getMaxX(points); + final double maxY = SvekUtils.getMaxY(points); + cluster.setPosition(minX, minY, maxX, maxY); + + if (cluster.getTitleWidth() == 0 || cluster.getTitleHeight() == 0) { + continue; + } + final String keyTitle = "=\"" + StringUtils.getAsHtml(cluster.getTitleColor()).toLowerCase() + "\""; + idx = svg.indexOf(keyTitle); + if (idx == -1) { + throw new IllegalStateException(keyTitle); + } + final List pointsTitle = SvekUtils.extractPointsList(svg, idx, fullHeight); + final double minXtitle = SvekUtils.getMinX(pointsTitle); + final double minYtitle = SvekUtils.getMinY(pointsTitle); + cluster.setTitlePosition(minXtitle, minYtitle); + + } + + for (Line line : lines) { + line.solveLine(svg, fullHeight); + } + + for (Line line : lines) { + line.manageCollision(allShapes); + } + + + return new Dimension2DDouble(fullWidth, fullHeight); + } + + public void addLine(Line line) { + lines.add(line); + } + + public final List getShapes() { + return Collections.unmodifiableList(allShapes); + } + + public List getLines() { + return Collections.unmodifiableList(lines); + } + + public void openCluster(Group g, int titleWidth, int titleHeight, TextBlock title, boolean isSpecialGroup) { + this.current = current.createChild(g, titleWidth, titleHeight, title, isSpecialGroup, colorSequence); + this.allCluster.add(this.current); + } + + public void closeCluster() { + if (current.getParent() == null) { + throw new IllegalStateException(); + } + this.current = current.getParent(); + } + + public final List getAllSubCluster() { + return Collections.unmodifiableList(allCluster); + } + +} diff --git a/src/net/sourceforge/plantuml/svek/EntityImageActivity.java b/src/net/sourceforge/plantuml/svek/EntityImageActivity.java new file mode 100644 index 000000000..819ccdf5b --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/EntityImageActivity.java @@ -0,0 +1,104 @@ +/* ======================================================================== + * 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: 5183 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignement; +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.UGraphic; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public class EntityImageActivity extends AbstractEntityImage { + + public static final int CORNER = 25; + final private TextBlock desc; + final private static int MARGIN = 10; + + public EntityImageActivity(IEntity entity, ISkinParam skinParam) { + super(entity, skinParam); + final Stereotype stereotype = entity.getStereotype(); + + this.desc = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( + getFont(FontParam.ACTIVITY, stereotype), getFontColor(FontParam.ACTIVITY, stereotype)), + HorizontalAlignement.CENTER); + } + + @Override + public Dimension2D getDimension(StringBounder stringBounder) { + final Dimension2D dim = desc.calculateDimension(stringBounder); + return Dimension2DDouble.delta(dim, MARGIN * 2); + } + + public void drawU(UGraphic ug, double xTheoricalPosition, double yTheoricalPosition) { + final StringBounder stringBounder = ug.getStringBounder(); + final Dimension2D dimTotal = getDimension(stringBounder); + + final double widthTotal = dimTotal.getWidth(); + final double heightTotal = dimTotal.getHeight(); + final URectangle rect = new URectangle(widthTotal, heightTotal, CORNER, CORNER); + + ug.getParam().setStroke(new UStroke(1.5)); + ug.getParam().setColor(getColor(ColorParam.activityBorder, getStereo())); + HtmlColor backcolor = getEntity().getSpecificBackColor(); + if (backcolor == null) { + backcolor = getColor(ColorParam.activityBackground, getStereo()); + } + ug.getParam().setBackcolor(backcolor); + + ug.draw(xTheoricalPosition, yTheoricalPosition, rect); + ug.getParam().setStroke(new UStroke()); + + final double x = xTheoricalPosition + MARGIN; + final double y = yTheoricalPosition + MARGIN; + desc.drawU(ug, x, y); + + } + + public ShapeType getShapeType() { + return ShapeType.ROUND_RECTANGLE; + } +} diff --git a/src/net/sourceforge/plantuml/svek/EntityImageActor.java b/src/net/sourceforge/plantuml/svek/EntityImageActor.java new file mode 100644 index 000000000..fd6929144 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/EntityImageActor.java @@ -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: 5183 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.MathUtils; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.skin.StickMan; +import net.sourceforge.plantuml.ugraphic.UGraphic; + +public class EntityImageActor extends AbstractEntityImage { + + private final StickMan stickman; + private final TextBlock name; + private final TextBlock stereo; + + public EntityImageActor(IEntity entity, ISkinParam skinParam) { + super(entity, skinParam); + final Stereotype stereotype = entity.getStereotype(); + + this.name = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( + getFont(FontParam.USECASE_ACTOR, stereotype), getFontColor(FontParam.USECASE_ACTOR, stereotype)), + HorizontalAlignement.CENTER); + this.stickman = new StickMan(getColor(ColorParam.usecaseActorBackground, getStereo()), getColor( + ColorParam.usecaseActorBorder, getStereo())); + + if (stereotype == null || stereotype.getLabel() == null) { + this.stereo = null; + } else { + this.stereo = TextBlockUtils.create(StringUtils.getWithNewlines(stereotype.getLabel()), + new FontConfiguration(getFont(FontParam.USECASE_ACTOR_STEREOTYPE, stereotype), getFontColor( + FontParam.USECASE_ACTOR_STEREOTYPE, null)), HorizontalAlignement.CENTER); + } + + } + + @Override + public Dimension2D getDimension(StringBounder stringBounder) { + final Dimension2D dimName = name.calculateDimension(stringBounder); + final Dimension2D dimStereo = getStereoDimension(stringBounder); + final Dimension2D dimActor = new Dimension2DDouble(stickman.getPreferredWidth(stringBounder), stickman + .getPreferredHeight(stringBounder)); + return Dimension2DDouble.mergeTB(dimStereo, dimActor, dimName); + } + + private Dimension2D getStereoDimension(StringBounder stringBounder) { + if (stereo == null) { + return new Dimension2DDouble(0, 0); + } + return stereo.calculateDimension(stringBounder); + } + + public void drawU(UGraphic ug, double xTheoricalPosition, double yTheoricalPosition) { + final StringBounder stringBounder = ug.getStringBounder(); + final Dimension2D dimStereo = getStereoDimension(stringBounder); + final Dimension2D dimTotal = getDimension(stringBounder); + final Dimension2D dimName = name.calculateDimension(stringBounder); + final double dx = ug.getTranslateX(); + final double dy = ug.getTranslateY(); + final double manX = (dimTotal.getWidth() - stickman.getPreferredWidth(stringBounder)) / 2; + final double manY = dimStereo.getHeight(); + ug.translate(xTheoricalPosition + manX, yTheoricalPosition + manY); + stickman.drawU(ug); + ug.setTranslate(dx, dy); + final double nameX = (dimTotal.getWidth() - dimName.getWidth()) / 2; + final double nameY = stickman.getPreferredHeight(stringBounder) + dimStereo.getHeight(); + name.drawU(ug, xTheoricalPosition + nameX, yTheoricalPosition + nameY); + + if (stereo != null) { + final double stereoX = (dimTotal.getWidth() - dimStereo.getWidth()) / 2; + stereo.drawU(ug, xTheoricalPosition + stereoX, yTheoricalPosition); + } + + } + + public ShapeType getShapeType() { + return ShapeType.RECTANGLE; + } +} diff --git a/src/net/sourceforge/plantuml/svek/EntityImageAssociationPoint.java b/src/net/sourceforge/plantuml/svek/EntityImageAssociationPoint.java new file mode 100644 index 000000000..d5b4680a4 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/EntityImageAssociationPoint.java @@ -0,0 +1,71 @@ +/* ======================================================================== + * 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: 5183 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.UEllipse; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UShape; + +public class EntityImageAssociationPoint extends AbstractEntityImage { + + private static final int SIZE = 4; + + public EntityImageAssociationPoint(IEntity entity, ISkinParam skinParam) { + super(entity, skinParam); + } + + @Override + public Dimension2D getDimension(StringBounder stringBounder) { + return new Dimension2DDouble(SIZE, SIZE); + } + + public void drawU(UGraphic ug, double xTheoricalPosition, double yTheoricalPosition) { + final UShape circle = new UEllipse(SIZE, SIZE); + ug.getParam().setColor(null); + ug.getParam().setBackcolor(HtmlColor.BLACK); + ug.draw(xTheoricalPosition, yTheoricalPosition, circle); + } + + public ShapeType getShapeType() { + return ShapeType.CIRCLE; + } + +} diff --git a/src/net/sourceforge/plantuml/svek/EntityImageBranch.java b/src/net/sourceforge/plantuml/svek/EntityImageBranch.java new file mode 100644 index 000000000..da92e7843 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/EntityImageBranch.java @@ -0,0 +1,84 @@ +/* ======================================================================== + * 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: 5183 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UPolygon; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public class EntityImageBranch extends AbstractEntityImage { + + final private static int SIZE = 12; + + public EntityImageBranch(IEntity entity, ISkinParam skinParam) { + super(entity, skinParam); + } + + @Override + public Dimension2D getDimension(StringBounder stringBounder) { + return new Dimension2DDouble(SIZE * 2, SIZE * 2); + } + + public void drawU(UGraphic ug, double xTheoricalPosition, double yTheoricalPosition) { + // final StringBounder stringBounder = ug.getStringBounder(); + // final Dimension2D dimTotal = getDimension(stringBounder); + // + // final double widthTotal = dimTotal.getWidth(); + // final double heightTotal = dimTotal.getHeight(); + + final UPolygon diams = new UPolygon(); + diams.addPoint(SIZE, 0); + diams.addPoint(SIZE * 2, SIZE); + diams.addPoint(SIZE, SIZE * 2); + diams.addPoint(0, SIZE); + diams.addPoint(SIZE, 0); + + ug.getParam().setStroke(new UStroke(1.5)); + ug.getParam().setColor(getColor(ColorParam.activityBorder, getStereo())); + ug.getParam().setBackcolor(getColor(ColorParam.activityBackground, getStereo())); + ug.draw(xTheoricalPosition, yTheoricalPosition, diams); + ug.getParam().setStroke(new UStroke()); + } + + public ShapeType getShapeType() { + return ShapeType.DIAMOND; + } +} diff --git a/src/net/sourceforge/plantuml/svek/EntityImageCircleEnd.java b/src/net/sourceforge/plantuml/svek/EntityImageCircleEnd.java new file mode 100644 index 000000000..e3cdf64c2 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/EntityImageCircleEnd.java @@ -0,0 +1,81 @@ +/* ======================================================================== + * 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: 5183 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.UEllipse; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UShape; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public class EntityImageCircleEnd extends AbstractEntityImage { + + private static final int SIZE = 20; + + public EntityImageCircleEnd(IEntity entity, ISkinParam skinParam) { + super(entity, skinParam); + } + + @Override + public Dimension2D getDimension(StringBounder stringBounder) { + return new Dimension2DDouble(SIZE, SIZE); + } + + public void drawU(UGraphic ug, double xTheoricalPosition, double yTheoricalPosition) { + final UShape circle = new UEllipse(SIZE, SIZE); + ug.getParam().setStroke(new UStroke()); + ug.getParam().setBackcolor(null); + ug.getParam().setColor(getColor(ColorParam.activityEnd, getStereo())); + ug.draw(xTheoricalPosition, yTheoricalPosition, circle); + ug.getParam().setStroke(new UStroke()); + + final double delta = 4; + final UShape circleSmall = new UEllipse(SIZE - delta * 2, SIZE - delta * 2); + ug.getParam().setColor(null); + ug.getParam().setBackcolor(getColor(ColorParam.activityEnd, getStereo())); + ug.draw(xTheoricalPosition + delta + 0.5, yTheoricalPosition + delta + 0.5, circleSmall); + + } + + public ShapeType getShapeType() { + return ShapeType.CIRCLE; + } + +} diff --git a/src/net/sourceforge/plantuml/svek/EntityImageCircleInterface.java b/src/net/sourceforge/plantuml/svek/EntityImageCircleInterface.java new file mode 100644 index 000000000..67bac2b9d --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/EntityImageCircleInterface.java @@ -0,0 +1,127 @@ +/* ======================================================================== + * 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: 5183 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.UEllipse; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UShape; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public class EntityImageCircleInterface extends AbstractEntityImage { + + private static final int SIZE = 16; + + private final TextBlock name; + private final TextBlock stereo; + + public EntityImageCircleInterface(IEntity entity, ISkinParam skinParam) { + super(entity, skinParam); + + final Stereotype stereotype = entity.getStereotype(); + + this.name = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( + getFont(FontParam.COMPONENT, stereotype), getFontColor(FontParam.COMPONENT, stereotype)), + HorizontalAlignement.CENTER); + + if (stereotype == null || stereotype.getLabel() == null) { + this.stereo = null; + } else { + this.stereo = TextBlockUtils.create(StringUtils.getWithNewlines(stereotype.getLabel()), + new FontConfiguration(getFont(FontParam.COMPONENT_STEREOTYPE, stereotype), getFontColor( + FontParam.COMPONENT_STEREOTYPE, null)), HorizontalAlignement.CENTER); + } + + } + + @Override + public Dimension2D getDimension(StringBounder stringBounder) { + final Dimension2D dimName = name.calculateDimension(stringBounder); + final Dimension2D dimStereo = getStereoDimension(stringBounder); + final Dimension2D circle = new Dimension2DDouble(SIZE, SIZE); + return Dimension2DDouble.mergeTB(dimStereo, circle, dimName); + } + + private Dimension2D getStereoDimension(StringBounder stringBounder) { + if (stereo == null) { + return new Dimension2DDouble(0, 0); + } + return stereo.calculateDimension(stringBounder); + } + + public void drawU(UGraphic ug, double xTheoricalPosition, double yTheoricalPosition) { + final StringBounder stringBounder = ug.getStringBounder(); + final Dimension2D dimStereo = getStereoDimension(stringBounder); + final Dimension2D dimTotal = getDimension(stringBounder); + final Dimension2D dimName = name.calculateDimension(stringBounder); + + final double circleX = (dimTotal.getWidth() - SIZE) / 2; + final double circleY = dimStereo.getHeight(); + + final UShape circle = new UEllipse(SIZE, SIZE); + ug.getParam().setStroke(new UStroke(2)); + ug.getParam().setColor(getColor(ColorParam.componentInterfaceBorder, getStereo())); + ug.getParam().setBackcolor(getColor(ColorParam.componentInterfaceBackground, getStereo())); + ug.draw(xTheoricalPosition + circleX, yTheoricalPosition + circleY, circle); + ug.getParam().setStroke(new UStroke()); + + final double nameX = (dimTotal.getWidth() - dimName.getWidth()) / 2; + final double nameY = SIZE + dimStereo.getHeight(); + name.drawU(ug, xTheoricalPosition + nameX, yTheoricalPosition + nameY); + + if (stereo != null) { + final double stereoX = (dimTotal.getWidth() - dimStereo.getWidth()) / 2; + stereo.drawU(ug, xTheoricalPosition + stereoX, yTheoricalPosition); + } + + } + + public ShapeType getShapeType() { + return ShapeType.RECTANGLE; + } + +} diff --git a/src/net/sourceforge/plantuml/svek/EntityImageCircleStart.java b/src/net/sourceforge/plantuml/svek/EntityImageCircleStart.java new file mode 100644 index 000000000..4a8b87acd --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/EntityImageCircleStart.java @@ -0,0 +1,71 @@ +/* ======================================================================== + * 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: 5183 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.UEllipse; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UShape; + +public class EntityImageCircleStart extends AbstractEntityImage { + + private static final int SIZE = 20; + + public EntityImageCircleStart(IEntity entity, ISkinParam skinParam) { + super(entity, skinParam); + } + + @Override + public Dimension2D getDimension(StringBounder stringBounder) { + return new Dimension2DDouble(SIZE, SIZE); + } + + public void drawU(UGraphic ug, double xTheoricalPosition, double yTheoricalPosition) { + final UShape circle = new UEllipse(SIZE, SIZE); + ug.getParam().setColor(null); + ug.getParam().setBackcolor(getColor(ColorParam.activityStart, getStereo())); + ug.draw(xTheoricalPosition, yTheoricalPosition, circle); + } + + public ShapeType getShapeType() { + return ShapeType.CIRCLE; + } + +} diff --git a/src/net/sourceforge/plantuml/svek/EntityImageClass.java b/src/net/sourceforge/plantuml/svek/EntityImageClass.java new file mode 100644 index 000000000..cfa8312f1 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/EntityImageClass.java @@ -0,0 +1,266 @@ +/* ======================================================================== + * 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: 5183 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.MathUtils; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.cucadiagram.EntityPortion; +import net.sourceforge.plantuml.cucadiagram.EntityType; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.PortionShower; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.graph.MethodsOrFieldsArea2; +import net.sourceforge.plantuml.graphic.CircledCharacter; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignement; +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.PlacementStrategyX1Y2Y3; +import net.sourceforge.plantuml.ugraphic.PlacementStrategyY1Y2; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UGroup; +import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public class EntityImageClass extends AbstractEntityImage { + + final private TextBlock name; + final private TextBlock stereo; + final private MethodsOrFieldsArea2 methods; + final private MethodsOrFieldsArea2 fields; + final private CircledCharacter circledCharacter; + + public EntityImageClass(IEntity entity, ISkinParam skinParam, PortionShower portionShower) { + super(entity, skinParam); + + final boolean italic = entity.getType() == EntityType.ABSTRACT_CLASS + || entity.getType() == EntityType.INTERFACE; + + final HtmlColor color = getFontColor(FontParam.CLASS, getStereo()); + final Stereotype stereotype = entity.getStereotype(); + FontConfiguration fontConfigurationName = new FontConfiguration(getFont(FontParam.CLASS, stereotype), color); + if (italic) { + fontConfigurationName = fontConfigurationName.italic(); + } + this.name = TextBlockUtils.create(entity.getDisplay2(), fontConfigurationName, + HorizontalAlignement.CENTER); + + if (stereotype == null || stereotype.getLabel() == null + || portionShower.showPortion(EntityPortion.STEREOTYPE, entity) == false) { + this.stereo = null; + } else { + this.stereo = TextBlockUtils.create(StringUtils.getWithNewlines(stereotype.getLabel()), + new FontConfiguration(getFont(FontParam.CLASS_STEREOTYPE, stereotype), getFontColor( + FontParam.CLASS_STEREOTYPE, stereotype)), HorizontalAlignement.CENTER); + } + + // see LabelBuilderHtmlHeaderTableForObjectOrClass for colors + + final boolean showMethods = portionShower.showPortion(EntityPortion.METHOD, getEntity()); + if (showMethods) { + this.methods = new MethodsOrFieldsArea2(entity.getMethodsToDisplay(), FontParam.CLASS_ATTRIBUTE, skinParam); + } else { + this.methods = null; + } + + final boolean showFields = portionShower.showPortion(EntityPortion.FIELD, getEntity()); + if (showFields) { + this.fields = new MethodsOrFieldsArea2(entity.getFieldsToDisplay(), FontParam.CLASS_ATTRIBUTE, skinParam); + } else { + this.fields = null; + } + + if (portionShower.showPortion(EntityPortion.CIRCLED_CHARACTER, getEntity())) { + circledCharacter = getCircledCharacter(entity); + } else { + circledCharacter = null; + } + } + + private CircledCharacter getCircledCharacter(IEntity entity) { + final Stereotype stereotype = entity.getStereotype(); + if (stereotype != null && stereotype.getCharacter() != 0) { + final HtmlColor classBorder = getColor(ColorParam.classBorder, stereotype); + final UFont font = getFont(FontParam.CIRCLED_CHARACTER, null); + return new CircledCharacter(stereotype.getCharacter(), getSkinParam().getCircledCharacterRadius(), font, + stereotype.getHtmlColor(), classBorder, getFontColor(FontParam.CIRCLED_CHARACTER, null)); + } + if (entity.getType() == EntityType.ABSTRACT_CLASS) { + return new CircledCharacter('A', getSkinParam().getCircledCharacterRadius(), getFont( + FontParam.CIRCLED_CHARACTER, null), getColor(ColorParam.stereotypeABackground, stereotype), + getColor(ColorParam.classBorder, stereotype), getFontColor(FontParam.CIRCLED_CHARACTER, null)); + } + if (entity.getType() == EntityType.CLASS) { + return new CircledCharacter('C', getSkinParam().getCircledCharacterRadius(), getFont( + FontParam.CIRCLED_CHARACTER, null), getColor(ColorParam.stereotypeCBackground, stereotype), + getColor(ColorParam.classBorder, stereotype), getFontColor(FontParam.CIRCLED_CHARACTER, null)); + } + if (entity.getType() == EntityType.INTERFACE) { + return new CircledCharacter('I', getSkinParam().getCircledCharacterRadius(), getFont( + FontParam.CIRCLED_CHARACTER, null), getColor(ColorParam.stereotypeIBackground, stereotype), + getColor(ColorParam.classBorder, stereotype), getFontColor(FontParam.CIRCLED_CHARACTER, null)); + } + if (entity.getType() == EntityType.ENUM) { + return new CircledCharacter('E', getSkinParam().getCircledCharacterRadius(), getFont( + FontParam.CIRCLED_CHARACTER, null), getColor(ColorParam.stereotypeEBackground, stereotype), + getColor(ColorParam.classBorder, stereotype), getFontColor(FontParam.CIRCLED_CHARACTER, null)); + } + assert false; + return null; + } + + private int xMarginFieldsOrMethod = 5; + private int marginEmptyFieldsOrMethod = 13; + + @Override + public Dimension2D getDimension(StringBounder stringBounder) { + final Dimension2D dimTitle = getTitleDimension(stringBounder); + final Dimension2D dimMethods = methods == null ? new Dimension2DDouble(0, 0) : methods + .calculateDimension(stringBounder); + final Dimension2D dimFields = fields == null ? new Dimension2DDouble(0, 0) : fields + .calculateDimension(stringBounder); + final double width = MathUtils.max(dimMethods.getWidth() + 2 * xMarginFieldsOrMethod, dimFields.getWidth() + 2 + * xMarginFieldsOrMethod, dimTitle.getWidth() + 2 * xMarginCircle); + final double height = getMethodOrFieldHeight(dimMethods, EntityPortion.METHOD) + + getMethodOrFieldHeight(dimFields, EntityPortion.FIELD) + dimTitle.getHeight(); + return new Dimension2DDouble(width, height); + } + + private double getMethodOrFieldHeight(final Dimension2D dim, EntityPortion portion) { + if (methods == null && portion == EntityPortion.METHOD) { + return 0; + } + if (fields == null && portion == EntityPortion.FIELD) { + return 0; + } + final double fieldsHeight = dim.getHeight(); + if (fieldsHeight == 0) { + return marginEmptyFieldsOrMethod; + } + return fieldsHeight; + } + + private int xMarginCircle = 5; + private int yMarginCircle = 5; + + private Dimension2D getTitleDimension(StringBounder stringBounder) { + final Dimension2D nameAndStereo = getNameAndSteretypeDimension(stringBounder); + if (circledCharacter == null) { + return Dimension2DDouble.atLeast(nameAndStereo, 4 * xMarginCircle, 6 * yMarginCircle); + } + return new Dimension2DDouble(nameAndStereo.getWidth() + getCircledWidth(stringBounder), Math.max(nameAndStereo + .getHeight(), circledCharacter.getPreferredHeight(stringBounder) + 2 * yMarginCircle)); + } + + private Dimension2D getNameAndSteretypeDimension(StringBounder stringBounder) { + final Dimension2D nameDim = name.calculateDimension(stringBounder); + final Dimension2D stereoDim = stereo == null ? new Dimension2DDouble(0, 0) : stereo + .calculateDimension(stringBounder); + return Dimension2DDouble.mergeTB(nameDim, stereoDim); + } + + private double getCircledWidth(StringBounder stringBounder) { + if (circledCharacter == null) { + return 0; + } + return circledCharacter.getPreferredWidth(stringBounder) + 3; + } + + public void drawU(UGraphic ug, double xTheoricalPosition, double yTheoricalPosition) { + final StringBounder stringBounder = ug.getStringBounder(); + final Dimension2D dimTotal = getDimension(stringBounder); + final Dimension2D dimTitle = getTitleDimension(stringBounder); + + final double widthTotal = dimTotal.getWidth(); + final double heightTotal = dimTotal.getHeight(); + final URectangle rect = new URectangle(widthTotal, heightTotal); + + ug.getParam().setColor(getColor(ColorParam.classBorder, getStereo())); + ug.getParam().setBackcolor(getColor(ColorParam.classBackground, getStereo())); + + double x = xTheoricalPosition; + double y = yTheoricalPosition; + ug.getParam().setStroke(new UStroke(1.5)); + ug.draw(x, y, rect); + ug.getParam().setStroke(new UStroke()); + + final UGroup header; + if (circledCharacter == null) { + header = new UGroup(new PlacementStrategyY1Y2(ug.getStringBounder())); + } else { + header = new UGroup(new PlacementStrategyX1Y2Y3(ug.getStringBounder())); + header.add(circledCharacter); + } + if (stereo != null) { + header.add(stereo); + } + header.add(name); + header.drawU(ug, x, y, dimTotal.getWidth(), dimTitle.getHeight()); + + y += dimTitle.getHeight(); + + x = xTheoricalPosition; + if (fields != null) { + ug.getParam().setColor(getColor(ColorParam.classBorder, getStereo())); + ug.getParam().setStroke(new UStroke(1.5)); + ug.draw(x, y, new ULine(widthTotal, 0)); + ug.getParam().setStroke(new UStroke()); + fields.draw(ug, x + xMarginFieldsOrMethod, y); + y += getMethodOrFieldHeight(fields.calculateDimension(stringBounder), EntityPortion.FIELD); + } + + if (methods != null) { + ug.getParam().setColor(getColor(ColorParam.classBorder, getStereo())); + ug.getParam().setStroke(new UStroke(1.5)); + ug.draw(x, y, new ULine(widthTotal, 0)); + ug.getParam().setStroke(new UStroke()); + methods.draw(ug, x + xMarginFieldsOrMethod, y); + } + } + + public ShapeType getShapeType() { + return ShapeType.RECTANGLE; + } + +} diff --git a/src/net/sourceforge/plantuml/svek/EntityImageComponent.java b/src/net/sourceforge/plantuml/svek/EntityImageComponent.java new file mode 100644 index 000000000..9e30dbf44 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/EntityImageComponent.java @@ -0,0 +1,126 @@ +/* ======================================================================== + * 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: 5183 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UShape; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public class EntityImageComponent extends AbstractEntityImage { + + final private TextBlock desc; + private final TextBlock stereo; + final private static int MARGIN = 10; + + public EntityImageComponent(IEntity entity, ISkinParam skinParam) { + super(entity, skinParam); + final Stereotype stereotype = entity.getStereotype(); + this.desc = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( + getFont(FontParam.COMPONENT, stereotype), getFontColor(FontParam.COMPONENT, stereotype)), + HorizontalAlignement.CENTER); + + if (stereotype == null || stereotype.getLabel() == null) { + this.stereo = null; + } else { + this.stereo = TextBlockUtils.create(StringUtils.getWithNewlines(stereotype.getLabel()), + new FontConfiguration(getFont(FontParam.COMPONENT_STEREOTYPE, stereotype), getFontColor( + FontParam.COMPONENT_STEREOTYPE, null)), HorizontalAlignement.CENTER); + } + + } + + private Dimension2D getStereoDimension(StringBounder stringBounder) { + if (stereo == null) { + return new Dimension2DDouble(0, 0); + } + return stereo.calculateDimension(stringBounder); + } + + @Override + public Dimension2D getDimension(StringBounder stringBounder) { + final Dimension2D dim = Dimension2DDouble.mergeTB(desc.calculateDimension(stringBounder), + getStereoDimension(stringBounder)); + return Dimension2DDouble.delta(dim, MARGIN * 2); + } + + public void drawU(UGraphic ug, double xTheoricalPosition, double yTheoricalPosition) { + final StringBounder stringBounder = ug.getStringBounder(); + final Dimension2D dimTotal = getDimension(stringBounder); + final Dimension2D dimStereo = getStereoDimension(stringBounder); + final Dimension2D dimDesc = desc.calculateDimension(stringBounder); + + final double widthTotal = dimTotal.getWidth(); + final double heightTotal = dimTotal.getHeight(); + final UShape form = new URectangle(widthTotal, heightTotal); + + final UShape small = new URectangle(10, 5); + + ug.getParam().setStroke(new UStroke(1.5)); + ug.getParam().setColor(getColor(ColorParam.componentBorder, getStereo())); + ug.getParam().setBackcolor(getColor(ColorParam.componentBackground, getStereo())); + ug.draw(xTheoricalPosition, yTheoricalPosition, form); + ug.draw(xTheoricalPosition - 5, yTheoricalPosition + 5, small); + ug.draw(xTheoricalPosition - 5, yTheoricalPosition + heightTotal - MARGIN, small); + ug.getParam().setStroke(new UStroke()); + + final double x = xTheoricalPosition + (dimTotal.getWidth() - dimDesc.getWidth()) / 2; + final double y = yTheoricalPosition + MARGIN + dimStereo.getHeight(); + desc.drawU(ug, x, y); + + if (stereo != null) { + final double stereoX = (dimTotal.getWidth() - dimStereo.getWidth()) / 2; + stereo.drawU(ug, xTheoricalPosition + stereoX, yTheoricalPosition + MARGIN); + } + + } + + public ShapeType getShapeType() { + return ShapeType.RECTANGLE; + } +} diff --git a/src/net/sourceforge/plantuml/svek/EntityImageEmptyPackage.java b/src/net/sourceforge/plantuml/svek/EntityImageEmptyPackage.java new file mode 100644 index 000000000..a3a3f761a --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/EntityImageEmptyPackage.java @@ -0,0 +1,100 @@ +/* ======================================================================== + * 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: 5183 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UShape; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public class EntityImageEmptyPackage extends AbstractEntityImage { + + final private TextBlock desc; + final private static int MARGIN = 10; + + public EntityImageEmptyPackage(IEntity entity, ISkinParam skinParam) { + super(entity, skinParam); + final Stereotype stereotype = entity.getStereotype(); + this.desc = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( + getFont(FontParam.PACKAGE, stereotype), getFontColor(FontParam.PACKAGE, stereotype)), + HorizontalAlignement.CENTER); + } + + @Override + public Dimension2D getDimension(StringBounder stringBounder) { + final Dimension2D dim = desc.calculateDimension(stringBounder); + return Dimension2DDouble.delta(dim, MARGIN * 2); + } + + public void drawU(UGraphic ug, double xTheoricalPosition, double yTheoricalPosition) { + final StringBounder stringBounder = ug.getStringBounder(); + final Dimension2D dimTotal = getDimension(stringBounder); + + final double widthTotal = dimTotal.getWidth(); + final double heightTotal = dimTotal.getHeight(); + final UShape form = new URectangle(widthTotal, heightTotal); + + final UShape small = new URectangle(15, 5); + + ug.getParam().setStroke(new UStroke(1.5)); + ug.getParam().setColor(getColor(ColorParam.packageBorder, getStereo())); + ug.getParam().setBackcolor(getColor(ColorParam.packageBackground, getStereo())); + ug.draw(xTheoricalPosition, yTheoricalPosition, form); + ug.draw(xTheoricalPosition, yTheoricalPosition - 5, small); + ug.getParam().setStroke(new UStroke()); + + final double x = xTheoricalPosition + MARGIN; + final double y = yTheoricalPosition + MARGIN; + desc.drawU(ug, x, y); + + } + + public ShapeType getShapeType() { + return ShapeType.RECTANGLE; + } +} diff --git a/src/net/sourceforge/plantuml/svek/EntityImageGroup.java b/src/net/sourceforge/plantuml/svek/EntityImageGroup.java new file mode 100644 index 000000000..14888b75b --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/EntityImageGroup.java @@ -0,0 +1,86 @@ +/* ======================================================================== + * 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: 5183 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.UGraphic; + +public class EntityImageGroup extends AbstractEntityImage { + +// final private TextBlock desc; +// final private static int MARGIN = 10; + + public EntityImageGroup(IEntity entity, ISkinParam skinParam) { + super(entity, skinParam); +// this.desc = TextBlockUtils.create(StringUtils.getWithNewlines(entity.getDisplay()), new FontConfiguration( +// getFont(FontParam.ACTIVITY), HtmlColor.BLACK), HorizontalAlignement.CENTER); + } + + @Override + public Dimension2D getDimension(StringBounder stringBounder) { +// final Dimension2D dim = desc.calculateDimension(stringBounder); +// return Dimension2DDouble.delta(dim, MARGIN * 2); + return new Dimension2DDouble(30, 30); + } + + public void drawU(UGraphic ug, double xTheoricalPosition, double yTheoricalPosition) { +// final StringBounder stringBounder = ug.getStringBounder(); +// final Dimension2D dimTotal = getDimension(stringBounder); +// +// final double widthTotal = dimTotal.getWidth(); +// final double heightTotal = dimTotal.getHeight(); +// final URectangle rect = new URectangle(widthTotal, heightTotal, 25, 25); +// +// ug.getParam().setStroke(new UStroke(1.5)); +// ug.getParam().setColor(getColor(ColorParam.activityBorder)); +// ug.getParam().setBackcolor(getColor(ColorParam.activityBackground)); +// +// ug.draw(xTheoricalPosition, yTheoricalPosition, rect); +// ug.getParam().setStroke(new UStroke()); +// +// final double x = xTheoricalPosition + MARGIN; +// final double y = yTheoricalPosition + MARGIN; +// desc.drawU(ug, x, y); + + } + + public ShapeType getShapeType() { + return ShapeType.RECTANGLE; + } +} diff --git a/src/net/sourceforge/plantuml/svek/EntityImageLollipopInterface.java b/src/net/sourceforge/plantuml/svek/EntityImageLollipopInterface.java new file mode 100644 index 000000000..b7158f159 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/EntityImageLollipopInterface.java @@ -0,0 +1,95 @@ +/* ======================================================================== + * 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: 5183 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.UEllipse; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UShape; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public class EntityImageLollipopInterface extends AbstractEntityImage { + + private static final int SIZE = 10; + private final TextBlock desc; + + public EntityImageLollipopInterface(IEntity entity, ISkinParam skinParam) { + super(entity, skinParam); + final Stereotype stereotype = entity.getStereotype(); + this.desc = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( + getFont(FontParam.CLASS, stereotype), getFontColor(FontParam.CLASS, stereotype)), + HorizontalAlignement.CENTER); + + } + + @Override + public Dimension2D getDimension(StringBounder stringBounder) { + return new Dimension2DDouble(SIZE, SIZE); + } + + public void drawU(UGraphic ug, double xTheoricalPosition, double yTheoricalPosition) { + final UShape circle = new UEllipse(SIZE, SIZE); + ug.getParam().setStroke(new UStroke(1.5)); + ug.getParam().setColor(getColor(ColorParam.classBorder, getStereo())); + ug.getParam().setBackcolor(getColor(ColorParam.classBackground, getStereo())); + ug.draw(xTheoricalPosition, yTheoricalPosition, circle); + ug.getParam().setStroke(new UStroke()); + + final Dimension2D dimDesc = desc.calculateDimension(ug.getStringBounder()); + final double widthDesc = dimDesc.getWidth(); + // final double totalWidth = Math.max(widthDesc, SIZE); + + final double x = xTheoricalPosition + SIZE / 2 - widthDesc / 2; + final double y = yTheoricalPosition + SIZE; + desc.drawU(ug, x, y); + } + + public ShapeType getShapeType() { + return ShapeType.CIRCLE_IN_RECT; + } + +} diff --git a/src/net/sourceforge/plantuml/svek/EntityImageNote.java b/src/net/sourceforge/plantuml/svek/EntityImageNote.java new file mode 100644 index 000000000..c77daf87c --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/EntityImageNote.java @@ -0,0 +1,105 @@ +/* ======================================================================== + * 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: 5183 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.SkinParamBackcolored; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.skin.Component; +import net.sourceforge.plantuml.skin.ComponentType; +import net.sourceforge.plantuml.skin.SimpleContext2D; +import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.ugraphic.UGraphic; + +public class EntityImageNote extends AbstractEntityImage { + + private final Component comp; + + public EntityImageNote(IEntity entity, ISkinParam skinParam) { + super(entity, getSkin(skinParam, entity)); + + final Rose skin = new Rose(); + + comp = skin.createComponent(ComponentType.NOTE, getSkinParam(), entity.getDisplay2()); + + } + + private static ISkinParam getSkin(ISkinParam skinParam, IEntity entity) { + final Stereotype stereotype = entity.getStereotype(); + HtmlColor back = entity.getSpecificBackColor(); + if (back != null) { + return new SkinParamBackcolored(skinParam, back); + } + back = getColorStatic(skinParam, ColorParam.noteBackground, stereotype); + if (back != null) { + return new SkinParamBackcolored(skinParam, back); + } + return skinParam; + } + + private static HtmlColor getColorStatic(ISkinParam skinParam, ColorParam colorParam, Stereotype stereo) { + final String s = stereo == null ? null : stereo.getLabel(); + final Rose rose = new Rose(); + return rose.getHtmlColor(skinParam, colorParam, s); + } + + @Override + public Dimension2D getDimension(StringBounder stringBounder) { + final double height = comp.getPreferredHeight(stringBounder); + final double width = comp.getPreferredWidth(stringBounder); + return new Dimension2DDouble(width, height); + } + + public void drawU(UGraphic ug, double xTheoricalPosition, double yTheoricalPosition) { + final double dx = ug.getTranslateX(); + final double dy = ug.getTranslateY(); + ug.translate(xTheoricalPosition, yTheoricalPosition); + comp.drawU(ug, getDimension(ug.getStringBounder()), new SimpleContext2D(false)); + ug.setTranslate(dx, dy); + + } + + public ShapeType getShapeType() { + return ShapeType.RECTANGLE; + } + +} diff --git a/src/net/sourceforge/plantuml/svek/EntityImageNoteLink.java b/src/net/sourceforge/plantuml/svek/EntityImageNoteLink.java new file mode 100644 index 000000000..d58273767 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/EntityImageNoteLink.java @@ -0,0 +1,81 @@ +/* ======================================================================== + * 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: 5183 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; +import java.util.List; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.skin.Component; +import net.sourceforge.plantuml.skin.ComponentType; +import net.sourceforge.plantuml.skin.SimpleContext2D; +import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.ugraphic.UGraphic; + +public class EntityImageNoteLink implements IEntityImage { + + private final Component comp; + + public EntityImageNoteLink(List note, ISkinParam skinParam) { + final Rose skin = new Rose(); + comp = skin.createComponent(ComponentType.NOTE, skinParam, note); + } + + public Dimension2D getDimension(StringBounder stringBounder) { + final double height = comp.getPreferredHeight(stringBounder); + final double width = comp.getPreferredWidth(stringBounder); + return new Dimension2DDouble(width, height); + } + + public void drawU(UGraphic ug, double xTheoricalPosition, double yTheoricalPosition) { + final double dx = ug.getTranslateX(); + final double dy = ug.getTranslateY(); + ug.translate(xTheoricalPosition, yTheoricalPosition); + comp.drawU(ug, getDimension(ug.getStringBounder()), new SimpleContext2D(false)); + ug.setTranslate(dx, dy); + + } + + public ShapeType getShapeType() { + return ShapeType.RECTANGLE; + } + + public HtmlColor getBackcolor() { + return null; + } + +} diff --git a/src/net/sourceforge/plantuml/svek/EntityImageObject.java b/src/net/sourceforge/plantuml/svek/EntityImageObject.java new file mode 100644 index 000000000..120394e0d --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/EntityImageObject.java @@ -0,0 +1,161 @@ +/* ======================================================================== + * 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: 5183 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.graph.MethodsOrFieldsArea2; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.PlacementStrategyY1Y2; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UGroup; +import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public class EntityImageObject extends AbstractEntityImage { + + final private TextBlock name; + final private TextBlock stereo; + // final private MethodsOrFieldsArea2 methods; + final private MethodsOrFieldsArea2 fields; + + public EntityImageObject(IEntity entity, ISkinParam skinParam) { + super(entity, skinParam); + final Stereotype stereotype = entity.getStereotype(); + this.name = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( + getFont(FontParam.OBJECT, stereotype), getFontColor(FontParam.OBJECT, stereotype)), + HorizontalAlignement.CENTER); + if (stereotype == null || stereotype.getLabel() == null) { + this.stereo = null; + } else { + this.stereo = TextBlockUtils.create(StringUtils.getWithNewlines(stereotype.getLabel()), + new FontConfiguration(getFont(FontParam.OBJECT_STEREOTYPE, stereotype), getFontColor( + FontParam.OBJECT_STEREOTYPE, stereotype)), HorizontalAlignement.CENTER); + } + // this.methods = new MethodsOrFieldsArea2(entity.getMethodsToDisplay(), + // FontParam.OBJECT_ATTRIBUTE, skinParam); + this.fields = new MethodsOrFieldsArea2(entity.getFieldsToDisplay(), FontParam.OBJECT_ATTRIBUTE, skinParam); + } + + private int xMarginFieldsOrMethod = 5; + private int marginEmptyFieldsOrMethod = 13; + + @Override + public Dimension2D getDimension(StringBounder stringBounder) { + final Dimension2D dimTitle = getTitleDimension(stringBounder); + // final Dimension2D dimMethods = + // methods.calculateDimension(stringBounder); + final Dimension2D dimFields = fields.calculateDimension(stringBounder); + final double width = Math.max(dimFields.getWidth() + 2 * xMarginFieldsOrMethod, dimTitle.getWidth() + 2 + * xMarginCircle); + final double height = getMethodOrFieldHeight(dimFields) + dimTitle.getHeight(); + return new Dimension2DDouble(width, height); + } + + private double getMethodOrFieldHeight(final Dimension2D dim) { + final double fieldsHeight = dim.getHeight(); + if (fieldsHeight == 0) { + return marginEmptyFieldsOrMethod; + } + return fieldsHeight; + } + + private int xMarginCircle = 5; + + private Dimension2D getTitleDimension(StringBounder stringBounder) { + return getNameAndSteretypeDimension(stringBounder); + } + + private Dimension2D getNameAndSteretypeDimension(StringBounder stringBounder) { + final Dimension2D nameDim = name.calculateDimension(stringBounder); + final Dimension2D stereoDim = stereo == null ? new Dimension2DDouble(0, 0) : stereo + .calculateDimension(stringBounder); + final Dimension2D nameAndStereo = new Dimension2DDouble(Math.max(nameDim.getWidth(), stereoDim.getWidth()), + nameDim.getHeight() + stereoDim.getHeight()); + return nameAndStereo; + } + + public void drawU(UGraphic ug, double xTheoricalPosition, double yTheoricalPosition) { + final StringBounder stringBounder = ug.getStringBounder(); + final Dimension2D dimTotal = getDimension(stringBounder); + final Dimension2D dimTitle = getTitleDimension(stringBounder); + + final double widthTotal = dimTotal.getWidth(); + final double heightTotal = dimTotal.getHeight(); + final URectangle rect = new URectangle(widthTotal, heightTotal); + + ug.getParam().setColor(getColor(ColorParam.objectBorder, getStereo())); + ug.getParam().setBackcolor(getColor(ColorParam.objectBackground, getStereo())); + + double x = xTheoricalPosition; + double y = yTheoricalPosition; + ug.getParam().setStroke(new UStroke(1.5)); + ug.draw(x, y, rect); + ug.getParam().setStroke(new UStroke()); + + final UGroup header = new UGroup(new PlacementStrategyY1Y2(ug.getStringBounder())); + if (stereo != null) { + header.add(stereo); + } + header.add(name); + header.drawU(ug, x, y, dimTotal.getWidth(), dimTitle.getHeight()); + + y += dimTitle.getHeight(); + + x = xTheoricalPosition; + ug.getParam().setColor(getColor(ColorParam.objectBorder, getStereo())); + ug.getParam().setStroke(new UStroke(1.5)); + ug.draw(x, y, new ULine(widthTotal, 0)); + ug.getParam().setStroke(new UStroke()); + fields.draw(ug, x + xMarginFieldsOrMethod, y); + + } + + public ShapeType getShapeType() { + return ShapeType.RECTANGLE; + } + +} diff --git a/src/net/sourceforge/plantuml/svek/EntityImageState.java b/src/net/sourceforge/plantuml/svek/EntityImageState.java new file mode 100644 index 000000000..7e988df0b --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/EntityImageState.java @@ -0,0 +1,133 @@ +/* ======================================================================== + * 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: 5183 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.Member; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignement; +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.UGraphic; +import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public class EntityImageState extends AbstractEntityImage { + + public static final int CORNER = 25; + final private TextBlock desc; + final private TextBlock fields; + + final public static int MARGIN = 5; + final public static int MARGIN_LINE = 5; + final private static int MIN_WIDTH = 50; + final private static int MIN_HEIGHT = 50; + + public EntityImageState(IEntity entity, ISkinParam skinParam) { + super(entity, skinParam); + final Stereotype stereotype = entity.getStereotype(); + + this.desc = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( + getFont(FontParam.STATE, stereotype), getFontColor(FontParam.STATE, stereotype)), + HorizontalAlignement.CENTER); + + final List list = new ArrayList(); + for (Member att : entity.getFieldsToDisplay()) { + list.add(att.getDisplayWithVisibilityChar()); + } + + this.fields = TextBlockUtils.create(list, new FontConfiguration(getFont(FontParam.STATE_ATTRIBUTE, stereotype), + getFontColor(FontParam.STATE_ATTRIBUTE, stereotype)), HorizontalAlignement.LEFT); + + } + + @Override + public Dimension2D getDimension(StringBounder stringBounder) { + final Dimension2D dim = Dimension2DDouble.mergeTB(desc.calculateDimension(stringBounder), fields + .calculateDimension(stringBounder)); + final Dimension2D result = Dimension2DDouble.delta(dim, MARGIN * 2 + 2 * MARGIN_LINE); + return Dimension2DDouble.atLeast(result, MIN_WIDTH, MIN_HEIGHT); + } + + public void drawU(UGraphic ug, double xTheoricalPosition, double yTheoricalPosition) { + final StringBounder stringBounder = ug.getStringBounder(); + final Dimension2D dimTotal = getDimension(stringBounder); + final Dimension2D dimDesc = desc.calculateDimension(stringBounder); + + final double widthTotal = dimTotal.getWidth(); + final double heightTotal = dimTotal.getHeight(); + final URectangle rect = new URectangle(widthTotal, heightTotal, CORNER, CORNER); + + ug.getParam().setStroke(new UStroke(1.5)); + ug.getParam().setColor(getColor(ColorParam.stateBorder, getStereo())); + HtmlColor backcolor = getEntity().getSpecificBackColor(); + if (backcolor == null) { + backcolor = getColor(ColorParam.stateBackground, getStereo()); + } + ug.getParam().setBackcolor(backcolor); + + ug.draw(xTheoricalPosition, yTheoricalPosition, rect); + + final double yLine = yTheoricalPosition + MARGIN + dimDesc.getHeight() + MARGIN_LINE; + ug.draw(xTheoricalPosition, yLine, new ULine(widthTotal, 0)); + + ug.getParam().setStroke(new UStroke()); + + final double xDesc = (widthTotal - dimDesc.getWidth()) / 2; + final double yDesc = yTheoricalPosition + MARGIN; + desc.drawU(ug, xTheoricalPosition + xDesc, yDesc); + + final double xFields = xTheoricalPosition + MARGIN; + final double yFields = yLine + MARGIN_LINE; + fields.drawU(ug, xFields, yFields); + + } + + public ShapeType getShapeType() { + return ShapeType.ROUND_RECTANGLE; + } +} diff --git a/src/net/sourceforge/plantuml/svek/EntityImageSynchroBar.java b/src/net/sourceforge/plantuml/svek/EntityImageSynchroBar.java new file mode 100644 index 000000000..80b1b94b6 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/EntityImageSynchroBar.java @@ -0,0 +1,70 @@ +/* ======================================================================== + * 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: 5183 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UShape; + +public class EntityImageSynchroBar extends AbstractEntityImage { + + public EntityImageSynchroBar(IEntity entity, ISkinParam skinParam) { + super(entity, skinParam); + } + + @Override + public Dimension2D getDimension(StringBounder stringBounder) { + return new Dimension2DDouble(80, 8); + } + + public void drawU(UGraphic ug, double xTheoricalPosition, double yTheoricalPosition) { + final Dimension2D dim = getDimension(ug.getStringBounder()); + final UShape rect = new URectangle(dim.getWidth(), dim.getHeight()); + ug.getParam().setColor(null); + ug.getParam().setBackcolor(getColor(ColorParam.activityBar, getStereo())); + ug.draw(xTheoricalPosition, yTheoricalPosition, rect); + } + + public ShapeType getShapeType() { + return ShapeType.RECTANGLE; + } + +} diff --git a/src/net/sourceforge/plantuml/svek/EntityImageUseCase.java b/src/net/sourceforge/plantuml/svek/EntityImageUseCase.java new file mode 100644 index 000000000..280f33f3c --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/EntityImageUseCase.java @@ -0,0 +1,121 @@ +/* ======================================================================== + * 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: 5183 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.UEllipse; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public class EntityImageUseCase extends AbstractEntityImage { + + final private TextBlock desc; + final private static int MARGIN = 10; + final private TextBlock stereo; + + public EntityImageUseCase(IEntity entity, ISkinParam skinParam) { + super(entity, skinParam); + final Stereotype stereotype = entity.getStereotype(); + + this.desc = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( + getFont(FontParam.USECASE, stereotype), getFontColor(FontParam.USECASE, stereotype)), HorizontalAlignement.CENTER); + + if (stereotype == null || stereotype.getLabel() == null) { + this.stereo = null; + } else { + this.stereo = TextBlockUtils.create(StringUtils.getWithNewlines(stereotype.getLabel()), + new FontConfiguration(getFont(FontParam.USECASE_ACTOR_STEREOTYPE, stereotype), getFontColor( + FontParam.USECASE_ACTOR_STEREOTYPE, null)), HorizontalAlignement.CENTER); + } + + } + + private Dimension2D getStereoDimension(StringBounder stringBounder) { + if (stereo == null) { + return new Dimension2DDouble(0, 0); + } + return stereo.calculateDimension(stringBounder); + } + + @Override + public Dimension2D getDimension(StringBounder stringBounder) { + final Dimension2D dim = Dimension2DDouble.mergeTB(desc.calculateDimension(stringBounder), + getStereoDimension(stringBounder)); + return Dimension2DDouble.delta(dim, MARGIN * 2); + } + + public void drawU(UGraphic ug, double xTheoricalPosition, double yTheoricalPosition) { + final StringBounder stringBounder = ug.getStringBounder(); + final Dimension2D dimTotal = getDimension(stringBounder); + final Dimension2D dimStereo = getStereoDimension(stringBounder); + final Dimension2D dimDesc = desc.calculateDimension(stringBounder); + + final double widthTotal = dimTotal.getWidth(); + final double heightTotal = dimTotal.getHeight(); + final UEllipse ellipse = new UEllipse(widthTotal, heightTotal); + + ug.getParam().setStroke(new UStroke(1.5)); + ug.getParam().setColor(getColor(ColorParam.usecaseBorder, getStereo())); + ug.getParam().setBackcolor(getColor(ColorParam.usecaseBackground, getStereo())); + ug.draw(xTheoricalPosition, yTheoricalPosition, ellipse); + ug.getParam().setStroke(new UStroke()); + + final double x = (dimTotal.getWidth() - dimDesc.getWidth()) / 2; + final double y = MARGIN + dimStereo.getHeight(); + desc.drawU(ug, xTheoricalPosition + x, yTheoricalPosition + y); + + if (stereo != null) { + final double stereoX = (dimTotal.getWidth() - dimStereo.getWidth()) / 2; + stereo.drawU(ug, xTheoricalPosition + stereoX, yTheoricalPosition + MARGIN); + } + + } + + public ShapeType getShapeType() { + return ShapeType.OVAL; + } +} diff --git a/src/net/sourceforge/plantuml/svek/GroupPngMaker2.java b/src/net/sourceforge/plantuml/svek/GroupPngMaker2.java new file mode 100644 index 000000000..4210deb02 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/GroupPngMaker2.java @@ -0,0 +1,148 @@ +/* ======================================================================== + * 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.svek; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.OptionFlags; +import net.sourceforge.plantuml.SkinParamBackcolored; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.cucadiagram.CucaDiagram; +import net.sourceforge.plantuml.cucadiagram.EntityType; +import net.sourceforge.plantuml.cucadiagram.Group; +import net.sourceforge.plantuml.cucadiagram.GroupHierarchy; +import net.sourceforge.plantuml.cucadiagram.GroupType; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.cucadiagram.dot.DotData; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.sequencediagram.GroupingType; +import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.ugraphic.UFont; + +public final class GroupPngMaker2 { + + private final CucaDiagram diagram; + private final Group group; + + class InnerGroupHierarchy implements GroupHierarchy { + + public Collection getChildrenGroups(Group parent) { + if (parent == null) { + return diagram.getChildrenGroups(group); + } + return diagram.getChildrenGroups(parent); + } + + public boolean isEmpty(Group g) { + return diagram.isEmpty(g); + } + + } + + public GroupPngMaker2(CucaDiagram diagram, Group group) { + this.diagram = diagram; + this.group = group; + } + + private List getPureInnerLinks() { + final List result = new ArrayList(); + for (Link link : diagram.getLinks()) { + final IEntity e1 = link.getEntity1(); + final IEntity e2 = link.getEntity2(); + if (e1.getParent() == group && e1.getType() != EntityType.GROUP && e2.getParent() == group + && e2.getType() != EntityType.GROUP) { + result.add(link); + } + } + return result; + } + + public IEntityImage getImage() throws IOException, InterruptedException { + final String display = group.getDisplay(); + final TextBlock title = TextBlockUtils.create(StringUtils.getWithNewlines(display), new FontConfiguration( + getFont(FontParam.STATE), HtmlColor.BLACK), HorizontalAlignement.CENTER); + + if (group.entities().size() == 0) { + return new EntityImageState(group.getEntityCluster(), diagram.getSkinParam()); + } + final List links = getPureInnerLinks(); + ISkinParam skinParam = diagram.getSkinParam(); + if (OptionFlags.PBBACK && group.getBackColor() != null) { + skinParam = new SkinParamBackcolored(skinParam, null, group.getBackColor()); + } + final DotData dotData = new DotData(group, links, group.entities(), diagram.getUmlDiagramType(), skinParam, + group.getRankdir(), new InnerGroupHierarchy(), diagram.getColorMapper()); + + final CucaDiagramFileMakerSvek2 svek2 = new CucaDiagramFileMakerSvek2(dotData); + + if (group.getType() == GroupType.CONCURRENT_STATE) { + return new InnerStateConcurrent(svek2.createFile()); + } else if (group.getType() == GroupType.INNER_ACTIVITY) { + final HtmlColor borderColor = getColor(ColorParam.stateBorder, null); + return new InnerActivity(svek2.createFile(), borderColor); + } else if (group.getType() == GroupType.STATE) { + final HtmlColor borderColor = getColor(ColorParam.stateBorder, null); + final HtmlColor backColor = getColor(ColorParam.stateBackground, null); + return new InnerStateAutonom(svek2.createFile(), title, borderColor, backColor); + } + + throw new UnsupportedOperationException(group.getType().toString()); + + } + + private UFont getFont(FontParam fontParam) { + final ISkinParam skinParam = diagram.getSkinParam(); + return skinParam.getFont(fontParam, null); + } + + private final Rose rose = new Rose(); + + protected final HtmlColor getColor(ColorParam colorParam, Stereotype stereo) { + final String s = stereo == null ? null : stereo.getLabel(); + final ISkinParam skinParam = diagram.getSkinParam(); + return rose.getHtmlColor(skinParam, colorParam, s); + } +} diff --git a/src/net/sourceforge/plantuml/svek/IEntityImage.java b/src/net/sourceforge/plantuml/svek/IEntityImage.java new file mode 100644 index 000000000..1cd617a1e --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/IEntityImage.java @@ -0,0 +1,52 @@ +/* ======================================================================== + * 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: 4236 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.UGraphic; + +public interface IEntityImage { + + Dimension2D getDimension(StringBounder stringBounder); + + void drawU(UGraphic ug, double xTheoricalPosition, double yTheoricalPosition); + + ShapeType getShapeType(); + + HtmlColor getBackcolor(); + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/svek/InnerActivity.java b/src/net/sourceforge/plantuml/svek/InnerActivity.java new file mode 100644 index 000000000..58c91da17 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/InnerActivity.java @@ -0,0 +1,81 @@ +/* ======================================================================== + * 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.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public final class InnerActivity implements IEntityImage { + + private final IEntityImage im; + private final HtmlColor borderColor; + + public InnerActivity(final IEntityImage im, HtmlColor borderColor) { + this.im = im; + this.borderColor = borderColor; + } + + public final static double THICKNESS_BORDER = 1.5; + + public void drawU(UGraphic ug, double x, double y) { + final Dimension2D total = getDimension(ug.getStringBounder()); + + ug.getParam().setColor(borderColor); + ug.getParam().setBackcolor(null); + ug.getParam().setStroke(new UStroke(THICKNESS_BORDER)); + ug.draw(x, y, new URectangle(total.getWidth(), total.getHeight(), EntityImageState.CORNER, + EntityImageState.CORNER)); + ug.getParam().setStroke(new UStroke()); + im.drawU(ug, x, y); + } + + public HtmlColor getBackcolor() { + return im.getBackcolor(); + } + + public Dimension2D getDimension(StringBounder stringBounder) { + final Dimension2D img = im.getDimension(stringBounder); + return img; + } + + public ShapeType getShapeType() { + return ShapeType.ROUND_RECTANGLE; + } + +} diff --git a/src/net/sourceforge/plantuml/svek/InnerStateAutonom.java b/src/net/sourceforge/plantuml/svek/InnerStateAutonom.java new file mode 100644 index 000000000..c9e5d8d32 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/InnerStateAutonom.java @@ -0,0 +1,94 @@ +/* ======================================================================== + * 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.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.ugraphic.UGraphic; + +public final class InnerStateAutonom implements IEntityImage { + + private final IEntityImage im; + private final TextBlock title; + private final HtmlColor borderColor; + private final HtmlColor backColor; + + public InnerStateAutonom(final IEntityImage im, final TextBlock title, HtmlColor borderColor, HtmlColor backColor) { + this.im = im; + this.title = title; + this.borderColor = borderColor; + this.backColor = backColor; + } + + + public final static double THICKNESS_BORDER = 1.5; + + public void drawU(UGraphic ug, double x, double y) { + final Dimension2D text = title.calculateDimension(ug.getStringBounder()); + final Dimension2D total = getDimension(ug.getStringBounder()); + + final double suppY = EntityImageState.MARGIN + text.getHeight() + EntityImageState.MARGIN_LINE; + final RoundedContainer r = new RoundedContainer(total, suppY, borderColor, backColor, im.getBackcolor()); + + r.drawU(ug, x, y); + title.drawU(ug, x + (total.getWidth() - text.getWidth()) / 2, y + EntityImageState.MARGIN); + + im.drawU(ug, x + EntityImageState.MARGIN, y+suppY + EntityImageState.MARGIN_LINE); + } + + public HtmlColor getBackcolor() { + return null; + } + + public Dimension2D getDimension(StringBounder stringBounder) { + final Dimension2D img = im.getDimension(stringBounder); + final Dimension2D text = title.calculateDimension(stringBounder); + + final Dimension2D dim = Dimension2DDouble.mergeTB(text, img); + + final Dimension2D result = Dimension2DDouble.delta(dim, EntityImageState.MARGIN * 2 + 2 + * EntityImageState.MARGIN_LINE); + + return result; + } + + public ShapeType getShapeType() { + return ShapeType.ROUND_RECTANGLE; + } + +} diff --git a/src/net/sourceforge/plantuml/svek/InnerStateConcurrent.java b/src/net/sourceforge/plantuml/svek/InnerStateConcurrent.java new file mode 100644 index 000000000..40ddf16fb --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/InnerStateConcurrent.java @@ -0,0 +1,83 @@ +/* ======================================================================== + * 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.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UShape; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public final class InnerStateConcurrent implements IEntityImage { + + private final IEntityImage im; + + public InnerStateConcurrent(final IEntityImage im) { + this.im = im; + } + + public final static double THICKNESS_BORDER = 1.5; + private static final int DASH = 8; + + public void drawU(UGraphic ug, double x, double y) { + + final Dimension2D dim = getDimension(ug.getStringBounder()); + final UShape rect = new URectangle(dim.getWidth(), dim.getHeight()); + ug.getParam().setBackcolor(null); + ug.getParam().setColor(HtmlColor.BLACK); + ug.getParam().setStroke(new UStroke(DASH, 10, THICKNESS_BORDER)); + ug.draw(x, y, rect); + ug.getParam().setStroke(new UStroke()); + + im.drawU(ug, x, y); + } + + public HtmlColor getBackcolor() { + return null; + } + + public Dimension2D getDimension(StringBounder stringBounder) { + final Dimension2D img = im.getDimension(stringBounder); + + return img; + } + + public ShapeType getShapeType() { + return ShapeType.RECTANGLE; + } + +} diff --git a/src/net/sourceforge/plantuml/svek/Line.java b/src/net/sourceforge/plantuml/svek/Line.java new file mode 100644 index 000000000..d3f2c810a --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/Line.java @@ -0,0 +1,464 @@ +/* ======================================================================== + * 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: 4236 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.List; + +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.cucadiagram.LinkDecor; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignement; +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.posimo.BezierUtils; +import net.sourceforge.plantuml.posimo.DotPath; +import net.sourceforge.plantuml.posimo.Positionable; +import net.sourceforge.plantuml.svek.SvekUtils.PointListIterator; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UPolygon; +import net.sourceforge.plantuml.ugraphic.UShape; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public class Line { + + private final String ltail; + private final String lhead; + private final Link link; + + private DotPath dotPath; + + private final String startUid; + private final String endUid; + + private final TextBlock labelText; + private final TextBlock startTailText; + private final TextBlock endHeadText; + private final IEntityImage note; + + private final int lineColor; + private final int labelColor; + private final int startTailColor; + private final int endHeadColor; + private final int noteColor; + + private Point2D.Double labelXY; + private Point2D.Double startTailLabelXY; + private Point2D.Double endHeadLabelXY; + private Point2D.Double noteXY; + + private List endHead; + private List startTail; + + private final StringBounder stringBounder; + + public Line(String startUid, String endUid, Link link, ColorSequence colorSequence, String ltail, String lhead, + ISkinParam skinParam, StringBounder stringBounder, FontConfiguration labelFont) { + if (startUid == null || endUid == null || link == null) { + throw new IllegalArgumentException(); + } + this.stringBounder = stringBounder; + this.link = link; + this.startUid = startUid; + this.endUid = endUid; + this.ltail = ltail; + this.lhead = lhead; + + this.lineColor = colorSequence.getValue(); + this.labelColor = colorSequence.getValue(); + this.startTailColor = colorSequence.getValue(); + this.endHeadColor = colorSequence.getValue(); + this.noteColor = colorSequence.getValue(); + + if (link.getLabel() == null) { + labelText = null; + } else { + labelText = TextBlockUtils.create(StringUtils.getWithNewlines(link.getLabel()), labelFont, + HorizontalAlignement.CENTER); + } + + if (link.getQualifier1() == null) { + startTailText = null; + } else { + startTailText = TextBlockUtils.create(StringUtils.getWithNewlines(link.getQualifier1()), labelFont, + HorizontalAlignement.CENTER); + } + + if (link.getQualifier2() == null) { + endHeadText = null; + } else { + endHeadText = TextBlockUtils.create(StringUtils.getWithNewlines(link.getQualifier2()), labelFont, + HorizontalAlignement.CENTER); + } + + if (link.getNote() == null) { + note = null; + } else { + note = new EntityImageNoteLink(link.getNote(), skinParam); + } + + } + + public void appendLine(StringBuilder sb) { + sb.append(startUid); + sb.append("->"); + sb.append(endUid); + sb.append("["); + String decoration = link.getType().getSpecificDecoration(); + if (decoration.endsWith(",") == false) { + decoration += ","; + } + sb.append(decoration); + + if (link.getLength() != 1) { + sb.append("minlen=" + (link.getLength() - 1)); + sb.append(","); + } + sb.append("color=\"" + StringUtils.getAsHtml(lineColor) + "\""); + if (labelText != null) { + sb.append(","); + sb.append("label=<"); + appendTable(sb, labelText.calculateDimension(stringBounder), labelColor); + sb.append(">"); + } else if (note != null) { + sb.append(","); + sb.append("label=<"); + appendTable(sb, note.getDimension(stringBounder), noteColor); + sb.append(">"); + } + + if (startTailText != null) { + sb.append(","); + sb.append("taillabel=<"); + appendTable(sb, startTailText.calculateDimension(stringBounder), startTailColor); + sb.append(">"); + } + if (endHeadText != null) { + sb.append(","); + sb.append("headlabel=<"); + appendTable(sb, endHeadText.calculateDimension(stringBounder), endHeadColor); + sb.append(">"); + } + + if (ltail != null) { + sb.append(","); + sb.append("ltail="); + sb.append(ltail); + } + if (lhead != null) { + sb.append(","); + sb.append("lhead="); + sb.append(lhead); + } + if (link.isInvis()) { + sb.append(","); + sb.append("style=invis"); + } + sb.append("];"); + SvekUtils.println(sb); + } + + public String rankSame() { + if (link.getLength() == 1) { + return "{rank=same; " + startUid + "; " + endUid + "}"; + } + return null; + } + + public static void appendTable(StringBuilder sb, Dimension2D dim, int col) { + final int w = (int) dim.getWidth(); + final int h = (int) dim.getHeight(); + appendTable(sb, w, h, col); + } + + public static void appendTable(StringBuilder sb, int w, int h, int col) { + sb.append(""); + sb.append(""); + sb.append(""); + sb.append(""); + sb.append(""); + sb.append("
"); + } + + public final String getStartUid() { + return startUid; + } + + public final String getEndUid() { + return endUid; + } + + public void solveLine(final String svg, final int fullHeight) { + if (this.link.isInvis()) { + return; + } + + int idx = svg.indexOf(SvekUtils.getStrokeString(this.lineColor)); + if (idx == -1) { + throw new IllegalStateException(); + } + idx = svg.indexOf("d=\"", idx); + if (idx == -1) { + throw new IllegalStateException(); + } + final int end = svg.indexOf("\"", idx + 3); + final String path = svg.substring(idx + 3, end); + dotPath = new DotPath(path, fullHeight); + + final PointListIterator pointListIterator = new PointListIterator(svg.substring(end), fullHeight); + + if (link.getType().getDecor2() != LinkDecor.NONE) { + this.endHead = pointListIterator.next(); + } + + if (link.getType().getDecor1() != LinkDecor.NONE) { + this.startTail = pointListIterator.next(); + } + + if (this.labelText != null) { + this.labelXY = getXY(svg, this.labelColor, fullHeight); + } + + if (this.startTailText != null) { + this.startTailLabelXY = getXY(svg, this.startTailColor, fullHeight); + } + + if (this.endHeadText != null) { + this.endHeadLabelXY = getXY(svg, this.endHeadColor, fullHeight); + } + + if (this.note != null) { + this.noteXY = getXY(svg, this.noteColor, fullHeight); + } + + } + + private Point2D.Double getXY(String svg, int color, int height) { + final int idx = svg.indexOf(SvekUtils.getStrokeString(color)); + if (idx == -1) { + throw new IllegalStateException(); + } + return SvekUtils.getMinXY(SvekUtils.extractPointsList(svg, idx, height)); + + } + + public void drawU(UGraphic ug, double x, double y, HtmlColor color) { + if (link.isInvis()) { + return; + } + if (this.link.getSpecificColor() != null) { + color = this.link.getSpecificColor(); + } + ug.getParam().setColor(color); + ug.getParam().setBackcolor(null); + ug.getParam().setStroke(link.getType().getStroke()); + ug.draw(x, y, dotPath); + ug.getParam().setStroke(new UStroke()); + + if (this.startTail != null) { + final UShape shape = new UPolygon(this.startTail); + ug.getParam().setColor(color); + if (this.link.getType().getDecor1().isFill()) { + ug.getParam().setBackcolor(color); + } else { + ug.getParam().setBackcolor(null); + } + ug.draw(x, y, shape); + } + if (this.endHead != null) { + final UShape shape = new UPolygon(this.endHead); + ug.getParam().setColor(color); + if (this.link.getType().getDecor2().isFill()) { + ug.getParam().setBackcolor(color); + } else { + ug.getParam().setBackcolor(null); + } + ug.draw(x, y, shape); + } + if (this.labelText != null) { + this.labelText.drawU(ug, x + this.labelXY.x, y + this.labelXY.y); + } + if (this.startTailText != null) { + this.startTailText.drawU(ug, x + this.startTailLabelXY.x, y + this.startTailLabelXY.y); + } + if (this.endHeadText != null) { + this.endHeadText.drawU(ug, x + this.endHeadLabelXY.x, y + this.endHeadLabelXY.y); + } + + if (this.note != null) { + this.note.drawU(ug, x + this.noteXY.x, y + this.noteXY.y); + } + } + + public boolean isInverted() { + return link.isInverted(); + } + + private double getDecorDzeta() { + final int size1 = link.getType().getDecor1().getSize(); + final int size2 = link.getType().getDecor2().getSize(); + return size1 + size2; + } + + public double getHorizontalDzeta(StringBounder stringBounder) { + if (startUid.equals(endUid)) { + return getDecorDzeta(); + } + final ArithmeticStrategy strategy; + if (isHorizontal()) { + strategy = new ArithmeticStrategySum(); + } else { + return 0; + } + if (labelText != null) { + strategy.eat(labelText.calculateDimension(stringBounder).getWidth()); + } + if (startTailText != null) { + strategy.eat(startTailText.calculateDimension(stringBounder).getWidth()); + } + if (endHeadText != null) { + strategy.eat(endHeadText.calculateDimension(stringBounder).getWidth()); + } + return strategy.getResult() + getDecorDzeta(); + } + + private boolean isHorizontal() { + return link.getLength() == 1; + } + + public double getVerticalDzeta(StringBounder stringBounder) { + if (startUid.equals(endUid)) { + return getDecorDzeta(); + } + final ArithmeticStrategy strategy; + if (isHorizontal()) { + return 0; + } else { + strategy = new ArithmeticStrategySum(); + } + if (labelText != null) { + strategy.eat(labelText.calculateDimension(stringBounder).getHeight()); + } + if (startTailText != null) { + strategy.eat(startTailText.calculateDimension(stringBounder).getHeight()); + } + if (endHeadText != null) { + strategy.eat(endHeadText.calculateDimension(stringBounder).getHeight()); + } + return strategy.getResult() + getDecorDzeta(); + } + + private Positionable getStartTailPositionnable() { + if (startTailText == null) { + return null; + } + return new Positionable() { + public Point2D getPosition() { + return startTailLabelXY; + } + + public Dimension2D getSize() { + return startTailText.calculateDimension(stringBounder); + } + }; + } + + private Positionable getEndHeadPositionnable() { + if (endHeadText == null) { + return null; + } + return new Positionable() { + public Point2D getPosition() { + return endHeadLabelXY; + } + + public Dimension2D getSize() { + return endHeadText.calculateDimension(stringBounder); + } + }; + } + + public void manageCollision(List allShapes) { +// final Positionable start = getStartTailPositionnable(); +// if (start != null) { +// for (Shape sh : allShapes) { +// if (cut(start, sh)) { +// avoid(startTailLabelXY, start, sh); +// } +// } +// } +// +// final Positionable end = getEndHeadPositionnable(); +// if (end != null) { +// for (Shape sh : allShapes) { +// if (cut(end, sh)) { +// avoid(endHeadLabelXY, end, sh); +// } +// } +// } + + } + + private void avoid(Point2D.Double move, Positionable pos, Shape sh) { + final Oscillator oscillator = new Oscillator(); + final Point2D.Double orig = new Point2D.Double(move.x, move.y); + while (cut(pos, sh)) { + final Point2D.Double m = oscillator.nextPosition(); + move.setLocation(orig.x + m.x, orig.y + m.y); + } + } + + private boolean cut(Positionable pos, Shape sh) { + return BezierUtils.intersect(pos, sh) || tooClose(pos); + } + + private boolean tooClose(Positionable pos) { + final double dist = dotPath.getMinDist(BezierUtils.getCenter(pos)); + final Dimension2D dim = pos.getSize(); + System.err.println("dist=" + dist); + return dist < (dim.getWidth() / 2 + 2) || dist < (dim.getHeight() / 2 + 2); + } + +} diff --git a/src/net/sourceforge/plantuml/svek/Oscillator.java b/src/net/sourceforge/plantuml/svek/Oscillator.java new file mode 100644 index 000000000..b618e51e3 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/Oscillator.java @@ -0,0 +1,87 @@ +/* ======================================================================== + * 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: 3831 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Point2D; + +public class Oscillator { + + private int n = 3; + private int i = 0; + private char seg = 'A'; + + private int x = -1; + private int y = -1; + + public Point2D.Double nextPosition() { + assert n % 2 == 1; + final int halfN = (n - 1) / 2; + final Point2D.Double result = new Point2D.Double(x, y); + i++; + if (seg == 'A') { + x++; + if (x > halfN) { + seg = 'B'; + x = halfN; + y = -halfN + 1; + } + } else if (seg == 'B') { + y++; + if (y > halfN) { + seg = 'C'; + x = halfN - 1; + y = halfN; + } + } else if (seg == 'C') { + x--; + if (x < -halfN) { + seg = 'D'; + x = -halfN; + y = halfN - 1; + } + } else if (seg == 'D') { + y--; + if (y == -halfN) { + n += 2; + i = 0; + x = -((n - 1) / 2); + y = x; + seg = 'A'; + } + } else { + throw new UnsupportedOperationException(); + } + return result; + } +} diff --git a/src/net/sourceforge/plantuml/svek/RoundedContainer.java b/src/net/sourceforge/plantuml/svek/RoundedContainer.java new file mode 100644 index 000000000..91e9a2572 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/RoundedContainer.java @@ -0,0 +1,88 @@ +/* ======================================================================== + * 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.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public final class RoundedContainer { + + private final Dimension2D dim; + private final double titleHeight; + private final HtmlColor borderColor; + private final HtmlColor backColor; + private final HtmlColor imgBackcolor; + + public RoundedContainer(Dimension2D dim, double titleHeight, HtmlColor borderColor, HtmlColor backColor, + HtmlColor imgBackcolor) { + this.dim = dim; + this.imgBackcolor = imgBackcolor; + this.titleHeight = titleHeight; + this.borderColor = borderColor; + this.backColor = backColor; + } + + public final static double THICKNESS_BORDER = 1.5; + + public void drawU(UGraphic ug, double x, double y) { + + ug.getParam().setColor(borderColor); + ug.getParam().setBackcolor(backColor); + ug.getParam().setStroke(new UStroke(THICKNESS_BORDER)); + ug + .draw(x, y, new URectangle(dim.getWidth(), dim.getHeight(), EntityImageState.CORNER, + EntityImageState.CORNER)); + + final double yLine = y + titleHeight; + + ug.getParam().setBackcolor(imgBackcolor); + ug.getParam().setColor(imgBackcolor); + ug.getParam().setStroke(new UStroke()); + ug.draw(x + 2 * THICKNESS_BORDER, yLine + 2 * THICKNESS_BORDER, new URectangle(dim.getWidth() - 4 + * THICKNESS_BORDER, dim.getHeight() - titleHeight - 4 * THICKNESS_BORDER, EntityImageState.CORNER, + EntityImageState.CORNER)); + + ug.getParam().setColor(borderColor); + ug.getParam().setStroke(new UStroke(THICKNESS_BORDER)); + ug.draw(x, yLine, new ULine(dim.getWidth(), 0)); + ug.getParam().setStroke(new UStroke()); + + } + +} diff --git a/src/net/sourceforge/plantuml/svek/Shape.java b/src/net/sourceforge/plantuml/svek/Shape.java new file mode 100644 index 000000000..32a584195 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/Shape.java @@ -0,0 +1,176 @@ +/* ======================================================================== + * 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: 4236 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.posimo.Positionable; + +public class Shape implements Positionable { + + private final ShapeType type; + private final double width; + private final double height; + + private final String uid; + private final int color; + + private double minX; + private double minY; + + private Cluster cluster; + + private final boolean top; + + public final Cluster getCluster() { + return cluster; + } + + public final void setCluster(Cluster cluster) { + this.cluster = cluster; + } + + public Shape(ShapeType type, double width, double height, ColorSequence colorSequence, boolean top) { + this.top = top; + this.type = type; + this.width = width; + this.height = height; + this.color = colorSequence.getValue(); + this.uid = String.format("sh%04d", color); + } + + public final ShapeType getType() { + return type; + } + + public final double getWidth() { + return width; + } + + public final double getHeight() { + return height; + } + + public void appendShape(StringBuilder sb) { + // if (type == ShapeType.CIRCLE_IN_RECT) { + // sb.append("subgraph clusterlol" + uid + " {"); + // DotStringFactory.println(sb); + // } + sb.append(uid); + sb.append(" ["); + appendShapeInternal(sb); + sb.append(","); + sb.append("label=\"\""); + sb.append(","); + sb.append("width=" + SvekUtils.pixelToInches(getWidth())); + sb.append(","); + sb.append("height=" + SvekUtils.pixelToInches(getHeight())); + sb.append(","); + sb.append("color=\"" + StringUtils.getAsHtml(color) + "\""); + sb.append("];"); + SvekUtils.println(sb); + // if (type == ShapeType.CIRCLE_IN_RECT) { + // sb.append("}"); + // DotStringFactory.println(sb); + // } + + } + + private void appendShapeInternal(StringBuilder sb) { + if (type == ShapeType.RECTANGLE) { + sb.append("shape=rect"); + } else if (type == ShapeType.DIAMOND) { + sb.append("shape=diamond"); + } else if (type == ShapeType.CIRCLE) { + sb.append("shape=circle"); + } else if (type == ShapeType.CIRCLE_IN_RECT) { + sb.append("shape=circle"); + } else if (type == ShapeType.OVAL) { + sb.append("shape=ellipse"); + } else if (type == ShapeType.ROUND_RECTANGLE) { + sb.append("shape=rect,style=rounded"); + } else { + throw new IllegalStateException(type.toString()); + } + } + + public final String getUid() { + if (uid == null) { + throw new IllegalStateException(); + } + return uid; + } + + public final double getMinX() { + return minX; + } + + public final void setMinX(double minX) { + this.minX = minX; + } + + public final double getMinY() { + return minY; + } + + public final void setMinY(double minY) { + this.minY = minY; + } + + private IEntityImage image; + + public void setImage(IEntityImage image) { + this.image = image; + } + + public IEntityImage getImage() { + return image; + } + + public final boolean isTop() { + return top; + } + + public Point2D getPosition() { + return new Point2D.Double(minX, minY); + } + + public Dimension2D getSize() { + return new Dimension2DDouble(width, height); + } + +} diff --git a/src/net/sourceforge/plantuml/eps/Inkscape.java b/src/net/sourceforge/plantuml/svek/ShapeType.java similarity index 84% rename from src/net/sourceforge/plantuml/eps/Inkscape.java rename to src/net/sourceforge/plantuml/svek/ShapeType.java index 9ea14b9c9..ad448efc9 100644 --- a/src/net/sourceforge/plantuml/eps/Inkscape.java +++ b/src/net/sourceforge/plantuml/svek/ShapeType.java @@ -27,16 +27,14 @@ * in the United States and other countries.] * * Original Author: Arnaud Roques - * - * Revision $Revision: 4826 $ * + * Revision $Revision: 4236 $ + * */ -package net.sourceforge.plantuml.eps; +package net.sourceforge.plantuml.svek; -import java.io.File; -import java.io.IOException; +public enum ShapeType { -public interface Inkscape { + RECTANGLE, ROUND_RECTANGLE, CIRCLE, CIRCLE_IN_RECT, OVAL, DIAMOND - public void createEps(File svg, File eps) throws IOException, InterruptedException; } diff --git a/src/net/sourceforge/plantuml/svek/SvekResult.java b/src/net/sourceforge/plantuml/svek/SvekResult.java new file mode 100644 index 000000000..1ec64df11 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/SvekResult.java @@ -0,0 +1,110 @@ +/* ======================================================================== + * 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.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.UmlDiagramType; +import net.sourceforge.plantuml.cucadiagram.dot.DotData; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.ugraphic.UGraphic; + +public final class SvekResult implements IEntityImage { + + private final Rose rose = new Rose(); + + private final HtmlColor clusterBorder; + private final Dimension2D dim; + private final DotData dotData; + private final DotStringFactory dotStringFactory; + + public SvekResult(Dimension2D dim, DotData dotData, DotStringFactory dotStringFactory, HtmlColor clusterBorder) { + this.dim = dim; + this.dotData = dotData; + this.dotStringFactory = dotStringFactory; + this.clusterBorder = clusterBorder; + } + + public void drawU(UGraphic ug, double x, double y) { + for (Cluster cluster : dotStringFactory.getAllSubCluster()) { + cluster.drawU(ug, x, y, clusterBorder, dotData); + } + + for (Shape shape : dotStringFactory.getShapes()) { + final double minX = shape.getMinX(); + final double minY = shape.getMinY(); + shape.getImage().drawU(ug, x + minX, y + minY); + } + + for (Line line : dotStringFactory.getLines()) { + final HtmlColor color = rose.getHtmlColor(dotData.getSkinParam(), getArrowColorParam(), null); + line.drawU(ug, x, y, color); + } + + } + + private ColorParam getArrowColorParam() { + if (dotData.getUmlDiagramType() == UmlDiagramType.CLASS) { + return ColorParam.classArrow; + } else if (dotData.getUmlDiagramType() == UmlDiagramType.OBJECT) { + return ColorParam.objectArrow; + } else if (dotData.getUmlDiagramType() == UmlDiagramType.USECASE) { + return ColorParam.usecaseArrow; + } else if (dotData.getUmlDiagramType() == UmlDiagramType.ACTIVITY) { + return ColorParam.activityArrow; + } else if (dotData.getUmlDiagramType() == UmlDiagramType.COMPONENT) { + return ColorParam.componentArrow; + } else if (dotData.getUmlDiagramType() == UmlDiagramType.STATE) { + return ColorParam.stateArrow; + } + throw new IllegalStateException(); + } + + public HtmlColor getBackcolor() { + return dotData.getSkinParam().getBackgroundColor(); + } + + public Dimension2D getDimension(StringBounder stringBounder) { + return dim; + } + + public ShapeType getShapeType() { + return ShapeType.RECTANGLE; + } + +} diff --git a/src/net/sourceforge/plantuml/svek/SvekUtils.java b/src/net/sourceforge/plantuml/svek/SvekUtils.java new file mode 100644 index 000000000..0594b15d8 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/SvekUtils.java @@ -0,0 +1,185 @@ +/* ======================================================================== + * 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: 4236 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Point2D; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.StringTokenizer; + +import net.sourceforge.plantuml.Log; +import net.sourceforge.plantuml.StringUtils; + +public class SvekUtils { + + static public String getStrokeString(int color) { + return "stroke=\"" + StringUtils.getAsHtml(color).toLowerCase() + "\""; + } + + static public void traceSvgString(String svg) throws IOException { + final File f = new File("svek.svg"); + PrintWriter pw = null; + try { + pw = new PrintWriter(new FileWriter(f)); + pw.print(svg); + Log.info("Creating file " + f); + } finally { + if (pw != null) { + pw.close(); + } + } + } + + static class PointListIterator implements Iterator> { + + private final String text; + private final double yDelta; + private int pos = 0; + + public PointListIterator(String text, double yDelta) { + this.text = text; + this.yDelta = yDelta; + } + + public boolean hasNext() { + return true; + } + + public List next() { + final List result = extractPointsList(text, pos, yDelta); + pos = text.indexOf(pointsString, pos) + pointsString.length() + 1; + return result; + } + + public void remove() { + throw new UnsupportedOperationException(); + } + + } + + final private static String pointsString = "points=\""; + + public static List extractPointsList(final String svg, final int starting, double yDelta) { + final int p2 = svg.indexOf(pointsString, starting); + final int p3 = svg.indexOf("\"", p2 + pointsString.length()); + final String points = svg.substring(p2 + pointsString.length(), p3); + final List pointsList = getPoints(points, yDelta); + return pointsList; + } + + static public double getValue(String svg, int starting, String varName) { + final String varNameString = varName + "=\""; + int p1 = svg.indexOf(varNameString, starting); + if (p1 == -1) { + throw new IllegalStateException(); + } + p1 += varNameString.length(); + final int p2 = svg.indexOf('\"', p1); + return Double.parseDouble(svg.substring(p1, p2)); + + } + + public static double getMaxX(List points) { + double result = points.get(0).x; + for (int i = 1; i < points.size(); i++) { + if (points.get(i).x > result) { + result = points.get(i).x; + } + } + return result; + } + + public static double getMinX(List points) { + double result = points.get(0).x; + for (int i = 1; i < points.size(); i++) { + if (points.get(i).x < result) { + result = points.get(i).x; + } + } + return result; + } + + public static Point2D.Double getMinXY(List points) { + return new Point2D.Double(getMinX(points), getMinY(points)); + } + + public static double getMaxY(List points) { + double result = points.get(0).y; + for (int i = 1; i < points.size(); i++) { + if (points.get(i).y > result) { + result = points.get(i).y; + } + } + return result; + } + + public static double getMinY(List points) { + double result = points.get(0).y; + for (int i = 1; i < points.size(); i++) { + if (points.get(i).y < result) { + result = points.get(i).y; + } + } + return result; + } + + static private List getPoints(String points, double yDelta) { + final List result = new ArrayList(); + final StringTokenizer st = new StringTokenizer(points, " "); + while (st.hasMoreTokens()) { + final String t = st.nextToken(); + final StringTokenizer st2 = new StringTokenizer(t, ","); + final double x = Double.parseDouble(st2.nextToken()); + final double y = Double.parseDouble(st2.nextToken()) + yDelta; + result.add(new Point2D.Double(x, y)); + } + return result; + } + + public static void println(StringBuilder sb) { + sb.append('\n'); + } + + public static String pixelToInches(double pixel) { + final double v = pixel / 72.0; + return String.format(Locale.US, "%6.6f", v); + } + +} diff --git a/src/net/sourceforge/plantuml/svek/UDrawable2.java b/src/net/sourceforge/plantuml/svek/UDrawable2.java new file mode 100644 index 000000000..31c642e86 --- /dev/null +++ b/src/net/sourceforge/plantuml/svek/UDrawable2.java @@ -0,0 +1,45 @@ +/* ======================================================================== + * 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: 3836 $ + * + */ +package net.sourceforge.plantuml.svek; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.skin.UDrawable; + +public interface UDrawable2 extends UDrawable { + + Dimension2D getDimension(StringBounder stringBounder); + +} diff --git a/src/net/sourceforge/plantuml/svg/SvgData.java b/src/net/sourceforge/plantuml/svg/SvgData.java new file mode 100644 index 000000000..97c0050da --- /dev/null +++ b/src/net/sourceforge/plantuml/svg/SvgData.java @@ -0,0 +1,142 @@ +/* ======================================================================== + * 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: 4173 $ + * + */ +package net.sourceforge.plantuml.svg; + +import java.util.StringTokenizer; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public final class SvgData { + + private String svg; + private double startX; + private double startY; + private double width; + private double height; + + public static SvgData fromGraphViz(String s) { + return new SvgData(removeSvgXmlHeader1(s)); + } + + private SvgData(String svg) { + this.svg = svg; + init(); + } + + private SvgData() { + } + + private static String removeSvgXmlHeader1(String svg) { + final String newString = ""; + svg = svg.replaceFirst("(?i)]*>", newString); + return svg; + } + + public SvgData mutateFromSvgTitler(String newSvg, double suppHeight, double suppWidth) { + final SvgData result = new SvgData(); + result.svg = newSvg; + result.startX = this.startX - suppWidth / 2; + result.startY = this.startY; + result.width = this.width + suppWidth; + result.height = this.height + suppHeight; + return result; + } + + public final String getSvg() { + return modifiedSvgXmlHeader(); + } + + private void init() { + final Pattern p = Pattern.compile("(?i)]*points=\"([^\"]+)\""); + final Matcher m = p.matcher(svg); + double minX = Double.MAX_VALUE; + double minY = Double.MAX_VALUE; + double maxX = -Double.MAX_VALUE; + double maxY = -Double.MAX_VALUE; + if (m.find() == false) { + return; + } + final String points = m.group(1); + final StringTokenizer st = new StringTokenizer(points, " "); + 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; + } + } + + this.width = maxX - minX; + this.height = maxY - minY; + } + + private String modifiedSvgXmlHeader() { + final StringBuilder newString = new StringBuilder( + ""); + return svg.replaceFirst("(?i)]*>", newString.toString()); + } + + public double getWidth() { + return width; + } + + public double getHeight() { + return height; + } + +} diff --git a/src/net/sourceforge/plantuml/svg/SvgGraphics.java b/src/net/sourceforge/plantuml/svg/SvgGraphics.java index cffd6c30b..3b6115cb1 100644 --- a/src/net/sourceforge/plantuml/svg/SvgGraphics.java +++ b/src/net/sourceforge/plantuml/svg/SvgGraphics.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6461 $ + * Revision $Revision: 6910 $ * */ package net.sourceforge.plantuml.svg; @@ -51,6 +51,7 @@ import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import net.sourceforge.plantuml.Log; import net.sourceforge.plantuml.eps.EpsGraphics; import net.sourceforge.plantuml.ugraphic.UPath; import net.sourceforge.plantuml.ugraphic.USegment; @@ -313,6 +314,9 @@ public class SvgGraphics { if (textDecoration != null) { elt.setAttribute("text-decoration", textDecoration); } + if (fontFamily != null) { + elt.setAttribute("font-family", fontFamily); + } elt.setTextContent(text); getG().appendChild(elt); ensureVisible(x, y); @@ -326,9 +330,18 @@ public class SvgGraphics { private Transformer getTransformer() throws TransformerException { // Get a TransformerFactory object. final TransformerFactory xformFactory = TransformerFactory.newInstance(); + // try { + // final Class factoryClass = Class + // .forName("com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl"); + // xformFactory = (TransformerFactory) factoryClass.newInstance(); + // } catch (Exception e) { + // xformFactory = TransformerFactory.newInstance(); + // } + Log.info("TransformerFactory=" + xformFactory.getClass()); // Get an XSL Transformer object. final Transformer transformer = xformFactory.newTransformer(); + Log.info("Transformer=" + transformer.getClass()); // // Sets the standalone property in the first line of // // the output file. @@ -349,11 +362,14 @@ public class SvgGraphics { // Document object final DOMSource source = new DOMSource(document); - String style = "width:" + maxX + ";height:" + maxY + ";"; + String style = "width:" + maxX + "px;height:" + maxY + "px;"; if (backcolor != null) { style += "background:" + backcolor + ";"; } root.setAttribute("style", style); + root.setAttribute("width", "" + maxX + "pt"); + root.setAttribute("height", "" + maxY + "pt"); + root.setAttribute("viewBox", "0 0 " + maxX + " " + maxY); // Get a StreamResult object that points to the // screen. Then transform the DOM sending XML to @@ -383,6 +399,9 @@ public class SvgGraphics { } else if (type == USegmentType.SEG_QUADTO) { sb.append("Q" + (coord[0] + x) + "," + (coord[1] + y) + " " + (coord[2] + x) + "," + (coord[3] + y) + " "); + } else if (type == USegmentType.SEG_CUBICTO) { + sb.append("C" + (coord[0] + x) + "," + (coord[1] + y) + " " + (coord[2] + x) + "," + (coord[3] + y) + + " " + (coord[4] + x) + "," + (coord[5] + y) + " "); } else if (type == USegmentType.SEG_CLOSE) { // Nothing } else { @@ -393,6 +412,7 @@ public class SvgGraphics { final Element elt = (Element) document.createElement("path"); elt.setAttribute("d", sb.toString()); elt.setAttribute("style", getStyle()); + elt.setAttribute("fill", fill); getG().appendChild(elt); ensureVisible(x, y); } diff --git a/src/net/sourceforge/plantuml/svg/SvgTitler.java b/src/net/sourceforge/plantuml/svg/SvgTitler.java index fc4316625..ad9f64fbc 100644 --- a/src/net/sourceforge/plantuml/svg/SvgTitler.java +++ b/src/net/sourceforge/plantuml/svg/SvgTitler.java @@ -33,7 +33,6 @@ */ package net.sourceforge.plantuml.svg; -import java.awt.Color; import java.awt.Font; import java.awt.geom.Dimension2D; import java.io.IOException; @@ -44,56 +43,51 @@ import java.util.regex.Pattern; import net.sourceforge.plantuml.cucadiagram.dot.CucaDiagramFileMaker; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; import net.sourceforge.plantuml.graphic.VerticalPosition; +import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.svg.UGraphicSvg; public final class SvgTitler { - private final Color textColor; - private final List text; - // private final int fontSize; - // private final String fontFamily; + private final List text; private final HorizontalAlignement horizontalAlignement; private final VerticalPosition verticalPosition; private final int margin; private final TextBlock textBloc; + private final ColorMapper colorMapper; - public SvgTitler(Color textColor, List text, int fontSize, String fontFamily, + public SvgTitler(ColorMapper colorMapper, HtmlColor textColor, List text, int fontSize, String fontFamily, HorizontalAlignement horizontalAlignement, VerticalPosition verticalPosition, int margin) { - this.textColor = textColor; this.text = text; - // this.fontSize = fontSize; - // this.fontFamily = fontFamily; + this.colorMapper = colorMapper; this.horizontalAlignement = horizontalAlignement; this.verticalPosition = verticalPosition; this.margin = margin; if (text == null || text.size() == 0) { textBloc = null; } else { - final Font normalFont = new Font(fontFamily, Font.PLAIN, fontSize); + final UFont normalFont = new UFont(fontFamily, Font.PLAIN, fontSize); textBloc = TextBlockUtils.create(text, new FontConfiguration(normalFont, textColor), HorizontalAlignement.LEFT); } } - public double getHeight() { - if (textBloc == null) { - return 0; - } - return textBloc.calculateDimension(new UGraphicSvg(false).getStringBounder()).getHeight() + margin; - } - - public String addTitleSvg(String svg, double width, double height) throws IOException { + public SvgData addTitle(SvgData svgData) throws IOException { if (text == null || text.size() == 0) { - return svg; + return svgData; } - final UGraphicSvg uGraphicSvg = new UGraphicSvg(false); + final UGraphicSvg uGraphicSvg = new UGraphicSvg(colorMapper, false); final Dimension2D dimText = textBloc.calculateDimension(uGraphicSvg.getStringBounder()); final double xpos; + final double width = svgData.getWidth(); + final double height = svgData.getHeight(); + if (horizontalAlignement == HorizontalAlignement.LEFT) { xpos = 2; } else if (horizontalAlignement == HorizontalAlignement.RIGHT) { @@ -105,8 +99,12 @@ public final class SvgTitler { assert false; } - final double yText; + double suppWidth = 0; + if (dimText.getWidth() > width) { + suppWidth = dimText.getWidth() - width; + } + final double yText; if (verticalPosition == VerticalPosition.TOP) { yText = 0; } else { @@ -117,9 +115,11 @@ public final class SvgTitler { String svgTitle = CucaDiagramFileMaker.getSvg(uGraphicSvg); svgTitle = svgTitle.replaceFirst("(?i)", ""); + String newSvg = svgData.getSvg(); + if (verticalPosition == VerticalPosition.TOP) { final Pattern p = Pattern.compile("(?i)translate\\((\\d+)\\s+(\\d+)"); - final Matcher m = p.matcher(svg); + final Matcher m = p.matcher(newSvg); final StringBuffer sb = new StringBuffer(); while (m.find()) { @@ -128,16 +128,15 @@ public final class SvgTitler { m.appendReplacement(sb, "translate(" + tx + " " + ty); } m.appendTail(sb); - svg = sb.toString(); + newSvg = sb.toString(); } - final int x = svg.indexOf(" listModel.getSize() - 1) { + index = listModel.getSize() - 1; + } + simpleLine2 = (SimpleLine2) listModel.getElementAt(index); + setTitle(simpleLine2.toString()); + refreshImage(); + } + + private ScrollablePicture buildScrollablePicture() { + final GeneratedImage generatedImage = simpleLine2.getGeneratedImage(); + if (generatedImage == null) { + return null; + } + final File png = generatedImage.getPngFile(); + final Image image = Toolkit.getDefaultToolkit().createImage(png.getAbsolutePath()); + final ImageIcon imageIcon = new ImageIcon(image, simpleLine2.toString()); + final ScrollablePicture scrollablePicture = new ScrollablePicture(imageIcon, 1); + return scrollablePicture; + } + + public SimpleLine2 getSimpleLine() { + return simpleLine2; + } + + public void refreshImage() { + scrollPane.setViewportView(buildScrollablePicture()); + force(); + } + + private void force() { + // setVisible(true); + repaint(); + // validate(); + // getContentPane().validate(); + // getContentPane().setVisible(true); + // getContentPane().repaint(); + // scrollPane.validate(); + // scrollPane.setVisible(true); + // scrollPane.repaint(); + } + +} diff --git a/src/net/sourceforge/plantuml/swing/MainWindow.java b/src/net/sourceforge/plantuml/swing/MainWindow.java index a707b38b3..0eec83f4d 100644 --- a/src/net/sourceforge/plantuml/swing/MainWindow.java +++ b/src/net/sourceforge/plantuml/swing/MainWindow.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6453 $ + * Revision $Revision: 6533 $ * */ package net.sourceforge.plantuml.swing; @@ -83,7 +83,6 @@ public class MainWindow extends JFrame { private final JList jList1 = new JList(); private final JScrollPane scrollPane; private final JButton changeDirButton = new JButton("Change Directory"); - // private final JButton refreshButton = new JButton("Refresh"); private final JTextField extensions = new JTextField(); final private List currentDirectoryListing = new ArrayList(); @@ -130,11 +129,6 @@ public class MainWindow extends JFrame { changeDir(dirWatcher.getDir()); } - private void refreshReloadDir() { - changeDir(dirWatcher.getDir()); - } - - private String getRegexpPattern(String ext) { final Pattern p = Pattern.compile("\\w+"); final Matcher m = p.matcher(ext); @@ -172,10 +166,6 @@ public class MainWindow extends JFrame { south.add(labelFileExtensions, BorderLayout.WEST); south.add(extensions, BorderLayout.CENTER); -// final JPanel southSouth = new JPanel(new GridLayout(1, 2)); -// southSouth.add(changeDirButton); -// southSouth.add(refreshButton); -// south.add(southSouth, BorderLayout.SOUTH); south.add(changeDirButton, BorderLayout.SOUTH); getContentPane().add(south, BorderLayout.SOUTH); @@ -200,11 +190,6 @@ public class MainWindow extends JFrame { displayDialogChangeDir(); } }); -// refreshButton.addActionListener(new ActionListener() { -// public void actionPerformed(ActionEvent e) { -// refreshReloadDir(); -// } -// }); extensions.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { diff --git a/src/net/sourceforge/plantuml/swing/MainWindow2.java b/src/net/sourceforge/plantuml/swing/MainWindow2.java new file mode 100644 index 000000000..0ea9e0f45 --- /dev/null +++ b/src/net/sourceforge/plantuml/swing/MainWindow2.java @@ -0,0 +1,340 @@ +/* ======================================================================== + * 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: 6533 $ + * + */ +package net.sourceforge.plantuml.swing; + +import java.awt.BorderLayout; +import java.awt.Frame; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.FocusEvent; +import java.awt.event.FocusListener; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.Vector; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.prefs.Preferences; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.swing.BorderFactory; +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextField; +import javax.swing.ListModel; +import javax.swing.SwingUtilities; +import javax.swing.Timer; + +import net.sourceforge.plantuml.DirWatcher2; +import net.sourceforge.plantuml.GeneratedImage; +import net.sourceforge.plantuml.Log; +import net.sourceforge.plantuml.Option; + +public class MainWindow2 extends JFrame { + + final private static Preferences prefs = Preferences.userNodeForPackage(MainWindow2.class); + final private static String KEY_DIR = "cur"; + final private static String KEY_PATTERN = "pat"; + + private final JList jList1 = new JList(); + private final JScrollPane scrollPane; + private final JButton changeDirButton = new JButton("Change Directory"); + private final JTextField extensions = new JTextField(); + + final private List currentDirectoryListing2 = new ArrayList(); + final private Set openWindows2 = new HashSet(); + final private Option option; + + private DirWatcher2 dirWatcher; + + public MainWindow2(Option option) { + this(new File(prefs.get(KEY_DIR, ".")), option); + + } + + private String getExtensions() { + return prefs.get(KEY_PATTERN, getDefaultFileExtensions()); + } + + private String getDefaultFileExtensions() { + return "txt, tex, java, htm, html, c, h, cpp, apt"; + } + + private void changeExtensions(String ext) { + if (ext.equals(getExtensions())) { + return; + } + final Pattern p = Pattern.compile("\\w+"); + final Matcher m = p.matcher(ext); + final StringBuilder sb = new StringBuilder(); + + while (m.find()) { + final String value = m.group(); + if (sb.length() > 0) { + sb.append(", "); + } + sb.append(value); + + } + ext = sb.toString(); + if (ext.length() == 0) { + ext = getDefaultFileExtensions(); + } + extensions.setText(ext); + prefs.put(KEY_PATTERN, ext); + changeDir(dirWatcher.getDir()); + } + + private String getRegexpPattern(String ext) { + final Pattern p = Pattern.compile("\\w+"); + final Matcher m = p.matcher(ext); + final StringBuilder filePattern = new StringBuilder("(?i)^.*\\.("); + + while (m.find()) { + final String value = m.group(); + if (filePattern.toString().endsWith("(") == false) { + filePattern.append("|"); + } + filePattern.append(value); + } + if (filePattern.toString().endsWith("(") == false) { + filePattern.append(")$"); + return filePattern.toString(); + } + return Option.getPattern(); + } + + private MainWindow2(File dir, Option option) { + super(dir.getAbsolutePath()); + this.option = option; + dirWatcher = new DirWatcher2(dir, option, getRegexpPattern(getExtensions())); + + Log.info("Showing MainWindow"); + scrollPane = new JScrollPane(jList1); + + final JPanel south = new JPanel(new BorderLayout()); + final JLabel labelFileExtensions = new JLabel("File extensions: "); + extensions.setText(getExtensions()); + + labelFileExtensions.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); + south.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3), BorderFactory + .createEtchedBorder())); + south.add(labelFileExtensions, BorderLayout.WEST); + south.add(extensions, BorderLayout.CENTER); + + south.add(changeDirButton, BorderLayout.SOUTH); + + getContentPane().add(south, BorderLayout.SOUTH); + getContentPane().add(scrollPane, BorderLayout.CENTER); + setSize(320, 200); + setVisible(true); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + final MouseListener mouseListener = new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + if (e.getClickCount() == 2) { + final int index = jList1.locationToIndex(e.getPoint()); + doubleClick((SimpleLine2) jList1.getModel().getElementAt(index), jList1.getModel(), index); + } + } + }; + jList1.addMouseListener(mouseListener); + changeDirButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + System.err.println("Opening Directory Window"); + displayDialogChangeDir(); + } + }); + + extensions.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + changeExtensions(extensions.getText()); + } + }); + extensions.addFocusListener(new FocusListener() { + + public void focusGained(FocusEvent e) { + } + + public void focusLost(FocusEvent e) { + changeExtensions(extensions.getText()); + } + }); + + startTimer(); + } + + private void startTimer() { + Log.info("Init done"); + final Timer timer = new Timer(3000, new ActionListener() { + public void actionPerformed(ActionEvent e) { + tick(); + } + }); + timer.setInitialDelay(0); + timer.start(); + Log.info("Timer started"); + } + + private void displayDialogChangeDir() { + final JFileChooser chooser = new JFileChooser(); + chooser.setDialogType(JFileChooser.CUSTOM_DIALOG); + chooser.setDialogTitle("Directory to watch:"); + chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); + chooser.setAcceptAllFileFilterUsed(false); + final String currentPath = prefs.get(KEY_DIR, "."); + chooser.setCurrentDirectory(new File(currentPath)); + Log.info("Showing OpenDialog"); + final int returnVal = chooser.showOpenDialog(this); + Log.info("Closing OpenDialog"); + if (returnVal == JFileChooser.APPROVE_OPTION) { + final File dir = chooser.getSelectedFile(); + changeDir(dir); + } + + } + + private void changeDir(File dir) { + prefs.put(KEY_DIR, dir.getAbsolutePath()); + dirWatcher.cancel(); + dirWatcher = new DirWatcher2(dir, option, getRegexpPattern(getExtensions())); + setTitle(dir.getAbsolutePath()); + Log.info("Creating DirWatcher"); + currentDirectoryListing2.clear(); + jList1.setListData(new Vector(currentDirectoryListing2)); + jList1.setVisible(true); + } + + private void doubleClick(SimpleLine2 simpleLine, ListModel listModel, int index) { + for (ImageWindow2 win : openWindows2) { + if (win.getSimpleLine().equals(simpleLine)) { + win.setVisible(true); + win.setExtendedState(Frame.NORMAL); + return; + } + } + openWindows2.add(new ImageWindow2(simpleLine, this, listModel, index)); + } + + private void tick() { + SwingUtilities.invokeLater(new Runnable() { + public void run() { + try { + final boolean changed = refreshDir(); + if (changed) { + jList1.setListData(new Vector(currentDirectoryListing2)); + jList1.setVisible(true); + } + } catch (IOException e) { + e.printStackTrace(); + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (ExecutionException e) { + e.printStackTrace(); + } + } + }); + } + + private boolean refreshDir() throws IOException, InterruptedException, ExecutionException { + final Map>> createdFiles2 = dirWatcher.buildCreatedFiles(); + boolean changed = false; + + for (Map.Entry>> ent : createdFiles2.entrySet()) { + final File file = ent.getKey(); + removeAllThatUseThisFile(file); + final Future> future = ent.getValue(); + final SimpleLine2 simpleLine = new SimpleLine2(file, null, future); + currentDirectoryListing2.add(simpleLine); + changed = true; + } + + for (SimpleLine2 line : new ArrayList(currentDirectoryListing2)) { + if (line.pendingAndFinished()) { + currentDirectoryListing2.remove(line); + changed = true; + final Future> future = line.getFuture(); + for (GeneratedImage im : future.get()) { + mayRefreshImageWindow(im.getPngFile()); + final SimpleLine2 simpleLine = new SimpleLine2(line.getFile(), im, null); + currentDirectoryListing2.add(simpleLine); + } + } + } + Collections.sort(currentDirectoryListing2); + return changed; + } + + private void removeAllThatUseThisFile(File file) { + for (final Iterator it = currentDirectoryListing2.iterator(); it.hasNext();) { + final SimpleLine2 line = it.next(); + if (line.getFile().equals(file)) { + it.remove(); + } + } + } + + private void mayRefreshImageWindow(File pngFile) { + for (ImageWindow2 win : openWindows2) { + if (pngFile.equals(win.getSimpleLine().getGeneratedImage().getPngFile())) { + win.refreshImage(); + } + } + + } + + public void closing(ImageWindow2 imageWindow) { + final boolean ok = openWindows2.remove(imageWindow); + if (ok == false) { + throw new IllegalStateException(); + } + } + +} diff --git a/src/net/sourceforge/plantuml/swing/SimpleLine2.java b/src/net/sourceforge/plantuml/swing/SimpleLine2.java new file mode 100644 index 000000000..fb45b91ce --- /dev/null +++ b/src/net/sourceforge/plantuml/swing/SimpleLine2.java @@ -0,0 +1,103 @@ +/* ======================================================================== + * 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: 3837 $ + * + */ +package net.sourceforge.plantuml.swing; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +import net.sourceforge.plantuml.GeneratedImage; + +class SimpleLine2 implements Comparable { + + private final File file; + private final GeneratedImage generatedImage; + private final Future> future; + + public SimpleLine2(File file, GeneratedImage generatedImage, Future> future) { + this.generatedImage = generatedImage; + this.file = file; + this.future = future; + } + + public File getFile() { + return file; + } + + public boolean pendingAndFinished() { + return generatedImage == null && future.isDone(); + } + + public List getFutureTerminated() throws InterruptedException, ExecutionException { + if (future == null) { + throw new IllegalStateException(); + } + final List list = future.get(); + if (list == null) { + return null; + } + final List result = new ArrayList(); + for (GeneratedImage im : list) { + result.add(new SimpleLine2(file, im, null)); + } + return Collections.unmodifiableList(result); + } + + @Override + public String toString() { + if (generatedImage == null) { + return file.getName() + " (...pending...)"; + } + final StringBuilder sb = new StringBuilder(generatedImage.getPngFile().getName()); + sb.append(" "); + sb.append(generatedImage.getDescription()); + return sb.toString(); + } + + public Future> getFuture() { + return future; + } + + public int compareTo(SimpleLine2 other) { + return toString().compareTo(other.toString()); + } + + public GeneratedImage getGeneratedImage() { + return generatedImage; + } + +} diff --git a/src/net/sourceforge/plantuml/telnet/AcceptTelnetClient.java b/src/net/sourceforge/plantuml/telnet/AcceptTelnetClient.java new file mode 100644 index 000000000..14dfd1fa8 --- /dev/null +++ b/src/net/sourceforge/plantuml/telnet/AcceptTelnetClient.java @@ -0,0 +1,89 @@ +/* ======================================================================== + * 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: 3837 $ + * + */ +package net.sourceforge.plantuml.telnet; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.Socket; + +import net.sourceforge.plantuml.FileFormat; +import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.SourceStringReader; + +class AcceptTelnetClient extends Thread { + final private Socket clientSocket; + final private BufferedReader br; + final private OutputStream os; + + AcceptTelnetClient(Socket socket) throws Exception { + clientSocket = socket; + System.out.println("Client Connected ..."); + br = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); + os = clientSocket.getOutputStream(); + + start(); + } + + public String runInternal() throws IOException { + StringBuilder sb = new StringBuilder(); + while (true) { + String s = br.readLine(); + if (s == null) { + return sb.toString(); + } + System.err.println("S=" + s); + sb.append(s); + sb.append('\n'); + if (s.equalsIgnoreCase("@enduml")) { + return sb.toString(); + } + } + } + + public void run() { + try { + final String uml = runInternal(); + System.err.println("UML=" + uml); + SourceStringReader s = new SourceStringReader(uml); + s.generateImage(os, new FileFormatOption(FileFormat.ATXT)); + os.close(); + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + } +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/telnet/TelnetServer.java b/src/net/sourceforge/plantuml/telnet/TelnetServer.java new file mode 100644 index 000000000..e5840c063 --- /dev/null +++ b/src/net/sourceforge/plantuml/telnet/TelnetServer.java @@ -0,0 +1,48 @@ +/* ======================================================================== + * 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: 3837 $ + * + */ +package net.sourceforge.plantuml.telnet; + +import java.net.ServerSocket; +import java.net.Socket; + +public class TelnetServer { + public static void main(String args[]) throws Exception { + final ServerSocket server = new ServerSocket(4242); + while (true) { + final Socket socket = server.accept(); + final AcceptTelnetClient ob = new AcceptTelnetClient(socket); + } + } + +} diff --git a/src/net/sourceforge/plantuml/ugraphic/AbstractCommonUGraphic.java b/src/net/sourceforge/plantuml/ugraphic/AbstractCommonUGraphic.java index ac13bd3bc..761d2d887 100644 --- a/src/net/sourceforge/plantuml/ugraphic/AbstractCommonUGraphic.java +++ b/src/net/sourceforge/plantuml/ugraphic/AbstractCommonUGraphic.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3837 $ + * Revision $Revision: 6578 $ * */ package net.sourceforge.plantuml.ugraphic; @@ -38,6 +38,11 @@ public abstract class AbstractCommonUGraphic implements UGraphic { private final UParam param = new UParam(); private double dx; private double dy; + private final ColorMapper colorMapper; + + public AbstractCommonUGraphic(ColorMapper colorMapper) { + this.colorMapper = colorMapper; + } final public UParam getParam() { return param; @@ -61,4 +66,8 @@ public abstract class AbstractCommonUGraphic implements UGraphic { return dy; } + final public ColorMapper getColorMapper() { + return colorMapper; + } + } diff --git a/src/net/sourceforge/plantuml/ugraphic/AbstractPlacementStrategy.java b/src/net/sourceforge/plantuml/ugraphic/AbstractPlacementStrategy.java index a6f9fb030..64e560286 100644 --- a/src/net/sourceforge/plantuml/ugraphic/AbstractPlacementStrategy.java +++ b/src/net/sourceforge/plantuml/ugraphic/AbstractPlacementStrategy.java @@ -106,4 +106,8 @@ public abstract class AbstractPlacementStrategy implements PlacementStrategy { return result; } + protected final StringBounder getStringBounder() { + return stringBounder; + } + } diff --git a/src/net/sourceforge/plantuml/ugraphic/AbstractUGraphic.java b/src/net/sourceforge/plantuml/ugraphic/AbstractUGraphic.java index 94e796c55..4ade5f430 100644 --- a/src/net/sourceforge/plantuml/ugraphic/AbstractUGraphic.java +++ b/src/net/sourceforge/plantuml/ugraphic/AbstractUGraphic.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4206 $ + * Revision $Revision: 6578 $ * */ package net.sourceforge.plantuml.ugraphic; @@ -42,7 +42,8 @@ public abstract class AbstractUGraphic extends AbstractCommonUGraphic { private final Map, UDriver> drivers = new HashMap, UDriver>(); - public AbstractUGraphic(O g2d) { + public AbstractUGraphic(ColorMapper colorMapper, O g2d) { + super(colorMapper); this.g2d = g2d; } @@ -59,7 +60,7 @@ public abstract class AbstractUGraphic extends AbstractCommonUGraphic { if (driver == null) { throw new UnsupportedOperationException(shape.getClass().toString() + " " + this.getClass()); } - driver.draw(shape, x + getTranslateX(), y + getTranslateY(), getParam(), g2d); + driver.draw(shape, x + getTranslateX(), y + getTranslateY(), getColorMapper(), getParam(), g2d); } } diff --git a/src/net/sourceforge/plantuml/ugraphic/ColorChangerMonochrome.java b/src/net/sourceforge/plantuml/ugraphic/ColorChangerMonochrome.java index 002ec135b..a27dc2e84 100644 --- a/src/net/sourceforge/plantuml/ugraphic/ColorChangerMonochrome.java +++ b/src/net/sourceforge/plantuml/ugraphic/ColorChangerMonochrome.java @@ -35,7 +35,7 @@ package net.sourceforge.plantuml.ugraphic; import java.awt.Color; -public class ColorChangerMonochrome implements ColorChanger { +public class ColorChangerMonochrome { public Color getChangedColor(Color color) { if (color==null) { diff --git a/src/net/sourceforge/plantuml/ugraphic/ColorChanger.java b/src/net/sourceforge/plantuml/ugraphic/ColorMapper.java similarity index 91% rename from src/net/sourceforge/plantuml/ugraphic/ColorChanger.java rename to src/net/sourceforge/plantuml/ugraphic/ColorMapper.java index e8b503b68..81c90a25f 100644 --- a/src/net/sourceforge/plantuml/ugraphic/ColorChanger.java +++ b/src/net/sourceforge/plantuml/ugraphic/ColorMapper.java @@ -35,7 +35,9 @@ package net.sourceforge.plantuml.ugraphic; import java.awt.Color; -public interface ColorChanger { +import net.sourceforge.plantuml.graphic.HtmlColor; - Color getChangedColor(Color color); +public interface ColorMapper { + + Color getMappedColor(HtmlColor color); } diff --git a/src/net/sourceforge/plantuml/ugraphic/ColorMapperIdentity.java b/src/net/sourceforge/plantuml/ugraphic/ColorMapperIdentity.java new file mode 100644 index 000000000..af6bc6539 --- /dev/null +++ b/src/net/sourceforge/plantuml/ugraphic/ColorMapperIdentity.java @@ -0,0 +1,48 @@ +/* ======================================================================== + * 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: 4912 $ + * + */ +package net.sourceforge.plantuml.ugraphic; + +import java.awt.Color; + +import net.sourceforge.plantuml.graphic.HtmlColor; + +public class ColorMapperIdentity implements ColorMapper { + + public Color getMappedColor(HtmlColor color) { + if (color == null) { + return null; + } + return color.getColor999(); + } +} diff --git a/src/net/sourceforge/plantuml/eps/InkscapeLinux.java b/src/net/sourceforge/plantuml/ugraphic/ColorMapperMonochrome.java similarity index 69% rename from src/net/sourceforge/plantuml/eps/InkscapeLinux.java rename to src/net/sourceforge/plantuml/ugraphic/ColorMapperMonochrome.java index 5d89f975e..a283fdef1 100644 --- a/src/net/sourceforge/plantuml/eps/InkscapeLinux.java +++ b/src/net/sourceforge/plantuml/ugraphic/ColorMapperMonochrome.java @@ -28,32 +28,23 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4826 $ + * Revision $Revision: 4912 $ * */ -package net.sourceforge.plantuml.eps; +package net.sourceforge.plantuml.ugraphic; -import java.io.File; +import java.awt.Color; -class InkscapeLinux extends AbstractInkscape { +import net.sourceforge.plantuml.graphic.HtmlColor; - @Override - protected File specificExe() { - final File usrLocalBin = new File("/usr/local/bin/inkscape"); - if (usrLocalBin.exists()) { - return usrLocalBin; +public class ColorMapperMonochrome implements ColorMapper { + + public Color getMappedColor(HtmlColor htmlColor) { + if (htmlColor == null) { + return null; } - - final File usrBin = new File("/usr/bin/inkscape"); - if (usrBin.exists()) { - return usrBin; - } - return null; + final Color color = new ColorMapperIdentity().getMappedColor(htmlColor); + final int grayScale = (int) (color.getRed() * .3 + color.getGreen() * .59 + color.getBlue() * .11); + return new Color(grayScale, grayScale, grayScale); } - - @Override - protected void appendFilePath(final StringBuilder sb, File file) { - sb.append(file.getAbsolutePath()); - } - } diff --git a/src/net/sourceforge/plantuml/ugraphic/PlacementStrategyX1Y2Y3.java b/src/net/sourceforge/plantuml/ugraphic/PlacementStrategyX1Y2Y3.java index c0fae4371..e550b394f 100644 --- a/src/net/sourceforge/plantuml/ugraphic/PlacementStrategyX1Y2Y3.java +++ b/src/net/sourceforge/plantuml/ugraphic/PlacementStrategyX1Y2Y3.java @@ -54,22 +54,25 @@ public class PlacementStrategyX1Y2Y3 extends AbstractPlacementStrategy { double maxWidthButFirst = getMaxWidth(butFirst()); double sumHeightButFirst = getSumHeight(butFirst()); - final double space = (width - first.getWidth() - maxWidthButFirst) / 5; + final double space = (width - first.getWidth() - maxWidthButFirst) / 3; final Map result = new LinkedHashMap(); - double x = space * 2; + // double x = space * 2; final Iterator> it = getDimensions().entrySet().iterator(); final Map.Entry ent = it.next(); double y = (height - ent.getValue().getHeight()) / 2; - result.put(ent.getKey(), new Point2D.Double(x, y)); + result.put(ent.getKey(), new Point2D.Double(space, y)); - x += ent.getValue().getWidth() + space; + // x += ent.getValue().getWidth() + space; y = (height - sumHeightButFirst) / 2; while (it.hasNext()) { final Map.Entry ent2 = it.next(); - result.put(ent2.getKey(), new Point2D.Double(x, y)); + final TextBlock textBlock = ent2.getKey(); + final Dimension2D dim = getDimensions().get(textBlock); + final double x = 2 * space + first.getWidth() + (maxWidthButFirst - dim.getWidth()) / 2; + result.put(textBlock, new Point2D.Double(x, y)); y += ent2.getValue().getHeight(); } return result; diff --git a/src/net/sourceforge/plantuml/ugraphic/UDriver.java b/src/net/sourceforge/plantuml/ugraphic/UDriver.java index 4a5e949cf..0d1bf2ced 100644 --- a/src/net/sourceforge/plantuml/ugraphic/UDriver.java +++ b/src/net/sourceforge/plantuml/ugraphic/UDriver.java @@ -28,12 +28,12 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3837 $ + * Revision $Revision: 6576 $ * */ package net.sourceforge.plantuml.ugraphic; public interface UDriver { - public void draw(UShape shape, double x, double y, UParam param, O object); + public void draw(UShape shape, double x, double y, ColorMapper mapper, UParam param, O object); } diff --git a/src/net/sourceforge/plantuml/ugraphic/UFont.java b/src/net/sourceforge/plantuml/ugraphic/UFont.java new file mode 100644 index 000000000..0c12e1c9f --- /dev/null +++ b/src/net/sourceforge/plantuml/ugraphic/UFont.java @@ -0,0 +1,123 @@ +/* ======================================================================== + * 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: 3837 $ + * + */ +package net.sourceforge.plantuml.ugraphic; + +import java.awt.Font; +import java.awt.Graphics2D; +import java.util.Locale; + +public class UFont { + + private final Font font; + private final String family; + + public UFont(String fontFamily, int fontStyle, int fontSize) { + this(new Font(fontFamily, fontStyle, fontSize), fontFamily); + } + + private UFont(Font font, String family) { + this.font = font; + this.family = family; + } + + public final Font getFont() { + return font; + } + + public UFont deriveSize(float size) { + return new UFont(font.deriveFont(size), family); + } + + public UFont deriveStyle(int style) { + return new UFont(font.deriveFont(style), family); + } + + public int getStyle() { + return font.getStyle(); + } + + public int getSize() { + return font.getSize(); + } + + public double getSize2D() { + return font.getSize2D(); + } + + public boolean isBold() { + return font.isBold(); + } + + public boolean isItalic() { + return font.isItalic(); + } + + public String getFamily(UFontContext context) { + if (context == UFontContext.EPS) { + if (family == null) { + return "Times-Roman"; + } + return font.getPSName(); + } + if (context == UFontContext.SVG) { + return family; + } + // return font.getFamily(); + return family; + } + + @Override + public String toString() { + return font.toString() + " " + font.getPSName(); + } + + @Override + public int hashCode() { + return font.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof UFont == false) { + return false; + } + return this.font.equals(((UFont) obj).font); + + } + + @Deprecated + public static UFont getCurrentFont(Graphics2D g2d) { + return new UFont(g2d.getFont(), g2d.getFont().getFontName()); + } +} diff --git a/src/net/sourceforge/plantuml/ugraphic/ColorChangerIdentity.java b/src/net/sourceforge/plantuml/ugraphic/UFontContext.java similarity index 87% rename from src/net/sourceforge/plantuml/ugraphic/ColorChangerIdentity.java rename to src/net/sourceforge/plantuml/ugraphic/UFontContext.java index e48ae2ab4..c6495c065 100644 --- a/src/net/sourceforge/plantuml/ugraphic/ColorChangerIdentity.java +++ b/src/net/sourceforge/plantuml/ugraphic/UFontContext.java @@ -28,16 +28,11 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4912 $ + * Revision $Revision: 3837 $ * */ package net.sourceforge.plantuml.ugraphic; -import java.awt.Color; - -public class ColorChangerIdentity implements ColorChanger { - - public Color getChangedColor(Color color) { - return color; - } +public enum UFontContext { + JAVA, EPS, SVG, DOT, SYSTEM, PNG } diff --git a/src/net/sourceforge/plantuml/ugraphic/UFontUser.java b/src/net/sourceforge/plantuml/ugraphic/UFontUser.java new file mode 100644 index 000000000..d12d1c53a --- /dev/null +++ b/src/net/sourceforge/plantuml/ugraphic/UFontUser.java @@ -0,0 +1,38 @@ +/* ======================================================================== + * 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: 3837 $ + * + */ +package net.sourceforge.plantuml.ugraphic; + +public enum UFontUser { + JAVA, DOT +} diff --git a/src/net/sourceforge/plantuml/ugraphic/UGradient.java b/src/net/sourceforge/plantuml/ugraphic/UGradient.java index de7230b07..59a36a4e4 100644 --- a/src/net/sourceforge/plantuml/ugraphic/UGradient.java +++ b/src/net/sourceforge/plantuml/ugraphic/UGradient.java @@ -33,39 +33,42 @@ package net.sourceforge.plantuml.ugraphic; import java.awt.Color; +import net.sourceforge.plantuml.graphic.HtmlColor; + public class UGradient { - private final Color color1; - private final Color color2; + private final HtmlColor color1; + private final HtmlColor color2; - public UGradient(Color color1, Color color2) { + public UGradient(HtmlColor color1, HtmlColor color2) { if (color1 == null || color2 == null) { throw new IllegalArgumentException(); } this.color1 = color1; this.color2 = color2; - } - public final Color getColor1() { + public final HtmlColor getColor1() { return color1; } - public final Color getColor2() { + public final HtmlColor getColor2() { return color2; } - public final Color getColor(double coeff) { + public final Color getColor(ColorMapper mapper, double coeff) { if (coeff > 1 || coeff < 0) { throw new IllegalArgumentException("c=" + coeff); } - final int vred = color2.getRed() - color1.getRed(); - final int vgreen = color2.getGreen() - color1.getGreen(); - final int vblue = color2.getBlue() - color1.getBlue(); + final Color c1 = mapper.getMappedColor(color1); + final Color c2 = mapper.getMappedColor(color2); + final int vred = c2.getRed() - c1.getRed(); + final int vgreen = c2.getGreen() - c1.getGreen(); + final int vblue = c2.getBlue() - c1.getBlue(); - final int red = color1.getRed() + (int) (coeff * vred); - final int green = color1.getGreen() + (int) (coeff * vgreen); - final int blue = color1.getBlue() + (int) (coeff * vblue); + final int red = c1.getRed() + (int) (coeff * vred); + final int green = c1.getGreen() + (int) (coeff * vgreen); + final int blue = c1.getBlue() + (int) (coeff * vblue); return new Color(red, green, blue); diff --git a/src/net/sourceforge/plantuml/ugraphic/UGraphic.java b/src/net/sourceforge/plantuml/ugraphic/UGraphic.java index 24dbcc51e..10837aad1 100644 --- a/src/net/sourceforge/plantuml/ugraphic/UGraphic.java +++ b/src/net/sourceforge/plantuml/ugraphic/UGraphic.java @@ -28,13 +28,11 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6398 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.ugraphic; -import java.awt.Font; - import net.sourceforge.plantuml.graphic.StringBounder; public interface UGraphic { @@ -45,7 +43,7 @@ public interface UGraphic { public void draw(double x, double y, UShape shape); - public void centerChar(double x, double y, char c, Font font); + public void centerChar(double x, double y, char c, UFont font); public void translate(double dx, double dy); @@ -60,5 +58,7 @@ public interface UGraphic { public void setAntiAliasing(boolean trueForOn); public void setUrl(String url, String tooltip); + + public ColorMapper getColorMapper(); } diff --git a/src/net/sourceforge/plantuml/ugraphic/UGraphicUtils.java b/src/net/sourceforge/plantuml/ugraphic/UGraphicUtils.java index e12451b36..3754b74f3 100644 --- a/src/net/sourceforge/plantuml/ugraphic/UGraphicUtils.java +++ b/src/net/sourceforge/plantuml/ugraphic/UGraphicUtils.java @@ -33,8 +33,6 @@ */ package net.sourceforge.plantuml.ugraphic; -import java.awt.Font; - import net.sourceforge.plantuml.graphic.StringBounder; public abstract class UGraphicUtils { @@ -42,7 +40,7 @@ public abstract class UGraphicUtils { public static UGraphic translate(final UGraphic g, final double tx, final double ty) { return new UGraphic() { - public void centerChar(double x, double y, char c, Font font) { + public void centerChar(double x, double y, char c, UFont font) { g.centerChar(tx + x, ty + y, c, font); } @@ -85,6 +83,10 @@ public abstract class UGraphicUtils { public void setUrl(String url, String tooltip) { g.setUrl(url, tooltip); } + + public ColorMapper getColorMapper() { + return g.getColorMapper(); + } }; } diff --git a/src/net/sourceforge/plantuml/ugraphic/UParam.java b/src/net/sourceforge/plantuml/ugraphic/UParam.java index e2b247615..1e9195ca9 100644 --- a/src/net/sourceforge/plantuml/ugraphic/UParam.java +++ b/src/net/sourceforge/plantuml/ugraphic/UParam.java @@ -28,27 +28,25 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6398 $ + * Revision $Revision: 6576 $ * */ package net.sourceforge.plantuml.ugraphic; -import java.awt.Color; +import net.sourceforge.plantuml.graphic.HtmlColor; public class UParam { - private Color color = null; - private Color backcolor = null; + private HtmlColor color = null; + private HtmlColor backcolor = null; private UStroke stroke = new UStroke(1); private UGradient gradient = null; - private ColorChanger colorChanger = new ColorChangerIdentity(); public void reset() { color = null; backcolor = null; gradient = null; stroke = new UStroke(1); - colorChanger = new ColorChangerIdentity(); } public final UGradient getGradient() { @@ -59,20 +57,20 @@ public class UParam { this.gradient = gradient; } - public void setColor(Color color) { + public void setColor(HtmlColor color) { this.color = color; } - public Color getColor() { - return colorChanger.getChangedColor(color); + public HtmlColor getColor() { + return color; } - public void setBackcolor(Color color) { + public void setBackcolor(HtmlColor color) { this.backcolor = color; } - public Color getBackcolor() { - return colorChanger.getChangedColor(backcolor); + public HtmlColor getBackcolor() { + return backcolor; } public void setStroke(UStroke stroke) { @@ -83,11 +81,4 @@ public class UParam { return stroke; } - private void setColorChanger(ColorChanger colorChanger) { - if (colorChanger == null) { - throw new IllegalArgumentException(); - } - this.colorChanger = colorChanger; - } - } diff --git a/src/net/sourceforge/plantuml/ugraphic/UPolygon.java b/src/net/sourceforge/plantuml/ugraphic/UPolygon.java index 6cafee9fd..b25bea040 100644 --- a/src/net/sourceforge/plantuml/ugraphic/UPolygon.java +++ b/src/net/sourceforge/plantuml/ugraphic/UPolygon.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5392 $ + * Revision $Revision: 6743 $ * */ package net.sourceforge.plantuml.ugraphic; @@ -42,6 +42,13 @@ public class UPolygon implements UShape { private final List all = new ArrayList(); + public UPolygon() { + } + + public UPolygon(List points) { + all.addAll(points); + } + public void addPoint(double x, double y) { all.add(new Point2D.Double(x, y)); } diff --git a/src/net/sourceforge/plantuml/ugraphic/eps/DriverDotPathEps.java b/src/net/sourceforge/plantuml/ugraphic/eps/DriverDotPathEps.java new file mode 100644 index 000000000..4015e7faf --- /dev/null +++ b/src/net/sourceforge/plantuml/ugraphic/eps/DriverDotPathEps.java @@ -0,0 +1,56 @@ +/* ======================================================================== + * 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: 3837 $ + * + */ +package net.sourceforge.plantuml.ugraphic.eps; + +import net.sourceforge.plantuml.eps.EpsGraphics; +import net.sourceforge.plantuml.posimo.DotPath; +import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.ugraphic.UDriver; +import net.sourceforge.plantuml.ugraphic.UParam; +import net.sourceforge.plantuml.ugraphic.UShape; + +public class DriverDotPathEps implements UDriver { + + public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, EpsGraphics eps) { + final DotPath shape = (DotPath) ushape; + //DriverLineG2d.manageStroke(param, g2d); + + if (param.getColor() != null) { + eps.setStrokeColor(mapper.getMappedColor(param.getColor())); + eps.setStrokeWidth("" + param.getStroke().getThickness(), param.getStroke().getDashVisible(), param.getStroke() + .getDashSpace()); + shape.draw(eps, x, y); + } + } +} diff --git a/src/net/sourceforge/plantuml/ugraphic/eps/DriverEllipseEps.java b/src/net/sourceforge/plantuml/ugraphic/eps/DriverEllipseEps.java index 6beb1c77e..136a1c647 100644 --- a/src/net/sourceforge/plantuml/ugraphic/eps/DriverEllipseEps.java +++ b/src/net/sourceforge/plantuml/ugraphic/eps/DriverEllipseEps.java @@ -32,6 +32,7 @@ package net.sourceforge.plantuml.ugraphic.eps; import net.sourceforge.plantuml.eps.EpsGraphics; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UDriver; import net.sourceforge.plantuml.ugraphic.UEllipse; import net.sourceforge.plantuml.ugraphic.UParam; @@ -39,13 +40,13 @@ import net.sourceforge.plantuml.ugraphic.UShape; public class DriverEllipseEps implements UDriver { - public void draw(UShape ushape, double x, double y, UParam param, EpsGraphics eps) { + public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, EpsGraphics eps) { final UEllipse rect = (UEllipse) ushape; final double width = rect.getWidth(); final double height = rect.getHeight(); - eps.setFillColor(param.getBackcolor()); - eps.setStrokeColor(param.getColor()); + eps.setFillColor(mapper.getMappedColor(param.getBackcolor())); + eps.setStrokeColor(mapper.getMappedColor(param.getColor())); eps.setStrokeWidth("" + param.getStroke().getThickness(), param.getStroke().getDashVisible(), param.getStroke() .getDashSpace()); diff --git a/src/net/sourceforge/plantuml/ugraphic/eps/DriverImageEps.java b/src/net/sourceforge/plantuml/ugraphic/eps/DriverImageEps.java index 188c84ddc..7d3ea3da7 100644 --- a/src/net/sourceforge/plantuml/ugraphic/eps/DriverImageEps.java +++ b/src/net/sourceforge/plantuml/ugraphic/eps/DriverImageEps.java @@ -32,6 +32,7 @@ package net.sourceforge.plantuml.ugraphic.eps; import net.sourceforge.plantuml.eps.EpsGraphics; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UDriver; import net.sourceforge.plantuml.ugraphic.UImage; import net.sourceforge.plantuml.ugraphic.UParam; @@ -39,7 +40,7 @@ import net.sourceforge.plantuml.ugraphic.UShape; public class DriverImageEps implements UDriver { - public void draw(UShape ushape, double x, double y, UParam param, EpsGraphics eps) { + public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, EpsGraphics eps) { final UImage shape = (UImage) ushape; eps.drawImage(shape.getImage(), x, y); } diff --git a/src/net/sourceforge/plantuml/ugraphic/eps/DriverLineEps.java b/src/net/sourceforge/plantuml/ugraphic/eps/DriverLineEps.java index 2d7bb2c44..5cfcf15ca 100644 --- a/src/net/sourceforge/plantuml/ugraphic/eps/DriverLineEps.java +++ b/src/net/sourceforge/plantuml/ugraphic/eps/DriverLineEps.java @@ -35,6 +35,7 @@ import java.awt.geom.Line2D; import net.sourceforge.plantuml.eps.EpsGraphics; import net.sourceforge.plantuml.ugraphic.ClipContainer; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UClip; import net.sourceforge.plantuml.ugraphic.UDriver; import net.sourceforge.plantuml.ugraphic.ULine; @@ -49,7 +50,7 @@ public class DriverLineEps implements UDriver { this.clipContainer = clipContainer; } - public void draw(UShape ushape, double x, double y, UParam param, EpsGraphics eps) { + public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, EpsGraphics eps) { final ULine shape = (ULine) ushape; double x2 = x + shape.getDX(); @@ -67,7 +68,7 @@ public class DriverLineEps implements UDriver { y2 = line.y2; } - eps.setStrokeColor(param.getColor()); + eps.setStrokeColor(mapper.getMappedColor(param.getColor())); eps.setStrokeWidth("" + param.getStroke().getThickness(), param.getStroke().getDashVisible(), param.getStroke() .getDashSpace()); eps.epsLine(x, y, x2, y2); diff --git a/src/net/sourceforge/plantuml/ugraphic/eps/DriverPolygonEps.java b/src/net/sourceforge/plantuml/ugraphic/eps/DriverPolygonEps.java index 59bf4926f..7be45dc76 100644 --- a/src/net/sourceforge/plantuml/ugraphic/eps/DriverPolygonEps.java +++ b/src/net/sourceforge/plantuml/ugraphic/eps/DriverPolygonEps.java @@ -35,6 +35,7 @@ import java.awt.geom.Point2D; import net.sourceforge.plantuml.eps.EpsGraphics; import net.sourceforge.plantuml.ugraphic.ClipContainer; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UClip; import net.sourceforge.plantuml.ugraphic.UDriver; import net.sourceforge.plantuml.ugraphic.UParam; @@ -49,7 +50,7 @@ public class DriverPolygonEps implements UDriver { this.clipContainer = clipContainer; } - public void draw(UShape ushape, double x, double y, UParam param, EpsGraphics eps) { + public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, EpsGraphics eps) { final UPolygon shape = (UPolygon) ushape; final double points[] = new double[shape.getPoints().size() * 2]; @@ -70,8 +71,8 @@ public class DriverPolygonEps implements UDriver { } } - eps.setFillColor(param.getBackcolor()); - eps.setStrokeColor(param.getColor()); + eps.setFillColor(mapper.getMappedColor(param.getBackcolor())); + eps.setStrokeColor(mapper.getMappedColor(param.getColor())); eps.epsPolygon(points); } diff --git a/src/net/sourceforge/plantuml/ugraphic/eps/DriverRectangleEps.java b/src/net/sourceforge/plantuml/ugraphic/eps/DriverRectangleEps.java index 2148be9a2..1bf924ba5 100644 --- a/src/net/sourceforge/plantuml/ugraphic/eps/DriverRectangleEps.java +++ b/src/net/sourceforge/plantuml/ugraphic/eps/DriverRectangleEps.java @@ -35,6 +35,7 @@ import java.awt.geom.Rectangle2D; import net.sourceforge.plantuml.eps.EpsGraphics; import net.sourceforge.plantuml.ugraphic.ClipContainer; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UClip; import net.sourceforge.plantuml.ugraphic.UDriver; import net.sourceforge.plantuml.ugraphic.UGradient; @@ -50,7 +51,7 @@ public class DriverRectangleEps implements UDriver { this.clipContainer = clipContainer; } - public void draw(UShape ushape, double x, double y, UParam param, EpsGraphics eps) { + public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, EpsGraphics eps) { final URectangle rect = (URectangle) ushape; double width = rect.getWidth(); @@ -70,13 +71,13 @@ public class DriverRectangleEps implements UDriver { final UGradient gr = param.getGradient(); if (gr == null) { - eps.setStrokeColor(param.getColor()); - eps.setFillColor(param.getBackcolor()); + eps.setStrokeColor(mapper.getMappedColor(param.getColor())); + eps.setFillColor(mapper.getMappedColor(param.getBackcolor())); eps.setStrokeWidth("" + param.getStroke().getThickness(), param.getStroke().getDashVisible(), param .getStroke().getDashSpace()); eps.epsRectangle(x, y, width, height, rx / 2, ry / 2); } else { - eps.epsRectangle(x, y, width, height, rx / 2, ry / 2, gr); + eps.epsRectangle(x, y, width, height, rx / 2, ry / 2, gr, mapper); } } diff --git a/src/net/sourceforge/plantuml/ugraphic/eps/DriverTextEps.java b/src/net/sourceforge/plantuml/ugraphic/eps/DriverTextEps.java index b27ccff1d..7fedde58b 100644 --- a/src/net/sourceforge/plantuml/ugraphic/eps/DriverTextEps.java +++ b/src/net/sourceforge/plantuml/ugraphic/eps/DriverTextEps.java @@ -31,8 +31,6 @@ */ package net.sourceforge.plantuml.ugraphic.eps; -import java.awt.Color; -import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics2D; import java.awt.font.FontRenderContext; @@ -41,13 +39,18 @@ import java.awt.geom.Dimension2D; import java.awt.geom.PathIterator; import net.sourceforge.plantuml.eps.EpsGraphics; +import net.sourceforge.plantuml.eps.EpsGraphicsMacroAndText; +import net.sourceforge.plantuml.eps.EpsStrategy; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.FontStyle; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounderUtils; import net.sourceforge.plantuml.ugraphic.ClipContainer; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UClip; import net.sourceforge.plantuml.ugraphic.UDriver; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UParam; import net.sourceforge.plantuml.ugraphic.UShape; import net.sourceforge.plantuml.ugraphic.UText; @@ -59,15 +62,17 @@ public class DriverTextEps implements UDriver { private final ClipContainer clipContainer; private final FontRenderContext fontRenderContext; private final Graphics2D g2dummy; + private final EpsStrategy strategy; - public DriverTextEps(Graphics2D g2dummy, ClipContainer clipContainer) { + public DriverTextEps(Graphics2D g2dummy, ClipContainer clipContainer, EpsStrategy strategy) { this.stringBounder = StringBounderUtils.asStringBounder(g2dummy); this.clipContainer = clipContainer; this.fontRenderContext = g2dummy.getFontRenderContext(); this.g2dummy = g2dummy; + this.strategy = strategy; } - public void draw(UShape ushape, double x, double y, UParam param, EpsGraphics eps) { + public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, EpsGraphics eps) { final UClip clip = clipContainer.getClip(); if (clip != null && clip.isInside(x, y) == false) { @@ -75,17 +80,23 @@ public class DriverTextEps implements UDriver { } final UText shape = (UText) ushape; - final FontConfiguration fontConfiguration = shape.getFontConfiguration(); - final Font font = fontConfiguration.getFont(); - final TextLayout t = new TextLayout(shape.getText(), font, fontRenderContext); - eps.setStrokeColor(fontConfiguration.getColor()); + if (strategy == EpsStrategy.WITH_MACRO_AND_TEXT) { + drawAsText(shape, x, y, param, eps, mapper); + return; + } + + final FontConfiguration fontConfiguration = shape.getFontConfiguration(); + final UFont font = fontConfiguration.getFont(); + + final TextLayout t = new TextLayout(shape.getText(), font.getFont(), fontRenderContext); + eps.setStrokeColor(mapper.getMappedColor(fontConfiguration.getColor())); drawPathIterator(eps, x, y, t.getOutline(null).getPathIterator(null)); if (fontConfiguration.containsStyle(FontStyle.UNDERLINE)) { - final Color extended = fontConfiguration.getExtendedColor(); + final HtmlColor extended = fontConfiguration.getExtendedColor(); if (extended != null) { - eps.setStrokeColor(extended); + eps.setStrokeColor(mapper.getMappedColor(extended)); } final Dimension2D dim = DriverTextG2d.calculateDimension(stringBounder, font, shape.getText()); eps.setStrokeWidth("1.1", 0, 0); @@ -95,9 +106,9 @@ public class DriverTextEps implements UDriver { if (fontConfiguration.containsStyle(FontStyle.WAVE)) { final Dimension2D dim = DriverTextG2d.calculateDimension(stringBounder, font, shape.getText()); final int ypos = (int) (y + 2.5) - 1; - final Color extended = fontConfiguration.getExtendedColor(); + final HtmlColor extended = fontConfiguration.getExtendedColor(); if (extended != null) { - eps.setStrokeColor(extended); + eps.setStrokeColor(mapper.getMappedColor(extended)); } eps.setStrokeWidth("1.1", 0, 0); for (int i = (int) x; i < x + dim.getWidth() - 5; i += 6) { @@ -107,12 +118,12 @@ public class DriverTextEps implements UDriver { eps.setStrokeWidth("1", 0, 0); } if (fontConfiguration.containsStyle(FontStyle.STRIKE)) { - final Color extended = fontConfiguration.getExtendedColor(); + final HtmlColor extended = fontConfiguration.getExtendedColor(); if (extended != null) { - eps.setStrokeColor(extended); + eps.setStrokeColor(mapper.getMappedColor(extended)); } final Dimension2D dim = DriverTextG2d.calculateDimension(stringBounder, font, shape.getText()); - final FontMetrics fm = g2dummy.getFontMetrics(font); + final FontMetrics fm = g2dummy.getFontMetrics(font.getFont()); final int ypos = (int) (y - fm.getDescent() - 0.5); eps.setStrokeWidth("1.3", 0, 0); eps.epsLine(x, ypos, x + dim.getWidth(), ypos); @@ -121,6 +132,17 @@ public class DriverTextEps implements UDriver { } + private void drawAsText(UText shape, double x, double y, UParam param, EpsGraphics eps, ColorMapper mapper) { + final FontConfiguration fontConfiguration = shape.getFontConfiguration(); + final FontMetrics fm = g2dummy.getFontMetrics(fontConfiguration.getFont().getFont()); + // final double ypos = y - fm.getDescent() + 0.5; + final double ypos = y - 1; + + eps.setStrokeColor(mapper.getMappedColor(fontConfiguration.getColor())); + ((EpsGraphicsMacroAndText) eps).drawText(shape.getText(), fontConfiguration, x, ypos); + + } + static void drawPathIterator(EpsGraphics eps, double x, double y, PathIterator path) { eps.newpath(); diff --git a/src/net/sourceforge/plantuml/ugraphic/eps/UGraphicEps.java b/src/net/sourceforge/plantuml/ugraphic/eps/UGraphicEps.java index b038f8eb3..634fd42a8 100644 --- a/src/net/sourceforge/plantuml/ugraphic/eps/UGraphicEps.java +++ b/src/net/sourceforge/plantuml/ugraphic/eps/UGraphicEps.java @@ -31,7 +31,6 @@ */ package net.sourceforge.plantuml.ugraphic.eps; -import java.awt.Font; import java.awt.Graphics2D; import java.awt.font.TextLayout; import java.awt.image.BufferedImage; @@ -44,11 +43,14 @@ import net.sourceforge.plantuml.eps.EpsStrategy; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounderUtils; import net.sourceforge.plantuml.graphic.UnusedSpace; +import net.sourceforge.plantuml.posimo.DotPath; import net.sourceforge.plantuml.skin.UDrawable; import net.sourceforge.plantuml.ugraphic.AbstractUGraphic; import net.sourceforge.plantuml.ugraphic.ClipContainer; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UClip; import net.sourceforge.plantuml.ugraphic.UEllipse; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UImage; import net.sourceforge.plantuml.ugraphic.ULine; import net.sourceforge.plantuml.ugraphic.UPolygon; @@ -62,20 +64,20 @@ public class UGraphicEps extends AbstractUGraphic implements ClipCo private final StringBounder stringBounder; - public UGraphicEps(EpsStrategy strategy) { - this(strategy.creatEpsGraphics()); + public UGraphicEps(ColorMapper colorMapper, EpsStrategy strategy) { + this(colorMapper, strategy, strategy.creatEpsGraphics()); } - private UGraphicEps(EpsGraphics eps) { - super(eps); + private UGraphicEps(ColorMapper colorMapper, EpsStrategy strategy, EpsGraphics eps) { + super(colorMapper, eps); stringBounder = StringBounderUtils.asStringBounder(imDummy); registerDriver(URectangle.class, new DriverRectangleEps(this)); - registerDriver(UText.class, new DriverTextEps(imDummy, this)); + registerDriver(UText.class, new DriverTextEps(imDummy, this, strategy)); registerDriver(ULine.class, new DriverLineEps(this)); registerDriver(UPolygon.class, new DriverPolygonEps(this)); registerDriver(UEllipse.class, new DriverEllipseEps()); registerDriver(UImage.class, new DriverImageEps()); - // registerDriver(UPath.class, new DriverPathSvg(this)); + registerDriver(DotPath.class, new DriverDotPathEps()); } public void close() { @@ -106,28 +108,29 @@ public class UGraphicEps extends AbstractUGraphic implements ClipCo return clip; } - public void centerChar(double x, double y, char c, Font font) { + public void centerChar(double x, double y, char c, UFont font) { final UnusedSpace unusedSpace = UnusedSpace.getUnusedSpace(font, c); final double xpos = x - unusedSpace.getCenterX() - 0.5; final double ypos = y - unusedSpace.getCenterY() - 0.5; - final TextLayout t = new TextLayout("" + c, font, imDummy.getFontRenderContext()); - getGraphicObject().setStrokeColor(getParam().getColor()); + final TextLayout t = new TextLayout("" + c, font.getFont(), imDummy.getFontRenderContext()); + getGraphicObject().setStrokeColor(getColorMapper().getMappedColor(getParam().getColor())); DriverTextEps.drawPathIterator(getGraphicObject(), xpos + getTranslateX(), ypos + getTranslateY(), t .getOutline(null).getPathIterator(null)); } - static public String getEpsString(UDrawable udrawable) throws IOException { - final UGraphicEps ug = new UGraphicEps(EpsStrategy.getDefault()); + static public String getEpsString(ColorMapper colorMapper, EpsStrategy epsStrategy, UDrawable udrawable) throws IOException { + final UGraphicEps ug = new UGraphicEps(colorMapper, epsStrategy); udrawable.drawU(ug); return ug.getEPSCode(); } - static public void copyEpsToFile(UDrawable udrawable, File f) throws IOException { + static public void copyEpsToFile(ColorMapper colorMapper, UDrawable udrawable, File f) throws IOException { final PrintWriter pw = new PrintWriter(f); - pw.print(UGraphicEps.getEpsString(udrawable)); + final EpsStrategy epsStrategy = EpsStrategy.getDefault2(); + pw.print(UGraphicEps.getEpsString(colorMapper, epsStrategy, udrawable)); pw.close(); } @@ -135,6 +138,11 @@ public class UGraphicEps extends AbstractUGraphic implements ClipCo } public void setUrl(String url, String tooltip) { + if (url == null) { + getGraphicObject().closeLink(); + } else { + getGraphicObject().openLink(url); + } } } diff --git a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverDotPathG2d.java b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverDotPathG2d.java index bd3a81eda..f9204aa75 100644 --- a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverDotPathG2d.java +++ b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverDotPathG2d.java @@ -36,18 +36,19 @@ package net.sourceforge.plantuml.ugraphic.g2d; import java.awt.Graphics2D; import net.sourceforge.plantuml.posimo.DotPath; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UDriver; import net.sourceforge.plantuml.ugraphic.UParam; import net.sourceforge.plantuml.ugraphic.UShape; public class DriverDotPathG2d implements UDriver { - public void draw(UShape ushape, double x, double y, UParam param, Graphics2D g2d) { + public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, Graphics2D g2d) { final DotPath shape = (DotPath) ushape; DriverLineG2d.manageStroke(param, g2d); if (param.getColor() != null) { - g2d.setColor(param.getColor()); + g2d.setColor(mapper.getMappedColor(param.getColor())); shape.draw(g2d, x, y); } } diff --git a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverEllipseG2d.java b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverEllipseG2d.java index 53c8f727e..488e2a6c3 100644 --- a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverEllipseG2d.java +++ b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverEllipseG2d.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4984 $ + * Revision $Revision: 6576 $ * */ package net.sourceforge.plantuml.ugraphic.g2d; @@ -39,6 +39,7 @@ import java.awt.Shape; import java.awt.geom.Arc2D; import java.awt.geom.Ellipse2D; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UDriver; import net.sourceforge.plantuml.ugraphic.UEllipse; import net.sourceforge.plantuml.ugraphic.UParam; @@ -46,29 +47,29 @@ import net.sourceforge.plantuml.ugraphic.UShape; public class DriverEllipseG2d implements UDriver { - public void draw(UShape ushape, double x, double y, UParam param, Graphics2D g2d) { + public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, Graphics2D g2d) { final UEllipse shape = (UEllipse) ushape; g2d.setStroke(new BasicStroke((float) param.getStroke().getThickness())); if (shape.getStart() == 0 && shape.getExtend() == 0) { final Shape ellipse = new Ellipse2D.Double(x, y, shape.getWidth(), shape.getHeight()); if (param.getBackcolor() != null) { - g2d.setColor(param.getBackcolor()); + g2d.setColor(mapper.getMappedColor(param.getBackcolor())); g2d.fill(ellipse); } if (param.getColor() != null) { - g2d.setColor(param.getColor()); + g2d.setColor(mapper.getMappedColor(param.getColor())); g2d.draw(ellipse); } } else { final Shape arc = new Arc2D.Double(x, y, shape.getWidth(), shape.getHeight(), shape.getStart(), shape .getExtend(), Arc2D.OPEN); if (param.getColor() != null) { - g2d.setColor(param.getBackcolor()); + g2d.setColor(mapper.getMappedColor(param.getBackcolor())); g2d.fill(arc); } if (param.getColor() != null) { - g2d.setColor(param.getColor()); + g2d.setColor(mapper.getMappedColor(param.getColor())); g2d.draw(arc); } } diff --git a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverImageG2d.java b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverImageG2d.java index db02471a4..77b3f447e 100644 --- a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverImageG2d.java +++ b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverImageG2d.java @@ -28,13 +28,14 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3961 $ + * Revision $Revision: 6576 $ * */ package net.sourceforge.plantuml.ugraphic.g2d; import java.awt.Graphics2D; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UDriver; import net.sourceforge.plantuml.ugraphic.UImage; import net.sourceforge.plantuml.ugraphic.UParam; @@ -42,7 +43,7 @@ import net.sourceforge.plantuml.ugraphic.UShape; public class DriverImageG2d implements UDriver { - public void draw(UShape ushape, double x, double y, UParam param, Graphics2D g2d) { + public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, Graphics2D g2d) { final UImage shape = (UImage) ushape; g2d.drawImage(shape.getImage(), (int) x, (int) y, null); } diff --git a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverLineG2d.java b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverLineG2d.java index 73905f00b..8018184c3 100644 --- a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverLineG2d.java +++ b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverLineG2d.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5939 $ + * Revision $Revision: 6576 $ * */ package net.sourceforge.plantuml.ugraphic.g2d; @@ -38,6 +38,7 @@ import java.awt.Graphics2D; import java.awt.Shape; import java.awt.geom.Line2D; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UDriver; import net.sourceforge.plantuml.ugraphic.ULine; import net.sourceforge.plantuml.ugraphic.UParam; @@ -46,12 +47,12 @@ import net.sourceforge.plantuml.ugraphic.UStroke; public class DriverLineG2d implements UDriver { - public void draw(UShape ushape, double x, double y, UParam param, Graphics2D g2d) { + public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, Graphics2D g2d) { final ULine shape = (ULine) ushape; final Shape line = new Line2D.Double(x, y, x + shape.getDX(), y + shape.getDY()); manageStroke(param, g2d); - g2d.setColor(param.getColor()); + g2d.setColor(mapper.getMappedColor(param.getColor())); g2d.draw(line); } diff --git a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverPolygonG2d.java b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverPolygonG2d.java index 24b6a0fd0..10963664e 100644 --- a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverPolygonG2d.java +++ b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverPolygonG2d.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3837 $ + * Revision $Revision: 6576 $ * */ package net.sourceforge.plantuml.ugraphic.g2d; @@ -38,6 +38,7 @@ import java.awt.Graphics2D; import java.awt.Polygon; import java.awt.geom.Point2D; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UDriver; import net.sourceforge.plantuml.ugraphic.UParam; import net.sourceforge.plantuml.ugraphic.UPolygon; @@ -45,7 +46,7 @@ import net.sourceforge.plantuml.ugraphic.UShape; public class DriverPolygonG2d implements UDriver { - public void draw(UShape ushape, double x, double y, UParam param, Graphics2D g2d) { + public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, Graphics2D g2d) { final UPolygon shape = (UPolygon) ushape; final Polygon polygon = new Polygon(); @@ -56,11 +57,11 @@ public class DriverPolygonG2d implements UDriver { } if (param.getBackcolor() != null) { - g2d.setColor(param.getBackcolor()); + g2d.setColor(mapper.getMappedColor(param.getBackcolor())); g2d.fill(polygon); } if (param.getColor() != null) { - g2d.setColor(param.getColor()); + g2d.setColor(mapper.getMappedColor(param.getColor())); g2d.draw(polygon); } } diff --git a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverRectangleG2d.java b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverRectangleG2d.java index e678145e1..fb90c440e 100644 --- a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverRectangleG2d.java +++ b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverRectangleG2d.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6475 $ + * Revision $Revision: 6859 $ * */ package net.sourceforge.plantuml.ugraphic.g2d; @@ -40,6 +40,7 @@ import java.awt.Shape; import java.awt.geom.Rectangle2D; import java.awt.geom.RoundRectangle2D; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UDriver; import net.sourceforge.plantuml.ugraphic.UGradient; import net.sourceforge.plantuml.ugraphic.UParam; @@ -48,7 +49,7 @@ import net.sourceforge.plantuml.ugraphic.UShape; public class DriverRectangleG2d implements UDriver { - public void draw(UShape ushape, double x, double y, UParam param, Graphics2D g2d) { + public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, Graphics2D g2d) { g2d.setStroke(new BasicStroke((float) param.getStroke().getThickness())); final URectangle shape = (URectangle) ushape; final double rx = shape.getRx(); @@ -62,17 +63,19 @@ public class DriverRectangleG2d implements UDriver { final UGradient gr = param.getGradient(); if (gr == null) { if (param.getBackcolor() != null) { - g2d.setColor(param.getBackcolor()); + g2d.setColor(mapper.getMappedColor(param.getBackcolor())); DriverLineG2d.manageStroke(param, g2d); g2d.fill(rect); } if (param.getColor() != null) { - g2d.setColor(param.getColor()); + g2d.setColor(mapper.getMappedColor(param.getColor())); + DriverLineG2d.manageStroke(param, g2d); g2d.draw(rect); } } else { - final GradientPaint paint = new GradientPaint((float) x, (float) y, gr.getColor1(), (float) (x + shape - .getWidth()), (float) (y + shape.getHeight()), gr.getColor2()); + final GradientPaint paint = new GradientPaint((float) x, (float) y, mapper.getMappedColor(gr.getColor1()), + (float) (x + shape.getWidth()), (float) (y + shape.getHeight()), mapper.getMappedColor(gr + .getColor2())); g2d.setPaint(paint); g2d.fill(rect); } diff --git a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverTextG2d.java b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverTextG2d.java index e6e4b5dfe..6e8a37a3d 100644 --- a/src/net/sourceforge/plantuml/ugraphic/g2d/DriverTextG2d.java +++ b/src/net/sourceforge/plantuml/ugraphic/g2d/DriverTextG2d.java @@ -28,14 +28,13 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6000 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.ugraphic.g2d; import java.awt.BasicStroke; import java.awt.Color; -import java.awt.Font; import java.awt.FontMetrics; import java.awt.Graphics2D; import java.awt.GraphicsEnvironment; @@ -46,9 +45,12 @@ import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.Log; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.FontStyle; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounderUtils; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UDriver; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UParam; import net.sourceforge.plantuml.ugraphic.UShape; import net.sourceforge.plantuml.ugraphic.UText; @@ -68,14 +70,14 @@ public class DriverTextG2d implements UDriver { } } - public void draw(UShape ushape, double x, double y, UParam param, Graphics2D g2d) { + public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, Graphics2D g2d) { final UText shape = (UText) ushape; final FontConfiguration fontConfiguration = shape.getFontConfiguration(); - final Font font = fontConfiguration.getFont(); + final UFont font = fontConfiguration.getFont(); if (fontConfiguration.containsStyle(FontStyle.BACKCOLOR)) { final Dimension2D dim = calculateDimension(StringBounderUtils.asStringBounder(g2d), font, shape.getText()); - final Color extended = fontConfiguration.getExtendedColor(); + final Color extended = mapper.getMappedColor(fontConfiguration.getExtendedColor()); if (extended != null) { g2d.setColor(extended); g2d.setBackground(extended); @@ -83,14 +85,14 @@ public class DriverTextG2d implements UDriver { } } - g2d.setFont(font); - g2d.setColor(fontConfiguration.getColor()); + g2d.setFont(font.getFont()); + g2d.setColor(mapper.getMappedColor(fontConfiguration.getColor())); g2d.drawString(shape.getText(), (float) x, (float) y); if (fontConfiguration.containsStyle(FontStyle.UNDERLINE)) { - final Color extended = fontConfiguration.getExtendedColor(); + final HtmlColor extended = fontConfiguration.getExtendedColor(); if (extended != null) { - g2d.setColor(extended); + g2d.setColor(mapper.getMappedColor(extended)); } final Dimension2D dim = calculateDimension(StringBounderUtils.asStringBounder(g2d), font, shape.getText()); final int ypos = (int) (y + 2.5); @@ -101,9 +103,9 @@ public class DriverTextG2d implements UDriver { if (fontConfiguration.containsStyle(FontStyle.WAVE)) { final Dimension2D dim = calculateDimension(StringBounderUtils.asStringBounder(g2d), font, shape.getText()); final int ypos = (int) (y + 2.5) - 1; - final Color extended = fontConfiguration.getExtendedColor(); + final HtmlColor extended = fontConfiguration.getExtendedColor(); if (extended != null) { - g2d.setColor(extended); + g2d.setColor(mapper.getMappedColor(extended)); } for (int i = (int) x; i < x + dim.getWidth() - 5; i += 6) { g2d.drawLine(i, ypos - 0, i + 3, ypos + 1); @@ -112,11 +114,11 @@ public class DriverTextG2d implements UDriver { } if (fontConfiguration.containsStyle(FontStyle.STRIKE)) { final Dimension2D dim = calculateDimension(StringBounderUtils.asStringBounder(g2d), font, shape.getText()); - final FontMetrics fm = g2d.getFontMetrics(font); + final FontMetrics fm = g2d.getFontMetrics(font.getFont()); final int ypos = (int) (y - fm.getDescent() - 0.5); - final Color extended = fontConfiguration.getExtendedColor(); + final HtmlColor extended = fontConfiguration.getExtendedColor(); if (extended != null) { - g2d.setColor(extended); + g2d.setColor(mapper.getMappedColor(extended)); } g2d.setStroke(new BasicStroke((float) 1.5)); g2d.drawLine((int) x, ypos, (int) (x + dim.getWidth()), ypos); @@ -124,7 +126,7 @@ public class DriverTextG2d implements UDriver { } } - static public Dimension2D calculateDimension(StringBounder stringBounder, Font font, String text) { + static public Dimension2D calculateDimension(StringBounder stringBounder, UFont font, String text) { final Dimension2D rect = stringBounder.calculateDimension(font, text); double h = rect.getHeight(); if (h < 10) { diff --git a/src/net/sourceforge/plantuml/ugraphic/g2d/UGraphicG2d.java b/src/net/sourceforge/plantuml/ugraphic/g2d/UGraphicG2d.java index e99cba34d..1b0e61825 100644 --- a/src/net/sourceforge/plantuml/ugraphic/g2d/UGraphicG2d.java +++ b/src/net/sourceforge/plantuml/ugraphic/g2d/UGraphicG2d.java @@ -28,12 +28,11 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6398 $ + * Revision $Revision: 6590 $ * */ package net.sourceforge.plantuml.ugraphic.g2d; -import java.awt.Font; import java.awt.Graphics2D; import java.awt.RenderingHints; import java.awt.Shape; @@ -49,8 +48,10 @@ import net.sourceforge.plantuml.graphic.UnusedSpace; import net.sourceforge.plantuml.posimo.DotPath; import net.sourceforge.plantuml.skin.UDrawable; import net.sourceforge.plantuml.ugraphic.AbstractUGraphic; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UClip; import net.sourceforge.plantuml.ugraphic.UEllipse; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UImage; import net.sourceforge.plantuml.ugraphic.ULine; import net.sourceforge.plantuml.ugraphic.UPolygon; @@ -64,8 +65,8 @@ public class UGraphicG2d extends AbstractUGraphic { private final double dpiFactor; - public UGraphicG2d(Graphics2D g2d, BufferedImage bufferedImage, double dpiFactor) { - super(g2d); + public UGraphicG2d(ColorMapper colorMapper, Graphics2D g2d, BufferedImage bufferedImage, double dpiFactor) { + super(colorMapper, g2d); this.dpiFactor = dpiFactor; if (dpiFactor != 1.0) { final AffineTransform at = g2d.getTransform(); @@ -100,21 +101,21 @@ public class UGraphicG2d extends AbstractUGraphic { } } - public void centerChar(double x, double y, char c, Font font) { + public void centerChar(double x, double y, char c, UFont font) { final UnusedSpace unusedSpace = UnusedSpace.getUnusedSpace(font, c); - getGraphicObject().setColor(getParam().getColor()); + getGraphicObject().setColor(getColorMapper().getMappedColor(getParam().getColor())); final double xpos = x - unusedSpace.getCenterX(); final double ypos = y - unusedSpace.getCenterY() - 0.5; - getGraphicObject().setFont(font); + getGraphicObject().setFont(font.getFont()); getGraphicObject().drawString("" + c, (float) (xpos + getTranslateX()), (float) (ypos + getTranslateY())); // getGraphicObject().drawString("" + c, Math.round(xpos + // getTranslateX()), Math.round(ypos + getTranslateY())); } - static public String getSvgString(UDrawable udrawable) throws IOException { - final UGraphicSvg ug = new UGraphicSvg(false); + static public String getSvgString(ColorMapper colorMapper, UDrawable udrawable) throws IOException { + final UGraphicSvg ug = new UGraphicSvg(colorMapper, false); udrawable.drawU(ug); return CucaDiagramFileMaker.getSvg(ug); } diff --git a/src/net/sourceforge/plantuml/ugraphic/svg/DriverDotPathSvg.java b/src/net/sourceforge/plantuml/ugraphic/svg/DriverDotPathSvg.java new file mode 100644 index 000000000..be51f4890 --- /dev/null +++ b/src/net/sourceforge/plantuml/ugraphic/svg/DriverDotPathSvg.java @@ -0,0 +1,60 @@ +/* ======================================================================== + * 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: 3837 $ + * + */ +package net.sourceforge.plantuml.ugraphic.svg; + +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.posimo.DotPath; +import net.sourceforge.plantuml.svg.SvgGraphics; +import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.ugraphic.UDriver; +import net.sourceforge.plantuml.ugraphic.UParam; +import net.sourceforge.plantuml.ugraphic.UShape; + +public class DriverDotPathSvg implements UDriver { + + public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, SvgGraphics svg) { + final DotPath shape = (DotPath) ushape; + // DriverLineG2d.manageStroke(param, g2d); + + if (param.getColor() != null) { + final String color = param.getColor() == null ? "none" : StringUtils.getAsHtml(mapper.getMappedColor(param + .getColor())); + svg.setStrokeColor(color); + svg.setFillColor(null); + svg.setStrokeWidth("" + param.getStroke().getThickness(), param.getStroke().getDasharraySvg()); + + svg.svgPath(x, y, shape.toUPath()); + } + } +} diff --git a/src/net/sourceforge/plantuml/ugraphic/svg/DriverEllipseSvg.java b/src/net/sourceforge/plantuml/ugraphic/svg/DriverEllipseSvg.java index 047a09b2f..a33e9bb0d 100644 --- a/src/net/sourceforge/plantuml/ugraphic/svg/DriverEllipseSvg.java +++ b/src/net/sourceforge/plantuml/ugraphic/svg/DriverEllipseSvg.java @@ -31,8 +31,9 @@ */ package net.sourceforge.plantuml.ugraphic.svg; -import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.svg.SvgGraphics; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UDriver; import net.sourceforge.plantuml.ugraphic.UEllipse; import net.sourceforge.plantuml.ugraphic.UParam; @@ -40,13 +41,13 @@ import net.sourceforge.plantuml.ugraphic.UShape; public class DriverEllipseSvg implements UDriver { - public void draw(UShape ushape, double x, double y, UParam param, SvgGraphics svg) { + public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, SvgGraphics svg) { final UEllipse rect = (UEllipse) ushape; final double width = rect.getWidth(); final double height = rect.getHeight(); - final String color = param.getColor() == null ? "none" : HtmlColor.getAsHtml(param.getColor()); - final String backcolor = param.getBackcolor() == null ? "none" : HtmlColor.getAsHtml(param.getBackcolor()); + final String color = param.getColor() == null ? "none" : StringUtils.getAsHtml(mapper.getMappedColor(param.getColor())); + final String backcolor = param.getBackcolor() == null ? "none" : StringUtils.getAsHtml(mapper.getMappedColor(param.getBackcolor())); svg.setFillColor(backcolor); svg.setStrokeColor(color); diff --git a/src/net/sourceforge/plantuml/ugraphic/svg/DriverImageSvg.java b/src/net/sourceforge/plantuml/ugraphic/svg/DriverImageSvg.java index e7f965007..ad0539b52 100644 --- a/src/net/sourceforge/plantuml/ugraphic/svg/DriverImageSvg.java +++ b/src/net/sourceforge/plantuml/ugraphic/svg/DriverImageSvg.java @@ -32,13 +32,14 @@ package net.sourceforge.plantuml.ugraphic.svg; import net.sourceforge.plantuml.svg.SvgGraphics; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UDriver; import net.sourceforge.plantuml.ugraphic.UParam; import net.sourceforge.plantuml.ugraphic.UShape; public class DriverImageSvg implements UDriver { - public void draw(UShape ushape, double x, double y, UParam param, SvgGraphics svg) { + public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, SvgGraphics svg) { // Not supported } diff --git a/src/net/sourceforge/plantuml/ugraphic/svg/DriverLineSvg.java b/src/net/sourceforge/plantuml/ugraphic/svg/DriverLineSvg.java index 2fb0c7d7f..c77be2bc0 100644 --- a/src/net/sourceforge/plantuml/ugraphic/svg/DriverLineSvg.java +++ b/src/net/sourceforge/plantuml/ugraphic/svg/DriverLineSvg.java @@ -33,9 +33,10 @@ package net.sourceforge.plantuml.ugraphic.svg; import java.awt.geom.Line2D; -import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.svg.SvgGraphics; import net.sourceforge.plantuml.ugraphic.ClipContainer; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UClip; import net.sourceforge.plantuml.ugraphic.UDriver; import net.sourceforge.plantuml.ugraphic.ULine; @@ -50,7 +51,7 @@ public class DriverLineSvg implements UDriver { this.clipContainer = clipContainer; } - public void draw(UShape ushape, double x, double y, UParam param, SvgGraphics svg) { + public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, SvgGraphics svg) { final ULine shape = (ULine) ushape; double x2 = x + shape.getDX(); @@ -70,7 +71,7 @@ public class DriverLineSvg implements UDriver { // svg.setStroke(new BasicStroke((float) // param.getStroke().getThickness())); - final String color = param.getColor() == null ? "none" : HtmlColor.getAsHtml(param.getColor()); + final String color = param.getColor() == null ? "none" : StringUtils.getAsHtml(mapper.getMappedColor(param.getColor())); svg.setStrokeColor(color); svg.setStrokeWidth("" + param.getStroke().getThickness(), param.getStroke().getDasharraySvg()); svg.svgLine(x, y, x2, y2); diff --git a/src/net/sourceforge/plantuml/ugraphic/svg/DriverPathSvg.java b/src/net/sourceforge/plantuml/ugraphic/svg/DriverPathSvg.java index 62c315c47..8f36f7160 100644 --- a/src/net/sourceforge/plantuml/ugraphic/svg/DriverPathSvg.java +++ b/src/net/sourceforge/plantuml/ugraphic/svg/DriverPathSvg.java @@ -33,6 +33,7 @@ package net.sourceforge.plantuml.ugraphic.svg; import net.sourceforge.plantuml.svg.SvgGraphics; import net.sourceforge.plantuml.ugraphic.ClipContainer; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UDriver; import net.sourceforge.plantuml.ugraphic.UParam; import net.sourceforge.plantuml.ugraphic.UPath; @@ -46,7 +47,7 @@ public class DriverPathSvg implements UDriver { this.clipContainer = clipContainer; } - public void draw(UShape ushape, double x, double y, UParam param, SvgGraphics svg) { + public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, SvgGraphics svg) { final UPath shape = (UPath) ushape; svg.svgPath(x, y, shape); diff --git a/src/net/sourceforge/plantuml/ugraphic/svg/DriverPolygonSvg.java b/src/net/sourceforge/plantuml/ugraphic/svg/DriverPolygonSvg.java index f0b33c507..2ef81ed75 100644 --- a/src/net/sourceforge/plantuml/ugraphic/svg/DriverPolygonSvg.java +++ b/src/net/sourceforge/plantuml/ugraphic/svg/DriverPolygonSvg.java @@ -33,9 +33,10 @@ package net.sourceforge.plantuml.ugraphic.svg; import java.awt.geom.Point2D; -import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.svg.SvgGraphics; import net.sourceforge.plantuml.ugraphic.ClipContainer; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UClip; import net.sourceforge.plantuml.ugraphic.UDriver; import net.sourceforge.plantuml.ugraphic.UParam; @@ -50,7 +51,7 @@ public class DriverPolygonSvg implements UDriver { this.clipContainer = clipContainer; } - public void draw(UShape ushape, double x, double y, UParam param, SvgGraphics svg) { + public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, SvgGraphics svg) { final UPolygon shape = (UPolygon) ushape; final double points[] = new double[shape.getPoints().size() * 2]; @@ -71,8 +72,8 @@ public class DriverPolygonSvg implements UDriver { } } - final String color = param.getColor() == null ? "none" : HtmlColor.getAsHtml(param.getColor()); - final String backcolor = param.getBackcolor() == null ? "none" : HtmlColor.getAsHtml(param.getBackcolor()); + final String color = param.getColor() == null ? "none" : StringUtils.getAsHtml(mapper.getMappedColor(param.getColor())); + final String backcolor = param.getBackcolor() == null ? "none" : StringUtils.getAsHtml(mapper.getMappedColor(param.getBackcolor())); svg.setFillColor(backcolor); svg.setStrokeColor(color); diff --git a/src/net/sourceforge/plantuml/ugraphic/svg/DriverRectangleSvg.java b/src/net/sourceforge/plantuml/ugraphic/svg/DriverRectangleSvg.java index 2b936cf72..24c701fea 100644 --- a/src/net/sourceforge/plantuml/ugraphic/svg/DriverRectangleSvg.java +++ b/src/net/sourceforge/plantuml/ugraphic/svg/DriverRectangleSvg.java @@ -33,9 +33,10 @@ package net.sourceforge.plantuml.ugraphic.svg; import java.awt.geom.Rectangle2D; -import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.svg.SvgGraphics; import net.sourceforge.plantuml.ugraphic.ClipContainer; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UClip; import net.sourceforge.plantuml.ugraphic.UDriver; import net.sourceforge.plantuml.ugraphic.UGradient; @@ -51,7 +52,7 @@ public class DriverRectangleSvg implements UDriver { this.clipContainer = clipContainer; } - public void draw(UShape ushape, double x, double y, UParam param, SvgGraphics svg) { + public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, SvgGraphics svg) { final URectangle rect = (URectangle) ushape; final double rx = rect.getRx(); @@ -61,13 +62,15 @@ public class DriverRectangleSvg implements UDriver { final UGradient gr = param.getGradient(); if (gr == null) { - final String color = param.getColor() == null ? "none" : HtmlColor.getAsHtml(param.getColor()); - final String backcolor = param.getBackcolor() == null ? "none" : HtmlColor.getAsHtml(param.getBackcolor()); + final String color = param.getColor() == null ? "none" : StringUtils.getAsHtml(mapper.getMappedColor(param + .getColor())); + final String backcolor = param.getBackcolor() == null ? "none" : StringUtils.getAsHtml(mapper + .getMappedColor(param.getBackcolor())); svg.setFillColor(backcolor); svg.setStrokeColor(color); } else { - final String id = svg.createSvgGradient(HtmlColor.getAsHtml(gr.getColor1()), HtmlColor.getAsHtml(gr - .getColor2())); + final String id = svg.createSvgGradient(StringUtils.getAsHtml(mapper.getMappedColor(gr.getColor1())), + StringUtils.getAsHtml(mapper.getMappedColor(gr.getColor2()))); svg.setFillColor("url(#" + id + ")"); svg.setStrokeColor(null); } diff --git a/src/net/sourceforge/plantuml/ugraphic/svg/DriverTextAsPathSvg.java b/src/net/sourceforge/plantuml/ugraphic/svg/DriverTextAsPathSvg.java index 7ab91ac70..32f665254 100644 --- a/src/net/sourceforge/plantuml/ugraphic/svg/DriverTextAsPathSvg.java +++ b/src/net/sourceforge/plantuml/ugraphic/svg/DriverTextAsPathSvg.java @@ -31,7 +31,6 @@ */ package net.sourceforge.plantuml.ugraphic.svg; -import java.awt.Font; import java.awt.font.FontRenderContext; import java.awt.font.TextLayout; import java.awt.geom.PathIterator; @@ -39,8 +38,10 @@ import java.awt.geom.PathIterator; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.svg.SvgGraphics; import net.sourceforge.plantuml.ugraphic.ClipContainer; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UClip; import net.sourceforge.plantuml.ugraphic.UDriver; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UParam; import net.sourceforge.plantuml.ugraphic.UShape; import net.sourceforge.plantuml.ugraphic.UText; @@ -55,7 +56,7 @@ public class DriverTextAsPathSvg implements UDriver { this.clipContainer = clipContainer; } - public void draw(UShape ushape, double x, double y, UParam param, SvgGraphics svg) { + public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, SvgGraphics svg) { final UClip clip = clipContainer.getClip(); if (clip != null && clip.isInside(x, y) == false) { @@ -64,9 +65,9 @@ public class DriverTextAsPathSvg implements UDriver { final UText shape = (UText) ushape; final FontConfiguration fontConfiguration = shape.getFontConfiguration(); - final Font font = fontConfiguration.getFont(); + final UFont font = fontConfiguration.getFont(); - final TextLayout t = new TextLayout(shape.getText(), font, fontRenderContext); + final TextLayout t = new TextLayout(shape.getText(), font.getFont(), fontRenderContext); drawPathIterator(svg, x, y, t.getOutline(null).getPathIterator(null)); } diff --git a/src/net/sourceforge/plantuml/ugraphic/svg/DriverTextSvg.java b/src/net/sourceforge/plantuml/ugraphic/svg/DriverTextSvg.java index 01ec9e8d7..41693389b 100644 --- a/src/net/sourceforge/plantuml/ugraphic/svg/DriverTextSvg.java +++ b/src/net/sourceforge/plantuml/ugraphic/svg/DriverTextSvg.java @@ -31,17 +31,19 @@ */ package net.sourceforge.plantuml.ugraphic.svg; -import java.awt.Font; import java.awt.geom.Dimension2D; +import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.FontStyle; -import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.svg.SvgGraphics; import net.sourceforge.plantuml.ugraphic.ClipContainer; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UClip; import net.sourceforge.plantuml.ugraphic.UDriver; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UFontContext; import net.sourceforge.plantuml.ugraphic.UParam; import net.sourceforge.plantuml.ugraphic.UShape; import net.sourceforge.plantuml.ugraphic.UText; @@ -56,7 +58,7 @@ public class DriverTextSvg implements UDriver { this.clipContainer = clipContainer; } - public void draw(UShape ushape, double x, double y, UParam param, SvgGraphics svg) { + public void draw(UShape ushape, double x, double y, ColorMapper mapper, UParam param, SvgGraphics svg) { final UClip clip = clipContainer.getClip(); if (clip != null && clip.isInside(x, y) == false) { @@ -65,7 +67,7 @@ public class DriverTextSvg implements UDriver { final UText shape = (UText) ushape; final FontConfiguration fontConfiguration = shape.getFontConfiguration(); - final Font font = fontConfiguration.getFont(); + final UFont font = fontConfiguration.getFont(); String fontWeight = null; if (fontConfiguration.containsStyle(FontStyle.BOLD) || font.isBold()) { fontWeight = "bold"; @@ -81,7 +83,7 @@ public class DriverTextSvg implements UDriver { textDecoration = "line-through"; } - svg.setFillColor(HtmlColor.getAsHtml(fontConfiguration.getColor())); + svg.setFillColor(StringUtils.getAsHtml(mapper.getMappedColor(fontConfiguration.getColor()))); String text = shape.getText(); if (text.startsWith(" ")) { final double space = stringBounder.calculateDimension(font, " ").getWidth(); @@ -92,6 +94,6 @@ public class DriverTextSvg implements UDriver { } text = text.trim(); final Dimension2D dim = stringBounder.calculateDimension(font, text); - svg.text(text, x, y, font.getFamily(), font.getSize(), fontWeight, fontStyle, textDecoration, dim.getWidth()); + svg.text(text, x, y, font.getFamily(UFontContext.SVG), font.getSize(), fontWeight, fontStyle, textDecoration, dim.getWidth()); } } diff --git a/src/net/sourceforge/plantuml/ugraphic/svg/UGraphicSvg.java b/src/net/sourceforge/plantuml/ugraphic/svg/UGraphicSvg.java index 35c235a4c..0545d35da 100644 --- a/src/net/sourceforge/plantuml/ugraphic/svg/UGraphicSvg.java +++ b/src/net/sourceforge/plantuml/ugraphic/svg/UGraphicSvg.java @@ -31,7 +31,6 @@ */ package net.sourceforge.plantuml.ugraphic.svg; -import java.awt.Font; import java.awt.Graphics2D; import java.awt.font.TextLayout; import java.awt.image.BufferedImage; @@ -40,16 +39,18 @@ import java.io.OutputStream; import javax.xml.transform.TransformerException; -import net.sourceforge.plantuml.graphic.FontConfiguration; -import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounderUtils; import net.sourceforge.plantuml.graphic.UnusedSpace; +import net.sourceforge.plantuml.posimo.DotPath; import net.sourceforge.plantuml.svg.SvgGraphics; import net.sourceforge.plantuml.ugraphic.AbstractUGraphic; import net.sourceforge.plantuml.ugraphic.ClipContainer; +import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UClip; import net.sourceforge.plantuml.ugraphic.UEllipse; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UImage; import net.sourceforge.plantuml.ugraphic.ULine; import net.sourceforge.plantuml.ugraphic.UPath; @@ -64,16 +65,16 @@ public class UGraphicSvg extends AbstractUGraphic implements ClipCo private final StringBounder stringBounder; - public UGraphicSvg(String backcolor, boolean textAsPath) { - this(new SvgGraphics(backcolor), textAsPath); + public UGraphicSvg(ColorMapper colorMapper, String backcolor, boolean textAsPath) { + this(colorMapper, new SvgGraphics(backcolor), textAsPath); } - public UGraphicSvg(boolean textAsPath) { - this(new SvgGraphics(), textAsPath); + public UGraphicSvg(ColorMapper colorMapper, boolean textAsPath) { + this(colorMapper, new SvgGraphics(), textAsPath); } - private UGraphicSvg(SvgGraphics svg, boolean textAsPath) { - super(svg); + private UGraphicSvg(ColorMapper colorMapper, SvgGraphics svg, boolean textAsPath) { + super(colorMapper, svg); stringBounder = StringBounderUtils.asStringBounder(imDummy); registerDriver(URectangle.class, new DriverRectangleSvg(this)); textAsPath = false; @@ -87,6 +88,7 @@ public class UGraphicSvg extends AbstractUGraphic implements ClipCo registerDriver(UEllipse.class, new DriverEllipseSvg()); registerDriver(UImage.class, new DriverImageSvg()); registerDriver(UPath.class, new DriverPathSvg(this)); + registerDriver(DotPath.class, new DriverDotPathSvg()); } public SvgGraphics getSvgGraphics() { @@ -113,20 +115,20 @@ public class UGraphicSvg extends AbstractUGraphic implements ClipCo return clip; } - public void centerCharOld(double x, double y, char c, Font font) { - final UText uText = new UText("" + c, new FontConfiguration(font, getParam().getColor())); - final UnusedSpace unusedSpace = UnusedSpace.getUnusedSpace(font, c); - draw(x - unusedSpace.getCenterX() + getTranslateX(), y - unusedSpace.getCenterY() + getTranslateY(), uText); - } +// public void centerCharOld(double x, double y, char c, Font font) { +// final UText uText = new UText("" + c, new FontConfiguration(font, getParam().getColor())); +// final UnusedSpace unusedSpace = UnusedSpace.getUnusedSpace(font, c); +// draw(x - unusedSpace.getCenterX() + getTranslateX(), y - unusedSpace.getCenterY() + getTranslateY(), uText); +// } - public void centerChar(double x, double y, char c, Font font) { + public void centerChar(double x, double y, char c, UFont font) { final UnusedSpace unusedSpace = UnusedSpace.getUnusedSpace(font, c); final double xpos = x - unusedSpace.getCenterX() - 0.5; final double ypos = y - unusedSpace.getCenterY() - 0.5; - final TextLayout t = new TextLayout("" + c, font, imDummy.getFontRenderContext()); - getGraphicObject().setStrokeColor(HtmlColor.getAsHtml(getParam().getColor())); + final TextLayout t = new TextLayout("" + c, font.getFont(), imDummy.getFontRenderContext()); + getGraphicObject().setStrokeColor(StringUtils.getAsHtml(getColorMapper().getMappedColor(getParam().getColor()))); DriverTextAsPathSvg.drawPathIterator(getGraphicObject(), xpos + getTranslateX(), ypos + getTranslateY(), t .getOutline(null).getPathIterator(null)); } diff --git a/src/net/sourceforge/plantuml/ugraphic/txt/UGraphicTxt.java b/src/net/sourceforge/plantuml/ugraphic/txt/UGraphicTxt.java index aeddf6d87..d11f3a68d 100644 --- a/src/net/sourceforge/plantuml/ugraphic/txt/UGraphicTxt.java +++ b/src/net/sourceforge/plantuml/ugraphic/txt/UGraphicTxt.java @@ -31,8 +31,6 @@ */ package net.sourceforge.plantuml.ugraphic.txt; -import java.awt.Font; - import net.sourceforge.plantuml.asciiart.TextStringBounder; import net.sourceforge.plantuml.asciiart.TranslatedCharArea; import net.sourceforge.plantuml.asciiart.UmlCharArea; @@ -40,7 +38,9 @@ import net.sourceforge.plantuml.asciiart.UmlCharAreaImpl; import net.sourceforge.plantuml.graphic.FontStyle; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.ugraphic.AbstractCommonUGraphic; +import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity; import net.sourceforge.plantuml.ugraphic.UClip; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UShape; import net.sourceforge.plantuml.ugraphic.UText; @@ -49,6 +49,10 @@ public class UGraphicTxt extends AbstractCommonUGraphic { private final UmlCharArea charArea = new UmlCharAreaImpl(); private int lastPrint = 0; + public UGraphicTxt() { + super(new ColorMapperIdentity()); + } + public StringBounder getStringBounder() { return new TextStringBounder(); } @@ -71,7 +75,7 @@ public class UGraphicTxt extends AbstractCommonUGraphic { // throw new UnsupportedOperationException(); } - public void centerChar(double x, double y, char c, Font font) { + public void centerChar(double x, double y, char c, UFont font) { throw new UnsupportedOperationException(); } diff --git a/src/net/sourceforge/plantuml/usecasediagram/command/CommandCreateActor.java b/src/net/sourceforge/plantuml/usecasediagram/command/CommandCreateActor.java index be8cc7391..fa01159dc 100644 --- a/src/net/sourceforge/plantuml/usecasediagram/command/CommandCreateActor.java +++ b/src/net/sourceforge/plantuml/usecasediagram/command/CommandCreateActor.java @@ -69,7 +69,7 @@ public class CommandCreateActor extends SingleLineCommand { code = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(1)); } final Entity entity = (Entity) getSystem().getOrCreateClass(code); - entity.setDisplay(display); + entity.setDisplay2(display); final String stereotype = arg.get(2); if (stereotype != null) { diff --git a/src/net/sourceforge/plantuml/usecasediagram/command/CommandCreateActor2.java b/src/net/sourceforge/plantuml/usecasediagram/command/CommandCreateActor2.java index ecb2167b0..1c8a3f112 100644 --- a/src/net/sourceforge/plantuml/usecasediagram/command/CommandCreateActor2.java +++ b/src/net/sourceforge/plantuml/usecasediagram/command/CommandCreateActor2.java @@ -63,7 +63,7 @@ public class CommandCreateActor2 extends SingleLineCommand { final String display = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(1)); final String stereotype = arg.get(2); final Entity entity = (Entity) getSystem().getOrCreateClass(code); - entity.setDisplay(display); + entity.setDisplay2(display); if (stereotype != null) { entity.setStereotype(new Stereotype(stereotype, getSystem().getSkinParam().getCircledCharacterRadius(), diff --git a/src/net/sourceforge/plantuml/usecasediagram/command/CommandCreateUsecase.java b/src/net/sourceforge/plantuml/usecasediagram/command/CommandCreateUsecase.java index aa84b5053..d44fa05a9 100644 --- a/src/net/sourceforge/plantuml/usecasediagram/command/CommandCreateUsecase.java +++ b/src/net/sourceforge/plantuml/usecasediagram/command/CommandCreateUsecase.java @@ -73,7 +73,7 @@ public class CommandCreateUsecase extends SingleLineCommand { 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(), getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null))); diff --git a/src/net/sourceforge/plantuml/usecasediagram/command/CommandCreateUsecase2.java b/src/net/sourceforge/plantuml/usecasediagram/command/CommandCreateUsecase2.java index 047f56c2b..3241c3403 100644 --- a/src/net/sourceforge/plantuml/usecasediagram/command/CommandCreateUsecase2.java +++ b/src/net/sourceforge/plantuml/usecasediagram/command/CommandCreateUsecase2.java @@ -65,7 +65,7 @@ public class CommandCreateUsecase2 extends SingleLineCommand { 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(), getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null))); diff --git a/src/net/sourceforge/plantuml/usecasediagram/command/CommandLinkUsecase2.java b/src/net/sourceforge/plantuml/usecasediagram/command/CommandLinkUsecase2.java index 1c8a592a2..2667dbaf5 100644 --- a/src/net/sourceforge/plantuml/usecasediagram/command/CommandLinkUsecase2.java +++ b/src/net/sourceforge/plantuml/usecasediagram/command/CommandLinkUsecase2.java @@ -61,8 +61,8 @@ public class CommandLinkUsecase2 extends SingleLineCommand2 { getGroup("ENT1"), new RegexLeaf("\\s*"), new RegexOr( - new RegexLeaf("LEFT_TO_RIGHT", "(([-=.]+)(?:(left|right|up|down|le?|ri?|up?|do?)(?=[-=.]))?([-=.]*)([\\]>]|\\|[>\\]])?)"), - new RegexLeaf("RIGHT_TO_LEFT", "(([\\[<]|[<\\[]\\|)?([-=.]*)(left|right|up|down|le?|ri?|up?|do?)?([-=.]+))")), + new RegexLeaf("LEFT_TO_RIGHT", "(([-=.]+)(?:(left|right|up|down|le?|ri?|up?|do?)(?=[-=.]))?([-=.]*)([\\]>^]|\\|[>\\]])?)"), + new RegexLeaf("RIGHT_TO_LEFT", "(([\\[<^]|[<\\[]\\|)?([-=.]*)(left|right|up|down|le?|ri?|up?|do?)?([-=.]+))")), new RegexLeaf("\\s*"), getGroup("ENT2"), new RegexLeaf("\\s*"), @@ -208,6 +208,9 @@ public class CommandLinkUsecase2 extends SingleLineCommand2 { if (k.equals("<|") || k.equals("|>")) { return new LinkType(LinkDecor.EXTENDS, LinkDecor.NONE); } + if (k.equals("^")) { + return new LinkType(LinkDecor.EXTENDS, LinkDecor.NONE); + } return null; } diff --git a/src/net/sourceforge/plantuml/version/PSystemVersion.java b/src/net/sourceforge/plantuml/version/PSystemVersion.java index 05b4be44b..2cfdbf087 100644 --- a/src/net/sourceforge/plantuml/version/PSystemVersion.java +++ b/src/net/sourceforge/plantuml/version/PSystemVersion.java @@ -31,7 +31,6 @@ */ package net.sourceforge.plantuml.version; -import java.awt.Color; import java.awt.Font; import java.awt.image.BufferedImage; import java.io.IOException; @@ -49,6 +48,8 @@ import net.sourceforge.plantuml.FileFormatOption; import net.sourceforge.plantuml.cucadiagram.dot.GraphvizUtils; import net.sourceforge.plantuml.graphic.GraphicPosition; import net.sourceforge.plantuml.graphic.GraphicStrings; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.ugraphic.UFont; public class PSystemVersion extends AbstractPSystem { @@ -66,21 +67,8 @@ public class PSystemVersion extends AbstractPSystem { } } -// public List createFiles(File suggestedFile, FileFormatOption fileFormat) throws IOException, -// InterruptedException { -// OutputStream os = null; -// try { -// os = new FileOutputStream(suggestedFile); -// getGraphicStrings().writeImage(os, 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 { getGraphicStrings().writeImage(os, fileFormat); } @@ -96,6 +84,7 @@ public class PSystemVersion extends AbstractPSystem { strings.add(p.getProperty("java.vm.name")); strings.add(p.getProperty("java.runtime.version")); strings.add(p.getProperty("os.name")); + strings.add("Processors: " + Runtime.getRuntime().availableProcessors()); return new PSystemVersion(true, strings); } @@ -122,9 +111,9 @@ public class PSystemVersion extends AbstractPSystem { } private GraphicStrings getGraphicStrings() throws IOException { - final Font font = new Font("SansSerif", Font.PLAIN, 12); - return new GraphicStrings(strings, font, Color.BLACK, Color.WHITE, image, GraphicPosition.BACKGROUND_CORNER, - false); + final UFont font = new UFont("SansSerif", Font.PLAIN, 12); + return new GraphicStrings(strings, font, HtmlColor.BLACK, HtmlColor.WHITE, image, + GraphicPosition.BACKGROUND_CORNER, false); // return new GraphicStrings(strings, font, Color.BLACK, Color.WHITE, // false); } diff --git a/src/net/sourceforge/plantuml/version/PSystemVersionFactory.java b/src/net/sourceforge/plantuml/version/PSystemVersionFactory.java index b92d3d86c..85ea6b395 100644 --- a/src/net/sourceforge/plantuml/version/PSystemVersionFactory.java +++ b/src/net/sourceforge/plantuml/version/PSystemVersionFactory.java @@ -41,11 +41,7 @@ public class PSystemVersionFactory implements PSystemBasicFactory { private PSystemVersion system; - public PSystemVersionFactory() { - reset(); - } - - public void reset() { + public void init(String startLine) { } public boolean executeLine(String line) { diff --git a/src/net/sourceforge/plantuml/version/Version.java b/src/net/sourceforge/plantuml/version/Version.java index d930ce73a..fd57597e8 100644 --- a/src/net/sourceforge/plantuml/version/Version.java +++ b/src/net/sourceforge/plantuml/version/Version.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6488 $ + * Revision $Revision: 6940 $ * */ package net.sourceforge.plantuml.version; @@ -36,11 +36,11 @@ package net.sourceforge.plantuml.version; public class Version { public static int version() { - return 6487; + return 6939; } public static long compileTime() { - return 1303229639640L; + return 1312823992421L; } } diff --git a/src/net/sourceforge/plantuml/xmi/XmiClassDiagram.java b/src/net/sourceforge/plantuml/xmi/XmiClassDiagram.java index 3d026f3e5..5da50fd5f 100644 --- a/src/net/sourceforge/plantuml/xmi/XmiClassDiagram.java +++ b/src/net/sourceforge/plantuml/xmi/XmiClassDiagram.java @@ -189,7 +189,7 @@ public class XmiClassDiagram { final Element cla = document.createElement("UML:Class"); cla.setAttribute("xmi.id", entity.getUid()); - cla.setAttribute("name", entity.getDisplay()); + cla.setAttribute("name", entity.getDisplay2().get(0).toString()); cla.setAttribute("namespace", "model1"); final Element feature = document.createElement("UML:Classifier.feature"); diff --git a/src/org/stathissideris/ascii2image/core/ConversionOptions.java b/src/org/stathissideris/ascii2image/core/ConversionOptions.java index 0a59ca641..922c26da4 100644 --- a/src/org/stathissideris/ascii2image/core/ConversionOptions.java +++ b/src/org/stathissideris/ascii2image/core/ConversionOptions.java @@ -27,13 +27,13 @@ package org.stathissideris.ascii2image.core; */ public class ConversionOptions { - public ProcessingOptions processingOptions = - new ProcessingOptions(); +// public ProcessingOptions processingOptions = +// new ProcessingOptions(); public RenderingOptions renderingOptions = new RenderingOptions(); public void setDebug(boolean value){ - processingOptions.setPrintDebugOutput(value); + // processingOptions.setPrintDebugOutput(value); renderingOptions.setRenderDebugLines(value); } diff --git a/src/org/stathissideris/ascii2image/graphics/BitmapRenderer.java b/src/org/stathissideris/ascii2image/graphics/BitmapRenderer.java index 5fee87a03..c2d1d0c70 100644 --- a/src/org/stathissideris/ascii2image/graphics/BitmapRenderer.java +++ b/src/org/stathissideris/ascii2image/graphics/BitmapRenderer.java @@ -61,28 +61,28 @@ public class BitmapRenderer { Stroke normalStroke; Stroke dashStroke; - public static void main(String[] args) throws Exception { - - - long startTime = System.currentTimeMillis(); - - ConversionOptions options = new ConversionOptions(); - - TextGrid grid = new TextGrid(); - - String filename = "dak_orgstruktur_vs_be.ditaa.OutOfMemoryError.edit.txt"; - - grid.loadFrom("tests/text/"+filename); - - Diagram diagram = new Diagram(grid, options); - new BitmapRenderer().renderToPNG(diagram, "tests/images/"+filename+".png", options.renderingOptions); - long endTime = System.currentTimeMillis(); - long totalTime = (endTime - startTime) / 1000; - System.out.println("Done in "+totalTime+"sec"); - - File workDir = new File("tests/images"); - //Process p = Runtime.getRuntime().exec("display "+filename+".png", null, workDir); - } +// public static void main(String[] args) throws Exception { +// +// +// long startTime = System.currentTimeMillis(); +// +// ConversionOptions options = new ConversionOptions(); +// +// TextGrid grid = new TextGrid(); +// +// String filename = "dak_orgstruktur_vs_be.ditaa.OutOfMemoryError.edit.txt"; +// +// grid.loadFrom("tests/text/"+filename); +// +// Diagram diagram = new Diagram(grid, options); +// new BitmapRenderer().renderToPNG(diagram, "tests/images/"+filename+".png", options.renderingOptions); +// long endTime = System.currentTimeMillis(); +// long totalTime = (endTime - startTime) / 1000; +// System.out.println("Done in "+totalTime+"sec"); +// +// File workDir = new File("tests/images"); +// //Process p = Runtime.getRuntime().exec("display "+filename+".png", null, workDir); +// } private boolean renderToPNG(Diagram diagram, String filename, RenderingOptions options){ RenderedImage image = renderToImage(diagram, options); diff --git a/src/org/stathissideris/ascii2image/graphics/Diagram.java b/src/org/stathissideris/ascii2image/graphics/Diagram.java index 5db33abaf..c41af73b2 100644 --- a/src/org/stathissideris/ascii2image/graphics/Diagram.java +++ b/src/org/stathissideris/ascii2image/graphics/Diagram.java @@ -27,6 +27,7 @@ import java.util.Iterator; import org.stathissideris.ascii2image.core.ConversionOptions; import org.stathissideris.ascii2image.core.Pair; +import org.stathissideris.ascii2image.core.ProcessingOptions; import org.stathissideris.ascii2image.text.AbstractionGrid; import org.stathissideris.ascii2image.text.CellSet; import org.stathissideris.ascii2image.text.TextGrid; @@ -105,7 +106,7 @@ public class Diagram { * @param cellWidth * @param cellHeight */ - public Diagram(TextGrid grid, ConversionOptions options) { + public Diagram(TextGrid grid, ConversionOptions options, ProcessingOptions processingOptions) { this.cellWidth = options.renderingOptions.getCellWidth(); this.cellHeight = options.renderingOptions.getCellHeight(); @@ -311,7 +312,7 @@ public class Diagram { boolean removedAnyObsolete = removeObsoleteShapes(workGrid, closed); boolean allCornersRound = false; - if(options.processingOptions.areAllCornersRound()) allCornersRound = true; + if(processingOptions.areAllCornersRound()) allCornersRound = true; //make shapes from the boundary sets //make closed shapes @@ -329,7 +330,7 @@ public class Diagram { } } - if(options.processingOptions.performSeparationOfCommonEdges()) + if(processingOptions.performSeparationOfCommonEdges()) separateCommonEdges(closedShapes); //make open shapes @@ -412,7 +413,7 @@ public class Diagram { //TODO: the code below could be a lot more concise if(pair.tag.equals("d")){ CustomShapeDefinition def = - options.processingOptions.getFromCustomShapes("d"); + processingOptions.getFromCustomShapes("d"); if(def == null) containingShape.setType(DiagramShape.TYPE_DOCUMENT); else { @@ -421,7 +422,7 @@ public class Diagram { } } else if(pair.tag.equals("s")){ CustomShapeDefinition def = - options.processingOptions.getFromCustomShapes("s"); + processingOptions.getFromCustomShapes("s"); if(def == null) containingShape.setType(DiagramShape.TYPE_STORAGE); else { @@ -430,7 +431,7 @@ public class Diagram { } } else if(pair.tag.equals("io")){ CustomShapeDefinition def = - options.processingOptions.getFromCustomShapes("io"); + processingOptions.getFromCustomShapes("io"); if(def == null) containingShape.setType(DiagramShape.TYPE_IO); else { @@ -439,7 +440,7 @@ public class Diagram { } } else if(pair.tag.equals("c")){ CustomShapeDefinition def = - options.processingOptions.getFromCustomShapes("c"); + processingOptions.getFromCustomShapes("c"); if(def == null) containingShape.setType(DiagramShape.TYPE_DECISION); else { @@ -448,7 +449,7 @@ public class Diagram { } } else if(pair.tag.equals("mo")){ CustomShapeDefinition def = - options.processingOptions.getFromCustomShapes("mo"); + processingOptions.getFromCustomShapes("mo"); if(def == null) containingShape.setType(DiagramShape.TYPE_MANUAL_OPERATION); else { @@ -457,7 +458,7 @@ public class Diagram { } } else if(pair.tag.equals("tr")){ CustomShapeDefinition def = - options.processingOptions.getFromCustomShapes("tr"); + processingOptions.getFromCustomShapes("tr"); if(def == null) containingShape.setType(DiagramShape.TYPE_TRAPEZOID); else { @@ -466,7 +467,7 @@ public class Diagram { } } else if(pair.tag.equals("o")){ CustomShapeDefinition def = - options.processingOptions.getFromCustomShapes("o"); + processingOptions.getFromCustomShapes("o"); if(def == null) containingShape.setType(DiagramShape.TYPE_ELLIPSE); else { @@ -475,7 +476,7 @@ public class Diagram { } } else { CustomShapeDefinition def = - options.processingOptions.getFromCustomShapes(pair.tag); + processingOptions.getFromCustomShapes(pair.tag); containingShape.setType(DiagramShape.TYPE_CUSTOM); containingShape.setDefinition(def); }