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

Import from version 5538

This commit is contained in:
Arnaud Roques 2010-11-15 21:35:36 +01:00
commit 042fad1353
651 changed files with 70374 additions and 0 deletions

58
build.xml Normal file
View File

@ -0,0 +1,58 @@
<!--
========================================================================
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
Script Author: Ilya V. Paramonov
-->
<project name="PlantUML" default="dist" basedir=".">
<description>
PlantUML Build File
</description>
<target name="compile">
<delete dir="build" />
<mkdir dir="build" />
<javac target="1.5" srcdir="src" destdir="build" />
<copy file="src/net/sourceforge/plantuml/version/logo.png"
todir="build/net/sourceforge/plantuml/version" />
</target>
<target name="dist" depends="compile">
<delete dir="dist" />
<mkdir dir="dist" />
<jar jarfile="plantuml.jar" basedir="build">
<manifest>
<attribute name="Main-Class" value="net.sourceforge.plantuml.Run" />
</manifest>
</jar>
<delete dir="build" />
<delete dir="dist" />
</target>
</project>

View File

@ -0,0 +1,81 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5520 $
*
*/
package net.sourceforge.plantuml;
import java.util.Date;
import java.util.Properties;
import net.sourceforge.plantuml.version.Version;
public abstract class AbstractPSystem implements PSystem {
private UmlSource source;
private String getVersion() {
final StringBuilder toAppend = new StringBuilder();
toAppend.append("PlantUML version ");
toAppend.append(Version.version());
toAppend.append("(" + new Date(Version.compileTime()) + ")\n");
final Properties p = System.getProperties();
toAppend.append(p.getProperty("java.runtime.name"));
toAppend.append('\n');
toAppend.append(p.getProperty("java.vm.name"));
toAppend.append('\n');
toAppend.append(p.getProperty("java.runtime.version"));
toAppend.append('\n');
toAppend.append(p.getProperty("os.name"));
return toAppend.toString();
}
final public String getMetadata() {
if (source == null) {
return getVersion();
}
return source.getPlainString() + "\n" + getVersion();
}
final public UmlSource getSource() {
return source;
}
final public void setSource(UmlSource source) {
this.source = source;
}
public int getNbImages() {
return 1;
}
}

View File

@ -0,0 +1,86 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4780 $
*
*/
package net.sourceforge.plantuml;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
class BlockUml {
private final List<String> data;
private PSystem system;
private static final Pattern pattern1 = Pattern.compile("^@startuml\\s+\"?(.*?)\"?$");
BlockUml(String... strings) {
this(Arrays.asList(strings));
}
BlockUml(List<String> strings) {
final String s0 = strings.get(0);
if (s0.startsWith("@startuml") == false) {
throw new IllegalArgumentException();
}
this.data = new ArrayList<String>(strings);
}
public String getFilename() {
if (OptionFlags.getInstance().isWord()) {
return null;
}
final Matcher m = pattern1.matcher(data.get(0));
final boolean ok = m.find();
if (ok == false) {
return null;
}
return m.group(1);
}
public PSystem getSystem() throws IOException, InterruptedException {
if (system==null) {
createSystem();
}
return system;
}
private void createSystem() throws IOException, InterruptedException {
system = new PSystemBuilder().createPSystem(data);
}
}

View File

@ -0,0 +1,106 @@
/* ========================================================================
* 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: 4952 $
*
*/
package net.sourceforge.plantuml;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.sourceforge.plantuml.preproc.Defines;
import net.sourceforge.plantuml.preproc.Preprocessor;
import net.sourceforge.plantuml.preproc.ReadLineReader;
import net.sourceforge.plantuml.preproc.UncommentReadLine;
final public class BlockUmlBuilder {
private final List<BlockUml> blocks = new ArrayList<BlockUml>();
public BlockUmlBuilder(List<String> config, Defines defines, Reader reader) throws IOException {
Preprocessor includer = null;
try {
includer = new Preprocessor(new UncommentReadLine(new ReadLineReader(reader)), defines);
init(includer, config);
} finally {
if (includer != null) {
includer.close();
}
}
}
private boolean isArobaseEnduml(final String s) {
return s.equals("@enduml") || s.startsWith("@enduml ");
}
private boolean isIgnoredLine(final String s) {
// return s.length() == 0 || s.startsWith("#") || s.startsWith("'");
return s.length() == 0 || s.startsWith("'");
}
private boolean isArobaseStartuml(final String s) {
return s.equals("@startuml") || s.startsWith("@startuml ");
}
private void init(Preprocessor includer, List<String> config) throws IOException {
String s = null;
List<String> current = null;
while ((s = includer.readLine()) != null) {
if (isArobaseStartuml(s)) {
current = new ArrayList<String>();
}
if (current != null && isIgnoredLine(s) == false) {
current.add(s);
}
if (isArobaseEnduml(s) && current != null) {
current.addAll(1, config);
blocks.add(new BlockUml(current));
current = null;
}
}
}
public List<BlockUml> getBlockUmls() {
return Collections.unmodifiableList(blocks);
}
/*
* private List<String> getStrings(Reader reader) throws IOException {
* final List<String> result = new ArrayList<String>(); Preprocessor
* includer = null; try { includer = new Preprocessor(reader, defines);
* String s = null; while ((s = includer.readLine()) != null) {
* result.add(s); } } finally { if (includer != null) { includer.close(); } }
* return Collections.unmodifiableList(result); }
*/
}

View File

@ -0,0 +1,117 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5218 $
*
*/
package net.sourceforge.plantuml;
public enum ColorParam {
background,
activityBackground,
activityBorder,
activityStart,
activityEnd,
activityBar,
activityArrow,
actorBackground,
actorBorder,
usecaseBorder,
usecaseBackground,
usecaseArrow,
objectBackground,
objectBorder,
objectArrow,
classBackground,
classBorder,
stereotypeCBackground,
stereotypeABackground,
stereotypeIBackground,
stereotypeEBackground,
classArrow,
packageBackground,
packageBorder,
componentBackground,
componentBorder,
interfaceBackground,
interfaceBorder,
componentArrow,
stateBackground,
stateBorder,
stateArrow,
noteBackground(true),
noteBorder,
sequenceActorBackground(true),
sequenceActorBorder,
sequenceGroupBackground(true),
sequenceDividerBackground(true),
sequenceLifeLineBackground(true),
sequenceLifeLineBorder,
sequenceParticipantBackground(true),
sequenceParticipantBorder,
sequenceArrow,
sequenceEngloberLine,
sequenceEngloberBackground(true),
iconPrivate,
iconPrivateBackground,
iconPackage,
iconPackageBackground,
iconProtected,
iconProtectedBackground,
iconPublic,
iconPublicBackground;
private final boolean isBackground;
private ColorParam() {
this(false);
}
private ColorParam(boolean isBackground) {
this.isBackground = isBackground;
}
protected boolean isBackground() {
return isBackground;
}
}

View File

@ -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: 4959 $
*
*/
package net.sourceforge.plantuml;
import java.awt.geom.Dimension2D;
public class Dimension2DDouble extends Dimension2D {
final private double width;
final private double height;
public Dimension2DDouble(double width, double height) {
this.width = width;
this.height = height;
}
@Override
public String toString() {
return "[" + width + "," + height + "]";
}
@Override
public double getHeight() {
return height;
}
@Override
public double getWidth() {
return width;
}
@Override
public void setSize(double width, double height) {
throw new UnsupportedOperationException();
}
public static Dimension2D delta(Dimension2D dim, double delta) {
return delta(dim, delta, delta);
}
public static Dimension2D delta(Dimension2D dim, double deltaWidth, double deltaHeight) {
return new Dimension2DDouble(dim.getWidth() + deltaWidth, dim.getHeight() + deltaHeight);
}
}

View File

@ -0,0 +1,100 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5229 $
*
*/
package net.sourceforge.plantuml;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sourceforge.plantuml.preproc.Defines;
public class DirWatcher {
final private File dir;
final private Option option;
final private String pattern;
final private Map<File, Long> modifieds = new HashMap<File, Long>();
public DirWatcher(File dir, Option option, String pattern) {
this.dir = dir;
this.option = option;
this.pattern = pattern;
}
public List<GeneratedImage> buildCreatedFiles() throws IOException, InterruptedException {
final List<GeneratedImage> result = new ArrayList<GeneratedImage>();
process(dir, result);
Collections.sort(result);
return Collections.unmodifiableList(result);
}
private void process(File dirToProcess, final List<GeneratedImage> result) throws IOException, InterruptedException {
for (File f : dirToProcess.listFiles()) {
if (f.isFile() == false) {
continue;
}
if (fileToProcess(f.getName()) == false) {
continue;
}
final long modified = f.lastModified();
final Long previousModified = modifieds.get(f);
if (previousModified == null || previousModified.longValue() != modified) {
final SourceFileReader sourceFileReader = new SourceFileReader(new Defines(), f, option.getOutputDir(),
option.getConfig(), option.getCharset(), option.getFileFormat());
for (GeneratedImage g : sourceFileReader.getGeneratedImages()) {
result.add(g);
}
modifieds.put(f, modified);
}
}
}
private boolean fileToProcess(String name) {
return name.matches(pattern);
}
public final File getDir() {
return dir;
}
// public void setPattern(String pattern) {
// this.pattern = pattern;
// }
}

View File

@ -0,0 +1,54 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 3828 $
*
*/
package net.sourceforge.plantuml;
public enum Direction {
RIGHT, LEFT, DOWN, UP;
public Direction getInv() {
if (this == RIGHT) {
return LEFT;
}
if (this == LEFT) {
return RIGHT;
}
if (this == DOWN) {
return UP;
}
if (this == UP) {
return DOWN;
}
throw new IllegalStateException();
}
}

View File

@ -0,0 +1,62 @@
/* ========================================================================
* 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: 3824 $
*
*/
package net.sourceforge.plantuml;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
public class EmptyImageBuilder {
private final BufferedImage im;
private final Graphics2D g2d;
public EmptyImageBuilder(int width, int height, Color background) {
im = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
g2d = im.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(background);
g2d.fillRect(0, 0, width, height);
}
public BufferedImage getBufferedImage() {
return im;
}
public Graphics2D getGraphics2D() {
return g2d;
}
}

View File

@ -0,0 +1,80 @@
/* ========================================================================
* 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: 3824 $
*
*/
package net.sourceforge.plantuml;
class ErrorUml {
private final String error;
private final int position;
private final ErrorUmlType type;
ErrorUml(ErrorUmlType type, String error, int position) {
if (error == null || type == null || StringUtils.isEmpty(error)) {
throw new IllegalArgumentException();
}
this.error = error;
this.type = type;
this.position = position;
}
@Override
public boolean equals(Object obj) {
final ErrorUml this2 = (ErrorUml) obj;
return this.type == this2.type && this.position == this2.position
&& this.error.equals(this2.error);
}
@Override
public int hashCode() {
return error.hashCode() + type.hashCode() + position;
}
@Override
public String toString() {
return type.toString() + " " + position + " " + error;
}
public final String getError() {
return error;
}
public final ErrorUmlType getType() {
return type;
}
public int getPosition() {
return position;
}
}

View File

@ -0,0 +1,39 @@
/* ========================================================================
* 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: 3824 $
*
*/
package net.sourceforge.plantuml;
enum ErrorUmlType {
SYNTAX_ERROR, EXECUTION_ERROR
}

View File

@ -0,0 +1,46 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5333 $
*
*/
package net.sourceforge.plantuml;
public enum FileFormat {
PNG, SVG, EPS, EPS_VIA_SVG, ATXT, UTXT;
public String getFileSuffix() {
if (this == EPS_VIA_SVG) {
throw new UnsupportedOperationException("Not used anymore");
// return EPS.getFileSuffix();
}
return "." + name().toLowerCase();
}
}

View File

@ -0,0 +1,174 @@
/* ========================================================================
* 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: 3824 $
*
*/
package net.sourceforge.plantuml;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class FileGroup {
private final List<File> result = new ArrayList<File>();
private final String pattern;
private final List<String> excluded;
private final Option option;
private final static Pattern predirPath = Pattern.compile("^([^*?]*[/\\\\])?(.*)$");
public FileGroup(String pattern, List<String> excluded, Option option) {
this.pattern = pattern;
this.excluded = excluded;
this.option = option;
if (pattern.indexOf("*") == -1 && pattern.indexOf("?") == -1) {
initNoStar();
} else if (pattern.indexOf("**") != -1) {
recurse();
} else {
initWithSimpleStar();
}
Collections.sort(result);
}
private void recurse() {
final Matcher m = predirPath.matcher(pattern);
final boolean ok = m.find();
if (ok == false) {
throw new IllegalArgumentException();
}
final File parent;
if (m.group(1) == null) {
parent = new File(".");
} else {
parent = new File(m.group(1));
}
initWithDoubleStar(parent);
}
private void initNoStar() {
final File f = new File(pattern);
if (f.isDirectory()) {
addSimpleDirectory(f);
} else if (f.isFile()) {
addResultFile(f);
}
}
private void addResultFile(final File f) {
final String path = getNormalizedPath(f);
for (String x : excluded) {
if (path.matches(toRegexp(x))) {
return;
}
}
result.add(f);
}
private void addSimpleDirectory(File dir) {
if (OptionFlags.getInstance().isWord()) {
addSimpleDirectory(dir, "(?i)^.*_extr\\d+\\.txt$");
} else {
addSimpleDirectory(dir, option.getPattern());
}
}
private void addSimpleDirectory(File dir, String pattern) {
if (dir.isDirectory() == false) {
throw new IllegalArgumentException("dir=" + dir);
}
for (File f : dir.listFiles()) {
if (f.getName().matches(pattern)) {
addResultFile(f);
}
}
}
private static String getNormalizedPath(File f) {
return f.getPath().replace('\\', '/');
}
private final static Pattern noStarInDirectory = Pattern.compile("^(?:([^*?]*)[/\\\\])?([^/\\\\]*)$");
private void initWithSimpleStar() {
assert pattern.indexOf("**") == -1;
final Matcher m = noStarInDirectory.matcher(pattern);
if (m.find()) {
File dir = new File(".");
if (m.group(1) != null) {
final String dirPart = m.group(1);
dir = new File(dirPart);
}
final String filesPart = m.group(2);
addSimpleDirectory(dir, toRegexp(filesPart));
} else {
recurse();
}
}
private void initWithDoubleStar(File currentDir) {
for (File f : currentDir.listFiles()) {
if (f.isDirectory()) {
initWithDoubleStar(f);
} else if (f.isFile()) {
final String path = getNormalizedPath(f);
if (path.matches(toRegexp(pattern))) {
addResultFile(f);
}
}
}
}
public List<File> getFiles() {
return Collections.unmodifiableList(result);
}
static String toRegexp(String pattern) {
pattern = pattern.replace("\\", "/");
pattern = pattern.replace(".", "\\.");
pattern = pattern.replace("?", "[^/]");
pattern = pattern.replace("/**/", "(/|/.{0,}/)");
pattern = pattern.replace("**", ".{0,}");
pattern = pattern.replace("*", "[^/]{0,}");
pattern = "(?i)^(\\./)?" + pattern + "$";
return pattern;
}
}

View File

@ -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: 4929 $
*
*/
package net.sourceforge.plantuml;
import java.io.File;
import java.io.IOException;
public class FileSystem {
private final static FileSystem singleton = new FileSystem();
private File currentDir;
private FileSystem() {
reset();
}
public static FileSystem getInstance() {
return singleton;
}
public void setCurrentDir(File dir) {
if (dir == null) {
throw new IllegalArgumentException();
}
Log.info("Setting current dir: " + dir);
this.currentDir = dir;
}
public File getCurrentDir() {
return this.currentDir;
}
public File getFile(String nameOrPath) throws IOException {
return new File(currentDir.getAbsoluteFile(), nameOrPath).getCanonicalFile();
}
public void reset() {
setCurrentDir(new File("."));
}
}

View File

@ -0,0 +1,105 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5218 $
*
*/
package net.sourceforge.plantuml;
import java.awt.Font;
public enum FontParam {
ACTIVITY(14, Font.PLAIN, "black", null),
ACTIVITY_ARROW(13, Font.PLAIN, "black", null),
CIRCLED_CHARACTER(17, Font.BOLD, "black", "Courier"),
OBJECT_ARROW(10, Font.PLAIN, "black", null),
OBJECT_ATTRIBUTE(10, Font.PLAIN, "black", null),
OBJECT(12, Font.PLAIN, "black", null),
OBJECT_STEREOTYPE(12, Font.ITALIC, "black", null),
CLASS_ARROW(10, Font.PLAIN, "black", null),
CLASS_ATTRIBUTE(10, Font.PLAIN, "black", null),
CLASS(12, Font.PLAIN, "black", null),
CLASS_STEREOTYPE(12, Font.ITALIC, "black", null),
COMPONENT(14, Font.PLAIN, "black", null),
COMPONENT_STEREOTYPE(14, Font.ITALIC, "black", null),
COMPONENT_ARROW(13, Font.PLAIN, "black", null),
NOTE(13, Font.PLAIN, "black", null),
PACKAGE(14, Font.PLAIN, "black", null),
SEQUENCE_ACTOR(13, Font.PLAIN, "black", null),
SEQUENCE_ARROW(13, Font.PLAIN, "black", null),
SEQUENCE_ENGLOBER(13, Font.BOLD, "black", null),
SEQUENCE_DIVIDER(13, Font.BOLD, "black", null),
SEQUENCE_GROUPING(11, Font.BOLD, "black", null),
SEQUENCE_GROUPING_HEADER(13, Font.BOLD, "black", null),
SEQUENCE_PARTICIPANT(13, Font.PLAIN, "black", null),
SEQUENCE_TITLE(13, Font.BOLD, "black", null),
STATE(14, Font.PLAIN, "black", null),
STATE_ARROW(13, Font.PLAIN, "black", null),
STATE_ATTRIBUTE(12, Font.PLAIN, "black", null),
TITLE(18, Font.PLAIN, "black", null),
FOOTER(10, Font.PLAIN, "#888888", null),
HEADER(10, Font.PLAIN, "#888888", null),
USECASE(14, Font.PLAIN, "black", null),
USECASE_STEREOTYPE(14, Font.ITALIC, "black", null),
USECASE_ACTOR(14, Font.PLAIN, "black", null),
USECASE_ACTOR_STEREOTYPE(14, Font.ITALIC, "black", null),
USECASE_ARROW(13, Font.PLAIN, "black", null);
private final int defaultSize;
private final int fontStyle;
private final String defaultColor;
private final String defaultFamily;
private FontParam(int defaultSize, int fontStyle, String defaultColor, String defaultFamily) {
this.defaultSize = defaultSize;
this.fontStyle = fontStyle;
this.defaultColor = defaultColor;
this.defaultFamily = defaultFamily;
}
public final int getDefaultSize() {
return defaultSize;
}
public final int getDefaultFontStyle() {
return fontStyle;
}
public final String getDefaultColor() {
return defaultColor;
}
public String getDefaultFamily() {
return defaultFamily;
}
}

View File

@ -0,0 +1,83 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 3824 $
*
*/
package net.sourceforge.plantuml;
import java.io.File;
public class GeneratedImage implements Comparable<GeneratedImage> {
private final File pngFile;
private final String description;
public GeneratedImage(File pngFile, String description) {
if (pngFile == null) {
throw new IllegalArgumentException();
}
this.pngFile = pngFile;
this.description = description;
}
public File getPngFile() {
return pngFile;
}
public String getDescription() {
return description;
}
@Override
public String toString() {
return pngFile.getAbsolutePath() + " " + description;
}
public int compareTo(GeneratedImage this2) {
final int cmp = this.pngFile.compareTo(this2.pngFile);
if (cmp != 0) {
return cmp;
}
return this.description.compareTo(this2.description);
}
@Override
public int hashCode() {
return pngFile.hashCode() + description.hashCode();
}
@Override
public boolean equals(Object obj) {
final GeneratedImage this2 = (GeneratedImage) obj;
return this2.pngFile.equals(this.pngFile) && this2.description.equals(this.description);
}
}

View File

@ -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: 4236 $
*
*/
package net.sourceforge.plantuml;
import java.awt.Font;
import net.sourceforge.plantuml.graphic.HtmlColor;
public interface ISkinParam {
public HtmlColor getBackgroundColor();
public String getValue(String key);
public HtmlColor getHtmlColor(ColorParam param);
public int getFontSize(FontParam param);
public String getFontFamily(FontParam param);
public HtmlColor getFontHtmlColor(FontParam param);
public int getFontStyle(FontParam param);
public Font getFont(FontParam fontParam);
public int getCircledCharacterRadius();
public boolean isClassCollapse();
public int classAttributeIconSize();
public boolean isMonochrome();
}

View File

@ -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: 4639 $
*
*/
package net.sourceforge.plantuml;
import java.io.PrintStream;
import java.util.Collection;
import java.util.Set;
import java.util.TreeSet;
import net.sourceforge.plantuml.graphic.HtmlColor;
public class LanguageDescriptor {
private final Set<String> type = new TreeSet<String>();
private final Set<String> keyword = new TreeSet<String>();
private final Set<String> preproc = new TreeSet<String>();
public LanguageDescriptor() {
type.add("actor");
type.add("participant");
type.add("usecase");
type.add("class");
type.add("interface");
type.add("abstract");
type.add("enum");
type.add("component");
type.add("state");
type.add("object");
keyword.add("@startuml");
keyword.add("@enduml");
keyword.add("as");
keyword.add("autonumber");
keyword.add("title");
keyword.add("newpage");
keyword.add("box");
keyword.add("alt");
keyword.add("else");
keyword.add("opt");
keyword.add("loop");
keyword.add("par");
keyword.add("break");
keyword.add("critical");
keyword.add("note");
keyword.add("group");
keyword.add("left");
keyword.add("right");
keyword.add("of");
keyword.add("over");
keyword.add("end");
keyword.add("activate");
keyword.add("deactivate");
keyword.add("destroy");
keyword.add("create");
keyword.add("footbox");
keyword.add("hide");
keyword.add("show");
keyword.add("skinparam");
keyword.add("skin");
keyword.add("top");
keyword.add("bottom");
keyword.add("top to bottom direction");
keyword.add("package");
keyword.add("namespace");
keyword.add("page");
keyword.add("up");
keyword.add("down");
keyword.add("if");
keyword.add("else");
keyword.add("endif");
keyword.add("partition");
keyword.add("footer");
keyword.add("header");
keyword.add("center");
keyword.add("rotate");
preproc.add("!include");
preproc.add("!define");
preproc.add("!undef");
preproc.add("!ifdef");
preproc.add("!endif");
preproc.add("!ifndef");
}
public void print(PrintStream ps) {
print(ps, "type", type);
print(ps, "keyword", keyword);
print(ps, "preprocessor", preproc);
print(ps, "skinparameter", SkinParam.getPossibleValues());
print(ps, "color", HtmlColor.names());
ps.println(";EOF");
}
private static void print(PrintStream ps, String name, Collection<String> data) {
ps.println(";"+name);
ps.println(";" + data.size());
for (String k : data) {
ps.println(k);
}
ps.println();
}
}

View File

@ -0,0 +1,71 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 3824 $
*
*/
package net.sourceforge.plantuml;
public abstract class Log {
private static long start = System.currentTimeMillis();
public static void debug(String s) {
}
public static void info(String s) {
if (OptionFlags.getInstance().isVerbose()) {
System.out.println(format(s));
}
}
public static void error(String s) {
System.err.println(s);
}
private static String format(String s) {
final long delta = System.currentTimeMillis() - start;
final StringBuilder sb = new StringBuilder();
sb.append("(");
sb.append(delta / 1000L);
sb.append(".");
sb.append(String.format("%03d", delta % 1000L));
sb.append(" - ");
final long total = (Runtime.getRuntime().totalMemory()) / 1024 / 1024;
final long free = (Runtime.getRuntime().freeMemory()) / 1024 / 1024;
sb.append(total);
sb.append(" Mo) ");
sb.append(free);
sb.append(" Mo - ");
sb.append(s);
return sb.toString();
}
}

View File

