diff --git a/pom.xml b/pom.xml index f6762d6c6..14bf8d890 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ net.sourceforge.plantuml plantuml - 6141-SNAPSHOT + 6210-SNAPSHOT jar PlantUML diff --git a/src/net/sourceforge/plantuml/Option.java b/src/net/sourceforge/plantuml/Option.java index 0e0a5e834..f736a75db 100644 --- a/src/net/sourceforge/plantuml/Option.java +++ b/src/net/sourceforge/plantuml/Option.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6130 $ + * Revision $Revision: 6187 $ * */ package net.sourceforge.plantuml; @@ -57,6 +57,7 @@ public class Option { private boolean decodeurl = false; private boolean pipe = false; private boolean syntax = false; + private boolean pattern = false; private File outputDir = null; private final List result = new ArrayList(); @@ -147,6 +148,8 @@ public class Option { OptionFlags.getInstance().setVerbose(true); } else if (s.equalsIgnoreCase("-pipe") || s.equalsIgnoreCase("-p")) { pipe = true; + } else if (s.equalsIgnoreCase("-pattern")) { + pattern = true; } else if (s.equalsIgnoreCase("-syntax")) { syntax = true; OptionFlags.getInstance().setQuiet(true); @@ -270,6 +273,10 @@ public class Option { return syntax; } + public final boolean isPattern() { + return pattern; + } + public FileFormatOption getFileFormatOption() { return new FileFormatOption(getFileFormat()); } diff --git a/src/net/sourceforge/plantuml/PSystemBuilder.java b/src/net/sourceforge/plantuml/PSystemBuilder.java index d229c1414..8ffd84187 100644 --- a/src/net/sourceforge/plantuml/PSystemBuilder.java +++ b/src/net/sourceforge/plantuml/PSystemBuilder.java @@ -49,6 +49,7 @@ import net.sourceforge.plantuml.eggs.PSystemPathFactory; import net.sourceforge.plantuml.eggs.PSystemRIPFactory; import net.sourceforge.plantuml.objectdiagram.ObjectDiagramFactory; import net.sourceforge.plantuml.oregon.PSystemOregonFactory; +import net.sourceforge.plantuml.postit.PostIdDiagramFactory; import net.sourceforge.plantuml.printskin.PrintSkinFactory; import net.sourceforge.plantuml.sequencediagram.SequenceDiagramFactory; import net.sourceforge.plantuml.statediagram.StateDiagramFactory; @@ -71,6 +72,7 @@ public class PSystemBuilder { factories.add(new ActivityDiagramFactory2()); factories.add(new CompositeDiagramFactory()); factories.add(new ObjectDiagramFactory()); + factories.add(new PostIdDiagramFactory()); factories.add(new PrintSkinFactory()); factories.add(new PSystemVersionFactory()); factories.add(new PSystemSudokuFactory()); diff --git a/src/net/sourceforge/plantuml/Run.java b/src/net/sourceforge/plantuml/Run.java index e8b2bfa6d..a0e6f777e 100644 --- a/src/net/sourceforge/plantuml/Run.java +++ b/src/net/sourceforge/plantuml/Run.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5969 $ + * Revision $Revision: 6188 $ * */ package net.sourceforge.plantuml; @@ -39,15 +39,34 @@ import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintStream; +import java.util.ArrayList; import java.util.List; import javax.swing.UIManager; +import net.sourceforge.plantuml.activitydiagram.ActivityDiagramFactory; +import net.sourceforge.plantuml.activitydiagram2.ActivityDiagramFactory2; +import net.sourceforge.plantuml.classdiagram.ClassDiagramFactory; import net.sourceforge.plantuml.code.Transcoder; import net.sourceforge.plantuml.code.TranscoderUtil; +import net.sourceforge.plantuml.command.AbstractUmlSystemCommandFactory; +import net.sourceforge.plantuml.componentdiagram.ComponentDiagramFactory; +import net.sourceforge.plantuml.compositediagram.CompositeDiagramFactory; +import net.sourceforge.plantuml.eggs.PSystemEggFactory; +import net.sourceforge.plantuml.eggs.PSystemLostFactory; +import net.sourceforge.plantuml.eggs.PSystemPathFactory; +import net.sourceforge.plantuml.eggs.PSystemRIPFactory; +import net.sourceforge.plantuml.objectdiagram.ObjectDiagramFactory; +import net.sourceforge.plantuml.oregon.PSystemOregonFactory; import net.sourceforge.plantuml.png.MetadataTag; import net.sourceforge.plantuml.preproc.Defines; +import net.sourceforge.plantuml.printskin.PrintSkinFactory; +import net.sourceforge.plantuml.sequencediagram.SequenceDiagramFactory; +import net.sourceforge.plantuml.statediagram.StateDiagramFactory; +import net.sourceforge.plantuml.sudoku.PSystemSudokuFactory; import net.sourceforge.plantuml.swing.MainWindow; +import net.sourceforge.plantuml.usecasediagram.UsecaseDiagramFactory; +import net.sourceforge.plantuml.version.PSystemVersionFactory; public class Run { @@ -56,7 +75,9 @@ public class Run { if (OptionFlags.getInstance().isVerbose()) { Log.info("GraphicsEnvironment.isHeadless() " + GraphicsEnvironment.isHeadless()); } - if (OptionFlags.getInstance().isGui()) { + if (option.isPattern()) { + managePattern(); + } else if (OptionFlags.getInstance().isGui()) { try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception e) { @@ -69,6 +90,24 @@ public class Run { } } + private static void managePattern() { + printPattern(new SequenceDiagramFactory()); + printPattern(new ClassDiagramFactory()); + printPattern(new ActivityDiagramFactory()); + printPattern(new UsecaseDiagramFactory()); + printPattern(new ComponentDiagramFactory()); + printPattern(new StateDiagramFactory()); + printPattern(new ObjectDiagramFactory()); + } + + private static void printPattern(AbstractUmlSystemCommandFactory factory) { + System.out.println(); + System.out.println(factory.getClass().getSimpleName().replaceAll("Factory", "")); + for (String s : factory.getDescription()) { + System.out.println(s); + } + } + private static void managePipe(Option option) throws IOException { final String charset = option.getCharset(); final BufferedReader br; @@ -127,8 +166,8 @@ public class Run { System.out.println(new MetadataTag(f, "plantuml").getData()); System.out.println("------------------------"); } else { - final SourceFileReader sourceFileReader = new SourceFileReader(option.getDefaultDefines(), f, option - .getOutputDir(), option.getConfig(), option.getCharset(), option.getFileFormatOption()); + final SourceFileReader sourceFileReader = new SourceFileReader(option.getDefaultDefines(), f, + option.getOutputDir(), option.getConfig(), option.getCharset(), option.getFileFormatOption()); if (option.isComputeurl()) { final List urls = sourceFileReader.getEncodedUrl(); for (String s : urls) { diff --git a/src/net/sourceforge/plantuml/activitydiagram2/ActivityDiagram2.java b/src/net/sourceforge/plantuml/activitydiagram2/ActivityDiagram2.java index 5aa30a503..2455c0c4f 100644 --- a/src/net/sourceforge/plantuml/activitydiagram2/ActivityDiagram2.java +++ b/src/net/sourceforge/plantuml/activitydiagram2/ActivityDiagram2.java @@ -100,10 +100,10 @@ public class ActivityDiagram2 extends CucaDiagram { afterAdd(act); } - private void afterAdd(final Entity act) { + private void afterAdd(final IEntity act) { for (IEntity last : this.waitings) { - System.err.println("last=" + last); - System.err.println("act=" + act); + // System.err.println("last=" + last); + // System.err.println("act=" + act); this.addLink(new Link(last, act, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), futureLabel, futureLength)); futureLabel = null; } @@ -117,15 +117,14 @@ public class ActivityDiagram2 extends CucaDiagram { this.waitings.add(act); this.futureLength = 2; } - + public IEntity getLastEntityConsulted() { - if (waitings.size()==1) { + if (waitings.size() == 1) { return waitings.iterator().next(); } return null; } - private String getAutoCode() { return "ac" + UniqueSequence.getValue(); } @@ -142,7 +141,8 @@ public class ActivityDiagram2 extends CucaDiagram { currentContext = new ConditionalContext2(currentContext, br, Direction.DOWN, when); for (IEntity last : this.waitings) { if (test == null) { - // this.addLink(new Link(last, br, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), test, futureLength)); + // this.addLink(new Link(last, br, new LinkType(LinkDecor.ARROW, + // LinkDecor.NONE), test, futureLength)); throw new IllegalArgumentException(); } else { this.addLink(new Link(last, br, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), this.futureLabel, @@ -162,14 +162,14 @@ public class ActivityDiagram2 extends CucaDiagram { public void endif() { final boolean hasElse = currentContext.isHasElse(); - System.err.println("CALL endif hasElse " + hasElse); +// System.err.println("CALL endif hasElse " + hasElse); this.waitings.addAll(currentContext.getPendings()); currentContext = currentContext.getParent(); - if (currentContext == null) { - System.err.println("after endif " + currentContext); - } else { - System.err.println("after endif " + currentContext.getPendings()); - } + // if (currentContext == null) { + // System.err.println("after endif " + currentContext); + // } else { + // System.err.println("after endif " + currentContext.getPendings()); + // } } public void else2(String when) { @@ -196,7 +196,7 @@ public class ActivityDiagram2 extends CucaDiagram { private final Collection pendingLinks = new ArrayList(); public void callGoto(String gotoLabel) { - System.err.println("CALL goto " + gotoLabel); + // System.err.println("CALL goto " + gotoLabel); final IEntity dest = labels.get(gotoLabel); for (IEntity last : this.waitings) { if (dest == null) { @@ -206,14 +206,17 @@ public class ActivityDiagram2 extends CucaDiagram { this.futureLength)); } } - System.err.println("Avant fin goto, waitings=" + waitings); + // System.err.println("Avant fin goto, waitings=" + waitings); this.waitings.clear(); // currentContext.clearPendingsButFirst(); } public void end() { - // TODO Auto-generated method stub - + if (waitings.size() == 0) { + throw new IllegalStateException(); + } + final IEntity act = getOrCreateEntity("end", EntityType.CIRCLE_END); + afterAdd(act); } } diff --git a/src/net/sourceforge/plantuml/activitydiagram2/ActivityDiagramFactory2.java b/src/net/sourceforge/plantuml/activitydiagram2/ActivityDiagramFactory2.java index 3b85e0e16..5df1311e4 100644 --- a/src/net/sourceforge/plantuml/activitydiagram2/ActivityDiagramFactory2.java +++ b/src/net/sourceforge/plantuml/activitydiagram2/ActivityDiagramFactory2.java @@ -42,6 +42,7 @@ import net.sourceforge.plantuml.activitydiagram2.command.CommandIf2; import net.sourceforge.plantuml.activitydiagram2.command.CommandLabel2; import net.sourceforge.plantuml.activitydiagram2.command.CommandMultilinesNoteActivity2; import net.sourceforge.plantuml.activitydiagram2.command.CommandNewActivity2; +import net.sourceforge.plantuml.activitydiagram2.command.CommandNewMultilinesActivity2; import net.sourceforge.plantuml.activitydiagram2.command.CommandStart2; import net.sourceforge.plantuml.command.AbstractUmlSystemCommandFactory; @@ -83,6 +84,7 @@ public class ActivityDiagramFactory2 extends AbstractUmlSystemCommandFactory { // addCommand(new CommandElse(system)); // addCommand(new CommandEndif(system)); // addCommand(new CommandInnerConcurrent(system)); + addCommand(new CommandNewMultilinesActivity2(system)); } } diff --git a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandNewMultilinesActivity2.java b/src/net/sourceforge/plantuml/activitydiagram2/command/CommandNewMultilinesActivity2.java new file mode 100644 index 000000000..a88039a16 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram2/command/CommandNewMultilinesActivity2.java @@ -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: 5751 $ + * + */ +package net.sourceforge.plantuml.activitydiagram2.command; + +import java.util.List; + +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.activitydiagram2.ActivityDiagram2; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.CommandMultilines; + +public class CommandNewMultilinesActivity2 extends CommandMultilines { + + public CommandNewMultilinesActivity2(final ActivityDiagram2 system) { + super(system, "(?i)^[\"<].*$", "(?i)^.*[\">]$"); + } + + public final CommandExecutionResult execute(List lines) { + if (getSystem().entities().size() == 0) { + return CommandExecutionResult.error("Missing start keyword"); + } + + if (getSystem().isReachable() == false) { + return CommandExecutionResult.error("Unreachable statement"); + } + String s = StringUtils.getMergedLines(lines); + s = s.substring(1, s.length() - 2); + + getSystem().newActivity(s); + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/classdiagram/AbstractEntityDiagram.java b/src/net/sourceforge/plantuml/classdiagram/AbstractEntityDiagram.java index be8839c4a..db736db7c 100644 --- a/src/net/sourceforge/plantuml/classdiagram/AbstractEntityDiagram.java +++ b/src/net/sourceforge/plantuml/classdiagram/AbstractEntityDiagram.java @@ -28,12 +28,14 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6095 $ + * Revision $Revision: 6192 $ * */ package net.sourceforge.plantuml.classdiagram; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import net.sourceforge.plantuml.cucadiagram.CucaDiagram; @@ -43,16 +45,24 @@ public abstract class AbstractEntityDiagram extends CucaDiagram { abstract public IEntity getOrCreateClass(String code); - protected List getDotStrings() { -// return Arrays.asList("nodesep=.5;", "ranksep=0.8;", "edge [fontsize=11,labelfontsize=11];", -// "node [fontsize=11,height=.35,width=.55];"); - return Arrays.asList("nodesep=.35;", "ranksep=0.8;", "edge [fontsize=11,labelfontsize=11];", - "node [fontsize=11,height=.35,width=.55];"); + final protected List getDotStrings() { + // return Arrays.asList("nodesep=.5;", "ranksep=0.8;", "edge + // [fontsize=11,labelfontsize=11];", + // "node [fontsize=11,height=.35,width=.55];"); + + final List def = Arrays.asList("nodesep=.35;", "ranksep=0.8;", "edge [fontsize=11,labelfontsize=11];", + "node [fontsize=11,height=.35,width=.55];"); + if (getPragma().isDefine("graphattributes")==false) { + return def; + } + final String attribute = getPragma().getValue("graphattributes"); + final List result = new ArrayList(def); + result.add(attribute); + return Collections.unmodifiableList(result); } final public String getDescription() { return "(" + entities().size() + " entities)"; } - } diff --git a/src/net/sourceforge/plantuml/classdiagram/ClassDiagram.java b/src/net/sourceforge/plantuml/classdiagram/ClassDiagram.java index 00f7cbb81..d014aa124 100644 --- a/src/net/sourceforge/plantuml/classdiagram/ClassDiagram.java +++ b/src/net/sourceforge/plantuml/classdiagram/ClassDiagram.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5895 $ + * Revision $Revision: 6167 $ * */ package net.sourceforge.plantuml.classdiagram; @@ -146,4 +146,5 @@ public class ClassDiagram extends AbstractClassOrObjectDiagram { return UmlDiagramType.CLASS; } + } diff --git a/src/net/sourceforge/plantuml/classdiagram/ClassDiagramFactory.java b/src/net/sourceforge/plantuml/classdiagram/ClassDiagramFactory.java index 1ad3790a0..1aeb84c12 100644 --- a/src/net/sourceforge/plantuml/classdiagram/ClassDiagramFactory.java +++ b/src/net/sourceforge/plantuml/classdiagram/ClassDiagramFactory.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5613 $ + * Revision $Revision: 6169 $ * */ package net.sourceforge.plantuml.classdiagram; @@ -38,6 +38,7 @@ import net.sourceforge.plantuml.classdiagram.command.CommandCreateEntityClass2; import net.sourceforge.plantuml.classdiagram.command.CommandCreateEntityClassMultilines2; import net.sourceforge.plantuml.classdiagram.command.CommandEndNamespace; import net.sourceforge.plantuml.classdiagram.command.CommandHideShow; +import net.sourceforge.plantuml.classdiagram.command.CommandHideShow3; import net.sourceforge.plantuml.classdiagram.command.CommandImport; import net.sourceforge.plantuml.classdiagram.command.CommandLinkClass2; import net.sourceforge.plantuml.classdiagram.command.CommandLinkLollipop; @@ -93,6 +94,7 @@ public class ClassDiagramFactory extends AbstractUmlSystemCommandFactory { // addCommand(new CommandCreateEntityClassMultilines(system)); addCommand(new CommandCreateEntityClassMultilines2(system)); + addCommand(new CommandHideShow3(system)); addCommand(new CommandHideShow(system)); } diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandHideShow.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandHideShow.java index de816aa4d..65eabe9c4 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandHideShow.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandHideShow.java @@ -34,19 +34,22 @@ package net.sourceforge.plantuml.classdiagram.command; import java.util.EnumSet; -import java.util.List; +import java.util.Map; import java.util.Set; import net.sourceforge.plantuml.classdiagram.ClassDiagram; 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.RegexPartialMatch; import net.sourceforge.plantuml.cucadiagram.EntityGender; import net.sourceforge.plantuml.cucadiagram.EntityGenderUtils; import net.sourceforge.plantuml.cucadiagram.EntityPortion; import net.sourceforge.plantuml.cucadiagram.EntityType; import net.sourceforge.plantuml.cucadiagram.IEntity; -public class CommandHideShow extends SingleLineCommand { +public class CommandHideShow extends SingleLineCommand2 { private static final EnumSet PORTION_METHOD = EnumSet. of(EntityPortion.METHOD); private static final EnumSet PORTION_MEMBER = EnumSet. of(EntityPortion.FIELD, @@ -54,9 +57,18 @@ public class CommandHideShow extends SingleLineCommand { private static final EnumSet PORTION_FIELD = EnumSet. of(EntityPortion.FIELD); public CommandHideShow(ClassDiagram classDiagram) { - super( - classDiagram, - "(?i)^(hide|show)\\s+(?:(class|interface|enum|abstract|[\\p{L}0-9_.]+|\"[^\"]+\"|\\<\\<.*\\>\\>)\\s+)*?(?:(empty)\\s+)?(members?|attributes?|fields?|methods?|circle\\w*|stereotypes?)$"); + super(classDiagram, getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("COMMAND", "(hide|show)"), // + new RegexLeaf("\\s+"), // + new RegexLeaf("GENDER", + "(?:(class|interface|enum|abstract|[\\p{L}0-9_.]+|\"[^\"]+\"|\\<\\<.*\\>\\>)\\s+)*?"), // + new RegexLeaf("EMPTY", "(?:(empty)\\s+)?"), // + new RegexLeaf("PORTION", "(members?|attributes?|fields?|methods?|circle\\w*|stereotypes?)"), // + new RegexLeaf("$")); } private final EntityGender emptyByGender(Set portion) { @@ -73,35 +85,38 @@ public class CommandHideShow extends SingleLineCommand { } @Override - protected CommandExecutionResult executeArg(List arg) { - final Set portion = getEntityPortion(arg.get(3)); + protected CommandExecutionResult executeArg(Map arg) { + + final Set portion = getEntityPortion(arg.get("PORTION").get(0)); EntityGender gender = null; - if (arg.get(1) == null) { + final String arg1 = arg.get("GENDER").get(0); + + if (arg1 == null) { gender = EntityGenderUtils.all(); - } else if (arg.get(1).equalsIgnoreCase("class")) { + } else if (arg1.equalsIgnoreCase("class")) { gender = EntityGenderUtils.byEntityType(EntityType.CLASS); - } else if (arg.get(1).equalsIgnoreCase("interface")) { + } else if (arg1.equalsIgnoreCase("interface")) { gender = EntityGenderUtils.byEntityType(EntityType.INTERFACE); - } else if (arg.get(1).equalsIgnoreCase("enum")) { + } else if (arg1.equalsIgnoreCase("enum")) { gender = EntityGenderUtils.byEntityType(EntityType.ENUM); - } else if (arg.get(1).equalsIgnoreCase("abstract")) { + } else if (arg1.equalsIgnoreCase("abstract")) { gender = EntityGenderUtils.byEntityType(EntityType.ABSTRACT_CLASS); - } else if (arg.get(1).startsWith("<<")) { - gender = EntityGenderUtils.byStereotype(arg.get(1)); + } else if (arg1.startsWith("<<")) { + gender = EntityGenderUtils.byStereotype(arg1); } else { - final IEntity entity = getSystem().getOrCreateClass(arg.get(1)); + final IEntity entity = getSystem().getOrCreateClass(arg1); gender = EntityGenderUtils.byEntityAlone(entity); } if (gender != null) { - final boolean empty = arg.get(2) != null; + final boolean empty = arg.get("EMPTY").get(0) != null; if (empty == true) { gender = EntityGenderUtils.and(gender, emptyByGender(portion)); } if (getSystem().getCurrentGroup() != null) { gender = EntityGenderUtils.and(gender, EntityGenderUtils.byPackage(getSystem().getCurrentGroup())); } - getSystem().hideOrShow(gender, portion, arg.get(0).equalsIgnoreCase("show")); + getSystem().hideOrShow(gender, portion, arg.get("COMMAND").get(0).equalsIgnoreCase("show")); } return CommandExecutionResult.ok(); } @@ -125,4 +140,5 @@ public class CommandHideShow extends SingleLineCommand { } throw new IllegalArgumentException(); } + } diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandHideShow3.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandHideShow3.java new file mode 100644 index 000000000..b51dbb753 --- /dev/null +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandHideShow3.java @@ -0,0 +1,129 @@ +/* ======================================================================== + * 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: 5019 $ + * + */ +package net.sourceforge.plantuml.classdiagram.command; + +import java.util.EnumSet; +import java.util.Map; +import java.util.Set; +import java.util.StringTokenizer; + +import net.sourceforge.plantuml.classdiagram.ClassDiagram; +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.RegexPartialMatch; +import net.sourceforge.plantuml.cucadiagram.EntityPortion; +import net.sourceforge.plantuml.skin.VisibilityModifier; + +public class CommandHideShow3 extends SingleLineCommand2 { + + private static final EnumSet PORTION_METHOD = EnumSet. of(EntityPortion.METHOD); + private static final EnumSet PORTION_MEMBER = EnumSet. of(EntityPortion.FIELD, + EntityPortion.METHOD); + private static final EnumSet PORTION_FIELD = EnumSet. of(EntityPortion.FIELD); + + public CommandHideShow3(ClassDiagram classDiagram) { + super(classDiagram, getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("COMMAND", "(hide|show)"), // + new RegexLeaf("\\s+"), // + new RegexLeaf("VISIBILITY", + "((?:public|private|protected|package)?(?:[,\\s]+(?:public|private|protected|package))*)"), // + new RegexLeaf("\\s+"), // + new RegexLeaf("PORTION", "(members?|attributes?|fields?|methods?)"), // + new RegexLeaf("$")); + } + + @Override + protected CommandExecutionResult executeArg(Map arg) { + + final Set portion = getEntityPortion(arg.get("PORTION").get(0)); + + final Set visibilities = EnumSet. noneOf(VisibilityModifier.class); + final StringTokenizer st = new StringTokenizer(arg.get("VISIBILITY").get(0).toLowerCase(), " ,"); + while (st.hasMoreTokens()) { + addVisibilities(st.nextToken(), portion, visibilities); + } + + getSystem().hideOrShow(visibilities, arg.get("COMMAND").get(0).equalsIgnoreCase("show")); + + return CommandExecutionResult.ok(); + } + + private void addVisibilities(String token, Set portion, Set result) { + if (token.equals("public") && portion.contains(EntityPortion.FIELD)) { + result.add(VisibilityModifier.PUBLIC_FIELD); + } + if (token.equals("public") && portion.contains(EntityPortion.METHOD)) { + result.add(VisibilityModifier.PUBLIC_METHOD); + } + if (token.equals("private") && portion.contains(EntityPortion.FIELD)) { + result.add(VisibilityModifier.PRIVATE_FIELD); + } + if (token.equals("private") && portion.contains(EntityPortion.METHOD)) { + result.add(VisibilityModifier.PRIVATE_METHOD); + } + if (token.equals("protected") && portion.contains(EntityPortion.FIELD)) { + result.add(VisibilityModifier.PROTECTED_FIELD); + } + if (token.equals("protected") && portion.contains(EntityPortion.METHOD)) { + result.add(VisibilityModifier.PROTECTED_METHOD); + } + if (token.equals("package") && portion.contains(EntityPortion.FIELD)) { + result.add(VisibilityModifier.PACKAGE_PRIVATE_FIELD); + } + if (token.equals("package") && portion.contains(EntityPortion.METHOD)) { + result.add(VisibilityModifier.PACKAGE_PRIVATE_METHOD); + } + } + + private Set getEntityPortion(String s) { + final String sub = s.substring(0, 3).toLowerCase(); + if (sub.equals("met")) { + return PORTION_METHOD; + } + if (sub.equals("mem")) { + return PORTION_MEMBER; + } + if (sub.equals("att") || sub.equals("fie")) { + return PORTION_FIELD; + } + throw new IllegalArgumentException(); + } + +} diff --git a/src/net/sourceforge/plantuml/code/AsciiEncoder.java b/src/net/sourceforge/plantuml/code/AsciiEncoder.java index c3786bfe4..9ac76f9c8 100644 --- a/src/net/sourceforge/plantuml/code/AsciiEncoder.java +++ b/src/net/sourceforge/plantuml/code/AsciiEncoder.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3827 $ + * Revision $Revision: 6170 $ * */ package net.sourceforge.plantuml.code; @@ -55,7 +55,9 @@ public class AsciiEncoder implements URLEncoder { } public byte[] decode(String s) { - assert s.length() % 4 == 0 : "Cannot decode " + s; + if (s.length() % 4 != 0) { + throw new IllegalArgumentException("Cannot decode " + s); + } final byte data[] = new byte[(s.length() * 3 + 3) / 4]; int pos = 0; for (int i = 0; i < s.length(); i += 4) { diff --git a/src/net/sourceforge/plantuml/command/AbstractUmlSystemCommandFactory.java b/src/net/sourceforge/plantuml/command/AbstractUmlSystemCommandFactory.java index 5deb62d4b..e95823323 100644 --- a/src/net/sourceforge/plantuml/command/AbstractUmlSystemCommandFactory.java +++ b/src/net/sourceforge/plantuml/command/AbstractUmlSystemCommandFactory.java @@ -28,12 +28,14 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6097 $ + * Revision $Revision: 6191 $ * */ package net.sourceforge.plantuml.command; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import net.sourceforge.plantuml.UmlDiagram; @@ -82,6 +84,7 @@ public abstract class AbstractUmlSystemCommandFactory implements PSystemCommandF final protected void addCommonCommands(UmlDiagram system) { addCommand(new CommandNope(system)); + addCommand(new CommandMultilinesComment(system)); addCommand(new CommandPragma(system)); addCommand(new CommandTitle(system)); addCommand(new CommandMultilinesTitle(system)); @@ -107,4 +110,13 @@ public abstract class AbstractUmlSystemCommandFactory implements PSystemCommandF cmds.add(cmd); } + final public List getDescription() { + final List result = new ArrayList(); + for (Command cmd : cmds) { + result.addAll(Arrays.asList(cmd.getDescription())); + } + return Collections.unmodifiableList(result); + + } + } diff --git a/src/net/sourceforge/plantuml/command/Command.java b/src/net/sourceforge/plantuml/command/Command.java index 1e48903d5..ef9453be8 100644 --- a/src/net/sourceforge/plantuml/command/Command.java +++ b/src/net/sourceforge/plantuml/command/Command.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4762 $ + * Revision $Revision: 6184 $ * */ package net.sourceforge.plantuml.command; @@ -44,5 +44,7 @@ public interface Command { boolean isDeprecated(List lines); String getHelpMessageForDeprecated(List lines); + + String[] getDescription(); } diff --git a/src/net/sourceforge/plantuml/command/CommandMultilines.java b/src/net/sourceforge/plantuml/command/CommandMultilines.java index 272702b28..c5f3f975c 100644 --- a/src/net/sourceforge/plantuml/command/CommandMultilines.java +++ b/src/net/sourceforge/plantuml/command/CommandMultilines.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5749 $ + * Revision $Revision: 6186 $ * */ package net.sourceforge.plantuml.command; @@ -57,6 +57,10 @@ public abstract class CommandMultilines implements Command { this.starting = Pattern.compile(patternStart); this.ending = Pattern.compile(patternEnd); } + + public String[] getDescription() { + return new String[] { "START: " + starting.pattern(), "END: " + ending.pattern() }; + } final public CommandControl isValid(List lines) { if (isCommandForbidden()) { diff --git a/src/net/sourceforge/plantuml/command/CommandMultilines2.java b/src/net/sourceforge/plantuml/command/CommandMultilines2.java index a557daead..11799034d 100644 --- a/src/net/sourceforge/plantuml/command/CommandMultilines2.java +++ b/src/net/sourceforge/plantuml/command/CommandMultilines2.java @@ -58,6 +58,10 @@ public abstract class CommandMultilines2 implements Command { this.starting = patternStart; this.ending = Pattern.compile(patternEnd); } + + public String[] getDescription() { + return new String[] { "START: "+starting.getPattern(), "END: "+ending.pattern() }; + } final public CommandControl isValid(List lines) { if (isCommandForbidden()) { diff --git a/src/net/sourceforge/plantuml/command/CommandMultilinesBracket.java b/src/net/sourceforge/plantuml/command/CommandMultilinesBracket.java index 7e02dfc9a..e17ac0c8d 100644 --- a/src/net/sourceforge/plantuml/command/CommandMultilinesBracket.java +++ b/src/net/sourceforge/plantuml/command/CommandMultilinesBracket.java @@ -56,6 +56,10 @@ public abstract class CommandMultilinesBracket implements Com protected boolean isCommandForbidden() { return false; } + + public String[] getDescription() { + return new String[] { "BRACKET: " + starting.pattern() }; + } protected void actionIfCommandValid() { } diff --git a/src/net/sourceforge/plantuml/command/CommandMultilinesComment.java b/src/net/sourceforge/plantuml/command/CommandMultilinesComment.java new file mode 100644 index 000000000..32ad7ea8a --- /dev/null +++ b/src/net/sourceforge/plantuml/command/CommandMultilinesComment.java @@ -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: 5957 $ + * + */ +package net.sourceforge.plantuml.command; + +import java.util.List; + +import net.sourceforge.plantuml.UmlDiagram; + +public class CommandMultilinesComment extends CommandMultilines { + + public CommandMultilinesComment(final UmlDiagram diagram) { + super(diagram, "(?i)^\\s*/'.*$", "(?i)^.*'/\\s*$"); + } + + public CommandExecutionResult execute(List lines) { + System.err.println(lines); + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/command/CommandPackage.java b/src/net/sourceforge/plantuml/command/CommandPackage.java index 72ead852f..838ee0fe7 100644 --- a/src/net/sourceforge/plantuml/command/CommandPackage.java +++ b/src/net/sourceforge/plantuml/command/CommandPackage.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5983 $ + * Revision $Revision: 6209 $ * */ package net.sourceforge.plantuml.command; @@ -36,6 +36,7 @@ package net.sourceforge.plantuml.command; import java.util.List; import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.UniqueSequence; import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram; import net.sourceforge.plantuml.cucadiagram.Group; import net.sourceforge.plantuml.cucadiagram.GroupType; @@ -45,7 +46,8 @@ public class CommandPackage extends SingleLineCommand { public CommandPackage(AbstractEntityDiagram diagram) { super(diagram, - "(?i)^package\\s+(\"[^\"]+\"|\\S+)(?:\\s+as\\s+([\\p{L}0-9_.]+))?\\s*(#[0-9a-fA-F]{6}|#?\\w+)?\\s*\\{?$"); + "(?i)^package\\s+(\"[^\"]+\"|[^#\\s{}]*)(?:\\s+as\\s+([\\p{L}0-9_.]+))?\\s*(#[0-9a-fA-F]{6}|#?\\w+)?\\s*\\{?$"); + // "(?i)^package\\s+(\"[^\"]+\"|\\S+)(?:\\s+as\\s+([\\p{L}0-9_.]+))?\\s*(#[0-9a-fA-F]{6}|#?\\w+)?\\s*\\{?$"); } @Override @@ -53,16 +55,22 @@ public class CommandPackage extends SingleLineCommand { final String code; final String display; if (arg.get(1) == null) { - code = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(0)); - display = code; + if (StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(0)).length() == 0) { + code = "##" + UniqueSequence.getValue(); + display = null; + } else { + code = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(0)); + display = code; + } } else { display = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(0)); code = arg.get(1); } final Group currentPackage = getSystem().getCurrentGroup(); -// if (getSystem().entityExist(code)) { -// return CommandExecutionResult.error("Package cannot have the same name as an existing class"); -// } + // if (getSystem().entityExist(code)) { + // return CommandExecutionResult.error("Package cannot have the same + // name as an existing class"); + // } final Group p = getSystem().getOrCreateGroup(code, display, null, GroupType.PACKAGE, currentPackage); p.setBold(true); final String color = arg.get(2); diff --git a/src/net/sourceforge/plantuml/command/ProtectedCommand.java b/src/net/sourceforge/plantuml/command/ProtectedCommand.java index 6669f90bb..e0d3f018a 100644 --- a/src/net/sourceforge/plantuml/command/ProtectedCommand.java +++ b/src/net/sourceforge/plantuml/command/ProtectedCommand.java @@ -75,4 +75,8 @@ public class ProtectedCommand implements Command { return cmd.isValid(lines); } + public String[] getDescription() { + return cmd.getDescription(); + } + } diff --git a/src/net/sourceforge/plantuml/command/SingleLineCommand.java b/src/net/sourceforge/plantuml/command/SingleLineCommand.java index b2a8d3e37..599e87926 100644 --- a/src/net/sourceforge/plantuml/command/SingleLineCommand.java +++ b/src/net/sourceforge/plantuml/command/SingleLineCommand.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5041 $ + * Revision $Revision: 6186 $ * */ package net.sourceforge.plantuml.command; @@ -67,6 +67,10 @@ public abstract class SingleLineCommand implements Command { this.system = system; this.pattern = Pattern.compile(pattern); } + + public String[] getDescription() { + return new String[]{pattern.pattern()}; + } final protected S getSystem() { return system; diff --git a/src/net/sourceforge/plantuml/command/SingleLineCommand2.java b/src/net/sourceforge/plantuml/command/SingleLineCommand2.java index b9c019da3..2864f3ce4 100644 --- a/src/net/sourceforge/plantuml/command/SingleLineCommand2.java +++ b/src/net/sourceforge/plantuml/command/SingleLineCommand2.java @@ -63,6 +63,10 @@ public abstract class SingleLineCommand2 implements Command { final protected S getSystem() { return system; } + + public String[] getDescription() { + return new String[] { pattern.getPattern() }; + } final public CommandControl isValid(List lines) { if (lines.size() != 1) { diff --git a/src/net/sourceforge/plantuml/cucadiagram/CucaDiagram.java b/src/net/sourceforge/plantuml/cucadiagram/CucaDiagram.java index a4fefa3fc..a321f0d9b 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/CucaDiagram.java +++ b/src/net/sourceforge/plantuml/cucadiagram/CucaDiagram.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6062 $ + * Revision $Revision: 6199 $ * */ package net.sourceforge.plantuml.cucadiagram; @@ -40,6 +40,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; @@ -58,6 +59,8 @@ import net.sourceforge.plantuml.cucadiagram.dot.CucaDiagramFileMaker; import net.sourceforge.plantuml.cucadiagram.dot.CucaDiagramFileMakerBeta; import net.sourceforge.plantuml.cucadiagram.dot.CucaDiagramPngMaker3; import net.sourceforge.plantuml.cucadiagram.dot.CucaDiagramTxtMaker; +import net.sourceforge.plantuml.cucadiagram.dot.GraphvizLayoutStrategy; +import net.sourceforge.plantuml.skin.VisibilityModifier; import net.sourceforge.plantuml.xmi.CucaDiagramXmiMaker; public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, PortionShower { @@ -105,7 +108,7 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, if (display == null) { display = code; } - final Entity entity = new Entity(code, display, type, group); + final Entity entity = new Entity(code, display, type, group, getHides()); entities.put(code, entity); nbLinks.put(entity, 0); return entity; @@ -166,9 +169,9 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, protected final Group getOrCreateGroupInternal(String code, String display, String namespace, GroupType type, Group parent) { -// if (entityExist(code)) { -// throw new IllegalArgumentException("code=" + code); -// } + // if (entityExist(code)) { + // throw new IllegalArgumentException("code=" + code); + // } Group g = groups.get(code); if (g == null) { g = new Group(code, display, namespace, type, parent); @@ -176,7 +179,7 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, Entity entityGroup = entities.get(code); if (entityGroup == null) { - entityGroup = new Entity("$$" + code, code, EntityType.GROUP, g); + entityGroup = new Entity("$$" + code, code, EntityType.GROUP, g, getHides()); } else { entityGroup.muteToCluster(g); } @@ -272,7 +275,7 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, final public List createFiles(File suggestedFile, FileFormatOption fileFormatOption) throws IOException, InterruptedException { - + final FileFormat fileFormat = fileFormatOption.getFileFormat(); if (fileFormat == FileFormat.ATXT || fileFormat == FileFormat.UTXT) { @@ -480,7 +483,16 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, } } + public void hideOrShow(Set visibilities, boolean show) { + if (show) { + hides.removeAll(visibilities); + } else { + hides.addAll(visibilities); + } + } + private final List hideOrShows = new ArrayList(); + private final Set hides = new HashSet(); static class HideOrShow { private final EntityGender gender; @@ -498,5 +510,19 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, public int getNbImages() { return this.horizontalPages * this.verticalPages; } + + public final Set getHides() { + return Collections.unmodifiableSet(hides); + } + private GraphvizLayoutStrategy strategy = GraphvizLayoutStrategy.DOT; + + public void setStrategy(GraphvizLayoutStrategy strategy) { + this.strategy = strategy; + } + + public GraphvizLayoutStrategy getStrategy() { + return strategy; + } + } diff --git a/src/net/sourceforge/plantuml/cucadiagram/Entity.java b/src/net/sourceforge/plantuml/cucadiagram/Entity.java index 536bae4c7..1833f5267 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/Entity.java +++ b/src/net/sourceforge/plantuml/cucadiagram/Entity.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6121 $ + * Revision $Revision: 6169 $ * */ package net.sourceforge.plantuml.cucadiagram; @@ -38,10 +38,12 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Set; import net.sourceforge.plantuml.UniqueSequence; import net.sourceforge.plantuml.cucadiagram.dot.DrawFile; import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.skin.VisibilityModifier; public class Entity implements IEntity { @@ -53,14 +55,15 @@ public class Entity implements IEntity { private Stereotype stereotype; - private final List fields2 = new ArrayList(); - private final List methods2 = new ArrayList(); + private final List fields = new ArrayList(); + private final List methods = new ArrayList(); + private final Set hides; private Group container; private DrawFile imageFile; private String url; - + private boolean top; public final boolean isTop() { @@ -71,17 +74,19 @@ public class Entity implements IEntity { this.top = top; } - public Entity(String code, String display, EntityType type, Group entityPackage) { - this("cl" + UniqueSequence.getValue(), code, display, type, entityPackage); + public Entity(String code, String display, EntityType type, Group entityPackage, Set hides) { + this("cl" + UniqueSequence.getValue(), code, display, type, entityPackage, hides); } - public Entity(String uid, String code, String display, EntityType type, Group entityPackage) { + public Entity(String uid, String code, String display, EntityType type, Group entityPackage, + Set hides) { if (code == null || code.length() == 0) { throw new IllegalArgumentException(); } if (display == null /* || display.length() == 0 */) { throw new IllegalArgumentException(); } + this.hides = hides; this.uid = uid; this.type = type; this.code = code; @@ -105,30 +110,48 @@ public class Entity implements IEntity { public void addFieldOrMethod(String s) { if (isMethod(s)) { - methods2.add(new Member(s, true)); + methods.add(new Member(s, true)); } else { addField(s); } } public void addField(String s) { - fields2.add(new Member(s, false)); + fields.add(new Member(s, false)); } public void addField(Member s) { - fields2.add(s); + fields.add(s); } private boolean isMethod(String s) { return s.contains("(") || s.contains(")"); } - public List methods2() { - return Collections.unmodifiableList(methods2); + public List getMethodsToDisplay() { + if (hides==null || hides.size() == 0) { + return Collections.unmodifiableList(methods); + } + final List result = new ArrayList(); + for (Member m : methods) { + if (hides.contains(m.getVisibilityModifier()) == false) { + result.add(m); + } + } + return Collections.unmodifiableList(result); } - public List fields2() { - return Collections.unmodifiableList(fields2); + public List getFieldsToDisplay() { + if (hides==null || hides.size() == 0) { + return Collections.unmodifiableList(fields); + } + final List result = new ArrayList(); + for (Member m : fields) { + if (hides.contains(m.getVisibilityModifier()) == false) { + result.add(m); + } + } + return Collections.unmodifiableList(result); } public EntityType getType() { diff --git a/src/net/sourceforge/plantuml/cucadiagram/EntityGenderUtils.java b/src/net/sourceforge/plantuml/cucadiagram/EntityGenderUtils.java index e98630d63..a1b70fa45 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/EntityGenderUtils.java +++ b/src/net/sourceforge/plantuml/cucadiagram/EntityGenderUtils.java @@ -99,7 +99,7 @@ public class EntityGenderUtils { static public EntityGender emptyMethods() { return new EntityGender() { public boolean contains(IEntity test) { - return test.methods2().size()==0; + return test.getMethodsToDisplay().size()==0; } }; } @@ -107,7 +107,7 @@ public class EntityGenderUtils { static public EntityGender emptyFields() { return new EntityGender() { public boolean contains(IEntity test) { - return test.fields2().size()==0; + return test.getFieldsToDisplay().size()==0; } }; } @@ -115,7 +115,7 @@ public class EntityGenderUtils { static public EntityGender emptyMembers() { return new EntityGender() { public boolean contains(IEntity test) { - return test.methods2().size()==0 && test.fields2().size()==0; + return test.getMethodsToDisplay().size()==0 && test.getFieldsToDisplay().size()==0; } }; } diff --git a/src/net/sourceforge/plantuml/cucadiagram/EntityUtils.java b/src/net/sourceforge/plantuml/cucadiagram/EntityUtils.java index e2a9b3937..4411f8c32 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/EntityUtils.java +++ b/src/net/sourceforge/plantuml/cucadiagram/EntityUtils.java @@ -47,8 +47,8 @@ public abstract class EntityUtils { throw new IllegalArgumentException(); } return new IEntity() { - public List fields2() { - return ent.fields2(); + public List getFieldsToDisplay() { + return ent.getFieldsToDisplay(); } public String getDisplay() { @@ -79,8 +79,8 @@ public abstract class EntityUtils { return ent.getUrl(); } - public List methods2() { - return ent.methods2(); + public List getMethodsToDisplay() { + return ent.getMethodsToDisplay(); } public DrawFile getImageFile() { diff --git a/src/net/sourceforge/plantuml/cucadiagram/IEntity.java b/src/net/sourceforge/plantuml/cucadiagram/IEntity.java index b81384971..1af23a863 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/IEntity.java +++ b/src/net/sourceforge/plantuml/cucadiagram/IEntity.java @@ -52,13 +52,13 @@ public interface IEntity extends Imaged, SpecificBackcolorable { public String getUrl(); - public List fields2(); + public List getFieldsToDisplay(); public Stereotype getStereotype(); public void setStereotype(Stereotype stereotype); - public List methods2(); + public List getMethodsToDisplay(); public String getCode(); diff --git a/src/net/sourceforge/plantuml/cucadiagram/Link.java b/src/net/sourceforge/plantuml/cucadiagram/Link.java index 8a1a15e86..ec47ca9e1 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/Link.java +++ b/src/net/sourceforge/plantuml/cucadiagram/Link.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6009 $ + * Revision $Revision: 6152 $ * */ package net.sourceforge.plantuml.cucadiagram; @@ -42,6 +42,7 @@ import net.sourceforge.plantuml.UniqueSequence; import net.sourceforge.plantuml.cucadiagram.dot.DrawFile; import net.sourceforge.plantuml.graphic.FontConfiguration; import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; @@ -66,12 +67,19 @@ public class Link implements Imaged { private final String labeldistance; private final String labelangle; + private HtmlColor specificColor; + public Link(IEntity cl1, IEntity cl2, LinkType type, String label, int length) { - this(cl1, cl2, type, label, length, null, null, null, null); + this(cl1, cl2, type, label, length, null, null, null, null, null); } public Link(IEntity cl1, IEntity cl2, LinkType type, String label, int length, String qualifier1, String qualifier2, String labeldistance, String labelangle) { + this(cl1, cl2, type, label, length, qualifier1, qualifier2, labeldistance, labelangle, null); + } + + public Link(IEntity cl1, IEntity cl2, LinkType type, String label, int length, String qualifier1, + String qualifier2, String labeldistance, String labelangle, HtmlColor specificColor) { if (length < 1) { throw new IllegalArgumentException(); } @@ -87,10 +95,27 @@ public class Link implements Imaged { this.qualifier2 = qualifier2; this.labeldistance = labeldistance; this.labelangle = labelangle; + this.specificColor = specificColor; } public Link getInv() { - return new Link(cl2, cl1, type.getInv(), label, length, qualifier2, qualifier1, labeldistance, labelangle); + return new Link(cl2, cl1, type.getInv(), label, length, qualifier2, qualifier1, labeldistance, labelangle, + specificColor); + } + + public Link getDashed() { + return new Link(cl1, cl2, type.getDashed(), label, length, qualifier1, qualifier2, labeldistance, labelangle, + specificColor); + } + + public Link getDotted() { + return new Link(cl1, cl2, type.getDotted(), label, length, qualifier1, qualifier2, labeldistance, labelangle, + specificColor); + } + + public Link getBold() { + return new Link(cl1, cl2, type.getBold(), label, length, qualifier1, qualifier2, labeldistance, labelangle, + specificColor); } public String getLabeldistance() { @@ -281,4 +306,12 @@ public class Link implements Imaged { return 0; } + public HtmlColor getSpecificColor() { + return specificColor; + } + + public void setSpecificColor(String s) { + this.specificColor = HtmlColor.getColorIfValid(s); + } + } diff --git a/src/net/sourceforge/plantuml/cucadiagram/LinkStyle.java b/src/net/sourceforge/plantuml/cucadiagram/LinkStyle.java index 4f197a645..7187a9bf9 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/LinkStyle.java +++ b/src/net/sourceforge/plantuml/cucadiagram/LinkStyle.java @@ -35,6 +35,6 @@ package net.sourceforge.plantuml.cucadiagram; public enum LinkStyle { - NORMAL, DASHED, INTERFACE_PROVIDER, INTERFACE_USER; + NORMAL, DASHED, INTERFACE_PROVIDER, INTERFACE_USER, DOTTED, BOLD; } diff --git a/src/net/sourceforge/plantuml/cucadiagram/LinkType.java b/src/net/sourceforge/plantuml/cucadiagram/LinkType.java index c644d3dfa..108e228fc 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/LinkType.java +++ b/src/net/sourceforge/plantuml/cucadiagram/LinkType.java @@ -73,10 +73,26 @@ public class LinkType { return style == LinkStyle.DASHED; } + public boolean isDotted() { + return style == LinkStyle.DOTTED; + } + + public boolean isBold() { + return style == LinkStyle.BOLD; + } + public LinkType getDashed() { return new LinkType(decor1, LinkStyle.DASHED, decor2); } + public LinkType getDotted() { + return new LinkType(decor1, LinkStyle.DOTTED, decor2); + } + + public LinkType getBold() { + return new LinkType(decor1, LinkStyle.BOLD, decor2); + } + public LinkType getInterfaceProvider() { return new LinkType(decor1, LinkStyle.INTERFACE_PROVIDER, decor2); } @@ -114,6 +130,12 @@ public class LinkType { if (style == LinkStyle.DASHED) { sb.append(",style=dashed"); } + if (style == LinkStyle.DOTTED) { + sb.append(",style=dotted,"); + } + if (style == LinkStyle.BOLD) { + sb.append(",style=bold,"); + } return sb.toString(); } diff --git a/src/net/sourceforge/plantuml/cucadiagram/Member.java b/src/net/sourceforge/plantuml/cucadiagram/Member.java index ce65fce42..94db7c9fb 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/Member.java +++ b/src/net/sourceforge/plantuml/cucadiagram/Member.java @@ -41,11 +41,6 @@ public class Member { private final boolean staticModifier; private final boolean abstractModifier; - private boolean privateModifier; - private boolean protectedModifier; - private boolean publicModifier; - private boolean packagePrivateModifier; - private final VisibilityModifier visibilityModifier; public Member(String display, boolean isMethod) { @@ -55,30 +50,15 @@ public class Member { final String displayClean = display.replaceAll("(?i)\\{(static|classifier|abstract)\\}", "").trim(); if (VisibilityModifier.isVisibilityCharacter(displayClean.charAt(0))) { - updateVisibility(display.charAt(0)); visibilityModifier = VisibilityModifier.getVisibilityModifier(display.charAt(0), isMethod == false); this.display = displayClean.substring(1).trim(); } else { this.display = displayClean; visibilityModifier = null; } - // assert VisibilityModifier.isVisibilityCharacter(this.display.charAt(0)) == false; - - } - - private void updateVisibility(char c) { - if (c == '-') { - this.privateModifier = true; - } - if (c == '#') { - this.protectedModifier = true; - } - if (c == '+') { - this.publicModifier = true; - } - if (c == '~') { - this.packagePrivateModifier = true; - } + // assert + // VisibilityModifier.isVisibilityCharacter(this.display.charAt(0)) == + // false; } @@ -130,23 +110,27 @@ public class Member { } public final boolean isVisibilityModified() { - return privateModifier || publicModifier || protectedModifier || packagePrivateModifier; + return visibilityModifier != null; } public final boolean isPrivate() { - return privateModifier; + return visibilityModifier == VisibilityModifier.PRIVATE_FIELD + || visibilityModifier == VisibilityModifier.PRIVATE_METHOD; } public final boolean isProtected() { - return protectedModifier; + return visibilityModifier == VisibilityModifier.PROTECTED_FIELD + || visibilityModifier == VisibilityModifier.PROTECTED_METHOD; } public final boolean isPublic() { - return publicModifier; + return visibilityModifier == VisibilityModifier.PUBLIC_FIELD + || visibilityModifier == VisibilityModifier.PUBLIC_METHOD; } public final boolean isPackagePrivate() { - return packagePrivateModifier; + return visibilityModifier == VisibilityModifier.PACKAGE_PRIVATE_FIELD + || visibilityModifier == VisibilityModifier.PACKAGE_PRIVATE_METHOD; } public final VisibilityModifier getVisibilityModifier() { diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/AbstractGraphviz2.java b/src/net/sourceforge/plantuml/cucadiagram/dot/AbstractGraphviz2.java new file mode 100644 index 000000000..151d7a40a --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/AbstractGraphviz2.java @@ -0,0 +1,184 @@ +/* ======================================================================== + * 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: 6104 $ + * + */ +package net.sourceforge.plantuml.cucadiagram.dot; + +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +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; +import net.sourceforge.plantuml.graphic.GraphicStrings; + +class AbstractGraphviz2 implements Graphviz { + + private final OS os; + private final GraphvizLayoutStrategy strategy; + private final String dotString; + private final String[] type; + + + AbstractGraphviz2(OS os, GraphvizLayoutStrategy strategy, String dotString, String... type) { + if (type == null) { + throw new IllegalArgumentException(); + } + this.os = os; + this.strategy = strategy; + this.dotString = dotString; + this.type = type; + } + + + final public void createPng(OutputStream os) throws IOException, InterruptedException { + if (dotString == null) { + throw new IllegalArgumentException(); + } + + if (illegalDotExe()) { + createPngNoGraphviz(os, new FileFormatOption(FileFormat.valueOf(type[0].toUpperCase()))); + return; + } + final String cmd = getCommandLine(); + ProcessRunner p = null; + try { + Log.info("Starting Graphviz process " + cmd); + Log.info("DotString size: " + dotString.length()); + p = new ProcessRunner(cmd); + p.run(dotString.getBytes(), os); + Log.info("Ending process ok"); + } catch (Throwable e) { + e.printStackTrace(); + Log.error("Error: " + e); + Log.error("The command was " + cmd); + Log.error(""); + Log.error("Try java -jar plantuml.jar -testdot to figure out the issue"); + Log.error(""); + } finally { + Log.info("Ending Graphviz process"); + } + if (OptionFlags.getInstance().isCheckDotError() && p != null && p.getError().length() > 0) { + Log.error("GraphViz error stream : " + p.getError()); + if (OptionFlags.getInstance().isCheckDotError()) { + throw new IllegalStateException("Dot error " + p.getError()); + } + } + if (OptionFlags.getInstance().isCheckDotError() && p != null && p.getOut().length() > 0) { + Log.error("GraphViz out stream : " + p.getOut()); + if (OptionFlags.getInstance().isCheckDotError()) { + throw new IllegalStateException("Dot out " + p.getOut()); + } + } + + } + + + private String getCommandLine() { + final StringBuilder sb = new StringBuilder(); + sb.append(os.getCommand(strategy)); + appendImageType(sb); + return sb.toString(); + } + + + public String dotVersion() throws IOException, InterruptedException { + final String cmd = os.getCommand(strategy)+" -V"; + return executeCmd(cmd); + } + + + public File getDotExe() { + return os.getExecutable(strategy); + } + + private boolean illegalDotExe() { + final File exe = getDotExe(); + return exe == null || exe.isFile() == false || exe.canRead() == false; + } + + private String executeCmd(final String cmd) throws IOException, InterruptedException { + final ProcessRunner p = new ProcessRunner(cmd); + p.run(null, null); + final StringBuilder sb = new StringBuilder(); + if (StringUtils.isNotEmpty(p.getOut())) { + sb.append(p.getOut()); + } + if (StringUtils.isNotEmpty(p.getError())) { + if (sb.length() > 0) { + sb.append(' '); + } + sb.append(p.getError()); + } + return sb.toString().replace('\n', ' ').trim(); + } + + final private void createPngNoGraphviz(OutputStream os, FileFormatOption format) throws IOException { + final List msg = new ArrayList(); + final File exe = getDotExe(); + msg.add("Dot Executable: " + exe); + if (exe != null) { + if (exe.exists() == false) { + msg.add("File does not exist"); + } else if (exe.isDirectory()) { + msg.add("It should be an executable, not a directory"); + } else if (exe.isFile() == false) { + msg.add("Not a valid file"); + } else if (exe.canRead() == false) { + msg.add("File cannot be read"); + } + } + msg.add("Cannot find Graphviz. You should try"); + msg.add(" "); + msg.add("@startuml"); + msg.add("testdot"); + msg.add("@enduml"); + msg.add(" "); + msg.add(" or "); + msg.add(" "); + msg.add("java -jar plantuml.jar -testdot"); + final GraphicStrings errorResult = new GraphicStrings(msg); + errorResult.writeImage(os, format); + } + + private final void appendImageType(final StringBuilder sb) { + for (String t : type) { + sb.append(" -T" + t + " "); + } + } + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramFileMaker.java b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramFileMaker.java index 3bfd3a156..fe9564ac1 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramFileMaker.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramFileMaker.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6130 $ + * Revision $Revision: 6197 $ * */ package net.sourceforge.plantuml.cucadiagram.dot; @@ -57,6 +57,8 @@ import java.util.regex.Pattern; import javax.imageio.ImageIO; +import com.sun.org.apache.bcel.internal.generic.GETSTATIC; + import net.sourceforge.plantuml.ColorParam; import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.EmptyImageBuilder; @@ -966,8 +968,9 @@ public final class CucaDiagramFileMaker { dotData.setVisibilityModifierPresent(true); } } - - return new DotMaker(dotData, dotStrings, fileFormat); + + return diagram.getStrategy().getGraphvizMaker(dotData, dotStrings, fileFormat); + // return new DotMaker(dotData, dotStrings, fileFormat); } private void populateImages(double dpiFactor, int dpi) throws IOException { diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramSimplifier.java b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramSimplifier.java index 3546382cc..e8d34a507 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramSimplifier.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramSimplifier.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5789 $ + * Revision $Revision: 6169 $ * */ package net.sourceforge.plantuml.cucadiagram.dot; @@ -83,11 +83,11 @@ public final class CucaDiagramSimplifier { } else { throw new IllegalStateException(); } - final Entity proxy = new Entity("#" + g.getCode(), g.getDisplay(), type, g.getParent()); + final Entity proxy = new Entity("#" + g.getCode(), g.getDisplay(), type, g.getParent(), diagram.getHides()); if (type == EntityType.STATE) { manageBackColorForState(diagram, g, proxy); } - for (Member field : g.getEntityCluster().fields2()) { + for (Member field : g.getEntityCluster().getFieldsToDisplay()) { proxy.addField(field); } computeImageGroup(g, proxy, dotStrings); diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramTxtMaker.java b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramTxtMaker.java index 1ef3ff628..471ec364c 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramTxtMaker.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramTxtMaker.java @@ -126,14 +126,14 @@ public final class CucaDiagramTxtMaker { int y = 2; ug.getCharArea().drawHLine('-', y, 1, w - 1); y++; - for (Member att : ent.fields2()) { + for (Member att : ent.getFieldsToDisplay()) { final List disp = StringUtils.getWithNewlines(att.getDisplayWithVisibilityChar()); ug.getCharArea().drawStringsLR(disp, 1, y); y += StringUtils.getHeight(disp); } ug.getCharArea().drawHLine('-', y, 1, w - 1); y++; - for (Member att : ent.methods2()) { + for (Member att : ent.getMethodsToDisplay()) { final List disp = StringUtils.getWithNewlines(att.getDisplayWithVisibilityChar()); ug.getCharArea().drawStringsLR(disp, 1, y); y += StringUtils.getHeight(disp); @@ -151,10 +151,10 @@ public final class CucaDiagramTxtMaker { private int getHeight(Entity entity) { int result = StringUtils.getHeight(StringUtils.getWithNewlines(entity.getDisplay())); - for (Member att : entity.methods2()) { + for (Member att : entity.getMethodsToDisplay()) { result += StringUtils.getHeight(StringUtils.getWithNewlines(att.getDisplayWithVisibilityChar())); } - for (Member att : entity.fields2()) { + for (Member att : entity.getFieldsToDisplay()) { result += StringUtils.getHeight(StringUtils.getWithNewlines(att.getDisplayWithVisibilityChar())); } return result + 4; @@ -162,13 +162,13 @@ public final class CucaDiagramTxtMaker { private int getWidth(Entity entity) { int result = StringUtils.getWidth(StringUtils.getWithNewlines(entity.getDisplay())); - for (Member att : entity.methods2()) { + for (Member att : entity.getMethodsToDisplay()) { final int w = StringUtils.getWidth(StringUtils.getWithNewlines(att.getDisplayWithVisibilityChar())); if (w > result) { result = w; } } - for (Member att : entity.fields2()) { + for (Member att : entity.getFieldsToDisplay()) { final int w = StringUtils.getWidth(StringUtils.getWithNewlines(att.getDisplayWithVisibilityChar())); if (w > result) { result = w; diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/DotMaker.java b/src/net/sourceforge/plantuml/cucadiagram/dot/DotMaker.java index 5a7598b1c..ee7246472 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/DotMaker.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/DotMaker.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6141 $ + * Revision $Revision: 6195 $ * */ package net.sourceforge.plantuml.cucadiagram.dot; @@ -148,7 +148,6 @@ final public class DotMaker implements GraphvizMaker { } - private void initPrintWriter(StringBuilder sb) { Log.info("Entities = " + data.getEntities().size()); @@ -195,7 +194,7 @@ final public class DotMaker implements GraphvizMaker { for (Group g : data.getGroupHierarchy().getChildrenGroups(parent)) { if (data.isEmpty(g) && g.getType() == GroupType.PACKAGE) { final IEntity folder = new Entity(g.getUid(), g.getCode(), g.getDisplay(), EntityType.EMPTY_PACKAGE, - null); + null, null); printEntity(sb, folder); } else { printGroup(sb, g); @@ -346,9 +345,9 @@ final public class DotMaker implements GraphvizMaker { if (g.getDisplay() != null) { final StringBuilder label = new StringBuilder(manageHtmlIB(g.getDisplay(), getFontParamForGroup(), null)); - if (g.getEntityCluster().fields2().size() > 0) { + if (g.getEntityCluster().getFieldsToDisplay().size() > 0) { label.append("
"); - for (Member att : g.getEntityCluster().fields2()) { + for (Member att : g.getEntityCluster().getFieldsToDisplay()) { label.append(manageHtmlIB(" " + att.getDisplayWithVisibilityChar() + " ", FontParam.STATE_ATTRIBUTE, null)); label.append("
"); @@ -512,7 +511,7 @@ final public class DotMaker implements GraphvizMaker { } private void printLink(StringBuilder sb, Link link) throws IOException { - final StringBuilder decoration = getLinkDecoration(); + final StringBuilder decoration = getLinkDecoration(link); if (link.getWeight() > 1) { decoration.append("weight=" + link.getWeight() + ","); @@ -611,8 +610,14 @@ final public class DotMaker implements GraphvizMaker { return g.getUid() + "_" + link.getUid(); } - private StringBuilder getLinkDecoration() { - final StringBuilder decoration = new StringBuilder("[color=" + getColorString(getArrowColorParam(), null) + ","); + private StringBuilder getLinkDecoration(Link link) { + final StringBuilder decoration = new StringBuilder("[color="); + if (link.getSpecificColor() == null) { + decoration.append(getColorString(getArrowColorParam(), null)); + } else { + decoration.append("\"" + link.getSpecificColor().getAsHtml() + "\""); + } + decoration.append(","); decoration.append("fontcolor=" + getFontColorString(getArrowFontParam(), null) + ","); decoration.append("fontsize=\"" + data.getSkinParam().getFontSize(getArrowFontParam(), null) + "\","); @@ -838,7 +843,7 @@ final public class DotMaker implements GraphvizMaker { sb.append(entity.getUid() + " [margin=0,pad=0," + label + ",shape=none,image=\"" + absolutePath + "\"];"); } else if (type == EntityType.ACTIVITY) { String shape = "octagon"; - if (data.getSkinParam().useOctagonForActivity()==false || entity.getImageFile() != null) { + if (data.getSkinParam().useOctagonForActivity() == false || entity.getImageFile() != null) { shape = "rect"; } sb.append(entity.getUid() + " [fontcolor=" + getFontColorString(FontParam.ACTIVITY, stereo) + ",fillcolor=" @@ -908,7 +913,7 @@ final public class DotMaker implements GraphvizMaker { } else { throw new IllegalStateException(type.toString() + " " + data.getUmlDiagramType()); } - + if (entity.isTop()) { rankMin.add(entity.getUid()); } @@ -1020,9 +1025,9 @@ final public class DotMaker implements GraphvizMaker { sb.append("" + manageHtmlIB(entity.getDisplay(), FontParam.STATE, stereotype) + ""); sb.append(""); - if (entity.fields2().size() > 0) { + if (entity.getFieldsToDisplay().size() > 0) { sb.append("|"); - for (Member att : entity.fields2()) { + for (Member att : entity.getFieldsToDisplay()) { sb.append(manageHtmlIB(att.getDisplayWithVisibilityChar(), FontParam.STATE_ATTRIBUTE, stereotype)); sb.append("
"); } @@ -1046,7 +1051,7 @@ final public class DotMaker implements GraphvizMaker { sb.append(""); } - if (entity.fields2().size() == 0 && cFile == null) { + if (entity.getFieldsToDisplay().size() == 0 && cFile == null) { sb.append("|"); } @@ -1252,9 +1257,9 @@ final public class DotMaker implements GraphvizMaker { // if (fileFormat == FileFormat.EPS) { // sb.append(addFieldsEps(entity.fields2(), true)); // } else { - final boolean hasStatic = hasStatic(entity.fields2()); + final boolean hasStatic = hasStatic(entity.getFieldsToDisplay()); sb.append(""); - for (Member att : entity.fields2()) { + for (Member att : entity.getFieldsToDisplay()) { sb.append(manageHtmlIBspecial(att, FontParam.CLASS_ATTRIBUTE, hasStatic, getColorString( ColorParam.classBackground, stereo), true)); sb.append("
"); @@ -1266,9 +1271,9 @@ final public class DotMaker implements GraphvizMaker { // if (fileFormat == FileFormat.EPS) { // sb.append(addFieldsEps(entity.methods2(), true)); // } else { - final boolean hasStatic = hasStatic(entity.methods2()); + final boolean hasStatic = hasStatic(entity.getMethodsToDisplay()); sb.append(""); - for (Member att : entity.methods2()) { + for (Member att : entity.getMethodsToDisplay()) { sb.append(manageHtmlIBspecial(att, FontParam.CLASS_ATTRIBUTE, hasStatic, getColorString( ColorParam.classBackground, stereo), true)); sb.append("
"); @@ -1365,14 +1370,14 @@ final public class DotMaker implements GraphvizMaker { if (showFields) { sb.append(""); - if (entity.fields2().size() > 0) { + if (entity.getFieldsToDisplay().size() > 0) { buildTableVisibility(entity, true, sb, springField); } sb.append(""); } if (showMethods) { sb.append(""); - if (entity.methods2().size() > 0) { + if (entity.getMethodsToDisplay().size() > 0) { buildTableVisibility(entity, false, sb, springMethod); } sb.append(""); @@ -1400,9 +1405,9 @@ final public class DotMaker implements GraphvizMaker { throws IOException { sb.append(""); - final boolean hasStatic = hasStatic(entity.methods2()); + final boolean hasStatic = hasStatic(entity.getMethodsToDisplay()); final boolean dpiNormal = data.getDpi() == 96; - for (Member att : isField ? entity.fields2() : entity.methods2()) { + for (Member att : isField ? entity.getFieldsToDisplay() : entity.getMethodsToDisplay()) { sb.append(""); if (dpiNormal) { sb.append(""); sb.append(""); sb.append("
"); @@ -1454,7 +1459,7 @@ final public class DotMaker implements GraphvizMaker { private int getLongestMethods(IEntity entity) { int result = 0; - for (Member att : entity.methods2()) { + for (Member att : entity.getMethodsToDisplay()) { final int size = att.getDisplayWithVisibilityChar().length(); if (size > result) { result = size; @@ -1466,7 +1471,7 @@ final public class DotMaker implements GraphvizMaker { private int getLongestField(IEntity entity) { int result = 0; - for (Member att : entity.fields2()) { + for (Member att : entity.getFieldsToDisplay()) { final int size = att.getDisplayWithVisibilityChar().length(); if (size > result) { result = size; @@ -1501,7 +1506,7 @@ final public class DotMaker implements GraphvizMaker { sb.append("
"); - if (entity.fields2().size() == 0) { + if (entity.getFieldsToDisplay().size() == 0) { sb.append(manageHtmlIB(" ", FontParam.OBJECT_ATTRIBUTE, stereo)); } else { buildTableVisibility(entity, true, sb, springField); @@ -1532,10 +1537,10 @@ final public class DotMaker implements GraphvizMaker { sb.append("
"); - if (entity.fields2().size() == 0) { + if (entity.getFieldsToDisplay().size() == 0) { sb.append(manageHtmlIB(" ", FontParam.OBJECT_ATTRIBUTE, stereo)); } else { - for (Member att : entity.fields2()) { + for (Member att : entity.getFieldsToDisplay()) { sb.append(manageHtmlIB(att.getDisplayWithVisibilityChar(), FontParam.OBJECT_ATTRIBUTE, stereo)); sb.append("
"); } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/Executable.java b/src/net/sourceforge/plantuml/cucadiagram/dot/Executable.java new file mode 100644 index 000000000..297102b17 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/Executable.java @@ -0,0 +1,135 @@ +/* ======================================================================== + * 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: 6104 $ + * + */ +package net.sourceforge.plantuml.cucadiagram.dot; + +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.OptionFlags; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.graphic.GraphicStrings; + +abstract class Executable { + + private final File dotExe; + + static boolean isWindows() { + return File.separatorChar == '\\'; + } + + Executable(String dotString, String... type) { + if (type == null) { + throw new IllegalArgumentException(); + } + this.dotExe = searchDotExe(); + } + + private File searchDotExe() { + if (OptionFlags.getInstance().getDotExecutable() == null) { + final String getenv = GraphvizUtils.getenvGraphvizDot(); + if (getenv == null) { + return specificDotExe(); + } + return new File(getenv); + } + + return new File(OptionFlags.getInstance().getDotExecutable()); + + } + + abstract protected File specificDotExe(); + + + final public String dotVersion() throws IOException, InterruptedException { + final String cmd = getCommandLineVersion(); + return executeCmd(cmd); + } + + private String executeCmd(final String cmd) throws IOException, InterruptedException { + final ProcessRunner p = new ProcessRunner(cmd); + p.run(null, null); + final StringBuilder sb = new StringBuilder(); + if (StringUtils.isNotEmpty(p.getOut())) { + sb.append(p.getOut()); + } + if (StringUtils.isNotEmpty(p.getError())) { + if (sb.length() > 0) { + sb.append(' '); + } + sb.append(p.getError()); + } + return sb.toString().replace('\n', ' ').trim(); + } + + final private void createPngNoGraphviz(OutputStream os, FileFormatOption format) throws IOException { + final List msg = new ArrayList(); + msg.add("Dot Executable: " + dotExe); + if (dotExe != null) { + if (dotExe.exists() == false) { + msg.add("File does not exist"); + } else if (dotExe.isDirectory()) { + msg.add("It should be an executable, not a directory"); + } else if (dotExe.isFile() == false) { + msg.add("Not a valid file"); + } else if (dotExe.canRead() == false) { + msg.add("File cannot be read"); + } + } + msg.add("Cannot find Graphviz. You should try"); + msg.add(" "); + msg.add("@startuml"); + msg.add("testdot"); + msg.add("@enduml"); + msg.add(" "); + msg.add(" or "); + msg.add(" "); + msg.add("java -jar plantuml.jar -testdot"); + final GraphicStrings errorResult = new GraphicStrings(msg); + errorResult.writeImage(os, format); + } + + abstract String getCommandLine(); + + abstract String getCommandLineVersion(); + + public final File getDotExe() { + return dotExe; + } + + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizLayoutStrategy.java b/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizLayoutStrategy.java new file mode 100644 index 000000000..cc3da797c --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizLayoutStrategy.java @@ -0,0 +1,73 @@ +/* ======================================================================== + * 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; +import java.util.List; + +import net.sourceforge.plantuml.FileFormat; +import net.sourceforge.plantuml.OptionFlags; + +public enum GraphvizLayoutStrategy { + DOT, NEATO; + + public GraphvizMaker getGraphvizMaker(DotData data, + List dotStrings, FileFormat fileFormat) { + if (this == DOT) { + return new DotMaker(data, dotStrings, fileFormat); + } + throw new UnsupportedOperationException(this.toString()); + } + + public File getSystemForcedExecutable() { + if (this == DOT) { + return getSystemForcedDot(); + } + throw new UnsupportedOperationException(this.toString()); + } + + private File getSystemForcedDot() { + if (OptionFlags.getInstance().getDotExecutable() == null) { + final String getenv = GraphvizUtils.getenvGraphvizDot(); + if (getenv == null) { + return null; + } + return new File(getenv); + } + + return new File(OptionFlags.getInstance().getDotExecutable()); + + } + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizUtils.java b/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizUtils.java index e044ba344..7ef787bc3 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizUtils.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizUtils.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6007 $ + * Revision $Revision: 6200 $ * */ package net.sourceforge.plantuml.cucadiagram.dot; @@ -51,6 +51,7 @@ public class GraphvizUtils { return File.separatorChar == '\\'; } + @Deprecated public static Graphviz create(String dotString, String... type) { if (isWindows()) { return new GraphvizWindows(dotString, type); @@ -58,6 +59,10 @@ public class GraphvizUtils { return new GraphvizLinux(dotString, type); } + public static Graphviz create2(GraphvizLayoutStrategy strategy, String dotString, String... type) { + return new AbstractGraphviz2(getOS(), strategy, dotString, type); + } + static public File getDotExe() { return create(null, "png").getDotExe(); } @@ -161,5 +166,12 @@ public class GraphvizUtils { return Collections.unmodifiableList(result); } + + public static OS getOS() { + if (isWindows()) { + return new OSWindows(); + } + return new OSLinux(); + } } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/GroupPngMaker.java b/src/net/sourceforge/plantuml/cucadiagram/dot/GroupPngMaker.java index 336040262..be12ae745 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/GroupPngMaker.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/GroupPngMaker.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5872 $ + * Revision $Revision: 6197 $ * */ package net.sourceforge.plantuml.cucadiagram.dot; @@ -47,6 +47,8 @@ import java.util.Map; import javax.imageio.ImageIO; +import com.sun.org.apache.bcel.internal.generic.GETSTATIC; + import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.FileUtils; import net.sourceforge.plantuml.ISkinParam; @@ -214,7 +216,8 @@ public final class GroupPngMaker { // dotData.putAllStaticImages(staticImages); // dotData.putAllImagesLink(imagesLink); - return new DotMaker(dotData, dotStrings, fileFormat); + // return new DotMaker(dotData, dotStrings, fileFormat); + return diagram.getStrategy().getGraphvizMaker(dotData, dotStrings, fileFormat); } private List getPureInnerLinks() { diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/OS.java b/src/net/sourceforge/plantuml/cucadiagram/dot/OS.java new file mode 100644 index 000000000..65885e7b3 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/OS.java @@ -0,0 +1,50 @@ +/* ======================================================================== + * 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: 6104 $ + * + */ +package net.sourceforge.plantuml.cucadiagram.dot; + +import java.io.File; + +abstract class OS { + + static boolean isWindows() { + return File.separatorChar == '\\'; + } + + abstract String getFileName(GraphvizLayoutStrategy strategy); + + abstract File getExecutable(GraphvizLayoutStrategy strategy); + + public abstract String getCommand(GraphvizLayoutStrategy strategy); + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/OSLinux.java b/src/net/sourceforge/plantuml/cucadiagram/dot/OSLinux.java new file mode 100644 index 000000000..5979c42e5 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/OSLinux.java @@ -0,0 +1,66 @@ +/* ======================================================================== + * 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: 6104 $ + * + */ +package net.sourceforge.plantuml.cucadiagram.dot; + +import java.io.File; + +class OSLinux extends OS { + + @Override + File getExecutable(GraphvizLayoutStrategy strategy) { + File result = strategy.getSystemForcedExecutable(); + if (result != null) { + return result; + } + final String fileName = getFileName(strategy); + final File usrLocalBin = new File("/usr/local/bin/" + fileName); + + if (usrLocalBin.exists()) { + return usrLocalBin; + } + final File usrBin = new File("/usr/bin/" + fileName); + return usrBin; + } + + @Override + String getFileName(GraphvizLayoutStrategy strategy) { + return strategy.name().toLowerCase(); + } + + @Override + public String getCommand(GraphvizLayoutStrategy strategy) { + return getExecutable(strategy).getAbsolutePath(); + } + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/OSWindows.java b/src/net/sourceforge/plantuml/cucadiagram/dot/OSWindows.java new file mode 100644 index 000000000..b6cddcefd --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/OSWindows.java @@ -0,0 +1,94 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009, Arnaud Roques + * + * Project Info: http://plantuml.sourceforge.net + * + * This file is part of PlantUML. + * + * PlantUML is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PlantUML distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 6104 $ + * + */ +package net.sourceforge.plantuml.cucadiagram.dot; + +import java.io.File; +import java.io.FileFilter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +class OSWindows extends OS { + + @Override + File getExecutable(GraphvizLayoutStrategy strategy) { + File result = strategy.getSystemForcedExecutable(); + if (result != null) { + return result; + } + result = searchInDir(new File("c:/Program Files"), strategy); + if (result != null) { + return result; + } + result = searchInDir(new File("c:/Program Files (x86)"), strategy); + return result; + } + + private File searchInDir(final File programFile, GraphvizLayoutStrategy strategy) { + if (programFile.exists() == false || programFile.isDirectory() == false) { + return null; + } + final List dots = new ArrayList(); + for (File f : programFile.listFiles(new FileFilter() { + public boolean accept(File pathname) { + return pathname.isDirectory() && pathname.getName().startsWith("Graphviz"); + } + })) { + final File result = new File(new File(f, "bin"), getFileName(strategy)); + if (result.exists() && result.canRead()) { + dots.add(result.getAbsoluteFile()); + } + } + return higherVersion(dots); + } + + static File higherVersion(List dots) { + if (dots.size() == 0) { + return null; + } + Collections.sort(dots, Collections.reverseOrder()); + return dots.get(0); + } + + @Override + String getFileName(GraphvizLayoutStrategy strategy) { + return strategy.name().toLowerCase() + ".exe"; + } + + @Override + public String getCommand(GraphvizLayoutStrategy strategy) { + return "\"" + getExecutable(strategy).getAbsolutePath() + "\""; + } + +} diff --git a/src/net/sourceforge/plantuml/graph/EntityImageClass.java b/src/net/sourceforge/plantuml/graph/EntityImageClass.java index f8cfb47a6..00d1417c7 100644 --- a/src/net/sourceforge/plantuml/graph/EntityImageClass.java +++ b/src/net/sourceforge/plantuml/graph/EntityImageClass.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6009 $ + * Revision $Revision: 6168 $ * */ package net.sourceforge.plantuml.graph; @@ -63,8 +63,8 @@ class EntityImageClass extends AbstractEntityImage { super(entity); this.name = TextBlockUtils.create(StringUtils.getWithNewlines(entity.getDisplay()), new FontConfiguration( getFont14(), Color.BLACK), HorizontalAlignement.CENTER); - this.methods = new MethodsOrFieldsArea(entity.methods2(), getFont14()); - this.fields = new MethodsOrFieldsArea(entity.fields2(), getFont14()); + this.methods = new MethodsOrFieldsArea(entity.getMethodsToDisplay(), getFont14()); + this.fields = new MethodsOrFieldsArea(entity.getFieldsToDisplay(), getFont14()); circledCharacter = getCircledCharacter(entity); diff --git a/src/net/sourceforge/plantuml/posimo/EntityImageClass2.java b/src/net/sourceforge/plantuml/posimo/EntityImageClass2.java index 0f075ddf5..195572a4c 100644 --- a/src/net/sourceforge/plantuml/posimo/EntityImageClass2.java +++ b/src/net/sourceforge/plantuml/posimo/EntityImageClass2.java @@ -82,8 +82,8 @@ public class EntityImageClass2 extends AbstractEntityImage2 { getFont(FontParam.CLASS_STEREOTYPE), getFontColor(FontParam.CLASS_STEREOTYPE)), HorizontalAlignement.CENTER); } - this.methods = new MethodsOrFieldsArea2(entity.methods2(), FontParam.CLASS_ATTRIBUTE, skinParam); - this.fields = new MethodsOrFieldsArea2(entity.fields2(), FontParam.CLASS_ATTRIBUTE, skinParam); + this.methods = new MethodsOrFieldsArea2(entity.getMethodsToDisplay(), FontParam.CLASS_ATTRIBUTE, skinParam); + this.fields = new MethodsOrFieldsArea2(entity.getFieldsToDisplay(), FontParam.CLASS_ATTRIBUTE, skinParam); circledCharacter = getCircledCharacter(entity); } diff --git a/src/net/sourceforge/plantuml/postit/Area.java b/src/net/sourceforge/plantuml/postit/Area.java new file mode 100644 index 000000000..ac8c29913 --- /dev/null +++ b/src/net/sourceforge/plantuml/postit/Area.java @@ -0,0 +1,112 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009, Arnaud Roques + * + * Project Info: http://plantuml.sourceforge.net + * + * This file is part of PlantUML. + * + * PlantUML is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PlantUML distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 4167 $ + * + */ +package net.sourceforge.plantuml.postit; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.UGraphic; + +public class Area implements Elastic { + + private final String title; + private final char id; + + private Dimension2D minimunDimension; + + private final List postIts = new ArrayList(); + + public Area(char id, String title) { + this.id = id; + this.title = title; + } + + public char getId() { + return id; + } + + public String getTitle() { + return title; + } + + public Dimension2D getMinimunDimension() { + return minimunDimension; + } + + public void setMinimunDimension(Dimension2D minimunDimension) { + this.minimunDimension = minimunDimension; + } + + public Dimension2D getDimension() { + throw new UnsupportedOperationException(); + } + + public double heightWhenWidthIs(double width, StringBounder stringBounder) { + final AreaLayoutFixedWidth layout = new AreaLayoutFixedWidth(); + final Map pos = layout.getPositions(postIts, stringBounder); + double max = 10; + for (Map.Entry ent : pos.entrySet()) { + final double y = ent.getKey().getDimension(stringBounder).getHeight() + ent.getValue().getY(); + max = Math.max(max, y); + } + + return max + 10; + } + + public double widthWhenHeightIs(double height, StringBounder stringBounder) { + throw new UnsupportedOperationException(); + } + + public void add(PostIt postIt) { + postIts.add(postIt); + } + + public void drawU(UGraphic ug) { + final AreaLayout layout = new AreaLayoutFixedWidth(); + final Map pos = layout.getPositions(postIts, ug.getStringBounder()); + final double tx = ug.getTranslateX(); + final double ty = ug.getTranslateY(); + for (Map.Entry ent : pos.entrySet()) { + ug.translate(ent.getValue().getX(), ent.getValue().getY()); + ent.getKey().drawU(ug); + ug.setTranslate(tx, ty); + } + + } + +} diff --git a/src/net/sourceforge/plantuml/postit/AreaLayout.java b/src/net/sourceforge/plantuml/postit/AreaLayout.java new file mode 100644 index 000000000..28cf5c010 --- /dev/null +++ b/src/net/sourceforge/plantuml/postit/AreaLayout.java @@ -0,0 +1,46 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009, Arnaud Roques + * + * Project Info: http://plantuml.sourceforge.net + * + * This file is part of PlantUML. + * + * PlantUML is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PlantUML distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 4167 $ + * + */ +package net.sourceforge.plantuml.postit; + +import java.awt.geom.Point2D; +import java.util.Collection; +import java.util.Map; + +import net.sourceforge.plantuml.graphic.StringBounder; + +public interface AreaLayout { + + Map getPositions(Collection all, StringBounder stringBounder); + +} diff --git a/src/net/sourceforge/plantuml/postit/AreaLayoutFixedWidth.java b/src/net/sourceforge/plantuml/postit/AreaLayoutFixedWidth.java new file mode 100644 index 000000000..3272b9507 --- /dev/null +++ b/src/net/sourceforge/plantuml/postit/AreaLayoutFixedWidth.java @@ -0,0 +1,61 @@ +/* ======================================================================== + * 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: 4167 $ + * + */ +package net.sourceforge.plantuml.postit; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; + +import net.sourceforge.plantuml.graphic.StringBounder; + +public class AreaLayoutFixedWidth implements AreaLayout { + + public Map getPositions(Collection all, StringBounder stringBounder) { + double x = 0; + double y = 0; + final Map result = new LinkedHashMap(); + + for (PostIt p : all) { + result.put(p, new Point2D.Double(x, y)); + final Dimension2D dim = p.getDimension(stringBounder); + x += dim.getWidth() + 10; + } + + return Collections.unmodifiableMap(result); + } + +} diff --git a/src/net/sourceforge/plantuml/postit/CommandCreatePostIt.java b/src/net/sourceforge/plantuml/postit/CommandCreatePostIt.java new file mode 100644 index 000000000..086d93836 --- /dev/null +++ b/src/net/sourceforge/plantuml/postit/CommandCreatePostIt.java @@ -0,0 +1,67 @@ +/* ======================================================================== + * 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: 5424 $ + * + */ +package net.sourceforge.plantuml.postit; + +import java.util.Map; + +import net.sourceforge.plantuml.StringUtils; +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.RegexPartialMatch; + +public class CommandCreatePostIt extends SingleLineCommand2 { + + public CommandCreatePostIt(PostItDiagram diagram) { + super(diagram, getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("post[- ]?it\\s+"), // + new RegexLeaf("ID", "([-\\p{L}0-9_./]+)"), // + new RegexLeaf("\\s+"), // + new RegexLeaf("TEXT", ":?(.*)?$")); + } + + @Override + protected CommandExecutionResult executeArg(Map arg) { + final String id = arg.get("ID").get(0); + final String text = arg.get("TEXT").get(0); + getSystem().createPostIt(id, StringUtils.getWithNewlines(text)); + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/postit/CommandWidth.java b/src/net/sourceforge/plantuml/postit/CommandWidth.java new file mode 100644 index 000000000..67f40cb27 --- /dev/null +++ b/src/net/sourceforge/plantuml/postit/CommandWidth.java @@ -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: 4762 $ + * + */ +package net.sourceforge.plantuml.postit; + +import java.util.List; + +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.SingleLineCommand; + +public class CommandWidth extends SingleLineCommand { + + public CommandWidth(PostItDiagram system) { + super(system, "(?i)^width\\s+(\\d+)$"); + } + + @Override + protected CommandExecutionResult executeArg(List arg) { + + final int width = Integer.parseInt(arg.get(0)); + getSystem().setWidth(width); + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/postit/Elastic.java b/src/net/sourceforge/plantuml/postit/Elastic.java new file mode 100644 index 000000000..e335f3697 --- /dev/null +++ b/src/net/sourceforge/plantuml/postit/Elastic.java @@ -0,0 +1,44 @@ +/* ======================================================================== + * 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: 4167 $ + * + */ +package net.sourceforge.plantuml.postit; + +import net.sourceforge.plantuml.graphic.StringBounder; + +public interface Elastic { + + double widthWhenHeightIs(double height, StringBounder stringBounder); + + double heightWhenWidthIs(double width, StringBounder stringBounder); + +} diff --git a/src/net/sourceforge/plantuml/postit/PostIdDiagramFactory.java b/src/net/sourceforge/plantuml/postit/PostIdDiagramFactory.java new file mode 100644 index 000000000..c1182b6f3 --- /dev/null +++ b/src/net/sourceforge/plantuml/postit/PostIdDiagramFactory.java @@ -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: 6137 $ + * + */ +package net.sourceforge.plantuml.postit; + +import net.sourceforge.plantuml.command.AbstractUmlSystemCommandFactory; + +public class PostIdDiagramFactory extends AbstractUmlSystemCommandFactory { + + private PostItDiagram system; + + @Override + protected void initCommands() { + system = new PostItDiagram(); + + addCommonCommands(system); + addCommand(new CommandCreatePostIt(system)); + addCommand(new CommandWidth(system)); + } + + public PostItDiagram getSystem() { + return system; + } + +} diff --git a/src/net/sourceforge/plantuml/postit/PostIt.java b/src/net/sourceforge/plantuml/postit/PostIt.java new file mode 100644 index 000000000..3a17d596d --- /dev/null +++ b/src/net/sourceforge/plantuml/postit/PostIt.java @@ -0,0 +1,114 @@ +/* ======================================================================== + * 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: 4167 $ + * + */ +package net.sourceforge.plantuml.postit; + +import java.awt.Color; +import java.awt.Font; +import java.awt.geom.Dimension2D; +import java.util.Collections; +import java.util.List; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.SkinParam; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.skin.Component; +import net.sourceforge.plantuml.skin.SimpleContext2D; +import net.sourceforge.plantuml.skin.rose.ComponentRoseNote; +import net.sourceforge.plantuml.ugraphic.UGraphic; + +public class PostIt { + + private final String id; + private final List text; + + private Dimension2D minimunDimension; + + public PostIt(String id, List text) { + this.id = id; + this.text = text; + } + + public String getId() { + return id; + } + + public List getText() { + return Collections.unmodifiableList(text); + } + + public Dimension2D getMinimunDimension() { + return minimunDimension; + } + + public void setMinimunDimension(Dimension2D minimunDimension) { + this.minimunDimension = minimunDimension; + } + + public Dimension2D getDimension(StringBounder stringBounder) { + double width = getComponent().getPreferredWidth(stringBounder); + double height = getComponent().getPreferredHeight(stringBounder); + + if (minimunDimension != null && width < minimunDimension.getWidth()) { + width = minimunDimension.getWidth(); + } + if (minimunDimension != null && height < minimunDimension.getHeight()) { + height = minimunDimension.getHeight(); + } + + return new Dimension2DDouble(width, height); + } + + public void drawU(UGraphic ug) { + + final Component note = getComponent(); + final StringBounder stringBounder = ug.getStringBounder(); + final Dimension2D dimensionToUse = getDimension(stringBounder); + + note.drawU(ug, dimensionToUse, new SimpleContext2D(false)); + + } + + private Component getComponent() { + final Color noteBackgroundColor = HtmlColor.getColorIfValid("#FBFB77").getColor(); + final Color borderColor = HtmlColor.getColorIfValid("#A80036").getColor(); + + final SkinParam param = new SkinParam(); + final Font fontNote = param.getFont(FontParam.NOTE, null); + final ComponentRoseNote note = new ComponentRoseNote(noteBackgroundColor, borderColor, Color.BLACK, fontNote, + text); + return note; + } +} diff --git a/src/net/sourceforge/plantuml/postit/PostItDiagram.java b/src/net/sourceforge/plantuml/postit/PostItDiagram.java new file mode 100644 index 000000000..2e8518eff --- /dev/null +++ b/src/net/sourceforge/plantuml/postit/PostItDiagram.java @@ -0,0 +1,147 @@ +/* ======================================================================== + * 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: 4167 $ + * + */ +package net.sourceforge.plantuml.postit; + +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.sourceforge.plantuml.EmptyImageBuilder; +import net.sourceforge.plantuml.FileFormat; +import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.UmlDiagram; +import net.sourceforge.plantuml.UmlDiagramType; +import net.sourceforge.plantuml.png.PngIO; +import net.sourceforge.plantuml.sequencediagram.graphic.SequenceDiagramFileMaker; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.eps.UGraphicEps; +import net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d; +import net.sourceforge.plantuml.ugraphic.svg.UGraphicSvg; + +public class PostItDiagram extends UmlDiagram { + + private final Area defaultArea = new Area('\0', null); + + private final Map postIts = new HashMap(); + + @Override + public UmlDiagramType getUmlDiagramType() { + throw new UnsupportedOperationException(); + } + + public void createFile(OutputStream os, int index, FileFormatOption fileFormatOption) throws IOException { + final UGraphic ug = createImage(fileFormatOption); + drawU(ug); + if (ug instanceof UGraphicG2d) { + final BufferedImage im = ((UGraphicG2d) ug).getBufferedImage(); + PngIO.write(im, os, this.getMetadata(), this.getDpi(fileFormatOption)); + } else if (ug instanceof UGraphicSvg) { + final UGraphicSvg svg = (UGraphicSvg) ug; + svg.createXml(os); + } else if (ug instanceof UGraphicEps) { + final UGraphicEps eps = (UGraphicEps) ug; + os.write(eps.getEPSCode().getBytes()); + } + } + + public List createFiles(File suggestedFile, FileFormatOption fileFormatOption) throws IOException, + InterruptedException { + OutputStream os = null; + try { + os = new FileOutputStream(suggestedFile); + createFile(os, 0, fileFormatOption); + } finally { + if (os != null) { + os.close(); + } + } + return Arrays.asList(suggestedFile); + } + + public String getDescription() { + return "Board of post-it"; + } + + public Area getDefaultArea() { + return defaultArea; + } + + public Area createArea(char id) { + throw new UnsupportedOperationException(); + } + + public PostIt createPostIt(String id, List text) { + if (postIts.containsKey(id)) { + throw new IllegalArgumentException(); + } + final PostIt postIt = new PostIt(id, text); + postIts.put(id, postIt); + getDefaultArea().add(postIt); + return postIt; + } + + void drawU(UGraphic ug) { + getDefaultArea().drawU(ug); + } + + private UGraphic createImage(FileFormatOption fileFormatOption) { + final Color backColor = this.getSkinParam().getBackgroundColor().getColor(); + final FileFormat fileFormat = fileFormatOption.getFileFormat(); + if (fileFormat == FileFormat.PNG) { + final double height = getDefaultArea().heightWhenWidthIs(width, + SequenceDiagramFileMaker.getDummystringbounder()); + final EmptyImageBuilder builder = new EmptyImageBuilder(width, height, backColor); + + final Graphics2D graphics2D = builder.getGraphics2D(); + final double dpiFactor = this.getDpiFactor(fileFormatOption); + return new UGraphicG2d(graphics2D, builder.getBufferedImage(), dpiFactor); + } + throw new UnsupportedOperationException(); + } + + private int width = 800; + + public void setWidth(int width) { + this.width = width; + } + +} diff --git a/src/net/sourceforge/plantuml/preproc/StartumlExtractReader.java b/src/net/sourceforge/plantuml/preproc/StartumlExtractReader.java new file mode 100644 index 000000000..5d3edd9df --- /dev/null +++ b/src/net/sourceforge/plantuml/preproc/StartumlExtractReader.java @@ -0,0 +1,76 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009, Arnaud Roques + * + * Project Info: http://plantuml.sourceforge.net + * + * This file is part of PlantUML. + * + * PlantUML is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PlantUML distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 3835 $ + * + */ +package net.sourceforge.plantuml.preproc; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +public class StartumlExtractReader implements ReadLine { + + private final ReadLine raw; + + public StartumlExtractReader(File f, int num) throws FileNotFoundException { + if (num < 0) { + throw new IllegalArgumentException(); + } + raw = getReadLine(f); + } + + static public boolean containsStartuml(File f) throws IOException { + ReadLine r = null; + try { + r = getReadLine(f); + } finally { + if (r != null) { + r.close(); + } + } + return false; + } + + private static ReadLine getReadLine(File f) throws FileNotFoundException { + return new UncommentReadLine(new ReadLineReader(new FileReader(f))); + } + + public String readLine() throws IOException { + return raw.readLine(); + } + + public void close() throws IOException { + raw.close(); + } + +} diff --git a/src/net/sourceforge/plantuml/sequencediagram/graphic/ConstraintSet.java b/src/net/sourceforge/plantuml/sequencediagram/graphic/ConstraintSet.java index f76abb83b..23ea853de 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/graphic/ConstraintSet.java +++ b/src/net/sourceforge/plantuml/sequencediagram/graphic/ConstraintSet.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5251 $ + * Revision $Revision: 6198 $ * */ package net.sourceforge.plantuml.sequencediagram.graphic; @@ -133,7 +133,7 @@ class ConstraintSet { } } - private void pushToLeftParticipantBox(double deltaX, Pushable firstToChange) { + public void pushToLeftParticipantBox(double deltaX, Pushable firstToChange, boolean including) { if (deltaX <= 0) { throw new IllegalArgumentException(); } @@ -145,6 +145,9 @@ class ConstraintSet { for (Pushable box : participantList) { if (box.equals(firstToChange)) { founded = true; + if (including==false) { + continue; + } } if (founded) { box.pushToLeft(deltaX); @@ -153,7 +156,7 @@ class ConstraintSet { } public void pushToLeft(double delta) { - pushToLeftParticipantBox(delta, firstBorder); + pushToLeftParticipantBox(delta, firstBorder, true); } private void ensureSpaceAfter(StringBounder stringBounder, Pushable p1, Pushable p2, double space) { @@ -167,7 +170,7 @@ class ConstraintSet { assert p1.getCenterX(stringBounder) < p2.getCenterX(stringBounder); final double existingSpace = p2.getCenterX(stringBounder) - p1.getCenterX(stringBounder); if (existingSpace < space) { - pushToLeftParticipantBox(space - existingSpace, p2); + pushToLeftParticipantBox(space - existingSpace, p2, true); } } diff --git a/src/net/sourceforge/plantuml/sequencediagram/graphic/DrawableSet.java b/src/net/sourceforge/plantuml/sequencediagram/graphic/DrawableSet.java index dbc0017ef..e11898f6c 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/graphic/DrawableSet.java +++ b/src/net/sourceforge/plantuml/sequencediagram/graphic/DrawableSet.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6113 $ + * Revision $Revision: 6198 $ * */ package net.sourceforge.plantuml.sequencediagram.graphic; @@ -141,7 +141,7 @@ class DrawableSet { return height + heightEnglober; } - public List getExistingParticipantEnglober2() { + public List getExistingParticipantEnglober() { final List result = new ArrayList(); ParticipantEngloberContexted pending = null; for (Map.Entry ent : participantEnglobers2.entrySet()) { @@ -163,7 +163,7 @@ class DrawableSet { public double getOffsetForEnglobers(StringBounder stringBounder) { double result = 0; - for (ParticipantEngloberContexted englober : getExistingParticipantEnglober2()) { + for (ParticipantEngloberContexted englober : getExistingParticipantEnglober()) { final Component comp = skin.createComponent(ComponentType.ENGLOBER, skinParam, englober .getParticipantEnglober().getTitle()); final double height = comp.getPreferredHeight(stringBounder); @@ -178,7 +178,7 @@ class DrawableSet { static private final int MARGIN_FOR_ENGLOBERS1 = 2; public double getTailHeight(StringBounder stringBounder, boolean showTail) { - final double marginForEnglobers = getExistingParticipantEnglober2().size() > 0 ? MARGIN_FOR_ENGLOBERS : 0; + final double marginForEnglobers = getExistingParticipantEnglober().size() > 0 ? MARGIN_FOR_ENGLOBERS : 0; if (showTail == false) { return 1 + marginForEnglobers; @@ -315,7 +315,7 @@ class DrawableSet { } private void drawEnglobers(UGraphic ug, double height, Context2D context) { - for (ParticipantEngloberContexted englober : getExistingParticipantEnglober2()) { + for (ParticipantEngloberContexted englober : getExistingParticipantEnglober()) { double x1 = getX1(englober); final double x2 = getX2(ug.getStringBounder(), englober); @@ -325,9 +325,9 @@ class DrawableSet { final double preferedWidth = getEngloberPreferedWidth(ug.getStringBounder(), englober.getParticipantEnglober()); if (preferedWidth > width) { - if (englober.getFirst2() == englober.getLast2()) { + //if (englober.getFirst2() == englober.getLast2()) { x1 -= (preferedWidth - width) / 2; - } + //} final Dimension2DDouble dim = new Dimension2DDouble(preferedWidth, height); ug.translate(x1, 1); comp.drawU(ug, dim, context); @@ -351,13 +351,13 @@ class DrawableSet { return skin.createComponent(ComponentType.ENGLOBER, s, englober.getTitle()); } - private double getX1(ParticipantEngloberContexted englober) { + public double getX1(ParticipantEngloberContexted englober) { final Participant first = englober.getFirst2(); final ParticipantBox firstBox = participants.get(first).getParticipantBox(); return firstBox.getStartingX() + 1; } - private double getX2(StringBounder stringBounder, ParticipantEngloberContexted englober) { + public double getX2(StringBounder stringBounder, ParticipantEngloberContexted englober) { final Participant last = englober.getLast2(); final ParticipantBox lastBox = participants.get(last).getParticipantBox(); return lastBox.getMaxX(stringBounder) - 1; @@ -394,7 +394,7 @@ class DrawableSet { // } private ParticipantEngloberContexted getParticipantEnglober(Participant p) { - for (ParticipantEngloberContexted pe : getExistingParticipantEnglober2()) { + for (ParticipantEngloberContexted pe : getExistingParticipantEnglober()) { if (pe.contains(p)) { return pe; } diff --git a/src/net/sourceforge/plantuml/sequencediagram/graphic/DrawableSetInitializer.java b/src/net/sourceforge/plantuml/sequencediagram/graphic/DrawableSetInitializer.java index f5569daa1..d80f566b2 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/graphic/DrawableSetInitializer.java +++ b/src/net/sourceforge/plantuml/sequencediagram/graphic/DrawableSetInitializer.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6113 $ + * Revision $Revision: 6198 $ * */ package net.sourceforge.plantuml.sequencediagram.graphic; @@ -154,9 +154,10 @@ class DrawableSetInitializer { } } - takeParticipantEngloberTitleWidth(stringBounder); - + //takeParticipantEngloberTitleWidth(stringBounder); constraintSet.takeConstraintIntoAccount(stringBounder); + //takeParticipantEngloberTitleWidth2(stringBounder); + takeParticipantEngloberTitleWidth3(stringBounder); prepareMissingSpace(stringBounder); @@ -164,26 +165,66 @@ class DrawableSetInitializer { return drawableSet; } - private void takeParticipantEngloberTitleWidth(StringBounder stringBounder) { - for (ParticipantEngloberContexted pe : drawableSet.getExistingParticipantEnglober2()) { + private void takeParticipantEngloberTitleWidth3(StringBounder stringBounder) { + for (ParticipantEngloberContexted pe : drawableSet.getExistingParticipantEnglober()) { final double preferredWidth = drawableSet.getEngloberPreferedWidth(stringBounder, pe.getParticipantEnglober()); final ParticipantBox first = drawableSet.getLivingParticipantBox(pe.getFirst2()).getParticipantBox(); final ParticipantBox last = drawableSet.getLivingParticipantBox(pe.getLast2()).getParticipantBox(); + final double x1 = drawableSet.getX1(pe); + final double x2 = drawableSet.getX2(stringBounder, pe); + final double missing = preferredWidth - (x2 - x1); + System.err.println("x1=" + x1 + " x2=" + x2 + " preferredWidth=" + preferredWidth + " missing=" + missing); + if (missing>0) { + constraintSet + .pushToLeftParticipantBox(missing / 2, first, true); + constraintSet + .pushToLeftParticipantBox(missing / 2, last, false); + } + } + } + + private void takeParticipantEngloberTitleWidth2(StringBounder stringBounder) { + double lastX2; + for (ParticipantEngloberContexted pe : drawableSet.getExistingParticipantEnglober()) { + final double preferredWidth = drawableSet.getEngloberPreferedWidth(stringBounder, + pe.getParticipantEnglober()); + final ParticipantBox first = drawableSet.getLivingParticipantBox(pe.getFirst2()).getParticipantBox(); + final ParticipantBox last = drawableSet.getLivingParticipantBox(pe.getLast2()).getParticipantBox(); + final double x1 = drawableSet.getX1(pe); + final double x2 = drawableSet.getX2(stringBounder, pe); + final double missing = preferredWidth - (x2 - x1); + System.err.println("x1=" + x1 + " x2=" + x2 + " preferredWidth=" + preferredWidth + " missing=" + missing); + if (missing > 0) { + constraintSet.getConstraintAfter(last).push(missing); + constraintSet.takeConstraintIntoAccount(stringBounder); + } + lastX2 = x2; + } + } + private void takeParticipantEngloberTitleWidth(StringBounder stringBounder) { + ParticipantBox previousLast = null; + for (ParticipantEngloberContexted pe : drawableSet.getExistingParticipantEnglober()) { + final double preferredWidth = drawableSet.getEngloberPreferedWidth(stringBounder, + pe.getParticipantEnglober()); + final ParticipantBox first = drawableSet.getLivingParticipantBox(pe.getFirst2()).getParticipantBox(); + final ParticipantBox last = drawableSet.getLivingParticipantBox(pe.getLast2()).getParticipantBox(); + final double margin = 5; if (first == last) { final Constraint constraint1 = constraintSet.getConstraintBefore(first); final Constraint constraint2 = constraintSet.getConstraintAfter(last); final double w1 = constraint1.getParticipant1().getPreferredWidth(stringBounder); final double w2 = constraint2.getParticipant2().getPreferredWidth(stringBounder); - constraint1.ensureValue(preferredWidth / 2 + w1 / 2 + 5); - constraint2.ensureValue(preferredWidth / 2 + w2 / 2 + 5); + constraint1.ensureValue(preferredWidth / 2 + w1 / 2 + margin); + constraint2.ensureValue(preferredWidth / 2 + w2 / 2 + margin); } else { final Pushable beforeFirst = constraintSet.getPrevious(first); final Pushable afterLast = constraintSet.getNext(last); final Constraint constraint1 = constraintSet.getConstraint(beforeFirst, afterLast); constraint1.ensureValue(preferredWidth + beforeFirst.getPreferredWidth(stringBounder) / 2 - + afterLast.getPreferredWidth(stringBounder) / 2 + 10); + + afterLast.getPreferredWidth(stringBounder) / 2 + 2 * margin); } + previousLast = last; } } diff --git a/src/net/sourceforge/plantuml/sequencediagram/graphic/SequenceDiagramFileMaker.java b/src/net/sourceforge/plantuml/sequencediagram/graphic/SequenceDiagramFileMaker.java index d4bd3f23b..5a65bd800 100644 --- a/src/net/sourceforge/plantuml/sequencediagram/graphic/SequenceDiagramFileMaker.java +++ b/src/net/sourceforge/plantuml/sequencediagram/graphic/SequenceDiagramFileMaker.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6113 $ + * Revision $Revision: 6208 $ * */ package net.sourceforge.plantuml.sequencediagram.graphic; @@ -408,4 +408,8 @@ public class SequenceDiagramFileMaker implements FileMaker { text.drawU(ug, area.getHeaderX(diagram.getHeaderAlignement()), area.getHeaderY()); } + public static StringBounder getDummystringbounder() { + return dummyStringBounder; + } + } diff --git a/src/net/sourceforge/plantuml/statediagram/command/CommandLinkState2.java b/src/net/sourceforge/plantuml/statediagram/command/CommandLinkState2.java index 240d35543..e41d04527 100644 --- a/src/net/sourceforge/plantuml/statediagram/command/CommandLinkState2.java +++ b/src/net/sourceforge/plantuml/statediagram/command/CommandLinkState2.java @@ -34,6 +34,7 @@ package net.sourceforge.plantuml.statediagram.command; import java.util.Map; +import java.util.StringTokenizer; import net.sourceforge.plantuml.Direction; import net.sourceforge.plantuml.StringUtils; @@ -57,14 +58,15 @@ public class CommandLinkState2 extends SingleLineCommand2 { static RegexConcat getRegex() { return new RegexConcat( - new RegexLeaf("^"), - getStatePattern("ENT1"), - new RegexLeaf("\\s*"), - new RegexLeaf("ARROW", "((-+)(left|right|up|down|le?|ri?|up?|do?)?(-*)([\\]>]))"), - new RegexLeaf("\\s*"), - getStatePattern("ENT2"), - new RegexLeaf("\\s*"), - new RegexLeaf("LABEL", "(?::\\s*([^\"]+))?"), + new RegexLeaf("^"), // + getStatePattern("ENT1"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("ARROW", + "((-+)(left|right|up|down|le?|ri?|up?|do?)?(?:\\[((?:#\\w+|dotted|dashed|bold)(?:,#\\w+|,dotted|,dashed|,bold)*)\\])?(-*)\\>)"), + new RegexLeaf("\\s*"), // + getStatePattern("ENT2"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("LABEL", "(?::\\s*([^\"]+))?"), // new RegexLeaf("$")); } @@ -79,7 +81,7 @@ public class CommandLinkState2 extends SingleLineCommand2 { final IEntity cl1 = getEntityStart(ent1); final IEntity cl2 = getEntityEnd(ent2); - + if (arg.get("ENT1").get(1) != null) { cl1.setStereotype(new Stereotype(arg.get("ENT1").get(1))); } @@ -93,7 +95,7 @@ public class CommandLinkState2 extends SingleLineCommand2 { cl2.setSpecificBackcolor(arg.get("ENT2").get(2)); } - String queue = arg.get("ARROW").get(1) + arg.get("ARROW").get(3); + String queue = arg.get("ARROW").get(1) + arg.get("ARROW").get(4); final Direction dir = getDirection(arg); if (dir == Direction.LEFT || dir == Direction.RIGHT) { @@ -106,6 +108,21 @@ public class CommandLinkState2 extends SingleLineCommand2 { if (dir == Direction.LEFT || dir == Direction.UP) { link = link.getInv(); } + if (arg.get("ARROW").get(3) != null) { + final StringTokenizer st = new StringTokenizer(arg.get("ARROW").get(3), ","); + while (st.hasMoreTokens()) { + final String s = st.nextToken(); + if (s.equalsIgnoreCase("dashed")) { + link = link.getDashed(); + } else if (s.equalsIgnoreCase("bold")) { + link = link.getBold(); + } else if (s.equalsIgnoreCase("dotted")) { + link = link.getDotted(); + } else { + link.setSpecificColor(s); + } + } + } getSystem().addLink(link); return CommandExecutionResult.ok(); diff --git a/src/net/sourceforge/plantuml/usecasediagram/UsecaseDiagramFactory.java b/src/net/sourceforge/plantuml/usecasediagram/UsecaseDiagramFactory.java index b3a78a856..97f5f9df7 100644 --- a/src/net/sourceforge/plantuml/usecasediagram/UsecaseDiagramFactory.java +++ b/src/net/sourceforge/plantuml/usecasediagram/UsecaseDiagramFactory.java @@ -45,6 +45,7 @@ import net.sourceforge.plantuml.usecasediagram.command.CommandCreateUsecase2; import net.sourceforge.plantuml.usecasediagram.command.CommandLinkUsecase2; import net.sourceforge.plantuml.usecasediagram.command.CommandMultilinesUsecaseNoteEntity; import net.sourceforge.plantuml.usecasediagram.command.CommandRankDirUsecase; +import net.sourceforge.plantuml.usecasediagram.command.CommandSetStrategy; public class UsecaseDiagramFactory extends AbstractUmlSystemCommandFactory { @@ -77,5 +78,7 @@ public class UsecaseDiagramFactory extends AbstractUmlSystemCommandFactory { addCommand(new CommandMultilinesUsecaseNoteEntity(system)); addCommand(new CommandMultilinesStandaloneNote(system)); - } + + addCommand(new CommandSetStrategy(system)); +} } diff --git a/src/net/sourceforge/plantuml/usecasediagram/command/CommandSetStrategy.java b/src/net/sourceforge/plantuml/usecasediagram/command/CommandSetStrategy.java new file mode 100644 index 000000000..917162f7e --- /dev/null +++ b/src/net/sourceforge/plantuml/usecasediagram/command/CommandSetStrategy.java @@ -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 + * + */ +package net.sourceforge.plantuml.usecasediagram.command; + +import java.util.List; + +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.SingleLineCommand; +import net.sourceforge.plantuml.cucadiagram.CucaDiagram; +import net.sourceforge.plantuml.cucadiagram.dot.GraphvizLayoutStrategy; + +public class CommandSetStrategy extends SingleLineCommand { + + public CommandSetStrategy(CucaDiagram diagram) { + super( + diagram, + "(?i)^layout with neato$"); + } + + @Override + protected CommandExecutionResult executeArg(List arg) { + getSystem().setStrategy(GraphvizLayoutStrategy.NEATO); + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/version/Version.java b/src/net/sourceforge/plantuml/version/Version.java index fa4216aec..0a0b922a6 100644 --- a/src/net/sourceforge/plantuml/version/Version.java +++ b/src/net/sourceforge/plantuml/version/Version.java @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6142 $ + * Revision $Revision: 6211 $ * */ package net.sourceforge.plantuml.version; @@ -36,11 +36,11 @@ package net.sourceforge.plantuml.version; public class Version { public static int version() { - return 6141; + return 6210; } public static long compileTime() { - return 1298495043843L; + return 1300656476468L; } } diff --git a/src/net/sourceforge/plantuml/xmi/XmiClassDiagram.java b/src/net/sourceforge/plantuml/xmi/XmiClassDiagram.java index 7583d6900..3d026f3e5 100644 --- a/src/net/sourceforge/plantuml/xmi/XmiClassDiagram.java +++ b/src/net/sourceforge/plantuml/xmi/XmiClassDiagram.java @@ -195,7 +195,7 @@ public class XmiClassDiagram { final Element feature = document.createElement("UML:Classifier.feature"); cla.appendChild(feature); - for (Member m : entity.fields2()) { + for (Member m : entity.getFieldsToDisplay()) { //