1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-11-24 22:07:33 +00:00

Commit of version 5878

This commit is contained in:
Arnaud Roques 2011-01-05 19:23:06 +01:00
parent 543e0271f4
commit 9005abef50
185 changed files with 3767 additions and 3805 deletions

View File

@ -40,7 +40,7 @@ import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class BlockUml {
public class BlockUml {
private final List<String> data;
private PSystem system;
@ -52,7 +52,7 @@ class BlockUml {
}
BlockUml(List<String> strings) {
final String s0 = strings.get(0);
final String s0 = strings.get(0).trim();
if (s0.startsWith("@startuml") == false) {
throw new IllegalArgumentException();
}
@ -63,7 +63,7 @@ class BlockUml {
if (OptionFlags.getInstance().isWord()) {
return null;
}
final Matcher m = pattern1.matcher(data.get(0));
final Matcher m = pattern1.matcher(data.get(0).trim());
final boolean ok = m.find();
if (ok == false) {
return null;

View File

@ -60,16 +60,19 @@ final public class BlockUmlBuilder {
}
}
private boolean isArobaseEnduml(final String s) {
static boolean isArobaseEnduml(String s) {
s = s.trim();
return s.equals("@enduml") || s.startsWith("@enduml ");
}
private boolean isIgnoredLine(final String s) {
// return s.length() == 0 || s.startsWith("#") || s.startsWith("'");
return s.length() == 0 || s.startsWith("'");
// return s.length() == 0 || s.startsWith("'");
return s.startsWith("'");
}
private boolean isArobaseStartuml(final String s) {
static boolean isArobaseStartuml(String s) {
s = s.trim();
return s.equals("@startuml") || s.startsWith("@startuml ");
}
@ -80,7 +83,7 @@ final public class BlockUmlBuilder {
if (isArobaseStartuml(s)) {
current = new ArrayList<String>();
}
if (current != null && isIgnoredLine(s) == false) {
if (current != null && isIgnoredLine(s.trim()) == false) {
current.add(s);
}
if (isArobaseEnduml(s) && current != null) {

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5218 $
* Revision $Revision: 5823 $
*
*/
package net.sourceforge.plantuml;
@ -44,8 +44,8 @@ public enum ColorParam {
activityBar,
activityArrow,
actorBackground,
actorBorder,
usecaseActorBackground,
usecaseActorBorder,
usecaseBorder,
usecaseBackground,
usecaseArrow,
@ -67,13 +67,15 @@ public enum ColorParam {
componentBackground,
componentBorder,
interfaceBackground,
interfaceBorder,
componentInterfaceBackground,
componentInterfaceBorder,
componentArrow,
stateBackground,
stateBorder,
stateArrow,
stateStart,
stateEnd,
noteBackground(true),
noteBorder,

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5229 $
* Revision $Revision: 5794 $
*
*/
package net.sourceforge.plantuml;
@ -77,7 +77,7 @@ public class DirWatcher {
if (previousModified == null || previousModified.longValue() != modified) {
final SourceFileReader sourceFileReader = new SourceFileReader(new Defines(), f, option.getOutputDir(),
option.getConfig(), option.getCharset(), option.getFileFormat());
option.getConfig(), option.getCharset(), option.getFileFormatOption());
for (GeneratedImage g : sourceFileReader.getGeneratedImages()) {
result.add(g);
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5579 $
* Revision $Revision: 5810 $
*
*/
package net.sourceforge.plantuml;
@ -36,6 +36,7 @@ package net.sourceforge.plantuml;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
public class EmptyImageBuilder {
@ -43,6 +44,10 @@ public class EmptyImageBuilder {
private final BufferedImage im;
private final Graphics2D g2d;
public EmptyImageBuilder(double width, double height, Color background) {
this((int) width, (int) height, background);
}
public EmptyImageBuilder(int width, int height, Color background) {
Log.info("Creating image " + width + "x" + height);
im = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
@ -52,6 +57,13 @@ public class EmptyImageBuilder {
g2d.fillRect(0, 0, width, height);
}
public EmptyImageBuilder(int width, int height, Color background, double dpiFactor) {
this(width * dpiFactor, height * dpiFactor, background);
if (dpiFactor != 1.0) {
g2d.setTransform(AffineTransform.getScaleInstance(dpiFactor, dpiFactor));
}
}
public BufferedImage getBufferedImage() {
return im;
}

View File

@ -28,19 +28,22 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5333 $
* Revision $Revision: 5877 $
*
*/
package net.sourceforge.plantuml;
public enum FileFormat {
PNG, SVG, EPS, EPS_VIA_SVG, ATXT, UTXT;
PNG, SVG, EPS, EPS_VIA_SVG, ATXT, UTXT, XMI_STANDARD, XMI_STAR, XMI_ARGO;
public String getFileSuffix() {
if (this == EPS_VIA_SVG) {
throw new UnsupportedOperationException("Not used anymore");
// return EPS.getFileSuffix();
}
if (name().startsWith("XMI")) {
return ".XMI";
}
return "." + name().toLowerCase();
}
}

View File

@ -0,0 +1,64 @@
/* ========================================================================
* 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: 5333 $
*
*/
package net.sourceforge.plantuml;
public class FileFormatOption {
private final FileFormat fileFormat;
private final int dpi;
public FileFormatOption(FileFormat fileFormat, int dpi) {
this.fileFormat = fileFormat;
this.dpi = dpi;
}
public FileFormatOption(FileFormat fileFormat) {
this(fileFormat, 96);
}
public final FileFormat getFileFormat() {
return fileFormat;
}
// public final int getDpi() {
// return dpi;
// }
//
// public double getDpiFactor() {
// if (dpi == 96) {
// return 1.0;
// }
// return dpi / 96.0;
// }
}

View File

@ -0,0 +1,97 @@
/* ========================================================================
* 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: 5749 $
*
*/
package net.sourceforge.plantuml;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import net.sourceforge.plantuml.cucadiagram.dot.DrawFile;
public class FileUtils {
private static final Collection<DrawFile> toDelete = new ArrayList<DrawFile>();
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 File getTmpDir() {
final File tmpDir = new File(System.getProperty("java.io.tmpdir"));
if (tmpDir.exists() == false || tmpDir.isDirectory() == false) {
throw new IllegalStateException();
}
return tmpDir;
}
public static void delete(File f) {
if (f == null) {
return;
}
Thread.yield();
Log.info("Deleting temporary file " + f);
final boolean ok = f.delete();
if (ok == false) {
Log.error("Cannot delete: " + f);
}
}
static public File createTempFile(String prefix, String suffix) throws IOException {
if (suffix.startsWith(".") == false) {
throw new IllegalArgumentException();
}
final File f = File.createTempFile(prefix, suffix);
Log.info("Creating temporary file: " + f);
if (OptionFlags.getInstance().isKeepTmpFiles() == false) {
f.deleteOnExit();
}
return f;
}
}

View File

@ -43,17 +43,17 @@ public interface ISkinParam {
public String getValue(String key);
public HtmlColor getHtmlColor(ColorParam param);
public HtmlColor getHtmlColor(ColorParam param, String stereotype);
public int getFontSize(FontParam param);
public int getFontSize(FontParam param, String stereotype);
public String getFontFamily(FontParam param);
public String getFontFamily(FontParam param, String stereotype);
public HtmlColor getFontHtmlColor(FontParam param);
public HtmlColor getFontHtmlColor(FontParam param, String stereotype);
public int getFontStyle(FontParam param);
public int getFontStyle(FontParam param, String stereotype);
public Font getFont(FontParam fontParam);
public Font getFont(FontParam fontParam, String stereotype);
public int getCircledCharacterRadius();
@ -63,4 +63,6 @@ public interface ISkinParam {
public boolean isMonochrome();
public int getDpi();
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5343 $
* Revision $Revision: 5877 $
*
*/
package net.sourceforge.plantuml;
@ -82,6 +82,12 @@ public class Option {
String s = arg[i];
if (s.equalsIgnoreCase("-tsvg") || s.equalsIgnoreCase("-svg")) {
setFileFormat(FileFormat.SVG);
} else if (s.equalsIgnoreCase("-txmi") || s.equalsIgnoreCase("-xmi")) {
setFileFormat(FileFormat.XMI_STANDARD);
} else if (s.equalsIgnoreCase("-txmi:argo") || s.equalsIgnoreCase("-xmi:argo")) {
setFileFormat(FileFormat.XMI_ARGO);
} else if (s.equalsIgnoreCase("-txmi:star") || s.equalsIgnoreCase("-xmi:star")) {
setFileFormat(FileFormat.XMI_STAR);
} else if (s.equalsIgnoreCase("-teps") || s.equalsIgnoreCase("-eps")) {
setFileFormat(FileFormat.EPS);
} else if (s.equalsIgnoreCase("-ttxt") || s.equalsIgnoreCase("-txt")) {
@ -261,4 +267,8 @@ public class Option {
return syntax;
}
public FileFormatOption getFileFormatOption() {
return new FileFormatOption(getFileFormat());
}
}

View File

@ -28,13 +28,15 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5244 $
* Revision $Revision: 5746 $
*
*/
package net.sourceforge.plantuml;
public class OptionFlags {
static public final boolean PBBACK = false;
void reset() {
keepTmpFiles = false;
verbose = false;
@ -58,21 +60,12 @@ public class OptionFlags {
private boolean metadata = false;
private boolean word = false;
private boolean systemExit = true;
// private boolean pipe = false;
private boolean debugDot = false;
private boolean forceGd = false;
private boolean forceCairo = false;
private String dotExecutable = null;
private boolean gui = false;
private boolean quiet = false;
//
// public final boolean isPipe() {
// return pipe;
// }
//
// public final void setPipe(boolean pipe) {
// this.pipe = pipe;
// }
private OptionFlags() {
reset();

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5520 $
* Revision $Revision: 5794 $
*
*/
package net.sourceforge.plantuml;
@ -40,9 +40,9 @@ import java.util.List;
public interface PSystem {
List<File> createFiles(File suggestedFile, FileFormat fileFormat) throws IOException, InterruptedException;
List<File> createFiles(File suggestedFile, FileFormatOption fileFormatOption) throws IOException, InterruptedException;
void createFile(OutputStream os, int index, FileFormat fileFormat) throws IOException;
void createFile(OutputStream os, int index, FileFormatOption fileFormatOption) throws IOException;
int getNbImages();

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5507 $
* Revision $Revision: 5794 $
*/
package net.sourceforge.plantuml;
@ -79,7 +79,10 @@ public class PSystemError extends AbstractPSystem {
this(source, Arrays.asList(errorUml));
}
public List<File> createFiles(File suggestedFile, FileFormat fileFormat) throws IOException, InterruptedException {
public List<File> createFiles(File suggestedFile, FileFormatOption fileFormat) throws IOException, InterruptedException {
if (suggestedFile.exists() && suggestedFile.isDirectory()) {
throw new IllegalArgumentException("File is a directory "+suggestedFile);
}
OutputStream os = null;
try {
os = new FileOutputStream(suggestedFile);
@ -92,7 +95,7 @@ public class PSystemError extends AbstractPSystem {
return Arrays.asList(suggestedFile);
}
public void createFile(OutputStream os, int index, FileFormat fileFormat) throws IOException {
public void createFile(OutputStream os, int index, FileFormatOption fileFormat) throws IOException {
getPngError().writeImage(os, getMetadata(), fileFormat);
}

View File

@ -69,7 +69,7 @@ final public class PSystemSingleBuilder {
public PSystemSingleBuilder(List<String> strings, PSystemFactory systemFactory) throws IOException {
source = new UmlSource(strings);
it = strings.iterator();
if (next().startsWith("@startuml") == false) {
if (BlockUmlBuilder.isArobaseStartuml(next()) == false) {
throw new UnsupportedOperationException();
}
@ -84,7 +84,7 @@ final public class PSystemSingleBuilder {
systemFactory.reset();
while (hasNext()) {
final String s = next();
if (s.equals("@enduml")) {
if (BlockUmlBuilder.isArobaseEnduml(s)) {
if (source.getSize() == 2) {
sys = buildEmptyError(source);
} else {
@ -116,7 +116,7 @@ final public class PSystemSingleBuilder {
systemFactory.reset();
while (hasNext()) {
final String s = next();
if (s.equals("@enduml")) {
if (BlockUmlBuilder.isArobaseEnduml(s)) {
if (source.getSize() == 2) {
sys = buildEmptyError(source);
} else {
@ -174,7 +174,7 @@ final public class PSystemSingleBuilder {
lines.add(init);
while (hasNext()) {
final String s = next();
if (s.equals("@enduml")) {
if (BlockUmlBuilder.isArobaseEnduml(s)) {
return false;
}
lines.add(s);

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5391 $
* Revision $Revision: 5810 $
*
*/
package net.sourceforge.plantuml;
@ -44,6 +44,7 @@ import java.util.List;
import javax.swing.UIManager;
import net.sourceforge.plantuml.code.Transcoder;
import net.sourceforge.plantuml.code.TranscoderUtil;
import net.sourceforge.plantuml.png.MetadataTag;
import net.sourceforge.plantuml.preproc.Defines;
import net.sourceforge.plantuml.swing.MainWindow;
@ -113,7 +114,7 @@ public class Run {
Log.error("InterruptedException " + e);
}
} else if (option.isPipe()) {
final String result = sourceStringReader.generateImage(ps, 0, option.getFileFormat());
final String result = sourceStringReader.generateImage(ps, 0, option.getFileFormatOption());
}
}
@ -127,7 +128,7 @@ public class Run {
System.out.println("------------------------");
} else {
final SourceFileReader sourceFileReader = new SourceFileReader(option.getDefaultDefines(), f, option
.getOutputDir(), option.getConfig(), option.getCharset(), option.getFileFormat());
.getOutputDir(), option.getConfig(), option.getCharset(), option.getFileFormatOption());
if (option.isComputeurl()) {
final List<String> urls = sourceFileReader.getEncodedUrl();
for (String s : urls) {
@ -162,7 +163,7 @@ public class Run {
private static void processArgs(Option option) throws IOException, InterruptedException {
for (String s : option.getResult()) {
if (option.isDecodeurl()) {
final Transcoder transcoder = new Transcoder();
final Transcoder transcoder = TranscoderUtil.getDefaultTranscoder();
System.out.println("@startuml");
System.out.println(transcoder.decode(s));
System.out.println("@enduml");

View File

@ -28,11 +28,14 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 3883 $
* Revision $Revision: 5877 $
*
*/
package net.sourceforge.plantuml;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@ -58,7 +61,8 @@ public class SignatureUtils {
}
public static String getSignatureWithoutImgSrc(String s) {
return getSignature(purge(s));
s = getSignature(purge(s));
return s;
}
public static String purge(String s) {
@ -68,4 +72,25 @@ public class SignatureUtils {
s = s.replaceAll(regex2, "image=\"$1$2\"");
return s;
}
public static String getSignature(File f) throws IOException {
try {
final AsciiEncoder coder = new AsciiEncoder();
final MessageDigest msgDigest = MessageDigest.getInstance("MD5");
final FileInputStream is = new FileInputStream(f);
int read = -1;
while ((read = is.read()) != -1) {
msgDigest.update((byte) read);
}
is.close();
final byte[] digest = msgDigest.digest();
return coder.encode(digest);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
throw new IllegalStateException();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
throw new IllegalStateException();
}
}
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5403 $
* Revision $Revision: 5845 $
*
*/
package net.sourceforge.plantuml;
@ -41,6 +41,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sourceforge.plantuml.graphic.HtmlColor;
@ -49,11 +51,26 @@ public class SkinParam implements ISkinParam {
private final Map<String, String> params = new HashMap<String, String>();
public void setParam(String key, String value) {
params.put(key.toLowerCase().trim(), value.trim());
params.put(cleanForKey(key), value.trim());
}
private static final String stereoPatternString = "\\<\\<(.*?)\\>\\>";
private static final Pattern stereoPattern = Pattern.compile(stereoPatternString);
static String cleanForKey(String key) {
key = key.toLowerCase().trim();
key = key.replaceAll("_|\\.|\\s", "");
final Matcher m = stereoPattern.matcher(key);
if (m.find()) {
final String s = m.group(1);
key = key.replaceAll(stereoPatternString, "");
key += "<<" + s + ">>";
}
return key;
}
public HtmlColor getBackgroundColor() {
final HtmlColor result = getHtmlColor(ColorParam.background);
final HtmlColor result = getHtmlColor(ColorParam.background, null);
if (result == null) {
return new HtmlColor("white");
}
@ -61,7 +78,7 @@ public class SkinParam implements ISkinParam {
}
public String getValue(String key) {
return params.get(key.toLowerCase().replaceAll("_", ""));
return params.get(cleanForKey(key));
}
static String humanName(String key) {
@ -79,7 +96,14 @@ public class SkinParam implements ISkinParam {
return sb.toString();
}
public HtmlColor getHtmlColor(ColorParam param) {
public HtmlColor getHtmlColor(ColorParam param, String stereotype) {
if (stereotype != null) {
checkStereotype(stereotype);
final String value2 = getValue(param.name() + "color" + stereotype);
if (value2 != null && HtmlColor.isValid(value2)) {
return new HtmlColor(value2);
}
}
final String value = getValue(param.name() + "color");
if (value == null || HtmlColor.isValid(value) == false) {
return null;
@ -87,7 +111,20 @@ public class SkinParam implements ISkinParam {
return new HtmlColor(value);
}
public int getFontSize(FontParam param) {
private void checkStereotype(String stereotype) {
if (stereotype.startsWith("<<") == false || stereotype.endsWith(">>") == false) {
throw new IllegalArgumentException();
}
}
public int getFontSize(FontParam param, String stereotype) {
if (stereotype != null) {
checkStereotype(stereotype);
final String value2 = getValue(param.name() + "fontsize" + stereotype);
if (value2 != null && value2.matches("\\d+")) {
return Integer.parseInt(value2);
}
}
String value = getValue(param.name() + "fontsize");
if (value == null || value.matches("\\d+") == false) {
value = getValue("defaultfontsize");
@ -98,34 +135,55 @@ public class SkinParam implements ISkinParam {
return Integer.parseInt(value);
}
public String getFontFamily(FontParam param) {
public String getFontFamily(FontParam param, String stereotype) {
if (stereotype != null) {
checkStereotype(stereotype);
final String value2 = getValue(param.name() + "fontname" + stereotype);
if (value2 != null) {
return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(value2);
}
}
// Times, Helvetica, Courier or Symbol
String value = getValue(param.name() + "fontname");
if (value != null) {
return value;
return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(value);
}
if (param != FontParam.CIRCLED_CHARACTER) {
value = getValue("defaultfontname");
if (value != null) {
return value;
return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(value);
}
}
return param.getDefaultFamily();
}
public HtmlColor getFontHtmlColor(FontParam param) {
String value = getValue(param.name() + "fontcolor");
if (value == null) {
public HtmlColor getFontHtmlColor(FontParam param, String stereotype) {
String value = null;
if (stereotype != null) {
checkStereotype(stereotype);
value = getValue(param.name() + "fontcolor" + stereotype);
}
if (value == null || HtmlColor.isValid(value) == false) {
value = getValue(param.name() + "fontcolor");
}
if (value == null || HtmlColor.isValid(value) == false) {
value = getValue("defaultfontcolor");
}
if (value == null) {
if (value == null || HtmlColor.isValid(value) == false) {
value = param.getDefaultColor();
}
return new HtmlColor(value);
}
public int getFontStyle(FontParam param) {
String value = getValue(param.name() + "fontstyle");
public int getFontStyle(FontParam param, String stereotype) {
String value = null;
if (stereotype != null) {
checkStereotype(stereotype);
value = getValue(param.name() + "fontstyle" + stereotype);
}
if (value == null) {
value = getValue(param.name() + "fontstyle");
}
if (value == null) {
value = getValue("defaultfontstyle");
}
@ -142,8 +200,12 @@ public class SkinParam implements ISkinParam {
return result;
}
public Font getFont(FontParam fontParam) {
return new Font(getFontFamily(fontParam), getFontStyle(fontParam), getFontSize(fontParam));
public Font getFont(FontParam fontParam, String stereotype) {
if (stereotype != null) {
checkStereotype(stereotype);
}
return new Font(getFontFamily(fontParam, stereotype), getFontStyle(fontParam, stereotype), getFontSize(
fontParam, stereotype));
}
public int getCircledCharacterRadius() {
@ -154,7 +216,7 @@ public class SkinParam implements ISkinParam {
// return 11;
// System.err.println("SIZE1="+getFontSize(FontParam.CIRCLED_CHARACTER));
// System.err.println("SIZE1="+getFontSize(FontParam.CIRCLED_CHARACTER)/3);
return getFontSize(FontParam.CIRCLED_CHARACTER) / 3 + 6;
return getFontSize(FontParam.CIRCLED_CHARACTER, null) / 3 + 6;
}
public boolean isClassCollapse() {
@ -193,4 +255,12 @@ public class SkinParam implements ISkinParam {
return Collections.unmodifiableSet(result);
}
public int getDpi() {
final String value = getValue("dpi");
if (value != null && value.matches("\\d+")) {
return Integer.parseInt(value);
}
return 96;
}
}

View File

@ -65,31 +65,31 @@ public class SkinParamBackcolored implements ISkinParam {
return skinParam.getCircledCharacterRadius();
}
public Font getFont(FontParam fontParam) {
return skinParam.getFont(fontParam);
public Font getFont(FontParam fontParam, String stereotype) {
return skinParam.getFont(fontParam, stereotype);
}
public String getFontFamily(FontParam param) {
return skinParam.getFontFamily(param);
public String getFontFamily(FontParam param, String stereotype) {
return skinParam.getFontFamily(param, stereotype);
}
public HtmlColor getFontHtmlColor(FontParam param) {
return skinParam.getFontHtmlColor(param);
public HtmlColor getFontHtmlColor(FontParam param, String stereotype) {
return skinParam.getFontHtmlColor(param, stereotype);
}
public int getFontSize(FontParam param) {
return skinParam.getFontSize(param);
public int getFontSize(FontParam param, String stereotype) {
return skinParam.getFontSize(param, stereotype);
}
public int getFontStyle(FontParam param) {
return skinParam.getFontStyle(param);
public int getFontStyle(FontParam param, String stereotype) {
return skinParam.getFontStyle(param, stereotype);
}
public HtmlColor getHtmlColor(ColorParam param) {
public HtmlColor getHtmlColor(ColorParam param, String stereotype) {
if (param.isBackground() && backColorElement != null) {
return backColorElement;
}
return skinParam.getHtmlColor(param);
return skinParam.getHtmlColor(param, stereotype);
}
public String getValue(String key) {
@ -107,4 +107,8 @@ public class SkinParamBackcolored implements ISkinParam {
public boolean isMonochrome() {
return skinParam.isMonochrome();
}
public int getDpi() {
return skinParam.getDpi();
}
}

View File

@ -45,6 +45,7 @@ import java.util.Collections;
import java.util.List;
import net.sourceforge.plantuml.code.Transcoder;
import net.sourceforge.plantuml.code.TranscoderUtil;
import net.sourceforge.plantuml.preproc.Defines;
public class SourceFileReader {
@ -53,24 +54,24 @@ public class SourceFileReader {
private final File outputDirectory;
private final BlockUmlBuilder builder;
private FileFormat fileFormat;
private FileFormatOption fileFormatOption;
public SourceFileReader(File file) throws IOException {
this(file, file.getAbsoluteFile().getParentFile());
}
public SourceFileReader(final File file, File outputDirectory) throws IOException {
this(new Defines(), file, outputDirectory, Collections.<String> emptyList(), null, FileFormat.PNG);
this(new Defines(), file, outputDirectory, Collections.<String> emptyList(), null, new FileFormatOption(FileFormat.PNG));
}
public SourceFileReader(final File file, File outputDirectory, FileFormat fileFormat) throws IOException {
this(new Defines(), file, outputDirectory, Collections.<String> emptyList(), null, fileFormat);
public SourceFileReader(final File file, File outputDirectory, FileFormatOption fileFormatOption) throws IOException {
this(new Defines(), file, outputDirectory, Collections.<String> emptyList(), null, fileFormatOption);
}
public SourceFileReader(Defines defines, final File file, File outputDirectory, List<String> config,
String charset, FileFormat fileFormat) throws IOException {
String charset, FileFormatOption fileFormatOption) throws IOException {
this.file = file;
this.fileFormat = fileFormat;
this.fileFormatOption = fileFormatOption;
if (file.exists() == false) {
throw new IllegalArgumentException();
}
@ -98,13 +99,13 @@ public class SourceFileReader {
String newName = blockUml.getFilename();
if (newName == null) {
newName = changeName(file.getName(), cpt++, fileFormat);
newName = changeName(file.getName(), cpt++, fileFormatOption.getFileFormat());
}
final File suggested = new File(outputDirectory, newName);
suggested.getParentFile().mkdirs();
for (File f : blockUml.getSystem().createFiles(suggested, fileFormat)) {
for (File f : blockUml.getSystem().createFiles(suggested, fileFormatOption)) {
final String desc = "[" + file.getName() + "] " + blockUml.getSystem().getDescription();
final GeneratedImage generatedImage = new GeneratedImage(f, desc);
result.add(generatedImage);
@ -119,7 +120,7 @@ public class SourceFileReader {
public List<String> getEncodedUrl() throws IOException, InterruptedException {
final List<String> result = new ArrayList<String>();
final Transcoder transcoder = new Transcoder();
final Transcoder transcoder = TranscoderUtil.getDefaultTranscoder();
for (BlockUml blockUml : builder.getBlockUmls()) {
final String source = blockUml.getSystem().getSource().getPlainString();
final String encoded = transcoder.encode(source);
@ -144,8 +145,8 @@ public class SourceFileReader {
return new InputStreamReader(new FileInputStream(file), charset);
}
public final void setFileFormat(FileFormat fileFormat) {
this.fileFormat = fileFormat;
public final void setFileFormatOption(FileFormatOption fileFormatOption) {
this.fileFormatOption = fileFormatOption;
}
}

View File

@ -33,6 +33,8 @@
*/
package net.sourceforge.plantuml;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringReader;
@ -64,18 +66,25 @@ public class SourceStringReader {
return generateImage(os, 0);
}
public String generateImage(OutputStream os, FileFormat fileFormat) throws IOException {
return generateImage(os, 0, fileFormat);
public String generateImage(File f) throws IOException {
final FileOutputStream os = new FileOutputStream(f);
final String result = generateImage(os, 0);
os.close();
return result;
}
public String generateImage(OutputStream os, FileFormatOption fileFormatOption) throws IOException {
return generateImage(os, 0, fileFormatOption);
}
public String generateImage(OutputStream os, int numImage) throws IOException {
return generateImage(os, numImage, FileFormat.PNG);
return generateImage(os, numImage, new FileFormatOption(FileFormat.PNG));
}
public String generateImage(OutputStream os, int numImage, FileFormat fileFormat) throws IOException {
public String generateImage(OutputStream os, int numImage, FileFormatOption fileFormatOption) throws IOException {
if (blocks.size() == 0) {
final GraphicStrings error = new GraphicStrings(Arrays.asList("No @startuml found"));
error.writeImage(os, fileFormat);
error.writeImage(os, fileFormatOption);
return null;
}
try {
@ -83,7 +92,7 @@ public class SourceStringReader {
final PSystem system = b.getSystem();
final int nbInSystem = system.getNbImages();
if (numImage < nbInSystem) {
system.createFile(os, numImage, fileFormat);
system.createFile(os, numImage, fileFormatOption);
return system.getDescription();
}
numImage -= nbInSystem;

View File

@ -28,37 +28,49 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5427 $
* Revision $Revision: 5749 $
*
*/
package net.sourceforge.plantuml;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class StringUtils {
static private final Pattern multiLines = Pattern.compile("((?:\\\\\\\\|[^\\\\])+)(\\\\n)?");
public static String getPlateformDependentAbsolutePath(File file) {
return file.getAbsolutePath();
}
public static List<String> getWithNewlines(String s) {
if (s == null) {
throw new IllegalArgumentException();
}
final Matcher matcher = multiLines.matcher(s);
final List<String> strings = new ArrayList<String>();
while (matcher.find()) {
strings.add(matcher.group(1).replace("\\\\", "\\"));
final List<String> result = new ArrayList<String>();
final StringBuilder current = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
final char c = s.charAt(i);
if (c == '\\' && i < s.length() + 1) {
final char c2 = s.charAt(i + 1);
i++;
if (c2 == 'n') {
result.add(current.toString());
current.setLength(0);
} else if (c2 == 't') {
current.append('\t');
} else if (c2 == '\\') {
current.append(c2);
}
return strings;
} else {
current.append(c);
}
}
result.add(current.toString());
return Collections.unmodifiableList(result);
}
public static String getMergedLines(List<String> strings) {
@ -260,4 +272,46 @@ public class StringUtils {
return stringsToDisplay.size();
}
private static boolean firstColumnRemovable(List<String> data) {
boolean allEmpty = true;
for (String s : data) {
if (s.length() == 0) {
continue;
}
allEmpty = false;
final char c = s.charAt(0);
if (c != ' ' && c != '\t') {
return false;
}
}
return allEmpty == false;
}
private static void removeFirstColumn(List<String> data) {
for (int i = 0; i < data.size(); i++) {
final String s = data.get(i);
if (s.length() > 0) {
data.set(i, s.substring(1));
}
}
}
public static List<String> removeEmptyColumns(List<String> data) {
if (firstColumnRemovable(data) == false) {
return data;
}
final List<String> result = new ArrayList<String>(data);
do {
removeFirstColumn(result);
} while (firstColumnRemovable(result));
return Collections.unmodifiableList(result);
}
public static void trim(List<String> data) {
for (int i = 0; i < data.size(); i++) {
final String s = data.get(i);
data.set(i, s.trim());
}
}
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5503 $
* Revision $Revision: 5811 $
*
*/
package net.sourceforge.plantuml;
@ -131,4 +131,15 @@ public abstract class UmlDiagram extends AbstractPSystem implements PSystem {
return scale;
}
public final double getDpiFactor(FileFormatOption fileFormatOption) {
if (getSkinParam().getDpi() == 96) {
return 1.0;
}
return getSkinParam().getDpi() / 96.0;
}
public final int getDpi(FileFormatOption fileFormatOption) {
return getSkinParam().getDpi();
}
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5223 $
* Revision $Revision: 5721 $
*
*/
package net.sourceforge.plantuml.activitydiagram;
@ -52,7 +52,6 @@ public class ActivityDiagram extends CucaDiagram {
private IEntity lastEntityConsulted;
private IEntity lastEntityBrancheConsulted;
private ConditionalContext currentContext;
private boolean acceptOldSyntaxForBranch = true;
private String getAutoBranch() {
return "#" + UniqueSequence.getValue();
@ -63,7 +62,7 @@ public class ActivityDiagram extends CucaDiagram {
if (entityExist(code)) {
result = super.getOrCreateEntity(code, type);
if (result.getType() != type) {
throw new IllegalArgumentException("Already known: " + code);
throw new IllegalArgumentException("Already known: " + code + " " + result.getType() + " " + type);
// return null;
}
} else {
@ -73,8 +72,8 @@ public class ActivityDiagram extends CucaDiagram {
return result;
}
public void startIf() {
final IEntity br = createEntity(getAutoBranch(), "", EntityType.BRANCH);
public void startIf(String optionalCode) {
final IEntity br = createEntity(optionalCode == null ? getAutoBranch() : optionalCode, "", EntityType.BRANCH);
currentContext = new ConditionalContext(currentContext, br, Direction.DOWN);
}
@ -153,14 +152,6 @@ public class ActivityDiagram extends CucaDiagram {
this.lastEntityConsulted = lastEntityConsulted;
}
public final boolean isAcceptOldSyntaxForBranch() {
return acceptOldSyntaxForBranch;
}
public final void setAcceptOldSyntaxForBranch(boolean acceptOldSyntaxForBranch) {
this.acceptOldSyntaxForBranch = acceptOldSyntaxForBranch;
}
public IEntity createInnerActivity() {
// System.err.println("createInnerActivity A");
final String code = "##" + UniqueSequence.getValue();

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5190 $
* Revision $Revision: 5847 $
*
*/
package net.sourceforge.plantuml.activitydiagram;
@ -38,8 +38,8 @@ import net.sourceforge.plantuml.activitydiagram.command.CommandEndPartition;
import net.sourceforge.plantuml.activitydiagram.command.CommandEndif;
import net.sourceforge.plantuml.activitydiagram.command.CommandIf;
import net.sourceforge.plantuml.activitydiagram.command.CommandInnerConcurrent;
import net.sourceforge.plantuml.activitydiagram.command.CommandLinkActivity2;
import net.sourceforge.plantuml.activitydiagram.command.CommandLinkLongActivity2;
import net.sourceforge.plantuml.activitydiagram.command.CommandLinkActivity;
import net.sourceforge.plantuml.activitydiagram.command.CommandLinkLongActivity;
import net.sourceforge.plantuml.activitydiagram.command.CommandMultilinesNoteActivity;
import net.sourceforge.plantuml.activitydiagram.command.CommandMultilinesNoteActivityLink;
import net.sourceforge.plantuml.activitydiagram.command.CommandNoteActivity;
@ -61,10 +61,10 @@ public class ActivityDiagramFactory extends AbstractUmlSystemCommandFactory {
addCommonCommands(system);
addCommand(new CommandLinkActivity2(system));
addCommand(new CommandLinkActivity(system));
addCommand(new CommandPartition(system));
addCommand(new CommandEndPartition(system));
addCommand(new CommandLinkLongActivity2(system));
addCommand(new CommandLinkLongActivity(system));
addCommand(new CommandNoteActivity(system));
addCommand(new CommandMultilinesNoteActivity(system));
@ -75,7 +75,7 @@ public class ActivityDiagramFactory extends AbstractUmlSystemCommandFactory {
addCommand(new CommandIf(system));
addCommand(new CommandElse(system));
addCommand(new CommandEndif(system));
addCommand(new CommandInnerConcurrent(system));
// addCommand(new CommandInnerConcurrent(system));
}
}

View File

@ -54,7 +54,6 @@ public class CommandElse extends SingleLineCommand<ActivityDiagram> {
final IEntity branch = getSystem().getCurrentContext().getBranch();
getSystem().setLastEntityConsulted(branch);
getSystem().setAcceptOldSyntaxForBranch(false);
return CommandExecutionResult.ok();
}

View File

@ -51,7 +51,6 @@ public class CommandEndif extends SingleLineCommand<ActivityDiagram> {
return CommandExecutionResult.error("No if for this endif");
}
getSystem().endif();
getSystem().setAcceptOldSyntaxForBranch(false);
return CommandExecutionResult.ok();
}

View File

@ -33,47 +33,63 @@
*/
package net.sourceforge.plantuml.activitydiagram.command;
import java.util.List;
import java.util.Map;
import net.sourceforge.plantuml.Direction;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.activitydiagram.ActivityDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand;
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.RegexOr;
import net.sourceforge.plantuml.command.regex.RegexPartialMatch;
import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.LinkDecor;
import net.sourceforge.plantuml.cucadiagram.LinkType;
public class CommandIf extends SingleLineCommand<ActivityDiagram> {
public class CommandIf extends SingleLineCommand2<ActivityDiagram> {
public CommandIf(ActivityDiagram diagram) {
super(
diagram,
"(?i)^(?:(\\(\\*\\))|([\\p{L}0-9_.]+)|(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)|\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?)?"
+ "\\s*([=-]+(?:left|right|up|down|le?|ri?|up?|do?)?[=-]*\\>)?\\s*(?:\\[([^\\]*]+[^\\]]*)\\])?\\s*if\\s*\"([^\"]*)\"\\s*then$");
super(diagram, getRegexConcat());
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
final IEntity entity1 = CommandLinkActivity2.getEntity(getSystem(), arg, true);
static RegexConcat getRegexConcat() {
return new RegexConcat(new RegexLeaf("^"),
new RegexOr("FIRST", true,
new RegexLeaf("STAR", "(\\(\\*\\))"),
new RegexLeaf("CODE", "([\\p{L}0-9_.]+)"),
new RegexLeaf("BAR", "(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)"),
new RegexLeaf("QUOTED", "\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?")),
new RegexLeaf("\\s*"),
new RegexLeaf("ARROW", "([=-]+(?:left|right|up|down|le?|ri?|up?|do?)?[=-]*\\>)?"),
new RegexLeaf("\\s*"),
new RegexLeaf("BRACKET", "(?:\\[([^\\]*]+[^\\]]*)\\])?"),
new RegexLeaf("\\s*"),
new RegexLeaf("IF", "if\\s*\"([^\"]*)\"\\s*(?:as\\s+([\\p{L}0-9_.]+)\\s+)?then$"));
}
getSystem().startIf();
@Override
protected CommandExecutionResult executeArg(Map<String, RegexPartialMatch> arg) {
final IEntity entity1 = CommandLinkActivity.getEntity(getSystem(), arg, true);
getSystem().startIf(arg.get("IF").get(1));
int lenght = 2;
if (arg.get(5) != null) {
final String arrow = StringUtils.manageArrowForCuca(arg.get(5));
if (arg.get("ARROW").get(0) != null) {
final String arrow = StringUtils.manageArrowForCuca(arg.get("ARROW").get(0));
lenght = arrow.length() - 1;
}
final IEntity branch = getSystem().getCurrentContext().getBranch();
Link link = new Link(entity1, branch, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), arg.get(6), lenght, null,
arg.get(7), getSystem().getLabeldistance(), getSystem().getLabelangle());
if (arg.get(5) != null) {
final Direction direction = StringUtils.getArrowDirection(arg.get(5));
Link link = new Link(entity1, branch, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), arg.get("BRACKET").get(0),
lenght, null, arg.get("IF").get(0), getSystem().getLabeldistance(), getSystem().getLabelangle());
if (arg.get("ARROW").get(0) != null) {
final Direction direction = StringUtils.getArrowDirection(arg.get("ARROW").get(0));
if (direction == Direction.LEFT || direction == Direction.UP) {
link = link.getInv();
}
@ -81,7 +97,6 @@ public class CommandIf extends SingleLineCommand<ActivityDiagram> {
getSystem().addLink(link);
getSystem().setAcceptOldSyntaxForBranch(false);
return CommandExecutionResult.ok();
}

View File

@ -0,0 +1,187 @@
/* ========================================================================
* 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: 5024 $
*
*/
package net.sourceforge.plantuml.activitydiagram.command;
import java.util.Map;
import net.sourceforge.plantuml.Direction;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.activitydiagram.ActivityDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
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.RegexOr;
import net.sourceforge.plantuml.command.regex.RegexPartialMatch;
import net.sourceforge.plantuml.cucadiagram.EntityType;
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.cucadiagram.Stereotype;
public class CommandLinkActivity extends SingleLineCommand2<ActivityDiagram> {
public CommandLinkActivity(ActivityDiagram diagram) {
super(
diagram, getRegexConcat());
}
static RegexConcat getRegexConcat() {
return new RegexConcat(new RegexLeaf("^"),
new RegexOr("FIRST", true,
new RegexLeaf("STAR", "(\\(\\*\\))"),
new RegexLeaf("CODE", "([\\p{L}0-9_.]+)"),
new RegexLeaf("BAR", "(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)"),
new RegexLeaf("QUOTED", "\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?")),
new RegexLeaf("\\s*"),
new RegexLeaf("STEREOTYPE", "(\\<\\<.*\\>\\>)?"),
new RegexLeaf("\\s*"),
new RegexLeaf("BACKCOLOR", "(#\\w+)?"),
new RegexLeaf("\\s*"),
new RegexLeaf("ARROW", "([=-]+(?:left|right|up|down|le?|ri?|up?|do?)?[=-]*\\>)"),
new RegexLeaf("\\s*"),
new RegexLeaf("BRACKET", "(?:\\[([^\\]*]+[^\\]]*)\\])?"),
new RegexLeaf("\\s*"),
new RegexOr("FIRST2",
new RegexLeaf("STAR2", "(\\(\\*\\))"),
new RegexLeaf("OPENBRACKET2", "(\\{)"),
new RegexLeaf("CODE2", "([\\p{L}0-9_.]+)"),
new RegexLeaf("BAR2", "(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)"),
new RegexLeaf("QUOTED2", "\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?")),
new RegexLeaf("\\s*"),
new RegexLeaf("STEREOTYPE2", "(\\<\\<.*\\>\\>)?"),
new RegexLeaf("\\s*"),
new RegexLeaf("BACKCOLOR2", "(#\\w+)?"),
new RegexLeaf("$"));
}
@Override
protected CommandExecutionResult executeArg(Map<String, RegexPartialMatch> arg2) {
final IEntity entity1 = getEntity(getSystem(), arg2, true);
if (arg2.get("STEREOTYPE").get(0) != null) {
entity1.setStereotype(new Stereotype(arg2.get("STEREOTYPE").get(0)));
}
if (arg2.get("BACKCOLOR").get(0) != null) {
entity1.setSpecificBackcolor(arg2.get("BACKCOLOR").get(0));
}
final IEntity entity2 = getEntity(getSystem(), arg2, false);
if (arg2.get("BACKCOLOR2").get(0) != null) {
entity2.setSpecificBackcolor(arg2.get("BACKCOLOR2").get(0));
}
if (arg2.get("STEREOTYPE2").get(0) != null) {
entity2.setStereotype(new Stereotype(arg2.get("STEREOTYPE2").get(0)));
}
final String linkLabel = arg2.get("BRACKET").get(0);
final String arrow = StringUtils.manageArrowForCuca(arg2.get("ARROW").get(0));
final int lenght = arrow.length() - 1;
Link link = new Link(entity1, entity2, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), linkLabel, lenght);
final Direction direction = StringUtils.getArrowDirection(arg2.get("ARROW").get(0));
if (direction == Direction.LEFT || direction == Direction.UP) {
link = link.getInv();
}
getSystem().addLink(link);
return CommandExecutionResult.ok();
}
static IEntity getEntity(ActivityDiagram system, Map<String, RegexPartialMatch> arg, final boolean start) {
final String suf = start ? "" : "2";
final RegexPartialMatch openBracket = arg.get("OPENBRACKET" + suf);
if (openBracket!=null && openBracket.get(0) != null) {
return system.createInnerActivity();
}
if (arg.get("STAR" + suf).get(0) != null) {
if (start) {
return system.getStart();
}
return system.getEnd();
}
final String code = arg.get("CODE" + suf).get(0);
if (code != null) {
return system.getOrCreate(code, code, getTypeIfExisting(system, code));
}
final String bar = arg.get("BAR" + suf).get(0);
if (bar != null) {
return system.getOrCreate(bar, bar, EntityType.SYNCHRO_BAR);
}
final RegexPartialMatch quoted = arg.get("QUOTED" + suf);
if (quoted.get(0) != null) {
final String quotedCode = quoted.get(1) == null ? quoted.get(0) : quoted.get(1);
return system.getOrCreate(quotedCode, quoted.get(0), getTypeIfExisting(system,
quotedCode));
}
final String first = arg.get("FIRST" + suf).get(0);
if (first == null) {
return system.getLastEntityConsulted();
}
throw new UnsupportedOperationException();
}
static EntityType getTypeIfExisting(ActivityDiagram system, String code) {
if (system.entityExist(code)) {
final IEntity ent = system.entities().get(code);
if (ent.getType() == EntityType.BRANCH) {
return EntityType.BRANCH;
}
}
return EntityType.ACTIVITY;
}
static EntityType getTypeFromString(String type, final EntityType circle) {
if (type == null) {
return EntityType.ACTIVITY;
}
if (type.equals("*")) {
return circle;
}
if (type.startsWith("=")) {
return EntityType.SYNCHRO_BAR;
}
throw new IllegalArgumentException();
}
}

View File

@ -1,125 +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: 5024 $
*
*/
package net.sourceforge.plantuml.activitydiagram.command;
import java.util.List;
import net.sourceforge.plantuml.Direction;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.activitydiagram.ActivityDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand;
import net.sourceforge.plantuml.cucadiagram.EntityType;
import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.LinkDecor;
import net.sourceforge.plantuml.cucadiagram.LinkType;
public class CommandLinkActivity2 extends SingleLineCommand<ActivityDiagram> {
public CommandLinkActivity2(ActivityDiagram diagram) {
super(
diagram,
"(?i)^(?:(\\(\\*\\))|([\\p{L}0-9_.]+)|(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)|\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?)?"
+ "\\s*([=-]+(?:left|right|up|down|le?|ri?|up?|do?)?[=-]*\\>)\\s*(?:\\[([^\\]*]+[^\\]]*)\\])?\\s*"
+ "(?:(\\(\\*\\)|\\{)|([\\p{L}0-9_.]+)|(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)|\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?)$");
}
@Override
protected void actionIfCommandValid() {
getSystem().setAcceptOldSyntaxForBranch(false);
}
static IEntity getEntity(ActivityDiagram system, List<String> arg, final boolean start) {
if ("{".equals(arg.get(0))) {
return system.createInnerActivity();
}
if ("(*)".equals(arg.get(0))) {
if (start) {
return system.getStart();
}
return system.getEnd();
}
if (arg.get(1) != null) {
return system.getOrCreate(arg.get(1), arg.get(1), EntityType.ACTIVITY);
}
if (arg.get(2) != null) {
return system.getOrCreate(arg.get(2), arg.get(2), EntityType.SYNCHRO_BAR);
}
if (arg.get(3) != null) {
final String code = arg.get(4) == null ? arg.get(3) : arg.get(4);
return system.getOrCreate(code, arg.get(3), EntityType.ACTIVITY);
}
if (start && arg.get(0) == null && arg.get(1) == null && arg.get(2) == null && arg.get(3) == null
&& arg.get(4) == null) {
return system.getLastEntityConsulted();
}
throw new UnsupportedOperationException();
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
final IEntity entity1 = getEntity(getSystem(), arg, true);
final IEntity entity2 = getEntity(getSystem(), arg.subList(7, 12), false);
final String linkLabel = arg.get(6);
final String arrow = StringUtils.manageArrowForCuca(arg.get(5));
final int lenght = arrow.length() - 1;
Link link = new Link(entity1, entity2, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), linkLabel, lenght);
final Direction direction = StringUtils.getArrowDirection(arg.get(5));
if (direction == Direction.LEFT || direction == Direction.UP) {
link = link.getInv();
}
getSystem().addLink(link);
return CommandExecutionResult.ok();
}
static EntityType getTypeFromString(String type, final EntityType circle) {
if (type == null) {
return EntityType.ACTIVITY;
}
if (type.equals("*")) {
return circle;
}
if (type.startsWith("=")) {
return EntityType.SYNCHRO_BAR;
}
throw new IllegalArgumentException();
}
}

View File

@ -34,45 +34,69 @@
package net.sourceforge.plantuml.activitydiagram.command;
import java.util.List;
import java.util.Map;
import net.sourceforge.plantuml.Direction;
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.CommandMultilines2;
import net.sourceforge.plantuml.command.regex.RegexConcat;
import net.sourceforge.plantuml.command.regex.RegexLeaf;
import net.sourceforge.plantuml.command.regex.RegexOr;
import net.sourceforge.plantuml.command.regex.RegexPartialMatch;
import net.sourceforge.plantuml.cucadiagram.Entity;
import net.sourceforge.plantuml.cucadiagram.EntityType;
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.cucadiagram.Stereotype;
public class CommandLinkLongActivity2 extends CommandMultilines<ActivityDiagram> {
public class CommandLinkLongActivity extends CommandMultilines2<ActivityDiagram> {
public CommandLinkLongActivity2(final ActivityDiagram diagram) {
public CommandLinkLongActivity(final ActivityDiagram diagram) {
super(
diagram,
"(?i)^(?:(\\(\\*\\))|([\\p{L}0-9_.]+)|(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)|\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?)?"
+ "\\s*([=-]+(?:left|right|up|down|le?|ri?|up?|do?)?[=-]*\\>)\\s*(?:\\[([^\\]*]+[^\\]]*)\\])?\\s*\"([^\"]*?)\\s*$",
"(?i)^\\s*([^\"]*)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?$");
getRegexConcat(),
"(?i)^\\s*([^\"]*)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?\\s*(\\<\\<.*\\>\\>)?\\s*(#\\w+)?$");
}
@Override
protected void actionIfCommandValid() {
getSystem().setAcceptOldSyntaxForBranch(false);
static RegexConcat getRegexConcat() {
return new RegexConcat(new RegexLeaf("^"),
new RegexOr("FIRST", true,
new RegexLeaf("STAR", "(\\(\\*\\))"),
new RegexLeaf("CODE", "([\\p{L}0-9_.]+)"),
new RegexLeaf("BAR", "(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)"),
new RegexLeaf("QUOTED", "\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?")),
new RegexLeaf("\\s*"),
new RegexLeaf("STEREOTYPE", "(\\<\\<.*\\>\\>)?"),
new RegexLeaf("\\s*"),
new RegexLeaf("BACKCOLOR", "(#\\w+)?"),
new RegexLeaf("\\s*"),
new RegexLeaf("ARROW", "([=-]+(?:left|right|up|down|le?|ri?|up?|do?)?[=-]*\\>)"),
new RegexLeaf("\\s*"),
new RegexLeaf("BRACKET", "(?:\\[([^\\]*]+[^\\]]*)\\])?"),
new RegexLeaf("\\s*"),
new RegexLeaf("DESC", "\"([^\"]*?)"),
new RegexLeaf("\\s*"),
new RegexLeaf("$"));
}
public CommandExecutionResult execute(List<String> lines) {
// final IEntity lastEntityConsulted =
// getSystem().getLastEntityConsulted();
final List<String> line0 = StringUtils.getSplit(getStartingPattern(), lines.get(0));
final IEntity entity1 = CommandLinkActivity2.getEntity(getSystem(), line0, true);
StringUtils.trim(lines);
final Map<String, RegexPartialMatch> line0 = getStartingPattern().matcher(lines.get(0).trim());
final IEntity entity1 = CommandLinkActivity.getEntity(getSystem(), line0, true);
if (line0.get("STEREOTYPE").get(0) != null) {
entity1.setStereotype(new Stereotype(line0.get("STEREOTYPE").get(0)));
}
if (line0.get("BACKCOLOR").get(0)!=null) {
entity1.setSpecificBackcolor(line0.get("BACKCOLOR").get(0));
}
final StringBuilder sb = new StringBuilder();
if (StringUtils.isNotEmpty(line0.get(7))) {
sb.append(line0.get(7));
if (StringUtils.isNotEmpty(line0.get("DESC").get(0))) {
sb.append(line0.get("DESC").get(0));
sb.append("\\n");
}
for (int i = 1; i < lines.size() - 1; i++) {
@ -84,7 +108,9 @@ public class CommandLinkLongActivity2 extends CommandMultilines<ActivityDiagram>
final List<String> lineLast = StringUtils.getSplit(getEnding(), lines.get(lines.size() - 1));
if (StringUtils.isNotEmpty(lineLast.get(0))) {
if (sb.toString().endsWith("\\n") == false) {
sb.append("\\n");
}
sb.append(lineLast.get(0));
}
@ -92,18 +118,24 @@ public class CommandLinkLongActivity2 extends CommandMultilines<ActivityDiagram>
final String code = lineLast.get(1) == null ? display : lineLast.get(1);
final Entity entity2 = getSystem().createEntity(code, display, EntityType.ACTIVITY);
if (lineLast.get(2)!=null) {
entity2.setStereotype(new Stereotype(lineLast.get(2)));
}
if (lineLast.get(3)!=null) {
entity2.setSpecificBackcolor(lineLast.get(3));
}
if (entity1 == null || entity2 == null) {
return CommandExecutionResult.error("No such entity");
}
final String arrow = StringUtils.manageArrowForCuca(line0.get(5));
final String arrow = StringUtils.manageArrowForCuca(line0.get("ARROW").get(0));
final int lenght = arrow.length() - 1;
final String linkLabel = line0.get(6);
final String linkLabel = line0.get("BRACKET").get(0);
Link link = new Link(entity1, entity2, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), linkLabel, lenght);
final Direction direction = StringUtils.getArrowDirection(line0.get(5));
final Direction direction = StringUtils.getArrowDirection(line0.get("ARROW").get(0));
if (direction == Direction.LEFT || direction == Direction.UP) {
link = link.getInv();
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5019 $
* Revision $Revision: 5751 $
*
*/
package net.sourceforge.plantuml.activitydiagram.command;
@ -56,7 +56,7 @@ public class CommandMultilinesNoteActivity extends CommandMultilines<ActivityDia
public final CommandExecutionResult execute(List<String> lines) {
final List<String> line0 = StringUtils.getSplit(getStartingPattern(), lines.get(0));
final List<String> line0 = StringUtils.getSplit(getStartingPattern(), lines.get(0).trim());
final String pos = line0.get(0);
IEntity activity = getSystem().getLastEntityConsulted();
@ -64,7 +64,7 @@ public class CommandMultilinesNoteActivity extends CommandMultilines<ActivityDia
activity = getSystem().getStart();
}
final List<String> strings = lines.subList(1, lines.size() - 1);
final List<String> strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1));
final String s = StringUtils.getMergedLines(strings);
final Entity note = getSystem().createEntity("GMN" + UniqueSequence.getValue(), s, EntityType.NOTE);

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4762 $
* Revision $Revision: 5751 $
*
*/
package net.sourceforge.plantuml.activitydiagram.command;
@ -49,7 +49,7 @@ public class CommandMultilinesNoteActivityLink extends CommandMultilines<Activit
public final CommandExecutionResult execute(List<String> lines) {
final List<String> strings = lines.subList(1, lines.size() - 1);
final List<String> strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1));
final String s = StringUtils.getMergedLines(strings);
final Link link = getSystem().getLastActivityLink();

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5354 $
* Revision $Revision: 5877 $
*
*/
package net.sourceforge.plantuml.ant;
@ -145,7 +145,7 @@ public class PlantUmlTask extends Task {
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.getFileFormat());
.getConfig(), option.getCharset(), option.getFileFormatOption());
final Collection<GeneratedImage> result = sourceFileReader.getGeneratedImages();
for (GeneratedImage g : result) {
this.log(g + " " + g.getDescription());
@ -198,6 +198,15 @@ public class PlantUmlTask extends Task {
}
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);
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5354 $
* Revision $Revision: 5877 $
*
*/
package net.sourceforge.plantuml.ant;
@ -145,7 +145,7 @@ public class PlantuTask extends Task {
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.getFileFormat());
.getConfig(), option.getCharset(), option.getFileFormatOption());
final Collection<GeneratedImage> result = sourceFileReader.getGeneratedImages();
for (GeneratedImage g : result) {
this.log(g + " " + g.getDescription());
@ -198,6 +198,15 @@ public class PlantuTask extends Task {
}
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);
}

View File

@ -1,77 +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 net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.classdiagram.ClassDiagram;
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.Stereotype;
public class CommandCreateEntityClass extends SingleLineCommand<ClassDiagram> {
public CommandCreateEntityClass(ClassDiagram diagram) {
super(
diagram,
"(?i)^(interface|enum|abstract\\s+class|abstract|class)\\s+(?:\"([^\"]+)\"\\s+as\\s+)?(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)(?:\\s*([\\<\\[]{2}.*[\\>\\]]{2}))?$");
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
final String arg0 = arg.get(0).toUpperCase();
final EntityType type = EntityType.getEntityType(arg0);
final String code = arg.get(2);
final String display = arg.get(1);
final String stereotype = arg.get(3);
final Entity entity;
if (getSystem().entityExist(code)) {
// return CommandExecutionResult.error("Class already exists : "
// + code);
entity = (Entity) getSystem().getOrCreateEntity(code, type);
entity.muteToType(type);
} else {
entity = getSystem().createEntity(code, display, type);
}
if (stereotype != null) {
entity.setStereotype(new Stereotype(stereotype, getSystem().getSkinParam().getCircledCharacterRadius(),
getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER)));
}
return CommandExecutionResult.ok();
}
}

View File

@ -89,7 +89,7 @@ public class CommandCreateEntityClass2 extends SingleLineCommand2<ClassDiagram>
}
if (stereotype != null) {
entity.setStereotype(new Stereotype(stereotype, getSystem().getSkinParam().getCircledCharacterRadius(),
getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER)));
getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null)));
}
return CommandExecutionResult.ok();
}

View File

@ -1,91 +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: 4161 $
*
*/
package net.sourceforge.plantuml.classdiagram.command;
import java.util.List;
import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.classdiagram.ClassDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.CommandMultilines;
import net.sourceforge.plantuml.cucadiagram.Entity;
import net.sourceforge.plantuml.cucadiagram.EntityType;
import net.sourceforge.plantuml.cucadiagram.Stereotype;
import net.sourceforge.plantuml.skin.VisibilityModifier;
public class CommandCreateEntityClassMultilines extends CommandMultilines<ClassDiagram> {
public CommandCreateEntityClassMultilines(ClassDiagram diagram) {
super(
diagram,
"(?i)^(interface|enum|abstract\\s+class|abstract|class)\\s+(?:\"([^\"]+)\"\\s+as\\s+)?(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)(?:\\s*([\\<\\[]{2}.*[\\>\\]]{2}))?\\s*\\{\\s*$",
"(?i)^\\s*\\}\\s*$");
}
public CommandExecutionResult execute(List<String> lines) {
final List<String> line0 = StringUtils.getSplit(getStartingPattern(), lines.get(0));
final Entity entity = executeArg0(line0);
if (entity == null) {
return CommandExecutionResult.error("No such entity");
}
for (String s : lines.subList(1, lines.size() - 1)) {
if (s.length() > 0 && VisibilityModifier.isVisibilityCharacter(s.charAt(0))) {
getSystem().setVisibilityModifierPresent(true);
}
entity.addFieldOrMethod(s);
}
return CommandExecutionResult.ok();
}
private Entity executeArg0(List<String> arg) {
final String arg0 = arg.get(0).toUpperCase();
final EntityType type = EntityType.getEntityType(arg0);
final String code = arg.get(2);
final String display = arg.get(1);
final String stereotype = arg.get(3);
if (getSystem().entityExist(code)) {
final Entity result = (Entity) getSystem().getOrCreateClass(code);
result.muteToType(type);
return result;
}
final Entity entity = getSystem().createEntity(code, display, type);
if (stereotype != null) {
entity.setStereotype(new Stereotype(stereotype, getSystem().getSkinParam().getCircledCharacterRadius(),
getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER)));
}
return entity;
}
}

View File

@ -37,6 +37,7 @@ import java.util.List;
import java.util.Map;
import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.classdiagram.ClassDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.CommandMultilines2;
@ -68,12 +69,16 @@ public class CommandCreateEntityClassMultilines2 extends CommandMultilines2<Clas
public CommandExecutionResult execute(List<String> lines) {
final Map<String, RegexPartialMatch> line0 = getStartingPattern().matcher(lines.get(0));
StringUtils.trim(lines);
final Map<String, RegexPartialMatch> line0 = getStartingPattern().matcher(lines.get(0).trim());
final Entity entity = executeArg0(line0);
if (entity == null) {
return CommandExecutionResult.error("No such entity");
}
for (String s : lines.subList(1, lines.size() - 1)) {
if (s.length()==0) {
continue;
}
if (s.length() > 0 && VisibilityModifier.isVisibilityCharacter(s.charAt(0))) {
getSystem().setVisibilityModifierPresent(true);
}
@ -107,7 +112,7 @@ public class CommandCreateEntityClassMultilines2 extends CommandMultilines2<Clas
final Entity entity = getSystem().createEntity(code, display, type);
if (stereotype != null) {
entity.setStereotype(new Stereotype(stereotype, getSystem().getSkinParam().getCircledCharacterRadius(),
getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER)));
getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null)));
}
return entity;
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5436 $
* Revision $Revision: 5848 $
*
*/
package net.sourceforge.plantuml.classdiagram.command;
@ -86,7 +86,7 @@ final public class CommandLinkClass extends SingleLineCommand<AbstractClassOrObj
public CommandLinkClass(AbstractClassOrObjectDiagram diagram) {
super(
diagram,
"(?i)^(?:@(\\d+)\\s+)?((?:"
"(?i)^(?:@([\\d.]+)\\s+)?((?:"
+ optionalKeywords(diagram.getUmlDiagramType())
+ "\\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*\\)"
@ -225,7 +225,7 @@ final public class CommandLinkClass extends SingleLineCommand<AbstractClassOrObj
// }
// }
} else {
link.setWeight(Integer.parseInt(arg0));
link.setWeight(Double.parseDouble(arg0));
}
}

View File

@ -36,6 +36,7 @@ package net.sourceforge.plantuml.classdiagram.command;
import java.util.Map;
import net.sourceforge.plantuml.Direction;
import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.UmlDiagramType;
import net.sourceforge.plantuml.command.CommandExecutionResult;
@ -51,6 +52,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.cucadiagram.Stereotype;
import net.sourceforge.plantuml.objectdiagram.AbstractClassOrObjectDiagram;
final public class CommandLinkClass2 extends SingleLineCommand2<AbstractClassOrObjectDiagram> {
@ -61,10 +63,10 @@ final public class CommandLinkClass2 extends SingleLineCommand2<AbstractClassOrO
static RegexConcat getRegexConcat(UmlDiagramType umlDiagramType) {
return new RegexConcat(
new RegexLeaf("HEADER", "^(?:@(\\d+)\\s+)?"),
new RegexLeaf("HEADER", "^(?:@([\\d.]+)\\s+)?"),
new RegexOr(
new RegexLeaf("ENT1", "(?:" + optionalKeywords(umlDiagramType) + "\\s+)?"
+ "(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*|\"[^\"]+\")"),
+ "(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*|\"[^\"]+\")\\s*(\\<\\<.*\\>\\>)?"),
new RegexLeaf("COUPLE1",
"\\(\\s*(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s*,\\s*(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s*\\)")),
new RegexLeaf("\\s*"),
@ -83,7 +85,7 @@ final public class CommandLinkClass2 extends SingleLineCommand2<AbstractClassOrO
new RegexLeaf("\\s*"),
new RegexOr(
new RegexLeaf("ENT2", "(?:" + optionalKeywords(umlDiagramType) + "\\s+)?"
+ "(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*|\"[^\"]+\")"),
+ "(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*|\"[^\"]+\")\\s*(\\<\\<.*\\>\\>)?"),
new RegexLeaf("COUPLE2",
"\\(\\s*(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s*,\\s*(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s*\\)")),
new RegexLeaf("\\s*"), new RegexLeaf("LABEL_LINK", "(?::\\s*([^\"]+))?$"));
@ -133,6 +135,14 @@ final public class CommandLinkClass2 extends SingleLineCommand2<AbstractClassOrO
cl2.muteToType(type);
}
}
if (arg.get("ENT1").get(2) != null) {
cl1.setStereotype(new Stereotype(arg.get("ENT1").get(2), getSystem().getSkinParam().getCircledCharacterRadius(),
getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null)));
}
if (arg.get("ENT2").get(2) != null) {
cl2.setStereotype(new Stereotype(arg.get("ENT2").get(2), getSystem().getSkinParam().getCircledCharacterRadius(),
getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null)));
}
final LinkType linkType = getLinkType(arg);
Direction dir = getDirection(arg);
@ -177,7 +187,7 @@ final public class CommandLinkClass2 extends SingleLineCommand2<AbstractClassOrO
// }
// }
} else {
link.setWeight(Integer.parseInt(arg0));
link.setWeight(Double.parseDouble(arg0));
}
}

View File

@ -73,7 +73,7 @@ final public class CommandLinkLollipop extends SingleLineCommand<AbstractClassOr
public 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*"
"(?i)^(?:@([\\d.])\\s+)?((?:(interface|enum|abstract\\s+class|abstract|class)\\s+)?(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)|\\(\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*,\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*\\))\\s*(?:\"([^\"]+)\")?\\s*"
// +
// "(?:(([-=.]+)([\\]>o*+]|\\|[>\\]])?)|(([\\[<o*+]|[<\\[]\\|)?([-=.]+))|(\\<([-=.]+)([o*]))|(([o*])([-=.]+)\\>))"
+ "(?:\\(\\)([-=.]+)|([-=.]+)\\(\\))"
@ -158,7 +158,7 @@ final public class CommandLinkLollipop extends SingleLineCommand<AbstractClassOr
// }
// }
} else {
link.setWeight(Integer.parseInt(arg0));
link.setWeight(Double.parseDouble(arg0));
}
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5654 $
* Revision $Revision: 5728 $
*
*/
package net.sourceforge.plantuml.classdiagram.command;
@ -54,7 +54,7 @@ public class CommandStereotype extends SingleLineCommand<ClassDiagram> {
final String stereotype = arg.get(1);
final Entity entity = (Entity) getSystem().getOrCreateClass(code);
entity.setStereotype(new Stereotype(stereotype, getSystem().getSkinParam().getCircledCharacterRadius(),
getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER)));
getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null)));
return CommandExecutionResult.ok();
}

View File

@ -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: 3827 $
*
*/
package net.sourceforge.plantuml.code;
import java.io.IOException;
import java.util.zip.DataFormatException;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
public class CompressionZlib implements Compression {
public byte[] compress(byte[] in) {
int len = in.length * 2;
byte[] result = null;
while (result == null) {
result = tryCompress(in, len);
len *= 2;
}
return result;
}
private byte[] tryCompress(byte[] in, final int len) {
// Compress the bytes
final Deflater compresser = new Deflater(9, true);
compresser.setInput(in);
compresser.finish();
final byte[] output = new byte[len];
final int compressedDataLength = compresser.deflate(output);
if (compresser.finished() == false) {
return null;
}
final byte[] result = copyArray(output, compressedDataLength);
return result;
}
public byte[] decompress(byte[] in) throws IOException {
final byte in2[] = new byte[in.length + 256];
for (int i = 0; i < in.length; i++) {
in2[i] = in[i];
}
int len = in.length * 5;
byte[] result = null;
while (result == null) {
result = tryDecompress(in2, len);
len *= 2;
}
return result;
}
private byte[] tryDecompress(byte[] in, final int len) throws IOException {
// Decompress the bytes
final byte[] tmp = new byte[len];
final Inflater decompresser = new Inflater(true);
decompresser.setInput(in);
try {
final int resultLength = decompresser.inflate(tmp);
if (decompresser.finished() == false) {
return null;
}
decompresser.end();
final byte[] result = copyArray(tmp, resultLength);
return result;
} catch (DataFormatException e) {
e.printStackTrace();
throw new IOException(e.toString());
}
}
private byte[] copyArray(final byte[] data, final int len) {
final byte[] result = new byte[len];
for (int i = 0; i < result.length; i++) {
result[i] = data[i];
}
return result;
}
}

View File

@ -28,48 +28,16 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 3827 $
* Revision $Revision: 5669 $
*
*/
package net.sourceforge.plantuml.code;
import java.io.IOException;
public class Transcoder {
public interface Transcoder {
private final Compression compression;
private final URLEncoder urlEncoder;
private final StringCompressor stringCompressor;
public Transcoder() {
this(new AsciiEncoder(), new CompressionHuffman());
}
public Transcoder(URLEncoder urlEncoder, Compression compression) {
this(urlEncoder, new ArobaseStringCompressor(), compression);
}
public Transcoder(URLEncoder urlEncoder, StringCompressor stringCompressor, Compression compression) {
this.compression = compression;
this.urlEncoder = urlEncoder;
this.stringCompressor = stringCompressor;
}
public String encode(String text) throws IOException {
final String stringAnnoted = stringCompressor.compress(text);
final byte[] data = stringAnnoted.getBytes("UTF-8");
final byte[] compressedData = compression.compress(data);
return urlEncoder.encode(compressedData);
}
public String decode(String code) throws IOException {
final byte compressedData[] = urlEncoder.decode(code);
final byte data[] = compression.decompress(compressedData);
return stringCompressor.decompress(new String(data, "UTF-8"));
}
public String encode(String text) throws IOException;
public String decode(String code) throws IOException;
}

View File

@ -0,0 +1,75 @@
/* ========================================================================
* 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: 5667 $
*
*/
package net.sourceforge.plantuml.code;
import java.io.IOException;
public class TranscoderImpl implements Transcoder {
private final Compression compression;
private final URLEncoder urlEncoder;
private final StringCompressor stringCompressor;
public TranscoderImpl() {
this(new AsciiEncoder(), new CompressionHuffman());
}
public TranscoderImpl(URLEncoder urlEncoder, Compression compression) {
this(urlEncoder, new ArobaseStringCompressor(), compression);
}
public TranscoderImpl(URLEncoder urlEncoder, StringCompressor stringCompressor, Compression compression) {
this.compression = compression;
this.urlEncoder = urlEncoder;
this.stringCompressor = stringCompressor;
}
public String encode(String text) throws IOException {
final String stringAnnoted = stringCompressor.compress(text);
final byte[] data = stringAnnoted.getBytes("UTF-8");
final byte[] compressedData = compression.compress(data);
return urlEncoder.encode(compressedData);
}
public String decode(String code) throws IOException {
final byte compressedData[] = urlEncoder.decode(code);
final byte data[] = compression.decompress(compressedData);
return stringCompressor.decompress(new String(data, "UTF-8"));
}
}

View File

@ -0,0 +1,54 @@
/* ========================================================================
* 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: 5667 $
*
*/
package net.sourceforge.plantuml.code;
import java.io.IOException;
public class TranscoderSmart implements Transcoder {
private final Transcoder oldOne = new TranscoderImpl(new AsciiEncoder(), new CompressionHuffman());
private final Transcoder zlib = new TranscoderImpl(new AsciiEncoder(), new CompressionZlib());
public String decode(String code) throws IOException {
try {
return zlib.decode(code);
} catch (Exception ex) {
return oldOne.decode(code);
}
}
public String encode(String text) throws IOException {
return zlib.encode(text);
}
}

View File

@ -28,12 +28,15 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 3836 $
* Revision $Revision: 5667 $
*
*/
package net.sourceforge.plantuml.sequencediagram.graphic;
package net.sourceforge.plantuml.code;
public enum VirtualHBarType {
START, END
public class TranscoderUtil {
public static Transcoder getDefaultTranscoder() {
return new TranscoderSmart();
}
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5019 $
* Revision $Revision: 5751 $
*
*/
package net.sourceforge.plantuml.command;
@ -53,12 +53,12 @@ public abstract class AbstractCommandMultilinesNoteEntity extends CommandMultili
public final CommandExecutionResult execute(List<String> lines) {
final List<String> line0 = StringUtils.getSplit(getStartingPattern(), lines.get(0));
final List<String> line0 = StringUtils.getSplit(getStartingPattern(), lines.get(0).trim());
final String pos = line0.get(0);
final IEntity cl1 = getSystem().getOrCreateClass(line0.get(1));
final List<String> strings = lines.subList(1, lines.size() - 1);
final List<String> strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1));
final String s = StringUtils.getMergedLines(strings);
final Entity note = getSystem().createEntity("GMN" + UniqueSequence.getValue(), s, EntityType.NOTE);

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5504 $
* Revision $Revision: 5764 $
*
*/
package net.sourceforge.plantuml.command;
@ -77,6 +77,7 @@ public abstract class AbstractUmlSystemCommandFactory implements PSystemCommandF
protected abstract void initCommands();
final protected void addCommonCommands(UmlDiagram system) {
addCommand(new CommandNope(system));
addCommand(new CommandPragma(system));
addCommand(new CommandTitle(system));
addCommand(new CommandMultilinesTitle(system));
@ -88,6 +89,7 @@ public abstract class AbstractUmlSystemCommandFactory implements PSystemCommandF
addCommand(new CommandMultilinesHeader(system));
addCommand(new CommandSkinParam(system));
addCommand(new CommandSkinParamMultilines(system));
addCommand(new CommandMinwidth(system));
addCommand(new CommandRotate(system));
addCommand(new CommandScale(system));

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5041 $
* Revision $Revision: 5749 $
*
*/
package net.sourceforge.plantuml.command;
@ -62,7 +62,7 @@ public abstract class CommandMultilines<S extends PSystem> implements Command {
if (isCommandForbidden()) {
return CommandControl.NOT_OK;
}
Matcher m1 = starting.matcher(lines.get(0));
Matcher m1 = starting.matcher(lines.get(0).trim());
if (m1.matches() == false) {
return CommandControl.NOT_OK;
}
@ -70,7 +70,7 @@ public abstract class CommandMultilines<S extends PSystem> implements Command {
return CommandControl.OK_PARTIAL;
}
m1 = ending.matcher(lines.get(lines.size() - 1));
m1 = ending.matcher(lines.get(lines.size() - 1).trim());
if (m1.matches() == false) {
return CommandControl.OK_PARTIAL;
}

View File

@ -63,8 +63,7 @@ public abstract class CommandMultilines2<S extends PSystem> implements Command {
if (isCommandForbidden()) {
return CommandControl.NOT_OK;
}
//Matcher m1 = starting.matcher(lines.get(0));
final boolean result1 = starting.match(lines.get(0));
final boolean result1 = starting.match(lines.get(0).trim());
if (result1 == false) {
return CommandControl.NOT_OK;
}
@ -72,7 +71,7 @@ public abstract class CommandMultilines2<S extends PSystem> implements Command {
return CommandControl.OK_PARTIAL;
}
Matcher m1 = ending.matcher(lines.get(lines.size() - 1));
Matcher m1 = ending.matcher(lines.get(lines.size() - 1).trim());
if (m1.matches() == false) {
return CommandControl.OK_PARTIAL;
}

View File

@ -0,0 +1,117 @@
/* ========================================================================
* 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: 5041 $
*
*/
package net.sourceforge.plantuml.command;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sourceforge.plantuml.PSystem;
public abstract class CommandMultilinesBracket<S extends PSystem> implements Command {
private final S system;
private final Pattern starting;
public CommandMultilinesBracket(final S system, String patternStart) {
if (patternStart.startsWith("(?i)^") == false || patternStart.endsWith("$") == false) {
throw new IllegalArgumentException("Bad pattern " + patternStart);
}
this.system = system;
this.starting = Pattern.compile(patternStart);
}
protected boolean isCommandForbidden() {
return false;
}
protected void actionIfCommandValid() {
}
protected S getSystem() {
return system;
}
protected final Pattern getStartingPattern() {
return starting;
}
public boolean isDeprecated(List<String> line) {
return false;
}
public String getHelpMessageForDeprecated(List<String> lines) {
return null;
}
final public CommandControl isValid(List<String> lines) {
if (isCommandForbidden()) {
return CommandControl.NOT_OK;
}
final Matcher m1 = starting.matcher(lines.get(0).trim());
if (m1.matches() == false) {
return CommandControl.NOT_OK;
}
if (lines.size() == 1) {
return CommandControl.OK_PARTIAL;
}
int level = 1;
for (int i = 1; i < lines.size(); i++) {
final String s = lines.get(i).trim();
if (isLineConsistent(s, level) == false) {
return CommandControl.NOT_OK;
}
if (s.endsWith("{")) {
level++;
}
if (s.endsWith("}")) {
level--;
}
if (level < 0) {
return CommandControl.NOT_OK;
}
}
if (level != 0) {
return CommandControl.OK_PARTIAL;
}
actionIfCommandValid();
return CommandControl.OK;
}
protected abstract boolean isLineConsistent(String line, int level);
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4762 $
* Revision $Revision: 5750 $
*
*/
package net.sourceforge.plantuml.command;
@ -36,6 +36,7 @@ package net.sourceforge.plantuml.command;
import java.util.List;
import java.util.regex.Matcher;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.UmlDiagram;
import net.sourceforge.plantuml.graphic.HorizontalAlignement;
@ -46,7 +47,8 @@ public class CommandMultilinesFooter extends CommandMultilines<UmlDiagram> {
}
public CommandExecutionResult execute(List<String> lines) {
final Matcher m = getStartingPattern().matcher(lines.get(0));
StringUtils.trim(lines);
final Matcher m = getStartingPattern().matcher(lines.get(0).trim());
if (m.find() == false) {
throw new IllegalStateException();
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4762 $
* Revision $Revision: 5750 $
*
*/
package net.sourceforge.plantuml.command;
@ -36,6 +36,7 @@ package net.sourceforge.plantuml.command;
import java.util.List;
import java.util.regex.Matcher;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.UmlDiagram;
import net.sourceforge.plantuml.graphic.HorizontalAlignement;
@ -46,7 +47,8 @@ public class CommandMultilinesHeader extends CommandMultilines<UmlDiagram> {
}
public CommandExecutionResult execute(List<String> lines) {
final Matcher m = getStartingPattern().matcher(lines.get(0));
StringUtils.trim(lines);
final Matcher m = getStartingPattern().matcher(lines.get(0).trim());
if (m.find() == false) {
throw new IllegalStateException();
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4762 $
* Revision $Revision: 5751 $
*
*/
package net.sourceforge.plantuml.command;
@ -47,9 +47,9 @@ public class CommandMultilinesStandaloneNote extends CommandMultilines<AbstractE
public CommandExecutionResult execute(List<String> lines) {
final List<String> line0 = StringUtils.getSplit(getStartingPattern(), lines.get(0));
final List<String> line0 = StringUtils.getSplit(getStartingPattern(), lines.get(0).trim());
final List<String> strings = lines.subList(1, lines.size() - 1);
final List<String> strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1));
final String display = StringUtils.getMergedLines(strings);
final EntityType type = EntityType.NOTE;

View File

@ -28,13 +28,14 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4765 $
* Revision $Revision: 5752 $
*
*/
package net.sourceforge.plantuml.command;
import java.util.List;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.UmlDiagram;
public class CommandMultilinesTitle extends CommandMultilines<UmlDiagram> {
@ -44,7 +45,7 @@ public class CommandMultilinesTitle extends CommandMultilines<UmlDiagram> {
}
public CommandExecutionResult execute(List<String> lines) {
final List<String> strings = lines.subList(1, lines.size() - 1);
final List<String> strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1));
if (strings.size() > 0) {
getSystem().setTitle(strings);
return CommandExecutionResult.ok();

View File

@ -0,0 +1,51 @@
/* ========================================================================
* 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: 4762 $
*
*/
package net.sourceforge.plantuml.command;
import java.util.List;
import net.sourceforge.plantuml.UmlDiagram;
public class CommandNope extends SingleLineCommand<UmlDiagram> {
public CommandNope(UmlDiagram diagram) {
super(diagram, "(?i)^\\s*$");
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
return CommandExecutionResult.ok();
}
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4762 $
* Revision $Revision: 5769 $
*
*/
package net.sourceforge.plantuml.command;
@ -40,7 +40,7 @@ import net.sourceforge.plantuml.UmlDiagram;
public class CommandSkinParam extends SingleLineCommand<UmlDiagram> {
public CommandSkinParam(UmlDiagram diagram) {
super(diagram, "(?i)^skinparam\\s+(\\w+)\\s+(.*)$");
super(diagram, "(?i)^skinparam\\s+([\\w.]*(?:\\<\\<.*\\>\\>)?[\\w.]*)\\s+([^{}]*)$");
}
@Override

View File

@ -0,0 +1,116 @@
/* ========================================================================
* 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: 5727 $
*
*/
package net.sourceforge.plantuml.command;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.UmlDiagram;
public class CommandSkinParamMultilines extends CommandMultilinesBracket<UmlDiagram> {
static class Context {
private List<String> strings = new ArrayList<String>();
public void push(String s) {
strings.add(s);
}
public void pop() {
strings.remove(strings.size() - 1);
}
public String getFullParam() {
final StringBuilder sb = new StringBuilder();
for (String s : strings) {
sb.append(s);
}
return sb.toString();
}
}
private final static Pattern p1 = Pattern.compile("^([\\w.]*(?:\\<\\<.*\\>\\>)?[\\w.]*)\\s+(?:(\\{)|(.*))$|^\\}?$");
public CommandSkinParamMultilines(UmlDiagram diagram) {
super(diagram, "(?i)^skinparam\\s*(?:\\s+([\\w.]*(?:\\<\\<.*\\>\\>)?[\\w.]*))?\\s*\\{$");
}
@Override
protected boolean isLineConsistent(String line, int level) {
line = line.trim();
return p1.matcher(line).matches();
}
public CommandExecutionResult execute(List<String> lines) {
final Context context = new Context();
final Matcher mStart = getStartingPattern().matcher(lines.get(0).trim());
if (mStart.find() == false) {
throw new IllegalStateException();
}
if (mStart.group(1) != null) {
context.push(mStart.group(1));
}
lines = new ArrayList<String>(lines.subList(1, lines.size() - 1));
StringUtils.trim(lines);
for (String s : lines) {
if (s.length() == 0) {
continue;
}
if (s.equals("}")) {
context.pop();
continue;
}
final Matcher m = p1.matcher(s);
if (m.find() == false) {
throw new IllegalStateException();
}
if (m.group(2) != null) {
context.push(m.group(1));
} else if (m.group(3) != null) {
final String key = context.getFullParam() + m.group(1);
getSystem().setParam(key, m.group(3));
} else {
throw new IllegalStateException();
}
}
return CommandExecutionResult.ok();
}
}

View File

@ -78,7 +78,7 @@ public abstract class RegexComposed implements IRegex {
public Map<String, RegexPartialMatch> matcher(String s) {
final Matcher matcher = getFull().matcher(s);
if (matcher.find() == false) {
throw new IllegalArgumentException(s);
throw new IllegalArgumentException(getClass()+" "+s);
}
final Iterator<String> it = new MatcherIterator(matcher);

View File

@ -45,7 +45,7 @@ public class RegexConcat extends RegexComposed implements IRegex {
for (IRegex p : partial) {
sb.append(p.getPattern());
}
this.full = Pattern.compile(sb.toString());
this.full = Pattern.compile(sb.toString(), Pattern.CASE_INSENSITIVE);
}
@Override

View File

@ -48,6 +48,10 @@ public class RegexOr extends RegexComposed implements IRegex {
}
public RegexOr(String name, IRegex... partial) {
this(name, false, partial);
}
public RegexOr(String name, boolean optionnal, IRegex... partial) {
super(partial);
this.name = name;
final StringBuilder sb = new StringBuilder("(");
@ -60,6 +64,9 @@ public class RegexOr extends RegexComposed implements IRegex {
}
sb.setLength(sb.length() - 1);
sb.append(')');
if (optionnal) {
sb.append('?');
}
this.full = Pattern.compile(sb.toString());
}

View File

@ -76,7 +76,7 @@ public class CommandCreateActorInComponent extends SingleLineCommand<ComponentDi
if (stereotype != null) {
entity.setStereotype(new Stereotype(stereotype, getSystem().getSkinParam().getCircledCharacterRadius(),
getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER)));
getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null)));
}
return CommandExecutionResult.ok();
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5019 $
* Revision $Revision: 5728 $
*
*/
package net.sourceforge.plantuml.componentdiagram.command;
@ -78,7 +78,7 @@ public class CommandCreateCircleInterface extends SingleLineCommand<ComponentDia
entity.setDisplay(display);
if (stereotype != null) {
entity.setStereotype(new Stereotype(stereotype, getSystem().getSkinParam().getCircledCharacterRadius(),
getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER)));
getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null)));
}
return CommandExecutionResult.ok();
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5019 $
* Revision $Revision: 5728 $
*
*/
package net.sourceforge.plantuml.componentdiagram.command;
@ -78,7 +78,7 @@ public class CommandCreateComponent extends SingleLineCommand<ComponentDiagram>
entity.setDisplay(display);
if (stereotype != null) {
entity.setStereotype(new Stereotype(stereotype, getSystem().getSkinParam().getCircledCharacterRadius(),
getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER)));
getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null)));
}
return CommandExecutionResult.ok();
}

View File

@ -1,128 +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: 5443 $
*
*/
package net.sourceforge.plantuml.componentdiagram.command;
import java.util.List;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand;
import net.sourceforge.plantuml.componentdiagram.ComponentDiagram;
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;
public class CommandLinkComponent extends SingleLineCommand<ComponentDiagram> {
public CommandLinkComponent(ComponentDiagram diagram) {
super(
diagram,
"(?i)^([\\p{L}0-9_.]+|:[^:]+:|\\[[^\\]*]+[^\\]]*\\]|\\(\\)\\s*[\\p{L}0-9_.]+|\\(\\)\\s*\"[^\"]+\")\\s*"
+ "(?:("
+ "([=-]+(?:left|right|up|down|le?|ri?|up?|do?)?[=-]*|\\.+(?:left|right|up|down|le?|ri?|up?|do?)?\\.*)([\\]>]|\\|[>\\]])?"
+ ")|("
+ "([\\[<]|[<\\[]\\|)?([=-]*(?:left|right|up|down|le?|ri?|up?|do?)?[=-]+|\\.*(?:left|right|up|down|le?|ri?|up?|do?)?\\.+)"
+ "))"
+ "\\s*([\\p{L}0-9_.]+|:[^:]+:|\\[[^\\]*]+[^\\]]*\\]|\\(\\)\\s*[\\p{L}0-9_.]+|\\(\\)\\s*\"[^\"]+\")\\s*(?::\\s*([^\"]+))?$");
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
if (getSystem().isGroup(arg.get(0)) && getSystem().isGroup(arg.get(7))) {
return executePackageLink(arg);
}
if (getSystem().isGroup(arg.get(0)) || getSystem().isGroup(arg.get(7))) {
return CommandExecutionResult.error("Package can be only linked to other package");
}
final IEntity cl1 = getSystem().getOrCreateClass(arg.get(0));
final IEntity cl2 = getSystem().getOrCreateClass(arg.get(7));
final LinkType linkType = arg.get(1) != null ? getLinkTypeNormal(arg) : getLinkTypeInv(arg);
final String queue = arg.get(1) != null ? arg.get(2) : arg.get(6);
final Link link = new Link(cl1, cl2, linkType, arg.get(8), queue.length());
getSystem().addLink(link);
return CommandExecutionResult.ok();
}
private CommandExecutionResult executePackageLink(List<String> arg) {
final Group cl1 = getSystem().getGroup(arg.get(0));
final Group cl2 = getSystem().getGroup(arg.get(7));
final LinkType linkType = arg.get(1) != null ? getLinkTypeNormal(arg) : getLinkTypeInv(arg);
final String queue = arg.get(1) != null ? arg.get(2) : arg.get(6);
final Link link = new Link(cl1.getEntityCluster(), cl2.getEntityCluster(), linkType, arg.get(8), queue.length());
getSystem().addLink(link);
return CommandExecutionResult.ok();
}
private LinkType getLinkTypeNormal(List<String> arg) {
final String queue = arg.get(2);
final String key = arg.get(3);
LinkType linkType = getLinkTypeFromKey(key);
if (queue.startsWith(".")) {
linkType = linkType.getDashed();
}
return linkType;
}
private LinkType getLinkTypeInv(List<String> arg) {
final String queue = arg.get(6);
final String key = arg.get(5);
LinkType linkType = getLinkTypeFromKey(key);
if (queue.startsWith(".")) {
linkType = linkType.getDashed();
}
return linkType.getInv();
}
private LinkType getLinkTypeFromKey(String k) {
if (k == null) {
return new LinkType(LinkDecor.NONE, LinkDecor.NONE);
}
if (k.equals("<") || k.equals(">")) {
return new LinkType(LinkDecor.ARROW, LinkDecor.NONE);
}
if (k.equals("<|") || k.equals("|>")) {
return new LinkType(LinkDecor.EXTENDS, LinkDecor.NONE);
}
return null;
}
}

View File

@ -49,6 +49,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.cucadiagram.Stereotype;
public class CommandLinkComponent2 extends SingleLineCommand2<ComponentDiagram> {
@ -68,7 +69,7 @@ public class CommandLinkComponent2 extends SingleLineCommand2<ComponentDiagram>
private static RegexLeaf getRegexGroup(String name) {
return new RegexLeaf(name,
"([\\p{L}0-9_.]+|:[^:]+:|\\[[^\\]*]+[^\\]]*\\]|\\(\\)\\s*[\\p{L}0-9_.]+|\\(\\)\\s*\"[^\"]+\")");
"([\\p{L}0-9_.]+|:[^:]+:|\\[[^\\]*]+[^\\]]*\\]|\\(\\)\\s*[\\p{L}0-9_.]+|\\(\\)\\s*\"[^\"]+\")(?:\\s*(\\<\\<.*\\>\\>))?");
}
@Override
@ -86,6 +87,14 @@ public class CommandLinkComponent2 extends SingleLineCommand2<ComponentDiagram>
final IEntity cl1 = getSystem().getOrCreateClass(g1);
final IEntity cl2 = getSystem().getOrCreateClass(g2);
if (arg.get("G1").get(1) != null) {
cl1.setStereotype(new Stereotype(arg.get("G1").get(1)));
}
if (arg.get("G2").get(1) != null) {
cl2.setStereotype(new Stereotype(arg.get("G2").get(1)));
}
final LinkType linkType;
String queue;
if (arg.get("AR_TO_RIGHT").get(0) != null) {

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5584 $
* Revision $Revision: 5877 $
*
*/
package net.sourceforge.plantuml.cucadiagram;
@ -49,6 +49,7 @@ import java.util.Set;
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;
@ -57,6 +58,7 @@ 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.xmi.CucaDiagramXmiMaker;
public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, PortionShower {
@ -268,13 +270,19 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy,
abstract protected List<String> getDotStrings();
final public List<File> createFiles(File suggestedFile, FileFormat fileFormat) throws IOException,
final public List<File> createFiles(File suggestedFile, FileFormatOption fileFormatOption) throws IOException,
InterruptedException {
final FileFormat fileFormat = fileFormatOption.getFileFormat();
if (fileFormat == FileFormat.ATXT || fileFormat == FileFormat.UTXT) {
return createFilesTxt(suggestedFile, fileFormat);
}
if (fileFormat.name().startsWith("XMI")) {
return createFilesXmi(suggestedFile, fileFormat);
}
if (OptionFlags.getInstance().useJavaInsteadOfDot()) {
return createPng2(suggestedFile);
}
@ -283,7 +291,12 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy,
return maker.createFile(suggestedFile, getDotStrings(), fileFormat);
}
final CucaDiagramFileMaker maker = new CucaDiagramFileMaker(this);
return maker.createFile(suggestedFile, getDotStrings(), fileFormat);
return maker.createFile(suggestedFile, getDotStrings(), fileFormatOption);
}
private List<File> createFilesXmi(File suggestedFile, FileFormat fileFormat) throws IOException {
final CucaDiagramXmiMaker maker = new CucaDiagramXmiMaker(this, fileFormat);
return maker.createFiles(suggestedFile);
}
private List<File> createFilesTxt(File suggestedFile, FileFormat fileFormat) throws IOException {
@ -293,7 +306,8 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy,
public static boolean BETA;
final public void createFile(OutputStream os, int index, FileFormat fileFormat) throws IOException {
final public void createFile(OutputStream os, int index, FileFormatOption fileFormatOption) throws IOException {
final FileFormat fileFormat = fileFormatOption.getFileFormat();
if (fileFormat == FileFormat.ATXT || fileFormat == FileFormat.UTXT) {
createFilesTxt(os, index, fileFormat);
return;
@ -311,7 +325,7 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy,
}
final CucaDiagramFileMaker maker = new CucaDiagramFileMaker(this);
try {
maker.createFile(os, getDotStrings(), fileFormat);
maker.createFile(os, getDotStrings(), fileFormatOption);
} catch (InterruptedException e) {
Log.error(e.toString());
throw new IOException(e.toString());

View File

@ -28,11 +28,13 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5593 $
* Revision $Revision: 5694 $
*
*/
package net.sourceforge.plantuml.cucadiagram;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -226,4 +228,24 @@ public class Entity implements IEntity {
return uid.equals(other.getUid());
}
private final List<DrawFile> subImages = new ArrayList<DrawFile>();
public void addSubImage(DrawFile subImage) {
if (subImage == null) {
throw new IllegalArgumentException();
}
subImages.add(subImage);
}
public DrawFile getImageFile(File searched) throws IOException {
if (imageFile != null && imageFile.getPng().getCanonicalFile().equals(searched)) {
return imageFile;
}
for (DrawFile f : subImages) {
if (f.getPng().getCanonicalFile().equals(searched)) {
return f;
}
}
return null;
}
}

View File

@ -33,6 +33,8 @@
*/
package net.sourceforge.plantuml.cucadiagram;
import java.io.File;
import java.io.IOException;
import java.util.List;
import net.sourceforge.plantuml.cucadiagram.dot.DrawFile;
@ -61,6 +63,10 @@ public abstract class EntityUtils {
return ent.getStereotype();
}
public void setStereotype(Stereotype stereotype) {
ent.setStereotype(stereotype);
}
public EntityType getType() {
return ent.getType();
}
@ -108,6 +114,10 @@ public abstract class EntityUtils {
return ent.getCode();
}
public DrawFile getImageFile(File searched) throws IOException {
return ent.getImageFile(searched);
}
};
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5190 $
* Revision $Revision: 5743 $
*
*/
package net.sourceforge.plantuml.cucadiagram;
@ -260,4 +260,14 @@ public class Group {
this.rankdir = rankdir;
}
private String stereotype;
public final void setStereotype(String stereotype) {
this.stereotype = stereotype;
}
public final String getStereotype() {
return stereotype;
}
}

View File

@ -33,9 +33,12 @@
*/
package net.sourceforge.plantuml.cucadiagram;
import java.io.File;
import java.io.IOException;
import java.util.List;
import net.sourceforge.plantuml.SpecificBackcolorable;
import net.sourceforge.plantuml.cucadiagram.dot.DrawFile;
public interface IEntity extends Imaged, SpecificBackcolorable {
@ -53,8 +56,12 @@ public interface IEntity extends Imaged, SpecificBackcolorable {
public Stereotype getStereotype();
public void setStereotype(Stereotype stereotype);
public List<Member> methods2();
public String getCode();
public DrawFile getImageFile(File searched) throws IOException;
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5649 $
* Revision $Revision: 5848 $
*
*/
package net.sourceforge.plantuml.cucadiagram;
@ -38,7 +38,6 @@ import java.awt.Font;
import java.awt.geom.Dimension2D;
import java.util.Arrays;
import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.UniqueSequence;
import net.sourceforge.plantuml.cucadiagram.dot.DrawFile;
import net.sourceforge.plantuml.graphic.HorizontalAlignement;
@ -61,7 +60,7 @@ public class Link implements Imaged {
private DrawFile imageFile;
private String note;
private boolean invis = false;
private int weight = 1;
private double weight = 1.0;
private final String labeldistance;
private final String labelangle;
@ -178,11 +177,11 @@ public class Link implements Imaged {
return qualifier2;
}
public final int getWeight() {
public final double getWeight() {
return weight;
}
public final void setWeight(int weight) {
public final void setWeight(double weight) {
this.weight = weight;
}

View File

@ -62,7 +62,7 @@ public class Member {
this.display = displayClean;
visibilityModifier = null;
}
assert VisibilityModifier.isVisibilityCharacter(this.display.charAt(0)) == false;
// assert VisibilityModifier.isVisibilityCharacter(this.display.charAt(0)) == false;
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4111 $
* Revision $Revision: 5771 $
*
*/
package net.sourceforge.plantuml.cucadiagram;
@ -77,6 +77,14 @@ public class Stereotype implements CharSequence {
}
}
public Stereotype(String stereotype) {
this.label = stereotype;
this.htmlColor = null;
this.character = '\0';
this.radius = 0;
this.circledFont = null;
}
public Color getColor() {
if (htmlColor == null) {
return null;
@ -89,6 +97,7 @@ public class Stereotype implements CharSequence {
}
public String getLabel() {
assert label == null || label.length() > 0;
return label;
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4826 $
* Revision $Revision: 5794 $
*
*/
package net.sourceforge.plantuml.cucadiagram.dot;
@ -40,6 +40,7 @@ import java.util.ArrayList;
import java.util.List;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.Log;
import net.sourceforge.plantuml.OptionFlags;
import net.sourceforge.plantuml.StringUtils;
@ -85,7 +86,7 @@ abstract class AbstractGraphviz implements Graphviz {
}
if (illegalDotExe()) {
createPngNoGraphviz(os, FileFormat.valueOf(type[0].toUpperCase()));
createPngNoGraphviz(os, new FileFormatOption(FileFormat.valueOf(type[0].toUpperCase())));
return;
}
final String cmd = getCommandLine();
@ -133,7 +134,7 @@ abstract class AbstractGraphviz implements Graphviz {
return sb.toString().replace('\n', ' ').trim();
}
final private void createPngNoGraphviz(OutputStream os, FileFormat format) throws IOException {
final private void createPngNoGraphviz(OutputStream os, FileFormatOption format) throws IOException {
final List<String> msg = new ArrayList<String>();
msg.add("Dot Executable: " + dotExe);
if (dotExe != null) {

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5655 $
* Revision $Revision: 5872 $
*
*/
package net.sourceforge.plantuml.cucadiagram.dot;
@ -51,7 +51,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@ -62,6 +61,8 @@ 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;
import net.sourceforge.plantuml.FileUtils;
import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.Log;
@ -74,6 +75,7 @@ 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.IEntity;
import net.sourceforge.plantuml.cucadiagram.Imaged;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.Stereotype;
@ -92,10 +94,11 @@ import net.sourceforge.plantuml.png.PngScaler;
import net.sourceforge.plantuml.png.PngSizer;
import net.sourceforge.plantuml.png.PngSplitter;
import net.sourceforge.plantuml.png.PngTitler;
import net.sourceforge.plantuml.skin.CircleInterface;
import net.sourceforge.plantuml.skin.Component;
import net.sourceforge.plantuml.skin.ComponentType;
import net.sourceforge.plantuml.skin.SimpleContext2D;
import net.sourceforge.plantuml.skin.VisibilityModifier;
import net.sourceforge.plantuml.skin.StickMan;
import net.sourceforge.plantuml.skin.rose.Rose;
import net.sourceforge.plantuml.svg.SvgTitler;
import net.sourceforge.plantuml.ugraphic.eps.UGraphicEps;
@ -105,7 +108,7 @@ import net.sourceforge.plantuml.ugraphic.svg.UGraphicSvg;
public final class CucaDiagramFileMaker {
private final CucaDiagram diagram;
private final StaticFiles staticFiles;
private final StaticFilesMap staticFilesMap;
private final Rose rose = new Rose();
static private final StringBounder stringBounder;
@ -118,20 +121,25 @@ public final class CucaDiagramFileMaker {
public CucaDiagramFileMaker(CucaDiagram diagram) throws IOException {
HtmlColor.setForceMonochrome(diagram.getSkinParam().isMonochrome());
this.diagram = diagram;
this.staticFiles = new StaticFiles(diagram.getSkinParam());
if (diagram.getUmlDiagramType() == UmlDiagramType.CLASS || diagram.getUmlDiagramType() == UmlDiagramType.OBJECT) {
this.staticFilesMap = new StaticFilesMap(diagram.getSkinParam(), diagram.getDpiFactor(null));
} else {
this.staticFilesMap = null;
}
}
static String changeName(String name) {
return name.replaceAll("(?i)\\.png$", ".cmapx");
}
public List<File> createFile(File suggested, List<String> dotStrings, FileFormat fileFormat) throws IOException,
InterruptedException {
public List<File> createFile(File suggested, List<String> dotStrings, FileFormatOption fileFormatOption)
throws IOException, InterruptedException {
final FileFormat fileFormat = fileFormatOption.getFileFormat();
OutputStream os = null;
try {
os = new FileOutputStream(suggested);
final String cmap = createFile(os, dotStrings, fileFormat);
final String cmap = createFile(os, dotStrings, fileFormatOption);
if (diagram.hasUrl() && fileFormat == FileFormat.PNG) {
final File cmapFile = new File(changeName(suggested.getAbsolutePath()));
final PrintWriter pw = new PrintWriter(cmapFile);
@ -145,8 +153,8 @@ public final class CucaDiagramFileMaker {
}
if (fileFormat == FileFormat.PNG) {
final List<File> result = new PngSplitter(suggested, diagram.getHorizontalPages(),
diagram.getVerticalPages(), diagram.getMetadata()).getFiles();
final List<File> result = new PngSplitter(suggested, diagram.getHorizontalPages(), diagram
.getVerticalPages(), diagram.getMetadata(), diagram.getDpi(fileFormatOption)).getFiles();
for (File f : result) {
Log.info("Creating file: " + f);
}
@ -171,26 +179,28 @@ public final class CucaDiagramFileMaker {
}
public String createFile(OutputStream os, List<String> dotStrings, FileFormat fileFormat) throws IOException,
InterruptedException {
public String createFile(OutputStream os, List<String> dotStrings, FileFormatOption fileFormatOption)
throws IOException, InterruptedException {
final FileFormat fileFormat = fileFormatOption.getFileFormat();
if (fileFormat == FileFormat.PNG) {
return createPng(os, dotStrings);
return createPng(os, dotStrings, fileFormatOption);
} else if (fileFormat == FileFormat.SVG) {
return createSvg(os, dotStrings);
return createSvg(os, dotStrings, fileFormatOption);
} else if (fileFormat == FileFormat.EPS_VIA_SVG) {
return createEpsViaSvg(os, dotStrings);
return createEpsViaSvg(os, dotStrings, fileFormatOption);
} else if (fileFormat == FileFormat.EPS) {
return createEps(os, dotStrings);
return createEps(os, dotStrings, fileFormatOption);
} else {
throw new UnsupportedOperationException();
}
}
private String createEpsViaSvg(OutputStream os, List<String> dotStrings) throws IOException, InterruptedException {
final File svgTmp = createTempFile("svgtmp", ".svg");
private String createEpsViaSvg(OutputStream os, List<String> dotStrings, FileFormatOption fileFormatOption)
throws IOException, InterruptedException {
final File svgTmp = FileUtils.createTempFile("svgtmp", ".svg");
final FileOutputStream svgOs = new FileOutputStream(svgTmp);
final String status = createSvg(svgOs, dotStrings);
final String status = createSvg(svgOs, dotStrings, fileFormatOption);
svgOs.close();
final SvgToEpsConverter converter = new SvgToEpsConverter(svgTmp);
converter.createEps(os);
@ -199,14 +209,14 @@ public final class CucaDiagramFileMaker {
private double deltaY;
private String createSvg(OutputStream os, List<String> dotStrings) throws IOException, InterruptedException {
private String createSvg(OutputStream os, List<String> dotStrings, FileFormatOption fileFormatOption)
throws IOException, InterruptedException {
try {
deltaY = 0;
populateImages();
populateImagesLink();
final GraphvizMaker dotMaker = createDotMaker(staticFiles.getStaticImages(),
staticFiles.getVisibilityImages(), dotStrings, FileFormat.SVG);
populateImages(diagram.getDpiFactor(fileFormatOption), diagram.getDpi(fileFormatOption));
populateImagesLink(diagram.getDpiFactor(fileFormatOption), diagram.getDpi(fileFormatOption));
final GraphvizMaker dotMaker = createDotMaker(dotStrings, fileFormatOption);
final String dotString = dotMaker.createDotString();
if (OptionFlags.getInstance().isKeepTmpFiles()) {
@ -221,7 +231,7 @@ public final class CucaDiagramFileMaker {
baos.close();
dotMaker.clean();
String svg = new String(baos.toByteArray(), "UTF-8");
String svg = new String(baos.toByteArray(), "UTF-8").replace('\\', '/');
final Dimension2D dim = getDimensionSvg(svg);
if (dim != null) {
@ -233,6 +243,9 @@ public final class CucaDiagramFileMaker {
// Image management
final Pattern pImage = Pattern.compile("(?i)<image\\W[^>]*>");
boolean changed;
do {
changed = false;
final Matcher mImage = pImage.matcher(svg);
final StringBuffer sb = new StringBuffer();
while (mImage.find()) {
@ -243,16 +256,23 @@ public final class CucaDiagramFileMaker {
final double x = Double.parseDouble(getValue(image, "x"));
final double y = Double.parseDouble(getValue(image, "y"));
final DrawFile drawFile = getDrawFileFromHref(href);
if (drawFile == null) {
mImage.appendReplacement(sb, image);
} else {
final int widthPng = drawFile.getWidthPng();
final int heightPng = drawFile.getHeightPng();
String svg2 = drawFile.getSvg();
final String scale = getScale(widthSvg, heightSvg, widthPng, heightPng);
svg2 = svg2
.replaceFirst("<[gG]>", "<g transform=\"translate(" + x + " " + y + ") " + scale + "\">");
svg2 = svg2.replaceFirst("<[gG]>", "<g transform=\"translate(" + 0 + " " + 0 + ") " + scale
+ "\">");
svg2 = "<svg x=\"" + x + "\" y=\"" + y + "\">" + svg2 + "</svg>";
mImage.appendReplacement(sb, svg2);
changed = true;
}
}
mImage.appendTail(sb);
svg = sb.toString();
} while (changed);
}
os.write(svg.getBytes("UTF-8"));
@ -326,22 +346,32 @@ public final class CucaDiagramFileMaker {
return new Dimension2DDouble(maxX - minX, maxY - minY);
}
private DrawFile getDrawFileFromHref(final String href) throws IOException {
final DrawFile drawFile = staticFiles.getDrawFile(href);
if (drawFile != null) {
return drawFile;
}
final File searched = new File(href).getCanonicalFile();
for (Entity ent : diagram.entities().values()) {
final DrawFile df = ent.getImageFile();
if (df == null) {
continue;
}
if (df.getPng().getCanonicalFile().equals(searched)) {
private DrawFile searchImageFile(File searched, Collection<? extends IEntity> entities) throws IOException {
for (IEntity ent : entities) {
final DrawFile df = ent.getImageFile(searched);
if (df != null) {
assert df.getPng().getCanonicalFile().equals(searched.getCanonicalFile());
return df;
}
}
return null;
}
private DrawFile getDrawFileFromHref(final String href) throws IOException {
if (diagram.getUmlDiagramType() == UmlDiagramType.CLASS || diagram.getUmlDiagramType() == UmlDiagramType.OBJECT) {
final DrawFile drawFile = staticFilesMap.getDrawFile(href);
if (drawFile != null) {
return drawFile;
}
}
final File searched = new File(href).getCanonicalFile();
final DrawFile result = searchImageFile(searched, diagram.entities().values());
if (result != null) {
return result;
}
for (Link ent : diagram.getLinks()) {
final DrawFile df = ent.getImageFile();
if (df == null) {
@ -351,38 +381,39 @@ public final class CucaDiagramFileMaker {
return df;
}
}
return drawFile;
Log.error("Cannot find " + href);
return null;
}
private String getScale(double widthSvg, double heightSvg, double widthPng, double heightPng) {
private static String getScale(double widthSvg, double heightSvg, double widthPng, double heightPng) {
final double v1 = heightSvg / heightPng;
final double v2 = widthSvg / widthPng;
final double min = Math.min(v1, v2);
return "scale(" + min + " " + min + ")";
}
static String getValue(String s, String param) {
private static String getValue(String s, String param) {
final Pattern p = Pattern.compile("(?i)" + param + "=\"([^\"]+)\"");
final Matcher m = p.matcher(s);
m.find();
return m.group(1);
}
static String getValuePx(String s, String param) {
private static String getValuePx(String s, String param) {
final Pattern p = Pattern.compile("(?i)" + param + "=\"([^\"]+?)(?:px)?\"");
final Matcher m = p.matcher(s);
m.find();
return m.group(1);
}
private String createPng(OutputStream os, List<String> dotStrings) throws IOException, InterruptedException {
private String createPng(OutputStream os, List<String> dotStrings, FileFormatOption fileFormatOption)
throws IOException, InterruptedException {
final StringBuilder cmap = new StringBuilder();
try {
populateImages();
populateImagesLink();
final GraphvizMaker dotMaker = createDotMaker(staticFiles.getStaticImages(),
staticFiles.getVisibilityImages(), dotStrings, FileFormat.PNG);
populateImages(diagram.getDpiFactor(fileFormatOption), diagram.getDpi(fileFormatOption));
populateImagesLink(diagram.getDpiFactor(fileFormatOption), diagram.getDpi(fileFormatOption));
final GraphvizMaker dotMaker = createDotMaker(dotStrings, fileFormatOption);
final String dotString = dotMaker.createDotString();
if (OptionFlags.getInstance().isKeepTmpFiles()) {
@ -392,12 +423,12 @@ public final class CucaDiagramFileMaker {
final byte[] imageData = getImageData(dotString, cmap);
if (imageData.length == 0) {
createError(os, imageData.length, FileFormat.PNG, "imageData.length == 0");
createError(os, imageData.length, new FileFormatOption(FileFormat.PNG), "imageData.length == 0");
return null;
}
if (isPngHeader(imageData, 0) == false) {
createError(os, imageData.length, FileFormat.PNG, "No PNG header found",
createError(os, imageData.length, new FileFormatOption(FileFormat.PNG), "No PNG header found",
"Try -forcegd or -forcecairo flag");
return null;
}
@ -405,7 +436,7 @@ public final class CucaDiagramFileMaker {
final ByteArrayInputStream bais = new ByteArrayInputStream(imageData);
BufferedImage im = ImageIO.read(bais);
if (im == null) {
createError(os, imageData.length, FileFormat.PNG, "im == null");
createError(os, imageData.length, new FileFormatOption(FileFormat.PNG), "im == null");
return null;
}
bais.close();
@ -426,7 +457,7 @@ public final class CucaDiagramFileMaker {
im = PngRotation.process(im);
}
im = PngSizer.process(im, diagram.getMinwidth());
PngIO.write(im, os, diagram.getMetadata());
PngIO.write(im, os, diagram.getMetadata(), diagram.getDpi(fileFormatOption));
} finally {
cleanTemporaryFiles(diagram.entities().values());
cleanTemporaryFiles(diagram.getLinks());
@ -516,7 +547,7 @@ public final class CucaDiagramFileMaker {
return "png";
}
void createError(OutputStream os, int length, FileFormat fileFormat, String... supp) throws IOException {
void createError(OutputStream os, int length, FileFormatOption fileFormat, String... supp) throws IOException {
final List<String> msg = new ArrayList<String>();
msg.add("Error: Reading " + length + " byte(s) from dot");
msg.add("Error reading the generated image");
@ -528,18 +559,18 @@ public final class CucaDiagramFileMaker {
}
private BufferedImage addTitle(BufferedImage im, final Color background) {
final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.TITLE).getColor();
final String fontFamily = getSkinParam().getFontFamily(FontParam.TITLE);
final int fontSize = getSkinParam().getFontSize(FontParam.TITLE);
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);
return pngTitler.processImage(im, background, 3);
}
private String addTitleSvg(String svg, double width, double height) throws IOException {
final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.TITLE).getColor();
final String fontFamily = getSkinParam().getFontFamily(FontParam.TITLE);
final int fontSize = getSkinParam().getFontSize(FontParam.TITLE);
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);
@ -548,39 +579,39 @@ public final class CucaDiagramFileMaker {
}
private String addHeaderSvg(String svg, double width, double height) throws IOException {
final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.HEADER).getColor();
final String fontFamily = getSkinParam().getFontFamily(FontParam.HEADER);
final int fontSize = getSkinParam().getFontSize(FontParam.HEADER);
final SvgTitler svgTitler = new SvgTitler(titleColor, diagram.getHeader(), fontSize, fontFamily,
diagram.getHeaderAlignement(), VerticalPosition.TOP, 3);
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 String addFooterSvg(String svg, double width, double height) throws IOException {
final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.FOOTER).getColor();
final String fontFamily = getSkinParam().getFontFamily(FontParam.FOOTER);
final int fontSize = getSkinParam().getFontSize(FontParam.FOOTER);
final SvgTitler svgTitler = new SvgTitler(titleColor, diagram.getFooter(), fontSize, fontFamily,
diagram.getFooterAlignement(), VerticalPosition.BOTTOM, 3);
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 BufferedImage addFooter(BufferedImage im, final Color background) {
final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.FOOTER).getColor();
final String fontFamily = getSkinParam().getFontFamily(FontParam.FOOTER);
final int fontSize = getSkinParam().getFontSize(FontParam.FOOTER);
final PngTitler pngTitler = new PngTitler(titleColor, diagram.getFooter(), fontSize, fontFamily,
diagram.getFooterAlignement(), VerticalPosition.BOTTOM);
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);
return pngTitler.processImage(im, background, 3);
}
private BufferedImage addHeader(BufferedImage im, final Color background) throws IOException {
final Color titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.HEADER).getColor();
final String fontFamily = getSkinParam().getFontFamily(FontParam.HEADER);
final int fontSize = getSkinParam().getFontSize(FontParam.HEADER);
final PngTitler pngTitler = new PngTitler(titleColor, diagram.getHeader(), fontSize, fontFamily,
diagram.getHeaderAlignement(), VerticalPosition.TOP);
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);
return pngTitler.processImage(im, background, 3);
}
@ -594,9 +625,10 @@ public final class CucaDiagramFileMaker {
}
}
private GraphvizMaker createDotMaker(Map<EntityType, DrawFile> staticImages,
Map<VisibilityModifier, DrawFile> visibilities, List<String> dotStrings, FileFormat fileFormat)
private GraphvizMaker createDotMaker(List<String> dotStrings, FileFormatOption fileFormatOption)
throws IOException, InterruptedException {
final FileFormat fileFormat = fileFormatOption.getFileFormat();
if (diagram.getUmlDiagramType() == UmlDiagramType.STATE
|| diagram.getUmlDiagramType() == UmlDiagramType.ACTIVITY) {
new CucaDiagramSimplifier(diagram, dotStrings, fileFormat);
@ -604,52 +636,60 @@ public final class CucaDiagramFileMaker {
final DotData dotData = new DotData(null, diagram.getLinks(), diagram.entities(), diagram.getUmlDiagramType(),
diagram.getSkinParam(), diagram.getRankdir(), diagram, diagram);
dotData.putAllStaticImages(staticImages);
dotData.setDpi(diagram.getDpi(fileFormatOption));
if (diagram.getUmlDiagramType() == UmlDiagramType.CLASS || diagram.getUmlDiagramType() == UmlDiagramType.OBJECT) {
dotData.setStaticImagesMap(staticFilesMap);
if (diagram.isVisibilityModifierPresent()) {
dotData.putAllVisibilityImages(visibilities);
dotData.setVisibilityModifierPresent(true);
}
}
return new DotMaker(dotData, dotStrings, fileFormat);
}
private void populateImages() throws IOException {
private void populateImages(double dpiFactor, int dpi) throws IOException {
for (Entity entity : diagram.entities().values()) {
final DrawFile f = createImage(entity);
final DrawFile f = createImage(entity, dpiFactor, dpi);
if (f != null) {
entity.setImageFile(f);
}
}
}
private void populateImagesLink() throws IOException {
private void populateImagesLink(double dpiFactor, int dpi) throws IOException {
for (Link link : diagram.getLinks()) {
final String note = link.getNote();
if (note == null) {
continue;
}
final DrawFile f = createImageForNote(note, null);
final DrawFile f = createImageForNote(note, null, dpiFactor, dpi);
if (f != null) {
link.setImageFile(f);
}
}
}
DrawFile createImage(Entity entity) throws IOException {
DrawFile createImage(Entity entity, double dpiFactor, int dpi) throws IOException {
if (entity.getType() == EntityType.NOTE) {
return createImageForNote(entity.getDisplay(), entity.getSpecificBackColor());
return createImageForNote(entity.getDisplay(), entity.getSpecificBackColor(), dpiFactor, dpi);
}
if (entity.getType() == EntityType.ACTIVITY) {
return createImageForActivity(entity);
if (entity.getType() == EntityType.ACTOR) {
return createImageForActor(entity, dpiFactor);
}
if (entity.getType() == EntityType.CIRCLE_INTERFACE) {
return createImageForCircleInterface(entity, dpiFactor);
}
if (entity.getType() == EntityType.ABSTRACT_CLASS || entity.getType() == EntityType.CLASS
|| entity.getType() == EntityType.ENUM || entity.getType() == EntityType.INTERFACE) {
return createImageForCircleCharacter(entity);
return createImageForCircleCharacter(entity, dpiFactor);
}
return null;
}
private DrawFile createImageForNote(String display, HtmlColor backColor) throws IOException {
final File fPng = createTempFile("plantumlB", ".png");
private DrawFile createImageForNote(String display, HtmlColor backColor, double dpiFactor, int dpi) throws IOException {
final File fPng = FileUtils.createTempFile("plantumlB", ".png");
final Rose skin = new Rose();
@ -657,29 +697,29 @@ public final class CucaDiagramFileMaker {
final Component comp = skin
.createComponent(ComponentType.NOTE, skinParam, StringUtils.getWithNewlines(display));
final int width = (int) comp.getPreferredWidth(stringBounder);
final int height = (int) comp.getPreferredHeight(stringBounder);
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), new Dimension(width, height), new SimpleContext2D(false));
PngIO.write(im, fPng);
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 = createTempFile("plantumlB", ".eps");
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 new DrawFile(fPng, getSvg(ug), fEps);
return DrawFile.createFromFile(fPng, getSvg(ug), fEps);
}
static public String getSvg(UGraphicSvg ug) throws IOException {
@ -697,50 +737,125 @@ public final class CucaDiagramFileMaker {
return null;
}
private DrawFile createImageForCircleCharacter(Entity entity) throws IOException {
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 CircleInterface circleInterface = new CircleInterface(interfaceBackground, interfaceBorder);
final Lazy<File> lpng = new Lazy<File>() {
public File getNow() throws IOException {
final EmptyImageBuilder builder = new EmptyImageBuilder(circleInterface.getPreferredWidth(null)
* dpiFactor, circleInterface.getPreferredHeight(null) * dpiFactor, background);
final BufferedImage im = builder.getBufferedImage();
final Graphics2D g2d = builder.getGraphics2D();
circleInterface.drawU(new UGraphicG2d(g2d, null, 1.0));
final File png = FileUtils.createTempFile("circleinterface", ".png");
ImageIO.write(im, "png", png);
return png;
}
};
final Lazy<File> leps = new Lazy<File>() {
public File getNow() throws IOException {
final File epsFile = FileUtils.createTempFile("circleinterface", ".eps");
UGraphicEps.copyEpsToFile(circleInterface, epsFile);
return epsFile;
}
};
final Lazy<String> lsvg = new Lazy<String>() {
public String getNow() throws IOException {
return UGraphicG2d.getSvgString(circleInterface);
}
};
final Object signature = Arrays.asList("circleinterface", interfaceBackground, interfaceBorder, background,
dpiFactor);
return DrawFile.create(lpng, lsvg, leps, signature);
}
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 StickMan stickMan = new StickMan(actorBackground, actorBorder);
final Lazy<File> lpng = new Lazy<File>() {
public File getNow() throws IOException {
final EmptyImageBuilder builder = new EmptyImageBuilder(stickMan.getPreferredWidth(null) * dpiFactor,
// stickMan.getPreferredHeight(null) * dpiFactor, dpiFactor > 1
// ? Color.BLUE : background);
stickMan.getPreferredHeight(null) * dpiFactor, background);
final BufferedImage im = builder.getBufferedImage();
final Graphics2D g2d = builder.getGraphics2D();
stickMan.drawU(new UGraphicG2d(g2d, null, dpiFactor));
final File png = FileUtils.createTempFile("actor", ".png");
ImageIO.write(im, "png", png);
return png;
}
};
final Lazy<File> leps = new Lazy<File>() {
public File getNow() throws IOException {
final File epsFile = FileUtils.createTempFile("actor", ".eps");
UGraphicEps.copyEpsToFile(stickMan, epsFile);
return epsFile;
}
};
final Lazy<String> lsvg = new Lazy<String>() {
public String getNow() throws IOException {
return UGraphicG2d.getSvgString(stickMan);
}
};
final Object signature = Arrays.asList("actor", actorBackground, actorBorder, background, dpiFactor);
return DrawFile.create(lpng, lsvg, leps, signature);
}
private DrawFile createImageForCircleCharacter(Entity entity, double dpiFactor) throws IOException {
final Stereotype stereotype = entity.getStereotype();
if (stereotype == null || stereotype.getColor() == null) {
return null;
}
final File f = createTempFile("plantumlA", ".png");
final File fEps = createTempFile("plantumlA", ".eps");
final Color classBorder = rose.getHtmlColor(getSkinParam(), ColorParam.classBorder).getColor();
final Color classBackground = rose.getHtmlColor(getSkinParam(), ColorParam.classBackground).getColor();
final Font font = diagram.getSkinParam().getFont(FontParam.CIRCLED_CHARACTER);
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 CircledCharacter circledCharacter = new CircledCharacter(stereotype.getCharacter(), getSkinParam()
.getCircledCharacterRadius(), font, stereotype.getColor(), classBorder, Color.BLACK);
return staticFiles.generateCircleCharacter(f, fEps, circledCharacter, classBackground);
// return new DrawFile(f, UGraphicG2d.getSvgString(circledCharacter),
// fEps);
return circledCharacter.generateCircleCharacter(classBackground, dpiFactor);
}
private ISkinParam getSkinParam() {
return diagram.getSkinParam();
}
static public File createTempFile(String prefix, String suffix) throws IOException {
if (suffix.startsWith(".") == false) {
throw new IllegalArgumentException();
}
final File f = File.createTempFile(prefix, suffix);
Log.info("Creating temporary file: " + f);
if (OptionFlags.getInstance().isKeepTmpFiles() == false) {
f.deleteOnExit();
}
return f;
}
private String createEps(OutputStream os, List<String> dotStrings) throws IOException, InterruptedException {
private String createEps(OutputStream os, List<String> dotStrings, FileFormatOption fileFormatOption)
throws IOException, InterruptedException {
try {
deltaY = 0;
populateImages();
populateImagesLink();
final GraphvizMaker dotMaker = createDotMaker(staticFiles.getStaticImages(),
staticFiles.getVisibilityImages(), dotStrings, FileFormat.EPS);
populateImages(diagram.getDpiFactor(fileFormatOption), diagram.getDpi(fileFormatOption));
populateImagesLink(diagram.getDpiFactor(fileFormatOption), diagram.getDpi(fileFormatOption));
final GraphvizMaker dotMaker = createDotMaker(dotStrings, fileFormatOption);
final String dotString = dotMaker.createDotString();
if (OptionFlags.getInstance().isKeepTmpFiles()) {

View File

@ -79,7 +79,7 @@ public final class CucaDiagramFileMakerBeta {
if (fileFormat == FileFormat.PNG) {
final List<File> result = new PngSplitter(suggested, diagram.getHorizontalPages(), diagram
.getVerticalPages(), diagram.getMetadata()).getFiles();
.getVerticalPages(), diagram.getMetadata(), 96).getFiles();
for (File f : result) {
Log.info("Creating file: " + f);
}
@ -109,7 +109,7 @@ public final class CucaDiagramFileMakerBeta {
EmptyImageBuilder builder = new EmptyImageBuilder(10, 10, background);
BufferedImage im = builder.getBufferedImage();
Graphics2D g2d = builder.getGraphics2D();
UGraphicG2d ug = new UGraphicG2d(g2d, im);
UGraphicG2d ug = new UGraphicG2d(g2d, im, 1.0);
final PlayField playField = new PlayField(diagram.getSkinParam());
final Collection<IEntity> entities = getFirstLevelEntities();
@ -122,15 +122,15 @@ public final class CucaDiagramFileMakerBeta {
final Dimension2D dim = playField.solve();
builder = new EmptyImageBuilder((int) (dim.getWidth() + 1), (int) (dim.getHeight() + 1), background);
builder = new EmptyImageBuilder(dim.getWidth() + 1, dim.getHeight() + 1, background);
im = builder.getBufferedImage();
g2d = builder.getGraphics2D();
g2d.translate(10, 0);
ug = new UGraphicG2d(g2d, im);
ug = new UGraphicG2d(g2d, im, 1.0);
playField.drawInternal(ug);
PngIO.write(im, os);
PngIO.write(im, os, 96);
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5047 $
* Revision $Revision: 5872 $
*
*/
package net.sourceforge.plantuml.cucadiagram.dot;
@ -92,8 +92,7 @@ public final class CucaDiagramPngMaker2 {
final List<Graph2> graphs = getGraphs2(zoda2.getHeaps());
final Dimension2D totalDim = getTotalDimension(graphs);
final EmptyImageBuilder im = new EmptyImageBuilder((int) totalDim.getWidth(), (int) totalDim.getHeight(),
Color.WHITE);
final EmptyImageBuilder im = new EmptyImageBuilder(totalDim.getWidth(), totalDim.getHeight(), Color.WHITE);
double x = 0;
@ -178,7 +177,7 @@ public final class CucaDiagramPngMaker2 {
}
}
return new PngSplitter(pngFile, diagram.getHorizontalPages(), diagram.getVerticalPages(), diagram.getMetadata())
.getFiles();
return new PngSplitter(pngFile, diagram.getHorizontalPages(), diagram.getVerticalPages(),
diagram.getMetadata(), 96).getFiles();
}
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5047 $
* Revision $Revision: 5872 $
*
*/
package net.sourceforge.plantuml.cucadiagram.dot;
@ -91,7 +91,7 @@ public final class CucaDiagramPngMaker3 {
final List<Graph5> graphs = getGraphs3(zoda2.getHeaps());
final Dimension2D totalDim = getTotalDimension(graphs);
final EmptyImageBuilder im = new EmptyImageBuilder((int) totalDim.getWidth(), (int) totalDim.getHeight(),
final EmptyImageBuilder im = new EmptyImageBuilder(totalDim.getWidth(), totalDim.getHeight(),
Color.WHITE);
double x = 0;
@ -156,7 +156,7 @@ public final class CucaDiagramPngMaker3 {
}
}
return new PngSplitter(pngFile, diagram.getHorizontalPages(), diagram.getVerticalPages(), diagram.getMetadata())
return new PngSplitter(pngFile, diagram.getHorizontalPages(), diagram.getVerticalPages(), diagram.getMetadata(), 96)
.getFiles();
}
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5378 $
* Revision $Revision: 5789 $
*
*/
package net.sourceforge.plantuml.cucadiagram.dot;
@ -41,21 +41,28 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import net.sourceforge.plantuml.ColorParam;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.cucadiagram.Member;
import net.sourceforge.plantuml.FileUtils;
import net.sourceforge.plantuml.OptionFlags;
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.cucadiagram.Stereotype;
import net.sourceforge.plantuml.graphic.HtmlColor;
import net.sourceforge.plantuml.skin.rose.Rose;
public final class CucaDiagramSimplifier {
private final CucaDiagram diagram;
private final FileFormat fileFormat;
public CucaDiagramSimplifier(CucaDiagram diagram, List<String> dotStrings, FileFormat fileFormat) throws IOException,
InterruptedException {
public CucaDiagramSimplifier(CucaDiagram diagram, List<String> dotStrings, FileFormat fileFormat)
throws IOException, InterruptedException {
this.diagram = diagram;
this.fileFormat = fileFormat;
boolean changed;
@ -77,27 +84,66 @@ public final class CucaDiagramSimplifier {
throw new IllegalStateException();
}
final Entity proxy = new Entity("#" + g.getCode(), g.getDisplay(), type, g.getParent());
if (type == EntityType.STATE) {
manageBackColorForState(diagram, g, proxy);
}
for (Member field : g.getEntityCluster().fields2()) {
proxy.addField(field);
}
computeImageGroup(g, proxy, dotStrings);
diagram.overideGroup(g, proxy);
for (IEntity sub : g.entities().values()) {
final DrawFile subImage = sub.getImageFile();
if (subImage != null) {
proxy.addSubImage(subImage);
}
}
changed = true;
}
}
} while (changed);
}
private void manageBackColorForState(CucaDiagram diagram, Group g, final Entity proxy) {
if (OptionFlags.PBBACK == false) {
return;
}
if (g.getBackColor() != null) {
proxy.setSpecificBackcolor(g.getBackColor().getAsHtml());
return;
}
assert g.getBackColor() == null;
if (g.getStereotype() != null) {
proxy.setStereotype(new Stereotype(g.getStereotype()));
}
//PBBACK
final Rose rose = new Rose();
final HtmlColor back = rose.getHtmlColor(diagram.getSkinParam(), ColorParam.stateBackground, g.getStereotype());
// final HtmlColor back = diagram.getSkinParam().getHtmlColor(ColorParam.stateBackground, g.getStereotype());
// if (back != null) {
// proxy.setSpecificBackcolor(back.getAsHtml());
// }
assert g.getBackColor() == null;
g.setBackColor(back);
}
private void computeImageGroup(final Group group, final Entity entity, List<String> dotStrings) throws IOException,
FileNotFoundException, InterruptedException {
final GroupPngMaker maker = new GroupPngMaker(diagram, group, fileFormat);
final File f = CucaDiagramFileMaker.createTempFile("inner", ".png");
final File f = FileUtils.createTempFile("inner", ".png");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(f);
maker.createPng(fos, dotStrings);
final String svg = maker.createSvg(dotStrings);
entity.setImageFile(new DrawFile(f, svg));
// final Pattern pImage = Pattern.compile("(?i)<image\\W[^>]*>");
// final Matcher mImage = pImage.matcher(svg);
// if (mImage.find()) {
// throw new IllegalStateException();
// }
entity.setImageFile(DrawFile.createFromFile(f, svg, null));
} finally {
if (fos != null) {
fos.close();

View File

@ -28,16 +28,15 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5084 $
* Revision $Revision: 5813 $
*
*/
package net.sourceforge.plantuml.cucadiagram.dot;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@ -65,10 +64,10 @@ final public class DotData implements PortionShower {
final private GroupHierarchy groupHierarchy;
final private Group topParent;
final private PortionShower portionShower;
private int dpi = 96;
final private Map<EntityType, DrawFile> staticImages = new HashMap<EntityType, DrawFile>();
final private Map<VisibilityModifier, DrawFile> visibilityImages = new EnumMap<VisibilityModifier, DrawFile>(
VisibilityModifier.class);
private StaticFilesMap staticFilesMap;
private boolean visibilityModifierPresent;
public DotData(Group topParent, List<Link> links, Map<String, ? extends IEntity> entities,
UmlDiagramType umlDiagramType, ISkinParam skinParam, Rankdir rankdir, GroupHierarchy groupHierarchy,
@ -96,20 +95,38 @@ final public class DotData implements PortionShower {
return true;
}
public Map<EntityType, DrawFile> getStaticImages() {
return staticImages;
public DrawFile getStaticImages(EntityType type, String stereo) throws IOException {
checkObjectOrClassDiagram();
assert type == EntityType.ABSTRACT_CLASS || type == EntityType.CLASS || type == EntityType.ENUM
|| type == EntityType.INTERFACE || type == EntityType.LOLLIPOP;
return staticFilesMap.getStaticFiles(stereo).getStaticImages(type);
}
public void putAllStaticImages(Map<EntityType, DrawFile> staticImages) {
this.staticImages.putAll(staticImages);
public DrawFile getVisibilityImages(VisibilityModifier visibilityModifier, String stereo) throws IOException {
checkObjectOrClassDiagram();
return staticFilesMap.getStaticFiles(stereo).getVisibilityImages(visibilityModifier);
}
public Map<VisibilityModifier, DrawFile> getVisibilityImages() {
return visibilityImages;
public boolean isThereVisibilityImages() {
return visibilityModifierPresent;
}
public void putAllVisibilityImages(Map<VisibilityModifier, DrawFile> visibilityImages) {
this.visibilityImages.putAll(visibilityImages);
public void setVisibilityModifierPresent(boolean b) {
checkObjectOrClassDiagram();
this.visibilityModifierPresent = b;
}
public void setStaticImagesMap(StaticFilesMap staticFilesMap) {
checkObjectOrClassDiagram();
this.staticFilesMap = staticFilesMap;
}
private void checkObjectOrClassDiagram() {
if (umlDiagramType != UmlDiagramType.CLASS && umlDiagramType != UmlDiagramType.OBJECT) {
throw new IllegalStateException();
}
}
public UmlDiagramType getUmlDiagramType() {
@ -231,4 +248,19 @@ final public class DotData implements PortionShower {
return portionShower.showPortion(portion, entity);
}
public final int getDpi() {
return dpi;
}
public double getDpiFactor() {
if (dpi == 96) {
return 1.0;
}
return dpi / 96.0;
}
public final void setDpi(int dpi) {
this.dpi = dpi;
}
}

View File

@ -28,21 +28,28 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5396 $
* Revision $Revision: 5705 $
*
*/
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.List;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileSystem;
import net.sourceforge.plantuml.Log;
import net.sourceforge.plantuml.graphic.FontChange;
import net.sourceforge.plantuml.graphic.FontConfiguration;
import net.sourceforge.plantuml.graphic.FontStyle;
import net.sourceforge.plantuml.graphic.HtmlColor;
import net.sourceforge.plantuml.graphic.HtmlCommand;
import net.sourceforge.plantuml.graphic.Img;
import net.sourceforge.plantuml.graphic.Splitter;
import net.sourceforge.plantuml.graphic.Text;
@ -60,7 +67,12 @@ final class DotExpression {
private final FileFormat fileFormat;
private boolean hasImg;
DotExpression(String html, int defaultFontSize, HtmlColor color, String fontFamily, int style, FileFormat fileFormat) {
if (html.contains("\n")) {
throw new IllegalArgumentException(html);
}
this.fontFamily = fontFamily;
this.normalFont = new Font("SansSerif", Font.PLAIN, defaultFontSize);
this.fontConfiguration = new FontConfiguration(normalFont, color.getColor());
@ -78,15 +90,66 @@ final class DotExpression {
html = html.replaceAll("\\</[uU]\\> ", "</u>");
underline = html.contains("<u>") || html.contains("<U>");
final Splitter splitter = new Splitter(html);
for (HtmlCommand command : splitter.getHtmlCommands()) {
List<HtmlCommand> htmlCommands = splitter.getHtmlCommands(false);
for (HtmlCommand command : htmlCommands) {
if (command instanceof Img) {
hasImg = true;
}
}
if (hasImg) {
htmlCommands = splitter.getHtmlCommands(true);
sb.append("<TABLE BORDER=\"0\" CELLBORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\">");
for (Collection<HtmlCommand> cmds : split(htmlCommands)) {
sb.append("<TR><TD><TABLE BORDER=\"0\" CELLBORDER=\"0\" CELLPADDING=\"0\" CELLSPACING=\"0\"><TR>");
manageCommands(cmds);
sb.append("</TR></TABLE></TD></TR>");
}
sb.append("</TABLE>");
} else {
manageCommands(htmlCommands);
}
}
private static List<Collection<HtmlCommand>> split(Collection<HtmlCommand> all) {
final List<Collection<HtmlCommand>> result = new ArrayList<Collection<HtmlCommand>>();
Collection<HtmlCommand> current = null;
for (HtmlCommand c : all) {
if (c instanceof Text && ((Text) c).isNewline()) {
current = null;
} else {
if (current == null) {
current = new ArrayList<HtmlCommand>();
result.add(current);
}
current.add(c);
}
}
return result;
}
private void manageCommands(Collection<HtmlCommand> htmlCommands) {
for (HtmlCommand command : htmlCommands) {
if (command instanceof Text) {
manage((Text) command);
} else if (command instanceof FontChange) {
manage((FontChange) command);
} else if (command instanceof Img) {
manageImage((Img) command);
} else {
Log.error("Cannot manage " + command);
}
}
}
private void manageImage(Img img) {
try {
final File f = FileSystem.getInstance().getFile(img.getFilePath());
if (f.exists() == false) {
throw new IOException();
}
sb.append("<TD><IMG SRC=\"" + f.getAbsolutePath() + "\"/></TD>");
} catch (IOException e) {
sb.append("<TD>File Not Found</TD>");
}
}
@ -95,17 +158,29 @@ final class DotExpression {
}
private void manage(Text command) {
if (hasImg) {
sb.append("<TD>");
}
underline(false);
sb.append(getFontTag());
String text = command.getText();
text = text.replace("<", "&lt;");
text = text.replace(">", "&gt;");
if (hasImg == false) {
text = text.replace("\\n", "<BR/>");
}
sb.append(text);
sb.append("</FONT>");
underline(true);
if (hasImg) {
sb.append("</TD>");
if (text.contains("\\n")) {
throw new IllegalStateException();
}
}
}
private String getFontTag() {

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5581 $
* Revision $Revision: 5847 $
*
*/
package net.sourceforge.plantuml.cucadiagram.dot;
@ -49,6 +49,7 @@ 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;
@ -100,7 +101,7 @@ final public class DotMaker implements GraphvizMaker {
this.dotStrings = dotStrings;
this.fileFormat = fileFormat;
if (data.getSkinParam().classAttributeIconSize() > 0) {
this.isVisibilityModifierPresent = data.getVisibilityImages().size() > 0;
this.isVisibilityModifierPresent = data.isThereVisibilityImages();
} else {
this.isVisibilityModifierPresent = false;
}
@ -129,11 +130,11 @@ final public class DotMaker implements GraphvizMaker {
final boolean huge = data.getEntities().size() > 800;
sb.append("digraph unix {");
if (isJunit == false) {
//if (isJunit == false) {
for (String s : dotStrings) {
sb.append(s);
}
}
// }
sb.append("bgcolor=\"" + data.getSkinParam().getBackgroundColor().getAsHtml() + "\";");
if (huge) {
sb.append("size=\"400,400;\"");
@ -147,6 +148,11 @@ final public class DotMaker implements GraphvizMaker {
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<IEntity> getUnpackagedEntities() {
@ -185,27 +191,31 @@ final public class DotMaker implements GraphvizMaker {
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()) + "\";");
final String fontFamily = data.getSkinParam().getFontFamily(getFontParamForGroup());
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()) + ">;");
sb.append("label=<" + manageHtmlIB(g.getDisplay(), getFontParamForGroup(), stereo) + ">;");
}
final String fontColor = data.getSkinParam().getFontHtmlColor(getFontParamForGroup()).getAsHtml();
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) + ";");
sb.append("color=" + getColorString(ColorParam.stateBorder, stereo) + ";");
} else {
sb.append("color=" + getColorString(ColorParam.packageBorder) + ";");
sb.append("color=" + getColorString(ColorParam.packageBorder, stereo) + ";");
}
sb.append("style=\"" + getStyle(g) + "\";");
@ -221,7 +231,7 @@ final public class DotMaker implements GraphvizMaker {
private HtmlColor getGroupBackColor(Group g) {
HtmlColor value = g.getBackColor();
if (value == null) {
value = data.getSkinParam().getHtmlColor(ColorParam.packageBackground);
value = data.getSkinParam().getHtmlColor(ColorParam.packageBackground, null);
// value = rose.getHtmlColor(this.data.getSkinParam(),
// ColorParam.packageBackground);
}
@ -302,34 +312,35 @@ final public class DotMaker implements GraphvizMaker {
}
// sb.append(g.getUid() + "min->" + g.getUid() + "max;");
sb.append("fontsize=\"" + data.getSkinParam().getFontSize(getFontParamForGroup()) + "\";");
final String fontFamily = data.getSkinParam().getFontFamily(getFontParamForGroup());
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()));
final StringBuilder label = new StringBuilder(manageHtmlIB(g.getDisplay(), getFontParamForGroup(), null));
if (g.getEntityCluster().fields2().size() > 0) {
label.append("<BR ALIGN=\"LEFT\"/>");
for (Member att : g.getEntityCluster().fields2()) {
label.append(manageHtmlIB(" " + att.getDisplayWithVisibilityChar() + " ",
FontParam.STATE_ATTRIBUTE));
FontParam.STATE_ATTRIBUTE, null));
label.append("<BR ALIGN=\"LEFT\"/>");
}
}
sb.append("label=<" + label + ">;");
}
final String fontColor = data.getSkinParam().getFontHtmlColor(getFontParamForGroup()).getAsHtml();
final String fontColor = data.getSkinParam().getFontHtmlColor(getFontParamForGroup(), null).getAsHtml();
sb.append("fontcolor=\"" + fontColor + "\";");
if (getGroupBackColor(g) != null) {
sb.append("fillcolor=\"" + getGroupBackColor(g).getAsHtml() + "\";");
final HtmlColor groupBackColor = getGroupBackColor(g);
if (groupBackColor != null) {
sb.append("fillcolor=\"" + groupBackColor.getAsHtml() + "\";");
}
if (g.getType() == GroupType.STATE) {
sb.append("color=" + getColorString(ColorParam.stateBorder) + ";");
sb.append("color=" + getColorString(ColorParam.stateBorder, null) + ";");
} else {
sb.append("color=" + getColorString(ColorParam.packageBorder) + ";");
sb.append("color=" + getColorString(ColorParam.packageBorder, null) + ";");
}
sb.append("style=\"" + getStyle(g) + "\";");
@ -339,8 +350,17 @@ final public class DotMaker implements GraphvizMaker {
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);
@ -373,14 +393,14 @@ final public class DotMaker implements GraphvizMaker {
sb.append("style=invis;");
sb.append("label=\"\";");
}
final String decorationColor = ",color=" + getColorString(getArrowColorParam());
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())
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
@ -400,7 +420,7 @@ final public class DotMaker implements GraphvizMaker {
sb.append("style=invis;");
sb.append("label=\"\";");
}
final String decorationColor = ",color=" + getColorString(getArrowColorParam());
final String decorationColor = ",color=" + getColorString(getArrowColorParam(), null);
String label = fromEdgeLinks.get(i).getLabel();
if (label == null) {
label = "";
@ -412,7 +432,7 @@ final public class DotMaker implements GraphvizMaker {
+ "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()) + ">];");
sb.append(",label=<" + manageHtmlIB(label, getArrowFontParam(), null) + ">];");
}
sb.append("}"); // end of a
@ -481,17 +501,17 @@ final public class DotMaker implements GraphvizMaker {
final DrawFile noteLink = link.getImageFile();
if (link.getLabel() != null) {
decoration.append("label=<" + manageHtmlIB(link.getLabel(), getArrowFontParam()) + ">,");
decoration.append("label=<" + manageHtmlIB(link.getLabel(), getArrowFontParam(), null) + ">,");
} else if (noteLink != null) {
decoration
.append("label=<" + getHtmlForLinkNote(noteLink.getPngOrEps(fileFormat == FileFormat.EPS)) + ">,");
}
if (link.getQualifier1() != null) {
decoration.append("taillabel=<" + manageHtmlIB(link.getQualifier1(), getArrowFontParam()) + ">,");
decoration.append("taillabel=<" + manageHtmlIB(link.getQualifier1(), getArrowFontParam(), null) + ">,");
}
if (link.getQualifier2() != null) {
decoration.append("headlabel=<" + manageHtmlIB(link.getQualifier2(), getArrowFontParam()) + ">,");
decoration.append("headlabel=<" + manageHtmlIB(link.getQualifier2(), getArrowFontParam(), null) + ">,");
}
decoration.append(link.getType().getSpecificDecoration());
if (link.isInvis()) {
@ -552,12 +572,12 @@ final public class DotMaker implements GraphvizMaker {
}
private StringBuilder getLinkDecoration() {
final StringBuilder decoration = new StringBuilder("[color=" + getColorString(getArrowColorParam()) + ",");
final StringBuilder decoration = new StringBuilder("[color=" + getColorString(getArrowColorParam(), null) + ",");
decoration.append("fontcolor=" + getFontColorString(getArrowFontParam()) + ",");
decoration.append("fontsize=\"" + data.getSkinParam().getFontSize(getArrowFontParam()) + "\",");
decoration.append("fontcolor=" + getFontColorString(getArrowFontParam(), null) + ",");
decoration.append("fontsize=\"" + data.getSkinParam().getFontSize(getArrowFontParam(), null) + "\",");
final String fontName = data.getSkinParam().getFontFamily(getArrowFontParam());
final String fontName = data.getSkinParam().getFontFamily(getArrowFontParam(), null);
if (fontName != null) {
decoration.append("fontname=\"" + fontName + "\",");
}
@ -624,16 +644,16 @@ final public class DotMaker implements GraphvizMaker {
throw new IllegalStateException();
}
private String getColorString(ColorParam colorParam) {
return "\"" + rose.getHtmlColor(data.getSkinParam(), colorParam).getAsHtml() + "\"";
private String getColorString(ColorParam colorParam, String stereotype) {
return "\"" + rose.getHtmlColor(data.getSkinParam(), colorParam, stereotype).getAsHtml() + "\"";
}
private String getFontColorString(FontParam fontParam) {
return "\"" + getFontHtmlColor(fontParam).getAsHtml() + "\"";
private String getFontColorString(FontParam fontParam, String stereotype) {
return "\"" + getFontHtmlColor(fontParam, stereotype).getAsHtml() + "\"";
}
private HtmlColor getFontHtmlColor(FontParam fontParam) {
return data.getSkinParam().getFontHtmlColor(fontParam);
private HtmlColor getFontHtmlColor(FontParam fontParam, String stereotype) {
return data.getSkinParam().getFontHtmlColor(fontParam, stereotype);
}
private void eventuallySameRank(StringBuilder sb, Group entityPackage, Link link) {
@ -718,10 +738,10 @@ final public class DotMaker implements GraphvizMaker {
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);
final String color2 = getColorString(ColorParam.classBorder);
final String colorBack = getColorString(ColorParam.background);
final String labelLo = manageHtmlIB(entity.getDisplay(), FontParam.CLASS_ATTRIBUTE);
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
@ -738,39 +758,40 @@ final public class DotMaker implements GraphvizMaker {
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) + ",margin=0,fillcolor="
+ getColorString(ColorParam.classBackground) + ",color=" + getColorString(ColorParam.classBorder)
+ ",style=filled,shape=box," + label;
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) + ",margin=0,fillcolor="
+ getColorString(ColorParam.classBackground) + ",color=" + getColorString(ColorParam.classBorder)
+ ",style=filled,shape=record," + label + "];");
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) + ",fillcolor="
+ getColorString(ColorParam.usecaseBackground) + ",color="
+ getColorString(ColorParam.usecaseBorder) + ",style=filled," + label + "];");
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)
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)
+ ",fillcolor=" + getColorString(ColorParam.componentBackground) + ",color="
+ getColorString(ColorParam.componentBorder) + ",style=filled,shape=component," + label + "];");
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) {
// sb.append(entity.getUid() + ";");
// Log.error("Warning : no file for NOTE");
// return;
throw new IllegalStateException("No file for NOTE");
}
if (file.getPngOrEps(fileFormat == FileFormat.EPS).exists() == false) {
@ -784,13 +805,12 @@ final public class DotMaker implements GraphvizMaker {
if (entity.getImageFile() != null) {
shape = "rect";
}
sb.append(entity.getUid() + " [fontcolor=" + getFontColorString(FontParam.ACTIVITY) + ",fillcolor="
+ getColorString(ColorParam.activityBackground) + ",color="
+ getColorString(ColorParam.activityBorder) + ",style=\"rounded,filled\",shape=" + shape + ","
+ label + "];");
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=" + getColorString(ColorParam.activityBackground) + ",color="
+ getColorString(ColorParam.activityBorder)
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() +
@ -798,27 +818,27 @@ final public class DotMaker implements GraphvizMaker {
// + "\",arrowtail=none,arrowhead=none,color=\"white\"];");
// }
} else if (type == EntityType.SYNCHRO_BAR) {
final String color = getColorString(ColorParam.activityBar);
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(ColorParam.activityStart);
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(ColorParam.activityEnd);
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)
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)
+ ",shape=record,style=\"rounded,filled\",color=" + getColorString(ColorParam.stateBorder));
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=" + getColorString(ColorParam.stateBackground));
sb.append(",fillcolor=" + getBackColorOfEntity(entity));
} else {
sb.append(",fillcolor=" + getColorString(ColorParam.stateBackground));
sb.append(",fillcolor=" + getBackColorOfEntity(entity));
// sb.append(",fillcolor=\"" +
// data.getSkinParam().getBackgroundColor().getAsHtml() + "\"");
}
@ -846,14 +866,34 @@ final public class DotMaker implements GraphvizMaker {
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)
+ ",fillcolor=" + getColorString(ColorParam.packageBackground) + ",color="
+ getColorString(ColorParam.packageBorder) + ",style=filled,shape=tab," + label + "];");
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());
}
}
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) {
@ -897,9 +937,10 @@ final public class DotMaker implements GraphvizMaker {
sb.append(">");
return sb.toString();
}
return "label=" + getSimpleLabelAsHtml(entity, FontParam.ACTIVITY);
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());
return "label=" + getSimpleLabelAsHtml(entity, getFontParamForGroup(), null);
} else if (entity.getType() == EntityType.USECASE) {
return "label=" + getLabelForUsecase(entity);
} else if (entity.getType() == EntityType.STATE) {
@ -908,23 +949,40 @@ final public class DotMaker implements GraphvizMaker {
return "label=\"" + entity.getDisplay() + "\"";
}
private String getSimpleLabelAsHtml(IEntity entity, FontParam param) {
return "<" + manageHtmlIB(entity.getDisplay(), param) + ">";
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 = getColorString(ColorParam.stateBackground);
final String stateBgcolor = getBackColorOfEntity(entity);
final String stereotype = entity.getStereotype() == null ? null : entity.getStereotype().getLabel();
final StringBuilder sb = new StringBuilder("<{<TABLE BGCOLOR=" + stateBgcolor
+ " BORDER=\"0\" CELLBORDER=\"0\" CELLSPACING=\"0\">");
sb.append("<TR><TD>" + manageHtmlIB(entity.getDisplay(), FontParam.STATE) + "</TD></TR>");
sb.append("<TR><TD>" + manageHtmlIB(entity.getDisplay(), FontParam.STATE, stereotype) + "</TD></TR>");
sb.append("</TABLE>");
if (entity.fields2().size() > 0) {
sb.append("|");
for (Member att : entity.fields2()) {
sb.append(manageHtmlIB(att.getDisplayWithVisibilityChar(), FontParam.STATE_ATTRIBUTE));
sb.append(manageHtmlIB(att.getDisplayWithVisibilityChar(), FontParam.STATE_ATTRIBUTE, stereotype));
sb.append("<BR ALIGN=\"LEFT\"/>");
}
}
@ -932,7 +990,13 @@ final public class DotMaker implements GraphvizMaker {
if (cFile != null) {
sb.append("|");
final String path = StringUtils.getPlateformDependentAbsolutePath(cFile.getPng());
final String bgcolor = "\"" + data.getSkinParam().getBackgroundColor().getAsHtml() + "\"";
final String bgcolor;
if (OptionFlags.PBBACK) {
bgcolor = stateBgcolor;
} else {
bgcolor = "\"" + data.getSkinParam().getBackgroundColor().getAsHtml() + "\"";
}
// PBBACK
sb.append("<TABLE BORDER=\"0\" CELLBORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\">");
sb.append("<TR>");
@ -952,14 +1016,16 @@ final public class DotMaker implements GraphvizMaker {
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);
return getSimpleLabelAsHtml(entity, FontParam.USECASE, stereo);
}
final StringBuilder sb = new StringBuilder("<<TABLE BORDER=\"0\" CELLBORDER=\"0\" CELLSPACING=\"0\">");
if (isThereLabel(stereotype)) {
sb.append("<TR><TD>" + manageHtmlIB(stereotype.getLabel(), FontParam.USECASE_STEREOTYPE) + "</TD></TR>");
sb.append("<TR><TD>" + manageHtmlIB(stereotype.getLabel(), FontParam.USECASE_STEREOTYPE, stereo)
+ "</TD></TR>");
}
sb.append("<TR><TD>" + manageHtmlIB(entity.getDisplay(), FontParam.USECASE) + "</TD></TR>");
sb.append("<TR><TD>" + manageHtmlIB(entity.getDisplay(), FontParam.USECASE, stereo) + "</TD></TR>");
sb.append("</TABLE>>");
return sb.toString();
}
@ -967,61 +1033,129 @@ final public class DotMaker implements GraphvizMaker {
private String getLabelForComponent(IEntity entity) {
final Stereotype stereotype = getStereotype(entity);
if (stereotype == null) {
return getSimpleLabelAsHtml(entity, FontParam.COMPONENT);
return getSimpleLabelAsHtml(entity, FontParam.COMPONENT, null);
}
final String stereo = stereotype.getLabel();
final StringBuilder sb = new StringBuilder("<<TABLE BORDER=\"0\" CELLBORDER=\"0\" CELLSPACING=\"0\">");
if (isThereLabel(stereotype)) {
sb.append("<TR><TD>" + manageHtmlIB(stereotype.getLabel(), FontParam.COMPONENT_STEREOTYPE) + "</TD></TR>");
sb.append("<TR><TD>" + manageHtmlIB(stereotype.getLabel(), FontParam.COMPONENT_STEREOTYPE, stereo)
+ "</TD></TR>");
}
sb.append("<TR><TD>" + manageHtmlIB(entity.getDisplay(), FontParam.COMPONENT) + "</TD></TR>");
sb.append("<TR><TD>" + manageHtmlIB(entity.getDisplay(), FontParam.COMPONENT, stereo) + "</TD></TR>");
sb.append("</TABLE>>");
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("<<TABLE BORDER=\"0\" CELLBORDER=\"0\" CELLSPACING=\"0\">");
sb.append("<TR>");
addTdImageBugB1983(sb, absolutePath);
sb.append("</TR>");
sb.append("</TABLE>>");
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("<TABLE BORDER=\"0\" CELLBORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\">");
sb.append("<TR>");
sb.append(getTdHeaderForDpi(w2, h2));
sb.append("<IMG SCALE=\"TRUE\" SRC=\"" + absolutePath + "\"/>");
sb.append("</TD>");
sb.append("</TR>");
sb.append("</TABLE>");
sb.append("</TD>");
}
private double getMagicFactorForImageDpi() {
return 10500 / 100000.0;
}
private String getLabelForActor(IEntity entity) throws IOException {
final String actorAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(data.getStaticImages().get(
EntityType.ACTOR).getPngOrEps(fileFormat == FileFormat.EPS));
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("<<TABLE BORDER=\"0\" CELLBORDER=\"0\" CELLSPACING=\"0\">");
if (isThereLabel(stereotype)) {
sb.append("<TR><TD>" + manageHtmlIB(stereotype.getLabel(), FontParam.USECASE_ACTOR_STEREOTYPE)
sb.append("<TR><TD>" + manageHtmlIB(stereotype.getLabel(), FontParam.USECASE_ACTOR_STEREOTYPE, stereo)
+ "</TD></TR>");
}
if (data.getDpi() == 96) {
sb.append("<TR><TD><IMG SRC=\"" + actorAbsolutePath + "\"/></TD></TR>");
sb.append("<TR><TD>" + manageHtmlIB(entity.getDisplay(), FontParam.USECASE_ACTOR) + "</TD></TR>");
} else {
sb.append("<TR>");
addTdImageBugB1983(sb, actorAbsolutePath);
sb.append("</TR>");
}
sb.append("<TR><TD>" + manageHtmlIB(entity.getDisplay(), FontParam.USECASE_ACTOR, stereo) + "</TD></TR>");
sb.append("</TABLE>>");
return sb.toString();
}
private String getLabelForCircleInterface(IEntity entity) throws IOException {
final String circleInterfaceAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(data.getStaticImages()
.get(EntityType.CIRCLE_INTERFACE).getPngOrEps(fileFormat == FileFormat.EPS));
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("<<TABLE BORDER=\"0\" CELLBORDER=\"0\" CELLSPACING=\"0\">");
if (isThereLabel(stereotype)) {
sb.append("<TR><TD>" + manageHtmlIB(stereotype.getLabel(), FontParam.COMPONENT_STEREOTYPE) + "</TD></TR>");
sb.append("<TR><TD>" + manageHtmlIB(stereotype.getLabel(), FontParam.COMPONENT_STEREOTYPE, stereo)
+ "</TD></TR>");
}
sb.append("<TR><TD><IMG SRC=\"" + circleInterfaceAbsolutePath + "\"/></TD></TR>");
sb.append("<TR><TD>" + manageHtmlIB(entity.getDisplay(), FontParam.COMPONENT) + "</TD></TR>");
sb.append("<TR>");
if (data.getDpi() == 96) {
sb.append("<TD><IMG SRC=\"" + circleInterfaceAbsolutePath + "\"/></TD>");
} else {
addTdImageBugB1983(sb, circleInterfaceAbsolutePath);
}
sb.append("</TR>");
sb.append("<TR><TD>" + manageHtmlIB(entity.getDisplay(), FontParam.COMPONENT, stereo) + "</TD></TR>");
sb.append("</TABLE>>");
return sb.toString();
}
private String getLabelForLollipop(IEntity entity) throws IOException {
final String circleInterfaceAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(data.getStaticImages()
.get(EntityType.LOLLIPOP).getPngOrEps(fileFormat == FileFormat.EPS));
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("<<TABLE BORDER=\"0\" CELLBORDER=\"0\" CELLSPACING=\"0\">");
if (isThereLabel(stereotype)) {
sb.append("<TR><TD>" + manageHtmlIB(stereotype.getLabel(), FontParam.CLASS) + "</TD></TR>");
sb.append("<TR><TD>" + manageHtmlIB(stereotype.getLabel(), FontParam.CLASS, null) + "</TD></TR>");
}
sb.append("<TR><TD><IMG SRC=\"" + circleInterfaceAbsolutePath + "\"/></TD></TR>");
sb.append("<TR><TD>" + manageHtmlIB(entity.getDisplay(), FontParam.CLASS) + "</TD></TR>");
sb.append("<TR>");
if (data.getDpi() == 96) {
sb.append("<TD><IMG SRC=\"" + circleInterfaceAbsolutePath + "\"/></TD>");
} else {
addTdImageBugB1983(sb, circleInterfaceAbsolutePath);
}
sb.append("</TR>");
sb.append("<TR><TD>" + manageHtmlIB(entity.getDisplay(), FontParam.CLASS, null) + "</TD></TR>");
sb.append("</TABLE>>");
return sb.toString();
@ -1038,7 +1172,8 @@ final public class DotMaker implements GraphvizMaker {
private String getLabelForClassOrInterfaceOrEnumOld(IEntity entity) throws IOException {
DrawFile cFile = entity.getImageFile();
if (cFile == null) {
cFile = data.getStaticImages().get(entity.getType());
final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel();
cFile = data.getStaticImages(entity.getType(), stereo);
}
if (cFile == null) {
throw new IllegalStateException();
@ -1056,10 +1191,12 @@ final public class DotMaker implements GraphvizMaker {
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("<TABLE BGCOLOR=" + getColorString(ColorParam.classBackground)
sb.append("<TABLE BGCOLOR=" + getColorString(ColorParam.classBackground, stereo)
+ " BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"4\">");
sb.append("<TR><TD>");
final int longuestFieldOrAttribute = getLongestFieldOrAttribute(entity);
@ -1075,10 +1212,10 @@ final public class DotMaker implements GraphvizMaker {
// sb.append(addFieldsEps(entity.fields2(), true));
// } else {
final boolean hasStatic = hasStatic(entity.fields2());
sb.append("<TR ALIGN=\"LEFT\"><TD WIDTH=\"55\" ALIGN=\"LEFT\">");
sb.append("<TR ALIGN=\"LEFT\"><TD " + getWitdh55() + " ALIGN=\"LEFT\">");
for (Member att : entity.fields2()) {
sb.append(manageHtmlIBspecial(att, FontParam.CLASS_ATTRIBUTE, hasStatic,
getColorString(ColorParam.classBackground), true));
sb.append(manageHtmlIBspecial(att, FontParam.CLASS_ATTRIBUTE, hasStatic, getColorString(
ColorParam.classBackground, stereo), true));
sb.append("<BR ALIGN=\"LEFT\"/>");
}
sb.append("</TD></TR>");
@ -1091,8 +1228,8 @@ final public class DotMaker implements GraphvizMaker {
final boolean hasStatic = hasStatic(entity.methods2());
sb.append("<TR ALIGN=\"LEFT\"><TD ALIGN=\"LEFT\">");
for (Member att : entity.methods2()) {
sb.append(manageHtmlIBspecial(att, FontParam.CLASS_ATTRIBUTE, hasStatic,
getColorString(ColorParam.classBackground), true));
sb.append(manageHtmlIBspecial(att, FontParam.CLASS_ATTRIBUTE, hasStatic, getColorString(
ColorParam.classBackground, stereo), true));
sb.append("<BR ALIGN=\"LEFT\"/>");
}
sb.append("</TD></TR>");
@ -1119,10 +1256,10 @@ final public class DotMaker implements GraphvizMaker {
}
texts.add(s);
}
final Font font = data.getSkinParam().getFont(FontParam.CLASS_ATTRIBUTE);
final Color color = getFontHtmlColor(FontParam.CLASS_ATTRIBUTE).getColor();
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, font, color, HorizontalAlignement.LEFT);
final File feps = CucaDiagramFileMaker.createTempFile("member", ".eps");
final File feps = FileUtils.createTempFile("member", ".eps");
UGraphicEps.copyEpsToFile(new UDrawable() {
public void drawU(UGraphic ug) {
text.drawU(ug, 0, 0);
@ -1134,8 +1271,6 @@ final public class DotMaker implements GraphvizMaker {
return "<TR ALIGN=\"LEFT\"><TD ALIGN=\"LEFT\">" + "<TABLE BORDER=\"0\" CELLBORDER=\"0\" CELLSPACING=\"0\">"
+ "<TR><TD><IMG SRC=\"" + path + "\"/>" + "</TD>" + "<TD></TD>" + "</TR></TABLE></TD></TR>";
// return "<TR ALIGN=\"LEFT\"><TD WIDTH=\"55\"
// ALIGN=\"LEFT\">toto</TD></TR>";
}
private boolean hasStatic(Collection<Member> attributes) {
@ -1150,7 +1285,8 @@ final public class DotMaker implements GraphvizMaker {
private String getLabelForClassOrInterfaceOrEnumWithVisibilityImage(IEntity entity) throws IOException {
DrawFile cFile = entity.getImageFile();
if (cFile == null) {
cFile = data.getStaticImages().get(entity.getType());
final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel();
cFile = data.getStaticImages(entity.getType(), stereo);
}
if (cFile == null) {
throw new IllegalStateException();
@ -1170,6 +1306,7 @@ final public class DotMaker implements GraphvizMaker {
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,
@ -1177,7 +1314,7 @@ final public class DotMaker implements GraphvizMaker {
final int springMethod = computeSpring(getLongestMethods(entity), Math.max(longuestHeader,
getLongestField(entity)), 30);
sb.append("<TABLE BGCOLOR=" + getColorString(ColorParam.classBackground)
sb.append("<TABLE BGCOLOR=" + getColorString(ColorParam.classBackground, stereo)
+ " BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"4\">");
sb.append("<TR><TD>");
@ -1185,7 +1322,7 @@ final public class DotMaker implements GraphvizMaker {
sb.append("</TD></TR>");
if (showFields) {
sb.append("<TR><TD WIDTH=\"55\">");
sb.append("<TR><TD " + getWitdh55() + ">");
if (entity.fields2().size() > 0) {
buildTableVisibility(entity, true, sb, springField);
}
@ -1222,21 +1359,32 @@ final public class DotMaker implements GraphvizMaker {
sb.append("<TABLE BORDER=\"0\" CELLBORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\">");
final boolean hasStatic = hasStatic(entity.methods2());
final boolean dpiNormal = data.getDpi() == 96;
for (Member att : isField ? entity.fields2() : entity.methods2()) {
sb.append("<TR><TD WIDTH=\"10\">");
sb.append("<TR>");
if (dpiNormal) {
sb.append("<TD WIDTH=\"10\">");
}
String s = att.getDisplayWithVisibilityChar();
final VisibilityModifier visibilityModifier = VisibilityModifier
.getVisibilityModifier(s.charAt(0), isField);
if (visibilityModifier != null) {
final String modifierFile = StringUtils.getPlateformDependentAbsolutePath(data.getVisibilityImages()
.get(visibilityModifier).getPngOrEps(fileFormat == FileFormat.EPS));
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("<IMG SRC=\"" + modifierFile + "\"/>");
} else {
addTdImageBugB1983(sb, modifierFile);
}
s = s.substring(1);
}
sb.append("</TD><TD ALIGN=\"LEFT\">");
sb.append(manageHtmlIBspecial(att, FontParam.CLASS_ATTRIBUTE, hasStatic,
getColorString(ColorParam.classBackground), false));
// sb.append(manageHtmlIB(s, FontParam.CLASS_ATTRIBUTE));
if (dpiNormal) {
sb.append("</TD>");
}
sb.append("<TD ALIGN=\"LEFT\">");
sb.append(manageHtmlIBspecial(att, FontParam.CLASS_ATTRIBUTE, hasStatic, getColorString(
ColorParam.classBackground, null), false));
sb.append("</TD>");
for (int i = 0; i < spring; i++) {
sb.append("<TD></TD>");
@ -1299,17 +1447,20 @@ final public class DotMaker implements GraphvizMaker {
final int springField = computeSpring(getLongestField(entity), Math.max(longuestHeader,
getLongestMethods(entity)), 30);
final StringBuilder sb = new StringBuilder("<<TABLE BGCOLOR=" + getColorString(ColorParam.classBackground)
final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel();
final StringBuilder sb = new StringBuilder("<<TABLE BGCOLOR="
+ getColorString(ColorParam.classBackground, stereo)
+ " BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"4\">");
sb.append("<TR><TD>");
sb.append(getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(entity, null, spring, false, 0));
sb.append("</TD></TR>");
sb.append("<TR><TD WIDTH=\"55\">");
sb.append("<TR><TD " + getWitdh55() + ">");
if (entity.fields2().size() == 0) {
sb.append(manageHtmlIB(" ", FontParam.OBJECT_ATTRIBUTE));
sb.append(manageHtmlIB(" ", FontParam.OBJECT_ATTRIBUTE, stereo));
} else {
buildTableVisibility(entity, true, sb, springField);
}
@ -1322,7 +1473,11 @@ final public class DotMaker implements GraphvizMaker {
}
private String getLabelForObjectOld(IEntity entity) throws IOException {
final StringBuilder sb = new StringBuilder("<<TABLE BGCOLOR=" + getColorString(ColorParam.classBackground)
final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel();
final StringBuilder sb = new StringBuilder("<<TABLE BGCOLOR="
+ getColorString(ColorParam.classBackground, stereo)
+ " BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"4\">");
sb.append("<TR><TD>");
@ -1333,13 +1488,13 @@ final public class DotMaker implements GraphvizMaker {
sb.append(getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(entity, null, spring, false, 0));
sb.append("</TD></TR>");
sb.append("<TR ALIGN=\"LEFT\"><TD WIDTH=\"55\" ALIGN=\"LEFT\">");
sb.append("<TR ALIGN=\"LEFT\"><TD " + getWitdh55() + " ALIGN=\"LEFT\">");
if (entity.fields2().size() == 0) {
sb.append(manageHtmlIB(" ", FontParam.OBJECT_ATTRIBUTE));
sb.append(manageHtmlIB(" ", FontParam.OBJECT_ATTRIBUTE, stereo));
} else {
for (Member att : entity.fields2()) {
sb.append(manageHtmlIB(att.getDisplayWithVisibilityChar(), FontParam.OBJECT_ATTRIBUTE));
sb.append(manageHtmlIB(att.getDisplayWithVisibilityChar(), FontParam.OBJECT_ATTRIBUTE, stereo));
sb.append("<BR ALIGN=\"LEFT\"/>");
}
}
@ -1350,13 +1505,20 @@ final public class DotMaker implements GraphvizMaker {
return sb.toString();
}
private String manageHtmlIB(String s, FontParam param) {
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);
final int style = data.getSkinParam().getFontStyle(param);
final String fontFamily = data.getSkinParam().getFontFamily(param);
final DotExpression dotExpression = new DotExpression(s, fontSize, getFontHtmlColor(param), fontFamily, style,
fileFormat);
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;
@ -1371,12 +1533,12 @@ final public class DotMaker implements GraphvizMaker {
prefix = "<FONT COLOR=" + backColor + ">_</FONT>";
}
if (att.isAbstract()) {
return prefix + manageHtmlIB("<i>" + att.getDisplay(withVisibilityChar), param);
return prefix + manageHtmlIB("<i>" + att.getDisplay(withVisibilityChar), param, null);
}
if (att.isStatic()) {
return manageHtmlIB("<u>" + att.getDisplay(withVisibilityChar), param);
return manageHtmlIB("<u>" + att.getDisplay(withVisibilityChar), param, null);
}
return prefix + manageHtmlIB(att.getDisplay(withVisibilityChar), param);
return prefix + manageHtmlIB(att.getDisplay(withVisibilityChar), param, null);
}
private String manageSpace(int size) {
@ -1400,15 +1562,20 @@ final public class DotMaker implements GraphvizMaker {
}
private String getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnumNoSpring(IEntity entity,
final String circleAbsolutePath, int cellSpacing, boolean classes) {
final String circleAbsolutePath, int cellSpacing, boolean classes) throws IOException {
final StringBuilder sb = new StringBuilder();
sb.append("<TABLE BORDER=\"0\" CELLBORDER=\"0\" CELLSPACING=\"" + cellSpacing + "\" CELLPADDING=\"0\">");
sb.append("<TR>");
if (circleAbsolutePath == null) {
sb.append("<TD>");
} else {
if (data.getDpi() == 96) {
sb.append("<TD ALIGN=\"RIGHT\">");
sb.append("<IMG SRC=\"" + circleAbsolutePath + "\"/></TD>");
} else {
addTdImageBugB1983(sb, circleAbsolutePath);
}
sb.append("<TD ALIGN=\"LEFT\">");
}
@ -1417,6 +1584,12 @@ final public class DotMaker implements GraphvizMaker {
return sb.toString();
}
private String getTdHeaderForDpi(final double w, final double h) {
// return "<TD BGCOLOR=\"#000000\" FIXEDSIZE=\"TRUE\" WIDTH=\"" + w +
// "\" HEIGHT=\"" + h + "\">";
return "<TD FIXEDSIZE=\"TRUE\" WIDTH=\"" + w + "\" HEIGHT=\"" + h + "\">";
}
private String getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(IEntity entity, final String circleAbsolutePath,
int spring, boolean classes, int border) throws IOException {
if (spring == 0) {
@ -1435,11 +1608,15 @@ final public class DotMaker implements GraphvizMaker {
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("<TD FIXEDSIZE=\"TRUE\" WIDTH=\"" + width + "\" HEIGHT=\"" + height + "\"><IMG SRC=\""
+ circleAbsolutePath + "\"/></TD>");
} else {
addTdImageBugB1983(sb, circleAbsolutePath);
}
} else if (circleAbsolutePath.endsWith(".eps")) {
sb.append("<TD><IMG SRC=\"" + circleAbsolutePath + "\"/></TD>");
}
@ -1458,10 +1635,11 @@ final public class DotMaker implements GraphvizMaker {
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("<BR ALIGN=\"LEFT\"/>");
sb.append(manageHtmlIB(stereotype.getLabel(), classes ? FontParam.CLASS_STEREOTYPE
: FontParam.OBJECT_STEREOTYPE));
: FontParam.OBJECT_STEREOTYPE, stereo));
sb.append("<BR/>");
}
String display = entity.getDisplay();
@ -1470,7 +1648,7 @@ final public class DotMaker implements GraphvizMaker {
if (italic) {
display = "<i>" + display;
}
sb.append(manageHtmlIB(display, classes ? FontParam.CLASS : FontParam.OBJECT));
sb.append(manageHtmlIB(display, classes ? FontParam.CLASS : FontParam.OBJECT, stereo));
}
private String getHtmlHeaderTableForClassOrInterfaceOrEnumNew(Entity entity, final String circleAbsolutePath) {

File diff suppressed because it is too large Load Diff

View File

@ -36,48 +36,53 @@ package net.sourceforge.plantuml.cucadiagram.dot;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import javax.imageio.ImageIO;
import net.sourceforge.plantuml.FileUtils;
import net.sourceforge.plantuml.Log;
public class DrawFile {
private final LazyCached<File> png2;
private static final Map<Object, DrawFile> cache = new HashMap<Object, DrawFile>();
private final LazyFile png2;
private final LazyCached<String> svg2;
private final LazyCached<File> eps2;
private final LazyFile eps2;
private int widthPng = -1;
private int heightPng = -1;
public DrawFile(Lazy<File> png) {
this(png, (Lazy<String>) null, null);
public static DrawFile create(Lazy<File> png, Lazy<String> svg, Lazy<File> eps, Object signature) {
DrawFile result = cache.get(signature);
if (result == null) {
result = new DrawFile(png, svg, eps);
cache.put(signature, result);
Log.info("DrawFile cache size = " + cache.size());
FileUtils.deleteOnExit(result);
}
return result;
}
public DrawFile(Lazy<File> png, Lazy<String> svg) {
this(png, svg, null);
public static DrawFile createFromFile(File fPng, String svg, File fEps) {
final DrawFile result = new DrawFile(fPng, svg, fEps);
FileUtils.deleteOnExit(result);
return result;
}
public DrawFile(Lazy<File> png, Lazy<String> svg, Lazy<File> eps) {
this.png2 = new LazyCached<File>(png);
private DrawFile(Lazy<File> png, Lazy<String> svg, Lazy<File> eps) {
this.png2 = new LazyFile(png);
this.svg2 = new LazyCached<String>(svg);
this.eps2 = new LazyCached<File>(eps);
this.eps2 = new LazyFile(eps);
}
public DrawFile(File fPng, String svg, File fEps) {
private DrawFile(File fPng, String svg, File fEps) {
this(new Unlazy<File>(fPng), new Unlazy<String>(svg), new Unlazy<File>(fEps));
if (svg.contains("\\")) {
throw new IllegalArgumentException();
}
public DrawFile(File fPng, String svg, Lazy<File> eps) {
this(new Unlazy<File>(fPng), new Unlazy<String>(svg), eps);
}
public DrawFile(Lazy<File> png, String svg, Lazy<File> eps) {
this(png, new Unlazy<String>(svg), eps);
}
public DrawFile(File f, String svg) {
this(f, svg, (File) null);
}
public File getPngOrEps(boolean isEps) throws IOException {

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5385 $
* Revision $Revision: 5872 $
*
*/
package net.sourceforge.plantuml.cucadiagram.dot;
@ -48,7 +48,10 @@ import java.util.Map;
import javax.imageio.ImageIO;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileUtils;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.OptionFlags;
import net.sourceforge.plantuml.SkinParamBackcolored;
import net.sourceforge.plantuml.cucadiagram.CucaDiagram;
import net.sourceforge.plantuml.cucadiagram.Entity;
import net.sourceforge.plantuml.cucadiagram.EntityType;
@ -57,13 +60,11 @@ import net.sourceforge.plantuml.cucadiagram.GroupHierarchy;
import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.png.PngIO;
import net.sourceforge.plantuml.skin.rose.Rose;
public final class GroupPngMaker {
private final CucaDiagram diagram;
private final Group group;
private final Rose rose = new Rose();
private final FileFormat fileFormat;
class InnerGroupHierarchy implements GroupHierarchy {
@ -115,7 +116,7 @@ public final class GroupPngMaker {
// Color.BLACK).process();
// }
PngIO.write(im, os, diagram.getMetadata());
PngIO.write(im, os, diagram.getMetadata(), 96);
} finally {
cleanTemporaryFiles(imageFiles);
}
@ -143,7 +144,43 @@ public final class GroupPngMaker {
String svg = new String(baos.toByteArray(), "UTF-8");
svg = removeSvgXmlHeader(svg);
return svg;
// // Image management
// final Pattern pImage = Pattern.compile("(?i)<image\\W[^>]*>");
// final Matcher mImage = pImage.matcher(svg);
// final StringBuffer sb = new StringBuffer();
// while (mImage.find()) {
// final String image = mImage.group(0);
// final String href = CucaDiagramFileMaker.getValue(image, "href");
// final double widthSvg =
// Double.parseDouble(CucaDiagramFileMaker.getValuePx(image,
// "width"));
// final double heightSvg =
// Double.parseDouble(CucaDiagramFileMaker.getValuePx(image,
// "height"));
// final double x =
// Double.parseDouble(CucaDiagramFileMaker.getValue(image, "x")) +
// 20;
// final double y =
// Double.parseDouble(CucaDiagramFileMaker.getValue(image, "y")) +
// 20;
// // final DrawFile drawFile = getDrawFileFromHref(href);
// // final int widthPng = drawFile.getWidthPng();
// // final int heightPng = drawFile.getHeightPng();
// // String svg2 = drawFile.getSvg();
// // final String scale = CucaDiagramFileMaker.getScale(widthSvg,
// heightSvg, widthPng, heightPng);
// // svg2 = svg2
// // .replaceFirst("<[gG]>", "<g transform=\"translate(" + 0 + " "
// + 0 + ") " + scale + "\">");
// String svg2 = "<text>toto</text>";
// svg2 = "<svg x=\"" + x + "\" y=\"" + y + "\">" + svg2 + "</svg>";
// mImage.appendReplacement(sb, svg2);
// }
// mImage.appendTail(sb);
// svg = sb.toString();
return svg.replace('\\', '/');
} finally {
cleanTemporaryFiles(imageFiles);
@ -160,15 +197,19 @@ public final class GroupPngMaker {
private void cleanTemporaryFiles(final Map<Entity, File> imageFiles) {
if (OptionFlags.getInstance().isKeepTmpFiles() == false) {
for (File f : imageFiles.values()) {
StaticFiles.delete(f);
FileUtils.delete(f);
}
}
}
GraphvizMaker createDotMaker(List<String> dotStrings) {
final List<Link> links = getPureInnerLinks();
final DotData dotData = new DotData(group, links, group.entities(), diagram.getUmlDiagramType(), diagram
.getSkinParam(), group.getRankdir(), new InnerGroupHierarchy());
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());
// dotData.putAllImages(images);
// dotData.putAllStaticImages(staticImages);
// dotData.putAllImagesLink(imagesLink);

View File

@ -45,12 +45,16 @@ public class LazyCached<O> implements Lazy<O> {
}
public O getNow() throws IOException {
if (data == null) {
if (isLoaded() == false) {
this.data = this.lazy.getNow();
}
return this.data;
}
protected O getRowData() {
return data;
}
public boolean isLoaded() {
return data != null;
}

View File

@ -0,0 +1,55 @@
/* ========================================================================
* 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: 3977 $
*
*/
package net.sourceforge.plantuml.cucadiagram.dot;
import java.io.File;
public class LazyFile extends LazyCached<File> {
public LazyFile(Lazy<File> f) {
super(f);
}
@Override
public boolean isLoaded() {
if (super.isLoaded() == false) {
return false;
}
if (getRowData().exists() == false) {
return false;
}
return true;
}
}

View File

@ -96,7 +96,7 @@ public final class PlayField {
public PlayField(ISkinParam skinParam) {
this.skinParam = skinParam;
this.fontQualif = skinParam.getFont(FontParam.CLASS_ARROW);
this.fontQualif = skinParam.getFont(FontParam.CLASS_ARROW, null);
}
public void initInternal(Collection<IEntity> entities, Collection<Link> links, StringBounder stringBounder) {
@ -259,7 +259,7 @@ public final class PlayField {
final String qual1 = link.getQualifier1();
if (qual1 != null) {
final TextBlock b = TextBlockUtils.create(Arrays.asList(qual1), fontQualif,
skinParam.getFontHtmlColor(FontParam.CLASS_ARROW).getColor(), HorizontalAlignement.LEFT);
skinParam.getFontHtmlColor(FontParam.CLASS_ARROW, null).getColor(), HorizontalAlignement.LEFT);
final Point2D pos = p.getDotPath().getStartPoint();
b.drawU(ug, pos.getX(), pos.getY());
}
@ -267,7 +267,7 @@ public final class PlayField {
final String qual2 = link.getQualifier2();
if (qual2 != null) {
final TextBlock b = TextBlockUtils.create(Arrays.asList(qual2), fontQualif,
skinParam.getFontHtmlColor(FontParam.CLASS_ARROW).getColor(), HorizontalAlignement.LEFT);
skinParam.getFontHtmlColor(FontParam.CLASS_ARROW, null).getColor(), HorizontalAlignement.LEFT);
final Point2D pos = p.getDotPath().getEndPoint();
b.drawU(ug, pos.getX(), pos.getY());
}

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5339 $
* Revision $Revision: 5823 $
*
*/
package net.sourceforge.plantuml.cucadiagram.dot;
@ -39,9 +39,7 @@ import java.awt.Graphics2D;
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.Arrays;
import java.util.EnumMap;
import java.util.EnumSet;
import java.util.Map;
@ -50,16 +48,12 @@ import javax.imageio.ImageIO;
import net.sourceforge.plantuml.ColorParam;
import net.sourceforge.plantuml.EmptyImageBuilder;
import net.sourceforge.plantuml.FileUtils;
import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.Log;
import net.sourceforge.plantuml.OptionFlags;
import net.sourceforge.plantuml.cucadiagram.EntityType;
import net.sourceforge.plantuml.graphic.CircledCharacter;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.StringBounderUtils;
import net.sourceforge.plantuml.skin.CircleInterface;
import net.sourceforge.plantuml.skin.StickMan;
import net.sourceforge.plantuml.skin.UDrawable;
import net.sourceforge.plantuml.skin.VisibilityModifier;
import net.sourceforge.plantuml.skin.rose.Rose;
@ -68,24 +62,9 @@ import net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d;
public class StaticFiles {
private final String circleInterfaceName = "cinterface.png";
private final String lollipopName = "lollipop.png";
private final String actorName = "actor.png";
private final String cName = "stereotypec.png";
private final String iName = "stereotypei.png";
private final String aName = "stereotypea.png";
private final String eName = "stereotypee.png";
private final Color stereotypeCBackground;
private final Color stereotypeIBackground;
private final Color stereotypeABackground;
private final Color stereotypeEBackground;
private final Color interfaceBorder;
private final Color classborder;
private final Color actorBorder;
private final Color classBackground;
private final Color actorBackground;
private final Color interfaceBackground;
private final Color background;
@ -101,262 +80,105 @@ public class StaticFiles {
private final Map<VisibilityModifier, Color> backgroundColor = new EnumMap<VisibilityModifier, Color>(
VisibilityModifier.class);
private static final Collection<DrawFile> toDelete = new ArrayList<DrawFile>();
private final double dpiFactor;
private void deleteOnExit() {
if (toDelete.isEmpty()) {
toDelete.addAll(staticImages.values());
toDelete.addAll(visibilityImages.values());
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
if (OptionFlags.getInstance().isKeepTmpFiles() == false) {
for (DrawFile f : toDelete) {
f.delete();
}
}
}
});
}
}
public StaticFiles(ISkinParam param) throws IOException {
public StaticFiles(ISkinParam param, String stereotype, double dpiFactor) throws IOException {
final Rose rose = new Rose();
radius = param.getCircledCharacterRadius();
circledFont = param.getFont(FontParam.CIRCLED_CHARACTER);
// circledFont = new Font("Courier", Font.BOLD, 17);
this.dpiFactor = dpiFactor;
actorBorder = rose.getHtmlColor(param, ColorParam.actorBorder).getColor();
classborder = rose.getHtmlColor(param, ColorParam.classBorder).getColor();
interfaceBorder = rose.getHtmlColor(param, ColorParam.interfaceBorder).getColor();
interfaceBackground = rose.getHtmlColor(param, ColorParam.interfaceBackground).getColor();
actorBackground = rose.getHtmlColor(param, ColorParam.actorBackground).getColor();
classBackground = rose.getHtmlColor(param, ColorParam.classBackground).getColor();
stereotypeCBackground = rose.getHtmlColor(param, ColorParam.stereotypeCBackground).getColor();
stereotypeABackground = rose.getHtmlColor(param, ColorParam.stereotypeABackground).getColor();
stereotypeIBackground = rose.getHtmlColor(param, ColorParam.stereotypeIBackground).getColor();
stereotypeEBackground = rose.getHtmlColor(param, ColorParam.stereotypeEBackground).getColor();
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();
background = param.getBackgroundColor().getColor();
final File dir = getTmpDir();
staticImages.put(EntityType.LOLLIPOP, ensurePngLollipopPresent(dir));
staticImages.put(EntityType.CIRCLE_INTERFACE, ensurePngCircleInterfacePresent(dir));
staticImages.put(EntityType.ACTOR, ensurePngActorPresent(dir));
staticImages.put(EntityType.ABSTRACT_CLASS, ensurePngAPresent(dir));
staticImages.put(EntityType.CLASS, ensurePngCPresent(dir));
staticImages.put(EntityType.INTERFACE, ensurePngIPresent(dir));
staticImages.put(EntityType.ENUM, ensurePngEPresent(dir));
final File dir = FileUtils.getTmpDir();
staticImages.put(EntityType.LOLLIPOP, getLollipop());
staticImages.put(EntityType.ABSTRACT_CLASS, getCircledCharacter('A', stereotypeABackground));
staticImages.put(EntityType.CLASS, getCircledCharacter('C', stereotypeCBackground));
staticImages.put(EntityType.INTERFACE, getCircledCharacter('I', stereotypeIBackground));
staticImages.put(EntityType.ENUM, getCircledCharacter('E', stereotypeEBackground));
if (param.classAttributeIconSize() > 0) {
for (VisibilityModifier modifier : EnumSet.allOf(VisibilityModifier.class)) {
final Color back = modifier.getBackground() == null ? null : rose.getHtmlColor(param,
modifier.getBackground()).getColor();
final Color fore = rose.getHtmlColor(param, modifier.getForeground()).getColor();
modifier.getBackground(), stereotype).getColor();
final Color fore = rose.getHtmlColor(param, modifier.getForeground(), stereotype).getColor();
backgroundColor.put(modifier, back);
foregroundColor.put(modifier, fore);
visibilityImages.put(modifier,
ensureVisibilityModifierPresent(modifier, dir, param.classAttributeIconSize()));
visibilityImages.put(modifier, getVisibilityModifier(modifier, dir, param.classAttributeIconSize(),
dpiFactor));
}
}
}
deleteOnExit();
}
public File getTmpDir() {
final File tmpDir = new File(System.getProperty("java.io.tmpdir"));
if (tmpDir.exists() == false || tmpDir.isDirectory() == false) {
throw new IllegalStateException();
}
return tmpDir;
}
public static void delete(File f) {
if (f == null) {
return;
}
Thread.yield();
Log.info("Deleting temporary file " + f);
final boolean ok = f.delete();
if (ok == false) {
Log.error("Cannot delete: " + f);
}
}
private DrawFile ensurePngActorPresent(final File dir) throws IOException {
final StickMan stickMan = new StickMan(actorBackground, actorBorder);
final Lazy<File> lpng = new Lazy<File>() {
public File getNow() throws IOException {
final EmptyImageBuilder builder = new EmptyImageBuilder((int) stickMan.getPreferredWidth(null),
(int) stickMan.getPreferredHeight(null), background);
final BufferedImage im = builder.getBufferedImage();
final Graphics2D g2d = builder.getGraphics2D();
stickMan.drawU(new UGraphicG2d(g2d, null));
final File png = new File(dir, actorName);
Log.info("Creating temporary file: " + png);
ImageIO.write(im, "png", png);
return png;
}
};
final Lazy<File> leps = new Lazy<File>() {
public File getNow() throws IOException {
final File epsFile = new File(dir, actorName.replaceFirst("\\.png", ".eps"));
UGraphicEps.copyEpsToFile(stickMan, epsFile);
return epsFile;
}
};
return new DrawFile(lpng, UGraphicG2d.getSvgString(stickMan), leps);
}
private DrawFile ensurePngCircleInterfacePresent(final File dir) throws IOException {
final CircleInterface circleInterface = new CircleInterface(interfaceBackground, interfaceBorder);
final Lazy<File> lpng = new Lazy<File>() {
public File getNow() throws IOException {
final EmptyImageBuilder builder = new EmptyImageBuilder((int) circleInterface.getPreferredWidth(null),
(int) circleInterface.getPreferredHeight(null), background);
final BufferedImage im = builder.getBufferedImage();
final Graphics2D g2d = builder.getGraphics2D();
circleInterface.drawU(new UGraphicG2d(g2d, null));
final File png = new File(dir, circleInterfaceName);
Log.info("Creating temporary file: " + png);
ImageIO.write(im, "png", png);
return png;
}
};
final Lazy<File> leps = new Lazy<File>() {
public File getNow() throws IOException {
final File epsFile = new File(dir, circleInterfaceName.replaceFirst("\\.png", ".eps"));
Log.info("Creating temporary file: " + epsFile);
UGraphicEps.copyEpsToFile(circleInterface, epsFile);
return epsFile;
}
};
return new DrawFile(lpng, UGraphicG2d.getSvgString(circleInterface), leps);
}
private DrawFile ensurePngLollipopPresent(final File dir) throws IOException {
private DrawFile getLollipop() throws IOException {
final CircleInterface circleInterface = new CircleInterface(interfaceBackground, interfaceBorder, 10, 2);
final Lazy<File> lpng = new Lazy<File>() {
public File getNow() throws IOException {
final EmptyImageBuilder builder = new EmptyImageBuilder((int) circleInterface.getPreferredWidth(null),
(int) circleInterface.getPreferredHeight(null), background);
final EmptyImageBuilder builder = new EmptyImageBuilder(circleInterface.getPreferredWidth(null),
circleInterface.getPreferredHeight(null), background);
final BufferedImage im = builder.getBufferedImage();
final Graphics2D g2d = builder.getGraphics2D();
circleInterface.drawU(new UGraphicG2d(g2d, null));
circleInterface.drawU(new UGraphicG2d(g2d, null, dpiFactor));
final File result = new File(dir, lollipopName);
Log.info("Creating temporary file: " + result);
final File result = FileUtils.createTempFile("lollipop", ".png");
ImageIO.write(im, "png", result);
return result;
}
};
final Lazy<File> leps = new Lazy<File>() {
public File getNow() throws IOException {
final File epsFile = new File(dir, lollipopName.replaceFirst("\\.png", ".eps"));
Log.info("Creating temporary file: " + epsFile);
final File epsFile = FileUtils.createTempFile("lollipop", ".eps");
UGraphicEps.copyEpsToFile(circleInterface, epsFile);
return epsFile;
}
};
return new DrawFile(lpng, UGraphicG2d.getSvgString(circleInterface), leps);
}
private DrawFile ensurePngCPresent(File dir) throws IOException {
final CircledCharacter circledCharacter = new CircledCharacter('C', radius, circledFont, stereotypeCBackground,
classborder, Color.BLACK);
return generateCircleCharacterFile(dir, cName, circledCharacter, classBackground);
}
private DrawFile ensurePngAPresent(File dir) throws IOException {
final CircledCharacter circledCharacter = new CircledCharacter('A', radius, circledFont, stereotypeABackground,
classborder, Color.BLACK);
return generateCircleCharacterFile(dir, aName, circledCharacter, classBackground);
}
private DrawFile ensurePngIPresent(File dir) throws IOException {
final CircledCharacter circledCharacter = new CircledCharacter('I', radius, circledFont, stereotypeIBackground,
classborder, Color.BLACK);
return generateCircleCharacterFile(dir, iName, circledCharacter, classBackground);
}
private DrawFile ensurePngEPresent(File dir) throws IOException {
final CircledCharacter circledCharacter = new CircledCharacter('E', radius, circledFont, stereotypeEBackground,
classborder, Color.BLACK);
return generateCircleCharacterFile(dir, eName, circledCharacter, classBackground);
}
private DrawFile generateCircleCharacterFile(File dir, String filename, final CircledCharacter circledCharacter,
final Color yellow) throws IOException {
final File png = new File(dir, filename);
final File epsFile = new File(dir, filename.replaceFirst("\\.png", ".eps"));
return generateCircleCharacter(png, epsFile, circledCharacter, yellow);
}
public DrawFile generateCircleCharacter(final File png, final File epsFile,
final CircledCharacter circledCharacter, final Color yellow) throws IOException {
final Lazy<File> lpng = new Lazy<File>() {
public File getNow() throws IOException {
Log.info("Creating temporary file: " + png);
final EmptyImageBuilder builder = new EmptyImageBuilder(90, 90, yellow);
BufferedImage im = builder.getBufferedImage();
final Graphics2D g2d = builder.getGraphics2D();
final StringBounder stringBounder = StringBounderUtils.asStringBounder(g2d);
circledCharacter.draw(g2d, 0, 0);
im = im.getSubimage(0, 0, (int) circledCharacter.getPreferredWidth(stringBounder) + 5,
(int) circledCharacter.getPreferredHeight(stringBounder) + 1);
ImageIO.write(im, "png", png);
return png;
final Lazy<String> lsvg = new Lazy<String>() {
public String getNow() throws IOException {
return UGraphicG2d.getSvgString(circleInterface);
}
};
final Lazy<File> leps = new Lazy<File>() {
public File getNow() throws IOException {
Log.info("Creating temporary file: " + epsFile);
UGraphicEps.copyEpsToFile(circledCharacter, epsFile);
return epsFile;
}
};
final Object signature = Arrays.asList("lollipop", interfaceBackground, interfaceBorder, background);
return DrawFile.create(lpng, lsvg, leps, signature);
return new DrawFile(lpng, UGraphicG2d.getSvgString(circledCharacter), leps);
}
public final Map<EntityType, DrawFile> getStaticImages() {
return Collections.unmodifiableMap(staticImages);
private DrawFile getCircledCharacter(char c, Color background) throws IOException {
final CircledCharacter circledCharacter = new CircledCharacter(c, radius, circledFont, background, classborder,
Color.BLACK);
return circledCharacter.generateCircleCharacter(classBackground, dpiFactor);
}
public final Map<VisibilityModifier, DrawFile> getVisibilityImages() {
return Collections.unmodifiableMap(visibilityImages);
public DrawFile getStaticImages(EntityType type) {
return staticImages.get(type);
}
public final DrawFile getVisibilityImages(VisibilityModifier visibilityModifier) {
return visibilityImages.get(visibilityModifier);
}
public DrawFile getDrawFile(String pngPath) throws IOException {
@ -376,18 +198,18 @@ public class StaticFiles {
return null;
}
private DrawFile ensureVisibilityModifierPresent(final VisibilityModifier modifier, final File dir, final int size)
throws IOException {
final UDrawable drawable = modifier.getUDrawable(size, foregroundColor.get(modifier),
backgroundColor.get(modifier));
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 Lazy<File> lpng = new Lazy<File>() {
public File getNow() throws IOException {
final File png = new File(dir, modifier.name() + ".png");
Log.info("Creating temporary file: " + png);
final EmptyImageBuilder builder = new EmptyImageBuilder(size, size, classBackground);
final File png = FileUtils.createTempFile("visi", ".png");
final EmptyImageBuilder builder = new EmptyImageBuilder(size * dpiFactor, size * dpiFactor,
classBackground);
final BufferedImage im = builder.getBufferedImage();
drawable.drawU(new UGraphicG2d(builder.getGraphics2D(), im));
drawable.drawU(new UGraphicG2d(builder.getGraphics2D(), im, dpiFactor));
ImageIO.write(im, "png", png);
return png;
}
@ -395,14 +217,22 @@ public class StaticFiles {
final Lazy<File> leps = new Lazy<File>() {
public File getNow() throws IOException {
final File eps = new File(dir, modifier.name() + ".eps");
Log.info("Creating temporary file: " + eps);
final File eps = FileUtils.createTempFile("visi", ".eps");
UGraphicEps.copyEpsToFile(drawable, eps);
return eps;
}
};
return new DrawFile(lpng, UGraphicG2d.getSvgString(drawable), leps);
final Lazy<String> lsvg = new Lazy<String>() {
public String getNow() throws IOException {
return UGraphicG2d.getSvgString(drawable);
}
};
final Object signature = Arrays.asList("visi", modifier, foregroundColor.get(modifier), backgroundColor
.get(modifier), size, classBackground);
return DrawFile.create(lpng, lsvg, leps, signature);
}
}

View File

@ -0,0 +1,72 @@
/* ========================================================================
* 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: 5775 $
*
*/
package net.sourceforge.plantuml.cucadiagram.dot;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import net.sourceforge.plantuml.ISkinParam;
public class StaticFilesMap {
private final Map<String, StaticFiles> map = new HashMap<String, StaticFiles>();
private final ISkinParam param;
private final double dpiFactor;
public StaticFilesMap(ISkinParam param, double dpiFactor) {
this.param = param;
this.dpiFactor = dpiFactor;
}
public StaticFiles getStaticFiles(String stereotype) throws IOException {
StaticFiles result = map.get(stereotype);
if (result == null) {
result = new StaticFiles(param, stereotype, dpiFactor);
map.put(stereotype, result);
}
return result;
}
public DrawFile getDrawFile(String href) throws IOException {
for (StaticFiles staticFiles : map.values()) {
final DrawFile drawFile = staticFiles.getDrawFile(href);
if (drawFile != null) {
return drawFile;
}
}
return null;
}
}

View File

@ -57,7 +57,7 @@ public class GraphicsPath {
public void writeImage(OutputStream os) throws IOException {
final BufferedImage im = createImage();
PngIO.write(im, os);
PngIO.write(im, os, 96);
}
private BufferedImage createImage() {
@ -66,7 +66,7 @@ public class GraphicsPath {
final BufferedImage im = builder.getBufferedImage();
final Graphics2D g2d = builder.getGraphics2D();
final UGraphicG2d ug = new UGraphicG2d(g2d, im);
final UGraphicG2d ug = new UGraphicG2d(g2d, im, 1.0);
ug.getParam().setColor(Color.BLACK);
final UMotif motif = new UMotif(path);
motif.drawHorizontal(ug, 20, 20, 1);

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4984 $
* Revision $Revision: 5794 $
*
*/
package net.sourceforge.plantuml.eggs;
@ -45,7 +45,7 @@ import java.util.List;
import java.util.StringTokenizer;
import net.sourceforge.plantuml.AbstractPSystem;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.graphic.GraphicStrings;
public class PSystemEgg extends AbstractPSystem {
@ -59,7 +59,7 @@ public class PSystemEgg extends AbstractPSystem {
}
}
public List<File> createFiles(File suggestedFile, FileFormat fileFormat) throws IOException, InterruptedException {
public List<File> createFiles(File suggestedFile, FileFormatOption fileFormat) throws IOException, InterruptedException {
OutputStream os = null;
try {
os = new FileOutputStream(suggestedFile);
@ -72,7 +72,7 @@ public class PSystemEgg extends AbstractPSystem {
return Arrays.asList(suggestedFile);
}
public void createFile(OutputStream os, int index, FileFormat fileFormat) throws IOException {
public void createFile(OutputStream os, int index, FileFormatOption fileFormat) throws IOException {
getGraphicStrings().writeImage(os, fileFormat);
}

View File

@ -44,7 +44,7 @@ import java.util.Arrays;
import java.util.List;
import net.sourceforge.plantuml.AbstractPSystem;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.graphic.GraphicStrings;
public class PSystemLost extends AbstractPSystem {
@ -55,7 +55,7 @@ public class PSystemLost extends AbstractPSystem {
strings.add("Thank you for choosing Oceanic Airlines.");
}
public List<File> createFiles(File suggestedFile, FileFormat fileFormat) throws IOException, InterruptedException {
public List<File> createFiles(File suggestedFile, FileFormatOption fileFormat) throws IOException, InterruptedException {
OutputStream os = null;
try {
os = new FileOutputStream(suggestedFile);
@ -68,7 +68,7 @@ public class PSystemLost extends AbstractPSystem {
return Arrays.asList(suggestedFile);
}
public void createFile(OutputStream os, int index, FileFormat fileFormat) throws IOException {
public void createFile(OutputStream os, int index, FileFormatOption fileFormat) throws IOException {
getGraphicStrings().writeImage(os, fileFormat);
}

View File

@ -41,7 +41,7 @@ import java.util.Arrays;
import java.util.List;
import net.sourceforge.plantuml.AbstractPSystem;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
public class PSystemPath extends AbstractPSystem {
@ -52,7 +52,7 @@ public class PSystemPath extends AbstractPSystem {
}
public List<File> createFiles(File suggestedFile, FileFormat fileFormat) throws IOException, InterruptedException {
public List<File> createFiles(File suggestedFile, FileFormatOption fileFormat) throws IOException, InterruptedException {
OutputStream os = null;
try {
os = new FileOutputStream(suggestedFile);
@ -65,7 +65,7 @@ public class PSystemPath extends AbstractPSystem {
return Arrays.asList(suggestedFile);
}
public void createFile(OutputStream os, int index, FileFormat fileFormat) throws IOException {
public void createFile(OutputStream os, int index, FileFormatOption fileFormat) throws IOException {
path.writeImage(os);
}

View File

@ -49,7 +49,7 @@ import java.util.List;
import javax.imageio.ImageIO;
import net.sourceforge.plantuml.AbstractPSystem;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.graphic.GraphicPosition;
import net.sourceforge.plantuml.graphic.GraphicStrings;
@ -75,7 +75,7 @@ public class PSystemRIP extends AbstractPSystem {
is.close();
}
public List<File> createFiles(File suggestedFile, FileFormat fileFormat) throws IOException, InterruptedException {
public List<File> createFiles(File suggestedFile, FileFormatOption fileFormat) throws IOException, InterruptedException {
OutputStream os = null;
try {
os = new FileOutputStream(suggestedFile);
@ -88,7 +88,7 @@ public class PSystemRIP extends AbstractPSystem {
return Arrays.asList(suggestedFile);
}
public void createFile(OutputStream os, int index, FileFormat fileFormat) throws IOException {
public void createFile(OutputStream os, int index, FileFormatOption fileFormat) throws IOException {
getGraphicStrings().writeImage(os, fileFormat);
}

View File

@ -40,8 +40,8 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import net.sourceforge.plantuml.FileUtils;
import net.sourceforge.plantuml.OptionFlags;
import net.sourceforge.plantuml.cucadiagram.dot.CucaDiagramFileMaker;
public class SvgToEpsConverter {
@ -53,7 +53,7 @@ public class SvgToEpsConverter {
throw new IllegalArgumentException();
}
this.inkscape = InkscapeUtils.create();
this.svgFile = CucaDiagramFileMaker.createTempFile("convert", ".svg");
this.svgFile = FileUtils.createTempFile("convert", ".svg");
final PrintWriter pw = new PrintWriter(svgFile);
pw.println(svg);
pw.close();
@ -73,7 +73,7 @@ public class SvgToEpsConverter {
public void createEps(OutputStream os) throws IOException, InterruptedException {
final File epsFile = CucaDiagramFileMaker.createTempFile("eps", ".eps");
final File epsFile = FileUtils.createTempFile("eps", ".eps");
createEps(epsFile);
int read;
final InputStream is = new FileInputStream(epsFile);

View File

@ -28,7 +28,7 @@
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5609 $
* Revision $Revision: 5798 $
*
*/
package net.sourceforge.plantuml.graph;
@ -146,7 +146,7 @@ class EntityImageClass extends AbstractEntityImage {
methods.drawTOBEREMOVED(g2d, xMargin, line2 + yMargin);
if (circledCharacter != null) {
circledCharacter.draw(g2d, xMargin, yMargin);
circledCharacter.draw(g2d, xMargin, yMargin, 1.0);
}
}

View File

@ -67,7 +67,7 @@ public class MethodsOrFieldsArea2 {
public MethodsOrFieldsArea2(List<Member> attributes, FontParam fontParam, ISkinParam skinParam) {
this.members.addAll(attributes);
this.skinParam = skinParam;
this.font = skinParam.getFont(fontParam);
this.font = skinParam.getFont(fontParam, null);
this.color = rose.getFontColor(skinParam, FontParam.CLASS_ATTRIBUTE);
}

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