@ -0,0 +1,264 @@
/* ========================================================================
* 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: 5343 $
*
*/
package net.sourceforge.plantuml;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sourceforge.plantuml.preproc.Defines;
public class Option {
private final List<String> excludes = new ArrayList<String>();
private final List<String> config = new ArrayList<String>();
private final Map<String, String> defines = new LinkedHashMap<String, String>();
private String charset;
private boolean computeurl = false;
private boolean decodeurl = false;
private boolean pipe = false;
private boolean syntax = false;
private File outputDir = null;
private final List<String> result = new ArrayList<String>();
public Option() {
}
private FileFormat fileFormat = FileFormat.PNG;
public FileFormat getFileFormat() {
return fileFormat;
}
public void setFileFormat(FileFormat fileFormat) {
this.fileFormat = fileFormat;
}
public Option(String... arg) throws InterruptedException, IOException {
if (arg.length == 0) {
OptionFlags.getInstance().setGui(true);
}
for (int i = 0; i < arg.length; i++) {
String s = arg[i];
if (s.equalsIgnoreCase("-tsvg") || s.equalsIgnoreCase("-svg")) {
setFileFormat(FileFormat.SVG);
} else if (s.equalsIgnoreCase("-teps") || s.equalsIgnoreCase("-eps")) {
setFileFormat(FileFormat.EPS);
} else if (s.equalsIgnoreCase("-ttxt") || s.equalsIgnoreCase("-txt")) {
setFileFormat(FileFormat.ATXT);
} else if (s.equalsIgnoreCase("-tutxt") || s.equalsIgnoreCase("-utxt")) {
setFileFormat(FileFormat.UTXT);
} else if (s.equalsIgnoreCase("-output") || s.equalsIgnoreCase("-o")) {
i++;
if (i == arg.length) {
continue;
}
outputDir = new File(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i]));
} else if (s.equalsIgnoreCase("-graphvizdot") || s.equalsIgnoreCase("-graphviz_dot")) {
i++;
if (i == arg.length) {
continue;
}
OptionFlags.getInstance().setDotExecutable(
StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i]));
} else if (s.equalsIgnoreCase("-charset")) {
i++;
if (i == arg.length) {
continue;
}
charset = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i]);
} else if (s.startsWith("-o") && s.length() > 3) {
s = s.substring(2);
outputDir = new File(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(s));
} else if (s.equalsIgnoreCase("-recurse") || s.equalsIgnoreCase("-r")) {
// recurse = true;
} else if (s.equalsIgnoreCase("-exclude") || s.equalsIgnoreCase("-x")) {
i++;
if (i == arg.length) {
continue;
}
excludes.add(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i]));
} else if (s.equalsIgnoreCase("-config")) {
i++;
if (i == arg.length) {
continue;
}
initConfig(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg[i]));
} else if (s.equalsIgnoreCase("-computeurl") || s.equalsIgnoreCase("-encodeurl")) {
this.computeurl = true;
} else if (s.startsWith("-c")) {
s = s.substring(2);
config.add(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(s));
} else if (s.startsWith("-x")) {
s = s.substring(2);
excludes.add(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(s));
} else if (s.equalsIgnoreCase("-debugdot")) {
OptionFlags.getInstance().setDebugDot(true);
} else if (s.equalsIgnoreCase("-verbose") || s.equalsIgnoreCase("-v")) {
OptionFlags.getInstance().setVerbose(true);
} else if (s.equalsIgnoreCase("-pipe") || s.equalsIgnoreCase("-p")) {
pipe = true;
} else if (s.equalsIgnoreCase("-syntax")) {
syntax = true;
OptionFlags.getInstance().setQuiet(true);
} else if (s.equalsIgnoreCase("-keepfiles") || s.equalsIgnoreCase("-keepfile")) {
OptionFlags.getInstance().setKeepTmpFiles(true);
} else if (s.equalsIgnoreCase("-metadata")) {
OptionFlags.getInstance().setMetadata(true);
} else if (s.equalsIgnoreCase("-word")) {
OptionFlags.getInstance().setWord(true);
OptionFlags.getInstance().setQuiet(true);
} else if (s.equalsIgnoreCase("-forcegd")) {
OptionFlags.getInstance().setForceGd(true);
} else if (s.equalsIgnoreCase("-forcecairo")) {
OptionFlags.getInstance().setForceCairo(true);
} else if (s.equalsIgnoreCase("-quiet")) {
OptionFlags.getInstance().setQuiet(true);
} else if (s.equalsIgnoreCase("-decodeurl")) {
this.decodeurl = true;
} else if (s.equalsIgnoreCase("-version")) {
OptionPrint.printVersion();
} else if (s.startsWith("-D")) {
manageDefine(s.substring(2));
} else if (s.equalsIgnoreCase("-testdot")) {
OptionPrint.printTestDot();
} else if (s.equalsIgnoreCase("-about") || s.equalsIgnoreCase("-author") || s.equalsIgnoreCase("-authors")) {
OptionPrint.printAbout();
} else if (s.equalsIgnoreCase("-help") || s.equalsIgnoreCase("-h") || s.equalsIgnoreCase("-?")) {
OptionPrint.printHelp();
} else if (s.equalsIgnoreCase("-language")) {
OptionPrint.printLanguage();
} else if (s.equalsIgnoreCase("-gui")) {
OptionFlags.getInstance().setGui(true);
} else {
result.add(s);
}
}
}
public void initConfig(String filename) throws IOException {
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader(filename));
String s = null;
while ((s = br.readLine()) != null) {
config.add(s);
}
} finally {
if (br != null) {
br.close();
}
}
}
private void manageDefine(String s) {
final Pattern p = Pattern.compile("^(\\w+)(?:=(.*))?$");
final Matcher m = p.matcher(s);
if (m.find()) {
define(m.group(1), m.group(2));
}
}
public final File getOutputDir() {
return outputDir;
}
public final static String getPattern() {
return "(?i)^.*\\.(txt|tex|java|htm|html|c|h|cpp|apt)$";
}
public void setOutputDir(File f) {
outputDir = f;
}
public final List<String> getExcludes() {
return Collections.unmodifiableList(excludes);
}
public Defines getDefaultDefines() {
final Defines result = new Defines();
for (Map.Entry<String, String> ent : defines.entrySet()) {
result.define(ent.getKey(), ent.getValue());
}
return result;
}
public void define(String name, String value) {
defines.put(name, value);
}
public List<String> getConfig() {
return Collections.unmodifiableList(config);
}
public final List<String> getResult() {
return Collections.unmodifiableList(result);
}
public final String getCharset() {
return charset;
}
public void setCharset(String s) {
this.charset = s;
}
public final boolean isComputeurl() {
return computeurl;
}
public final boolean isDecodeurl() {
return decodeurl;
}
public final boolean isPipe() {
return pipe;
}
public final boolean isSyntax() {
return syntax;
}
}

View File

@ -0,0 +1,173 @@
/* ========================================================================
* 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: 5244 $
*
*/
package net.sourceforge.plantuml;
public class OptionFlags {
void reset() {
keepTmpFiles = false;
verbose = false;
metadata = false;
word = false;
debugDot = false;
forceGd = false;
forceCairo = false;
quiet = false;
dotExecutable = null;
}
public boolean useJavaInsteadOfDot() {
return false;
}
private static final OptionFlags singleton = new OptionFlags();
private boolean keepTmpFiles = false;
private boolean verbose = false;
private boolean metadata = false;
private boolean word = false;
private boolean systemExit = true;
// private boolean pipe = false;
private boolean debugDot = false;
private boolean forceGd = false;
private boolean forceCairo = false;
private String dotExecutable = null;
private boolean gui = false;
private boolean quiet = false;
//
// public final boolean isPipe() {
// return pipe;
// }
//
// public final void setPipe(boolean pipe) {
// this.pipe = pipe;
// }
private OptionFlags() {
reset();
}
public static OptionFlags getInstance() {
return singleton;
}
public final boolean isKeepTmpFiles() {
return keepTmpFiles;
}
public final void setKeepTmpFiles(boolean keepTmpFiles) {
this.keepTmpFiles = keepTmpFiles;
}
public final boolean isVerbose() {
return verbose;
}
public final void setVerbose(boolean verbose) {
this.verbose = verbose;
}
public final boolean isMetadata() {
return metadata;
}
public final void setMetadata(boolean metadata) {
this.metadata = metadata;
}
public final boolean isWord() {
return word;
}
public final void setWord(boolean word) {
this.word = word;
}
public final boolean isSystemExit() {
return systemExit;
}
public final void setSystemExit(boolean systemExit) {
this.systemExit = systemExit;
}
public final boolean isDebugDot() {
return debugDot;
}
public final void setDebugDot(boolean debugDot) {
this.debugDot = debugDot;
}
public final String getDotExecutable() {
return dotExecutable;
}
public final void setDotExecutable(String dotExecutable) {
this.dotExecutable = dotExecutable;
}
public final boolean isGui() {
return gui;
}
public final void setGui(boolean gui) {
this.gui = gui;
}
public final boolean isForceGd() {
return forceGd;
}
public final void setForceGd(boolean forceGd) {
this.forceGd = forceGd;
}
public final boolean isForceCairo() {
return forceCairo;
}
public final void setForceCairo(boolean forceCairo) {
this.forceCairo = forceCairo;
}
public final boolean isQuiet() {
return quiet;
}
public final void setQuiet(boolean quiet) {
this.quiet = quiet;
}
}

View File

@ -0,0 +1,170 @@
/* ========================================================================
* 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: 5211 $
*
*/
package net.sourceforge.plantuml;
import java.io.File;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizUtils;
import net.sourceforge.plantuml.version.Version;
public class OptionPrint {
static public void printTestDot() throws InterruptedException {
for (String s : getTestDotStrings()) {
System.err.println(s);
}
exit();
}
static public List<String> getTestDotStrings() {
final List<String> result = new ArrayList<String>();
final String ent = GraphvizUtils.getenvGraphvizDot();
if (ent == null) {
result.add("The environment variable GRAPHVIZ_DOT has not been set");
} else {
result.add("The environment variable GRAPHVIZ_DOT has been set to " + ent);
}
final File dotExe = GraphvizUtils.getDotExe();
result.add("Dot executable is " + dotExe);
boolean ok = true;
if (dotExe == null) {
result.add("Error: No dot executable found");
ok = false;
} else if (dotExe.exists() == false) {
result.add("Error: file does not exist");
ok = false;
} else if (dotExe.isFile() == false) {
result.add("Error: not a valid file");
ok = false;
} else if (dotExe.canRead() == false) {
result.add("Error: cannot be read");
ok = false;
}
if (ok) {
try {
final String version = GraphvizUtils.dotVersion();
result.add("Dot version: " + version);
result.add("Installation seems OK");
} catch (Exception e) {
e.printStackTrace();
}
} else {
result.add("Error: only sequence diagrams will be generated");
}
return Collections.unmodifiableList(result);
}
static public void printHelp() throws InterruptedException {
final String charset = Charset.defaultCharset().displayName();
System.err.println("Usage: java -jar plantuml.jar [options] -gui");
System.err.println("\t(to execute the GUI)");
System.err.println(" or java -jar plantuml.jar [options] [files/dirs]");
System.err.println("\t(to process files or directories)");
System.err.println();
System.err.println("You can use the following wildcards in files/dirs:");
System.err.println("\t*\tmeans any characters but '" + File.separator + "'");
System.err.println("\t?\tone and only one character but '" + File.separator + "'");
System.err.println("\t**\tmeans any characters (used to recurse through directories)");
System.err.println();
System.err.println("where options include:");
System.err.println(" -gui\t\tTo run the graphical user interface");
System.err.println(" -tsvg\t\tTo generate images using SVG format");
System.err.println(" -o[utput] \"dir\"\tTo generate images in the specified directory");
System.err.println(" -config \"file\"\tTo read the provided config file before each diagram");
System.err.println(" -charset xxx\tTo use a specific charset (default is " + charset + ")");
System.err.println(" -e[x]clude pattern\tTo exclude files that match the provided pattern");
System.err.println(" -metadata\t\tTo retrieve PlantUML sources from PNG images");
System.err.println(" -version\t\tTo display information about PlantUML and Java versions");
System.err.println(" -v[erbose]\t\tTo have log information");
System.err.println(" -quiet\t\tTo NOT print error message into the console");
System.err.println(" -forcegd\t\tTo force dot to use GD PNG library");
System.err.println(" -forcecairo\t\tTo force dot to use Cairo PNG library");
System.err.println(" -keepfiles\t\tTo NOT delete temporary files after process");
System.err.println(" -h[elp]\t\tTo display this help message");
System.err.println(" -testdot\t\tTo test the installation of graphviz");
System.err.println(" -graphvizdot \"exe\"\tTo specify dot executable");
System.err.println(" -p[ipe]\t\tTo use stdin for PlantUML source and stdout for PNG/SVG generation");
System.err.println(" -computeurl\t\tTo compute the encoded URL of a PlantUML source file");
System.err.println(" -decodeurl\t\tTo retrieve the PlantUML source from an encoded URL");
System.err.println();
System.err.println("If needed, you can setup the environment variable GRAPHVIZ_DOT.");
exit();
}
static private void exit() throws InterruptedException {
if (OptionFlags.getInstance().isSystemExit()) {
System.exit(0);
}
throw new InterruptedException("exit");
}
public static void printVersion() throws InterruptedException {
System.err.println("PlantUML version " + Version.version() + " (" + new Date(Version.compileTime()) + ")");
final Properties p = System.getProperties();
System.err.println(p.getProperty("java.runtime.name"));
System.err.println(p.getProperty("java.vm.name"));
System.err.println(p.getProperty("java.runtime.version"));
System.err.println(p.getProperty("os.name"));
exit();
}
public static void printAbout() throws InterruptedException {
System.err.println("PlantUML version " + Version.version() + " (" + new Date(Version.compileTime()) + ")");
System.err.println();
System.err.println("Original idea: Arnaud Roques");
System.err.println("Word Macro: Alain Bertucat & Matthieu Sabatier");
System.err.println("Eclipse Plugin: Claude Durif & Anne Pecoil");
System.err.println("Site design: Raphael Cotisson");
System.err.println();
System.err.println("http://plantuml.sourceforge.net");
exit();
}
public static void printLanguage() throws InterruptedException {
new LanguageDescriptor().print(System.out);
exit();
}
}

View File

@ -0,0 +1,55 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5520 $
*
*/
package net.sourceforge.plantuml;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
public interface PSystem {
List<File> createFiles(File suggestedFile, FileFormat fileFormat) throws IOException, InterruptedException;
void createFile(OutputStream os, int index, FileFormat fileFormat) throws IOException;
int getNbImages();
String getDescription();
String getMetadata();
UmlSource getSource();
}

View File

@ -0,0 +1,38 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 3824 $
*/
package net.sourceforge.plantuml;
public interface PSystemBasicFactory extends PSystemFactory {
boolean executeLine(String line);
}

View File

@ -0,0 +1,119 @@
/* ========================================================================
* 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: 5207 $
*
*/
package net.sourceforge.plantuml;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import net.sourceforge.plantuml.activitydiagram.ActivityDiagramFactory;
import net.sourceforge.plantuml.classdiagram.ClassDiagramFactory;
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.printskin.PrintSkinFactory;
import net.sourceforge.plantuml.sequencediagram.SequenceDiagramFactory;
import net.sourceforge.plantuml.statediagram.StateDiagramFactory;
import net.sourceforge.plantuml.sudoku.PSystemSudokuFactory;
import net.sourceforge.plantuml.usecasediagram.UsecaseDiagramFactory;
import net.sourceforge.plantuml.version.PSystemVersionFactory;
public class PSystemBuilder {
final public PSystem createPSystem(final List<String> strings) throws IOException, InterruptedException {
final List<PSystemFactory> factories = new ArrayList<PSystemFactory>();
factories.add(new SequenceDiagramFactory());
factories.add(new ClassDiagramFactory());
factories.add(new ActivityDiagramFactory());
factories.add(new UsecaseDiagramFactory());
factories.add(new ComponentDiagramFactory());
factories.add(new StateDiagramFactory());
factories.add(new CompositeDiagramFactory());
factories.add(new ObjectDiagramFactory());
factories.add(new PrintSkinFactory());
factories.add(new PSystemVersionFactory());
factories.add(new PSystemSudokuFactory());
factories.add(new PSystemEggFactory());
factories.add(new PSystemRIPFactory());
factories.add(new PSystemLostFactory());
factories.add(new PSystemPathFactory());
factories.add(new PSystemOregonFactory());
final List<PSystemError> errors = new ArrayList<PSystemError>();
for (PSystemFactory systemFactory : factories) {
final PSystem sys = new PSystemSingleBuilder(strings, systemFactory).getPSystem();
if (isOk(sys)) {
return sys;
}
errors.add((PSystemError) sys);
}
final PSystemError err = merge(errors);
if (OptionFlags.getInstance().isQuiet() == false) {
err.print(System.err);
}
return err;
}
private PSystemError merge(Collection<PSystemError> ps) {
UmlSource source = null;
final List<ErrorUml> errors = new ArrayList<ErrorUml>();
for (PSystemError system : ps) {
if (system.getSource() != null && source == null) {
source = system.getSource();
}
errors.addAll(system.getErrorsUml());
}
if (source == null) {
throw new IllegalStateException();
}
return new PSystemError(source, errors);
}
private boolean isOk(PSystem ps) {
if (ps == null || ps instanceof PSystemError) {
return false;
}
return true;
}
}

View File

@ -0,0 +1,191 @@
/* ========================================================================
* 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: 5507 $
*/
package net.sourceforge.plantuml;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.TreeSet;
import net.sourceforge.plantuml.graphic.GraphicStrings;
public class PSystemError extends AbstractPSystem {
private final List<ErrorUml> errorsUml = new ArrayList<ErrorUml>();
private final List<String> htmlStrings = new ArrayList<String>();
private final List<String> plainStrings = new ArrayList<String>();
private final int higherErrorPosition;
private final Collection<String> errs;
public PSystemError(UmlSource source, List<ErrorUml> errorUml) {
this.errorsUml.addAll(errorUml);
this.setSource(source);
final Collection<ErrorUml> executions = getErrors(ErrorUmlType.EXECUTION_ERROR);
if (executions.size() > 0) {
higherErrorPosition = getHigherErrorPosition(ErrorUmlType.EXECUTION_ERROR);
errs = getErrorsAt(higherErrorPosition, ErrorUmlType.EXECUTION_ERROR);
appendSource(higherErrorPosition, errs);
} else {
higherErrorPosition = getHigherErrorPosition(ErrorUmlType.SYNTAX_ERROR);
errs = getErrorsAt(higherErrorPosition, ErrorUmlType.SYNTAX_ERROR);
if (errs.size() != 1) {
throw new UnsupportedOperationException(errs.toString());
}
appendSource(higherErrorPosition, errs);
}
}
public PSystemError(UmlSource source, ErrorUml... errorUml) {
this(source, Arrays.asList(errorUml));
}
public List<File> createFiles(File suggestedFile, FileFormat fileFormat) throws IOException, InterruptedException {
OutputStream os = null;
try {
os = new FileOutputStream(suggestedFile);
getPngError().writeImage(os, getMetadata(), fileFormat);
} finally {
if (os != null) {
os.close();
}
}
return Arrays.asList(suggestedFile);
}
public void createFile(OutputStream os, int index, FileFormat fileFormat) throws IOException {
getPngError().writeImage(os, getMetadata(), fileFormat);
}
public GraphicStrings getPngError() throws IOException {
return new GraphicStrings(htmlStrings);
}
private void appendSource(int position, Collection<String> errs) {
final int limit = 4;
int start;
final int skip = position - limit + 1;
if (skip <= 0) {
start = 0;
} else {
if (skip == 1) {
htmlStrings.add("... (skipping 1 line) ...");
plainStrings.add("... (skipping 1 line) ...");
} else {
htmlStrings.add("... (skipping " + skip + " lines) ...");
plainStrings.add("... (skipping " + skip + " lines) ...");
}
start = position - limit + 1;
}
for (int i = start; i < position; i++) {
htmlStrings.add(StringUtils.hideComparatorCharacters(getSource().getLine(i)));
plainStrings.add(getSource().getLine(i));
}
final String errorLine = getSource().getLine(position);
htmlStrings.add("<w:red>" + StringUtils.hideComparatorCharacters(errorLine) + "</w>");
plainStrings.add(StringUtils.hideComparatorCharacters(errorLine));
final StringBuilder underscore = new StringBuilder();
for (int i = 0; i < errorLine.length(); i++) {
underscore.append("^");
}
plainStrings.add(underscore.toString());
for (String er : errs) {
htmlStrings.add(" <font color=red>" + er);
plainStrings.add(" " + er);
}
}
private Collection<ErrorUml> getErrors(ErrorUmlType type) {
final Collection<ErrorUml> result = new LinkedHashSet<ErrorUml>();
for (ErrorUml error : errorsUml) {
if (error.getType() == type) {
result.add(error);
}
}
return result;
}
private int getHigherErrorPosition(ErrorUmlType type) {
int max = Integer.MIN_VALUE;
for (ErrorUml error : getErrors(type)) {
if (error.getPosition() > max) {
max = error.getPosition();
}
}
if (max == Integer.MIN_VALUE) {
throw new IllegalStateException();
}
return max;
}
private Collection<String> getErrorsAt(int position, ErrorUmlType type) {
final Collection<String> result = new TreeSet<String>();
for (ErrorUml error : getErrors(type)) {
if (error.getPosition() == position && StringUtils.isNotEmpty(error.getError())) {
result.add(error.getError());
}
}
return result;
}
public String getDescription() {
return "(Error)";
}
public final List<ErrorUml> getErrorsUml() {
return Collections.unmodifiableList(errorsUml);
}
public void print(PrintStream ps) {
for (String s : plainStrings) {
ps.println(StringUtils.showComparatorCharacters(s));
}
}
public final int getHigherErrorPosition() {
return higherErrorPosition;
}
public final Collection<String> getErrs() {
return Collections.unmodifiableCollection(errs);
}
}

View File

@ -0,0 +1,42 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 3824 $
*
*/
package net.sourceforge.plantuml;
public interface PSystemFactory {
PSystem getSystem();
void reset();
}

View File

@ -0,0 +1,195 @@
/* ========================================================================
* 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: 4975 $
*
*/
package net.sourceforge.plantuml;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import net.sourceforge.plantuml.command.Command;
import net.sourceforge.plantuml.command.CommandControl;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.PSystemCommandFactory;
import net.sourceforge.plantuml.command.ProtectedCommand;
final public class PSystemSingleBuilder {
private final Iterator<String> it;
private final UmlSource source;
private int nb = 0;
private AbstractPSystem sys;
private boolean hasNext() {
return it.hasNext();
}
private String next() {
nb++;
return it.next();
}
public PSystem getPSystem() {
return sys;
}
public PSystemSingleBuilder(List<String> strings, PSystemFactory systemFactory) throws IOException {
source = new UmlSource(strings);
it = strings.iterator();
if (next().startsWith("@startuml") == false) {
throw new UnsupportedOperationException();
}
if (systemFactory instanceof PSystemCommandFactory) {
executeUmlCommand((PSystemCommandFactory) systemFactory);
} else if (systemFactory instanceof PSystemBasicFactory) {
executeUmlBasic((PSystemBasicFactory) systemFactory);
}
}
private void executeUmlBasic(PSystemBasicFactory systemFactory) throws IOException {
systemFactory.reset();
while (hasNext()) {
final String s = next();
if (s.equals("@enduml")) {
if (source.getSize() == 2) {
sys = buildEmptyError(source);
} else {
sys = (AbstractPSystem) systemFactory.getSystem();
}
if (sys == null) {
return;
}
sys.setSource(source);
return;
}
final boolean ok = systemFactory.executeLine(s);
if (ok == false) {
sys = new PSystemError(source, new ErrorUml(ErrorUmlType.SYNTAX_ERROR, "Syntax Error?", nb - 1));
return;
}
}
sys = (AbstractPSystem) systemFactory.getSystem();
sys.setSource(source);
}
private PSystemError buildEmptyError(UmlSource source) {
final PSystemError result = new PSystemError(source, new ErrorUml(ErrorUmlType.SYNTAX_ERROR,
"Empty description", 1));
return result;
}
private void executeUmlCommand(PSystemCommandFactory systemFactory) throws IOException {
systemFactory.reset();
while (hasNext()) {
final String s = next();
if (s.equals("@enduml")) {
if (source.getSize() == 2) {
sys = buildEmptyError(source);
} else {
sys = (AbstractPSystem) systemFactory.getSystem();
}
if (sys == null) {
return;
}
sys.setSource(source);
return;
}
final CommandControl commandControl = systemFactory.isValid(Arrays.asList(s));
if (commandControl == CommandControl.NOT_OK) {
sys = new PSystemError(source, new ErrorUml(ErrorUmlType.SYNTAX_ERROR, "Syntax Error?", nb - 1));
return;
} else if (commandControl == CommandControl.OK_PARTIAL) {
final boolean ok = manageMultiline(systemFactory, s);
if (ok == false) {
sys = new PSystemError(source, new ErrorUml(ErrorUmlType.EXECUTION_ERROR, "Syntax Error?", nb - 1));
return;
}
} else if (commandControl == CommandControl.OK) {
final Command cmd = new ProtectedCommand(systemFactory.createCommand(Arrays.asList(s)));
final CommandExecutionResult result = cmd.execute(Arrays.asList(s));
if (result.isOk() == false) {
sys = new PSystemError(source, new ErrorUml(ErrorUmlType.EXECUTION_ERROR, result.getError(),
nb - 1));
return;
}
testDeprecated(Arrays.asList(s), cmd);
} else {
assert false;
}
}
sys = (AbstractPSystem) systemFactory.getSystem();
sys.setSource(source);
}
private void testDeprecated(final List<String> lines, final Command cmd) {
if (cmd.isDeprecated(lines)) {
Log.error("The following syntax is deprecated :");
for (String s : lines) {
Log.error(s);
}
final String msg = cmd.getHelpMessageForDeprecated(lines);
if (msg != null) {
Log.error("Use instead :");
Log.error(msg);
}
}
}
private boolean manageMultiline(PSystemCommandFactory systemFactory, final String init) throws IOException {
final List<String> lines = new ArrayList<String>();
lines.add(init);
while (hasNext()) {
final String s = next();
if (s.equals("@enduml")) {
return false;
}
lines.add(s);
final CommandControl commandControl = systemFactory.isValid(lines);
if (commandControl == CommandControl.NOT_OK) {
throw new IllegalStateException();
}
if (commandControl == CommandControl.OK) {
final Command cmd = systemFactory.createCommand(lines);
testDeprecated(lines, cmd);
return cmd.execute(lines).isOk();
}
}
return false;
}
}

View File

@ -0,0 +1,71 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 3835 $
*
*/
package net.sourceforge.plantuml;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
public class Pragma {
private final Map<String, String> values = new LinkedHashMap<String, String>();
public void define(String name, String value) {
values.put(name, value);
if (name.equalsIgnoreCase("graphviz_dot")) {
OptionFlags.getInstance().setDotExecutable(value);
}
}
public boolean isDefine(String name) {
return values.containsKey(name);
}
public void undefine(String name) {
values.remove(name);
}
public String getValue(String name) {
final String result = values.get(name);
if (result == null) {
throw new IllegalArgumentException();
}
return result;
}
protected Set<Map.Entry<String, String>> entrySet() {
return Collections.unmodifiableSet(values.entrySet());
}
}

View File

@ -0,0 +1,178 @@
/* ========================================================================
* 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: 5391 $
*
*/
package net.sourceforge.plantuml;
import java.awt.GraphicsEnvironment;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.util.List;
import javax.swing.UIManager;
import net.sourceforge.plantuml.code.Transcoder;
import net.sourceforge.plantuml.png.MetadataTag;
import net.sourceforge.plantuml.preproc.Defines;
import net.sourceforge.plantuml.swing.MainWindow;
public class Run {
public static void main(String[] argsArray) throws IOException, InterruptedException {
final Option option = new Option(argsArray);
if (OptionFlags.getInstance().isVerbose()) {
Log.info("GraphicsEnvironment.isHeadless() " + GraphicsEnvironment.isHeadless());
}
if (OptionFlags.getInstance().isGui()) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception e) {
}
new MainWindow(option);
} else if (option.isPipe() || option.isSyntax()) {
managePipe(option);
} else {
manageFiles(option);
}
}
private static void managePipe(Option option) throws IOException {
final String charset = option.getCharset();
final BufferedReader br;
if (charset == null) {
br = new BufferedReader(new InputStreamReader(System.in));
} else {
br = new BufferedReader(new InputStreamReader(System.in, charset));
}
managePipe(option, br, System.out);
}
static void managePipe(Option option, final BufferedReader br, final PrintStream ps) throws IOException {
final StringBuilder sb = new StringBuilder();
String s = null;
while ((s = br.readLine()) != null) {
sb.append(s);
sb.append("\n");
}
String source = sb.toString();
if (source.contains("@startuml") == false) {
source = "@startuml\n" + source + "\n@enduml";
}
final SourceStringReader sourceStringReader = new SourceStringReader(new Defines(), source, option.getConfig());
if (option.isSyntax()) {
try {
final PSystem system = sourceStringReader.getBlocks().get(0).getSystem();
if (system instanceof UmlDiagram) {
ps.println(((UmlDiagram) system).getUmlDiagramType().name());
ps.println(system.getDescription());
} else if (system instanceof PSystemError) {
ps.println("ERROR");
final PSystemError sys = (PSystemError) system;
ps.println(sys.getHigherErrorPosition());
for (String er : sys.getErrs()) {
ps.println(er);
}
} else {
ps.println("OTHER");
ps.println(system.getDescription());
}
} catch (InterruptedException e) {
Log.error("InterruptedException " + e);
}
} else if (option.isPipe()) {
final String result = sourceStringReader.generateImage(ps, 0, option.getFileFormat());
}
}
private static void manageFile(File f, Option option) throws IOException, InterruptedException {
if (OptionFlags.getInstance().isMetadata()) {
System.out.println("------------------------");
System.out.println(f);
// new Metadata().readAndDisplayMetadata(f);
System.out.println();
System.out.println(new MetadataTag(f, "plantuml").getData());
System.out.println("------------------------");
} else {
final SourceFileReader sourceFileReader = new SourceFileReader(option.getDefaultDefines(), f, option
.getOutputDir(), option.getConfig(), option.getCharset(), option.getFileFormat());
if (option.isComputeurl()) {
final List<String> urls = sourceFileReader.getEncodedUrl();
for (String s : urls) {
System.out.println(s);
}
} else {
sourceFileReader.getGeneratedImages();
}
}
}
private static void manageFiles(Option option) throws IOException, InterruptedException {
File lockFile = null;
try {
if (OptionFlags.getInstance().isWord()) {
final File dir = new File(option.getResult().get(0));
final File javaIsRunningFile = new File(dir, "javaisrunning.tmp");
javaIsRunningFile.delete();
lockFile = new File(dir, "javaumllock.tmp");
}
processArgs(option);
} finally {
if (lockFile != null) {
lockFile.delete();
}
}
}
private static void processArgs(Option option) throws IOException, InterruptedException {
for (String s : option.getResult()) {
if (option.isDecodeurl()) {
final Transcoder transcoder = new Transcoder();
System.out.println("@startuml");
System.out.println(transcoder.decode(s));
System.out.println("@enduml");
} else {
final FileGroup group = new FileGroup(s, option.getExcludes(), option);
for (File f : group.getFiles()) {
manageFile(f, option);
}
}
}
}
}

View File

@ -0,0 +1,39 @@
/* ========================================================================
* 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: 5401 $
*
*/
package net.sourceforge.plantuml;
public interface Scale {
public double getScale(double width, double height);
}

View File

@ -0,0 +1,47 @@
/* ========================================================================
* 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: 5401 $
*
*/
package net.sourceforge.plantuml;
public class ScaleHeight implements Scale {
private final double maxHeight;
public ScaleHeight(double maxHeight) {
this.maxHeight = maxHeight;
}
public double getScale(double width, double height) {
return maxHeight / height;
}
}

View File

@ -0,0 +1,47 @@
/* ========================================================================
* 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: 5401 $
*
*/
package net.sourceforge.plantuml;
public class ScaleSimple implements Scale {
private final double scale;
public ScaleSimple(double scale) {
this.scale = scale;
}
public double getScale(double width, double height) {
return scale;
}
}

View File

@ -0,0 +1,47 @@
/* ========================================================================
* 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: 5401 $
*
*/
package net.sourceforge.plantuml;
public class ScaleWidth implements Scale {
private final double maxWidth;
public ScaleWidth(double maxWidth) {
this.maxWidth = maxWidth;
}
public double getScale(double width, double height) {
return maxWidth / width;
}
}

View File

@ -0,0 +1,54 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5401 $
*
*/
package net.sourceforge.plantuml;
public class ScaleWidthAndHeight implements Scale {
private final double maxWidth;
private final double maxHeight;
public ScaleWidthAndHeight(double maxWidth, double maxHeight) {
this.maxWidth = maxWidth;
this.maxHeight = maxHeight;
}
public double getScale(double width, double height) {
final double scale1 = maxWidth / width;
final double scale2 = maxHeight / height;
// if (scale1 > 1 && scale2 > 1) {
// return 1;
// }
return Math.min(scale1, scale2);
}
}

View File

@ -0,0 +1,71 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 3883 $
*
*/
package net.sourceforge.plantuml;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import net.sourceforge.plantuml.code.AsciiEncoder;
public class SignatureUtils {
public static String getSignature(String s) {
try {
final AsciiEncoder coder = new AsciiEncoder();
final MessageDigest msgDigest = MessageDigest.getInstance("MD5");
msgDigest.update(s.getBytes("UTF-8"));
final byte[] digest = msgDigest.digest();
return coder.encode(digest);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
throw new IllegalStateException();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
throw new IllegalStateException();
}
}
public static String getSignatureWithoutImgSrc(String s) {
return getSignature(purge(s));
}
public static String purge(String s) {
final String regex = "(?i)\\<img\\s+src=\"(?:[^\"]+[/\\\\])?([^/\\\\\\d.]+)\\d*(\\.\\w+)\"/\\>";
s = s.replaceAll(regex, "<img src=\"$1$2\"/>");
final String regex2 = "(?i)image=\"(?:[^\"]+[/\\\\])?([^/\\\\\\d.]+)\\d*(\\.\\w+)\"";
s = s.replaceAll(regex2, "image=\"$1$2\"");
return s;
}
}

View File

@ -0,0 +1,39 @@
/* ========================================================================
* 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: 3824 $
*
*/
package net.sourceforge.plantuml;
public interface SingleLine {
PSystem getSystemFromSingleLine(String singleLine);
}

View File

@ -0,0 +1,196 @@
/* ========================================================================
* 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: 5403 $
*
*/
package net.sourceforge.plantuml;
import java.awt.Font;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import net.sourceforge.plantuml.graphic.HtmlColor;
public class SkinParam implements ISkinParam {
private final Map<String, String> params = new HashMap<String, String>();
public void setParam(String key, String value) {
params.put(key.toLowerCase().trim(), value.trim());
}
public HtmlColor getBackgroundColor() {
final HtmlColor result = getHtmlColor(ColorParam.background);
if (result == null) {
return new HtmlColor("white");
}
return result;
}
public String getValue(String key) {
return params.get(key.toLowerCase().replaceAll("_", ""));
}
static String humanName(String key) {
final StringBuilder sb = new StringBuilder();
boolean upper = true;
for (int i = 0; i < key.length(); i++) {
final char c = key.charAt(i);
if (c == '_') {
upper = true;
} else {
sb.append(upper ? Character.toUpperCase(c) : Character.toLowerCase(c));
upper = false;
}
}
return sb.toString();
}
public HtmlColor getHtmlColor(ColorParam param) {
final String value = getValue(param.name() + "color");
if (value == null || HtmlColor.isValid(value) == false) {
return null;
}
return new HtmlColor(value);
}
public int getFontSize(FontParam param) {
String value = getValue(param.name() + "fontsize");
if (value == null || value.matches("\\d+") == false) {
value = getValue("defaultfontsize");
}
if (value == null || value.matches("\\d+") == false) {
return param.getDefaultSize();
}
return Integer.parseInt(value);
}
public String getFontFamily(FontParam param) {
// Times, Helvetica, Courier or Symbol
String value = getValue(param.name() + "fontname");
if (value != null) {
return value;
}
if (param != FontParam.CIRCLED_CHARACTER) {
value = getValue("defaultfontname");
if (value != null) {
return value;
}
}
return param.getDefaultFamily();
}
public HtmlColor getFontHtmlColor(FontParam param) {
String value = getValue(param.name() + "fontcolor");
if (value == null) {
value = getValue("defaultfontcolor");
}
if (value == null) {
value = param.getDefaultColor();
}
return new HtmlColor(value);
}
public int getFontStyle(FontParam param) {
String value = getValue(param.name() + "fontstyle");
if (value == null) {
value = getValue("defaultfontstyle");
}
if (value == null) {
return param.getDefaultFontStyle();
}
int result = Font.PLAIN;
if (value.toLowerCase().contains("bold")) {
result = result | Font.BOLD;
}
if (value.toLowerCase().contains("italic")) {
result = result | Font.ITALIC;
}
return result;
}
public Font getFont(FontParam fontParam) {
return new Font(getFontFamily(fontParam), getFontStyle(fontParam), getFontSize(fontParam));
}
public int getCircledCharacterRadius() {
final String value = getValue("circledcharacterradius");
if (value != null && value.matches("\\d+")) {
return Integer.parseInt(value);
}
// return 11;
// System.err.println("SIZE1="+getFontSize(FontParam.CIRCLED_CHARACTER));
// System.err.println("SIZE1="+getFontSize(FontParam.CIRCLED_CHARACTER)/3);
return getFontSize(FontParam.CIRCLED_CHARACTER) / 3 + 6;
}
public boolean isClassCollapse() {
return true;
}
public int classAttributeIconSize() {
final String value = getValue("classAttributeIconSize");
if (value != null && value.matches("\\d+")) {
return Integer.parseInt(value);
}
return 10;
}
public boolean isMonochrome() {
return "true".equals(getValue("monochrome"));
}
public static Collection<String> getPossibleValues() {
final Set<String> result = new TreeSet<String>();
result.add("Monochrome");
result.add("BackgroundColor");
result.add("CircledCharacterRadius");
result.add("ClassAttributeIconSize");
result.add("DefaultFontName");
result.add("DefaultFontStyle");
result.add("DefaultFontSize");
result.add("DefaultFontColor");
for (FontParam p : EnumSet.allOf(FontParam.class)) {
final String h = humanName(p.name());
result.add(h + "FontStyle");
result.add(h + "FontName");
result.add(h + "FontSize");
result.add(h + "FontColor");
}
return Collections.unmodifiableSet(result);
}
}

View File

@ -0,0 +1,110 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4246 $
*
*/
package net.sourceforge.plantuml;
import java.awt.Font;
import net.sourceforge.plantuml.graphic.HtmlColor;
public class SkinParamBackcolored implements ISkinParam {
final private ISkinParam skinParam;
final private HtmlColor backColorElement;
final private HtmlColor backColorGeneral;
public SkinParamBackcolored(ISkinParam skinParam, HtmlColor backColorElement) {
this(skinParam, backColorElement, null);
}
public SkinParamBackcolored(ISkinParam skinParam,
HtmlColor backColorElement, HtmlColor backColorGeneral) {
this.skinParam = skinParam;
this.backColorElement = backColorElement;
this.backColorGeneral = backColorGeneral;
}
public HtmlColor getBackgroundColor() {
if (backColorGeneral != null) {
return backColorGeneral;
}
return skinParam.getBackgroundColor();
}
public int getCircledCharacterRadius() {
return skinParam.getCircledCharacterRadius();
}
public Font getFont(FontParam fontParam) {
return skinParam.getFont(fontParam);
}
public String getFontFamily(FontParam param) {
return skinParam.getFontFamily(param);
}
public HtmlColor getFontHtmlColor(FontParam param) {
return skinParam.getFontHtmlColor(param);
}
public int getFontSize(FontParam param) {
return skinParam.getFontSize(param);
}
public int getFontStyle(FontParam param) {
return skinParam.getFontStyle(param);
}
public HtmlColor getHtmlColor(ColorParam param) {
if (param.isBackground() && backColorElement != null) {
return backColorElement;
}
return skinParam.getHtmlColor(param);
}
public String getValue(String key) {
return skinParam.getValue(key);
}
public boolean isClassCollapse() {
return skinParam.isClassCollapse();
}
public int classAttributeIconSize() {
return skinParam.classAttributeIconSize();
}
public boolean isMonochrome() {
return skinParam.isMonochrome();
}
}

View File

@ -0,0 +1,151 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4771 $
*
*/
package net.sourceforge.plantuml;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.sourceforge.plantuml.code.Transcoder;
import net.sourceforge.plantuml.preproc.Defines;
public class SourceFileReader {
private final File file;
private final File outputDirectory;
private final BlockUmlBuilder builder;
private FileFormat fileFormat;
public SourceFileReader(File file) throws IOException {
this(file, file.getAbsoluteFile().getParentFile());
}
public SourceFileReader(final File file, File outputDirectory) throws IOException {
this(new Defines(), file, outputDirectory, Collections.<String> emptyList(), null, FileFormat.PNG);
}
public SourceFileReader(final File file, File outputDirectory, FileFormat fileFormat) throws IOException {
this(new Defines(), file, outputDirectory, Collections.<String> emptyList(), null, fileFormat);
}
public SourceFileReader(Defines defines, final File file, File outputDirectory, List<String> config,
String charset, FileFormat fileFormat) throws IOException {
this.file = file;
this.fileFormat = fileFormat;
if (file.exists() == false) {
throw new IllegalArgumentException();
}
FileSystem.getInstance().setCurrentDir(file.getAbsoluteFile().getParentFile());
if (outputDirectory == null) {
outputDirectory = file.getAbsoluteFile().getParentFile();
} else if (outputDirectory.isAbsolute() == false) {
outputDirectory = FileSystem.getInstance().getFile(outputDirectory.getName());
}
if (outputDirectory.exists() == false) {
outputDirectory.mkdirs();
}
this.outputDirectory = outputDirectory;
builder = new BlockUmlBuilder(config, defines, getReader(charset));
}
public List<GeneratedImage> getGeneratedImages() throws IOException, InterruptedException {
Log.info("Reading file: " + file);
int cpt = 0;
final List<GeneratedImage> result = new ArrayList<GeneratedImage>();
for (BlockUml blockUml : builder.getBlockUmls()) {
String newName = blockUml.getFilename();
if (newName == null) {
newName = changeName(file.getName(), cpt++, fileFormat);
}
final File suggested = new File(outputDirectory, newName);
suggested.getParentFile().mkdirs();
for (File f : blockUml.getSystem().createFiles(suggested, fileFormat)) {
final String desc = "[" + file.getName() + "] " + blockUml.getSystem().getDescription();
final GeneratedImage generatedImage = new GeneratedImage(f, desc);
result.add(generatedImage);
}
}
Log.info("Number of image(s): " + result.size());
return Collections.unmodifiableList(result);
}
public List<String> getEncodedUrl() throws IOException, InterruptedException {
final List<String> result = new ArrayList<String>();
final Transcoder transcoder = new Transcoder();
for (BlockUml blockUml : builder.getBlockUmls()) {
final String source = blockUml.getSystem().getSource().getPlainString();
final String encoded = transcoder.encode(source);
result.add(encoded);
}
return Collections.unmodifiableList(result);
}
static String changeName(String name, int cpt, FileFormat fileFormat) {
if (cpt == 0) {
return name.replaceAll("\\.\\w+$", fileFormat.getFileSuffix());
}
return name.replaceAll("\\.\\w+$", "_" + String.format("%03d", cpt) + fileFormat.getFileSuffix());
}
private Reader getReader(String charset) throws FileNotFoundException, UnsupportedEncodingException {
if (charset == null) {
Log.info("Using default charset");
return new InputStreamReader(new FileInputStream(file));
}
Log.info("Using charset " + charset);
return new InputStreamReader(new FileInputStream(file), charset);
}
public final void setFileFormat(FileFormat fileFormat) {
this.fileFormat = fileFormat;
}
}

View File

@ -0,0 +1,103 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4041 $
*
*/
package net.sourceforge.plantuml;
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringReader;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import net.sourceforge.plantuml.graphic.GraphicStrings;
import net.sourceforge.plantuml.preproc.Defines;
public class SourceStringReader {
final private List<BlockUml> blocks;
public SourceStringReader(String source) {
this(new Defines(), source, Collections.<String> emptyList());
}
public SourceStringReader(Defines defines, String source, List<String> config) {
try {
final BlockUmlBuilder builder = new BlockUmlBuilder(config, defines, new StringReader(source));
this.blocks = builder.getBlockUmls();
} catch (IOException e) {
throw new IllegalStateException();
}
}
public String generateImage(OutputStream os) throws IOException {
return generateImage(os, 0);
}
public String generateImage(OutputStream os, FileFormat fileFormat) throws IOException {
return generateImage(os, 0, fileFormat);
}
public String generateImage(OutputStream os, int numImage) throws IOException {
return generateImage(os, numImage, FileFormat.PNG);
}
public String generateImage(OutputStream os, int numImage, FileFormat fileFormat) throws IOException {
if (blocks.size() == 0) {
final GraphicStrings error = new GraphicStrings(Arrays.asList("No @startuml found"));
error.writeImage(os, fileFormat);
return null;
}
try {
for (BlockUml b : blocks) {
final PSystem system = b.getSystem();
final int nbInSystem = system.getNbImages();
if (numImage < nbInSystem) {
system.createFile(os, numImage, fileFormat);
return system.getDescription();
}
numImage -= nbInSystem;
}
} catch (InterruptedException e) {
return null;
}
Log.error("numImage is too big = ");
return null;
}
public final List<BlockUml> getBlocks() {
return Collections.unmodifiableList(blocks);
}
}

View File

@ -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: 3835 $
*
*/
package net.sourceforge.plantuml;
import net.sourceforge.plantuml.graphic.HtmlColor;
public interface SpecificBackcolorable {
public HtmlColor getSpecificBackColor();
public void setSpecificBackcolor(String specificBackcolor);
}

View File

@ -0,0 +1,263 @@
/* ========================================================================
* 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: 5427 $
*
*/
package net.sourceforge.plantuml;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class StringUtils {
static private final Pattern multiLines = Pattern.compile("((?:\\\\\\\\|[^\\\\])+)(\\\\n)?");
public static String getPlateformDependentAbsolutePath(File file) {
return file.getAbsolutePath();
}
public static List<String> getWithNewlines(String s) {
if (s == null) {
throw new IllegalArgumentException();
}
final Matcher matcher = multiLines.matcher(s);
final List<String> strings = new ArrayList<String>();
while (matcher.find()) {
strings.add(matcher.group(1).replace("\\\\", "\\"));
}
return strings;
}
public static String getMergedLines(List<String> strings) {
final StringBuilder sb = new StringBuilder();
for (int i = 0; i < strings.size(); i++) {
sb.append(strings.get(i));
if (i < strings.size() - 1) {
sb.append("\\n");
}
}
return sb.toString();
}
final static public List<String> getSplit(Pattern pattern, String line) {
final Matcher m = pattern.matcher(line);
if (m.find() == false) {
return null;
}
final List<String> result = new ArrayList<String>();
for (int i = 1; i <= m.groupCount(); i++) {
result.add(m.group(i));
}
return result;
}
public static boolean isNotEmpty(String input) {
return input != null && input.trim().length() > 0;
}
public static boolean isEmpty(String input) {
return input == null || input.trim().length() == 0;
}
public static String manageHtml(String s) {
s = s.replace("<", "&lt;");
s = s.replace(">", "&gt;");
return s;
}
public static String manageArrowForSequence(String s) {
s = s.replace('=', '-');
return s;
}
public static String manageArrowForCuca(String s) {
final Direction dir = getArrowDirection(s);
s = s.replace('=', '-');
s = s.replaceAll("\\w*", "");
if (dir == Direction.LEFT || dir == Direction.RIGHT) {
s = s.replaceAll("-+", "-");
}
if (s.length() == 2 && (dir == Direction.UP || dir == Direction.DOWN)) {
s = s.replaceFirst("-", "--");
}
return s;
}
public static String manageQueueForCuca(String s) {
final Direction dir = getQueueDirection(s);
s = s.replace('=', '-');
s = s.replaceAll("\\w*", "");
if (dir == Direction.LEFT || dir == Direction.RIGHT) {
s = s.replaceAll("-+", "-");
}
if (s.length() == 1 && (dir == Direction.UP || dir == Direction.DOWN)) {
s = s.replaceFirst("-", "--");
}
return s;
}
public static Direction getArrowDirection(String s) {
if (s.endsWith(">")) {
return getQueueDirection(s.substring(0, s.length() - 1));
}
if (s.startsWith("<")) {
if (s.length() == 2) {
return Direction.LEFT;
}
return Direction.UP;
}
throw new IllegalArgumentException(s);
}
public static Direction getQueueDirection(String s) {
if (s.indexOf('<') != -1 || s.indexOf('>') != -1) {
throw new IllegalArgumentException(s);
}
s = s.toLowerCase();
if (s.contains("left")) {
return Direction.LEFT;
}
if (s.contains("right")) {
return Direction.RIGHT;
}
if (s.contains("up")) {
return Direction.UP;
}
if (s.contains("down")) {
return Direction.DOWN;
}
if (s.contains("l")) {
return Direction.LEFT;
}
if (s.contains("r")) {
return Direction.RIGHT;
}
if (s.contains("u")) {
return Direction.UP;
}
if (s.contains("d")) {
return Direction.DOWN;
}
if (s.length() == 1) {
return Direction.RIGHT;
}
return Direction.DOWN;
}
public static String eventuallyRemoveStartingAndEndingDoubleQuote(String s) {
if (s.startsWith("\"") && s.endsWith("\"")) {
return s.substring(1, s.length() - 1);
}
if (s.startsWith("(") && s.endsWith(")")) {
return s.substring(1, s.length() - 1);
}
if (s.startsWith("[") && s.endsWith("]")) {
return s.substring(1, s.length() - 1);
}
if (s.startsWith(":") && s.endsWith(":")) {
return s.substring(1, s.length() - 1);
}
return s;
}
// private static String cleanLineFromSource(String s) {
// if (s.startsWith("\uFEFF")) {
// s = s.substring(1);
// }
// if (s.startsWith("~~")) {
// s = s.substring("~~".length());
// }
// // if (s.startsWith(" * ")) {
// // s = s.substring(" * ".length());
// // }
// s = s.replaceFirst("^\\s+\\* ", "");
// if (s.equals(" *")) {
// s = "";
// }
// s = s.trim();
// while (s.startsWith(" ") || s.startsWith("/") || s.startsWith("\t") ||
// s.startsWith("%") || s.startsWith("/*")) {
// if (s.startsWith("/*")) {
// s = s.substring(2).trim();
// } else {
// s = s.substring(1).trim();
// }
// }
// return s;
// }
public static boolean isCJK(char c) {
final Character.UnicodeBlock block = Character.UnicodeBlock.of(c);
System.err.println(block);
return false;
}
public static char hiddenLesserThan() {
return '\u0005';
}
public static char hiddenBiggerThan() {
return '\u0006';
}
public static String hideComparatorCharacters(String s) {
s = s.replace('<', hiddenLesserThan());
s = s.replace('>', hiddenBiggerThan());
return s;
}
public static String showComparatorCharacters(String s) {
s = s.replace(hiddenLesserThan(), '<');
s = s.replace(hiddenBiggerThan(), '>');
return s;
}
public static int getWidth(List<? extends CharSequence> stringsToDisplay) {
int result = 1;
for (CharSequence s : stringsToDisplay) {
if (result < s.length()) {
result = s.length();
}
}
return result;
}
public static int getHeight(List<? extends CharSequence> stringsToDisplay) {
return stringsToDisplay.size();
}
}

View File

@ -0,0 +1,134 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5503 $
*
*/
package net.sourceforge.plantuml;
import java.util.List;
import net.sourceforge.plantuml.graphic.HorizontalAlignement;
public abstract class UmlDiagram extends AbstractPSystem implements PSystem {
private boolean rotation;
private int minwidth = Integer.MAX_VALUE;
private List<String> title;
private List<String> header;
private List<String> footer;
private HorizontalAlignement headerAlignement = HorizontalAlignement.RIGHT;
private HorizontalAlignement footerAlignement = HorizontalAlignement.CENTER;
private final Pragma pragma = new Pragma();
private Scale scale;
private final SkinParam skinParam = new SkinParam();
final public void setTitle(List<String> strings) {
this.title = strings;
}
final public List<String> getTitle() {
return title;
}
final public int getMinwidth() {
return minwidth;
}
final public void setMinwidth(int minwidth) {
this.minwidth = minwidth;
}
final public boolean isRotation() {
return rotation;
}
final public void setRotation(boolean rotation) {
this.rotation = rotation;
}
public final ISkinParam getSkinParam() {
return skinParam;
}
public void setParam(String key, String value) {
skinParam.setParam(key.toLowerCase(), value);
}
public final List<String> getHeader() {
return header;
}
public final void setHeader(List<String> header) {
this.header = header;
}
public final List<String> getFooter() {
return footer;
}
public final void setFooter(List<String> footer) {
this.footer = footer;
}
public final HorizontalAlignement getHeaderAlignement() {
return headerAlignement;
}
public final void setHeaderAlignement(HorizontalAlignement headerAlignement) {
this.headerAlignement = headerAlignement;
}
public final HorizontalAlignement getFooterAlignement() {
return footerAlignement;
}
public final void setFooterAlignement(HorizontalAlignement footerAlignement) {
this.footerAlignement = footerAlignement;
}
abstract public UmlDiagramType getUmlDiagramType();
public Pragma getPragma() {
return pragma;
}
final public void setScale(Scale scale) {
this.scale = scale;
}
final public Scale getScale() {
return scale;
}
}

View File

@ -0,0 +1,38 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4539 $
*
*/
package net.sourceforge.plantuml;
public enum UmlDiagramType {
SEQUENCE, STATE, CLASS, OBJECT, ACTIVITY, USECASE, COMPONENT, COMPOSITE
}

View File

@ -0,0 +1,83 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4768 $
*
*/
package net.sourceforge.plantuml;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
final public class UmlSource {
final private List<String> source = new ArrayList<String>();
@Deprecated
public UmlSource(UmlSource start) {
this.source.addAll(start.source);
}
public UmlSource(List<String> source) {
this.source.addAll(source);
}
@Deprecated
public UmlSource() {
}
public Iterator<String> iterator() {
return source.iterator();
}
@Deprecated
public void append(String s) {
source.add(s);
}
public String getPlainString() {
final StringBuilder sb = new StringBuilder();
for (String s : source) {
sb.append(s);
sb.append('\n');
}
return sb.toString();
}
public String getLine(int n) {
return source.get(n);
}
public int getSize() {
return source.size();
}
}

View File

@ -0,0 +1,48 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 3823 $
*
*/
package net.sourceforge.plantuml;
public class UniqueSequence {
private static int cpt = 1;
public static void reset() {
cpt = 1;
}
public static int getValue() {
return cpt++;
}
}

View File

@ -0,0 +1,192 @@
/* ========================================================================
* 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: 5223 $
*
*/
package net.sourceforge.plantuml.activitydiagram;
import java.util.Arrays;
import java.util.List;
import net.sourceforge.plantuml.Direction;
import net.sourceforge.plantuml.UmlDiagramType;
import net.sourceforge.plantuml.UniqueSequence;
import net.sourceforge.plantuml.cucadiagram.CucaDiagram;
import net.sourceforge.plantuml.cucadiagram.Entity;
import net.sourceforge.plantuml.cucadiagram.EntityType;
import net.sourceforge.plantuml.cucadiagram.Group;
import net.sourceforge.plantuml.cucadiagram.GroupType;
import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.Link;
public class ActivityDiagram extends CucaDiagram {
private IEntity lastEntityConsulted;
private IEntity lastEntityBrancheConsulted;
private ConditionalContext currentContext;
private boolean acceptOldSyntaxForBranch = true;
private String getAutoBranch() {
return "#" + UniqueSequence.getValue();
}
public IEntity getOrCreate(String code, String display, EntityType type) {
final IEntity result;
if (entityExist(code)) {
result = super.getOrCreateEntity(code, type);
if (result.getType() != type) {
throw new IllegalArgumentException("Already known: " + code);
// return null;
}
} else {
result = createEntity(code, display, type);
}
updateLasts(result);
return result;
}
public void startIf() {
final IEntity br = createEntity(getAutoBranch(), "", EntityType.BRANCH);
currentContext = new ConditionalContext(currentContext, br, Direction.DOWN);
}
public void endif() {
currentContext = currentContext.getParent();
}
public IEntity getStart() {
return getOrCreate("start", "start", EntityType.CIRCLE_START);
}
public IEntity getEnd() {
return getOrCreate("end", "end", EntityType.CIRCLE_END);
}
final public Link getLastActivityLink() {
final List<Link> links = getLinks();
for (int i = links.size() - 1; i >= 0; i--) {
final Link link = links.get(i);
if (link.getEntity1().getType() != EntityType.NOTE && link.getEntity2().getType() != EntityType.NOTE) {
return link;
}
}
return null;
}
private void updateLasts(final IEntity result) {
if (result.getType() == EntityType.NOTE) {
return;
}
this.lastEntityConsulted = result;
if (result.getType() == EntityType.BRANCH) {
lastEntityBrancheConsulted = result;
}
}
@Override
public Entity createEntity(String code, String display, EntityType type) {
final Entity result = super.createEntity(code, display, type);
updateLasts(result);
return result;
}
public Entity createNote(String code, String display) {
return super.createEntity(code, display, EntityType.NOTE);
}
final protected List<String> getDotStrings() {
return Arrays.asList("nodesep=.20;", "ranksep=0.4;", "edge [fontsize=11,labelfontsize=11];",
"node [fontsize=11];");
}
public String getDescription() {
return "(" + entities().size() + " activities)";
}
public IEntity getLastEntityConsulted() {
return lastEntityConsulted;
}
@Deprecated
public IEntity getLastEntityBrancheConsulted() {
return lastEntityBrancheConsulted;
}
@Override
public UmlDiagramType getUmlDiagramType() {
return UmlDiagramType.ACTIVITY;
}
public final ConditionalContext getCurrentContext() {
return currentContext;
}
public final void setLastEntityConsulted(IEntity lastEntityConsulted) {
this.lastEntityConsulted = lastEntityConsulted;
}
public final boolean isAcceptOldSyntaxForBranch() {
return acceptOldSyntaxForBranch;
}
public final void setAcceptOldSyntaxForBranch(boolean acceptOldSyntaxForBranch) {
this.acceptOldSyntaxForBranch = acceptOldSyntaxForBranch;
}
public IEntity createInnerActivity() {
// System.err.println("createInnerActivity A");
final String code = "##" + UniqueSequence.getValue();
final Group g = getOrCreateGroup(code, code, null, GroupType.INNER_ACTIVITY, getCurrentGroup());
// g.setRankdir(Rankdir.LEFT_TO_RIGHT);
lastEntityConsulted = null;
lastEntityBrancheConsulted = null;
// System.err.println("createInnerActivity B "+getCurrentGroup());
return g.getEntityCluster();
}
public void concurrentActivity(String name) {
// System.err.println("concurrentActivity A name=" + name+" "+getCurrentGroup());
if (getCurrentGroup().getType() == GroupType.CONCURRENT_ACTIVITY) {
// getCurrentGroup().setRankdir(Rankdir.LEFT_TO_RIGHT);
endGroup();
System.err.println("endgroup");
}
// System.err.println("concurrentActivity A name=" + name+" "+getCurrentGroup());
final String code = "##" + UniqueSequence.getValue();
if (getCurrentGroup().getType() != GroupType.INNER_ACTIVITY) {
throw new IllegalStateException("type=" + getCurrentGroup().getType());
}
final Group g = getOrCreateGroup(code, "code", null, GroupType.CONCURRENT_ACTIVITY, getCurrentGroup());
lastEntityConsulted = null;
lastEntityBrancheConsulted = null;
}
}

View File

@ -0,0 +1,81 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5190 $
*
*/
package net.sourceforge.plantuml.activitydiagram;
import net.sourceforge.plantuml.activitydiagram.command.CommandElse;
import net.sourceforge.plantuml.activitydiagram.command.CommandEndPartition;
import net.sourceforge.plantuml.activitydiagram.command.CommandEndif;
import net.sourceforge.plantuml.activitydiagram.command.CommandIf;
import net.sourceforge.plantuml.activitydiagram.command.CommandInnerConcurrent;
import net.sourceforge.plantuml.activitydiagram.command.CommandLinkActivity2;
import net.sourceforge.plantuml.activitydiagram.command.CommandLinkLongActivity2;
import net.sourceforge.plantuml.activitydiagram.command.CommandMultilinesNoteActivity;
import net.sourceforge.plantuml.activitydiagram.command.CommandMultilinesNoteActivityLink;
import net.sourceforge.plantuml.activitydiagram.command.CommandNoteActivity;
import net.sourceforge.plantuml.activitydiagram.command.CommandNoteOnActivityLink;
import net.sourceforge.plantuml.activitydiagram.command.CommandPartition;
import net.sourceforge.plantuml.command.AbstractUmlSystemCommandFactory;
public class ActivityDiagramFactory extends AbstractUmlSystemCommandFactory {
private ActivityDiagram system;
public ActivityDiagram getSystem() {
return system;
}
@Override
protected void initCommands() {
system = new ActivityDiagram();
addCommonCommands(system);
addCommand(new CommandLinkActivity2(system));
addCommand(new CommandPartition(system));
addCommand(new CommandEndPartition(system));
addCommand(new CommandLinkLongActivity2(system));
addCommand(new CommandNoteActivity(system));
addCommand(new CommandMultilinesNoteActivity(system));
addCommand(new CommandNoteOnActivityLink(system));
addCommand(new CommandMultilinesNoteActivityLink(system));
addCommand(new CommandIf(system));
addCommand(new CommandElse(system));
addCommand(new CommandEndif(system));
addCommand(new CommandInnerConcurrent(system));
}
}

View File

@ -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: 3828 $
*
*/
package net.sourceforge.plantuml.activitydiagram;
import net.sourceforge.plantuml.Direction;
import net.sourceforge.plantuml.cucadiagram.EntityType;
import net.sourceforge.plantuml.cucadiagram.IEntity;
public class ConditionalContext {
private final IEntity branch;
private final Direction direction;
private final ConditionalContext parent;
public ConditionalContext(ConditionalContext parent, IEntity branch, Direction direction) {
if (branch.getType() != EntityType.BRANCH) {
throw new IllegalArgumentException();
}
this.branch = branch;
this.direction = direction;
this.parent = parent;
}
public Direction getDirection() {
return direction;
}
public final ConditionalContext getParent() {
return parent;
}
public final IEntity getBranch() {
return branch;
}
}

View File

@ -0,0 +1,62 @@
/* ========================================================================
* 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.activitydiagram.command;
import java.util.List;
import net.sourceforge.plantuml.activitydiagram.ActivityDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand;
import net.sourceforge.plantuml.cucadiagram.IEntity;
public class CommandElse extends SingleLineCommand<ActivityDiagram> {
public CommandElse(ActivityDiagram diagram) {
super(diagram, "(?i)^else$");
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
if (getSystem().getLastEntityConsulted() == null) {
return CommandExecutionResult.error("No if for this else");
}
final IEntity branch = getSystem().getCurrentContext().getBranch();
getSystem().setLastEntityConsulted(branch);
getSystem().setAcceptOldSyntaxForBranch(false);
return CommandExecutionResult.ok();
}
}

View File

@ -0,0 +1,59 @@
/* ========================================================================
* 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: 5048 $
*
*/
package net.sourceforge.plantuml.activitydiagram.command;
import java.util.List;
import net.sourceforge.plantuml.activitydiagram.ActivityDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand;
import net.sourceforge.plantuml.cucadiagram.Group;
public class CommandEndPartition extends SingleLineCommand<ActivityDiagram> {
public CommandEndPartition(ActivityDiagram diagram) {
super(diagram, "(?i)^(end ?partition|\\})$");
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
final Group currentPackage = getSystem().getCurrentGroup();
if (currentPackage == null) {
return CommandExecutionResult.error("No partition defined");
}
getSystem().endGroup();
return CommandExecutionResult.ok();
}
}

View File

@ -0,0 +1,59 @@
/* ========================================================================
* 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.activitydiagram.command;
import java.util.List;
import net.sourceforge.plantuml.activitydiagram.ActivityDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand;
public class CommandEndif extends SingleLineCommand<ActivityDiagram> {
public CommandEndif(ActivityDiagram diagram) {
super(diagram, "(?i)^endif$");
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
if (getSystem().getLastEntityConsulted() == null) {
return CommandExecutionResult.error("No if for this endif");
}
getSystem().endif();
getSystem().setAcceptOldSyntaxForBranch(false);
return CommandExecutionResult.ok();
}
}

View File

@ -0,0 +1,88 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4762 $
*
*/
package net.sourceforge.plantuml.activitydiagram.command;
import java.util.List;
import net.sourceforge.plantuml.Direction;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.activitydiagram.ActivityDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand;
import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.LinkDecor;
import net.sourceforge.plantuml.cucadiagram.LinkType;
public class CommandIf extends SingleLineCommand<ActivityDiagram> {
public CommandIf(ActivityDiagram diagram) {
super(
diagram,
"(?i)^(?:(\\(\\*\\))|([\\p{L}0-9_.]+)|(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)|\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?)?"
+ "\\s*([=-]+(?:left|right|up|down|le?|ri?|up?|do?)?[=-]*\\>)?\\s*(?:\\[([^\\]*]+[^\\]]*)\\])?\\s*if\\s*\"([^\"]*)\"\\s*then$");
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
final IEntity entity1 = CommandLinkActivity2.getEntity(getSystem(), arg, true);
getSystem().startIf();
int lenght = 2;
if (arg.get(5) != null) {
final String arrow = StringUtils.manageArrowForCuca(arg.get(5));
lenght = arrow.length() - 1;
}
final IEntity branch = getSystem().getCurrentContext().getBranch();
Link link = new Link(entity1, branch, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), arg.get(6), lenght, null,
arg.get(7), getSystem().getLabeldistance(), getSystem().getLabelangle());
if (arg.get(5) != null) {
final Direction direction = StringUtils.getArrowDirection(arg.get(5));
if (direction == Direction.LEFT || direction == Direction.UP) {
link = link.getInv();
}
}
getSystem().addLink(link);
getSystem().setAcceptOldSyntaxForBranch(false);
return CommandExecutionResult.ok();
}
}

View File

@ -0,0 +1,58 @@
/* ========================================================================
* 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.activitydiagram.command;
import java.util.List;
import net.sourceforge.plantuml.activitydiagram.ActivityDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand;
public class CommandInnerConcurrent extends SingleLineCommand<ActivityDiagram> {
public CommandInnerConcurrent(ActivityDiagram diagram) {
super(diagram, "(?i)^--\\s*(.*)$");
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
if (getSystem().getCurrentGroup() == null) {
return CommandExecutionResult.error("No inner activity");
}
getSystem().concurrentActivity(arg.get(0));
return CommandExecutionResult.ok();
}
}

View File

@ -0,0 +1,125 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5024 $
*
*/
package net.sourceforge.plantuml.activitydiagram.command;
import java.util.List;
import net.sourceforge.plantuml.Direction;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.activitydiagram.ActivityDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand;
import net.sourceforge.plantuml.cucadiagram.EntityType;
import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.LinkDecor;
import net.sourceforge.plantuml.cucadiagram.LinkType;
public class CommandLinkActivity2 extends SingleLineCommand<ActivityDiagram> {
public CommandLinkActivity2(ActivityDiagram diagram) {
super(
diagram,
"(?i)^(?:(\\(\\*\\))|([\\p{L}0-9_.]+)|(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)|\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?)?"
+ "\\s*([=-]+(?:left|right|up|down|le?|ri?|up?|do?)?[=-]*\\>)\\s*(?:\\[([^\\]*]+[^\\]]*)\\])?\\s*"
+ "(?:(\\(\\*\\)|\\{)|([\\p{L}0-9_.]+)|(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)|\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?)$");
}
@Override
protected void actionIfCommandValid() {
getSystem().setAcceptOldSyntaxForBranch(false);
}
static IEntity getEntity(ActivityDiagram system, List<String> arg, final boolean start) {
if ("{".equals(arg.get(0))) {
return system.createInnerActivity();
}
if ("(*)".equals(arg.get(0))) {
if (start) {
return system.getStart();
}
return system.getEnd();
}
if (arg.get(1) != null) {
return system.getOrCreate(arg.get(1), arg.get(1), EntityType.ACTIVITY);
}
if (arg.get(2) != null) {
return system.getOrCreate(arg.get(2), arg.get(2), EntityType.SYNCHRO_BAR);
}
if (arg.get(3) != null) {
final String code = arg.get(4) == null ? arg.get(3) : arg.get(4);
return system.getOrCreate(code, arg.get(3), EntityType.ACTIVITY);
}
if (start && arg.get(0) == null && arg.get(1) == null && arg.get(2) == null && arg.get(3) == null
&& arg.get(4) == null) {
return system.getLastEntityConsulted();
}
throw new UnsupportedOperationException();
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
final IEntity entity1 = getEntity(getSystem(), arg, true);
final IEntity entity2 = getEntity(getSystem(), arg.subList(7, 12), false);
final String linkLabel = arg.get(6);
final String arrow = StringUtils.manageArrowForCuca(arg.get(5));
final int lenght = arrow.length() - 1;
Link link = new Link(entity1, entity2, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), linkLabel, lenght);
final Direction direction = StringUtils.getArrowDirection(arg.get(5));
if (direction == Direction.LEFT || direction == Direction.UP) {
link = link.getInv();
}
getSystem().addLink(link);
return CommandExecutionResult.ok();
}
static EntityType getTypeFromString(String type, final EntityType circle) {
if (type == null) {
return EntityType.ACTIVITY;
}
if (type.equals("*")) {
return circle;
}
if (type.startsWith("=")) {
return EntityType.SYNCHRO_BAR;
}
throw new IllegalArgumentException();
}
}

View File

@ -0,0 +1,116 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5031 $
*
*/
package net.sourceforge.plantuml.activitydiagram.command;
import java.util.List;
import net.sourceforge.plantuml.Direction;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.activitydiagram.ActivityDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.CommandMultilines;
import net.sourceforge.plantuml.cucadiagram.Entity;
import net.sourceforge.plantuml.cucadiagram.EntityType;
import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.LinkDecor;
import net.sourceforge.plantuml.cucadiagram.LinkType;
public class CommandLinkLongActivity2 extends CommandMultilines<ActivityDiagram> {
public CommandLinkLongActivity2(final ActivityDiagram diagram) {
super(
diagram,
"(?i)^(?:(\\(\\*\\))|([\\p{L}0-9_.]+)|(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)|\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?)?"
+ "\\s*([=-]+(?:left|right|up|down|le?|ri?|up?|do?)?[=-]*\\>)\\s*(?:\\[([^\\]*]+[^\\]]*)\\])?\\s*\"([^\"]*?)\\s*$",
"(?i)^\\s*([^\"]*)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?$");
}
@Override
protected void actionIfCommandValid() {
getSystem().setAcceptOldSyntaxForBranch(false);
}
public CommandExecutionResult execute(List<String> lines) {
// final IEntity lastEntityConsulted =
// getSystem().getLastEntityConsulted();
final List<String> line0 = StringUtils.getSplit(getStartingPattern(), lines.get(0));
final IEntity entity1 = CommandLinkActivity2.getEntity(getSystem(), line0, true);
final StringBuilder sb = new StringBuilder();
if (StringUtils.isNotEmpty(line0.get(7))) {
sb.append(line0.get(7));
sb.append("\\n");
}
for (int i = 1; i < lines.size() - 1; i++) {
sb.append(lines.get(i));
if (i < lines.size() - 2) {
sb.append("\\n");
}
}
final List<String> lineLast = StringUtils.getSplit(getEnding(), lines.get(lines.size() - 1));
if (StringUtils.isNotEmpty(lineLast.get(0))) {
sb.append("\\n");
sb.append(lineLast.get(0));
}
final String display = sb.toString();
final String code = lineLast.get(1) == null ? display : lineLast.get(1);
final Entity entity2 = getSystem().createEntity(code, display, EntityType.ACTIVITY);
if (entity1 == null || entity2 == null) {
return CommandExecutionResult.error("No such entity");
}
final String arrow = StringUtils.manageArrowForCuca(line0.get(5));
final int lenght = arrow.length() - 1;
final String linkLabel = line0.get(6);
Link link = new Link(entity1, entity2, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), linkLabel, lenght);
final Direction direction = StringUtils.getArrowDirection(line0.get(5));
if (direction == Direction.LEFT || direction == Direction.UP) {
link = link.getInv();
}
getSystem().addLink(link);
return CommandExecutionResult.ok();
}
}

View File

@ -0,0 +1,93 @@
/* ========================================================================
* 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.activitydiagram.command;
import java.util.List;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.UniqueSequence;
import net.sourceforge.plantuml.activitydiagram.ActivityDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.CommandMultilines;
import net.sourceforge.plantuml.command.Position;
import net.sourceforge.plantuml.cucadiagram.Entity;
import net.sourceforge.plantuml.cucadiagram.EntityType;
import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.LinkDecor;
import net.sourceforge.plantuml.cucadiagram.LinkType;
public class CommandMultilinesNoteActivity extends CommandMultilines<ActivityDiagram> {
public CommandMultilinesNoteActivity(final ActivityDiagram system) {
super(system, "(?i)^note\\s+(right|left|top|bottom)$", "(?i)^end ?note$");
}
public final CommandExecutionResult execute(List<String> lines) {
final List<String> line0 = StringUtils.getSplit(getStartingPattern(), lines.get(0));
final String pos = line0.get(0);
IEntity activity = getSystem().getLastEntityConsulted();
if (activity == null) {
activity = getSystem().getStart();
}
final List<String> strings = lines.subList(1, lines.size() - 1);
final String s = StringUtils.getMergedLines(strings);
final Entity note = getSystem().createEntity("GMN" + UniqueSequence.getValue(), s, EntityType.NOTE);
final Link link;
final Position position = Position.valueOf(pos.toUpperCase()).withRankdir(getSystem().getRankdir());
final LinkType type = new LinkType(LinkDecor.NONE, LinkDecor.NONE).getDashed();
if (position == Position.RIGHT) {
link = new Link(activity, note, type, null, 1);
} else if (position == Position.LEFT) {
link = new Link(note, activity, type, null, 1);
} else if (position == Position.BOTTOM) {
link = new Link(activity, note, type, null, 2);
} else if (position == Position.TOP) {
link = new Link(note, activity, type, null, 2);
} else {
throw new IllegalArgumentException();
}
getSystem().addLink(link);
return CommandExecutionResult.ok();
}
}

View File

@ -0,0 +1,63 @@
/* ========================================================================
* 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.activitydiagram.command;
import java.util.List;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.activitydiagram.ActivityDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.CommandMultilines;
import net.sourceforge.plantuml.cucadiagram.Link;
public class CommandMultilinesNoteActivityLink extends CommandMultilines<ActivityDiagram> {
public CommandMultilinesNoteActivityLink(final ActivityDiagram system) {
super(system, "(?i)^note\\s+on\\s+link$", "(?i)^end ?note$");
}
public final CommandExecutionResult execute(List<String> lines) {
final List<String> strings = lines.subList(1, lines.size() - 1);
final String s = StringUtils.getMergedLines(strings);
final Link link = getSystem().getLastActivityLink();
if (link == null) {
return CommandExecutionResult.error("Nothing to note");
}
link.setNote(s);
return CommandExecutionResult.ok();
}
}

View File

@ -0,0 +1,85 @@
/* ========================================================================
* 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.activitydiagram.command;
import java.util.List;
import net.sourceforge.plantuml.UniqueSequence;
import net.sourceforge.plantuml.activitydiagram.ActivityDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.Position;
import net.sourceforge.plantuml.command.SingleLineCommand;
import net.sourceforge.plantuml.cucadiagram.Entity;
import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.LinkDecor;
import net.sourceforge.plantuml.cucadiagram.LinkType;
public class CommandNoteActivity extends SingleLineCommand<ActivityDiagram> {
public CommandNoteActivity(ActivityDiagram diagram) {
super(diagram, "(?i)^note\\s+(right|left|top|bottom)\\s*:\\s*(.*)$");
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
final String pos = arg.get(0);
final Entity note = getSystem().createNote("GN" + UniqueSequence.getValue(), arg.get(1));
IEntity activity = getSystem().getLastEntityConsulted();
if (activity == null) {
activity = getSystem().getStart();
}
final Position position = Position.valueOf(pos.toUpperCase()).withRankdir(getSystem().getRankdir());
final Link link;
final LinkType type = new LinkType(LinkDecor.NONE, LinkDecor.NONE).getDashed();
if (position == Position.RIGHT) {
link = new Link(activity, note, type, null, 1);
} else if (position == Position.LEFT) {
link = new Link(note, activity, type, null, 1);
} else if (position == Position.BOTTOM) {
link = new Link(activity, note, type, null, 2);
} else if (position == Position.TOP) {
link = new Link(note, activity, type, null, 2);
} else {
throw new IllegalArgumentException();
}
getSystem().addLink(link);
return CommandExecutionResult.ok();
}
}

View File

@ -0,0 +1,60 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4762 $
*
*/
package net.sourceforge.plantuml.activitydiagram.command;
import java.util.List;
import net.sourceforge.plantuml.activitydiagram.ActivityDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand;
import net.sourceforge.plantuml.cucadiagram.Link;
public class CommandNoteOnActivityLink extends SingleLineCommand<ActivityDiagram> {
public CommandNoteOnActivityLink(ActivityDiagram diagram) {
super(diagram, "(?i)^note\\s+on\\s+link\\s*:\\s*(.*)$");
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
final Link link = getSystem().getLastActivityLink();
if (link == null) {
return CommandExecutionResult.error("No link defined");
}
link.setNote(arg.get(0));
return CommandExecutionResult.ok();
}
}

View File

@ -0,0 +1,65 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5048 $
*
*/
package net.sourceforge.plantuml.activitydiagram.command;
import java.util.List;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.activitydiagram.ActivityDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand;
import net.sourceforge.plantuml.cucadiagram.Group;
import net.sourceforge.plantuml.cucadiagram.GroupType;
import net.sourceforge.plantuml.graphic.HtmlColor;
public class CommandPartition extends SingleLineCommand<ActivityDiagram> {
public CommandPartition(ActivityDiagram diagram) {
super(diagram, "(?i)^partition\\s+(\"[^\"]+\"|\\S+)\\s*(#[0-9a-fA-F]{6}|#?\\w+)?\\s*\\{?$");
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
final String code = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(0));
final Group currentPackage = getSystem().getCurrentGroup();
final Group p = getSystem().getOrCreateGroup(code, code, null, GroupType.PACKAGE, currentPackage);
p.setBold(true);
final String color = arg.get(1);
if (color != null) {
p.setBackColor(new HtmlColor(color));
}
return CommandExecutionResult.ok();
}
}

View File

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

View File

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

View File

@ -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.applet;
import java.applet.Applet;
import java.awt.Graphics;
import net.sourceforge.plantuml.version.Version;
public class VersionApplet extends Applet {
@Override
public void init() {
super.init();
}
@Override
public void start() {
super.start();
}
@Override
public void paint(Graphics g) {
g.drawString("" + Version.version(), 0, 10);
}
}

View File

@ -0,0 +1,64 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 3826 $
*
*/
package net.sourceforge.plantuml.asciiart;
import java.io.PrintStream;
import java.util.List;
public interface BasicCharArea {
int getWidth();
int getHeight();
void drawChar(char c, int x, int y);
void fillRect(char c, int x, int y, int width, int height);
void drawStringLR(String string, int x, int y);
void drawStringTB(String string, int x, int y);
String getLine(int line);
void print(PrintStream ps);
List<String> getLines();
void drawHLine(char c, int line, int col1, int col2);
void drawHLine(char c, int line, int col1, int col2, char ifFound, char thenUse);
void drawVLine(char c, int col, int line1, int line2);
}

View File

@ -0,0 +1,176 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5178 $
*
*/
package net.sourceforge.plantuml.asciiart;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class BasicCharAreaImpl implements BasicCharArea {
private int charSize1 = 160;
private int charSize2 = 160;
private int width;
private int height;
private char chars[][];
public BasicCharAreaImpl() {
chars = new char[charSize1][charSize2];
for (int i = 0; i < charSize1; i++) {
for (int j = 0; j < charSize2; j++) {
chars[i][j] = ' ';
}
}
}
public final int getWidth() {
return width;
}
public final int getHeight() {
return height;
}
public void drawChar(char c, int x, int y) {
ensurePossible(x, y);
chars[x][y] = c;
if (x >= width) {
width = x + 1;
}
if (y >= height) {
height = y + 1;
}
}
private void ensurePossible(int x, int y) {
int newCharSize1 = charSize1;
int newCharSize2 = charSize2;
while (x >= newCharSize1) {
newCharSize1 *= 2;
}
while (y >= newCharSize2) {
newCharSize2 *= 2;
}
if (newCharSize1 != charSize1 || newCharSize2 != charSize2) {
final char newChars[][] = new char[newCharSize1][newCharSize2];
for (int i = 0; i < newCharSize1; i++) {
for (int j = 0; j < newCharSize2; j++) {
char c = ' ';
if (i < charSize1 && j < charSize2) {
c = chars[i][j];
}
newChars[i][j] = c;
}
}
this.chars = newChars;
this.charSize1 = newCharSize1;
this.charSize2 = newCharSize2;
}
}
public void drawStringLR(String string, int x, int y) {
for (int i = 0; i < string.length(); i++) {
drawChar(string.charAt(i), x + i, y);
}
}
public void drawStringTB(String string, int x, int y) {
for (int i = 0; i < string.length(); i++) {
drawChar(string.charAt(i), x, y + i);
}
}
public String getLine(int line) {
final StringBuilder sb = new StringBuilder(charSize1);
for (int x = 0; x < width; x++) {
sb.append(chars[x][line]);
}
return sb.toString();
}
public void print(PrintStream ps) {
for (String s : getLines()) {
ps.println(s);
}
}
public List<String> getLines() {
final List<String> result = new ArrayList<String>(height);
for (int y = 0; y < height; y++) {
result.add(getLine(y));
}
return Collections.unmodifiableList(result);
}
public void drawHLine(char c, int line, int col1, int col2) {
for (int x = col1; x < col2; x++) {
this.drawChar(c, x, line);
}
}
public void drawHLine(char c, int line, int col1, int col2, char ifFound, char thenUse) {
for (int x = col1; x < col2; x++) {
ensurePossible(x, line);
if (this.chars[x][line] == ifFound) {
this.drawChar(thenUse, x, line);
} else {
this.drawChar(c, x, line);
}
}
}
public void drawVLine(char c, int col, int line1, int line2) {
for (int y = line1; y < line2; y++) {
this.drawChar(c, col, y);
}
}
@Override
public String toString() {
return getLines().toString();
}
public void fillRect(char c, int x, int y, int width, int height) {
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
drawChar(c, x + i, y + j);
}
}
}
}

View File

@ -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: 4169 $
*
*/
package net.sourceforge.plantuml.asciiart;
import java.awt.geom.Dimension2D;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.skin.Component;
import net.sourceforge.plantuml.skin.Context2D;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt;
public class ComponentTextActiveLine implements Component {
private final FileFormat fileFormat;
public ComponentTextActiveLine(FileFormat fileFormat) {
this.fileFormat = fileFormat;
}
public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) {
final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea();
final int width = (int) dimensionToUse.getWidth();
final int height = (int) dimensionToUse.getHeight();
if (fileFormat == FileFormat.UTXT) {
charArea.fillRect(' ', 0, 0, width, height);
charArea.drawBoxSimpleUnicode(0, 0, width, height);
charArea.drawChar('\u2534', width/2, 0);
charArea.drawChar('\u252c', width/2, height-1);
} else {
charArea.fillRect('X', 0, 0, width, height);
charArea.drawBoxSimple(0, 0, width, height);
}
}
public double getPreferredHeight(StringBounder stringBounder) {
return 0;
}
public double getPreferredWidth(StringBounder stringBounder) {
return 3;
}
}

View File

@ -0,0 +1,102 @@
/* ========================================================================
* 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: 4169 $
*
*/
package net.sourceforge.plantuml.asciiart;
import java.awt.geom.Dimension2D;
import java.util.List;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.skin.Component;
import net.sourceforge.plantuml.skin.ComponentType;
import net.sourceforge.plantuml.skin.Context2D;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt;
public class ComponentTextActor implements Component {
private final ComponentType type;
private final List<? extends CharSequence> stringsToDisplay;
private final FileFormat fileFormat;
public ComponentTextActor(ComponentType type, List<? extends CharSequence> stringsToDisplay, FileFormat fileFormat) {
this.type = type;
this.stringsToDisplay = stringsToDisplay;
this.fileFormat = fileFormat;
}
public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) {
final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea();
final int width = (int) dimensionToUse.getWidth();
// final int textWidth = StringUtils.getWidth(stringsToDisplay);
final int height = (int) dimensionToUse.getHeight();
charArea.fillRect(' ', 0, 0, width, height);
final int xman = width / 2 - 1;
if (type == ComponentType.ACTOR_HEAD) {
charArea.drawStringsLR(stringsToDisplay, 1, getStickManHeight());
if (fileFormat == FileFormat.UTXT) {
charArea.drawStickManUnicode(xman, 0);
} else {
charArea.drawStickMan(xman, 0);
}
} else if (type == ComponentType.ACTOR_TAIL) {
charArea.drawStringsLR(stringsToDisplay, 1, 0);
if (fileFormat == FileFormat.UTXT) {
charArea.drawStickManUnicode(xman, 1);
} else {
charArea.drawStickMan(xman, 1);
}
} else {
assert false;
}
}
private int getStickManHeight() {
if (fileFormat == FileFormat.UTXT) {
return UmlCharArea.STICKMAN_UNICODE_HEIGHT;
}
return UmlCharArea.STICKMAN_HEIGHT;
}
public double getPreferredHeight(StringBounder stringBounder) {
return StringUtils.getHeight(stringsToDisplay) + getStickManHeight();
}
public double getPreferredWidth(StringBounder stringBounder) {
return StringUtils.getWidth(stringsToDisplay) + 2;
}
}

View File

@ -0,0 +1,92 @@
/* ========================================================================
* 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: 4169 $
*
*/
package net.sourceforge.plantuml.asciiart;
import java.awt.geom.Dimension2D;
import java.util.List;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.skin.Component;
import net.sourceforge.plantuml.skin.ComponentType;
import net.sourceforge.plantuml.skin.Context2D;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt;
public class ComponentTextArrow implements Component {
private final ComponentType type;
private final List<? extends CharSequence> stringsToDisplay;
private final FileFormat fileFormat;
public ComponentTextArrow(ComponentType type, List<? extends CharSequence> stringsToDisplay, FileFormat fileFormat) {
this.type = type;
this.stringsToDisplay = stringsToDisplay;
this.fileFormat = fileFormat;
}
public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) {
final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea();
final int width = (int) dimensionToUse.getWidth();
final int height = (int) dimensionToUse.getHeight();
final int textWidth = StringUtils.getWidth(stringsToDisplay);
final int yarrow = height - 2;
charArea.drawHLine(fileFormat == FileFormat.UTXT ? '\u2500' : '-', yarrow, 1, width);
if (type == ComponentType.DOTTED_ARROW || type == ComponentType.RETURN_DOTTED_ARROW) {
for (int i = 1; i < width; i += 2) {
charArea.drawChar(' ', i, yarrow);
}
}
if (type == ComponentType.ARROW || type == ComponentType.DOTTED_ARROW) {
charArea.drawChar('>', width - 1, yarrow);
} else if (type == ComponentType.RETURN_ARROW || type == ComponentType.RETURN_DOTTED_ARROW) {
charArea.drawChar('<', 1, yarrow);
} else {
throw new UnsupportedOperationException();
}
charArea.drawStringsLR(stringsToDisplay, (width - textWidth) / 2, 0);
}
public double getPreferredHeight(StringBounder stringBounder) {
return StringUtils.getHeight(stringsToDisplay) + 2;
}
public double getPreferredWidth(StringBounder stringBounder) {
return StringUtils.getWidth(stringsToDisplay) + 2;
}
}

View File

@ -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: 4169 $
*
*/
package net.sourceforge.plantuml.asciiart;
import java.awt.geom.Dimension2D;
import java.util.List;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.skin.Component;
import net.sourceforge.plantuml.skin.ComponentType;
import net.sourceforge.plantuml.skin.Context2D;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt;
public class ComponentTextDivider implements Component {
private final ComponentType type;
private final List<? extends CharSequence> stringsToDisplay;
private final FileFormat fileFormat;
public ComponentTextDivider(ComponentType type, List<? extends CharSequence> stringsToDisplay, FileFormat fileFormat) {
this.type = type;
this.stringsToDisplay = stringsToDisplay;
this.fileFormat = fileFormat;
}
public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) {
final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea();
final int width = (int) dimensionToUse.getWidth();
final int textWidth = StringUtils.getWidth(stringsToDisplay);
// final int height = (int) dimensionToUse.getHeight();
final int textPos = (width - textWidth - 1) / 2;
final String desc = " " + stringsToDisplay.get(0).toString();
if (fileFormat == FileFormat.UTXT) {
charArea.drawHLine('\u2550', 2, 0, width, '\u2502', '\u256a');
charArea.drawStringLR(desc, textPos, 2);
charArea.drawHLine('\u2550', 1, textPos - 1, textPos + desc.length() + 1, '\u2502', '\u2567');
charArea.drawHLine('\u2550', 3, textPos - 1, textPos + desc.length() + 1, '\u2502', '\u2564');
charArea.drawStringTB("\u2554\u2563\u255a", textPos - 1, 1);
charArea.drawStringTB("\u2557\u2560\u255d", textPos + desc.length(), 1);
} else {
charArea.drawHLine('=', 2, 0, width);
charArea.drawStringLR(desc, textPos, 2);
charArea.drawHLine('=', 1, textPos - 1, textPos + desc.length() + 1);
charArea.drawHLine('=', 3, textPos - 1, textPos + desc.length() + 1);
}
}
public double getPreferredHeight(StringBounder stringBounder) {
return StringUtils.getHeight(stringsToDisplay) + 4;
}
public double getPreferredWidth(StringBounder stringBounder) {
return StringUtils.getWidth(stringsToDisplay) + 2;
}
}

View File

@ -0,0 +1,86 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4169 $
*
*/
package net.sourceforge.plantuml.asciiart;
import java.awt.geom.Dimension2D;
import java.util.List;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.skin.Component;
import net.sourceforge.plantuml.skin.ComponentType;
import net.sourceforge.plantuml.skin.Context2D;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt;
public class ComponentTextGroupingBody implements Component {
private final ComponentType type;
private final List<? extends CharSequence> stringsToDisplay;
private final FileFormat fileFormat;
public ComponentTextGroupingBody(ComponentType type, List<? extends CharSequence> stringsToDisplay,
FileFormat fileFormat) {
this.type = type;
this.stringsToDisplay = stringsToDisplay;
this.fileFormat = fileFormat;
}
public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) {
final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea();
final int width = (int) dimensionToUse.getWidth();
final int height = (int) dimensionToUse.getHeight();
if (fileFormat == FileFormat.UTXT) {
charArea.drawVLine('\u2551', 0, 0, height);
charArea.drawVLine('\u2551', width - 1, 0, height);
charArea.drawHLine('\u2550', height - 1, 1, width - 1, '\u2502', '\u256a');
charArea.drawChar('\u2560', 0, height - 1);
charArea.drawChar('\u2563', width - 1, height - 1);
} else {
charArea.drawVLine('!', 0, 0, height);
charArea.drawVLine('!', width - 1, 0, height);
charArea.drawHLine('~', height - 1, 1, width - 1);
}
}
public double getPreferredHeight(StringBounder stringBounder) {
return 1;
}
public double getPreferredWidth(StringBounder stringBounder) {
return 1;
}
}

View File

@ -0,0 +1,80 @@
/* ========================================================================
* 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: 4169 $
*
*/
package net.sourceforge.plantuml.asciiart;
import java.awt.geom.Dimension2D;
import java.util.List;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.skin.Component;
import net.sourceforge.plantuml.skin.ComponentType;
import net.sourceforge.plantuml.skin.Context2D;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt;
public class ComponentTextGroupingElse implements Component {
private final ComponentType type;
private final List<? extends CharSequence> stringsToDisplay;
private final FileFormat fileFormat;
public ComponentTextGroupingElse(ComponentType type, List<? extends CharSequence> stringsToDisplay,
FileFormat fileFormat) {
this.type = type;
this.stringsToDisplay = stringsToDisplay;
this.fileFormat = fileFormat;
}
public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) {
final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea();
// final int width = (int) dimensionToUse.getWidth();
// final int height = (int) dimensionToUse.getHeight();
if (stringsToDisplay.get(0) != null) {
charArea.drawStringLR("[" + stringsToDisplay.get(0) + "]", 2, 0);
}
// charArea.fillRect('E', 0, 0, width, height);
}
public double getPreferredHeight(StringBounder stringBounder) {
return 1;
}
public double getPreferredWidth(StringBounder stringBounder) {
return 1;
}
}

View File

@ -0,0 +1,103 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4169 $
*
*/
package net.sourceforge.plantuml.asciiart;
import java.awt.geom.Dimension2D;
import java.util.List;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.skin.Component;
import net.sourceforge.plantuml.skin.ComponentType;
import net.sourceforge.plantuml.skin.Context2D;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt;
public class ComponentTextGroupingHeader implements Component {
private final ComponentType type;
private final List<? extends CharSequence> stringsToDisplay;
private final FileFormat fileFormat;
public ComponentTextGroupingHeader(ComponentType type, List<? extends CharSequence> stringsToDisplay,
FileFormat fileFormat) {
this.type = type;
this.stringsToDisplay = stringsToDisplay;
this.fileFormat = fileFormat;
}
public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) {
final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea();
final int width = (int) dimensionToUse.getWidth();
final int height = (int) dimensionToUse.getHeight();
// charArea.fillRect('G', 0, 0, width, height);
final String text = stringsToDisplay.get(0).toString();
if (fileFormat == FileFormat.UTXT) {
charArea.drawHLine('\u2550', 0, 1, width - 1, '\u2502', '\u256a');
charArea.drawStringLR(text.toUpperCase() + " /", 2, 1);
charArea.drawHLine('\u2500', 2, 1, text.length() + 4);
charArea.drawVLine('\u2551', 0, 1, height + 3);
charArea.drawVLine('\u2551', width - 1, 1, height + 3);
charArea.drawChar('\u255f', 0, 2);
charArea.drawStringTB("\u2564\u2502\u2518", text.length() + 4, 0);
charArea.drawChar('\u2554', 0, 0);
charArea.drawChar('\u2557', width - 1, 0);
} else {
charArea.drawHLine('_', 0, 0, width - 1);
charArea.drawStringLR(text.toUpperCase() + " /", 2, 1);
charArea.drawHLine('_', 2, 1, text.length() + 3);
charArea.drawChar('/', text.length() + 3, 2);
charArea.drawVLine('!', 0, 1, height + 3);
charArea.drawVLine('!', width - 1, 1, height + 3);
}
if (stringsToDisplay.size() > 1) {
final String comment = stringsToDisplay.get(1).toString();
charArea.drawStringLR(comment, text.length() + 7, 1);
}
}
public double getPreferredHeight(StringBounder stringBounder) {
return StringUtils.getHeight(stringsToDisplay) + 2;
}
public double getPreferredWidth(StringBounder stringBounder) {
return StringUtils.getWidth(stringsToDisplay) + 2;
}
}

View File

@ -0,0 +1,80 @@
/* ========================================================================
* 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: 4169 $
*
*/
package net.sourceforge.plantuml.asciiart;
import java.awt.geom.Dimension2D;
import java.util.List;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.skin.Component;
import net.sourceforge.plantuml.skin.ComponentType;
import net.sourceforge.plantuml.skin.Context2D;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt;
public class ComponentTextGroupingTail implements Component {
private final ComponentType type;
private final List<? extends CharSequence> stringsToDisplay;
private final FileFormat fileFormat;
public ComponentTextGroupingTail(ComponentType type, List<? extends CharSequence> stringsToDisplay,
FileFormat fileFormat) {
this.type = type;
this.stringsToDisplay = stringsToDisplay;
this.fileFormat = fileFormat;
}
public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) {
final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea();
final int width = (int) dimensionToUse.getWidth();
final int height = (int) dimensionToUse.getHeight();
// charArea.fillRect('T', 0, 0, width, height);
if (fileFormat == FileFormat.UTXT) {
charArea.drawChar('\u255a', 0, height - 1);
charArea.drawChar('\u255d', width - 1, height - 1);
}
}
public double getPreferredHeight(StringBounder stringBounder) {
return 1;
}
public double getPreferredWidth(StringBounder stringBounder) {
return 1;
}
}

View File

@ -0,0 +1,72 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4169 $
*
*/
package net.sourceforge.plantuml.asciiart;
import java.awt.geom.Dimension2D;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.skin.Component;
import net.sourceforge.plantuml.skin.Context2D;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt;
public class ComponentTextLine implements Component {
private final FileFormat fileFormat;
public ComponentTextLine(FileFormat fileFormat) {
this.fileFormat = fileFormat;
}
public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) {
final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea();
final int width = (int) dimensionToUse.getWidth();
final int height = (int) dimensionToUse.getHeight();
if (fileFormat == FileFormat.UTXT) {
charArea.drawVLine('\u2502', (width - 1) / 2, 0, height - 1);
} else {
charArea.drawVLine('|', (width - 1) / 2, 0, height - 1);
}
}
public double getPreferredHeight(StringBounder stringBounder) {
return 0;
}
public double getPreferredWidth(StringBounder stringBounder) {
return 3;
}
}

View File

@ -0,0 +1,81 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4169 $
*
*/
package net.sourceforge.plantuml.asciiart;
import java.awt.geom.Dimension2D;
import java.util.List;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.skin.Component;
import net.sourceforge.plantuml.skin.ComponentType;
import net.sourceforge.plantuml.skin.Context2D;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt;
public class ComponentTextNote implements Component {
private final ComponentType type;
private final List<? extends CharSequence> stringsToDisplay;
private final FileFormat fileFormat;
public ComponentTextNote(ComponentType type, List<? extends CharSequence> stringsToDisplay, FileFormat fileFormat) {
this.type = type;
this.stringsToDisplay = stringsToDisplay;
this.fileFormat = fileFormat;
}
public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) {
final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea();
final int width = (int) dimensionToUse.getWidth() - 1;
final int height = (int) dimensionToUse.getHeight();
charArea.fillRect(' ', 2, 1, width - 3, height - 2);
if (fileFormat == FileFormat.UTXT) {
charArea.drawNoteSimpleUnicode(2, 0, width - 2, height);
} else {
charArea.drawNoteSimple(2, 0, width - 2, height);
}
charArea.drawStringsLR(stringsToDisplay, 3, 1);
}
public double getPreferredHeight(StringBounder stringBounder) {
return StringUtils.getHeight(stringsToDisplay) + 2;
}
public double getPreferredWidth(StringBounder stringBounder) {
return StringUtils.getWidth(stringsToDisplay) + 7;
}
}

View File

@ -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: 4169 $
*
*/
package net.sourceforge.plantuml.asciiart;
import java.awt.geom.Dimension2D;
import java.util.List;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.skin.Component;
import net.sourceforge.plantuml.skin.ComponentType;
import net.sourceforge.plantuml.skin.Context2D;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt;
public class ComponentTextParticipant implements Component {
private final ComponentType type;
private final List<? extends CharSequence> stringsToDisplay;
private final FileFormat fileFormat;
public ComponentTextParticipant(ComponentType type, List<? extends CharSequence> stringsToDisplay,
FileFormat fileFormat) {
this.type = type;
this.stringsToDisplay = stringsToDisplay;
this.fileFormat = fileFormat;
}
public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) {
final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea();
final int width = (int) dimensionToUse.getWidth();
final int height = (int) dimensionToUse.getHeight();
charArea.fillRect(' ', 0, 0, width, height);
if (fileFormat == FileFormat.UTXT) {
charArea.drawBoxSimpleUnicode(0, 0, width, height);
if (type == ComponentType.PARTICIPANT_TAIL) {
charArea.drawChar('\u2534', (width - 1) / 2, 0);
}
if (type == ComponentType.PARTICIPANT_HEAD) {
charArea.drawChar('\u252c', (width - 1) / 2, height - 1);
}
} else {
charArea.drawBoxSimple(0, 0, width, height);
if (type == ComponentType.PARTICIPANT_TAIL) {
charArea.drawChar('+', (width - 1) / 2, 0);
}
if (type == ComponentType.PARTICIPANT_HEAD) {
charArea.drawChar('+', (width - 1) / 2, height - 1);
}
}
charArea.drawStringsLR(stringsToDisplay, 1, 1);
}
public double getPreferredHeight(StringBounder stringBounder) {
return StringUtils.getHeight(stringsToDisplay) + 2;
}
public double getPreferredWidth(StringBounder stringBounder) {
return StringUtils.getWidth(stringsToDisplay) + 2;
}
}

View File

@ -0,0 +1,101 @@
/* ========================================================================
* 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: 4169 $
*
*/
package net.sourceforge.plantuml.asciiart;
import java.awt.geom.Dimension2D;
import java.util.List;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.skin.Component;
import net.sourceforge.plantuml.skin.ComponentType;
import net.sourceforge.plantuml.skin.Context2D;
import net.sourceforge.plantuml.ugraphic.UGraphic;
import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt;
public class ComponentTextSelfArrow implements Component {
private final ComponentType type;
private final List<? extends CharSequence> stringsToDisplay;
private final FileFormat fileFormat;
public ComponentTextSelfArrow(ComponentType type, List<? extends CharSequence> stringsToDisplay,
FileFormat fileFormat) {
this.type = type;
this.stringsToDisplay = stringsToDisplay;
this.fileFormat = fileFormat;
}
public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) {
final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea();
final int width = (int) dimensionToUse.getWidth();
final int height = (int) dimensionToUse.getHeight() - 1;
charArea.fillRect(' ', 0, 0, width, height);
if (fileFormat == FileFormat.UTXT) {
if (type == ComponentType.SELF_ARROW) {
charArea.drawStringLR("\u2500\u2500\u2500\u2500\u2510", 0, 0);
charArea.drawStringLR("\u2502", 4, 1);
charArea.drawStringLR("<\u2500\u2500\u2500\u2518", 0, 2);
} else if (type == ComponentType.DOTTED_SELF_ARROW) {
charArea.drawStringLR("\u2500 \u2500 \u2510", 0, 0);
charArea.drawStringLR("|", 4, 1);
charArea.drawStringLR("< \u2500 \u2518", 0, 2);
}
} else {
if (type == ComponentType.SELF_ARROW) {
charArea.drawStringLR("----.", 0, 0);
charArea.drawStringLR("|", 4, 1);
charArea.drawStringLR("<---'", 0, 2);
} else if (type == ComponentType.DOTTED_SELF_ARROW) {
charArea.drawStringLR("- - .", 0, 0);
charArea.drawStringLR("|", 4, 1);
charArea.drawStringLR("< - '", 0, 2);
}
}
charArea.drawStringsLR(stringsToDisplay, 6, 1);
}
public double getPreferredHeight(StringBounder stringBounder) {
return StringUtils.getHeight(stringsToDisplay) + 3;
}
public double getPreferredWidth(StringBounder stringBounder) {
return StringUtils.getWidth(stringsToDisplay) + 6;
}
}

View File

@ -0,0 +1,97 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5140 $
*
*/
package net.sourceforge.plantuml.asciiart;
import java.util.List;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.ISkinParam;
import net.sourceforge.plantuml.skin.Component;
import net.sourceforge.plantuml.skin.ComponentType;
import net.sourceforge.plantuml.skin.Skin;
public class TextSkin implements Skin {
private final FileFormat fileFormat;
public TextSkin(FileFormat fileFormat) {
this.fileFormat = fileFormat;
}
public Component createComponent(ComponentType type, ISkinParam param, List<? extends CharSequence> stringsToDisplay) {
if (type == ComponentType.PARTICIPANT_HEAD || type == ComponentType.PARTICIPANT_TAIL) {
return new ComponentTextParticipant(type, stringsToDisplay, fileFormat);
}
if (type == ComponentType.ACTOR_HEAD || type == ComponentType.ACTOR_TAIL) {
return new ComponentTextActor(type, stringsToDisplay, fileFormat);
}
if (type == ComponentType.ARROW || type == ComponentType.RETURN_ARROW || type == ComponentType.DOTTED_ARROW
|| type == ComponentType.RETURN_DOTTED_ARROW) {
return new ComponentTextArrow(type, stringsToDisplay, fileFormat);
}
if (type == ComponentType.SELF_ARROW || type == ComponentType.DOTTED_SELF_ARROW) {
return new ComponentTextSelfArrow(type, stringsToDisplay, fileFormat);
}
if (type == ComponentType.PARTICIPANT_LINE || type == ComponentType.ACTOR_LINE) {
return new ComponentTextLine(fileFormat);
}
if (type == ComponentType.ALIVE_LINE) {
return new ComponentTextActiveLine(fileFormat);
}
if (type == ComponentType.NOTE) {
return new ComponentTextNote(type, stringsToDisplay, fileFormat);
}
if (type == ComponentType.DIVIDER) {
return new ComponentTextDivider(type, stringsToDisplay, fileFormat);
}
if (type == ComponentType.GROUPING_HEADER) {
return new ComponentTextGroupingHeader(type, stringsToDisplay, fileFormat);
}
if (type == ComponentType.GROUPING_BODY) {
return new ComponentTextGroupingBody(type, stringsToDisplay, fileFormat);
}
if (type == ComponentType.GROUPING_TAIL) {
return new ComponentTextGroupingTail(type, stringsToDisplay, fileFormat);
}
if (type == ComponentType.GROUPING_ELSE) {
return new ComponentTextGroupingElse(type, stringsToDisplay, fileFormat);
}
throw new UnsupportedOperationException(type.toString());
}
public Object getProtocolVersion() {
return 1;
}
}

View File

@ -0,0 +1,48 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4246 $
*
*/
package net.sourceforge.plantuml.asciiart;
import java.awt.Font;
import java.awt.geom.Dimension2D;
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.graphic.StringBounder;
public class TextStringBounder implements StringBounder {
public Dimension2D calculateDimension(Font font, String text) {
return new Dimension2DDouble(text.length(), 1);
}
}

View File

@ -0,0 +1,133 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5109 $
*
*/
package net.sourceforge.plantuml.asciiart;
import java.io.PrintStream;
import java.util.Collection;
import java.util.List;
public class TranslatedCharArea implements UmlCharArea {
private final int dx;
private final int dy;
private final UmlCharArea charArea;
public TranslatedCharArea(UmlCharArea charArea, int dx, int dy) {
this.charArea = charArea;
this.dx = dx;
this.dy = dy;
}
public void drawBoxSimple(int x, int y, int width, int height) {
charArea.drawBoxSimple(x + dx, y + dy, width, height);
}
public void drawBoxSimpleUnicode(int x, int y, int width, int height) {
charArea.drawBoxSimpleUnicode(x + dx, y + dy, width, height);
}
public void drawNoteSimple(int x, int y, int width, int height) {
charArea.drawNoteSimple(x + dx, y + dy, width, height);
}
public void drawNoteSimpleUnicode(int x, int y, int width, int height) {
charArea.drawNoteSimpleUnicode(x + dx, y + dy, width, height);
}
public void drawStickMan(int x, int y) {
charArea.drawStickMan(x + dx, y + dy);
}
public void drawStickManUnicode(int x, int y) {
charArea.drawStickManUnicode(x + dx, y + dy);
}
public void drawChar(char c, int x, int y) {
charArea.drawChar(c, x + dx, y + dy);
}
public void drawHLine(char c, int line, int col1, int col2) {
charArea.drawHLine(c, line + dy, col1 + dx, col2 + dx);
}
public void drawHLine(char c, int line, int col1, int col2, char ifFound, char thenUse) {
charArea.drawHLine(c, line + dy, col1 + dx, col2 + dx, ifFound, thenUse);
}
public void drawStringLR(String string, int x, int y) {
charArea.drawStringLR(string, x + dx, y + dy);
}
public void drawStringTB(String string, int x, int y) {
charArea.drawStringTB(string, x + dx, y + dy);
}
public void drawVLine(char c, int col, int line1, int line2) {
charArea.drawVLine(c, col + dx, line1 + dy, line2 + dy);
}
public int getHeight() {
return charArea.getHeight();
}
public int getWidth() {
return charArea.getWidth();
}
public String getLine(int line) {
return charArea.getLine(line);
}
public List<String> getLines() {
return charArea.getLines();
}
public void print(PrintStream ps) {
charArea.print(ps);
}
public void drawStringsLR(Collection<? extends CharSequence> strings, int x, int y) {
charArea.drawStringsLR(strings, x + dx, y + dy);
}
public void fillRect(char c, int x, int y, int width, int height) {
charArea.fillRect(c, x + dx, y + dy, width, height);
}
}

View File

@ -0,0 +1,57 @@
/* ========================================================================
* 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: 3826 $
*
*/
package net.sourceforge.plantuml.asciiart;
import java.util.Collection;
public interface UmlCharArea extends BasicCharArea {
int STICKMAN_HEIGHT = 5;
int STICKMAN_UNICODE_HEIGHT = 6;
void drawBoxSimple(int x, int y, int width, int height);
void drawBoxSimpleUnicode(int x, int y, int width, int height);
void drawNoteSimple(int x, int y, int width, int height);
void drawNoteSimpleUnicode(int x, int y, int width, int height);
void drawStickMan(int x, int y);
void drawStickManUnicode(int x, int y);
void drawStringsLR(Collection<? extends CharSequence> strings, int x, int y);
}

View File

@ -0,0 +1,122 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5156 $
*
*/
package net.sourceforge.plantuml.asciiart;
import java.util.Collection;
public class UmlCharAreaImpl extends BasicCharAreaImpl implements UmlCharArea {
public void drawBoxSimple(int x, int y, int width, int height) {
this.drawHLine('-', y, x + 1, x + width - 1);
this.drawHLine('-', y + height - 1, x + 1, x + width - 1);
this.drawVLine('|', x, y + 1, y + height - 1);
this.drawVLine('|', x + width - 1, y + 1, y + height - 1);
this.drawChar(',', x, y);
this.drawChar('.', x + width - 1, y);
this.drawChar('`', x, y + height - 1);
this.drawChar('\'', x + width - 1, y + height - 1);
}
public void drawBoxSimpleUnicode(int x, int y, int width, int height) {
this.drawHLine('\u2500', y, x + 1, x + width - 1);
this.drawHLine('\u2500', y + height - 1, x + 1, x + width - 1);
this.drawVLine('\u2502', x, y + 1, y + height - 1);
this.drawVLine('\u2502', x + width - 1, y + 1, y + height - 1);
this.drawChar('\u250c', x, y);
this.drawChar('\u2510', x + width - 1, y);
this.drawChar('\u2514', x, y + height - 1);
this.drawChar('\u2518', x + width - 1, y + height - 1);
}
public void drawStickMan(int x, int y) {
this.drawStringLR(",-.", x, y++);
this.drawStringLR("`-'", x, y++);
this.drawStringLR("/|\\", x, y++);
this.drawStringLR(" | ", x, y++);
this.drawStringLR("/ \\", x, y++);
}
public void drawStickManUnicode(int x, int y) {
this.drawStringLR("\u250c\u2500\u2510", x, y++);
this.drawStringLR("\u2551\"\u2502", x, y++);
this.drawStringLR("\u2514\u252c\u2518", x, y++);
this.drawStringLR("\u250c\u253c\u2510", x, y++);
this.drawStringLR(" \u2502 ", x, y++);
this.drawStringLR("\u250c\u2534\u2510", x, y++);
}
public void drawStringsLR(Collection<? extends CharSequence> strings, int x, int y) {
int i = 0;
for (CharSequence s : strings) {
this.drawStringLR(s.toString(), x, y + i);
i++;
}
}
public void drawNoteSimple(int x, int y, int width, int height) {
this.drawHLine('-', y, x + 1, x + width - 1);
this.drawHLine('-', y + height - 1, x + 1, x + width - 1);
this.drawVLine('|', x, y + 1, y + height - 1);
this.drawVLine('|', x + width - 1, y + 1, y + height - 1);
this.drawChar(',', x, y);
this.drawStringLR("!. ", x + width - 3, y);
this.drawStringLR("|_\\", x + width - 3, y + 1);
this.drawChar('`', x, y + height - 1);
this.drawChar('\'', x + width - 1, y + height - 1);
}
public void drawNoteSimpleUnicode(int x, int y, int width, int height) {
this.drawChar('\u2591', x + width - 2, y + 1);
this.drawHLine('\u2550', y, x + 1, x + width - 1, '\u2502', '\u2567');
this.drawHLine('\u2550', y + height - 1, x + 1, x + width - 1, '\u2502', '\u2564');
this.drawVLine('\u2551', x, y + 1, y + height - 1);
this.drawVLine('\u2551', x + width - 1, y + 1, y + height - 1);
this.drawChar('\u2554', x, y);
this.drawChar('\u2557', x + width - 1, y);
this.drawChar('\u255a', x, y + height - 1);
this.drawChar('\u255d', x + width - 1, y + height - 1);
}
}

View File

@ -0,0 +1,58 @@
/* ========================================================================
* 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: 5350 $
*
*/
package net.sourceforge.plantuml.classdiagram;
import java.util.Arrays;
import java.util.List;
import net.sourceforge.plantuml.cucadiagram.CucaDiagram;
import net.sourceforge.plantuml.cucadiagram.IEntity;
public abstract class AbstractEntityDiagram extends CucaDiagram {
abstract public IEntity getOrCreateClass(String code);
final protected List<String> 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 public String getDescription() {
return "(" + entities().size() + " entities)";
}
}

View File

@ -0,0 +1,148 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5536 $
*
*/
package net.sourceforge.plantuml.classdiagram;
import net.sourceforge.plantuml.UmlDiagramType;
import net.sourceforge.plantuml.cucadiagram.Entity;
import net.sourceforge.plantuml.cucadiagram.EntityType;
import net.sourceforge.plantuml.cucadiagram.Group;
import net.sourceforge.plantuml.cucadiagram.GroupType;
import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.objectdiagram.AbstractClassOrObjectDiagram;
public class ClassDiagram extends AbstractClassOrObjectDiagram {
@Override
public IEntity getOrCreateEntity(String code, EntityType defaultType) {
assert defaultType == EntityType.ABSTRACT_CLASS || defaultType == EntityType.CLASS
|| defaultType == EntityType.INTERFACE || defaultType == EntityType.ENUM
|| defaultType == EntityType.LOLLIPOP;
code = getFullyQualifiedCode(code);
if (super.entityExist(code)) {
return super.getOrCreateEntity(code, defaultType);
}
return createEntityWithNamespace(code, getShortName(code), defaultType);
}
@Override
public Entity createEntity(String code, String display, EntityType type) {
if (type != EntityType.ABSTRACT_CLASS && type != EntityType.CLASS && type != EntityType.INTERFACE
&& type != EntityType.ENUM && type != EntityType.LOLLIPOP) {
return super.createEntity(code, display, type);
}
code = getFullyQualifiedCode(code);
if (super.entityExist(code)) {
throw new IllegalArgumentException("Already known: " + code);
}
return createEntityWithNamespace(code, display, type);
}
private Entity createEntityWithNamespace(String fullyCode, String display, EntityType type) {
Group group = getCurrentGroup();
final String namespace = getNamespace(fullyCode);
if (namespace != null && (group == null || group.getCode().equals(namespace) == false)) {
group = getOrCreateGroupInternal(namespace, namespace, namespace, GroupType.PACKAGE, null);
group.setBold(true);
}
return createEntityInternal(fullyCode, display == null ? getShortName(fullyCode) : display, type, group);
}
@Override
public final boolean entityExist(String code) {
return super.entityExist(getFullyQualifiedCode(code));
}
@Override
public IEntity getOrCreateClass(String code) {
return getOrCreateEntity(code, EntityType.CLASS);
}
final public IEntity getOrCreateClass(String code, EntityType type) {
if (type != EntityType.ABSTRACT_CLASS && type != EntityType.CLASS && type != EntityType.INTERFACE
&& type != EntityType.ENUM && type != EntityType.LOLLIPOP) {
throw new IllegalArgumentException();
}
return getOrCreateEntity(code, type);
}
private String getFullyQualifiedCode(String code) {
if (code.startsWith("\\") || code.startsWith("~") || code.startsWith(".")) {
return code.substring(1);
}
if (code.contains(".")) {
return code;
}
final Group g = this.getCurrentGroup();
if (g == null) {
return code;
}
final String namespace = g.getNamespace();
if (namespace == null) {
return code;
}
return namespace + "." + code;
}
private String getShortName(String code) {
// final int x = code.lastIndexOf('.');
// if (x == -1) {
// return code;
// }
// return code.substring(x + 1);
final String namespace = getNamespace(code);
if (namespace == null) {
return code;
}
return code.substring(namespace.length() + 1);
}
private String getNamespace(String code) {
assert code.startsWith("\\") == false;
assert code.startsWith("~") == false;
do {
final int x = code.lastIndexOf('.');
if (x == -1) {
return null;
}
code = code.substring(0, x);
} while (entityExist(code));
return code;
}
@Override
public UmlDiagramType getUmlDiagramType() {
return UmlDiagramType.CLASS;
}
}

View File

@ -0,0 +1,97 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5472 $
*
*/
package net.sourceforge.plantuml.classdiagram;
import net.sourceforge.plantuml.classdiagram.command.CommandAddMethod;
import net.sourceforge.plantuml.classdiagram.command.CommandCreateEntityClass;
import net.sourceforge.plantuml.classdiagram.command.CommandCreateEntityClassMultilines;
import net.sourceforge.plantuml.classdiagram.command.CommandEndNamespace;
import net.sourceforge.plantuml.classdiagram.command.CommandHideShow;
import net.sourceforge.plantuml.classdiagram.command.CommandImport;
import net.sourceforge.plantuml.classdiagram.command.CommandLinkClass2;
import net.sourceforge.plantuml.classdiagram.command.CommandLinkLollipop;
import net.sourceforge.plantuml.classdiagram.command.CommandMultilinesClassNote;
import net.sourceforge.plantuml.classdiagram.command.CommandNamespace;
import net.sourceforge.plantuml.classdiagram.command.CommandStereotype;
import net.sourceforge.plantuml.classdiagram.command.CommandUrl;
import net.sourceforge.plantuml.command.AbstractUmlSystemCommandFactory;
import net.sourceforge.plantuml.command.CommandCreateNote;
import net.sourceforge.plantuml.command.CommandEndPackage;
import net.sourceforge.plantuml.command.CommandMultilinesStandaloneNote;
import net.sourceforge.plantuml.command.CommandNoteEntity;
import net.sourceforge.plantuml.command.CommandPackage;
import net.sourceforge.plantuml.command.CommandPage;
public class ClassDiagramFactory extends AbstractUmlSystemCommandFactory {
private ClassDiagram system;
public ClassDiagram getSystem() {
return system;
}
@Override
protected void initCommands() {
system = new ClassDiagram();
addCommonCommands(system);
addCommand(new CommandPage(system));
addCommand(new CommandAddMethod(system));
addCommand(new CommandCreateEntityClass(system));
addCommand(new CommandCreateNote(system));
addCommand(new CommandPackage(system));
addCommand(new CommandEndPackage(system));
addCommand(new CommandNamespace(system));
addCommand(new CommandEndNamespace(system));
addCommand(new CommandStereotype(system));
//addCommand(new CommandLinkClass(system));
addCommand(new CommandLinkClass2(system));
addCommand(new CommandLinkLollipop(system));
addCommand(new CommandImport(system));
addCommand(new CommandNoteEntity(system));
addCommand(new CommandUrl(system));
addCommand(new CommandMultilinesClassNote(system));
addCommand(new CommandMultilinesStandaloneNote(system));
addCommand(new CommandCreateEntityClassMultilines(system));
addCommand(new CommandHideShow(system));
}
}

View File

@ -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: 5019 $
*
*/
package net.sourceforge.plantuml.classdiagram.command;
import java.util.List;
import net.sourceforge.plantuml.classdiagram.ClassDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand;
import net.sourceforge.plantuml.cucadiagram.Entity;
import net.sourceforge.plantuml.skin.VisibilityModifier;
public class CommandAddMethod extends SingleLineCommand<ClassDiagram> {
public CommandAddMethod(ClassDiagram diagram) {
super(diagram, "(?i)^([\\p{L}0-9_.]+)\\s*:\\s*(.*)$");
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
final Entity entity = (Entity) getSystem().getOrCreateClass(arg.get(0));
final String field = arg.get(1);
if (field.length() > 0 && VisibilityModifier.isVisibilityCharacter(field.charAt(0))) {
getSystem().setVisibilityModifierPresent(true);
}
entity.addFieldOrMethod(field);
return CommandExecutionResult.ok();
}
}

View File

@ -0,0 +1,77 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5075 $
*
*/
package net.sourceforge.plantuml.classdiagram.command;
import java.util.List;
import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.classdiagram.ClassDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand;
import net.sourceforge.plantuml.cucadiagram.Entity;
import net.sourceforge.plantuml.cucadiagram.EntityType;
import net.sourceforge.plantuml.cucadiagram.Stereotype;
public class CommandCreateEntityClass extends SingleLineCommand<ClassDiagram> {
public CommandCreateEntityClass(ClassDiagram diagram) {
super(
diagram,
"(?i)^(interface|enum|abstract\\s+class|abstract|class)\\s+(?:\"([^\"]+)\"\\s+as\\s+)?(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)(?:\\s*([\\<\\[]{2}.*[\\>\\]]{2}))?$");
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
final String arg0 = arg.get(0).toUpperCase();
final EntityType type = EntityType.getEntityType(arg0);
final String code = arg.get(2);
final String display = arg.get(1);
final String stereotype = arg.get(3);
final Entity entity;
if (getSystem().entityExist(code)) {
// return CommandExecutionResult.error("Class already exists : "
// + code);
entity = (Entity) getSystem().getOrCreateEntity(code, type);
entity.muteToType(type);
} else {
entity = getSystem().createEntity(code, display, type);
}
if (stereotype != null) {
entity.setStereotype(new Stereotype(stereotype, getSystem().getSkinParam().getCircledCharacterRadius(),
getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER)));
}
return CommandExecutionResult.ok();
}
}

View File

@ -0,0 +1,91 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4161 $
*
*/
package net.sourceforge.plantuml.classdiagram.command;
import java.util.List;
import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.classdiagram.ClassDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.CommandMultilines;
import net.sourceforge.plantuml.cucadiagram.Entity;
import net.sourceforge.plantuml.cucadiagram.EntityType;
import net.sourceforge.plantuml.cucadiagram.Stereotype;
import net.sourceforge.plantuml.skin.VisibilityModifier;
public class CommandCreateEntityClassMultilines extends CommandMultilines<ClassDiagram> {
public CommandCreateEntityClassMultilines(ClassDiagram diagram) {
super(
diagram,
"(?i)^(interface|enum|abstract\\s+class|abstract|class)\\s+(?:\"([^\"]+)\"\\s+as\\s+)?(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)(?:\\s*([\\<\\[]{2}.*[\\>\\]]{2}))?\\s*\\{\\s*$",
"(?i)^\\s*\\}\\s*$");
}
public CommandExecutionResult execute(List<String> lines) {
final List<String> line0 = StringUtils.getSplit(getStartingPattern(), lines.get(0));
final Entity entity = executeArg0(line0);
if (entity == null) {
return CommandExecutionResult.error("No such entity");
}
for (String s : lines.subList(1, lines.size() - 1)) {
if (s.length() > 0 && VisibilityModifier.isVisibilityCharacter(s.charAt(0))) {
getSystem().setVisibilityModifierPresent(true);
}
entity.addFieldOrMethod(s);
}
return CommandExecutionResult.ok();
}
private Entity executeArg0(List<String> arg) {
final String arg0 = arg.get(0).toUpperCase();
final EntityType type = EntityType.getEntityType(arg0);
final String code = arg.get(2);
final String display = arg.get(1);
final String stereotype = arg.get(3);
if (getSystem().entityExist(code)) {
final Entity result = (Entity) getSystem().getOrCreateClass(code);
result.muteToType(type);
return result;
}
final Entity entity = getSystem().createEntity(code, display, type);
if (stereotype != null) {
entity.setStereotype(new Stereotype(stereotype, getSystem().getSkinParam().getCircledCharacterRadius(),
getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER)));
}
return entity;
}
}

View File

@ -0,0 +1,59 @@
/* ========================================================================
* 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: 3828 $
*
*/
package net.sourceforge.plantuml.classdiagram.command;
import java.util.List;
import net.sourceforge.plantuml.classdiagram.ClassDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand;
import net.sourceforge.plantuml.cucadiagram.Group;
public class CommandEndNamespace extends SingleLineCommand<ClassDiagram> {
public CommandEndNamespace(ClassDiagram diagram) {
super(diagram, "(?i)^end ?namespace$");
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
final Group currentPackage = getSystem().getCurrentGroup();
if (currentPackage == null) {
return CommandExecutionResult.error("No namesspace defined");
}
getSystem().endGroup();
return CommandExecutionResult.ok();
}
}

View File

@ -0,0 +1,128 @@
/* ========================================================================
* 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.List;
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.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<ClassDiagram> {
private static final EnumSet<EntityPortion> PORTION_METHOD = EnumSet.<EntityPortion> of(EntityPortion.METHOD);
private static final EnumSet<EntityPortion> PORTION_MEMBER = EnumSet.<EntityPortion> of(EntityPortion.FIELD,
EntityPortion.METHOD);
private static final EnumSet<EntityPortion> PORTION_FIELD = EnumSet.<EntityPortion> 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?)$");
}
private final EntityGender emptyByGender(Set<EntityPortion> portion) {
if (portion == PORTION_METHOD) {
return EntityGenderUtils.emptyMethods();
}
if (portion == PORTION_FIELD) {
return EntityGenderUtils.emptyFields();
}
if (portion == PORTION_MEMBER) {
return EntityGenderUtils.emptyMembers();
}
return EntityGenderUtils.all();
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
final Set<EntityPortion> portion = getEntityPortion(arg.get(3));
EntityGender gender = null;
if (arg.get(1) == null) {
gender = EntityGenderUtils.all();
} else if (arg.get(1).equalsIgnoreCase("class")) {
gender = EntityGenderUtils.byEntityType(EntityType.CLASS);
} else if (arg.get(1).equalsIgnoreCase("interface")) {
gender = EntityGenderUtils.byEntityType(EntityType.INTERFACE);
} else if (arg.get(1).equalsIgnoreCase("enum")) {
gender = EntityGenderUtils.byEntityType(EntityType.ENUM);
} else if (arg.get(1).equalsIgnoreCase("abstract")) {
gender = EntityGenderUtils.byEntityType(EntityType.ABSTRACT_CLASS);
} else if (arg.get(1).startsWith("<<")) {
gender = EntityGenderUtils.byStereotype(arg.get(1));
} else {
final IEntity entity = getSystem().getOrCreateClass(arg.get(1));
gender = EntityGenderUtils.byEntityAlone(entity);
}
if (gender != null) {
final boolean empty = arg.get(2) != 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"));
}
return CommandExecutionResult.ok();
}
private Set<EntityPortion> 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;
}
if (sub.equals("cir")) {
return EnumSet.<EntityPortion> of(EntityPortion.CIRCLED_CHARACTER);
}
if (sub.equals("ste")) {
return EnumSet.<EntityPortion> of(EntityPortion.STEREOTYPE);
}
throw new IllegalArgumentException();
}
}

View File

@ -0,0 +1,110 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5019 $
*
*/
package net.sourceforge.plantuml.classdiagram.command;
import java.io.File;
import java.io.IOException;
import java.util.List;
import net.sourceforge.plantuml.FileSystem;
import net.sourceforge.plantuml.classdiagram.ClassDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand;
import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.LinkDecor;
import net.sourceforge.plantuml.cucadiagram.LinkType;
public class CommandImport extends SingleLineCommand<ClassDiagram> {
public CommandImport(ClassDiagram classDiagram) {
super(classDiagram, "(?i)^import\\s+\"?([^\"]+)\"?$");
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
final String arg0 = arg.get(0);
try {
final File f = FileSystem.getInstance().getFile(arg0);
if (f.isFile()) {
includeSimpleFile(f);
} else if (f.isDirectory()) {
includeDirectory(f);
}
} catch (IOException e) {
e.printStackTrace();
return CommandExecutionResult.error("IO error " + e);
}
return CommandExecutionResult.ok();
}
private void includeDirectory(File dir) throws IOException {
for (File f : dir.listFiles()) {
includeSimpleFile(f);
}
}
private void includeSimpleFile(File f) throws IOException {
if (f.getName().toLowerCase().endsWith(".java")) {
includeFileJava(f);
}
// if (f.getName().toLowerCase().endsWith(".sql")) {
// includeFileSql(f);
// }
}
private void includeFileJava(final File f) throws IOException {
final JavaFile javaFile = new JavaFile(f);
for (JavaClass cl : javaFile.getJavaClasses()) {
final String name = cl.getName();
final IEntity ent1 = getSystem()
.getOrCreateClass(name, cl.getType());
for (String p : cl.getParents()) {
final IEntity ent2 = getSystem().getOrCreateClass(p,
cl.getParentType());
final Link link = new Link(ent2, ent1, new LinkType(
LinkDecor.NONE, LinkDecor.EXTENDS), null, 2);
getSystem().addLink(link);
}
}
}
// private void includeFileSql(final File f) throws IOException {
// new SqlImporter(getSystem(), f).process();
// }
}

View File

@ -0,0 +1,418 @@
/* ========================================================================
* 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: 5436 $
*
*/
package net.sourceforge.plantuml.classdiagram.command;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sourceforge.plantuml.Direction;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.UmlDiagramType;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand;
import net.sourceforge.plantuml.cucadiagram.Entity;
import net.sourceforge.plantuml.cucadiagram.EntityType;
import net.sourceforge.plantuml.cucadiagram.Group;
import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.LinkDecor;
import net.sourceforge.plantuml.cucadiagram.LinkType;
import net.sourceforge.plantuml.objectdiagram.AbstractClassOrObjectDiagram;
final public class CommandLinkClass extends SingleLineCommand<AbstractClassOrObjectDiagram> {
private static final int OFFSET = 1;
private static final int FIRST_TYPE_AND_CLASS = 0 + OFFSET;
private static final int FIRST_TYPE = 1 + OFFSET;
private static final int FIRST_CLASS = 2 + OFFSET;
private static final int FIRST_LABEL = 3 + OFFSET;
private static final int LEFT_TO_RIGHT = 4 + OFFSET;
private static final int LEFT_TO_RIGHT_QUEUE = 5 + OFFSET;
private static final int LEFT_TO_RIGHT_HEAD = 6 + OFFSET;
private static final int RIGHT_TO_LEFT = 7 + OFFSET;
private static final int RIGHT_TO_LEFT_HEAD = 8 + OFFSET;
private static final int RIGHT_TO_LEFT_QUEUE = 9 + OFFSET;
private static final int NAV_AGREG_OR_COMPO_INV = 10 + OFFSET;
private static final int NAV_AGREG_OR_COMPO_INV_QUEUE = 11 + OFFSET;
private static final int NAV_AGREG_OR_COMPO_INV_HEAD = 12 + OFFSET;
private static final int NAV_AGREG_OR_COMPO = 13 + OFFSET;
private static final int NAV_AGREG_OR_COMPO_HEAD = 14 + OFFSET;
private static final int NAV_AGREG_OR_COMPO_QUEUE = 15 + OFFSET;
private static final int SECOND_LABEL = 16 + OFFSET;
private static final int SECOND_TYPE_AND_CLASS = 17 + OFFSET;
private static final int SECOND_TYPE = 18 + OFFSET;
private static final int SECOND_CLASS = 19 + OFFSET;
private static final int LINK_LABEL = 20 + OFFSET;
private final Pattern patternAssociationPoint = Pattern
.compile("\\(\\s*(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s*,\\s*(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s*\\)");
// [\\p{L}0-9_.]+
// \\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*
public CommandLinkClass(AbstractClassOrObjectDiagram diagram) {
super(
diagram,
"(?i)^(?:@(\\d+)\\s+)?((?:"
+ optionalKeywords(diagram.getUmlDiagramType())
+ "\\s+)?"
+ "(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)|\\(\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*,\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*\\)"
+ ")\\s*(?:\"([^\"]+)\")?\\s*"
// split here
+ "(?:"
+ "(([-=.]+(?:left|right|up|down|le?|ri?|up?|do?)?[-=.]*)(o +|[\\]>*+]|\\|[>\\]])?)"
+ "|"
+ "(( +o|[\\[<*+]|[<\\[]\\|)?([-=.]*(?:left|right|up|down|le?|ri?|up?|do?)?[-=.]+))"
+ "|"
+ "(\\<([-=.]*(?:left|right|up|down|le?|ri?|up?|do?[-=.]+)?[-=.]+)(o +|\\*))"
+ "|"
+ "(( +o|\\*)([-=.]+(?:left|right|up|down|le?|ri?|up?|do?)?[-=.]*)\\>)"
+ ")"
// split here
+ "\\s*(?:\"([^\"]+)\")?\\s*((?:"
+ optionalKeywords(diagram.getUmlDiagramType())
+ "\\s+)?"
+ "(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)|\\(\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*,\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*\\)"
+ ")\\s*(?::\\s*([^\"]+))?$");
// "(?i)^(?:@(\\d+)\\s+)?((?:(interface|enum|abstract\\s+class|abstract|class)\\s+)?(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)|\\(\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*,\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*\\))\\s*(?:\"([^\"]+)\")?\\s*"
// +
// "(?:(([-=.]+)([\\]>o*+]|\\|[>\\]])?)|(([\\[<o*+]|[<\\[]\\|)?([-=.]+))|(\\<([-=.]+)([o*]))|(([o*])([-=.]+)\\>))"
// +
// "\\s*(?:\"([^\"]+)\")?\\s*((?:(interface|enum|abstract\\s+class|abstract|class)\\s+)?(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)|\\(\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*,\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*\\))\\s*(?::\\s*([^\"]+))?$");
}
private static String optionalKeywords(UmlDiagramType type) {
if (type == UmlDiagramType.CLASS) {
return "(interface|enum|abstract\\s+class|abstract|class)";
}
if (type == UmlDiagramType.OBJECT) {
return "(object)";
}
throw new IllegalArgumentException();
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
if (arg.get(FIRST_TYPE_AND_CLASS).startsWith("(")) {
return executeArgSpecial1(arg);
}
if (arg.get(SECOND_TYPE_AND_CLASS).startsWith("(")) {
return executeArgSpecial2(arg);
}
if (getSystem().isGroup(arg.get(FIRST_CLASS)) && getSystem().isGroup(arg.get(SECOND_CLASS))) {
return executePackageLink(arg);
}
if (getSystem().isGroup(arg.get(FIRST_CLASS)) || getSystem().isGroup(arg.get(SECOND_CLASS))) {
return CommandExecutionResult.error("Package can be only linked to other package");
}
final Entity cl1 = (Entity) getSystem().getOrCreateClass(arg.get(FIRST_CLASS));
final Entity cl2 = (Entity) getSystem().getOrCreateClass(arg.get(SECOND_CLASS));
if (arg.get(FIRST_TYPE) != null) {
final EntityType type = EntityType.getEntityType(arg.get(FIRST_TYPE));
if (type != EntityType.OBJECT) {
cl1.muteToType(type);
}
}
if (arg.get(SECOND_TYPE) != null) {
final EntityType type = EntityType.getEntityType(arg.get(SECOND_TYPE));
if (type != EntityType.OBJECT) {
cl2.muteToType(type);
}
}
final LinkType linkType = getLinkType(arg);
final String queueRaw = getQueue(arg);
final String queue = StringUtils.manageQueueForCuca(queueRaw);
Link link = new Link(cl1, cl2, linkType, arg.get(LINK_LABEL), queue.length(), arg.get(FIRST_LABEL), arg
.get(SECOND_LABEL), getSystem().getLabeldistance(), getSystem().getLabelangle());
if (queueRaw.matches(".*\\w.*")) {
if (arg.get(LEFT_TO_RIGHT) != null) {
Direction direction = StringUtils.getQueueDirection(arg.get(LEFT_TO_RIGHT_QUEUE));
if (linkType.isExtendsOrAgregationOrCompositionOrPlus()) {
direction = direction.getInv();
}
if (direction == Direction.LEFT || direction == Direction.UP) {
link = link.getInv();
}
}
if (arg.get(RIGHT_TO_LEFT) != null) {
Direction direction = StringUtils.getQueueDirection(arg.get(RIGHT_TO_LEFT_QUEUE));
if (linkType.isExtendsOrAgregationOrCompositionOrPlus()) {
direction = direction.getInv();
}
if (direction == Direction.RIGHT || direction == Direction.DOWN) {
link = link.getInv();
}
}
if (arg.get(NAV_AGREG_OR_COMPO) != null) {
Direction direction = StringUtils.getQueueDirection(arg.get(NAV_AGREG_OR_COMPO_QUEUE));
if (linkType.isExtendsOrAgregationOrCompositionOrPlus()) {
direction = direction.getInv();
}
if (direction == Direction.RIGHT || direction == Direction.DOWN) {
link = link.getInv();
}
}
if (arg.get(NAV_AGREG_OR_COMPO_INV) != null) {
Direction direction = StringUtils.getQueueDirection(arg.get(NAV_AGREG_OR_COMPO_INV_QUEUE));
if (linkType.isExtendsOrAgregationOrCompositionOrPlus()) {
direction = direction.getInv();
}
if (direction == Direction.LEFT || direction == Direction.UP) {
link = link.getInv();
}
}
}
getSystem().resetPragmaLabel();
addLink(link, arg.get(0));
return CommandExecutionResult.ok();
}
private void addLink(Link link, String arg0) {
getSystem().addLink(link);
if (arg0 == null) {
final LinkType type = link.getType();
// --|> highest
// --*, -->, --o normal
// ..*, ..>, ..o lowest
// if (type.isDashed() == false) {
// if (type.contains(LinkDecor.EXTENDS)) {
// link.setWeight(3);
// }
// if (type.contains(LinkDecor.ARROW) ||
// type.contains(LinkDecor.COMPOSITION)
// || type.contains(LinkDecor.AGREGATION)) {
// link.setWeight(2);
// }
// }
} else {
link.setWeight(Integer.parseInt(arg0));
}
}
private CommandExecutionResult executePackageLink(List<String> arg) {
final Group cl1 = getSystem().getGroup(arg.get(FIRST_CLASS));
final Group cl2 = getSystem().getGroup(arg.get(SECOND_CLASS));
final LinkType linkType = getLinkType(arg);
final String queue = getQueue(arg);
final Link link = new Link(cl1.getEntityCluster(), cl2.getEntityCluster(), linkType, arg.get(LINK_LABEL), queue
.length(), arg.get(FIRST_LABEL), arg.get(SECOND_LABEL), getSystem().getLabeldistance(), getSystem()
.getLabelangle());
getSystem().resetPragmaLabel();
addLink(link, arg.get(0));
return CommandExecutionResult.ok();
}
private CommandExecutionResult executeArgSpecial1(List<String> arg) {
final Matcher m = patternAssociationPoint.matcher(arg.get(FIRST_TYPE_AND_CLASS));
if (m.matches() == false) {
throw new IllegalStateException();
}
final String clName1 = m.group(1);
final String clName2 = m.group(2);
if (getSystem().entityExist(clName1) == false) {
return CommandExecutionResult.error("No class " + clName1);
}
if (getSystem().entityExist(clName2) == false) {
return CommandExecutionResult.error("No class " + clName2);
}
final IEntity entity1 = getSystem().getOrCreateClass(clName1);
final IEntity entity2 = getSystem().getOrCreateClass(clName2);
final Entity node = getSystem().createEntity(arg.get(FIRST_TYPE_AND_CLASS), "node",
EntityType.POINT_FOR_ASSOCIATION);
getSystem().insertBetween(entity1, entity2, node);
final IEntity cl2 = getSystem().getOrCreateClass(arg.get(SECOND_CLASS));
final LinkType linkType = getLinkType(arg);
final String queue = getQueue(arg);
final Link link = new Link(node, cl2, linkType, arg.get(LINK_LABEL), queue.length());
addLink(link, arg.get(0));
return CommandExecutionResult.ok();
}
private CommandExecutionResult executeArgSpecial2(List<String> arg) {
final Matcher m = patternAssociationPoint.matcher(arg.get(SECOND_TYPE_AND_CLASS));
if (m.matches() == false) {
throw new IllegalStateException();
}
final String clName1 = m.group(1);
final String clName2 = m.group(2);
if (getSystem().entityExist(clName1) == false) {
return CommandExecutionResult.error("No class " + clName1);
}
if (getSystem().entityExist(clName2) == false) {
return CommandExecutionResult.error("No class " + clName2);
}
final IEntity entity1 = getSystem().getOrCreateClass(clName1);
final IEntity entity2 = getSystem().getOrCreateClass(clName2);
final IEntity node = getSystem().createEntity(arg.get(SECOND_TYPE_AND_CLASS), "node",
EntityType.POINT_FOR_ASSOCIATION);
getSystem().insertBetween(entity1, entity2, node);
final IEntity cl1 = getSystem().getOrCreateClass(arg.get(FIRST_TYPE_AND_CLASS));
final LinkType linkType = getLinkType(arg);
final String queue = getQueue(arg);
final Link link = new Link(cl1, node, linkType, arg.get(LINK_LABEL), queue.length());
addLink(link, arg.get(0));
return CommandExecutionResult.ok();
}
private LinkType getLinkTypeNormal(List<String> arg) {
final String queue = arg.get(LEFT_TO_RIGHT_QUEUE).trim();
String key = arg.get(LEFT_TO_RIGHT_HEAD);
if (key != null) {
key = key.trim();
}
LinkType linkType = getLinkTypeFromKey(key);
if (queue.startsWith(".")) {
linkType = linkType.getDashed();
}
return linkType;
}
private LinkType getLinkTypeInv(List<String> arg) {
final String queue = arg.get(RIGHT_TO_LEFT_QUEUE).trim();
String key = arg.get(RIGHT_TO_LEFT_HEAD);
if (key != null) {
key = key.trim();
}
LinkType linkType = getLinkTypeFromKey(key);
if (queue.startsWith(".")) {
linkType = linkType.getDashed();
}
return linkType.getInv();
}
private LinkType getLinkType(List<String> arg) {
if (arg.get(LEFT_TO_RIGHT) != null) {
return getLinkTypeNormal(arg);
}
if (arg.get(RIGHT_TO_LEFT) != null) {
return getLinkTypeInv(arg);
}
if (arg.get(NAV_AGREG_OR_COMPO_INV) != null) {
final String type = arg.get(NAV_AGREG_OR_COMPO_INV_HEAD).trim();
final String queue = arg.get(NAV_AGREG_OR_COMPO_INV_QUEUE).trim();
LinkType result;
if (type.equals("*")) {
result = new LinkType(LinkDecor.COMPOSITION, LinkDecor.ARROW);
} else if (type.equals("o")) {
result = new LinkType(LinkDecor.AGREGATION, LinkDecor.ARROW);
} else {
throw new IllegalArgumentException();
}
if (queue.startsWith(".")) {
result = result.getDashed();
}
return result;
}
if (arg.get(NAV_AGREG_OR_COMPO) != null) {
final String type = arg.get(NAV_AGREG_OR_COMPO_HEAD).trim();
final String queue = arg.get(NAV_AGREG_OR_COMPO_QUEUE).trim();
LinkType result;
if (type.equals("*")) {
result = new LinkType(LinkDecor.ARROW, LinkDecor.COMPOSITION);
} else if (type.equals("o")) {
result = new LinkType(LinkDecor.ARROW, LinkDecor.AGREGATION);
} else {
throw new IllegalArgumentException();
}
if (queue.startsWith(".")) {
result = result.getDashed();
}
return result;
}
throw new IllegalArgumentException();
}
private String getQueue(List<String> arg) {
if (arg.get(LEFT_TO_RIGHT) != null) {
return arg.get(LEFT_TO_RIGHT_QUEUE).trim();
}
if (arg.get(RIGHT_TO_LEFT) != null) {
return arg.get(RIGHT_TO_LEFT_QUEUE).trim();
}
if (arg.get(NAV_AGREG_OR_COMPO_INV) != null) {
return arg.get(NAV_AGREG_OR_COMPO_INV_QUEUE).trim();
}
if (arg.get(NAV_AGREG_OR_COMPO) != null) {
return arg.get(NAV_AGREG_OR_COMPO_QUEUE).trim();
}
throw new IllegalArgumentException();
}
private LinkType getLinkTypeFromKey(String k) {
if (k == null) {
return new LinkType(LinkDecor.NONE, LinkDecor.NONE);
}
if (k.equals("+")) {
return new LinkType(LinkDecor.PLUS, LinkDecor.NONE);
}
if (k.equals("*")) {
return new LinkType(LinkDecor.COMPOSITION, LinkDecor.NONE);
}
if (k.equalsIgnoreCase("o")) {
return new LinkType(LinkDecor.AGREGATION, LinkDecor.NONE);
}
if (k.equals("<") || k.equals(">")) {
return new LinkType(LinkDecor.ARROW, LinkDecor.NONE);
}
if (k.equals("<|") || k.equals("|>")) {
return new LinkType(LinkDecor.EXTENDS, LinkDecor.NONE);
}
// return null;
throw new IllegalArgumentException(k);
}
}

View File

@ -0,0 +1,388 @@
/* ========================================================================
* 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: 5436 $
*
*/
package net.sourceforge.plantuml.classdiagram.command;
import java.util.Map;
import net.sourceforge.plantuml.Direction;
import net.sourceforge.plantuml.StringUtils;
import net.sourceforge.plantuml.UmlDiagramType;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand2;
import net.sourceforge.plantuml.command.regex.RegexConcat;
import net.sourceforge.plantuml.command.regex.RegexLeaf;
import net.sourceforge.plantuml.command.regex.RegexOr;
import net.sourceforge.plantuml.command.regex.RegexPartialMatch;
import net.sourceforge.plantuml.cucadiagram.Entity;
import net.sourceforge.plantuml.cucadiagram.EntityType;
import net.sourceforge.plantuml.cucadiagram.Group;
import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.LinkDecor;
import net.sourceforge.plantuml.cucadiagram.LinkType;
import net.sourceforge.plantuml.objectdiagram.AbstractClassOrObjectDiagram;
final public class CommandLinkClass2 extends SingleLineCommand2<AbstractClassOrObjectDiagram> {
public CommandLinkClass2(AbstractClassOrObjectDiagram diagram) {
super(diagram, getRegexConcat(diagram.getUmlDiagramType()));
}
static RegexConcat getRegexConcat(UmlDiagramType umlDiagramType) {
return new RegexConcat(
new RegexLeaf("HEADER", "^(?:@(\\d+)\\s+)?"),
new RegexOr(
new RegexLeaf("ENT1", "(?:" + optionalKeywords(umlDiagramType) + "\\s+)?"
+ "(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)"),
new RegexLeaf("COUPLE1",
"\\(\\s*(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s*,\\s*(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s*\\)")),
new RegexLeaf("\\s*"),
new RegexLeaf("FIRST_LABEL", "(?:\"([^\"]+)\")?"),
new RegexLeaf("\\s*"),
new RegexOr(new RegexLeaf("LEFT_TO_RIGHT",
"(([-=.]+)(left|right|up|down|le?|ri?|up?|do?)?([-=.]*)(o +|[\\]>*+]|\\|[>\\]])?)"),
new RegexLeaf("RIGHT_TO_LEFT",
"(( +o|[\\[<*+]|[<\\[]\\|)?([-=.]*)(left|right|up|down|le?|ri?|up?|do?)?([-=.]+))"),
new RegexLeaf("NAV_AGREG_OR_COMPO_INV",
"(\\<([-=.]*)(left|right|up|down|le?|ri?|up?|do?[-=.]+)?([-=.]+)(o +|\\*))"),
new RegexLeaf("NAV_AGREG_OR_COMPO",
"(( +o|\\*)([-=.]+)(left|right|up|down|le?|ri?|up?|do?)?([-=.]*)\\>)")),
new RegexLeaf("\\s*"),
new RegexLeaf("SECOND_LABEL", "(?:\"([^\"]+)\")?"),
new RegexLeaf("\\s*"),
new RegexOr(
new RegexLeaf("ENT2", "(?:" + optionalKeywords(umlDiagramType) + "\\s+)?"
+ "(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)"),
new RegexLeaf("COUPLE2",
"\\(\\s*(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s*,\\s*(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s*\\)")),
new RegexLeaf("\\s*"), new RegexLeaf("LABEL_LINK", "(?::\\s*([^\"]+))?$"));
}
private static String optionalKeywords(UmlDiagramType type) {
if (type == UmlDiagramType.CLASS) {
return "(interface|enum|abstract\\s+class|abstract|class)";
}
if (type == UmlDiagramType.OBJECT) {
return "(object)";
}
throw new IllegalArgumentException();
}
@Override
protected CommandExecutionResult executeArg(Map<String, RegexPartialMatch> arg) {
final String ent1 = arg.get("ENT1").get(1);
final String ent2 = arg.get("ENT2").get(1);
if (ent1 == null) {
return executeArgSpecial1(arg);
}
if (ent2 == null) {
return executeArgSpecial2(arg);
}
if (getSystem().isGroup(ent1) && getSystem().isGroup(ent2)) {
return executePackageLink(arg);
}
if (getSystem().isGroup(ent1) || getSystem().isGroup(ent2)) {
return CommandExecutionResult.error("Package can be only linked to other package");
}
final Entity cl1 = (Entity) getSystem().getOrCreateClass(ent1);
final Entity cl2 = (Entity) getSystem().getOrCreateClass(ent2);
if (arg.get("ENT1").get(0) != null) {
final EntityType type = EntityType.getEntityType(arg.get("ENT1").get(0));
if (type != EntityType.OBJECT) {
cl1.muteToType(type);
}
}
if (arg.get("ENT2").get(0) != null) {
final EntityType type = EntityType.getEntityType(arg.get("ENT2").get(0));
if (type != EntityType.OBJECT) {
cl2.muteToType(type);
}
}
final LinkType linkType = getLinkType(arg);
Direction dir = getDirection(arg);
final String queue;
if (dir == Direction.LEFT || dir == Direction.RIGHT) {
queue = "-";
} else {
queue = getQueue(arg);
}
if (dir != null && linkType.isExtendsOrAgregationOrCompositionOrPlus()) {
dir = dir.getInv();
}
Link link = new Link(cl1, cl2, linkType, arg.get("LABEL_LINK").get(0), queue.length(), arg.get("FIRST_LABEL")
.get(0), arg.get("SECOND_LABEL").get(0), getSystem().getLabeldistance(), getSystem().getLabelangle());
if (dir == Direction.LEFT || dir == Direction.UP) {
link = link.getInv();
}
// getSystem().resetPragmaLabel();
addLink(link, arg.get("HEADER").get(0));
return CommandExecutionResult.ok();
}
private void addLink(Link link, String arg0) {
getSystem().addLink(link);
if (arg0 == null) {
final LinkType type = link.getType();
// --|> highest
// --*, -->, --o normal
// ..*, ..>, ..o lowest
// if (type.isDashed() == false) {
// if (type.contains(LinkDecor.EXTENDS)) {
// link.setWeight(3);
// }
// if (type.contains(LinkDecor.ARROW) ||
// type.contains(LinkDecor.COMPOSITION)
// || type.contains(LinkDecor.AGREGATION)) {
// link.setWeight(2);
// }
// }
} else {
link.setWeight(Integer.parseInt(arg0));
}
}
private CommandExecutionResult executePackageLink(Map<String, RegexPartialMatch> arg) {
final String ent1 = arg.get("ENT1").get(1);
final String ent2 = arg.get("ENT2").get(1);
final Group cl1 = getSystem().getGroup(ent1);
final Group cl2 = getSystem().getGroup(ent2);
final LinkType linkType = getLinkType(arg);
final Direction dir = getDirection(arg);
final String queue;
if (dir == Direction.LEFT || dir == Direction.RIGHT) {
queue = "-";
} else {
queue = getQueue(arg);
}
Link link = new Link(cl1.getEntityCluster(), cl2.getEntityCluster(), linkType, arg.get("LABEL_LINK").get(
0), queue.length(), arg.get("FIRST_LABEL").get(0), arg.get("SECOND_LABEL").get(0), getSystem()
.getLabeldistance(), getSystem().getLabelangle());
if (dir == Direction.LEFT || dir == Direction.UP) {
link = link.getInv();
}
getSystem().resetPragmaLabel();
addLink(link, arg.get("HEADER").get(0));
return CommandExecutionResult.ok();
}
private CommandExecutionResult executeArgSpecial1(Map<String, RegexPartialMatch> arg) {
final String clName1 = arg.get("COUPLE1").get(0);
final String clName2 = arg.get("COUPLE1").get(1);
if (getSystem().entityExist(clName1) == false) {
return CommandExecutionResult.error("No class " + clName1);
}
if (getSystem().entityExist(clName2) == false) {
return CommandExecutionResult.error("No class " + clName2);
}
final Entity node = createAssociationPoint(clName1, clName2);
final String ent2 = arg.get("ENT2").get(1);
final IEntity cl2 = getSystem().getOrCreateClass(ent2);
final LinkType linkType = getLinkType(arg);
final String queue = getQueue(arg);
final Link link = new Link(node, cl2, linkType, arg.get("LABEL_LINK").get(0), queue.length());
addLink(link, arg.get("HEADER").get(0));
return CommandExecutionResult.ok();
}
private CommandExecutionResult executeArgSpecial2(Map<String, RegexPartialMatch> arg) {
final String clName1 = arg.get("COUPLE2").get(0);
final String clName2 = arg.get("COUPLE2").get(1);
if (getSystem().entityExist(clName1) == false) {
return CommandExecutionResult.error("No class " + clName1);
}
if (getSystem().entityExist(clName2) == false) {
return CommandExecutionResult.error("No class " + clName2);
}
final Entity node = createAssociationPoint(clName1, clName2);
final String ent1 = arg.get("ENT1").get(1);
final IEntity cl1 = getSystem().getOrCreateClass(ent1);
final LinkType linkType = getLinkType(arg);
final String queue = getQueue(arg);
final Link link = new Link(cl1, node, linkType, arg.get("LABEL_LINK").get(0), queue.length());
addLink(link, arg.get("HEADER").get(0));
return CommandExecutionResult.ok();
}
private Entity createAssociationPoint(final String clName1, final String clName2) {
final IEntity entity1 = getSystem().getOrCreateClass(clName1);
final IEntity entity2 = getSystem().getOrCreateClass(clName2);
final Entity node = getSystem().createEntity(clName1 + "," + clName2, "node", EntityType.POINT_FOR_ASSOCIATION);
getSystem().insertBetween(entity1, entity2, node);
return node;
}
private LinkType getLinkTypeNormal(RegexPartialMatch regexPartialMatch) {
final String queue = regexPartialMatch.get(1).trim() + regexPartialMatch.get(3).trim();
final String key = regexPartialMatch.get(4);
return getLinkType(queue, key);
}
private LinkType getLinkTypeInv(RegexPartialMatch regexPartialMatch) {
final String queue = regexPartialMatch.get(2).trim() + regexPartialMatch.get(4).trim();
final String key = regexPartialMatch.get(1);
return getLinkType(queue, key).getInv();
}
private LinkType getLinkType(String queue, String key) {
if (key != null) {
key = key.trim();
}
LinkType linkType = getLinkTypeFromKey(key);
if (queue.startsWith(".")) {
linkType = linkType.getDashed();
}
return linkType;
}
private LinkType getLinkType(Map<String, RegexPartialMatch> arg) {
if (arg.get("LEFT_TO_RIGHT").get(0) != null) {
return getLinkTypeNormal(arg.get("LEFT_TO_RIGHT"));
}
if (arg.get("RIGHT_TO_LEFT").get(0) != null) {
return getLinkTypeInv(arg.get("RIGHT_TO_LEFT"));
}
if (arg.get("NAV_AGREG_OR_COMPO_INV").get(0) != null) {
final String type = arg.get("NAV_AGREG_OR_COMPO_INV").get(4).trim();
final String queue = arg.get("NAV_AGREG_OR_COMPO_INV").get(1).trim()
+ arg.get("NAV_AGREG_OR_COMPO_INV").get(3).trim();
LinkType result;
if (type.equals("*")) {
result = new LinkType(LinkDecor.COMPOSITION, LinkDecor.ARROW);
} else if (type.equals("o")) {
result = new LinkType(LinkDecor.AGREGATION, LinkDecor.ARROW);
} else {
throw new IllegalArgumentException();
}
if (queue.startsWith(".")) {
result = result.getDashed();
}
return result;
}
if (arg.get("NAV_AGREG_OR_COMPO").get(0) != null) {
final String type = arg.get("NAV_AGREG_OR_COMPO").get(1).trim();
final String queue = arg.get("NAV_AGREG_OR_COMPO").get(2).trim()
+ arg.get("NAV_AGREG_OR_COMPO").get(4).trim();
LinkType result;
if (type.equals("*")) {
result = new LinkType(LinkDecor.ARROW, LinkDecor.COMPOSITION);
} else if (type.equals("o")) {
result = new LinkType(LinkDecor.ARROW, LinkDecor.AGREGATION);
} else {
throw new IllegalArgumentException();
}
if (queue.startsWith(".")) {
result = result.getDashed();
}
return result;
}
throw new IllegalArgumentException();
}
private String getQueue(Map<String, RegexPartialMatch> arg) {
if (arg.get("LEFT_TO_RIGHT").get(1) != null) {
return arg.get("LEFT_TO_RIGHT").get(1).trim() + arg.get("LEFT_TO_RIGHT").get(3).trim();
}
if (arg.get("RIGHT_TO_LEFT").get(2) != null) {
return arg.get("RIGHT_TO_LEFT").get(2).trim() + arg.get("RIGHT_TO_LEFT").get(4).trim();
}
if (arg.get("NAV_AGREG_OR_COMPO_INV").get(1) != null) {
return arg.get("NAV_AGREG_OR_COMPO_INV").get(1).trim() + arg.get("NAV_AGREG_OR_COMPO_INV").get(3).trim();
}
if (arg.get("NAV_AGREG_OR_COMPO").get(2) != null) {
return arg.get("NAV_AGREG_OR_COMPO").get(2).trim() + arg.get("NAV_AGREG_OR_COMPO").get(4).trim();
}
throw new IllegalArgumentException();
}
private Direction getDirection(Map<String, RegexPartialMatch> arg) {
if (arg.get("LEFT_TO_RIGHT").get(2) != null) {
return StringUtils.getQueueDirection(arg.get("LEFT_TO_RIGHT").get(2));
}
if (arg.get("RIGHT_TO_LEFT").get(3) != null) {
return StringUtils.getQueueDirection(arg.get("RIGHT_TO_LEFT").get(3)).getInv();
}
if (arg.get("NAV_AGREG_OR_COMPO").get(3) != null) {
return StringUtils.getQueueDirection(arg.get("NAV_AGREG_OR_COMPO").get(3)).getInv();
}
if (arg.get("NAV_AGREG_OR_COMPO_INV").get(2) != null) {
return StringUtils.getQueueDirection(arg.get("NAV_AGREG_OR_COMPO_INV").get(2));
}
return null;
}
private LinkType getLinkTypeFromKey(String k) {
if (k == null) {
return new LinkType(LinkDecor.NONE, LinkDecor.NONE);
}
if (k.equals("+")) {
return new LinkType(LinkDecor.PLUS, LinkDecor.NONE);
}
if (k.equals("*")) {
return new LinkType(LinkDecor.COMPOSITION, LinkDecor.NONE);
}
if (k.equalsIgnoreCase("o")) {
return new LinkType(LinkDecor.AGREGATION, LinkDecor.NONE);
}
if (k.equals("<") || k.equals(">")) {
return new LinkType(LinkDecor.ARROW, LinkDecor.NONE);
}
if (k.equals("<|") || k.equals("|>")) {
return new LinkType(LinkDecor.EXTENDS, LinkDecor.NONE);
}
// return null;
throw new IllegalArgumentException(k);
}
}

View File

@ -0,0 +1,242 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 5075 $
*
*/
package net.sourceforge.plantuml.classdiagram.command;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import net.sourceforge.plantuml.UniqueSequence;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand;
import net.sourceforge.plantuml.cucadiagram.Entity;
import net.sourceforge.plantuml.cucadiagram.EntityType;
import net.sourceforge.plantuml.cucadiagram.Group;
import net.sourceforge.plantuml.cucadiagram.IEntity;
import net.sourceforge.plantuml.cucadiagram.Link;
import net.sourceforge.plantuml.cucadiagram.LinkDecor;
import net.sourceforge.plantuml.cucadiagram.LinkType;
import net.sourceforge.plantuml.objectdiagram.AbstractClassOrObjectDiagram;
final public class CommandLinkLollipop extends SingleLineCommand<AbstractClassOrObjectDiagram> {
private static final int OFFSET = 1;
private static final int FIRST_TYPE_AND_CLASS = 0 + OFFSET;
private static final int FIRST_TYPE = 1 + OFFSET;
private static final int FIRST_CLASS = 2 + OFFSET;
private static final int FIRST_LABEL = 3 + OFFSET;
private static final int LINK1 = 4 + OFFSET;
private static final int LINK2 = 5 + OFFSET;
private static final int SECOND_LABEL = 6 + OFFSET;
private static final int SECOND_TYPE_AND_CLASS = 7 + OFFSET;
private static final int SECOND_TYPE = 8 + OFFSET;
private static final int SECOND_CLASS = 9 + OFFSET;
private static final int LINK_LABEL = 10 + OFFSET;
private final Pattern patternAssociationPoint = Pattern
.compile("\\(\\s*(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s*,\\s*(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s*\\)");
public CommandLinkLollipop(AbstractClassOrObjectDiagram diagram) {
super(
diagram,
"(?i)^(?:@(\\d+)\\s+)?((?:(interface|enum|abstract\\s+class|abstract|class)\\s+)?(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)|\\(\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*,\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*\\))\\s*(?:\"([^\"]+)\")?\\s*"
// +
// "(?:(([-=.]+)([\\]>o*+]|\\|[>\\]])?)|(([\\[<o*+]|[<\\[]\\|)?([-=.]+))|(\\<([-=.]+)([o*]))|(([o*])([-=.]+)\\>))"
+ "(?:\\(\\)([-=.]+)|([-=.]+)\\(\\))"
+ "\\s*(?:\"([^\"]+)\")?\\s*((?:(interface|enum|abstract\\s+class|abstract|class)\\s+)?(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)|\\(\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*,\\s*\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*\\s*\\))\\s*(?::\\s*([^\"]+))?$");
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
if (arg.get(FIRST_TYPE_AND_CLASS).startsWith("(")) {
return executeArgSpecial1(arg);
}
if (arg.get(SECOND_TYPE_AND_CLASS).startsWith("(")) {
return executeArgSpecial2(arg);
}
if (getSystem().isGroup(arg.get(FIRST_CLASS)) && getSystem().isGroup(arg.get(SECOND_CLASS))) {
return executePackageLink(arg);
}
if (getSystem().isGroup(arg.get(FIRST_CLASS)) || getSystem().isGroup(arg.get(SECOND_CLASS))) {
return CommandExecutionResult.error("Package can be only linked to other package");
}
final Entity cl1;
final Entity cl2;
final Entity normalEntity;
final String suffix = "lol" + UniqueSequence.getValue();
if (arg.get(LINK1) != null) {
cl2 = (Entity) getSystem().getOrCreateClass(arg.get(SECOND_CLASS));
cl1 = getSystem().createEntity(cl2.getCode() + suffix, arg.get(FIRST_CLASS), EntityType.LOLLIPOP);
normalEntity = cl2;
} else {
assert arg.get(LINK2) != null;
cl1 = (Entity) getSystem().getOrCreateClass(arg.get(FIRST_CLASS));
cl2 = getSystem().createEntity(cl1.getCode() + suffix, arg.get(SECOND_CLASS), EntityType.LOLLIPOP);
normalEntity = cl1;
}
final LinkType linkType = getLinkType(arg);
final String queue = getQueue(arg);
int length = queue.length();
if (length == 1 && getSystem().getNbOfHozizontalLollipop(normalEntity) > 1) {
length++;
}
final Link link = new Link(cl1, cl2, linkType, arg.get(LINK_LABEL), length, arg.get(FIRST_LABEL), arg
.get(SECOND_LABEL), getSystem().getLabeldistance(), getSystem().getLabelangle());
getSystem().resetPragmaLabel();
addLink(link, arg.get(0));
return CommandExecutionResult.ok();
}
private String getQueue(List<String> arg) {
if (arg.get(LINK1) != null) {
return arg.get(LINK1);
}
if (arg.get(LINK2) != null) {
return arg.get(LINK2);
}
throw new IllegalArgumentException();
}
private LinkType getLinkType(List<String> arg) {
return new LinkType(LinkDecor.NONE, LinkDecor.NONE);
}
private void addLink(Link link, String arg0) {
getSystem().addLink(link);
if (arg0 == null) {
final LinkType type = link.getType();
// --|> highest
// --*, -->, --o normal
// ..*, ..>, ..o lowest
// if (type.isDashed() == false) {
// if (type.contains(LinkDecor.EXTENDS)) {
// link.setWeight(3);
// }
// if (type.contains(LinkDecor.ARROW) ||
// type.contains(LinkDecor.COMPOSITION)
// || type.contains(LinkDecor.AGREGATION)) {
// link.setWeight(2);
// }
// }
} else {
link.setWeight(Integer.parseInt(arg0));
}
}
private CommandExecutionResult executePackageLink(List<String> arg) {
final Group cl1 = getSystem().getGroup(arg.get(FIRST_CLASS));
final Group cl2 = getSystem().getGroup(arg.get(SECOND_CLASS));
final LinkType linkType = getLinkType(arg);
final String queue = getQueue(arg);
final Link link = new Link(cl1.getEntityCluster(), cl2.getEntityCluster(), linkType, arg.get(LINK_LABEL), queue
.length(), arg.get(FIRST_LABEL), arg.get(SECOND_LABEL), getSystem().getLabeldistance(), getSystem()
.getLabelangle());
getSystem().resetPragmaLabel();
addLink(link, arg.get(0));
return CommandExecutionResult.ok();
}
private CommandExecutionResult executeArgSpecial1(List<String> arg) {
final Matcher m = patternAssociationPoint.matcher(arg.get(FIRST_TYPE_AND_CLASS));
if (m.matches() == false) {
throw new IllegalStateException();
}
final String clName1 = m.group(1);
final String clName2 = m.group(2);
if (getSystem().entityExist(clName1) == false) {
return CommandExecutionResult.error("No class " + clName1);
}
if (getSystem().entityExist(clName2) == false) {
return CommandExecutionResult.error("No class " + clName2);
}
final IEntity entity1 = getSystem().getOrCreateClass(clName1);
final IEntity entity2 = getSystem().getOrCreateClass(clName2);
final Entity node = getSystem().createEntity(arg.get(FIRST_TYPE_AND_CLASS), "node",
EntityType.POINT_FOR_ASSOCIATION);
getSystem().insertBetween(entity1, entity2, node);
final IEntity cl2 = getSystem().getOrCreateClass(arg.get(SECOND_CLASS));
final LinkType linkType = getLinkType(arg);
final String queue = getQueue(arg);
final Link link = new Link(node, cl2, linkType, arg.get(LINK_LABEL), queue.length());
addLink(link, arg.get(0));
return CommandExecutionResult.ok();
}
private CommandExecutionResult executeArgSpecial2(List<String> arg) {
final Matcher m = patternAssociationPoint.matcher(arg.get(SECOND_TYPE_AND_CLASS));
if (m.matches() == false) {
throw new IllegalStateException();
}
final String clName1 = m.group(1);
final String clName2 = m.group(2);
if (getSystem().entityExist(clName1) == false) {
return CommandExecutionResult.error("No class " + clName1);
}
if (getSystem().entityExist(clName2) == false) {
return CommandExecutionResult.error("No class " + clName2);
}
final IEntity entity1 = getSystem().getOrCreateClass(clName1);
final IEntity entity2 = getSystem().getOrCreateClass(clName2);
final IEntity node = getSystem().createEntity(arg.get(SECOND_TYPE_AND_CLASS), "node",
EntityType.POINT_FOR_ASSOCIATION);
getSystem().insertBetween(entity1, entity2, node);
final IEntity cl1 = getSystem().getOrCreateClass(arg.get(FIRST_TYPE_AND_CLASS));
final LinkType linkType = getLinkType(arg);
final String queue = getQueue(arg);
final Link link = new Link(cl1, node, linkType, arg.get(LINK_LABEL), queue.length());
addLink(link, arg.get(0));
return CommandExecutionResult.ok();
}
}

View File

@ -0,0 +1,45 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4239 $
*
*/
package net.sourceforge.plantuml.classdiagram.command;
import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram;
import net.sourceforge.plantuml.command.AbstractCommandMultilinesNoteEntity;
public class CommandMultilinesClassNote extends AbstractCommandMultilinesNoteEntity {
public CommandMultilinesClassNote(final AbstractEntityDiagram system) {
super(system, "(?i)^note\\s+(right|left|top|bottom)\\s+(?:of\\s+)?([\\p{L}0-9_.]+)\\s*(#\\w+)?$");
}
}

View File

@ -0,0 +1,64 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 3979 $
*
*/
package net.sourceforge.plantuml.classdiagram.command;
import java.util.List;
import net.sourceforge.plantuml.classdiagram.ClassDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand;
import net.sourceforge.plantuml.cucadiagram.Group;
import net.sourceforge.plantuml.cucadiagram.GroupType;
import net.sourceforge.plantuml.graphic.HtmlColor;
public class CommandNamespace extends SingleLineCommand<ClassDiagram> {
public CommandNamespace(ClassDiagram diagram) {
super(diagram, "(?i)^namespace\\s+([\\p{L}0-9_][\\p{L}0-9_.]*)\\s*(#[0-9a-fA-F]{6}|\\w+)?\\s*\\{?$");
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
final String code = arg.get(0);
final Group currentPackage = getSystem().getCurrentGroup();
final Group p = getSystem().getOrCreateGroup(code, code, code, GroupType.PACKAGE, currentPackage);
p.setBold(true);
final String color = arg.get(1);
if (color != null) {
p.setBackColor(new HtmlColor(color));
}
return CommandExecutionResult.ok();
}
}

View File

@ -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: 5019 $
*
*/
package net.sourceforge.plantuml.classdiagram.command;
import java.util.List;
import net.sourceforge.plantuml.FontParam;
import net.sourceforge.plantuml.classdiagram.ClassDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand;
import net.sourceforge.plantuml.cucadiagram.Entity;
import net.sourceforge.plantuml.cucadiagram.Stereotype;
public class CommandStereotype extends SingleLineCommand<ClassDiagram> {
public CommandStereotype(ClassDiagram classDiagram) {
super(classDiagram, "(?i)^([\\p{L}0-9_.]+)\\s*(\\<\\<.*\\>\\>)$");
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
final String code = arg.get(0);
final String stereotype = arg.get(1);
final Entity entity = (Entity) getSystem().getOrCreateClass(code);
entity.setStereotype(new Stereotype(stereotype, getSystem().getSkinParam().getCircledCharacterRadius(),
getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER)));
return CommandExecutionResult.ok();
}
}

View File

@ -0,0 +1,58 @@
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
* (C) Copyright 2009, Arnaud Roques
*
* Project Info: http://plantuml.sourceforge.net
*
* This file is part of PlantUML.
*
* PlantUML is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PlantUML distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
* License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
*
* Revision $Revision: 4161 $
*
*/
package net.sourceforge.plantuml.classdiagram.command;
import java.util.List;
import net.sourceforge.plantuml.classdiagram.ClassDiagram;
import net.sourceforge.plantuml.command.CommandExecutionResult;
import net.sourceforge.plantuml.command.SingleLineCommand;
import net.sourceforge.plantuml.cucadiagram.Entity;
public class CommandUrl extends SingleLineCommand<ClassDiagram> {
public CommandUrl(ClassDiagram classDiagram) {
super(classDiagram, "(?i)^url\\s*(?:of|for)?\\s+([\\p{L}0-9_.]+)\\s+(?:is)?\\s*\\[\\[(.*)\\]\\]$");
}
@Override
protected CommandExecutionResult executeArg(List<String> arg) {
final String code = arg.get(0);
final String url = arg.get(1);
final Entity entity = (Entity) getSystem().getOrCreateClass(code);
entity.setUrl(url);
return CommandExecutionResult.ok();
}
}

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