diff --git a/src/com/ctreber/acearth/plugins/markers/Marker.java b/src/com/ctreber/acearth/plugins/markers/Marker.java index d059db43b..5b8b0d86b 100644 --- a/src/com/ctreber/acearth/plugins/markers/Marker.java +++ b/src/com/ctreber/acearth/plugins/markers/Marker.java @@ -3,10 +3,6 @@ package com.ctreber.acearth.plugins.markers; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; -import java.io.FileReader; -import java.io.IOException; -import java.io.LineNumberReader; -import java.util.ArrayList; import java.util.List; import com.ctreber.acearth.gui.PixelCanvas; diff --git a/src/com/ctreber/acearth/plugins/markers/PluginMarkers.java b/src/com/ctreber/acearth/plugins/markers/PluginMarkers.java index b3b7f5f1b..1bc826a4c 100644 --- a/src/com/ctreber/acearth/plugins/markers/PluginMarkers.java +++ b/src/com/ctreber/acearth/plugins/markers/PluginMarkers.java @@ -1,10 +1,8 @@ package com.ctreber.acearth.plugins.markers; -import java.io.IOException; import java.util.Iterator; import java.util.List; -import com.ctreber.acearth.ACearth; import com.ctreber.acearth.plugins.Plugin; /** diff --git a/src/com/ctreber/acearth/projection/Projection.java b/src/com/ctreber/acearth/projection/Projection.java index bae3534f5..0b56eb061 100644 --- a/src/com/ctreber/acearth/projection/Projection.java +++ b/src/com/ctreber/acearth/projection/Projection.java @@ -1,6 +1,9 @@ package com.ctreber.acearth.projection; -import com.ctreber.acearth.util.*; +import com.ctreber.acearth.util.Coordinate; +import com.ctreber.acearth.util.Point2D; +import com.ctreber.acearth.util.Point3D; +import com.ctreber.acearth.util.Toolkit; /** *

A projection for a globe on a flat surface (must be subclassed). diff --git a/src/com/ctreber/acearth/renderer/Renderer.java b/src/com/ctreber/acearth/renderer/Renderer.java index eca8905ba..a007d1e37 100644 --- a/src/com/ctreber/acearth/renderer/Renderer.java +++ b/src/com/ctreber/acearth/renderer/Renderer.java @@ -1,7 +1,8 @@ package com.ctreber.acearth.renderer; -import java.awt.*; -import java.util.*; +import java.awt.Color; +import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import com.ctreber.acearth.shader.Shader; diff --git a/src/com/ctreber/acearth/renderer/RowTypeRendererScanBit.java b/src/com/ctreber/acearth/renderer/RowTypeRendererScanBit.java index 8ae020f6f..216c8b061 100644 --- a/src/com/ctreber/acearth/renderer/RowTypeRendererScanBit.java +++ b/src/com/ctreber/acearth/renderer/RowTypeRendererScanBit.java @@ -1,7 +1,7 @@ package com.ctreber.acearth.renderer; -import com.ctreber.acearth.scanbit.ScanBit; import com.ctreber.acearth.scanbit.BitGeneratorMap; +import com.ctreber.acearth.scanbit.ScanBit; /** *

Renders a row of ScanBits to pixel types.

diff --git a/src/com/ctreber/acearth/scanbit/BitGeneratorMap.java b/src/com/ctreber/acearth/scanbit/BitGeneratorMap.java index be84ee7e8..daeed0a36 100644 --- a/src/com/ctreber/acearth/scanbit/BitGeneratorMap.java +++ b/src/com/ctreber/acearth/scanbit/BitGeneratorMap.java @@ -1,9 +1,14 @@ package com.ctreber.acearth.scanbit; -import java.util.*; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; import com.ctreber.acearth.projection.Projection; -import com.ctreber.acearth.util.*; +import com.ctreber.acearth.util.EdgeCrossing; +import com.ctreber.acearth.util.Point2D; +import com.ctreber.acearth.util.Point3D; +import com.ctreber.acearth.util.Polygon; import com.ctreber.aclib.sort.CTSort; import com.ctreber.aclib.sort.QuickSort; diff --git a/src/com/ctreber/acearth/scanbit/BitGeneratorMapDefault.java b/src/com/ctreber/acearth/scanbit/BitGeneratorMapDefault.java index 2defe754f..2a069e86d 100644 --- a/src/com/ctreber/acearth/scanbit/BitGeneratorMapDefault.java +++ b/src/com/ctreber/acearth/scanbit/BitGeneratorMapDefault.java @@ -3,7 +3,9 @@ package com.ctreber.acearth.scanbit; import java.util.Comparator; import com.ctreber.acearth.projection.Projection; -import com.ctreber.acearth.util.*; +import com.ctreber.acearth.util.EdgeCrossing; +import com.ctreber.acearth.util.Point2D; +import com.ctreber.acearth.util.Point3D; /** *

Map scanner for mercator and cylindrical projections. diff --git a/src/com/ctreber/acearth/scanbit/BitGeneratorMapOrtho.java b/src/com/ctreber/acearth/scanbit/BitGeneratorMapOrtho.java index 7a069746a..75ddef020 100644 --- a/src/com/ctreber/acearth/scanbit/BitGeneratorMapOrtho.java +++ b/src/com/ctreber/acearth/scanbit/BitGeneratorMapOrtho.java @@ -3,7 +3,9 @@ package com.ctreber.acearth.scanbit; import java.util.Comparator; import com.ctreber.acearth.projection.Projection; -import com.ctreber.acearth.util.*; +import com.ctreber.acearth.util.EdgeCrossing; +import com.ctreber.acearth.util.Point2D; +import com.ctreber.acearth.util.Point3D; /** *

Map scanner for orthographic projection. diff --git a/src/com/ctreber/acearth/scandot/DotGeneratorLines.java b/src/com/ctreber/acearth/scandot/DotGeneratorLines.java index f544a8f8c..05da3be69 100644 --- a/src/com/ctreber/acearth/scandot/DotGeneratorLines.java +++ b/src/com/ctreber/acearth/scandot/DotGeneratorLines.java @@ -1,7 +1,9 @@ package com.ctreber.acearth.scandot; import com.ctreber.acearth.projection.Projection; -import com.ctreber.acearth.util.*; +import com.ctreber.acearth.util.Coordinate; +import com.ctreber.acearth.util.Point2D; +import com.ctreber.acearth.util.Point3D; /** *

Generate latitude and longitude grid as dots. diff --git a/src/com/ctreber/acearth/shader/Shader.java b/src/com/ctreber/acearth/shader/Shader.java index 3be67ed4a..26634a7d7 100644 --- a/src/com/ctreber/acearth/shader/Shader.java +++ b/src/com/ctreber/acearth/shader/Shader.java @@ -1,6 +1,6 @@ package com.ctreber.acearth.shader; -import java.awt.*; +import java.awt.Color; import com.ctreber.acearth.projection.Projection; import com.ctreber.acearth.scanbit.BitGeneratorMap; diff --git a/src/com/ctreber/acearth/shader/ShaderDefault.java b/src/com/ctreber/acearth/shader/ShaderDefault.java index 1aa561352..5dab763d0 100644 --- a/src/com/ctreber/acearth/shader/ShaderDefault.java +++ b/src/com/ctreber/acearth/shader/ShaderDefault.java @@ -1,6 +1,6 @@ package com.ctreber.acearth.shader; -import java.awt.*; +import java.awt.Color; /** *

Shader for projections which display the whole surface.

diff --git a/src/com/ctreber/acearth/shader/ShaderFlat.java b/src/com/ctreber/acearth/shader/ShaderFlat.java index 18fab74af..203790a64 100644 --- a/src/com/ctreber/acearth/shader/ShaderFlat.java +++ b/src/com/ctreber/acearth/shader/ShaderFlat.java @@ -1,6 +1,6 @@ package com.ctreber.acearth.shader; -import java.awt.*; +import java.awt.Color; /** *

Flat shader (does not care for Projection).

diff --git a/src/com/ctreber/acearth/shader/ShaderOrtho.java b/src/com/ctreber/acearth/shader/ShaderOrtho.java index 227523fb5..b4e3046aa 100644 --- a/src/com/ctreber/acearth/shader/ShaderOrtho.java +++ b/src/com/ctreber/acearth/shader/ShaderOrtho.java @@ -1,6 +1,6 @@ package com.ctreber.acearth.shader; -import java.awt.*; +import java.awt.Color; /** *

Shader for the orthographic projection.

diff --git a/src/com/ctreber/acearth/util/SunPositionCalculator.java b/src/com/ctreber/acearth/util/SunPositionCalculator.java index 9054a30a4..8df1d0d2b 100644 --- a/src/com/ctreber/acearth/util/SunPositionCalculator.java +++ b/src/com/ctreber/acearth/util/SunPositionCalculator.java @@ -1,6 +1,8 @@ package com.ctreber.acearth.util; -import java.util.*; +import java.util.Calendar; +import java.util.Date; +import java.util.TimeZone; /** *

Calculates the position of the point on Earth which is directly diff --git a/src/doc-files/umls.html b/src/doc-files/umls.html new file mode 100644 index 000000000..dfb93c1f7 --- /dev/null +++ b/src/doc-files/umls.html @@ -0,0 +1,40 @@ + + +@startuml img1.png +title foo2 +component PlantUML +@enduml + + + diff --git a/src/jcckit/data/DataContainer.java b/src/jcckit/data/DataContainer.java index 444cf7299..831ad0b32 100644 --- a/src/jcckit/data/DataContainer.java +++ b/src/jcckit/data/DataContainer.java @@ -18,8 +18,8 @@ */ package jcckit.data; -import java.text.*; -import java.util.*; +import java.text.MessageFormat; +import java.util.Vector; /** * Abstract superclass of all data containers. A data container holds an diff --git a/src/jcckit/data/DataPlot.java b/src/jcckit/data/DataPlot.java index 43511d52e..4ebf14f94 100644 --- a/src/jcckit/data/DataPlot.java +++ b/src/jcckit/data/DataPlot.java @@ -18,10 +18,10 @@ */ package jcckit.data; -import jcckit.util.ConfigParameters; - import java.util.StringTokenizer; +import jcckit.util.ConfigParameters; + /** * A plot is a {@link DataContainer} of {@link DataCurve DataCurves}. * diff --git a/src/jcckit/graphic/BasicGraphicAttributes.java b/src/jcckit/graphic/BasicGraphicAttributes.java index 251dc7946..5b63ff161 100644 --- a/src/jcckit/graphic/BasicGraphicAttributes.java +++ b/src/jcckit/graphic/BasicGraphicAttributes.java @@ -18,10 +18,10 @@ */ package jcckit.graphic; -import jcckit.util.ConfigParameters; - import java.awt.Color; +import jcckit.util.ConfigParameters; + /** * The basic attributes of any {@link BasicGraphicalElement}. This is an * extension of {@link ShapeAttributes} implementing {@link TextAttributes}. diff --git a/src/jcckit/graphic/FontStyle.java b/src/jcckit/graphic/FontStyle.java index fb3d5d90e..7c037d9c3 100644 --- a/src/jcckit/graphic/FontStyle.java +++ b/src/jcckit/graphic/FontStyle.java @@ -18,11 +18,11 @@ */ package jcckit.graphic; +import java.util.Hashtable; + import jcckit.util.ConfigParameters; import jcckit.util.FactoryException; -import java.util.Hashtable; - /** * Font style constants. * This class is based on the typesafe enumeration pattern. diff --git a/src/jcckit/graphic/ShapeAttributes.java b/src/jcckit/graphic/ShapeAttributes.java index 23e14d13f..362f3037d 100644 --- a/src/jcckit/graphic/ShapeAttributes.java +++ b/src/jcckit/graphic/ShapeAttributes.java @@ -18,10 +18,10 @@ */ package jcckit.graphic; -import jcckit.util.ConfigParameters; - import java.awt.Color; +import jcckit.util.ConfigParameters; + /** * Basic attributes for shapes. * diff --git a/src/jcckit/plot/BarFactory.java b/src/jcckit/plot/BarFactory.java index 4f8e4c98b..6a452a1e6 100644 --- a/src/jcckit/plot/BarFactory.java +++ b/src/jcckit/plot/BarFactory.java @@ -18,6 +18,7 @@ */ package jcckit.plot; +import jcckit.graphic.ClippingShape; import jcckit.graphic.GraphPoint; import jcckit.graphic.GraphicAttributes; import jcckit.graphic.GraphicalElement; diff --git a/src/jcckit/plot/CartesianCoordinateSystem.java b/src/jcckit/plot/CartesianCoordinateSystem.java index 36fd2c73f..dbfaae8db 100644 --- a/src/jcckit/plot/CartesianCoordinateSystem.java +++ b/src/jcckit/plot/CartesianCoordinateSystem.java @@ -21,10 +21,10 @@ package jcckit.plot; import jcckit.data.DataPoint; import jcckit.graphic.ClippingRectangle; import jcckit.graphic.ClippingShape; +import jcckit.graphic.GraphPoint; +import jcckit.graphic.GraphicAttributes; import jcckit.graphic.GraphicalComposite; import jcckit.graphic.GraphicalElement; -import jcckit.graphic.GraphicAttributes; -import jcckit.graphic.GraphPoint; import jcckit.graphic.LineAttributes; import jcckit.graphic.Polygon; import jcckit.graphic.Text; diff --git a/src/jcckit/plot/CircleSymbolFactory.java b/src/jcckit/plot/CircleSymbolFactory.java index 6b3f4246d..b9eb9a6b9 100644 --- a/src/jcckit/plot/CircleSymbolFactory.java +++ b/src/jcckit/plot/CircleSymbolFactory.java @@ -18,9 +18,9 @@ */ package jcckit.plot; +import jcckit.graphic.GraphPoint; import jcckit.graphic.GraphicAttributes; import jcckit.graphic.GraphicalElement; -import jcckit.graphic.GraphPoint; import jcckit.graphic.Oval; import jcckit.util.ConfigParameters; diff --git a/src/jcckit/plot/CoordinateSystem.java b/src/jcckit/plot/CoordinateSystem.java index 62aeb7e35..11ac62838 100644 --- a/src/jcckit/plot/CoordinateSystem.java +++ b/src/jcckit/plot/CoordinateSystem.java @@ -18,8 +18,8 @@ */ package jcckit.plot; -import jcckit.graphic.GraphicalElement; import jcckit.graphic.ClippingShape; +import jcckit.graphic.GraphicalElement; import jcckit.transformation.Transformation; /** diff --git a/src/jcckit/plot/Curve.java b/src/jcckit/plot/Curve.java index 47b1bb866..03cb3cb78 100644 --- a/src/jcckit/plot/Curve.java +++ b/src/jcckit/plot/Curve.java @@ -18,8 +18,8 @@ */ package jcckit.plot; -import jcckit.graphic.GraphicalElement; import jcckit.graphic.GraphPoint; +import jcckit.graphic.GraphicalElement; /** * A curve is defined by a sequence of points in device-independent diff --git a/src/jcckit/plot/Legend.java b/src/jcckit/plot/Legend.java index aa5f93418..3feea40c8 100644 --- a/src/jcckit/plot/Legend.java +++ b/src/jcckit/plot/Legend.java @@ -18,11 +18,13 @@ */ package jcckit.plot; +import java.util.Properties; + import jcckit.graphic.BasicGraphicAttributes; -import jcckit.graphic.GraphicalElement; -import jcckit.graphic.GraphicalComposite; -import jcckit.graphic.GraphicAttributes; import jcckit.graphic.GraphPoint; +import jcckit.graphic.GraphicAttributes; +import jcckit.graphic.GraphicalComposite; +import jcckit.graphic.GraphicalElement; import jcckit.graphic.Polygon; import jcckit.graphic.Rectangle; import jcckit.graphic.ShapeAttributes; @@ -34,8 +36,6 @@ import jcckit.util.ConfigParametersBasedConfigData; import jcckit.util.Factory; import jcckit.util.PropertiesBasedConfigData; -import java.util.Properties; - /** * Helper class for creating the legend of a {@link Plot}. diff --git a/src/jcckit/plot/SquareSymbolFactory.java b/src/jcckit/plot/SquareSymbolFactory.java index 10eecb751..4dc377268 100644 --- a/src/jcckit/plot/SquareSymbolFactory.java +++ b/src/jcckit/plot/SquareSymbolFactory.java @@ -18,9 +18,9 @@ */ package jcckit.plot; +import jcckit.graphic.GraphPoint; import jcckit.graphic.GraphicAttributes; import jcckit.graphic.GraphicalElement; -import jcckit.graphic.GraphPoint; import jcckit.graphic.Rectangle; import jcckit.util.ConfigParameters; diff --git a/src/jcckit/plot/SymbolFactory.java b/src/jcckit/plot/SymbolFactory.java index 605275e13..d354bc095 100644 --- a/src/jcckit/plot/SymbolFactory.java +++ b/src/jcckit/plot/SymbolFactory.java @@ -18,8 +18,8 @@ */ package jcckit.plot; -import jcckit.graphic.GraphicalElement; import jcckit.graphic.GraphPoint; +import jcckit.graphic.GraphicalElement; /** * Interface of a symbol factory. A symbol is a {@link GraphicalElement} diff --git a/src/jcckit/renderer/Transformation.java b/src/jcckit/renderer/Transformation.java index beea06ad2..1277c2e7e 100644 --- a/src/jcckit/renderer/Transformation.java +++ b/src/jcckit/renderer/Transformation.java @@ -21,8 +21,8 @@ package jcckit.renderer; import java.awt.Graphics2D; import jcckit.graphic.Anchor; -import jcckit.graphic.GraphPoint; import jcckit.graphic.ClippingRectangle; +import jcckit.graphic.GraphPoint; /** * Transformation between device-independent coordinates diff --git a/src/jcckit/util/ConfigParameters.java b/src/jcckit/util/ConfigParameters.java index 6936be490..331d874e0 100644 --- a/src/jcckit/util/ConfigParameters.java +++ b/src/jcckit/util/ConfigParameters.java @@ -22,6 +22,7 @@ import java.awt.Color; import java.util.StringTokenizer; import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity; /** @@ -300,8 +301,8 @@ public class ConfigParameters { } private Color decodeInternal(String value) { - if (HtmlColor.isValid(value)) { - return new ColorMapperIdentity().getMappedColor(HtmlColor.getColorIfValid(value)); + if (HtmlColorUtils.getColorIfValid(value)!=null) { + return new ColorMapperIdentity().getMappedColor(HtmlColorUtils.getColorIfValid(value)); } return Color.decode(value); } diff --git a/src/jcckit/util/Factory.java b/src/jcckit/util/Factory.java index d3b82562d..240f8befe 100644 --- a/src/jcckit/util/Factory.java +++ b/src/jcckit/util/Factory.java @@ -18,7 +18,7 @@ */ package jcckit.util; -import java.lang.reflect.*; +import java.lang.reflect.Constructor; /** * General purpose factory method based on {@link ConfigParameters} diff --git a/src/jcckit/util/FactoryException.java b/src/jcckit/util/FactoryException.java index e33f325b9..28d0f39e9 100644 --- a/src/jcckit/util/FactoryException.java +++ b/src/jcckit/util/FactoryException.java @@ -18,7 +18,7 @@ */ package jcckit.util; -import java.lang.reflect.*; +import java.lang.reflect.InvocationTargetException; /** * Exception thrown in the case of an error during creation of a new diff --git a/src/jcckit/util/PropertiesBasedConfigData.java b/src/jcckit/util/PropertiesBasedConfigData.java index 6ecdd1f11..1d5bcc436 100644 --- a/src/jcckit/util/PropertiesBasedConfigData.java +++ b/src/jcckit/util/PropertiesBasedConfigData.java @@ -18,7 +18,8 @@ */ package jcckit.util; -import java.io.*; +import java.io.FileInputStream; +import java.io.IOException; import java.util.Properties; /** diff --git a/src/net/sourceforge/plantuml/AbstractPSystem.java b/src/net/sourceforge/plantuml/AbstractPSystem.java index 27eb16ad9..56ae0e5d2 100644 --- a/src/net/sourceforge/plantuml/AbstractPSystem.java +++ b/src/net/sourceforge/plantuml/AbstractPSystem.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,33 +28,34 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6922 $ + * Revision $Revision: 11351 $ * */ package net.sourceforge.plantuml; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.Arrays; -import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Properties; +import net.sourceforge.plantuml.command.Command; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.ProtectedCommand; +import net.sourceforge.plantuml.core.Diagram; +import net.sourceforge.plantuml.core.UmlSource; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.version.License; import net.sourceforge.plantuml.version.Version; -public abstract class AbstractPSystem implements PSystem { +public abstract class AbstractPSystem implements Diagram { private UmlSource source; private String getVersion() { final StringBuilder toAppend = new StringBuilder(); toAppend.append("PlantUML version "); - toAppend.append(Version.version()); + toAppend.append(Version.versionString()); toAppend.append("(" + new Date(Version.compileTime()) + ")\n"); + toAppend.append("(" + License.getCurrent() + " source distribution)\n"); final Properties p = System.getProperties(); toAppend.append(p.getProperty("java.runtime.name")); toAppend.append('\n'); @@ -86,28 +87,31 @@ public abstract class AbstractPSystem implements PSystem { return 1; } - public List exportDiagrams(File suggestedFile, FileFormatOption fileFormat) throws IOException, - InterruptedException { - if (suggestedFile.exists() && suggestedFile.isDirectory()) { - throw new IllegalArgumentException("File is a directory " + suggestedFile); - } - OutputStream os = null; - try { - os = new BufferedOutputStream(new FileOutputStream(suggestedFile)); - this.exportDiagram(os, null, 0, fileFormat); - } finally { - if (os != null) { - os.close(); - } - } - return Arrays.asList(suggestedFile); - } - - public List getTitle() { + public Display getTitle() { if (source == null) { - return Collections.emptyList(); + return Display.emptyList(); } return source.getTitle(); } + public String getWarningOrError() { + return null; + } + + public void makeDiagramReady() { + } + + public boolean isOk() { + return true; + } + + public CommandExecutionResult executeCommand(Command cmd, List lines) { + cmd = new ProtectedCommand(cmd); + return cmd.execute(this, lines); + } + + public boolean hasUrl() { + return false; + } + } diff --git a/src/net/sourceforge/plantuml/AlignParam.java b/src/net/sourceforge/plantuml/AlignParam.java index a3d372dc6..1e3f27439 100644 --- a/src/net/sourceforge/plantuml/AlignParam.java +++ b/src/net/sourceforge/plantuml/AlignParam.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,21 +33,22 @@ */ package net.sourceforge.plantuml; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; public enum AlignParam { - SEQUENCE_MESSAGE_ALIGN(HorizontalAlignement.LEFT), - SEQUENCE_REFERENCE_ALIGN(HorizontalAlignement.CENTER); + SEQUENCE_MESSAGE_ALIGN(HorizontalAlignment.LEFT), + SEQUENCE_MESSAGETEXT_ALIGN(HorizontalAlignment.LEFT), + SEQUENCE_REFERENCE_ALIGN(HorizontalAlignment.CENTER); - private final HorizontalAlignement defaultValue; + private final HorizontalAlignment defaultValue; - private AlignParam(HorizontalAlignement defaultValue) { + private AlignParam(HorizontalAlignment defaultValue) { this.defaultValue = defaultValue; } - public final HorizontalAlignement getDefaultValue() { + public final HorizontalAlignment getDefaultValue() { return defaultValue; } } diff --git a/src/net/sourceforge/plantuml/BasicEnsureVisible.java b/src/net/sourceforge/plantuml/BasicEnsureVisible.java new file mode 100644 index 000000000..772632ca3 --- /dev/null +++ b/src/net/sourceforge/plantuml/BasicEnsureVisible.java @@ -0,0 +1,76 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7903 $ + * + */ +package net.sourceforge.plantuml; + +public class BasicEnsureVisible implements EnsureVisible { + + private double minX = Double.MAX_VALUE; + private double maxX = -Double.MAX_VALUE; + private double minY = Double.MAX_VALUE; + private double maxY = -Double.MAX_VALUE; + + public void ensureVisible(double x, double y) { + if (x > maxX) { + maxX = x; + } + if (x < minX) { + minX = x; + } + if (y > maxY) { + maxY = y; + } + if (y < minY) { + minY = y; + } + } + + public String getCoords(double scale) { + if (minX == Double.MAX_VALUE) { + return "0,0,0,0"; + } + final int x1 = (int) (minX * scale); + final int y1 = (int) (minY * scale); + final int x2 = (int) (maxX * scale); + final int y2 = (int) (maxY * scale); + return "" + x1 + "," + y1 + "," + x2 + "," + y2; + } + + public double getSurface() { + if (minX == Double.MAX_VALUE) { + return 0; + } + return (maxX - minX) * (maxY - minY); + } + +} diff --git a/src/net/sourceforge/plantuml/BlockUml.java b/src/net/sourceforge/plantuml/BlockUml.java index c4fdd7bc7..f9d607f3d 100644 --- a/src/net/sourceforge/plantuml/BlockUml.java +++ b/src/net/sourceforge/plantuml/BlockUml.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,37 +33,41 @@ */ 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; +import net.sourceforge.plantuml.core.Diagram; + public class BlockUml { - private final List data; - private PSystem system; + private final List data; + private Diagram system; - private static final Pattern patternFilename = Pattern.compile("^@start\\S+\\s+\"?(.*?)\"?$"); + // private static final Pattern patternFilename = + // Pattern.compile("^@start\\S+\\s+\"?(.*?)\"?$"); + private static final Pattern patternFilename = Pattern + .compile("^@start[^\\s{}\"]+[\\s{][\\s\"]*([^\"]*?)[\\s}\"]*$"); BlockUml(String... strings) { this(Arrays.asList(strings)); } - public BlockUml(List strings) { - final String s0 = strings.get(0).trim(); + public BlockUml(List strings) { + final String s0 = strings.get(0).toString().trim(); if (s0.startsWith("@start") == false) { throw new IllegalArgumentException(); } - this.data = new ArrayList(strings); + this.data = new ArrayList(strings); } public String getFilename() { if (OptionFlags.getInstance().isWord()) { return null; } - final Matcher m = patternFilename.matcher(data.get(0).trim()); + final Matcher m = patternFilename.matcher(data.get(0).toString().trim()); final boolean ok = m.find(); if (ok == false) { return null; @@ -78,16 +82,19 @@ public class BlockUml { return result; } - public PSystem getSystem() throws IOException, InterruptedException { + private Diagram getSystem() { if (system == null) { createSystem(); } return system; } - private void createSystem() throws IOException, InterruptedException { - system = new PSystemBuilder().createPSystem(data); + public Diagram getDiagram() { + return getSystem(); + } + private void createSystem() { + system = new PSystemBuilder().createPSystem(data); } } diff --git a/src/net/sourceforge/plantuml/BlockUmlBuilder.java b/src/net/sourceforge/plantuml/BlockUmlBuilder.java index 68f5aa11d..21997feda 100644 --- a/src/net/sourceforge/plantuml/BlockUmlBuilder.java +++ b/src/net/sourceforge/plantuml/BlockUmlBuilder.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -52,10 +52,10 @@ final public class BlockUmlBuilder { private final List blocks = new ArrayList(); private final Set usedFiles = new HashSet(); - public BlockUmlBuilder(List config, Defines defines, Reader reader, File newCurrentDir) throws IOException { + public BlockUmlBuilder(List config, String charset, Defines defines, Reader reader, File newCurrentDir) throws IOException { Preprocessor includer = null; try { - includer = new Preprocessor(new UncommentReadLine(new ReadLineReader(reader)), defines, usedFiles, newCurrentDir); + includer = new Preprocessor(new UncommentReadLine(new ReadLineReader(reader)), charset, defines, usedFiles, newCurrentDir); init(includer, config); } finally { if (includer != null) { diff --git a/src/net/sourceforge/plantuml/CMapData.java b/src/net/sourceforge/plantuml/CMapData.java new file mode 100644 index 000000000..002bc7c1d --- /dev/null +++ b/src/net/sourceforge/plantuml/CMapData.java @@ -0,0 +1,92 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8368 $ + * + */ +package net.sourceforge.plantuml; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +public class CMapData { + + private final StringBuilder stringBuilder = new StringBuilder(); + + public String asString(String nameId) { + return "\n" + stringBuilder.toString() + "\n"; + } + + public boolean containsData() { + return stringBuilder.length() > 0; + } + + public void appendString(String s) { + stringBuilder.append(s); + } + + public void appendLong(long s) { + stringBuilder.append(s); + } + + public void appendUrl(int seq, Url url, double scale) { + appendString("\"\""); + + appendString("\n"); + } + + // private CMapData() { + // } + + public static CMapData cmapString(Set allUrlEncountered, double scale) { + final CMapData cmapdata = new CMapData(); + + final List all = new ArrayList(allUrlEncountered); + Collections.sort(all, Url.SURFACE_COMPARATOR); + + int seq = 1; + for (Url u : all) { + cmapdata.appendUrl(seq, u, scale); + seq++; + } + return cmapdata; + } + +} diff --git a/src/net/sourceforge/plantuml/ColorParam.java b/src/net/sourceforge/plantuml/ColorParam.java index bc5d63b35..6ecfcb283 100644 --- a/src/net/sourceforge/plantuml/ColorParam.java +++ b/src/net/sourceforge/plantuml/ColorParam.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6549 $ + * Revision $Revision: 11149 $ * */ package net.sourceforge.plantuml; @@ -65,11 +65,14 @@ public enum ColorParam { packageBackground, packageBorder, + partitionBackground, + partitionBorder, + componentBackground, componentBorder, componentInterfaceBackground, componentInterfaceBorder, - componentArrow, + // componentArrow, stateBackground, stateBorder, @@ -80,6 +83,9 @@ public enum ColorParam { noteBackground(true), noteBorder, + legendBackground(true), + legendBorder, + sequenceActorBackground(true), sequenceActorBorder, sequenceGroupBorder, @@ -118,6 +124,4 @@ public enum ColorParam { protected boolean isBackground() { return isBackground; } - - } diff --git a/src/net/sourceforge/plantuml/Dimension2DDouble.java b/src/net/sourceforge/plantuml/Dimension2DDouble.java index 0a8949708..092598a1d 100644 --- a/src/net/sourceforge/plantuml/Dimension2DDouble.java +++ b/src/net/sourceforge/plantuml/Dimension2DDouble.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 7157 $ + * Revision $Revision: 11564 $ * */ package net.sourceforge.plantuml; @@ -79,17 +79,27 @@ public class Dimension2DDouble extends Dimension2D { return new Dimension2DDouble(width, height); } + public static Dimension2D mergeTB(Dimension2D a, Dimension2D b, Dimension2D c) { + final double width = MathUtils.max(a.getWidth(), b.getWidth(), c.getWidth()); + final double height = a.getHeight() + b.getHeight() + c.getHeight(); + return new Dimension2DDouble(width, height); + } + public static Dimension2D mergeLR(Dimension2D left, Dimension2D right) { final double height = Math.max(left.getHeight(), right.getHeight()); final double width = left.getWidth() + right.getWidth(); return new Dimension2DDouble(width, height); } - public static Dimension2D mergeTB(Dimension2D top1, Dimension2D top2, Dimension2D bottom) { + public static Dimension2D mergeLayoutT12B3(Dimension2D top1, Dimension2D top2, Dimension2D bottom) { final double width = MathUtils.max(top1.getWidth(), top2.getWidth(), bottom.getWidth()); final double height = top1.getHeight() + top2.getHeight() + bottom.getHeight(); return new Dimension2DDouble(width, height); } + + public static Dimension2D max(Dimension2D dim1, Dimension2D dim2) { + return atLeast(dim1, dim2.getWidth(), dim2.getHeight()); + } public static Dimension2D atLeast(Dimension2D dim, double minWidth, double minHeight) { double h = dim.getHeight(); diff --git a/src/net/sourceforge/plantuml/DirWatcher.java b/src/net/sourceforge/plantuml/DirWatcher.java index a3e55edb2..b721b3d6e 100644 --- a/src/net/sourceforge/plantuml/DirWatcher.java +++ b/src/net/sourceforge/plantuml/DirWatcher.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6616 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml; @@ -45,6 +45,7 @@ import java.util.Set; import net.sourceforge.plantuml.preproc.Defines; +@Deprecated public class DirWatcher { final private File dir; diff --git a/src/net/sourceforge/plantuml/DirWatcher2.java b/src/net/sourceforge/plantuml/DirWatcher2.java index be676b45c..34c47354b 100644 --- a/src/net/sourceforge/plantuml/DirWatcher2.java +++ b/src/net/sourceforge/plantuml/DirWatcher2.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -69,34 +69,39 @@ public class DirWatcher2 { public Map>> buildCreatedFiles() throws IOException, InterruptedException { final Map>> result = new TreeMap>>(); - for (final File f : dir.listFiles()) { - if (f.isFile() == false) { - continue; - } - if (fileToProcess(f.getName()) == false) { - continue; - } - final FileWatcher watcher = modifieds.get(f); + if (dir.listFiles() != null) { + for (final File f : dir.listFiles()) { + if (f.isFile() == false) { + continue; + } + if (fileToProcess(f.getName()) == false) { + continue; + } + final FileWatcher watcher = modifieds.get(f); - if (watcher == null || watcher.hasChanged()) { - final SourceFileReader sourceFileReader = new SourceFileReader(new Defines(), f, option.getOutputDir(), - option.getConfig(), option.getCharset(), option.getFileFormatOption()); - modifieds.put(f, new FileWatcher(Collections.singleton(f))); - final Future> value = executorService.submit(new Callable>() { - public List call() throws Exception { - try { - final List generatedImages = sourceFileReader.getGeneratedImages(); - final Set files = new HashSet(sourceFileReader.getIncludedFiles()); - files.add(f); - modifieds.put(f, new FileWatcher(files)); - return Collections.unmodifiableList(generatedImages); - } catch (Exception e) { - e.printStackTrace(); - return Collections.emptyList(); - } - } - }); - result.put(f, value); + if (watcher == null || watcher.hasChanged()) { + final SourceFileReader sourceFileReader = new SourceFileReader(new Defines(), f, + option.getOutputDir(), option.getConfig(), option.getCharset(), + option.getFileFormatOption()); + modifieds.put(f, new FileWatcher(Collections.singleton(f))); + final Future> value = executorService + .submit(new Callable>() { + public List call() throws Exception { + try { + final List generatedImages = sourceFileReader + .getGeneratedImages(); + final Set files = new HashSet(sourceFileReader.getIncludedFiles()); + files.add(f); + modifieds.put(f, new FileWatcher(files)); + return Collections.unmodifiableList(generatedImages); + } catch (Exception e) { + e.printStackTrace(); + return Collections.emptyList(); + } + } + }); + result.put(f, value); + } } } return Collections.unmodifiableMap(result); diff --git a/src/net/sourceforge/plantuml/Direction.java b/src/net/sourceforge/plantuml/Direction.java index f09e4bab5..f644ceff5 100644 --- a/src/net/sourceforge/plantuml/Direction.java +++ b/src/net/sourceforge/plantuml/Direction.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,6 +33,8 @@ */ package net.sourceforge.plantuml; +import java.awt.geom.Point2D; + public enum Direction { RIGHT, LEFT, DOWN, UP; @@ -64,4 +66,30 @@ public enum Direction { } return Direction.DOWN; } + + public Direction clockwise() { + if (this == RIGHT) { + return DOWN; + } + if (this == LEFT) { + return UP; + } + if (this == DOWN) { + return LEFT; + } + if (this == UP) { + return RIGHT; + } + throw new IllegalStateException(); + } + + public static Direction leftOrRight(Point2D p1, Point2D p2) { + if (p1.getX() < p2.getX()) { + return Direction.LEFT; + } + if (p1.getX() > p2.getX()) { + return Direction.RIGHT; + } + throw new IllegalArgumentException(); + } } diff --git a/src/net/sourceforge/plantuml/EmbededDiagram.java b/src/net/sourceforge/plantuml/EmbededDiagram.java index 825f0a950..348321b3d 100644 --- a/src/net/sourceforge/plantuml/EmbededDiagram.java +++ b/src/net/sourceforge/plantuml/EmbededDiagram.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,16 +33,14 @@ */ package net.sourceforge.plantuml; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; +import net.sourceforge.plantuml.cucadiagram.Display; public class EmbededDiagram implements CharSequence { - private final List system; + private final Display system; - public EmbededDiagram(List system) { - this.system = new ArrayList(system); + public EmbededDiagram(Display system) { + this.system = system; } public int length() { @@ -57,7 +55,7 @@ public class EmbededDiagram implements CharSequence { return toString().subSequence(start, end); } - public final List getLines() { - return Collections.unmodifiableList(system); + public final Display getLines() { + return system; } } diff --git a/src/net/sourceforge/plantuml/EmptyImageBuilder.java b/src/net/sourceforge/plantuml/EmptyImageBuilder.java index b215bf14c..6d1b40f88 100644 --- a/src/net/sourceforge/plantuml/EmptyImageBuilder.java +++ b/src/net/sourceforge/plantuml/EmptyImageBuilder.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,17 +28,20 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5810 $ + * Revision $Revision: 10103 $ * */ package net.sourceforge.plantuml; import java.awt.Color; import java.awt.Graphics2D; -import java.awt.RenderingHints; import java.awt.geom.AffineTransform; import java.awt.image.BufferedImage; +import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity; +import net.sourceforge.plantuml.ugraphic.UAntiAliasing; +import net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d; + public class EmptyImageBuilder { private final BufferedImage im; @@ -50,11 +53,14 @@ public class EmptyImageBuilder { public EmptyImageBuilder(int width, int height, Color background) { Log.info("Creating image " + width + "x" + height); - im = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + im = new BufferedImage(width, height, background == null ? BufferedImage.TYPE_INT_ARGB + : 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); + UAntiAliasing.ANTI_ALIASING_ON.apply(g2d); + if (background != null) { + g2d.setColor(background); + g2d.fillRect(0, 0, width, height); + } } public EmptyImageBuilder(int width, int height, Color background, double dpiFactor) { @@ -72,4 +78,10 @@ public class EmptyImageBuilder { return g2d; } + public UGraphicG2d getUGraphicG2d() { + final UGraphicG2d result = new UGraphicG2d(new ColorMapperIdentity(), g2d, 1.0); + result.setBufferedImage(im); + return result; + } + } diff --git a/src/net/sourceforge/plantuml/PSystemBasicFactory.java b/src/net/sourceforge/plantuml/EnsureVisible.java similarity index 82% rename from src/net/sourceforge/plantuml/PSystemBasicFactory.java rename to src/net/sourceforge/plantuml/EnsureVisible.java index 5795f02b7..65c8ffd0c 100644 --- a/src/net/sourceforge/plantuml/PSystemBasicFactory.java +++ b/src/net/sourceforge/plantuml/EnsureVisible.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -27,12 +27,14 @@ * in the United States and other countries.] * * Original Author: Arnaud Roques + * + * Revision $Revision: 7903 $ * - * Revision $Revision: 3824 $ */ package net.sourceforge.plantuml; -public interface PSystemBasicFactory extends PSystemFactory { +public interface EnsureVisible { + + public void ensureVisible(double x, double y); - boolean executeLine(String line); } diff --git a/src/net/sourceforge/plantuml/ErrorUml.java b/src/net/sourceforge/plantuml/ErrorUml.java index 951ad25d9..d5ac0da3a 100644 --- a/src/net/sourceforge/plantuml/ErrorUml.java +++ b/src/net/sourceforge/plantuml/ErrorUml.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -36,14 +36,14 @@ package net.sourceforge.plantuml; import net.sourceforge.plantuml.suggest.SuggestEngineResult; import net.sourceforge.plantuml.suggest.SuggestEngineStatus; -class ErrorUml { +public class ErrorUml { private final String error; private final int position; private final ErrorUmlType type; private SuggestEngineResult suggest; - ErrorUml(ErrorUmlType type, String error, int position) { + public ErrorUml(ErrorUmlType type, String error, int position) { if (error == null || type == null || StringUtils.isEmpty(error)) { throw new IllegalArgumentException(); } diff --git a/src/net/sourceforge/plantuml/ErrorUmlType.java b/src/net/sourceforge/plantuml/ErrorUmlType.java index 11f09f759..451ce1efb 100644 --- a/src/net/sourceforge/plantuml/ErrorUmlType.java +++ b/src/net/sourceforge/plantuml/ErrorUmlType.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,7 +33,7 @@ */ package net.sourceforge.plantuml; -enum ErrorUmlType { +public enum ErrorUmlType { SYNTAX_ERROR, EXECUTION_ERROR } diff --git a/src/net/sourceforge/plantuml/FileFormat.java b/src/net/sourceforge/plantuml/FileFormat.java index dd4dc9de6..dbe54940a 100644 --- a/src/net/sourceforge/plantuml/FileFormat.java +++ b/src/net/sourceforge/plantuml/FileFormat.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,17 +28,30 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6671 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml; -public enum FileFormat { - PNG, SVG, EPS, EPS_TEXT, ATXT, UTXT, DOT, XMI_STANDARD, XMI_STAR, XMI_ARGO, PDF; +import java.io.File; +/** + * Format for output files generated by PlantUML. + * + * @author Arnaud Roques + * + */ +public enum FileFormat { + PNG, SVG, EPS, EPS_TEXT, ATXT, UTXT, XMI_STANDARD, XMI_STAR, XMI_ARGO, PDF, MJPEG, HTML, HTML5, VDX; + + /** + * Returns the file format to be used for that format. + * + * @return a string starting by a point. + */ public String getFileSuffix() { if (name().startsWith("XMI")) { - return ".XMI"; + return ".xmi"; } if (this == EPS_TEXT) { return EPS.getFileSuffix(); @@ -46,6 +59,11 @@ public enum FileFormat { return "." + name().toLowerCase(); } + /** + * Check if this file format is Encapsulated PostScript. + * + * @return true for EPS. + */ public boolean isEps() { if (this == EPS) { return true; @@ -58,9 +76,36 @@ public enum FileFormat { public String changeName(String fileName, int cpt) { if (cpt == 0) { - return fileName.replaceAll("\\.\\w+$", getFileSuffix()); + return changeName(fileName, getFileSuffix()); } - return fileName.replaceAll("\\.\\w+$", "_" + String.format("%03d", cpt) + getFileSuffix()); + return changeName(fileName, "_" + String.format("%03d", cpt) + getFileSuffix()); + } + + private String changeName(String fileName, String replacement) { + String result = fileName.replaceAll("\\.\\w+$", replacement); + if (result.equals(fileName)) { + result = fileName + replacement; + } + return result; + } + + public File computeFilename(File pngFile, int i) { + if (i == 0) { + return pngFile; + } + final File dir = pngFile.getParentFile(); + return new File(dir, computeFilename(pngFile.getName(), i)); + // String name = pngFile.getName(); + // name = name.replaceAll("\\" + getFileSuffix() + "$", "_" + String.format("%03d", i) + getFileSuffix()); + // return new File(dir, name); + + } + + public String computeFilename(String name, int i) { + if (i == 0) { + return name; + } + return name.replaceAll("\\" + getFileSuffix() + "$", "_" + String.format("%03d", i) + getFileSuffix()); } } diff --git a/src/net/sourceforge/plantuml/FileFormatOption.java b/src/net/sourceforge/plantuml/FileFormatOption.java index 900827f19..b55e5529c 100644 --- a/src/net/sourceforge/plantuml/FileFormatOption.java +++ b/src/net/sourceforge/plantuml/FileFormatOption.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,32 +33,160 @@ */ package net.sourceforge.plantuml; +import java.awt.Color; +import java.awt.Graphics2D; +import java.awt.geom.AffineTransform; +import java.awt.geom.Dimension2D; +import java.awt.image.BufferedImage; + +import net.sourceforge.plantuml.eps.EpsStrategy; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorGradient; +import net.sourceforge.plantuml.graphic.HtmlColorSimple; +import net.sourceforge.plantuml.graphic.HtmlColorTransparent; +import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.eps.UGraphicEps; +import net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d; +import net.sourceforge.plantuml.ugraphic.html5.UGraphicHtml5; +import net.sourceforge.plantuml.ugraphic.svg.UGraphicSvg; +import net.sourceforge.plantuml.ugraphic.visio.UGraphicVdx; + +/** + * A FileFormat with some parameters. + * + * + * @author Arnaud Roques + * + */ public class FileFormatOption { private final FileFormat fileFormat; - private final int dpi; - - public FileFormatOption(FileFormat fileFormat, int dpi) { - this.fileFormat = fileFormat; - this.dpi = dpi; - } + private final AffineTransform affineTransform; + private final boolean withMetadata; public FileFormatOption(FileFormat fileFormat) { - this(fileFormat, 96); + this(fileFormat, null, true); + } + + public final boolean isWithMetadata() { + return withMetadata; + } + + public FileFormatOption(FileFormat fileFormat, boolean withMetadata) { + this(fileFormat, null, false); + } + + public FileFormatOption(FileFormat fileFormat, AffineTransform at) { + this(fileFormat, at, true); + } + + public FileFormatOption(FileFormat fileFormat, AffineTransform at, boolean withMetadata) { + this.fileFormat = fileFormat; + this.affineTransform = at; + this.withMetadata = withMetadata; + } + + @Override + public String toString() { + return fileFormat.toString() + " " + affineTransform; } public final FileFormat getFileFormat() { return fileFormat; } -// public final int getDpi() { -// return dpi; -// } -// -// public double getDpiFactor() { -// if (dpi == 96) { -// return 1.0; -// } -// return dpi / 96.0; -// } + public AffineTransform getAffineTransform() { + return affineTransform; + } + + /** + * Create a UGraphic corresponding to this FileFormatOption + * + * @param colorMapper + * @param dpiFactor + * 1.0 for a standard dot per inch + * @param dim + * @param mybackcolor + * @param rotation + * @return + */ + public UGraphic createUGraphic(ColorMapper colorMapper, double dpiFactor, final Dimension2D dim, + HtmlColor mybackcolor, boolean rotation) { + switch (fileFormat) { + case PNG: + return createUGraphicPNG(colorMapper, dpiFactor, dim, mybackcolor, rotation); + case SVG: + return createUGraphicSVG(colorMapper, dpiFactor, dim, mybackcolor, rotation); + case EPS: + return new UGraphicEps(colorMapper, EpsStrategy.getDefault2()); + case EPS_TEXT: + return new UGraphicEps(colorMapper, EpsStrategy.WITH_MACRO_AND_TEXT); + case HTML5: + return new UGraphicHtml5(colorMapper); + case VDX: + return new UGraphicVdx(colorMapper); + default: + throw new UnsupportedOperationException(fileFormat.toString()); + } + } + + public UGraphic createUGraphic(final Dimension2D dim) { + return createUGraphic(new ColorMapperIdentity(), 1.0, dim, null, false); + } + + private UGraphic createUGraphicSVG(ColorMapper colorMapper, double scale, Dimension2D dim, HtmlColor mybackcolor, + boolean rotation) { + Color backColor = Color.WHITE; + if (mybackcolor instanceof HtmlColorSimple) { + backColor = colorMapper.getMappedColor(mybackcolor); + } + final UGraphicSvg ug; + if (mybackcolor instanceof HtmlColorGradient) { + ug = new UGraphicSvg(colorMapper, (HtmlColorGradient) mybackcolor, false, scale); + } else if (backColor == null || backColor.equals(Color.WHITE)) { + ug = new UGraphicSvg(colorMapper, false, scale); + } else { + ug = new UGraphicSvg(colorMapper, StringUtils.getAsHtml(backColor), false, scale); + } + return ug; + + } + + private UGraphic createUGraphicPNG(ColorMapper colorMapper, double dpiFactor, final Dimension2D dim, + HtmlColor mybackcolor, boolean rotation) { + Color backColor = Color.WHITE; + if (mybackcolor instanceof HtmlColorSimple) { + backColor = colorMapper.getMappedColor(mybackcolor); + } else if (mybackcolor instanceof HtmlColorTransparent) { + backColor = null; + } + + final EmptyImageBuilder builder; + final Graphics2D graphics2D; + if (rotation) { + builder = new EmptyImageBuilder((int) (dim.getHeight() * dpiFactor), (int) (dim.getWidth() * dpiFactor), + backColor); + graphics2D = builder.getGraphics2D(); + graphics2D.rotate(-Math.PI / 2); + graphics2D.translate(-builder.getBufferedImage().getHeight(), 0); + } else { + builder = new EmptyImageBuilder((int) (dim.getWidth() * dpiFactor), (int) (dim.getHeight() * dpiFactor), + backColor); + graphics2D = builder.getGraphics2D(); + + } + final UGraphicG2d ug = new UGraphicG2d(colorMapper, graphics2D, dpiFactor); + ug.setBufferedImage(builder.getBufferedImage()); + final BufferedImage im = ((UGraphicG2d) ug).getBufferedImage(); + if (mybackcolor instanceof HtmlColorGradient) { + ug.apply(new UChangeBackColor(mybackcolor)).draw(new URectangle(im.getWidth(), im.getHeight())); + } + + return ug; + } + } diff --git a/src/net/sourceforge/plantuml/FileGroup.java b/src/net/sourceforge/plantuml/FileGroup.java index 4e211fb75..c2fcdbc83 100644 --- a/src/net/sourceforge/plantuml/FileGroup.java +++ b/src/net/sourceforge/plantuml/FileGroup.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3824 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml; diff --git a/src/net/sourceforge/plantuml/FileSystem.java b/src/net/sourceforge/plantuml/FileSystem.java index 184182149..ce5ae9549 100644 --- a/src/net/sourceforge/plantuml/FileSystem.java +++ b/src/net/sourceforge/plantuml/FileSystem.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,13 +28,16 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6908 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml; import java.io.File; import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; public class FileSystem { @@ -64,10 +67,47 @@ public class FileSystem { public File getFile(String nameOrPath) throws IOException { final File dir = currentDir.get(); - if (dir == null) { + if (dir == null || isAbsolute(nameOrPath)) { return new File(nameOrPath).getCanonicalFile(); } - return new File(dir.getAbsoluteFile(), nameOrPath).getCanonicalFile(); + final File filecurrent = new File(dir.getAbsoluteFile(), nameOrPath); + if (filecurrent.exists()) { + return filecurrent.getCanonicalFile(); + } + for (File d : getPath("plantuml.include.path")) { + final File file = new File(d, nameOrPath); + if (file.exists()) { + return file.getCanonicalFile(); + } + } + for (File d : getPath("java.class.path")) { + final File file = new File(d, nameOrPath); + if (file.exists()) { + return file.getCanonicalFile(); + } + } + return filecurrent; + } + + private List getPath(String prop) { + final List result = new ArrayList(); + final String paths = System.getProperty(prop); + if (paths == null) { + return result; + } + final StringTokenizer st = new StringTokenizer(paths, System.getProperty("path.separator")); + while (st.hasMoreTokens()) { + final File f = new File(st.nextToken()); + if (f.exists() && f.isDirectory()) { + result.add(f); + } + } + return result; + } + + private boolean isAbsolute(String nameOrPath) { + final File f = new File(nameOrPath); + return f.isAbsolute(); } public void reset() { diff --git a/src/net/sourceforge/plantuml/FileUtils.java b/src/net/sourceforge/plantuml/FileUtils.java index 467b35644..b9e990202 100644 --- a/src/net/sourceforge/plantuml/FileUtils.java +++ b/src/net/sourceforge/plantuml/FileUtils.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -51,26 +51,6 @@ public class FileUtils { counter = new AtomicInteger(0); } - public static File getTmpDir() { - final File tmpDir = new File(System.getProperty("java.io.tmpdir")); - if (tmpDir.exists() == false || tmpDir.isDirectory() == false) { - throw new IllegalStateException(); - } - return tmpDir; - } - - public static void delete(File f) { - if (f == null) { - return; - } - Thread.yield(); - Log.info("Deleting temporary file " + f); - final boolean ok = f.delete(); - if (ok == false) { - Log.error("Cannot delete: " + f); - } - } - static public File createTempFile(String prefix, String suffix) throws IOException { if (suffix.startsWith(".") == false) { throw new IllegalArgumentException(); @@ -92,40 +72,41 @@ public class FileUtils { return f; } + private static void copyInternal(final InputStream fis, final OutputStream fos) throws IOException { + final byte[] buf = new byte[10240]; + int len; + while ((len = fis.read(buf)) > 0) { + fos.write(buf, 0, len); + } + fos.close(); + fis.close(); + } + static public void copyToFile(File src, File dest) throws IOException { if (dest.isDirectory()) { dest = new File(dest, src.getName()); } final InputStream fis = new BufferedInputStream(new FileInputStream(src)); final OutputStream fos = new BufferedOutputStream(new FileOutputStream(dest)); - int lu; - while ((lu = fis.read()) != -1) { - fos.write(lu); - } - fos.close(); - fis.close(); + copyInternal(fis, fos); } static public void copyToStream(File src, OutputStream os) throws IOException { final InputStream fis = new BufferedInputStream(new FileInputStream(src)); final OutputStream fos = new BufferedOutputStream(os); - int lu; - while ((lu = fis.read()) != -1) { - fos.write(lu); - } - fos.close(); - fis.close(); + copyInternal(fis, fos); } static public void copyToStream(InputStream is, OutputStream os) throws IOException { final InputStream fis = new BufferedInputStream(is); final OutputStream fos = new BufferedOutputStream(os); - int lu; - while ((lu = fis.read()) != -1) { - fos.write(lu); - } + copyInternal(fis, fos); + } + + static public void copyToFile(byte[] src, File dest) throws IOException { + final OutputStream fos = new BufferedOutputStream(new FileOutputStream(dest)); + fos.write(src); fos.close(); - fis.close(); } } diff --git a/src/net/sourceforge/plantuml/FileWatcher.java b/src/net/sourceforge/plantuml/FileWatcher.java index ea2ef21c8..eafe7ff12 100644 --- a/src/net/sourceforge/plantuml/FileWatcher.java +++ b/src/net/sourceforge/plantuml/FileWatcher.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/FontParam.java b/src/net/sourceforge/plantuml/FontParam.java index b75cf3b59..9c1cb9e27 100644 --- a/src/net/sourceforge/plantuml/FontParam.java +++ b/src/net/sourceforge/plantuml/FontParam.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,53 +28,61 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 7130 $ + * Revision $Revision: 11985 $ * */ package net.sourceforge.plantuml; import java.awt.Font; -public enum FontParam { +interface FontParamConstant { + String FAMILY = "SansSerif"; + String COLOR = "black"; +} + +public enum FontParam { + ACTIVITY(14, Font.PLAIN), // + // ACTIVITY_ARROW(13, Font.PLAIN), // + GENERIC_ARROW(13, Font.PLAIN), // + ACTIVITY2(12, Font.PLAIN), // + ACTIVITY_ARROW2(11, Font.PLAIN), // + CIRCLED_CHARACTER(17, Font.BOLD, FontParamConstant.COLOR, "Monospaced"), // + // OBJECT_ARROW(10, Font.PLAIN), // + OBJECT_ATTRIBUTE(10, Font.PLAIN), // + OBJECT(12, Font.PLAIN), // + OBJECT_STEREOTYPE(12, Font.ITALIC), // + // CLASS_ARROW(10, Font.PLAIN), // + CLASS_ATTRIBUTE(10, Font.PLAIN), // + CLASS(12, Font.PLAIN), // + CLASS_STEREOTYPE(12, Font.ITALIC), // + COMPONENT(14, Font.PLAIN), // + COMPONENT_STEREOTYPE(14, Font.ITALIC), // + // COMPONENT_ARROW(13, Font.PLAIN), // + NOTE(13, Font.PLAIN), // + PACKAGE(14, Font.PLAIN), // + SEQUENCE_ACTOR(13, Font.PLAIN), // + SEQUENCE_ARROW(13, Font.PLAIN), // + SEQUENCE_BOX(13, Font.BOLD), // + SEQUENCE_DIVIDER(13, Font.BOLD), // + SEQUENCE_REFERENCE(13, Font.PLAIN), // + SEQUENCE_DELAY(11, Font.PLAIN), // + SEQUENCE_GROUP(11, Font.BOLD), // + SEQUENCE_GROUP_HEADER(13, Font.BOLD), // + SEQUENCE_PARTICIPANT(13, Font.PLAIN), // + SEQUENCE_TITLE(13, Font.BOLD), // + STATE(14, Font.PLAIN), // + // STATE_ARROW(13, Font.PLAIN), // + STATE_ATTRIBUTE(12, Font.PLAIN), // + LEGEND(14, Font.PLAIN), // + TITLE(18, Font.PLAIN), // + FOOTER(10, Font.PLAIN, "#888888", FontParamConstant.FAMILY), // + HEADER(10, Font.PLAIN, "#888888", FontParamConstant.FAMILY), // + USECASE(14, Font.PLAIN), // + USECASE_STEREOTYPE(14, Font.ITALIC), // + USECASE_ACTOR(14, Font.PLAIN), // + USECASE_ACTOR_STEREOTYPE(14, Font.ITALIC); // + // USECASE_ARROW(13, Font.PLAIN, FontParamConstant.COLOR, FontParamConstant.FAMILY); - 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_BOX(13, Font.BOLD, "black", null), - SEQUENCE_DIVIDER(13, Font.BOLD, "black", null), - SEQUENCE_REFERENCE(13, Font.PLAIN, "black", null), - SEQUENCE_DELAY(11, Font.PLAIN, "black", null), - SEQUENCE_GROUP(11, Font.BOLD, "black", null), - SEQUENCE_GROUP_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; @@ -87,15 +95,19 @@ public enum FontParam { this.defaultFamily = defaultFamily; } + private FontParam(int defaultSize, int fontStyle) { + this(defaultSize, fontStyle, FontParamConstant.COLOR, FontParamConstant.FAMILY); + } + public final int getDefaultSize(ISkinParam skinParam) { - if (skinParam.isSvek() && this==CLASS_ATTRIBUTE) { + if (this == CLASS_ATTRIBUTE) { return 11; } return defaultSize; } public final int getDefaultFontStyle(ISkinParam skinParam) { - if (skinParam.isSvek() && this==PACKAGE) { + if (this == PACKAGE) { return Font.BOLD; } return fontStyle; @@ -108,6 +120,5 @@ public enum FontParam { public String getDefaultFamily() { return defaultFamily; } - - + } diff --git a/src/net/sourceforge/plantuml/GeneratedImage.java b/src/net/sourceforge/plantuml/GeneratedImage.java index dd086a6f7..6ca2e8b8c 100644 --- a/src/net/sourceforge/plantuml/GeneratedImage.java +++ b/src/net/sourceforge/plantuml/GeneratedImage.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,20 +28,22 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6615 $ + * Revision $Revision: 10298 $ * */ package net.sourceforge.plantuml; import java.io.File; +import net.sourceforge.plantuml.core.Diagram; + public class GeneratedImage implements Comparable { private final File pngFile; private final String description; - private final PSystem system; + private final Diagram system; - public GeneratedImage(File pngFile, String description, PSystem system) { + public GeneratedImage(File pngFile, String description, Diagram system) { this.system = system; this.pngFile = pngFile; this.description = description; diff --git a/src/net/sourceforge/plantuml/Hideable.java b/src/net/sourceforge/plantuml/Hideable.java new file mode 100644 index 000000000..ab66c8855 --- /dev/null +++ b/src/net/sourceforge/plantuml/Hideable.java @@ -0,0 +1,40 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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; + +public interface Hideable { + + public boolean isHidden(); + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/ISkinParam.java b/src/net/sourceforge/plantuml/ISkinParam.java index 6f870b1ea..5165625d8 100644 --- a/src/net/sourceforge/plantuml/ISkinParam.java +++ b/src/net/sourceforge/plantuml/ISkinParam.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -35,43 +35,68 @@ package net.sourceforge.plantuml; import net.sourceforge.plantuml.cucadiagram.dot.DotSplines; import net.sourceforge.plantuml.cucadiagram.dot.GraphvizLayoutStrategy; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.svek.ConditionStyle; +import net.sourceforge.plantuml.svek.PackageStyle; import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UStroke; -public interface ISkinParam { +public interface ISkinParam extends SpriteContainer { public HtmlColor getBackgroundColor(); public String getValue(String key); - public HtmlColor getHtmlColor(ColorParam param, String stereotype); + public HtmlColor getHtmlColor(ColorParam param, String stereotype, boolean clickable); public HtmlColor getFontHtmlColor(FontParam param, String stereotype); + public UStroke getThickness(LineParam param); + public UFont getFont(FontParam fontParam, String stereotype); - - public HorizontalAlignement getHorizontalAlignement(AlignParam param); + + public HorizontalAlignment getHorizontalAlignment(AlignParam param); public int getCircledCharacterRadius(); - public boolean isClassCollapse(); - public int classAttributeIconSize(); - + public ColorMapper getColorMapper(); - + public int getDpi(); - - public boolean useOctagonForActivity(); - + public DotSplines getDotSplines(); - + public GraphvizLayoutStrategy getStrategy(); - - public boolean isSvek(); - + public boolean shadowing(); + public PackageStyle getPackageStyle(); + + public boolean useUml2ForComponent(); + + public boolean stereotypePositionTop(); + + public boolean useSwimlanes(); + + public double getNodesep(); + + public double getRanksep(); + + public double getRoundCorner(); + + public double maxMessageSize(); + + public boolean strictUmlStyle(); + + public boolean forceSequenceParticipantUnderlined(); + + public ConditionStyle getConditionStyle(); + + public double minClassWidth(); + + public boolean sameClassWidth(); + } \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/ISourceFileReader.java b/src/net/sourceforge/plantuml/ISourceFileReader.java index cebb2a2a9..1957010ca 100644 --- a/src/net/sourceforge/plantuml/ISourceFileReader.java +++ b/src/net/sourceforge/plantuml/ISourceFileReader.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/LineConfigurable.java b/src/net/sourceforge/plantuml/LineConfigurable.java new file mode 100644 index 000000000..90166ad62 --- /dev/null +++ b/src/net/sourceforge/plantuml/LineConfigurable.java @@ -0,0 +1,49 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public interface LineConfigurable { + + public HtmlColor getSpecificLineColor(); + + public void setSpecificLineColor(HtmlColor specificLinecolor); + + public UStroke getSpecificLineStroke(); + + public void setSpecificLineStroke(UStroke specificLineStoke); + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/LineParam.java b/src/net/sourceforge/plantuml/LineParam.java new file mode 100644 index 000000000..86530369f --- /dev/null +++ b/src/net/sourceforge/plantuml/LineParam.java @@ -0,0 +1,47 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7715 $ + * + */ +package net.sourceforge.plantuml; + + +public enum LineParam { +// sequenceBoundaryBorder, + sequenceActorBorder, + sequenceDividerBorder, +// sequenceGroupBorder(0.1), +// sequenceReferenceBorder(0.1), + sequenceLifeLineBorder, + sequenceParticipantBorder, noteBorder, sequenceGroupBorder, sequenceReferenceBorder; +// sequenceBoxBorder(0.1); + +} diff --git a/src/net/sourceforge/plantuml/Log.java b/src/net/sourceforge/plantuml/Log.java index 7cb8809ee..2a31b8029 100644 --- a/src/net/sourceforge/plantuml/Log.java +++ b/src/net/sourceforge/plantuml/Log.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6528 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml; @@ -68,4 +68,18 @@ public abstract class Log { return sb.toString(); } + + public static void println(Object s) { + if (header == null) { + System.err.println("L = " + s); + } else { + System.err.println(header + " " + s); + } + } + + private static String header; + + public static void header(String s) { + header = s; + } } diff --git a/src/net/sourceforge/plantuml/MathUtils.java b/src/net/sourceforge/plantuml/MathUtils.java index fb21bd013..fcea40029 100644 --- a/src/net/sourceforge/plantuml/MathUtils.java +++ b/src/net/sourceforge/plantuml/MathUtils.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -45,7 +45,9 @@ public class MathUtils { public static double limitation(double v, double min, double max) { if (min >= max) { - throw new IllegalArgumentException(); + assert false : "min="+min+" max="+max+" v="+v; + return v; + // throw new IllegalArgumentException("min="+min+" max="+max+" v="+v); } if (v < min) { return min; diff --git a/src/net/sourceforge/plantuml/NewpagedDiagram.java b/src/net/sourceforge/plantuml/NewpagedDiagram.java new file mode 100644 index 000000000..d28647e12 --- /dev/null +++ b/src/net/sourceforge/plantuml/NewpagedDiagram.java @@ -0,0 +1,111 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 10459 $ + * + */ +package net.sourceforge.plantuml; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.plantuml.command.Command; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.core.Diagram; +import net.sourceforge.plantuml.core.DiagramDescription; +import net.sourceforge.plantuml.core.DiagramDescriptionImpl; +import net.sourceforge.plantuml.core.ImageData; + +public class NewpagedDiagram extends AbstractPSystem { + + private final List diagrams = new ArrayList(); + + private NewpagedDiagram(Diagram diag1, Diagram diag2) { + if (diag1 instanceof NewpagedDiagram) { + throw new IllegalArgumentException(); + } + if (diag2 instanceof NewpagedDiagram) { + throw new IllegalArgumentException(); + } + this.diagrams.add(diag1); + this.diagrams.add(diag2); + } + + public static NewpagedDiagram newpage(AbstractPSystem diagram, AbstractPSystem empty) { + if (diagram instanceof NewpagedDiagram) { + final NewpagedDiagram other = (NewpagedDiagram) diagram; + other.diagrams.add(empty); + return other; + } + return new NewpagedDiagram(diagram, empty); + } + + public CommandExecutionResult executeCommand(Command cmd, List lines) { + final int nb = diagrams.size(); + return cmd.execute(diagrams.get(nb - 1), lines); + } + + public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException { + return diagrams.get(num).exportDiagram(os, 0, fileFormat); + } + + public int getNbImages() { + int nb = 0; + for (Diagram d : diagrams) { + nb += d.getNbImages(); + } + return nb; + } + + public DiagramDescription getDescription() { + final StringBuilder sb = new StringBuilder(); + for (Diagram d : diagrams) { + if (sb.length() > 0) { + sb.append(" "); + } + sb.append(d.getDescription()); + } + return new DiagramDescriptionImpl(sb.toString(), getClass()); + } + + public String getWarningOrError() { + final StringBuilder sb = new StringBuilder(); + for (Diagram d : diagrams) { + if (sb.length() > 0) { + sb.append(" "); + } + sb.append(d.getWarningOrError()); + } + return sb.toString(); + } + +} diff --git a/src/net/sourceforge/plantuml/EmptyDiagramFactory.java b/src/net/sourceforge/plantuml/NullOutputStream.java similarity index 60% rename from src/net/sourceforge/plantuml/EmptyDiagramFactory.java rename to src/net/sourceforge/plantuml/NullOutputStream.java index 845f7556f..77a7f8fa7 100644 --- a/src/net/sourceforge/plantuml/EmptyDiagramFactory.java +++ b/src/net/sourceforge/plantuml/NullOutputStream.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,31 +28,39 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5890 $ + * Revision $Revision: 4780 $ * */ package net.sourceforge.plantuml; -import net.sourceforge.plantuml.command.AbstractUmlSystemCommandFactory; -import net.sourceforge.plantuml.command.CommandComment; -import net.sourceforge.plantuml.command.CommandMultilinesComment; -import net.sourceforge.plantuml.command.CommandNope; +import java.io.IOException; +import java.io.OutputStream; -public class EmptyDiagramFactory extends AbstractUmlSystemCommandFactory { +// Modified by Maxime Sinclair +public class NullOutputStream extends OutputStream { - private PSystemError system; + /** + * Writes to nowhere + */ + @Override + public void write(int b) throws IOException { + // Do nothing silently + } - public PSystemError getSystem() { - return system; - } + /** + * Overridden for performance reason + */ + @Override + public void write(byte b[]) throws IOException { + // Do nothing silently + } - @Override - protected void initCommands() { - // system = new PSystemError(); - - addCommand(new CommandNope(null)); - addCommand(new CommandComment(null)); - addCommand(new CommandMultilinesComment(null)); - } + /** + * Overridden for performance reason + */ + @Override + public void write(byte b[], int off, int len) throws IOException { + // Do nothing silently + } } diff --git a/src/net/sourceforge/plantuml/Option.java b/src/net/sourceforge/plantuml/Option.java index 39b105da1..d88265e13 100644 --- a/src/net/sourceforge/plantuml/Option.java +++ b/src/net/sourceforge/plantuml/Option.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6702 $ + * Revision $Revision: 12022 $ * */ package net.sourceforge.plantuml; @@ -65,7 +65,7 @@ public class Option { private File outputDir = null; private File outputFile = null; - + private final List result = new ArrayList(); public Option() { @@ -89,6 +89,8 @@ public class Option { String s = arg[i]; if (s.equalsIgnoreCase("-tsvg") || s.equalsIgnoreCase("-svg")) { setFileFormat(FileFormat.SVG); + } else if (s.equalsIgnoreCase("-thtml") || s.equalsIgnoreCase("-html")) { + setFileFormat(FileFormat.HTML); } else if (s.equalsIgnoreCase("-txmi") || s.equalsIgnoreCase("-xmi")) { setFileFormat(FileFormat.XMI_STANDARD); } else if (s.equalsIgnoreCase("-txmi:argo") || s.equalsIgnoreCase("-xmi:argo")) { @@ -99,15 +101,18 @@ public class Option { setFileFormat(FileFormat.EPS); } else if (s.equalsIgnoreCase("-teps:text") || s.equalsIgnoreCase("-eps:text")) { setFileFormat(FileFormat.EPS_TEXT); - } else if (s.equalsIgnoreCase("-tdot") || s.equalsIgnoreCase("-dot")) { - setFileFormat(FileFormat.DOT); - OptionFlags.getInstance().setKeepTmpFiles(true); } 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("-png") || s.equalsIgnoreCase("-tpng")) { + setFileFormat(FileFormat.PNG); + } else if (s.equalsIgnoreCase("-vdx") || s.equalsIgnoreCase("-tvdx")) { + setFileFormat(FileFormat.VDX); } else if (s.equalsIgnoreCase("-pdf") || s.equalsIgnoreCase("-tpdf")) { setFileFormat(FileFormat.PDF); + } else if (s.equalsIgnoreCase("-overwrite")) { + OptionFlags.getInstance().setOverwrite(true); } else if (s.equalsIgnoreCase("-output") || s.equalsIgnoreCase("-o")) { i++; if (i == arg.length) { @@ -166,14 +171,9 @@ public class Option { 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")) { @@ -199,16 +199,16 @@ public class Option { } 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.matches("(?i)^-li[sc][ea]n[sc]e\\s*$")) { + OptionPrint.printLicense(); + } else if (s.equalsIgnoreCase("-checkversion")) { + OptionPrint.checkVersion(); } else if (s.startsWith("-D")) { manageDefine(s.substring(2)); } else if (s.startsWith("-S")) { @@ -223,6 +223,8 @@ public class Option { OptionPrint.printLanguage(); } else if (s.equalsIgnoreCase("-gui")) { OptionFlags.getInstance().setGui(true); + } else if (s.equalsIgnoreCase("-encodesprite")) { + OptionFlags.getInstance().setEncodesprite(true); } else if (s.equalsIgnoreCase("-nosuggestengine")) { OptionFlags.getInstance().setUseSuggestEngine(false); } else if (s.equalsIgnoreCase("-failonerror")) { @@ -236,6 +238,9 @@ public class Option { } else { this.ftpPort = Integer.parseInt(s.substring(x + 1)); } + } else if (s.startsWith("-c")) { + s = s.substring(2); + config.add(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(s)); } else { result.add(s); } @@ -289,7 +294,7 @@ public class Option { } public final static String getPattern() { - return "(?i)^.*\\.(txt|tex|java|htm|html|c|h|cpp|apt)$"; + return "(?i)^.*\\.(txt|tex|java|htm|html|c|h|cpp|apt|pu)$"; } public void setOutputDir(File f) { diff --git a/src/net/sourceforge/plantuml/OptionFlags.java b/src/net/sourceforge/plantuml/OptionFlags.java index 294218eed..bd6cddbe0 100644 --- a/src/net/sourceforge/plantuml/OptionFlags.java +++ b/src/net/sourceforge/plantuml/OptionFlags.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 7231 $ + * Revision $Revision: 11833 $ * */ package net.sourceforge.plantuml; @@ -39,13 +39,20 @@ import java.io.FileOutputStream; import java.io.PrintStream; import java.util.concurrent.atomic.AtomicBoolean; +import net.sourceforge.plantuml.core.Diagram; import net.sourceforge.plantuml.cucadiagram.dot.GraphvizUtils; public class OptionFlags { - static public final boolean PBBACK = false; - static public final boolean GRAPHVIZCACHE = false; - static public final boolean SVEK = false; + // static public final boolean PBBACK = false; + static public boolean GRAPHVIZCACHE = false; + static public final boolean TRACE_DOT = false; + + static public final boolean HORIZONTAL_LINE_BETWEEN_DIFFERENT_PACKAGE_ALLOWED = false; + static public boolean ALLOW_INCLUDE = true; + + static public final boolean USE_HECTOR = false; + static public final boolean USE_CREOLE = true; void reset() { reset(false); @@ -57,9 +64,6 @@ public class OptionFlags { metadata = false; word = false; systemExit = exit; - debugDot = false; - forceGd = false; - forceCairo = false; dotExecutable = null; gui = false; quiet = false; @@ -67,6 +71,8 @@ public class OptionFlags { printFonts = false; useSuggestEngine = true; failOnError = false; + encodesprite = false; + // PIC_LINE = false; } public boolean useJavaInsteadOfDot() { @@ -80,9 +86,6 @@ public class OptionFlags { private boolean metadata; private boolean word; private boolean systemExit; - private boolean debugDot; - private boolean forceGd; - private boolean forceCairo; private String dotExecutable; private boolean gui; private boolean quiet; @@ -90,6 +93,8 @@ public class OptionFlags { private boolean printFonts; private boolean useSuggestEngine; private boolean failOnError; + private boolean encodesprite; + private boolean overwrite; private File logData; private OptionFlags() { @@ -140,14 +145,6 @@ public class OptionFlags { this.systemExit = systemExit; } - public final boolean isDebugDot() { - return debugDot; - } - - public final void setDebugDot(boolean debugDot) { - this.debugDot = debugDot; - } - public final String getDotExecutable() { return dotExecutable; } @@ -164,22 +161,6 @@ public class OptionFlags { 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; } @@ -198,8 +179,9 @@ public class OptionFlags { private final AtomicBoolean logDataInitized = new AtomicBoolean(false); - public void logData(File file, PSystem system) { - if (system instanceof PSystemError == false) { + public void logData(File file, Diagram system) { + final String warnOrError = system.getWarningOrError(); + if (warnOrError == null) { return; } synchronized (logDataInitized) { @@ -214,19 +196,12 @@ public class OptionFlags { if (logData == null) { return; } - final PSystemError systemError = (PSystemError) system; + // final PSystemError systemError = (PSystemError) system; PrintStream ps = null; try { ps = new PrintStream(new FileOutputStream(logData, true)); ps.println("Start of " + file.getName()); - ps.println(systemError.getDescription()); - for (CharSequence t : systemError.getTitle()) { - ps.println(t); - } - systemError.print(ps); - for (String s : systemError.getSuggest()) { - ps.println(s); - } + ps.println(warnOrError); ps.println("End of " + file.getName()); ps.println(); } catch (FileNotFoundException e) { @@ -240,6 +215,17 @@ public class OptionFlags { } } + // public static void logErrorFile(final PSystemError systemError, PrintStream ps) { + // ps.println(systemError.getDescription()); + // for (CharSequence t : systemError.getTitle()) { + // ps.println(t); + // } + // systemError.print(ps); + // for (String s : systemError.getSuggest()) { + // ps.println(s); + // } + // } + public final void setLogData(File logData) { this.logData = logData; logData.delete(); @@ -281,4 +267,20 @@ public class OptionFlags { this.failOnError = failOnError; } + public final boolean isEncodesprite() { + return encodesprite; + } + + public final void setEncodesprite(boolean encodesprite) { + this.encodesprite = encodesprite; + } + + public final boolean isOverwrite() { + return overwrite; + } + + public final void setOverwrite(boolean overwrite) { + this.overwrite = overwrite; + } + } diff --git a/src/net/sourceforge/plantuml/OptionPrint.java b/src/net/sourceforge/plantuml/OptionPrint.java index b8360e3a1..0c3dcac2a 100644 --- a/src/net/sourceforge/plantuml/OptionPrint.java +++ b/src/net/sourceforge/plantuml/OptionPrint.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6626 $ + * Revision $Revision: 11786 $ * */ package net.sourceforge.plantuml; @@ -39,13 +39,16 @@ import java.util.Date; import java.util.Properties; import net.sourceforge.plantuml.cucadiagram.dot.GraphvizUtils; +import net.sourceforge.plantuml.syntax.LanguageDescriptor; +import net.sourceforge.plantuml.version.License; +import net.sourceforge.plantuml.version.PSystemVersion; import net.sourceforge.plantuml.version.Version; public class OptionPrint { static public void printTestDot() throws InterruptedException { for (String s : GraphvizUtils.getTestDotStrings(false)) { - System.err.println(s); + System.out.println(s); } exit(); } @@ -54,54 +57,58 @@ public class OptionPrint { 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] [file/dir] [file/dir] [file/dir]"); - 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(" -teps\t\tTo generate images using EPS format"); - System.err.println(" -txmi\t\tTo generate XMI file for classes diagrams"); - System.err.println(" -tdot\t\tTo generate DOT intermediate file"); - System.err.println(" -ttxt\t\tTo generate images with ASCII art"); - System.err.println(" -tutxt\t\tTo generate images with ASCII art using Unicode characters"); - System.err.println(" -o[utput] \"dir\"\tTo generate images in the specified directory"); - System.err.println(" -DVAR1=value\tTo set a preprocessing variable as if '!define VAR1 value' were used"); - System.err.println(" -Sparam1=value\tTo set a skin parameter as if 'skinparam param1 value' were used"); - 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/EPS generation"); - System.err.println(" -computeurl\t\tTo compute the encoded URL of a PlantUML source file"); - System.err.println(" -decodeurl\t\tTo retrieve the PlantUML source from an encoded URL"); - System.err.println(" -syntax\t\tTo report any syntax error from standard input without generating images"); - System.err.println(" -language\t\tTo print the list of PlantUML keywords"); - System.err.println(" -nosuggestengine\tTo disable the suggest engine when errors in diagrams"); - System.err.println(" -checkonly\t\tTo check the syntax of files without generating images"); - System.err.println(" -failonerror\tTo stop processing if syntax error in diagram occurs"); - System.err.println(" -pattern\t\tTo print the list of Regular Expression used by PlantUML"); - System.err.println(" -duration\t\tTo print the duration of complete diagrams processing"); - System.err.println(" -nbthread N\tTo use (N) threads for processing"); - System.err.println(" -nbthread auto\tTo use " + Option.defaultNbThreads() + " threads for processing"); - System.err.println(); - System.err.println("If needed, you can setup the environment variable GRAPHVIZ_DOT."); + System.out.println("Usage: java -jar plantuml.jar [options] -gui"); + System.out.println("\t(to execute the GUI)"); + System.out.println(" or java -jar plantuml.jar [options] [file/dir] [file/dir] [file/dir]"); + System.out.println("\t(to process files or directories)"); + System.out.println(); + System.out.println("You can use the following wildcards in files/dirs:"); + System.out.println("\t*\tmeans any characters but '" + File.separator + "'"); + System.out.println("\t?\tone and only one character but '" + File.separator + "'"); + System.out.println("\t**\tmeans any characters (used to recurse through directories)"); + System.out.println(); + System.out.println("where options include:"); + System.out.println(" -gui\t\tTo run the graphical user interface"); + System.out.println(" -tpng\t\tTo generate images using PNG format (default)"); + System.out.println(" -tsvg\t\tTo generate images using SVG format"); + System.out.println(" -teps\t\tTo generate images using EPS format"); + System.out.println(" -txmi\t\tTo generate XMI file for class diagram"); + System.out.println(" -thtml\t\tTo generate HTML files for class diagram"); + System.out.println(" -ttxt\t\tTo generate images with ASCII art"); + System.out.println(" -tutxt\t\tTo generate images with ASCII art using Unicode characters"); + System.out.println(" -o[utput] \"dir\"\tTo generate images in the specified directory"); + System.out.println(" -DVAR1=value\tTo set a preprocessing variable as if '!define VAR1 value' were used"); + System.out.println(" -Sparam1=value\tTo set a skin parameter as if 'skinparam param1 value' were used"); + System.out.println(" -config \"file\"\tTo read the provided config file before each diagram"); + System.out.println(" -charset xxx\tTo use a specific charset (default is " + charset + ")"); + System.out.println(" -e[x]clude pattern\tTo exclude files that match the provided pattern"); + System.out.println(" -metadata\t\tTo retrieve PlantUML sources from PNG images"); + System.out.println(" -version\t\tTo display information about PlantUML and Java versions"); + System.out.println(" -checkversion\tTo check if a newer version is available for download"); + System.out.println(" -v[erbose]\t\tTo have log information"); + System.out.println(" -quiet\t\tTo NOT print error message into the console"); + // Log.println(" -forcegd\t\tTo force dot to use GD PNG library"); + // Log.println(" -forcecairo\t\tTo force dot to use Cairo PNG library"); + System.out.println(" -keepfiles\t\tTo NOT delete temporary files after process"); + System.out.println(" -h[elp]\t\tTo display this help message"); + System.out.println(" -testdot\t\tTo test the installation of graphviz"); + System.out.println(" -graphvizdot \"exe\"\tTo specify dot executable"); + System.out.println(" -p[ipe]\t\tTo use stdin for PlantUML source and stdout for PNG/SVG/EPS generation"); + System.out.println(" -computeurl\t\tTo compute the encoded URL of a PlantUML source file"); + System.out.println(" -decodeurl\t\tTo retrieve the PlantUML source from an encoded URL"); + System.out.println(" -syntax\t\tTo report any syntax error from standard input without generating images"); + System.out.println(" -language\t\tTo print the list of PlantUML keywords"); + System.out.println(" -nosuggestengine\tTo disable the suggest engine when errors in diagrams"); + System.out.println(" -checkonly\t\tTo check the syntax of files without generating images"); + System.out.println(" -failonerror\tTo stop processing if syntax error in diagram occurs"); + System.out.println(" -pattern\t\tTo print the list of Regular Expression used by PlantUML"); + System.out.println(" -duration\t\tTo print the duration of complete diagrams processing"); + System.out.println(" -nbthread N\t\tTo use (N) threads for processing"); + System.out.println(" -nbthread auto\tTo use " + Option.defaultNbThreads() + " threads for processing"); + System.out.println(" -author[s]\t\tTo print information about PlantUML authors"); + System.out.println(" -overwrite\t\tTo all to overwrite read only files"); + System.out.println(); + System.out.println("If needed, you can setup the environment variable GRAPHVIZ_DOT."); exit(); } @@ -112,25 +119,66 @@ public class OptionPrint { throw new InterruptedException("exit"); } + public static void printLicense() throws InterruptedException { + for (String s : License.getCurrent().getText()) { + System.out.println(s); + } + exit(); + } + public static void printVersion() throws InterruptedException { - System.err.println("PlantUML version " + Version.version() + " (" + new Date(Version.compileTime()) + ")"); + System.out + .println("PlantUML version " + Version.versionString() + " (" + new Date(Version.compileTime()) + ")"); + System.out.println("(" + License.getCurrent() + " source distribution)"); 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")); + System.out.println(p.getProperty("java.runtime.name")); + System.out.println(p.getProperty("java.vm.name")); + System.out.println(p.getProperty("java.runtime.version")); + System.out.println(p.getProperty("os.name")); + System.out.println(); + for (String s : GraphvizUtils.getTestDotStrings(false)) { + System.out.println(s); + } + exit(); + } + + public static void checkVersion() throws InterruptedException { + System.out + .println("PlantUML version " + Version.versionString() + " (" + new Date(Version.compileTime()) + ")"); + System.out.println(); + final int lastversion = PSystemVersion.extractDownloadableVersion(null, null); + if (lastversion == -1) { + System.out.println("Error"); + System.out.println("Cannot connect to http://plantuml.sourceforge.net/"); + System.out.println("Maybe you should set your proxy ?"); + } else if (lastversion == 0) { + System.out.println("Error"); + System.out.println("Cannot retrieve last version from http://plantuml.sourceforge.net/"); + } else { + System.out.println("Last available version for download : " + lastversion); + System.out.println(); + if (Version.version() >= lastversion) { + System.out.println("Your version is up to date."); + } else { + System.out.println("A newer version is available for download."); + } + } + 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"); + // Duplicate in PSystemVersion + System.out + .println("PlantUML version " + Version.versionString() + " (" + new Date(Version.compileTime()) + ")"); + System.out.println(); + System.out.println("Original idea: Arnaud Roques"); + System.out.println("Word Macro: Alain Bertucat & Matthieu Sabatier"); + System.out.println("Eclipse Plugin: Claude Durif & Anne Pecoil"); + System.out.println("Servlet & XWiki: Maxime Sinclair"); + System.out.println("Site design: Raphael Cotisson"); + System.out.println(); + System.out.println("http://plantuml.sourceforge.net"); exit(); } diff --git a/src/net/sourceforge/plantuml/PSystemBuilder.java b/src/net/sourceforge/plantuml/PSystemBuilder.java index ce556d1dc..b58f12e43 100644 --- a/src/net/sourceforge/plantuml/PSystemBuilder.java +++ b/src/net/sourceforge/plantuml/PSystemBuilder.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,50 +33,63 @@ */ package net.sourceforge.plantuml; -import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.List; import net.sourceforge.plantuml.acearth.PSystemXearthFactory; import net.sourceforge.plantuml.activitydiagram.ActivityDiagramFactory; -import net.sourceforge.plantuml.activitydiagram2.ActivityDiagramFactory2; +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagramFactory3; +import net.sourceforge.plantuml.api.PSystemFactory; import net.sourceforge.plantuml.classdiagram.ClassDiagramFactory; -import net.sourceforge.plantuml.componentdiagram.ComponentDiagramFactory; import net.sourceforge.plantuml.compositediagram.CompositeDiagramFactory; +import net.sourceforge.plantuml.core.Diagram; +import net.sourceforge.plantuml.core.DiagramType; +import net.sourceforge.plantuml.core.UmlSource; +import net.sourceforge.plantuml.creole.PSystemCreoleFactory; +import net.sourceforge.plantuml.descdiagram.DescriptionDiagramFactory; import net.sourceforge.plantuml.directdot.PSystemDotFactory; import net.sourceforge.plantuml.ditaa.PSystemDitaaFactory; +import net.sourceforge.plantuml.donors.PSystemDonorsFactory; +import net.sourceforge.plantuml.eggs.PSystemAppleTwoFactory; 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.flowdiagram.FlowDiagramFactory; +import net.sourceforge.plantuml.font.PSystemListFontsFactory; import net.sourceforge.plantuml.jcckit.PSystemJcckitFactory; +import net.sourceforge.plantuml.logo.PSystemLogoFactory; import net.sourceforge.plantuml.objectdiagram.ObjectDiagramFactory; import net.sourceforge.plantuml.oregon.PSystemOregonFactory; import net.sourceforge.plantuml.postit.PostIdDiagramFactory; import net.sourceforge.plantuml.printskin.PrintSkinFactory; -import net.sourceforge.plantuml.project.PSystemProjectFactory; +import net.sourceforge.plantuml.project2.PSystemProjectFactory2; import net.sourceforge.plantuml.salt.PSystemSaltFactory; 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.turing.PSystemTuringFactory; +import net.sourceforge.plantuml.version.License; +import net.sourceforge.plantuml.version.PSystemLicenseFactory; import net.sourceforge.plantuml.version.PSystemVersionFactory; public class PSystemBuilder { - final public PSystem createPSystem(final List strings) throws IOException, InterruptedException { + final public Diagram createPSystem(final List strings) { final List factories = getAllFactories(); - final UmlSource umlSource = new UmlSource(strings); + final DiagramType type = DiagramType.getTypeFromArobaseStart(strings.get(0).toString()); + + final UmlSource umlSource = new UmlSource(strings, type == DiagramType.UML); final DiagramType diagramType = umlSource.getDiagramType(); final List errors = new ArrayList(); for (PSystemFactory systemFactory : factories) { if (diagramType != systemFactory.getDiagramType()) { continue; } - final PSystem sys = new PSystemSingleBuilder(umlSource, systemFactory).getPSystem(); + final Diagram sys = systemFactory.createSystem(umlSource); if (isOk(sys)) { return sys; } @@ -84,9 +97,9 @@ public class PSystemBuilder { } final PSystemError err = merge(errors); - if (OptionFlags.getInstance().isQuiet() == false) { - err.print(System.err); - } +// if (OptionFlags.getInstance().isQuiet() == false) { +// err.print(System.err); +// } return err; } @@ -96,32 +109,42 @@ public class PSystemBuilder { factories.add(new SequenceDiagramFactory()); factories.add(new ClassDiagramFactory()); factories.add(new ActivityDiagramFactory()); - factories.add(new ActivityDiagramFactory2()); - factories.add(new UsecaseDiagramFactory()); - factories.add(new ComponentDiagramFactory()); + factories.add(new DescriptionDiagramFactory()); factories.add(new StateDiagramFactory()); - factories.add(new ActivityDiagramFactory2()); + factories.add(new ActivityDiagramFactory3()); factories.add(new CompositeDiagramFactory()); factories.add(new ObjectDiagramFactory()); factories.add(new PostIdDiagramFactory()); factories.add(new PrintSkinFactory()); + factories.add(new PSystemLicenseFactory()); factories.add(new PSystemVersionFactory()); + factories.add(new PSystemDonorsFactory()); + factories.add(new PSystemListFontsFactory()); factories.add(new PSystemSaltFactory(DiagramType.SALT)); factories.add(new PSystemSaltFactory(DiagramType.UML)); factories.add(new PSystemDotFactory(DiagramType.DOT)); factories.add(new PSystemDotFactory(DiagramType.UML)); - factories.add(new PSystemDitaaFactory(DiagramType.DITAA)); - factories.add(new PSystemDitaaFactory(DiagramType.UML)); - factories.add(new PSystemJcckitFactory(DiagramType.JCCKIT)); - factories.add(new PSystemJcckitFactory(DiagramType.UML)); - factories.add(new PSystemSudokuFactory()); + if (License.getCurrent() == License.GPL) { + factories.add(new PSystemDitaaFactory(DiagramType.DITAA)); + factories.add(new PSystemDitaaFactory(DiagramType.UML)); + factories.add(new PSystemJcckitFactory(DiagramType.JCCKIT)); + factories.add(new PSystemJcckitFactory(DiagramType.UML)); + factories.add(new PSystemLogoFactory()); + factories.add(new PSystemSudokuFactory()); + factories.add(new PSystemTuringFactory()); + } + factories.add(new PSystemCreoleFactory()); factories.add(new PSystemEggFactory()); + factories.add(new PSystemAppleTwoFactory()); factories.add(new PSystemRIPFactory()); factories.add(new PSystemLostFactory()); factories.add(new PSystemPathFactory()); factories.add(new PSystemOregonFactory()); - factories.add(new PSystemXearthFactory()); - factories.add(new PSystemProjectFactory()); + if (License.getCurrent() == License.GPL) { + factories.add(new PSystemXearthFactory()); + } + factories.add(new PSystemProjectFactory2()); + factories.add(new FlowDiagramFactory()); return factories; } @@ -140,7 +163,7 @@ public class PSystemBuilder { return new PSystemError(source, errors); } - private boolean isOk(PSystem ps) { + private boolean isOk(Diagram ps) { if (ps == null || ps instanceof PSystemError) { return false; } diff --git a/src/net/sourceforge/plantuml/PSystemError.java b/src/net/sourceforge/plantuml/PSystemError.java index c08dfc348..05a30625c 100644 --- a/src/net/sourceforge/plantuml/PSystemError.java +++ b/src/net/sourceforge/plantuml/PSystemError.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6622 $ + * Revision $Revision: 12053 $ */ package net.sourceforge.plantuml; @@ -41,6 +41,10 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.List; +import net.sourceforge.plantuml.core.DiagramDescription; +import net.sourceforge.plantuml.core.DiagramDescriptionImpl; +import net.sourceforge.plantuml.core.ImageData; +import net.sourceforge.plantuml.core.UmlSource; import net.sourceforge.plantuml.graphic.GraphicStrings; public class PSystemError extends AbstractPSystem { @@ -76,13 +80,9 @@ public class PSystemError extends AbstractPSystem { this(source, Collections.singletonList(singleError)); } - public void exportDiagram(OutputStream os, StringBuilder cmap, int index, FileFormatOption fileFormat) - throws IOException { - getPngError().writeImage(os, getMetadata(), fileFormat); - } - - public GraphicStrings getPngError() throws IOException { - return new GraphicStrings(htmlStrings); + public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException { + final GraphicStrings result = new GraphicStrings(htmlStrings); + return result.exportDiagram(os, getMetadata(), fileFormat); } private void appendSource(int position) { @@ -186,11 +186,11 @@ public class PSystemError extends AbstractPSystem { return result; } - public String getDescription() { - return "(Error)"; + public DiagramDescription getDescription() { + return new DiagramDescriptionImpl("(Error)", getClass()); } - public void print(PrintStream ps) { + private void print(PrintStream ps) { synchronized (ps) { for (String s : plainStrings) { ps.println(StringUtils.showComparatorCharacters(s)); @@ -205,4 +205,21 @@ public class PSystemError extends AbstractPSystem { public final Collection getErrorsUml() { return Collections.unmodifiableCollection(printedErrors); } + + @Override + public String getWarningOrError() { + final StringBuilder sb = new StringBuilder(); + sb.append(getDescription()); + sb.append('\n'); + for (CharSequence t : getTitle()) { + sb.append(t); + sb.append('\n'); + } + sb.append('\n'); + for (String s : getSuggest()) { + sb.append(s); + sb.append('\n'); + } + return sb.toString(); + } } diff --git a/src/net/sourceforge/plantuml/PSystemSingleBuilder.java b/src/net/sourceforge/plantuml/PSystemSingleBuilder.java deleted file mode 100644 index ddc555fe2..000000000 --- a/src/net/sourceforge/plantuml/PSystemSingleBuilder.java +++ /dev/null @@ -1,225 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 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.AbstractUmlSystemCommandFactory; -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; -import net.sourceforge.plantuml.suggest.SuggestEngine; -import net.sourceforge.plantuml.suggest.SuggestEngineResult; -import net.sourceforge.plantuml.suggest.SuggestEngineStatus; - -final public class PSystemSingleBuilder { - - private final Iterator it; - private final UmlSource source; - private final String startLine; - - 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(UmlSource s, PSystemFactory systemFactory) throws IOException { - this.source = s; - it = s.iterator(); - startLine = next(); - if (StartUtils.isArobaseStartDiagram(startLine) == false) { - throw new UnsupportedOperationException(); - } - - if (s.isEmpty()) { - sys = buildEmptyError(); - } else if (systemFactory instanceof PSystemCommandFactory) { - executeUmlCommand((PSystemCommandFactory) systemFactory); - } else if (systemFactory instanceof PSystemBasicFactory) { - executeUmlBasic((PSystemBasicFactory) systemFactory); - } - } - - private void executeUmlBasic(PSystemBasicFactory systemFactory) throws IOException { - systemFactory.init(startLine); - while (hasNext()) { - final String s = next(); - if (StartUtils.isArobaseEndDiagram(s)) { - if (source.getSize() == 2) { - assert false; - sys = buildEmptyError(); - } 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() { - final PSystemError result = new PSystemError(source, new ErrorUml(ErrorUmlType.SYNTAX_ERROR, - "Empty description", 1)); - result.setSource(source); - return result; - } - - private PSystemError buildEmptyError(String err) { - final PSystemError result = new PSystemError(source, new ErrorUml(ErrorUmlType.EXECUTION_ERROR, err, 1)); - result.setSource(source); - return result; - } - - private void executeUmlCommand(PSystemCommandFactory systemFactory) throws IOException { - systemFactory.init(startLine); - while (hasNext()) { - final String s = next(); - if (StartUtils.isArobaseEndDiagram(s)) { - final String err = ((AbstractUmlSystemCommandFactory) systemFactory).checkFinalError(); - if (err != null) { - sys = buildEmptyError(err); - } - if (source.getSize() == 2) { - assert false; - sys = buildEmptyError(); - } 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) { - final ErrorUml err = new ErrorUml(ErrorUmlType.SYNTAX_ERROR, "Syntax Error?", nb - 1); - if (OptionFlags.getInstance().isUseSuggestEngine()) { - final SuggestEngine engine = new SuggestEngine(source, systemFactory); - final SuggestEngineResult result = engine.tryToSuggest(); - if (result.getStatus() == SuggestEngineStatus.ONE_SUGGESTION) { - err.setSuggest(result); - } - } - sys = new PSystemError(source, err); - 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 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 lines = new ArrayList(); - lines.add(init); - while (hasNext()) { - final String s = next(); - if (StartUtils.isArobaseEndDiagram(s)) { - return false; - } - lines.add(s); - final CommandControl commandControl = systemFactory.isValid(lines); - if (commandControl == CommandControl.NOT_OK) { - // throw new IllegalStateException(); - return false; - } - if (commandControl == CommandControl.OK) { - final Command cmd = systemFactory.createCommand(lines); - testDeprecated(lines, cmd); - return cmd.execute(lines).isOk(); - } - } - return false; - - } - -} diff --git a/src/net/sourceforge/plantuml/PSystemUtils.java b/src/net/sourceforge/plantuml/PSystemUtils.java new file mode 100644 index 000000000..efa7b39a4 --- /dev/null +++ b/src/net/sourceforge/plantuml/PSystemUtils.java @@ -0,0 +1,230 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 9997 $ + * + */ +package net.sourceforge.plantuml; + +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +import net.sourceforge.plantuml.core.Diagram; +import net.sourceforge.plantuml.core.ImageData; +import net.sourceforge.plantuml.cucadiagram.CucaDiagram; +import net.sourceforge.plantuml.html.CucaDiagramHtmlMaker; +import net.sourceforge.plantuml.png.PngSplitter; +import net.sourceforge.plantuml.sequencediagram.SequenceDiagram; + +public class PSystemUtils { + + public static List exportDiagrams(Diagram system, File suggestedFile, FileFormatOption fileFormatOption) + throws IOException { + if (system instanceof NewpagedDiagram) { + return exportDiagramsNewpaged((NewpagedDiagram) system, suggestedFile, fileFormatOption); + } + if (system instanceof SequenceDiagram) { + return exportDiagramsSequence((SequenceDiagram) system, suggestedFile, fileFormatOption); + } + if (system instanceof CucaDiagram) { + return exportDiagramsCuca((CucaDiagram) system, suggestedFile, fileFormatOption); + } + if (system instanceof ActivityDiagram3) { + return exportDiagramsActivityDiagram3((ActivityDiagram3) system, suggestedFile, fileFormatOption); + } + return exportDiagramsDefault(system, suggestedFile, fileFormatOption); + } + + private static List exportDiagramsNewpaged(NewpagedDiagram system, File suggestedFile, + FileFormatOption fileFormat) throws IOException { + final List result = new ArrayList(); + final int nbImages = system.getNbImages(); + for (int i = 0; i < nbImages; i++) { + + final File f = fileFormat.getFileFormat().computeFilename(suggestedFile, i); + if (canFileBeWritten(f) == false) { + return result; + } + final OutputStream fos = new BufferedOutputStream(new FileOutputStream(f)); + // ImageData cmap = null; + try { + /* cmap = */system.exportDiagram(fos, i, fileFormat); + } finally { + fos.close(); + } + // if (system.hasUrl() && cmap != null && cmap.containsCMapData()) { + // system.exportCmap(suggestedFile, cmap); + // } + Log.info("File size : " + f.length()); + result.add(f); + } + return result; + } + + public static boolean canFileBeWritten(final File f) { + Log.info("Creating file: " + f); + if (f.exists() && f.canWrite() == false) { + if (OptionFlags.getInstance().isOverwrite()) { + Log.info("Overwrite " + f); + f.setWritable(true); + f.delete(); + return true; + } + Log.error("Cannot write to file " + f); + return false; + } + return true; + } + + static private List exportDiagramsDefault(Diagram system, File suggestedFile, FileFormatOption fileFormat) + throws IOException { + if (suggestedFile.exists() && suggestedFile.isDirectory()) { + throw new IllegalArgumentException("File is a directory " + suggestedFile); + } + OutputStream os = null; + try { + if (canFileBeWritten(suggestedFile) == false) { + return Collections.emptyList(); + } + os = new BufferedOutputStream(new FileOutputStream(suggestedFile)); + // system.exportDiagram(os, null, 0, fileFormat); + system.exportDiagram(os, 0, fileFormat); + } finally { + if (os != null) { + os.close(); + } + } + return Arrays.asList(suggestedFile); + } + + static private List exportDiagramsActivityDiagram3(ActivityDiagram3 system, File suggestedFile, + FileFormatOption fileFormat) throws IOException { + if (suggestedFile.exists() && suggestedFile.isDirectory()) { + throw new IllegalArgumentException("File is a directory " + suggestedFile); + } + OutputStream os = null; + ImageData cmap = null; + try { + if (canFileBeWritten(suggestedFile) == false) { + return Collections.emptyList(); + } + os = new BufferedOutputStream(new FileOutputStream(suggestedFile)); + cmap = system.exportDiagram(os, 0, fileFormat); + } finally { + if (os != null) { + os.close(); + } + } + if (system.hasUrl() && cmap != null && cmap.containsCMapData()) { + system.exportCmap(suggestedFile, cmap); + } + return Arrays.asList(suggestedFile); + } + + private static List exportDiagramsSequence(SequenceDiagram system, File suggestedFile, + FileFormatOption fileFormat) throws IOException { + final List result = new ArrayList(); + final int nbImages = system.getNbImages(); + for (int i = 0; i < nbImages; i++) { + + final File f = fileFormat.getFileFormat().computeFilename(suggestedFile, i); + if (canFileBeWritten(suggestedFile) == false) { + return result; + } + final OutputStream fos = new BufferedOutputStream(new FileOutputStream(f)); + ImageData cmap = null; + try { + cmap = system.exportDiagram(fos, i, fileFormat); + } finally { + fos.close(); + } + if (system.hasUrl() && cmap != null && cmap.containsCMapData()) { + system.exportCmap(suggestedFile, cmap); + } + Log.info("File size : " + f.length()); + result.add(f); + } + return result; + } + + static public List exportDiagramsCuca(CucaDiagram system, File suggestedFile, FileFormatOption fileFormat) + throws IOException { + if (suggestedFile.exists() && suggestedFile.isDirectory()) { + throw new IllegalArgumentException("File is a directory " + suggestedFile); + } + + if (fileFormat.getFileFormat() == FileFormat.HTML) { + return createFilesHtml(system, suggestedFile); + } + + ImageData cmap = null; + OutputStream os = null; + try { + if (canFileBeWritten(suggestedFile) == false) { + return Collections.emptyList(); + } + os = new BufferedOutputStream(new FileOutputStream(suggestedFile)); + cmap = system.exportDiagram(os, 0, fileFormat); + } finally { + if (os != null) { + os.close(); + } + } + List result = Arrays.asList(suggestedFile); + + if (system.hasUrl() && cmap != null && cmap.containsCMapData()) { + system.exportCmap(suggestedFile, cmap); + } + + if (fileFormat.getFileFormat() == FileFormat.PNG) { + result = new PngSplitter(suggestedFile, system.getHorizontalPages(), system.getVerticalPages(), + system.getMetadata(), system.getDpi(fileFormat), fileFormat.isWithMetadata()).getFiles(); + } + return result; + + } + + private static List createFilesHtml(CucaDiagram system, File suggestedFile) throws IOException { + final String name = suggestedFile.getName(); + final int idx = name.lastIndexOf('.'); + final File dir = new File(suggestedFile.getParentFile(), name.substring(0, idx)); + final CucaDiagramHtmlMaker maker = new CucaDiagramHtmlMaker(system, dir); + return maker.create(); + } + +} diff --git a/src/net/sourceforge/plantuml/Pragma.java b/src/net/sourceforge/plantuml/Pragma.java index 0eae22abf..d5b371b96 100644 --- a/src/net/sourceforge/plantuml/Pragma.java +++ b/src/net/sourceforge/plantuml/Pragma.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -45,7 +45,7 @@ public class Pragma { public void define(String name, String value) { values.put(name, value); if (name.equalsIgnoreCase("graphviz_dot")) { - OptionFlags.getInstance().setDotExecutable(value); + OptionFlags.getInstance().setDotExecutable(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(value)); } } @@ -58,11 +58,7 @@ public class Pragma { } public String getValue(String name) { - final String result = values.get(name); - if (result == null) { - throw new IllegalArgumentException(); - } - return result; + return values.get(name); } protected Set> entrySet() { diff --git a/src/net/sourceforge/plantuml/Removeable.java b/src/net/sourceforge/plantuml/Removeable.java new file mode 100644 index 000000000..a78ae5ea4 --- /dev/null +++ b/src/net/sourceforge/plantuml/Removeable.java @@ -0,0 +1,40 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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; + +public interface Removeable { + + public boolean isRemoved(); + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/Run.java b/src/net/sourceforge/plantuml/Run.java index f8c25319c..cc38beeda 100644 --- a/src/net/sourceforge/plantuml/Run.java +++ b/src/net/sourceforge/plantuml/Run.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,13 +28,14 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6750 $ + * Revision $Revision: 12023 $ * */ package net.sourceforge.plantuml; import java.awt.Font; import java.awt.GraphicsEnvironment; +import java.awt.image.BufferedImage; import java.io.BufferedReader; import java.io.File; import java.io.IOException; @@ -43,18 +44,19 @@ import java.io.PrintStream; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; +import javax.imageio.ImageIO; import javax.swing.UIManager; import net.sourceforge.plantuml.activitydiagram.ActivityDiagramFactory; import net.sourceforge.plantuml.classdiagram.ClassDiagramFactory; import net.sourceforge.plantuml.code.Transcoder; import net.sourceforge.plantuml.code.TranscoderUtil; -import net.sourceforge.plantuml.command.AbstractUmlSystemCommandFactory; -import net.sourceforge.plantuml.componentdiagram.ComponentDiagramFactory; +import net.sourceforge.plantuml.command.UmlDiagramFactory; +import net.sourceforge.plantuml.core.Diagram; +import net.sourceforge.plantuml.descdiagram.DescriptionDiagramFactory; import net.sourceforge.plantuml.ftp.FtpServer; import net.sourceforge.plantuml.objectdiagram.ObjectDiagramFactory; import net.sourceforge.plantuml.png.MetadataTag; @@ -62,16 +64,29 @@ import net.sourceforge.plantuml.preproc.Defines; import net.sourceforge.plantuml.sequencediagram.SequenceDiagramFactory; import net.sourceforge.plantuml.statediagram.StateDiagramFactory; import net.sourceforge.plantuml.swing.MainWindow2; -import net.sourceforge.plantuml.usecasediagram.UsecaseDiagramFactory; +import net.sourceforge.plantuml.ugraphic.SpriteGrayLevel; +import net.sourceforge.plantuml.ugraphic.SpriteUtils; +import net.sourceforge.plantuml.version.Version; public class Run { public static void main(String[] argsArray) throws IOException, InterruptedException { final long start = System.currentTimeMillis(); final Option option = new Option(argsArray); + if (OptionFlags.getInstance().isEncodesprite()) { + encodeSprite(option.getResult()); + return; + } if (OptionFlags.getInstance().isVerbose()) { + Log.info("PlantUML Version " + Version.versionString()); Log.info("GraphicsEnvironment.isHeadless() " + GraphicsEnvironment.isHeadless()); } + if (GraphicsEnvironment.isHeadless()) { + Log.info("Forcing -Djava.awt.headless=true"); + System.setProperty("java.awt.headless", "true"); + Log.info("java.awt.headless set as true"); + + } if (OptionFlags.getInstance().isPrintFonts()) { printFonts(); return; @@ -83,6 +98,7 @@ public class Run { } boolean error = false; + boolean forceQuit = false; if (option.isPattern()) { managePattern(); } else if (OptionFlags.getInstance().isGui()) { @@ -93,8 +109,10 @@ public class Run { new MainWindow2(option); } else if (option.isPipe() || option.isSyntax()) { managePipe(option); + forceQuit = true; } else { error = manageAllFiles(option); + forceQuit = true; } if (option.isDuration()) { @@ -106,6 +124,53 @@ public class Run { Log.error("Some diagram description contains errors"); System.exit(1); } + + if (forceQuit && OptionFlags.getInstance().isSystemExit()) { + System.exit(0); + } + } + + private static void encodeSprite(List result) throws IOException { + SpriteGrayLevel level = SpriteGrayLevel.GRAY_16; + boolean compressed = false; + final File f; + if (result.size() > 1 && result.get(0).matches("(4|8|16)z?")) { + if (result.get(0).startsWith("8")) { + level = SpriteGrayLevel.GRAY_8; + } + if (result.get(0).startsWith("4")) { + level = SpriteGrayLevel.GRAY_4; + } + compressed = result.get(0).toLowerCase().endsWith("z"); + f = new File(result.get(1)); + } else { + f = new File(result.get(0)); + } + final BufferedImage im = ImageIO.read(f); + final String name = getSpriteName(f); + final String s = compressed ? SpriteUtils.encodeCompressed(im, name, level) : SpriteUtils.encode(im, name, + level); + System.out.println(s); + } + + private static String getSpriteName(File f) { + final String s = getSpriteNameInternal(f); + if (s.length() == 0) { + return "test"; + } + return s; + } + + private static String getSpriteNameInternal(File f) { + final StringBuilder sb = new StringBuilder(); + for (char c : f.getName().toCharArray()) { + if (("" + c).matches("[\\p{L}0-9_]")) { + sb.append(c); + } else { + return sb.toString(); + } + } + return sb.toString(); } private static void goFtp(Option option) throws IOException { @@ -132,17 +197,17 @@ public class Run { printPattern(new SequenceDiagramFactory()); printPattern(new ClassDiagramFactory()); printPattern(new ActivityDiagramFactory()); - printPattern(new UsecaseDiagramFactory()); - printPattern(new ComponentDiagramFactory()); + printPattern(new DescriptionDiagramFactory()); + // printPattern(new ComponentDiagramFactory()); printPattern(new StateDiagramFactory()); printPattern(new ObjectDiagramFactory()); } - private static void printPattern(AbstractUmlSystemCommandFactory factory) { - factory.init(null); + private static void printPattern(UmlDiagramFactory factory) { System.out.println(); System.out.println(factory.getClass().getSimpleName().replaceAll("Factory", "")); - for (String s : factory.getDescription()) { + final List descriptions = factory.getDescription(); + for (String s : descriptions) { System.out.println(s); } } @@ -172,27 +237,23 @@ public class Run { 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 (ErrorUml er : sys.getErrorsUml()) { - ps.println(er.getError()); - } - } else { - ps.println("OTHER"); - ps.println(system.getDescription()); + final Diagram system = sourceStringReader.getBlocks().get(0).getDiagram(); + 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 (ErrorUml er : sys.getErrorsUml()) { + ps.println(er.getError()); } - } catch (InterruptedException e) { - Log.error("InterruptedException " + e); + } else { + ps.println("OTHER"); + ps.println(system.getDescription()); } } else if (option.isPipe()) { - final String result = sourceStringReader.generateImage(ps, 0, option.getFileFormatOption()); + sourceStringReader.generateImage(ps, 0, option.getFileFormatOption()); } } @@ -250,7 +311,7 @@ public class Run { for (String s : option.getResult()) { final FileGroup group = new FileGroup(s, option.getExcludes(), option); for (final File f : group.getFiles()) { - final Future future = executor.submit(new Runnable() { + executor.submit(new Runnable() { public void run() { if (errors.get()) { return; @@ -286,11 +347,11 @@ public class Run { } final ISourceFileReader sourceFileReader; if (option.getOutputFile() == null) { - sourceFileReader = new SourceFileReader(option.getDefaultDefines(), f, option.getOutputDir(), option - .getConfig(), option.getCharset(), option.getFileFormatOption()); + sourceFileReader = new SourceFileReader(option.getDefaultDefines(), f, option.getOutputDir(), + option.getConfig(), option.getCharset(), option.getFileFormatOption()); } else { - sourceFileReader = new SourceFileReader2(option.getDefaultDefines(), f, option.getOutputFile(), option - .getConfig(), option.getCharset(), option.getFileFormatOption()); + sourceFileReader = new SourceFileReader2(option.getDefaultDefines(), f, option.getOutputFile(), + option.getConfig(), option.getCharset(), option.getFileFormatOption()); } if (option.isComputeurl()) { final List urls = sourceFileReader.getEncodedUrl(); diff --git a/src/net/sourceforge/plantuml/Scale.java b/src/net/sourceforge/plantuml/Scale.java index 292c5aafe..c4d89c358 100644 --- a/src/net/sourceforge/plantuml/Scale.java +++ b/src/net/sourceforge/plantuml/Scale.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/ScaleHeight.java b/src/net/sourceforge/plantuml/ScaleHeight.java index 28b0434d5..e39d65f58 100644 --- a/src/net/sourceforge/plantuml/ScaleHeight.java +++ b/src/net/sourceforge/plantuml/ScaleHeight.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/ScaleSimple.java b/src/net/sourceforge/plantuml/ScaleSimple.java index 8854b81cf..a1d585f4f 100644 --- a/src/net/sourceforge/plantuml/ScaleSimple.java +++ b/src/net/sourceforge/plantuml/ScaleSimple.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/ScaleWidth.java b/src/net/sourceforge/plantuml/ScaleWidth.java index 57dbe92f4..5f3a1a90f 100644 --- a/src/net/sourceforge/plantuml/ScaleWidth.java +++ b/src/net/sourceforge/plantuml/ScaleWidth.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/ScaleWidthAndHeight.java b/src/net/sourceforge/plantuml/ScaleWidthAndHeight.java index ad3b3ce3f..0701873fc 100644 --- a/src/net/sourceforge/plantuml/ScaleWidthAndHeight.java +++ b/src/net/sourceforge/plantuml/ScaleWidthAndHeight.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/SignatureUtils.java b/src/net/sourceforge/plantuml/SignatureUtils.java index 31686d057..2dfd849dd 100644 --- a/src/net/sourceforge/plantuml/SignatureUtils.java +++ b/src/net/sourceforge/plantuml/SignatureUtils.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5877 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml; @@ -53,10 +53,10 @@ public class SignatureUtils { return coder.encode(digest); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); - throw new IllegalStateException(); + throw new UnsupportedOperationException(e); } catch (UnsupportedEncodingException e) { e.printStackTrace(); - throw new IllegalStateException(); + throw new UnsupportedOperationException(e); } } @@ -87,10 +87,10 @@ public class SignatureUtils { return coder.encode(digest); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); - throw new IllegalStateException(); + throw new UnsupportedOperationException(e); } catch (UnsupportedEncodingException e) { e.printStackTrace(); - throw new IllegalStateException(); + throw new UnsupportedOperationException(e); } } } diff --git a/src/net/sourceforge/plantuml/SingleLine.java b/src/net/sourceforge/plantuml/SingleLine.java index 1a9960282..bb3ebfb55 100644 --- a/src/net/sourceforge/plantuml/SingleLine.java +++ b/src/net/sourceforge/plantuml/SingleLine.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,12 +28,14 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3824 $ + * Revision $Revision: 10298 $ * */ package net.sourceforge.plantuml; +import net.sourceforge.plantuml.core.Diagram; + public interface SingleLine { - PSystem getSystemFromSingleLine(String singleLine); + Diagram getSystemFromSingleLine(String singleLine); } diff --git a/src/net/sourceforge/plantuml/SkinParam.java b/src/net/sourceforge/plantuml/SkinParam.java index 08be6e591..46792ec68 100644 --- a/src/net/sourceforge/plantuml/SkinParam.java +++ b/src/net/sourceforge/plantuml/SkinParam.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 7230 $ + * Revision $Revision: 11707 $ * */ package net.sourceforge.plantuml; @@ -46,12 +46,17 @@ import java.util.regex.Pattern; import net.sourceforge.plantuml.cucadiagram.dot.DotSplines; import net.sourceforge.plantuml.cucadiagram.dot.GraphvizLayoutStrategy; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.svek.ConditionStyle; +import net.sourceforge.plantuml.svek.PackageStyle; import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity; import net.sourceforge.plantuml.ugraphic.ColorMapperMonochrome; +import net.sourceforge.plantuml.ugraphic.Sprite; import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UStroke; public class SkinParam implements ISkinParam { @@ -68,11 +73,21 @@ public class SkinParam implements ISkinParam { public SkinParam(UmlDiagramType type) { this.type = type; + if (type == null) { + setParam("shadowing", "false"); + } } static String cleanForKey(String key) { key = key.toLowerCase().trim(); key = key.replaceAll("_|\\.|\\s", ""); + key = key.replaceAll("partition", "package"); + key = key.replaceAll("activityarrow", "genericarrow"); + key = key.replaceAll("objectarrow", "genericarrow"); + key = key.replaceAll("classarrow", "genericarrow"); + key = key.replaceAll("componentarrow", "genericarrow"); + key = key.replaceAll("statearrow", "genericarrow"); + key = key.replaceAll("usecasearrow", "genericarrow"); final Matcher m = stereoPattern.matcher(key); if (m.find()) { final String s = m.group(1); @@ -83,9 +98,9 @@ public class SkinParam implements ISkinParam { } public HtmlColor getBackgroundColor() { - final HtmlColor result = getHtmlColor(ColorParam.background, null); + final HtmlColor result = getHtmlColor(ColorParam.background, null, false); if (result == null) { - return HtmlColor.WHITE; + return HtmlColorUtils.WHITE; } return result; } @@ -109,19 +124,30 @@ public class SkinParam implements ISkinParam { return sb.toString(); } - public HtmlColor getHtmlColor(ColorParam param, String stereotype) { + public HtmlColor getHtmlColor(ColorParam param, String stereotype, boolean clickable) { if (stereotype != null) { checkStereotype(stereotype); final String value2 = getValue(param.name() + "color" + stereotype); - if (value2 != null && HtmlColor.isValid(value2)) { - return HtmlColor.getColorIfValid(value2); + if (value2 != null && HtmlColorUtils.getColorIfValid(value2) != null) { + return HtmlColorUtils.getColorIfValid(value2); } } - final String value = getValue(param.name() + "color"); - if (value == null || HtmlColor.isValid(value) == false) { + final String value = getValue(getParamName(param, clickable)); + final boolean acceptTransparent = param == ColorParam.background; + if (value == null) { return null; } - return HtmlColor.getColorIfValid(value); + return HtmlColorUtils.getColorIfValid(value, acceptTransparent); + } + + private String getParamName(ColorParam param, boolean clickable) { + String n = param.name(); + if (clickable && n.endsWith("Background")) { + n = n.replaceAll("Background", "ClickableBackground"); + } else if (clickable && n.endsWith("Border")) { + n = n.replaceAll("Border", "ClickableBorder"); + } + return n + "color"; } private void checkStereotype(String stereotype) { @@ -176,16 +202,16 @@ public class SkinParam implements ISkinParam { checkStereotype(stereotype); value = getValue(param.name() + "fontcolor" + stereotype); } - if (value == null || HtmlColor.isValid(value) == false) { + if (value == null || HtmlColorUtils.getColorIfValid(value) == null) { value = getValue(param.name() + "fontcolor"); } - if (value == null || HtmlColor.isValid(value) == false) { + if (value == null || HtmlColorUtils.getColorIfValid(value) == null) { value = getValue("defaultfontcolor"); } - if (value == null || HtmlColor.isValid(value) == false) { + if (value == null || HtmlColorUtils.getColorIfValid(value) == null) { value = param.getDefaultColor(); } - return HtmlColor.getColorIfValid(value); + return HtmlColorUtils.getColorIfValid(value); } private int getFontStyle(FontParam param, String stereotype) { @@ -217,8 +243,9 @@ public class SkinParam implements ISkinParam { if (stereotype != null) { checkStereotype(stereotype); } - return new UFont(getFontFamily(fontParam, stereotype), getFontStyle(fontParam, stereotype), getFontSize( - fontParam, stereotype)); + final String fontFamily = getFontFamily(fontParam, stereotype); + final int fontStyle = getFontStyle(fontParam, stereotype); + return new UFont(fontFamily, fontStyle, getFontSize(fontParam, stereotype)); } public int getCircledCharacterRadius() { @@ -227,15 +254,11 @@ public class SkinParam implements ISkinParam { return Integer.parseInt(value); } // return 11; - // System.err.println("SIZE1="+getFontSize(FontParam.CIRCLED_CHARACTER)); - // System.err.println("SIZE1="+getFontSize(FontParam.CIRCLED_CHARACTER)/3); + // Log.println("SIZE1="+getFontSize(FontParam.CIRCLED_CHARACTER)); + // Log.println("SIZE1="+getFontSize(FontParam.CIRCLED_CHARACTER)/3); return getFontSize(FontParam.CIRCLED_CHARACTER, null) / 3 + 6; } - public boolean isClassCollapse() { - return true; - } - public int classAttributeIconSize() { final String value = getValue("classAttributeIconSize"); if (value != null && value.matches("\\d+")) { @@ -284,17 +307,6 @@ public class SkinParam implements ISkinParam { return 96; } - public boolean useOctagonForActivity() { - final String value = getValue("activityshape"); - if ("roundedbox".equalsIgnoreCase(value)) { - return false; - } - if ("octagon".equalsIgnoreCase(value)) { - return true; - } - return false; - } - public DotSplines getDotSplines() { final String value = getValue("linetype"); if ("polyline".equalsIgnoreCase(value)) { @@ -323,15 +335,36 @@ public class SkinParam implements ISkinParam { return GraphvizLayoutStrategy.DOT; } - public HorizontalAlignement getHorizontalAlignement(AlignParam param) { - final String value = getValue(param.name()); - final HorizontalAlignement result = HorizontalAlignement.fromString(value); + public HorizontalAlignment getHorizontalAlignment(AlignParam param) { + final String value; + switch (param) { + case SEQUENCE_MESSAGE_ALIGN: + value = getArg(getValue(AlignParam.SEQUENCE_MESSAGE_ALIGN.name()), 0); + break; + case SEQUENCE_MESSAGETEXT_ALIGN: + value = getArg(getValue(AlignParam.SEQUENCE_MESSAGE_ALIGN.name()), 1); + break; + default: + value = getValue(param.name()); + } + final HorizontalAlignment result = HorizontalAlignment.fromString(value); if (result == null) { return param.getDefaultValue(); } return result; } + private String getArg(String value, int i) { + if (value == null) { + return null; + } + final String[] split = value.split(":"); + if (i >= split.length) { + return split[0]; + } + return split[i]; + } + public ColorMapper getColorMapper() { if (isMonochrome()) { return new ColorMapperMonochrome(); @@ -339,19 +372,10 @@ public class SkinParam implements ISkinParam { return new ColorMapperIdentity(); } - public boolean isSvek() { - boolean defaultValue = false; - if (OptionFlags.SVEK && type == UmlDiagramType.CLASS) { - defaultValue = true; - } - final String value = getValue("svek"); - if (value == null) { - return defaultValue; - } - return "true".equalsIgnoreCase(value); - } - public boolean shadowing() { + if (strictUmlStyle()) { + return false; + } final String value = getValue("shadowing"); if ("false".equalsIgnoreCase(value)) { return false; @@ -359,4 +383,129 @@ public class SkinParam implements ISkinParam { return true; } + public PackageStyle getPackageStyle() { + final String value = getValue("packageStyle"); + final PackageStyle p = PackageStyle.fromString(value); + if (p == null) { + return PackageStyle.FOLDER; + } + return p; + } + + private final Map sprites = new HashMap(); + + public void addSprite(String name, Sprite sprite) { + sprites.put(name, sprite); + } + + public Sprite getSprite(String name) { + return sprites.get(name); + } + + public boolean useUml2ForComponent() { + if (strictUmlStyle()) { + return true; + } + final String value = getValue("componentstyle"); + return "uml2".equalsIgnoreCase(value); + } + + public boolean stereotypePositionTop() { + final String value = getValue("stereotypePosition"); + if ("bottom".equalsIgnoreCase(value)) { + return false; + } + return true; + } + + public boolean useSwimlanes() { + if (type != UmlDiagramType.ACTIVITY) { + return false; + } + if ("true".equalsIgnoreCase(getValue("swimlane"))) { + return true; + } + if ("true".equalsIgnoreCase(getValue("swimlanes"))) { + return true; + } + return false; + } + + public double getNodesep() { + final String value = getValue("nodesep"); + if (value != null && value.matches("\\d+")) { + return Double.parseDouble(value); + } + return 0; + } + + public double getRanksep() { + final String value = getValue("ranksep"); + if (value != null && value.matches("\\d+")) { + return Double.parseDouble(value); + } + return 0; + } + + public double getRoundCorner() { + final String value = getValue("roundcorner"); + if (value != null && value.matches("\\d+")) { + return Double.parseDouble(value); + } + return 0; + } + + public UStroke getThickness(LineParam param) { + final String value = getValue(param.name() + "thickness"); + if (value != null && value.matches("[\\d.]+")) { + return new UStroke(Double.parseDouble(value)); + } + return null; + } + + public double maxMessageSize() { + final String value = getValue("maxmessagesize"); + if (value != null && value.matches("-?\\d+")) { + return Double.parseDouble(value); + } + return 0; + } + + public boolean strictUmlStyle() { + final String value = getValue("style"); + if ("strictuml".equalsIgnoreCase(value)) { + return true; + } + return false; + } + + public boolean forceSequenceParticipantUnderlined() { + final String value = getValue("sequenceParticipant"); + if ("underline".equalsIgnoreCase(value)) { + return true; + } + return false; + } + + public ConditionStyle getConditionStyle() { + final String value = getValue("conditionStyle"); + final ConditionStyle p = ConditionStyle.fromString(value); + if (p == null) { + return ConditionStyle.INSIDE; + } + return p; + } + + public double minClassWidth() { + final String value = getValue("minclasswidth"); + if (value != null && value.matches("\\d+")) { + return Integer.parseInt(value); + } + return 0; + } + + public boolean sameClassWidth() { + return "true".equals(getValue("sameclasswidth")); + } + } diff --git a/src/net/sourceforge/plantuml/SkinParamBackcolored.java b/src/net/sourceforge/plantuml/SkinParamBackcolored.java index 4503676e7..93f10eae2 100644 --- a/src/net/sourceforge/plantuml/SkinParamBackcolored.java +++ b/src/net/sourceforge/plantuml/SkinParamBackcolored.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,26 +33,30 @@ */ package net.sourceforge.plantuml; -import net.sourceforge.plantuml.cucadiagram.dot.DotSplines; -import net.sourceforge.plantuml.cucadiagram.dot.GraphvizLayoutStrategy; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; import net.sourceforge.plantuml.graphic.HtmlColor; -import net.sourceforge.plantuml.ugraphic.ColorMapper; -import net.sourceforge.plantuml.ugraphic.UFont; -public class SkinParamBackcolored implements ISkinParam { +public class SkinParamBackcolored extends SkinParamDelegator { - final private ISkinParam skinParam; final private HtmlColor backColorElement; final private HtmlColor backColorGeneral; + final private boolean forceClickage; public SkinParamBackcolored(ISkinParam skinParam, HtmlColor backColorElement) { - this(skinParam, backColorElement, null); + this(skinParam, backColorElement, null, false); } - public SkinParamBackcolored(ISkinParam skinParam, - HtmlColor backColorElement, HtmlColor backColorGeneral) { - this.skinParam = skinParam; + public SkinParamBackcolored(ISkinParam skinParam, HtmlColor backColorElement, boolean forceClickage) { + this(skinParam, backColorElement, null, forceClickage); + } + + public SkinParamBackcolored(ISkinParam skinParam, HtmlColor backColorElement, HtmlColor backColorGeneral) { + this(skinParam, backColorElement, backColorGeneral, false); + } + + public SkinParamBackcolored(ISkinParam skinParam, HtmlColor backColorElement, HtmlColor backColorGeneral, + boolean forceClickage) { + super(skinParam); + this.forceClickage = forceClickage; this.backColorElement = backColorElement; this.backColorGeneral = backColorGeneral; } @@ -61,70 +65,17 @@ public class SkinParamBackcolored implements ISkinParam { if (backColorGeneral != null) { return backColorGeneral; } - return skinParam.getBackgroundColor(); + return super.getBackgroundColor(); } - public int getCircledCharacterRadius() { - return skinParam.getCircledCharacterRadius(); - } - - public UFont getFont(FontParam fontParam, String stereotype) { - return skinParam.getFont(fontParam, stereotype); - } - - public HtmlColor getFontHtmlColor(FontParam param, String stereotype) { - return skinParam.getFontHtmlColor(param, stereotype); - } - - public HtmlColor getHtmlColor(ColorParam param, String stereotype) { + public HtmlColor getHtmlColor(ColorParam param, String stereotype, boolean clickable) { if (param.isBackground() && backColorElement != null) { return backColorElement; } - return skinParam.getHtmlColor(param, stereotype); - } - - public String getValue(String key) { - return skinParam.getValue(key); - } - - public boolean isClassCollapse() { - return skinParam.isClassCollapse(); - } - - public int classAttributeIconSize() { - return skinParam.classAttributeIconSize(); - } - - public int getDpi() { - return skinParam.getDpi(); - } - - public boolean useOctagonForActivity() { - return skinParam.useOctagonForActivity(); - } - - public DotSplines getDotSplines() { - return skinParam.getDotSplines(); - } - - public GraphvizLayoutStrategy getStrategy() { - return skinParam.getStrategy(); - } - - public HorizontalAlignement getHorizontalAlignement(AlignParam param) { - return skinParam.getHorizontalAlignement(param); - } - - public ColorMapper getColorMapper() { - return skinParam.getColorMapper(); - } - - public boolean isSvek() { - return skinParam.isSvek(); - } - - public boolean shadowing() { - return skinParam.shadowing(); + if (forceClickage) { + clickable = true; + } + return super.getHtmlColor(param, stereotype, clickable); } } diff --git a/src/net/sourceforge/plantuml/SkinParamBackcoloredReference.java b/src/net/sourceforge/plantuml/SkinParamBackcoloredReference.java index 54c510bf3..9559a5dcd 100644 --- a/src/net/sourceforge/plantuml/SkinParamBackcoloredReference.java +++ b/src/net/sourceforge/plantuml/SkinParamBackcoloredReference.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,94 +33,28 @@ */ package net.sourceforge.plantuml; -import net.sourceforge.plantuml.cucadiagram.dot.DotSplines; -import net.sourceforge.plantuml.cucadiagram.dot.GraphvizLayoutStrategy; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; import net.sourceforge.plantuml.graphic.HtmlColor; -import net.sourceforge.plantuml.ugraphic.ColorMapper; -import net.sourceforge.plantuml.ugraphic.UFont; -public class SkinParamBackcoloredReference implements ISkinParam { +public class SkinParamBackcoloredReference extends SkinParamDelegator { - final private ISkinParam skinParam; final private HtmlColor sequenceReferenceHeaderBackground; final private HtmlColor sequenceReferenceBackground; public SkinParamBackcoloredReference(ISkinParam skinParam, HtmlColor sequenceReferenceHeaderBackground, HtmlColor sequenceReferenceBackground) { - this.skinParam = skinParam; + super(skinParam); this.sequenceReferenceBackground = sequenceReferenceBackground; this.sequenceReferenceHeaderBackground = sequenceReferenceHeaderBackground; } - public HtmlColor getBackgroundColor() { - return skinParam.getBackgroundColor(); - } - - public int getCircledCharacterRadius() { - return skinParam.getCircledCharacterRadius(); - } - - public UFont getFont(FontParam fontParam, String stereotype) { - return skinParam.getFont(fontParam, stereotype); - } - - public HtmlColor getFontHtmlColor(FontParam param, String stereotype) { - return skinParam.getFontHtmlColor(param, stereotype); - } - - public HtmlColor getHtmlColor(ColorParam param, String stereotype) { + public HtmlColor getHtmlColor(ColorParam param, String stereotype, boolean clickable) { if (param == ColorParam.sequenceReferenceHeaderBackground && sequenceReferenceHeaderBackground != null) { return sequenceReferenceHeaderBackground; } if (param == ColorParam.sequenceReferenceBackground && sequenceReferenceBackground != null) { return sequenceReferenceBackground; } - return skinParam.getHtmlColor(param, stereotype); - } - - public String getValue(String key) { - return skinParam.getValue(key); - } - - public boolean isClassCollapse() { - return skinParam.isClassCollapse(); - } - - public int classAttributeIconSize() { - return skinParam.classAttributeIconSize(); - } - - public int getDpi() { - return skinParam.getDpi(); - } - - public boolean useOctagonForActivity() { - return skinParam.useOctagonForActivity(); - } - - public DotSplines getDotSplines() { - return skinParam.getDotSplines(); - } - - public GraphvizLayoutStrategy getStrategy() { - return skinParam.getStrategy(); - } - - public HorizontalAlignement getHorizontalAlignement(AlignParam param) { - return skinParam.getHorizontalAlignement(param); - } - - public ColorMapper getColorMapper() { - return skinParam.getColorMapper(); - } - - public boolean isSvek() { - return skinParam.isSvek(); - } - - public boolean shadowing() { - return skinParam.shadowing(); + return super.getHtmlColor(param, stereotype, clickable); } } diff --git a/src/net/sourceforge/plantuml/SkinParamDelegator.java b/src/net/sourceforge/plantuml/SkinParamDelegator.java new file mode 100644 index 000000000..189878e2d --- /dev/null +++ b/src/net/sourceforge/plantuml/SkinParamDelegator.java @@ -0,0 +1,167 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 4246 $ + * + */ +package net.sourceforge.plantuml; + +import net.sourceforge.plantuml.cucadiagram.dot.DotSplines; +import net.sourceforge.plantuml.cucadiagram.dot.GraphvizLayoutStrategy; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.svek.ConditionStyle; +import net.sourceforge.plantuml.svek.PackageStyle; +import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.ugraphic.Sprite; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public class SkinParamDelegator implements ISkinParam { + + final private ISkinParam skinParam; + + public SkinParamDelegator(ISkinParam skinParam) { + this.skinParam = skinParam; + } + + public HtmlColor getBackgroundColor() { + return skinParam.getBackgroundColor(); + } + + public int getCircledCharacterRadius() { + return skinParam.getCircledCharacterRadius(); + } + + public UFont getFont(FontParam fontParam, String stereotype) { + return skinParam.getFont(fontParam, stereotype); + } + + public HtmlColor getFontHtmlColor(FontParam param, String stereotype) { + return skinParam.getFontHtmlColor(param, stereotype); + } + + public HtmlColor getHtmlColor(ColorParam param, String stereotype, boolean clickable) { + return skinParam.getHtmlColor(param, stereotype, clickable); + } + + public String getValue(String key) { + return skinParam.getValue(key); + } + + public int classAttributeIconSize() { + return skinParam.classAttributeIconSize(); + } + + public int getDpi() { + return skinParam.getDpi(); + } + + public DotSplines getDotSplines() { + return skinParam.getDotSplines(); + } + + public GraphvizLayoutStrategy getStrategy() { + return skinParam.getStrategy(); + } + + public HorizontalAlignment getHorizontalAlignment(AlignParam param) { + return skinParam.getHorizontalAlignment(param); + } + + public ColorMapper getColorMapper() { + return skinParam.getColorMapper(); + } + + public boolean shadowing() { + return skinParam.shadowing(); + } + + public PackageStyle getPackageStyle() { + return skinParam.getPackageStyle(); + } + + public Sprite getSprite(String name) { + return skinParam.getSprite(name); + } + + public boolean useUml2ForComponent() { + return skinParam.useUml2ForComponent(); + } + + public boolean stereotypePositionTop() { + return skinParam.stereotypePositionTop(); + } + + public boolean useSwimlanes() { + return skinParam.useSwimlanes(); + } + + public double getNodesep() { + return skinParam.getNodesep(); + } + + public double getRanksep() { + return skinParam.getRanksep(); + } + + public double getRoundCorner() { + return skinParam.getRoundCorner(); + } + + public UStroke getThickness(LineParam param) { + return skinParam.getThickness(param); + } + + public double maxMessageSize() { + return skinParam.maxMessageSize(); + } + + public boolean strictUmlStyle() { + return skinParam.strictUmlStyle(); + } + + public boolean forceSequenceParticipantUnderlined() { + return skinParam.forceSequenceParticipantUnderlined(); + } + + public ConditionStyle getConditionStyle() { + return skinParam.getConditionStyle(); + } + + public double minClassWidth() { + return skinParam.minClassWidth(); + } + + public boolean sameClassWidth() { + return skinParam.sameClassWidth(); + } + +} diff --git a/src/net/sourceforge/plantuml/SkinParamForecolored.java b/src/net/sourceforge/plantuml/SkinParamForecolored.java new file mode 100644 index 000000000..11def217a --- /dev/null +++ b/src/net/sourceforge/plantuml/SkinParamForecolored.java @@ -0,0 +1,51 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 4246 $ + * + */ +package net.sourceforge.plantuml; + +import net.sourceforge.plantuml.graphic.HtmlColor; + +public class SkinParamForecolored extends SkinParamDelegator { + + final private HtmlColor forecolor; + + public SkinParamForecolored(ISkinParam skinParam, HtmlColor forecolor) { + super(skinParam); + this.forecolor = forecolor; + } + + public HtmlColor getHtmlColor(ColorParam param, String stereotype, boolean clickable) { + return forecolor; + } + +} diff --git a/src/net/sourceforge/plantuml/SkinParamSameClassWidth.java b/src/net/sourceforge/plantuml/SkinParamSameClassWidth.java new file mode 100644 index 000000000..5e189b4aa --- /dev/null +++ b/src/net/sourceforge/plantuml/SkinParamSameClassWidth.java @@ -0,0 +1,49 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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; + +public class SkinParamSameClassWidth extends SkinParamDelegator { + + final private double width; + + public SkinParamSameClassWidth(ISkinParam skinParam, double width) { + super(skinParam); + this.width = width; + } + + public double minClassWidth() { + return width; + } + +} diff --git a/src/net/sourceforge/plantuml/SkinParamUtils.java b/src/net/sourceforge/plantuml/SkinParamUtils.java new file mode 100644 index 000000000..2ecd1dce9 --- /dev/null +++ b/src/net/sourceforge/plantuml/SkinParamUtils.java @@ -0,0 +1,60 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 9423 $ + * + */ +package net.sourceforge.plantuml; + +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.ugraphic.UFont; + +public class SkinParamUtils { + + private static final Rose rose = new Rose(); + + public static UFont getFont(ISkinParam skinParam, FontParam fontParam, Stereotype stereo) { + final String s = stereo == null ? null : stereo.getLabel(); + return skinParam.getFont(fontParam, s); + } + + public static HtmlColor getFontColor(ISkinParam skinParam, FontParam fontParam, Stereotype stereo) { + final String s = stereo == null ? null : stereo.getLabel(); + return skinParam.getFontHtmlColor(fontParam, s); + } + + public static HtmlColor getColor(ISkinParam skinParam, ColorParam colorParam, Stereotype stereo) { + final String s = stereo == null ? null : stereo.getLabel(); + return rose.getHtmlColor(skinParam, colorParam, s); + } + +} diff --git a/src/net/sourceforge/plantuml/SourceFileReader.java b/src/net/sourceforge/plantuml/SourceFileReader.java index 9ee570a85..946abab82 100644 --- a/src/net/sourceforge/plantuml/SourceFileReader.java +++ b/src/net/sourceforge/plantuml/SourceFileReader.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -36,8 +36,10 @@ package net.sourceforge.plantuml; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; +import java.io.PrintStream; import java.io.Reader; import java.io.UnsupportedEncodingException; import java.util.ArrayList; @@ -47,6 +49,7 @@ import java.util.Set; import net.sourceforge.plantuml.code.Transcoder; import net.sourceforge.plantuml.code.TranscoderUtil; +import net.sourceforge.plantuml.core.Diagram; import net.sourceforge.plantuml.preproc.Defines; public class SourceFileReader implements ISourceFileReader { @@ -61,6 +64,11 @@ public class SourceFileReader implements ISourceFileReader { this(file, file.getAbsoluteFile().getParentFile()); } + public SourceFileReader(File file, File outputDirectory, String charset) throws IOException { + this(new Defines(), file, outputDirectory, Collections. emptyList(), charset, new FileFormatOption( + FileFormat.PNG)); + } + public SourceFileReader(final File file, File outputDirectory) throws IOException { this(new Defines(), file, outputDirectory, Collections. emptyList(), null, new FileFormatOption( FileFormat.PNG)); @@ -82,26 +90,27 @@ public class SourceFileReader implements ISourceFileReader { if (outputDirectory == null) { outputDirectory = file.getAbsoluteFile().getParentFile(); } else if (outputDirectory.isAbsolute() == false) { - outputDirectory = FileSystem.getInstance().getFile(outputDirectory.getName()); + outputDirectory = FileSystem.getInstance().getFile(outputDirectory.getPath()); } if (outputDirectory.exists() == false) { outputDirectory.mkdirs(); } this.outputDirectory = outputDirectory; - builder = new BlockUmlBuilder(config, defines, getReader(charset), file.getAbsoluteFile().getParentFile()); + builder = new BlockUmlBuilder(config, charset, defines, getReader(charset), file.getAbsoluteFile() + .getParentFile()); } public boolean hasError() throws IOException, InterruptedException { for (final BlockUml b : builder.getBlockUmls()) { - if (b.getSystem() instanceof PSystemError) { + if (b.getDiagram() instanceof PSystemError) { return true; } } return false; } - public List getGeneratedImages() throws IOException, InterruptedException { + public List getGeneratedImages() throws IOException { Log.info("Reading file: " + file); int cpt = 0; @@ -117,11 +126,22 @@ public class SourceFileReader implements ISourceFileReader { final File suggested = new File(outputDirectory, newName); suggested.getParentFile().mkdirs(); - final PSystem system = blockUml.getSystem(); + final Diagram system = blockUml.getDiagram(); + final List exportDiagrams = PSystemUtils.exportDiagrams(system, suggested, fileFormatOption); OptionFlags.getInstance().logData(file, system); - for (File f : system.exportDiagrams(suggested, fileFormatOption)) { + for (File f : exportDiagrams) { final String desc = "[" + file.getName() + "] " + system.getDescription(); + if (OptionFlags.getInstance().isWord()) { + final String warnOrError = system.getWarningOrError(); + if (warnOrError != null) { + final String name = f.getName().substring(0, f.getName().length() - 4) + ".err"; + final File errorFile = new File(f.getParentFile(), name); + final PrintStream ps = new PrintStream(new FileOutputStream(errorFile)); + ps.print(warnOrError); + ps.close(); + } + } final GeneratedImage generatedImage = new GeneratedImage(f, desc, system); result.add(generatedImage); } @@ -137,7 +157,7 @@ public class SourceFileReader implements ISourceFileReader { final List result = new ArrayList(); final Transcoder transcoder = TranscoderUtil.getDefaultTranscoder(); for (BlockUml blockUml : builder.getBlockUmls()) { - final String source = blockUml.getSystem().getSource().getPlainString(); + final String source = blockUml.getDiagram().getSource().getPlainString(); final String encoded = transcoder.encode(source); result.add(encoded); } diff --git a/src/net/sourceforge/plantuml/SourceFileReader2.java b/src/net/sourceforge/plantuml/SourceFileReader2.java index 32a9a0705..2c0c6ed52 100644 --- a/src/net/sourceforge/plantuml/SourceFileReader2.java +++ b/src/net/sourceforge/plantuml/SourceFileReader2.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -47,6 +47,7 @@ import java.util.Set; import net.sourceforge.plantuml.code.Transcoder; import net.sourceforge.plantuml.code.TranscoderUtil; +import net.sourceforge.plantuml.core.Diagram; import net.sourceforge.plantuml.preproc.Defines; public class SourceFileReader2 implements ISourceFileReader { @@ -67,12 +68,12 @@ public class SourceFileReader2 implements ISourceFileReader { } FileSystem.getInstance().setCurrentDir(file.getAbsoluteFile().getParentFile()); - builder = new BlockUmlBuilder(config, defines, getReader(charset), file.getAbsoluteFile().getParentFile()); + builder = new BlockUmlBuilder(config, charset, defines, getReader(charset), file.getAbsoluteFile().getParentFile()); } public boolean hasError() throws IOException, InterruptedException { for (final BlockUml b : builder.getBlockUmls()) { - if (b.getSystem() instanceof PSystemError) { + if (b.getDiagram() instanceof PSystemError) { return true; } } @@ -87,10 +88,10 @@ public class SourceFileReader2 implements ISourceFileReader { for (BlockUml blockUml : builder.getBlockUmls()) { final File suggested = outputFile; - final PSystem system = blockUml.getSystem(); + final Diagram system = blockUml.getDiagram(); OptionFlags.getInstance().logData(file, system); - for (File f : system.exportDiagrams(suggested, fileFormatOption)) { + for (File f : PSystemUtils.exportDiagrams(system, suggested, fileFormatOption)) { final String desc = "[" + file.getName() + "] " + system.getDescription(); final GeneratedImage generatedImage = new GeneratedImage(f, desc, system); result.add(generatedImage); @@ -107,7 +108,7 @@ public class SourceFileReader2 implements ISourceFileReader { final List result = new ArrayList(); final Transcoder transcoder = TranscoderUtil.getDefaultTranscoder(); for (BlockUml blockUml : builder.getBlockUmls()) { - final String source = blockUml.getSystem().getSource().getPlainString(); + final String source = blockUml.getDiagram().getSource().getPlainString(); final String encoded = transcoder.encode(source); result.add(encoded); } diff --git a/src/net/sourceforge/plantuml/SourceStringReader.java b/src/net/sourceforge/plantuml/SourceStringReader.java index 92517e5df..e64622a92 100644 --- a/src/net/sourceforge/plantuml/SourceStringReader.java +++ b/src/net/sourceforge/plantuml/SourceStringReader.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -43,6 +43,10 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import net.sourceforge.plantuml.core.Diagram; +import net.sourceforge.plantuml.core.DiagramDescription; +import net.sourceforge.plantuml.core.DiagramDescriptionImpl; +import net.sourceforge.plantuml.core.ImageData; import net.sourceforge.plantuml.graphic.GraphicStrings; import net.sourceforge.plantuml.preproc.Defines; @@ -54,15 +58,25 @@ public class SourceStringReader { this(new Defines(), source, Collections. emptyList()); } - public SourceStringReader(Defines defines, String source, List config) { - try { - final BlockUmlBuilder builder = new BlockUmlBuilder(config, defines, new StringReader(source), null); - this.blocks = builder.getBlockUmls(); - } catch (IOException e) { - throw new IllegalStateException(); - } + public SourceStringReader(String source, String charset) { + this(new Defines(), source, "UTF-8", Collections. emptyList()); } + public SourceStringReader(Defines defines, String source, List config) { + this(defines, source, "UTF-8", config); + } + + public SourceStringReader(Defines defines, String source, String charset, List config) { + try { + final BlockUmlBuilder builder = new BlockUmlBuilder(config, charset, defines, new StringReader(source), + null); + this.blocks = builder.getBlockUmls(); + } catch (IOException e) { + Log.error("error " + e); + throw new IllegalStateException(e); + } + } + public String generateImage(OutputStream os) throws IOException { return generateImage(os, 0); } @@ -85,22 +99,68 @@ public class SourceStringReader { public String generateImage(OutputStream os, int numImage, FileFormatOption fileFormatOption) throws IOException { if (blocks.size() == 0) { final GraphicStrings error = new GraphicStrings(Arrays.asList("No @startuml found")); - error.writeImage(os, fileFormatOption); + error.writeImage(os, fileFormatOption, null); return null; } - try { - for (BlockUml b : blocks) { - final PSystem system = b.getSystem(); - final int nbInSystem = system.getNbImages(); - if (numImage < nbInSystem) { - system.exportDiagram(os, null, numImage, fileFormatOption); - return system.getDescription(); + for (BlockUml b : blocks) { + final Diagram system = b.getDiagram(); + final int nbInSystem = system.getNbImages(); + if (numImage < nbInSystem) { + //final CMapData cmap = new CMapData(); + final ImageData imageData = system.exportDiagram(os, numImage, fileFormatOption); + if (imageData.containsCMapData()) { + return system.getDescription().getDescription() + "\n" + imageData.getCMapData("plantuml"); } - numImage -= nbInSystem; + return system.getDescription().getDescription(); } - } catch (InterruptedException e) { + numImage -= nbInSystem; + } + Log.error("numImage is too big = " + numImage); + return null; + + } + + + public DiagramDescription generateDiagramDescription(OutputStream os) throws IOException { + return generateDiagramDescription(os, 0); + } + + public DiagramDescription generateDiagramDescription(File f) throws IOException { + final OutputStream os = new BufferedOutputStream(new FileOutputStream(f)); + final DiagramDescription result = generateDiagramDescription(os, 0); + os.close(); + return result; + } + + public DiagramDescription generateDiagramDescription(OutputStream os, FileFormatOption fileFormatOption) throws IOException { + return generateDiagramDescription(os, 0, fileFormatOption); + } + + public DiagramDescription generateDiagramDescription(OutputStream os, int numImage) throws IOException { + return generateDiagramDescription(os, numImage, new FileFormatOption(FileFormat.PNG)); + } + + public DiagramDescription generateDiagramDescription(OutputStream os, int numImage, FileFormatOption fileFormatOption) + throws IOException { + if (blocks.size() == 0) { + final GraphicStrings error = new GraphicStrings(Arrays.asList("No @startuml found")); + error.writeImage(os, fileFormatOption, null); return null; } + for (BlockUml b : blocks) { + final Diagram system = b.getDiagram(); + final int nbInSystem = system.getNbImages(); + if (numImage < nbInSystem) { + // final CMapData cmap = new CMapData(); + final ImageData imageData = system.exportDiagram(os, numImage, fileFormatOption); + if (imageData.containsCMapData()) { + return ((DiagramDescriptionImpl) system.getDescription()).withCMapData(imageData + .getCMapData("plantuml")); + } + return system.getDescription(); + } + numImage -= nbInSystem; + } Log.error("numImage is too big = " + numImage); return null; diff --git a/src/net/sourceforge/plantuml/SpecificBackcolorable.java b/src/net/sourceforge/plantuml/SpecificBackcolorable.java index 18f96a647..2e5df02d9 100644 --- a/src/net/sourceforge/plantuml/SpecificBackcolorable.java +++ b/src/net/sourceforge/plantuml/SpecificBackcolorable.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/SpriteContainer.java b/src/net/sourceforge/plantuml/SpriteContainer.java new file mode 100644 index 000000000..d9d841034 --- /dev/null +++ b/src/net/sourceforge/plantuml/SpriteContainer.java @@ -0,0 +1,42 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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 net.sourceforge.plantuml.ugraphic.Sprite; + +public interface SpriteContainer { + + public Sprite getSprite(String name); + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/SpriteContainerEmpty.java b/src/net/sourceforge/plantuml/SpriteContainerEmpty.java new file mode 100644 index 000000000..12259c80e --- /dev/null +++ b/src/net/sourceforge/plantuml/SpriteContainerEmpty.java @@ -0,0 +1,44 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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 net.sourceforge.plantuml.ugraphic.Sprite; + +public class SpriteContainerEmpty implements SpriteContainer { + + public Sprite getSprite(String name) { + return null; + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/StartUtils.java b/src/net/sourceforge/plantuml/StartUtils.java index a856096e7..2799327af 100644 --- a/src/net/sourceforge/plantuml/StartUtils.java +++ b/src/net/sourceforge/plantuml/StartUtils.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/StringUtils.java b/src/net/sourceforge/plantuml/StringUtils.java index a305643f6..ba2945947 100644 --- a/src/net/sourceforge/plantuml/StringUtils.java +++ b/src/net/sourceforge/plantuml/StringUtils.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 7064 $ + * Revision $Revision: 11949 $ * */ package net.sourceforge.plantuml; @@ -44,8 +44,13 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorTransparent; import net.sourceforge.plantuml.preproc.ReadLineReader; import net.sourceforge.plantuml.preproc.UncommentReadLine; +import net.sourceforge.plantuml.ugraphic.ColorMapper; public class StringUtils { @@ -53,15 +58,19 @@ public class StringUtils { return file.getAbsolutePath(); } - public static List getWithNewlines(String s) { + public static List getWithNewlines2(Code s) { + return getWithNewlines2(s.getCode()); + } + + public static List getWithNewlines2(String s) { if (s == null) { - throw new IllegalArgumentException(); + return null; } final List result = new ArrayList(); final StringBuilder current = new StringBuilder(); for (int i = 0; i < s.length(); i++) { final char c = s.charAt(i); - if (c == '\\' && i < s.length() + 1) { + if (c == '\\' && i < s.length() - 1) { final char c2 = s.charAt(i + 1); i++; if (c2 == 'n') { @@ -122,11 +131,52 @@ public class StringUtils { return s; } + public static String unicode(String s) { + final StringBuilder result = new StringBuilder(); + for (char c : s.toCharArray()) { + if (c > 127 || c == '&' || c == '|') { + final int i = c; + result.append("&#" + i + ";"); + } else { + result.append(c); + } + } + return result.toString(); + } + + public static String unicodeForHtml(String s) { + final StringBuilder result = new StringBuilder(); + for (char c : s.toCharArray()) { + if (c > 127 || c == '&' || c == '|' || c == '<' || c == '>') { + final int i = c; + result.append("&#" + i + ";"); + } else { + result.append(c); + } + } + return result.toString(); + } + + public static String unicodeForHtml(Display display) { + final StringBuilder result = new StringBuilder(); + for (int i = 0; i < display.size(); i++) { + result.append(unicodeForHtml(display.get(i).toString())); + if (i < display.size() - 1) { + result.append("
"); + } + } + return result.toString(); + } + public static String manageArrowForSequence(String s) { - s = s.replace('=', '-'); + s = s.replace('=', '-').toLowerCase(); return s; } + public static String capitalize(String s) { + return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase(); + } + public static String manageArrowForCuca(String s) { final Direction dir = getArrowDirection(s); s = s.replace('=', '-'); @@ -201,6 +251,10 @@ public class StringUtils { return Direction.DOWN; } + // public static Code eventuallyRemoveStartingAndEndingDoubleQuote(Code s) { + // return Code.of(eventuallyRemoveStartingAndEndingDoubleQuote(s.getCode())); + // } + public static String eventuallyRemoveStartingAndEndingDoubleQuote(String s) { if (s.startsWith("\"") && s.endsWith("\"")) { return s.substring(1, s.length() - 1); @@ -219,7 +273,7 @@ public class StringUtils { public static boolean isCJK(char c) { final Character.UnicodeBlock block = Character.UnicodeBlock.of(c); - System.err.println(block); + Log.println("block=" + block); return false; } @@ -230,7 +284,7 @@ public class StringUtils { public static char hiddenBiggerThan() { return '\u0006'; } - + public static String hideComparatorCharacters(String s) { s = s.replace('<', hiddenLesserThan()); s = s.replace('>', hiddenBiggerThan()); @@ -253,10 +307,33 @@ public class StringUtils { return result; } + public static int getWidth(Display stringsToDisplay) { + int result = 1; + for (CharSequence s : stringsToDisplay) { + if (result < s.length()) { + result = s.length(); + } + } + return result; + } + public static int getHeight(List stringsToDisplay) { return stringsToDisplay.size(); } + public static int getHeight(Display stringsToDisplay) { + return stringsToDisplay.size(); + } + + private static void removeFirstColumn(List data) { + for (int i = 0; i < data.size(); i++) { + final String s = data.get(i); + if (s.length() > 0) { + data.set(i, s.substring(1)); + } + } + } + private static boolean firstColumnRemovable(List data) { boolean allEmpty = true; for (String s : data) { @@ -272,15 +349,6 @@ public class StringUtils { return allEmpty == false; } - private static void removeFirstColumn(List data) { - for (int i = 0; i < data.size(); i++) { - final String s = data.get(i); - if (s.length() > 0) { - data.set(i, s.substring(1)); - } - } - } - public static List removeEmptyColumns(List data) { if (firstColumnRemovable(data) == false) { return data; @@ -289,7 +357,7 @@ public class StringUtils { do { removeFirstColumn(result); } while (firstColumnRemovable(result)); - return Collections.unmodifiableList(result); + return result; } public static void trim(List data, boolean removeEmptyLines) { @@ -330,6 +398,9 @@ public class StringUtils { if (uml.startsWith("@startuml\nversion\n")) { return false; } + if (uml.startsWith("@startuml\ncheckversion")) { + return false; + } if (uml.startsWith("@startuml\ntestdot\n")) { return false; } @@ -352,27 +423,59 @@ public class StringUtils { } return Collections.unmodifiableList(result); } - + public static String getAsHtml(Color color) { if (color == null) { throw new IllegalArgumentException(); } return getAsHtml(color.getRGB()); } - + + public static String getAsSvg(ColorMapper mapper, HtmlColor color) { + if (color == null) { + return "none"; + } + if (color instanceof HtmlColorTransparent) { + return "#FFFFFF"; + } + return getAsHtml(mapper.getMappedColor(color)); + } + public static String getAsHtml(int color) { final int v = 0xFFFFFF & color; String s = "000000" + Integer.toHexString(v).toUpperCase(); s = s.substring(s.length() - 6); return "#" + s; } - + public static String getUid(String uid1, int uid2) { return uid1 + String.format("%04d", uid2); } - - - public static List manageEmbededDiagrams(final List strings) { + + public static Display manageEmbededDiagrams(final Display strings) { + Display result = new Display(); + final Iterator it = strings.iterator(); + while (it.hasNext()) { + CharSequence s = it.next(); + if (s.equals("{{")) { + Display other = new Display(); + other = other.add("@startuml"); + while (it.hasNext()) { + final CharSequence s2 = it.next(); + if (s2.equals("}}")) { + break; + } + other = other.add(s2); + } + other = other.add("@enduml"); + s = new EmbededDiagram(other); + } + result = result.add(s); + } + return result; + } + + public static List manageEmbededDiagrams2(final List strings) { final List result = new ArrayList(); final Iterator it = strings.iterator(); while (it.hasNext()) { @@ -381,20 +484,28 @@ public class StringUtils { final List other = new ArrayList(); other.add("@startuml"); while (it.hasNext()) { - String s2 = it.next(); + final String s2 = it.next(); if (s2.equals("}}")) { break; } other.add(s2); } other.add("@enduml"); - s = new EmbededDiagram(other); + s = new EmbededDiagram(new Display(other)); } result.add(s); } return result; } + public static boolean isMethod(String s) { + return s.contains("(") || s.contains(")"); + } + public static List merge(List l1, List l2) { + final List result = new ArrayList(l1); + result.addAll(l2); + return Collections.unmodifiableList(result); + } } diff --git a/src/net/sourceforge/plantuml/UmlDiagram.java b/src/net/sourceforge/plantuml/UmlDiagram.java index 7fcff94a1..47eb960ba 100644 --- a/src/net/sourceforge/plantuml/UmlDiagram.java +++ b/src/net/sourceforge/plantuml/UmlDiagram.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,13 +28,18 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 7173 $ + * Revision $Revision: 11873 $ * */ package net.sourceforge.plantuml; +import java.awt.Font; +import java.awt.geom.AffineTransform; +import java.awt.geom.Dimension2D; import java.awt.image.BufferedImage; import java.io.BufferedOutputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -42,46 +47,54 @@ import java.io.IOException; import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Hashtable; import java.util.List; -import net.sourceforge.plantuml.code.Compression; -import net.sourceforge.plantuml.code.CompressionZlib; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import javax.imageio.ImageIO; + +import net.sourceforge.plantuml.api.ImageDataSimple; +import net.sourceforge.plantuml.core.Diagram; +import net.sourceforge.plantuml.core.ImageData; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.UnparsableGraphvizException; +import net.sourceforge.plantuml.flashcode.FlashCodeFactory; +import net.sourceforge.plantuml.flashcode.FlashCodeUtils; +import net.sourceforge.plantuml.graphic.GraphicStrings; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.QuoteUtils; +import net.sourceforge.plantuml.mjpeg.MJPEGGenerator; import net.sourceforge.plantuml.pdf.PdfConverter; +import net.sourceforge.plantuml.svek.EmptySvgException; +import net.sourceforge.plantuml.ugraphic.Sprite; +import net.sourceforge.plantuml.ugraphic.UAntiAliasing; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.version.Version; -import com.google.zxing.BarcodeFormat; -import com.google.zxing.EncodeHintType; -import com.google.zxing.WriterException; -import com.google.zxing.client.j2se.MatrixToImageWriter; -import com.google.zxing.common.BitMatrix; -import com.google.zxing.qrcode.QRCodeWriter; -import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; - -public abstract class UmlDiagram extends AbstractPSystem implements PSystem { +public abstract class UmlDiagram extends AbstractPSystem implements Diagram { private boolean rotation; private boolean hideUnlinkedData; private int minwidth = Integer.MAX_VALUE; - private List title; - private List header; - private List footer; - private HorizontalAlignement headerAlignement = HorizontalAlignement.RIGHT; - private HorizontalAlignement footerAlignement = HorizontalAlignement.CENTER; + private Display title; + private Display header; + private Display footer; + private Display legend = null; + private HorizontalAlignment legendAlignment = HorizontalAlignment.CENTER; + + private HorizontalAlignment headerAlignment = HorizontalAlignment.RIGHT; + private HorizontalAlignment footerAlignment = HorizontalAlignment.CENTER; private final Pragma pragma = new Pragma(); private Scale scale; private final SkinParam skinParam = new SkinParam(getUmlDiagramType()); - final public void setTitle(List strings) { + final public void setTitle(Display strings) { this.title = strings; } - final public List getTitle() { + final public Display getTitle() { return title; } @@ -109,36 +122,36 @@ public abstract class UmlDiagram extends AbstractPSystem implements PSystem { skinParam.setParam(key.toLowerCase(), value); } - public final List getHeader() { + public final Display getHeader() { return header; } - public final void setHeader(List header) { + public final void setHeader(Display header) { this.header = header; } - public final List getFooter() { + public final Display getFooter() { return footer; } - public final void setFooter(List footer) { + public final void setFooter(Display footer) { this.footer = footer; } - public final HorizontalAlignement getHeaderAlignement() { - return headerAlignement; + public final HorizontalAlignment getHeaderAlignment() { + return headerAlignment; } - public final void setHeaderAlignement(HorizontalAlignement headerAlignement) { - this.headerAlignement = headerAlignement; + public final void setHeaderAlignment(HorizontalAlignment headerAlignment) { + this.headerAlignment = headerAlignment; } - public final HorizontalAlignement getFooterAlignement() { - return footerAlignement; + public final HorizontalAlignment getFooterAlignment() { + return footerAlignment; } - public final void setFooterAlignement(HorizontalAlignement footerAlignement) { - this.footerAlignement = footerAlignement; + public final void setFooterAlignment(HorizontalAlignment footerAlignment) { + this.footerAlignment = footerAlignment; } abstract public UmlDiagramType getUmlDiagramType(); @@ -174,55 +187,137 @@ public abstract class UmlDiagram extends AbstractPSystem implements PSystem { this.hideUnlinkedData = hideUnlinkedData; } - final public void exportDiagram(OutputStream os, StringBuilder cmap, int index, FileFormatOption fileFormatOption) + final public ImageData exportDiagram(OutputStream os, int index, FileFormatOption fileFormatOption) throws IOException { + List flashcodes = null; try { if ("split".equalsIgnoreCase(getSkinParam().getValue("flashcode")) && fileFormatOption.getFileFormat() == FileFormat.PNG) { final String s = getSource().getPlainString(); - flashcodes = exportSplitCompress(s); + flashcodes = getFlashCodeUtils().exportSplitCompress(s); } else if ("compress".equalsIgnoreCase(getSkinParam().getValue("flashcode")) && fileFormatOption.getFileFormat() == FileFormat.PNG) { final String s = getSource().getPlainString(); - flashcodes = exportFlashcodeCompress(s); + flashcodes = getFlashCodeUtils().exportFlashcodeCompress(s); } else if (getSkinParam().getValue("flashcode") != null && fileFormatOption.getFileFormat() == FileFormat.PNG) { final String s = getSource().getPlainString(); - flashcodes = exportFlashcodeSimple(s); + flashcodes = getFlashCodeUtils().exportFlashcodeSimple(s); } - } catch (WriterException e) { + } catch (IOException e) { Log.error("Cannot generate flashcode"); e.printStackTrace(); flashcodes = null; } if (fileFormatOption.getFileFormat() == FileFormat.PDF) { - exportDiagramInternalPdf(os, cmap, index, flashcodes); - return; + return exportDiagramInternalPdf(os, index, flashcodes); } - exportDiagramInternal(os, cmap, index, fileFormatOption, flashcodes); + if (fileFormatOption.getFileFormat() == FileFormat.MJPEG) { + // exportDiagramInternalMjpeg(os); + // return;* + throw new UnsupportedOperationException(); + } + try { + final ImageData imageData = exportDiagramInternal(os, index, fileFormatOption, flashcodes); + this.lastInfo = new Dimension2DDouble(imageData.getWidth(), imageData.getHeight()); + return imageData; + } catch (UnparsableGraphvizException e) { + e.printStackTrace(); + exportDiagramError(os, e.getCause(), fileFormatOption, e.getGraphvizVersion(), e.getDebugData()); + } catch (Exception e) { + e.printStackTrace(); + exportDiagramError(os, e, fileFormatOption, null, null); + } + return new ImageDataSimple(); + } - private void exportDiagramInternalPdf(OutputStream os, StringBuilder cmap, int index, List flashcodes) + private void exportDiagramError(OutputStream os, Throwable exception, FileFormatOption fileFormat, + String graphvizVersion, String svg) throws IOException { + final UFont font = new UFont("SansSerif", Font.PLAIN, 12); + final List strings = new ArrayList(); + strings.add("An error has occured : " + exception); + final String quote = QuoteUtils.getSomeQuote(); + strings.add("" + quote); + strings.add(" "); + strings.add("PlantUML (" + Version.versionString() + ") cannot parse result from dot/GraphViz."); + if (exception instanceof EmptySvgException) { + strings.add("Because dot/GraphViz returns an empty string."); + } + if (graphvizVersion != null) { + strings.add(" "); + strings.add("GraphViz version used : " + graphvizVersion); + } + strings.add(" "); + strings.add("This may be caused by :"); + strings.add(" - a bug in PlantUML"); + strings.add(" - a problem in GraphViz"); + strings.add(" "); + strings.add("You should send this diagram and this image to plantuml@gmail.com to solve this issue."); + strings.add("You can try to turn arround this issue by simplifing your diagram."); + strings.add(" "); + strings.add(exception.toString()); + for (StackTraceElement ste : exception.getStackTrace()) { + strings.add(" " + ste.toString()); + + } + final GraphicStrings graphicStrings = new GraphicStrings(strings, font, HtmlColorUtils.BLACK, + HtmlColorUtils.WHITE, UAntiAliasing.ANTI_ALIASING_ON); + graphicStrings.writeImage(os, fileFormat, svg); + } + + private FlashCodeUtils getFlashCodeUtils() { + return FlashCodeFactory.getFlashCodeUtils(); + } + + private void exportDiagramInternalMjpeg(OutputStream os) throws IOException { + final File f = new File("c:/test.avi"); + final int nb = 150; + final double framerate = 30; + final MJPEGGenerator m = new MJPEGGenerator(f, 640, 480, framerate, nb); + + for (int i = 0; i < nb; i++) { + final AffineTransform at = new AffineTransform(); + final double coef = (nb - 1 - i) * 1.0 / nb; + at.setToShear(coef, coef); + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + // exportDiagramTOxxBEREMOVED(baos, null, 0, new FileFormatOption(FileFormat.PNG, at)); + baos.close(); + final BufferedImage im = ImageIO.read(new ByteArrayInputStream(baos.toByteArray())); + m.addImage(im); + } + m.finishAVI(); + + } + + private Dimension2D lastInfo; + + private ImageData exportDiagramInternalPdf(OutputStream os, int index, List flashcodes) throws IOException { final File svg = FileUtils.createTempFile("pdf", ".svf"); final File pdfFile = FileUtils.createTempFile("pdf", ".pdf"); final OutputStream fos = new BufferedOutputStream(new FileOutputStream(svg)); - exportDiagram(fos, cmap, index, new FileFormatOption(FileFormat.SVG)); + final ImageData result = exportDiagram(fos, index, new FileFormatOption(FileFormat.SVG)); fos.close(); PdfConverter.convert(svg, pdfFile); FileUtils.copyToStream(pdfFile, os); + return result; } - protected abstract void exportDiagramInternal(OutputStream os, StringBuilder cmap, int index, - FileFormatOption fileFormatOption, List flashcodes) throws IOException; + protected abstract ImageData exportDiagramInternal(OutputStream os, int index, FileFormatOption fileFormatOption, + List flashcodes) throws IOException; - final protected void exportCmap(File suggestedFile, final StringBuilder cmap) throws FileNotFoundException { - final File cmapFile = new File(changeName(suggestedFile.getAbsolutePath())); + final protected void exportCmap(File suggestedFile, final ImageData cmapdata) throws FileNotFoundException { + final String name = changeName(suggestedFile.getAbsolutePath()); + final File cmapFile = new File(name); PrintWriter pw = null; try { + if (PSystemUtils.canFileBeWritten(cmapFile) == false) { + return; + } pw = new PrintWriter(cmapFile); - pw.print(cmap.toString()); + pw.print(cmapdata.getCMapData(cmapFile.getName().substring(0, cmapFile.getName().length() - 6))); pw.close(); } finally { if (pw != null) { @@ -235,83 +330,43 @@ public abstract class UmlDiagram extends AbstractPSystem implements PSystem { return name.replaceAll("(?i)\\.\\w{3}$", ".cmapx"); } - private List exportFlashcodeSimple(String s) throws IOException, WriterException { - final QRCodeWriter writer = new QRCodeWriter(); - final int multiple = 1; - final Hashtable hints = new Hashtable(); - hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); - final BitMatrix bit = writer.encode(s, BarcodeFormat.QR_CODE, multiple); - final BufferedImage im = MatrixToImageWriter.toBufferedImage(bit); - return Arrays.asList(im); - } - - private List exportFlashcodeCompress(String s) throws IOException, WriterException { - final QRCodeWriter writer = new QRCodeWriter(); - final int multiple = 1; - final Hashtable hints = new Hashtable(); - hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); - - final Compression comp = new CompressionZlib(); - final byte data[] = comp.compress(s.getBytes("UTF-8")); - - // Encoder.DEFAULT_BYTE_MODE_ENCODING - final BitMatrix bit = writer.encode(new String(data, "ISO-8859-1"), BarcodeFormat.QR_CODE, multiple); - final BufferedImage im = MatrixToImageWriter.toBufferedImage(bit); - return Arrays.asList(im); - } - - private List exportSplitCompress(String s) throws IOException, WriterException { - final QRCodeWriter writer = new QRCodeWriter(); - final int multiple = 1; - final Hashtable hints = new Hashtable(); - hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); - - final Compression comp = new CompressionZlib(); - final byte data[] = comp.compress(s.getBytes("UTF-8")); - - final List result = new ArrayList(); - - final List blocs = new ArrayList(); - for (int i = 0; i < 4; i++) { - blocs.add(getSplited(data, i, 4)); + @Override + public String getWarningOrError() { + if (lastInfo == null) { + return null; } - - blocs.add(xor(blocs)); - - for (byte d[] : blocs) { - // Encoder.DEFAULT_BYTE_MODE_ENCODING - final BitMatrix bit = writer.encode(new String(d, "ISO-8859-1"), BarcodeFormat.QR_CODE, multiple); - result.add(MatrixToImageWriter.toBufferedImage(bit)); + final double actualWidth = lastInfo.getWidth(); + if (actualWidth == 0) { + return null; } - - return Collections.unmodifiableList(result); + final String value = getSkinParam().getValue("widthwarning"); + if (value == null) { + return null; + } + if (value.matches("\\d+") == false) { + return null; + } + final int widthwarning = Integer.parseInt(value); + if (actualWidth > widthwarning) { + return "The image is " + ((int) actualWidth) + " pixel width. (Warning limit is " + widthwarning + ")"; + } + return null; } - static byte[] xor(List blocs) { - final byte result[] = new byte[blocs.get(0).length]; - for (int i = 0; i < result.length; i++) { - result[i] = xor(blocs, i); - } - return result; + public void addSprite(String name, Sprite sprite) { + skinParam.addSprite(name, sprite); } - static byte xor(List blocs, int nb) { - byte result = 0; - for (byte[] bloc : blocs) { - result = (byte) (result ^ bloc[nb]); - } - return result; + public final Display getLegend() { + return legend; } - static byte[] getSplited(byte[] data, int n, int total) { - final int size = (data.length + total - 1) / total; - assert size * total >= data.length; - final byte result[] = new byte[size + 1]; - result[0] = (byte) (1 << n); - for (int i = 0; (i < size) && (n * total + i < data.length); i++) { - result[i + 1] = data[n * total + i]; - } - return result; + public final HorizontalAlignment getLegendAlignment() { + return legendAlignment; } + public final void setLegend(Display legend, HorizontalAlignment horizontalAlignment) { + this.legend = legend; + this.legendAlignment = horizontalAlignment; + } } diff --git a/src/net/sourceforge/plantuml/UmlDiagramType.java b/src/net/sourceforge/plantuml/UmlDiagramType.java index bff9ea936..32242a642 100644 --- a/src/net/sourceforge/plantuml/UmlDiagramType.java +++ b/src/net/sourceforge/plantuml/UmlDiagramType.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,11 +28,11 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4539 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml; public enum UmlDiagramType { - SEQUENCE, STATE, CLASS, OBJECT, ACTIVITY, USECASE, COMPONENT, COMPOSITE + SEQUENCE, STATE, CLASS, OBJECT, ACTIVITY, DESCRIPTION, COMPOSITE, FLOW } diff --git a/src/net/sourceforge/plantuml/UmlSource.java b/src/net/sourceforge/plantuml/UmlSource.java deleted file mode 100644 index 0e947ead0..000000000 --- a/src/net/sourceforge/plantuml/UmlSource.java +++ /dev/null @@ -1,107 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 4768 $ - * - */ -package net.sourceforge.plantuml; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -final public class UmlSource { - - final private List source; - - public UmlSource(List source) { - this.source = Collections.unmodifiableList(new ArrayList(source)); - } - - public DiagramType getDiagramType() { - return DiagramType.getTypeFromArobaseStart(source.get(0)); - } - - public Iterator iterator() { - return source.iterator(); - } - - 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(); - } - - public boolean isEmpty() { - for (String s : source) { - if (StartUtils.isArobaseStartDiagram(s)) { - continue; - } - if (StartUtils.isArobaseEndDiagram(s)) { - continue; - } - if (s.matches("\\s*'.*")) { - continue; - } - if (s.trim().length() != 0) { - return false; - } - } - return true; - } - - public List getTitle() { - final Pattern p = Pattern.compile("(?i)^\\s*title\\s+(.+)$"); - for (String s : source) { - final Matcher m = p.matcher(s); - final boolean ok = m.matches(); - if (ok) { - return Arrays.asList(m.group(1)); - } - } - return Collections.emptyList(); - } - -} diff --git a/src/net/sourceforge/plantuml/UniqueSequence.java b/src/net/sourceforge/plantuml/UniqueSequence.java index 646181448..4e23535d2 100644 --- a/src/net/sourceforge/plantuml/UniqueSequence.java +++ b/src/net/sourceforge/plantuml/UniqueSequence.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,13 +28,15 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6644 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml; import java.util.concurrent.atomic.AtomicInteger; +import net.sourceforge.plantuml.cucadiagram.Code; + public class UniqueSequence { private static final AtomicInteger cpt = new AtomicInteger(1); @@ -47,4 +49,8 @@ public class UniqueSequence { return cpt.addAndGet(1); } + public static Code getCode(String prefix) { + return Code.of(prefix + getValue()); + } + } diff --git a/src/net/sourceforge/plantuml/Url.java b/src/net/sourceforge/plantuml/Url.java index a49a5deaf..305d5308b 100644 --- a/src/net/sourceforge/plantuml/Url.java +++ b/src/net/sourceforge/plantuml/Url.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,18 +33,34 @@ */ package net.sourceforge.plantuml; -public class Url { +import java.util.Comparator; + +public class Url implements EnsureVisible { private final String url; private final String tooltip; + private final String label; + private boolean member; public Url(String url, String tooltip) { + this(url, tooltip, null); + } + + public Url(String url, String tooltip, String label) { + if (url.contains("{")) { + throw new IllegalArgumentException(url); + } this.url = url; if (tooltip == null) { this.tooltip = url; } else { this.tooltip = tooltip; } + if (label == null) { + this.label = url; + } else { + this.label = label; + } } public final String getUrl() { @@ -54,10 +70,45 @@ public class Url { public final String getTooltip() { return tooltip; } - - @Override - public String toString() { - throw new UnsupportedOperationException(); + + public String getLabel() { + return label; } + @Override + public String toString() { + return super.toString() + " " + url + " " + visible.getCoords(1.0); + } + + public String getCoords(double scale) { + return visible.getCoords(scale); + } + + public void setMember(boolean member) { + this.member = member; + } + + public final boolean isMember() { + return member; + } + + private final BasicEnsureVisible visible = new BasicEnsureVisible(); + + public void ensureVisible(double x, double y) { + visible.ensureVisible(x, y); + } + + public static final Comparator SURFACE_COMPARATOR = new Comparator() { + public int compare(Url url1, Url url2) { + final double surface1 = url1.visible.getSurface(); + final double surface2 = url2.visible.getSurface(); + if (surface1 > surface2) { + return 1; + } else if (surface1 < surface2) { + return -1; + } + return 0; + } + }; + } diff --git a/src/net/sourceforge/plantuml/UrlBuilder.java b/src/net/sourceforge/plantuml/UrlBuilder.java new file mode 100644 index 000000000..bdacdb083 --- /dev/null +++ b/src/net/sourceforge/plantuml/UrlBuilder.java @@ -0,0 +1,95 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 6396 $ + * + */ +package net.sourceforge.plantuml; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class UrlBuilder { + + public static enum ModeUrl { + STRICT, AT_START, ANYWHERE + } + + private static final String URL_PATTERN = "\\[\\[(\"[^\"]+\"|[^{} \\]\\[]*)(?: *\\{([^{}]+)\\})?(?: *([^\\]\\[]+))?\\]\\]"; + + private final String topurl; + private ModeUrl mode; + + public UrlBuilder(String topurl, ModeUrl mode) { + this.topurl = topurl; + this.mode = mode; + } + + public Url getUrl(String s) { + final Pattern p; + if (mode == ModeUrl.STRICT) { + p = Pattern.compile("(?i)^" + URL_PATTERN + "$"); + } else if (mode == ModeUrl.AT_START) { + p = Pattern.compile("(?i)^" + URL_PATTERN + ".*"); + } else if (mode == ModeUrl.ANYWHERE) { + p = Pattern.compile("(?i).*" + URL_PATTERN + ".*"); + } else { + throw new IllegalStateException(); + } + final Matcher m = p.matcher(s.trim()); + if (m.matches() == false) { + return null; + } + String url = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m.group(1)); + if (url.startsWith("http:") == false && url.startsWith("https:") == false) { + // final String top = getSystem().getSkinParam().getValue("topurl"); + if (topurl != null) { + url = topurl + url; + } + } + return new Url(url, m.group(2), m.group(3)); + } + + public static String getRegexp() { + return URL_PATTERN; + } + + public static String purgeUrl(final String label) { + final Pattern p = Pattern.compile("(?: )*" + URL_PATTERN + "(?: )*"); + final Matcher m = p.matcher(label); + if (m.find() == false) { + throw new IllegalStateException(); + } + final String url = m.group(0); + final int x = label.indexOf(url); + return label.substring(0, x) + label.substring(x + url.length()); + } + +} diff --git a/src/net/sourceforge/plantuml/acearth/PSystemXearth.java b/src/net/sourceforge/plantuml/acearth/PSystemXearth.java index 8f9f2dd54..969ac726e 100644 --- a/src/net/sourceforge/plantuml/acearth/PSystemXearth.java +++ b/src/net/sourceforge/plantuml/acearth/PSystemXearth.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -46,6 +46,10 @@ import java.util.TimeZone; import net.sourceforge.plantuml.AbstractPSystem; import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.api.ImageDataSimple; +import net.sourceforge.plantuml.core.DiagramDescription; +import net.sourceforge.plantuml.core.DiagramDescriptionImpl; +import net.sourceforge.plantuml.core.ImageData; import com.ctreber.acearth.ACearth; import com.ctreber.acearth.ConfigurationACearth; @@ -71,9 +75,8 @@ public class PSystemXearth extends AbstractPSystem { this.config = config; this.markers = markers; } - - public void exportDiagram(OutputStream os, StringBuilder cmap, int index, FileFormatOption fileFormat) - throws IOException { + + public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException { final ACearth earth = new ACearth(markers); final ConfigurationACearth conf = earth.getConf(); conf.setInt("imageWidth", width); @@ -98,8 +101,10 @@ public class PSystemXearth extends AbstractPSystem { } } earth.exportPng(os); + return new ImageDataSimple(width, height); } + private Date extractGmt(String s) { final SimpleDateFormat timeFormat; if (s.matches("\\d{4}/\\d{2}/\\d{2} \\d{2}:\\d{2}:\\d{2}")) { @@ -118,8 +123,9 @@ public class PSystemXearth extends AbstractPSystem { } - public String getDescription() { - return "(XEarth)"; + public DiagramDescription getDescription() { + return new DiagramDescriptionImpl("(XEarth)", getClass()); } + } diff --git a/src/net/sourceforge/plantuml/acearth/PSystemXearthFactory.java b/src/net/sourceforge/plantuml/acearth/PSystemXearthFactory.java index ac8ac0db3..6562cbc3d 100644 --- a/src/net/sourceforge/plantuml/acearth/PSystemXearthFactory.java +++ b/src/net/sourceforge/plantuml/acearth/PSystemXearthFactory.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -40,23 +40,23 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import net.sourceforge.plantuml.command.PSystemBasicFactory; + import com.ctreber.acearth.plugins.markers.Marker; -import net.sourceforge.plantuml.DiagramType; -import net.sourceforge.plantuml.PSystemBasicFactory; +public class PSystemXearthFactory extends PSystemBasicFactory { -public class PSystemXearthFactory implements PSystemBasicFactory { - - private PSystemXearth system; private final Map config = new LinkedHashMap(); private final List markers = new ArrayList(); private int width; private int height; - public void init(String startLine) { + public PSystemXearth init(String startLine) { this.width = 512; this.height = 512; this.config.clear(); + this.markers.clear(); + return null; } private void extractDimension(String startLine) { @@ -69,43 +69,36 @@ public class PSystemXearthFactory implements PSystemBasicFactory { } } - public PSystemXearth getSystem() { - return system; - } - - public boolean executeLine(String line) { - if (line.startsWith("xearth")) { + @Override + public PSystemXearth executeLine(PSystemXearth system, String line) { + if (system == null && line.startsWith("xearth")) { extractDimension(line); system = new PSystemXearth(width, height, config, markers); - return true; + return system; } if (system == null) { - return false; + return null; } if (line.startsWith("#") || line.startsWith("'")) { - return true; + return system; } final Pattern p = Pattern.compile("(\\w+)\\s*=\\s*(.*)"); final Matcher m = p.matcher(line); if (m.find()) { config.put(m.group(1), m.group(2)); - return true; + return system; } try { final Marker marker = Marker.loadMarkerFile(line); if (marker != null) { markers.add(marker); - return true; + return system; } } catch (Exception e) { e.printStackTrace(); - return false; + return null; } - return false; - } - - public DiagramType getDiagramType() { - return DiagramType.UML; + return null; } } diff --git a/src/net/sourceforge/plantuml/activitydiagram/ActivityDiagram.java b/src/net/sourceforge/plantuml/activitydiagram/ActivityDiagram.java index 2abcb56e8..7a3212036 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/ActivityDiagram.java +++ b/src/net/sourceforge/plantuml/activitydiagram/ActivityDiagram.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5721 $ + * Revision $Revision: 12053 $ * */ package net.sourceforge.plantuml.activitydiagram; @@ -39,13 +39,15 @@ import java.util.List; import net.sourceforge.plantuml.Direction; import net.sourceforge.plantuml.UmlDiagramType; import net.sourceforge.plantuml.UniqueSequence; +import net.sourceforge.plantuml.core.DiagramDescription; +import net.sourceforge.plantuml.core.DiagramDescriptionImpl; +import net.sourceforge.plantuml.cucadiagram.Code; 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.Display; import net.sourceforge.plantuml.cucadiagram.GroupType; import net.sourceforge.plantuml.cucadiagram.IEntity; -import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.cucadiagram.ILeaf; +import net.sourceforge.plantuml.cucadiagram.LeafType; public class ActivityDiagram extends CucaDiagram { @@ -53,27 +55,32 @@ public class ActivityDiagram extends CucaDiagram { private IEntity lastEntityBrancheConsulted; private ConditionalContext currentContext; + public ILeaf getOrCreateLeaf(Code code, LeafType type) { + return getOrCreateLeafDefault(code, type); + } + private String getAutoBranch() { return "#" + UniqueSequence.getValue(); } - public IEntity getOrCreate(String code, String display, EntityType type) { + public IEntity getOrCreate(Code code, Display display, LeafType type) { final IEntity result; - if (entityExist(code)) { - result = super.getOrCreateEntity(code, type); - if (result.getType() != type) { - throw new IllegalArgumentException("Already known: " + code + " " + result.getType() + " " + type); - // return null; + if (leafExist(code)) { + result = getOrCreateLeafDefault(code, type); + if (result.getEntityType() != type) { + // throw new IllegalArgumentException("Already known: " + code + " " + result.getType() + " " + type); + return null; } } else { - result = createEntity(code, display, type); + result = createLeaf(code, display, type); } updateLasts(result); return result; } - public void startIf(String optionalCode) { - final IEntity br = createEntity(optionalCode == null ? getAutoBranch() : optionalCode, "", EntityType.BRANCH); + public void startIf(Code optionalCode) { + final IEntity br = createLeaf(optionalCode == null ? Code.of(getAutoBranch()) : optionalCode, + Display.asList(""), LeafType.BRANCH); currentContext = new ConditionalContext(currentContext, br, Direction.DOWN); } @@ -81,44 +88,33 @@ public class ActivityDiagram extends CucaDiagram { currentContext = currentContext.getParent(); } - public IEntity getStart() { - return getOrCreate("start", "start", EntityType.CIRCLE_START); + public ILeaf getStart() { + return (ILeaf) getOrCreate(Code.of("start"), Display.getWithNewlines("start"), LeafType.CIRCLE_START); } - public IEntity getEnd() { - return getOrCreate("end", "end", EntityType.CIRCLE_END); - } - - final public Link getLastActivityLink() { - final List links = getLinks(); - for (int i = links.size() - 1; i >= 0; i--) { - final Link link = links.get(i); - if (link.getEntity1().getType() != EntityType.NOTE && link.getEntity2().getType() != EntityType.NOTE) { - return link; - } - } - return null; + public ILeaf getEnd() { + return (ILeaf) getOrCreate(Code.of("end"), Display.getWithNewlines("end"), LeafType.CIRCLE_END); } private void updateLasts(final IEntity result) { - if (result.getType() == EntityType.NOTE) { + if (result.getEntityType() == LeafType.NOTE) { return; } this.lastEntityConsulted = result; - if (result.getType() == EntityType.BRANCH) { + if (result.getEntityType() == LeafType.BRANCH) { lastEntityBrancheConsulted = result; } } @Override - public Entity createEntity(String code, String display, EntityType type) { - final Entity result = super.createEntity(code, display, type); + public ILeaf createLeaf(Code code, Display display, LeafType type) { + final ILeaf result = super.createLeaf(code, display, type); updateLasts(result); return result; } - public Entity createNote(String code, String display) { - return super.createEntity(code, display, EntityType.NOTE); + public IEntity createNote(Code code, Display display) { + return super.createLeaf(code, display, LeafType.NOTE); } final protected List getDotStrings() { @@ -126,8 +122,8 @@ public class ActivityDiagram extends CucaDiagram { "node [fontsize=11];"); } - public String getDescription() { - return "(" + entities().size() + " activities)"; + public DiagramDescription getDescription() { + return new DiagramDescriptionImpl("(" + getLeafs().size() + " activities)", getClass()); } public IEntity getLastEntityConsulted() { @@ -153,29 +149,31 @@ public class ActivityDiagram extends CucaDiagram { } public IEntity createInnerActivity() { - // System.err.println("createInnerActivity A"); - final String code = "##" + UniqueSequence.getValue(); - final Group g = getOrCreateGroup(code, code, null, GroupType.INNER_ACTIVITY, getCurrentGroup()); + // Log.println("createInnerActivity A"); + final Code code = Code.of("##" + UniqueSequence.getValue()); + final IEntity g = getOrCreateGroup(code, Display.getWithNewlines(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(); + // Log.println("createInnerActivity B "+getCurrentGroup()); + return g; } public void concurrentActivity(String name) { - // System.err.println("concurrentActivity A name=" + name+" "+getCurrentGroup()); - if (getCurrentGroup().getType() == GroupType.CONCURRENT_ACTIVITY) { + // Log.println("concurrentActivity A name=" + name+" "+getCurrentGroup()); + if (getCurrentGroup().getGroupType() == GroupType.CONCURRENT_ACTIVITY) { // getCurrentGroup().setRankdir(Rankdir.LEFT_TO_RIGHT); endGroup(); - System.err.println("endgroup"); + // Log.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()); + // Log.println("concurrentActivity A name=" + name+" "+getCurrentGroup()); + final Code code = Code.of("##" + UniqueSequence.getValue()); + if (getCurrentGroup().getGroupType() != GroupType.INNER_ACTIVITY) { + throw new IllegalStateException("type=" + getCurrentGroup().getGroupType()); } - final Group g = getOrCreateGroup(code, "code", null, GroupType.CONCURRENT_ACTIVITY, getCurrentGroup()); + getOrCreateGroup(code, Display.getWithNewlines("code"), null, GroupType.CONCURRENT_ACTIVITY, + getCurrentGroup()); lastEntityConsulted = null; lastEntityBrancheConsulted = null; } diff --git a/src/net/sourceforge/plantuml/activitydiagram/ActivityDiagramFactory.java b/src/net/sourceforge/plantuml/activitydiagram/ActivityDiagramFactory.java index 8a9057728..de498fbc8 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/ActivityDiagramFactory.java +++ b/src/net/sourceforge/plantuml/activitydiagram/ActivityDiagramFactory.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -27,54 +27,62 @@ * in the United States and other countries.] * * Original Author: Arnaud Roques - * - * Revision $Revision: 5890 $ + * + * Revision $Revision: 10006 $ * */ package net.sourceforge.plantuml.activitydiagram; +import java.util.ArrayList; +import java.util.List; + 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.CommandLinkActivity; -import net.sourceforge.plantuml.activitydiagram.command.CommandLinkLongActivity; -import net.sourceforge.plantuml.activitydiagram.command.CommandMultilinesNoteActivity; -import net.sourceforge.plantuml.activitydiagram.command.CommandMultilinesNoteActivityLink; -import net.sourceforge.plantuml.activitydiagram.command.CommandNoteActivity; -import net.sourceforge.plantuml.activitydiagram.command.CommandNoteOnActivityLink; +import net.sourceforge.plantuml.activitydiagram.command.CommandLinkActivity2; +import net.sourceforge.plantuml.activitydiagram.command.CommandLinkLongActivity2; import net.sourceforge.plantuml.activitydiagram.command.CommandPartition; -import net.sourceforge.plantuml.command.AbstractUmlSystemCommandFactory; +import net.sourceforge.plantuml.command.Command; +import net.sourceforge.plantuml.command.CommandRankDir; +import net.sourceforge.plantuml.command.UmlDiagramFactory; +import net.sourceforge.plantuml.command.note.FactoryNoteActivityCommand; +import net.sourceforge.plantuml.command.note.FactoryNoteOnLinkCommand; -public class ActivityDiagramFactory extends AbstractUmlSystemCommandFactory { +public class ActivityDiagramFactory extends UmlDiagramFactory { - private ActivityDiagram system; - - public ActivityDiagram getSystem() { - return system; + @Override + public ActivityDiagram createEmptyDiagram() { + return new ActivityDiagram(); } @Override - protected void initCommands() { - system = new ActivityDiagram(); + protected List createCommands() { + final List cmds = new ArrayList(); + addCommonCommands(cmds); + cmds.add(new CommandRankDir()); - addCommonCommands(system); + cmds.add(new CommandPartition()); + cmds.add(new CommandEndPartition()); + cmds.add(new CommandLinkLongActivity2()); - addCommand(new CommandLinkActivity(system)); - addCommand(new CommandPartition(system)); - addCommand(new CommandEndPartition(system)); - addCommand(new CommandLinkLongActivity(system)); + final FactoryNoteActivityCommand factoryNoteActivityCommand = new FactoryNoteActivityCommand(); + cmds.add(factoryNoteActivityCommand.createSingleLine()); + cmds.add(factoryNoteActivityCommand.createMultiLine()); - addCommand(new CommandNoteActivity(system)); - addCommand(new CommandMultilinesNoteActivity(system)); + final FactoryNoteOnLinkCommand factoryNoteOnLinkCommand = new FactoryNoteOnLinkCommand(); + cmds.add(factoryNoteOnLinkCommand.createSingleLine()); + cmds.add(factoryNoteOnLinkCommand.createMultiLine()); - addCommand(new CommandNoteOnActivityLink(system)); - addCommand(new CommandMultilinesNoteActivityLink(system)); - - addCommand(new CommandIf(system)); - addCommand(new CommandElse(system)); - addCommand(new CommandEndif(system)); + cmds.add(new CommandIf()); + cmds.add(new CommandElse()); + cmds.add(new CommandEndif()); + + cmds.add(new CommandLinkActivity2()); // addCommand(new CommandInnerConcurrent(system)); + + return cmds; + } } diff --git a/src/net/sourceforge/plantuml/activitydiagram/ConditionalContext.java b/src/net/sourceforge/plantuml/activitydiagram/ConditionalContext.java index cc220e857..927631b42 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/ConditionalContext.java +++ b/src/net/sourceforge/plantuml/activitydiagram/ConditionalContext.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -34,8 +34,8 @@ package net.sourceforge.plantuml.activitydiagram; import net.sourceforge.plantuml.Direction; -import net.sourceforge.plantuml.cucadiagram.EntityType; import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.LeafType; public class ConditionalContext { @@ -44,7 +44,7 @@ public class ConditionalContext { private final ConditionalContext parent; public ConditionalContext(ConditionalContext parent, IEntity branch, Direction direction) { - if (branch.getType() != EntityType.BRANCH) { + if (branch.getEntityType() != LeafType.BRANCH) { throw new IllegalArgumentException(); } this.branch = branch; diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandElse.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandElse.java index cbfbbffe7..ff956d9ac 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandElse.java +++ b/src/net/sourceforge/plantuml/activitydiagram/command/CommandElse.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -42,21 +42,21 @@ import net.sourceforge.plantuml.cucadiagram.IEntity; public class CommandElse extends SingleLineCommand { - public CommandElse(ActivityDiagram diagram) { - super(diagram, "(?i)^else$"); + public CommandElse() { + super("(?i)^else$"); } @Override - protected CommandExecutionResult executeArg(List arg) { - if (getSystem().getLastEntityConsulted() == null) { + protected CommandExecutionResult executeArg(ActivityDiagram system, List arg) { + if (system.getLastEntityConsulted() == null) { return CommandExecutionResult.error("No if for this else"); } - if (getSystem().getCurrentContext() == null) { + if (system.getCurrentContext() == null) { return CommandExecutionResult.error("No if for this else"); } - final IEntity branch = getSystem().getCurrentContext().getBranch(); + final IEntity branch = system.getCurrentContext().getBranch(); - getSystem().setLastEntityConsulted(branch); + system.setLastEntityConsulted(branch); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandEndPartition.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandEndPartition.java index 583e28737..cec0e0a39 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandEndPartition.java +++ b/src/net/sourceforge/plantuml/activitydiagram/command/CommandEndPartition.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5048 $ + * Revision $Revision: 10778 $ * */ package net.sourceforge.plantuml.activitydiagram.command; @@ -38,21 +38,21 @@ 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; +import net.sourceforge.plantuml.cucadiagram.IEntity; public class CommandEndPartition extends SingleLineCommand { - public CommandEndPartition(ActivityDiagram diagram) { - super(diagram, "(?i)^(end ?partition|\\})$"); + public CommandEndPartition() { + super("(?i)^(end ?partition|\\})$"); } @Override - protected CommandExecutionResult executeArg(List arg) { - final Group currentPackage = getSystem().getCurrentGroup(); + protected CommandExecutionResult executeArg(ActivityDiagram diagram, List arg) { + final IEntity currentPackage = diagram.getCurrentGroup(); if (currentPackage == null) { return CommandExecutionResult.error("No partition defined"); } - getSystem().endGroup(); + diagram.endGroup(); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandEndif.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandEndif.java index e75aa0528..a46a02bea 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandEndif.java +++ b/src/net/sourceforge/plantuml/activitydiagram/command/CommandEndif.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -41,19 +41,19 @@ import net.sourceforge.plantuml.command.SingleLineCommand; public class CommandEndif extends SingleLineCommand { - public CommandEndif(ActivityDiagram diagram) { - super(diagram, "(?i)^end ?if$"); + public CommandEndif() { + super("(?i)^end ?if$"); } @Override - protected CommandExecutionResult executeArg(List arg) { - if (getSystem().getLastEntityConsulted() == null) { + protected CommandExecutionResult executeArg(ActivityDiagram diagram, List arg) { + if (diagram.getLastEntityConsulted() == null) { return CommandExecutionResult.error("No if for this endif"); } - if (getSystem().getCurrentContext() == null) { + if (diagram.getCurrentContext() == null) { return CommandExecutionResult.error("No if for this endif"); } - getSystem().endif(); + diagram.endif(); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandIf.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandIf.java index 85fbdef9d..ec8541c75 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandIf.java +++ b/src/net/sourceforge/plantuml/activitydiagram/command/CommandIf.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,8 +33,6 @@ */ package net.sourceforge.plantuml.activitydiagram.command; -import java.util.Map; - import net.sourceforge.plantuml.Direction; import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.activitydiagram.ActivityDiagram; @@ -42,8 +40,11 @@ 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.RegexOptional; import net.sourceforge.plantuml.command.regex.RegexOr; -import net.sourceforge.plantuml.command.regex.RegexPartialMatch; +import net.sourceforge.plantuml.command.regex.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.cucadiagram.Link; import net.sourceforge.plantuml.cucadiagram.LinkDecor; @@ -51,51 +52,67 @@ import net.sourceforge.plantuml.cucadiagram.LinkType; public class CommandIf extends SingleLineCommand2 { - public CommandIf(ActivityDiagram diagram) { - super(diagram, getRegexConcat()); + public CommandIf() { + super(getRegexConcat()); } static RegexConcat getRegexConcat() { - return new RegexConcat(new RegexLeaf("^"), - new RegexOr("FIRST", true, - new RegexLeaf("STAR", "(\\(\\*(top)?\\))"), - new RegexLeaf("CODE", "([\\p{L}0-9_.]+)"), - new RegexLeaf("BAR", "(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)"), - new RegexLeaf("QUOTED", "\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?")), - new RegexLeaf("\\s*"), - new RegexLeaf("ARROW", "([=-]+(?:(left|right|up|down|le?|ri?|up?|do?)(?=[-=.]))?[=-]*\\>)?"), - new RegexLeaf("\\s*"), - new RegexLeaf("BRACKET", "(?:\\[([^\\]*]+[^\\]]*)\\])?"), - new RegexLeaf("\\s*"), - new RegexLeaf("IF", "if\\s*\"([^\"]*)\"\\s*(?:as\\s+([\\p{L}0-9_.]+)\\s+)?(?:then)?$")); + return new RegexConcat(new RegexLeaf("^"), // + new RegexOptional(// + new RegexOr("FIRST", // + new RegexLeaf("STAR", "(\\(\\*(top)?\\))"), // + new RegexLeaf("CODE", "([\\p{L}0-9_.]+)"), // + new RegexLeaf("BAR", "(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)"), // + new RegexLeaf("QUOTED", "\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?"))), // + new RegexLeaf("\\s*"), // + new RegexLeaf("ARROW", "([=-]+(?:(left|right|up|down|le?|ri?|up?|do?)(?=[-=.]))?[=-]*\\>)?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("BRACKET", "(?:\\[([^\\]*]+[^\\]]*)\\])?"), // + new RegexLeaf("\\s*"), // + new RegexOr(// + new RegexLeaf("IF1", "if\\s*\"([^\"]*)\"\\s*(?:as\\s+([\\p{L}0-9_.]+)\\s+)?"), // + new RegexLeaf("IF2", "if\\s+(.+?)\\s*")), // + new RegexLeaf("(?:then)?$")); } - @Override - protected CommandExecutionResult executeArg(Map arg) { - final IEntity entity1 = CommandLinkActivity.getEntity(getSystem(), arg, true); + protected CommandExecutionResult executeArg(ActivityDiagram system, RegexResult arg) { + final IEntity entity1 = CommandLinkActivity.getEntity(system, arg, true); + if (entity1 == null) { + return CommandExecutionResult.error("No if possible at this point"); + } - getSystem().startIf(arg.get("IF").get(1)); + final String ifCode; + final String ifLabel; + if (arg.get("IF2", 0) == null) { + ifCode = arg.get("IF1", 1); + ifLabel = arg.get("IF1", 0); + } else { + ifCode = null; + ifLabel = arg.get("IF2", 0); + } + system.startIf(Code.of(ifCode)); int lenght = 2; - if (arg.get("ARROW").get(0) != null) { - final String arrow = StringUtils.manageArrowForCuca(arg.get("ARROW").get(0)); + if (arg.get("ARROW", 0) != null) { + final String arrow = StringUtils.manageArrowForCuca(arg.get("ARROW", 0)); lenght = arrow.length() - 1; } - final IEntity branch = getSystem().getCurrentContext().getBranch(); + final IEntity branch = system.getCurrentContext().getBranch(); - Link link = new Link(entity1, branch, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), arg.get("BRACKET").get(0), - lenght, null, arg.get("IF").get(0), getSystem().getLabeldistance(), getSystem().getLabelangle()); - if (arg.get("ARROW").get(0) != null) { - final Direction direction = StringUtils.getArrowDirection(arg.get("ARROW").get(0)); + Link link = new Link(entity1, branch, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), + Display.getWithNewlines(arg.get("BRACKET", 0)), lenght, null, ifLabel, system.getLabeldistance(), + system.getLabelangle()); + if (arg.get("ARROW", 0) != null) { + final Direction direction = StringUtils.getArrowDirection(arg.get("ARROW", 0)); if (direction == Direction.LEFT || direction == Direction.UP) { link = link.getInv(); } } - getSystem().addLink(link); + system.addLink(link); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandInnerConcurrent.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandInnerConcurrent.java index 9cc70377b..c0d989889 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandInnerConcurrent.java +++ b/src/net/sourceforge/plantuml/activitydiagram/command/CommandInnerConcurrent.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -38,19 +38,20 @@ 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.EntityUtils; public class CommandInnerConcurrent extends SingleLineCommand { - public CommandInnerConcurrent(ActivityDiagram diagram) { - super(diagram, "(?i)^--\\s*(.*)$"); + public CommandInnerConcurrent() { + super("(?i)^--\\s*(.*)$"); } @Override - protected CommandExecutionResult executeArg(List arg) { - if (getSystem().getCurrentGroup() == null) { + protected CommandExecutionResult executeArg(ActivityDiagram diagram, List arg) { + if (EntityUtils.groupRoot(diagram.getCurrentGroup())) { return CommandExecutionResult.error("No inner activity"); } - getSystem().concurrentActivity(arg.get(0)); + diagram.concurrentActivity(arg.get(0)); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkActivity.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkActivity.java index c421cdfa1..07800c4e8 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkActivity.java +++ b/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkActivity.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,163 +33,219 @@ */ package net.sourceforge.plantuml.activitydiagram.command; -import java.util.Map; - import net.sourceforge.plantuml.Direction; import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.UrlBuilder; +import net.sourceforge.plantuml.UrlBuilder.ModeUrl; import net.sourceforge.plantuml.activitydiagram.ActivityDiagram; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.SingleLineCommand2; import net.sourceforge.plantuml.command.regex.RegexConcat; import net.sourceforge.plantuml.command.regex.RegexLeaf; +import net.sourceforge.plantuml.command.regex.RegexOptional; import net.sourceforge.plantuml.command.regex.RegexOr; import net.sourceforge.plantuml.command.regex.RegexPartialMatch; -import net.sourceforge.plantuml.cucadiagram.EntityType; +import net.sourceforge.plantuml.command.regex.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.GroupType; import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.LeafType; import net.sourceforge.plantuml.cucadiagram.Link; import net.sourceforge.plantuml.cucadiagram.LinkDecor; import net.sourceforge.plantuml.cucadiagram.LinkType; import net.sourceforge.plantuml.cucadiagram.Stereotype; -import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; public class CommandLinkActivity extends SingleLineCommand2 { - public CommandLinkActivity(ActivityDiagram diagram) { - super(diagram, getRegexConcat()); + public CommandLinkActivity() { + super(getRegexConcat()); } static RegexConcat getRegexConcat() { - return new RegexConcat( - new RegexLeaf("^"), // - new RegexOr("FIRST", true, // - new RegexLeaf("STAR", "(\\(\\*(top)?\\))"), // - new RegexLeaf("CODE", "([\\p{L}0-9_.]+)"), // - new RegexLeaf("BAR", "(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)"), // - new RegexLeaf("QUOTED", "\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?")), // + return new RegexConcat(new RegexLeaf("^"), // + new RegexOptional(// + new RegexOr("FIRST", // + new RegexLeaf("STAR", "(\\(\\*(top)?\\))"), // + new RegexLeaf("CODE", "([\\p{L}0-9][\\p{L}0-9_.]*)"), // + new RegexLeaf("BAR", "(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)"), // + new RegexLeaf("QUOTED", "\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?"))), // new RegexLeaf("\\s*"), // new RegexLeaf("STEREOTYPE", "(\\<\\<.*\\>\\>)?"), // new RegexLeaf("\\s*"), // - new RegexLeaf("BACKCOLOR", "(#\\w+)?"), // - new RegexLeaf("\\s*"), // - new RegexLeaf("ARROW", "([=-]+(?:\\*|left|right|up|down|le?|ri?|up?|do?)?[=-]*\\>)"), // + new RegexLeaf("BACKCOLOR", "(#\\w+[-\\\\|/]?\\w+)?"), // new RegexLeaf("\\s*"), // - new RegexLeaf("BRACKET", "(?:\\[([^\\]*]+[^\\]]*)\\])?"), // + new RegexLeaf("URL", "(" + UrlBuilder.getRegexp() + ")?"), // + new RegexLeaf("ARROW", "([-=.]+(?:\\*|left|right|up|down|le?|ri?|up?|do?)?[-=.]*\\>)"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("BRACKET", "(?:\\[([^\\]*]+[^\\]]*)\\])?"), // + new RegexLeaf("\\s*"), // + new RegexOr("FIRST2", // + new RegexLeaf("STAR2", "(\\(\\*(top)?\\))"), // + new RegexLeaf("OPENBRACKET2", "(\\{)"), // + new RegexLeaf("CODE2", "([\\p{L}0-9][\\p{L}0-9_.]*)"), // + new RegexLeaf("BAR2", "(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)"), // + new RegexLeaf("QUOTED2", "\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9][\\p{L}0-9_.]*))?"), // + new RegexLeaf("QUOTED_INVISIBLE2", "(\\w.*?)")), // new RegexLeaf("\\s*"), // - new RegexOr("FIRST2", // - new RegexLeaf("STAR2", "(\\(\\*(top)?\\))"), // - new RegexLeaf("OPENBRACKET2", "(\\{)"), // - new RegexLeaf("CODE2", "([\\p{L}0-9_.]+)"), // - new RegexLeaf("BAR2", "(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)"), // - new RegexLeaf("QUOTED2", "\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?")), - new RegexLeaf("\\s*"), // new RegexLeaf("STEREOTYPE2", "(\\<\\<.*\\>\\>)?"), // new RegexLeaf("\\s*"), // - new RegexLeaf("BACKCOLOR2", "(#\\w+)?"), // + new RegexLeaf("PARTITION2", "(?:in\\s+(\"[^\"]+\"|\\S+))?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("BACKCOLOR2", "(#\\w+[-\\\\|/]?\\w+)?"), // new RegexLeaf("$")); } @Override - protected CommandExecutionResult executeArg(Map arg2) { - final IEntity entity1 = getEntity(getSystem(), arg2, true); + protected CommandExecutionResult executeArg(ActivityDiagram diagram, RegexResult arg2) { + final IEntity entity1 = getEntity(diagram, arg2, true); if (entity1 == null) { return CommandExecutionResult.error("No such activity"); } - if (arg2.get("STEREOTYPE").get(0) != null) { - entity1.setStereotype(new Stereotype(arg2.get("STEREOTYPE").get(0))); + if (arg2.get("STEREOTYPE", 0) != null) { + entity1.setStereotype(new Stereotype(arg2.get("STEREOTYPE", 0))); } - if (arg2.get("BACKCOLOR").get(0) != null) { - entity1.setSpecificBackcolor(HtmlColor.getColorIfValid(arg2.get("BACKCOLOR").get(0))); + if (arg2.get("BACKCOLOR", 0) != null) { + entity1.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(arg2.get("BACKCOLOR", 0))); } - final IEntity entity2 = getEntity(getSystem(), arg2, false); + final IEntity entity2 = getEntity(diagram, arg2, false); if (entity2 == null) { return CommandExecutionResult.error("No such activity"); } - if (arg2.get("BACKCOLOR2").get(0) != null) { - entity2.setSpecificBackcolor(HtmlColor.getColorIfValid(arg2.get("BACKCOLOR2").get(0))); + if (arg2.get("BACKCOLOR2", 0) != null) { + entity2.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(arg2.get("BACKCOLOR2", 0))); } - if (arg2.get("STEREOTYPE2").get(0) != null) { - entity2.setStereotype(new Stereotype(arg2.get("STEREOTYPE2").get(0))); + if (arg2.get("STEREOTYPE2", 0) != null) { + entity2.setStereotype(new Stereotype(arg2.get("STEREOTYPE2", 0))); } - final String linkLabel = arg2.get("BRACKET").get(0); + final Display linkLabel = Display.getWithNewlines(arg2.get("BRACKET", 0)); - final String arrow = StringUtils.manageArrowForCuca(arg2.get("ARROW").get(0)); + final String arrow = StringUtils.manageArrowForCuca(arg2.get("ARROW", 0)); int lenght = arrow.length() - 1; - if (arg2.get("ARROW").get(0).contains("*")) { + if (arg2.get("ARROW", 0).contains("*")) { lenght = 2; } - Link link = new Link(entity1, entity2, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), linkLabel, lenght); - if (arg2.get("ARROW").get(0).contains("*")) { + LinkType type = new LinkType(LinkDecor.ARROW, LinkDecor.NONE); + if (arg2.get("ARROW", 0).contains(".")) { + type = type.getDotted(); + } + + Link link = new Link(entity1, entity2, type, linkLabel, lenght); + if (arg2.get("ARROW", 0).contains("*")) { link.setConstraint(false); } - final Direction direction = StringUtils.getArrowDirection(arg2.get("ARROW").get(0)); + final Direction direction = StringUtils.getArrowDirection(arg2.get("ARROW", 0)); if (direction == Direction.LEFT || direction == Direction.UP) { link = link.getInv(); } + if (arg2.get("URL", 0) != null) { + final UrlBuilder urlBuilder = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), ModeUrl.STRICT); + final Url urlLink = urlBuilder.getUrl(arg2.get("URL", 0)); + link.setUrl(urlLink); + } - getSystem().addLink(link); + diagram.addLink(link); return CommandExecutionResult.ok(); } - static IEntity getEntity(ActivityDiagram system, Map arg, final boolean start) { + static IEntity getEntity(ActivityDiagram system, RegexResult arg, final boolean start) { final String suf = start ? "" : "2"; - final RegexPartialMatch openBracket = arg.get("OPENBRACKET" + suf); - if (openBracket != null && openBracket.get(0) != null) { + final String openBracket2 = arg.get("OPENBRACKET" + suf, 0); + if (openBracket2 != null) { return system.createInnerActivity(); } - if (arg.get("STAR" + suf).get(0) != null) { + if (arg.get("STAR" + suf, 0) != null) { if (start) { - if (arg.get("STAR" + suf).get(1) != null) { + if (arg.get("STAR" + suf, 1) != null) { system.getStart().setTop(true); } return system.getStart(); } return system.getEnd(); } - final String code = arg.get("CODE" + suf).get(0); - if (code != null) { - return system.getOrCreate(code, code, getTypeIfExisting(system, code)); + String partition = arg.get("PARTITION" + suf, 0); + if (partition != null) { + partition = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(partition); } - final String bar = arg.get("BAR" + suf).get(0); + final Code code = Code.of(arg.get("CODE" + suf, 0)); + if (code != null) { + if (partition != null) { + system.getOrCreateGroup(Code.of(partition), Display.getWithNewlines(partition), null, + GroupType.PACKAGE, system.getRootGroup()); + } + final IEntity result = system.getOrCreate(code, Display.getWithNewlines(code), + getTypeIfExisting(system, code)); + if (partition != null) { + system.endGroup(); + } + return result; + } + final String bar = arg.get("BAR" + suf, 0); if (bar != null) { - return system.getOrCreate(bar, bar, EntityType.SYNCHRO_BAR); + return system.getOrCreate(Code.of(bar), Display.getWithNewlines(bar), LeafType.SYNCHRO_BAR); } final RegexPartialMatch quoted = arg.get("QUOTED" + suf); if (quoted.get(0) != null) { - final String quotedCode = quoted.get(1) == null ? quoted.get(0) : quoted.get(1); - return system.getOrCreate(quotedCode, quoted.get(0), getTypeIfExisting(system, quotedCode)); + final Code quotedCode = Code.of(quoted.get(1) == null ? quoted.get(0) : quoted.get(1)); + if (partition != null) { + system.getOrCreateGroup(Code.of(partition), Display.getWithNewlines(partition), null, + GroupType.PACKAGE, system.getRootGroup()); + } + final IEntity result = system.getOrCreate(quotedCode, Display.getWithNewlines(quoted.get(0)), + getTypeIfExisting(system, quotedCode)); + if (partition != null) { + system.endGroup(); + } + return result; } - final String first = arg.get("FIRST" + suf).get(0); + final Code quotedInvisible = Code.of(arg.get("QUOTED_INVISIBLE" + suf, 0)); + if (quotedInvisible != null) { + if (partition != null) { + system.getOrCreateGroup(Code.of(partition), Display.getWithNewlines(partition), null, + GroupType.PACKAGE, system.getRootGroup()); + } + final IEntity result = system.getOrCreate(quotedInvisible, Display.getWithNewlines(quotedInvisible), + LeafType.ACTIVITY); + if (partition != null) { + system.endGroup(); + } + return result; + } + final String first = arg.get("FIRST" + suf, 0); if (first == null) { return system.getLastEntityConsulted(); } - throw new UnsupportedOperationException(); + + return null; } - static EntityType getTypeIfExisting(ActivityDiagram system, String code) { - if (system.entityExist(code)) { - final IEntity ent = system.entities().get(code); - if (ent.getType() == EntityType.BRANCH) { - return EntityType.BRANCH; + static LeafType getTypeIfExisting(ActivityDiagram system, Code code) { + if (system.leafExist(code)) { + final IEntity ent = system.getLeafs().get(code); + if (ent.getEntityType() == LeafType.BRANCH) { + return LeafType.BRANCH; } } - return EntityType.ACTIVITY; + return LeafType.ACTIVITY; } - static EntityType getTypeFromString(String type, final EntityType circle) { + static LeafType getTypeFromString(String type, final LeafType circle) { if (type == null) { - return EntityType.ACTIVITY; + return LeafType.ACTIVITY; } if (type.equals("*")) { return circle; } if (type.startsWith("=")) { - return EntityType.SYNCHRO_BAR; + return LeafType.SYNCHRO_BAR; } throw new IllegalArgumentException(); } diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkActivity2.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkActivity2.java new file mode 100644 index 000000000..0d663a52f --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkActivity2.java @@ -0,0 +1,268 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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 net.sourceforge.plantuml.Direction; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.UrlBuilder; +import net.sourceforge.plantuml.UrlBuilder.ModeUrl; +import net.sourceforge.plantuml.activitydiagram.ActivityDiagram; +import net.sourceforge.plantuml.classdiagram.command.CommandLinkClass; +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.RegexOptional; +import net.sourceforge.plantuml.command.regex.RegexOr; +import net.sourceforge.plantuml.command.regex.RegexPartialMatch; +import net.sourceforge.plantuml.command.regex.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.GroupType; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.LeafType; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.cucadiagram.LinkDecor; +import net.sourceforge.plantuml.cucadiagram.LinkType; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; + +public class CommandLinkActivity2 extends SingleLineCommand2 { + + public CommandLinkActivity2() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexOptional(// + new RegexOr("FIRST", // + new RegexLeaf("STAR", "(\\(\\*(top)?\\))"), // + new RegexLeaf("CODE", "([\\p{L}0-9][\\p{L}0-9_.]*)"), // + new RegexLeaf("BAR", "(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)"), // + new RegexLeaf("QUOTED", "\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?"))), // + new RegexLeaf("\\s*"), // + new RegexLeaf("STEREOTYPE", "(\\<\\<.*\\>\\>)?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("BACKCOLOR", "(#\\w+[-\\\\|/]?\\w+)?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("URL", "(" + UrlBuilder.getRegexp() + ")?"), // + + new RegexLeaf("ARROW_BODY1", "([-.]+)"), // + new RegexLeaf("ARROW_STYLE1", + "(?:\\[((?:#\\w+|dotted|dashed|bold|hidden)(?:,#\\w+|,dotted|,dashed|,bold|,hidden)*)\\])?"), // + new RegexLeaf("ARROW_DIRECTION", "(\\*|left|right|up|down|le?|ri?|up?|do?)?"), // + new RegexLeaf("ARROW_STYLE2", + "(?:\\[((?:#\\w+|dotted|dashed|bold|hidden)(?:,#\\w+|,dotted|,dashed|,bold|,hidden)*)\\])?"), // + new RegexLeaf("ARROW_BODY2", "([-.]*)\\>"), // + + // new RegexLeaf("ARROW", "([-=.]+(?:\\*|left|right|up|down|le?|ri?|up?|do?)?[-=.]*\\>)"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("BRACKET", "(?:\\[([^\\]*]+[^\\]]*)\\])?"), // + new RegexLeaf("\\s*"), // + new RegexOr("FIRST2", // + new RegexLeaf("STAR2", "(\\(\\*(top)?\\))"), // + new RegexLeaf("OPENBRACKET2", "(\\{)"), // + new RegexLeaf("CODE2", "([\\p{L}0-9][\\p{L}0-9_.]*)"), // + new RegexLeaf("BAR2", "(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)"), // + new RegexLeaf("QUOTED2", "\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9][\\p{L}0-9_.]*))?"), // + new RegexLeaf("QUOTED_INVISIBLE2", "(\\w.*?)")), // + new RegexLeaf("\\s*"), // + new RegexLeaf("STEREOTYPE2", "(\\<\\<.*\\>\\>)?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("PARTITION2", "(?:in\\s+(\"[^\"]+\"|\\S+))?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("BACKCOLOR2", "(#\\w+[-\\\\|/]?\\w+)?"), // + new RegexLeaf("$")); + } + + @Override + protected CommandExecutionResult executeArg(ActivityDiagram diagram, RegexResult arg2) { + final IEntity entity1 = getEntity(diagram, arg2, true); + if (entity1 == null) { + return CommandExecutionResult.error("No such activity"); + } + if (arg2.get("STEREOTYPE", 0) != null) { + entity1.setStereotype(new Stereotype(arg2.get("STEREOTYPE", 0))); + } + if (arg2.get("BACKCOLOR", 0) != null) { + entity1.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(arg2.get("BACKCOLOR", 0))); + } + + final IEntity entity2 = getEntity(diagram, arg2, false); + if (entity2 == null) { + return CommandExecutionResult.error("No such activity"); + } + if (arg2.get("BACKCOLOR2", 0) != null) { + entity2.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(arg2.get("BACKCOLOR2", 0))); + } + if (arg2.get("STEREOTYPE2", 0) != null) { + entity2.setStereotype(new Stereotype(arg2.get("STEREOTYPE2", 0))); + } + + final Display linkLabel = Display.getWithNewlines(arg2.get("BRACKET", 0)); + + final String arrowBody1 = CommandLinkClass.notNull(arg2.get("ARROW_BODY1", 0)); + final String arrowBody2 = CommandLinkClass.notNull(arg2.get("ARROW_BODY2", 0)); + final String arrowDirection = CommandLinkClass.notNull(arg2.get("ARROW_DIRECTION", 0)); + + final String arrow = StringUtils.manageArrowForCuca(arrowBody1 + arrowDirection + arrowBody2 + ">"); + int lenght = arrow.length() - 1; + if (arrowDirection.contains("*")) { + lenght = 2; + } + + LinkType type = new LinkType(LinkDecor.ARROW, LinkDecor.NONE); + if ((arrowBody1 + arrowBody2).contains(".")) { + type = type.getDotted(); + } + + Link link = new Link(entity1, entity2, type, linkLabel, lenght); + if (arrowDirection.contains("*")) { + link.setConstraint(false); + } + final Direction direction = StringUtils.getArrowDirection(arrowBody1 + arrowDirection + arrowBody2 + ">"); + if (direction == Direction.LEFT || direction == Direction.UP) { + link = link.getInv(); + } + if (arg2.get("URL", 0) != null) { + final UrlBuilder urlBuilder = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), ModeUrl.STRICT); + final Url urlLink = urlBuilder.getUrl(arg2.get("URL", 0)); + link.setUrl(urlLink); + } + + CommandLinkClass.applyStyle(arg2.getLazzy("ARROW_STYLE", 0), link); + diagram.addLink(link); + + return CommandExecutionResult.ok(); + + } + + static IEntity getEntity(ActivityDiagram system, RegexResult arg, final boolean start) { + final String suf = start ? "" : "2"; + + final String openBracket2 = arg.get("OPENBRACKET" + suf, 0); + if (openBracket2 != null) { + return system.createInnerActivity(); + } + if (arg.get("STAR" + suf, 0) != null) { + if (start) { + if (arg.get("STAR" + suf, 1) != null) { + system.getStart().setTop(true); + } + return system.getStart(); + } + return system.getEnd(); + } + String partition = arg.get("PARTITION" + suf, 0); + if (partition != null) { + partition = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(partition); + } + final Code code = Code.of(arg.get("CODE" + suf, 0)); + if (code != null) { + if (partition != null) { + system.getOrCreateGroup(Code.of(partition), Display.getWithNewlines(partition), null, + GroupType.PACKAGE, system.getRootGroup()); + } + final IEntity result = system.getOrCreate(code, Display.getWithNewlines(code), + getTypeIfExisting(system, code)); + if (partition != null) { + system.endGroup(); + } + return result; + } + final String bar = arg.get("BAR" + suf, 0); + if (bar != null) { + return system.getOrCreate(Code.of(bar), Display.getWithNewlines(bar), LeafType.SYNCHRO_BAR); + } + final RegexPartialMatch quoted = arg.get("QUOTED" + suf); + if (quoted.get(0) != null) { + final Code quotedCode = Code.of(quoted.get(1) == null ? quoted.get(0) : quoted.get(1)); + if (partition != null) { + system.getOrCreateGroup(Code.of(partition), Display.getWithNewlines(partition), null, + GroupType.PACKAGE, system.getRootGroup()); + } + final IEntity result = system.getOrCreate(quotedCode, Display.getWithNewlines(quoted.get(0)), + getTypeIfExisting(system, quotedCode)); + if (partition != null) { + system.endGroup(); + } + return result; + } + final Code quotedInvisible = Code.of(arg.get("QUOTED_INVISIBLE" + suf, 0)); + if (quotedInvisible != null) { + if (partition != null) { + system.getOrCreateGroup(Code.of(partition), Display.getWithNewlines(partition), null, + GroupType.PACKAGE, system.getRootGroup()); + } + final IEntity result = system.getOrCreate(quotedInvisible, Display.getWithNewlines(quotedInvisible), + LeafType.ACTIVITY); + if (partition != null) { + system.endGroup(); + } + return result; + } + final String first = arg.get("FIRST" + suf, 0); + if (first == null) { + return system.getLastEntityConsulted(); + } + + return null; + } + + static LeafType getTypeIfExisting(ActivityDiagram system, Code code) { + if (system.leafExist(code)) { + final IEntity ent = system.getLeafs().get(code); + if (ent.getEntityType() == LeafType.BRANCH) { + return LeafType.BRANCH; + } + } + return LeafType.ACTIVITY; + } + + static LeafType getTypeFromString(String type, final LeafType circle) { + if (type == null) { + return LeafType.ACTIVITY; + } + if (type.equals("*")) { + return circle; + } + if (type.startsWith("=")) { + return LeafType.SYNCHRO_BAR; + } + throw new IllegalArgumentException(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkLongActivity.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkLongActivity.java index 1f2e0fe46..a47e5baac 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkLongActivity.java +++ b/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkLongActivity.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -34,114 +34,167 @@ package net.sourceforge.plantuml.activitydiagram.command; import java.util.List; -import java.util.Map; +import java.util.regex.Pattern; import net.sourceforge.plantuml.Direction; import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.UrlBuilder; +import net.sourceforge.plantuml.UrlBuilder.ModeUrl; import net.sourceforge.plantuml.activitydiagram.ActivityDiagram; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.CommandMultilines2; +import net.sourceforge.plantuml.command.MultilinesStrategy; import net.sourceforge.plantuml.command.regex.RegexConcat; import net.sourceforge.plantuml.command.regex.RegexLeaf; +import net.sourceforge.plantuml.command.regex.RegexOptional; 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.command.regex.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.GroupType; import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.LeafType; import net.sourceforge.plantuml.cucadiagram.Link; import net.sourceforge.plantuml.cucadiagram.LinkDecor; import net.sourceforge.plantuml.cucadiagram.LinkType; import net.sourceforge.plantuml.cucadiagram.Stereotype; -import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; public class CommandLinkLongActivity extends CommandMultilines2 { - public CommandLinkLongActivity(final ActivityDiagram diagram) { - super( - diagram, - getRegexConcat(), - "(?i)^\\s*([^\"]*)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?\\s*(\\<\\<.*\\>\\>)?\\s*(#\\w+)?$"); + public CommandLinkLongActivity() { + super(getRegexConcat(), MultilinesStrategy.REMOVE_STARTING_QUOTE); } - + + @Override + public String getPatternEnd() { + return "(?i)^\\s*([^\"]*)\"(?:\\s+as\\s+([\\p{L}0-9][\\p{L}0-9_.]*))?\\s*(\\<\\<.*\\>\\>)?\\s*(?:in\\s+(\"[^\"]+\"|\\S+))?\\s*(#\\w+)?$"; + } + static RegexConcat getRegexConcat() { - return new RegexConcat(new RegexLeaf("^"), - new RegexOr("FIRST", true, - new RegexLeaf("STAR", "(\\(\\*(top)?\\))"), - new RegexLeaf("CODE", "([\\p{L}0-9_.]+)"), - new RegexLeaf("BAR", "(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)"), - new RegexLeaf("QUOTED", "\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?")), - new RegexLeaf("\\s*"), - new RegexLeaf("STEREOTYPE", "(\\<\\<.*\\>\\>)?"), - new RegexLeaf("\\s*"), - new RegexLeaf("BACKCOLOR", "(#\\w+)?"), - new RegexLeaf("\\s*"), - new RegexLeaf("ARROW", "([=-]+(?:(left|right|up|down|le?|ri?|up?|do?)(?=[-=]))?[=-]*\\>)"), - new RegexLeaf("\\s*"), - new RegexLeaf("BRACKET", "(?:\\[([^\\]*]+[^\\]]*)\\])?"), - new RegexLeaf("\\s*"), - new RegexLeaf("DESC", "\"([^\"]*?)"), - new RegexLeaf("\\s*"), + return new RegexConcat(new RegexLeaf("^"), // + new RegexOptional(// + new RegexOr("FIRST", // + new RegexLeaf("STAR", "(\\(\\*(top)?\\))"), // + new RegexLeaf("CODE", "([\\p{L}0-9][\\p{L}0-9_.]*)"), // + new RegexLeaf("BAR", "(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)"), // + new RegexLeaf("QUOTED", "\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?"))), // + new RegexLeaf("\\s*"), // + new RegexLeaf("STEREOTYPE", "(\\<\\<.*\\>\\>)?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("BACKCOLOR", "(#\\w+)?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("URL", "(" + UrlBuilder.getRegexp() + ")?"), // + new RegexLeaf("ARROW", "([-=.]+(?:(left|right|up|down|le?|ri?|up?|do?)(?=[-=.]))?[-=.]*\\>)"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("BRACKET", "(?:\\[([^\\]*]+[^\\]]*)\\])?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("DESC", "\"([^\"]*?)"), // + new RegexLeaf("\\s*"), // new RegexLeaf("$")); } - public CommandExecutionResult execute(List lines) { + public CommandExecutionResult executeNow(final ActivityDiagram diagram, List lines) { StringUtils.trim(lines, false); - final Map line0 = getStartingPattern().matcher(lines.get(0).trim()); - final IEntity entity1 = CommandLinkActivity.getEntity(getSystem(), line0, true); - if (line0.get("STEREOTYPE").get(0) != null) { - entity1.setStereotype(new Stereotype(line0.get("STEREOTYPE").get(0))); + final RegexResult line0 = getStartingPattern().matcher(lines.get(0).trim()); + + final IEntity entity1 = CommandLinkActivity.getEntity(diagram, line0, true); + + if (line0.get("STEREOTYPE", 0) != null) { + entity1.setStereotype(new Stereotype(line0.get("STEREOTYPE", 0))); } - if (line0.get("BACKCOLOR").get(0)!=null) { - entity1.setSpecificBackcolor(HtmlColor.getColorIfValid(line0.get("BACKCOLOR").get(0))); + if (line0.get("BACKCOLOR", 0) != null) { + entity1.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(line0.get("BACKCOLOR", 0))); } final StringBuilder sb = new StringBuilder(); - if (StringUtils.isNotEmpty(line0.get("DESC").get(0))) { - sb.append(line0.get("DESC").get(0)); - sb.append("\\n"); + final String desc0 = line0.get("DESC", 0); + Url urlActivity = null; + if (StringUtils.isNotEmpty(desc0)) { + final UrlBuilder urlBuilder = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), ModeUrl.STRICT); + urlActivity = urlBuilder.getUrl(desc0); + if (urlActivity == null) { + sb.append(desc0); + sb.append("\\n"); + } } for (int i = 1; i < lines.size() - 1; i++) { + if (i == 1 && urlActivity == null) { + final UrlBuilder urlBuilder = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), ModeUrl.STRICT); + urlActivity = urlBuilder.getUrl(lines.get(i)); + if (urlActivity != null) { + continue; + } + } sb.append(lines.get(i)); if (i < lines.size() - 2) { sb.append("\\n"); } } - final List lineLast = StringUtils.getSplit(getEnding(), lines.get(lines.size() - 1)); + final List lineLast = StringUtils.getSplit(Pattern.compile(getPatternEnd()), + lines.get(lines.size() - 1)); if (StringUtils.isNotEmpty(lineLast.get(0))) { - if (sb.toString().endsWith("\\n") == false) { + if (sb.length() > 0 && sb.toString().endsWith("\\n") == false) { 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 Code code = Code.of(lineLast.get(1) == null ? display : lineLast.get(1)); - final Entity entity2 = getSystem().createEntity(code, display, EntityType.ACTIVITY); - if (lineLast.get(2)!=null) { + String partition = null; + if (lineLast.get(3) != null) { + partition = lineLast.get(3); + partition = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(partition); + } + if (partition != null) { + diagram.getOrCreateGroup(Code.of(partition), Display.getWithNewlines(partition), null, + GroupType.PACKAGE, null); + } + final IEntity entity2 = diagram.createLeaf(code, Display.getWithNewlines(display), LeafType.ACTIVITY); + if (partition != null) { + diagram.endGroup(); + } + if (urlActivity != null) { + entity2.addUrl(urlActivity); + } + + if (lineLast.get(2) != null) { entity2.setStereotype(new Stereotype(lineLast.get(2))); } - if (lineLast.get(3)!=null) { - entity2.setSpecificBackcolor(HtmlColor.getColorIfValid(lineLast.get(3))); + if (lineLast.get(4) != null) { + entity2.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(lineLast.get(4))); } if (entity1 == null || entity2 == null) { return CommandExecutionResult.error("No such entity"); } - final String arrow = StringUtils.manageArrowForCuca(line0.get("ARROW").get(0)); + final String arrow = StringUtils.manageArrowForCuca(line0.get("ARROW", 0)); final int lenght = arrow.length() - 1; - final String linkLabel = line0.get("BRACKET").get(0); + final Display linkLabel = Display.getWithNewlines(line0.get("BRACKET", 0)); - Link link = new Link(entity1, entity2, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), linkLabel, lenght); - final Direction direction = StringUtils.getArrowDirection(line0.get("ARROW").get(0)); + LinkType type = new LinkType(LinkDecor.ARROW, LinkDecor.NONE); + if (line0.get("ARROW", 0).contains(".")) { + type = type.getDotted(); + } + Link link = new Link(entity1, entity2, type, linkLabel, lenght); + final Direction direction = StringUtils.getArrowDirection(line0.get("ARROW", 0)); if (direction == Direction.LEFT || direction == Direction.UP) { link = link.getInv(); } - getSystem().addLink(link); + if (line0.get("URL", 0) != null) { + final UrlBuilder urlBuilder = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), ModeUrl.STRICT); + final Url urlLink = urlBuilder.getUrl(line0.get("URL", 0)); + link.setUrl(urlLink); + } + + diagram.addLink(link); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkLongActivity2.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkLongActivity2.java new file mode 100644 index 000000000..cd5e27b9f --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram/command/CommandLinkLongActivity2.java @@ -0,0 +1,219 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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 java.util.regex.Pattern; + +import net.sourceforge.plantuml.Direction; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.UrlBuilder; +import net.sourceforge.plantuml.UrlBuilder.ModeUrl; +import net.sourceforge.plantuml.activitydiagram.ActivityDiagram; +import net.sourceforge.plantuml.classdiagram.command.CommandLinkClass; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.CommandMultilines2; +import net.sourceforge.plantuml.command.MultilinesStrategy; +import net.sourceforge.plantuml.command.regex.RegexConcat; +import net.sourceforge.plantuml.command.regex.RegexLeaf; +import net.sourceforge.plantuml.command.regex.RegexOptional; +import net.sourceforge.plantuml.command.regex.RegexOr; +import net.sourceforge.plantuml.command.regex.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.GroupType; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.LeafType; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.cucadiagram.LinkDecor; +import net.sourceforge.plantuml.cucadiagram.LinkType; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; + +public class CommandLinkLongActivity2 extends CommandMultilines2 { + + public CommandLinkLongActivity2() { + super(getRegexConcat(), MultilinesStrategy.REMOVE_STARTING_QUOTE); + } + + @Override + public String getPatternEnd() { + return "(?i)^\\s*([^\"]*)\"(?:\\s+as\\s+([\\p{L}0-9][\\p{L}0-9_.]*))?\\s*(\\<\\<.*\\>\\>)?\\s*(?:in\\s+(\"[^\"]+\"|\\S+))?\\s*(#\\w+)?$"; + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexOptional(// + new RegexOr("FIRST", // + new RegexLeaf("STAR", "(\\(\\*(top)?\\))"), // + new RegexLeaf("CODE", "([\\p{L}0-9][\\p{L}0-9_.]*)"), // + new RegexLeaf("BAR", "(?:==+)\\s*([\\p{L}0-9_.]+)\\s*(?:==+)"), // + new RegexLeaf("QUOTED", "\"([^\"]+)\"(?:\\s+as\\s+([\\p{L}0-9_.]+))?"))), // + new RegexLeaf("\\s*"), // + new RegexLeaf("STEREOTYPE", "(\\<\\<.*\\>\\>)?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("BACKCOLOR", "(#\\w+)?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("URL", "(" + UrlBuilder.getRegexp() + ")?"), // + + new RegexLeaf("ARROW_BODY1", "([-.]+)"), // + new RegexLeaf("ARROW_STYLE1", + "(?:\\[((?:#\\w+|dotted|dashed|bold|hidden)(?:,#\\w+|,dotted|,dashed|,bold|,hidden)*)\\])?"), // + new RegexLeaf("ARROW_DIRECTION", "(\\*|left|right|up|down|le?|ri?|up?|do?)?"), // + new RegexLeaf("ARROW_STYLE2", + "(?:\\[((?:#\\w+|dotted|dashed|bold|hidden)(?:,#\\w+|,dotted|,dashed|,bold|,hidden)*)\\])?"), // + new RegexLeaf("ARROW_BODY2", "([-.]*)\\>"), // + + // new RegexLeaf("ARROW", "([-=.]+(?:(left|right|up|down|le?|ri?|up?|do?)(?=[-=.]))?[-=.]*\\>)"), // + + new RegexLeaf("\\s*"), // + new RegexLeaf("BRACKET", "(?:\\[([^\\]*]+[^\\]]*)\\])?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("DESC", "\"([^\"]*?)"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("$")); + } + + public CommandExecutionResult executeNow(final ActivityDiagram diagram, List lines) { + StringUtils.trim(lines, false); + final RegexResult line0 = getStartingPattern().matcher(lines.get(0).trim()); + + final IEntity entity1 = CommandLinkActivity.getEntity(diagram, line0, true); + + if (line0.get("STEREOTYPE", 0) != null) { + entity1.setStereotype(new Stereotype(line0.get("STEREOTYPE", 0))); + } + if (line0.get("BACKCOLOR", 0) != null) { + entity1.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(line0.get("BACKCOLOR", 0))); + } + final StringBuilder sb = new StringBuilder(); + + final String desc0 = line0.get("DESC", 0); + Url urlActivity = null; + if (StringUtils.isNotEmpty(desc0)) { + final UrlBuilder urlBuilder = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), ModeUrl.STRICT); + urlActivity = urlBuilder.getUrl(desc0); + if (urlActivity == null) { + sb.append(desc0); + sb.append("\\n"); + } + } + for (int i = 1; i < lines.size() - 1; i++) { + if (i == 1 && urlActivity == null) { + final UrlBuilder urlBuilder = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), ModeUrl.STRICT); + urlActivity = urlBuilder.getUrl(lines.get(i)); + if (urlActivity != null) { + continue; + } + } + sb.append(lines.get(i)); + if (i < lines.size() - 2) { + sb.append("\\n"); + } + } + + final List lineLast = StringUtils.getSplit(Pattern.compile(getPatternEnd()), + lines.get(lines.size() - 1)); + if (StringUtils.isNotEmpty(lineLast.get(0))) { + if (sb.length() > 0 && sb.toString().endsWith("\\n") == false) { + sb.append("\\n"); + } + sb.append(lineLast.get(0)); + } + + final String display = sb.toString(); + final Code code = Code.of(lineLast.get(1) == null ? display : lineLast.get(1)); + + String partition = null; + if (lineLast.get(3) != null) { + partition = lineLast.get(3); + partition = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(partition); + } + if (partition != null) { + diagram.getOrCreateGroup(Code.of(partition), Display.getWithNewlines(partition), null, GroupType.PACKAGE, + null); + } + final IEntity entity2 = diagram.createLeaf(code, Display.getWithNewlines(display), LeafType.ACTIVITY); + if (partition != null) { + diagram.endGroup(); + } + if (urlActivity != null) { + entity2.addUrl(urlActivity); + } + + if (lineLast.get(2) != null) { + entity2.setStereotype(new Stereotype(lineLast.get(2))); + } + if (lineLast.get(4) != null) { + entity2.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(lineLast.get(4))); + } + + if (entity1 == null || entity2 == null) { + return CommandExecutionResult.error("No such entity"); + } + + final String arrowBody1 = CommandLinkClass.notNull(line0.get("ARROW_BODY1", 0)); + final String arrowBody2 = CommandLinkClass.notNull(line0.get("ARROW_BODY2", 0)); + final String arrowDirection = CommandLinkClass.notNull(line0.get("ARROW_DIRECTION", 0)); + + final String arrow = StringUtils.manageArrowForCuca(arrowBody1 + arrowDirection + arrowBody2 + ">"); + + final int lenght = arrow.length() - 1; + + final Display linkLabel = Display.getWithNewlines(line0.get("BRACKET", 0)); + + LinkType type = new LinkType(LinkDecor.ARROW, LinkDecor.NONE); + if (arrow.contains(".")) { + type = type.getDotted(); + } + Link link = new Link(entity1, entity2, type, linkLabel, lenght); + final Direction direction = StringUtils.getArrowDirection(arrowBody1 + arrowDirection + arrowBody2 + ">"); + if (direction == Direction.LEFT || direction == Direction.UP) { + link = link.getInv(); + } + + if (line0.get("URL", 0) != null) { + final UrlBuilder urlBuilder = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), ModeUrl.STRICT); + final Url urlLink = urlBuilder.getUrl(line0.get("URL", 0)); + link.setUrl(urlLink); + } + + CommandLinkClass.applyStyle(line0.getLazzy("ARROW_STYLE", 0), link); + diagram.addLink(link); + + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandMultilinesNoteActivity.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandMultilinesNoteActivity.java deleted file mode 100644 index 9ac8153d3..000000000 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandMultilinesNoteActivity.java +++ /dev/null @@ -1,93 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 5751 $ - * - */ -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 { - - public CommandMultilinesNoteActivity(final ActivityDiagram system) { - super(system, "(?i)^note\\s+(right|left|top|bottom)$", "(?i)^end ?note$"); - } - - public final CommandExecutionResult execute(List lines) { - - final List line0 = StringUtils.getSplit(getStartingPattern(), lines.get(0).trim()); - final String pos = line0.get(0); - - IEntity activity = getSystem().getLastEntityConsulted(); - if (activity == null) { - activity = getSystem().getStart(); - } - - final List strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1)); - final String s = StringUtils.getMergedLines(strings); - - final Entity note = getSystem().createEntity("GMN" + UniqueSequence.getValue(), s, EntityType.NOTE); - - 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(); - } - -} diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandMultilinesNoteActivityLink.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandMultilinesNoteActivityLink.java deleted file mode 100644 index 151cdf976..000000000 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandMultilinesNoteActivityLink.java +++ /dev/null @@ -1,64 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6939 $ - * - */ -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.command.Position; -import net.sourceforge.plantuml.cucadiagram.Link; - -public class CommandMultilinesNoteActivityLink extends CommandMultilines { - - public CommandMultilinesNoteActivityLink(final ActivityDiagram system) { - super(system, "(?i)^note\\s+on\\s+link$", "(?i)^end ?note$"); - } - - public final CommandExecutionResult execute(List lines) { - - final List strings = StringUtils.removeEmptyColumns(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.addNote(strings, Position.BOTTOM); - return CommandExecutionResult.ok(); - } - -} diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandNoteActivity.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandNoteActivity.java deleted file mode 100644 index 4c623a1e9..000000000 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandNoteActivity.java +++ /dev/null @@ -1,85 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 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 { - - public CommandNoteActivity(ActivityDiagram diagram) { - super(diagram, "(?i)^note\\s+(right|left|top|bottom)\\s*:\\s*(.*)$"); - } - - @Override - protected CommandExecutionResult executeArg(List 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(); - - } - -} diff --git a/src/net/sourceforge/plantuml/activitydiagram/command/CommandPartition.java b/src/net/sourceforge/plantuml/activitydiagram/command/CommandPartition.java index 0cee587aa..f521839ab 100644 --- a/src/net/sourceforge/plantuml/activitydiagram/command/CommandPartition.java +++ b/src/net/sourceforge/plantuml/activitydiagram/command/CommandPartition.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5983 $ + * Revision $Revision: 10778 $ * */ package net.sourceforge.plantuml.activitydiagram.command; @@ -39,25 +39,28 @@ 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.Code; +import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.cucadiagram.GroupType; -import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.IGroup; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; public class CommandPartition extends SingleLineCommand { - public CommandPartition(ActivityDiagram diagram) { - super(diagram, "(?i)^partition\\s+(\"[^\"]+\"|\\S+)\\s*(#[0-9a-fA-F]{6}|#?\\w+)?\\s*\\{?$"); + public CommandPartition() { + super("(?i)^partition\\s+(\"[^\"]+\"|\\S+)\\s*(#[0-9a-fA-F]{6}|#?\\w+)?\\s*\\{?$"); } @Override - protected CommandExecutionResult executeArg(List 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); + protected CommandExecutionResult executeArg(ActivityDiagram diagram, List arg) { + final Code code = Code.of(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(0))); + final IGroup currentPackage = diagram.getCurrentGroup(); + final IEntity p = diagram.getOrCreateGroup(code, Display.getWithNewlines(code), null, GroupType.PACKAGE, + currentPackage); final String color = arg.get(1); if (color != null) { - p.setBackColor(HtmlColor.getColorIfValid(color)); + p.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(color)); } return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/activitydiagram2/ActivityDiagram2.java b/src/net/sourceforge/plantuml/activitydiagram2/ActivityDiagram2.java deleted file mode 100644 index 29f15fcf7..000000000 --- a/src/net/sourceforge/plantuml/activitydiagram2/ActivityDiagram2.java +++ /dev/null @@ -1,263 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 5721 $ - * - */ -package net.sourceforge.plantuml.activitydiagram2; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; - -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.IEntity; -import net.sourceforge.plantuml.cucadiagram.Link; -import net.sourceforge.plantuml.cucadiagram.LinkDecor; -import net.sourceforge.plantuml.cucadiagram.LinkType; -import net.sourceforge.plantuml.cucadiagram.dot.DotMaker; - -public class ActivityDiagram2 extends CucaDiagram { - - private Collection waitings = new LinkedHashSet(); - private ConditionalContext2 currentContext; - // private int futureLength = 2; - private String futureLabel = null; - - private final Collection pendingLabels = new HashSet(); - private final Map labels = new HashMap(); - - final protected List getDotStrings() { - return Arrays.asList("nodesep=.20;", "ranksep=0.4;", "edge [fontsize=11,labelfontsize=11];", - "node [fontsize=11];"); - } - - public String getDescription() { - return "(" + entities().size() + " activities)"; - } - - @Override - public UmlDiagramType getUmlDiagramType() { - return UmlDiagramType.ACTIVITY; - } - - public boolean isReachable() { - return waitings.size() > 0; - } - - public void newActivity(String display, Direction direction) { - if (waitings.size() == 0) { - throw new IllegalStateException(); - } - final Entity act = createEntity(getAutoCode(), display, EntityType.ACTIVITY); - afterAdd(act, direction); - - } - - private final Map bars = new HashMap(); - - public void bar(String bar) { - final Direction direction = Direction.DOWN; - if (bars.containsKey(bar)) { - final IEntity existingBar = bars.get(bar); - for (Iterator it = waitings.iterator(); it.hasNext();) { - final IEntity w = it.next(); - if (w.getType() == EntityType.SYNCHRO_BAR) { - it.remove(); - } - } - afterAdd(existingBar, direction); - return; - } - - if (waitings.size() == 0) { - // throw new IllegalStateException(bar); - } - label(bar); - final Entity act = createEntity(getAutoCode(), bar, EntityType.SYNCHRO_BAR); - bars.put(bar, act); - afterAdd(act, direction); - } - - private void afterAdd(final IEntity dest, Direction direction) { - for (IEntity last : this.waitings) { - // System.err.println("last=" + last); - // System.err.println("act=" + act); - final Link link; - if (direction == Direction.DOWN) { - link = new Link(last, dest, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), futureLabel, 2); - } else if (direction == Direction.RIGHT) { - link = new Link(last, dest, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), futureLabel, 1); - } else if (direction == Direction.LEFT) { - link = new Link(dest, last, new LinkType(LinkDecor.NONE, LinkDecor.ARROW), futureLabel, 1); - } else if (direction == Direction.UP) { - link = new Link(dest, last, new LinkType(LinkDecor.NONE, LinkDecor.ARROW), futureLabel, 2); - } else { - throw new UnsupportedOperationException(); - } - this.addLink(link); - futureLabel = null; - } - - for (String p : pendingLabels) { - labels.put(p, dest); - } - pendingLabels.clear(); - - this.waitings.clear(); - this.waitings.add(dest); - // this.futureLength = 2; - } - - public IEntity getLastEntityConsulted() { - if (waitings.size() == 1) { - return waitings.iterator().next(); - } - return null; - } - - private String getAutoCode() { - return "ac" + UniqueSequence.getValue(); - } - - public void start() { - if (waitings.size() != 0) { - throw new IllegalStateException(); - } - this.waitings.add(createEntity("start", "start", EntityType.CIRCLE_START)); - } - - public void startIf(String test, String when) { - final IEntity br = createEntity(getAutoCode(), test, EntityType.BRANCH); - if (DotMaker.MODE_BRANCHE_CLUSTER) { - test = null; - } - currentContext = new ConditionalContext2(currentContext, br, Direction.DOWN, when); - for (IEntity last : this.waitings) { - // if (test == null) { - // // this.addLink(new Link(last, br, new LinkType(LinkDecor.ARROW, - // // LinkDecor.NONE), test, futureLength)); - // throw new IllegalArgumentException(); - // } else { - this.addLink(new Link(last, br, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), this.futureLabel, 2, null, - test, getLabeldistance(), getLabelangle())); - // } - test = null; - } - this.waitings.clear(); - this.waitings.add(br); - // this.futureLength = 2; - this.futureLabel = when; - } - - // public Collection getWaitings() { - // return this.waitings; - // } - - public void endif() { - // final boolean hasElse = currentContext.isHasElse(); - // System.err.println("CALL endif hasElse " + hasElse); - this.waitings.addAll(currentContext.getPendings()); - currentContext = currentContext.getParent(); - // if (currentContext == null) { - // System.err.println("after endif " + currentContext); - // } else { - // System.err.println("after endif " + currentContext.getPendings()); - // } - } - - public void else2(String when) { - this.currentContext.executeElse(this.waitings); - this.waitings.clear(); - this.waitings.add(currentContext.getBranch()); - this.futureLabel = when; - } - - public void label(String label) { - pendingLabels.add(label); - for (final Iterator it = pendingLinks.iterator(); it.hasNext();) { - final PendingLink pending = it.next(); - if (pending.getGotoLabel().equals(label)) { - if (pending.getLinkLabel() != null) { - this.futureLabel = pending.getLinkLabel(); - } - final List olds = new ArrayList(waitings); - waitings.clear(); - waitings.add(pending.getEntityFrom()); - waitings.addAll(olds); - it.remove(); - } - } - } - - private final Collection pendingLinks = new ArrayList(); - - public void callGoto(String gotoLabel) { - // System.err.println("CALL goto " + gotoLabel); - final IEntity dest = labels.get(gotoLabel); - for (IEntity last : this.waitings) { - if (dest == null) { - this.pendingLinks.add(new PendingLink(last, gotoLabel, this.futureLabel)); - } else { - // final Link link = new Link(last, dest, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), - // this.futureLabel, - // this.futureLength); - final Link link = new Link(last, dest, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), this.futureLabel, - 2); - link.setConstraint(false); - this.addLink(link); - } - } - this.futureLabel = null; - // System.err.println("Avant fin goto, waitings=" + waitings); - this.waitings.clear(); - // currentContext.clearPendingsButFirst(); - } - - public void end(Direction direction) { - if (waitings.size() == 0) { - throw new IllegalStateException(); - } - final IEntity act = getOrCreateEntity("end", EntityType.CIRCLE_END); - afterAdd(act, direction); - } - -} diff --git a/src/net/sourceforge/plantuml/activitydiagram2/ActivityDiagramFactory2.java b/src/net/sourceforge/plantuml/activitydiagram2/ActivityDiagramFactory2.java deleted file mode 100644 index 0200ba310..000000000 --- a/src/net/sourceforge/plantuml/activitydiagram2/ActivityDiagramFactory2.java +++ /dev/null @@ -1,90 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 5847 $ - * - */ -package net.sourceforge.plantuml.activitydiagram2; - -import net.sourceforge.plantuml.activitydiagram2.command.CommandBar2; -import net.sourceforge.plantuml.activitydiagram2.command.CommandElse2; -import net.sourceforge.plantuml.activitydiagram2.command.CommandEnd2; -import net.sourceforge.plantuml.activitydiagram2.command.CommandEndif2; -import net.sourceforge.plantuml.activitydiagram2.command.CommandGoto2; -import net.sourceforge.plantuml.activitydiagram2.command.CommandIf2; -import net.sourceforge.plantuml.activitydiagram2.command.CommandLabel2; -import net.sourceforge.plantuml.activitydiagram2.command.CommandMultilinesNoteActivity2; -import net.sourceforge.plantuml.activitydiagram2.command.CommandNewActivity2; -import net.sourceforge.plantuml.activitydiagram2.command.CommandNewMultilinesActivity2; -import net.sourceforge.plantuml.activitydiagram2.command.CommandStart2; -import net.sourceforge.plantuml.command.AbstractUmlSystemCommandFactory; - -public class ActivityDiagramFactory2 extends AbstractUmlSystemCommandFactory { - - private ActivityDiagram2 system; - - public ActivityDiagram2 getSystem() { - return system; - } - - @Override - protected void initCommands() { - system = new ActivityDiagram2(); - - addCommonCommands(system); - addCommand(new CommandEnd2(system)); - addCommand(new CommandStart2(system)); - addCommand(new CommandNewActivity2(system)); - addCommand(new CommandIf2(system)); - addCommand(new CommandEndif2(system)); - addCommand(new CommandElse2(system)); - addCommand(new CommandLabel2(system)); - addCommand(new CommandGoto2(system)); - addCommand(new CommandBar2(system)); - -// addCommand(new CommandLinkActivity(system)); -// addCommand(new CommandPartition(system)); -// addCommand(new CommandEndPartition(system)); -// addCommand(new CommandLinkLongActivity(system)); -// -// addCommand(new CommandNoteActivity(system)); - addCommand(new CommandMultilinesNoteActivity2(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)); - addCommand(new CommandNewMultilinesActivity2(system)); - } - -} diff --git a/src/net/sourceforge/plantuml/activitydiagram2/ConditionalContext2.java b/src/net/sourceforge/plantuml/activitydiagram2/ConditionalContext2.java deleted file mode 100644 index 7fd51bd90..000000000 --- a/src/net/sourceforge/plantuml/activitydiagram2/ConditionalContext2.java +++ /dev/null @@ -1,114 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 3828 $ - * - */ -package net.sourceforge.plantuml.activitydiagram2; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.LinkedHashSet; - -import net.sourceforge.plantuml.Direction; -import net.sourceforge.plantuml.cucadiagram.EntityType; -import net.sourceforge.plantuml.cucadiagram.IEntity; - -public class ConditionalContext2 { - - private final Collection pendings = new LinkedHashSet(); - private final IEntity branch; - private final Direction direction; - private final ConditionalContext2 parent; - private final String when; - - public ConditionalContext2(ConditionalContext2 parent, IEntity branch, Direction direction, String when) { - if (branch.getType() != EntityType.BRANCH) { - throw new IllegalArgumentException(); - } - this.branch = branch; - this.direction = direction; - this.parent = parent; - this.when = when; - this.pendings.add(branch); - } - - public Direction getDirection() { - return direction; - } - - public final ConditionalContext2 getParent() { - return parent; - } - - public final Collection getPendings() { - return Collections.unmodifiableCollection(pendings); - } - - public final IEntity getBranch() { - return branch; - } - - public void clearPendingsButFirst() { - //System.err.println("ConditionalContext2::clearPendingsButFirst"); - this.pendings.clear(); - pendings.add(branch); - } - - private boolean hasElse = false; - - public void executeElse(Collection pendingsToAdd) { - if (this.hasElse) { - throw new IllegalStateException(); - } - this.hasElse = true; - //System.err.println("pend=" + pendings); - if (pendings.size() == 0) { - throw new IllegalStateException(); - } - final Iterator it = pendings.iterator(); - final IEntity toRemove = it.next(); - if (toRemove.getType() != EntityType.BRANCH) { - throw new IllegalStateException(); - } - it.remove(); - this.pendings.addAll(pendingsToAdd); - } - - public boolean isHasElse() { - return hasElse; - } - - public final String getWhen() { - return when; - } - -} diff --git a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandIf2.java b/src/net/sourceforge/plantuml/activitydiagram2/command/CommandIf2.java deleted file mode 100644 index 895af0e45..000000000 --- a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandIf2.java +++ /dev/null @@ -1,90 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 4762 $ - * - */ -package net.sourceforge.plantuml.activitydiagram2.command; - -import java.util.Map; - -import net.sourceforge.plantuml.activitydiagram2.ActivityDiagram2; -import net.sourceforge.plantuml.command.CommandExecutionResult; -import net.sourceforge.plantuml.command.SingleLineCommand2; -import net.sourceforge.plantuml.command.regex.RegexConcat; -import net.sourceforge.plantuml.command.regex.RegexLeaf; -import net.sourceforge.plantuml.command.regex.RegexPartialMatch; - -public class CommandIf2 extends SingleLineCommand2 { - - public CommandIf2(ActivityDiagram2 diagram) { - super(diagram, getRegexConcat()); - } - - static RegexConcat getRegexConcat() { - return new RegexConcat(new RegexLeaf("^"), - new RegexLeaf("if"), - new RegexLeaf("\\s*"), - new RegexLeaf("TEST", "[\"(](.+)[\")]"), - new RegexLeaf("\\s*"), - new RegexLeaf("WHEN", "(?:then\\s*(?:when\\s+(.*))?)?"), - new RegexLeaf("$")); - } - - - @Override - protected CommandExecutionResult executeArg(Map arg) { -// - getSystem().startIf(arg.get("TEST").get(0), arg.get("WHEN").get(0)); -// -// int lenght = 2; -// -// if (arg.get("ARROW").get(0) != null) { -// final String arrow = StringUtils.manageArrowForCuca(arg.get("ARROW").get(0)); -// lenght = arrow.length() - 1; -// } -// -// final IEntity branch = getSystem().getCurrentContext().getBranch(); -// -// Link link = new Link(entity1, branch, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), arg.get("BRACKET").get(0), -// lenght, null, arg.get("IF").get(0), getSystem().getLabeldistance(), getSystem().getLabelangle()); -// if (arg.get("ARROW").get(0) != null) { -// final Direction direction = StringUtils.getArrowDirection(arg.get("ARROW").get(0)); -// if (direction == Direction.LEFT || direction == Direction.UP) { -// link = link.getInv(); -// } -// } -// -// getSystem().addLink(link); - - return CommandExecutionResult.ok(); - } - -} diff --git a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandMultilinesNoteActivity2.java b/src/net/sourceforge/plantuml/activitydiagram2/command/CommandMultilinesNoteActivity2.java deleted file mode 100644 index 6e732f59a..000000000 --- a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandMultilinesNoteActivity2.java +++ /dev/null @@ -1,94 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 5751 $ - * - */ -package net.sourceforge.plantuml.activitydiagram2.command; - -import java.util.List; - -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.UniqueSequence; -import net.sourceforge.plantuml.activitydiagram2.ActivityDiagram2; -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 CommandMultilinesNoteActivity2 extends CommandMultilines { - - public CommandMultilinesNoteActivity2(final ActivityDiagram2 system) { - super(system, "(?i)^note\\s+(right|left|top|bottom)$", "(?i)^end ?note$"); - } - - public final CommandExecutionResult execute(List lines) { - - final List line0 = StringUtils.getSplit(getStartingPattern(), lines.get(0).trim()); - final String pos = line0.get(0); - - IEntity activity = getSystem().getLastEntityConsulted(); - if (activity == null) { - // activity = getSystem().getStart(); - return CommandExecutionResult.error("No activity defined"); - } - - final List strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1)); - final String s = StringUtils.getMergedLines(strings); - - final Entity note = getSystem().createEntity("GMN" + UniqueSequence.getValue(), s, EntityType.NOTE); - - 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(); - } - -} diff --git a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandNewActivity2.java b/src/net/sourceforge/plantuml/activitydiagram2/command/CommandNewActivity2.java deleted file mode 100644 index 975b6648c..000000000 --- a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandNewActivity2.java +++ /dev/null @@ -1,64 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 4762 $ - * - */ -package net.sourceforge.plantuml.activitydiagram2.command; - -import java.util.List; - -import net.sourceforge.plantuml.Direction; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.activitydiagram2.ActivityDiagram2; -import net.sourceforge.plantuml.command.CommandExecutionResult; -import net.sourceforge.plantuml.command.SingleLineCommand; - -public class CommandNewActivity2 extends SingleLineCommand { - - public CommandNewActivity2(ActivityDiagram2 diagram) { - super(diagram, "(?i)^\\s*([-*<>^])\\s*([^\"\\s].*|\\s*\"[^\"\\s].*\")$"); - } - - @Override - protected CommandExecutionResult executeArg(List arg) { - if (getSystem().entities().size() == 0) { - return CommandExecutionResult.error("Missing start keyword"); - } - - if (getSystem().isReachable() == false) { - return CommandExecutionResult.error("Unreachable statement"); - } - - getSystem().newActivity(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(1).trim()), - Direction.fromChar(arg.get(0).charAt(0))); - return CommandExecutionResult.ok(); - } -} diff --git a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandNewMultilinesActivity2.java b/src/net/sourceforge/plantuml/activitydiagram2/command/CommandNewMultilinesActivity2.java deleted file mode 100644 index d28819668..000000000 --- a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandNewMultilinesActivity2.java +++ /dev/null @@ -1,72 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 5751 $ - * - */ -package net.sourceforge.plantuml.activitydiagram2.command; - -import java.util.List; - -import net.sourceforge.plantuml.Direction; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.activitydiagram2.ActivityDiagram2; -import net.sourceforge.plantuml.command.CommandExecutionResult; -import net.sourceforge.plantuml.command.CommandMultilines; - -public class CommandNewMultilinesActivity2 extends CommandMultilines { - - public CommandNewMultilinesActivity2(final ActivityDiagram2 system) { - super(system, "(?i)^\\s*[-*<>^]\\s*\"\\s*.*$", "(?i)^.*\\s*\"\\s*$"); - } - - public final CommandExecutionResult execute(List lines) { - if (getSystem().entities().size() == 0) { - return CommandExecutionResult.error("Missing start keyword"); - } - - if (getSystem().isReachable() == false) { - return CommandExecutionResult.error("Unreachable statement"); - } - String s = StringUtils.getMergedLines(lines); - s = s.trim(); - assert s.startsWith("-") || s.startsWith("*") || s.startsWith("<") || s.startsWith(">") || s.startsWith("^"); - final Direction direction = Direction.fromChar(s.charAt(0)); - s = s.substring(1); - s = s.trim(); - assert s.startsWith("\""); - assert s.endsWith("\""); - s = s.substring(1, s.length() - 1); - - getSystem().newActivity(s, direction); - return CommandExecutionResult.ok(); - } - -} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ActivityDiagram3.java b/src/net/sourceforge/plantuml/activitydiagram3/ActivityDiagram3.java new file mode 100644 index 000000000..0d6afe29c --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ActivityDiagram3.java @@ -0,0 +1,411 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 9786 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3; + +import java.awt.geom.Dimension2D; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.OutputStream; +import java.util.List; +import java.util.Set; + +import net.sourceforge.plantuml.CMapData; +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.Scale; +import net.sourceforge.plantuml.UmlDiagram; +import net.sourceforge.plantuml.UmlDiagramType; +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.activitydiagram3.ftile.BoxStyle; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlanes; +import net.sourceforge.plantuml.api.ImageDataComplex; +import net.sourceforge.plantuml.api.ImageDataSimple; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.core.DiagramDescription; +import net.sourceforge.plantuml.core.DiagramDescriptionImpl; +import net.sourceforge.plantuml.core.ImageData; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockCompressed; +import net.sourceforge.plantuml.graphic.TextBlockRecentred; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.sequencediagram.NotePosition; +import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.svek.DecorateTextBlock; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d; + +public class ActivityDiagram3 extends UmlDiagram { + + enum SwimlaneStrategy { + SWIMLANE_FORBIDDEN, SWIMLANE_ALLOWED; + } + + private SwimlaneStrategy swimlaneStrategy; + + private final Swimlanes swinlanes = new Swimlanes(getSkinParam()); + + private void manageSwimlaneStrategy() { + if (swimlaneStrategy == null) { + swimlaneStrategy = SwimlaneStrategy.SWIMLANE_FORBIDDEN; + } + } + + public CommandExecutionResult swimlane(String name, HtmlColor color, Display label) { + if (swimlaneStrategy == null) { + swimlaneStrategy = SwimlaneStrategy.SWIMLANE_ALLOWED; + } + if (swimlaneStrategy == SwimlaneStrategy.SWIMLANE_FORBIDDEN) { + return CommandExecutionResult.error("This swimlane must be defined at the start of the diagram."); + } + + swinlanes.swimlane(name, color, label); + return CommandExecutionResult.ok(); + } + + private void setCurrent(Instruction ins) { + swinlanes.setCurrent(ins); + } + + private Instruction current() { + return swinlanes.getCurrent(); + } + + private LinkRendering nextLinkRenderer() { + return swinlanes.nextLinkRenderer(); + } + + public void addActivity(Display activity, HtmlColor color, BoxStyle style) { + manageSwimlaneStrategy(); + current() + .add(new InstructionSimple(activity, color, nextLinkRenderer(), swinlanes.getCurrentSwimlane(), style)); + setNextLinkRendererInternal(null); + manageHasUrl(activity); + } + + public void start() { + manageSwimlaneStrategy(); + current().add(new InstructionStart(swinlanes.getCurrentSwimlane())); + } + + public void stop() { + manageSwimlaneStrategy(); + current().add(new InstructionStop(swinlanes.getCurrentSwimlane())); + } + + public DiagramDescription getDescription() { + return new DiagramDescriptionImpl("activity3", getClass()); + } + + @Override + public UmlDiagramType getUmlDiagramType() { + return UmlDiagramType.ACTIVITY; + } + + protected ImageData exportDiagramInternal(OutputStream os, int index, FileFormatOption fileFormatOption, + List flashcodes) throws IOException { + // BUG42 + // TextBlock result = swinlanes; + TextBlock result = new TextBlockCompressed(swinlanes); + result = new TextBlockRecentred(result); + result = addTitle(result); + result = addHeaderAndFooter(result); + final ISkinParam skinParam = getSkinParam(); + final Dimension2D dim = TextBlockUtils.getMinMax(result).getDimension(); + final double margin = 10; + final double dpiFactor = getDpiFactor(fileFormatOption, Dimension2DDouble.delta(dim, 2 * margin, 0)); + + final UGraphic ug = TextBlockUtils.getPrinted(result, fileFormatOption, skinParam.getColorMapper(), dpiFactor, + getSkinParam().getBackgroundColor(), margin); + + ug.writeImage(os, fileFormatOption.isWithMetadata() ? getMetadata() : null, getDpi(fileFormatOption)); + + if (ug instanceof UGraphicG2d) { + final Set urls = ((UGraphicG2d) ug).getAllUrlsEncountered(); + if (urls.size() > 0) { + final CMapData cmap = CMapData.cmapString(urls, dpiFactor); + return new ImageDataComplex(dim, cmap, getWarningOrError()); + } + } + + return new ImageDataSimple(dim); + } + + private final double getDpiFactor(FileFormatOption fileFormatOption, final Dimension2D dim) { + final double dpiFactor; + final Scale scale = getScale(); + if (scale == null) { + dpiFactor = getDpiFactor(fileFormatOption); + } else { + dpiFactor = scale.getScale(dim.getWidth(), dim.getHeight()); + } + return dpiFactor; + } + + private TextBlock addTitle(TextBlock original) { + final Display title = getTitle(); + if (title == null) { + return original; + } + final TextBlock text = TextBlockUtils.create(title, new FontConfiguration(getFont(FontParam.TITLE), + getFontColor(FontParam.TITLE, null)), HorizontalAlignment.CENTER, getSkinParam()); + + return new DecorateTextBlock(original, text, HorizontalAlignment.CENTER); + } + + private TextBlock addHeaderAndFooter(TextBlock original) { + final Display footer = getFooter(); + final Display header = getHeader(); + if (footer == null && header == null) { + return original; + } + final TextBlock textFooter = footer == null ? null : TextBlockUtils.create(footer, new FontConfiguration( + getFont(FontParam.FOOTER), getFontColor(FontParam.FOOTER, null)), getFooterAlignment(), getSkinParam()); + final TextBlock textHeader = header == null ? null : TextBlockUtils.create(header, new FontConfiguration( + getFont(FontParam.HEADER), getFontColor(FontParam.HEADER, null)), getHeaderAlignment(), getSkinParam()); + + return new DecorateTextBlock(original, textHeader, getHeaderAlignment(), textFooter, getFooterAlignment()); + } + + private final UFont getFont(FontParam fontParam) { + final ISkinParam skinParam = getSkinParam(); + return skinParam.getFont(fontParam, null); + } + + private final HtmlColor getFontColor(FontParam fontParam, String stereo) { + final ISkinParam skinParam = getSkinParam(); + return skinParam.getFontHtmlColor(fontParam, stereo); + } + + public void fork() { + final InstructionFork instructionFork = new InstructionFork(current()); + current().add(instructionFork); + setCurrent(instructionFork); + } + + public CommandExecutionResult forkAgain() { + if (current() instanceof InstructionFork) { + ((InstructionFork) current()).forkAgain(); + return CommandExecutionResult.ok(); + } + return CommandExecutionResult.error("Cannot find fork"); + } + + public CommandExecutionResult endFork() { + if (current() instanceof InstructionFork) { + setCurrent(((InstructionFork) current()).getParent()); + return CommandExecutionResult.ok(); + } + return CommandExecutionResult.error("Cannot find fork"); + } + + public void split() { + final InstructionSplit instructionSplit = new InstructionSplit(current()); + current().add(instructionSplit); + setCurrent(instructionSplit); + } + + public CommandExecutionResult splitAgain() { + if (current() instanceof InstructionSplit) { + ((InstructionSplit) current()).splitAgain(); + return CommandExecutionResult.ok(); + } + return CommandExecutionResult.error("Cannot find split"); + } + + public CommandExecutionResult endSplit() { + if (current() instanceof InstructionSplit) { + setCurrent(((InstructionSplit) current()).getParent()); + return CommandExecutionResult.ok(); + } + return CommandExecutionResult.error("Cannot find split"); + } + + public void startIf(Display test, Display whenThen) { + manageSwimlaneStrategy(); + final InstructionIf1 instructionIf = new InstructionIf1(swinlanes.getCurrentSwimlane(), current(), test, + whenThen, nextLinkRenderer()); + current().add(instructionIf); + setCurrent(instructionIf); + } + + public CommandExecutionResult elseIf(Display test, Display whenThen) { + if (current() instanceof InstructionIf1) { + ((InstructionIf1) current()).elseIf(test, whenThen, nextLinkRenderer()); + setNextLinkRendererInternal(null); + return CommandExecutionResult.ok(); + } + return CommandExecutionResult.error("Cannot find if"); + } + + public CommandExecutionResult else2(Display whenElse) { + if (current() instanceof InstructionIf1) { + ((InstructionIf1) current()).swithToElse(whenElse, nextLinkRenderer()); + setNextLinkRendererInternal(null); + return CommandExecutionResult.ok(); + } + return CommandExecutionResult.error("Cannot find if"); + } + + public CommandExecutionResult endif() { + if (current() instanceof InstructionIf1) { + ((InstructionIf1) current()).endif(nextLinkRenderer()); + setNextLinkRendererInternal(null); + setCurrent(((InstructionIf1) current()).getParent()); + return CommandExecutionResult.ok(); + } + return CommandExecutionResult.error("Cannot find if"); + } + + public void startRepeat() { + manageSwimlaneStrategy(); + final InstructionRepeat instructionRepeat = new InstructionRepeat(swinlanes.getCurrentSwimlane(), current(), + nextLinkRenderer()); + current().add(instructionRepeat); + setCurrent(instructionRepeat); + + } + + public CommandExecutionResult repeatWhile(Display label) { + manageSwimlaneStrategy(); + if (current() instanceof InstructionRepeat) { + final InstructionRepeat instructionRepeat = (InstructionRepeat) current(); + instructionRepeat.setTest(label, nextLinkRenderer()); + setCurrent(instructionRepeat.getParent()); + this.setNextLinkRendererInternal(null); + return CommandExecutionResult.ok(); + } + return CommandExecutionResult.error("Cannot find repeat"); + + } + + public void doWhile(Display test, Display yes) { + manageSwimlaneStrategy(); + final InstructionWhile instructionWhile = new InstructionWhile(swinlanes.getCurrentSwimlane(), current(), test, + nextLinkRenderer(), yes); + current().add(instructionWhile); + setCurrent(instructionWhile); + } + + public CommandExecutionResult endwhile(Display out) { + if (current() instanceof InstructionWhile) { + ((InstructionWhile) current()).endwhile(nextLinkRenderer(), out); + setNextLinkRendererInternal(null); + setCurrent(((InstructionWhile) current()).getParent()); + return CommandExecutionResult.ok(); + } + return CommandExecutionResult.error("Cannot find while"); + } + + final public CommandExecutionResult kill() { + if (current().kill() == false) { + return CommandExecutionResult.error("kill cannot be used here"); + } + return CommandExecutionResult.ok(); + } + + public void startGroup(Display name) { + manageSwimlaneStrategy(); + final InstructionGroup instructionGroup = new InstructionGroup(current(), name); + current().add(instructionGroup); + setCurrent(instructionGroup); + } + + public CommandExecutionResult endGroup() { + if (current() instanceof InstructionGroup) { + setCurrent(((InstructionGroup) current()).getParent()); + return CommandExecutionResult.ok(); + } + return CommandExecutionResult.error("Cannot find group"); + } + + private void setNextLinkRendererInternal(LinkRendering link) { + swinlanes.setNextLinkRenderer(link); + } + + private void setNextLink(LinkRendering linkRenderer) { + if (current() instanceof InstructionList) { + final Instruction last = ((InstructionList) current()).getLast(); + if (last instanceof InstructionWhile) { + ((InstructionWhile) last).afterEndwhile(linkRenderer); + } + } + this.setNextLinkRendererInternal(linkRenderer); + } + + private final Rose rose = new Rose(); + + public void setLabelNextArrow(Display label) { + if (nextLinkRenderer() == null) { + final HtmlColor arrowColor = rose.getHtmlColor(getSkinParam(), ColorParam.activityArrow); + this.setNextLink(new LinkRendering(arrowColor)); + } + nextLinkRenderer().setDisplay(label); + } + + public void setColorNextArrow(HtmlColor color) { + if (color == null) { + return; + } + final LinkRendering link = new LinkRendering(color); + setNextLink(link); + } + + public CommandExecutionResult addNote(Display note, NotePosition position) { + current().addNote(note, position); + manageHasUrl(note); + return CommandExecutionResult.ok(); + } + + private boolean hasUrl = false; + + private void manageHasUrl(Display display) { + if (display.hasUrl()) { + hasUrl = true; + } + } + + @Override + public boolean hasUrl() { + return hasUrl; + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ActivityDiagramFactory3.java b/src/net/sourceforge/plantuml/activitydiagram3/ActivityDiagramFactory3.java new file mode 100644 index 000000000..c9db30292 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ActivityDiagramFactory3.java @@ -0,0 +1,126 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 9786 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3; + +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.plantuml.activitydiagram3.command.CommandActivity3; +import net.sourceforge.plantuml.activitydiagram3.command.CommandActivityLegacy1; +import net.sourceforge.plantuml.activitydiagram3.command.CommandActivityLong3; +import net.sourceforge.plantuml.activitydiagram3.command.CommandArrow3; +import net.sourceforge.plantuml.activitydiagram3.command.CommandArrowLong3; +import net.sourceforge.plantuml.activitydiagram3.command.CommandElse3; +import net.sourceforge.plantuml.activitydiagram3.command.CommandElseIf2; +import net.sourceforge.plantuml.activitydiagram3.command.CommandElseLegacy1; +import net.sourceforge.plantuml.activitydiagram3.command.CommandEndif3; +import net.sourceforge.plantuml.activitydiagram3.command.CommandFork3; +import net.sourceforge.plantuml.activitydiagram3.command.CommandForkAgain3; +import net.sourceforge.plantuml.activitydiagram3.command.CommandForkEnd3; +import net.sourceforge.plantuml.activitydiagram3.command.CommandGroup3; +import net.sourceforge.plantuml.activitydiagram3.command.CommandGroupEnd3; +import net.sourceforge.plantuml.activitydiagram3.command.CommandIf2; +import net.sourceforge.plantuml.activitydiagram3.command.CommandIf4; +import net.sourceforge.plantuml.activitydiagram3.command.CommandIfLegacy1; +import net.sourceforge.plantuml.activitydiagram3.command.CommandKill3; +import net.sourceforge.plantuml.activitydiagram3.command.CommandLink3; +import net.sourceforge.plantuml.activitydiagram3.command.CommandNote3; +import net.sourceforge.plantuml.activitydiagram3.command.CommandNoteLong3; +import net.sourceforge.plantuml.activitydiagram3.command.CommandRepeat3; +import net.sourceforge.plantuml.activitydiagram3.command.CommandRepeatWhile3; +import net.sourceforge.plantuml.activitydiagram3.command.CommandSplit3; +import net.sourceforge.plantuml.activitydiagram3.command.CommandSplitAgain3; +import net.sourceforge.plantuml.activitydiagram3.command.CommandSplitEnd3; +import net.sourceforge.plantuml.activitydiagram3.command.CommandStart3; +import net.sourceforge.plantuml.activitydiagram3.command.CommandStop3; +import net.sourceforge.plantuml.activitydiagram3.command.CommandStopLegacy1; +import net.sourceforge.plantuml.activitydiagram3.command.CommandSwimlane; +import net.sourceforge.plantuml.activitydiagram3.command.CommandSwimlane2; +import net.sourceforge.plantuml.activitydiagram3.command.CommandWhile3; +import net.sourceforge.plantuml.activitydiagram3.command.CommandWhileEnd3; +import net.sourceforge.plantuml.command.Command; +import net.sourceforge.plantuml.command.UmlDiagramFactory; + +public class ActivityDiagramFactory3 extends UmlDiagramFactory { + + @Override + protected List createCommands() { + + final List cmds = new ArrayList(); + + addCommonCommands(cmds); + cmds.add(new CommandSwimlane()); + cmds.add(new CommandSwimlane2()); + cmds.add(new CommandArrow3()); + cmds.add(new CommandArrowLong3()); + cmds.add(new CommandActivity3()); + cmds.add(new CommandIf4()); + cmds.add(new CommandIf2()); + cmds.add(new CommandIfLegacy1()); + cmds.add(new CommandElseIf2()); + cmds.add(new CommandElse3()); + cmds.add(new CommandElseLegacy1()); + cmds.add(new CommandEndif3()); + cmds.add(new CommandRepeat3()); + cmds.add(new CommandRepeatWhile3()); + cmds.add(new CommandWhile3()); + cmds.add(new CommandWhileEnd3()); + cmds.add(new CommandFork3()); + cmds.add(new CommandForkAgain3()); + cmds.add(new CommandForkEnd3()); + cmds.add(new CommandSplit3()); + cmds.add(new CommandSplitAgain3()); + cmds.add(new CommandSplitEnd3()); + cmds.add(new CommandGroup3()); + cmds.add(new CommandGroupEnd3()); + cmds.add(new CommandStart3()); + cmds.add(new CommandStop3()); + cmds.add(new CommandStopLegacy1()); + cmds.add(new CommandKill3()); + cmds.add(new CommandLink3()); + cmds.add(new CommandNote3()); + cmds.add(new CommandNoteLong3()); + + cmds.add(new CommandActivityLong3()); + cmds.add(new CommandActivityLegacy1()); + + return cmds; + } + + @Override + public ActivityDiagram3 createEmptyDiagram() { + return new ActivityDiagram3(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/Branch.java b/src/net/sourceforge/plantuml/activitydiagram3/Branch.java new file mode 100644 index 000000000..c1093840d --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/Branch.java @@ -0,0 +1,104 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 9786 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3; + +import java.util.Collection; + +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.sequencediagram.NotePosition; + +public class Branch { + + private final InstructionList list; + private final Display labelTest; + private final Display labelPositive; + + private LinkRendering inlinkRendering; + + private Ftile ftile; + + public Branch(Swimlane swimlane, Display labelPositive, Display labelTest) { + this.list = new InstructionList(swimlane); + this.labelTest = labelTest; + this.labelPositive = labelPositive; + } + + public void add(Instruction ins) { + list.add(ins); + } + + public boolean kill() { + return list.kill(); + } + + public void addNote(Display note, NotePosition position) { + list.addNote(note, position); + } + + public final void setInlinkRendering(LinkRendering inlinkRendering) { + this.inlinkRendering = inlinkRendering; + } + + public void updateFtile(FtileFactory factory) { + this.ftile = factory.decorateOut(list.createFtile(factory), inlinkRendering); + } + + public Collection getSwimlanes() { + return list.getSwimlanes(); + } + + public final Display getLabelPositive() { + return labelPositive; + } + + public final Display getLabelTest() { + return labelTest; + } + + public final HtmlColor getInlinkRenderingColor() { + return inlinkRendering == null ? null : inlinkRendering.getColor(); + } + + public final Ftile getFtile() { + return ftile; + } + + public boolean shadowing() { + return ftile.shadowing(); + } +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/Instruction.java b/src/net/sourceforge/plantuml/activitydiagram3/Instruction.java new file mode 100644 index 000000000..cee42fc0d --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/Instruction.java @@ -0,0 +1,54 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 9786 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3; + +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimable; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.sequencediagram.NotePosition; + +public interface Instruction extends Swimable { + + public Ftile createFtile(FtileFactory factory); + + public void add(Instruction other); + + public boolean kill(); + + public LinkRendering getInLinkRendering(); + + public void addNote(Display note, NotePosition position); + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/InstructionFork.java b/src/net/sourceforge/plantuml/activitydiagram3/InstructionFork.java new file mode 100644 index 000000000..2ece5b576 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/InstructionFork.java @@ -0,0 +1,106 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 9786 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.sequencediagram.NotePosition; + +public class InstructionFork implements Instruction { + + private final List forks = new ArrayList(); + private final Instruction parent; + + public InstructionFork(Instruction parent) { + this.parent = parent; + this.forks.add(new InstructionList()); + } + + private InstructionList getLast() { + return forks.get(forks.size() - 1); + } + + + public void add(Instruction ins) { + getLast().add(ins); + } + + public Ftile createFtile(FtileFactory factory) { + final List all = new ArrayList(); + for (InstructionList list : forks) { + all.add(list.createFtile(factory)); + } + return factory.createFork(all); + } + + public Instruction getParent() { + return parent; + } + + public void forkAgain() { + this.forks.add(new InstructionList()); + } + + final public boolean kill() { + return getLast().kill(); + } + + public LinkRendering getInLinkRendering() { + return null; + } + + public void addNote(Display note, NotePosition position) { + getLast().addNote(note, position); + } + + public Set getSwimlanes() { + return InstructionList.getSwimlanes2(forks); + } + + public Swimlane getSwimlaneIn() { + return parent.getSwimlaneOut(); + } + + public Swimlane getSwimlaneOut() { + return getLast().getSwimlaneOut(); + } + + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/InstructionGroup.java b/src/net/sourceforge/plantuml/activitydiagram3/InstructionGroup.java new file mode 100644 index 000000000..4e4552223 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/InstructionGroup.java @@ -0,0 +1,96 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 9786 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3; + +import java.util.Set; + +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.sequencediagram.NotePosition; + +public class InstructionGroup implements Instruction { + + private final InstructionList list = new InstructionList(); + private final Instruction parent; + + private final Display test; + + public InstructionGroup(Instruction parent, Display test) { + this.parent = parent; + this.test = test; + } + + + public void add(Instruction ins) { + list.add(ins); + } + + public Ftile createFtile(FtileFactory factory) { + return factory.createGroup(list.createFtile(factory), test); + } + + public Instruction getParent() { + return parent; + } + + final public boolean kill() { + return list.kill(); + } + + public LinkRendering getInLinkRendering() { + return null; + } + + public void addNote(Display note, NotePosition position) { + list.addNote(note, position); + } + + public Set getSwimlanes() { + return list.getSwimlanes(); + } + + public Swimlane getSwimlaneIn() { + return list.getSwimlaneIn(); + } + + + public Swimlane getSwimlaneOut() { + return list.getSwimlaneOut(); + } + + + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/InstructionIf1.java b/src/net/sourceforge/plantuml/activitydiagram3/InstructionIf1.java new file mode 100644 index 000000000..83f712f1d --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/InstructionIf1.java @@ -0,0 +1,148 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 9786 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.sequencediagram.NotePosition; + +public class InstructionIf1 implements Instruction { + + private final List thens = new ArrayList(); + private Branch elseBranch; + + private final Instruction parent; + + private Branch current; + private final LinkRendering inlinkRendering; + + private final Swimlane swimlane; + + public InstructionIf1(Swimlane swimlane, Instruction parent, Display labelTest, Display whenThen, + LinkRendering inlinkRendering) { + this.parent = parent; + + this.inlinkRendering = inlinkRendering; + this.swimlane = swimlane; + this.thens.add(new Branch(swimlane, whenThen, labelTest)); + this.current = this.thens.get(0); + } + + public void add(Instruction ins) { + current.add(ins); + } + + public Ftile createFtile(FtileFactory factory) { + for (Branch branch : thens) { + branch.updateFtile(factory); + } + if (elseBranch == null) { + this.elseBranch = new Branch(swimlane, null, null); + } + elseBranch.updateFtile(factory); + return factory.createIf(swimlane, thens, elseBranch); + } + + public Instruction getParent() { + return parent; + } + + public void swithToElse(Display whenElse, LinkRendering nextLinkRenderer) { + if (elseBranch != null) { + throw new IllegalStateException(); + } + this.current.setInlinkRendering(nextLinkRenderer); + this.elseBranch = new Branch(swimlane, whenElse, null); + // this.elseBranch.setLabelPositive(whenElse); + this.current = elseBranch; + } + + public void elseIf(Display test, Display whenThen, LinkRendering nextLinkRenderer) { + if (elseBranch != null) { + throw new IllegalStateException(); + } + this.current.setInlinkRendering(nextLinkRenderer); + this.current = new Branch(swimlane, whenThen, test); + this.thens.add(current); + + } + + public void endif(LinkRendering nextLinkRenderer) { + if (elseBranch == null) { + this.elseBranch = new Branch(swimlane, null, null); + } + this.current.setInlinkRendering(nextLinkRenderer); + } + + final public boolean kill() { + return current.kill(); + } + + public LinkRendering getInLinkRendering() { + return inlinkRendering; + } + + public void addNote(Display note, NotePosition position) { + current.addNote(note, position); + } + + public Set getSwimlanes() { + final Set result = new HashSet(); + if (swimlane != null) { + result.add(swimlane); + } + for (Branch branch : thens) { + result.addAll(branch.getSwimlanes()); + } + result.addAll(elseBranch.getSwimlanes()); + return Collections.unmodifiableSet(result); + } + + public Swimlane getSwimlaneIn() { + return swimlane; + } + + public Swimlane getSwimlaneOut() { + return swimlane; + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/InstructionList.java b/src/net/sourceforge/plantuml/activitydiagram3/InstructionList.java new file mode 100644 index 000000000..58d0bba5c --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/InstructionList.java @@ -0,0 +1,134 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 9786 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileEmpty; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileKilled; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.sequencediagram.NotePosition; + +public class InstructionList implements Instruction { + + private final List all = new ArrayList(); + private boolean killed = false; + private final Swimlane defaultSwimlane; + + public InstructionList() { + this(null); + } + + public InstructionList(Swimlane defaultSwimlane) { + this.defaultSwimlane = defaultSwimlane; + } + + public void add(Instruction ins) { + if (killed == false) { + all.add(ins); + } + } + + public Ftile createFtile(FtileFactory factory) { + if (all.size() == 0) { + return new FtileEmpty(factory.shadowing(), defaultSwimlane); + } + Ftile result = null; + for (Instruction ins : all) { + Ftile cur = ins.createFtile(factory); + if (ins.getInLinkRendering() != null) { + cur = factory.decorateIn(cur, ins.getInLinkRendering()); + } + if (result == null) { + result = cur; + } else { + result = factory.assembly(result, cur); + } + + } + if (killed) { + result = new FtileKilled(result); + } + return result; + } + + final public boolean kill() { + this.killed = true; + return true; + } + + public LinkRendering getInLinkRendering() { + return all.iterator().next().getInLinkRendering(); + } + + public Instruction getLast() { + if (all.size() == 0) { + return null; + } + return all.get(all.size() - 1); + } + + public void addNote(Display note, NotePosition position) { + getLast().addNote(note, position); + } + + public Set getSwimlanes() { + return getSwimlanes2(all); + } + + public Swimlane getSwimlaneIn() { + return all.get(0).getSwimlaneIn(); + } + + public Swimlane getSwimlaneOut() { + return getLast().getSwimlaneOut(); + } + + + public static Set getSwimlanes2(List list) { + final Set result = new HashSet(); + for (Instruction ins : list) { + result.addAll(ins.getSwimlanes()); + } + return Collections.unmodifiableSet(result); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/InstructionRepeat.java b/src/net/sourceforge/plantuml/activitydiagram3/InstructionRepeat.java new file mode 100644 index 000000000..05e726b1e --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/InstructionRepeat.java @@ -0,0 +1,102 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 9786 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3; + +import java.util.Set; + +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.sequencediagram.NotePosition; + +public class InstructionRepeat implements Instruction { + + private final InstructionList repeatList = new InstructionList(); + private final Instruction parent; + private final LinkRendering nextLinkRenderer; + private final Swimlane swimlane; + + private Display test; + private LinkRendering endRepeatLinkRendering; + + public InstructionRepeat(Swimlane swimlane, Instruction parent, LinkRendering nextLinkRenderer) { + this.parent = parent; + this.swimlane = swimlane; + this.nextLinkRenderer = nextLinkRenderer; + } + + public void add(Instruction ins) { + repeatList.add(ins); + } + + public Ftile createFtile(FtileFactory factory) { + return factory.repeat(swimlane, factory.decorateOut(repeatList.createFtile(factory), endRepeatLinkRendering), test); + } + + public Instruction getParent() { + return parent; + } + + public void setTest(Display test, LinkRendering linkRenderer) { + this.test = test; + this.endRepeatLinkRendering = linkRenderer; + } + + final public boolean kill() { + return repeatList.kill(); + } + + public LinkRendering getInLinkRendering() { + return nextLinkRenderer; + } + + public void addNote(Display note, NotePosition position) { + repeatList.addNote(note, position); + } + + public Set getSwimlanes() { + return repeatList.getSwimlanes(); + } + + public Swimlane getSwimlaneIn() { + return parent.getSwimlaneOut(); + } + + public Swimlane getSwimlaneOut() { + return repeatList.getSwimlaneOut(); + } + + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/InstructionSimple.java b/src/net/sourceforge/plantuml/activitydiagram3/InstructionSimple.java new file mode 100644 index 000000000..7d61c5a2c --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/InstructionSimple.java @@ -0,0 +1,86 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 9786 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3; + +import net.sourceforge.plantuml.activitydiagram3.ftile.BoxStyle; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.sequencediagram.NotePosition; + +public class InstructionSimple extends MonoSwimable implements Instruction { + + private final Display label; + private final HtmlColor color; + private final LinkRendering inlinkRendering; + private Display note; + private NotePosition notePosition; + private final BoxStyle style; + + public InstructionSimple(Display label, HtmlColor color, LinkRendering inlinkRendering, Swimlane swimlane, BoxStyle style) { + super(swimlane); + this.style = style; + this.label = label; + this.color = color; + this.inlinkRendering = inlinkRendering; + } + + public Ftile createFtile(FtileFactory factory) { + final Ftile result = factory.activity(label, color, getSwimlaneIn(), style); + if (note == null) { + return result; + } + return factory.addNote(result, note, notePosition); + } + + public void add(Instruction other) { + throw new UnsupportedOperationException(); + } + + final public boolean kill() { + return false; + } + + public LinkRendering getInLinkRendering() { + return inlinkRendering; + } + + public void addNote(Display note, NotePosition position) { + this.note = note; + this.notePosition = position; + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/InstructionSplit.java b/src/net/sourceforge/plantuml/activitydiagram3/InstructionSplit.java new file mode 100644 index 000000000..838965498 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/InstructionSplit.java @@ -0,0 +1,104 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 9786 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.sequencediagram.NotePosition; + +public class InstructionSplit implements Instruction { + + private final List splits = new ArrayList(); + private final Instruction parent; + + public InstructionSplit(Instruction parent) { + this.parent = parent; + this.splits.add(new InstructionList()); + } + + private InstructionList getLast() { + return splits.get(splits.size() - 1); + } + + public void add(Instruction ins) { + getLast().add(ins); + } + + public Ftile createFtile(FtileFactory factory) { + final List all = new ArrayList(); + for (InstructionList list : splits) { + all.add(list.createFtile(factory)); + } + return factory.createSplit(all); + } + + public Instruction getParent() { + return parent; + } + + public void splitAgain() { + this.splits.add(new InstructionList()); + } + + final public boolean kill() { + return getLast().kill(); + } + + public LinkRendering getInLinkRendering() { + return null; + } + + public void addNote(Display note, NotePosition position) { + getLast().addNote(note, position); + } + + public Set getSwimlanes() { + return InstructionList.getSwimlanes2(splits); + } + + public Swimlane getSwimlaneIn() { + return parent.getSwimlaneOut(); + } + + public Swimlane getSwimlaneOut() { + return getLast().getSwimlaneOut(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/InstructionStart.java b/src/net/sourceforge/plantuml/activitydiagram3/InstructionStart.java new file mode 100644 index 000000000..b725a4576 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/InstructionStart.java @@ -0,0 +1,68 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 9786 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3; + +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.sequencediagram.NotePosition; + +public class InstructionStart extends MonoSwimable implements Instruction { + + public InstructionStart(Swimlane swimlane) { + super(swimlane); + } + + public Ftile createFtile(FtileFactory factory) { + return factory.start(getSwimlaneIn()); + } + + public void add(Instruction other) { + throw new UnsupportedOperationException(); + } + + final public boolean kill() { + return false; + } + + public LinkRendering getInLinkRendering() { + return null; + } + + public void addNote(Display note, NotePosition position) { + throw new UnsupportedOperationException(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/InstructionStop.java b/src/net/sourceforge/plantuml/activitydiagram3/InstructionStop.java new file mode 100644 index 000000000..086ba8114 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/InstructionStop.java @@ -0,0 +1,69 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 9786 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3; + +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.sequencediagram.NotePosition; + +public class InstructionStop extends MonoSwimable implements Instruction { + + public InstructionStop(Swimlane swimlane) { + super(swimlane); + } + + public Ftile createFtile(FtileFactory factory) { + return factory.stop(getSwimlaneIn()); + } + + public void add(Instruction other) { + throw new UnsupportedOperationException(); + } + + final public boolean kill() { + return false; + } + + public LinkRendering getInLinkRendering() { + return null; + } + + public void addNote(Display note, NotePosition position) { + throw new UnsupportedOperationException(); + } + + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/InstructionWhile.java b/src/net/sourceforge/plantuml/activitydiagram3/InstructionWhile.java new file mode 100644 index 000000000..ab57410bb --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/InstructionWhile.java @@ -0,0 +1,115 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 9786 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3; + +import java.util.Set; + +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.sequencediagram.NotePosition; + +public class InstructionWhile implements Instruction { + + private final InstructionList repeatList = new InstructionList(); + private final Instruction parent; + private final LinkRendering nextLinkRenderer; + + private final Display test; + private final Display yes; + private Display out; + private LinkRendering endInlinkRendering; + private LinkRendering afterEndwhile; + private final Swimlane swimlane; + + public InstructionWhile(Swimlane swimlane, Instruction parent, Display test, LinkRendering nextLinkRenderer, Display yes) { + this.parent = parent; + this.test = test; + this.nextLinkRenderer = nextLinkRenderer; + this.yes = yes; + this.swimlane = swimlane; + } + + public void add(Instruction ins) { + repeatList.add(ins); + } + + public Ftile createFtile(FtileFactory factory) { + Ftile tmp = factory.decorateOut(repeatList.createFtile(factory), endInlinkRendering); + tmp = factory.createWhile(swimlane, tmp, test, yes, out, afterEndwhile); + // tmp = factory.decorateOut(tmp, afterEndwhile); + return tmp; + } + + public Instruction getParent() { + return parent; + } + + final public boolean kill() { + return repeatList.kill(); + } + + public LinkRendering getInLinkRendering() { + return nextLinkRenderer; + } + + public void endwhile(LinkRendering nextLinkRenderer, Display out) { + this.endInlinkRendering = nextLinkRenderer; + this.out = out; + } + + public void afterEndwhile(LinkRendering linkRenderer) { + this.afterEndwhile = linkRenderer; + } + + public void addNote(Display note, NotePosition position) { + repeatList.addNote(note, position); + } + + public Set getSwimlanes() { + return repeatList.getSwimlanes(); + } + + public Swimlane getSwimlaneIn() { + return parent.getSwimlaneOut(); + } + + public Swimlane getSwimlaneOut() { + return getSwimlaneIn(); + } + + + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/LinkRendering.java b/src/net/sourceforge/plantuml/activitydiagram3/LinkRendering.java new file mode 100644 index 000000000..6908eb069 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/LinkRendering.java @@ -0,0 +1,79 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 9786 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3; + +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HtmlColor; + +public class LinkRendering { + + private final HtmlColor color; + private Display display; + + public LinkRendering(HtmlColor color) { + this.color = color; + } + + public void setDisplay(Display display) { + this.display = display; + } + + public Display getDisplay() { + return display; + } + + public HtmlColor getColor() { + return color; + } + + @Override + public String toString() { + return super.toString() + " " + color; + } + + public static HtmlColor getColor(LinkRendering inLinkRendering, HtmlColor defaultColor) { + if (inLinkRendering == null || inLinkRendering.getColor() == null) { + return defaultColor; + } + return inLinkRendering.getColor(); + } + + public static HtmlColor getColor(HtmlColor col, HtmlColor defaultColor) { + if (col == null) { + return defaultColor; + } + return col; + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/MonoSwimable.java b/src/net/sourceforge/plantuml/activitydiagram3/MonoSwimable.java new file mode 100644 index 000000000..aafe1c825 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/MonoSwimable.java @@ -0,0 +1,62 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 9786 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3; + +import java.util.Collections; +import java.util.Set; + +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimable; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; + +public class MonoSwimable implements Swimable { + + private final Swimlane swimlane; + + public MonoSwimable(Swimlane swimlane) { + this.swimlane = swimlane; + } + + final public Set getSwimlanes() { + return swimlane == null ? Collections. emptySet() : Collections. singleton(swimlane); + } + + final public Swimlane getSwimlaneIn() { + return swimlane; + } + + final public Swimlane getSwimlaneOut() { + return swimlane; + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandActivity3.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandActivity3.java new file mode 100644 index 000000000..c0326b27e --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandActivity3.java @@ -0,0 +1,75 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +import net.sourceforge.plantuml.activitydiagram3.ftile.BoxStyle; +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.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; + +public class CommandActivity3 extends SingleLineCommand2 { + + // public static final String ENDING_GROUP = "([/;|<>}\\]])"; + // public static final String ENDING_GROUP = + // "(;|(?}\\]])(?:[/<}\\]])|(?]{1,999})(?:\\>)|(?}\\]])(?:[/<}\\]])|(?]{1,999})(?)|(? { + + public CommandActivityLegacy1() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("-"), // + new RegexLeaf("LABEL", "(.*)"), // + new RegexLeaf("$")); + } + + @Override + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + diagram.addActivity(Display.getWithNewlines(arg.get("LABEL", 0)), null, BoxStyle.PLAIN); + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandActivityLong3.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandActivityLong3.java new file mode 100644 index 000000000..511b5b151 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandActivityLong3.java @@ -0,0 +1,102 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import java.util.List; + +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +import net.sourceforge.plantuml.activitydiagram3.ftile.BoxStyle; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.CommandMultilines2; +import net.sourceforge.plantuml.command.MultilinesStrategy; +import net.sourceforge.plantuml.command.regex.RegexConcat; +import net.sourceforge.plantuml.command.regex.RegexLeaf; +import net.sourceforge.plantuml.command.regex.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; + +public class CommandActivityLong3 extends CommandMultilines2 { + + public CommandActivityLong3() { + super(getRegexConcat(), MultilinesStrategy.REMOVE_STARTING_QUOTE); + } + + @Override + public String getPatternEnd() { + return "^(.*)" + CommandActivity3.ENDING_GROUP + "$"; + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf(":"), // + new RegexLeaf("COLOR", "(?:(#\\w+[-\\\\|/]?\\w+):)?"), // + new RegexLeaf("DATA", "(.*)"), // + new RegexLeaf("$")); + } + + public CommandExecutionResult executeNow(ActivityDiagram3 diagram, List lines) { + lines = StringUtils.removeEmptyColumns(lines); + final RegexResult line0 = getStartingPattern().matcher(lines.get(0).trim()); + final HtmlColor color = HtmlColorUtils.getColorIfValid(line0.get("COLOR", 0)); + final BoxStyle style = BoxStyle.fromChar(getLastChar(lines)); + removeStarting(lines, line0.get("DATA", 0)); + removeEnding(lines); + diagram.addActivity(new Display(lines), color, style); + return CommandExecutionResult.ok(); + } + + private char getLastChar(List lines) { + final String s = lines.get(lines.size() - 1); + return s.charAt(s.length() - 1); + } + + private void removeStarting(List lines, String data) { + if (lines.size() == 0) { + return; + } + lines.set(0, data); + } + + private void removeEnding(List lines) { + if (lines.size() == 0) { + return; + } + final int n = lines.size() - 1; + final String s = lines.get(n); + lines.set(n, s.substring(0, s.length() - 1)); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandArrow3.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandArrow3.java new file mode 100644 index 000000000..643f3146d --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandArrow3.java @@ -0,0 +1,78 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +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.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; + +public class CommandArrow3 extends SingleLineCommand2 { + + public CommandArrow3() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexOr(// + new RegexLeaf("->"), // + new RegexLeaf("COLOR", "-\\[(#\\w+)\\]->")), // + new RegexLeaf("\\s*"), // + new RegexOr(// + new RegexLeaf("LABEL", "(.*);"), // + new RegexLeaf("")), // + new RegexLeaf("$")); + } + + @Override + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + + final HtmlColor color = HtmlColorUtils.getColorIfValid(arg.get("COLOR", 0)); + diagram.setColorNextArrow(color); + final String label = arg.get("LABEL", 0); + if (label != null && label.length() > 0) { + diagram.setLabelNextArrow(Display.getWithNewlines(label)); + } + + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandArrowLong3.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandArrowLong3.java new file mode 100644 index 000000000..1c76ebef2 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandArrowLong3.java @@ -0,0 +1,95 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import java.util.List; + +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.CommandMultilines2; +import net.sourceforge.plantuml.command.MultilinesStrategy; +import net.sourceforge.plantuml.command.regex.RegexConcat; +import net.sourceforge.plantuml.command.regex.RegexLeaf; +import net.sourceforge.plantuml.command.regex.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Display; + +public class CommandArrowLong3 extends CommandMultilines2 { + + public CommandArrowLong3() { + super(getRegexConcat(), MultilinesStrategy.REMOVE_STARTING_QUOTE); + } + + @Override + public String getPatternEnd() { + return "^(.*);$"; + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("->\\s*"), // + // new RegexLeaf("COLOR", "(?:(#\\w+[-\\\\|/]?\\w+):)?"), // + new RegexLeaf("LABEL", "(.*)"), // + new RegexLeaf("$")); + } + + public CommandExecutionResult executeNow(ActivityDiagram3 diagram, List lines) { + lines = StringUtils.removeEmptyColumns(lines); + final RegexResult line0 = getStartingPattern().matcher(lines.get(0).trim()); + // final HtmlColor color = HtmlColorUtils.getColorIfValid(line0.get("COLOR", 0)); + // final BoxStyle style = BoxStyle.fromChar(getLastChar(lines)); + removeStarting(lines, line0.get("LABEL", 0)); + removeEnding(lines); + // diagram.addActivity(Display.getWithNewlines(arg.get("LABEL", 0)), color, style); + diagram.setLabelNextArrow(new Display(lines)); + return CommandExecutionResult.ok(); + } + + private void removeStarting(List lines, String data) { + if (lines.size() == 0) { + return; + } + lines.set(0, data); + } + + private void removeEnding(List lines) { + if (lines.size() == 0) { + return; + } + final int n = lines.size() - 1; + final String s = lines.get(n); + lines.set(n, s.substring(0, s.length() - 1)); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandEnd2.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandElse3.java similarity index 61% rename from src/net/sourceforge/plantuml/activitydiagram2/command/CommandEnd2.java rename to src/net/sourceforge/plantuml/activitydiagram3/command/CommandElse3.java index 8bb9fa327..7214fb499 100644 --- a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandEnd2.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandElse3.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -31,44 +31,36 @@ * Revision $Revision: 4762 $ * */ -package net.sourceforge.plantuml.activitydiagram2.command; +package net.sourceforge.plantuml.activitydiagram3.command; -import java.util.Map; - -import net.sourceforge.plantuml.Direction; -import net.sourceforge.plantuml.activitydiagram2.ActivityDiagram2; +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.SingleLineCommand2; import net.sourceforge.plantuml.command.regex.RegexConcat; import net.sourceforge.plantuml.command.regex.RegexLeaf; -import net.sourceforge.plantuml.command.regex.RegexPartialMatch; +import net.sourceforge.plantuml.command.regex.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Display; -public class CommandEnd2 extends SingleLineCommand2 { +public class CommandElse3 extends SingleLineCommand2 { - public CommandEnd2(ActivityDiagram2 diagram) { - super(diagram, getRegexConcat()); + public CommandElse3() { + super(getRegexConcat()); } static RegexConcat getRegexConcat() { - return new RegexConcat(new RegexLeaf("^"), // - new RegexLeaf("direction", "([<>^])?\\s*"), // - new RegexLeaf("end"), // - new RegexLeaf("$")); + return new RegexConcat(// + new RegexLeaf("^"), // + new RegexLeaf("else"), // + new RegexLeaf("WHEN", "(?:\\s*(?:\\(([^()]*)\\))?)?"), // + new RegexLeaf(";?$")); } @Override - protected CommandExecutionResult executeArg(Map arg) { + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { // if (getSystem().getLastEntityConsulted() == null) { // return CommandExecutionResult.error("No if for this endif"); // } - final String sdir = arg.get("direction").get(0); - Direction direction = Direction.DOWN; - if (sdir != null) { - direction = Direction.fromChar(sdir.charAt(0)); - } - getSystem().end(direction); - - return CommandExecutionResult.ok(); + return diagram.else2(Display.getWithNewlines(arg.get("WHEN", 0))); } } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandElseIf2.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandElseIf2.java new file mode 100644 index 000000000..9c7aff7c6 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandElseIf2.java @@ -0,0 +1,71 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +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.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Display; + +public class CommandElseIf2 extends SingleLineCommand2 { + + public CommandElseIf2() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("else\\s*if"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("TEST", "\\((.*?)\\)"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("WHEN", "(?:then\\s*(?:\\((.+?)\\))?)?"), // + new RegexLeaf(";?$")); + } + + @Override + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + + String test = arg.get("TEST", 0); + if (test.length() == 0) { + test = null; + } + + return diagram.elseIf(Display.getWithNewlines(test), Display.getWithNewlines(arg.get("WHEN", 0))); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandElseLegacy1.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandElseLegacy1.java new file mode 100644 index 000000000..552f45b20 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandElseLegacy1.java @@ -0,0 +1,66 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +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.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Display; + +public class CommandElseLegacy1 extends SingleLineCommand2 { + + public CommandElseLegacy1() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(// + new RegexLeaf("^"), // + new RegexLeaf("else when"), // + new RegexLeaf("WHEN", "\\s+(.*)"), // + new RegexLeaf(";?$")); + } + + @Override + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + // if (getSystem().getLastEntityConsulted() == null) { + // return CommandExecutionResult.error("No if for this endif"); + // } + return diagram.else2(Display.getWithNewlines(arg.get("WHEN", 0))); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandEndif3.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandEndif3.java new file mode 100644 index 000000000..cf9c28196 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandEndif3.java @@ -0,0 +1,64 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +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.RegexResult; + +public class CommandEndif3 extends SingleLineCommand2 { + + public CommandEndif3() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(// + new RegexLeaf("^"), // + new RegexLeaf("endif"), // + new RegexLeaf(";?$")); + } + + @Override + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + // if (getSystem().getLastEntityConsulted() == null) { + // return CommandExecutionResult.error("No if for this endif"); + // } + return diagram.endif(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandLabel2.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandFork3.java similarity index 66% rename from src/net/sourceforge/plantuml/activitydiagram2/command/CommandLabel2.java rename to src/net/sourceforge/plantuml/activitydiagram3/command/CommandFork3.java index afd4d92fd..66e809a0d 100644 --- a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandLabel2.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandFork3.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -31,34 +31,32 @@ * Revision $Revision: 4762 $ * */ -package net.sourceforge.plantuml.activitydiagram2.command; +package net.sourceforge.plantuml.activitydiagram3.command; -import java.util.Map; - -import net.sourceforge.plantuml.activitydiagram2.ActivityDiagram2; +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.SingleLineCommand2; import net.sourceforge.plantuml.command.regex.RegexConcat; import net.sourceforge.plantuml.command.regex.RegexLeaf; -import net.sourceforge.plantuml.command.regex.RegexPartialMatch; +import net.sourceforge.plantuml.command.regex.RegexResult; -public class CommandLabel2 extends SingleLineCommand2 { +public class CommandFork3 extends SingleLineCommand2 { - public CommandLabel2(ActivityDiagram2 diagram) { - super(diagram, getRegexConcat()); + public CommandFork3() { + super(getRegexConcat()); } static RegexConcat getRegexConcat() { - return new RegexConcat(new RegexLeaf("^"), - new RegexLeaf("LABEL", "([\\p{L}0-9_.]+)"), - new RegexLeaf(":"), - new RegexLeaf("$")); + return new RegexConcat(// + new RegexLeaf("^"), // + new RegexLeaf("fork"), // + new RegexLeaf(";?$")); } - @Override - protected CommandExecutionResult executeArg(Map arg) { - getSystem().label(arg.get("LABEL").get(0)); + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + diagram.fork(); + return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandForkAgain3.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandForkAgain3.java new file mode 100644 index 000000000..4e0866e83 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandForkAgain3.java @@ -0,0 +1,62 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +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.RegexResult; + +public class CommandForkAgain3 extends SingleLineCommand2 { + + public CommandForkAgain3() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(// + new RegexLeaf("^"), // + new RegexLeaf("fork ?again"), // + new RegexLeaf(";?$")); + } + + @Override + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + return diagram.forkAgain(); + + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandForkEnd3.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandForkEnd3.java new file mode 100644 index 000000000..bf308c95a --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandForkEnd3.java @@ -0,0 +1,61 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +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.RegexResult; + +public class CommandForkEnd3 extends SingleLineCommand2 { + + public CommandForkEnd3() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(// + new RegexLeaf("^"), // + new RegexLeaf("(end ?fork|fork ?end)"), // + new RegexLeaf(";?$")); + } + + @Override + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + return diagram.endFork(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandGroup3.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandGroup3.java new file mode 100644 index 000000000..6e9a54e8b --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandGroup3.java @@ -0,0 +1,66 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +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.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Display; + +public class CommandGroup3 extends SingleLineCommand2 { + + public CommandGroup3() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("group"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("NAME", "(.*)"), // + new RegexLeaf(";?$")); + } + + @Override + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + + diagram.startGroup(Display.getWithNewlines(arg.get("NAME", 0))); + + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandGroupEnd3.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandGroupEnd3.java new file mode 100644 index 000000000..a9274dc12 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandGroupEnd3.java @@ -0,0 +1,60 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +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.RegexResult; + +public class CommandGroupEnd3 extends SingleLineCommand2 { + + public CommandGroupEnd3() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("(end ?group|group ?end)"), // + new RegexLeaf(";?$")); + } + + @Override + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + return diagram.endGroup(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandIf2.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandIf2.java new file mode 100644 index 000000000..7980fc4b8 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandIf2.java @@ -0,0 +1,73 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +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.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Display; + +public class CommandIf2 extends SingleLineCommand2 { + + public CommandIf2() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("if"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("TEST", "\\((.*?)\\)"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("WHEN", "(?:then\\s*(?:\\((.+?)\\))?)?"), // + new RegexLeaf(";?$")); + } + + @Override + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + + String test = arg.get("TEST", 0); + if (test.length() == 0) { + test = null; + } + + diagram.startIf(Display.getWithNewlines(test), Display.getWithNewlines(arg.get("WHEN", 0))); + + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandIf4.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandIf4.java new file mode 100644 index 000000000..e85641fae --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandIf4.java @@ -0,0 +1,72 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +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.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Display; + +public class CommandIf4 extends SingleLineCommand2 { + + public CommandIf4() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("if"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("TEST", "\\((.*?)\\)"), // + new RegexLeaf("\\s*(is|equals?)\\s*"), // + new RegexLeaf("WHEN", "\\((.+?)\\)"), // + new RegexLeaf("\\s*then\\s*"), // + new RegexLeaf(";?$")); + } + + @Override + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + + String test = arg.get("TEST", 0); + if (test.length() == 0) { + test = null; + } + diagram.startIf(Display.getWithNewlines(test), Display.getWithNewlines(arg.get("WHEN", 0))); + + return CommandExecutionResult.ok(); + } +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandIfLegacy1.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandIfLegacy1.java new file mode 100644 index 000000000..52d231e02 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandIfLegacy1.java @@ -0,0 +1,68 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +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.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Display; + +public class CommandIfLegacy1 extends SingleLineCommand2 { + + public CommandIfLegacy1() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("if"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("TEST", "\\((.+?)\\)"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("WHEN", "then when\\s+(.*)"), // + new RegexLeaf(";?$")); + } + + @Override + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + + diagram.startIf(Display.getWithNewlines(arg.get("TEST", 0)), Display.getWithNewlines(arg.get("WHEN", 0))); + + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandKill3.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandKill3.java new file mode 100644 index 000000000..cae6292a9 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandKill3.java @@ -0,0 +1,61 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +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.RegexResult; + +public class CommandKill3 extends SingleLineCommand2 { + + public CommandKill3() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(// + new RegexLeaf("^"), // + new RegexLeaf("kill"), // + new RegexLeaf(";?$")); + } + + @Override + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + return diagram.kill(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandLink3.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandLink3.java new file mode 100644 index 000000000..2736184a2 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandLink3.java @@ -0,0 +1,68 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +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.RegexResult; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; + +public class CommandLink3 extends SingleLineCommand2 { + + public CommandLink3() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("link +"), // + new RegexLeaf("COLOR", "(#\\w+)"), // + new RegexLeaf(";?"), // + new RegexLeaf("$")); + } + + @Override + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + final HtmlColor color = HtmlColorUtils.getColorIfValid(arg.get("COLOR", 0)); + if (color != null) { + diagram.setColorNextArrow(color); + } + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandNote3.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandNote3.java new file mode 100644 index 000000000..4a8bf776b --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandNote3.java @@ -0,0 +1,74 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +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.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.sequencediagram.NotePosition; + +public class CommandNote3 extends SingleLineCommand2 { + + public CommandNote3() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("note"), // + new RegexLeaf("POSITION", "\\s*(left|right)?"), // + new RegexLeaf("\\s*:\\s*"), // + new RegexLeaf("NOTE", "(.*)"), // + new RegexLeaf("$")); + } + + @Override + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + final Display note = Display.getWithNewlines(arg.get("NOTE", 0)); + final NotePosition position = getPosition(arg.get("POSITION", 0)); + return diagram.addNote(note, position); + } + + private NotePosition getPosition(String s) { + if (s == null) { + return NotePosition.LEFT; + } + return NotePosition.valueOf(s.toUpperCase()); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandNoteLong3.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandNoteLong3.java new file mode 100644 index 000000000..d0cfea326 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandNoteLong3.java @@ -0,0 +1,98 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import java.util.List; + +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.CommandMultilines2; +import net.sourceforge.plantuml.command.MultilinesStrategy; +import net.sourceforge.plantuml.command.regex.RegexConcat; +import net.sourceforge.plantuml.command.regex.RegexLeaf; +import net.sourceforge.plantuml.command.regex.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.sequencediagram.NotePosition; + +public class CommandNoteLong3 extends CommandMultilines2 { + + public CommandNoteLong3() { + super(getRegexConcat(), MultilinesStrategy.REMOVE_STARTING_QUOTE); + } + + public String getPatternEnd() { + return "(?i)^end ?note$"; + } + + public CommandExecutionResult executeNow(final ActivityDiagram3 diagram, List lines) { + // final RegexResult line0 = getStartingPattern().matcher(lines.get(0).trim()); + final List in = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1)); + final RegexResult line0 = getStartingPattern().matcher(lines.get(0).trim()); + final NotePosition position = getPosition(line0.get("POSITION", 0)); + final Display note = new Display(in); + return diagram.addNote(note, position); + } + + private NotePosition getPosition(String s) { + if (s == null) { + return NotePosition.LEFT; + } + return NotePosition.valueOf(s.toUpperCase()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("note"), // + new RegexLeaf("POSITION", "\\s*(left|right)?"), // + new RegexLeaf("$")); + } + + // static RegexConcat getRegexConcat() { + // return new RegexConcat(new RegexLeaf("^"), // + // new RegexLeaf("^"), // + // new RegexLeaf("note"), // + // new RegexLeaf("POSITION", "\\s*(left|right)?"), // + // new RegexLeaf("\\s*:\\s*"), // + // new RegexLeaf("NOTE", "(.*)"), // + // new RegexLeaf("$")); + // } + // + // @Override + // protected CommandExecutionResult executeArg(RegexResult arg) { + // final Display note = Display.getWithNewlines(arg.get("NOTE", 0)); + // return getSystem().addNote(note); + // } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandGoto2.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandRepeat3.java similarity index 67% rename from src/net/sourceforge/plantuml/activitydiagram2/command/CommandGoto2.java rename to src/net/sourceforge/plantuml/activitydiagram3/command/CommandRepeat3.java index e9cee3f9b..f31319151 100644 --- a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandGoto2.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandRepeat3.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -31,34 +31,32 @@ * Revision $Revision: 4762 $ * */ -package net.sourceforge.plantuml.activitydiagram2.command; +package net.sourceforge.plantuml.activitydiagram3.command; -import java.util.Map; - -import net.sourceforge.plantuml.activitydiagram2.ActivityDiagram2; +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.SingleLineCommand2; import net.sourceforge.plantuml.command.regex.RegexConcat; import net.sourceforge.plantuml.command.regex.RegexLeaf; -import net.sourceforge.plantuml.command.regex.RegexPartialMatch; +import net.sourceforge.plantuml.command.regex.RegexResult; -public class CommandGoto2 extends SingleLineCommand2 { +public class CommandRepeat3 extends SingleLineCommand2 { - public CommandGoto2(ActivityDiagram2 diagram) { - super(diagram, getRegexConcat()); + public CommandRepeat3() { + super(getRegexConcat()); } static RegexConcat getRegexConcat() { return new RegexConcat(new RegexLeaf("^"), // - new RegexLeaf("goto\\s+"), // - new RegexLeaf("LABEL", "([\\p{L}0-9_.]+)"), // - new RegexLeaf(":?"), // - new RegexLeaf("$")); + new RegexLeaf("repeat"), // + new RegexLeaf(";?$")); } @Override - protected CommandExecutionResult executeArg(Map arg) { - getSystem().callGoto(arg.get("LABEL").get(0)); + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + + diagram.startRepeat(); + return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandRepeatWhile3.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandRepeatWhile3.java new file mode 100644 index 000000000..0e912cd09 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandRepeatWhile3.java @@ -0,0 +1,64 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +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.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Display; + +public class CommandRepeatWhile3 extends SingleLineCommand2 { + + public CommandRepeatWhile3() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(// + new RegexLeaf("^"), // + new RegexLeaf("repeat ?while"), // + new RegexLeaf("WHEN", "\\s*(?:\\(([^()]*)\\))?"), // + new RegexLeaf(";?$")); + } + + @Override + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + + return diagram.repeatWhile(Display.getWithNewlines(arg.get("WHEN", 0))); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandElse2.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandSplit3.java similarity index 62% rename from src/net/sourceforge/plantuml/activitydiagram2/command/CommandElse2.java rename to src/net/sourceforge/plantuml/activitydiagram3/command/CommandSplit3.java index 1625e484b..42cd87c89 100644 --- a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandElse2.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandSplit3.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -31,36 +31,31 @@ * Revision $Revision: 4762 $ * */ -package net.sourceforge.plantuml.activitydiagram2.command; +package net.sourceforge.plantuml.activitydiagram3.command; -import java.util.Map; - -import net.sourceforge.plantuml.activitydiagram2.ActivityDiagram2; +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.SingleLineCommand2; import net.sourceforge.plantuml.command.regex.RegexConcat; import net.sourceforge.plantuml.command.regex.RegexLeaf; -import net.sourceforge.plantuml.command.regex.RegexPartialMatch; +import net.sourceforge.plantuml.command.regex.RegexResult; -public class CommandElse2 extends SingleLineCommand2 { +public class CommandSplit3 extends SingleLineCommand2 { - public CommandElse2(ActivityDiagram2 diagram) { - super(diagram, getRegexConcat()); + public CommandSplit3() { + super(getRegexConcat()); } static RegexConcat getRegexConcat() { - return new RegexConcat(new RegexLeaf("^"), - new RegexLeaf("WHEN", "(?:else\\s*(?:when\\s+(.*))?)?"), - new RegexLeaf("$")); + return new RegexConcat(// + new RegexLeaf("^"), // + new RegexLeaf("split"), // + new RegexLeaf(";?$")); } - @Override - protected CommandExecutionResult executeArg(Map arg) { -// if (getSystem().getLastEntityConsulted() == null) { -// return CommandExecutionResult.error("No if for this endif"); -// } - getSystem().else2(arg.get("WHEN").get(0)); + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + diagram.split(); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandSplitAgain3.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandSplitAgain3.java new file mode 100644 index 000000000..d877e8754 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandSplitAgain3.java @@ -0,0 +1,62 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +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.RegexResult; + +public class CommandSplitAgain3 extends SingleLineCommand2 { + + public CommandSplitAgain3() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(// + new RegexLeaf("^"), // + new RegexLeaf("split ?again"), // + new RegexLeaf(";?$")); + } + + @Override + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + return diagram.splitAgain(); + + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandSplitEnd3.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandSplitEnd3.java new file mode 100644 index 000000000..583af439d --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandSplitEnd3.java @@ -0,0 +1,61 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +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.RegexResult; + +public class CommandSplitEnd3 extends SingleLineCommand2 { + + public CommandSplitEnd3() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(// + new RegexLeaf("^"), // + new RegexLeaf("(end ?split|split ?end)"), // + new RegexLeaf(";?$")); + } + + @Override + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + return diagram.endSplit(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandBar2.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandStart3.java similarity index 67% rename from src/net/sourceforge/plantuml/activitydiagram2/command/CommandBar2.java rename to src/net/sourceforge/plantuml/activitydiagram3/command/CommandStart3.java index 504719391..cf1d45aeb 100644 --- a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandBar2.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandStart3.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -31,37 +31,34 @@ * Revision $Revision: 4762 $ * */ -package net.sourceforge.plantuml.activitydiagram2.command; +package net.sourceforge.plantuml.activitydiagram3.command; -import java.util.Map; - -import net.sourceforge.plantuml.activitydiagram2.ActivityDiagram2; +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.SingleLineCommand2; import net.sourceforge.plantuml.command.regex.RegexConcat; import net.sourceforge.plantuml.command.regex.RegexLeaf; -import net.sourceforge.plantuml.command.regex.RegexPartialMatch; +import net.sourceforge.plantuml.command.regex.RegexResult; -public class CommandBar2 extends SingleLineCommand2 { +public class CommandStart3 extends SingleLineCommand2 { - public CommandBar2(ActivityDiagram2 diagram) { - super(diagram, getRegexConcat()); + public CommandStart3() { + super(getRegexConcat()); } static RegexConcat getRegexConcat() { - return new RegexConcat(new RegexLeaf("^"), // - new RegexLeaf("==+"), // - new RegexLeaf("BAR", "\\s*(.*?)\\s*"), // - new RegexLeaf("==+"),// - new RegexLeaf("$")); + return new RegexConcat(// + new RegexLeaf("^"), // + new RegexLeaf("start"), // + new RegexLeaf(";?$")); } @Override - protected CommandExecutionResult executeArg(Map arg) { + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { // if (getSystem().getLastEntityConsulted() == null) { // return CommandExecutionResult.error("No if for this endif"); // } - getSystem().bar(arg.get("BAR").get(0)); + diagram.start(); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandEndif2.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandStop3.java similarity index 64% rename from src/net/sourceforge/plantuml/activitydiagram2/command/CommandEndif2.java rename to src/net/sourceforge/plantuml/activitydiagram3/command/CommandStop3.java index 1706feffd..0b663267a 100644 --- a/src/net/sourceforge/plantuml/activitydiagram2/command/CommandEndif2.java +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandStop3.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -31,36 +31,34 @@ * Revision $Revision: 4762 $ * */ -package net.sourceforge.plantuml.activitydiagram2.command; +package net.sourceforge.plantuml.activitydiagram3.command; -import java.util.Map; - -import net.sourceforge.plantuml.activitydiagram2.ActivityDiagram2; +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.SingleLineCommand2; import net.sourceforge.plantuml.command.regex.RegexConcat; import net.sourceforge.plantuml.command.regex.RegexLeaf; -import net.sourceforge.plantuml.command.regex.RegexPartialMatch; +import net.sourceforge.plantuml.command.regex.RegexResult; -public class CommandEndif2 extends SingleLineCommand2 { +public class CommandStop3 extends SingleLineCommand2 { - public CommandEndif2(ActivityDiagram2 diagram) { - super(diagram, getRegexConcat()); + public CommandStop3() { + super(getRegexConcat()); } static RegexConcat getRegexConcat() { - return new RegexConcat(new RegexLeaf("^"), - new RegexLeaf("endif"), - new RegexLeaf("$")); + return new RegexConcat(// + new RegexLeaf("^"), // + new RegexLeaf("stop"), // + new RegexLeaf(";?$")); } - @Override - protected CommandExecutionResult executeArg(Map arg) { -// if (getSystem().getLastEntityConsulted() == null) { -// return CommandExecutionResult.error("No if for this endif"); -// } - getSystem().endif(); + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + // if (getSystem().getLastEntityConsulted() == null) { + // return CommandExecutionResult.error("No if for this endif"); + // } + diagram.stop(); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandStopLegacy1.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandStopLegacy1.java new file mode 100644 index 000000000..43721e996 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandStopLegacy1.java @@ -0,0 +1,66 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +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.RegexResult; + +public class CommandStopLegacy1 extends SingleLineCommand2 { + + public CommandStopLegacy1() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(// + new RegexLeaf("^"), // + new RegexLeaf("end"), // + new RegexLeaf(";?$")); + } + + @Override + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + // if (getSystem().getLastEntityConsulted() == null) { + // return CommandExecutionResult.error("No if for this endif"); + // } + diagram.stop(); + + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandSwimlane.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandSwimlane.java new file mode 100644 index 000000000..2b250d1c5 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandSwimlane.java @@ -0,0 +1,70 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +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.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; + +public class CommandSwimlane extends SingleLineCommand2 { + + public CommandSwimlane() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("\\|"), // + new RegexLeaf("COLOR", "(?:(#\\w+[-\\\\|/]?\\w+)\\|)?"), // + new RegexLeaf("SWIMLANE", "([^|]+)"), // + new RegexLeaf("\\|"), // + new RegexLeaf("LABEL", "([^|]+)?"), // + new RegexLeaf("$")); + } + + @Override + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + final HtmlColor color = HtmlColorUtils.getColorIfValid(arg.get("COLOR", 0)); + final String name = arg.get("SWIMLANE", 0); + final Display label = Display.getWithNewlines(arg.get("LABEL", 0)); + return diagram.swimlane(name, color, label); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandSwimlane2.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandSwimlane2.java new file mode 100644 index 000000000..15f0db501 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandSwimlane2.java @@ -0,0 +1,70 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +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.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; + +public class CommandSwimlane2 extends SingleLineCommand2 { + + public CommandSwimlane2() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("swimlane\\s+"), // + new RegexLeaf("COLOR", "(?:(#\\w+[-\\\\|/]?\\w+))?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("SWIMLANE", "([^|]+)"), // + new RegexLeaf("LABEL", "(?:\\s+as\\s+([^|]+))?"), // + new RegexLeaf("$")); + } + + @Override + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + final HtmlColor color = HtmlColorUtils.getColorIfValid(arg.get("COLOR", 0)); + final String name = arg.get("SWIMLANE", 0); + final Display label = Display.getWithNewlines(arg.get("LABEL", 0)); + return diagram.swimlane(name, color, label); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandWhile3.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandWhile3.java new file mode 100644 index 000000000..405696e4f --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandWhile3.java @@ -0,0 +1,69 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +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.RegexOptional; +import net.sourceforge.plantuml.command.regex.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Display; + +public class CommandWhile3 extends SingleLineCommand2 { + + public CommandWhile3() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(// + new RegexLeaf("^"), // + new RegexLeaf("while"), // + new RegexLeaf("TEST", "\\s*\\((.+?)\\)"), // + new RegexOptional(new RegexConcat(// + new RegexLeaf("\\s*(is|equals?)\\s*"), // + new RegexLeaf("YES", "\\((.+?)\\)"))), // + new RegexLeaf(";?$")); + } + + @Override + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + diagram.doWhile(Display.getWithNewlines(arg.get("TEST", 0)), Display.getWithNewlines(arg.get("YES", 0))); + + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/command/CommandWhileEnd3.java b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandWhileEnd3.java new file mode 100644 index 000000000..ad77917d7 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/command/CommandWhileEnd3.java @@ -0,0 +1,62 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.activitydiagram3.command; + +import net.sourceforge.plantuml.activitydiagram3.ActivityDiagram3; +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.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Display; + +public class CommandWhileEnd3 extends SingleLineCommand2 { + + public CommandWhileEnd3() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("(end ?while|while ?end)"), // + new RegexLeaf("OUT", "\\s*(?:\\((.+?)\\))?"), // + new RegexLeaf(";?$")); + } + + @Override + protected CommandExecutionResult executeArg(ActivityDiagram3 diagram, RegexResult arg) { + return diagram.endwhile(Display.getWithNewlines(arg.get("OUT", 0))); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/AbstractConnection.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/AbstractConnection.java new file mode 100644 index 000000000..08d3d2099 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/AbstractConnection.java @@ -0,0 +1,59 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +public abstract class AbstractConnection implements Connection { + + private final Ftile ftile1; + private final Ftile ftile2; + + public AbstractConnection(Ftile ftile1, Ftile ftile2) { + this.ftile1 = ftile1; + this.ftile2 = ftile2; + } + + @Override + public String toString() { + return "[" + ftile1 + "]->[" + ftile2 + "]"; + } + + final public Ftile getFtile1() { + return ftile1; + } + + final public Ftile getFtile2() { + return ftile2; + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/AbstractFtile.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/AbstractFtile.java new file mode 100644 index 000000000..b3ceefaf7 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/AbstractFtile.java @@ -0,0 +1,71 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import java.util.Collection; +import java.util.Collections; + +import net.sourceforge.plantuml.activitydiagram3.LinkRendering; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public abstract class AbstractFtile implements Ftile { + + private final boolean shadowing; + + public AbstractFtile(boolean shadowing) { + this.shadowing = shadowing; + } + + final public boolean shadowing() { + return shadowing; + } + + public LinkRendering getInLinkRendering() { + return null; + } + + final public LinkRendering getOutLinkRendering() { + return null; + } + + public Collection getInnerConnections() { + return Collections.emptyList(); + } + + public UTranslate getTranslateFor(Ftile child, StringBounder stringBounder) { + throw new UnsupportedOperationException(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/Arrows.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/Arrows.java new file mode 100644 index 000000000..4185869e4 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/Arrows.java @@ -0,0 +1,79 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import net.sourceforge.plantuml.ugraphic.UPolygon; + +public class Arrows { + + final static private double delta1 = 10; + final static private double delta2 = 4; + + public static UPolygon asToUp() { + final UPolygon polygon = new UPolygon(); + polygon.addPoint(-delta2, delta1); + polygon.addPoint(0, 0); + polygon.addPoint(delta2, delta1); + polygon.addPoint(0, delta1 - 4); + return polygon; + } + + public static UPolygon asToDown() { + final UPolygon polygon = new UPolygon(); + polygon.addPoint(-delta2, -delta1); + polygon.addPoint(0, 0); + polygon.addPoint(delta2, -delta1); + polygon.addPoint(0, -delta1 + 4); + return polygon; + } + + public static UPolygon asToRight() { + final UPolygon polygon = new UPolygon(); + polygon.addPoint(-delta1, -delta2); + polygon.addPoint(0, 0); + polygon.addPoint(-delta1, delta2); + polygon.addPoint(-delta1 + 4, 0); + return polygon; + } + + public static UPolygon asToLeft() { + final UPolygon polygon = new UPolygon(); + polygon.addPoint(delta1, -delta2); + polygon.addPoint(0, 0); + polygon.addPoint(delta1, delta2); + polygon.addPoint(delta1 - 4, 0); + return polygon; + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/BoxStyle.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/BoxStyle.java new file mode 100644 index 000000000..0e70c4062 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/BoxStyle.java @@ -0,0 +1,175 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import net.sourceforge.plantuml.graphic.UDrawable; +import net.sourceforge.plantuml.ugraphic.Shadowable; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.UPath; +import net.sourceforge.plantuml.ugraphic.UPolygon; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.USegmentType; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +// Created from Luc Trudeau original work +public enum BoxStyle { + PLAIN { + @Override + protected Shadowable getShape(double width, double height) { + return new URectangle(width, height, CORNER, CORNER); + } + }, + SDL_INPUT('<') { + @Override + protected Shadowable getShape(double width, double height) { + final UPolygon result = new UPolygon(); + result.addPoint(0, 0); + result.addPoint(width + DELTA_INPUT_OUTPUT, 0); + result.addPoint(width, height / 2); + result.addPoint(width + DELTA_INPUT_OUTPUT, height); + result.addPoint(0, height); + return result; + } + }, + SDL_OUTPUT('>') { + @Override + protected Shadowable getShape(double width, double height) { + final UPolygon result = new UPolygon(); + result.addPoint(0.0, 0.0); + result.addPoint(width, 0.0); + result.addPoint(width + DELTA_INPUT_OUTPUT, height / 2); + result.addPoint(width, height); + result.addPoint(0.0, height); + return result; + } + }, + SDL_PROCEDURE('|') { + @Override + protected void drawInternal(UGraphic ug, double width, double height, boolean shadowing) { + final URectangle rect = new URectangle(width, height); + if (shadowing) { + rect.setDeltaShadow(3); + } + ug.draw(rect); + final ULine vline = new ULine(0, height); + ug.apply(new UTranslate(PADDING, 0)).draw(vline); + ug.apply(new UTranslate(width - PADDING, 0)).draw(vline); + } + }, + SDL_SAVE('/') { + @Override + protected Shadowable getShape(double width, double height) { + final UPolygon result = new UPolygon(); + result.addPoint(0.0, 0.0); + result.addPoint(width - DELTA_INPUT_OUTPUT, 0.0); + result.addPoint(width, height); + result.addPoint(DELTA_INPUT_OUTPUT, height); + return result; + } + }, + SDL_CONTINUOUS('}') { + @Override + protected Shadowable getShape(double width, double height) { + final UPath result = new UPath(); + final double c1[] = { DELTA_CONTINUOUS, 0 }; + final double c2[] = { 0, height / 2 }; + final double c3[] = { DELTA_CONTINUOUS, height }; + + result.add(c1, USegmentType.SEG_MOVETO); + result.add(c2, USegmentType.SEG_LINETO); + result.add(c3, USegmentType.SEG_LINETO); + + final double c4[] = { width - DELTA_CONTINUOUS, 0 }; + final double c5[] = { width, height / 2 }; + final double c6[] = { width - DELTA_CONTINUOUS, height }; + + result.add(c4, USegmentType.SEG_MOVETO); + result.add(c5, USegmentType.SEG_LINETO); + result.add(c6, USegmentType.SEG_LINETO); + return result; + } + }, + SDL_TASK(']') { + @Override + protected Shadowable getShape(double width, double height) { + return new URectangle(width, height); + } + }; + + private static final int CORNER = 25; + private final char style; + private static int DELTA_INPUT_OUTPUT = 10; + private static double DELTA_CONTINUOUS = 5.0; + private static int PADDING = 5; + + private BoxStyle() { + this('\0'); + } + + private BoxStyle(char style) { + this.style = style; + } + + public static BoxStyle fromChar(char style) { + for (BoxStyle bs : BoxStyle.values()) { + if (bs.style == style) { + return bs; + } + } + return PLAIN; + } + + public final UDrawable getUDrawable(final double width, final double height, final boolean shadowing) { + return new UDrawable() { + public void drawU(UGraphic ug) { + drawInternal(ug, width, height, shadowing); + } + }; + } + + protected Shadowable getShape(double width, double height) { + return null; + } + + protected void drawInternal(UGraphic ug, double width, double height, boolean shadowing) { + final Shadowable s = getShape(width, height); + if (shadowing) { + s.setDeltaShadow(3); + } + ug.draw(s); + + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/CollisionDetector.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/CollisionDetector.java new file mode 100644 index 000000000..387fdd6ab --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/CollisionDetector.java @@ -0,0 +1,224 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import java.awt.geom.Line2D; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.ugraphic.MinMax; +import net.sourceforge.plantuml.ugraphic.UChange; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.UParam; +import net.sourceforge.plantuml.ugraphic.UParamNull; +import net.sourceforge.plantuml.ugraphic.UPolygon; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UShape; +import net.sourceforge.plantuml.ugraphic.UStroke; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class CollisionDetector implements UGraphic { + + public UGraphic apply(UChange change) { + if (change instanceof UTranslate) { + return new CollisionDetector(stringBounder, translate.compose((UTranslate) change), this.context); + } else if (change instanceof UStroke) { + return new CollisionDetector(this); + } else if (change instanceof UChangeBackColor) { + return new CollisionDetector(this); + } else if (change instanceof UChangeColor) { + return new CollisionDetector(this); + } + throw new UnsupportedOperationException(); + } + + private final StringBounder stringBounder; + private final UTranslate translate; + private final Context context; + + static class Context { + private final List rectangles = new ArrayList(); + private final List snakes = new ArrayList(); + private boolean manageSnakes; + + public void drawDebug(UGraphic ug) { + for (MinMax minmax : rectangles) { + if (collision(minmax)) { + minmax.drawGrey(ug); + } + } + final HtmlColor color = HtmlColorUtils.BLACK; + ug = ug.apply(new UChangeColor(color)).apply(new UStroke(5)); + for (Snake snake : snakes) { + for (Line2D line : snake.getHorizontalLines()) { + if (collision(line)) { + drawLine(ug, line); + } + } + } + } + + private void drawLine(UGraphic ug, Line2D line) { + ug = ug.apply(new UTranslate(line.getX1(), line.getY1())); + ug.draw(new ULine(line.getX2() - line.getX1(), line.getY2() - line.getY1())); + } + + private boolean collision(Line2D hline) { + for (MinMax r : rectangles) { + if (collisionCheck(r, hline)) { + return true; + } + } + return false; + } + + private boolean collision(MinMax r) { + for (Snake snake : snakes) { + for (Line2D hline : snake.getHorizontalLines()) { + if (collisionCheck(r, hline)) { + return true; + } + } + } + return false; + } + + } + + private static boolean collisionCheck(MinMax rect, Line2D hline) { + if (hline.getY1() != hline.getY2()) { + throw new IllegalArgumentException(); + } + if (hline.getY1() < rect.getMinY()) { + return false; + } + if (hline.getY1() > rect.getMaxY()) { + return false; + } + final double x1 = Math.min(hline.getX1(), hline.getX2()); + final double x2 = Math.max(hline.getX1(), hline.getX2()); + if (x2 < rect.getMinX()) { + return false; + } + if (x1 > rect.getMaxX()) { + return false; + } + return true; + } + + public CollisionDetector(StringBounder stringBounder) { + this(stringBounder, new UTranslate(), new Context()); + } + + private CollisionDetector(StringBounder stringBounder, UTranslate translate, Context context) { + this.stringBounder = stringBounder; + this.translate = translate; + this.context = context; + } + + private CollisionDetector(CollisionDetector other) { + this(other.stringBounder, other.translate, other.context); + } + + public StringBounder getStringBounder() { + return stringBounder; + } + + public UParam getParam() { + return new UParamNull(); + } + + public void draw(UShape shape) { + if (shape instanceof UPolygon) { + drawPolygone((UPolygon) shape); + } else if (shape instanceof URectangle) { + drawRectangle((URectangle) shape); + } else if (shape instanceof Snake) { + drawSnake((Snake) shape); + } /* + * else { System.err.println("shape=" + shape.getClass() + " " + shape); } + */ + } + + private void drawSnake(Snake shape) { + if (context.manageSnakes) { + context.snakes.add(shape.translate(translate)); + } + + } + + private void drawRectangle(URectangle shape) { + context.rectangles.add(shape.getMinMax().translate(translate)); + } + + private void drawPolygone(UPolygon shape) { + context.rectangles.add(shape.getMinMax().translate(translate)); + } + + public void writeImage(OutputStream os, String metadata, int dpi) throws IOException { + throw new UnsupportedOperationException(); + } + + public ColorMapper getColorMapper() { + throw new UnsupportedOperationException(); + } + + public void startUrl(Url url) { + } + + public void closeAction() { + } + + public void flushUg() { + } + + public void drawDebug(UGraphic ug) { + context.drawDebug(ug); + } + + public final void setManageSnakes(boolean manageSnakes) { + this.context.manageSnakes = manageSnakes; + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/Connection.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/Connection.java new file mode 100644 index 000000000..22e2a2410 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/Connection.java @@ -0,0 +1,50 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import net.sourceforge.plantuml.graphic.UDrawable; +import net.sourceforge.plantuml.ugraphic.UShape; + + +public interface Connection extends UDrawable, UShape { + + public Ftile getFtile1(); + + // public Position getPosition1(); + + public Ftile getFtile2(); + + // public Position getPosition2(); + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/ConnectionCross.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/ConnectionCross.java new file mode 100644 index 000000000..73e1d4792 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/ConnectionCross.java @@ -0,0 +1,60 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import net.sourceforge.plantuml.ugraphic.UGraphic; + +public class ConnectionCross extends AbstractConnection { + + private final Connection connection; + + public ConnectionCross(Connection connection) { + super(connection.getFtile1(), connection.getFtile2()); + this.connection = connection; + } + + public void drawU(UGraphic ug) { + if (connection instanceof ConnectionTranslatable) { + final Swimlane swimlane1 = getFtile1().getSwimlaneOut(); + final Swimlane swimlane2 = getFtile2().getSwimlaneIn(); + if (swimlane1 == null) { + throw new IllegalStateException("" + getFtile1().getClass()); + } + if (swimlane2 == null) { + throw new IllegalStateException("" + getFtile2().getClass()); + } + ((ConnectionTranslatable) connection).drawTranslate(ug, swimlane1.getTranslate(), swimlane2.getTranslate()); + } + } +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/ConnectionTranslatable.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/ConnectionTranslatable.java new file mode 100644 index 000000000..ef3b1c4f2 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/ConnectionTranslatable.java @@ -0,0 +1,43 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public interface ConnectionTranslatable extends Connection { + + public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2); + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/Diamond.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/Diamond.java new file mode 100644 index 000000000..96e19752a --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/Diamond.java @@ -0,0 +1,91 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import net.sourceforge.plantuml.ugraphic.UPolygon; + +public class Diamond { + + final static public double diamondHalfSize = 12; + + public static UPolygon asPolygon(boolean shadowing) { + final UPolygon diams = new UPolygon(); + + diams.addPoint(diamondHalfSize, 0); + diams.addPoint(diamondHalfSize * 2, diamondHalfSize); + diams.addPoint(diamondHalfSize, diamondHalfSize * 2); + diams.addPoint(0, diamondHalfSize); + diams.addPoint(diamondHalfSize, 0); + + if (shadowing) { + diams.setDeltaShadow(3); + } + + return diams; + } + + public static UPolygon asPolygon(boolean shadowing, double width, double height) { + final UPolygon diams = new UPolygon(); + + diams.addPoint(diamondHalfSize, 0); + diams.addPoint(width - diamondHalfSize, 0); + diams.addPoint(width, height / 2); + diams.addPoint(width - diamondHalfSize, height); + diams.addPoint(diamondHalfSize, height); + diams.addPoint(0, height / 2); + diams.addPoint(diamondHalfSize, 0); + + if (shadowing) { + diams.setDeltaShadow(3); + } + + return diams; + } + + public static UPolygon asPolygonFoo1(boolean shadowing, double width, double height) { + final UPolygon diams = new UPolygon(); + + diams.addPoint(width / 2, 0); + diams.addPoint(width, height / 2); + diams.addPoint(width / 2, height); + diams.addPoint(0, height / 2); + + if (shadowing) { + diams.setDeltaShadow(3); + } + + return diams; + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/EntityImageLegend.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/EntityImageLegend.java new file mode 100644 index 000000000..46b1d2b10 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/EntityImageLegend.java @@ -0,0 +1,128 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 5183 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UPolygon; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class EntityImageLegend implements TextBlock { + + private final int cornersize = 10; + private final HtmlColor noteBackgroundColor; + private final HtmlColor borderColor; + private final int marginX = 6; + private final int marginY = 5; + private final boolean withShadow; + + private final TextBlock textBlock; + + private EntityImageLegend(Display note, ISkinParam skinParam) { + this.withShadow = false; + final Rose rose = new Rose(); + + noteBackgroundColor = rose.getHtmlColor(skinParam, ColorParam.legendBackground); + + borderColor = rose.getHtmlColor(skinParam, ColorParam.legendBorder); + final HtmlColor fontColor = rose.getFontColor(skinParam, FontParam.LEGEND); + final UFont fontNote = skinParam.getFont(FontParam.LEGEND, null); + + this.textBlock = TextBlockUtils.create(note, new FontConfiguration(fontNote, fontColor), + HorizontalAlignment.LEFT, skinParam); + } + + public static TextBlock create(Display legend, ISkinParam skinParam) { + return TextBlockUtils.withMargin(new EntityImageLegend(legend, skinParam), 8, 8); + } + + private double getTextHeight(StringBounder stringBounder) { + final Dimension2D size = textBlock.calculateDimension(stringBounder); + return size.getHeight() + 2 * marginY; + } + + private double getPureTextWidth(StringBounder stringBounder) { + final Dimension2D size = textBlock.calculateDimension(stringBounder); + return size.getWidth(); + } + + private double getTextWidth(StringBounder stringBounder) { + return getPureTextWidth(stringBounder) + 2 * marginX; + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + final double height = getTextHeight(stringBounder); + final double width = getTextWidth(stringBounder); + return new Dimension2DDouble(width + 1, height + 1); + } + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + final UPolygon polygon = getPolygonNormal(stringBounder); + if (withShadow) { + polygon.setDeltaShadow(4); + } + ug = ug.apply(new UChangeBackColor(noteBackgroundColor)).apply(new UChangeColor(borderColor)); + ug.draw(polygon); + textBlock.drawU(ug.apply(new UTranslate(marginX, marginY))); + } + + private UPolygon getPolygonNormal(final StringBounder stringBounder) { + final UPolygon polygon = new UPolygon(); + polygon.addPoint(0, 0); + polygon.addPoint(0, getTextHeight(stringBounder)); + final double width = getTextWidth(stringBounder); + polygon.addPoint(width, getTextHeight(stringBounder)); + polygon.addPoint(width, 0); + polygon.addPoint(0, 0); + return polygon; + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/Ftile.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/Ftile.java new file mode 100644 index 000000000..56adc9b25 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/Ftile.java @@ -0,0 +1,62 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import java.awt.geom.Point2D; +import java.util.Collection; + +import net.sourceforge.plantuml.activitydiagram3.LinkRendering; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlockable; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public interface Ftile extends TextBlockable, Swimable { + + public boolean shadowing(); + + public boolean isKilled(); + + public LinkRendering getInLinkRendering(); + + public LinkRendering getOutLinkRendering(); + + public Point2D getPointIn(StringBounder stringBounder); + + public Point2D getPointOut(StringBounder stringBounder); + + public UTranslate getTranslateFor(Ftile child, StringBounder stringBounder); + + public Collection getInnerConnections(); + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileAssemblySimple.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileAssemblySimple.java new file mode 100644 index 000000000..2261ab7bc --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileAssemblySimple.java @@ -0,0 +1,174 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.activitydiagram3.LinkRendering; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class FtileAssemblySimple implements Ftile { + + private final Ftile tile1; + private final Ftile tile2; + + @Override + public String toString() { + return "FtileAssemblySimple " + tile1 + " && " + tile2; + } + + public FtileAssemblySimple(Ftile tile1, Ftile tile2) { + this.tile1 = tile1; + this.tile2 = tile2; + } + + public Swimlane getSwimlaneIn() { + return tile1.getSwimlaneIn(); + } + + public Swimlane getSwimlaneOut() { + return tile2.getSwimlaneOut(); + } + + + public UTranslate getTranslateFor(Ftile child, StringBounder stringBounder) { + if (child == tile1) { + return getTranslated1(stringBounder); + } + if (child == tile2) { + return getTranslated2(stringBounder); + } + UTranslate tmp = tile1.getTranslateFor(child, stringBounder); + if (tmp != null) { + return tmp.compose(getTranslated1(stringBounder)); + } + tmp = tile2.getTranslateFor(child, stringBounder); + if (tmp != null) { + return tmp.compose(getTranslated2(stringBounder)); + } + throw new UnsupportedOperationException(); + } + + public TextBlock asTextBlock() { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + // final TextBlock textBlock1 = tile1.asTextBlock(); + // final TextBlock textBlock2 = tile2.asTextBlock(); + // textBlock1.drawUNewWayINLINED(ug.apply(getTranslated1(stringBounder))); + // textBlock2.drawUNewWayINLINED(ug.apply(getTranslated2(stringBounder))); + ug.apply(getTranslated1(stringBounder)).draw(tile1); + ug.apply(getTranslated2(stringBounder)).draw(tile2); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + final Dimension2D dim1 = tile1.asTextBlock().calculateDimension(stringBounder); + final Dimension2D dim2 = tile2.asTextBlock().calculateDimension(stringBounder); + return Dimension2DDouble.mergeTB(dim1, dim2); + } + + }; + } + + public boolean isKilled() { + return tile1.isKilled() || tile2.isKilled(); + } + + public LinkRendering getInLinkRendering() { + return tile1.getInLinkRendering(); + } + + public LinkRendering getOutLinkRendering() { + return null; + } + + public Point2D getPointIn(StringBounder stringBounder) { + final UTranslate dx1 = getTranslated1(stringBounder); + final Point2D pt = tile1.getPointIn(stringBounder); + return dx1.getTranslated(pt); + } + + public Point2D getPointOut(StringBounder stringBounder) { + final UTranslate dx2 = getTranslated2(stringBounder); + final Point2D pt = tile2.getPointOut(stringBounder); + if (pt == null) { + return null; + } + return dx2.getTranslated(pt); + } + + private UTranslate getTranslated1(StringBounder stringBounder) { + final Dimension2D dimTotal = asTextBlock().calculateDimension(stringBounder); + final TextBlock textBlock1 = tile1.asTextBlock(); + final Dimension2D dim1 = textBlock1.calculateDimension(stringBounder); + final double dx1 = dimTotal.getWidth() - dim1.getWidth(); + return new UTranslate(dx1 / 2, 0); + } + + private UTranslate getTranslated2(StringBounder stringBounder) { + final Dimension2D dimTotal = asTextBlock().calculateDimension(stringBounder); + final TextBlock textBlock1 = tile1.asTextBlock(); + final TextBlock textBlock2 = tile2.asTextBlock(); + final Dimension2D dim1 = textBlock1.calculateDimension(stringBounder); + final Dimension2D dim2 = textBlock2.calculateDimension(stringBounder); + final double dx2 = dimTotal.getWidth() - dim2.getWidth(); + return new UTranslate(dx2 / 2, dim1.getHeight()); + } + + public Collection getInnerConnections() { + return Collections.emptyList(); + } + + public Set getSwimlanes() { + final Set result = new HashSet(); + result.addAll(tile1.getSwimlanes()); + result.addAll(tile2.getSwimlanes()); + return Collections.unmodifiableSet(result); + } + + public boolean shadowing() { + return tile1.shadowing() || tile2.shadowing(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileEmpty.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileEmpty.java new file mode 100644 index 000000000..6f012c37a --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileEmpty.java @@ -0,0 +1,116 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.Collections; +import java.util.Set; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.ugraphic.UGraphic; + +public class FtileEmpty extends AbstractFtile { + + private final double width; + private final double height; + private final Swimlane swimlaneIn; + private final Swimlane swimlaneOut; + + public FtileEmpty(boolean shadowing, double width, double height) { + this(shadowing, width, height, null, null); + } + + public FtileEmpty(boolean shadowing, double width, double height, Swimlane swimlaneIn, Swimlane swimlaneOut) { + super(shadowing); + this.width = width; + this.height = height; + this.swimlaneIn = swimlaneIn; + this.swimlaneOut = swimlaneOut; + + } + + public FtileEmpty(boolean shadowing) { + this(shadowing, 0, 0, null, null); + } + + public FtileEmpty(boolean shadowing, Swimlane swimlane) { + this(shadowing, 0, 0, swimlane, swimlane); + } + + + @Override + public String toString() { + return "FtileEmpty"; + } + + public TextBlock asTextBlock() { + return new TextBlock() { + + public void drawU(UGraphic ug) { + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return new Dimension2DDouble(width, height); + } + }; + } + + public Point2D getPointIn(StringBounder stringBounder) { + return new Point2D.Double(width / 2, 0); + } + + public Point2D getPointOut(StringBounder stringBounder) { + return new Point2D.Double(width / 2, height); + } + + public boolean isKilled() { + return false; + } + + public Swimlane getSwimlaneIn() { + return swimlaneIn; + } + + public Swimlane getSwimlaneOut() { + return swimlaneOut; + } + + public Set getSwimlanes() { + return Collections.emptySet(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileFactory.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileFactory.java new file mode 100644 index 000000000..bdb65467f --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileFactory.java @@ -0,0 +1,79 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import java.util.List; + +import net.sourceforge.plantuml.SpriteContainer; +import net.sourceforge.plantuml.activitydiagram3.Branch; +import net.sourceforge.plantuml.activitydiagram3.LinkRendering; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.sequencediagram.NotePosition; + +public interface FtileFactory extends SpriteContainer { + + public StringBounder getStringBounder(); + + public boolean shadowing(); + + public Ftile start(Swimlane swimlane); + + public Ftile stop(Swimlane swimlane); + + public Ftile activity(Display label, HtmlColor color, Swimlane swimlane, BoxStyle style); + + public Ftile addNote(Ftile ftile, Display note, NotePosition notePosition); + + public Ftile decorateIn(Ftile ftile, LinkRendering linkRendering); + + public Ftile decorateOut(Ftile ftile, LinkRendering linkRendering); + + public Ftile assembly(Ftile tile1, Ftile tile2); + + public Ftile repeat(Swimlane swimlane, Ftile repeat, Display test); + + public Ftile createWhile(Swimlane swimlane, Ftile whileBlock, Display test, Display yes, Display out, + LinkRendering afterEndwhile); + + public Ftile createIf(Swimlane swimlane, List thens, Branch elseBranch); + + public Ftile createFork(List all); + + public Ftile createSplit(List all); + + public Ftile createGroup(Ftile list, Display name); + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileFactoryDelegator.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileFactoryDelegator.java new file mode 100644 index 000000000..c68e9b465 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileFactoryDelegator.java @@ -0,0 +1,156 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import java.util.List; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.activitydiagram3.Branch; +import net.sourceforge.plantuml.activitydiagram3.LinkRendering; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.sequencediagram.NotePosition; +import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.ugraphic.Sprite; + +public class FtileFactoryDelegator implements FtileFactory { + + private final FtileFactory factory; + private final ISkinParam skinParam; + private final Rose rose = new Rose(); + + protected HtmlColor getInLinkRenderingColor(Ftile tile) { + final HtmlColor color; + final LinkRendering linkRendering = tile.getInLinkRendering(); + if (linkRendering == null || linkRendering.getColor() == null) { + color = rose.getHtmlColor(getSkinParam(), ColorParam.activityArrow); + } else { + color = linkRendering.getColor(); + } + return color; + } + + protected Display getInLinkRenderingDisplay(Ftile tile) { + final LinkRendering linkRendering = tile.getInLinkRendering(); + if (linkRendering == null || linkRendering.getDisplay() == null) { + return null; + } + return linkRendering.getDisplay(); + } + + public FtileFactoryDelegator(FtileFactory factory, ISkinParam skinParam) { + this.factory = factory; + this.skinParam = skinParam; + } + + public Ftile start(Swimlane swimlane) { + return factory.start(swimlane); + } + + public Ftile stop(Swimlane swimlane) { + return factory.stop(swimlane); + } + + public Ftile activity(Display label, HtmlColor color, Swimlane swimlane, BoxStyle style) { + return factory.activity(label, color, swimlane, style); + } + + public Ftile addNote(Ftile ftile, Display note, NotePosition notePosition) { + return factory.addNote(ftile, note, notePosition); + } + + public Ftile decorateIn(Ftile ftile, LinkRendering linkRendering) { + return factory.decorateIn(ftile, linkRendering); + } + + public Ftile decorateOut(Ftile ftile, LinkRendering linkRendering) { + return factory.decorateOut(ftile, linkRendering); + } + + public Ftile assembly(Ftile tile1, Ftile tile2) { + return factory.assembly(tile1, tile2); + } + + public Ftile repeat(Swimlane swimlane, Ftile repeat, Display test) { + return factory.repeat(swimlane, repeat, test); + } + + public Ftile createWhile(Swimlane swimlane, Ftile whileBlock, Display test, Display yes, Display out, + LinkRendering afterEndwhile) { + return factory.createWhile(swimlane, whileBlock, test, yes, out, afterEndwhile); + } + + public Ftile createIf(Swimlane swimlane, List thens, Branch elseBranch) { + return factory.createIf(swimlane, thens, elseBranch); + } + + public Ftile createFork(List all) { + return factory.createFork(all); + } + + public Ftile createSplit(List all) { + return factory.createSplit(all); + } + + public Ftile createGroup(Ftile list, Display name) { + return factory.createGroup(list, name); + } + + public StringBounder getStringBounder() { + return factory.getStringBounder(); + } + + protected final ISkinParam getSkinParam() { + return skinParam; + } + + protected final Rose getRose() { + return rose; + } + + public boolean shadowing() { + return skinParam.shadowing(); + } + + protected FtileFactory getFactory() { + return factory; + } + + public Sprite getSprite(String name) { + return skinParam.getSprite(name); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileHeightFixed.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileHeightFixed.java new file mode 100644 index 000000000..a2d1bae8f --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileHeightFixed.java @@ -0,0 +1,107 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.Set; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class FtileHeightFixed extends AbstractFtile { + + private final Ftile tile; + private final double fixedHeight; + + public FtileHeightFixed(Ftile tile, double fixedHeight) { + super(tile.shadowing()); + this.tile = tile; + this.fixedHeight = fixedHeight; + } + + public Set getSwimlanes() { + return tile.getSwimlanes(); + } + + public Swimlane getSwimlaneIn() { + return tile.getSwimlaneIn(); + } + + public Swimlane getSwimlaneOut() { + return tile.getSwimlaneOut(); + } + + + + public Point2D getPointIn(StringBounder stringBounder) { + final Point2D p = tile.getPointIn(stringBounder); + return getTranslate(stringBounder).getTranslated(p); + } + + public Point2D getPointOut(StringBounder stringBounder) { + final Point2D p = tile.getPointOut(stringBounder); + return getTranslate(stringBounder).getTranslated(p); + } + + private UTranslate getTranslate(StringBounder stringBounder) { + final Dimension2D dim = tile.asTextBlock().calculateDimension(stringBounder); + if (dim.getHeight() > fixedHeight) { + throw new IllegalStateException(); + } + return new UTranslate(0, (fixedHeight - dim.getHeight()) / 2); + } + + public TextBlock asTextBlock() { + return new TextBlock() { + + public void drawU(UGraphic ug) { + ug.apply(getTranslate(ug.getStringBounder())).draw(tile); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + final Dimension2D dim = tile.asTextBlock().calculateDimension(stringBounder); + return new Dimension2DDouble(dim.getWidth(), fixedHeight); + } + }; + } + + public boolean isKilled() { + return tile.isKilled(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileKilled.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileKilled.java new file mode 100644 index 000000000..46dfd5f46 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileKilled.java @@ -0,0 +1,92 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.Set; + +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.ugraphic.UGraphic; + +public class FtileKilled extends AbstractFtile { + + private final Ftile tile; + + public FtileKilled(Ftile tileToKill) { + super(tileToKill.shadowing()); + this.tile = tileToKill; + } + + public Set getSwimlanes() { + return tile.getSwimlanes(); + } + + public Swimlane getSwimlaneIn() { + return tile.getSwimlaneIn(); + } + + public Swimlane getSwimlaneOut() { + return tile.getSwimlaneOut(); + } + + + + public Point2D getPointIn(StringBounder stringBounder) { + return tile.getPointIn(stringBounder); + } + + public Point2D getPointOut(StringBounder stringBounder) { + return null; + } + + public TextBlock asTextBlock() { + return new TextBlock() { + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return tile.asTextBlock().calculateDimension(stringBounder); + } + + public void drawU(UGraphic ug) { + ug.draw(tile); + } + }; + } + + public boolean isKilled() { + return true; + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileMarged.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileMarged.java new file mode 100644 index 000000000..8a9b32536 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileMarged.java @@ -0,0 +1,97 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.Set; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class FtileMarged extends AbstractFtile { + + private final Ftile tile; + private final double marge; + + public FtileMarged(Ftile tile, double marge) { + super(tile.shadowing()); + this.tile = tile; + this.marge = marge; + } + + public Set getSwimlanes() { + return tile.getSwimlanes(); + } + + public Swimlane getSwimlaneIn() { + return tile.getSwimlaneIn(); + } + + public Swimlane getSwimlaneOut() { + return tile.getSwimlaneOut(); + } + + + public Point2D getPointIn(StringBounder stringBounder) { + final Point2D p = tile.getPointIn(stringBounder); + return new UTranslate(marge, 0).getTranslated(p); + } + + public Point2D getPointOut(StringBounder stringBounder) { + final Point2D p = tile.getPointOut(stringBounder); + return new UTranslate(marge, 0).getTranslated(p); + } + + public TextBlock asTextBlock() { + return new TextBlock() { + + public void drawU(UGraphic ug) { + ug.apply(new UTranslate(marge, 0)).draw(tile); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return Dimension2DDouble.delta(tile.asTextBlock().calculateDimension(stringBounder), 2 * marge, 0); + } + }; + } + + public boolean isKilled() { + return tile.isKilled(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileMinWidth.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileMinWidth.java new file mode 100644 index 000000000..f1042a3e2 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileMinWidth.java @@ -0,0 +1,113 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDecorate; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class FtileMinWidth extends FtileDecorate { + + private final double minWidth; + + public FtileMinWidth(Ftile tile, double minWidth) { + super(tile); + this.minWidth = minWidth; + } + + public TextBlock asTextBlock() { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + final UTranslate change = getUTranslateInternal(stringBounder); + FtileMinWidth.super.asTextBlock().drawU(ug.apply(change)); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return getDimensionInternal(stringBounder); + } + }; + } + + private UTranslate getUTranslateInternal(final StringBounder stringBounder) { + final Dimension2D dimTile = getDimension(stringBounder); + final Dimension2D dimTotal = getDimensionInternal(stringBounder); + final UTranslate change = new UTranslate((dimTotal.getWidth() - dimTile.getWidth()) / 2, 0); + return change; + } + + private Dimension2D getDimensionInternal(StringBounder stringBounder) { + final Dimension2D dim = getDimension(stringBounder); + if (dim.getWidth() < minWidth) { + return new Dimension2DDouble(minWidth, dim.getHeight()); + } + return dim; + } + + public UTranslate getTranslateFor(Ftile child, StringBounder stringBounder) { + if (child == getFtileDelegated()) { + return getUTranslateInternal(stringBounder); + } + return null; + } + + private Dimension2D getDimension(StringBounder stringBounder) { + return super.asTextBlock().calculateDimension(stringBounder); + } + + private Point2D getPoint(Point2D pt, StringBounder stringBounder) { + final Dimension2D dim = getDimension(stringBounder); + if (dim.getWidth() < minWidth) { + final double diff = minWidth - dim.getWidth(); + return new Point2D.Double(pt.getX() + diff / 2, pt.getY()); + } + return pt; + } + + public Point2D getPointIn(StringBounder stringBounder) { + return getPoint(super.getPointIn(stringBounder), stringBounder); + } + + public Point2D getPointOut(StringBounder stringBounder) { + return getPoint(super.getPointOut(stringBounder), stringBounder); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileUtils.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileUtils.java new file mode 100644 index 000000000..7a5e84990 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileUtils.java @@ -0,0 +1,52 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import java.util.Collection; + +public class FtileUtils { + + public static Ftile addConnection(Ftile ftile, Connection connection) { + return new FtileWithConnection(ftile, connection); + } + + public static Ftile addConnection(Ftile ftile, Collection connections) { + return new FtileWithConnection(ftile, connections); + } + + public static Ftile withSwimlaneOut(Ftile ftile, Swimlane out) { + return new FtileWithSwimlanes(ftile, ftile.getSwimlaneIn(), out); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileWithConnection.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileWithConnection.java new file mode 100644 index 000000000..e4d7f995b --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileWithConnection.java @@ -0,0 +1,95 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import java.awt.geom.Dimension2D; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDecorate; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.ugraphic.UGraphic; + +class FtileWithConnection extends FtileDecorate { + + private final List connections = new ArrayList(); + + FtileWithConnection(Ftile ftile, Collection connections) { + super(ftile); + if (connections == null || connections.size() == 0) { + throw new IllegalArgumentException(); + } + this.connections.addAll(connections); + } + + @Override + public String toString() { + return super.toString() + " " + connections; + } + + public FtileWithConnection(Ftile ftile, Connection connection) { + this(ftile, Arrays.asList(connection)); + if (connection == null) { + throw new IllegalArgumentException(); + } + } + + public TextBlock asTextBlock() { + final TextBlock original = super.asTextBlock(); + return new TextBlock() { + + public void drawU(UGraphic ug) { + original.drawU(ug); + for (Connection c : connections) { + ug.draw(c); + } + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return original.calculateDimension(stringBounder); + } + }; + } + + public Collection getInnerConnections() { + final List result = new ArrayList(super.getInnerConnections()); + result.addAll(connections); + return Collections.unmodifiableList(connections); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileWithSwimlanes.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileWithSwimlanes.java new file mode 100644 index 000000000..812945ade --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/FtileWithSwimlanes.java @@ -0,0 +1,59 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDecorate; + +class FtileWithSwimlanes extends FtileDecorate { + + private final Swimlane in; + private final Swimlane out; + + FtileWithSwimlanes(Ftile ftile, Swimlane in, Swimlane out) { + super(ftile); + this.in = in; + this.out = out; + } + + @Override + public Swimlane getSwimlaneIn() { + return in; + } + + @Override + public Swimlane getSwimlaneOut() { + return out; + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/Snake.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/Snake.java new file mode 100644 index 000000000..d826f7a08 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/Snake.java @@ -0,0 +1,232 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Line2D; +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.UPolygon; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UShape; +import net.sourceforge.plantuml.ugraphic.UStroke; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class Snake implements UShape { + + private final List points = new ArrayList(); + private final UPolygon endDecoration; + private final HtmlColor color; + private final boolean mergeable; + private TextBlock textBlock; + + public Snake(HtmlColor color, UPolygon endDecoration, boolean mergeable) { + this.endDecoration = endDecoration; + this.color = color; + this.mergeable = mergeable; + } + + public void setLabel(TextBlock label) { + this.textBlock = label; + } + + public Snake move(double dx, double dy) { + final Snake result = new Snake(color, endDecoration, mergeable); + for (Point2D pt : points) { + result.addPoint(pt.getX() + dx, pt.getY() + dy); + } + result.textBlock = this.textBlock; + return result; + } + + public Snake translate(UTranslate translate) { + return move(translate.getDx(), translate.getDy()); + } + + @Override + public String toString() { + return points.toString(); + } + + SnakeDirection getDirection() { + if (points.size() < 2) { + throw new IllegalStateException(); + } + return SnakeDirection.getDirection(points.get(0), points.get(1)); + } + + public Snake(HtmlColor color, UPolygon endDecoration) { + this(color, endDecoration, false); + } + + public Snake(HtmlColor color) { + this(color, null, false); + } + + public Snake(HtmlColor color, boolean mergeable) { + this(color, null, mergeable); + } + + public void addPoint(double x, double y) { + if (mergeable && this.points.size() == 3) { + final SnakeDirection direction = getDirection(); + final Point2D first = this.points.get(0); + this.points.remove(2); + this.points.remove(1); + if (direction == SnakeDirection.VERTICAL_THEN_HORIZONTAL) { + this.points.add(new Point2D.Double(first.getX(), y)); + } else { + this.points.add(new Point2D.Double(x, first.getY())); + } + + } + this.points.add(new Point2D.Double(x, y)); + } + + public void addPoint(Point2D p) { + addPoint(p.getX(), p.getY()); + } + + public void drawInternal(UGraphic ug) { + ug = ug.apply(new UChangeColor(color)); + ug = ug.apply(new UStroke(1.5)); + for (int i = 0; i < points.size() - 1; i++) { + final Line2D line = new Line2D.Double(points.get(i), points.get(i + 1)); + drawLine(ug, line); + } + if (endDecoration != null) { + ug = ug.apply(new UChangeBackColor(color)); + final Point2D end = points.get(points.size() - 1); + ug.apply(new UTranslate(end)).apply(new UStroke()).draw(endDecoration); + } + if (textBlock != null) { + final Point2D position = getTextBlockPosition(ug.getStringBounder()); + // double max = getMaxX(ug.getStringBounder()); + // ug.apply(new UChangeBackColor(HtmlColorUtils.LIGHT_GRAY)).apply(new UTranslate(0, + // position.getY())).draw(new URectangle(max, 10)); + textBlock.drawU(ug.apply(new UTranslate(position))); + } + } + + public double getMaxX(StringBounder stringBounder) { + double result = -Double.MAX_VALUE; + for (Point2D pt : points) { + result = Math.max(result, pt.getX()); + } + if (textBlock != null) { + final Point2D position = getTextBlockPosition(stringBounder); + final Dimension2D dim = textBlock.calculateDimension(stringBounder); + result = Math.max(result, position.getX() + dim.getWidth()); + } + return result; + } + + private Point2D getTextBlockPosition(StringBounder stringBounder) { + final Point2D pt1 = points.get(0); + final Point2D pt2 = points.get(1); + final Dimension2D dim = textBlock.calculateDimension(stringBounder); + final double y = (pt1.getY() + pt2.getY()) / 2 - dim.getHeight() / 2; + return new Point2D.Double(Math.max(pt1.getX(), pt2.getX()) + 4, y); + } + + public List getHorizontalLines() { + final List result = new ArrayList(); + for (int i = 0; i < points.size() - 1; i++) { + final Point2D pt1 = points.get(i); + final Point2D pt2 = points.get(i + 1); + if (pt1.getY() == pt2.getY()) { + final Line2D line = new Line2D.Double(pt1, pt2); + result.add(line); + } + } + return result; + + } + + private Point2D getFirst() { + return points.get(0); + } + + public Point2D getLast() { + return points.get(points.size() - 1); + } + + private boolean same(Point2D pt1, Point2D pt2) { + return pt1.getX() == pt2.getX() && pt1.getY() == pt2.getY(); + } + + public Snake merge(Snake other) { + if (same(this.getLast(), other.getFirst())) { + final Snake result = new Snake(color, endDecoration, mergeable); + result.addPoint(getFirst()); + result.addPoint(getFirst().getX(), other.getLast().getY()); + result.addPoint(other.getLast()); + result.textBlock = this.textBlock; + return result; + } + if (same(this.getFirst(), other.getLast())) { + throw new UnsupportedOperationException(); + // final Snake result = new Snake(color, endDecoration, mergeable); + // result.addPoint(getFirst()); + // result.addPoint(getFirst().getX(), other.getLast().getY()); + // result.addPoint(other.getLast()); + // return result; + } + return null; + } + + private void drawLine(UGraphic ug, Line2D line) { + drawLine(ug, line.getX1(), line.getY1(), line.getX2(), line.getY2()); + } + + private void drawLine(UGraphic ug, double x1, double y1, double x2, double y2) { + ug = ug.apply(new UTranslate(x1, y1)); + ug.draw(new ULine(x2 - x1, y2 - y1)); + } + + public final boolean isMergeable() { + return mergeable; + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/SnakeDirection.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/SnakeDirection.java new file mode 100644 index 000000000..5950ee0dc --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/SnakeDirection.java @@ -0,0 +1,51 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import java.awt.geom.Point2D; + +public enum SnakeDirection { + VERTICAL_THEN_HORIZONTAL, HORIZONTAL_THEN_VERTICAL; + + public static SnakeDirection getDirection(Point2D pt1, Point2D pt2) { + if (pt1.getX() == pt2.getX()) { + return VERTICAL_THEN_HORIZONTAL; + } + if (pt1.getY() == pt2.getY()) { + return HORIZONTAL_THEN_VERTICAL; + } + throw new IllegalArgumentException(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/Swimable.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/Swimable.java new file mode 100644 index 000000000..5bff274ac --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/Swimable.java @@ -0,0 +1,46 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import java.util.Set; + +public interface Swimable { + + public Set getSwimlanes(); + + public Swimlane getSwimlaneIn(); + + public Swimlane getSwimlaneOut(); + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/Swimlane.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/Swimlane.java new file mode 100644 index 000000000..656b09943 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/Swimlane.java @@ -0,0 +1,94 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import net.sourceforge.plantuml.SpecificBackcolorable; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class Swimlane implements SpecificBackcolorable { + + private final String name; + private HtmlColor color; + private Display display; + + private UTranslate translate = new UTranslate(); + private double totalWidth; + + public Swimlane(String name) { + this.name = name; + this.display = Display.getWithNewlines(name); + + } + + @Override + public String toString() { + return name; + } + + public String getName() { + return name; + } + + public Display getDisplay() { + return display; + } + + public void setDisplay(Display label) { + this.display = label; + } + + public final UTranslate getTranslate() { + return translate; + } + + public final void setTranslateAndWidth(UTranslate translate, double totalWidth) { + this.translate = translate; + this.totalWidth = totalWidth; + } + + public HtmlColor getSpecificBackColor() { + return color; + } + + public void setSpecificBackcolor(HtmlColor specificBackcolor) { + this.color = specificBackcolor; + } + + public final double getTotalWidth() { + return totalWidth; + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/Swimlanes.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/Swimlanes.java new file mode 100644 index 000000000..e4bd1efdc --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/Swimlanes.java @@ -0,0 +1,306 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile; + +import java.awt.geom.Dimension2D; +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.activitydiagram3.Instruction; +import net.sourceforge.plantuml.activitydiagram3.InstructionList; +import net.sourceforge.plantuml.activitydiagram3.LinkRendering; +import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.FtileFactoryDelegatorAddNote; +import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.FtileFactoryDelegatorAssembly; +import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.FtileFactoryDelegatorCreateFork; +import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.FtileFactoryDelegatorCreateGroup; +import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.FtileFactoryDelegatorCreateSplit; +import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.FtileFactoryDelegatorIf; +import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.FtileFactoryDelegatorRepeat; +import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.FtileFactoryDelegatorWhile; +import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.UGraphicInterceptorOneSwimlane; +import net.sourceforge.plantuml.activitydiagram3.ftile.vcompact.VCompactFactory; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockInterceptorTextBlockable; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.graphic.UGraphicDelegator; +import net.sourceforge.plantuml.svek.UGraphicForSnake; +import net.sourceforge.plantuml.ugraphic.LimitFinder; +import net.sourceforge.plantuml.ugraphic.MinMax; +import net.sourceforge.plantuml.ugraphic.UChange; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UShape; +import net.sourceforge.plantuml.ugraphic.UStroke; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class Swimlanes implements TextBlock { + + private final ISkinParam skinParam;; + + private final List swinlanes = new ArrayList(); + private final FontConfiguration fontConfiguration; + private Swimlane currentSwimlane = null; + + private final Instruction root = new InstructionList(); + private Instruction currentInstruction = root; + + private LinkRendering nextLinkRenderer; + + public Swimlanes(ISkinParam skinParam) { + this.skinParam = skinParam; + final UFont font = skinParam.getFont(FontParam.TITLE, null); + this.fontConfiguration = new FontConfiguration(font, HtmlColorUtils.BLACK); + + } + + private FtileFactory getFtileFactory() { + FtileFactory factory = new VCompactFactory(skinParam, TextBlockUtils.getDummyStringBounder()); + factory = new FtileFactoryDelegatorAssembly(factory, skinParam); + factory = new FtileFactoryDelegatorIf(factory, skinParam); + factory = new FtileFactoryDelegatorWhile(factory, skinParam); + factory = new FtileFactoryDelegatorRepeat(factory, skinParam); + factory = new FtileFactoryDelegatorCreateFork(factory, skinParam); + factory = new FtileFactoryDelegatorCreateSplit(factory, skinParam); + factory = new FtileFactoryDelegatorAddNote(factory, skinParam); + factory = new FtileFactoryDelegatorCreateGroup(factory, skinParam); + return factory; + } + + public void swimlane(String name, HtmlColor color, Display label) { + currentSwimlane = getOrCreate(name); + if (color != null) { + currentSwimlane.setSpecificBackcolor(color); + } + if (label != null) { + currentSwimlane.setDisplay(label); + } + } + + private Swimlane getOrCreate(String name) { + for (Swimlane s : swinlanes) { + if (s.getName().equals(name)) { + return s; + } + } + final Swimlane result = new Swimlane(name); + swinlanes.add(result); + return result; + } + + class Cross extends UGraphicDelegator { + + private Cross(UGraphic ug) { + super(ug); + } + + @Override + public void draw(UShape shape) { + if (shape instanceof Ftile) { + final Ftile tile = (Ftile) shape; + tile.asTextBlock().drawU(this); + } else if (shape instanceof Connection) { + final Connection connection = (Connection) shape; + final Ftile tile1 = connection.getFtile1(); + final Ftile tile2 = connection.getFtile2(); + + if (tile1 == null || tile2 == null) { + return; + } + final Swimlane swimlane1 = tile1.getSwimlaneOut(); + final Swimlane swimlane2 = tile2.getSwimlaneIn(); + if (swimlane1 != swimlane2) { + final ConnectionCross connectionCross = new ConnectionCross(connection); + connectionCross.drawU(getUg()); + } + } + } + + public UGraphic apply(UChange change) { + return new Cross(getUg().apply(change)); + } + + } + + static final double separationMargin = 10; + + public void drawU(UGraphic ug) { + final FtileFactory factory = getFtileFactory(); + TextBlock full = root.createFtile(factory).asTextBlock(); + ug = new UGraphicForSnake(ug); + if (swinlanes.size() <= 1) { + full = new TextBlockInterceptorTextBlockable(full); + // BUG42 + // full.drawU(ug); + full.drawU(ug); + ug.flushUg(); + return; + } + + final StringBounder stringBounder = ug.getStringBounder(); + final Dimension2D dimensionFull = full.calculateDimension(stringBounder); + + final UTranslate titleHeightTranslate = getTitleHeightTranslate(stringBounder); + + computeSize(ug, full); + + double x2 = 0; + for (Swimlane swimlane : swinlanes) { + if (swimlane.getSpecificBackColor() != null) { + final UGraphic background = ug.apply(new UChangeBackColor(swimlane.getSpecificBackColor())) + .apply(new UChangeColor(swimlane.getSpecificBackColor())).apply(new UTranslate(x2, 0)); + background.draw(new URectangle(swimlane.getTotalWidth(), dimensionFull.getHeight() + + titleHeightTranslate.getDy())); + } + + final TextBlock swTitle = TextBlockUtils.create(swimlane.getDisplay(), fontConfiguration, + HorizontalAlignment.LEFT, skinParam); + final double titleWidth = swTitle.calculateDimension(stringBounder).getWidth(); + final double posTitle = x2 + (swimlane.getTotalWidth() - titleWidth) / 2; + swTitle.drawU(ug.apply(new UTranslate(posTitle, 0))); + + drawSeparation(ug.apply(new UTranslate(x2, 0)), dimensionFull.getHeight() + titleHeightTranslate.getDy()); + + full.drawU(new UGraphicInterceptorOneSwimlane(ug, swimlane).apply(swimlane.getTranslate()).apply( + titleHeightTranslate)); + x2 += swimlane.getTotalWidth(); + + } + drawSeparation(ug.apply(new UTranslate(x2, 0)), dimensionFull.getHeight() + titleHeightTranslate.getDy()); + final Cross cross = new Cross(ug.apply(titleHeightTranslate)); + full.drawU(cross); + cross.flushUg(); + + // getCollisionDetector(ug, titleHeightTranslate).drawDebug(ug); + } + + private void computeSize(UGraphic ug, TextBlock full) { + double x1 = 0; + final StringBounder stringBounder = ug.getStringBounder(); + for (Swimlane swimlane : swinlanes) { + + final LimitFinder limitFinder = new LimitFinder(stringBounder, false); + final UGraphicInterceptorOneSwimlane interceptor = new UGraphicInterceptorOneSwimlane(new UGraphicForSnake( + limitFinder), swimlane); + full.drawU(interceptor); + interceptor.flushUg(); + final MinMax minMax = limitFinder.getMinMax(); + + final double drawingWidth = minMax.getWidth() + 2 * separationMargin; + final TextBlock swTitle = TextBlockUtils.create(swimlane.getDisplay(), fontConfiguration, + HorizontalAlignment.LEFT, skinParam); + final double titleWidth = swTitle.calculateDimension(stringBounder).getWidth(); + final double totalWidth = Math.max(drawingWidth, titleWidth + 2 * separationMargin); + + final UTranslate translate = new UTranslate(x1 - minMax.getMinX() + separationMargin + + (totalWidth - drawingWidth) / 2.0, 0); + swimlane.setTranslateAndWidth(translate, totalWidth); + + x1 += totalWidth; + } + } + + private UTranslate getTitleHeightTranslate(final StringBounder stringBounder) { + double titlesHeight = 0; + for (Swimlane swimlane : swinlanes) { + final TextBlock swTitle = TextBlockUtils.create(swimlane.getDisplay(), fontConfiguration, + HorizontalAlignment.LEFT, skinParam); + + titlesHeight = Math.max(titlesHeight, swTitle.calculateDimension(stringBounder).getHeight()); + } + final UTranslate titleHeightTranslate = new UTranslate(0, titlesHeight); + return titleHeightTranslate; + } + + private CollisionDetector getCollisionDetector(UGraphic ug, final UTranslate titleHeightTranslate) { + final FtileFactory factory = getFtileFactory(); + final TextBlock full = root.createFtile(factory).asTextBlock(); + ug = new UGraphicForSnake(ug); + + final CollisionDetector collisionDetector = new CollisionDetector(ug.getStringBounder()); + + for (Swimlane swimlane : swinlanes) { + full.drawU(new UGraphicInterceptorOneSwimlane(collisionDetector, swimlane).apply(swimlane.getTranslate()) + .apply(titleHeightTranslate)); + } + + collisionDetector.setManageSnakes(true); + final Cross cross = new Cross(collisionDetector.apply(titleHeightTranslate)); + full.drawU(cross); + cross.flushUg(); + + return collisionDetector; + } + + private void drawSeparation(UGraphic ug, double height) { + ug.apply(new UStroke(2)).apply(new UChangeColor(HtmlColorUtils.BLACK)).draw(new ULine(0, height)); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return TextBlockUtils.getMinMax(this, stringBounder).getDimension(); + } + + public Instruction getCurrent() { + return currentInstruction; + } + + public void setCurrent(Instruction current) { + this.currentInstruction = current; + } + + public LinkRendering nextLinkRenderer() { + return nextLinkRenderer; + } + + public void setNextLinkRenderer(LinkRendering link) { + this.nextLinkRenderer = link; + } + + public Swimlane getCurrentSwimlane() { + return currentSwimlane; + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/ConnectionVerticalDown.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/ConnectionVerticalDown.java new file mode 100644 index 000000000..9a5e0f6fe --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/ConnectionVerticalDown.java @@ -0,0 +1,99 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact; + +import java.awt.geom.Point2D; + +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractConnection; +import net.sourceforge.plantuml.activitydiagram3.ftile.Arrows; +import net.sourceforge.plantuml.activitydiagram3.ftile.ConnectionTranslatable; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.Snake; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class ConnectionVerticalDown extends AbstractConnection implements ConnectionTranslatable { + + private final Point2D p1; + private final Point2D p2; + private final HtmlColor color; + private final TextBlock textBlock; + + public ConnectionVerticalDown(Ftile ftile1, Ftile ftile2, Point2D p1, Point2D p2, HtmlColor color, + TextBlock textBlock) { + super(ftile1, ftile2); + this.p1 = p1; + this.p2 = p2; + this.color = color; + this.textBlock = textBlock; + } + + public void drawU(UGraphic ug) { + ug.draw(getSimpleSnake()); + } + + public double getMaxX(StringBounder stringBounder) { + return getSimpleSnake().getMaxX(stringBounder); + } + + private Snake getSimpleSnake() { + final Snake snake = new Snake(color, Arrows.asToDown()); + snake.setLabel(textBlock); + snake.addPoint(p1); + snake.addPoint(p2); + return snake; + } + + public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { + final Snake snake = new Snake(color, true); + final Point2D mp1a = translate1.getTranslated(p1); + final Point2D mp2b = translate2.getTranslated(p2); + final double middle = (mp1a.getY() + mp2b.getY()) / 2.0; + snake.addPoint(mp1a); + snake.addPoint(mp1a.getX(), middle); + snake.addPoint(mp2b.getX(), middle); + // snake.addPoint(mp2b); + ug.draw(snake); + + final Snake small = new Snake(color, Arrows.asToDown()); + small.addPoint(mp2b.getX(), middle); + small.addPoint(mp2b); + ug.draw(small); + + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorAddNote.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorAddNote.java new file mode 100644 index 000000000..de9bfec00 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorAddNote.java @@ -0,0 +1,69 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.activitydiagram3.LinkRendering; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactoryDelegator; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.sequencediagram.NotePosition; +import net.sourceforge.plantuml.skin.rose.Rose; + +public class FtileFactoryDelegatorAddNote extends FtileFactoryDelegator { + + private final Rose rose = new Rose(); + + public FtileFactoryDelegatorAddNote(FtileFactory factory, ISkinParam skinParam) { + super(factory, skinParam); + } + + @Override + public Ftile addNote(Ftile ftile, Display note, NotePosition notePosition) { + if (note == null) { + throw new IllegalArgumentException(); + } + final HtmlColor colorlink; + final LinkRendering inlinkRendering = ftile.getInLinkRendering(); + if (inlinkRendering == null || inlinkRendering.getColor() == null) { + colorlink = rose.getHtmlColor(getSkinParam(), ColorParam.activityArrow); + } else { + colorlink = inlinkRendering.getColor(); + } + return new FtileWithNoteOpale(ftile, note, colorlink, notePosition); + } +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorAssembly.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorAssembly.java new file mode 100644 index 000000000..83984c57d --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorAssembly.java @@ -0,0 +1,112 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact; + +import java.awt.geom.Point2D; + +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileEmpty; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactoryDelegator; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileMinWidth; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileUtils; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class FtileFactoryDelegatorAssembly extends FtileFactoryDelegator { + + public FtileFactoryDelegatorAssembly(FtileFactory factory, ISkinParam skinParam) { + super(factory, skinParam); + } + + @Override + public Ftile assembly(final Ftile tile1, final Ftile tile2) { + double height = 35; + final TextBlock textBlock = getTextBlock(getInLinkRenderingDisplay(tile2)); + final StringBounder stringBounder = getStringBounder(); + if (textBlock != null) { + height += textBlock.calculateDimension(stringBounder).getHeight(); + } + final Ftile space = new FtileEmpty(getFactory().shadowing(), 1, height); + final Ftile tile1andSpace = super.assembly(tile1, space); + Ftile result = super.assembly(tile1andSpace, tile2); + final UTranslate translate1 = result.getTranslateFor(tile1, stringBounder); + final Point2D pointOut = tile1.getPointOut(stringBounder); + if (pointOut == null) { + return result; + } + final Point2D p1 = translate1.getTranslated(pointOut); + final UTranslate translate2 = result.getTranslateFor(tile2, stringBounder); + final Point2D p2 = translate2.getTranslated(tile2.getPointIn(stringBounder)); + + final HtmlColor color = getInLinkRenderingColor(tile2); + + final ConnectionVerticalDown connection = new ConnectionVerticalDown(tile1, tile2, p1, p2, color, textBlock); + result = FtileUtils.addConnection(result, connection); + if (textBlock != null) { + final double width = result.asTextBlock().calculateDimension(stringBounder).getWidth(); + // System.err.println("width=" + width); + // System.err.println("p1=" + p1); + // System.err.println("p2=" + p2); + final double maxX = connection.getMaxX(stringBounder); + // System.err.println("maxX=" + maxX); + final double needed = (maxX - width) * 2; + result = new FtileMinWidth(result, needed); + } + return result; + } + + private final Rose rose = new Rose(); + + private TextBlock getTextBlock(Display display) { + if (display == null) { + return null; + } + final ISkinParam skinParam = getSkinParam(); + final UFont font = skinParam.getFont(FontParam.ACTIVITY_ARROW2, null); + final HtmlColor color = rose.getFontColor(skinParam, FontParam.ACTIVITY_ARROW2); + final FontConfiguration fontConfiguration = new FontConfiguration(font, color); + return TextBlockUtils.create(display, fontConfiguration, HorizontalAlignment.LEFT, null); + } +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorCreateFork.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorCreateFork.java new file mode 100644 index 000000000..6f9d1b8bd --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorCreateFork.java @@ -0,0 +1,150 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractConnection; +import net.sourceforge.plantuml.activitydiagram3.ftile.Arrows; +import net.sourceforge.plantuml.activitydiagram3.ftile.Connection; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileAssemblySimple; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactoryDelegator; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileHeightFixed; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileMarged; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileUtils; +import net.sourceforge.plantuml.activitydiagram3.ftile.Snake; +import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileBlackBlock; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class FtileFactoryDelegatorCreateFork extends FtileFactoryDelegator { + + private final double spaceArroundBlackBar = 20; + private final double barHeight = 6; + private final double xMargin = 14; + + private final Rose rose = new Rose(); + + public FtileFactoryDelegatorCreateFork(FtileFactory factory, ISkinParam skinParam) { + super(factory, skinParam); + } + + @Override + public Ftile createFork(List all) { + final HtmlColor colorBar = rose.getHtmlColor(getSkinParam(), ColorParam.activityBar); + final HtmlColor arrowColor = rose.getHtmlColor(getSkinParam(), ColorParam.activityArrow); + + final Dimension2D dimSuper = super.createFork(all).asTextBlock().calculateDimension(getStringBounder()); + final double height1 = dimSuper.getHeight() + 2 * spaceArroundBlackBar; + + final List list = new ArrayList(); + for (Ftile tmp : all) { + list.add(new FtileHeightFixed(new FtileMarged(tmp, xMargin), height1)); + } + + Ftile inner = super.createFork(list); + + final List conns = new ArrayList(); + + double x = 0; + for (Ftile tmp : list) { + final Dimension2D dim = tmp.asTextBlock().calculateDimension(getStringBounder()); + conns.add(new ConnectionIn(tmp, x, arrowColor)); + conns.add(new ConnectionOut(tmp, x, arrowColor, height1)); + x += dim.getWidth(); + } + + inner = FtileUtils.addConnection(inner, conns); + final Ftile black = new FtileBlackBlock(shadowing(), inner.asTextBlock().calculateDimension(getStringBounder()) + .getWidth(), barHeight, colorBar, list.get(0).getSwimlaneIn()); + return new FtileAssemblySimple(new FtileAssemblySimple(black, inner), black); + } + + class ConnectionIn extends AbstractConnection { + + private final double x; + private final HtmlColor arrowColor; + + public ConnectionIn(Ftile tmp, double x, HtmlColor arrowColor) { + super(null, tmp); + this.x = x; + this.arrowColor = arrowColor; + } + + public void drawU(UGraphic ug) { + ug = ug.apply(new UTranslate(x, 0)); + final Point2D p = getFtile2().getPointIn(getStringBounder()); + final Snake s = new Snake(arrowColor, Arrows.asToDown()); + s.addPoint(p.getX(), 0); + s.addPoint(p.getX(), p.getY()); + ug.draw(s); + } + } + + class ConnectionOut extends AbstractConnection { + + private final double x; + private final HtmlColor arrowColor; + private final double height; + + public ConnectionOut(Ftile tmp, double x, HtmlColor arrowColor, double height) { + super(tmp, null); + this.x = x; + this.arrowColor = arrowColor; + this.height = height; + } + + public void drawU(UGraphic ug) { + ug = ug.apply(new UTranslate(x, 0)); + final Point2D p = getFtile1().getPointOut(getStringBounder()); + if (p == null) { + return; + } + final Snake s = new Snake(arrowColor, Arrows.asToDown()); + s.addPoint(p.getX(), p.getY()); + s.addPoint(p.getX(), height); + ug.draw(s); + } + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorCreateFork2.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorCreateFork2.java new file mode 100644 index 000000000..188da80b7 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorCreateFork2.java @@ -0,0 +1,159 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractConnection; +import net.sourceforge.plantuml.activitydiagram3.ftile.Arrows; +import net.sourceforge.plantuml.activitydiagram3.ftile.Connection; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileAssemblySimple; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactoryDelegator; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileHeightFixed; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileMarged; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileUtils; +import net.sourceforge.plantuml.activitydiagram3.ftile.Snake; +import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileBlackBlock; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class FtileFactoryDelegatorCreateFork2 extends FtileFactoryDelegator { + + private final double spaceArroundBlackBar = 20; + private final double barHeight = 6; + private final double xMargin = 14; + + private final Rose rose = new Rose(); + + public FtileFactoryDelegatorCreateFork2(FtileFactory factory, ISkinParam skinParam) { + super(factory, skinParam); + } + + @Override + public Ftile createFork(List all) { + final HtmlColor colorBar = rose.getHtmlColor(getSkinParam(), ColorParam.activityBar); + final HtmlColor arrowColor = rose.getHtmlColor(getSkinParam(), ColorParam.activityArrow); + + final Dimension2D dimSuper = super.createFork(all).asTextBlock().calculateDimension(getStringBounder()); + final double height1 = dimSuper.getHeight() + 2 * spaceArroundBlackBar; + + final List list = new ArrayList(); + for (Ftile tmp : all) { + list.add(new FtileHeightFixed(new FtileMarged(tmp, xMargin), height1)); + } + + final Ftile inner = super.createFork(list); + + final List conns1 = new ArrayList(); + final List conns2 = new ArrayList(); + + double x = 0; + for (Ftile tmp : list) { + final Dimension2D dim = tmp.asTextBlock().calculateDimension(getStringBounder()); + conns1.add(new ConnectionIn(tmp, x, arrowColor, barHeight)); + conns2.add(new ConnectionOut(tmp, x, arrowColor, height1)); + x += dim.getWidth(); + } + + Ftile black1 = new FtileBlackBlock(shadowing(), inner.asTextBlock().calculateDimension(getStringBounder()) + .getWidth(), barHeight, colorBar, list.get(0).getSwimlaneIn()); + black1 = FtileUtils.addConnection(black1, conns1); + + Ftile black2 = new FtileBlackBlock(shadowing(), inner.asTextBlock().calculateDimension(getStringBounder()) + .getWidth(), barHeight, colorBar, list.get(0).getSwimlaneIn()); + // black2 = FtileUtils.addConnection(black2, conns2); + + // return new FtileAssemblySimple(black1, inner); + return new FtileAssemblySimple(new FtileAssemblySimple(black1, inner), black2); + } + + class ConnectionIn extends AbstractConnection { + + private final double x; + private final HtmlColor arrowColor; + private final double barHeight; + + public ConnectionIn(Ftile tmp, double x, HtmlColor arrowColor, double barHeight) { + super(null, tmp); + this.x = x; + this.arrowColor = arrowColor; + this.barHeight = barHeight; + } + + public void drawU(UGraphic ug) { + ug = ug.apply(new UTranslate(x, barHeight)); + final Point2D p = getFtile2().getPointIn(getStringBounder()); + final Snake s = new Snake(arrowColor, Arrows.asToDown()); + s.addPoint(p.getX(), 0); + s.addPoint(p.getX(), p.getY()); + ug.draw(s); + } + } + + class ConnectionOut extends AbstractConnection { + + private final double x; + private final HtmlColor arrowColor; + private final double height; + + public ConnectionOut(Ftile tmp, double x, HtmlColor arrowColor, double height) { + super(tmp, null); + this.x = x; + this.arrowColor = arrowColor; + this.height = height; + } + + public void drawU(UGraphic ug) { + ug = ug.apply(new UTranslate(x, 0)); + final Point2D p = getFtile1().getPointOut(getStringBounder()); + if (p == null) { + return; + } + final Snake s = new Snake(arrowColor, Arrows.asToDown()); + s.addPoint(p.getX(), p.getY()); + s.addPoint(p.getX(), height); + ug.draw(s); + } + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorCreateGroup.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorCreateGroup.java new file mode 100644 index 000000000..a3c4addc9 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorCreateGroup.java @@ -0,0 +1,59 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactoryDelegator; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.skin.rose.Rose; + +public class FtileFactoryDelegatorCreateGroup extends FtileFactoryDelegator { + + private final Rose rose = new Rose(); + + public FtileFactoryDelegatorCreateGroup(FtileFactory factory, ISkinParam skinParam) { + super(factory, skinParam); + } + + @Override + public Ftile createGroup(Ftile list, Display name) { + final HtmlColor arrowColor = rose.getHtmlColor(getSkinParam(), ColorParam.activityArrow); + return new FtileGroup(list, name, arrowColor, this); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorCreateSplit.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorCreateSplit.java new file mode 100644 index 000000000..1f4644a16 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorCreateSplit.java @@ -0,0 +1,194 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractConnection; +import net.sourceforge.plantuml.activitydiagram3.ftile.Arrows; +import net.sourceforge.plantuml.activitydiagram3.ftile.Connection; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactoryDelegator; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileHeightFixed; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileMarged; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileUtils; +import net.sourceforge.plantuml.activitydiagram3.ftile.Snake; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class FtileFactoryDelegatorCreateSplit extends FtileFactoryDelegator { + + private final double spaceArroundBlackBar = 20; + private final double barHeight = 6; + private final double xMargin = 14; + + private final Rose rose = new Rose(); + + public FtileFactoryDelegatorCreateSplit(FtileFactory factory, ISkinParam skinParam) { + super(factory, skinParam); + } + + @Override + public Ftile createSplit(List all) { + // final HtmlColor colorBar = rose.getHtmlColor(getSkinParam(), ColorParam.activityBar); + final HtmlColor arrowColor = rose.getHtmlColor(getSkinParam(), ColorParam.activityArrow); + + final Dimension2D dimSuper = super.createSplit(all).asTextBlock().calculateDimension(getStringBounder()); + final double height1 = dimSuper.getHeight() + 2 * spaceArroundBlackBar; + + final List list = new ArrayList(); + for (Ftile tmp : all) { + list.add(new FtileHeightFixed(new FtileMarged(tmp, xMargin), height1)); + } + + Ftile inner = super.createSplit(list); + + final List conns = new ArrayList(); + + double x = 0; + for (Ftile tmp : list) { + final Dimension2D dim = tmp.asTextBlock().calculateDimension(getStringBounder()); + conns.add(new ConnectionIn(tmp, x, arrowColor)); + conns.add(new ConnectionOut(tmp, x, arrowColor, height1)); + x += dim.getWidth(); + } + final double totalWidth = inner.asTextBlock().calculateDimension(getStringBounder()).getWidth(); + conns.add(new ConnectionHline2(inner, arrowColor, 0, list, totalWidth)); + conns.add(new ConnectionHline2(inner, arrowColor, height1, list, totalWidth)); + + inner = FtileUtils.addConnection(inner, conns); + return inner; + } + + static class ConnectionHline2 extends AbstractConnection { + + private final Ftile inner; + private final double y; + private final HtmlColor arrowColor; + private final List list; + private final double totalWidth; + + public ConnectionHline2(Ftile inner, HtmlColor arrowColor, double y, List list, double totalWidth) { + super(null, null); + this.inner = inner; + this.y = y; + this.arrowColor = arrowColor; + this.list = list; + this.totalWidth = totalWidth; + } + + public void drawU(UGraphic ug) { + double minX = Double.MAX_VALUE; + double maxX = 0; + final StringBounder stringBounder = ug.getStringBounder(); + for (Ftile tmp : list) { + if (y > 0 && tmp.isKilled()) { + continue; + } + final UTranslate ut = inner.getTranslateFor(tmp, stringBounder); + final double middle = ut.getTranslated(tmp.getPointIn(stringBounder)).getX(); + minX = Math.min(minX, middle); + maxX = Math.max(maxX, middle); + } + if (minX > totalWidth / 2) { + minX = totalWidth / 2; + } + if (maxX < totalWidth / 2) { + maxX = totalWidth / 2; + } + + final Snake s = new Snake(arrowColor); + s.addPoint(minX, y); + s.addPoint(maxX, y); + ug.draw(s); + } + } + + static class ConnectionIn extends AbstractConnection { + + private final double x; + private final HtmlColor arrowColor; + + public ConnectionIn(Ftile tmp, double x, HtmlColor arrowColor) { + super(null, tmp); + this.x = x; + this.arrowColor = arrowColor; + } + + public void drawU(UGraphic ug) { + ug = ug.apply(new UTranslate(x, 0)); + final Point2D p = getFtile2().getPointIn(ug.getStringBounder()); + final Snake s = new Snake(arrowColor, Arrows.asToDown()); + s.addPoint(p.getX(), 0); + s.addPoint(p.getX(), p.getY()); + ug.draw(s); + } + } + + static class ConnectionOut extends AbstractConnection { + + private final double x; + private final HtmlColor arrowColor; + private final double height; + + public ConnectionOut(Ftile tmp, double x, HtmlColor arrowColor, double height) { + super(tmp, null); + this.x = x; + this.arrowColor = arrowColor; + this.height = height; + } + + public void drawU(UGraphic ug) { + ug = ug.apply(new UTranslate(x, 0)); + final Point2D p = getFtile1().getPointOut(ug.getStringBounder()); + if (p == null) { + return; + } + final Snake s = new Snake(arrowColor, Arrows.asToDown()); + s.addPoint(p.getX(), p.getY()); + s.addPoint(p.getX(), height); + ug.draw(s); + } + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorIf.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorIf.java new file mode 100644 index 000000000..d168b4fe6 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorIf.java @@ -0,0 +1,74 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact; + +import java.util.List; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.activitydiagram3.Branch; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactoryDelegator; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.svek.ConditionStyle; +import net.sourceforge.plantuml.ugraphic.UFont; + +public class FtileFactoryDelegatorIf extends FtileFactoryDelegator { + + public FtileFactoryDelegatorIf(FtileFactory factory, ISkinParam skinParam) { + super(factory, skinParam); + } + + @Override + public Ftile createIf(Swimlane swimlane, List thens, Branch elseBranch) { + + final UFont font = getSkinParam().getFont(FontParam.ACTIVITY_ARROW2, null); + + final HtmlColor borderColor = getRose().getHtmlColor(getSkinParam(), ColorParam.activityBorder); + final HtmlColor backColor = getRose().getHtmlColor(getSkinParam(), ColorParam.activityBackground); + final HtmlColor arrowColor = getRose().getHtmlColor(getSkinParam(), ColorParam.activityArrow); + + final ConditionStyle conditionStyle = getSkinParam().getConditionStyle(); + if (thens.size() > 1) { + return FtileIf2.create(swimlane, borderColor, backColor, font, arrowColor, getFactory(), conditionStyle, + thens, elseBranch); + } + return FtileIf.create(swimlane, borderColor, backColor, font, arrowColor, getFactory(), conditionStyle, + thens.get(0), elseBranch); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorRepeat.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorRepeat.java new file mode 100644 index 000000000..21a5c2753 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorRepeat.java @@ -0,0 +1,76 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.activitydiagram3.LinkRendering; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactoryDelegator; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.svek.ConditionStyle; +import net.sourceforge.plantuml.ugraphic.UFont; + +public class FtileFactoryDelegatorRepeat extends FtileFactoryDelegator { + + public FtileFactoryDelegatorRepeat(FtileFactory factory, ISkinParam skinParam) { + super(factory, skinParam); + } + + private static boolean NEW = true; + + @Override + public Ftile repeat(Swimlane swimlane, Ftile repeat, Display test) { + final UFont font = getSkinParam().getFont(FontParam.ACTIVITY_ARROW2, null); + + final HtmlColor borderColor = getRose().getHtmlColor(getSkinParam(), ColorParam.activityBorder); + final HtmlColor backColor = getRose().getHtmlColor(getSkinParam(), ColorParam.activityBackground); + final HtmlColor arrowColor = getRose().getHtmlColor(getSkinParam(), ColorParam.activityArrow); + + final LinkRendering endRepeatLinkRendering = repeat.getOutLinkRendering(); + final HtmlColor endRepeatLinkColor = endRepeatLinkRendering == null ? null : endRepeatLinkRendering.getColor(); + + if (NEW) { + final ConditionStyle conditionStyle = getSkinParam().getConditionStyle(); + return FtileRepeat2.create(swimlane, repeat, test, borderColor, backColor, font, arrowColor, + endRepeatLinkColor, conditionStyle, this); + } + return FtileRepeat.create(repeat, test, borderColor, backColor, font, arrowColor, endRepeatLinkColor, this); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorWhile.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorWhile.java new file mode 100644 index 000000000..27ae9421a --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileFactoryDelegatorWhile.java @@ -0,0 +1,74 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.activitydiagram3.LinkRendering; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactoryDelegator; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.svek.ConditionStyle; +import net.sourceforge.plantuml.ugraphic.UFont; + +public class FtileFactoryDelegatorWhile extends FtileFactoryDelegator { + + public FtileFactoryDelegatorWhile(FtileFactory factory, ISkinParam skinParam) { + super(factory, skinParam); + } + + private static boolean NEW = true; + + @Override + public Ftile createWhile(Swimlane swimlane, Ftile whileBlock, Display test, Display yes, Display out, LinkRendering afterEndwhile) { + final HtmlColor borderColor = getRose().getHtmlColor(getSkinParam(), ColorParam.activityBorder); + final HtmlColor backColor = getRose().getHtmlColor(getSkinParam(), ColorParam.activityBackground); + final HtmlColor arrowColor = getRose().getHtmlColor(getSkinParam(), ColorParam.activityArrow); + final UFont font = getSkinParam().getFont(FontParam.ACTIVITY_ARROW2, null); + final LinkRendering endInlinkRendering = whileBlock.getOutLinkRendering(); + final HtmlColor endInlinkColor = endInlinkRendering == null ? arrowColor : endInlinkRendering.getColor(); + if (NEW) { + final ConditionStyle conditionStyle = getSkinParam().getConditionStyle(); + return FtileWhile2.create(swimlane, whileBlock, test, borderColor, backColor, arrowColor, yes, out, font, + endInlinkColor, afterEndwhile, getFactory(), conditionStyle); + } + return FtileWhile.create(whileBlock, test, borderColor, backColor, arrowColor, yes, out, font, endInlinkColor, + afterEndwhile, getFactory()); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileForkInner.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileForkInner.java new file mode 100644 index 000000000..67df60843 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileForkInner.java @@ -0,0 +1,144 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractFtile; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +class FtileForkInner extends AbstractFtile { + + private final List forks = new ArrayList(); + + public FtileForkInner(List forks) { + super(forks.get(0).shadowing()); + for (Ftile ftile : forks) { + this.forks.add(ftile); + } + } + + public Swimlane getSwimlaneIn() { + return forks.get(0).getSwimlaneIn(); + } + + public Swimlane getSwimlaneOut() { + return getSwimlaneIn(); + } + + public Set getSwimlanes() { + return mergeSwimlanes(forks); + } + + public static Set mergeSwimlanes(List tiles) { + final Set result = new HashSet(); + for (Ftile tile : tiles) { + result.addAll(tile.getSwimlanes()); + } + return Collections.unmodifiableSet(result); + } + + public TextBlock asTextBlock() { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + + double xpos = 0; + for (Ftile ftile : forks) { + ug.apply(new UTranslate(xpos, 0)).draw(ftile); + final Dimension2D dim = ftile.asTextBlock().calculateDimension(stringBounder); + xpos += dim.getWidth(); + } + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return calculateDimensionInternal(stringBounder); + } + + }; + } + + public boolean isKilled() { + return false; + } + + private Dimension2D calculateDimensionInternal(StringBounder stringBounder) { + double height = 0; + double width = 0; + for (Ftile ftile : forks) { + final Dimension2D dim = ftile.asTextBlock().calculateDimension(stringBounder); + width += dim.getWidth(); + if (dim.getHeight() > height) { + height = dim.getHeight(); + } + } + return new Dimension2DDouble(width, height); + } + + public Point2D getPointIn(StringBounder stringBounder) { + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + return new Point2D.Double(dimTotal.getWidth() / 2, 0); + } + + public Point2D getPointOut(StringBounder stringBounder) { + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + return new Point2D.Double(dimTotal.getWidth() / 2, dimTotal.getHeight()); + } + + public UTranslate getTranslateFor(Ftile searched, StringBounder stringBounder) { + double xpos = 0; + for (Ftile ftile : forks) { + if (ftile == searched) { + return new UTranslate(xpos, 0); + } + final Dimension2D dim = ftile.asTextBlock().calculateDimension(stringBounder); + xpos += dim.getWidth(); + } + throw new IllegalArgumentException(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileGroup.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileGroup.java new file mode 100644 index 000000000..4e9c60882 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileGroup.java @@ -0,0 +1,137 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact; + +import java.awt.Font; +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.Set; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.SpriteContainer; +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractFtile; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileMarged; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.SymbolContext; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.graphic.USymbol; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UStroke; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class FtileGroup extends AbstractFtile { + + private final double diffYY = 25; + private final Ftile inner; + private final TextBlock name; + private final HtmlColor color; + + public FtileGroup(Ftile inner, Display test, HtmlColor color, SpriteContainer spriteContainer) { + super(inner.shadowing()); + this.inner = new FtileMarged(inner, 10); + this.color = color; + final UFont font = new UFont("Serif", Font.PLAIN, 14); + final FontConfiguration fc = new FontConfiguration(font, HtmlColorUtils.BLACK); + if (test == null) { + this.name = TextBlockUtils.empty(0, 0); + } else { + this.name = TextBlockUtils.create(test, fc, HorizontalAlignment.LEFT, spriteContainer); + } + } + + public Set getSwimlanes() { + return inner.getSwimlanes(); + } + + public Swimlane getSwimlaneIn() { + return inner.getSwimlaneIn(); + } + + public Swimlane getSwimlaneOut() { + return inner.getSwimlaneOut(); + } + + private Dimension2D calculateDimensionInternal(StringBounder stringBounder) { + final Dimension2D dim = inner.asTextBlock().calculateDimension(stringBounder); + return Dimension2DDouble.delta(dim, 0, diffYY * 2); + } + + private UTranslate getTranslate() { + return new UTranslate(0, diffYY); + } + + public Point2D getPointIn(StringBounder stringBounder) { + return getTranslate().getTranslated(inner.getPointIn(stringBounder)); + } + + public Point2D getPointOut(StringBounder stringBounder) { + return getTranslate().getTranslated(inner.getPointOut(stringBounder)); + } + + public TextBlock asTextBlock() { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final Dimension2D dimTotal = calculateDimension(ug.getStringBounder()); + + final SymbolContext symbolContext = new SymbolContext(HtmlColorUtils.WHITE, HtmlColorUtils.BLACK) + .withShadow(shadowing()).withStroke(new UStroke(2)); + USymbol.FRAME.asBig(name, TextBlockUtils.empty(0, 0), dimTotal.getWidth(), dimTotal.getHeight(), + symbolContext).drawU(ug); + + ug.apply(getTranslate()).draw(inner); + + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return calculateDimensionInternal(stringBounder); + } + }; + } + + public boolean isKilled() { + return false; + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileIf.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileIf.java new file mode 100644 index 000000000..8598eec3f --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileIf.java @@ -0,0 +1,532 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.Direction; +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.activitydiagram3.Branch; +import net.sourceforge.plantuml.activitydiagram3.LinkRendering; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractConnection; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractFtile; +import net.sourceforge.plantuml.activitydiagram3.ftile.Arrows; +import net.sourceforge.plantuml.activitydiagram3.ftile.Connection; +import net.sourceforge.plantuml.activitydiagram3.ftile.ConnectionTranslatable; +import net.sourceforge.plantuml.activitydiagram3.ftile.Diamond; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileEmpty; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileMinWidth; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileUtils; +import net.sourceforge.plantuml.activitydiagram3.ftile.Snake; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamond; +import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamondInside; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.svek.ConditionStyle; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UPolygon; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +class FtileIf extends AbstractFtile { + + private final Ftile tile1; + private final Ftile tile2; + private final Ftile diamond1; + private final Ftile diamond2; + + private final HtmlColor arrowColor; + + private FtileIf(Ftile diamond1, Ftile tile1, Ftile tile2, Ftile diamond2, HtmlColor arrowColor) { + super(tile1.shadowing() || tile2.shadowing()); + this.diamond1 = diamond1; + this.diamond2 = diamond2; + this.tile1 = tile1; + this.tile2 = tile2; + + this.arrowColor = arrowColor; + + } + + public Set getSwimlanes() { + final Set result = new HashSet(); + if (getSwimlaneIn() != null) { + result.add(getSwimlaneIn()); + } + result.addAll(tile1.getSwimlanes()); + result.addAll(tile2.getSwimlanes()); + return Collections.unmodifiableSet(result); + } + + public Swimlane getSwimlaneIn() { + return diamond1.getSwimlaneIn(); + } + + public Swimlane getSwimlaneOut() { + return getSwimlaneIn(); + } + + static Ftile create(Swimlane swimlane, HtmlColor borderColor, HtmlColor backColor, UFont font, + HtmlColor arrowColor, FtileFactory ftileFactory, ConditionStyle conditionStyle, Branch branch1, + Branch branch2) { + + final Ftile tile1 = new FtileMinWidth(branch1.getFtile(), 30); + final Ftile tile2 = new FtileMinWidth(branch2.getFtile(), 30); + + final FontConfiguration fc = new FontConfiguration(font, HtmlColorUtils.BLACK); + final TextBlock tb1 = TextBlockUtils.create(branch1.getLabelPositive(), fc, HorizontalAlignment.LEFT, + ftileFactory); + final TextBlock tb2 = TextBlockUtils.create(branch2.getLabelPositive(), fc, HorizontalAlignment.LEFT, + ftileFactory); + final TextBlock tbTest = TextBlockUtils.create(branch1.getLabelTest(), fc, HorizontalAlignment.LEFT, + ftileFactory); + + final Ftile diamond1; + if (conditionStyle == ConditionStyle.INSIDE) { + diamond1 = new FtileDiamondInside(tile1.shadowing(), backColor, borderColor, swimlane, tbTest) + .withWest(tb1).withEast(tb2); + } else if (conditionStyle == ConditionStyle.DIAMOND) { + diamond1 = new FtileDiamond(tile1.shadowing(), backColor, borderColor, swimlane).withWest(tb1) + .withEast(tb2).withNorth(tbTest); + } else { + throw new IllegalStateException(); + } + + final Ftile diamond2; + if (tile1.isKilled() || tile2.isKilled()) { + diamond2 = new FtileEmpty(tile1.shadowing(), Diamond.diamondHalfSize * 2, Diamond.diamondHalfSize * 2, + swimlane, swimlane); + } else { + diamond2 = new FtileDiamond(tile1.shadowing(), backColor, borderColor, swimlane); + } + final FtileIf result = new FtileIf(diamond1, tile1, tile2, diamond2, arrowColor); + + final List conns = new ArrayList(); + conns.add(result.new ConnectionHorizontalThenVertical(tile1)); + conns.add(result.new ConnectionHorizontalThenVertical(tile2)); + if (tile1.isKilled() == false && tile2.isKilled() == false) { + conns.add(result.new ConnectionVerticalThenHorizontal(tile1, branch1.getInlinkRenderingColor())); + conns.add(result.new ConnectionVerticalThenHorizontal(tile2, branch2.getInlinkRenderingColor())); + } else if (tile1.isKilled() == false && tile2.isKilled()) { + conns.add(result.new ConnectionVerticalThenHorizontalDirect(tile1, branch1.getInlinkRenderingColor())); + } else if (tile1.isKilled() && tile2.isKilled() == false) { + conns.add(result.new ConnectionVerticalThenHorizontalDirect(tile2, branch2.getInlinkRenderingColor())); + } + return FtileUtils.addConnection(result, conns); + } + + class ConnectionHorizontalThenVertical extends AbstractConnection implements ConnectionTranslatable { + + public ConnectionHorizontalThenVertical(Ftile tile) { + super(diamond1, tile); + } + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + final Point2D p1 = getP1(stringBounder); + final Point2D p2 = getP2(stringBounder); + final double x1 = p1.getX(); + final double y1 = p1.getY(); + final double x2 = p2.getX(); + final double y2 = p2.getY(); + + final LinkRendering linkIn = getFtile2().getInLinkRendering(); + + final Snake snake = new Snake(linkIn == null ? arrowColor : linkIn.getColor(), Arrows.asToDown()); + snake.addPoint(x1, y1); + snake.addPoint(x2, y1); + snake.addPoint(x2, y2); + + ug.draw(snake); + } + + public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { + final StringBounder stringBounder = ug.getStringBounder(); + Point2D p1 = getP1(stringBounder); + Point2D p2 = getP2(stringBounder); + final Direction originalDirection = Direction.leftOrRight(p1, p2); + p1 = translate1.getTranslated(p1); + p2 = translate2.getTranslated(p2); + final Direction newDirection = Direction.leftOrRight(p1, p2); + final LinkRendering linkIn = getFtile2().getInLinkRendering(); + if (originalDirection != newDirection) { + final double delta = (originalDirection == Direction.RIGHT ? -1 : 1) * Diamond.diamondHalfSize; + final Dimension2D dimDiamond1 = diamond1.asTextBlock().calculateDimension(stringBounder); + final Snake small = new Snake(linkIn == null ? arrowColor : linkIn.getColor(), false); + small.addPoint(p1); + small.addPoint(p1.getX() + delta, p1.getY()); + small.addPoint(p1.getX() + delta, p1.getY() + dimDiamond1.getHeight()); + ug.draw(small); + p1 = small.getLast(); + } + final Snake snake = new Snake(linkIn == null ? arrowColor : linkIn.getColor(), Arrows.asToDown(), true); + snake.addPoint(p1); + snake.addPoint(p2.getX(), p1.getY()); + snake.addPoint(p2); + ug.draw(snake); + + } + + private Point2D getP1(StringBounder stringBounder) { + final Dimension2D dimDiamond1 = diamond1.asTextBlock().calculateDimension(stringBounder); + final double diamondWidth = dimDiamond1.getWidth(); + final double x; + if (getFtile2() == tile1) { + x = 0; + } else if (getFtile2() == tile2) { + x = diamondWidth; + } else { + throw new IllegalStateException(); + } + return getTranslateDiamond1(stringBounder) + .getTranslated(new Point2D.Double(x, dimDiamond1.getHeight() / 2)); + } + + private Point2D getP2(final StringBounder stringBounder) { + return translate(stringBounder).getTranslated(getFtile2().getPointIn(stringBounder)); + } + + private UTranslate translate(StringBounder stringBounder) { + if (getFtile2() == tile1) { + return getTranslate1(stringBounder); + } + if (getFtile2() == tile2) { + return getTranslate2(stringBounder); + } + throw new IllegalStateException(); + } + } + + class ConnectionVerticalThenHorizontal extends AbstractConnection implements ConnectionTranslatable { + private final HtmlColor myArrowColor; + + public ConnectionVerticalThenHorizontal(Ftile tile, HtmlColor myArrowColor) { + super(tile, diamond2); + this.myArrowColor = myArrowColor == null ? arrowColor : myArrowColor; + } + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + + final Point2D pointOut = getFtile1().getPointOut(stringBounder); + if (pointOut == null) { + return; + } + final Point2D p1 = translate(stringBounder).getTranslated(pointOut); + final Point2D p2 = getP2(stringBounder); + + final double x1 = p1.getX(); + final double y1 = p1.getY(); + final double x2 = p2.getX(); + final double y2 = p2.getY(); + + final UPolygon arrow = x2 > x1 ? Arrows.asToRight() : Arrows.asToLeft(); + final Snake snake = new Snake(myArrowColor, arrow); + snake.addPoint(x1, y1); + snake.addPoint(x1, y2); + snake.addPoint(x2, y2); + + ug.draw(snake); + } + + public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { + final StringBounder stringBounder = ug.getStringBounder(); + final Point2D pointOut = getFtile1().getPointOut(stringBounder); + if (pointOut == null) { + return; + } + final Point2D p2 = getP2(stringBounder); + final Point2D p1 = translate(stringBounder).getTranslated(pointOut); + final Direction originalDirection = Direction.leftOrRight(p1, p2); + + final double x1 = p1.getX(); + final double x2 = p2.getX(); + final Point2D mp1a = translate1.getTranslated(p1); + final Point2D mp2b = translate2.getTranslated(p2); + final Direction newDirection = Direction.leftOrRight(mp1a, mp2b); + final UPolygon arrow = x2 > x1 ? Arrows.asToRight() : Arrows.asToLeft(); + if (originalDirection == newDirection) { + final double delta = (x2 > x1 ? -1 : 1) * 1.5 * Diamond.diamondHalfSize; + final Point2D mp2bc = new Point2D.Double(mp2b.getX() + delta, mp2b.getY()); + final Snake snake = new Snake(myArrowColor, true); + final double middle = (mp1a.getY() + mp2b.getY()) / 2.0; + snake.addPoint(mp1a); + snake.addPoint(mp1a.getX(), middle); + snake.addPoint(mp2bc.getX(), middle); + snake.addPoint(mp2bc); + ug.draw(snake); + final Snake small = new Snake(myArrowColor, arrow); + small.addPoint(mp2bc); + small.addPoint(mp2bc.getX(), mp2b.getY()); + small.addPoint(mp2b); + ug.draw(small); + } else { + final double delta = (x2 > x1 ? -1 : 1) * 1.5 * Diamond.diamondHalfSize; + final Point2D mp2bb = new Point2D.Double(mp2b.getX() + delta, mp2b.getY() - 3 * Diamond.diamondHalfSize); + final Snake snake = new Snake(myArrowColor, true); + snake.addPoint(mp1a); + snake.addPoint(mp1a.getX(), mp2bb.getY()); + snake.addPoint(mp2bb); + ug.draw(snake); + final Snake small = new Snake(myArrowColor, arrow); + small.addPoint(mp2bb); + small.addPoint(mp2bb.getX(), mp2b.getY()); + small.addPoint(mp2b); + ug.draw(small); + + } + + } + + private Point2D getP2(StringBounder stringBounder) { + final Dimension2D dimDiamond2 = diamond2.asTextBlock().calculateDimension(stringBounder); + final double diamondWidth = dimDiamond2.getWidth(); + final double x; + if (getFtile1() == tile1) { + x = 0; + } else if (getFtile1() == tile2) { + x = diamondWidth; + } else { + throw new IllegalStateException(); + } + return getTranslateDiamond2(stringBounder) + .getTranslated(new Point2D.Double(x, dimDiamond2.getHeight() / 2)); + } + + private UTranslate translate(StringBounder stringBounder) { + if (getFtile1() == tile1) { + return getTranslate1(stringBounder); + } + if (getFtile1() == tile2) { + return getTranslate2(stringBounder); + } + throw new IllegalStateException(); + } + } + + class ConnectionVerticalThenHorizontalDirect extends AbstractConnection implements ConnectionTranslatable { + private final HtmlColor myArrowColor; + + public ConnectionVerticalThenHorizontalDirect(Ftile tile, HtmlColor myArrowColor) { + super(tile, diamond2); + this.myArrowColor = myArrowColor == null ? arrowColor : myArrowColor; + } + + public void drawU(UGraphic ug) { + + final StringBounder stringBounder = ug.getStringBounder(); + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + + final Point2D pointOut = getFtile1().getPointOut(stringBounder); + if (pointOut == null) { + return; + } + final Point2D p1 = translate(stringBounder).getTranslated(pointOut); + final Point2D p2 = new Point2D.Double(dimTotal.getWidth() / 2, dimTotal.getHeight() + - Diamond.diamondHalfSize); + + final double x1 = p1.getX(); + final double y1 = p1.getY(); + final double x2 = p2.getX(); + final double y2 = p2.getY(); + + final Snake snake = new Snake(myArrowColor, true); + + snake.addPoint(x1, y1); + snake.addPoint(x1, y2); + snake.addPoint(x2, y2); + snake.addPoint(x2, dimTotal.getHeight()); + + ug.draw(snake); + } + + private UTranslate translate(StringBounder stringBounder) { + if (getFtile1() == tile1) { + return getTranslate1(stringBounder); + } + if (getFtile1() == tile2) { + return getTranslate2(stringBounder); + } + throw new IllegalStateException(); + } + + public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { + final StringBounder stringBounder = ug.getStringBounder(); + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + + final Point2D pointOut = getFtile1().getPointOut(stringBounder); + if (pointOut == null) { + return; + } + final Point2D p1 = translate(stringBounder).getTranslated(pointOut); + final Point2D p2 = new Point2D.Double(dimTotal.getWidth() / 2, dimTotal.getHeight() + - Diamond.diamondHalfSize); + + final Point2D mp1a = translate1.getTranslated(p1); + final Point2D mp2b = translate2.getTranslated(p2); + + final Snake snake = new Snake(myArrowColor, true); + // final Snake snake = new Snake(HtmlColorUtils.BLUE, true); + + final double x1 = mp1a.getX(); + final double x2 = mp2b.getX(); + final double y2 = mp2b.getY(); + + snake.addPoint(mp1a); + snake.addPoint(x1, y2); + snake.addPoint(mp2b); + snake.addPoint(x2, dimTotal.getHeight()); + + ug.draw(snake); + } + } + + private UTranslate getTranslate1(StringBounder stringBounder) { + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + final Dimension2D dimDiamond1 = diamond1.asTextBlock().calculateDimension(stringBounder); + final Dimension2D dim1 = tile1.asTextBlock().calculateDimension(stringBounder); + + final double x1 = 0; + final double h = dimDiamond1.getHeight(); + final double y1 = (dimTotal.getHeight() - 2 * h - dim1.getHeight()) / 2 + h; + return new UTranslate(x1, y1); + } + + private UTranslate getTranslate2(StringBounder stringBounder) { + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + final Dimension2D dimDiamond1 = diamond1.asTextBlock().calculateDimension(stringBounder); + final Dimension2D dim2 = tile2.asTextBlock().calculateDimension(stringBounder); + + final double x2 = dimTotal.getWidth() - dim2.getWidth(); + final double h = dimDiamond1.getHeight(); + final double y2 = (dimTotal.getHeight() - 2 * h - dim2.getHeight()) / 2 + h; + return new UTranslate(x2, y2); + + } + + private UTranslate getTranslateDiamond1(StringBounder stringBounder) { + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + final Dimension2D dimDiamond1 = diamond1.asTextBlock().calculateDimension(stringBounder); + + final double x1 = (dimTotal.getWidth() - dimDiamond1.getWidth()) / 2; + final double y1 = 0; + return new UTranslate(x1, y1); + } + + private UTranslate getTranslateDiamond2(StringBounder stringBounder) { + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + final Dimension2D dimDiamond2 = diamond2.asTextBlock().calculateDimension(stringBounder); + + final double x2 = (dimTotal.getWidth() - dimDiamond2.getWidth()) / 2; + final double y2 = dimTotal.getHeight() - dimDiamond2.getHeight(); + return new UTranslate(x2, y2); + } + + @Override + public UTranslate getTranslateFor(Ftile child, StringBounder stringBounder) { + if (child == diamond1) { + return getTranslateDiamond1(stringBounder); + } + if (child == tile1) { + return getTranslate1(stringBounder); + } + if (child == tile2) { + return getTranslate2(stringBounder); + } + if (child == diamond2) { + return getTranslateDiamond2(stringBounder); + } + throw new UnsupportedOperationException(); + } + + public TextBlock asTextBlock() { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + + ug.apply(getTranslateDiamond1(stringBounder)).draw(diamond1); + ug.apply(getTranslate1(stringBounder)).draw(tile1); + ug.apply(getTranslate2(stringBounder)).draw(tile2); + ug.apply(getTranslateDiamond2(stringBounder)).draw(diamond2); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return calculateDimensionInternal(stringBounder); + } + + }; + } + + public boolean isKilled() { + return tile1.isKilled() && tile2.isKilled(); + } + + private Dimension2D calculateDimensionInternal(StringBounder stringBounder) { + final Dimension2D dim1 = tile1.asTextBlock().calculateDimension(stringBounder); + final Dimension2D dim2 = tile2.asTextBlock().calculateDimension(stringBounder); + final Dimension2D dim12 = Dimension2DDouble.mergeLR(dim1, dim2); + final Dimension2D dimDiamond1 = diamond1.asTextBlock().calculateDimension(stringBounder); + final double widthA = dim12.getWidth(); + final double widthB = Math.max(dim1.getWidth(), dim2.getWidth()) + dimDiamond1.getWidth(); + final double width = Math.max(widthA, widthB); + return new Dimension2DDouble(width + 30, dim12.getHeight() + dimDiamond1.getHeight() * 3 + 40); + } + + public Point2D getPointIn(StringBounder stringBounder) { + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + return new Point2D.Double(dimTotal.getWidth() / 2, 0); + } + + public Point2D getPointOut(StringBounder stringBounder) { + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + return new Point2D.Double(dimTotal.getWidth() / 2, dimTotal.getHeight()); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileIf2.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileIf2.java new file mode 100644 index 000000000..7f91ff8db --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileIf2.java @@ -0,0 +1,524 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.activitydiagram3.Branch; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractConnection; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractFtile; +import net.sourceforge.plantuml.activitydiagram3.ftile.Arrows; +import net.sourceforge.plantuml.activitydiagram3.ftile.Connection; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileMinWidth; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileUtils; +import net.sourceforge.plantuml.activitydiagram3.ftile.Snake; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamondInside; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.svek.ConditionStyle; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +class FtileIf2 extends AbstractFtile { + + private final double xSeparation = 20; + + private final List tiles; + private final Ftile tile2; + private final List diamonds; + + private final HtmlColor arrowColor; + + private FtileIf2(List diamonds, List tiles, Ftile tile2, HtmlColor arrowColor) { + super(tiles.get(0).shadowing() || tile2.shadowing()); + this.diamonds = diamonds; + this.tiles = tiles; + this.tile2 = tile2; + + this.arrowColor = arrowColor; + + } + + public Set getSwimlanes() { + final Set result = new HashSet(); + if (getSwimlaneIn() != null) { + result.add(getSwimlaneIn()); + } + for (Ftile tile : tiles) { + result.addAll(tile.getSwimlanes()); + } + result.addAll(tile2.getSwimlanes()); + return Collections.unmodifiableSet(result); + } + + public Swimlane getSwimlaneIn() { + return diamonds.get(0).getSwimlaneIn(); + } + + public Swimlane getSwimlaneOut() { + return getSwimlaneIn(); + } + + static Ftile create(Swimlane swimlane, HtmlColor borderColor, HtmlColor backColor, UFont font, + HtmlColor arrowColor, FtileFactory ftileFactory, ConditionStyle conditionStyle, List thens, + Branch branch2) { + + final List tiles = new ArrayList(); + + for (Branch branch : thens) { + tiles.add(new FtileMinWidth(branch.getFtile(), 30)); + } + + final Ftile tile2 = new FtileMinWidth(branch2.getFtile(), 30); + + final FontConfiguration fc = new FontConfiguration(font, HtmlColorUtils.BLACK); + + final List diamonds = new ArrayList(); + final List conns = new ArrayList(); + for (Branch branch : thens) { + final TextBlock tb1 = TextBlockUtils.create(branch.getLabelPositive(), fc, HorizontalAlignment.LEFT, + ftileFactory); + final TextBlock tbTest = TextBlockUtils.create(branch.getLabelTest(), fc, HorizontalAlignment.LEFT, + ftileFactory); + FtileDiamondInside diamond = new FtileDiamondInside(branch.shadowing(), backColor, borderColor, swimlane, + tbTest); + diamond = diamond.withNorth(tb1); + diamonds.add(diamond); + } + + final TextBlock tb2 = TextBlockUtils.create(branch2.getLabelPositive(), fc, HorizontalAlignment.LEFT, + ftileFactory); + final int last = diamonds.size() - 1; + diamonds.set(last, ((FtileDiamondInside) diamonds.get(last)).withEast(tb2)); + + final FtileIf2 result = new FtileIf2(diamonds, tiles, tile2, arrowColor); + + for (int i = 0; i < thens.size(); i++) { + final Ftile ftile = tiles.get(i); + final Ftile diam = diamonds.get(i); + + final HtmlColor color = thens.get(i).getInlinkRenderingColor(); + conns.add(result.new ConnectionHorizontalIn(diam, ftile, color == null ? arrowColor : color)); + conns.add(result.new ConnectionHorizontalOut(ftile, arrowColor)); + } + + for (int i = 0; i < diamonds.size() - 1; i++) { + final Ftile diam1 = diamonds.get(i); + final Ftile diam2 = diamonds.get(i + 1); + conns.add(result.new ConnectionVertical(diam1, diam2, arrowColor)); + } + conns.add(result.new ConnectionIn(arrowColor)); + conns.add(result.new ConnectionLastElseIn(arrowColor)); + conns.add(result.new ConnectionLastElseOut(arrowColor)); + conns.add(result.new ConnectionHline(arrowColor)); + + return FtileUtils.addConnection(result, conns); + } + + class ConnectionVertical extends AbstractConnection { + + private final HtmlColor color; + + public ConnectionVertical(Ftile diam1, Ftile diam2, HtmlColor color) { + super(diam1, diam2); + this.color = color; + } + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + final Point2D p1 = getP1(stringBounder); + final Point2D p2 = getP2(stringBounder); + + final Snake snake = new Snake(color, Arrows.asToRight()); + snake.addPoint(p1); + snake.addPoint(p2); + ug.draw(snake); + } + + private Point2D getP1(StringBounder stringBounder) { + final Dimension2D dimDiamond1 = getFtile1().asTextBlock().calculateDimension(stringBounder); + final Point2D p = new Point2D.Double(dimDiamond1.getWidth(), dimDiamond1.getHeight() / 2); + + return getTranslateDiamond1(getFtile1(), stringBounder).getTranslated(p); + } + + private Point2D getP2(StringBounder stringBounder) { + final Dimension2D dimDiamond1 = getFtile2().asTextBlock().calculateDimension(stringBounder); + final Point2D p = new Point2D.Double(0, dimDiamond1.getHeight() / 2); + return getTranslateDiamond1(getFtile2(), stringBounder).getTranslated(p); + } + + } + + class ConnectionIn extends AbstractConnection { + + private final HtmlColor arrowColor; + + public ConnectionIn(HtmlColor arrowColor) { + super(null, diamonds.get(0)); + this.arrowColor = arrowColor; + } + + public void drawU(UGraphic ug) { + final Point2D p1 = getPointIn(ug.getStringBounder()); + final UTranslate tr = getTranslateDiamond1(getFtile2(), ug.getStringBounder()); + final Point2D p2 = tr.getTranslated(getFtile2().getPointIn(ug.getStringBounder())); + final Snake snake = new Snake(arrowColor, Arrows.asToDown()); + snake.addPoint(p1); + snake.addPoint(p2.getX(), p1.getY()); + snake.addPoint(p2); + ug.draw(snake); + } + + } + + class ConnectionLastElseIn extends AbstractConnection { + + private final HtmlColor arrowColor; + + public ConnectionLastElseIn(HtmlColor arrowColor) { + super(diamonds.get(diamonds.size() - 1), tile2); + this.arrowColor = arrowColor; + } + + public void drawU(UGraphic ug) { + final Point2D p1 = getP1(ug.getStringBounder()); + final UTranslate tr2 = getTranslate2(ug.getStringBounder()); + final Point2D p2 = tr2.getTranslated(getFtile2().getPointIn(ug.getStringBounder())); + final Snake snake = new Snake(arrowColor, Arrows.asToDown()); + snake.addPoint(p1); + snake.addPoint(p2.getX(), p1.getY()); + snake.addPoint(p2); + ug.draw(snake); + } + + private Point2D getP1(StringBounder stringBounder) { + final Dimension2D dimDiamond1 = getFtile1().asTextBlock().calculateDimension(stringBounder); + final Point2D p = new Point2D.Double(dimDiamond1.getWidth(), dimDiamond1.getHeight() / 2); + return getTranslateDiamond1(getFtile1(), stringBounder).getTranslated(p); + } + + } + + class ConnectionLastElseOut extends AbstractConnection { + + private final HtmlColor arrowColor; + + public ConnectionLastElseOut(HtmlColor arrowColor) { + super(tile2, null); + this.arrowColor = arrowColor; + } + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + final UTranslate tr1 = getTranslate2(stringBounder); + final Point2D p1 = tr1.getTranslated(getFtile1().getPointOut(stringBounder)); + final double totalHeight = calculateDimensionInternal(stringBounder).getHeight(); + final Point2D p2 = new Point2D.Double(p1.getX(), totalHeight); + + final Snake snake = new Snake(arrowColor, Arrows.asToDown()); + snake.addPoint(p1); + snake.addPoint(p2); + ug.draw(snake); + } + + } + + class ConnectionHorizontalIn extends AbstractConnection { + + private final HtmlColor color; + + public ConnectionHorizontalIn(Ftile diamond, Ftile tile, HtmlColor color) { + super(diamond, tile); + this.color = color; + } + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + final Point2D p1 = getP1(stringBounder); + final Point2D p2 = getP2(stringBounder); + + final Snake snake = new Snake(color, Arrows.asToDown()); + snake.addPoint(p1); + snake.addPoint(p2); + ug.draw(snake); + } + + private Point2D getP1(StringBounder stringBounder) { + final Point2D p = getFtile1().getPointOut(stringBounder); + return getTranslateDiamond1(getFtile1(), stringBounder).getTranslated(p); + } + + private Point2D getP2(StringBounder stringBounder) { + final Point2D p = getFtile2().getPointIn(stringBounder); + return getTranslate1(getFtile2(), stringBounder).getTranslated(p); + } + + } + + class ConnectionHorizontalOut extends AbstractConnection { + + private final HtmlColor color; + + public ConnectionHorizontalOut(Ftile tile, HtmlColor color) { + super(tile, null); + this.color = color; + } + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + final double totalHeight = calculateDimensionInternal(stringBounder).getHeight(); + final Point2D p1 = getP1(stringBounder); + if (p1 == null) { + return; + } + final Point2D p2 = new Point2D.Double(p1.getX(), totalHeight); + + final Snake snake = new Snake(color, Arrows.asToDown()); + snake.addPoint(p1); + snake.addPoint(p2); + ug.draw(snake); + } + + private Point2D getP1(StringBounder stringBounder) { + final Point2D p = getFtile1().getPointOut(stringBounder); + return getTranslate1(getFtile1(), stringBounder).getTranslated(p); + } + + } + + class ConnectionHline extends AbstractConnection { + + private final HtmlColor arrowColor; + + public ConnectionHline(HtmlColor arrowColor) { + super(null, null); + this.arrowColor = arrowColor; + } + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + final Dimension2D totalDim = calculateDimensionInternal(stringBounder); + + final List all = new ArrayList(tiles); + all.add(tile2); + double minX = Double.MAX_VALUE; + double maxX = 0; + for (Ftile tmp : all) { + if (tmp.isKilled()) { + continue; + } + final UTranslate ut = getTranslateFor(tmp, stringBounder); + final double middle = ut.getTranslated(tmp.getPointOut(stringBounder)).getX(); + minX = Math.min(minX, middle); + maxX = Math.max(maxX, middle); + } + + final Snake s = new Snake(arrowColor); + final double height = totalDim.getHeight(); + s.addPoint(minX, height); + s.addPoint(maxX, height); + ug.draw(s); + } + } + + @Override + public UTranslate getTranslateFor(Ftile child, StringBounder stringBounder) { + if (child == tile2) { + return getTranslate2(stringBounder); + } + if (tiles.contains(child)) { + return getTranslate1(child, stringBounder); + } + throw new UnsupportedOperationException(); + } + + private UTranslate getTranslate2(StringBounder stringBounder) { + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + // final Dimension2D dimDiamond1 = diamond1.asTextBlock().calculateDimension(stringBounder); + final Dimension2D dim2 = tile2.asTextBlock().calculateDimension(stringBounder); + + final double x2 = dimTotal.getWidth() - dim2.getWidth(); + + final double h = getAllDiamondsHeight(stringBounder); + final double y2 = (dimTotal.getHeight() - h * 2 - dim2.getHeight()) / 2 + h; + + // final double y2 = (dimTotal.getHeight() - dimDiamond1.getHeight() * 2 - dim2.getHeight()) / 2 + // + dimDiamond1.getHeight(); + return new UTranslate(x2, y2); + + } + + private UTranslate getTranslateDiamond1(Ftile diamond1, StringBounder stringBounder) { + double x1 = 0; + + for (Ftile diamond : diamonds) { + final Dimension2D dim1 = dimDiamondAndTile(stringBounder, diamond); + if (diamond == diamond1) { + final Dimension2D dimDiamond = diamond.asTextBlock().calculateDimension(stringBounder); + return new UTranslate(x1 + (dim1.getWidth() - dimDiamond.getWidth()) / 2, 25); + } + x1 += dim1.getWidth() + xSeparation; + } + throw new IllegalArgumentException(); + + } + + private UTranslate getTranslate1(Ftile tile1, StringBounder stringBounder) { + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + double x1 = 0; + + for (Ftile tile : tiles) { + final Dimension2D dim1 = dimDiamondAndTile(stringBounder, tile); + if (tile == tile1) { + final Dimension2D dimTile = tile.asTextBlock().calculateDimension(stringBounder); + final double h = getAllDiamondsHeight(stringBounder); + final double y1 = (dimTotal.getHeight() - 2 * h - dimTile.getHeight()) / 2 + h; + return new UTranslate(x1 + (dim1.getWidth() - dimTile.getWidth()) / 2, y1); + } + x1 += dim1.getWidth() + xSeparation; + } + throw new IllegalArgumentException(); + + } + + public TextBlock asTextBlock() { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + for (Ftile tile : tiles) { + ug.apply(getTranslate1(tile, stringBounder)).draw(tile); + } + for (Ftile diamond : diamonds) { + ug.apply(getTranslateDiamond1(diamond, stringBounder)).draw(diamond); + } + + // ug.apply(getTranslateDiamond1(stringBounder)).draw(diamond1); + // ug.apply(getTranslate1(stringBounder)).draw(tile1); + ug.apply(getTranslate2(stringBounder)).draw(tile2); + // ug.apply(getTranslateDiamond2(stringBounder)).draw(diamond2); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return calculateDimensionInternal(stringBounder); + } + + }; + } + + public boolean isKilled() { + for (Ftile tile : tiles) { + if (tile.isKilled() == false) { + return false; + } + } + return tile2.isKilled(); + } + + private Dimension2D dimDiamondAndTile(StringBounder stringBounder, Ftile tileOrDiamond) { + for (int i = 0; i < tiles.size(); i++) { + final Ftile tile = tiles.get(i); + final Ftile diamond = diamonds.get(i); + if (tile != tileOrDiamond && diamond != tileOrDiamond) { + continue; + } + final Dimension2D dimTile = tile.asTextBlock().calculateDimension(stringBounder); + final Dimension2D dimDiamond = diamond.asTextBlock().calculateDimension(stringBounder); + return Dimension2DDouble.mergeTB(dimDiamond, dimTile); + } + throw new UnsupportedOperationException(); + + } + + private Dimension2D calculateDimensionInternal(StringBounder stringBounder) { + Dimension2D dimOnlyTiles = new Dimension2DDouble(0, 0); + Dimension2D dimOnlyDiamond = new Dimension2DDouble(0, 0); + Dimension2D dimBoth = new Dimension2DDouble(0, 0); + for (int i = 0; i < tiles.size(); i++) { + final Ftile tile = tiles.get(i); + final Ftile diamond = diamonds.get(i); + final Dimension2D dimTile = tile.asTextBlock().calculateDimension(stringBounder); + final Dimension2D dimDiamond = diamond.asTextBlock().calculateDimension(stringBounder); + final Dimension2D both = Dimension2DDouble.mergeTB(dimDiamond, dimTile); + dimOnlyTiles = Dimension2DDouble.mergeLR(dimOnlyTiles, dimTile); + dimOnlyDiamond = Dimension2DDouble.mergeLR(dimOnlyDiamond, dimDiamond); + dimBoth = Dimension2DDouble.mergeLR(dimBoth, both); + } + final Dimension2D dimTile2 = tile2.asTextBlock().calculateDimension(stringBounder); + dimOnlyTiles = Dimension2DDouble.mergeLR(dimOnlyTiles, dimTile2); + dimBoth = Dimension2DDouble.mergeLR(dimBoth, dimTile2); + + final Dimension2D result = new Dimension2DDouble(dimBoth.getWidth(), dimOnlyDiamond.getHeight() * 4 + + dimOnlyTiles.getHeight()); + return Dimension2DDouble.delta(result, xSeparation * tiles.size(), 50); + } + + private double getAllDiamondsHeight(StringBounder stringBounder) { + Dimension2D dimOnlyDiamond = new Dimension2DDouble(0, 0); + for (Ftile diamond : diamonds) { + final Dimension2D dimDiamond = diamond.asTextBlock().calculateDimension(stringBounder); + dimOnlyDiamond = Dimension2DDouble.mergeLR(dimOnlyDiamond, dimDiamond); + } + return dimOnlyDiamond.getHeight(); + } + + public Point2D getPointIn(StringBounder stringBounder) { + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + return new Point2D.Double(dimTotal.getWidth() / 2, 0); + } + + public Point2D getPointOut(StringBounder stringBounder) { + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + return new Point2D.Double(dimTotal.getWidth() / 2, dimTotal.getHeight()); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileRepeat.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileRepeat.java new file mode 100644 index 000000000..058a21876 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileRepeat.java @@ -0,0 +1,243 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.SpriteContainer; +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.activitydiagram3.LinkRendering; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractConnection; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractFtile; +import net.sourceforge.plantuml.activitydiagram3.ftile.Arrows; +import net.sourceforge.plantuml.activitydiagram3.ftile.Connection; +import net.sourceforge.plantuml.activitydiagram3.ftile.Diamond; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileUtils; +import net.sourceforge.plantuml.activitydiagram3.ftile.Snake; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UStroke; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +class FtileRepeat extends AbstractFtile { + + private final Ftile repeat; + + private final TextBlock test; + + private final HtmlColor borderColor; + private final HtmlColor backColor; + + private FtileRepeat(Ftile repeat, Display test, HtmlColor borderColor, HtmlColor backColor, UFont font, + SpriteContainer spriteContainer) { + super(repeat.shadowing()); + this.repeat = repeat; + this.borderColor = borderColor; + this.backColor = backColor; + final FontConfiguration fc = new FontConfiguration(font, HtmlColorUtils.BLACK); + this.test = TextBlockUtils.create(test, fc, HorizontalAlignment.LEFT, spriteContainer); + } + + public Swimlane getSwimlaneIn() { + return repeat.getSwimlaneIn(); + } + + public Swimlane getSwimlaneOut() { + return getSwimlaneIn(); + } + + public Set getSwimlanes() { + return repeat.getSwimlanes(); + } + + public static Ftile create(Ftile repeat, Display test, HtmlColor borderColor, HtmlColor backColor, UFont font, + HtmlColor arrowColor, HtmlColor endRepeatLinkColor, SpriteContainer spriteContainer) { + final FtileRepeat result = new FtileRepeat(repeat, test, borderColor, backColor, font, spriteContainer); + final List conns = new ArrayList(); + conns.add(result.new ConnectionIn(LinkRendering.getColor(repeat.getInLinkRendering(), arrowColor))); + conns.add(result.new ConnectionBack(arrowColor)); + conns.add(result.new ConnectionOut(LinkRendering.getColor(endRepeatLinkColor, arrowColor))); + return FtileUtils.addConnection(result, conns); + } + + class ConnectionIn extends AbstractConnection { + private final HtmlColor arrowColor; + + public ConnectionIn(HtmlColor arrowColor) { + super(null, null); + this.arrowColor = arrowColor; + } + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + final UTranslate translate = getTranslate(stringBounder); + + final Point2D pIn = translate.getTranslated(repeat.getPointIn(stringBounder)); + final Snake snake = new Snake(arrowColor, Arrows.asToDown()); + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + snake.addPoint(dimTotal.getWidth() / 2, 2 * Diamond.diamondHalfSize); + snake.addPoint(pIn.getX(), pIn.getY()); + + ug.draw(snake); + } + } + + class ConnectionBack extends AbstractConnection { + private final HtmlColor arrowColor; + + public ConnectionBack(HtmlColor arrowColor) { + super(null, null); + this.arrowColor = arrowColor; + } + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + + final Snake snake = new Snake(arrowColor, Arrows.asToLeft()); + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + snake.addPoint(dimTotal.getWidth() / 2 + Diamond.diamondHalfSize, dimTotal.getHeight() + - Diamond.diamondHalfSize); + snake.addPoint(dimTotal.getWidth() - Diamond.diamondHalfSize, dimTotal.getHeight() + - Diamond.diamondHalfSize); + snake.addPoint(dimTotal.getWidth() - Diamond.diamondHalfSize, Diamond.diamondHalfSize); + snake.addPoint(dimTotal.getWidth() / 2 + Diamond.diamondHalfSize, Diamond.diamondHalfSize); + + ug = ug.apply(new UChangeColor(arrowColor)).apply(new UChangeBackColor(arrowColor)); + ug.apply(new UTranslate(dimTotal.getWidth() - Diamond.diamondHalfSize, dimTotal.getHeight() / 2)).draw( + Arrows.asToUp()); + ug.apply(new UStroke(1.5)).draw(snake); + } + } + + class ConnectionOut extends AbstractConnection { + private final HtmlColor arrowColor; + + public ConnectionOut(HtmlColor arrowColor) { + super(null, null); + this.arrowColor = arrowColor; + } + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + final UTranslate translate = getTranslate(stringBounder); + + final Point2D pIn = translate.getTranslated(repeat.getPointOut(stringBounder)); + final Snake snake = new Snake(arrowColor, Arrows.asToDown()); + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + snake.addPoint(pIn.getX(), pIn.getY()); + snake.addPoint(dimTotal.getWidth() / 2, dimTotal.getHeight() - 2 * Diamond.diamondHalfSize); + + ug.draw(snake); + } + } + + public TextBlock asTextBlock() { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + final Dimension2D dimTotal = calculateDimension(stringBounder); + ug.apply(getTranslate(stringBounder)).draw(repeat); + + final double xDiamond = (dimTotal.getWidth() - 2 * Diamond.diamondHalfSize) / 2; + drawDiamond(ug, xDiamond, 0); + drawDiamond(ug, xDiamond, dimTotal.getHeight() - 2 * Diamond.diamondHalfSize); + + final Dimension2D dimTest = test.calculateDimension(stringBounder); + test.drawU(ug.apply(new UTranslate(dimTotal.getWidth() / 2 + Diamond.diamondHalfSize, dimTotal + .getHeight() - Diamond.diamondHalfSize - dimTest.getHeight()))); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return calculateDimensionInternal(stringBounder); + } + + }; + } + + public boolean isKilled() { + return false; + } + + private void drawDiamond(UGraphic ug, double xTheoricalPosition, double yTheoricalPosition) { + ug.apply(new UChangeColor(borderColor)).apply(new UStroke(1.5)).apply(new UChangeBackColor(backColor)) + .apply(new UTranslate(xTheoricalPosition, yTheoricalPosition)).draw(Diamond.asPolygon(shadowing())); + } + + private Dimension2D calculateDimensionInternal(StringBounder stringBounder) { + Dimension2D dim = repeat.asTextBlock().calculateDimension(stringBounder); + dim = Dimension2DDouble.delta(dim, 2 * getDeltaX(stringBounder), 8 * Diamond.diamondHalfSize); + return dim; + } + + private UTranslate getTranslate(StringBounder stringBounder) { + return new UTranslate(getDeltaX(stringBounder), 4 * Diamond.diamondHalfSize); + } + + private double getDeltaX(StringBounder stringBounder) { + final double w = test.calculateDimension(stringBounder).getWidth(); + if (w < 2 * Diamond.diamondHalfSize) { + return 2 * Diamond.diamondHalfSize; + } + return w + Diamond.diamondHalfSize; + } + + public Point2D getPointIn(StringBounder stringBounder) { + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + return new Point2D.Double(dimTotal.getWidth() / 2, 0); + } + + public Point2D getPointOut(StringBounder stringBounder) { + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + return new Point2D.Double(dimTotal.getWidth() / 2, dimTotal.getHeight()); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileRepeat2.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileRepeat2.java new file mode 100644 index 000000000..e2b12be86 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileRepeat2.java @@ -0,0 +1,316 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.MathUtils; +import net.sourceforge.plantuml.SpriteContainer; +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.activitydiagram3.LinkRendering; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractConnection; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractFtile; +import net.sourceforge.plantuml.activitydiagram3.ftile.Arrows; +import net.sourceforge.plantuml.activitydiagram3.ftile.Connection; +import net.sourceforge.plantuml.activitydiagram3.ftile.Diamond; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileUtils; +import net.sourceforge.plantuml.activitydiagram3.ftile.Snake; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamond; +import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamondFoo1; +import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamondInside; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.svek.ConditionStyle; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +class FtileRepeat2 extends AbstractFtile { + + private final Ftile repeat; + private final Ftile diamond1; + private final Ftile diamond2; + private final TextBlock tbTest; + + private FtileRepeat2(Ftile repeat, Ftile diamond1, Ftile diamond2, TextBlock tbTest) { + super(repeat.shadowing()); + this.repeat = repeat; + this.diamond1 = diamond1; + this.diamond2 = diamond2; + this.tbTest = tbTest; + } + + public Swimlane getSwimlaneIn() { + return repeat.getSwimlaneIn(); + } + + public Swimlane getSwimlaneOut() { + return getSwimlaneIn(); + } + + public Set getSwimlanes() { + return repeat.getSwimlanes(); + } + + public static Ftile create(Swimlane swimlane, Ftile repeat, Display test, HtmlColor borderColor, + HtmlColor backColor, UFont font, HtmlColor arrowColor, HtmlColor endRepeatLinkColor, + ConditionStyle conditionStyle, SpriteContainer spriteContainer) { + + final FontConfiguration fc = new FontConfiguration(font, HtmlColorUtils.BLACK); + final TextBlock tbTest = TextBlockUtils.create(test, fc, HorizontalAlignment.LEFT, spriteContainer); + + final Ftile diamond1 = new FtileDiamond(repeat.shadowing(), backColor, borderColor, swimlane); + final FtileRepeat2 result; + if (conditionStyle == ConditionStyle.INSIDE) { + final Ftile diamond2 = new FtileDiamondInside(repeat.shadowing(), backColor, borderColor, swimlane, tbTest); + result = new FtileRepeat2(repeat, diamond1, diamond2, TextBlockUtils.empty(0, 0)); + } else if (conditionStyle == ConditionStyle.DIAMOND) { + final Ftile diamond2 = new FtileDiamond(repeat.shadowing(), backColor, borderColor, swimlane) + .withEast(tbTest); + result = new FtileRepeat2(repeat, diamond1, diamond2, tbTest); + } else if (conditionStyle == ConditionStyle.FOO1) { + final Ftile diamond2 = new FtileDiamondFoo1(repeat.shadowing(), backColor, borderColor, swimlane, tbTest); + result = new FtileRepeat2(repeat, diamond1, diamond2, TextBlockUtils.empty(0, 0)); + } else { + throw new IllegalStateException(); + } + + final List conns = new ArrayList(); + conns.add(result.new ConnectionIn(LinkRendering.getColor(repeat.getInLinkRendering(), arrowColor))); + conns.add(result.new ConnectionBack(arrowColor)); + conns.add(result.new ConnectionOut(LinkRendering.getColor(endRepeatLinkColor, arrowColor))); + return FtileUtils.addConnection(result, conns); + } + + class ConnectionIn extends AbstractConnection { + private final HtmlColor arrowColor; + + public ConnectionIn(HtmlColor arrowColor) { + super(diamond1, repeat); + this.arrowColor = arrowColor; + } + + private Point2D getP1(final StringBounder stringBounder) { + return getTranslateDiamond1(stringBounder).getTranslated(getFtile1().getPointOut(stringBounder)); + } + + private Point2D getP2(final StringBounder stringBounder) { + return getTranslateForRepeat(stringBounder).getTranslated(getFtile2().getPointIn(stringBounder)); + } + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + + final Snake snake = new Snake(arrowColor, Arrows.asToDown()); + snake.addPoint(getP1(stringBounder)); + snake.addPoint(getP2(stringBounder)); + + ug.draw(snake); + } + } + + class ConnectionOut extends AbstractConnection { + private final HtmlColor arrowColor; + + public ConnectionOut(HtmlColor arrowColor) { + super(repeat, diamond2); + this.arrowColor = arrowColor; + } + + private Point2D getP1(final StringBounder stringBounder) { + return getTranslateForRepeat(stringBounder).getTranslated(getFtile1().getPointOut(stringBounder)); + } + + private Point2D getP2(final StringBounder stringBounder) { + return getTranslateDiamond2(stringBounder).getTranslated(getFtile2().getPointIn(stringBounder)); + } + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + + final Snake snake = new Snake(arrowColor, Arrows.asToDown()); + snake.addPoint(getP1(stringBounder)); + snake.addPoint(getP2(stringBounder)); + + ug.draw(snake); + } + } + + class ConnectionBack extends AbstractConnection { + private final HtmlColor arrowColor; + + public ConnectionBack(HtmlColor arrowColor) { + super(diamond2, repeat); + this.arrowColor = arrowColor; + } + + private Point2D getP1(final StringBounder stringBounder) { + return getTranslateDiamond2(stringBounder).getTranslated(new Point2D.Double(0, 0)); + } + + private Point2D getP2(final StringBounder stringBounder) { + return getTranslateDiamond1(stringBounder).getTranslated(new Point2D.Double(0, 0)); + } + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + + final Snake snake = new Snake(arrowColor, Arrows.asToLeft()); + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + final Point2D p1 = getP1(stringBounder); + final Point2D p2 = getP2(stringBounder); + final Dimension2D dimDiamond1 = diamond1.asTextBlock().calculateDimension(stringBounder); + final Dimension2D dimDiamond2 = diamond2.asTextBlock().calculateDimension(stringBounder); + final double x1 = p1.getX() + dimDiamond2.getWidth(); + final double y1 = p1.getY() + dimDiamond2.getHeight() / 2; + final double x2 = p2.getX() + dimDiamond1.getWidth(); + final double y2 = p2.getY() + dimDiamond1.getHeight() / 2; + + snake.addPoint(x1, y1); + final double yy = dimTotal.getWidth() - Diamond.diamondHalfSize; + snake.addPoint(yy, y1); + snake.addPoint(yy, y2); + snake.addPoint(x2, y2); + + ug.draw(snake); + ug = ug.apply(new UChangeColor(arrowColor)).apply(new UChangeBackColor(arrowColor)); + ug.apply(new UTranslate(yy, dimTotal.getHeight() / 2)).draw(Arrows.asToUp()); + } + + } + + public TextBlock asTextBlock() { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + ug.apply(getTranslateForRepeat(stringBounder)).draw(repeat); + ug.apply(getTranslateDiamond1(stringBounder)).draw(diamond1); + ug.apply(getTranslateDiamond2(stringBounder)).draw(diamond2); + + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return calculateDimensionInternal(stringBounder); + } + }; + } + + public boolean isKilled() { + return false; + } + + private Dimension2D calculateDimensionInternal(StringBounder stringBounder) { + final Dimension2D dimDiamond1 = diamond1.asTextBlock().calculateDimension(stringBounder); + final Dimension2D dimDiamond2 = diamond2.asTextBlock().calculateDimension(stringBounder); + final double w = tbTest.calculateDimension(stringBounder).getWidth(); + + final Dimension2D dim = Dimension2DDouble.atLeast(repeat.asTextBlock().calculateDimension(stringBounder), 2 * w + + 2 * Diamond.diamondHalfSize, 0); + final double width = MathUtils.max(dimDiamond1.getWidth(), dim.getWidth(), dimDiamond2.getWidth()); + final double height = dimDiamond1.getHeight() + dim.getHeight() + dimDiamond2.getHeight(); + + final Dimension2D result = new Dimension2DDouble(width, height); + return Dimension2DDouble.delta(result, 4 * Diamond.diamondHalfSize, 8 * Diamond.diamondHalfSize); + + } + + @Override + public UTranslate getTranslateFor(Ftile child, StringBounder stringBounder) { + if (child == repeat) { + return getTranslateForRepeat(stringBounder); + } + if (child == diamond1) { + return getTranslateDiamond1(stringBounder); + } + throw new UnsupportedOperationException(); + } + + private UTranslate getTranslateForRepeat(StringBounder stringBounder) { + final Dimension2D dimDiamond1 = diamond1.asTextBlock().calculateDimension(stringBounder); + final Dimension2D dimDiamond2 = diamond2.asTextBlock().calculateDimension(stringBounder); + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + final Dimension2D dimRepeat = repeat.asTextBlock().calculateDimension(stringBounder); + + final double x = (dimTotal.getWidth() - dimRepeat.getWidth()) / 2; + final double y = (dimTotal.getHeight() - dimDiamond1.getHeight() - dimDiamond2.getHeight() - dimRepeat + .getHeight()) / 2; + return new UTranslate(x, y); + + } + + private UTranslate getTranslateDiamond1(StringBounder stringBounder) { + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + final Dimension2D dimDiamond1 = diamond1.asTextBlock().calculateDimension(stringBounder); + + final double x1 = (dimTotal.getWidth() - dimDiamond1.getWidth()) / 2; + final double y1 = 0; + return new UTranslate(x1, y1); + } + + private UTranslate getTranslateDiamond2(StringBounder stringBounder) { + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + final Dimension2D dimDiamond2 = diamond2.asTextBlock().calculateDimension(stringBounder); + + final double x2 = (dimTotal.getWidth() - dimDiamond2.getWidth()) / 2; + final double y2 = dimTotal.getHeight() - dimDiamond2.getHeight(); + return new UTranslate(x2, y2); + } + + public Point2D getPointIn(StringBounder stringBounder) { + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + return new Point2D.Double(dimTotal.getWidth() / 2, 0); + } + + public Point2D getPointOut(StringBounder stringBounder) { + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + return new Point2D.Double(dimTotal.getWidth() / 2, dimTotal.getHeight()); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileWhile.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileWhile.java new file mode 100644 index 000000000..3a299eba6 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileWhile.java @@ -0,0 +1,219 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.Set; + +import net.sourceforge.plantuml.SpriteContainer; +import net.sourceforge.plantuml.activitydiagram3.LinkRendering; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractConnection; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractFtile; +import net.sourceforge.plantuml.activitydiagram3.ftile.Arrows; +import net.sourceforge.plantuml.activitydiagram3.ftile.Diamond; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileAssemblySimple; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileEmpty; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileUtils; +import net.sourceforge.plantuml.activitydiagram3.ftile.Snake; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDecorateIn; +import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamond; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UEmpty; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +class FtileWhile extends AbstractFtile { + + private final Ftile whileBlock; + + public Set getSwimlanes() { + return whileBlock.getSwimlanes(); + } + + public Swimlane getSwimlaneIn() { + return whileBlock.getSwimlaneIn(); + } + + public Swimlane getSwimlaneOut() { + return getSwimlaneIn(); + } + + private FtileWhile(Ftile whileBlock) { + super(whileBlock.shadowing()); + this.whileBlock = whileBlock; + + } + + private static TextBlock createLabel1(Display test, Display yes, UFont font, SpriteContainer spriteContainer) { + final FontConfiguration fc = new FontConfiguration(font, HtmlColorUtils.BLACK); + final TextBlock tmpb = TextBlockUtils.create(yes, fc, HorizontalAlignment.LEFT, spriteContainer); + if (test == null) { + return tmpb; + } + return TextBlockUtils.mergeTB(TextBlockUtils.create(test, fc, HorizontalAlignment.LEFT, spriteContainer), tmpb, + HorizontalAlignment.CENTER); + } + + public static Ftile create(Ftile whileBlock, Display test, HtmlColor borderColor, HtmlColor backColor, + HtmlColor arrowColor, Display yes, Display out2, UFont font, HtmlColor endInlinkColor, + LinkRendering afterEndwhile, FtileFactory ftileFactory) { + + final TextBlock label1 = createLabel1(test, yes, font, ftileFactory); + final FontConfiguration fc = new FontConfiguration(font, HtmlColorUtils.BLACK); + final TextBlock out = TextBlockUtils.create(out2, fc, HorizontalAlignment.LEFT, ftileFactory); + + final Ftile diamond = new FtileDiamond(whileBlock.shadowing(), backColor, borderColor, + whileBlock.getSwimlaneOut()).withNorth(label1).withWest(out); + final FtileWhile wh = new FtileWhile(whileBlock); + HtmlColor afterEndwhileColor = arrowColor; + if (afterEndwhile != null && afterEndwhile.getColor() != null) { + afterEndwhileColor = afterEndwhile.getColor(); + } + + Ftile result = ftileFactory.assembly(diamond, new FtileDecorateIn(wh, whileBlock.getInLinkRendering())); + result = FtileUtils.addConnection(result, new ConnectionBack(result, diamond, endInlinkColor)); + result = new FtileAssemblySimple(result, new FtileEmpty(wh.shadowing(), 0, 2 * Diamond.diamondHalfSize, null, + result.getSwimlaneOut())); + result = FtileUtils.addConnection(result, new ConnectionOut(result, diamond, afterEndwhileColor)); + + return FtileUtils.withSwimlaneOut(result, result.getSwimlaneIn()); + } + + static class ConnectionBack extends AbstractConnection { + final private Ftile full; + private final HtmlColor endInlinkColor; + + public ConnectionBack(Ftile result, Ftile diamond, HtmlColor endInlinkColor) { + super(diamond, diamond); + this.full = result; + this.endInlinkColor = endInlinkColor; + } + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + + final Point2D pout = full.getPointOut(stringBounder); + + final Snake snake = new Snake(endInlinkColor, Arrows.asToLeft()); + final Dimension2D dimTotal = full.asTextBlock().calculateDimension(stringBounder); + + final double posY1 = pout.getY(); + snake.addPoint(pout.getX(), posY1); + snake.addPoint(pout.getX(), posY1 + Diamond.diamondHalfSize); + final double posX = dimTotal.getWidth() + Diamond.diamondHalfSize; + snake.addPoint(posX, posY1 + Diamond.diamondHalfSize); + final double posY2 = Diamond.diamondHalfSize; + snake.addPoint(posX, posY2); + snake.addPoint(dimTotal.getWidth() / 2 + Diamond.diamondHalfSize, posY2); + + ug = ug.apply(new UChangeColor(endInlinkColor)).apply(new UChangeBackColor(endInlinkColor)); + ug.apply(new UTranslate(posX, posY2 + (posY1 - posY2) / 2)).draw(Arrows.asToUp()); + ug.draw(snake); + + ug.apply(new UTranslate(dimTotal.getWidth() / 2, posY1 + Diamond.diamondHalfSize)).draw( + new UEmpty(5, Diamond.diamondHalfSize)); + + } + } + + static class ConnectionOut extends AbstractConnection { + private final HtmlColor afterEndwhileColor; + private final Ftile full; + + public ConnectionOut(Ftile full, Ftile diamond, HtmlColor afterEndwhileColor) { + super(diamond, diamond); + this.afterEndwhileColor = afterEndwhileColor; + this.full = full; + } + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + final Snake snake = new Snake(afterEndwhileColor); + final Dimension2D dimTotal = full.asTextBlock().calculateDimension(stringBounder); + final double posY1 = Diamond.diamondHalfSize; + snake.addPoint(dimTotal.getWidth() / 2 - Diamond.diamondHalfSize, posY1); + final double posX = -Diamond.diamondHalfSize; + snake.addPoint(posX, posY1); + final double posY2 = dimTotal.getHeight(); + snake.addPoint(posX, posY2); + snake.addPoint(dimTotal.getWidth() / 2, posY2); + + ug = ug.apply(new UChangeColor(afterEndwhileColor)).apply(new UChangeBackColor(afterEndwhileColor)); + ug.apply(new UTranslate(posX, posY1 + (posY2 - posY1) / 2)).draw(Arrows.asToDown()); + ug.draw(snake); + } + } + + public TextBlock asTextBlock() { + return new TextBlock() { + + public void drawU(UGraphic ug) { + ug.draw(whileBlock); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return whileBlock.asTextBlock().calculateDimension(stringBounder); + } + }; + } + + public boolean isKilled() { + return false; + } + + public Point2D getPointIn(StringBounder stringBounder) { + final Dimension2D dimTotal = asTextBlock().calculateDimension(stringBounder); + return new Point2D.Double(dimTotal.getWidth() / 2, 0); + } + + public Point2D getPointOut(StringBounder stringBounder) { + final Dimension2D dimTotal = asTextBlock().calculateDimension(stringBounder); + return new Point2D.Double(dimTotal.getWidth() / 2, dimTotal.getHeight()); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileWhile2.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileWhile2.java new file mode 100644 index 000000000..9c4d6aa89 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileWhile2.java @@ -0,0 +1,407 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.MathUtils; +import net.sourceforge.plantuml.SpriteContainer; +import net.sourceforge.plantuml.activitydiagram3.LinkRendering; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractConnection; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractFtile; +import net.sourceforge.plantuml.activitydiagram3.ftile.Arrows; +import net.sourceforge.plantuml.activitydiagram3.ftile.Connection; +import net.sourceforge.plantuml.activitydiagram3.ftile.ConnectionTranslatable; +import net.sourceforge.plantuml.activitydiagram3.ftile.Diamond; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileUtils; +import net.sourceforge.plantuml.activitydiagram3.ftile.Snake; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamond; +import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamondFoo1; +import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDiamondInside; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.svek.ConditionStyle; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UEmpty; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +class FtileWhile2 extends AbstractFtile { + + private final Ftile whileBlock; + private final Ftile diamond1; + private final TextBlock supplementarySouthText; + + public Set getSwimlanes() { + final Set result = new HashSet(whileBlock.getSwimlanes()); + result.add(getSwimlaneIn()); + return result; + } + + public Swimlane getSwimlaneIn() { + return diamond1.getSwimlaneIn(); + } + + public Swimlane getSwimlaneOut() { + return getSwimlaneIn(); + } + + private FtileWhile2(Ftile whileBlock, Ftile diamond1, TextBlock supplementarySouthText) { + super(whileBlock.shadowing()); + this.whileBlock = whileBlock; + this.diamond1 = diamond1; + this.supplementarySouthText = supplementarySouthText; + } + + private static TextBlock createLabel1(Display test, Display yes, UFont font, SpriteContainer spriteContainer) { + final FontConfiguration fc = new FontConfiguration(font, HtmlColorUtils.BLACK); + final TextBlock tmpb = TextBlockUtils.create(yes, fc, HorizontalAlignment.LEFT, spriteContainer); + if (test == null) { + return tmpb; + } + return TextBlockUtils.mergeTB(TextBlockUtils.create(test, fc, HorizontalAlignment.LEFT, spriteContainer), tmpb, + HorizontalAlignment.CENTER); + } + + public static Ftile create(Swimlane swimlane, Ftile whileBlock, Display test, HtmlColor borderColor, + HtmlColor backColor, HtmlColor arrowColor, Display yes, Display out2, UFont font, HtmlColor endInlinkColor, + LinkRendering afterEndwhile, FtileFactory ftileFactory, ConditionStyle conditionStyle) { + + // final TextBlock label1 = createLabel1(test, yes, font); + final FontConfiguration fc = new FontConfiguration(font, HtmlColorUtils.BLACK); + final TextBlock yesTb = TextBlockUtils.create(yes, fc, HorizontalAlignment.LEFT, ftileFactory); + final TextBlock testTb = TextBlockUtils.create(test, fc, HorizontalAlignment.LEFT, ftileFactory); + final TextBlock out = TextBlockUtils.create(out2, fc, HorizontalAlignment.LEFT, ftileFactory); + + final Ftile diamond1; + final TextBlock supplementarySouthText; + if (conditionStyle == ConditionStyle.INSIDE) { + supplementarySouthText = TextBlockUtils.empty(0, 0); + diamond1 = new FtileDiamondInside(whileBlock.shadowing(), backColor, borderColor, swimlane, testTb) + .withNorth(yesTb).withWest(out); + } else if (conditionStyle == ConditionStyle.FOO1) { + supplementarySouthText = TextBlockUtils.empty(0, 0); + diamond1 = new FtileDiamondFoo1(whileBlock.shadowing(), backColor, borderColor, swimlane, testTb) + .withNorth(yesTb).withWest(out); + } else if (conditionStyle == ConditionStyle.DIAMOND) { + supplementarySouthText = createLabel1(test, yes, font, ftileFactory); + diamond1 = new FtileDiamond(whileBlock.shadowing(), backColor, borderColor, swimlane).withWest(out) + .withSouth(supplementarySouthText); + } else { + throw new IllegalStateException(); + } + + final FtileWhile2 result = new FtileWhile2(whileBlock, diamond1, supplementarySouthText); + HtmlColor afterEndwhileColor = arrowColor; + if (afterEndwhile != null && afterEndwhile.getColor() != null) { + afterEndwhileColor = afterEndwhile.getColor(); + } + + final List conns = new ArrayList(); + conns.add(result.new ConnectionIn(LinkRendering.getColor(whileBlock.getInLinkRendering(), arrowColor))); + conns.add(result.new ConnectionBack(endInlinkColor)); + conns.add(result.new ConnectionOut(afterEndwhileColor)); + return FtileUtils.addConnection(result, conns); + } + + class ConnectionIn extends AbstractConnection implements ConnectionTranslatable { + private final HtmlColor arrowColor; + + public ConnectionIn(HtmlColor arrowColor) { + super(diamond1, whileBlock); + this.arrowColor = arrowColor; + } + + private Point2D getP1(final StringBounder stringBounder) { + return getTranslateDiamond1(stringBounder).getTranslated(getFtile1().getPointOut(stringBounder)); + } + + private Point2D getP2(final StringBounder stringBounder) { + return getTranslateForWhile(stringBounder).getTranslated(getFtile2().getPointIn(stringBounder)); + } + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + + final Snake snake = new Snake(arrowColor, Arrows.asToDown()); + snake.addPoint(getP1(stringBounder)); + snake.addPoint(getP2(stringBounder)); + + ug.draw(snake); + } + + public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { + final StringBounder stringBounder = ug.getStringBounder(); + final Point2D p1 = getP1(stringBounder); + final Point2D p2 = getP2(stringBounder); + final Snake snake = new Snake(arrowColor, Arrows.asToDown()); + final Point2D mp1a = translate1.getTranslated(p1); + final Point2D mp2b = translate2.getTranslated(p2); + final double middle = (mp1a.getY() + mp2b.getY()) / 2.0; + snake.addPoint(mp1a); + snake.addPoint(mp1a.getX(), middle); + snake.addPoint(mp2b.getX(), middle); + snake.addPoint(mp2b); + ug.draw(snake); + } + } + + class ConnectionBack extends AbstractConnection implements ConnectionTranslatable { + private final HtmlColor endInlinkColor; + + public ConnectionBack(HtmlColor endInlinkColor) { + super(whileBlock, diamond1); + this.endInlinkColor = endInlinkColor; + } + + private Point2D getP1(final StringBounder stringBounder) { + return getTranslateForWhile(stringBounder).getTranslated(whileBlock.getPointOut(stringBounder)); + } + + private Point2D getP2(final StringBounder stringBounder) { + return getTranslateDiamond1(stringBounder).getTranslated(new Point2D.Double(0, 0)); + } + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + + final Snake snake = new Snake(endInlinkColor, Arrows.asToLeft()); + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + final Point2D p1 = getP1(stringBounder); + if (p1 == null) { + return; + } + final Point2D p2 = getP2(stringBounder); + final Dimension2D dimDiamond1 = diamond1.asTextBlock().calculateDimension(stringBounder); + + final double x1 = p1.getX(); + final double y1 = p1.getY(); + final double x2 = p2.getX() + dimDiamond1.getWidth(); + final double y2 = p2.getY() + dimDiamond1.getHeight() / 2; + + snake.addPoint(x1, y1); + snake.addPoint(x1, y1 + Diamond.diamondHalfSize); + final double xx = dimTotal.getWidth() - Diamond.diamondHalfSize; + snake.addPoint(xx, y1 + Diamond.diamondHalfSize); + snake.addPoint(xx, y2); + snake.addPoint(x2, y2); + + ug.draw(snake); + + ug.apply(new UTranslate(x1, y1 + Diamond.diamondHalfSize)).draw(new UEmpty(5, Diamond.diamondHalfSize)); + + ug = ug.apply(new UChangeColor(endInlinkColor)).apply(new UChangeBackColor(endInlinkColor)); + ug.apply(new UTranslate(xx, (y1 + y2) / 2)).draw(Arrows.asToUp()); + } + + public void drawTranslate(UGraphic ug, UTranslate translate1, UTranslate translate2) { + final StringBounder stringBounder = ug.getStringBounder(); + final Snake snake = new Snake(endInlinkColor, Arrows.asToLeft()); + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + final Point2D ap1 = getP1(stringBounder); + final Point2D ap2 = getP2(stringBounder); + final Point2D p1 = translate1.getTranslated(ap1); + final Point2D p2 = translate2.getTranslated(ap2); + + final Dimension2D dimDiamond1 = diamond1.asTextBlock().calculateDimension(stringBounder); + + final double x1 = p1.getX(); + final double y1 = p1.getY(); + final double x2 = p2.getX() + dimDiamond1.getWidth(); + final double y2 = p2.getY() + dimDiamond1.getHeight() / 2; + + snake.addPoint(x1, y1); + snake.addPoint(x1, y1 + Diamond.diamondHalfSize); + final double xx = Math.max(translate1.getDx(), translate2.getDx()) + dimTotal.getWidth() + - Diamond.diamondHalfSize; + snake.addPoint(xx, y1 + Diamond.diamondHalfSize); + snake.addPoint(xx, y2); + snake.addPoint(x2, y2); + + ug.draw(snake); + + ug.apply(new UTranslate(x1, y1 + Diamond.diamondHalfSize)).draw(new UEmpty(5, Diamond.diamondHalfSize)); + + ug = ug.apply(new UChangeColor(endInlinkColor)).apply(new UChangeBackColor(endInlinkColor)); + ug.apply(new UTranslate(xx, (y1 + y2) / 2)).draw(Arrows.asToUp()); + + } + + } + + class ConnectionOut extends AbstractConnection { + private final HtmlColor afterEndwhileColor; + + public ConnectionOut(HtmlColor afterEndwhileColor) { + super(diamond1, null); + this.afterEndwhileColor = afterEndwhileColor; + } + + private Point2D getP1(final StringBounder stringBounder) { + return getTranslateDiamond1(stringBounder).getTranslated(new Point2D.Double(0, 0)); + } + + private Point2D getP2(final StringBounder stringBounder) { + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + return new Point2D.Double(dimTotal.getWidth() / 2, dimTotal.getHeight()); + } + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + + final Snake snake = new Snake(afterEndwhileColor); + + final Dimension2D dimDiamond1 = diamond1.asTextBlock().calculateDimension(stringBounder); + final Point2D p1 = getP1(stringBounder); + final Point2D p2 = getP2(stringBounder); + + final double x1 = p1.getX(); + final double y1 = p1.getY() + dimDiamond1.getHeight() / 2; + final double x2 = p2.getX(); + final double y2 = p2.getY(); + + snake.addPoint(x1, y1); + snake.addPoint(Diamond.diamondHalfSize, y1); + snake.addPoint(Diamond.diamondHalfSize, y2); + // snake.addPoint(x2, y2); + + ug.draw(snake); + ug = ug.apply(new UChangeColor(afterEndwhileColor)).apply(new UChangeBackColor(afterEndwhileColor)); + ug.apply(new UTranslate(Diamond.diamondHalfSize, (y1 + y2) / 2)).draw(Arrows.asToDown()); + + final Snake snake2 = new Snake(afterEndwhileColor, true); + snake2.addPoint(Diamond.diamondHalfSize, y2); + snake2.addPoint(x2, y2); + ug.draw(snake2); + + } + } + + public TextBlock asTextBlock() { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + ug.apply(getTranslateForWhile(stringBounder)).draw(whileBlock); + ug.apply(getTranslateDiamond1(stringBounder)).draw(diamond1); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return calculateDimensionInternal(stringBounder); + } + }; + } + + private Dimension2D calculateDimensionInternal(StringBounder stringBounder) { + final Dimension2D dimDiamond1 = diamond1.asTextBlock().calculateDimension(stringBounder); + final Dimension2D dimSupplementarySouth = supplementarySouthText.calculateDimension(stringBounder); + final Dimension2D dimWhile = whileBlock.asTextBlock().calculateDimension(stringBounder); + + final double width = MathUtils.max(dimDiamond1.getWidth(), dimWhile.getWidth()); + final double height = dimDiamond1.getHeight() + dimWhile.getHeight(); + + Dimension2D result = new Dimension2DDouble(width, height); + result = Dimension2DDouble.max(result, dimSupplementarySouth); + return Dimension2DDouble.delta(result, 4 * Diamond.diamondHalfSize, 8 * Diamond.diamondHalfSize); + + } + + @Override + public UTranslate getTranslateFor(Ftile child, StringBounder stringBounder) { + if (child == whileBlock) { + return getTranslateForWhile(stringBounder); + } + if (child == diamond1) { + return getTranslateDiamond1(stringBounder); + } + throw new UnsupportedOperationException(); + } + + private UTranslate getTranslateForWhile(StringBounder stringBounder) { + final Dimension2D dimDiamond1 = diamond1.asTextBlock().calculateDimension(stringBounder); + + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + final Dimension2D dimWhile = whileBlock.asTextBlock().calculateDimension(stringBounder); + + final double x = (dimTotal.getWidth() - dimWhile.getWidth()) / 2; + // final double y = dimDiamond1.getHeight(); + + final double y = dimDiamond1.getHeight() + + (dimTotal.getHeight() - dimDiamond1.getHeight() - dimWhile.getHeight()) / 2; + + return new UTranslate(x, y); + + } + + private UTranslate getTranslateDiamond1(StringBounder stringBounder) { + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + final Dimension2D dimDiamond1 = diamond1.asTextBlock().calculateDimension(stringBounder); + + final double x1 = (dimTotal.getWidth() - dimDiamond1.getWidth()) / 2; + final double y1 = 0; + return new UTranslate(x1, y1); + } + + public boolean isKilled() { + return false; + } + + public Point2D getPointIn(StringBounder stringBounder) { + final Dimension2D dimTotal = asTextBlock().calculateDimension(stringBounder); + return new Point2D.Double(dimTotal.getWidth() / 2, 0); + } + + public Point2D getPointOut(StringBounder stringBounder) { + final Dimension2D dimTotal = asTextBlock().calculateDimension(stringBounder); + return new Point2D.Double(dimTotal.getWidth() / 2, dimTotal.getHeight()); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileWithNoteOpale.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileWithNoteOpale.java new file mode 100644 index 000000000..ac185b756 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/FtileWithNoteOpale.java @@ -0,0 +1,193 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.Set; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.Direction; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.OptionFlags; +import net.sourceforge.plantuml.SkinParam; +import net.sourceforge.plantuml.UmlDiagramType; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractFtile; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.creole.CreoleParser; +import net.sourceforge.plantuml.creole.Sheet; +import net.sourceforge.plantuml.creole.SheetBlock; +import net.sourceforge.plantuml.creole.Stencil; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.sequencediagram.NotePosition; +import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.svek.image.Opale; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UStroke; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class FtileWithNoteOpale extends AbstractFtile implements Stencil { + + private final Ftile tile; + private final Opale opale; + + private final HtmlColor arrowColor; + private final NotePosition notePosition; + private final double halfSuppSpace = 20; + + public Set getSwimlanes() { + return tile.getSwimlanes(); + } + + public Swimlane getSwimlaneIn() { + return tile.getSwimlaneIn(); + } + + public Swimlane getSwimlaneOut() { + return tile.getSwimlaneOut(); + } + + public FtileWithNoteOpale(Ftile tile, Display note, HtmlColor arrowColor, NotePosition notePosition) { + super(tile.shadowing()); + this.tile = tile; + this.notePosition = notePosition; + this.arrowColor = arrowColor; + + final SkinParam skinParam = new SkinParam(UmlDiagramType.ACTIVITY); + if (shadowing() == false) { + skinParam.setParam("shadowing", "false"); + } + + final Rose rose = new Rose(); + final HtmlColor fontColor = rose.getFontColor(skinParam, FontParam.NOTE); + final UFont fontNote = skinParam.getFont(FontParam.NOTE, null); + + final HtmlColor noteBackgroundColor = rose.getHtmlColor(skinParam, ColorParam.noteBackground); + final HtmlColor borderColor = rose.getHtmlColor(skinParam, ColorParam.noteBorder); + + final FontConfiguration fc = new FontConfiguration(fontNote, fontColor); + final TextBlock text; + if (OptionFlags.USE_CREOLE) { + final Sheet sheet = new CreoleParser(fc, skinParam).createSheet(note); + text = new SheetBlock(sheet, this, new UStroke(1)); + } else { + text = TextBlockUtils.create(note, fc, HorizontalAlignment.LEFT, skinParam); + } + opale = new Opale(borderColor, noteBackgroundColor, text, skinParam.shadowing()); + + } + + public Point2D getPointIn(StringBounder stringBounder) { + return getTranslate(stringBounder).getTranslated(tile.getPointIn(stringBounder)); + } + + public Point2D getPointOut(StringBounder stringBounder) { + return getTranslate(stringBounder).getTranslated(tile.getPointOut(stringBounder)); + } + + private UTranslate getTranslate(StringBounder stringBounder) { + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + final Dimension2D dimNote = opale.calculateDimension(stringBounder); + final Dimension2D dimTile = tile.asTextBlock().calculateDimension(stringBounder); + final double yForFtile = (dimTotal.getHeight() - dimTile.getHeight()) / 2; + final double marge = dimNote.getWidth() + halfSuppSpace; + return new UTranslate(marge, yForFtile); + + } + + public TextBlock asTextBlock() { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + final Dimension2D dimTotal = calculateDimension(stringBounder); + final Dimension2D dimNote = opale.calculateDimension(stringBounder); + final Dimension2D dimTile = tile.asTextBlock().calculateDimension(stringBounder); + final double yForNote = (dimTotal.getHeight() - dimNote.getHeight()) / 2; + final double yForFtile = (dimTotal.getHeight() - dimTile.getHeight()) / 2; + + final double marge = dimNote.getWidth() + halfSuppSpace; + if (notePosition == NotePosition.LEFT) { + final Direction strategy = Direction.RIGHT; + final Point2D pp1 = new Point2D.Double(dimNote.getWidth(), dimNote.getHeight() / 2); + final Point2D pp2 = new Point2D.Double(marge, dimNote.getHeight() / 2); + opale.setOpale(strategy, pp1, pp2); + opale.drawU(ug.apply(new UTranslate(0, yForNote))); + } else { + final double dx = dimTotal.getWidth() - dimNote.getWidth(); + final Direction strategy = Direction.LEFT; + final Point2D pp1 = new Point2D.Double(0, dimNote.getHeight() / 2); + final Point2D pp2 = new Point2D.Double(-halfSuppSpace, dimNote.getHeight() / 2); + opale.setOpale(strategy, pp1, pp2); + opale.drawU(ug.apply(new UTranslate(dx, yForNote))); + } + ug.apply(getTranslate(stringBounder)).draw(tile); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return calculateDimensionInternal(stringBounder); + } + }; + } + + public boolean isKilled() { + return tile.isKilled(); + } + + private Dimension2D calculateDimensionInternal(StringBounder stringBounder) { + final Dimension2D dimNote = opale.calculateDimension(stringBounder); + final Dimension2D dimTile = tile.asTextBlock().calculateDimension(stringBounder); + final double height = Math.max(dimNote.getHeight(), dimTile.getHeight()); + return new Dimension2DDouble(dimTile.getWidth() + 2 * dimNote.getWidth() + halfSuppSpace * 2, height); + } + + public double getStartingX(StringBounder stringBounder, double y) { + return -opale.getMarginX1(); + } + + public double getEndingX(StringBounder stringBounder, double y) { + return opale.calculateDimension(stringBounder).getWidth() - opale.getMarginX1(); + // return calculateDimensionInternal(stringBounder).getWidth(); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/UGraphicInterceptorOneSwimlane.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/UGraphicInterceptorOneSwimlane.java new file mode 100644 index 000000000..6d307cc30 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/UGraphicInterceptorOneSwimlane.java @@ -0,0 +1,87 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 10266 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact; + +import java.util.Set; + +import net.sourceforge.plantuml.activitydiagram3.ftile.Connection; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.graphic.UGraphicDelegator; +import net.sourceforge.plantuml.ugraphic.UChange; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UShape; + +public class UGraphicInterceptorOneSwimlane extends UGraphicDelegator { + + private final Swimlane swimlane; + + public UGraphicInterceptorOneSwimlane(UGraphic ug, Swimlane swimlane) { + super(ug); + this.swimlane = swimlane; + } + + public void draw(UShape shape) { + // System.err.println("inter=" + shape.getClass()); + if (shape instanceof Ftile) { + final Ftile tile = (Ftile) shape; + final Set swinlanes = tile.getSwimlanes(); + final boolean contained = swinlanes.contains(swimlane); + if (contained) { + tile.asTextBlock().drawU(this); + } + } else if (shape instanceof Connection) { + final Connection connection = (Connection) shape; + final Ftile tile1 = connection.getFtile1(); + final Ftile tile2 = connection.getFtile2(); + final boolean contained1 = tile1 == null || tile1.getSwimlaneOut() == null + || tile1.getSwimlaneOut() == swimlane; + final boolean contained2 = tile2 == null || tile2.getSwimlaneIn() == null + || tile2.getSwimlaneIn() == swimlane; + if (contained1 && contained2) { + connection.drawU(this); + } + } else { + getUg().draw(shape); + // System.err.println("Drawing " + shape); + } + + } + + public UGraphic apply(UChange change) { + return new UGraphicInterceptorOneSwimlane(getUg().apply(change), swimlane); + } + + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/VCompactFactory.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/VCompactFactory.java new file mode 100644 index 000000000..638d4f9fe --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vcompact/VCompactFactory.java @@ -0,0 +1,155 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vcompact; + +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.activitydiagram3.Branch; +import net.sourceforge.plantuml.activitydiagram3.LinkRendering; +import net.sourceforge.plantuml.activitydiagram3.ftile.BoxStyle; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileAssemblySimple; +import net.sourceforge.plantuml.activitydiagram3.ftile.FtileFactory; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileBox; +import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileCircleStart; +import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileCircleStop; +import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDecorateIn; +import net.sourceforge.plantuml.activitydiagram3.ftile.vertical.FtileDecorateOut; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.sequencediagram.NotePosition; +import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.ugraphic.Sprite; +import net.sourceforge.plantuml.ugraphic.UFont; + +public class VCompactFactory implements FtileFactory { + + private final ISkinParam skinParam; + private final Rose rose = new Rose(); + private final StringBounder stringBounder; + + public StringBounder getStringBounder() { + return stringBounder; + } + + public VCompactFactory(ISkinParam skinParam, StringBounder stringBounder) { + this.skinParam = skinParam; + this.stringBounder = stringBounder; + } + + public Ftile start(Swimlane swimlane) { + final HtmlColor color = rose.getHtmlColor(skinParam, ColorParam.activityStart); + return new FtileCircleStart(shadowing(), color, swimlane); + } + + public Ftile stop(Swimlane swimlane) { + final HtmlColor color = rose.getHtmlColor(skinParam, ColorParam.activityEnd); + return new FtileCircleStop(shadowing(), color, swimlane); + } + + public Ftile activity(Display label, final HtmlColor color, Swimlane swimlane, BoxStyle style) { + final HtmlColor borderColor = rose.getHtmlColor(skinParam, ColorParam.activityBorder); + final HtmlColor backColor = color == null ? rose.getHtmlColor(skinParam, ColorParam.activityBackground) : color; + final UFont font = skinParam.getFont(FontParam.ACTIVITY2, null); + final HtmlColor arrowColor = rose.getHtmlColor(skinParam, ColorParam.activityArrow); + return new FtileBox(shadowing(), label, borderColor, backColor, font, arrowColor, swimlane, style, skinParam); + } + + public Ftile addNote(Ftile ftile, Display note, NotePosition notePosition) { + return ftile; + } + + public Ftile assembly(Ftile tile1, Ftile tile2) { + return new FtileAssemblySimple(tile1, tile2); + } + + public Ftile repeat(Swimlane swimlane, Ftile repeat, Display test) { + return repeat; + } + + public Ftile createWhile(Swimlane swimlane, Ftile whileBlock, Display test, Display yes, Display out, + LinkRendering afterEndwhile) { + return whileBlock; + } + + public Ftile createIf(Swimlane swimlane, List thens, Branch elseBranch) { + final List ftiles = new ArrayList(); + for (Branch branch : thens) { + ftiles.add(branch.getFtile()); + } + ftiles.add(elseBranch.getFtile()); + return new FtileForkInner(ftiles); + } + + public Ftile createFork(List all) { + return new FtileForkInner(all); + } + + public Ftile createSplit(List all) { + return new FtileForkInner(all); + } + + public Ftile createGroup(Ftile list, Display name) { + return list; + } + + public Ftile decorateIn(final Ftile ftile, final LinkRendering linkRendering) { + return new FtileDecorateIn(ftile, linkRendering); + } + + public Ftile decorateOut(final Ftile ftile, final LinkRendering linkRendering) { + // if (ftile instanceof FtileWhile) { + // if (linkRendering != null) { + // ((FtileWhile) ftile).changeAfterEndwhileColor(linkRendering.getColor()); + // } + // return ftile; + // } + return new FtileDecorateOut(ftile, linkRendering); + } + + public boolean shadowing() { + return skinParam.shadowing(); + } + + public Sprite getSprite(String name) { + return skinParam.getSprite(name); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileBlackBlock.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileBlackBlock.java new file mode 100644 index 000000000..12d498566 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileBlackBlock.java @@ -0,0 +1,108 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vertical; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.Collections; +import java.util.Set; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractFtile; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.URectangle; + +public class FtileBlackBlock extends AbstractFtile { + + private final double width; + private final double height; + private final HtmlColor colorBar; + private final Swimlane swimlane; + + public FtileBlackBlock(boolean shadowing, double width, double height, HtmlColor colorBar, Swimlane swimlane) { + super(shadowing); + this.height = height; + this.width = width; + this.colorBar = colorBar; + this.swimlane = swimlane; + } + + public Point2D getPointIn(StringBounder stringBounder) { + return new Point2D.Double(width / 2, 0); + } + + public Point2D getPointOut(StringBounder stringBounder) { + return new Point2D.Double(width / 2, height); + } + + public TextBlock asTextBlock() { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final URectangle rect = new URectangle(width, height, 5, 5); + if (shadowing()) { + rect.setDeltaShadow(3); + } + ug.apply(new UChangeColor(colorBar)).apply(new UChangeBackColor(colorBar)).draw(rect); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return new Dimension2DDouble(width, height); + } + }; + } + + public boolean isKilled() { + return false; + } + + public Set getSwimlanes() { + return Collections.singleton(swimlane); + } + + public Swimlane getSwimlaneIn() { + return swimlane; + } + + public Swimlane getSwimlaneOut() { + return swimlane; + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileBox.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileBox.java new file mode 100644 index 000000000..537186e51 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileBox.java @@ -0,0 +1,174 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vertical; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.Collections; +import java.util.Set; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.OptionFlags; +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.activitydiagram3.LinkRendering; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractFtile; +import net.sourceforge.plantuml.activitydiagram3.ftile.BoxStyle; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.creole.CreoleParser; +import net.sourceforge.plantuml.creole.Sheet; +import net.sourceforge.plantuml.creole.SheetBlock; +import net.sourceforge.plantuml.creole.Stencil; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.graphic.UDrawable; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UStroke; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class FtileBox extends AbstractFtile { + + private static final int MARGIN = 10; + + private final TextBlock tb; + + private final HtmlColor color; + private final HtmlColor backColor; + private final LinkRendering inRenreding; + private final Swimlane swimlane; + private final BoxStyle style; + + final public LinkRendering getInLinkRendering() { + return inRenreding; + } + + public Set getSwimlanes() { + if (swimlane == null) { + return Collections.emptySet(); + } + return Collections.singleton(swimlane); + } + + public Swimlane getSwimlaneIn() { + return swimlane; + } + + public Swimlane getSwimlaneOut() { + return swimlane; + } + + class MyStencil implements Stencil { + + public double getStartingX(StringBounder stringBounder, double y) { + return -MARGIN; + } + + public double getEndingX(StringBounder stringBounder, double y) { + final Dimension2D dim = asTextBlock().calculateDimension(stringBounder); + return dim.getWidth() - MARGIN; + } + + } + + public FtileBox(boolean shadowing, Display label, HtmlColor color, HtmlColor backColor, UFont font, + HtmlColor arrowColor, Swimlane swimlane, BoxStyle style, ISkinParam skinParam) { + super(shadowing); + this.style = style; + this.color = color; + this.swimlane = swimlane; + this.backColor = backColor; + this.inRenreding = new LinkRendering(arrowColor); + final FontConfiguration fc = new FontConfiguration(font, HtmlColorUtils.BLACK); + if (OptionFlags.USE_CREOLE) { + final Sheet sheet = new CreoleParser(fc, skinParam).createSheet(label); + tb = new SheetBlock(sheet, new MyStencil(), new UStroke(1)); + } else { + tb = TextBlockUtils.create(label, fc, HorizontalAlignment.LEFT, skinParam); + } + this.print = label.toString(); + } + + final private String print; + + @Override + public String toString() { + return print; + } + + public TextBlock asTextBlock() { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final Dimension2D dimTotal = calculateDimension(ug.getStringBounder()); + final double widthTotal = dimTotal.getWidth(); + final double heightTotal = dimTotal.getHeight(); + final UDrawable rect = style.getUDrawable(widthTotal, heightTotal, shadowing()); + + ug = ug.apply(new UChangeColor(color)).apply(new UChangeBackColor(backColor)).apply(new UStroke(1.5)); + rect.drawU(ug); + + tb.drawU(ug.apply(new UTranslate(MARGIN, MARGIN))); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + final Dimension2D dim = tb.calculateDimension(stringBounder); + return Dimension2DDouble.delta(dim, 2 * MARGIN, 2 * MARGIN); + } + }; + } + + public boolean isKilled() { + return false; + } + + public Point2D getPointIn(StringBounder stringBounder) { + final Dimension2D dim = tb.calculateDimension(stringBounder); + return new Point2D.Double(dim.getWidth() / 2 + MARGIN, 0); + } + + public Point2D getPointOut(StringBounder stringBounder) { + final Dimension2D dim = tb.calculateDimension(stringBounder); + return new Point2D.Double(dim.getWidth() / 2 + MARGIN, dim.getHeight() + 2 * MARGIN); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileCircleStart.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileCircleStart.java new file mode 100644 index 000000000..3e6a776ab --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileCircleStart.java @@ -0,0 +1,109 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 5183 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vertical; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.Collections; +import java.util.Set; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractFtile; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UEllipse; +import net.sourceforge.plantuml.ugraphic.UGraphic; + +public class FtileCircleStart extends AbstractFtile { + + private static final int SIZE = 20; + + private final HtmlColor backColor; + private final Swimlane swimlane; + + public FtileCircleStart(boolean shadowing, HtmlColor backColor, Swimlane swimlane) { + super(shadowing); + this.backColor = backColor; + this.swimlane = swimlane; + } + + public Set getSwimlanes() { + if (swimlane == null) { + return Collections.emptySet(); + } + return Collections.singleton(swimlane); + } + + public Swimlane getSwimlaneIn() { + return swimlane; + } + + public Swimlane getSwimlaneOut() { + return swimlane; + } + + public TextBlock asTextBlock() { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final UEllipse circle = new UEllipse(SIZE, SIZE); + if (shadowing()) { + circle.setDeltaShadow(3); + } + ug.apply(new UChangeColor(null)).apply(new UChangeBackColor(backColor)).draw(circle); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return new Dimension2DDouble(SIZE, SIZE); + } + }; + } + + public boolean isKilled() { + return false; + } + + public Point2D getPointIn(StringBounder stringBounder) { + return new Point2D.Double(SIZE / 2, 0); + } + + public Point2D getPointOut(StringBounder stringBounder) { + return new Point2D.Double(SIZE / 2, SIZE); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileCircleStop.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileCircleStop.java new file mode 100644 index 000000000..a95b44873 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileCircleStop.java @@ -0,0 +1,125 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 5183 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vertical; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.Collections; +import java.util.Set; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractFtile; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UEllipse; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class FtileCircleStop extends AbstractFtile { + + private static final int SIZE = 20; + + private final HtmlColor backColor; + private final Swimlane swimlane; + + public FtileCircleStop(boolean shadowing, HtmlColor backColor, Swimlane swimlane) { + super(shadowing); + this.backColor = backColor; + this.swimlane = swimlane; + } + + public Set getSwimlanes() { + if (swimlane == null) { + return Collections.emptySet(); + } + return Collections.singleton(swimlane); + } + + public Swimlane getSwimlaneIn() { + return swimlane; + } + + public Swimlane getSwimlaneOut() { + return swimlane; + } + + public TextBlock asTextBlock() { + return new TextBlock() { + + public void drawU(UGraphic ug) { + double xTheoricalPosition = 0; + double yTheoricalPosition = 0; + xTheoricalPosition = Math.round(xTheoricalPosition); + yTheoricalPosition = Math.round(yTheoricalPosition); + + final UEllipse circle = new UEllipse(SIZE, SIZE); + if (shadowing()) { + circle.setDeltaShadow(3); + } + ug.apply(new UChangeColor(backColor)).apply(new UChangeBackColor(null)) + .apply(new UTranslate(xTheoricalPosition, yTheoricalPosition)).draw(circle); + + final double delta = 4; + final UEllipse circleSmall = new UEllipse(SIZE - delta * 2, SIZE - delta * 2); + if (shadowing()) { + circleSmall.setDeltaShadow(3); + } + ug.apply(new UChangeColor(null)).apply(new UChangeBackColor(backColor)) + .apply(new UTranslate(xTheoricalPosition + delta + .5, yTheoricalPosition + delta + .5)) + .draw(circleSmall); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return new Dimension2DDouble(SIZE, SIZE); + } + }; + } + + public boolean isKilled() { + return true; + } + + public Point2D getPointIn(StringBounder stringBounder) { + return new Point2D.Double(SIZE / 2, 0); + } + + public Point2D getPointOut(StringBounder stringBounder) { + return null; + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDecorate.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDecorate.java new file mode 100644 index 000000000..8fd00eed7 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDecorate.java @@ -0,0 +1,113 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vertical; + +import java.awt.geom.Point2D; +import java.util.Collection; +import java.util.Set; + +import net.sourceforge.plantuml.activitydiagram3.LinkRendering; +import net.sourceforge.plantuml.activitydiagram3.ftile.Connection; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public abstract class FtileDecorate implements Ftile { + + final private Ftile ftile; + + public FtileDecorate(final Ftile ftile) { + this.ftile = ftile; + } + + @Override + public String toString() { + return "" + getClass() + " " + ftile; + } + + public boolean isKilled() { + return ftile.isKilled(); + } + + public LinkRendering getOutLinkRendering() { + return ftile.getOutLinkRendering(); + } + + public LinkRendering getInLinkRendering() { + return ftile.getInLinkRendering(); + } + + public TextBlock asTextBlock() { + return ftile.asTextBlock(); + } + + public Point2D getPointIn(StringBounder stringBounder) { + return ftile.getPointIn(stringBounder); + } + + public Point2D getPointOut(StringBounder stringBounder) { + return ftile.getPointOut(stringBounder); + } + + public Collection getInnerConnections() { + return ftile.getInnerConnections(); + } + + public UTranslate getTranslateFor(Ftile child, StringBounder stringBounder) { + return ftile.getTranslateFor(child, stringBounder); + } + + public Set getSwimlanes() { + return ftile.getSwimlanes(); + } + + public Swimlane getSwimlaneIn() { + return ftile.getSwimlaneIn(); + } + + public Swimlane getSwimlaneOut() { + return ftile.getSwimlaneOut(); + } + + public boolean shadowing() { + return ftile.shadowing(); + } + + protected final Ftile getFtileDelegated() { + return ftile; + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDecorateIn.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDecorateIn.java new file mode 100644 index 000000000..4ddb360ae --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDecorateIn.java @@ -0,0 +1,52 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vertical; + +import net.sourceforge.plantuml.activitydiagram3.LinkRendering; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; + +public class FtileDecorateIn extends FtileDecorate { + + final private LinkRendering linkRendering; + + public FtileDecorateIn(final Ftile ftile, final LinkRendering linkRendering) { + super(ftile); + this.linkRendering = linkRendering; + } + + public LinkRendering getInLinkRendering() { + return linkRendering; + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDecorateOut.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDecorateOut.java new file mode 100644 index 000000000..9cb2144e6 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDecorateOut.java @@ -0,0 +1,52 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vertical; + +import net.sourceforge.plantuml.activitydiagram3.LinkRendering; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; + +public class FtileDecorateOut extends FtileDecorate { + + final private LinkRendering linkRendering; + + public FtileDecorateOut(final Ftile ftile, final LinkRendering linkRendering) { + super(ftile); + this.linkRendering = linkRendering; + } + + public LinkRendering getOutLinkRendering() { + return linkRendering; + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDecoratePointOut.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDecoratePointOut.java new file mode 100644 index 000000000..32d0e2c04 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDecoratePointOut.java @@ -0,0 +1,66 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vertical; + +import java.awt.geom.Point2D; + +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; + +public class FtileDecoratePointOut extends FtileDecorate { + + final private double dx; + final private double dy; + + public FtileDecoratePointOut(final Ftile ftile, final double dx, double dy) { + super(ftile); + this.dx = dx; + this.dy = dy; + } + + @Override + public Point2D getPointOut(StringBounder stringBounder) { + final Point2D pt = super.getPointOut(stringBounder); + return new Point2D.Double(pt.getX() + dx, pt.getY() + dy); + } + + @Override + public TextBlock asTextBlock() { + final TextBlock result = super.asTextBlock(); + return TextBlockUtils.withMargin(result, 0, 0, dx, dy); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDiamond.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDiamond.java new file mode 100644 index 000000000..292374705 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDiamond.java @@ -0,0 +1,163 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 5183 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vertical; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.Collections; +import java.util.Set; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractFtile; +import net.sourceforge.plantuml.activitydiagram3.ftile.Diamond; +import net.sourceforge.plantuml.activitydiagram3.ftile.Ftile; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UStroke; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class FtileDiamond extends AbstractFtile { + + private final HtmlColor backColor; + private final HtmlColor borderColor; + private final Swimlane swimlane; + private final TextBlock north; + private final TextBlock south; + private final TextBlock west1; + private final TextBlock east1; + + public FtileDiamond(boolean shadowing, HtmlColor backColor, HtmlColor borderColor, Swimlane swimlane) { + this(shadowing, backColor, borderColor, swimlane, TextBlockUtils.empty(0, 0), TextBlockUtils.empty(0, 0), + TextBlockUtils.empty(0, 0), TextBlockUtils.empty(0, 0)); + } + + public FtileDiamond withNorth(TextBlock north) { + return new FtileDiamond(shadowing(), backColor, borderColor, swimlane, north, south, east1, west1); + } + + public FtileDiamond withWest(TextBlock west1) { + return new FtileDiamond(shadowing(), backColor, borderColor, swimlane, north, south, east1, west1); + } + + public FtileDiamond withEast(TextBlock east1) { + return new FtileDiamond(shadowing(), backColor, borderColor, swimlane, north, south, east1, west1); + } + + public Ftile withSouth(TextBlock south) { + return new FtileDiamond(shadowing(), backColor, borderColor, swimlane, north, south, east1, west1); + } + + private FtileDiamond(boolean shadowing, HtmlColor backColor, HtmlColor borderColor, Swimlane swimlane, + TextBlock north, TextBlock south, TextBlock east1, TextBlock west1) { + super(shadowing); + this.backColor = backColor; + this.swimlane = swimlane; + this.borderColor = borderColor; + this.north = north; + this.west1 = west1; + this.east1 = east1; + this.south = south; + } + + public Set getSwimlanes() { + if (swimlane == null) { + return Collections.emptySet(); + } + return Collections.singleton(swimlane); + } + + public Swimlane getSwimlaneIn() { + return swimlane; + } + + public Swimlane getSwimlaneOut() { + return swimlane; + } + + public TextBlock asTextBlock() { + return new TextBlock() { + + public void drawU(UGraphic ug) { + + ug.apply(new UChangeColor(borderColor)).apply(new UStroke(1.5)).apply(new UChangeBackColor(backColor)) + .draw(Diamond.asPolygon(shadowing())); + final Dimension2D dimNorth = north.calculateDimension(ug.getStringBounder()); + north.drawU(ug.apply(new UTranslate(Diamond.diamondHalfSize * 1.5, -dimNorth.getHeight() + - Diamond.diamondHalfSize))); + + final Dimension2D dimSouth = south.calculateDimension(ug.getStringBounder()); + south.drawU(ug.apply(new UTranslate(-(dimSouth.getWidth() - 2 * Diamond.diamondHalfSize) / 2, + 2 * Diamond.diamondHalfSize))); + + final Dimension2D dimWeat1 = west1.calculateDimension(ug.getStringBounder()); + west1.drawU(ug.apply(new UTranslate(-dimWeat1.getWidth(), -dimWeat1.getHeight() + + Diamond.diamondHalfSize))); + + final Dimension2D dimEast1 = east1.calculateDimension(ug.getStringBounder()); + east1.drawU(ug.apply(new UTranslate(Diamond.diamondHalfSize * 2, -dimEast1.getHeight() + + Diamond.diamondHalfSize))); + + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return calculateDimensionInternal(stringBounder); + } + }; + } + + private Dimension2D calculateDimensionInternal(StringBounder stringBounder) { + return new Dimension2DDouble(Diamond.diamondHalfSize * 2, Diamond.diamondHalfSize * 2); + } + + public boolean isKilled() { + return false; + } + + public Point2D getPointIn(StringBounder stringBounder) { + return new Point2D.Double(calculateDimensionInternal(stringBounder).getWidth() / 2, 0); + } + + public Point2D getPointOut(StringBounder stringBounder) { + // return new Point2D.Double(calculateDimensionInternal(stringBounder).getWidth() / 2, Diamond.diamondHalfSize * 2); + final Dimension2D dim = calculateDimensionInternal(stringBounder); + return new Point2D.Double(dim.getWidth() / 2, dim.getHeight()); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDiamondFoo1.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDiamondFoo1.java new file mode 100644 index 000000000..1da28dc09 --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDiamondFoo1.java @@ -0,0 +1,170 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 5183 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vertical; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.Collections; +import java.util.Set; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractFtile; +import net.sourceforge.plantuml.activitydiagram3.ftile.Diamond; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UStroke; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class FtileDiamondFoo1 extends AbstractFtile { + + private final HtmlColor backColor; + private final HtmlColor borderColor; + private final Swimlane swimlane; + private final TextBlock label; + private final TextBlock west; + private final TextBlock east; + private final TextBlock north; + + public FtileDiamondFoo1(boolean shadowing, HtmlColor backColor, HtmlColor borderColor, Swimlane swimlane, + TextBlock label) { + this(shadowing, backColor, borderColor, swimlane, label, TextBlockUtils.empty(0, 0), + TextBlockUtils.empty(0, 0), TextBlockUtils.empty(0, 0)); + } + + public FtileDiamondFoo1 withNorth(TextBlock north) { + return new FtileDiamondFoo1(shadowing(), backColor, borderColor, swimlane, label, north, west, east); + } + + public FtileDiamondFoo1 withWest(TextBlock west) { + return new FtileDiamondFoo1(shadowing(), backColor, borderColor, swimlane, label, north, west, east); + } + + public FtileDiamondFoo1 withEast(TextBlock east) { + return new FtileDiamondFoo1(shadowing(), backColor, borderColor, swimlane, label, north, west, east); + } + + private FtileDiamondFoo1(boolean shadowing, HtmlColor backColor, HtmlColor borderColor, Swimlane swimlane, + TextBlock label, TextBlock north, TextBlock west, TextBlock east) { + super(shadowing); + this.backColor = backColor; + this.swimlane = swimlane; + this.borderColor = borderColor; + this.label = label; + this.west = west; + this.east = east; + this.north = north; + } + + public Set getSwimlanes() { + if (swimlane == null) { + return Collections.emptySet(); + } + return Collections.singleton(swimlane); + } + + public Swimlane getSwimlaneIn() { + return swimlane; + } + + public Swimlane getSwimlaneOut() { + return swimlane; + } + + public TextBlock asTextBlock() { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + final Dimension2D dimLabel = label.calculateDimension(stringBounder); + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + ug = ug.apply(new UChangeColor(borderColor)).apply(new UStroke(1.5)) + .apply(new UChangeBackColor(backColor)); + ug.draw(Diamond.asPolygonFoo1(shadowing(), dimTotal.getWidth(), dimTotal.getHeight())); + + north.drawU(ug.apply(new UTranslate(4 + dimTotal.getWidth() / 2, dimTotal.getHeight()))); + + final double lx = (dimTotal.getWidth() - dimLabel.getWidth()) / 2; + final double ly = (dimTotal.getHeight() - dimLabel.getHeight()) / 2; + label.drawU(ug.apply(new UTranslate(lx, ly))); + + final Dimension2D dimWeat = west.calculateDimension(stringBounder); + west.drawU(ug.apply(new UTranslate(-dimWeat.getWidth(), -dimWeat.getHeight() + Diamond.diamondHalfSize))); + + final Dimension2D dimEast = east.calculateDimension(stringBounder); + east.drawU(ug.apply(new UTranslate(dimTotal.getWidth(), -dimEast.getHeight() + Diamond.diamondHalfSize))); + + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return calculateDimensionInternal(stringBounder); + } + }; + } + + private Dimension2D calculateDimensionInternal(StringBounder stringBounder) { + final Dimension2D dimLabel = label.calculateDimension(stringBounder); + if (dimLabel.getWidth() == 0 || dimLabel.getHeight() == 0) { + return new Dimension2DDouble(Diamond.diamondHalfSize * 2, Diamond.diamondHalfSize * 2); + } + Dimension2D result = dimLabel;// Dimension2DDouble.atLeast(dimLabel, Diamond.diamondHalfSize * 2, + // Diamond.diamondHalfSize * 2); + result = Dimension2DDouble.delta(result, Diamond.diamondHalfSize * 2, Diamond.diamondHalfSize * 2); + return result; + } + + public boolean isKilled() { + return false; + } + + public Point2D getPointIn(StringBounder stringBounder) { + return new Point2D.Double(calculateDimensionInternal(stringBounder).getWidth() / 2, 0); + } + + public Point2D getPointOut(StringBounder stringBounder) { + final Dimension2D dim = calculateDimensionInternal(stringBounder); + return new Point2D.Double(dim.getWidth() / 2, dim.getHeight()); + } + + // private double getDeltaX(StringBounder stringBounder) { + // return calculateDimensionInternal(stringBounder).getWidth() - + // Diamond.diamondHalfSize * 2; + // } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDiamondInside.java b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDiamondInside.java new file mode 100644 index 000000000..ef17a3eaa --- /dev/null +++ b/src/net/sourceforge/plantuml/activitydiagram3/ftile/vertical/FtileDiamondInside.java @@ -0,0 +1,172 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 5183 $ + * + */ +package net.sourceforge.plantuml.activitydiagram3.ftile.vertical; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.Collections; +import java.util.Set; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.activitydiagram3.ftile.AbstractFtile; +import net.sourceforge.plantuml.activitydiagram3.ftile.Diamond; +import net.sourceforge.plantuml.activitydiagram3.ftile.Swimlane; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UStroke; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class FtileDiamondInside extends AbstractFtile { + + private final HtmlColor backColor; + private final HtmlColor borderColor; + private final Swimlane swimlane; + private final TextBlock label; + private final TextBlock west; + private final TextBlock east; + private final TextBlock north; + + public FtileDiamondInside(boolean shadowing, HtmlColor backColor, HtmlColor borderColor, Swimlane swimlane, + TextBlock label) { + this(shadowing, backColor, borderColor, swimlane, label, TextBlockUtils.empty(0, 0), + TextBlockUtils.empty(0, 0), TextBlockUtils.empty(0, 0)); + } + + public FtileDiamondInside withNorth(TextBlock north) { + return new FtileDiamondInside(shadowing(), backColor, borderColor, swimlane, label, north, west, east); + } + + public FtileDiamondInside withWest(TextBlock west) { + return new FtileDiamondInside(shadowing(), backColor, borderColor, swimlane, label, north, west, east); + } + + public FtileDiamondInside withEast(TextBlock east) { + return new FtileDiamondInside(shadowing(), backColor, borderColor, swimlane, label, north, west, east); + } + + private FtileDiamondInside(boolean shadowing, HtmlColor backColor, HtmlColor borderColor, Swimlane swimlane, + TextBlock label, TextBlock north, TextBlock west, TextBlock east) { + super(shadowing); + this.backColor = backColor; + this.swimlane = swimlane; + this.borderColor = borderColor; + this.label = label; + this.west = west; + this.east = east; + this.north = north; + } + + public Set getSwimlanes() { + if (swimlane == null) { + return Collections.emptySet(); + } + return Collections.singleton(swimlane); + } + + public Swimlane getSwimlaneIn() { + return swimlane; + } + + public Swimlane getSwimlaneOut() { + return swimlane; + } + + public TextBlock asTextBlock() { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + final Dimension2D dimLabel = label.calculateDimension(stringBounder); + final Dimension2D dimTotal = calculateDimensionInternal(stringBounder); + ug = ug.apply(new UChangeColor(borderColor)).apply(new UStroke(1.5)) + .apply(new UChangeBackColor(backColor)); + ug.draw(Diamond.asPolygon(shadowing(), dimTotal.getWidth(), dimTotal.getHeight())); + + // final Dimension2D dimNorth = west.calculateDimension(stringBounder); + north.drawU(ug.apply(new UTranslate(4 + dimTotal.getWidth() / 2, dimTotal.getHeight()))); + + final double lx = (dimTotal.getWidth() - dimLabel.getWidth()) / 2; + final double ly = (dimTotal.getHeight() - dimLabel.getHeight()) / 2; + label.drawU(ug.apply(new UTranslate(lx, ly))); + + final Dimension2D dimWeat = west.calculateDimension(stringBounder); + west.drawU(ug.apply(new UTranslate(-dimWeat.getWidth(), -dimWeat.getHeight() + Diamond.diamondHalfSize))); + + final Dimension2D dimEast = east.calculateDimension(stringBounder); + east.drawU(ug.apply(new UTranslate(dimTotal.getWidth(), -dimEast.getHeight() + Diamond.diamondHalfSize))); + + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return calculateDimensionInternal(stringBounder); + } + }; + } + + private Dimension2D calculateDimensionInternal(StringBounder stringBounder) { + final Dimension2D dimLabel = label.calculateDimension(stringBounder); + if (dimLabel.getWidth() == 0 || dimLabel.getHeight() == 0) { + return new Dimension2DDouble(Diamond.diamondHalfSize * 2, Diamond.diamondHalfSize * 2); + } + Dimension2D result = Dimension2DDouble.atLeast(dimLabel, Diamond.diamondHalfSize * 2, + Diamond.diamondHalfSize * 2); + result = Dimension2DDouble.delta(result, Diamond.diamondHalfSize * 2, 0); + return result; + } + + public boolean isKilled() { + return false; + } + + public Point2D getPointIn(StringBounder stringBounder) { + return new Point2D.Double(calculateDimensionInternal(stringBounder).getWidth() / 2, 0); + } + + public Point2D getPointOut(StringBounder stringBounder) { + // return new Point2D.Double(calculateDimensionInternal(stringBounder).getWidth() / 2, Diamond.diamondHalfSize * 2); + final Dimension2D dim = calculateDimensionInternal(stringBounder); + return new Point2D.Double(dim.getWidth() / 2, dim.getHeight()); + } + + // private double getDeltaX(StringBounder stringBounder) { + // return calculateDimensionInternal(stringBounder).getWidth() - + // Diamond.diamondHalfSize * 2; + // } + +} diff --git a/src/net/sourceforge/plantuml/ant/PlantUmlTask.java b/src/net/sourceforge/plantuml/ant/PlantUmlTask.java index b850b99d4..7337d2fe8 100644 --- a/src/net/sourceforge/plantuml/ant/PlantUmlTask.java +++ b/src/net/sourceforge/plantuml/ant/PlantUmlTask.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6625 $ + * Revision $Revision: 11786 $ * */ package net.sourceforge.plantuml.ant; @@ -314,18 +314,6 @@ public class PlantUmlTask extends Task { 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); - } - } - public void setNbThread(String s) { if (s != null && s.matches("\\d+")) { option.setNbThreads(Integer.parseInt(s)); @@ -357,4 +345,9 @@ public class PlantUmlTask extends Task { OptionFlags.getInstance().setFailOnError(flag); } + public void setOverwrite(String s) { + final boolean flag = "true".equalsIgnoreCase(s) || "yes".equalsIgnoreCase(s) || "on".equalsIgnoreCase(s); + OptionFlags.getInstance().setOverwrite(flag); + } + } diff --git a/src/net/sourceforge/plantuml/api/ImageDataComplex.java b/src/net/sourceforge/plantuml/api/ImageDataComplex.java new file mode 100644 index 000000000..c05e0d0fe --- /dev/null +++ b/src/net/sourceforge/plantuml/api/ImageDataComplex.java @@ -0,0 +1,80 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 9885 $ + * + */ +package net.sourceforge.plantuml.api; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.CMapData; +import net.sourceforge.plantuml.core.ImageData; + +public class ImageDataComplex implements ImageData { + + private final Dimension2D info; + private final CMapData cmap; + private final String warningOrError; + +// public ImageDataComplex(Dimension2D info, CMapData cmap) { +// this(info, cmap, null); +// } + + public ImageDataComplex(Dimension2D info, CMapData cmap, String warningOrError) { + if (info==null) { + throw new IllegalArgumentException(); + } + this.info = info; + this.cmap = cmap; + this.warningOrError = warningOrError; + } + + public int getWidth() { + return (int) info.getWidth(); + } + + public int getHeight() { + return (int) info.getHeight(); + } + + public boolean containsCMapData() { + return cmap != null && cmap.containsData(); + } + + public String getCMapData(String nameId) { + return cmap.asString(nameId); + } + + public String getWarningOrError() { + return warningOrError; + } + +} diff --git a/src/net/sourceforge/plantuml/api/ImageDataSimple.java b/src/net/sourceforge/plantuml/api/ImageDataSimple.java new file mode 100644 index 000000000..c8844b763 --- /dev/null +++ b/src/net/sourceforge/plantuml/api/ImageDataSimple.java @@ -0,0 +1,78 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 9885 $ + * + */ +package net.sourceforge.plantuml.api; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.core.ImageData; + +public class ImageDataSimple implements ImageData { + + private final int width; + private final int height; + + public ImageDataSimple(int width, int height) { + this.width = width; + this.height = height; + } + + public ImageDataSimple() { + this(0, 0); + } + + public ImageDataSimple(Dimension2D dim) { + this((int) dim.getWidth(), (int) dim.getHeight()); + } + + public int getWidth() { + return width; + } + + public int getHeight() { + return height; + } + + public boolean containsCMapData() { + return false; + } + + public String getCMapData(String nameId) { + throw new UnsupportedOperationException(); + } + + public String getWarningOrError() { + return null; + } + +} diff --git a/src/net/sourceforge/plantuml/PSystemFactory.java b/src/net/sourceforge/plantuml/api/PSystemFactory.java similarity index 76% rename from src/net/sourceforge/plantuml/PSystemFactory.java rename to src/net/sourceforge/plantuml/api/PSystemFactory.java index bc659c5e8..8126d74f2 100644 --- a/src/net/sourceforge/plantuml/PSystemFactory.java +++ b/src/net/sourceforge/plantuml/api/PSystemFactory.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,17 +28,19 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6750 $ + * Revision $Revision: 9786 $ * */ -package net.sourceforge.plantuml; +package net.sourceforge.plantuml.api; + +import net.sourceforge.plantuml.core.Diagram; +import net.sourceforge.plantuml.core.DiagramType; +import net.sourceforge.plantuml.core.UmlSource; public interface PSystemFactory { - PSystem getSystem(); + Diagram createSystem(UmlSource source); - void init(String startLine); - DiagramType getDiagramType(); } diff --git a/src/net/sourceforge/plantuml/api/PlantumlUtils.java b/src/net/sourceforge/plantuml/api/PlantumlUtils.java new file mode 100644 index 000000000..54a6989ae --- /dev/null +++ b/src/net/sourceforge/plantuml/api/PlantumlUtils.java @@ -0,0 +1,58 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 9786 $ + * + */ +package net.sourceforge.plantuml.api; + +import java.util.List; + +import net.sourceforge.plantuml.BlockUml; +import net.sourceforge.plantuml.SourceStringReader; +import net.sourceforge.plantuml.core.Diagram; + +public class PlantumlUtils { + + public static boolean hasCMapData(String uml) { + List blocks = new SourceStringReader(uml).getBlocks(); + if (blocks.size() == 0) { + uml = "@startuml\n" + uml + "\n@enduml"; + blocks = new SourceStringReader(uml).getBlocks(); + if (blocks.size() == 0) { + return false; + } + } + final BlockUml block = blocks.get(0); + final Diagram diagram = block.getDiagram(); + return diagram.hasUrl(); + } + +} diff --git a/src/net/sourceforge/plantuml/api/doc-files/umls.html b/src/net/sourceforge/plantuml/api/doc-files/umls.html new file mode 100644 index 000000000..5480f8fbd --- /dev/null +++ b/src/net/sourceforge/plantuml/api/doc-files/umls.html @@ -0,0 +1,40 @@ + + +@startuml img1.png +title API +component API +@enduml + + + diff --git a/src/net/sourceforge/plantuml/api/package.html b/src/net/sourceforge/plantuml/api/package.html new file mode 100644 index 000000000..37e6b9af7 --- /dev/null +++ b/src/net/sourceforge/plantuml/api/package.html @@ -0,0 +1,44 @@ + + + +

Public API for calling PlantUML from Java.

+ +

Overview

+ +

+This package provides an API for generating UML diagram from Java application. +

+ + + diff --git a/src/net/sourceforge/plantuml/applet/VersionApplet.java b/src/net/sourceforge/plantuml/applet/VersionApplet.java index 7108f416b..f90a8825a 100644 --- a/src/net/sourceforge/plantuml/applet/VersionApplet.java +++ b/src/net/sourceforge/plantuml/applet/VersionApplet.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -50,6 +50,6 @@ public class VersionApplet extends Applet { @Override public void paint(Graphics g) { - g.drawString("" + Version.version(), 0, 10); + g.drawString(Version.versionString(), 0, 10); } } diff --git a/src/net/sourceforge/plantuml/asciiart/BasicCharArea.java b/src/net/sourceforge/plantuml/asciiart/BasicCharArea.java index e0eeba873..26702cc98 100644 --- a/src/net/sourceforge/plantuml/asciiart/BasicCharArea.java +++ b/src/net/sourceforge/plantuml/asciiart/BasicCharArea.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/asciiart/BasicCharAreaImpl.java b/src/net/sourceforge/plantuml/asciiart/BasicCharAreaImpl.java index c822cf160..1aa0951f2 100644 --- a/src/net/sourceforge/plantuml/asciiart/BasicCharAreaImpl.java +++ b/src/net/sourceforge/plantuml/asciiart/BasicCharAreaImpl.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5178 $ + * Revision $Revision: 12012 $ * */ package net.sourceforge.plantuml.asciiart; @@ -49,7 +49,7 @@ public class BasicCharAreaImpl implements BasicCharArea { private char chars[][]; public BasicCharAreaImpl() { - chars = new char[charSize1][charSize2]; + this.chars = new char[charSize1][charSize2]; for (int i = 0; i < charSize1; i++) { for (int j = 0; j < charSize2; j++) { chars[i][j] = ' '; diff --git a/src/net/sourceforge/plantuml/asciiart/ComponentTextActiveLine.java b/src/net/sourceforge/plantuml/asciiart/ComponentTextActiveLine.java index 5014122ac..7cdd6cd2a 100644 --- a/src/net/sourceforge/plantuml/asciiart/ComponentTextActiveLine.java +++ b/src/net/sourceforge/plantuml/asciiart/ComponentTextActiveLine.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -37,6 +37,7 @@ import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.skin.Area; import net.sourceforge.plantuml.skin.Component; import net.sourceforge.plantuml.skin.Context2D; import net.sourceforge.plantuml.ugraphic.UGraphic; @@ -50,7 +51,8 @@ public class ComponentTextActiveLine implements Component { this.fileFormat = fileFormat; } - public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) { + public void drawU(UGraphic ug, Area area, Context2D context) { + final Dimension2D dimensionToUse = area.getDimensionToUse(); final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea(); final int width = (int) dimensionToUse.getWidth(); final int height = (int) dimensionToUse.getHeight(); diff --git a/src/net/sourceforge/plantuml/asciiart/ComponentTextActor.java b/src/net/sourceforge/plantuml/asciiart/ComponentTextActor.java index 7df0e1651..6f2f75267 100644 --- a/src/net/sourceforge/plantuml/asciiart/ComponentTextActor.java +++ b/src/net/sourceforge/plantuml/asciiart/ComponentTextActor.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -34,11 +34,12 @@ 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.cucadiagram.Display; import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.skin.Area; import net.sourceforge.plantuml.skin.Component; import net.sourceforge.plantuml.skin.ComponentType; import net.sourceforge.plantuml.skin.Context2D; @@ -48,16 +49,17 @@ import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt; public class ComponentTextActor implements Component { private final ComponentType type; - private final List stringsToDisplay; + private final Display stringsToDisplay; private final FileFormat fileFormat; - public ComponentTextActor(ComponentType type, List stringsToDisplay, FileFormat fileFormat) { + public ComponentTextActor(ComponentType type, Display stringsToDisplay, FileFormat fileFormat) { this.type = type; this.stringsToDisplay = stringsToDisplay; this.fileFormat = fileFormat; } - public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) { + public void drawU(UGraphic ug, Area area, Context2D context) { + final Dimension2D dimensionToUse = area.getDimensionToUse(); final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea(); final int width = (int) dimensionToUse.getWidth(); // final int textWidth = StringUtils.getWidth(stringsToDisplay); @@ -66,14 +68,14 @@ public class ComponentTextActor implements Component { final int xman = width / 2 - 1; if (type == ComponentType.ACTOR_HEAD) { - charArea.drawStringsLR(stringsToDisplay, 1, getStickManHeight()); + charArea.drawStringsLR(stringsToDisplay.as(), 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); + charArea.drawStringsLR(stringsToDisplay.as(), 1, 0); if (fileFormat == FileFormat.UTXT) { charArea.drawStickManUnicode(xman, 1); } else { diff --git a/src/net/sourceforge/plantuml/asciiart/ComponentTextArrow.java b/src/net/sourceforge/plantuml/asciiart/ComponentTextArrow.java index a9222e64c..2f2af7d1d 100644 --- a/src/net/sourceforge/plantuml/asciiart/ComponentTextArrow.java +++ b/src/net/sourceforge/plantuml/asciiart/ComponentTextArrow.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -34,11 +34,15 @@ 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.cucadiagram.Display; import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.sequencediagram.MessageNumber; +import net.sourceforge.plantuml.skin.Area; +import net.sourceforge.plantuml.skin.ArrowConfiguration; +import net.sourceforge.plantuml.skin.ArrowDirection; import net.sourceforge.plantuml.skin.Component; import net.sourceforge.plantuml.skin.ComponentType; import net.sourceforge.plantuml.skin.Context2D; @@ -48,16 +52,41 @@ import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt; public class ComponentTextArrow implements Component { private final ComponentType type; - private final List stringsToDisplay; + private final Display stringsToDisplay; private final FileFormat fileFormat; + private final ArrowConfiguration config; - public ComponentTextArrow(ComponentType type, List stringsToDisplay, FileFormat fileFormat) { + public ComponentTextArrow(ComponentType type, ArrowConfiguration config, Display stringsToDisplay, + FileFormat fileFormat) { this.type = type; - this.stringsToDisplay = stringsToDisplay; + this.config = config; + this.stringsToDisplay = clean(stringsToDisplay); this.fileFormat = fileFormat; } - public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) { + private static Display clean(Display orig) { + if (orig.size() == 0 || orig.get(0) instanceof MessageNumber == false) { + return orig; + } + Display result = new Display(); + for (int i = 0; i < orig.size(); i++) { + CharSequence element = orig.get(i); + if (i == 1) { + element = removeTag(orig.get(0).toString()) + " " + element; + } + if (i != 0) { + result = result.add(element); + } + } + return result; + } + + private static String removeTag(String s) { + return s.replaceAll("\\<[^<>]+\\>", ""); + } + + public void drawU(UGraphic ug, Area area, Context2D context) { + final Dimension2D dimensionToUse = area.getDimensionToUse(); final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea(); final int width = (int) dimensionToUse.getWidth(); final int height = (int) dimensionToUse.getHeight(); @@ -65,20 +94,20 @@ public class ComponentTextArrow implements Component { final int yarrow = height - 2; charArea.drawHLine(fileFormat == FileFormat.UTXT ? '\u2500' : '-', yarrow, 1, width); - if (type.getArrowConfiguration().isDotted()) { + if (config.isDotted()) { for (int i = 1; i < width; i += 2) { charArea.drawChar(' ', i, yarrow); } } - if (type.getArrowConfiguration().isLeftToRightNormal()) { + if (config.getArrowDirection() == ArrowDirection.LEFT_TO_RIGHT_NORMAL) { charArea.drawChar('>', width - 1, yarrow); - } else if (type.getArrowConfiguration().isRightToLeftReverse()) { + } else if (config.getArrowDirection() == ArrowDirection.RIGHT_TO_LEFT_REVERSE) { charArea.drawChar('<', 1, yarrow); } else { throw new UnsupportedOperationException(); } - charArea.drawStringsLR(stringsToDisplay, (width - textWidth) / 2, 0); + charArea.drawStringsLR(stringsToDisplay.as(), (width - textWidth) / 2, 0); } public double getPreferredHeight(StringBounder stringBounder) { diff --git a/src/net/sourceforge/plantuml/asciiart/ComponentTextDivider.java b/src/net/sourceforge/plantuml/asciiart/ComponentTextDivider.java index d27d4980c..aefccc20b 100644 --- a/src/net/sourceforge/plantuml/asciiart/ComponentTextDivider.java +++ b/src/net/sourceforge/plantuml/asciiart/ComponentTextDivider.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -34,11 +34,12 @@ 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.cucadiagram.Display; import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.skin.Area; import net.sourceforge.plantuml.skin.Component; import net.sourceforge.plantuml.skin.ComponentType; import net.sourceforge.plantuml.skin.Context2D; @@ -48,16 +49,17 @@ import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt; public class ComponentTextDivider implements Component { private final ComponentType type; - private final List stringsToDisplay; + private final Display stringsToDisplay; private final FileFormat fileFormat; - public ComponentTextDivider(ComponentType type, List stringsToDisplay, FileFormat fileFormat) { + public ComponentTextDivider(ComponentType type, Display stringsToDisplay, FileFormat fileFormat) { this.type = type; this.stringsToDisplay = stringsToDisplay; this.fileFormat = fileFormat; } - public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) { + public void drawU(UGraphic ug, Area area, Context2D context) { + final Dimension2D dimensionToUse = area.getDimensionToUse(); final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea(); final int width = (int) dimensionToUse.getWidth(); final int textWidth = StringUtils.getWidth(stringsToDisplay); diff --git a/src/net/sourceforge/plantuml/asciiart/ComponentTextGroupingBody.java b/src/net/sourceforge/plantuml/asciiart/ComponentTextGroupingBody.java index b02cc0fa9..f59bfb214 100644 --- a/src/net/sourceforge/plantuml/asciiart/ComponentTextGroupingBody.java +++ b/src/net/sourceforge/plantuml/asciiart/ComponentTextGroupingBody.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -38,6 +38,7 @@ import java.util.List; import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.skin.Area; import net.sourceforge.plantuml.skin.Component; import net.sourceforge.plantuml.skin.ComponentType; import net.sourceforge.plantuml.skin.Context2D; @@ -57,7 +58,8 @@ public class ComponentTextGroupingBody implements Component { this.fileFormat = fileFormat; } - public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) { + public void drawU(UGraphic ug, Area area, Context2D context) { + final Dimension2D dimensionToUse = area.getDimensionToUse(); final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea(); final int width = (int) dimensionToUse.getWidth(); final int height = (int) dimensionToUse.getHeight(); diff --git a/src/net/sourceforge/plantuml/asciiart/ComponentTextGroupingElse.java b/src/net/sourceforge/plantuml/asciiart/ComponentTextGroupingElse.java index 27b6d8e65..f8843ecaa 100644 --- a/src/net/sourceforge/plantuml/asciiart/ComponentTextGroupingElse.java +++ b/src/net/sourceforge/plantuml/asciiart/ComponentTextGroupingElse.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -34,10 +34,11 @@ package net.sourceforge.plantuml.asciiart; import java.awt.geom.Dimension2D; -import java.util.List; import net.sourceforge.plantuml.FileFormat; +import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.skin.Area; import net.sourceforge.plantuml.skin.Component; import net.sourceforge.plantuml.skin.ComponentType; import net.sourceforge.plantuml.skin.Context2D; @@ -47,24 +48,31 @@ import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt; public class ComponentTextGroupingElse implements Component { private final ComponentType type; - private final List stringsToDisplay; + private final Display stringsToDisplay; private final FileFormat fileFormat; - public ComponentTextGroupingElse(ComponentType type, List stringsToDisplay, + public ComponentTextGroupingElse(ComponentType type, Display stringsToDisplay, FileFormat fileFormat) { this.type = type; this.stringsToDisplay = stringsToDisplay; this.fileFormat = fileFormat; } - public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) { + public void drawU(UGraphic ug, Area area, Context2D context) { + final Dimension2D dimensionToUse = area.getDimensionToUse(); final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea(); - // final int width = (int) dimensionToUse.getWidth(); - // final int height = (int) dimensionToUse.getHeight(); + final int width = (int) dimensionToUse.getWidth(); if (stringsToDisplay.get(0) != null) { charArea.drawStringLR("[" + stringsToDisplay.get(0) + "]", 2, 0); } + if (fileFormat == FileFormat.UTXT) { + charArea.drawChar('\u2560', 0, -1); + charArea.drawChar('\u2563', width - 1, -1); + charArea.drawHLine('\u2550', -1, 1, width - 1, '\u2502', '\u256a'); + } else { + charArea.drawHLine('~', -1, 1, width - 1); + } // charArea.fillRect('E', 0, 0, width, height); } diff --git a/src/net/sourceforge/plantuml/asciiart/ComponentTextGroupingHeader.java b/src/net/sourceforge/plantuml/asciiart/ComponentTextGroupingHeader.java index fe5166d44..1a3c402e0 100644 --- a/src/net/sourceforge/plantuml/asciiart/ComponentTextGroupingHeader.java +++ b/src/net/sourceforge/plantuml/asciiart/ComponentTextGroupingHeader.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -34,11 +34,12 @@ 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.cucadiagram.Display; import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.skin.Area; import net.sourceforge.plantuml.skin.Component; import net.sourceforge.plantuml.skin.ComponentType; import net.sourceforge.plantuml.skin.Context2D; @@ -48,17 +49,18 @@ import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt; public class ComponentTextGroupingHeader implements Component { private final ComponentType type; - private final List stringsToDisplay; + private final Display stringsToDisplay; private final FileFormat fileFormat; - public ComponentTextGroupingHeader(ComponentType type, List stringsToDisplay, + public ComponentTextGroupingHeader(ComponentType type, Display stringsToDisplay, FileFormat fileFormat) { this.type = type; this.stringsToDisplay = stringsToDisplay; this.fileFormat = fileFormat; } - public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) { + public void drawU(UGraphic ug, Area area, Context2D context) { + final Dimension2D dimensionToUse = area.getDimensionToUse(); final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea(); final int width = (int) dimensionToUse.getWidth(); final int height = (int) dimensionToUse.getHeight(); @@ -70,19 +72,23 @@ public class ComponentTextGroupingHeader implements Component { 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.drawVLine('\u2551', 0, 1, height - 1); + charArea.drawVLine('\u2551', width - 1, 1, height - 1); 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); + charArea.drawHLine('\u2550', height - 1, 1, width - 1, '\u2502', '\u256a'); + charArea.drawChar('\u255a', 0, height - 1); + charArea.drawChar('\u255d', width - 1, height - 1); } 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); + charArea.drawVLine('!', 0, 1, height); + charArea.drawVLine('!', width - 1, 1, height); + charArea.drawHLine('~', height - 1, 1, width - 1); } if (stringsToDisplay.size() > 1) { @@ -93,7 +99,7 @@ public class ComponentTextGroupingHeader implements Component { } public double getPreferredHeight(StringBounder stringBounder) { - return StringUtils.getHeight(stringsToDisplay) + 2; + return StringUtils.getHeight(stringsToDisplay) + 1; } public double getPreferredWidth(StringBounder stringBounder) { diff --git a/src/net/sourceforge/plantuml/asciiart/ComponentTextGroupingTail.java b/src/net/sourceforge/plantuml/asciiart/ComponentTextGroupingTail.java index 5db01e7a8..ff5cac52e 100644 --- a/src/net/sourceforge/plantuml/asciiart/ComponentTextGroupingTail.java +++ b/src/net/sourceforge/plantuml/asciiart/ComponentTextGroupingTail.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -38,6 +38,7 @@ import java.util.List; import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.skin.Area; import net.sourceforge.plantuml.skin.Component; import net.sourceforge.plantuml.skin.ComponentType; import net.sourceforge.plantuml.skin.Context2D; @@ -57,7 +58,8 @@ public class ComponentTextGroupingTail implements Component { this.fileFormat = fileFormat; } - public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) { + public void drawU(UGraphic ug, Area area, Context2D context) { + final Dimension2D dimensionToUse = area.getDimensionToUse(); final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea(); final int width = (int) dimensionToUse.getWidth(); final int height = (int) dimensionToUse.getHeight(); diff --git a/src/net/sourceforge/plantuml/asciiart/ComponentTextLine.java b/src/net/sourceforge/plantuml/asciiart/ComponentTextLine.java index 71ce1304e..9fd5b5f26 100644 --- a/src/net/sourceforge/plantuml/asciiart/ComponentTextLine.java +++ b/src/net/sourceforge/plantuml/asciiart/ComponentTextLine.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -37,6 +37,7 @@ import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.skin.Area; import net.sourceforge.plantuml.skin.Component; import net.sourceforge.plantuml.skin.Context2D; import net.sourceforge.plantuml.ugraphic.UGraphic; @@ -50,7 +51,8 @@ public class ComponentTextLine implements Component { this.fileFormat = fileFormat; } - public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) { + public void drawU(UGraphic ug, Area area, Context2D context) { + final Dimension2D dimensionToUse = area.getDimensionToUse(); final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea(); final int width = (int) dimensionToUse.getWidth(); final int height = (int) dimensionToUse.getHeight(); diff --git a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingTail.java b/src/net/sourceforge/plantuml/asciiart/ComponentTextNewpage.java similarity index 56% rename from src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingTail.java rename to src/net/sourceforge/plantuml/asciiart/ComponentTextNewpage.java index 9dc826601..cfa47154b 100644 --- a/src/net/sourceforge/plantuml/skin/rose/ComponentRoseGroupingTail.java +++ b/src/net/sourceforge/plantuml/asciiart/ComponentTextNewpage.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -27,48 +27,48 @@ * in the United States and other countries.] * * Original Author: Arnaud Roques - * - * Revision $Revision: 7170 $ + * + * Revision $Revision: 4169 $ * */ -package net.sourceforge.plantuml.skin.rose; +package net.sourceforge.plantuml.asciiart; import java.awt.geom.Dimension2D; -import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.graphic.StringBounder; -import net.sourceforge.plantuml.skin.AbstractComponent; +import net.sourceforge.plantuml.skin.Area; +import net.sourceforge.plantuml.skin.Component; +import net.sourceforge.plantuml.skin.Context2D; import net.sourceforge.plantuml.ugraphic.UGraphic; -import net.sourceforge.plantuml.ugraphic.ULine; -import net.sourceforge.plantuml.ugraphic.UStroke; +import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt; -public class ComponentRoseGroupingTail extends AbstractComponent { +public class ComponentTextNewpage implements Component { - private final HtmlColor foregroundColor; - private final HtmlColor groupBorder; + private final FileFormat fileFormat; - public ComponentRoseGroupingTail(HtmlColor foregroundColor,HtmlColor groupBorder) { - this.foregroundColor = foregroundColor; - this.groupBorder = groupBorder; - } - - - @Override - protected void drawInternalU(UGraphic ug, Dimension2D dimensionToUse, boolean withShadow) { - ug.getParam().setStroke(new UStroke(2)); - ug.getParam().setColor(groupBorder); - ug.draw(0, dimensionToUse.getHeight(), new ULine(dimensionToUse.getWidth(), 0)); - ug.getParam().setStroke(new UStroke()); + public ComponentTextNewpage(FileFormat fileFormat) { + this.fileFormat = fileFormat; } - @Override - public double getPreferredWidth(StringBounder stringBounder) { - return 0; + public void drawU(UGraphic ug, Area area, Context2D context) { + final Dimension2D dimensionToUse = area.getDimensionToUse(); + final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea(); + final int width = (int) dimensionToUse.getWidth(); + + if (fileFormat == FileFormat.UTXT) { + charArea.drawHLine('\u2550', 0, 0, width, '\u2502', '\u256a'); + } else { + charArea.drawHLine('=', 0, 0, width); + } } - @Override public double getPreferredHeight(StringBounder stringBounder) { - return 6; + return 2; + } + + public double getPreferredWidth(StringBounder stringBounder) { + return 2; } } diff --git a/src/net/sourceforge/plantuml/asciiart/ComponentTextNote.java b/src/net/sourceforge/plantuml/asciiart/ComponentTextNote.java index 99d5ced52..fad006bcc 100644 --- a/src/net/sourceforge/plantuml/asciiart/ComponentTextNote.java +++ b/src/net/sourceforge/plantuml/asciiart/ComponentTextNote.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -34,11 +34,12 @@ 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.cucadiagram.Display; import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.skin.Area; import net.sourceforge.plantuml.skin.Component; import net.sourceforge.plantuml.skin.ComponentType; import net.sourceforge.plantuml.skin.Context2D; @@ -48,16 +49,17 @@ import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt; public class ComponentTextNote implements Component { private final ComponentType type; - private final List stringsToDisplay; + private final Display stringsToDisplay; private final FileFormat fileFormat; - public ComponentTextNote(ComponentType type, List stringsToDisplay, FileFormat fileFormat) { + public ComponentTextNote(ComponentType type, Display stringsToDisplay, FileFormat fileFormat) { this.type = type; this.stringsToDisplay = stringsToDisplay; this.fileFormat = fileFormat; } - public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) { + public void drawU(UGraphic ug, Area area, Context2D context) { + final Dimension2D dimensionToUse = area.getDimensionToUse(); final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea(); final int width = (int) dimensionToUse.getWidth() - 1; final int height = (int) dimensionToUse.getHeight(); @@ -67,7 +69,7 @@ public class ComponentTextNote implements Component { } else { charArea.drawNoteSimple(2, 0, width - 2, height); } - charArea.drawStringsLR(stringsToDisplay, 3, 1); + charArea.drawStringsLR(stringsToDisplay.as(), 3, 1); } public double getPreferredHeight(StringBounder stringBounder) { diff --git a/src/net/sourceforge/plantuml/asciiart/ComponentTextParticipant.java b/src/net/sourceforge/plantuml/asciiart/ComponentTextParticipant.java index 58fa9f7f0..56835f5fd 100644 --- a/src/net/sourceforge/plantuml/asciiart/ComponentTextParticipant.java +++ b/src/net/sourceforge/plantuml/asciiart/ComponentTextParticipant.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -34,11 +34,12 @@ 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.cucadiagram.Display; import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.skin.Area; import net.sourceforge.plantuml.skin.Component; import net.sourceforge.plantuml.skin.ComponentType; import net.sourceforge.plantuml.skin.Context2D; @@ -48,17 +49,18 @@ import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt; public class ComponentTextParticipant implements Component { private final ComponentType type; - private final List stringsToDisplay; + private final Display stringsToDisplay; private final FileFormat fileFormat; - public ComponentTextParticipant(ComponentType type, List stringsToDisplay, + public ComponentTextParticipant(ComponentType type, Display stringsToDisplay, FileFormat fileFormat) { this.type = type; this.stringsToDisplay = stringsToDisplay; this.fileFormat = fileFormat; } - public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) { + public void drawU(UGraphic ug, Area area, Context2D context) { + final Dimension2D dimensionToUse = area.getDimensionToUse(); final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea(); final int width = (int) dimensionToUse.getWidth(); final int height = (int) dimensionToUse.getHeight(); @@ -80,7 +82,7 @@ public class ComponentTextParticipant implements Component { charArea.drawChar('+', (width - 1) / 2, height - 1); } } - charArea.drawStringsLR(stringsToDisplay, 1, 1); + charArea.drawStringsLR(stringsToDisplay.as(), 1, 1); } public double getPreferredHeight(StringBounder stringBounder) { diff --git a/src/net/sourceforge/plantuml/asciiart/ComponentTextSelfArrow.java b/src/net/sourceforge/plantuml/asciiart/ComponentTextSelfArrow.java index 7b84e4ed4..0987e79f7 100644 --- a/src/net/sourceforge/plantuml/asciiart/ComponentTextSelfArrow.java +++ b/src/net/sourceforge/plantuml/asciiart/ComponentTextSelfArrow.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -34,11 +34,13 @@ 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.cucadiagram.Display; import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.skin.Area; +import net.sourceforge.plantuml.skin.ArrowConfiguration; import net.sourceforge.plantuml.skin.Component; import net.sourceforge.plantuml.skin.ComponentType; import net.sourceforge.plantuml.skin.Context2D; @@ -48,17 +50,20 @@ import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt; public class ComponentTextSelfArrow implements Component { private final ComponentType type; - private final List stringsToDisplay; + private final Display stringsToDisplay; private final FileFormat fileFormat; + private final ArrowConfiguration config; - public ComponentTextSelfArrow(ComponentType type, List stringsToDisplay, - FileFormat fileFormat) { + public ComponentTextSelfArrow(ComponentType type, ArrowConfiguration config, + Display stringsToDisplay, FileFormat fileFormat) { this.type = type; this.stringsToDisplay = stringsToDisplay; this.fileFormat = fileFormat; + this.config = config; } - public void drawU(UGraphic ug, Dimension2D dimensionToUse, Context2D context) { + public void drawU(UGraphic ug, Area area, Context2D context) { + final Dimension2D dimensionToUse = area.getDimensionToUse(); final UmlCharArea charArea = ((UGraphicTxt) ug).getCharArea(); final int width = (int) dimensionToUse.getWidth(); final int height = (int) dimensionToUse.getHeight() - 1; @@ -66,7 +71,7 @@ public class ComponentTextSelfArrow implements Component { charArea.fillRect(' ', 0, 0, width, height); if (fileFormat == FileFormat.UTXT) { - if (type.getArrowConfiguration().isDotted()) { + if (config.isDotted()) { charArea.drawStringLR("\u2500 \u2500 \u2510", 0, 0); charArea.drawStringLR("|", 4, 1); charArea.drawStringLR("< \u2500 \u2518", 0, 2); @@ -75,19 +80,17 @@ public class ComponentTextSelfArrow implements Component { charArea.drawStringLR("\u2502", 4, 1); charArea.drawStringLR("<\u2500\u2500\u2500\u2518", 0, 2); } + } else if (config.isDotted()) { + charArea.drawStringLR("- - .", 0, 0); + charArea.drawStringLR("|", 4, 1); + charArea.drawStringLR("< - '", 0, 2); } else { - if (type.getArrowConfiguration().isDotted()) { - charArea.drawStringLR("- - .", 0, 0); - charArea.drawStringLR("|", 4, 1); - charArea.drawStringLR("< - '", 0, 2); - } else { - charArea.drawStringLR("----.", 0, 0); - charArea.drawStringLR("|", 4, 1); - charArea.drawStringLR("<---'", 0, 2); - } + charArea.drawStringLR("----.", 0, 0); + charArea.drawStringLR("|", 4, 1); + charArea.drawStringLR("<---'", 0, 2); } - charArea.drawStringsLR(stringsToDisplay, 6, 1); + charArea.drawStringsLR(stringsToDisplay.as(), 6, 1); } public double getPreferredHeight(StringBounder stringBounder) { diff --git a/src/net/sourceforge/plantuml/asciiart/TextSkin.java b/src/net/sourceforge/plantuml/asciiart/TextSkin.java index 6c8cbbb06..055a47240 100644 --- a/src/net/sourceforge/plantuml/asciiart/TextSkin.java +++ b/src/net/sourceforge/plantuml/asciiart/TextSkin.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,18 +28,20 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6046 $ + * Revision $Revision: 12001 $ * */ package net.sourceforge.plantuml.asciiart; -import java.util.List; - import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.skin.ArrowConfiguration; +import net.sourceforge.plantuml.skin.ArrowDirection; import net.sourceforge.plantuml.skin.Component; import net.sourceforge.plantuml.skin.ComponentType; import net.sourceforge.plantuml.skin.Skin; +import net.sourceforge.plantuml.skin.rose.ComponentRoseGroupingSpace; public class TextSkin implements Skin { @@ -49,7 +51,8 @@ public class TextSkin implements Skin { this.fileFormat = fileFormat; } - public Component createComponent(ComponentType type, ISkinParam param, List stringsToDisplay) { + public Component createComponent(ComponentType type, ArrowConfiguration config, ISkinParam param, + Display stringsToDisplay) { if (type == ComponentType.PARTICIPANT_HEAD || type == ComponentType.PARTICIPANT_TAIL) { return new ComponentTextParticipant(type, stringsToDisplay, fileFormat); } @@ -57,12 +60,11 @@ public class TextSkin implements Skin { return new ComponentTextActor(type, stringsToDisplay, fileFormat); } if (type.isArrow() - && (type.getArrowConfiguration().isLeftToRightNormal() || type.getArrowConfiguration() - .isRightToLeftReverse())) { - return new ComponentTextArrow(type, stringsToDisplay, fileFormat); + && ((config.getArrowDirection() == ArrowDirection.LEFT_TO_RIGHT_NORMAL) || (config.getArrowDirection() == ArrowDirection.RIGHT_TO_LEFT_REVERSE))) { + return new ComponentTextArrow(type, config, stringsToDisplay, fileFormat); } - if (type.isArrow() && type.getArrowConfiguration().isSelfArrow()) { - return new ComponentTextSelfArrow(type, stringsToDisplay, fileFormat); + if (type.isArrow() && config.isSelfArrow()) { + return new ComponentTextSelfArrow(type, config, stringsToDisplay, fileFormat); } if (type == ComponentType.PARTICIPANT_LINE) { return new ComponentTextLine(fileFormat); @@ -94,15 +96,15 @@ public class TextSkin implements Skin { 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_SPACE) { + return new ComponentRoseGroupingSpace(1); } if (type == ComponentType.GROUPING_ELSE) { return new ComponentTextGroupingElse(type, stringsToDisplay, fileFormat); } + if (type == ComponentType.NEWPAGE) { + return new ComponentTextNewpage(fileFormat); + } throw new UnsupportedOperationException(type.toString()); } diff --git a/src/net/sourceforge/plantuml/asciiart/TextStringBounder.java b/src/net/sourceforge/plantuml/asciiart/TextStringBounder.java index cdf202e66..852760c4b 100644 --- a/src/net/sourceforge/plantuml/asciiart/TextStringBounder.java +++ b/src/net/sourceforge/plantuml/asciiart/TextStringBounder.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/asciiart/TranslatedCharArea.java b/src/net/sourceforge/plantuml/asciiart/TranslatedCharArea.java index ecb7effe7..de874936e 100644 --- a/src/net/sourceforge/plantuml/asciiart/TranslatedCharArea.java +++ b/src/net/sourceforge/plantuml/asciiart/TranslatedCharArea.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/asciiart/UmlCharArea.java b/src/net/sourceforge/plantuml/asciiart/UmlCharArea.java index 3e00a3066..ba2e52667 100644 --- a/src/net/sourceforge/plantuml/asciiart/UmlCharArea.java +++ b/src/net/sourceforge/plantuml/asciiart/UmlCharArea.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/asciiart/UmlCharAreaImpl.java b/src/net/sourceforge/plantuml/asciiart/UmlCharAreaImpl.java index 522d189b1..7dbdd0997 100644 --- a/src/net/sourceforge/plantuml/asciiart/UmlCharAreaImpl.java +++ b/src/net/sourceforge/plantuml/asciiart/UmlCharAreaImpl.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,13 +28,15 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5156 $ + * Revision $Revision: 12012 $ * */ package net.sourceforge.plantuml.asciiart; import java.util.Collection; +import net.sourceforge.plantuml.ugraphic.ClipContainer; + public class UmlCharAreaImpl extends BasicCharAreaImpl implements UmlCharArea { public void drawBoxSimple(int x, int y, int width, int height) { @@ -70,7 +72,7 @@ public class UmlCharAreaImpl extends BasicCharAreaImpl implements UmlCharArea { 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++); diff --git a/src/net/sourceforge/plantuml/braille/BrailleUtils.java b/src/net/sourceforge/plantuml/braille/BrailleUtils.java index 3f3bcf700..c2bff7f2e 100644 --- a/src/net/sourceforge/plantuml/braille/BrailleUtils.java +++ b/src/net/sourceforge/plantuml/braille/BrailleUtils.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/classdiagram/AbstractEntityDiagram.java b/src/net/sourceforge/plantuml/classdiagram/AbstractEntityDiagram.java index db736db7c..f8bc8a883 100644 --- a/src/net/sourceforge/plantuml/classdiagram/AbstractEntityDiagram.java +++ b/src/net/sourceforge/plantuml/classdiagram/AbstractEntityDiagram.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6192 $ + * Revision $Revision: 12053 $ * */ package net.sourceforge.plantuml.classdiagram; @@ -38,21 +38,16 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import net.sourceforge.plantuml.core.DiagramDescription; +import net.sourceforge.plantuml.core.DiagramDescriptionImpl; 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 getDotStrings() { - // return Arrays.asList("nodesep=.5;", "ranksep=0.8;", "edge - // [fontsize=11,labelfontsize=11];", - // "node [fontsize=11,height=.35,width=.55];"); - final List def = Arrays.asList("nodesep=.35;", "ranksep=0.8;", "edge [fontsize=11,labelfontsize=11];", "node [fontsize=11,height=.35,width=.55];"); - if (getPragma().isDefine("graphattributes")==false) { + if (getPragma().isDefine("graphattributes") == false) { return def; } final String attribute = getPragma().getValue("graphattributes"); @@ -61,8 +56,8 @@ public abstract class AbstractEntityDiagram extends CucaDiagram { return Collections.unmodifiableList(result); } - final public String getDescription() { - return "(" + entities().size() + " entities)"; + final public DiagramDescription getDescription() { + return new DiagramDescriptionImpl("(" + getLeafs().size() + " entities)", getClass()); } } diff --git a/src/net/sourceforge/plantuml/classdiagram/ClassDiagram.java b/src/net/sourceforge/plantuml/classdiagram/ClassDiagram.java index d014aa124..5a694c9ae 100644 --- a/src/net/sourceforge/plantuml/classdiagram/ClassDiagram.java +++ b/src/net/sourceforge/plantuml/classdiagram/ClassDiagram.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,117 +28,85 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6167 $ + * Revision $Revision: 11432 $ * */ package net.sourceforge.plantuml.classdiagram; -import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.UmlDiagramType; -import net.sourceforge.plantuml.cucadiagram.Entity; -import net.sourceforge.plantuml.cucadiagram.EntityType; -import net.sourceforge.plantuml.cucadiagram.Group; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.EntityUtils; import net.sourceforge.plantuml.cucadiagram.GroupType; -import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.IGroup; +import net.sourceforge.plantuml.cucadiagram.ILeaf; +import net.sourceforge.plantuml.cucadiagram.LeafType; import net.sourceforge.plantuml.objectdiagram.AbstractClassOrObjectDiagram; public class ClassDiagram extends AbstractClassOrObjectDiagram { + private String namespaceSeparator = "."; + @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 || defaultType == EntityType.POINT_FOR_ASSOCIATION; - code = getFullyQualifiedCode(code); - if (super.entityExist(code)) { - return super.getOrCreateEntity(code, defaultType); + public ILeaf getOrCreateLeaf(Code code, LeafType type) { + if (type == null) { + code = code.eventuallyRemoveStartingAndEndingDoubleQuote(); + if (getNamespaceSeparator() == null) { + return getOrCreateLeafDefault(code, LeafType.CLASS); + } + code = code.getFullyQualifiedCode(getCurrentGroup(), getNamespaceSeparator()); + if (super.leafExist(code)) { + return getOrCreateLeafDefault(code, LeafType.CLASS); + } + return createEntityWithNamespace(code, + Display.getWithNewlines(code.getShortName(getLeafs(), getNamespaceSeparator())), LeafType.CLASS); } - return createEntityWithNamespace(code, getShortName(code), defaultType); + if (getNamespaceSeparator() == null) { + return getOrCreateLeafDefault(code, LeafType.CLASS); + } + code = code.getFullyQualifiedCode(getCurrentGroup(), getNamespaceSeparator()); + if (super.leafExist(code)) { + return getOrCreateLeafDefault(code, type); + } + return createEntityWithNamespace(code, + Display.getWithNewlines(code.getShortName(getLeafs(), getNamespaceSeparator())), type); } @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); + public ILeaf createLeaf(Code code, Display display, LeafType type) { + if (type != LeafType.ABSTRACT_CLASS && type != LeafType.ANNOTATION && type != LeafType.CLASS && type != LeafType.INTERFACE + && type != LeafType.ENUM && type != LeafType.LOLLIPOP && type != LeafType.NOTE) { + return super.createLeaf(code, display, type); } - code = getFullyQualifiedCode(code); - if (super.entityExist(code)) { + if (getNamespaceSeparator() == null) { + return super.createLeaf(code, display, type); + } + code = code.getFullyQualifiedCode(getCurrentGroup(), getNamespaceSeparator()); + if (super.leafExist(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); + private ILeaf createEntityWithNamespace(Code fullyCode, Display display, LeafType type) { + IGroup group = getCurrentGroup(); + final String namespace = fullyCode.getNamespace(getLeafs(), getNamespaceSeparator()); + if (namespace != null && (EntityUtils.groupRoot(group) || group.getCode().getCode().equals(namespace) == false)) { + group = getOrCreateGroupInternal(Code.of(namespace), Display.getWithNewlines(namespace), namespace, + GroupType.PACKAGE, getRootGroup()); } - return createEntityInternal(fullyCode, display == null ? getShortName(fullyCode) : display, type, group); + return createLeafInternal( + fullyCode, + display == null ? Display.getWithNewlines(fullyCode.getShortName(getLeafs(), + getNamespaceSeparator())) : display, type, group); } @Override - public final boolean entityExist(String code) { - return super.entityExist(getFullyQualifiedCode(code)); - } - - @Override - public IEntity getOrCreateClass(String code) { - return getOrCreateEntity(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(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(); + public final boolean leafExist(Code code) { + if (getNamespaceSeparator() == null) { + return super.leafExist(code); } - 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; + return super.leafExist(code.getFullyQualifiedCode(getCurrentGroup(), getNamespaceSeparator())); } @Override @@ -146,5 +114,12 @@ public class ClassDiagram extends AbstractClassOrObjectDiagram { return UmlDiagramType.CLASS; } + private String getNamespaceSeparator() { + return namespaceSeparator; + } + + public void setNamespaceSeparator(String namespaceSeparator) { + this.namespaceSeparator = namespaceSeparator; + } } diff --git a/src/net/sourceforge/plantuml/classdiagram/ClassDiagramFactory.java b/src/net/sourceforge/plantuml/classdiagram/ClassDiagramFactory.java index f61d24a84..7102761dd 100644 --- a/src/net/sourceforge/plantuml/classdiagram/ClassDiagramFactory.java +++ b/src/net/sourceforge/plantuml/classdiagram/ClassDiagramFactory.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -27,78 +27,131 @@ * in the United States and other countries.] * * Original Author: Arnaud Roques - * - * Revision $Revision: 6918 $ + * + * Revision $Revision: 10006 $ * */ package net.sourceforge.plantuml.classdiagram; +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.plantuml.AbstractPSystem; +import net.sourceforge.plantuml.UmlDiagramType; import net.sourceforge.plantuml.classdiagram.command.CommandAddMethod; -import net.sourceforge.plantuml.classdiagram.command.CommandCreateEntityClass2; -import net.sourceforge.plantuml.classdiagram.command.CommandCreateEntityClassMultilines2; +import net.sourceforge.plantuml.classdiagram.command.CommandCreateClass; +import net.sourceforge.plantuml.classdiagram.command.CommandCreateClassMultilines; import net.sourceforge.plantuml.classdiagram.command.CommandDiamondAssociation; -import net.sourceforge.plantuml.classdiagram.command.CommandEndNamespace; -import net.sourceforge.plantuml.classdiagram.command.CommandHideShow; -import net.sourceforge.plantuml.classdiagram.command.CommandHideShow3; +import net.sourceforge.plantuml.classdiagram.command.CommandHideShowSpecificClass; import net.sourceforge.plantuml.classdiagram.command.CommandImport; -import net.sourceforge.plantuml.classdiagram.command.CommandLinkClass2; -import net.sourceforge.plantuml.classdiagram.command.CommandLinkLollipop2; -import net.sourceforge.plantuml.classdiagram.command.CommandMultilinesClassNote; -import net.sourceforge.plantuml.classdiagram.command.CommandNamespace; +import net.sourceforge.plantuml.classdiagram.command.CommandLinkClass; +import net.sourceforge.plantuml.classdiagram.command.CommandLinkLollipop; +import net.sourceforge.plantuml.classdiagram.command.CommandMouseOver; +import net.sourceforge.plantuml.classdiagram.command.CommandNamespaceSeparator; 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.Command; +import net.sourceforge.plantuml.command.CommandEndNamespace; import net.sourceforge.plantuml.command.CommandEndPackage; -import net.sourceforge.plantuml.command.CommandMultilinesStandaloneNote; -import net.sourceforge.plantuml.command.CommandNoteEntity; +import net.sourceforge.plantuml.command.CommandNamespace; import net.sourceforge.plantuml.command.CommandPackage; +import net.sourceforge.plantuml.command.CommandPackageEmpty; import net.sourceforge.plantuml.command.CommandPage; +import net.sourceforge.plantuml.command.CommandRankDir; +import net.sourceforge.plantuml.command.UmlDiagramFactory; +import net.sourceforge.plantuml.command.note.FactoryNoteCommand; +import net.sourceforge.plantuml.command.note.FactoryNoteOnEntityCommand; +import net.sourceforge.plantuml.command.note.FactoryNoteOnLinkCommand; +import net.sourceforge.plantuml.command.regex.RegexLeaf; +import net.sourceforge.plantuml.cucadiagram.Link; -public class ClassDiagramFactory extends AbstractUmlSystemCommandFactory { +public class ClassDiagramFactory extends UmlDiagramFactory { - private ClassDiagram system; + @Override + public ClassDiagram createEmptyDiagram() { + return new ClassDiagram(); - public ClassDiagram getSystem() { - return system; } @Override - protected void initCommands() { - system = new ClassDiagram(); + protected List createCommands() { + final List cmds = new ArrayList(); + addCommonCommands(cmds); - addCommonCommands(system); + cmds.add(new CommandRankDir()); + cmds.add(new CommandPage()); + cmds.add(new CommandAddMethod()); - addCommand(new CommandPage(system)); - addCommand(new CommandAddMethod(system)); + cmds.add(new CommandCreateClass()); + final FactoryNoteCommand factoryNoteCommand = new FactoryNoteCommand(); + cmds.add(factoryNoteCommand.createSingleLine()); - //addCommand(new CommandCreateEntityClass(system)); - addCommand(new CommandCreateEntityClass2(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)); + cmds.add(new CommandPackage()); + cmds.add(new CommandEndPackage()); + cmds.add(new CommandPackageEmpty()); - //addCommand(new CommandLinkClass(system)); - addCommand(new CommandLinkClass2(system)); - addCommand(new CommandLinkLollipop2(system)); + cmds.add(new CommandNamespace()); + cmds.add(new CommandEndNamespace()); + cmds.add(new CommandStereotype()); - addCommand(new CommandImport(system)); - addCommand(new CommandNoteEntity(system)); - addCommand(new CommandUrl(system)); + cmds.add(new CommandLinkClass(UmlDiagramType.CLASS)); + cmds.add(new CommandLinkLollipop(UmlDiagramType.CLASS)); - addCommand(new CommandMultilinesClassNote(system)); - addCommand(new CommandMultilinesStandaloneNote(system)); -// addCommand(new CommandCreateEntityClassMultilines(system)); - addCommand(new CommandCreateEntityClassMultilines2(system)); + cmds.add(new CommandImport()); + final FactoryNoteOnEntityCommand factoryNoteOnEntityCommand = new FactoryNoteOnEntityCommand(new RegexLeaf( + "ENTITY", "(" + CommandCreateClass.CODE + "|\"[^\"]+\")")); + cmds.add(factoryNoteOnEntityCommand.createSingleLine()); + cmds.add(new CommandUrl()); - addCommand(new CommandDiamondAssociation(system)); + cmds.add(factoryNoteOnEntityCommand.createMultiLine()); + cmds.add(factoryNoteCommand.createMultiLine()); + cmds.add(new CommandCreateClassMultilines()); - addCommand(new CommandHideShow3(system)); - addCommand(new CommandHideShow(system)); + final FactoryNoteOnLinkCommand factoryNoteOnLinkCommand = new FactoryNoteOnLinkCommand(); + cmds.add(factoryNoteOnLinkCommand.createSingleLine()); + cmds.add(factoryNoteOnLinkCommand.createMultiLine()); + cmds.add(new CommandDiamondAssociation()); + cmds.add(new CommandMouseOver()); + + cmds.add(new CommandHideShowSpecificClass()); + + cmds.add(new CommandNamespaceSeparator()); + + return cmds; } + + @Override + public String checkFinalError(AbstractPSystem sys) { + final ClassDiagram system = (ClassDiagram) sys; + + for (Link link : system.getLinks()) { + final int len = link.getLength(); + if (len == 1) { + for (Link link2 : system.getLinks()) { + if (link2.sameConnections(link) && link2.getLength() != 1) { + link2.setLength(1); + } + } + } + } + + system.applySingleStrategy(); + +// for (IGroup g : system.getGroups(true)) { +// final List standalones = new ArrayList(); +// for (ILeaf ent : g.getLeafsDirect()) { +// if (system.isStandalone(ent)) { +// standalones.add(ent); +// } +// } +// if (standalones.size() < 3) { +// continue; +// } +// final Magma magma = new Magma(system, standalones); +// magma.putInSquare(); +// } + return super.checkFinalError(system); + } + } diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandAddMethod.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandAddMethod.java index 454c57867..bb18f89ff 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandAddMethod.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandAddMethod.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5618 $ + * Revision $Revision: 11432 $ * */ package net.sourceforge.plantuml.classdiagram.command; @@ -38,22 +38,23 @@ 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.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.skin.VisibilityModifier; public class CommandAddMethod extends SingleLineCommand { - public CommandAddMethod(ClassDiagram diagram) { - super(diagram, "(?i)^([\\p{L}0-9_.]+|\"[^\"]+\")\\s*:\\s*(.*)$"); + public CommandAddMethod() { + super("(?i)^([\\p{L}0-9_.]+|\"[^\"]+\")\\s*:\\s*(.*)$"); } @Override - protected CommandExecutionResult executeArg(List arg) { - final Entity entity = (Entity) getSystem().getOrCreateClass(arg.get(0)); + protected CommandExecutionResult executeArg(ClassDiagram system, List arg) { + final IEntity entity = system.getOrCreateLeaf(Code.of(arg.get(0)), null); final String field = arg.get(1); if (field.length() > 0 && VisibilityModifier.isVisibilityCharacter(field.charAt(0))) { - getSystem().setVisibilityModifierPresent(true); + system.setVisibilityModifierPresent(true); } entity.addFieldOrMethod(field); return CommandExecutionResult.ok(); diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClass.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClass.java new file mode 100644 index 000000000..86cf96892 --- /dev/null +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClass.java @@ -0,0 +1,155 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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 net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.UrlBuilder; +import net.sourceforge.plantuml.UrlBuilder.ModeUrl; +import net.sourceforge.plantuml.classdiagram.ClassDiagram; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.SingleLineCommand2; +import net.sourceforge.plantuml.command.regex.RegexConcat; +import net.sourceforge.plantuml.command.regex.RegexLeaf; +import net.sourceforge.plantuml.command.regex.RegexOr; +import net.sourceforge.plantuml.command.regex.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.ILeaf; +import net.sourceforge.plantuml.cucadiagram.LeafType; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.cucadiagram.LinkDecor; +import net.sourceforge.plantuml.cucadiagram.LinkType; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; + +public class CommandCreateClass extends SingleLineCommand2 { + + public static final String CODE = "[^\\s{}\"<>]+"; + + enum Mode { + EXTENDS, IMPLEMENTS + }; + + public CommandCreateClass() { + super(getRegexConcat()); + } + + private static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("TYPE", // + "(interface|enum|annotation|abstract\\s+class|abstract|class)\\s+"), // + new RegexOr(// + new RegexConcat(// + new RegexLeaf("DISPLAY1", "\"([^\"]+)\""), // + new RegexLeaf("\\s+as\\s+"), // + new RegexLeaf("CODE1", "(" + CODE + ")")), // + new RegexConcat(// + new RegexLeaf("CODE2", "(" + CODE + ")"), // + new RegexLeaf("\\s+as\\s+"), // // + new RegexLeaf("DISPLAY2", "\"([^\"]+)\"")), // + new RegexLeaf("CODE3", "(" + CODE + ")"), // + new RegexLeaf("CODE4", "\"([^\"]+)\"")), // + new RegexLeaf("GENERIC", "(?:\\s*\\<(" + GenericRegexProducer.PATTERN + ")\\>)?"), // + // new RegexLeaf("STEREO", "(?:\\s*(\\<{2}.*\\>{2}))?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("STEREO", "(\\<{2}.*\\>{2})?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("URL", "(" + UrlBuilder.getRegexp() + ")?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("COLOR", "(#\\w+[-\\\\|/]?\\w+)?"), // + new RegexLeaf("EXTENDS", "(\\s+(extends|implements)\\s+(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*))?"), // + new RegexLeaf("$")); + } + + @Override + protected CommandExecutionResult executeArg(ClassDiagram diagram, RegexResult arg) { + final LeafType type = LeafType.getLeafType(arg.get("TYPE", 0).toUpperCase()); + final Code code = Code.of(arg.getLazzy("CODE", 0)).eventuallyRemoveStartingAndEndingDoubleQuote(); + final String display = arg.getLazzy("DISPLAY", 0); + + final String stereotype = arg.get("STEREO", 0); + final String generic = arg.get("GENERIC", 0); + final ILeaf entity; + if (diagram.leafExist(code)) { + entity = diagram.getOrCreateLeaf(code, type); + entity.muteToType(type); + } else { + entity = diagram.createLeaf(code, Display.getWithNewlines(display), type); + } + if (stereotype != null) { + entity.setStereotype(new Stereotype(stereotype, diagram.getSkinParam().getCircledCharacterRadius(), diagram + .getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null))); + } + if (generic != null) { + entity.setGeneric(generic); + } + + final String urlString = arg.get("URL", 0); + if (urlString != null) { + final UrlBuilder urlBuilder = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), ModeUrl.STRICT); + final Url url = urlBuilder.getUrl(urlString); + entity.addUrl(url); + } + + entity.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(arg.get("COLOR", 0))); + manageExtends(diagram, arg, entity); + + return CommandExecutionResult.ok(); + } + + public static void manageExtends(ClassDiagram system, RegexResult arg, final IEntity entity) { + if (arg.get("EXTENDS", 1) != null) { + final Mode mode = arg.get("EXTENDS", 1).equalsIgnoreCase("extends") ? Mode.EXTENDS : Mode.IMPLEMENTS; + final Code other = Code.of(arg.get("EXTENDS", 2)); + LeafType type2 = LeafType.CLASS; + if (mode == Mode.IMPLEMENTS) { + type2 = LeafType.INTERFACE; + } + if (mode == Mode.EXTENDS && entity.getEntityType() == LeafType.INTERFACE) { + type2 = LeafType.INTERFACE; + } + final IEntity cl2 = system.getOrCreateLeaf(other, type2); + LinkType typeLink = new LinkType(LinkDecor.NONE, LinkDecor.EXTENDS); + if (type2 == LeafType.INTERFACE && entity.getEntityType() != LeafType.INTERFACE) { + typeLink = typeLink.getDashed(); + } + final Link link = new Link(cl2, entity, typeLink, null, 2, null, null, system.getLabeldistance(), + system.getLabelangle()); + system.addLink(link); + } + } + +} diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClassMultilines.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClassMultilines.java new file mode 100644 index 000000000..12ce83dee --- /dev/null +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateClassMultilines.java @@ -0,0 +1,225 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.Url; +import net.sourceforge.plantuml.UrlBuilder; +import net.sourceforge.plantuml.UrlBuilder.ModeUrl; +import net.sourceforge.plantuml.classdiagram.ClassDiagram; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.CommandMultilines2; +import net.sourceforge.plantuml.command.MultilinesStrategy; +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.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.ILeaf; +import net.sourceforge.plantuml.cucadiagram.LeafType; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.cucadiagram.LinkDecor; +import net.sourceforge.plantuml.cucadiagram.LinkStyle; +import net.sourceforge.plantuml.cucadiagram.LinkType; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.skin.VisibilityModifier; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public class CommandCreateClassMultilines extends CommandMultilines2 { + + enum Mode { + EXTENDS, IMPLEMENTS + }; + + public CommandCreateClassMultilines() { + super(getRegexConcat(), MultilinesStrategy.REMOVE_STARTING_QUOTE); + } + + @Override + public String getPatternEnd() { + return "(?i)^\\s*\\}\\s*$"; + } + + private static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("TYPE", "(interface|enum|abstract\\s+class|abstract|class)\\s+"), // + new RegexOr(// + new RegexConcat(// + new RegexLeaf("DISPLAY1", "\"([^\"]+)\""), // + new RegexLeaf("\\s+as\\s+"), // + new RegexLeaf("CODE1", "(" + CommandCreateClass.CODE + ")")), // + new RegexConcat(// + new RegexLeaf("CODE2", "(" + CommandCreateClass.CODE + ")"), // + new RegexLeaf("\\s+as\\s+"), // // + new RegexLeaf("DISPLAY2", "\"([^\"]+)\"")), // + new RegexLeaf("CODE3", "(" + CommandCreateClass.CODE + ")"), // + new RegexLeaf("CODE4", "\"([^\"]+)\"")), // + new RegexLeaf("GENERIC", "(?:\\s*\\<(" + GenericRegexProducer.PATTERN + ")\\>)?"), // + new RegexLeaf("\\s*"), // + // new RegexLeaf("STEREO", "(?:\\s*(\\<\\<.+\\>\\>))?"), // + new RegexLeaf("STEREO", "(\\<\\<.+\\>\\>)?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("URL", "(" + UrlBuilder.getRegexp() + ")?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("COLOR", "(#\\w+[-\\\\|/]?\\w+)?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("LINECOLOR", "(?:##(?:\\[(dotted|dashed|bold)\\])?(\\w+)?)?"), // + new RegexLeaf("EXTENDS", + "(\\s+(extends|implements)\\s+((?:\\.|::)?[\\p{L}0-9_]+(?:(?:\\.|::)[\\p{L}0-9_]+)*))?"), // + new RegexLeaf("\\s*\\{\\s*$")); + } + + public CommandExecutionResult executeNow(ClassDiagram diagram, List lines) { + StringUtils.trim(lines, false); + final RegexResult line0 = getStartingPattern().matcher(lines.get(0).trim()); + final IEntity entity = executeArg0(diagram, line0); + if (entity == null) { + return CommandExecutionResult.error("No such entity"); + } + lines = lines.subList(1, lines.size() - 1); + final Url url; + if (lines.size() > 0) { + final UrlBuilder urlBuilder = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), ModeUrl.STRICT); + url = urlBuilder.getUrl(lines.get(0).toString()); + } else { + url = null; + } + if (url != null) { + lines = lines.subList(1, lines.size()); + } + for (String s : lines) { + if (s.length() > 0 && VisibilityModifier.isVisibilityCharacter(s.charAt(0))) { + diagram.setVisibilityModifierPresent(true); + } + entity.addFieldOrMethod(s); + } + if (url != null) { + entity.addUrl(url); + } + + manageExtends(diagram, line0, entity); + + return CommandExecutionResult.ok(); + } + + private static void manageExtends(ClassDiagram system, RegexResult arg, final IEntity entity) { + if (arg.get("EXTENDS", 1) != null) { + final Mode mode = arg.get("EXTENDS", 1).equalsIgnoreCase("extends") ? Mode.EXTENDS : Mode.IMPLEMENTS; + final Code other = Code.of(arg.get("EXTENDS", 2)); + LeafType type2 = LeafType.CLASS; + if (mode == Mode.IMPLEMENTS) { + type2 = LeafType.INTERFACE; + } + if (mode == Mode.EXTENDS && entity.getEntityType() == LeafType.INTERFACE) { + type2 = LeafType.INTERFACE; + } + final IEntity cl2 = system.getOrCreateLeaf(other, type2); + LinkType typeLink = new LinkType(LinkDecor.NONE, LinkDecor.EXTENDS); + if (type2 == LeafType.INTERFACE && entity.getEntityType() != LeafType.INTERFACE) { + typeLink = typeLink.getDashed(); + } + final Link link = new Link(cl2, entity, typeLink, null, 2, null, null, system.getLabeldistance(), + system.getLabelangle()); + system.addLink(link); + } + } + + private IEntity executeArg0(ClassDiagram diagram, RegexResult arg) { + + final LeafType type = LeafType.getLeafType(arg.get("TYPE", 0).toUpperCase()); + + final Code code = Code.of(arg.getLazzy("CODE", 0)).eventuallyRemoveStartingAndEndingDoubleQuote(); + final String display = arg.getLazzy("DISPLAY", 0); + + final String stereotype = arg.get("STEREO", 0); + final String generic = arg.get("GENERIC", 0); + + final ILeaf result; + if (diagram.leafExist(code)) { + result = diagram.getOrCreateLeaf(code, null); + result.muteToType(type); + } else { + result = diagram.createLeaf(code, Display.getWithNewlines(display), type); + } + if (stereotype != null) { + result.setStereotype(new Stereotype(stereotype, diagram.getSkinParam().getCircledCharacterRadius(), diagram + .getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null))); + } + + final String urlString = arg.get("URL", 0); + if (urlString != null) { + final UrlBuilder urlBuilder = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), ModeUrl.STRICT); + final Url url = urlBuilder.getUrl(urlString); + result.addUrl(url); + } + + result.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(arg.get("COLOR", 0))); + result.setSpecificLineColor(HtmlColorUtils.getColorIfValid(arg.get("LINECOLOR", 1))); + applyStroke(result, arg.get("LINECOLOR", 0)); + + if (generic != null) { + result.setGeneric(generic); + } + return result; + } + + public UStroke getStroke(LinkStyle style) { + if (style == LinkStyle.DASHED) { + return new UStroke(6, 6, 1); + } + if (style == LinkStyle.DOTTED) { + return new UStroke(1, 3, 1); + } + if (style == LinkStyle.BOLD) { + return new UStroke(2.5); + } + return new UStroke(); + } + + private void applyStroke(ILeaf entity, String s) { + if (s == null) { + return; + } + final LinkStyle style = LinkStyle.valueOf(s.toUpperCase()); + entity.setSpecificLineStroke(getStroke(style)); + + } + +} diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateEntityClass2.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateEntityClass2.java deleted file mode 100644 index f77c18fd7..000000000 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateEntityClass2.java +++ /dev/null @@ -1,155 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 5075 $ - * - */ -package net.sourceforge.plantuml.classdiagram.command; - -import java.util.Map; - -import net.sourceforge.plantuml.FontParam; -import net.sourceforge.plantuml.classdiagram.ClassDiagram; -import net.sourceforge.plantuml.command.CommandExecutionResult; -import net.sourceforge.plantuml.command.SingleLineCommand2; -import net.sourceforge.plantuml.command.regex.RegexConcat; -import net.sourceforge.plantuml.command.regex.RegexLeaf; -import net.sourceforge.plantuml.command.regex.RegexOr; -import net.sourceforge.plantuml.command.regex.RegexPartialMatch; -import net.sourceforge.plantuml.cucadiagram.Entity; -import net.sourceforge.plantuml.cucadiagram.EntityType; -import net.sourceforge.plantuml.cucadiagram.IEntity; -import net.sourceforge.plantuml.cucadiagram.Link; -import net.sourceforge.plantuml.cucadiagram.LinkDecor; -import net.sourceforge.plantuml.cucadiagram.LinkType; -import net.sourceforge.plantuml.cucadiagram.Stereotype; - -public class CommandCreateEntityClass2 extends SingleLineCommand2 { - - enum Mode { - EXTENDS, IMPLEMENTS - }; - - public CommandCreateEntityClass2(ClassDiagram diagram) { - super(diagram, getRegexConcat()); - } - - private static RegexConcat getRegexConcat() { - return new RegexConcat(new RegexLeaf("^"), // - new RegexLeaf("TYPE",// - "(interface|enum|abstract\\s+class|abstract|class)\\s+"), // - new RegexOr(new RegexLeaf("NAME1", - "(?:\"([^\"]+)\"\\s+as\\s+)?(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)"), // - new RegexLeaf("NAME2", "(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s+as\\s+\"([^\"]+)\""), // - new RegexLeaf("NAME3", "\"([^\"]+)\"")), // - new RegexLeaf("STEREO", "(?:\\s*([\\<\\[]{2}.*[\\>\\]]{2}))?"), // - new RegexLeaf("EXTENDS", "(\\s+(extends|implements)\\s+(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*))?"), // - new RegexLeaf("$")); - } - - @Override - protected CommandExecutionResult executeArg(Map arg) { - final EntityType type = EntityType.getEntityType(arg.get("TYPE").get(0).toUpperCase()); - final String code; - final String display; - if (arg.get("NAME1").get(1) != null) { - code = arg.get("NAME1").get(1); - display = arg.get("NAME1").get(0); - } else if (arg.get("NAME3").get(0) != null) { - code = arg.get("NAME3").get(0); - display = arg.get("NAME3").get(0); - } else { - code = arg.get("NAME2").get(0); - display = arg.get("NAME2").get(1); - } - final String stereotype = arg.get("STEREO").get(0); - final Entity entity; - if (getSystem().entityExist(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, null))); - } - - manageExtends(getSystem(), arg, entity); - - return CommandExecutionResult.ok(); - } - - public static void manageExtends(ClassDiagram system, Map arg, final Entity entity) { - if (arg.get("EXTENDS").get(1) != null) { - final Mode mode = arg.get("EXTENDS").get(1).equalsIgnoreCase("extends") ? Mode.EXTENDS : Mode.IMPLEMENTS; - final String other = arg.get("EXTENDS").get(2); - EntityType type2 = EntityType.CLASS; - if (mode == Mode.IMPLEMENTS) { - type2 = EntityType.INTERFACE; - } - if (mode == Mode.EXTENDS && entity.getType() == EntityType.INTERFACE) { - type2 = EntityType.INTERFACE; - } - final IEntity cl2 = system.getOrCreateClass(other, type2); - LinkType typeLink = new LinkType(LinkDecor.NONE, LinkDecor.EXTENDS); - if (type2 == EntityType.INTERFACE && entity.getType() != EntityType.INTERFACE) { - typeLink = typeLink.getDashed(); - } - final Link link = new Link(cl2, entity, typeLink, null, 2, null, null, system.getLabeldistance(), - system.getLabelangle()); - system.addLink(link); - } - } - - // @Override - // protected CommandExecutionResult executeArg(List 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(); - // } - -} diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateEntityClassMultilines2.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateEntityClassMultilines2.java deleted file mode 100644 index 54b7bb3e0..000000000 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandCreateEntityClassMultilines2.java +++ /dev/null @@ -1,121 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 4161 $ - * - */ -package net.sourceforge.plantuml.classdiagram.command; - -import java.util.List; -import java.util.Map; - -import net.sourceforge.plantuml.FontParam; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.classdiagram.ClassDiagram; -import net.sourceforge.plantuml.command.CommandExecutionResult; -import net.sourceforge.plantuml.command.CommandMultilines2; -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.Stereotype; -import net.sourceforge.plantuml.skin.VisibilityModifier; - -public class CommandCreateEntityClassMultilines2 extends CommandMultilines2 { - - public CommandCreateEntityClassMultilines2(ClassDiagram diagram) { - super(diagram, getRegexConcat(), "(?i)^\\s*\\}\\s*$"); - } - - private static RegexConcat getRegexConcat() { - return new RegexConcat(new RegexLeaf("^"), // - new RegexLeaf("TYPE", "(interface|enum|abstract\\s+class|abstract|class)\\s+"), // - new RegexOr( // - new RegexLeaf("NAME1", "(?:\"([^\"]+)\"\\s+as\\s+)?(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)"), // - new RegexLeaf("NAME2", "(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s+as\\s+\"([^\"]+)\""), // - new RegexLeaf("NAME3", "\"([^\"]+)\"")), // - new RegexLeaf("STEREO", "(?:\\s*([\\<\\[]{2}.*[\\>\\]]{2}))?"), // - new RegexLeaf("EXTENDS", "(\\s+(extends|implements)\\s+(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*))?"), // - new RegexLeaf("\\s*\\{\\s*$")); - } - - public CommandExecutionResult execute(List lines) { - StringUtils.trim(lines, true); - final Map line0 = getStartingPattern().matcher(lines.get(0).trim()); - final Entity entity = executeArg0(line0); - if (entity == null) { - return CommandExecutionResult.error("No such entity"); - } - for (String s : lines.subList(1, lines.size() - 1)) { - assert s.length() > 0; - if (VisibilityModifier.isVisibilityCharacter(s.charAt(0))) { - getSystem().setVisibilityModifierPresent(true); - } - entity.addFieldOrMethod(s); - } - - CommandCreateEntityClass2.manageExtends(getSystem(), line0, entity); - - return CommandExecutionResult.ok(); - } - - private Entity executeArg0(Map arg) { - - final EntityType type = EntityType.getEntityType(arg.get("TYPE").get(0).toUpperCase()); - final String code; - final String display; - if (arg.get("NAME1").get(1) != null) { - code = arg.get("NAME1").get(1); - display = arg.get("NAME1").get(0); - } else if (arg.get("NAME3").get(0) != null) { - code = arg.get("NAME3").get(0); - display = arg.get("NAME3").get(0); - } else { - code = arg.get("NAME2").get(0); - display = arg.get("NAME2").get(1); - } - final String stereotype = arg.get("STEREO").get(0); - - 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, null))); - } - return entity; - } - -} diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandDiamondAssociation.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandDiamondAssociation.java index 4a6c2cfa8..53810fa54 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandDiamondAssociation.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandDiamondAssociation.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -38,21 +38,22 @@ 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.EntityType; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.LeafType; public class CommandDiamondAssociation extends SingleLineCommand { - public CommandDiamondAssociation(ClassDiagram diagram) { - super(diagram, "(?i)^\\<\\>\\s*([\\p{L}0-9_.]+)$"); + public CommandDiamondAssociation() { + super("(?i)^\\<\\>\\s*([\\p{L}0-9_.]+)$"); } @Override - protected CommandExecutionResult executeArg(List arg) { - final String code = arg.get(0); - if (getSystem().entityExist(code)) { + protected CommandExecutionResult executeArg(ClassDiagram diagram, List arg) { + final Code code = Code.of(arg.get(0)); + if (diagram.leafExist(code)) { return CommandExecutionResult.error("Already existing : "+code); } - getSystem().createEntity(code, null, EntityType.ASSOCIATION); + diagram.createLeaf(code, null, LeafType.ASSOCIATION); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandHideShow.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandHideShow.java index 65eabe9c4..6f6d19b43 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandHideShow.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandHideShow.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -34,38 +34,40 @@ package net.sourceforge.plantuml.classdiagram.command; import java.util.EnumSet; -import java.util.Map; import java.util.Set; +import net.sourceforge.plantuml.UmlDiagram; import net.sourceforge.plantuml.classdiagram.ClassDiagram; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.SingleLineCommand2; import net.sourceforge.plantuml.command.regex.RegexConcat; import net.sourceforge.plantuml.command.regex.RegexLeaf; -import net.sourceforge.plantuml.command.regex.RegexPartialMatch; +import net.sourceforge.plantuml.command.regex.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Code; 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.EntityUtils; import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.LeafType; -public class CommandHideShow extends SingleLineCommand2 { +public class CommandHideShow extends SingleLineCommand2 { private static final EnumSet PORTION_METHOD = EnumSet. of(EntityPortion.METHOD); private static final EnumSet PORTION_MEMBER = EnumSet. of(EntityPortion.FIELD, EntityPortion.METHOD); private static final EnumSet PORTION_FIELD = EnumSet. of(EntityPortion.FIELD); - public CommandHideShow(ClassDiagram classDiagram) { - super(classDiagram, getRegexConcat()); + public CommandHideShow() { + super(getRegexConcat()); } static RegexConcat getRegexConcat() { - return new RegexConcat(new RegexLeaf("^"), // + return new RegexConcat(new RegexLeaf("^"), // new RegexLeaf("COMMAND", "(hide|show)"), // new RegexLeaf("\\s+"), // new RegexLeaf("GENDER", - "(?:(class|interface|enum|abstract|[\\p{L}0-9_.]+|\"[^\"]+\"|\\<\\<.*\\>\\>)\\s+)*?"), // + "(?:(class|interface|enum|annotation|abstract|[\\p{L}0-9_.]+|\"[^\"]+\"|\\<\\<.*\\>\\>)\\s+)*?"), // new RegexLeaf("EMPTY", "(?:(empty)\\s+)?"), // new RegexLeaf("PORTION", "(members?|attributes?|fields?|methods?|circle\\w*|stereotypes?)"), // new RegexLeaf("$")); @@ -85,38 +87,48 @@ public class CommandHideShow extends SingleLineCommand2 { } @Override - protected CommandExecutionResult executeArg(Map arg) { + protected CommandExecutionResult executeArg(UmlDiagram classDiagram, RegexResult arg) { + if (classDiagram instanceof ClassDiagram) { + return executeArgClass((ClassDiagram) classDiagram, arg); + } + // Just ignored + return CommandExecutionResult.ok(); + } - final Set portion = getEntityPortion(arg.get("PORTION").get(0)); + private CommandExecutionResult executeArgClass(ClassDiagram classDiagram, RegexResult arg) { + + final Set portion = getEntityPortion(arg.get("PORTION", 0)); EntityGender gender = null; - final String arg1 = arg.get("GENDER").get(0); + final String arg1 = arg.get("GENDER", 0); if (arg1 == null) { gender = EntityGenderUtils.all(); } else if (arg1.equalsIgnoreCase("class")) { - gender = EntityGenderUtils.byEntityType(EntityType.CLASS); + gender = EntityGenderUtils.byEntityType(LeafType.CLASS); } else if (arg1.equalsIgnoreCase("interface")) { - gender = EntityGenderUtils.byEntityType(EntityType.INTERFACE); + gender = EntityGenderUtils.byEntityType(LeafType.INTERFACE); } else if (arg1.equalsIgnoreCase("enum")) { - gender = EntityGenderUtils.byEntityType(EntityType.ENUM); + gender = EntityGenderUtils.byEntityType(LeafType.ENUM); } else if (arg1.equalsIgnoreCase("abstract")) { - gender = EntityGenderUtils.byEntityType(EntityType.ABSTRACT_CLASS); + gender = EntityGenderUtils.byEntityType(LeafType.ABSTRACT_CLASS); + } else if (arg1.equalsIgnoreCase("annotation")) { + gender = EntityGenderUtils.byEntityType(LeafType.ANNOTATION); } else if (arg1.startsWith("<<")) { gender = EntityGenderUtils.byStereotype(arg1); } else { - final IEntity entity = getSystem().getOrCreateClass(arg1); + final IEntity entity = classDiagram.getOrCreateLeaf(Code.of(arg1), null); gender = EntityGenderUtils.byEntityAlone(entity); } if (gender != null) { - final boolean empty = arg.get("EMPTY").get(0) != null; + final boolean empty = arg.get("EMPTY", 0) != null; if (empty == true) { gender = EntityGenderUtils.and(gender, emptyByGender(portion)); } - if (getSystem().getCurrentGroup() != null) { - gender = EntityGenderUtils.and(gender, EntityGenderUtils.byPackage(getSystem().getCurrentGroup())); + if (EntityUtils.groupRoot(classDiagram.getCurrentGroup()) == false) { + gender = EntityGenderUtils.and(gender, EntityGenderUtils.byPackage(classDiagram.getCurrentGroup())); } - getSystem().hideOrShow(gender, portion, arg.get("COMMAND").get(0).equalsIgnoreCase("show")); + classDiagram.hideOrShow(gender, portion, arg.get("COMMAND", 0).equalsIgnoreCase("show")); } return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandHideShow3.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandHideShow3.java index b51dbb753..efdb46691 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandHideShow3.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandHideShow3.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -34,28 +34,28 @@ package net.sourceforge.plantuml.classdiagram.command; import java.util.EnumSet; -import java.util.Map; import java.util.Set; import java.util.StringTokenizer; +import net.sourceforge.plantuml.UmlDiagram; import net.sourceforge.plantuml.classdiagram.ClassDiagram; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.SingleLineCommand2; import net.sourceforge.plantuml.command.regex.RegexConcat; import net.sourceforge.plantuml.command.regex.RegexLeaf; -import net.sourceforge.plantuml.command.regex.RegexPartialMatch; +import net.sourceforge.plantuml.command.regex.RegexResult; import net.sourceforge.plantuml.cucadiagram.EntityPortion; import net.sourceforge.plantuml.skin.VisibilityModifier; -public class CommandHideShow3 extends SingleLineCommand2 { +public class CommandHideShow3 extends SingleLineCommand2 { private static final EnumSet PORTION_METHOD = EnumSet. of(EntityPortion.METHOD); private static final EnumSet PORTION_MEMBER = EnumSet. of(EntityPortion.FIELD, EntityPortion.METHOD); private static final EnumSet PORTION_FIELD = EnumSet. of(EntityPortion.FIELD); - public CommandHideShow3(ClassDiagram classDiagram) { - super(classDiagram, getRegexConcat()); + public CommandHideShow3() { + super(getRegexConcat()); } static RegexConcat getRegexConcat() { @@ -68,19 +68,28 @@ public class CommandHideShow3 extends SingleLineCommand2 { new RegexLeaf("PORTION", "(members?|attributes?|fields?|methods?)"), // new RegexLeaf("$")); } - + @Override - protected CommandExecutionResult executeArg(Map arg) { + protected CommandExecutionResult executeArg(UmlDiagram classDiagram, RegexResult arg) { + if (classDiagram instanceof ClassDiagram) { + return executeArgClass((ClassDiagram) classDiagram, arg); + } + // Just ignored + return CommandExecutionResult.ok(); + } - final Set portion = getEntityPortion(arg.get("PORTION").get(0)); + + private CommandExecutionResult executeArgClass(ClassDiagram classDiagram, RegexResult arg) { + + final Set portion = getEntityPortion(arg.get("PORTION", 0)); final Set visibilities = EnumSet. noneOf(VisibilityModifier.class); - final StringTokenizer st = new StringTokenizer(arg.get("VISIBILITY").get(0).toLowerCase(), " ,"); + final StringTokenizer st = new StringTokenizer(arg.get("VISIBILITY", 0).toLowerCase(), " ,"); while (st.hasMoreTokens()) { addVisibilities(st.nextToken(), portion, visibilities); } - getSystem().hideOrShow(visibilities, arg.get("COMMAND").get(0).equalsIgnoreCase("show")); + classDiagram.hideOrShow(visibilities, arg.get("COMMAND", 0).equalsIgnoreCase("show")); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandHideShowSpecificClass.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandHideShowSpecificClass.java new file mode 100644 index 000000000..b06a98efe --- /dev/null +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandHideShowSpecificClass.java @@ -0,0 +1,72 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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 net.sourceforge.plantuml.classdiagram.ClassDiagram; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.SingleLineCommand2; +import net.sourceforge.plantuml.command.regex.RegexConcat; +import net.sourceforge.plantuml.command.regex.RegexLeaf; +import net.sourceforge.plantuml.command.regex.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.ILeaf; + +public class CommandHideShowSpecificClass extends SingleLineCommand2 { + + public CommandHideShowSpecificClass() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("COMMAND", "(hide|show)"), // + new RegexLeaf("\\s+"), // + new RegexLeaf("CODE", "(" + CommandCreateClass.CODE + ")"), // + new RegexLeaf("$")); + } + + @Override + protected CommandExecutionResult executeArg(ClassDiagram classDiagram, RegexResult arg) { + + final Code code = Code.of(arg.get("CODE", 0)); + final ILeaf leaf = classDiagram.getEntityFactory().getLeafs().get(code); + if (leaf == null) { + return CommandExecutionResult.error("Class does not exit : " + code); + } + classDiagram.hideOrShow(leaf, arg.get("COMMAND", 0).equalsIgnoreCase("show")); + + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandImport.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandImport.java index 23b285e26..66137b691 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandImport.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandImport.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5019 $ + * Revision $Revision: 11432 $ * */ package net.sourceforge.plantuml.classdiagram.command; @@ -41,6 +41,7 @@ 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.Code; import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.cucadiagram.Link; import net.sourceforge.plantuml.cucadiagram.LinkDecor; @@ -48,20 +49,20 @@ import net.sourceforge.plantuml.cucadiagram.LinkType; public class CommandImport extends SingleLineCommand { - public CommandImport(ClassDiagram classDiagram) { - super(classDiagram, "(?i)^import\\s+\"?([^\"]+)\"?$"); + public CommandImport() { + super("(?i)^import\\s+\"?([^\"]+)\"?$"); } @Override - protected CommandExecutionResult executeArg(List arg) { + protected CommandExecutionResult executeArg(ClassDiagram classDiagram, List arg) { final String arg0 = arg.get(0); try { final File f = FileSystem.getInstance().getFile(arg0); if (f.isFile()) { - includeSimpleFile(f); + includeSimpleFile(classDiagram, f); } else if (f.isDirectory()) { - includeDirectory(f); + includeDirectory(classDiagram, f); } } catch (IOException e) { e.printStackTrace(); @@ -70,35 +71,32 @@ public class CommandImport extends SingleLineCommand { return CommandExecutionResult.ok(); } - private void includeDirectory(File dir) throws IOException { + private void includeDirectory(ClassDiagram classDiagram, File dir) throws IOException { for (File f : dir.listFiles()) { - includeSimpleFile(f); + includeSimpleFile(classDiagram, f); } } - private void includeSimpleFile(File f) throws IOException { + private void includeSimpleFile(ClassDiagram classDiagram, File f) throws IOException { if (f.getName().toLowerCase().endsWith(".java")) { - includeFileJava(f); + includeFileJava(classDiagram, f); } // if (f.getName().toLowerCase().endsWith(".sql")) { // includeFileSql(f); // } } - private void includeFileJava(final File f) throws IOException { + private void includeFileJava(ClassDiagram classDiagram, 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()); + final Code name = Code.of(cl.getName()); + final IEntity ent1 = classDiagram.getOrCreateLeaf(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); + final IEntity ent2 = classDiagram.getOrCreateLeaf(Code.of(p), cl.getParentType()); + final Link link = new Link(ent2, ent1, new LinkType(LinkDecor.NONE, LinkDecor.EXTENDS), null, 2); + classDiagram.addLink(link); } } } diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass.java new file mode 100644 index 000000000..736dc980d --- /dev/null +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass.java @@ -0,0 +1,482 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.StringTokenizer; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import net.sourceforge.plantuml.Direction; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.UmlDiagramType; +import net.sourceforge.plantuml.command.CommandExecutionResult; +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.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.ILeaf; +import net.sourceforge.plantuml.cucadiagram.LeafType; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.cucadiagram.LinkArrow; +import net.sourceforge.plantuml.cucadiagram.LinkDecor; +import net.sourceforge.plantuml.cucadiagram.LinkType; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.objectdiagram.AbstractClassOrObjectDiagram; + +final public class CommandLinkClass extends SingleLineCommand2 { + + public CommandLinkClass(UmlDiagramType umlDiagramType) { + super(getRegexConcat(umlDiagramType)); + } + + static private 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_]+)*|\"[^\"]+\")\\s*(\\<\\<.*\\>\\>)?"), + new RegexLeaf("COUPLE1", + "\\(\\s*(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s*,\\s*(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s*\\)")), + new RegexLeaf("\\s*"), // + new RegexLeaf("FIRST_LABEL", "(?:\"([^\"]+)\")?"), // + new RegexLeaf("\\s*"), // + + new RegexConcat( + // + new RegexLeaf("ARROW_HEAD1", "( +o|[\\[<*+^]|[<\\[]\\|)?"), // + new RegexLeaf("ARROW_BODY1", "([-=.]+)"), // + new RegexLeaf("ARROW_STYLE1", + "(?:\\[((?:#\\w+|dotted|dashed|bold|hidden)(?:,#\\w+|,dotted|,dashed|,bold|,hidden)*)\\])?"), + new RegexLeaf("ARROW_DIRECTION", "(left|right|up|down|le?|ri?|up?|do?)?"), // + new RegexLeaf("ARROW_STYLE2", + "(?:\\[((?:#\\w+|dotted|dashed|bold|hidden)(?:,#\\w+|,dotted|,dashed|,bold|,hidden)*)\\])?"), + new RegexLeaf("ARROW_BODY2", "([-=.]*)"), // + new RegexLeaf("ARROW_HEAD2", "(o +|[\\]>*+^]|\\|[>\\]])?")), // + + 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_]+)*|\"[^\"]+\")\\s*(\\<\\<.*\\>\\>)?"), + new RegexLeaf("COUPLE2", + "\\(\\s*(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s*,\\s*(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s*\\)")), + new RegexLeaf("\\s*"), // + new RegexLeaf("LABEL_LINK", "(?::\\s*(.+))?"), // + new RegexLeaf("$")); + } + + private static String optionalKeywords(UmlDiagramType type) { + if (type == UmlDiagramType.CLASS) { + return "(interface|enum|annotation|abstract\\s+class|abstract|class)"; + } + if (type == UmlDiagramType.OBJECT) { + return "(object)"; + } + throw new IllegalArgumentException(); + } + + @Override + protected CommandExecutionResult executeArg(AbstractClassOrObjectDiagram diagram, RegexResult arg) { + Code ent1 = Code.of(arg.get("ENT1", 1)); + Code ent2 = Code.of(arg.get("ENT2", 1)); + if (ent1 == null) { + return executeArgSpecial1(diagram, arg); + } + if (ent2 == null) { + return executeArgSpecial2(diagram, arg); + } + ent1 = ent1.eventuallyRemoveStartingAndEndingDoubleQuote(); + ent2 = ent2.eventuallyRemoveStartingAndEndingDoubleQuote(); + if (diagram.isGroup(ent1) && diagram.isGroup(ent2)) { + return executePackageLink(diagram, arg); + } + + final IEntity cl1 = diagram.isGroup(ent1) ? diagram.getGroup(Code.of(StringUtils + .eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT1", 1)))) : diagram.getOrCreateLeaf(ent1, + null); + final IEntity cl2 = diagram.isGroup(ent2) ? diagram.getGroup(Code.of(StringUtils + .eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT2", 1)))) : diagram.getOrCreateLeaf(ent2, + null); + + if (arg.get("ENT1", 0) != null) { + final LeafType type = LeafType.getLeafType(arg.get("ENT1", 0)); + if (type != LeafType.OBJECT) { + ((ILeaf) cl1).muteToType(type); + } + } + if (arg.get("ENT2", 0) != null) { + final LeafType type = LeafType.getLeafType(arg.get("ENT2", 0)); + if (type != LeafType.OBJECT) { + ((ILeaf) cl2).muteToType(type); + } + } + if (arg.get("ENT1", 2) != null) { + cl1.setStereotype(new Stereotype(arg.get("ENT1", 2), diagram.getSkinParam().getCircledCharacterRadius(), + diagram.getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null))); + } + if (arg.get("ENT2", 2) != null) { + cl2.setStereotype(new Stereotype(arg.get("ENT2", 2), diagram.getSkinParam().getCircledCharacterRadius(), + diagram.getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null))); + } + + final LinkType linkType = getLinkType(arg); + final Direction dir = getDirection(arg); + final int queue; + if (dir == Direction.LEFT || dir == Direction.RIGHT) { + queue = 1; + } else { + queue = getQueueLength(arg); + } + + String firstLabel = arg.get("FIRST_LABEL", 0); + String secondLabel = arg.get("SECOND_LABEL", 0); + + String labelLink = null; + + if (arg.get("LABEL_LINK", 0) != null) { + labelLink = arg.get("LABEL_LINK", 0); + if (firstLabel == null && secondLabel == null) { + final Pattern p1 = Pattern.compile("^\"([^\"]+)\"([^\"]+)\"([^\"]+)\"$"); + final Matcher m1 = p1.matcher(labelLink); + if (m1.matches()) { + firstLabel = m1.group(1); + labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m1.group(2).trim()).trim(); + secondLabel = m1.group(3); + } else { + final Pattern p2 = Pattern.compile("^\"([^\"]+)\"([^\"]+)$"); + final Matcher m2 = p2.matcher(labelLink); + if (m2.matches()) { + firstLabel = m2.group(1); + labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m2.group(2).trim()).trim(); + secondLabel = null; + } else { + final Pattern p3 = Pattern.compile("^([^\"]+)\"([^\"]+)\"$"); + final Matcher m3 = p3.matcher(labelLink); + if (m3.matches()) { + firstLabel = null; + labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m3.group(1).trim()) + .trim(); + secondLabel = m3.group(2); + } + } + } + } + labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(labelLink); + } + + LinkArrow linkArrow = LinkArrow.NONE; + if ("<".equals(labelLink)) { + linkArrow = LinkArrow.BACKWARD; + labelLink = null; + } else if (">".equals(labelLink)) { + linkArrow = LinkArrow.DIRECT_NORMAL; + labelLink = null; + } else if (labelLink != null && labelLink.startsWith("< ")) { + linkArrow = LinkArrow.BACKWARD; + labelLink = labelLink.substring(2).trim(); + } else if (labelLink != null && labelLink.startsWith("> ")) { + linkArrow = LinkArrow.DIRECT_NORMAL; + labelLink = labelLink.substring(2).trim(); + } else if (labelLink != null && labelLink.endsWith(" >")) { + linkArrow = LinkArrow.DIRECT_NORMAL; + labelLink = labelLink.substring(0, labelLink.length() - 2).trim(); + } else if (labelLink != null && labelLink.endsWith(" <")) { + linkArrow = LinkArrow.BACKWARD; + labelLink = labelLink.substring(0, labelLink.length() - 2).trim(); + } + + Link link = new Link(cl1, cl2, linkType, Display.getWithNewlines(labelLink), queue, firstLabel, secondLabel, + diagram.getLabeldistance(), diagram.getLabelangle()); + + if (dir == Direction.LEFT || dir == Direction.UP) { + link = link.getInv(); + } + link.setLinkArrow(linkArrow); + applyStyle(arg.getLazzy("ARROW_STYLE", 0), link); + + addLink(diagram, link, arg.get("HEADER", 0)); + + return CommandExecutionResult.ok(); + } + + private void addLink(AbstractClassOrObjectDiagram diagram, Link link, String weight) { + diagram.addLink(link); + if (weight == null) { + // final LinkType type = link.getType(); + // --|> highest + // --*, -->, --o normal + // ..*, ..>, ..o lowest + // if (type.isDashed() == false) { + // if (type.contains(LinkDecor.EXTENDS)) { + // link.setWeight(3); + // } + // if (type.contains(LinkDecor.ARROW) || + // type.contains(LinkDecor.COMPOSITION) + // || type.contains(LinkDecor.AGREGATION)) { + // link.setWeight(2); + // } + // } + } else { + link.setWeight(Double.parseDouble(weight)); + } + } + + private CommandExecutionResult executePackageLink(AbstractClassOrObjectDiagram diagram, RegexResult arg) { + final IEntity cl1 = diagram.getGroup(Code.of(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get( + "ENT1", 1)))); + final IEntity cl2 = diagram.getGroup(Code.of(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get( + "ENT2", 1)))); + + final LinkType linkType = getLinkType(arg); + final Direction dir = getDirection(arg); + final int queue; + if (dir == Direction.LEFT || dir == Direction.RIGHT) { + queue = 1; + } else { + queue = getQueueLength(arg); + } + + final Display labelLink = Display.getWithNewlines(arg.get("LABEL_LINK", 0)); + final String firstLabel = arg.get("FIRST_LABEL", 0); + final String secondLabel = arg.get("SECOND_LABEL", 0); + final Link link = new Link(cl1, cl2, linkType, labelLink, queue, firstLabel, secondLabel, + diagram.getLabeldistance(), diagram.getLabelangle()); + + diagram.resetPragmaLabel(); + addLink(diagram, link, arg.get("HEADER", 0)); + return CommandExecutionResult.ok(); + } + + private CommandExecutionResult executeArgSpecial1(AbstractClassOrObjectDiagram diagram, RegexResult arg) { + final Code clName1 = Code.of(arg.get("COUPLE1", 0)); + final Code clName2 = Code.of(arg.get("COUPLE1", 1)); + if (diagram.leafExist(clName1) == false) { + return CommandExecutionResult.error("No class " + clName1); + } + if (diagram.leafExist(clName2) == false) { + return CommandExecutionResult.error("No class " + clName2); + } + + final Code ent2 = Code.of(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT2", 1))); + final IEntity cl2 = diagram.getOrCreateLeaf(ent2, null); + + final LinkType linkType = getLinkType(arg); + final Display label = Display.getWithNewlines(arg.get("LABEL_LINK", 0)); + // final int length = getQueueLength(arg); + // final String weight = arg.get("HEADER").get(0); + + final boolean result = diagram.associationClass(1, clName1, clName2, cl2, linkType, label); + if (result == false) { + return CommandExecutionResult.error("Cannot have more than 2 assocications"); + } + + return CommandExecutionResult.ok(); + } + + private CommandExecutionResult executeArgSpecial2(AbstractClassOrObjectDiagram diagram, RegexResult arg) { + final Code clName1 = Code.of(arg.get("COUPLE2", 0)); + final Code clName2 = Code.of(arg.get("COUPLE2", 1)); + if (diagram.leafExist(clName1) == false) { + return CommandExecutionResult.error("No class " + clName1); + } + if (diagram.leafExist(clName2) == false) { + return CommandExecutionResult.error("No class " + clName2); + } + + final Code ent1 = Code.of(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT1", 1))); + final IEntity cl1 = diagram.getOrCreateLeaf(ent1, null); + + final LinkType linkType = getLinkType(arg); + final Display label = Display.getWithNewlines(arg.get("LABEL_LINK", 0)); + // final int length = getQueueLength(arg); + // final String weight = arg.get("HEADER").get(0); + + final boolean result = diagram.associationClass(2, clName1, clName2, cl1, linkType, label); + if (result == false) { + return CommandExecutionResult.error("Cannot have more than 2 assocications"); + } + + return CommandExecutionResult.ok(); + } + + private LinkDecor getDecors1(String s) { + if (s == null) { + return LinkDecor.NONE; + } + s = s.trim(); + if ("<|".equals(s)) { + return LinkDecor.EXTENDS; + } + if ("<".equals(s)) { + return LinkDecor.ARROW; + } + if ("^".equals(s)) { + return LinkDecor.EXTENDS; + } + if ("+".equals(s)) { + return LinkDecor.PLUS; + } + if ("o".equals(s)) { + return LinkDecor.AGREGATION; + } + if ("*".equals(s)) { + return LinkDecor.COMPOSITION; + } + return LinkDecor.NONE; + } + + private LinkDecor getDecors2(String s) { + if (s == null) { + return LinkDecor.NONE; + } + s = s.trim(); + if ("|>".equals(s)) { + return LinkDecor.EXTENDS; + } + if (">".equals(s)) { + return LinkDecor.ARROW; + } + if ("^".equals(s)) { + return LinkDecor.EXTENDS; + } + if ("+".equals(s)) { + return LinkDecor.PLUS; + } + if ("o".equals(s)) { + return LinkDecor.AGREGATION; + } + if ("*".equals(s)) { + return LinkDecor.COMPOSITION; + } + return LinkDecor.NONE; + } + + private LinkType getLinkType(RegexResult arg) { + final LinkDecor decors1 = getDecors1(arg.get("ARROW_HEAD1", 0)); + final LinkDecor decors2 = getDecors2(arg.get("ARROW_HEAD2", 0)); + + LinkType result = new LinkType(decors2, decors1); + if (arg.get("ARROW_BODY1", 0).contains(".") || arg.get("ARROW_BODY2", 0).contains(".")) { + result = result.getDashed(); + } + return result; + } + + private int getQueueLength(RegexResult arg) { + String s = getFullArrow(arg); + s = s.replaceAll("[^-.=]", ""); + return s.length(); + } + + private Direction getDirection(RegexResult arg) { + final LinkDecor decors1 = getDecors1(arg.get("ARROW_HEAD1", 0)); + final LinkDecor decors2 = getDecors2(arg.get("ARROW_HEAD2", 0)); + + String s = getFullArrow(arg); + s = s.replaceAll("[^-.=\\w]", ""); + if (s.startsWith("o")) { + s = s.substring(1); + } + if (s.endsWith("o")) { + s = s.substring(0, s.length() - 1); + } + + Direction result = StringUtils.getQueueDirection(s); + if (isInversed(decors1, decors2) && s.matches(".*\\w.*")) { + result = result.getInv(); + } + + return result; + } + + private String getFullArrow(RegexResult arg) { + return notNull(arg.get("ARROW_HEAD1", 0)) + notNull(arg.get("ARROW_BODY1", 0)) + + notNull(arg.get("ARROW_DIRECTION", 0)) + notNull(arg.get("ARROW_BODY2", 0)) + + notNull(arg.get("ARROW_HEAD2", 0)); + } + + public static String notNull(String s) { + if (s == null) { + return ""; + } + return s; + } + + public static void applyStyle(String arrowStyle, Link link) { + if (arrowStyle == null) { + return; + } + final StringTokenizer st = new StringTokenizer(arrowStyle, ","); + while (st.hasMoreTokens()) { + final String s = st.nextToken(); + if (s.equalsIgnoreCase("dashed")) { + link.goDashed(); + } else if (s.equalsIgnoreCase("bold")) { + link.goBold(); + } else if (s.equalsIgnoreCase("dotted")) { + link.goDotted(); + } else if (s.equalsIgnoreCase("hidden")) { + link.goHidden(); + } else { + link.setSpecificColor(s); + } + } + } + + private boolean isInversed(LinkDecor decors1, LinkDecor decors2) { + if (decors1 == LinkDecor.ARROW && decors2 != LinkDecor.ARROW) { + return true; + } + if (decors2 == LinkDecor.AGREGATION) { + return true; + } + if (decors2 == LinkDecor.COMPOSITION) { + return true; + } + if (decors2 == LinkDecor.PLUS) { + return true; + } + // if (decors2 == LinkDecor.EXTENDS) { + // return true; + // } + return false; + } + +} diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass2.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass2.java deleted file mode 100644 index 71e2c5233..000000000 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkClass2.java +++ /dev/null @@ -1,438 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 5436 $ - * - */ -package net.sourceforge.plantuml.classdiagram.command; - -import java.util.Map; - -import net.sourceforge.plantuml.Direction; -import net.sourceforge.plantuml.FontParam; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.UmlDiagramType; -import net.sourceforge.plantuml.command.CommandExecutionResult; -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.cucadiagram.Stereotype; -import net.sourceforge.plantuml.objectdiagram.AbstractClassOrObjectDiagram; - -final public class CommandLinkClass2 extends SingleLineCommand2 { - - 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_]+)*|\"[^\"]+\")\\s*(\\<\\<.*\\>\\>)?"), - new RegexLeaf("COUPLE1", - "\\(\\s*(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s*,\\s*(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s*\\)")), - new RegexLeaf("\\s*"), - 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_]+)*|\"[^\"]+\")\\s*(\\<\\<.*\\>\\>)?"), - new RegexLeaf("COUPLE2", - "\\(\\s*(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s*,\\s*(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)\\s*\\)")), - // new RegexLeaf("\\s*"), new RegexLeaf("LABEL_LINK", - // "(?::\\s*([^\"]+))?$")); - new RegexLeaf("\\s*"), new RegexOr(null, true, new RegexLeaf("LABEL_LINK", ":\\s*([^\"]+)"), - new RegexLeaf("LABEL_LINK_XT", ":\\s*(\"[^\"]*\")?\\s*([^\"]*)\\s*(\"[^\"]*\")?")), - new RegexLeaf("$")); - } - - 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 arg) { - String ent1 = arg.get("ENT1").get(1); - String ent2 = arg.get("ENT2").get(1); - if (ent1 == null) { - return executeArgSpecial1(arg); - } - if (ent2 == null) { - return executeArgSpecial2(arg); - } - ent1 = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(ent1); - ent2 = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(ent2); - 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); - } - } - if (arg.get("ENT1").get(2) != null) { - cl1 - .setStereotype(new Stereotype(arg.get("ENT1").get(2), getSystem().getSkinParam() - .getCircledCharacterRadius(), getSystem().getSkinParam().getFont( - FontParam.CIRCLED_CHARACTER, null))); - } - if (arg.get("ENT2").get(2) != null) { - cl2 - .setStereotype(new Stereotype(arg.get("ENT2").get(2), getSystem().getSkinParam() - .getCircledCharacterRadius(), getSystem().getSkinParam().getFont( - FontParam.CIRCLED_CHARACTER, null))); - } - - final LinkType linkType = getLinkType(arg); - Direction dir = getDirection(arg); - final String queue; - if (dir == Direction.LEFT || dir == Direction.RIGHT) { - queue = "-"; - } else { - queue = getQueue(arg); - } - if (dir != null && linkType.isExtendsOrAgregationOrCompositionOrPlus()) { - dir = dir.getInv(); - } - - String firstLabel = arg.get("FIRST_LABEL").get(0); - String secondLabel = arg.get("SECOND_LABEL").get(0); - - String labelLink = null; - - if (arg.get("LABEL_LINK").get(0) != null) { - labelLink = arg.get("LABEL_LINK").get(0); - } else if (arg.get("LABEL_LINK_XT").get(0) != null || arg.get("LABEL_LINK_XT").get(1) != null - || arg.get("LABEL_LINK_XT").get(2) != null) { - labelLink = arg.get("LABEL_LINK_XT").get(1); - firstLabel = merge(firstLabel, arg.get("LABEL_LINK_XT").get(0)); - secondLabel = merge(arg.get("LABEL_LINK_XT").get(2), secondLabel); - } - - Link link = new Link(cl1, cl2, linkType, labelLink, queue.length(), firstLabel, secondLabel, 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 String merge(String a, String b) { - if (a == null && b == null) { - return null; - } - if (a == null && b != null) { - return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(b); - } - if (b == null && a != null) { - return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(a); - } - return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(a) + "\\n" - + StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(b); - } - - private void addLink(Link link, String weight) { - getSystem().addLink(link); - if (weight == null) { - final LinkType type = link.getType(); - // --|> highest - // --*, -->, --o normal - // ..*, ..>, ..o lowest - // if (type.isDashed() == false) { - // if (type.contains(LinkDecor.EXTENDS)) { - // link.setWeight(3); - // } - // if (type.contains(LinkDecor.ARROW) || - // type.contains(LinkDecor.COMPOSITION) - // || type.contains(LinkDecor.AGREGATION)) { - // link.setWeight(2); - // } - // } - } else { - link.setWeight(Double.parseDouble(weight)); - } - } - - private CommandExecutionResult executePackageLink(Map arg) { - final String ent1 = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT1").get(1)); - final String ent2 = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(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); - } - - final String labelLink = arg.get("LABEL_LINK").get(0); - final String firstLabel = arg.get("FIRST_LABEL").get(0); - final String secondLabel = arg.get("SECOND_LABEL").get(0); - Link link = new Link(cl1.getEntityCluster(), cl2.getEntityCluster(), linkType, labelLink, queue.length(), - firstLabel, secondLabel, 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 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 String ent2 = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT2").get(1)); - final IEntity cl2 = getSystem().getOrCreateClass(ent2); - - final LinkType linkType = getLinkType(arg); - final String label = arg.get("LABEL_LINK").get(0); - final int length = getQueue(arg).length(); - final String weight = arg.get("HEADER").get(0); - - final boolean result = getSystem().associationClass(1, clName1, clName2, cl2, linkType, label); - if (result == false) { - return CommandExecutionResult.error("Cannot have more than 2 assocications"); - } - - return CommandExecutionResult.ok(); - } - - private CommandExecutionResult executeArgSpecial2(Map 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 String ent1 = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT1").get(1)); - final IEntity cl1 = getSystem().getOrCreateClass(ent1); - - final LinkType linkType = getLinkType(arg); - final String label = arg.get("LABEL_LINK").get(0); - final int length = getQueue(arg).length(); - final String weight = arg.get("HEADER").get(0); - - final boolean result = getSystem().associationClass(2, clName1, clName2, cl1, linkType, label); - if (result == false) { - return CommandExecutionResult.error("Cannot have more than 2 assocications"); - } - - return CommandExecutionResult.ok(); - } - - 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 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 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 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); - } - if (k.equals("^")) { - return new LinkType(LinkDecor.EXTENDS, LinkDecor.NONE); - } - // return null; - throw new IllegalArgumentException(k); - } - -} diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkLollipop.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkLollipop.java new file mode 100644 index 000000000..a70374691 --- /dev/null +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkLollipop.java @@ -0,0 +1,222 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.regex.Matcher; +import java.util.regex.Pattern; + +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.UmlDiagramType; +import net.sourceforge.plantuml.UniqueSequence; +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.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.LeafType; +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 SingleLineCommand2 { + + public CommandLinkLollipop(UmlDiagramType umlDiagramType) { + super(getRegexConcat(umlDiagramType)); + } + + static RegexConcat getRegexConcat(UmlDiagramType umlDiagramType) { + return new RegexConcat(new RegexLeaf("HEADER", "^(?:@([\\d.]+)\\s+)?"), // + new RegexLeaf("ENT1", "(?:" + optionalKeywords(umlDiagramType) + "\\s+)?" + + "(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*|\"[^\"]+\")\\s*(\\<\\<.*\\>\\>)?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("FIRST_LABEL", "(?:\"([^\"]+)\")?"), // + new RegexLeaf("\\s*"), // + new RegexOr(new RegexLeaf("LOL_THEN_ENT", "\\(\\)([-=.]+)"), // + new RegexLeaf("ENT_THEN_LOL", "([-=.]+)\\(\\)")), // + new RegexLeaf("\\s*"), // + new RegexLeaf("SECOND_LABEL", "(?:\"([^\"]+)\")?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("ENT2", "(?:" + optionalKeywords(umlDiagramType) + "\\s+)?" + + "(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*|\"[^\"]+\")\\s*(\\<\\<.*\\>\\>)?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("LABEL_LINK", "(?::\\s*(.+))?"), // + new RegexLeaf("$")); + } + + private static String optionalKeywords(UmlDiagramType type) { + if (type == UmlDiagramType.CLASS) { + return "(interface|enum|annotation|abstract\\s+class|abstract|class)"; + } + if (type == UmlDiagramType.OBJECT) { + return "(object)"; + } + throw new IllegalArgumentException(); + } + + @Override + protected CommandExecutionResult executeArg(AbstractClassOrObjectDiagram diagram, RegexResult arg) { + + final Code ent1 = Code.of(arg.get("ENT1", 1)); + final Code ent2 = Code.of(arg.get("ENT2", 1)); + + final IEntity cl1; + final IEntity cl2; + final IEntity normalEntity; + + final String suffix = "lol" + UniqueSequence.getValue(); + if (arg.get("LOL_THEN_ENT", 0) == null) { + assert arg.get("ENT_THEN_LOL", 0) != null; + cl1 = diagram.getOrCreateLeaf(ent1, null); + cl2 = diagram.createLeaf(cl1.getCode().addSuffix(suffix), Display.getWithNewlines(ent2), LeafType.LOLLIPOP); + normalEntity = cl1; + } else { + cl2 = diagram.getOrCreateLeaf(ent2, null); + cl1 = diagram.createLeaf(cl2.getCode().addSuffix(suffix), Display.getWithNewlines(ent1), LeafType.LOLLIPOP); + normalEntity = cl2; + } + + final LinkType linkType = getLinkType(arg); + final String queue = getQueue(arg); + + int length = queue.length(); + if (length == 1 && diagram.getNbOfHozizontalLollipop(normalEntity) > 1) { + length++; + } + + String firstLabel = arg.get("FIRST_LABEL", 0); + String secondLabel = arg.get("SECOND_LABEL", 0); + + String labelLink = null; + + if (arg.get("LABEL_LINK", 0) != null) { + labelLink = arg.get("LABEL_LINK", 0); + if (firstLabel == null && secondLabel == null) { + final Pattern p1 = Pattern.compile("^\"([^\"]+)\"([^\"]+)\"([^\"]+)\"$"); + final Matcher m1 = p1.matcher(labelLink); + if (m1.matches()) { + firstLabel = m1.group(1); + labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m1.group(2).trim()).trim(); + secondLabel = m1.group(3); + } else { + final Pattern p2 = Pattern.compile("^\"([^\"]+)\"([^\"]+)$"); + final Matcher m2 = p2.matcher(labelLink); + if (m2.matches()) { + firstLabel = m2.group(1); + labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m2.group(2).trim()).trim(); + secondLabel = null; + } else { + final Pattern p3 = Pattern.compile("^([^\"]+)\"([^\"]+)\"$"); + final Matcher m3 = p3.matcher(labelLink); + if (m3.matches()) { + firstLabel = null; + labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m3.group(1).trim()) + .trim(); + secondLabel = m3.group(2); + } + } + } + } + labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(labelLink); + } /* + * else if (arg.get("LABEL_LINK_XT").get(0) != null || arg.get("LABEL_LINK_XT").get(1) != null || + * arg.get("LABEL_LINK_XT").get(2) != null) { labelLink = arg.get("LABEL_LINK_XT").get(1); firstLabel = + * merge(firstLabel, arg.get("LABEL_LINK_XT").get(0)); secondLabel = merge(arg.get("LABEL_LINK_XT").get(2), + * secondLabel); } + */ + + final Link link = new Link(cl1, cl2, linkType, Display.getWithNewlines(labelLink), length, firstLabel, + secondLabel, diagram.getLabeldistance(), diagram.getLabelangle()); + diagram.resetPragmaLabel(); + addLink(diagram, link, arg.get("HEADER", 0)); + + return CommandExecutionResult.ok(); + } + + // private String merge(String a, String b) { + // if (a == null && b == null) { + // return null; + // } + // if (a == null && b != null) { + // return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(b); + // } + // if (b == null && a != null) { + // return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(a); + // } + // return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(a) + + // "\\n" + // + StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(b); + // } + + private void addLink(AbstractClassOrObjectDiagram diagram, Link link, String weight) { + diagram.addLink(link); + if (weight == null) { + // final LinkType type = link.getType(); + // --|> highest + // --*, -->, --o normal + // ..*, ..>, ..o lowest + // if (type.isDashed() == false) { + // if (type.contains(LinkDecor.EXTENDS)) { + // link.setWeight(3); + // } + // if (type.contains(LinkDecor.ARROW) || + // type.contains(LinkDecor.COMPOSITION) + // || type.contains(LinkDecor.AGREGATION)) { + // link.setWeight(2); + // } + // } + } else { + link.setWeight(Double.parseDouble(weight)); + } + } + + private LinkType getLinkType(RegexResult arg) { + return new LinkType(LinkDecor.NONE, LinkDecor.NONE); + } + + private String getQueue(RegexResult arg) { + if (arg.get("LOL_THEN_ENT", 0) != null) { + return arg.get("LOL_THEN_ENT", 0).trim(); + } + if (arg.get("ENT_THEN_LOL", 0) != null) { + return arg.get("ENT_THEN_LOL", 0).trim(); + } + throw new IllegalArgumentException(); + } + +} diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkLollipop2.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkLollipop2.java deleted file mode 100644 index 3bf0c44ac..000000000 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandLinkLollipop2.java +++ /dev/null @@ -1,193 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 5436 $ - * - */ -package net.sourceforge.plantuml.classdiagram.command; - -import java.util.Map; - -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.UmlDiagramType; -import net.sourceforge.plantuml.UniqueSequence; -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.Link; -import net.sourceforge.plantuml.cucadiagram.LinkDecor; -import net.sourceforge.plantuml.cucadiagram.LinkType; -import net.sourceforge.plantuml.objectdiagram.AbstractClassOrObjectDiagram; - -final public class CommandLinkLollipop2 extends SingleLineCommand2 { - - public CommandLinkLollipop2(AbstractClassOrObjectDiagram diagram) { - super(diagram, getRegexConcat(diagram.getUmlDiagramType())); - } - - static RegexConcat getRegexConcat(UmlDiagramType umlDiagramType) { - return new RegexConcat(new RegexLeaf("HEADER", "^(?:@([\\d.]+)\\s+)?"), // - new RegexLeaf("ENT1", "(?:" + optionalKeywords(umlDiagramType) + "\\s+)?" - + "(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*|\"[^\"]+\")\\s*(\\<\\<.*\\>\\>)?"), // - new RegexLeaf("\\s*"), // - new RegexLeaf("FIRST_LABEL", "(?:\"([^\"]+)\")?"), // - new RegexLeaf("\\s*"), // - new RegexOr(new RegexLeaf("LOL_THEN_ENT", "\\(\\)([-=.]+)"), // - new RegexLeaf("ENT_THEN_LOL", "([-=.]+)\\(\\)")), // - new RegexLeaf("\\s*"), // - new RegexLeaf("SECOND_LABEL", "(?:\"([^\"]+)\")?"), // - new RegexLeaf("\\s*"), // - new RegexLeaf("ENT2", "(?:" + optionalKeywords(umlDiagramType) + "\\s+)?" - + "(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*|\"[^\"]+\")\\s*(\\<\\<.*\\>\\>)?"), // - new RegexLeaf("\\s*"), // - new RegexOr(null, true, // - new RegexLeaf("LABEL_LINK", ":\\s*([^\"]+)"), // - new RegexLeaf("LABEL_LINK_XT", ":\\s*(\"[^\"]*\")?\\s*([^\"]*)\\s*(\"[^\"]*\")?")), // - new RegexLeaf("$")); - } - - 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 arg) { - - final String ent1 = arg.get("ENT1").get(1); - final String ent2 = arg.get("ENT2").get(1); - - final Entity cl1; - final Entity cl2; - final Entity normalEntity; - - final String suffix = "lol" + UniqueSequence.getValue(); - if (arg.get("LOL_THEN_ENT").get(0) != null) { - cl2 = (Entity) getSystem().getOrCreateClass(ent2); - cl1 = getSystem().createEntity(cl2.getCode() + suffix, ent1, EntityType.LOLLIPOP); - normalEntity = cl2; - } else { - assert arg.get("ENT_THEN_LOL").get(0) != null; - cl1 = (Entity) getSystem().getOrCreateClass(ent1); - cl2 = getSystem().createEntity(cl1.getCode() + suffix, ent2, 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++; - } - - String firstLabel = arg.get("FIRST_LABEL").get(0); - String secondLabel = arg.get("SECOND_LABEL").get(0); - - String labelLink = null; - - if (arg.get("LABEL_LINK").get(0) != null) { - labelLink = arg.get("LABEL_LINK").get(0); - } else if (arg.get("LABEL_LINK_XT").get(0) != null || arg.get("LABEL_LINK_XT").get(1) != null - || arg.get("LABEL_LINK_XT").get(2) != null) { - labelLink = arg.get("LABEL_LINK_XT").get(1); - firstLabel = merge(firstLabel, arg.get("LABEL_LINK_XT").get(0)); - secondLabel = merge(arg.get("LABEL_LINK_XT").get(2), secondLabel); - } - - final Link link = new Link(cl1, cl2, linkType, labelLink, length, firstLabel, secondLabel, getSystem() - .getLabeldistance(), getSystem().getLabelangle()); - getSystem().resetPragmaLabel(); - addLink(link, arg.get("HEADER").get(0)); - - return CommandExecutionResult.ok(); - } - - private String merge(String a, String b) { - if (a == null && b == null) { - return null; - } - if (a == null && b != null) { - return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(b); - } - if (b == null && a != null) { - return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(a); - } - return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(a) + "\\n" - + StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(b); - } - - private void addLink(Link link, String weight) { - getSystem().addLink(link); - if (weight == null) { - final LinkType type = link.getType(); - // --|> highest - // --*, -->, --o normal - // ..*, ..>, ..o lowest - // if (type.isDashed() == false) { - // if (type.contains(LinkDecor.EXTENDS)) { - // link.setWeight(3); - // } - // if (type.contains(LinkDecor.ARROW) || - // type.contains(LinkDecor.COMPOSITION) - // || type.contains(LinkDecor.AGREGATION)) { - // link.setWeight(2); - // } - // } - } else { - link.setWeight(Double.parseDouble(weight)); - } - } - - private LinkType getLinkType(Map arg) { - return new LinkType(LinkDecor.NONE, LinkDecor.NONE); - } - - private String getQueue(Map arg) { - if (arg.get("LOL_THEN_ENT").get(0) != null) { - return arg.get("LOL_THEN_ENT").get(0).trim(); - } - if (arg.get("ENT_THEN_LOL").get(0) != null) { - return arg.get("ENT_THEN_LOL").get(0).trim(); - } - throw new IllegalArgumentException(); - } - -} diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandMouseOver.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandMouseOver.java new file mode 100644 index 000000000..cb6d1b515 --- /dev/null +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandMouseOver.java @@ -0,0 +1,122 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.StringUtils; +import net.sourceforge.plantuml.classdiagram.ClassDiagram; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.CommandMultilines2; +import net.sourceforge.plantuml.command.MultilinesStrategy; +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.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.IEntity; + +public class CommandMouseOver extends CommandMultilines2 { + + public CommandMouseOver() { + super(getRegexConcat(), MultilinesStrategy.REMOVE_STARTING_QUOTE); + } + + @Override + public String getPatternEnd() { + return "(?i)^\\s*\\}\\s*$"; + } + + private static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("mouseover\\s+"), // + new RegexOr(// + new RegexLeaf("NAME1", "(\\.?[\\p{L}0-9_]+(?:\\.[\\p{L}0-9_]+)*)"), // + new RegexLeaf("NAME3", "\"([^\"]+)\"")), // + new RegexLeaf("\\s*\\{\\s*$")); + } + + public CommandExecutionResult executeNow(ClassDiagram system, List lines) { + StringUtils.trim(lines, false); + final RegexResult line0 = getStartingPattern().matcher(lines.get(0).trim()); + Code code = Code.of(line0.get("NAME1", 0)); + if (code == null) { + code = Code.of(line0.get("NAME3", 0)); + } + if (system.leafExist(code) == false) { + return CommandExecutionResult.error("No such entity"); + } + final IEntity entity = system.getLeafs().get(code); + for (String s : lines.subList(1, lines.size() - 1)) { + entity.mouseOver(s); + } + + return CommandExecutionResult.ok(); + } + + // private Entity executeArg0(Map arg) { + // + // final EntityType type = EntityType.getEntityType(arg.get("TYPE").get(0).toUpperCase()); + // final String code; + // final String display; + // if (arg.get("NAME1").get(1) != null) { + // code = arg.get("NAME1").get(1); + // display = arg.get("NAME1").get(0); + // } else if (arg.get("NAME3").get(0) != null) { + // code = arg.get("NAME3").get(0); + // display = arg.get("NAME3").get(0); + // } else { + // code = arg.get("NAME2").get(0); + // display = arg.get("NAME2").get(1); + // } + // final String stereotype = arg.get("STEREO").get(0); + // final String generic = arg.get("GENERIC").get(0); + // + // if (system.entityExist(code)) { + // final Entity result = (Entity) system.getOrCreateClass(code); + // result.muteToType(type); + // return result; + // } + // final Entity entity = system.createEntity(code, display, type); + // if (stereotype != null) { + // entity.setStereotype(new Stereotype(stereotype, system.getSkinParam().getCircledCharacterRadius(), + // system.getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null))); + // } + // if (generic != null) { + // entity.setGeneric(generic); + // } + // return entity; + // } + +} diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandNamespace.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandNamespace.java deleted file mode 100644 index 8abad3ac6..000000000 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandNamespace.java +++ /dev/null @@ -1,64 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 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 { - - 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 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(HtmlColor.getColorIfValid(color)); - } - return CommandExecutionResult.ok(); - } - -} diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandEndNamespace.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandNamespaceSeparator.java similarity index 69% rename from src/net/sourceforge/plantuml/classdiagram/command/CommandEndNamespace.java rename to src/net/sourceforge/plantuml/classdiagram/command/CommandNamespaceSeparator.java index 2ce5b13cd..bf6310fea 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandEndNamespace.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandNamespaceSeparator.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -27,8 +27,8 @@ * in the United States and other countries.] * * Original Author: Arnaud Roques - * - * Revision $Revision: 3828 $ + * + * Revision $Revision: 9434 $ * */ package net.sourceforge.plantuml.classdiagram.command; @@ -38,22 +38,21 @@ 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 { +public class CommandNamespaceSeparator extends SingleLineCommand { - public CommandEndNamespace(ClassDiagram diagram) { - super(diagram, "(?i)^end ?namespace$"); + public CommandNamespaceSeparator() { + super("(?i)^set namespaceseparator (\\S+)$"); } @Override - protected CommandExecutionResult executeArg(List arg) { - final Group currentPackage = getSystem().getCurrentGroup(); - if (currentPackage == null) { - return CommandExecutionResult.error("No namesspace defined"); + protected CommandExecutionResult executeArg(ClassDiagram diagram, List arg) { + final String s = arg.get(0); + if ("none".equalsIgnoreCase(s)) { + diagram.setNamespaceSeparator(null); + } else { + diagram.setNamespaceSeparator(s); } - getSystem().endGroup(); return CommandExecutionResult.ok(); } - } diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandStereotype.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandStereotype.java index 50506be3e..ca46618dd 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandStereotype.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandStereotype.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5728 $ + * Revision $Revision: 11432 $ * */ package net.sourceforge.plantuml.classdiagram.command; @@ -39,22 +39,23 @@ 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.Code; +import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.cucadiagram.Stereotype; public class CommandStereotype extends SingleLineCommand { - public CommandStereotype(ClassDiagram classDiagram) { - super(classDiagram, "(?i)^([\\p{L}0-9_.]+|\"[^\"]+\")\\s*(\\<\\<.*\\>\\>)$"); + public CommandStereotype() { + super("(?i)^([\\p{L}0-9_.]+|\"[^\"]+\")\\s*(\\<\\<.*\\>\\>)$"); } @Override - protected CommandExecutionResult executeArg(List arg) { - final String code = arg.get(0); + protected CommandExecutionResult executeArg(ClassDiagram classDiagram, List arg) { + final Code code = Code.of(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, null))); + final IEntity entity = classDiagram.getOrCreateLeaf(code, null); + entity.setStereotype(new Stereotype(stereotype, classDiagram.getSkinParam().getCircledCharacterRadius(), + classDiagram.getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null))); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandUrl.java b/src/net/sourceforge/plantuml/classdiagram/command/CommandUrl.java index 5c07fcb29..e243dc937 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandUrl.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/CommandUrl.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -36,31 +36,36 @@ package net.sourceforge.plantuml.classdiagram.command; import java.util.List; import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.UrlBuilder; +import net.sourceforge.plantuml.UrlBuilder.ModeUrl; import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.SingleLineCommand; -import net.sourceforge.plantuml.cucadiagram.Entity; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.IEntity; public class CommandUrl extends SingleLineCommand { - public CommandUrl(AbstractEntityDiagram diagram) { - super(diagram, - "(?i)^url\\s*(?:of|for)?\\s+([\\p{L}0-9_.]+|\"[^\"]+\")\\s+(?:is)?\\s*\\[\\[([^|]*)(?:\\|([^|]*))?\\]\\]$"); + public CommandUrl() { + super("(?i)^url\\s*(?:of|for)?\\s+([\\p{L}0-9_.]+|\"[^\"]+\")\\s+(?:is)?\\s*(" + UrlBuilder.getRegexp() + ")$"); } @Override - protected CommandExecutionResult executeArg(List arg) { - final String code = arg.get(0); - String url = arg.get(1); - final String title = arg.get(2); - final Entity entity = (Entity) getSystem().getOrCreateClass(code); - if (url.startsWith("http:") == false && url.startsWith("https:") == false) { - final String top = getSystem().getSkinParam().getValue("topurl"); - if (top != null) { - url = top + url; - } + protected CommandExecutionResult executeArg(AbstractEntityDiagram diagram, List arg) { + final Code code = Code.of(arg.get(0)); + final String urlString = arg.get(1); + final IEntity entity; + if (diagram.leafExist(code)) { + entity = diagram.getOrCreateLeaf(code, null); + } else if (diagram.isGroup(code)) { + entity = diagram.getGroup(code); + } else { + return CommandExecutionResult.error(code + " does not exist"); } - entity.setUrl(new Url(url, title)); + // final IEntity entity = diagram.getOrCreateLeaf(code, null); + final UrlBuilder urlBuilder = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), ModeUrl.STRICT); + final Url url = urlBuilder.getUrl(urlString); + entity.addUrl(url); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/classdiagram/command/CommandMultilinesClassNote.java b/src/net/sourceforge/plantuml/classdiagram/command/GenericRegexProducer.java similarity index 66% rename from src/net/sourceforge/plantuml/classdiagram/command/CommandMultilinesClassNote.java rename to src/net/sourceforge/plantuml/classdiagram/command/GenericRegexProducer.java index d84e965d6..a00eb3103 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/CommandMultilinesClassNote.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/GenericRegexProducer.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,18 +28,28 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5616 $ + * Revision $Revision: 5075 $ * */ package net.sourceforge.plantuml.classdiagram.command; -import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram; -import net.sourceforge.plantuml.command.AbstractCommandMultilinesNoteEntity; -public class CommandMultilinesClassNote extends AbstractCommandMultilinesNoteEntity { +public class GenericRegexProducer { - public CommandMultilinesClassNote(final AbstractEntityDiagram system) { - super(system, "(?i)^note\\s+(right|left|top|bottom)\\s+(?:of\\s+)?([\\p{L}0-9_.]+|\"[^\"]+\")\\s*(#\\w+)?$"); + public final static String PATTERN = "[^\\<\\>]" + getGenericRegex(4); + + // \<[^\<\>]([^\<\>]|\<\>)*\> + static final private String part1 = "(?:[^\\<\\>]|\\<"; + static final private String part2 = "\\>)*"; + + static String getGenericRegex(int level) { + if (level < 0) { + throw new IllegalArgumentException(); + } + if (level == 0) { + return part1 + part2; + } + return part1 + getGenericRegex(level - 1) + part2; } } diff --git a/src/net/sourceforge/plantuml/classdiagram/command/JavaClass.java b/src/net/sourceforge/plantuml/classdiagram/command/JavaClass.java index f088d9679..2eb4f861f 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/JavaClass.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/JavaClass.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3827 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.classdiagram.command; @@ -38,17 +38,17 @@ import java.util.Collections; import java.util.List; import java.util.StringTokenizer; -import net.sourceforge.plantuml.cucadiagram.EntityType; +import net.sourceforge.plantuml.cucadiagram.LeafType; class JavaClass { private final String name; private final String javaPackage; private final List parents = new ArrayList(); - private final EntityType type; - private final EntityType parentType; + private final LeafType type; + private final LeafType parentType; - public JavaClass(String javaPackage, String name, String p, EntityType type, EntityType parentType) { + public JavaClass(String javaPackage, String name, String p, LeafType type, LeafType parentType) { this.name = name; this.javaPackage = javaPackage; if (p == null) { @@ -66,7 +66,7 @@ class JavaClass { return name; } - public final EntityType getType() { + public final LeafType getType() { return type; } @@ -74,7 +74,7 @@ class JavaClass { return Collections.unmodifiableList(parents); } - public final EntityType getParentType() { + public final LeafType getParentType() { return parentType; } diff --git a/src/net/sourceforge/plantuml/classdiagram/command/JavaFile.java b/src/net/sourceforge/plantuml/classdiagram/command/JavaFile.java index c0b763247..211d742ec 100644 --- a/src/net/sourceforge/plantuml/classdiagram/command/JavaFile.java +++ b/src/net/sourceforge/plantuml/classdiagram/command/JavaFile.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3827 $ + * Revision $Revision: 11254 $ * */ package net.sourceforge.plantuml.classdiagram.command; @@ -43,12 +43,12 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import net.sourceforge.plantuml.cucadiagram.EntityType; +import net.sourceforge.plantuml.cucadiagram.LeafType; class JavaFile { private static final Pattern classDefinition = Pattern - .compile("^(?:public\\s+|abstract\\s+|final\\s+)*(class|interface|enum)\\s+(\\w+)(?:.*\\b(extends|implements)\\s+([\\w\\s,]+))?"); + .compile("^(?:public\\s+|abstract\\s+|final\\s+)*(class|interface|enum|annotation)\\s+(\\w+)(?:.*\\b(extends|implements)\\s+([\\w\\s,]+))?"); private static final Pattern packageDefinition = Pattern.compile("^package\\s+([\\w+.]+)\\s*;"); @@ -79,25 +79,25 @@ class JavaFile { if (matchClassDefinition.find()) { final String n = matchClassDefinition.group(2); final String p = matchClassDefinition.group(4); - final EntityType type = EntityType.valueOf(matchClassDefinition.group(1).toUpperCase()); - final EntityType parentType = getParentType(type, matchClassDefinition.group(3)); + final LeafType type = LeafType.valueOf(matchClassDefinition.group(1).toUpperCase()); + final LeafType parentType = getParentType(type, matchClassDefinition.group(3)); all.add(new JavaClass(javaPackage, n, p, type, parentType)); } } } } - static EntityType getParentType(EntityType type, String extendsOrImplements) { + static LeafType getParentType(LeafType type, String extendsOrImplements) { if (extendsOrImplements == null) { return null; } - if (type == EntityType.CLASS) { + if (type == LeafType.CLASS) { if (extendsOrImplements.equals("extends")) { - return EntityType.CLASS; + return LeafType.CLASS; } - return EntityType.INTERFACE; + return LeafType.INTERFACE; } - return EntityType.INTERFACE; + return LeafType.INTERFACE; } public List getJavaClasses() { diff --git a/src/net/sourceforge/plantuml/code/ArobaseStringCompressor.java b/src/net/sourceforge/plantuml/code/ArobaseStringCompressor.java index 6f1ae4774..f4f89b88a 100644 --- a/src/net/sourceforge/plantuml/code/ArobaseStringCompressor.java +++ b/src/net/sourceforge/plantuml/code/ArobaseStringCompressor.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,20 +28,54 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6362 $ + * Revision $Revision: 10933 $ * */ package net.sourceforge.plantuml.code; import java.io.IOException; +import java.io.StringReader; import java.util.regex.Matcher; import java.util.regex.Pattern; +import net.sourceforge.plantuml.preproc.ReadLine; +import net.sourceforge.plantuml.preproc.ReadLineReader; +import net.sourceforge.plantuml.preproc.UncommentReadLine; + public class ArobaseStringCompressor implements StringCompressor { private final static Pattern p = Pattern.compile("(?s)(?i)^\\s*(@startuml[^\\n\\r]*)?\\s*(.*?)\\s*(@enduml)?\\s*$"); - public String compress(String s) throws IOException { + public String compress(final String data) throws IOException { + final ReadLine r = new UncommentReadLine(new ReadLineReader(new StringReader(data))); + final StringBuilder sb = new StringBuilder(); + final StringBuilder full = new StringBuilder(); + String s = null; + boolean startDone = false; + while ((s = r.readLine()) != null) { + append(full, s); + if (s.startsWith("@startuml")) { + startDone = true; + } else if (s.startsWith("@enduml")) { + return sb.toString(); + } else if (startDone) { + append(sb, s); + } + } + if (startDone == false) { + return compressOld(full.toString()); + } + return sb.toString(); + } + + private void append(final StringBuilder sb, String s) { + if (sb.length() > 0) { + sb.append('\n'); + } + sb.append(s); + } + + private String compressOld(String s) throws IOException { final Matcher m = p.matcher(s); if (m.find()) { return clean(m.group(2)); diff --git a/src/net/sourceforge/plantuml/code/AsciiEncoder.java b/src/net/sourceforge/plantuml/code/AsciiEncoder.java index 9ac76f9c8..5b486972f 100644 --- a/src/net/sourceforge/plantuml/code/AsciiEncoder.java +++ b/src/net/sourceforge/plantuml/code/AsciiEncoder.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6170 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.code; @@ -67,7 +67,11 @@ public class AsciiEncoder implements URLEncoder { return data; } - private char encode6bit(byte b) { + public int decode6bit(char c) { + return decode6bit[c]; + } + + public char encode6bit(byte b) { assert b >= 0 && b < 64; if (b < 10) { return (char) ('0' + b); diff --git a/src/net/sourceforge/plantuml/code/Base64Coder.java b/src/net/sourceforge/plantuml/code/Base64Coder.java new file mode 100644 index 000000000..5ab87e32e --- /dev/null +++ b/src/net/sourceforge/plantuml/code/Base64Coder.java @@ -0,0 +1,321 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 6170 $ + * + */ +// Copyright 2003-2010 Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland +// www.source-code.biz, www.inventec.ch/chdh +// +// This module is multi-licensed and may be used under the terms +// of any of the following licenses: +// +// EPL, Eclipse Public License, V1.0 or later, http://www.eclipse.org/legal +// LGPL, GNU Lesser General Public License, V2.1 or later, http://www.gnu.org/licenses/lgpl.html +// GPL, GNU General Public License, V2 or later, http://www.gnu.org/licenses/gpl.html +// AL, Apache License, V2.0 or later, http://www.apache.org/licenses +// BSD, BSD License, http://www.opensource.org/licenses/bsd-license.php +// MIT, MIT License, http://www.opensource.org/licenses/MIT +// +// Please contact the author if you need another license. +// This module is provided "as is", without warranties of any kind. +package net.sourceforge.plantuml.code; + +/** + * A Base64 encoder/decoder. + * + *

+ * This class is used to encode and decode data in Base64 format as described in RFC 1521. + * + *

+ * Project home page: www.source-code.biz/base64coder/java
+ * Author: Christian d'Heureuse, Inventec Informatik AG, Zurich, Switzerland
+ * Multi-licensed: EPL / LGPL / GPL / AL / BSD / MIT. + */ +public class Base64Coder { + + // The line separator string of the operating system. + private static final String systemLineSeparator = System.getProperty("line.separator"); + + // Mapping table from 6-bit nibbles to Base64 characters. + private static final char[] map1 = new char[64]; + static { + int i = 0; + for (char c = 'A'; c <= 'Z'; c++) + map1[i++] = c; + for (char c = 'a'; c <= 'z'; c++) + map1[i++] = c; + for (char c = '0'; c <= '9'; c++) + map1[i++] = c; + map1[i++] = '+'; + map1[i++] = '/'; + } + + // Mapping table from Base64 characters to 6-bit nibbles. + private static final byte[] map2 = new byte[128]; + static { + for (int i = 0; i < map2.length; i++) + map2[i] = -1; + for (int i = 0; i < 64; i++) + map2[map1[i]] = (byte) i; + } + + /** + * Encodes a string into Base64 format. No blanks or line breaks are inserted. + * + * @param s + * A String to be encoded. + * @return A String containing the Base64 encoded data. + */ + public static String encodeString(String s) { + return new String(encode(s.getBytes())); + } + + /** + * Encodes a byte array into Base 64 format and breaks the output into lines of 76 characters. This method is + * compatible with sun.misc.BASE64Encoder.encodeBuffer(byte[]). + * + * @param in + * An array containing the data bytes to be encoded. + * @return A String containing the Base64 encoded data, broken into lines. + */ + public static String encodeLines(byte[] in) { + return encodeLines(in, 0, in.length, 76, systemLineSeparator); + } + + /** + * Encodes a byte array into Base 64 format and breaks the output into lines. + * + * @param in + * An array containing the data bytes to be encoded. + * @param iOff + * Offset of the first byte in in to be processed. + * @param iLen + * Number of bytes to be processed in in, starting at iOff. + * @param lineLen + * Line length for the output data. Should be a multiple of 4. + * @param lineSeparator + * The line separator to be used to separate the output lines. + * @return A String containing the Base64 encoded data, broken into lines. + */ + public static String encodeLines(byte[] in, int iOff, int iLen, int lineLen, String lineSeparator) { + int blockLen = (lineLen * 3) / 4; + if (blockLen <= 0) + throw new IllegalArgumentException(); + int lines = (iLen + blockLen - 1) / blockLen; + int bufLen = ((iLen + 2) / 3) * 4 + lines * lineSeparator.length(); + StringBuilder buf = new StringBuilder(bufLen); + int ip = 0; + while (ip < iLen) { + int l = Math.min(iLen - ip, blockLen); + buf.append(encode(in, iOff + ip, l)); + buf.append(lineSeparator); + ip += l; + } + return buf.toString(); + } + + /** + * Encodes a byte array into Base64 format. No blanks or line breaks are inserted in the output. + * + * @param in + * An array containing the data bytes to be encoded. + * @return A character array containing the Base64 encoded data. + */ + public static char[] encode(byte[] in) { + return encode(in, 0, in.length); + } + + /** + * Encodes a byte array into Base64 format. No blanks or line breaks are inserted in the output. + * + * @param in + * An array containing the data bytes to be encoded. + * @param iLen + * Number of bytes to process in in. + * @return A character array containing the Base64 encoded data. + */ + public static char[] encode(byte[] in, int iLen) { + return encode(in, 0, iLen); + } + + /** + * Encodes a byte array into Base64 format. No blanks or line breaks are inserted in the output. + * + * @param in + * An array containing the data bytes to be encoded. + * @param iOff + * Offset of the first byte in in to be processed. + * @param iLen + * Number of bytes to process in in, starting at iOff. + * @return A character array containing the Base64 encoded data. + */ + public static char[] encode(byte[] in, int iOff, int iLen) { + int oDataLen = (iLen * 4 + 2) / 3; // output length without padding + int oLen = ((iLen + 2) / 3) * 4; // output length including padding + char[] out = new char[oLen]; + int ip = iOff; + int iEnd = iOff + iLen; + int op = 0; + while (ip < iEnd) { + int i0 = in[ip++] & 0xff; + int i1 = ip < iEnd ? in[ip++] & 0xff : 0; + int i2 = ip < iEnd ? in[ip++] & 0xff : 0; + int o0 = i0 >>> 2; + int o1 = ((i0 & 3) << 4) | (i1 >>> 4); + int o2 = ((i1 & 0xf) << 2) | (i2 >>> 6); + int o3 = i2 & 0x3F; + out[op++] = map1[o0]; + out[op++] = map1[o1]; + out[op] = op < oDataLen ? map1[o2] : '='; + op++; + out[op] = op < oDataLen ? map1[o3] : '='; + op++; + } + return out; + } + + /** + * Decodes a string from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input data. + * + * @param s + * A Base64 String to be decoded. + * @return A String containing the decoded data. + * @throws IllegalArgumentException + * If the input is not valid Base64 encoded data. + */ + public static String decodeString(String s) { + return new String(decode(s)); + } + + /** + * Decodes a byte array from Base64 format and ignores line separators, tabs and blanks. CR, LF, Tab and Space + * characters are ignored in the input data. This method is compatible with + * sun.misc.BASE64Decoder.decodeBuffer(String). + * + * @param s + * A Base64 String to be decoded. + * @return An array containing the decoded data bytes. + * @throws IllegalArgumentException + * If the input is not valid Base64 encoded data. + */ + public static byte[] decodeLines(String s) { + char[] buf = new char[s.length()]; + int p = 0; + for (int ip = 0; ip < s.length(); ip++) { + char c = s.charAt(ip); + if (c != ' ' && c != '\r' && c != '\n' && c != '\t') + buf[p++] = c; + } + return decode(buf, 0, p); + } + + /** + * Decodes a byte array from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input + * data. + * + * @param s + * A Base64 String to be decoded. + * @return An array containing the decoded data bytes. + * @throws IllegalArgumentException + * If the input is not valid Base64 encoded data. + */ + public static byte[] decode(String s) { + return decode(s.toCharArray()); + } + + /** + * Decodes a byte array from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input + * data. + * + * @param in + * A character array containing the Base64 encoded data. + * @return An array containing the decoded data bytes. + * @throws IllegalArgumentException + * If the input is not valid Base64 encoded data. + */ + public static byte[] decode(char[] in) { + return decode(in, 0, in.length); + } + + /** + * Decodes a byte array from Base64 format. No blanks or line breaks are allowed within the Base64 encoded input + * data. + * + * @param in + * A character array containing the Base64 encoded data. + * @param iOff + * Offset of the first character in in to be processed. + * @param iLen + * Number of characters to process in in, starting at iOff. + * @return An array containing the decoded data bytes. + * @throws IllegalArgumentException + * If the input is not valid Base64 encoded data. + */ + public static byte[] decode(char[] in, int iOff, int iLen) { + if (iLen % 4 != 0) + throw new IllegalArgumentException("Length of Base64 encoded input string is not a multiple of 4."); + while (iLen > 0 && in[iOff + iLen - 1] == '=') + iLen--; + int oLen = (iLen * 3) / 4; + byte[] out = new byte[oLen]; + int ip = iOff; + int iEnd = iOff + iLen; + int op = 0; + while (ip < iEnd) { + int i0 = in[ip++]; + int i1 = in[ip++]; + int i2 = ip < iEnd ? in[ip++] : 'A'; + int i3 = ip < iEnd ? in[ip++] : 'A'; + if (i0 > 127 || i1 > 127 || i2 > 127 || i3 > 127) + throw new IllegalArgumentException("Illegal character in Base64 encoded data."); + int b0 = map2[i0]; + int b1 = map2[i1]; + int b2 = map2[i2]; + int b3 = map2[i3]; + if (b0 < 0 || b1 < 0 || b2 < 0 || b3 < 0) + throw new IllegalArgumentException("Illegal character in Base64 encoded data."); + int o0 = (b0 << 2) | (b1 >>> 4); + int o1 = ((b1 & 0xf) << 4) | (b2 >>> 2); + int o2 = ((b2 & 3) << 6) | b3; + out[op++] = (byte) o0; + if (op < oLen) + out[op++] = (byte) o1; + if (op < oLen) + out[op++] = (byte) o2; + } + return out; + } + + // Dummy constructor. + private Base64Coder() { + } + +} // end class Base64Coder \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/code/Compression.java b/src/net/sourceforge/plantuml/code/Compression.java index 19e8fc672..81fc984f0 100644 --- a/src/net/sourceforge/plantuml/code/Compression.java +++ b/src/net/sourceforge/plantuml/code/Compression.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3827 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.code; diff --git a/src/net/sourceforge/plantuml/code/CompressionGZip.java b/src/net/sourceforge/plantuml/code/CompressionGZip.java index fc1ec1249..a894c32eb 100644 --- a/src/net/sourceforge/plantuml/code/CompressionGZip.java +++ b/src/net/sourceforge/plantuml/code/CompressionGZip.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3827 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.code; diff --git a/src/net/sourceforge/plantuml/code/CompressionHuffman.java b/src/net/sourceforge/plantuml/code/CompressionHuffman.java index ab78a8e48..4f7b87df9 100644 --- a/src/net/sourceforge/plantuml/code/CompressionHuffman.java +++ b/src/net/sourceforge/plantuml/code/CompressionHuffman.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3827 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.code; diff --git a/src/net/sourceforge/plantuml/code/CompressionNone.java b/src/net/sourceforge/plantuml/code/CompressionNone.java index 93b69e117..c3bc62af3 100644 --- a/src/net/sourceforge/plantuml/code/CompressionNone.java +++ b/src/net/sourceforge/plantuml/code/CompressionNone.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3827 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.code; diff --git a/src/net/sourceforge/plantuml/code/CompressionZlib.java b/src/net/sourceforge/plantuml/code/CompressionZlib.java index d3d06266b..403dce02f 100644 --- a/src/net/sourceforge/plantuml/code/CompressionZlib.java +++ b/src/net/sourceforge/plantuml/code/CompressionZlib.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/code/StringCompressor.java b/src/net/sourceforge/plantuml/code/StringCompressor.java index 4be17abbe..5474f51a8 100644 --- a/src/net/sourceforge/plantuml/code/StringCompressor.java +++ b/src/net/sourceforge/plantuml/code/StringCompressor.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3827 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.code; diff --git a/src/net/sourceforge/plantuml/code/StringCompressorNone.java b/src/net/sourceforge/plantuml/code/StringCompressorNone.java index 79e8fee78..a49a082cf 100644 --- a/src/net/sourceforge/plantuml/code/StringCompressorNone.java +++ b/src/net/sourceforge/plantuml/code/StringCompressorNone.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3827 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.code; diff --git a/src/net/sourceforge/plantuml/code/Transcoder.java b/src/net/sourceforge/plantuml/code/Transcoder.java index 85bb12d67..78b18756f 100644 --- a/src/net/sourceforge/plantuml/code/Transcoder.java +++ b/src/net/sourceforge/plantuml/code/Transcoder.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5669 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.code; diff --git a/src/net/sourceforge/plantuml/code/TranscoderImpl.java b/src/net/sourceforge/plantuml/code/TranscoderImpl.java index 57acc0ecd..b38141b33 100644 --- a/src/net/sourceforge/plantuml/code/TranscoderImpl.java +++ b/src/net/sourceforge/plantuml/code/TranscoderImpl.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -42,7 +42,7 @@ public class TranscoderImpl implements Transcoder { private final StringCompressor stringCompressor; public TranscoderImpl() { - this(new AsciiEncoder(), new CompressionHuffman()); + this(new AsciiEncoder(), new StringCompressorNone(), new CompressionHuffman()); } public TranscoderImpl(URLEncoder urlEncoder, Compression compression) { diff --git a/src/net/sourceforge/plantuml/code/TranscoderSmart.java b/src/net/sourceforge/plantuml/code/TranscoderSmart.java index cfbe73ce0..1389fd306 100644 --- a/src/net/sourceforge/plantuml/code/TranscoderSmart.java +++ b/src/net/sourceforge/plantuml/code/TranscoderSmart.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/code/TranscoderUtil.java b/src/net/sourceforge/plantuml/code/TranscoderUtil.java index 6877fc28d..a8a68a1d6 100644 --- a/src/net/sourceforge/plantuml/code/TranscoderUtil.java +++ b/src/net/sourceforge/plantuml/code/TranscoderUtil.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/code/URLEncoder.java b/src/net/sourceforge/plantuml/code/URLEncoder.java index 2b7d26563..f7f0bf9cf 100644 --- a/src/net/sourceforge/plantuml/code/URLEncoder.java +++ b/src/net/sourceforge/plantuml/code/URLEncoder.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3827 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.code; diff --git a/src/net/sourceforge/plantuml/command/AbstractCommandMultilinesNoteEntity.java b/src/net/sourceforge/plantuml/command/AbstractCommandMultilinesNoteEntity.java deleted file mode 100644 index ebc46658f..000000000 --- a/src/net/sourceforge/plantuml/command/AbstractCommandMultilinesNoteEntity.java +++ /dev/null @@ -1,98 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6575 $ - * - */ -package net.sourceforge.plantuml.command; - -import java.util.List; - -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.UniqueSequence; -import net.sourceforge.plantuml.Url; -import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram; -import net.sourceforge.plantuml.cucadiagram.Entity; -import net.sourceforge.plantuml.cucadiagram.EntityType; -import net.sourceforge.plantuml.cucadiagram.IEntity; -import net.sourceforge.plantuml.cucadiagram.Link; -import net.sourceforge.plantuml.cucadiagram.LinkDecor; -import net.sourceforge.plantuml.cucadiagram.LinkType; -import net.sourceforge.plantuml.graphic.HtmlColor; -import net.sourceforge.plantuml.sequencediagram.Note; - -public abstract class AbstractCommandMultilinesNoteEntity extends CommandMultilines { - - protected AbstractCommandMultilinesNoteEntity(final AbstractEntityDiagram system, String patternStart) { - super(system, patternStart, "(?i)^end ?note$"); - } - - public final CommandExecutionResult execute(List lines) { - - final List line0 = StringUtils.getSplit(getStartingPattern(), lines.get(0).trim()); - final String pos = line0.get(0); - - final IEntity cl1 = getSystem().getOrCreateClass(line0.get(1)); - - List strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1)); - Url url = null; - if (strings.size() > 0) { - url = Note.extractUrl(strings.get(0)); - } - if (url != null) { - strings = strings.subList(1, strings.size()); - } - - final String s = StringUtils.getMergedLines(strings); - - final Entity note = getSystem().createEntity("GMN" + UniqueSequence.getValue(), s, EntityType.NOTE); - note.setSpecificBackcolor(HtmlColor.getColorIfValid(line0.get(2))); - note.setUrl(url); - - 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(cl1, note, type, null, 1); - } else if (position == Position.LEFT) { - link = new Link(note, cl1, type, null, 1); - } else if (position == Position.BOTTOM) { - link = new Link(cl1, note, type, null, 2); - } else if (position == Position.TOP) { - link = new Link(note, cl1, type, null, 2); - } else { - throw new IllegalArgumentException(); - } - getSystem().addLink(link); - return CommandExecutionResult.ok(); - } - -} diff --git a/src/net/sourceforge/plantuml/command/AbstractUmlSystemCommandFactory.java b/src/net/sourceforge/plantuml/command/AbstractUmlSystemCommandFactory.java deleted file mode 100644 index 1f33d5cb7..000000000 --- a/src/net/sourceforge/plantuml/command/AbstractUmlSystemCommandFactory.java +++ /dev/null @@ -1,134 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6750 $ - * - */ -package net.sourceforge.plantuml.command; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import net.sourceforge.plantuml.DiagramType; -import net.sourceforge.plantuml.UmlDiagram; - -public abstract class AbstractUmlSystemCommandFactory implements PSystemCommandFactory { - - private final DiagramType type; - private List cmds; - - protected AbstractUmlSystemCommandFactory() { - this(DiagramType.UML); - } - - protected AbstractUmlSystemCommandFactory(DiagramType type) { - this.type = type; - } - - public String checkFinalError() { - return null; - } - - - final public CommandControl isValid(List lines) { - for (Command cmd : cmds) { - final CommandControl result = cmd.isValid(lines); - if (result == CommandControl.OK || result == CommandControl.OK_PARTIAL) { - return result; - } - } - return CommandControl.NOT_OK; - - } - - final public Command createCommand(List lines) { - for (Command cmd : cmds) { - final CommandControl result = cmd.isValid(lines); - if (result == CommandControl.OK) { - return cmd; - } else if (result == CommandControl.OK_PARTIAL) { - throw new IllegalArgumentException(); - } - } - throw new IllegalArgumentException(); - } - - final public void init(String startLine) { - cmds = new ArrayList(); - initCommands(); - } - - protected abstract void initCommands(); - - final protected void addCommonCommands(UmlDiagram system) { - addCommand(new CommandNope(system)); - addCommand(new CommandComment(system)); - addCommand(new CommandMultilinesComment(system)); - addCommand(new CommandPragma(system)); - addCommand(new CommandTitle(system)); - addCommand(new CommandMultilinesTitle(system)); - - addCommand(new CommandFooter(system)); - addCommand(new CommandMultilinesFooter(system)); - - addCommand(new CommandHeader(system)); - addCommand(new CommandMultilinesHeader(system)); - - addCommand(new CommandSkinParam(system)); - addCommand(new CommandSkinParamMultilines(system)); - addCommand(new CommandMinwidth(system)); - addCommand(new CommandRotate(system)); - addCommand(new CommandScale(system)); - addCommand(new CommandScaleWidthAndHeight(system)); - addCommand(new CommandScaleWidthOrHeight(system)); - addCommand(new CommandHideUnlinked(system)); - - } - - protected final void addCommand(Command cmd) { - cmds.add(cmd); - } - - final public List getDescription() { - final List result = new ArrayList(); - for (Command cmd : cmds) { - result.addAll(Arrays.asList(cmd.getDescription())); - } - return Collections.unmodifiableList(result); - - } - - final public DiagramType getDiagramType() { - return type; - } - -} diff --git a/src/net/sourceforge/plantuml/command/Command.java b/src/net/sourceforge/plantuml/command/Command.java index ef9453be8..58a024ef5 100644 --- a/src/net/sourceforge/plantuml/command/Command.java +++ b/src/net/sourceforge/plantuml/command/Command.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,23 +28,21 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6184 $ + * Revision $Revision: 10778 $ * */ package net.sourceforge.plantuml.command; import java.util.List; -public interface Command { +import net.sourceforge.plantuml.core.Diagram; - CommandExecutionResult execute(List lines); +public interface Command { + + CommandExecutionResult execute(D diagram, List lines); CommandControl isValid(List lines); - boolean isDeprecated(List lines); - - String getHelpMessageForDeprecated(List lines); - String[] getDescription(); } diff --git a/src/net/sourceforge/plantuml/command/CommandComment.java b/src/net/sourceforge/plantuml/command/CommandComment.java index d4b1b46b9..12fda0d3d 100644 --- a/src/net/sourceforge/plantuml/command/CommandComment.java +++ b/src/net/sourceforge/plantuml/command/CommandComment.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -35,16 +35,16 @@ package net.sourceforge.plantuml.command; import java.util.List; -import net.sourceforge.plantuml.PSystem; +import net.sourceforge.plantuml.core.Diagram; -public class CommandComment extends SingleLineCommand { +public class CommandComment extends SingleLineCommand { - public CommandComment(PSystem diagram) { - super(diagram, "(?i)^\\s*('.*||/'.*'/\\s*)$"); + public CommandComment() { + super("(?i)^\\s*('.*||/'.*'/\\s*)$"); } @Override - protected CommandExecutionResult executeArg(List arg) { + protected CommandExecutionResult executeArg(Diagram diagram, List arg) { return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/command/CommandControl.java b/src/net/sourceforge/plantuml/command/CommandControl.java index cd795ff7c..18bd14c99 100644 --- a/src/net/sourceforge/plantuml/command/CommandControl.java +++ b/src/net/sourceforge/plantuml/command/CommandControl.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3828 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.command; diff --git a/src/net/sourceforge/plantuml/command/CommandEndNamespace.java b/src/net/sourceforge/plantuml/command/CommandEndNamespace.java new file mode 100644 index 000000000..8571aca89 --- /dev/null +++ b/src/net/sourceforge/plantuml/command/CommandEndNamespace.java @@ -0,0 +1,57 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.command; + +import java.util.List; + +import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram; +import net.sourceforge.plantuml.cucadiagram.IEntity; + +public class CommandEndNamespace extends SingleLineCommand { + + public CommandEndNamespace() { + super("(?i)^end ?namespace$"); + } + + @Override + protected CommandExecutionResult executeArg(AbstractEntityDiagram diagram, List arg) { + final IEntity currentPackage = diagram.getCurrentGroup(); + if (currentPackage == null) { + return CommandExecutionResult.error("No namesspace defined"); + } + diagram.endGroup(); + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/command/CommandEndPackage.java b/src/net/sourceforge/plantuml/command/CommandEndPackage.java index 37133498f..99db6ecac 100644 --- a/src/net/sourceforge/plantuml/command/CommandEndPackage.java +++ b/src/net/sourceforge/plantuml/command/CommandEndPackage.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4762 $ + * Revision $Revision: 10778 $ * */ package net.sourceforge.plantuml.command; @@ -36,21 +36,22 @@ package net.sourceforge.plantuml.command; import java.util.List; import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram; -import net.sourceforge.plantuml.cucadiagram.Group; +import net.sourceforge.plantuml.cucadiagram.EntityUtils; +import net.sourceforge.plantuml.cucadiagram.IGroup; public class CommandEndPackage extends SingleLineCommand { - public CommandEndPackage(AbstractEntityDiagram diagram) { - super(diagram, "(?i)^(end ?package|\\})$"); + public CommandEndPackage() { + super("(?i)^(end ?package|\\})$"); } @Override - protected CommandExecutionResult executeArg(List arg) { - final Group currentPackage = getSystem().getCurrentGroup(); - if (currentPackage == null) { + protected CommandExecutionResult executeArg(AbstractEntityDiagram diagram, List arg) { + final IGroup currentPackage = diagram.getCurrentGroup(); + if (EntityUtils.groupRoot(currentPackage)) { return CommandExecutionResult.error("No package defined"); } - getSystem().endGroup(); + diagram.endGroup(); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/command/CommandExecutionResult.java b/src/net/sourceforge/plantuml/command/CommandExecutionResult.java index 5e2d70a79..0c8a966b8 100644 --- a/src/net/sourceforge/plantuml/command/CommandExecutionResult.java +++ b/src/net/sourceforge/plantuml/command/CommandExecutionResult.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,21 +33,33 @@ */ package net.sourceforge.plantuml.command; +import net.sourceforge.plantuml.AbstractPSystem; public class CommandExecutionResult { private final String error; + private final AbstractPSystem newDiagram; - private CommandExecutionResult(String error) { - this.error = error; + private CommandExecutionResult(String error, AbstractPSystem newDiagram) { + this.error = error; + this.newDiagram = newDiagram; + } + + @Override + public String toString() { + return super.toString() + " " + error; + } + + public static CommandExecutionResult newDiagram(AbstractPSystem result) { + return new CommandExecutionResult(null, result); } public static CommandExecutionResult ok() { - return new CommandExecutionResult(null); + return new CommandExecutionResult(null, null); } public static CommandExecutionResult error(String error) { - return new CommandExecutionResult(error); + return new CommandExecutionResult(error, null); } public boolean isOk() { @@ -61,4 +73,8 @@ public class CommandExecutionResult { return error; } + public AbstractPSystem getNewDiagram() { + return newDiagram; + } + } diff --git a/src/net/sourceforge/plantuml/command/CommandFooter.java b/src/net/sourceforge/plantuml/command/CommandFooter.java index f153e63e8..26f5ac1cf 100644 --- a/src/net/sourceforge/plantuml/command/CommandFooter.java +++ b/src/net/sourceforge/plantuml/command/CommandFooter.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,30 +28,30 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4762 $ + * Revision $Revision: 11153 $ * */ package net.sourceforge.plantuml.command; import java.util.List; -import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.UmlDiagram; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; public class CommandFooter extends SingleLineCommand { - public CommandFooter(UmlDiagram diagram) { - super(diagram, "(?i)^(?:(left|right|center)?\\s*)footer(?:\\s*:\\s*|\\s+)(.*[\\p{L}0-9_.].*)$"); + public CommandFooter() { + super("(?i)^(?:(left|right|center)?\\s*)footer(?:\\s*:\\s*|\\s+)(.*[\\p{L}0-9_.].*)$"); } @Override - protected CommandExecutionResult executeArg(List arg) { + protected CommandExecutionResult executeArg(UmlDiagram diagram, List arg) { final String align = arg.get(0); if (align != null) { - getSystem().setFooterAlignement(HorizontalAlignement.valueOf(align.toUpperCase())); + diagram.setFooterAlignment(HorizontalAlignment.valueOf(align.toUpperCase())); } - getSystem().setFooter(StringUtils.getWithNewlines(arg.get(1))); + diagram.setFooter(Display.getWithNewlines(arg.get(1))); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/command/CommandHeader.java b/src/net/sourceforge/plantuml/command/CommandHeader.java index dcafe7ee7..38830abff 100644 --- a/src/net/sourceforge/plantuml/command/CommandHeader.java +++ b/src/net/sourceforge/plantuml/command/CommandHeader.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,30 +28,30 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4762 $ + * Revision $Revision: 11153 $ * */ package net.sourceforge.plantuml.command; import java.util.List; -import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.UmlDiagram; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; public class CommandHeader extends SingleLineCommand { - public CommandHeader(UmlDiagram diagram) { - super(diagram, "(?i)^(?:(left|right|center)?\\s*)header(?:\\s*:\\s*|\\s+)(.*[\\p{L}0-9_.].*)$"); + public CommandHeader() { + super("(?i)^(?:(left|right|center)?\\s*)header(?:\\s*:\\s*|\\s+)(.*[\\p{L}0-9_.].*)$"); } @Override - protected CommandExecutionResult executeArg(List arg) { + protected CommandExecutionResult executeArg(UmlDiagram diagram, List arg) { final String align = arg.get(0); if (align != null) { - getSystem().setHeaderAlignement(HorizontalAlignement.valueOf(align.toUpperCase())); + diagram.setHeaderAlignment(HorizontalAlignment.valueOf(align.toUpperCase())); } - getSystem().setHeader(StringUtils.getWithNewlines(arg.get(1))); + diagram.setHeader(Display.getWithNewlines(arg.get(1))); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/command/CommandHideUnlinked.java b/src/net/sourceforge/plantuml/command/CommandHideUnlinked.java index 9c46295f9..6628fa4bc 100644 --- a/src/net/sourceforge/plantuml/command/CommandHideUnlinked.java +++ b/src/net/sourceforge/plantuml/command/CommandHideUnlinked.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -39,13 +39,13 @@ import net.sourceforge.plantuml.UmlDiagram; public class CommandHideUnlinked extends SingleLineCommand { - public CommandHideUnlinked(UmlDiagram diagram) { - super(diagram, "(?i)^(hide|show)\\s+unlinked$"); + public CommandHideUnlinked() { + super("(?i)^(hide|show)\\s+unlinked$"); } @Override - protected CommandExecutionResult executeArg(List arg) { - getSystem().setHideUnlinkedData(arg.get(0).equalsIgnoreCase("hide")); + protected CommandExecutionResult executeArg(UmlDiagram diagram, List arg) { + diagram.setHideUnlinkedData(arg.get(0).equalsIgnoreCase("hide")); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/command/CommandMinwidth.java b/src/net/sourceforge/plantuml/command/CommandMinwidth.java index 8fd7fe988..7a0f9abc0 100644 --- a/src/net/sourceforge/plantuml/command/CommandMinwidth.java +++ b/src/net/sourceforge/plantuml/command/CommandMinwidth.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4762 $ + * Revision $Revision: 10778 $ * */ package net.sourceforge.plantuml.command; @@ -39,15 +39,15 @@ import net.sourceforge.plantuml.UmlDiagram; public class CommandMinwidth extends SingleLineCommand { - public CommandMinwidth(UmlDiagram system) { - super(system, "(?i)^minwidth\\s+(\\d+)$"); + public CommandMinwidth() { + super("(?i)^minwidth\\s+(\\d+)$"); } @Override - protected CommandExecutionResult executeArg(List arg) { + protected CommandExecutionResult executeArg(UmlDiagram system, List arg) { final int minwidth = Integer.parseInt(arg.get(0)); - ((UmlDiagram) getSystem()).setMinwidth(minwidth); + system.setMinwidth(minwidth); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/command/CommandMultilines.java b/src/net/sourceforge/plantuml/command/CommandMultilines.java index c5f3f975c..27a2ac15e 100644 --- a/src/net/sourceforge/plantuml/command/CommandMultilines.java +++ b/src/net/sourceforge/plantuml/command/CommandMultilines.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6186 $ + * Revision $Revision: 10778 $ * */ package net.sourceforge.plantuml.command; @@ -37,29 +37,26 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import net.sourceforge.plantuml.PSystem; +import net.sourceforge.plantuml.core.Diagram; -public abstract class CommandMultilines implements Command { - - private final S system; +public abstract class CommandMultilines implements Command { private final Pattern starting; - private final Pattern ending; - public CommandMultilines(final S system, String patternStart, String patternEnd) { + // private final Pattern ending; + + public CommandMultilines(String patternStart) { if (patternStart.startsWith("(?i)^") == false || patternStart.endsWith("$") == false) { throw new IllegalArgumentException("Bad pattern " + patternStart); } - if (patternEnd.startsWith("(?i)^") == false || patternEnd.endsWith("$") == false) { - throw new IllegalArgumentException("Bad pattern " + patternEnd); - } - this.system = system; this.starting = Pattern.compile(patternStart); - this.ending = Pattern.compile(patternEnd); + // this.ending = Pattern.compile(getPatternEnd()); } - + + public abstract String getPatternEnd(); + public String[] getDescription() { - return new String[] { "START: " + starting.pattern(), "END: " + ending.pattern() }; + return new String[] { "START: " + starting.pattern(), "END: " + getPatternEnd() }; } final public CommandControl isValid(List lines) { @@ -74,7 +71,7 @@ public abstract class CommandMultilines implements Command { return CommandControl.OK_PARTIAL; } - m1 = ending.matcher(lines.get(lines.size() - 1).trim()); + m1 = Pattern.compile(getPatternEnd()).matcher(lines.get(lines.size() - 1).trim()); if (m1.matches() == false) { return CommandControl.OK_PARTIAL; } @@ -90,24 +87,8 @@ public abstract class CommandMultilines implements Command { protected void actionIfCommandValid() { } - protected S getSystem() { - return system; - } - protected final Pattern getStartingPattern() { return starting; } - protected final Pattern getEnding() { - return ending; - } - - public boolean isDeprecated(List line) { - return false; - } - - public String getHelpMessageForDeprecated(List lines) { - return null; - } - } diff --git a/src/net/sourceforge/plantuml/command/CommandMultilines2.java b/src/net/sourceforge/plantuml/command/CommandMultilines2.java index deb795142..8c879cbc7 100644 --- a/src/net/sourceforge/plantuml/command/CommandMultilines2.java +++ b/src/net/sourceforge/plantuml/command/CommandMultilines2.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -37,33 +37,31 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import net.sourceforge.plantuml.PSystem; import net.sourceforge.plantuml.command.regex.RegexConcat; +import net.sourceforge.plantuml.core.Diagram; -public abstract class CommandMultilines2 implements Command { - - private final S system; +public abstract class CommandMultilines2 implements Command { private final RegexConcat starting; - private final Pattern ending; - public CommandMultilines2(final S system, RegexConcat patternStart, String patternEnd) { + private final MultilinesStrategy strategy; + + public CommandMultilines2(RegexConcat patternStart, MultilinesStrategy strategy) { if (patternStart.getPattern().startsWith("^") == false || patternStart.getPattern().endsWith("$") == false) { throw new IllegalArgumentException("Bad pattern " + patternStart.getPattern()); } - if (patternEnd.startsWith("(?i)^") == false || patternEnd.endsWith("$") == false) { - throw new IllegalArgumentException("Bad pattern " + patternEnd); - } - this.system = system; + this.strategy = strategy; this.starting = patternStart; - this.ending = Pattern.compile(patternEnd); } - + + public abstract String getPatternEnd(); + public String[] getDescription() { - return new String[] { "START: "+starting.getPattern(), "END: "+ending.pattern() }; + return new String[] { "START: " + starting.getPattern(), "END: " + getPatternEnd() }; } final public CommandControl isValid(List lines) { + lines = strategy.filter(lines); if (isCommandForbidden()) { return CommandControl.NOT_OK; } @@ -75,7 +73,7 @@ public abstract class CommandMultilines2 implements Command { return CommandControl.OK_PARTIAL; } - final Matcher m1 = ending.matcher(lines.get(lines.size() - 1).trim()); + final Matcher m1 = Pattern.compile(getPatternEnd()).matcher(lines.get(lines.size() - 1).trim()); if (m1.matches() == false) { return CommandControl.OK_PARTIAL; } @@ -84,6 +82,12 @@ public abstract class CommandMultilines2 implements Command { return CommandControl.OK; } + public final CommandExecutionResult execute(S system, List lines) { + return executeNow(system, strategy.filter(lines)); + } + + public abstract CommandExecutionResult executeNow(S system, List lines); + protected boolean isCommandForbidden() { return false; } @@ -91,24 +95,8 @@ public abstract class CommandMultilines2 implements Command { protected void actionIfCommandValid() { } - protected S getSystem() { - return system; - } - protected final RegexConcat getStartingPattern() { return starting; } - protected final Pattern getEnding() { - return ending; - } - - public boolean isDeprecated(List line) { - return false; - } - - public String getHelpMessageForDeprecated(List lines) { - return null; - } - } diff --git a/src/net/sourceforge/plantuml/command/CommandMultilinesBracket.java b/src/net/sourceforge/plantuml/command/CommandMultilinesBracket.java index e17ac0c8d..589400887 100644 --- a/src/net/sourceforge/plantuml/command/CommandMultilinesBracket.java +++ b/src/net/sourceforge/plantuml/command/CommandMultilinesBracket.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -37,19 +37,16 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import net.sourceforge.plantuml.PSystem; +import net.sourceforge.plantuml.core.Diagram; -public abstract class CommandMultilinesBracket implements Command { - - private final S system; +public abstract class CommandMultilinesBracket implements Command { private final Pattern starting; - public CommandMultilinesBracket(final S system, String patternStart) { + public CommandMultilinesBracket(String patternStart) { if (patternStart.startsWith("(?i)^") == false || patternStart.endsWith("$") == false) { throw new IllegalArgumentException("Bad pattern " + patternStart); } - this.system = system; this.starting = Pattern.compile(patternStart); } @@ -64,22 +61,10 @@ public abstract class CommandMultilinesBracket implements Com protected void actionIfCommandValid() { } - protected S getSystem() { - return system; - } - protected final Pattern getStartingPattern() { return starting; } - public boolean isDeprecated(List line) { - return false; - } - - public String getHelpMessageForDeprecated(List lines) { - return null; - } - final public CommandControl isValid(List lines) { if (isCommandForbidden()) { return CommandControl.NOT_OK; diff --git a/src/net/sourceforge/plantuml/command/CommandMultilinesComment.java b/src/net/sourceforge/plantuml/command/CommandMultilinesComment.java index 0b9c2eacc..a2135651d 100644 --- a/src/net/sourceforge/plantuml/command/CommandMultilinesComment.java +++ b/src/net/sourceforge/plantuml/command/CommandMultilinesComment.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -35,15 +35,20 @@ package net.sourceforge.plantuml.command; import java.util.List; -import net.sourceforge.plantuml.UmlDiagram; +import net.sourceforge.plantuml.core.Diagram; -public class CommandMultilinesComment extends CommandMultilines { +public class CommandMultilinesComment extends CommandMultilines { - public CommandMultilinesComment(final UmlDiagram diagram) { - super(diagram, "(?i)^\\s*/'.*$", "(?i)^.*'/\\s*$"); + public CommandMultilinesComment() { + super("(?i)^\\s*/'.*$"); } - public CommandExecutionResult execute(List lines) { + @Override + public String getPatternEnd() { + return "(?i)^.*'/\\s*$"; + } + + public CommandExecutionResult execute(final Diagram diagram, List lines) { return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/command/CommandMultilinesFooter.java b/src/net/sourceforge/plantuml/command/CommandMultilinesFooter.java index a0e2abf34..a3d1517f7 100644 --- a/src/net/sourceforge/plantuml/command/CommandMultilinesFooter.java +++ b/src/net/sourceforge/plantuml/command/CommandMultilinesFooter.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5957 $ + * Revision $Revision: 11153 $ * */ package net.sourceforge.plantuml.command; @@ -38,15 +38,21 @@ import java.util.regex.Matcher; import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.UmlDiagram; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; public class CommandMultilinesFooter extends CommandMultilines { - public CommandMultilinesFooter(final UmlDiagram diagram) { - super(diagram, "(?i)^(?:(left|right|center)?\\s*)footer$", "(?i)^end ?footer$"); + public CommandMultilinesFooter() { + super("(?i)^(?:(left|right|center)?\\s*)footer$"); } - public CommandExecutionResult execute(List lines) { + @Override + public String getPatternEnd() { + return "(?i)^end ?footer$"; + } + + public CommandExecutionResult execute(final UmlDiagram diagram, List lines) { StringUtils.trim(lines, false); final Matcher m = getStartingPattern().matcher(lines.get(0).trim()); if (m.find() == false) { @@ -54,11 +60,11 @@ public class CommandMultilinesFooter extends CommandMultilines { } final String align = m.group(1); if (align != null) { - getSystem().setFooterAlignement(HorizontalAlignement.valueOf(align.toUpperCase())); + diagram.setFooterAlignment(HorizontalAlignment.valueOf(align.toUpperCase())); } - final List strings = lines.subList(1, lines.size() - 1); + final Display strings = new Display(lines.subList(1, lines.size() - 1)); if (strings.size() > 0) { - getSystem().setFooter(strings); + diagram.setFooter(strings); return CommandExecutionResult.ok(); } return CommandExecutionResult.error("Empty footer"); diff --git a/src/net/sourceforge/plantuml/command/CommandMultilinesHeader.java b/src/net/sourceforge/plantuml/command/CommandMultilinesHeader.java index 8b8445886..e1de5aac5 100644 --- a/src/net/sourceforge/plantuml/command/CommandMultilinesHeader.java +++ b/src/net/sourceforge/plantuml/command/CommandMultilinesHeader.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5957 $ + * Revision $Revision: 11153 $ * */ package net.sourceforge.plantuml.command; @@ -38,15 +38,22 @@ import java.util.regex.Matcher; import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.UmlDiagram; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; public class CommandMultilinesHeader extends CommandMultilines { - public CommandMultilinesHeader(final UmlDiagram diagram) { - super(diagram, "(?i)^(?:(left|right|center)?\\s*)header$", "(?i)^end ?header$"); + public CommandMultilinesHeader() { + super("(?i)^(?:(left|right|center)?\\s*)header$"); + } + + @Override + public String getPatternEnd() { + return "(?i)^end ?header$"; } - public CommandExecutionResult execute(List lines) { + + public CommandExecutionResult execute(final UmlDiagram diagram, List lines) { StringUtils.trim(lines, false); final Matcher m = getStartingPattern().matcher(lines.get(0).trim()); if (m.find() == false) { @@ -54,11 +61,11 @@ public class CommandMultilinesHeader extends CommandMultilines { } final String align = m.group(1); if (align != null) { - getSystem().setHeaderAlignement(HorizontalAlignement.valueOf(align.toUpperCase())); + diagram.setHeaderAlignment(HorizontalAlignment.valueOf(align.toUpperCase())); } - final List strings = lines.subList(1, lines.size() - 1); + final Display strings = new Display(lines.subList(1, lines.size() - 1)); if (strings.size() > 0) { - getSystem().setHeader(strings); + diagram.setHeader(strings); return CommandExecutionResult.ok(); } return CommandExecutionResult.error("Empty header"); diff --git a/src/net/sourceforge/plantuml/command/CommandMultilinesLegend.java b/src/net/sourceforge/plantuml/command/CommandMultilinesLegend.java new file mode 100644 index 000000000..dd805f024 --- /dev/null +++ b/src/net/sourceforge/plantuml/command/CommandMultilinesLegend.java @@ -0,0 +1,80 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 10779 $ + * + */ +package net.sourceforge.plantuml.command; + +import java.util.List; + +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.UmlDiagram; +import net.sourceforge.plantuml.command.regex.RegexConcat; +import net.sourceforge.plantuml.command.regex.RegexLeaf; +import net.sourceforge.plantuml.command.regex.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; + +public class CommandMultilinesLegend extends CommandMultilines2 { + + public CommandMultilinesLegend() { + super(getRegexConcat(), MultilinesStrategy.REMOVE_STARTING_QUOTE); + } + + private static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("legend"), // + new RegexLeaf("ALIGN", "(?:\\s+(left|right|center))?"), // + new RegexLeaf("$")); + } + + @Override + public String getPatternEnd() { + return "(?i)^end ?legend$"; + } + + @Override + public CommandExecutionResult executeNow(UmlDiagram diagram, List lines) { + StringUtils.trim(lines, false); + final RegexResult line0 = getStartingPattern().matcher(lines.get(0).trim()); + final String align = line0.get("ALIGN", 0); + final Display strings = new Display(lines.subList(1, lines.size() - 1)).removeEmptyColumns(); + if (strings.size() > 0) { + HorizontalAlignment alignment = HorizontalAlignment.fromString(align); + if (alignment == null) { + alignment = HorizontalAlignment.CENTER; + } + diagram.setLegend(StringUtils.manageEmbededDiagrams(strings), alignment); + return CommandExecutionResult.ok(); + } + return CommandExecutionResult.error("No legend defined"); + } +} diff --git a/src/net/sourceforge/plantuml/command/CommandMultilinesStandaloneNote.java b/src/net/sourceforge/plantuml/command/CommandMultilinesStandaloneNote.java deleted file mode 100644 index 11f6a3ba8..000000000 --- a/src/net/sourceforge/plantuml/command/CommandMultilinesStandaloneNote.java +++ /dev/null @@ -1,63 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6575 $ - * - */ -package net.sourceforge.plantuml.command; - -import java.util.List; - -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram; -import net.sourceforge.plantuml.cucadiagram.EntityType; -import net.sourceforge.plantuml.graphic.HtmlColor; - -public class CommandMultilinesStandaloneNote extends CommandMultilines { - - public CommandMultilinesStandaloneNote(final AbstractEntityDiagram system) { - super(system, "(?i)^(note)\\s+as\\s+([\\p{L}0-9_.]+)\\s*(#\\w+)?$", "(?i)^end ?note$"); - } - - public CommandExecutionResult execute(List lines) { - - final List line0 = StringUtils.getSplit(getStartingPattern(), lines.get(0).trim()); - - final List strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1)); - final String display = StringUtils.getMergedLines(strings); - - final EntityType type = EntityType.NOTE; - final String code = line0.get(1); - getSystem().createEntity(code, display, type).setSpecificBackcolor(HtmlColor.getColorIfValid(line0.get(2))); - - return CommandExecutionResult.ok(); - } - -} diff --git a/src/net/sourceforge/plantuml/command/CommandMultilinesTitle.java b/src/net/sourceforge/plantuml/command/CommandMultilinesTitle.java index 8e10564d8..42315daf0 100644 --- a/src/net/sourceforge/plantuml/command/CommandMultilinesTitle.java +++ b/src/net/sourceforge/plantuml/command/CommandMultilinesTitle.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6922 $ + * Revision $Revision: 10779 $ * */ package net.sourceforge.plantuml.command; @@ -37,17 +37,23 @@ import java.util.List; import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.UmlDiagram; +import net.sourceforge.plantuml.cucadiagram.Display; public class CommandMultilinesTitle extends CommandMultilines { - public CommandMultilinesTitle(final UmlDiagram diagram) { - super(diagram, "(?i)^title$", "(?i)^end ?title$"); + public CommandMultilinesTitle() { + super("(?i)^title$"); } - public CommandExecutionResult execute(List lines) { - final List strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1)); + @Override + public String getPatternEnd() { + return "(?i)^end ?title$"; + } + + public CommandExecutionResult execute(final UmlDiagram diagram, List lines) { + final Display strings = new Display(lines.subList(1, lines.size() - 1)).removeEmptyColumns(); if (strings.size() > 0) { - getSystem().setTitle(StringUtils.manageEmbededDiagrams(strings)); + diagram.setTitle(StringUtils.manageEmbededDiagrams(strings)); return CommandExecutionResult.ok(); } return CommandExecutionResult.error("No title defined"); diff --git a/src/net/sourceforge/plantuml/command/CommandNamespace.java b/src/net/sourceforge/plantuml/command/CommandNamespace.java new file mode 100644 index 000000000..8e1284a78 --- /dev/null +++ b/src/net/sourceforge/plantuml/command/CommandNamespace.java @@ -0,0 +1,82 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.command; + +import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram; +import net.sourceforge.plantuml.command.regex.RegexConcat; +import net.sourceforge.plantuml.command.regex.RegexLeaf; +import net.sourceforge.plantuml.command.regex.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.GroupType; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.IGroup; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; + +public class CommandNamespace extends SingleLineCommand2 { + + public CommandNamespace() { + super(getRegexConcat()); + } + + private static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^namespace\\s+"), // + new RegexLeaf("NAME", "([\\p{L}0-9_][\\p{L}0-9_.:]*)"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("STEREOTYPE", "(\\<\\<.*\\>\\>)?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("COLOR", "(#\\w+[-\\\\|/]?\\w+)?"), // + new RegexLeaf("\\s*\\{?$")); + } + + + @Override + protected CommandExecutionResult executeArg(AbstractEntityDiagram diagram, RegexResult arg) { + final Code code = Code.of(arg.get("NAME", 0)); + final IGroup currentPackage = diagram.getCurrentGroup(); + final IEntity p = diagram.getOrCreateGroup(code, Display.getWithNewlines(code), code.getCode(), + GroupType.PACKAGE, currentPackage); + final String stereotype = arg.get("STEREOTYPE", 0); + if (stereotype != null) { + p.setStereotype(new Stereotype(stereotype)); + } + final String color = arg.get("COLOR", 0); + if (color != null) { + p.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(color)); + } + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/command/CommandNope.java b/src/net/sourceforge/plantuml/command/CommandNope.java index cd0287456..918d6f443 100644 --- a/src/net/sourceforge/plantuml/command/CommandNope.java +++ b/src/net/sourceforge/plantuml/command/CommandNope.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -35,16 +35,16 @@ package net.sourceforge.plantuml.command; import java.util.List; -import net.sourceforge.plantuml.PSystem; +import net.sourceforge.plantuml.core.Diagram; -public class CommandNope extends SingleLineCommand { +public class CommandNope extends SingleLineCommand { - public CommandNope(PSystem diagram) { - super(diagram, "(?i)^\\s*$"); + public CommandNope() { + super("(?i)^\\s*$"); } @Override - protected CommandExecutionResult executeArg(List arg) { + protected CommandExecutionResult executeArg(Diagram diagram, List arg) { return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/command/CommandNoteEntity.java b/src/net/sourceforge/plantuml/command/CommandNoteEntity.java deleted file mode 100644 index 10af25337..000000000 --- a/src/net/sourceforge/plantuml/command/CommandNoteEntity.java +++ /dev/null @@ -1,84 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6575 $ - * - */ -package net.sourceforge.plantuml.command; - -import java.util.List; - -import net.sourceforge.plantuml.UniqueSequence; -import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram; -import net.sourceforge.plantuml.cucadiagram.Entity; -import net.sourceforge.plantuml.cucadiagram.EntityType; -import net.sourceforge.plantuml.cucadiagram.IEntity; -import net.sourceforge.plantuml.cucadiagram.Link; -import net.sourceforge.plantuml.cucadiagram.LinkDecor; -import net.sourceforge.plantuml.cucadiagram.LinkType; -import net.sourceforge.plantuml.graphic.HtmlColor; - -final public class CommandNoteEntity extends SingleLineCommand { - - public CommandNoteEntity(AbstractEntityDiagram classDiagram) { - super( - classDiagram, - "(?i)^note\\s+(right|left|top|bottom)\\s+of\\s+([\\p{L}0-9_.]+|\\((?!\\*\\))[^\\)]+\\)|\\[[^\\]*]+[^\\]]*\\]|\\(\\)\\s*[\\p{L}0-9_.]+|\\(\\)\\s*\"[^\"]+\"|:[^:]+:|\"[^\"]+\")" - + "\\s*(#\\w+)?\\s*:\\s*(.*)$"); - } - - @Override - protected CommandExecutionResult executeArg(List arg) { - final String pos = arg.get(0); - final IEntity cl1 = getSystem().getOrCreateClass(arg.get(1)); - final Entity note = getSystem().createEntity("GN" + UniqueSequence.getValue(), arg.get(3), EntityType.NOTE); - note.setSpecificBackcolor(HtmlColor.getColorIfValid(arg.get(2))); - - 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(cl1, note, type, null, 1); - } else if (position == Position.LEFT) { - link = new Link(note, cl1, type, null, 1); - } else if (position == Position.BOTTOM) { - link = new Link(cl1, note, type, null, 2); - } else if (position == Position.TOP) { - link = new Link(note, cl1, type, null, 2); - } else { - throw new IllegalArgumentException(); - } - getSystem().addLink(link); - return CommandExecutionResult.ok(); - - } - -} diff --git a/src/net/sourceforge/plantuml/command/CommandPackage.java b/src/net/sourceforge/plantuml/command/CommandPackage.java index 838ee0fe7..9658afb83 100644 --- a/src/net/sourceforge/plantuml/command/CommandPackage.java +++ b/src/net/sourceforge/plantuml/command/CommandPackage.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,54 +28,82 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6209 $ + * Revision $Revision: 7800 $ * */ package net.sourceforge.plantuml.command; -import java.util.List; - import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.UniqueSequence; +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.UrlBuilder; +import net.sourceforge.plantuml.UrlBuilder.ModeUrl; import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram; -import net.sourceforge.plantuml.cucadiagram.Group; +import net.sourceforge.plantuml.command.regex.RegexConcat; +import net.sourceforge.plantuml.command.regex.RegexLeaf; +import net.sourceforge.plantuml.command.regex.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.cucadiagram.GroupType; -import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.IGroup; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; -public class CommandPackage extends SingleLineCommand { +public class CommandPackage extends SingleLineCommand2 { - public CommandPackage(AbstractEntityDiagram diagram) { - super(diagram, - "(?i)^package\\s+(\"[^\"]+\"|[^#\\s{}]*)(?:\\s+as\\s+([\\p{L}0-9_.]+))?\\s*(#[0-9a-fA-F]{6}|#?\\w+)?\\s*\\{?$"); - // "(?i)^package\\s+(\"[^\"]+\"|\\S+)(?:\\s+as\\s+([\\p{L}0-9_.]+))?\\s*(#[0-9a-fA-F]{6}|#?\\w+)?\\s*\\{?$"); + public CommandPackage() { + super(getRegexConcat()); + } + + private static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^package\\s+"), // + new RegexLeaf("NAME", "(\"[^\"]+\"|[^#\\s{}]*)"), // + new RegexLeaf("AS", "(?:\\s+as\\s+([\\p{L}0-9_.]+))?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("STEREOTYPE", "(\\<\\<.*\\>\\>)?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("URL", "(" + UrlBuilder.getRegexp() + ")?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("COLOR", "(#\\w+[-\\\\|/]?\\w+)?"), // + // new RegexLeaf("COLOR", "(#[0-9a-fA-F]{6}|#?\\w+)?"), // + new RegexLeaf("\\s*\\{?$")); } @Override - protected CommandExecutionResult executeArg(List arg) { - final String code; + protected CommandExecutionResult executeArg(AbstractEntityDiagram diagram, RegexResult arg) { + final Code code; final String display; - if (arg.get(1) == null) { - if (StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(0)).length() == 0) { - code = "##" + UniqueSequence.getValue(); + final String name = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("NAME", 0)); + if (arg.get("AS", 0) == null) { + if (name.length() == 0) { + code = Code.of("##" + UniqueSequence.getValue()); display = null; } else { - code = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(0)); - display = code; + code = Code.of(name); + display = code.getCode(); } } else { - display = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(0)); - code = arg.get(1); + display = name; + code = Code.of(arg.get("AS", 0)); } - final Group currentPackage = getSystem().getCurrentGroup(); - // if (getSystem().entityExist(code)) { - // return CommandExecutionResult.error("Package cannot have the same - // name as an existing class"); - // } - final Group p = getSystem().getOrCreateGroup(code, display, null, GroupType.PACKAGE, currentPackage); - p.setBold(true); - final String color = arg.get(2); + final IGroup currentPackage = diagram.getCurrentGroup(); + final IEntity p = diagram.getOrCreateGroup(code, Display.getWithNewlines(display), null, GroupType.PACKAGE, currentPackage); + final String stereotype = arg.get("STEREOTYPE", 0); + if (stereotype != null) { + p.setStereotype(new Stereotype(stereotype)); + } + + final String urlString = arg.get("URL", 0); + if (urlString != null) { + final UrlBuilder urlBuilder = new UrlBuilder(diagram.getSkinParam().getValue("topurl"), ModeUrl.STRICT); + final Url url = urlBuilder.getUrl(urlString); + p.addUrl(url); + } + + final String color = arg.get("COLOR", 0); if (color != null) { - p.setBackColor(HtmlColor.getColorIfValid(color)); + p.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(color)); } return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/command/CommandPackageEmpty.java b/src/net/sourceforge/plantuml/command/CommandPackageEmpty.java new file mode 100644 index 000000000..ffc0c8988 --- /dev/null +++ b/src/net/sourceforge/plantuml/command/CommandPackageEmpty.java @@ -0,0 +1,82 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 6209 $ + * + */ +package net.sourceforge.plantuml.command; + +import java.util.List; + +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.UniqueSequence; +import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.GroupType; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.IGroup; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; + +public class CommandPackageEmpty extends SingleLineCommand { + + public CommandPackageEmpty() { + super( + "(?i)^package\\s+(\"[^\"]+\"|[^#\\s{}]*)(?:\\s+as\\s+([\\p{L}0-9_.]+))?\\s*(#[0-9a-fA-F]{6}|#?\\w+)?\\s*\\{\\s*\\}$"); + } + + @Override + protected CommandExecutionResult executeArg(AbstractEntityDiagram diagram, List arg) { + final Code code; + final String display; + if (arg.get(1) == null) { + if (StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(0)).length() == 0) { + code = Code.of("##" + UniqueSequence.getValue()); + display = null; + } else { + code = Code.of(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(0))); + display = code.getCode(); + } + } else { + display = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(0)); + code = Code.of(arg.get(1)); + } + final IGroup currentPackage = diagram.getCurrentGroup(); + final IEntity p = diagram.getOrCreateGroup(code, Display.getWithNewlines(display), null, GroupType.PACKAGE, + currentPackage); + final String color = arg.get(2); + if (color != null) { + p.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(color)); + } + diagram.endGroup(); + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/command/CommandPage.java b/src/net/sourceforge/plantuml/command/CommandPage.java index fda580973..dec00dd92 100644 --- a/src/net/sourceforge/plantuml/command/CommandPage.java +++ b/src/net/sourceforge/plantuml/command/CommandPage.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4762 $ + * Revision $Revision: 10778 $ * */ package net.sourceforge.plantuml.command; @@ -39,20 +39,20 @@ import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram; public class CommandPage extends SingleLineCommand { - public CommandPage(AbstractEntityDiagram classDiagram) { - super(classDiagram, "(?i)^page\\s+(\\d+)\\s*x\\s*(\\d+)$"); + public CommandPage() { + super("(?i)^page\\s+(\\d+)\\s*x\\s*(\\d+)$"); } @Override - protected CommandExecutionResult executeArg(List arg) { + protected CommandExecutionResult executeArg(AbstractEntityDiagram classDiagram, List arg) { final int horizontal = Integer.parseInt(arg.get(0)); final int vertical = Integer.parseInt(arg.get(1)); if (horizontal <= 0 || vertical <= 0) { return CommandExecutionResult.error("Argument must be positive"); } - getSystem().setHorizontalPages(horizontal); - getSystem().setVerticalPages(vertical); + classDiagram.setHorizontalPages(horizontal); + classDiagram.setVerticalPages(vertical); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/command/CommandPragma.java b/src/net/sourceforge/plantuml/command/CommandPragma.java index b18aa6606..ab0113e18 100644 --- a/src/net/sourceforge/plantuml/command/CommandPragma.java +++ b/src/net/sourceforge/plantuml/command/CommandPragma.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -39,13 +39,13 @@ import net.sourceforge.plantuml.UmlDiagram; public class CommandPragma extends SingleLineCommand { - public CommandPragma(UmlDiagram system) { - super(system, "(?i)^!pragma\\s+([A-Za-z_][A-Za-z_0-9]*)(?:\\s+(.*))?$"); + public CommandPragma() { + super("(?i)^!pragma\\s+([A-Za-z_][A-Za-z_0-9]*)(?:\\s+(.*))?$"); } @Override - protected CommandExecutionResult executeArg(List arg) { - getSystem().getPragma().define(arg.get(0).toLowerCase(), arg.get(1)); + protected CommandExecutionResult executeArg(UmlDiagram system, List arg) { + system.getPragma().define(arg.get(0).toLowerCase(), arg.get(1)); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/usecasediagram/command/CommandRankDirUsecase.java b/src/net/sourceforge/plantuml/command/CommandRankDir.java similarity index 65% rename from src/net/sourceforge/plantuml/usecasediagram/command/CommandRankDirUsecase.java rename to src/net/sourceforge/plantuml/command/CommandRankDir.java index f196846f4..9fe3359f9 100644 --- a/src/net/sourceforge/plantuml/usecasediagram/command/CommandRankDirUsecase.java +++ b/src/net/sourceforge/plantuml/command/CommandRankDir.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -29,25 +29,23 @@ * Original Author: Arnaud Roques * */ -package net.sourceforge.plantuml.usecasediagram.command; +package net.sourceforge.plantuml.command; import java.util.List; -import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram; -import net.sourceforge.plantuml.command.CommandExecutionResult; -import net.sourceforge.plantuml.command.SingleLineCommand; +import net.sourceforge.plantuml.cucadiagram.CucaDiagram; import net.sourceforge.plantuml.cucadiagram.Rankdir; -public class CommandRankDirUsecase extends SingleLineCommand { +public class CommandRankDir extends SingleLineCommand { - public CommandRankDirUsecase(AbstractEntityDiagram diagram) { - super(diagram, "(?i)^(left to right|top to bottom)\\s+direction$"); + public CommandRankDir() { + super("(?i)^(left to right|top to bottom)\\s+direction$"); } @Override - protected CommandExecutionResult executeArg(List arg) { + protected CommandExecutionResult executeArg(CucaDiagram diagram, List arg) { final String s = arg.get(0).toUpperCase().replace(' ', '_'); - getSystem().setRankdir(Rankdir.valueOf(s)); + diagram.setRankdir(Rankdir.valueOf(s)); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/command/CommandRotate.java b/src/net/sourceforge/plantuml/command/CommandRotate.java index 661ea5c61..d281e333a 100644 --- a/src/net/sourceforge/plantuml/command/CommandRotate.java +++ b/src/net/sourceforge/plantuml/command/CommandRotate.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4762 $ + * Revision $Revision: 10778 $ * */ package net.sourceforge.plantuml.command; @@ -39,14 +39,14 @@ import net.sourceforge.plantuml.UmlDiagram; public class CommandRotate extends SingleLineCommand { - public CommandRotate(UmlDiagram diagram) { - super(diagram, "(?i)^rotate$"); + public CommandRotate() { + super("(?i)^rotate$"); } @Override - protected CommandExecutionResult executeArg(List arg) { + protected CommandExecutionResult executeArg(UmlDiagram diagram, List arg) { - getSystem().setRotation(true); + diagram.setRotation(true); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/command/CommandScale.java b/src/net/sourceforge/plantuml/command/CommandScale.java index b48762fd6..1cb91a5f4 100644 --- a/src/net/sourceforge/plantuml/command/CommandScale.java +++ b/src/net/sourceforge/plantuml/command/CommandScale.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -40,17 +40,17 @@ import net.sourceforge.plantuml.UmlDiagram; public class CommandScale extends SingleLineCommand { - public CommandScale(UmlDiagram diagram) { - super(diagram, "(?i)^scale\\s+([0-9.]+)(?:\\s*/\\s*([0-9.]+))?$"); + public CommandScale() { + super("(?i)^scale\\s+([0-9.]+)(?:\\s*/\\s*([0-9.]+))?$"); } @Override - protected CommandExecutionResult executeArg(List arg) { + protected CommandExecutionResult executeArg(UmlDiagram diagram, List arg) { double scale = Double.parseDouble(arg.get(0)); if (arg.get(1) != null) { scale /= Double.parseDouble(arg.get(1)); } - getSystem().setScale(new ScaleSimple(scale)); + diagram.setScale(new ScaleSimple(scale)); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/command/CommandScaleWidthAndHeight.java b/src/net/sourceforge/plantuml/command/CommandScaleWidthAndHeight.java index ab5a030ad..4f2f02d44 100644 --- a/src/net/sourceforge/plantuml/command/CommandScaleWidthAndHeight.java +++ b/src/net/sourceforge/plantuml/command/CommandScaleWidthAndHeight.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -40,15 +40,15 @@ import net.sourceforge.plantuml.UmlDiagram; public class CommandScaleWidthAndHeight extends SingleLineCommand { - public CommandScaleWidthAndHeight(UmlDiagram diagram) { - super(diagram, "(?i)^scale\\s+([0-9.]+)\\s*[*x]\\s*([0-9.]+)$"); + public CommandScaleWidthAndHeight() { + super("(?i)^scale\\s+([0-9.]+)\\s*[*x]\\s*([0-9.]+)$"); } @Override - protected CommandExecutionResult executeArg(List arg) { + protected CommandExecutionResult executeArg(UmlDiagram diagram, List arg) { final double width = Double.parseDouble(arg.get(0)); final double height = Double.parseDouble(arg.get(1)); - getSystem().setScale(new ScaleWidthAndHeight(width, height)); + diagram.setScale(new ScaleWidthAndHeight(width, height)); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/command/CommandScaleWidthOrHeight.java b/src/net/sourceforge/plantuml/command/CommandScaleWidthOrHeight.java index bda456820..fa59d5375 100644 --- a/src/net/sourceforge/plantuml/command/CommandScaleWidthOrHeight.java +++ b/src/net/sourceforge/plantuml/command/CommandScaleWidthOrHeight.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -41,18 +41,18 @@ import net.sourceforge.plantuml.UmlDiagram; public class CommandScaleWidthOrHeight extends SingleLineCommand { - public CommandScaleWidthOrHeight(UmlDiagram diagram) { - super(diagram, "(?i)^scale\\s+([0-9.]+)\\s+(width|height)$"); + public CommandScaleWidthOrHeight() { + super("(?i)^scale\\s+([0-9.]+)\\s+(width|height)$"); } @Override - protected CommandExecutionResult executeArg(List arg) { + protected CommandExecutionResult executeArg(UmlDiagram diagram, List arg) { final double size = Double.parseDouble(arg.get(0)); final boolean width = "width".equalsIgnoreCase(arg.get(1)); if (width) { - getSystem().setScale(new ScaleWidth(size)); + diagram.setScale(new ScaleWidth(size)); } else { - getSystem().setScale(new ScaleHeight(size)); + diagram.setScale(new ScaleHeight(size)); } return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/command/CommandSkinParam.java b/src/net/sourceforge/plantuml/command/CommandSkinParam.java index 0c6b3d1bc..4702a556d 100644 --- a/src/net/sourceforge/plantuml/command/CommandSkinParam.java +++ b/src/net/sourceforge/plantuml/command/CommandSkinParam.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6448 $ + * Revision $Revision: 10778 $ * */ package net.sourceforge.plantuml.command; @@ -39,14 +39,14 @@ import net.sourceforge.plantuml.UmlDiagram; public class CommandSkinParam extends SingleLineCommand { - public CommandSkinParam(UmlDiagram diagram) { - super(diagram, "(?i)^(skinparam|skinparamlocked)\\s+([\\w.]*(?:\\<\\<.*\\>\\>)?[\\w.]*)\\s+([^{}]*)$"); + public CommandSkinParam() { + super("(?i)^(skinparam|skinparamlocked)\\s+([\\w.]*(?:\\<\\<.*\\>\\>)?[\\w.]*)\\s+([^{}]*)$"); } @Override - protected CommandExecutionResult executeArg(List arg) { - boolean locked = arg.get(0).endsWith("locked"); - getSystem().setParam(arg.get(1), arg.get(2)); + protected CommandExecutionResult executeArg(UmlDiagram diagram, List arg) { + arg.get(0).endsWith("locked"); + diagram.setParam(arg.get(1), arg.get(2)); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/command/CommandSkinParamMultilines.java b/src/net/sourceforge/plantuml/command/CommandSkinParamMultilines.java index 6d2871539..fa57cbb68 100644 --- a/src/net/sourceforge/plantuml/command/CommandSkinParamMultilines.java +++ b/src/net/sourceforge/plantuml/command/CommandSkinParamMultilines.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -65,8 +65,8 @@ public class CommandSkinParamMultilines extends CommandMultilinesBracket\\>)?[\\w.]*)\\s+(?:(\\{)|(.*))$|^\\}?$"); - public CommandSkinParamMultilines(UmlDiagram diagram) { - super(diagram, "(?i)^skinparam\\s*(?:\\s+([\\w.]*(?:\\<\\<.*\\>\\>)?[\\w.]*))?\\s*\\{$"); + public CommandSkinParamMultilines() { + super("(?i)^skinparam\\s*(?:\\s+([\\w.]*(?:\\<\\<.*\\>\\>)?[\\w.]*))?\\s*\\{$"); } @Override @@ -75,7 +75,7 @@ public class CommandSkinParamMultilines extends CommandMultilinesBracket lines) { + public CommandExecutionResult execute(UmlDiagram diagram, List lines) { final Context context = new Context(); final Matcher mStart = getStartingPattern().matcher(lines.get(0).trim()); if (mStart.find() == false) { @@ -102,7 +102,7 @@ public class CommandSkinParamMultilines extends CommandMultilinesBracket { + + public CommandSpriteFile() { + super(getRegexConcat()); + } + + private static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("sprite\\s+\\$?"), // + new RegexLeaf("NAME", "([\\p{L}0-9_]+)\\s*"), // + new RegexLeaf("\\s+"), // + new RegexLeaf("FILE", "(.*)"), // + new RegexLeaf("$")); + } + + @Override + protected CommandExecutionResult executeArg(UmlDiagram system, RegexResult arg) { + final String src = arg.get("FILE", 0); + final BufferedImage im; + try { + final File f = FileSystem.getInstance().getFile(src); + if (f.exists() == false) { + return CommandExecutionResult.error("File does not exist: " + src); + } + im = ImageIO.read(f); + } catch (IOException e) { + Log.error("Error reading " + src + " " + e); + return CommandExecutionResult.error("Cannot read: " + src); + } + system.addSprite(arg.get("NAME", 0), new SpriteImage(im)); + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/command/CommandTitle.java b/src/net/sourceforge/plantuml/command/CommandTitle.java index 2da7a24fb..97c561e73 100644 --- a/src/net/sourceforge/plantuml/command/CommandTitle.java +++ b/src/net/sourceforge/plantuml/command/CommandTitle.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,25 +28,25 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4762 $ + * Revision $Revision: 10778 $ * */ package net.sourceforge.plantuml.command; import java.util.List; -import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.UmlDiagram; +import net.sourceforge.plantuml.cucadiagram.Display; public class CommandTitle extends SingleLineCommand { - public CommandTitle(UmlDiagram diagram) { - super(diagram, "(?i)^title(?:\\s*:\\s*|\\s+)(.*[\\p{L}0-9_.].*)$"); + public CommandTitle() { + super("(?i)^title(?:\\s*:\\s*|\\s+)(.*[\\p{L}0-9_.].*)$"); } @Override - protected CommandExecutionResult executeArg(List arg) { - getSystem().setTitle(StringUtils.getWithNewlines(arg.get(0))); + protected CommandExecutionResult executeArg(UmlDiagram diagram, List arg) { + diagram.setTitle(Display.getWithNewlines(arg.get(0))); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/command/FactorySpriteCommand.java b/src/net/sourceforge/plantuml/command/FactorySpriteCommand.java new file mode 100644 index 000000000..e20ca5eee --- /dev/null +++ b/src/net/sourceforge/plantuml/command/FactorySpriteCommand.java @@ -0,0 +1,138 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7558 $ + * + */ +package net.sourceforge.plantuml.command; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; + +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.UmlDiagram; +import net.sourceforge.plantuml.command.note.SingleMultiFactoryCommand; +import net.sourceforge.plantuml.command.regex.RegexConcat; +import net.sourceforge.plantuml.command.regex.RegexLeaf; +import net.sourceforge.plantuml.command.regex.RegexResult; +import net.sourceforge.plantuml.ugraphic.Sprite; +import net.sourceforge.plantuml.ugraphic.SpriteGrayLevel; + +public final class FactorySpriteCommand implements SingleMultiFactoryCommand { + + private RegexConcat getRegexConcatMultiLine() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("sprite\\s+\\$?"), // + new RegexLeaf("NAME", "([\\p{L}0-9_]+)\\s*"), // + new RegexLeaf("DIM", "(?:\\[(\\d+)x(\\d+)/(\\d+)(z)?\\])?"), // + new RegexLeaf("\\s*\\{"), // + new RegexLeaf("$")); + } + + private RegexConcat getRegexConcatSingleLine() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("sprite\\s+\\$?"), // + new RegexLeaf("NAME", "([\\p{L}0-9_]+)\\s*"), // + new RegexLeaf("DIM", "(?:\\[(\\d+)x(\\d+)/(\\d+)(z)\\])?"), // + new RegexLeaf("\\s+"), // + new RegexLeaf("DATA", "([-_A-Za-z0-9]+)"), // + new RegexLeaf("$")); + } + + public Command createSingleLine() { + return new SingleLineCommand2(getRegexConcatSingleLine()) { + + @Override + protected CommandExecutionResult executeArg(final UmlDiagram system, RegexResult arg) { + return executeInternal(system, arg, Arrays.asList(arg.get("DATA", 0))); + } + + }; + } + + public Command createMultiLine() { + return new CommandMultilines2(getRegexConcatMultiLine(), MultilinesStrategy.REMOVE_STARTING_QUOTE) { + + @Override + public String getPatternEnd() { + return "(?i)^end ?sprite|\\}$"; + } + + public CommandExecutionResult executeNow(final UmlDiagram system, List lines) { + StringUtils.trim(lines, true); + final RegexResult line0 = getStartingPattern().matcher(lines.get(0).trim()); + + final List strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1)); + if (strings.size() == 0) { + return CommandExecutionResult.error("No sprite defined."); + } + return executeInternal(system, line0, strings); + } + + }; + } + + private CommandExecutionResult executeInternal(UmlDiagram system, RegexResult line0, + final List strings) { + try { + final Sprite sprite; + if (line0.get("DIM", 0) == null) { + sprite = SpriteGrayLevel.GRAY_16.buildSprite(-1, -1, strings); + } else { + final int width = Integer.parseInt(line0.get("DIM", 0)); + final int height = Integer.parseInt(line0.get("DIM", 1)); + final int nbColor = Integer.parseInt(line0.get("DIM", 2)); + if (nbColor != 4 && nbColor != 8 && nbColor != 16) { + return CommandExecutionResult.error("Only 4, 8 or 16 graylevel are allowed."); + } + final SpriteGrayLevel level = SpriteGrayLevel.get(nbColor); + if (line0.get("DIM", 3) == null) { + sprite = level.buildSprite(width, height, strings); + } else { + sprite = level.buildSpriteZ(width, height, concat(strings)); + } + } + system.addSprite(line0.get("NAME", 0), sprite); + return CommandExecutionResult.ok(); + } catch (IOException e) { + return CommandExecutionResult.error("Cannot decode sprite."); + } + } + + private String concat(final List strings) { + final StringBuilder sb = new StringBuilder(); + for (String s : strings) { + sb.append(s.trim()); + } + return sb.toString(); + } + +} diff --git a/src/net/sourceforge/plantuml/command/MultilinesStrategy.java b/src/net/sourceforge/plantuml/command/MultilinesStrategy.java new file mode 100644 index 000000000..c3ddecef6 --- /dev/null +++ b/src/net/sourceforge/plantuml/command/MultilinesStrategy.java @@ -0,0 +1,61 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 5041 $ + * + */ +package net.sourceforge.plantuml.command; + +import java.util.Iterator; +import java.util.List; + +public enum MultilinesStrategy { + REMOVE_STARTING_QUOTE, KEEP_STARTING_QUOTE; + + public List filter(List lines) { + if (this == REMOVE_STARTING_QUOTE) { + filterQuote(lines); + } + return lines; + } + + private void filterQuote(List lines) { + for (final Iterator it = lines.iterator(); it.hasNext();) { + final String s = it.next(); + if (hasStartingQuote(s)) { + it.remove(); + } + } + } + + private boolean hasStartingQuote(String s) { + return s.trim().startsWith("\'"); + } +} diff --git a/src/net/sourceforge/plantuml/command/PSystemAbstractFactory.java b/src/net/sourceforge/plantuml/command/PSystemAbstractFactory.java new file mode 100644 index 000000000..5868aa1ca --- /dev/null +++ b/src/net/sourceforge/plantuml/command/PSystemAbstractFactory.java @@ -0,0 +1,69 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 10006 $ + * + */ +package net.sourceforge.plantuml.command; + +import net.sourceforge.plantuml.AbstractPSystem; +import net.sourceforge.plantuml.ErrorUml; +import net.sourceforge.plantuml.ErrorUmlType; +import net.sourceforge.plantuml.PSystemError; +import net.sourceforge.plantuml.api.PSystemFactory; +import net.sourceforge.plantuml.core.DiagramType; +import net.sourceforge.plantuml.core.UmlSource; + +public abstract class PSystemAbstractFactory implements PSystemFactory { + + private final DiagramType type; + + protected PSystemAbstractFactory(DiagramType type) { + this.type = type; + } + + final protected AbstractPSystem buildEmptyError(UmlSource source) { + final PSystemError result = new PSystemError(source, new ErrorUml(ErrorUmlType.SYNTAX_ERROR, + "Empty description", 1)); + result.setSource(source); + return result; + } + + final protected PSystemError buildEmptyError(UmlSource source, String err) { + final PSystemError result = new PSystemError(source, new ErrorUml(ErrorUmlType.EXECUTION_ERROR, err, 1)); + result.setSource(source); + return result; + } + + final public DiagramType getDiagramType() { + return type; + } + +} diff --git a/src/net/sourceforge/plantuml/command/PSystemBasicFactory.java b/src/net/sourceforge/plantuml/command/PSystemBasicFactory.java new file mode 100644 index 000000000..6219e9473 --- /dev/null +++ b/src/net/sourceforge/plantuml/command/PSystemBasicFactory.java @@ -0,0 +1,93 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 3830 $ + * + */ +package net.sourceforge.plantuml.command; + +import net.sourceforge.plantuml.AbstractPSystem; +import net.sourceforge.plantuml.ErrorUml; +import net.sourceforge.plantuml.ErrorUmlType; +import net.sourceforge.plantuml.PSystemError; +import net.sourceforge.plantuml.StartUtils; +import net.sourceforge.plantuml.core.Diagram; +import net.sourceforge.plantuml.core.DiagramType; +import net.sourceforge.plantuml.core.UmlSource; +import net.sourceforge.plantuml.version.IteratorCounter; + +public abstract class PSystemBasicFactory

extends PSystemAbstractFactory { + + public PSystemBasicFactory(DiagramType diagramType) { + super(diagramType); + } + + public PSystemBasicFactory() { + this(DiagramType.UML); + } + + public abstract P executeLine(P system, String line); + + public P init(String startLine) { + return null; + } + + + final public Diagram createSystem(UmlSource source) { + final IteratorCounter it = source.iterator(); + final String startLine = it.next(); + P system = init(startLine); + while (it.hasNext()) { + final String s = it.next(); + if (StartUtils.isArobaseEndDiagram(s)) { + if (source.getTotalLineCount() == 2) { + assert false; + return buildEmptyError(source); + } + if (system != null) { + system.setSource(source); + } + return system; + } + system = executeLine(system, s); + if (system == null) { + return new PSystemError(source, new ErrorUml(ErrorUmlType.SYNTAX_ERROR, "Syntax Error?", + it.currentNum() - 1)); + } + } + if (system != null) { + system.setSource(source); + } + return system; + } + + + +} diff --git a/src/net/sourceforge/plantuml/command/PSystemSingleLineFactory.java b/src/net/sourceforge/plantuml/command/PSystemSingleLineFactory.java new file mode 100644 index 000000000..65c0aeeaa --- /dev/null +++ b/src/net/sourceforge/plantuml/command/PSystemSingleLineFactory.java @@ -0,0 +1,83 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 10298 $ + * + */ +package net.sourceforge.plantuml.command; + +import net.sourceforge.plantuml.AbstractPSystem; +import net.sourceforge.plantuml.ErrorUml; +import net.sourceforge.plantuml.ErrorUmlType; +import net.sourceforge.plantuml.PSystemError; +import net.sourceforge.plantuml.StartUtils; +import net.sourceforge.plantuml.core.Diagram; +import net.sourceforge.plantuml.core.DiagramType; +import net.sourceforge.plantuml.core.UmlSource; +import net.sourceforge.plantuml.version.IteratorCounter; + +public abstract class PSystemSingleLineFactory extends PSystemAbstractFactory { + + protected abstract AbstractPSystem executeLine(String line); + + protected PSystemSingleLineFactory() { + super(DiagramType.UML); + } + + final public Diagram createSystem(UmlSource source) { + + if (source.isEmpty()) { + return buildEmptyError(source); + } + + final IteratorCounter it = source.iterator(); + final String startLine = it.next(); + if (StartUtils.isArobaseStartDiagram(startLine) == false) { + throw new UnsupportedOperationException(); + } + + if (it.hasNext() == false) { + return buildEmptyError(source); + } + final String s = it.next(); + if (StartUtils.isArobaseEndDiagram(s)) { + return buildEmptyError(source); + } + final AbstractPSystem sys = executeLine(s); + if (sys == null) { + return new PSystemError(source, new ErrorUml(ErrorUmlType.SYNTAX_ERROR, "Syntax Error?", + it.currentNum() - 1)); + } + sys.setSource(source); + return sys; + + } + +} diff --git a/src/net/sourceforge/plantuml/command/Position.java b/src/net/sourceforge/plantuml/command/Position.java index e6848fa56..3b468b38e 100644 --- a/src/net/sourceforge/plantuml/command/Position.java +++ b/src/net/sourceforge/plantuml/command/Position.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3828 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.command; diff --git a/src/net/sourceforge/plantuml/command/ProtectedCommand.java b/src/net/sourceforge/plantuml/command/ProtectedCommand.java index e0d3f018a..fe46c8195 100644 --- a/src/net/sourceforge/plantuml/command/ProtectedCommand.java +++ b/src/net/sourceforge/plantuml/command/ProtectedCommand.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -38,39 +38,39 @@ import java.io.PrintWriter; import java.util.List; import net.sourceforge.plantuml.Log; +import net.sourceforge.plantuml.core.Diagram; +import net.sourceforge.plantuml.version.Version; -public class ProtectedCommand implements Command { +public class ProtectedCommand implements Command { - private final Command cmd; + private final Command cmd; - public ProtectedCommand(Command cmd) { + public ProtectedCommand(Command cmd) { this.cmd = cmd; } - public CommandExecutionResult execute(List lines) { + public CommandExecutionResult execute(S system, List lines) { try { - return cmd.execute(lines); + final CommandExecutionResult result = cmd.execute(system, lines); +// if (result.isOk()) { +// // TRACECOMMAND +// System.err.println("CMD = " + cmd.getClass()); +// } + return result; } catch (Throwable t) { t.printStackTrace(); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final PrintWriter pw = new PrintWriter(baos); t.printStackTrace(pw); Log.error("Error " + t); - String msg = "You should send a mail to plantuml@gmail.com with this log"; + String msg = "You should send a mail to plantuml@gmail.com with this log (V" + Version.versionString() + + ")"; Log.error(msg); msg += " " + new String(baos.toByteArray()); return CommandExecutionResult.error(msg); } } - public String getHelpMessageForDeprecated(List lines) { - return cmd.getHelpMessageForDeprecated(lines); - } - - public boolean isDeprecated(List lines) { - return cmd.isDeprecated(lines); - } - public CommandControl isValid(List lines) { return cmd.isValid(lines); } diff --git a/src/net/sourceforge/plantuml/command/SingleLineCommand.java b/src/net/sourceforge/plantuml/command/SingleLineCommand.java index 23ec4f09a..87f027070 100644 --- a/src/net/sourceforge/plantuml/command/SingleLineCommand.java +++ b/src/net/sourceforge/plantuml/command/SingleLineCommand.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6280 $ + * Revision $Revision: 10779 $ * */ package net.sourceforge.plantuml.command; @@ -37,18 +37,14 @@ import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import net.sourceforge.plantuml.PSystem; import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.core.Diagram; -public abstract class SingleLineCommand implements Command { +public abstract class SingleLineCommand implements Command { - private final S system; private final Pattern pattern; - public SingleLineCommand(S system, String pattern) { - if (system == null) { - throw new IllegalArgumentException(); - } + public SingleLineCommand(String pattern) { if (pattern == null) { throw new IllegalArgumentException(); } @@ -56,16 +52,11 @@ public abstract class SingleLineCommand implements Command { throw new IllegalArgumentException("Bad pattern " + pattern); } - this.system = system; this.pattern = Pattern.compile(pattern); } - - public String[] getDescription() { - return new String[]{pattern.pattern()}; - } - final protected S getSystem() { - return system; + public String[] getDescription() { + return new String[] { pattern.pattern() }; } final public CommandControl isValid(List lines) { @@ -91,44 +82,29 @@ public abstract class SingleLineCommand implements Command { protected void actionIfCommandValid() { } - public final CommandExecutionResult execute(List lines) { + public final CommandExecutionResult execute(S system, List lines) { if (lines.size() != 1) { throw new IllegalArgumentException(); } final String line = lines.get(0).trim(); if (isForbidden(line)) { - return CommandExecutionResult.error("Forbidden line "+line); + return CommandExecutionResult.error("Forbidden line " + line); } final List arg = getSplit(line); if (arg == null) { - return CommandExecutionResult.error("Cannot parse line "+line); + return CommandExecutionResult.error("Cannot parse line " + line); } - return executeArg(arg); + return executeArg(system, arg); } protected boolean isForbidden(String line) { return false; } - protected abstract CommandExecutionResult executeArg(List arg); + protected abstract CommandExecutionResult executeArg(S system, List arg); final public List getSplit(String line) { return StringUtils.getSplit(pattern, line); } - final public boolean isDeprecated(List lines) { - if (lines.size() != 1) { - return false; - } - return isDeprecated(lines.get(0)); - } - - public String getHelpMessageForDeprecated(List lines) { - return null; - } - - protected boolean isDeprecated(String line) { - return false; - } - } diff --git a/src/net/sourceforge/plantuml/command/SingleLineCommand2.java b/src/net/sourceforge/plantuml/command/SingleLineCommand2.java index 2864f3ce4..be932f9a6 100644 --- a/src/net/sourceforge/plantuml/command/SingleLineCommand2.java +++ b/src/net/sourceforge/plantuml/command/SingleLineCommand2.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -34,21 +34,16 @@ package net.sourceforge.plantuml.command; import java.util.List; -import java.util.Map; -import net.sourceforge.plantuml.PSystem; import net.sourceforge.plantuml.command.regex.RegexConcat; -import net.sourceforge.plantuml.command.regex.RegexPartialMatch; +import net.sourceforge.plantuml.command.regex.RegexResult; +import net.sourceforge.plantuml.core.Diagram; -public abstract class SingleLineCommand2 implements Command { +public abstract class SingleLineCommand2 implements Command { - private final S system; private final RegexConcat pattern; - public SingleLineCommand2(S system, RegexConcat pattern) { - if (system == null) { - throw new IllegalArgumentException(); - } + public SingleLineCommand2(RegexConcat pattern) { if (pattern == null) { throw new IllegalArgumentException(); } @@ -56,14 +51,9 @@ public abstract class SingleLineCommand2 implements Command { throw new IllegalArgumentException("Bad pattern " + pattern.getPattern()); } - this.system = system; this.pattern = pattern; } - final protected S getSystem() { - return system; - } - public String[] getDescription() { return new String[] { pattern.getPattern() }; } @@ -90,7 +80,7 @@ public abstract class SingleLineCommand2 implements Command { protected void actionIfCommandValid() { } - public final CommandExecutionResult execute(List lines) { + public final CommandExecutionResult execute(S system, List lines) { if (lines.size() != 1) { throw new IllegalArgumentException(); } @@ -99,32 +89,19 @@ public abstract class SingleLineCommand2 implements Command { return CommandExecutionResult.error("Forbidden line " + line); } - final Map arg = pattern.matcher(line); + final RegexResult arg = pattern.matcher(line); if (arg == null) { return CommandExecutionResult.error("Cannot parse line " + line); } - return executeArg(arg); + // System.err.println("lines="+lines); + // System.err.println("pattern="+pattern.getPattern()); + return executeArg(system, arg); } protected boolean isForbidden(String line) { return false; } - protected abstract CommandExecutionResult executeArg(Map arg); - - final public boolean isDeprecated(List lines) { - if (lines.size() != 1) { - return false; - } - return isDeprecated(lines.get(0)); - } - - public String getHelpMessageForDeprecated(List lines) { - return null; - } - - protected boolean isDeprecated(String line) { - return false; - } + protected abstract CommandExecutionResult executeArg(S system, RegexResult arg); } diff --git a/src/net/sourceforge/plantuml/command/UmlDiagramFactory.java b/src/net/sourceforge/plantuml/command/UmlDiagramFactory.java new file mode 100644 index 000000000..342913db7 --- /dev/null +++ b/src/net/sourceforge/plantuml/command/UmlDiagramFactory.java @@ -0,0 +1,248 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 10006 $ + * + */ +package net.sourceforge.plantuml.command; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import net.sourceforge.plantuml.AbstractPSystem; +import net.sourceforge.plantuml.ErrorUml; +import net.sourceforge.plantuml.ErrorUmlType; +import net.sourceforge.plantuml.OptionFlags; +import net.sourceforge.plantuml.PSystemError; +import net.sourceforge.plantuml.StartUtils; +import net.sourceforge.plantuml.classdiagram.command.CommandHideShow; +import net.sourceforge.plantuml.classdiagram.command.CommandHideShow3; +import net.sourceforge.plantuml.core.Diagram; +import net.sourceforge.plantuml.core.DiagramType; +import net.sourceforge.plantuml.core.UmlSource; +import net.sourceforge.plantuml.suggest.SuggestEngine; +import net.sourceforge.plantuml.suggest.SuggestEngineResult; +import net.sourceforge.plantuml.suggest.SuggestEngineStatus; +import net.sourceforge.plantuml.version.IteratorCounter; + +public abstract class UmlDiagramFactory extends PSystemAbstractFactory { + + private final List cmds; + + protected UmlDiagramFactory() { + this(DiagramType.UML); + } + + protected UmlDiagramFactory(DiagramType type) { + super(type); + cmds = createCommands(); + } + + final public Diagram createSystem(UmlSource source) { + final IteratorCounter it = source.iterator(); + final String startLine = it.next(); + if (StartUtils.isArobaseStartDiagram(startLine) == false) { + throw new UnsupportedOperationException(); + } + + if (source.isEmpty()) { + return buildEmptyError(source); + } + AbstractPSystem sys = createEmptyDiagram(); + + while (it.hasNext()) { + final String line = it.next(); + if (StartUtils.isArobaseEndDiagram(line)) { + final String err = checkFinalError(sys); + if (err != null) { + return buildEmptyError(source, err); + } + if (source.getTotalLineCount() == 2) { + return buildEmptyError(source); + } + if (sys == null) { + return null; + } + sys.makeDiagramReady(); + if (sys.isOk() == false) { + return null; + } + sys.setSource(source); + return sys; + } + sys = executeOneLine(sys, source, it, line); + if (sys instanceof PSystemError) { + return sys; + } + } + sys.setSource(source); + return sys; + + } + + private AbstractPSystem executeOneLine(AbstractPSystem sys, UmlSource source, final IteratorCounter it, + final String line) { + final CommandControl commandControl = isValid(Arrays.asList(line)); + if (commandControl == CommandControl.NOT_OK) { + final ErrorUml err = new ErrorUml(ErrorUmlType.SYNTAX_ERROR, "Syntax Error?", it.currentNum() - 1); + if (OptionFlags.getInstance().isUseSuggestEngine()) { + final SuggestEngine engine = new SuggestEngine(source, this); + final SuggestEngineResult result = engine.tryToSuggest(sys); + if (result.getStatus() == SuggestEngineStatus.ONE_SUGGESTION) { + err.setSuggest(result); + } + } + sys = new PSystemError(source, err); + } else if (commandControl == CommandControl.OK_PARTIAL) { + final boolean ok = manageMultiline(sys, line, it); + if (ok == false) { + sys = new PSystemError(source, new ErrorUml(ErrorUmlType.EXECUTION_ERROR, "Syntax Error?", + it.currentNum() - 1)); + + } + } else if (commandControl == CommandControl.OK) { + Command cmd = createCommand(Arrays.asList(line)); + final CommandExecutionResult result = sys.executeCommand(cmd, Arrays.asList(line)); + if (result.isOk() == false) { + sys = new PSystemError(source, new ErrorUml(ErrorUmlType.EXECUTION_ERROR, result.getError(), + it.currentNum() - 1)); + } + if (result.getNewDiagram() != null) { + sys = result.getNewDiagram(); + } + } else { + assert false; + } + return sys; + } + + private boolean manageMultiline(AbstractPSystem system, final String init, IteratorCounter it) { + final List lines = new ArrayList(); + lines.add(init); + while (it.hasNext()) { + final String s = it.next(); + if (StartUtils.isArobaseEndDiagram(s)) { + return false; + } + lines.add(s); + final CommandControl commandControl = isValid(lines); + if (commandControl == CommandControl.NOT_OK) { + // throw new IllegalStateException(); + return false; + } + if (commandControl == CommandControl.OK) { + final Command cmd = createCommand(lines); + final CommandExecutionResult result = system.executeCommand(cmd, lines); + return result.isOk(); + } + } + return false; + + } + + // ----------------------------------- + + public String checkFinalError(AbstractPSystem system) { + return null; + } + + final public CommandControl isValid(List lines) { + for (Command cmd : cmds) { + final CommandControl result = cmd.isValid(lines); + if (result == CommandControl.OK || result == CommandControl.OK_PARTIAL) { + return result; + } + } + return CommandControl.NOT_OK; + + } + + final public Command createCommand(List lines) { + for (Command cmd : cmds) { + final CommandControl result = cmd.isValid(lines); + if (result == CommandControl.OK) { + return cmd; + } else if (result == CommandControl.OK_PARTIAL) { + throw new IllegalArgumentException(); + } + } + throw new IllegalArgumentException(); + } + + protected abstract List createCommands(); + + public abstract AbstractPSystem createEmptyDiagram(); + + final protected void addCommonCommands(List cmds) { + cmds.add(new CommandNope()); + cmds.add(new CommandComment()); + cmds.add(new CommandMultilinesComment()); + cmds.add(new CommandPragma()); + cmds.add(new CommandTitle()); + cmds.add(new CommandMultilinesTitle()); + cmds.add(new CommandMultilinesLegend()); + + cmds.add(new CommandFooter()); + cmds.add(new CommandMultilinesFooter()); + + cmds.add(new CommandHeader()); + cmds.add(new CommandMultilinesHeader()); + + cmds.add(new CommandSkinParam()); + cmds.add(new CommandSkinParamMultilines()); + cmds.add(new CommandMinwidth()); + cmds.add(new CommandRotate()); + cmds.add(new CommandScale()); + cmds.add(new CommandScaleWidthAndHeight()); + cmds.add(new CommandScaleWidthOrHeight()); + cmds.add(new CommandHideUnlinked()); + final FactorySpriteCommand factorySpriteCommand = new FactorySpriteCommand(); + cmds.add(factorySpriteCommand.createMultiLine()); + cmds.add(factorySpriteCommand.createSingleLine()); + cmds.add(new CommandSpriteFile()); + + cmds.add(new CommandHideShow3()); + cmds.add(new CommandHideShow()); + + + } + + final public List getDescription() { + final List result = new ArrayList(); + for (Command cmd : createCommands()) { + result.addAll(Arrays.asList(cmd.getDescription())); + } + return Collections.unmodifiableList(result); + + } + +} diff --git a/src/net/sourceforge/plantuml/command/note/FactoryNoteActivityCommand.java b/src/net/sourceforge/plantuml/command/note/FactoryNoteActivityCommand.java new file mode 100644 index 000000000..e65b1bc6b --- /dev/null +++ b/src/net/sourceforge/plantuml/command/note/FactoryNoteActivityCommand.java @@ -0,0 +1,156 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7558 $ + * + */ +package net.sourceforge.plantuml.command.note; + +import java.util.List; + +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.UniqueSequence; +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.UrlBuilder; +import net.sourceforge.plantuml.UrlBuilder.ModeUrl; +import net.sourceforge.plantuml.activitydiagram.ActivityDiagram; +import net.sourceforge.plantuml.command.Command; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.CommandMultilines2; +import net.sourceforge.plantuml.command.MultilinesStrategy; +import net.sourceforge.plantuml.command.Position; +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.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.LeafType; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.cucadiagram.LinkDecor; +import net.sourceforge.plantuml.cucadiagram.LinkType; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; + +public final class FactoryNoteActivityCommand implements SingleMultiFactoryCommand { + + private RegexConcat getRegexConcatMultiLine() { + return new RegexConcat(new RegexLeaf("^note\\s+"), // + new RegexLeaf("POSITION", "(right|left|top|bottom)\\s*"), // + new RegexLeaf("COLOR", "(#\\w+[-\\\\|/]?\\w+)?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("$")); + } + + private RegexConcat getRegexConcatSingleLine() { + return new RegexConcat(new RegexLeaf("^note\\s+"), // + new RegexLeaf("POSITION", "(right|left|top|bottom)\\s*"), // + new RegexLeaf("COLOR", "(#\\w+[-\\\\|/]?\\w+)?"), // + new RegexLeaf("\\s*:\\s*"), // + new RegexLeaf("NOTE", "(.*)"), // + new RegexLeaf("$")); + } + + public Command createMultiLine() { + return new CommandMultilines2(getRegexConcatMultiLine(), MultilinesStrategy.KEEP_STARTING_QUOTE) { + + @Override + public String getPatternEnd() { + return "(?i)^end ?note$"; + } + + public final CommandExecutionResult executeNow(final ActivityDiagram system, List lines) { + // StringUtils.trim(lines, true); + final RegexResult arg = getStartingPattern().matcher(lines.get(0).trim()); + Display strings = new Display(StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1))); + + Url url = null; + if (strings.size() > 0) { + final UrlBuilder urlBuilder = new UrlBuilder(system.getSkinParam().getValue("topurl"), ModeUrl.STRICT); + url = urlBuilder.getUrl(strings.get(0).toString()); + } + if (url != null) { + strings = strings.subList(1, strings.size()); + } + + // final String s = StringUtils.getMergedLines(strings); + + final IEntity note = system.createLeaf(UniqueSequence.getCode("GMN"), strings, LeafType.NOTE); + if (url != null) { + note.addUrl(url); + } + return executeInternal(system, arg, note); + } + }; + } + + public Command createSingleLine() { + return new SingleLineCommand2(getRegexConcatSingleLine()) { + + @Override + protected CommandExecutionResult executeArg(final ActivityDiagram system, RegexResult arg) { + final IEntity note = system.createNote(UniqueSequence.getCode("GN"), + Display.getWithNewlines(arg.get("NOTE", 0))); + return executeInternal(system, arg, note); + } + }; + } + + private CommandExecutionResult executeInternal(ActivityDiagram system, RegexResult arg, IEntity note) { + + note.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(arg.get("COLOR", 0))); + + IEntity activity = system.getLastEntityConsulted(); + if (activity == null) { + activity = system.getStart(); + } + + final Link link; + + final Position position = Position.valueOf(arg.get("POSITION", 0).toUpperCase()).withRankdir( + system.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(); + } + system.addLink(link); + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/command/note/FactoryNoteCommand.java b/src/net/sourceforge/plantuml/command/note/FactoryNoteCommand.java new file mode 100644 index 000000000..35b4adb77 --- /dev/null +++ b/src/net/sourceforge/plantuml/command/note/FactoryNoteCommand.java @@ -0,0 +1,115 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7558 $ + * + */ +package net.sourceforge.plantuml.command.note; + +import java.util.List; + +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram; +import net.sourceforge.plantuml.command.Command; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.CommandMultilines2; +import net.sourceforge.plantuml.command.MultilinesStrategy; +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.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.LeafType; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; + +public final class FactoryNoteCommand implements SingleMultiFactoryCommand { + + private RegexConcat getRegexConcatMultiLine() { + return new RegexConcat(new RegexLeaf("^(note)\\s+"), // + new RegexLeaf("CODE", "as\\s+([\\p{L}0-9_.]+)"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("COLOR", "(#\\w+[-\\\\|/]?\\w+)?"), // + new RegexLeaf("$") // + ); + } + + private RegexConcat getRegexConcatSingleLine() { + return new RegexConcat(new RegexLeaf("^note\\s+"), // + new RegexLeaf("DISPLAY", "\"([^\"]+)\"\\s+as\\s+"), // + new RegexLeaf("CODE", "([\\p{L}0-9_.]+)\\s*"), // + new RegexLeaf("COLOR", "(#\\w+[-\\\\|/]?\\w+)?"), // + new RegexLeaf("$") // + ); + + } + + public Command createSingleLine() { + return new SingleLineCommand2(getRegexConcatSingleLine()) { + + @Override + protected CommandExecutionResult executeArg(final AbstractEntityDiagram system, RegexResult arg) { + final String display = arg.get("DISPLAY", 0); + return executeInternal(system, arg, StringUtils.getWithNewlines2(display)); + } + + }; + } + + public Command createMultiLine() { + return new CommandMultilines2(getRegexConcatMultiLine(), MultilinesStrategy.KEEP_STARTING_QUOTE) { + + @Override + public String getPatternEnd() { + return "(?i)^end ?note$"; + } + + public CommandExecutionResult executeNow(final AbstractEntityDiagram system, List lines) { + //StringUtils.trim(lines, false); + final RegexResult line0 = getStartingPattern().matcher(lines.get(0).trim()); + + final List strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1)); + + return executeInternal(system, line0, strings); + } + }; + } + + private CommandExecutionResult executeInternal(AbstractEntityDiagram system, RegexResult arg, + final List display) { + final Code code = Code.of(arg.get("CODE", 0)); + final IEntity entity = system.createLeaf(code, new Display(display), LeafType.NOTE); + assert entity != null; + entity.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(arg.get("COLOR", 0))); + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/command/note/FactoryNoteOnEntityCommand.java b/src/net/sourceforge/plantuml/command/note/FactoryNoteOnEntityCommand.java new file mode 100644 index 000000000..9b3d7f234 --- /dev/null +++ b/src/net/sourceforge/plantuml/command/note/FactoryNoteOnEntityCommand.java @@ -0,0 +1,180 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7558 $ + * + */ +package net.sourceforge.plantuml.command.note; + +import java.util.List; + +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.UniqueSequence; +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.UrlBuilder; +import net.sourceforge.plantuml.UrlBuilder.ModeUrl; +import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram; +import net.sourceforge.plantuml.command.Command; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.CommandMultilines2; +import net.sourceforge.plantuml.command.MultilinesStrategy; +import net.sourceforge.plantuml.command.Position; +import net.sourceforge.plantuml.command.SingleLineCommand2; +import net.sourceforge.plantuml.command.regex.IRegex; +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.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.LeafType; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.cucadiagram.LinkDecor; +import net.sourceforge.plantuml.cucadiagram.LinkType; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; + +public final class FactoryNoteOnEntityCommand implements SingleMultiFactoryCommand { + + private final IRegex partialPattern; + + public FactoryNoteOnEntityCommand(IRegex partialPattern) { + this.partialPattern = partialPattern; + } + + private RegexConcat getRegexConcatSingleLine(IRegex partialPattern) { + return new RegexConcat(new RegexLeaf("^note\\s+"), // + new RegexLeaf("POSITION", "(right|left|top|bottom)"), // + new RegexOr(// + new RegexConcat(new RegexLeaf("\\s+of\\s+"), partialPattern), // + new RegexLeaf("")), // + new RegexLeaf("\\s*"), // + new RegexLeaf("COLOR", "(#\\w+[-\\\\|/]?\\w+)?"), // + new RegexLeaf("\\s*:\\s*"), // + new RegexLeaf("NOTE", "(.*)"), // + new RegexLeaf("$") // + ); + } + + private RegexConcat getRegexConcatMultiLine(IRegex partialPattern) { + return new RegexConcat(new RegexLeaf("^note\\s+"), // + new RegexLeaf("POSITION", "(right|left|top|bottom)"), // + new RegexOr(// + new RegexConcat(new RegexLeaf("\\s+of\\s+"), partialPattern), // + new RegexLeaf("")), // + new RegexLeaf("\\s*"), // + new RegexLeaf("COLOR", "(#\\w+[-\\\\|/]?\\w+)?"), // + new RegexLeaf("\\s*\\{?"), // + new RegexLeaf("$") // + ); + } + + public Command createSingleLine() { + return new SingleLineCommand2(getRegexConcatSingleLine(partialPattern)) { + + @Override + protected CommandExecutionResult executeArg(final AbstractEntityDiagram system, RegexResult arg) { + final String s = arg.get("NOTE", 0); + return executeInternal(arg, system, null, StringUtils.getWithNewlines2(s)); + } + }; + } + + public Command createMultiLine() { + return new CommandMultilines2(getRegexConcatMultiLine(partialPattern), MultilinesStrategy.KEEP_STARTING_QUOTE) { + + @Override + public String getPatternEnd() { + return "(?i)^(end ?note|\\})$"; + } + + public CommandExecutionResult executeNow(final AbstractEntityDiagram system, List lines) { + //StringUtils.trim(lines, false); + final RegexResult line0 = getStartingPattern().matcher(lines.get(0).trim()); + + List strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1)); + Url url = null; + if (strings.size() > 0) { + final UrlBuilder urlBuilder = new UrlBuilder(system.getSkinParam().getValue("topurl"), ModeUrl.STRICT); + url = urlBuilder.getUrl(strings.get(0)); + } + if (url != null) { + strings = strings.subList(1, strings.size()); + } + + return executeInternal(line0, system, url, strings); + } + }; + } + + private CommandExecutionResult executeInternal(RegexResult line0, AbstractEntityDiagram system, Url url, + List s) { + + final String pos = line0.get("POSITION", 0); + + final Code code = Code.of(line0.get("ENTITY", 0)); + final IEntity cl1; + if (code == null) { + cl1 = system.getLastEntity(); + if (cl1 == null) { + return CommandExecutionResult.error("Nothing to note to"); + } + } else { + cl1 = system.getOrCreateLeaf(code, null); + } + + final IEntity note = system.createLeaf(UniqueSequence.getCode("GMN"), new Display(s), LeafType.NOTE); + note.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(line0.get("COLOR", 0))); + if (url != null) { + note.addUrl(url); + } + + final Position position = Position.valueOf(pos.toUpperCase()).withRankdir(system.getRankdir()); + final Link link; + + final LinkType type = new LinkType(LinkDecor.NONE, LinkDecor.NONE).getDashed(); + if (position == Position.RIGHT) { + link = new Link(cl1, note, type, null, 1); + link.setHorizontalSolitary(true); + } else if (position == Position.LEFT) { + link = new Link(note, cl1, type, null, 1); + link.setHorizontalSolitary(true); + } else if (position == Position.BOTTOM) { + link = new Link(cl1, note, type, null, 2); + } else if (position == Position.TOP) { + link = new Link(note, cl1, type, null, 2); + } else { + throw new IllegalArgumentException(); + } + system.addLink(link); + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/command/note/FactoryNoteOnLinkCommand.java b/src/net/sourceforge/plantuml/command/note/FactoryNoteOnLinkCommand.java new file mode 100644 index 000000000..747d06a2e --- /dev/null +++ b/src/net/sourceforge/plantuml/command/note/FactoryNoteOnLinkCommand.java @@ -0,0 +1,130 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7558 $ + * + */ +package net.sourceforge.plantuml.command.note; + +import java.util.List; + +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.UrlBuilder; +import net.sourceforge.plantuml.UrlBuilder.ModeUrl; +import net.sourceforge.plantuml.command.Command; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.CommandMultilines2; +import net.sourceforge.plantuml.command.MultilinesStrategy; +import net.sourceforge.plantuml.command.Position; +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.RegexResult; +import net.sourceforge.plantuml.cucadiagram.CucaDiagram; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; + +public final class FactoryNoteOnLinkCommand implements SingleMultiFactoryCommand { + + private RegexConcat getRegexConcatSingleLine() { + return new RegexConcat(new RegexLeaf("^note\\s+"), // + new RegexLeaf("POSITION", "(right|left|top|bottom)?\\s*on\\s+link"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("COLOR", "(#\\w+[-\\\\|/]?\\w+)?"), // + new RegexLeaf("\\s*:\\s*"), // + new RegexLeaf("NOTE", "(.*)"), // + new RegexLeaf("$")); + } + + private RegexConcat getRegexConcatMultiLine() { + return new RegexConcat(new RegexLeaf("^note\\s+"), // + new RegexLeaf("POSITION", "(right|left|top|bottom)?\\s*on\\s+link"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("COLOR", "(#\\w+[-\\\\|/]?\\w+)?"), // + new RegexLeaf("$")); + } + + public Command createMultiLine() { + return new CommandMultilines2(getRegexConcatMultiLine(), MultilinesStrategy.KEEP_STARTING_QUOTE) { + + @Override + public String getPatternEnd() { + return "(?i)^end ?note$"; + } + + public CommandExecutionResult executeNow(final CucaDiagram system, List lines) { + final List strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1)); + if (strings.size() > 0) { + final List note = StringUtils.manageEmbededDiagrams2(strings); + final RegexResult arg = getStartingPattern().matcher(lines.get(0)); + return executeInternal(system, note, arg); + } + return CommandExecutionResult.error("No note defined"); + } + + }; + } + + public Command createSingleLine() { + return new SingleLineCommand2(getRegexConcatSingleLine()) { + + @Override + protected CommandExecutionResult executeArg(final CucaDiagram system, RegexResult arg) { + final List note = StringUtils.getWithNewlines2(arg.get("NOTE", 0)); + return executeInternal(system, note, arg); + } + }; + } + + private CommandExecutionResult executeInternal(CucaDiagram system, List note, + final RegexResult arg) { + final Link link = system.getLastLink(); + if (link == null) { + return CommandExecutionResult.error("No link defined"); + } + Position position = Position.BOTTOM; + if (arg.get("POSITION", 0) != null) { + position = Position.valueOf(arg.get("POSITION", 0).toUpperCase()); + } + Url url = null; + if (note.size() > 0) { + final UrlBuilder urlBuilder = new UrlBuilder(system.getSkinParam().getValue("topurl"), ModeUrl.STRICT); + url = urlBuilder.getUrl(note.get(0).toString()); + } + if (url != null) { + note = note.subList(1, note.size()); + } + link.addNote(new Display(note), position, HtmlColorUtils.getColorIfValid(arg.get("COLOR", 0))); + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/command/note/SingleMultiFactoryCommand.java b/src/net/sourceforge/plantuml/command/note/SingleMultiFactoryCommand.java new file mode 100644 index 000000000..e4ef52f39 --- /dev/null +++ b/src/net/sourceforge/plantuml/command/note/SingleMultiFactoryCommand.java @@ -0,0 +1,45 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7558 $ + * + */ +package net.sourceforge.plantuml.command.note; + +import net.sourceforge.plantuml.command.Command; +import net.sourceforge.plantuml.core.Diagram; + +public interface SingleMultiFactoryCommand { + + public Command createSingleLine(); + + public Command createMultiLine(); + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteCommand.java b/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteCommand.java new file mode 100644 index 000000000..5be8501dd --- /dev/null +++ b/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteCommand.java @@ -0,0 +1,127 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7558 $ + * + */ +package net.sourceforge.plantuml.command.note.sequence; + +import java.util.List; + +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.command.Command; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.CommandMultilines2; +import net.sourceforge.plantuml.command.MultilinesStrategy; +import net.sourceforge.plantuml.command.SingleLineCommand2; +import net.sourceforge.plantuml.command.note.SingleMultiFactoryCommand; +import net.sourceforge.plantuml.command.regex.RegexConcat; +import net.sourceforge.plantuml.command.regex.RegexLeaf; +import net.sourceforge.plantuml.command.regex.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.sequencediagram.Note; +import net.sourceforge.plantuml.sequencediagram.NotePosition; +import net.sourceforge.plantuml.sequencediagram.NoteStyle; +import net.sourceforge.plantuml.sequencediagram.Participant; +import net.sourceforge.plantuml.sequencediagram.SequenceDiagram; + +public final class FactorySequenceNoteCommand implements SingleMultiFactoryCommand { + + private RegexConcat getRegexConcatMultiLine() { + return new RegexConcat(// + new RegexLeaf("^"), // + new RegexLeaf("VMERGE", "(/)?\\s*"), // + new RegexLeaf("STYLE", "(note|hnote|rnote)\\s+"), // + new RegexLeaf("POSITION", "(right|left|over)\\s+"), // + new RegexLeaf("PARTICIPANT", "(?:of\\s+)?([\\p{L}0-9_.@]+|\"[^\"]+\")\\s*"), // + new RegexLeaf("COLOR", "(#\\w+[-\\\\|/]?\\w+)?"), // + new RegexLeaf("$")); + } + + private RegexConcat getRegexConcatSingleLine() { + return new RegexConcat(// + new RegexLeaf("^"), // + new RegexLeaf("VMERGE", "(/)?\\s*"), // + new RegexLeaf("STYLE", "(note|hnote|rnote)\\s+"), // + new RegexLeaf("POSITION", "(right|left|over)\\s+"), // + new RegexLeaf("PARTICIPANT", "(?:of\\s+)?([\\p{L}0-9_.@]+|\"[^\"]+\")\\s*"), // + new RegexLeaf("COLOR", "(#\\w+[-\\\\|/]?\\w+)?"), // + new RegexLeaf("\\s*:\\s*"), // + new RegexLeaf("NOTE", "(.*)"), // + new RegexLeaf("$")); + } + + public Command createMultiLine() { + return new CommandMultilines2(getRegexConcatMultiLine(), + MultilinesStrategy.KEEP_STARTING_QUOTE) { + + @Override + public String getPatternEnd() { + return "(?i)^end ?(note|hnote|rnote)$"; + } + + public CommandExecutionResult executeNow(final SequenceDiagram system, List lines) { + final RegexResult line0 = getStartingPattern().matcher(lines.get(0).trim()); + final List strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1)); + return executeInternal(system, line0, strings); + } + }; + } + + public Command createSingleLine() { + return new SingleLineCommand2(getRegexConcatSingleLine()) { + + @Override + protected CommandExecutionResult executeArg(final SequenceDiagram system, RegexResult arg) { + final List strings = StringUtils.getWithNewlines2(arg.get("NOTE", 0)); + return executeInternal(system, arg, strings); + } + + }; + } + + private CommandExecutionResult executeInternal(SequenceDiagram system, RegexResult arg, final List strings) { + final Participant p = system.getOrCreateParticipant(StringUtils + .eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("PARTICIPANT", 0))); + + final NotePosition position = NotePosition.valueOf(arg.get("POSITION", 0).toUpperCase()); + + if (strings.size() > 0) { + final boolean tryMerge = arg.get("VMERGE", 0) != null; + final Note note = new Note(p, position, new Display(strings)); + note.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(arg.get("COLOR", 0))); + note.setStyle(NoteStyle.getNoteStyle(arg.get("STYLE", 0))); + system.addNote(note, tryMerge); + } + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteOnArrowCommand.java b/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteOnArrowCommand.java new file mode 100644 index 000000000..40e3ba315 --- /dev/null +++ b/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteOnArrowCommand.java @@ -0,0 +1,127 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7558 $ + * + */ +package net.sourceforge.plantuml.command.note.sequence; + +import java.util.List; + +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.UrlBuilder; +import net.sourceforge.plantuml.UrlBuilder.ModeUrl; +import net.sourceforge.plantuml.command.Command; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.CommandMultilines2; +import net.sourceforge.plantuml.command.MultilinesStrategy; +import net.sourceforge.plantuml.command.SingleLineCommand2; +import net.sourceforge.plantuml.command.note.SingleMultiFactoryCommand; +import net.sourceforge.plantuml.command.regex.RegexConcat; +import net.sourceforge.plantuml.command.regex.RegexLeaf; +import net.sourceforge.plantuml.command.regex.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.sequencediagram.AbstractMessage; +import net.sourceforge.plantuml.sequencediagram.NotePosition; +import net.sourceforge.plantuml.sequencediagram.SequenceDiagram; + +public final class FactorySequenceNoteOnArrowCommand implements SingleMultiFactoryCommand { + + private RegexConcat getRegexConcatMultiLine() { + return new RegexConcat(new RegexLeaf("^note\\s+"), // + new RegexLeaf("POSITION", "(right|left)\\s*"), // + new RegexLeaf("COLOR", "(#\\w+[-\\\\|/]?\\w+)?"), // + new RegexLeaf("$")); + } + + private RegexConcat getRegexConcatSingleLine() { + return new RegexConcat(new RegexLeaf("^note\\s+"), // + new RegexLeaf("POSITION", "(right|left)\\s*"), // + new RegexLeaf("COLOR", "(#\\w+[-\\\\|/]?\\w+)?"), // + new RegexLeaf("\\s*:\\s*"), // + new RegexLeaf("NOTE", "(.*)"), // + new RegexLeaf("$")); + } + + public Command createSingleLine() { + return new SingleLineCommand2(getRegexConcatSingleLine()) { + + @Override + protected CommandExecutionResult executeArg(final SequenceDiagram system, RegexResult arg) { + final List strings = StringUtils.getWithNewlines2(arg.get("NOTE", 0)); + return executeInternal(system, arg, strings); + } + + }; + } + + public Command createMultiLine() { + return new CommandMultilines2(getRegexConcatMultiLine(), MultilinesStrategy.KEEP_STARTING_QUOTE) { + + @Override + public String getPatternEnd() { + return "(?i)^end ?note$"; + } + + public CommandExecutionResult executeNow(final SequenceDiagram system, List lines) { + final RegexResult line0 = getStartingPattern().matcher(lines.get(0).trim()); + final List in = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1)); + + return executeInternal(system, line0, in); + } + + }; + } + + private CommandExecutionResult executeInternal(SequenceDiagram system, final RegexResult line0, + final List in) { + final AbstractMessage m = system.getLastMessage(); + if (m != null) { + final NotePosition position = NotePosition.valueOf(line0.get("POSITION", 0).toUpperCase()); + List strings = StringUtils.manageEmbededDiagrams2(in); + final Url url; + if (strings.size() > 0) { + final UrlBuilder urlBuilder = new UrlBuilder(system.getSkinParam().getValue("topurl"), ModeUrl.STRICT); + url = urlBuilder.getUrl(strings.get(0).toString()); + } else { + url = null; + } + if (url != null) { + strings = strings.subList(1, strings.size()); + } + + m.setNote(new Display(strings), position, line0.get("COLOR", 0), url); + } + + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteOverSeveralCommand.java b/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteOverSeveralCommand.java new file mode 100644 index 000000000..8bc60e47d --- /dev/null +++ b/src/net/sourceforge/plantuml/command/note/sequence/FactorySequenceNoteOverSeveralCommand.java @@ -0,0 +1,130 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7558 $ + * + */ +package net.sourceforge.plantuml.command.note.sequence; + +import java.util.List; + +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.command.Command; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.CommandMultilines2; +import net.sourceforge.plantuml.command.MultilinesStrategy; +import net.sourceforge.plantuml.command.SingleLineCommand2; +import net.sourceforge.plantuml.command.note.SingleMultiFactoryCommand; +import net.sourceforge.plantuml.command.regex.RegexConcat; +import net.sourceforge.plantuml.command.regex.RegexLeaf; +import net.sourceforge.plantuml.command.regex.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.sequencediagram.Note; +import net.sourceforge.plantuml.sequencediagram.NoteStyle; +import net.sourceforge.plantuml.sequencediagram.Participant; +import net.sourceforge.plantuml.sequencediagram.SequenceDiagram; + +public final class FactorySequenceNoteOverSeveralCommand implements SingleMultiFactoryCommand { + + private RegexConcat getRegexConcatMultiLine() { + return new RegexConcat( // + new RegexLeaf("^"), // + new RegexLeaf("VMERGE", "(/)?\\s*"), // + new RegexLeaf("STYLE", "(note|hnote|rnote)\\s+over\\s+"), // + new RegexLeaf("P1", "([\\p{L}0-9_.@]+|\"[^\"]+\")\\s*\\,\\s*"), // + new RegexLeaf("P2", "([\\p{L}0-9_.@]+|\"[^\"]+\")\\s*"), // + new RegexLeaf("COLOR", "(#\\w+[-\\\\|/]?\\w+)?"), // + new RegexLeaf("$") // + ); + } + + private RegexConcat getRegexConcatSingleLine() { + return new RegexConcat( // + new RegexLeaf("^"), // + new RegexLeaf("VMERGE", "(/)?\\s*"), // + new RegexLeaf("STYLE", "(note|hnote|rnote)\\s+over\\s+"), // + new RegexLeaf("P1", "([\\p{L}0-9_.@]+|\"[^\"]+\")\\s*\\,\\s*"), // + new RegexLeaf("P2", "([\\p{L}0-9_.@]+|\"[^\"]+\")\\s*"), // + new RegexLeaf("COLOR", "(#\\w+[-\\\\|/]?\\w+)?"), // + new RegexLeaf("\\s*:\\s*"), // + new RegexLeaf("NOTE", "(.*)"), // + new RegexLeaf("$")); + } + + public Command createSingleLine() { + return new SingleLineCommand2(getRegexConcatSingleLine()) { + + @Override + protected CommandExecutionResult executeArg(final SequenceDiagram system, RegexResult arg) { + final List strings = StringUtils.getWithNewlines2(arg.get("NOTE", 0)); + + return executeInternal(system, arg, strings); + } + + }; + } + + public Command createMultiLine() { + return new CommandMultilines2(getRegexConcatMultiLine(), MultilinesStrategy.KEEP_STARTING_QUOTE) { + + @Override + public String getPatternEnd() { + return "(?i)^end ?(note|hnote|rnote)$"; + } + + public CommandExecutionResult executeNow(final SequenceDiagram system, List lines) { + final RegexResult line0 = getStartingPattern().matcher(lines.get(0).trim()); + final List strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1)); + + return executeInternal(system, line0, strings); + } + + }; + } + + private CommandExecutionResult executeInternal(SequenceDiagram system, final RegexResult line0, + final List strings) { + final Participant p1 = system.getOrCreateParticipant(StringUtils + .eventuallyRemoveStartingAndEndingDoubleQuote(line0.get("P1", 0))); + final Participant p2 = system.getOrCreateParticipant(StringUtils + .eventuallyRemoveStartingAndEndingDoubleQuote(line0.get("P2", 0))); + + if (strings.size() > 0) { + final boolean tryMerge = line0.get("VMERGE", 0) != null; + final Note note = new Note(p1, p2, new Display(strings)); + note.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(line0.get("COLOR", 0))); + note.setStyle(NoteStyle.getNoteStyle(line0.get("STYLE", 0))); + system.addNote(note, tryMerge); + } + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/command/regex/IRegex.java b/src/net/sourceforge/plantuml/command/regex/IRegex.java index 05f06eb5e..285f6326a 100644 --- a/src/net/sourceforge/plantuml/command/regex/IRegex.java +++ b/src/net/sourceforge/plantuml/command/regex/IRegex.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/command/regex/MatcherIterator.java b/src/net/sourceforge/plantuml/command/regex/MatcherIterator.java index aa4df25b0..7a983fdf9 100644 --- a/src/net/sourceforge/plantuml/command/regex/MatcherIterator.java +++ b/src/net/sourceforge/plantuml/command/regex/MatcherIterator.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/command/regex/RegexComposed.java b/src/net/sourceforge/plantuml/command/regex/RegexComposed.java index 6ac380884..23f15d18b 100644 --- a/src/net/sourceforge/plantuml/command/regex/RegexComposed.java +++ b/src/net/sourceforge/plantuml/command/regex/RegexComposed.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -34,7 +34,6 @@ package net.sourceforge.plantuml.command.regex; import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -50,9 +49,6 @@ public abstract class RegexComposed implements IRegex { public RegexComposed(IRegex... partial) { this.partials = Arrays.asList(partial); - if (partials.size() < 2) { - throw new IllegalArgumentException(); - } } public Map createPartialMatch(Iterator it) { @@ -75,14 +71,14 @@ public abstract class RegexComposed implements IRegex { return 0; } - public Map matcher(String s) { + public RegexResult matcher(String s) { final Matcher matcher = getFull().matcher(s); if (matcher.find() == false) { throw new IllegalArgumentException(getClass()+" "+s); } final Iterator it = new MatcherIterator(matcher); - return Collections.unmodifiableMap(createPartialMatch(it)); + return new RegexResult(createPartialMatch(it)); } final public boolean match(String s) { diff --git a/src/net/sourceforge/plantuml/command/regex/RegexConcat.java b/src/net/sourceforge/plantuml/command/regex/RegexConcat.java index cdd3f81a9..7b8635748 100644 --- a/src/net/sourceforge/plantuml/command/regex/RegexConcat.java +++ b/src/net/sourceforge/plantuml/command/regex/RegexConcat.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/command/regex/RegexLeaf.java b/src/net/sourceforge/plantuml/command/regex/RegexLeaf.java index a9105448b..e4c1eb119 100644 --- a/src/net/sourceforge/plantuml/command/regex/RegexLeaf.java +++ b/src/net/sourceforge/plantuml/command/regex/RegexLeaf.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/command/regex/RegexOptional.java b/src/net/sourceforge/plantuml/command/regex/RegexOptional.java new file mode 100644 index 000000000..fef8afb2c --- /dev/null +++ b/src/net/sourceforge/plantuml/command/regex/RegexOptional.java @@ -0,0 +1,55 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 4762 $ + * + */ +package net.sourceforge.plantuml.command.regex; + +import java.util.regex.Pattern; + +public class RegexOptional extends RegexComposed implements IRegex { + + private final Pattern full; + + public RegexOptional(IRegex partial) { + super(partial); + final StringBuilder sb = new StringBuilder("(?:"); + sb.append(partial.getPattern()); + sb.append(")?"); + this.full = Pattern.compile(sb.toString(), Pattern.CASE_INSENSITIVE); + } + + @Override + protected Pattern getFull() { + return full; + } + +} diff --git a/src/net/sourceforge/plantuml/command/regex/RegexOr.java b/src/net/sourceforge/plantuml/command/regex/RegexOr.java index b1a31176b..d3491886b 100644 --- a/src/net/sourceforge/plantuml/command/regex/RegexOr.java +++ b/src/net/sourceforge/plantuml/command/regex/RegexOr.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -48,10 +48,6 @@ public class RegexOr extends RegexComposed implements IRegex { } public RegexOr(String name, IRegex... partial) { - this(name, false, partial); - } - - public RegexOr(String name, boolean optionnal, IRegex... partial) { super(partial); this.name = name; final StringBuilder sb = new StringBuilder("("); @@ -64,9 +60,6 @@ public class RegexOr extends RegexComposed implements IRegex { } sb.setLength(sb.length() - 1); sb.append(')'); - if (optionnal) { - sb.append('?'); - } this.full = Pattern.compile(sb.toString()); } diff --git a/src/net/sourceforge/plantuml/command/regex/RegexPartialMatch.java b/src/net/sourceforge/plantuml/command/regex/RegexPartialMatch.java index 8f9e730f6..3a7e510c7 100644 --- a/src/net/sourceforge/plantuml/command/regex/RegexPartialMatch.java +++ b/src/net/sourceforge/plantuml/command/regex/RegexPartialMatch.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/command/regex/RegexResult.java b/src/net/sourceforge/plantuml/command/regex/RegexResult.java new file mode 100644 index 000000000..06196e1fc --- /dev/null +++ b/src/net/sourceforge/plantuml/command/regex/RegexResult.java @@ -0,0 +1,84 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 4762 $ + * + */ +package net.sourceforge.plantuml.command.regex; + +import java.util.Collections; +import java.util.Map; + +public class RegexResult { + + private final Map data; + + public RegexResult(Map data) { + this.data = Collections.unmodifiableMap(data); + } + + @Override + public String toString() { + return data.toString(); + } + + public RegexPartialMatch get(String key) { + return data.get(key); + } + + public String get(String key, int num) { + final RegexPartialMatch reg = data.get(key); + if (reg == null) { + return null; + } + return reg.get(num); + } + + public String getLazzy(String key, int num) { + for (Map.Entry ent : data.entrySet()) { + if (ent.getKey().startsWith(key) == false) { + continue; + } + final RegexPartialMatch match = ent.getValue(); + if (num >= match.size()) { + continue; + } + if (match.get(num) != null) { + return ent.getValue().get(num); + } + } + return null; + } + + public int size() { + return data.size(); + } + +} diff --git a/src/net/sourceforge/plantuml/componentdiagram/ComponentDiagram.java b/src/net/sourceforge/plantuml/componentdiagram/ComponentDiagram.java deleted file mode 100644 index c68162281..000000000 --- a/src/net/sourceforge/plantuml/componentdiagram/ComponentDiagram.java +++ /dev/null @@ -1,67 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 5019 $ - * - */ -package net.sourceforge.plantuml.componentdiagram; - -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.UmlDiagramType; -import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram; -import net.sourceforge.plantuml.cucadiagram.EntityType; -import net.sourceforge.plantuml.cucadiagram.IEntity; - -public class ComponentDiagram extends AbstractEntityDiagram { - - @Override - public IEntity getOrCreateClass(String code) { - if (code.startsWith("[") && code.endsWith("]")) { - return getOrCreateEntity(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(code), - EntityType.COMPONENT); - } - if (code.startsWith(":") && code.endsWith(":")) { - return getOrCreateEntity(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(code), EntityType.ACTOR); - } - if (code.startsWith("()")) { - code = code.substring(2).trim(); - code = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(code); - return getOrCreateEntity(code, EntityType.CIRCLE_INTERFACE); - } - code = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(code); - return getOrCreateEntity(code, EntityType.CIRCLE_INTERFACE); - } - - @Override - public UmlDiagramType getUmlDiagramType() { - return UmlDiagramType.COMPONENT; - } - -} diff --git a/src/net/sourceforge/plantuml/componentdiagram/ComponentDiagramFactory.java b/src/net/sourceforge/plantuml/componentdiagram/ComponentDiagramFactory.java deleted file mode 100644 index a38c60c8f..000000000 --- a/src/net/sourceforge/plantuml/componentdiagram/ComponentDiagramFactory.java +++ /dev/null @@ -1,84 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6396 $ - * - */ -package net.sourceforge.plantuml.componentdiagram; - -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; -import net.sourceforge.plantuml.componentdiagram.command.CommandCreateActorInComponent; -import net.sourceforge.plantuml.componentdiagram.command.CommandCreateCircleInterface; -import net.sourceforge.plantuml.componentdiagram.command.CommandCreateComponent; -import net.sourceforge.plantuml.componentdiagram.command.CommandLinkComponent2; -import net.sourceforge.plantuml.componentdiagram.command.CommandMultilinesComponentNoteEntity; -import net.sourceforge.plantuml.usecasediagram.command.CommandRankDirUsecase; - -public class ComponentDiagramFactory extends AbstractUmlSystemCommandFactory { - - private ComponentDiagram system; - - public ComponentDiagram getSystem() { - return system; - } - - @Override - protected void initCommands() { - system = new ComponentDiagram(); - - addCommand(new CommandRankDirUsecase(system)); - addCommonCommands(system); - - addCommand(new CommandPage(system)); - //addCommand(new CommandLinkComponent(system)); - addCommand(new CommandLinkComponent2(system)); - - addCommand(new CommandPackage(system)); - addCommand(new CommandEndPackage(system)); - addCommand(new CommandNoteEntity(system)); - - addCommand(new CommandCreateNote(system)); - addCommand(new CommandUrl(system)); - addCommand(new CommandCreateComponent(system)); - addCommand(new CommandCreateCircleInterface(system)); - addCommand(new CommandCreateActorInComponent(system)); - - addCommand(new CommandMultilinesComponentNoteEntity(system)); - addCommand(new CommandMultilinesStandaloneNote(system)); - - } -} diff --git a/src/net/sourceforge/plantuml/componentdiagram/command/CommandCreateActorInComponent.java b/src/net/sourceforge/plantuml/componentdiagram/command/CommandCreateActorInComponent.java deleted file mode 100644 index 37cfaa376..000000000 --- a/src/net/sourceforge/plantuml/componentdiagram/command/CommandCreateActorInComponent.java +++ /dev/null @@ -1,84 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - */ -package net.sourceforge.plantuml.componentdiagram.command; - -import java.util.List; - -import net.sourceforge.plantuml.FontParam; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.command.CommandExecutionResult; -import net.sourceforge.plantuml.command.SingleLineCommand; -import net.sourceforge.plantuml.componentdiagram.ComponentDiagram; -import net.sourceforge.plantuml.cucadiagram.Entity; -import net.sourceforge.plantuml.cucadiagram.EntityType; -import net.sourceforge.plantuml.cucadiagram.Stereotype; - -public class CommandCreateActorInComponent extends SingleLineCommand { - - public CommandCreateActorInComponent(ComponentDiagram diagram) { - super( - diagram, - "(?i)^(?:actor\\s+)?([\\p{L}0-9_.]+|:[^:]+:|\"[^\"]+\")\\s*(?:as\\s+:?([\\p{L}0-9_.]+):?)?(?:\\s*([\\<\\[]{2}.*[\\>\\]]{2}))?$"); - } - - @Override - protected boolean isForbidden(String line) { - if (line.matches("^[\\p{L}0-9_.]+$")) { - return true; - } - return false; - } - - @Override - protected CommandExecutionResult executeArg(List arg) { - final EntityType type = EntityType.ACTOR; - final String code; - final String display; - if (arg.get(1) == null) { - code = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(0)); - display = code; - } else { - display = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(0)); - code = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(1)); - } - final String stereotype = arg.get(2); - final Entity entity = (Entity) getSystem().getOrCreateEntity(code, type); - entity.setDisplay2(display); - - if (stereotype != null) { - entity.setStereotype(new Stereotype(stereotype, getSystem().getSkinParam().getCircledCharacterRadius(), - getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null))); - } - return CommandExecutionResult.ok(); - } - -} diff --git a/src/net/sourceforge/plantuml/componentdiagram/command/CommandCreateCircleInterface.java b/src/net/sourceforge/plantuml/componentdiagram/command/CommandCreateCircleInterface.java deleted file mode 100644 index 39d2d0561..000000000 --- a/src/net/sourceforge/plantuml/componentdiagram/command/CommandCreateCircleInterface.java +++ /dev/null @@ -1,86 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6923 $ - * - */ -package net.sourceforge.plantuml.componentdiagram.command; - -import java.util.List; - -import net.sourceforge.plantuml.FontParam; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.command.CommandExecutionResult; -import net.sourceforge.plantuml.command.SingleLineCommand; -import net.sourceforge.plantuml.componentdiagram.ComponentDiagram; -import net.sourceforge.plantuml.cucadiagram.Entity; -import net.sourceforge.plantuml.cucadiagram.EntityType; -import net.sourceforge.plantuml.cucadiagram.Stereotype; - -public class CommandCreateCircleInterface extends SingleLineCommand { - - public CommandCreateCircleInterface(ComponentDiagram diagram) { - super( - diagram, - "(?i)^(?:interface\\s+)?(?:\\(\\)\\s*)?([\\p{L}0-9_.]+|\"[^\"]+\")\\s*(?:as\\s+(?:\\(\\)\\s*)?([\\p{L}0-9_.]+))?(?:\\s*([\\<\\[]{2}.*[\\>\\]]{2}))?$"); - } - - @Override - protected boolean isForbidden(String line) { - if (line.matches("^[\\p{L}0-9_.]+$")) { - return true; - } - return false; - } - - @Override - protected CommandExecutionResult executeArg(List arg) { - final EntityType type = EntityType.CIRCLE_INTERFACE; - final String code; - final String display; - if (arg.get(1) == null) { - code = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(0)); - display = code; - } else { - display = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(0)); - code = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(1)); - } - final String stereotype = arg.get(2); - // final Entity entity = getSystem().createEntity(code, display, type); - final Entity entity = (Entity) getSystem().getOrCreateEntity(code, type); - entity.setDisplay2(display); - if (stereotype != null) { - entity.setStereotype(new Stereotype(stereotype, getSystem().getSkinParam().getCircledCharacterRadius(), - getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null))); - } - return CommandExecutionResult.ok(); - } - -} diff --git a/src/net/sourceforge/plantuml/componentdiagram/command/CommandCreateComponent.java b/src/net/sourceforge/plantuml/componentdiagram/command/CommandCreateComponent.java deleted file mode 100644 index f81671a35..000000000 --- a/src/net/sourceforge/plantuml/componentdiagram/command/CommandCreateComponent.java +++ /dev/null @@ -1,86 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6923 $ - * - */ -package net.sourceforge.plantuml.componentdiagram.command; - -import java.util.List; - -import net.sourceforge.plantuml.FontParam; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.command.CommandExecutionResult; -import net.sourceforge.plantuml.command.SingleLineCommand; -import net.sourceforge.plantuml.componentdiagram.ComponentDiagram; -import net.sourceforge.plantuml.cucadiagram.Entity; -import net.sourceforge.plantuml.cucadiagram.EntityType; -import net.sourceforge.plantuml.cucadiagram.Stereotype; - -public class CommandCreateComponent extends SingleLineCommand { - - public CommandCreateComponent(ComponentDiagram diagram) { - super( - diagram, - "(?i)^(?:component\\s+)?([\\p{L}0-9_.]+|\\[[^\\]*]+[^\\]]*\\]|\"[^\"]+\")\\s*(?:as\\s+\\[?([\\p{L}0-9_.]+)\\]?)?(?:\\s*([\\<\\[]{2}.*[\\>\\]]{2}))?$"); - } - - @Override - protected boolean isForbidden(String line) { - if (line.matches("^[\\p{L}0-9_.]+$")) { - return true; - } - return false; - } - - @Override - protected CommandExecutionResult executeArg(List arg) { - final EntityType type = EntityType.COMPONENT; - final String code; - final String display; - if (arg.get(1) == null) { - code = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(0)); - display = code; - } else { - display = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(0)); - code = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get(1)); - } - final String stereotype = arg.get(2); - // final Entity entity = getSystem().createEntity(code, display, type); - final Entity entity = (Entity) getSystem().getOrCreateEntity(code, type); - entity.setDisplay2(display); - if (stereotype != null) { - entity.setStereotype(new Stereotype(stereotype, getSystem().getSkinParam().getCircledCharacterRadius(), - getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null))); - } - return CommandExecutionResult.ok(); - } - -} diff --git a/src/net/sourceforge/plantuml/componentdiagram/command/CommandLinkComponent2.java b/src/net/sourceforge/plantuml/componentdiagram/command/CommandLinkComponent2.java deleted file mode 100644 index 86edb5198..000000000 --- a/src/net/sourceforge/plantuml/componentdiagram/command/CommandLinkComponent2.java +++ /dev/null @@ -1,187 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 5443 $ - * - */ -package net.sourceforge.plantuml.componentdiagram.command; - -import java.util.Map; - -import net.sourceforge.plantuml.Direction; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.command.CommandExecutionResult; -import net.sourceforge.plantuml.command.SingleLineCommand2; -import net.sourceforge.plantuml.command.regex.RegexConcat; -import net.sourceforge.plantuml.command.regex.RegexLeaf; -import net.sourceforge.plantuml.command.regex.RegexOr; -import net.sourceforge.plantuml.command.regex.RegexPartialMatch; -import net.sourceforge.plantuml.componentdiagram.ComponentDiagram; -import net.sourceforge.plantuml.cucadiagram.Group; -import net.sourceforge.plantuml.cucadiagram.IEntity; -import net.sourceforge.plantuml.cucadiagram.Link; -import net.sourceforge.plantuml.cucadiagram.LinkDecor; -import net.sourceforge.plantuml.cucadiagram.LinkType; -import net.sourceforge.plantuml.cucadiagram.Stereotype; - -public class CommandLinkComponent2 extends SingleLineCommand2 { - - public CommandLinkComponent2(ComponentDiagram diagram) { - super(diagram, getRegex()); - } - - static RegexConcat getRegex() { - return new RegexConcat(new RegexLeaf("^"), // - getRegexGroup("G1"),// - new RegexLeaf("\\s*"),// - new RegexOr( - // - new RegexLeaf("AR_TO_RIGHT", - "(([-=.]+)(?:(left|right|up|down|le?|ri?|up?|do?)(?=[-=.]))?([-=.]*)([\\]>^]|\\|[>\\]])?)"), - new RegexLeaf("AR_TO_LEFT", - "(([\\[<^]|[<\\[]\\|)?([-=.]*)(left|right|up|down|le?|ri?|up?|do?)?([-=.]+))")), - new RegexLeaf("\\s*"),// - getRegexGroup("G2"),// - new RegexLeaf("\\s*"),// - new RegexLeaf("END", "(?::\\s*([^\"]+))?$")); - } - - private static RegexLeaf getRegexGroup(String name) { - return new RegexLeaf(name, - "([\\p{L}0-9_.]+|:[^:]+:|\\[[^\\]*]+[^\\]]*\\]|\\(\\)\\s*[\\p{L}0-9_.]+|\\(\\)\\s*\"[^\"]+\")(?:\\s*(\\<\\<.*\\>\\>))?"); - } - - @Override - protected CommandExecutionResult executeArg(Map arg) { - final String g1 = arg.get("G1").get(0); - final String g2 = arg.get("G2").get(0); - - if (getSystem().isGroup(g1) && getSystem().isGroup(g2)) { - return executePackageLink(arg); - } - if (getSystem().isGroup(g1) || getSystem().isGroup(g2)) { - return CommandExecutionResult.error("Package can be only linked to other package"); - } - - final IEntity cl1 = getSystem().getOrCreateClass(g1); - final IEntity cl2 = getSystem().getOrCreateClass(g2); - - if (arg.get("G1").get(1) != null) { - cl1.setStereotype(new Stereotype(arg.get("G1").get(1))); - } - if (arg.get("G2").get(1) != null) { - cl2.setStereotype(new Stereotype(arg.get("G2").get(1))); - } - - final LinkType linkType; - String queue; - if (arg.get("AR_TO_RIGHT").get(0) != null) { - queue = arg.get("AR_TO_RIGHT").get(1) + arg.get("AR_TO_RIGHT").get(3); - linkType = getLinkTypeNormal(queue, arg.get("AR_TO_RIGHT").get(4)); - } else { - queue = arg.get("AR_TO_LEFT").get(2) + arg.get("AR_TO_LEFT").get(4); - linkType = getLinkTypeNormal(queue, arg.get("AR_TO_LEFT").get(1)).getInv(); - } - final Direction dir = getDirection(arg); - - if (dir == Direction.LEFT || dir == Direction.RIGHT) { - queue = "-"; - } - - Link link = new Link(cl1, cl2, linkType, arg.get("END").get(0), queue.length()); - - if (dir == Direction.LEFT || dir == Direction.UP) { - link = link.getInv(); - } - - getSystem().addLink(link); - return CommandExecutionResult.ok(); - } - - private Direction getDirection(Map arg) { - if (arg.get("AR_TO_RIGHT").get(2) != null) { - return StringUtils.getQueueDirection(arg.get("AR_TO_RIGHT").get(2)); - } - if (arg.get("AR_TO_LEFT").get(3) != null) { - return StringUtils.getQueueDirection(arg.get("AR_TO_LEFT").get(3)).getInv(); - } - return null; - } - - private CommandExecutionResult executePackageLink(Map arg) { - final String g1 = arg.get("G1").get(0); - final String g2 = arg.get("G2").get(0); - - final Group cl1 = getSystem().getGroup(g1); - final Group cl2 = getSystem().getGroup(g2); - - final LinkType linkType; - final String queue; - if (arg.get("AR_TO_RIGHT").get(0) != null) { - queue = arg.get("AR_TO_RIGHT").get(1) + arg.get("AR_TO_RIGHT").get(3); - linkType = getLinkTypeNormal(queue, arg.get("AR_TO_RIGHT").get(4)); - } else { - queue = arg.get("AR_TO_LEFT").get(2) + arg.get("AR_TO_LEFT").get(4); - linkType = getLinkTypeNormal(queue, arg.get("AR_TO_LEFT").get(1)).getInv(); - - } - - final Link link = new Link(cl1.getEntityCluster(), cl2.getEntityCluster(), linkType, arg.get("END").get(0), - queue.length()); - getSystem().addLink(link); - return CommandExecutionResult.ok(); - } - - private LinkType getLinkTypeNormal(String queue, String key) { - LinkType linkType = getLinkTypeFromKey(key); - - if (queue.startsWith(".")) { - linkType = linkType.getDashed(); - } - return linkType; - } - - private LinkType getLinkTypeFromKey(String k) { - if (k == null) { - return new LinkType(LinkDecor.NONE, LinkDecor.NONE); - } - if (k.equals("<") || k.equals(">")) { - return new LinkType(LinkDecor.ARROW, LinkDecor.NONE); - } - if (k.equals("<|") || k.equals("|>")) { - return new LinkType(LinkDecor.EXTENDS, LinkDecor.NONE); - } - if (k.equals("^")) { - return new LinkType(LinkDecor.EXTENDS, LinkDecor.NONE); - } - return null; - } - -} diff --git a/src/net/sourceforge/plantuml/compositediagram/CompositeDiagram.java b/src/net/sourceforge/plantuml/compositediagram/CompositeDiagram.java index bd1c3a35f..032867f48 100644 --- a/src/net/sourceforge/plantuml/compositediagram/CompositeDiagram.java +++ b/src/net/sourceforge/plantuml/compositediagram/CompositeDiagram.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -35,17 +35,20 @@ package net.sourceforge.plantuml.compositediagram; import net.sourceforge.plantuml.UmlDiagramType; import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram; -import net.sourceforge.plantuml.cucadiagram.EntityType; +import net.sourceforge.plantuml.cucadiagram.Code; import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.LeafType; public class CompositeDiagram extends AbstractEntityDiagram { - @Override - public IEntity getOrCreateClass(String code) { - if (isGroup(code)) { - return getGroup(code).getEntityCluster(); + public IEntity getOrCreateLeaf(Code code, LeafType type) { + if (type == null) { + if (isGroup(code)) { + return getGroup(code); + } + return getOrCreateLeafDefault(code, LeafType.BLOCK); } - return getOrCreateEntity(code, EntityType.BLOCK); + return getOrCreateLeafDefault(code, type); } @Override diff --git a/src/net/sourceforge/plantuml/compositediagram/CompositeDiagramFactory.java b/src/net/sourceforge/plantuml/compositediagram/CompositeDiagramFactory.java index ff796b985..526d21757 100644 --- a/src/net/sourceforge/plantuml/compositediagram/CompositeDiagramFactory.java +++ b/src/net/sourceforge/plantuml/compositediagram/CompositeDiagramFactory.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,28 +33,32 @@ */ package net.sourceforge.plantuml.compositediagram; -import net.sourceforge.plantuml.command.AbstractUmlSystemCommandFactory; +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.plantuml.command.Command; +import net.sourceforge.plantuml.command.UmlDiagramFactory; import net.sourceforge.plantuml.compositediagram.command.CommandCreateBlock; import net.sourceforge.plantuml.compositediagram.command.CommandCreatePackageBlock; import net.sourceforge.plantuml.compositediagram.command.CommandEndPackageBlock; import net.sourceforge.plantuml.compositediagram.command.CommandLinkBlock; -public class CompositeDiagramFactory extends AbstractUmlSystemCommandFactory { +public class CompositeDiagramFactory extends UmlDiagramFactory { - private CompositeDiagram system; + @Override + protected List createCommands() { + final List cmds = new ArrayList(); + cmds.add(new CommandCreateBlock()); + cmds.add(new CommandLinkBlock()); + cmds.add(new CommandCreatePackageBlock()); + cmds.add(new CommandEndPackageBlock()); + addCommonCommands(cmds); - public CompositeDiagram getSystem() { - return system; + return cmds; } @Override - protected void initCommands() { - system = new CompositeDiagram(); - - addCommand(new CommandCreateBlock(system)); - addCommand(new CommandLinkBlock(system)); - addCommand(new CommandCreatePackageBlock(system)); - addCommand(new CommandEndPackageBlock(system)); - addCommonCommands(system); + public CompositeDiagram createEmptyDiagram() { + return new CompositeDiagram(); } } diff --git a/src/net/sourceforge/plantuml/compositediagram/command/CommandCreateBlock.java b/src/net/sourceforge/plantuml/compositediagram/command/CommandCreateBlock.java index ee60dad84..a1be78843 100644 --- a/src/net/sourceforge/plantuml/compositediagram/command/CommandCreateBlock.java +++ b/src/net/sourceforge/plantuml/compositediagram/command/CommandCreateBlock.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -38,23 +38,25 @@ import java.util.List; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.SingleLineCommand; import net.sourceforge.plantuml.compositediagram.CompositeDiagram; -import net.sourceforge.plantuml.cucadiagram.Entity; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.IEntity; public class CommandCreateBlock extends SingleLineCommand { - public CommandCreateBlock(CompositeDiagram diagram) { - super(diagram, "(?i)^(?:block\\s+)(?:\"([^\"]+)\"\\s+as\\s+)?([\\p{L}0-9_.]+)$"); + public CommandCreateBlock() { + super("(?i)^(?:block\\s+)(?:\"([^\"]+)\"\\s+as\\s+)?([\\p{L}0-9_.]+)$"); } @Override - protected CommandExecutionResult executeArg(List arg) { + protected CommandExecutionResult executeArg(CompositeDiagram diagram, List arg) { String display = arg.get(0); - final String code = arg.get(1); + final Code code = Code.of(arg.get(1)); if (display == null) { - display = code; + display = code.getCode(); } - final Entity ent = (Entity) getSystem().getOrCreateClass(code); - ent.setDisplay2(display); + final IEntity ent = diagram.getOrCreateLeaf(code, null); + ent.setDisplay(Display.getWithNewlines(display)); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/compositediagram/command/CommandCreatePackageBlock.java b/src/net/sourceforge/plantuml/compositediagram/command/CommandCreatePackageBlock.java index 933140160..647b13abd 100644 --- a/src/net/sourceforge/plantuml/compositediagram/command/CommandCreatePackageBlock.java +++ b/src/net/sourceforge/plantuml/compositediagram/command/CommandCreatePackageBlock.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -38,24 +38,26 @@ import java.util.List; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.SingleLineCommand; import net.sourceforge.plantuml.compositediagram.CompositeDiagram; -import net.sourceforge.plantuml.cucadiagram.Group; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.cucadiagram.GroupType; +import net.sourceforge.plantuml.cucadiagram.IGroup; public class CommandCreatePackageBlock extends SingleLineCommand { - public CommandCreatePackageBlock(CompositeDiagram diagram) { - super(diagram, "(?i)^block\\s+(?:\"([^\"]+)\"\\s+as\\s+)?([\\p{L}0-9_.]+)(?:\\s*\\{|\\s+begin)$"); + public CommandCreatePackageBlock() { + super("(?i)^block\\s+(?:\"([^\"]+)\"\\s+as\\s+)?([\\p{L}0-9_.]+)(?:\\s*\\{|\\s+begin)$"); } @Override - protected CommandExecutionResult executeArg(List arg) { - final Group currentPackage = getSystem().getCurrentGroup(); + protected CommandExecutionResult executeArg(CompositeDiagram diagram, List arg) { + final IGroup currentPackage = diagram.getCurrentGroup(); String display = arg.get(0); - final String code = arg.get(1); + final Code code = Code.of(arg.get(1)); if (display == null) { - display = code; + display = code.getCode(); } - getSystem().getOrCreateGroup(code, display, null, GroupType.PACKAGE, currentPackage); + diagram.getOrCreateGroup(code, Display.getWithNewlines(display), null, GroupType.PACKAGE, currentPackage); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/compositediagram/command/CommandEndPackageBlock.java b/src/net/sourceforge/plantuml/compositediagram/command/CommandEndPackageBlock.java index bddbf7da0..5612762fa 100644 --- a/src/net/sourceforge/plantuml/compositediagram/command/CommandEndPackageBlock.java +++ b/src/net/sourceforge/plantuml/compositediagram/command/CommandEndPackageBlock.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -38,21 +38,21 @@ import java.util.List; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.SingleLineCommand; import net.sourceforge.plantuml.compositediagram.CompositeDiagram; -import net.sourceforge.plantuml.cucadiagram.Group; +import net.sourceforge.plantuml.cucadiagram.IEntity; public class CommandEndPackageBlock extends SingleLineCommand { - public CommandEndPackageBlock(CompositeDiagram diagram) { - super(diagram, "(?i)^(end ?block|\\})$"); + public CommandEndPackageBlock() { + super("(?i)^(end ?block|\\})$"); } @Override - protected CommandExecutionResult executeArg(List arg) { - final Group currentPackage = getSystem().getCurrentGroup(); + protected CommandExecutionResult executeArg(CompositeDiagram diagram, List arg) { + final IEntity currentPackage = diagram.getCurrentGroup(); if (currentPackage == null) { return CommandExecutionResult.error("No inner block defined"); } - getSystem().endGroup(); + diagram.endGroup(); return CommandExecutionResult.ok(); } diff --git a/src/net/sourceforge/plantuml/compositediagram/command/CommandLinkBlock.java b/src/net/sourceforge/plantuml/compositediagram/command/CommandLinkBlock.java index 8764a5cf9..1ff1535ce 100644 --- a/src/net/sourceforge/plantuml/compositediagram/command/CommandLinkBlock.java +++ b/src/net/sourceforge/plantuml/compositediagram/command/CommandLinkBlock.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -36,6 +36,8 @@ import java.util.List; import net.sourceforge.plantuml.command.CommandExecutionResult; import net.sourceforge.plantuml.command.SingleLineCommand; import net.sourceforge.plantuml.compositediagram.CompositeDiagram; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.cucadiagram.Link; import net.sourceforge.plantuml.cucadiagram.LinkDecor; @@ -43,14 +45,14 @@ import net.sourceforge.plantuml.cucadiagram.LinkType; public class CommandLinkBlock extends SingleLineCommand { - public CommandLinkBlock(CompositeDiagram diagram) { - super(diagram, "(?i)^([\\p{L}0-9_.]+)\\s*(\\[\\]|\\*\\))?([=-]+|\\.+)(\\[\\]|\\(\\*)?\\s*([\\p{L}0-9_.]+)\\s*(?::\\s*(\\S*+))?$"); + public CommandLinkBlock() { + super("(?i)^([\\p{L}0-9_.]+)\\s*(\\[\\]|\\*\\))?([=-]+|\\.+)(\\[\\]|\\(\\*)?\\s*([\\p{L}0-9_.]+)\\s*(?::\\s*(\\S*+))?$"); } @Override - protected CommandExecutionResult executeArg(List arg) { - final IEntity cl1 = getSystem().getOrCreateClass(arg.get(0)); - final IEntity cl2 = getSystem().getOrCreateClass(arg.get(4)); + protected CommandExecutionResult executeArg(CompositeDiagram diagram, List arg) { + final IEntity cl1 = diagram.getOrCreateLeaf(Code.of(arg.get(0)), null); + final IEntity cl2 = diagram.getOrCreateLeaf(Code.of(arg.get(4)), null); final String deco1 = arg.get(1); final String deco2 = arg.get(3); @@ -64,14 +66,14 @@ public class CommandLinkBlock extends SingleLineCommand { final String queue = arg.get(2); - final Link link = new Link(cl1, cl2, linkType, arg.get(5), queue.length()); - getSystem().addLink(link); + final Link link = new Link(cl1, cl2, linkType, Display.getWithNewlines(arg.get(5)), queue.length()); + diagram.addLink(link); return CommandExecutionResult.ok(); } private LinkDecor getLinkDecor(String s) { if ("[]".equals(s)) { - return LinkDecor.SQUARRE; + return LinkDecor.SQUARRE_toberemoved; } return LinkDecor.NONE; } diff --git a/src/net/sourceforge/plantuml/core/Diagram.java b/src/net/sourceforge/plantuml/core/Diagram.java new file mode 100644 index 000000000..00b397f38 --- /dev/null +++ b/src/net/sourceforge/plantuml/core/Diagram.java @@ -0,0 +1,92 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 12052 $ + * + */ +package net.sourceforge.plantuml.core; + +import java.io.IOException; +import java.io.OutputStream; + +import net.sourceforge.plantuml.FileFormatOption; + +/** + * Represents a single diagram. A Diagram could be a UML (sequence diagram, class diagram...) or an non-UML diagram. + * + * @author Arnaud Roques + */ +public interface Diagram { + + /** + * Export the diagram as an image to some format. Note that a diagram could be drawn as several images (think about + * new page for sequence diagram for example). + * + * @param os + * where to write the image + * @param num + * useually 0 (index of the image to be exported for this diagram). + * @param fileFormat + * file format to use + * + * @return a description of the generated image + * + * @throws IOException + */ + ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException; + + /** + * Number of images in this diagram (usually, 1) + * + * @return usually 1 + */ + int getNbImages(); + + DiagramDescription getDescription(); + + String getMetadata(); + + String getWarningOrError(); + + /** + * The original source of the diagram + * + * @return + */ + UmlSource getSource(); + + /** + * Check if the Diagram have some links. + * + * @return + */ + public boolean hasUrl(); + +} diff --git a/src/net/sourceforge/plantuml/core/DiagramDescription.java b/src/net/sourceforge/plantuml/core/DiagramDescription.java new file mode 100644 index 000000000..54051078a --- /dev/null +++ b/src/net/sourceforge/plantuml/core/DiagramDescription.java @@ -0,0 +1,44 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11351 $ + * + */ +package net.sourceforge.plantuml.core; + +public interface DiagramDescription { + + String getDescription(); + + String getCmapData(); + + public String getType(); + +} diff --git a/src/net/sourceforge/plantuml/core/DiagramDescriptionImpl.java b/src/net/sourceforge/plantuml/core/DiagramDescriptionImpl.java new file mode 100644 index 000000000..2aa39fd53 --- /dev/null +++ b/src/net/sourceforge/plantuml/core/DiagramDescriptionImpl.java @@ -0,0 +1,73 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11351 $ + * + */ +package net.sourceforge.plantuml.core; + +public class DiagramDescriptionImpl implements DiagramDescription { + + private final String description; + private final String cmapData; + private final Class clazz; + + public DiagramDescriptionImpl(String description, Class clazz) { + this(description, clazz, null); + } + + private DiagramDescriptionImpl(String description, Class clazz, String cmapData) { + this.description = description; + this.cmapData = cmapData; + this.clazz = clazz; + } + + public String getDescription() { + return description; + } + + public String getType() { + return clazz.getSimpleName(); + } + + public String getCmapData() { + return cmapData; + } + + public DiagramDescription withCMapData(String cmapData) { + return new DiagramDescriptionImpl(this.description, this.clazz, cmapData); + } + + @Override + public String toString() { + return description; + } + +} diff --git a/src/net/sourceforge/plantuml/DiagramType.java b/src/net/sourceforge/plantuml/core/DiagramType.java similarity index 74% rename from src/net/sourceforge/plantuml/DiagramType.java rename to src/net/sourceforge/plantuml/core/DiagramType.java index 08d60beb7..09d784e30 100644 --- a/src/net/sourceforge/plantuml/DiagramType.java +++ b/src/net/sourceforge/plantuml/core/DiagramType.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -31,12 +31,15 @@ * Revision $Revision: 4768 $ * */ -package net.sourceforge.plantuml; +package net.sourceforge.plantuml.core; public enum DiagramType { - UML, DITAA, DOT, PROJECT, JCCKIT, SALT, UNKNOWN; + UML, DITAA, DOT, PROJECT, JCCKIT, SALT, TURING, FLOW, CREOLE, UNKNOWN; - static DiagramType getTypeFromArobaseStart(String s) { + static public DiagramType getTypeFromArobaseStart(String s) { +// if (s.startsWith("@startuml2")) { +// return UML2; +// } if (s.startsWith("@startuml")) { return UML; } @@ -55,6 +58,15 @@ public enum DiagramType { if (s.startsWith("@startsalt")) { return SALT; } + if (s.startsWith("@startturing")) { + return TURING; + } + if (s.startsWith("@startflow")) { + return FLOW; + } + if (s.startsWith("@startcreole")) { + return CREOLE; + } return UNKNOWN; } } diff --git a/src/net/sourceforge/plantuml/core/ImageData.java b/src/net/sourceforge/plantuml/core/ImageData.java new file mode 100644 index 000000000..f8ae8b53c --- /dev/null +++ b/src/net/sourceforge/plantuml/core/ImageData.java @@ -0,0 +1,87 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 9885 $ + * + */ +package net.sourceforge.plantuml.core; + +// Remove CmapData and Dimension2D +// Merge CucaDiagramFileMakerResult +/** + * Information about a generated image for a diagram. + * For some diagrams, there are some position information about elements + * from the diagram. In that case, the method containsCMapData() returns + * true and you can retrieve those information using + * getCMapData() method. + * + * @author Arnaud Roques + * + */ +public interface ImageData { + + /** + * Width in pixel of the image. + * @return + */ + public int getWidth(); + + /** + * Height in pixel of the image. + * @return + */ + public int getHeight(); + + /** + * Indicates if the image has some position information. + * @return true if the image has position information. + */ + public boolean containsCMapData(); + + /** + * Return position information as a CMap formated string. + * For example, if you call this method with nameId + * set to "foo_map", you will get something like: + * + *

+	 * <map id="foo_map" name="foo_map">
+	 * <area shape="rect" id="..." href="..." title="..." alt="" coords="64,68,93,148"/>
+	 * </map>
+	 * 
+ * + * @param nameId thie id to be used in the cmap data string. + * @return + */ + public String getCMapData(String nameId); + + public String getWarningOrError(); + + +} diff --git a/src/net/sourceforge/plantuml/core/UmlSource.java b/src/net/sourceforge/plantuml/core/UmlSource.java new file mode 100644 index 000000000..7d0a94c98 --- /dev/null +++ b/src/net/sourceforge/plantuml/core/UmlSource.java @@ -0,0 +1,185 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.core; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import net.sourceforge.plantuml.StartUtils; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.version.IteratorCounter; +import net.sourceforge.plantuml.version.IteratorCounterImpl; + +/** + * Represents the textual source of some diagram. + * The source should start with a @startfoo and end with @endfoo. + *

+ * So the diagram does not have to be a UML one. + * + * @author Arnaud Roques + * + */ +final public class UmlSource { + + final private List source; + + /** + * Build the source from a text. + * + * @param source the source of the diagram + * @param checkEndingBackslash true if an ending backslash means that a line has + * to be collapsed with the following one. + */ + public UmlSource(List source, boolean checkEndingBackslash) { + final List tmp = new ArrayList(); + // final DiagramType type = + // DiagramType.getTypeFromArobaseStart(source.get(0).toString()); + if (checkEndingBackslash) { + final StringBuilder pending = new StringBuilder(); + for (CharSequence cs : source) { + final String s = cs.toString(); + if (s.endsWith("\\") && s.endsWith("\\\\") == false) { + pending.append(s.substring(0, s.length() - 1)); + } else { + pending.append(s); + tmp.add(pending.toString()); + pending.setLength(0); + } + } + } else { + for (CharSequence s : source) { + tmp.add(s.toString()); + } + } + this.source = Collections.unmodifiableList(tmp); + } + + /** + * Retrieve the type of the diagram. + * This is based on the first line @startfoo. + * + * @return the type of the diagram. + */ + public DiagramType getDiagramType() { + return DiagramType.getTypeFromArobaseStart(source.get(0)); + } + + /** + * Allows to iterator over the source. + * + * @return a iterator that allow counting line number. + */ + public IteratorCounter iterator() { + return new IteratorCounterImpl(source.iterator()); + } + + /** + * Return the source as a single String with \n as line separator. + * + * @return the whole diagram source + */ + public String getPlainString() { + final StringBuilder sb = new StringBuilder(); + for (String s : source) { + sb.append(s); + sb.append('\r'); + sb.append('\n'); + } + return sb.toString(); + } + + /** + * Return a specific line of the diagram description. + * + * @param n line number, starting at 0 + * @return + */ + public String getLine(int n) { + return source.get(n); + } + + /** + * Return the number of line in the diagram. + * + * @return + */ + public int getTotalLineCount() { + return source.size(); + } + + /** + * Check if a source diagram description is empty. + * Does not take comment line into account. + * + * @return true if the diagram does not contain information. + */ + public boolean isEmpty() { + for (String s : source) { + if (StartUtils.isArobaseStartDiagram(s)) { + continue; + } + if (StartUtils.isArobaseEndDiagram(s)) { + continue; + } + if (s.matches("\\s*'.*")) { + continue; + } + if (s.trim().length() != 0) { + return false; + } + } + return true; + } + + /** + * Retrieve the title, if defined in the diagram source. + * Never return null. + * @return + */ + public Display getTitle() { + final Pattern p = Pattern.compile("(?i)^\\s*title\\s+(.+)$"); + for (String s : source) { + final Matcher m = p.matcher(s); + final boolean ok = m.matches(); + if (ok) { + return Display.asList(m.group(1)); + } + } + return Display.emptyList(); + } + +} diff --git a/src/net/sourceforge/plantuml/core/package.html b/src/net/sourceforge/plantuml/core/package.html new file mode 100644 index 000000000..0f52f9822 --- /dev/null +++ b/src/net/sourceforge/plantuml/core/package.html @@ -0,0 +1,44 @@ + + + +

Core classes used by PlantUML.

+ +

Overview

+ +

+This package the basic classes used by PlantUML. +

+Classes in this package are supposed to be quite stable over time. + + diff --git a/src/net/sourceforge/plantuml/graphic/Tile.java b/src/net/sourceforge/plantuml/creole/Atom.java similarity index 71% rename from src/net/sourceforge/plantuml/graphic/Tile.java rename to src/net/sourceforge/plantuml/creole/Atom.java index f60af7065..6345d9a73 100644 --- a/src/net/sourceforge/plantuml/graphic/Tile.java +++ b/src/net/sourceforge/plantuml/creole/Atom.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,23 +28,23 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6577 $ + * Revision $Revision: 11025 $ * */ -package net.sourceforge.plantuml.graphic; +package net.sourceforge.plantuml.creole; -import java.awt.Graphics2D; import java.awt.geom.Dimension2D; -import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UShape; -interface Tile { +interface Atom extends UShape { - Dimension2D calculateDimension(StringBounder stringBounder); + public Dimension2D calculateDimension(StringBounder stringBounder); - void draw(ColorMapper colorMapper, Graphics2D g2d, double x, double y); + public double getStartingAltitude(StringBounder stringBounder); - void drawU(UGraphic ug, double x, double y); + public void drawU(UGraphic ug); -} \ No newline at end of file +} diff --git a/src/net/sourceforge/plantuml/creole/AtomImg.java b/src/net/sourceforge/plantuml/creole/AtomImg.java new file mode 100644 index 000000000..57d73e341 --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/AtomImg.java @@ -0,0 +1,136 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.awt.Font; +import java.awt.geom.Dimension2D; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; + +import javax.imageio.ImageIO; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.FileSystem; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.ImgValign; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UImage; + +public class AtomImg implements Atom { + + private final BufferedImage image; + + private AtomImg(BufferedImage image) { + this.image = image; + } + + public static Atom create(String src, final ImgValign valign, final int vspace) { + final UFont font = new UFont("Monospaced", Font.PLAIN, 14); + final FontConfiguration fc = new FontConfiguration(font, HtmlColorUtils.BLACK); + try { + final File f = FileSystem.getInstance().getFile(src); + if (f.exists() == false) { + // Check if valid URL + if (src.startsWith("http:") || src.startsWith("https:")) { + final byte image[] = getFile(src); + final BufferedImage read = ImageIO.read(new ByteArrayInputStream(image)); + if (read == null) { + return AtomText.create("(Cannot decode: " + src + ")", fc); + } + return new AtomImg(read); + } + return AtomText.create("(File not found: " + f + ")", fc); + } + if (f.getName().endsWith(".svg")) { + // return new AtomImg(new TileImageSvg(f)); + throw new UnsupportedOperationException(); + } + final BufferedImage read = ImageIO.read(f); + if (read == null) { + return AtomText.create("(Cannot decode: " + f + ")", fc); + } + return new AtomImg(ImageIO.read(f)); + } catch (IOException e) { + return AtomText.create("ERROR " + e.toString(), fc); + } + } + + // Added by Alain Corbiere + static byte[] getFile(String host) throws IOException { + final ByteArrayOutputStream image = new ByteArrayOutputStream(); + InputStream input = null; + try { + final URL url = new URL(host); + final URLConnection connection = url.openConnection(); + input = connection.getInputStream(); + final byte[] buffer = new byte[1024]; + int read; + while ((read = input.read(buffer)) > 0) { + image.write(buffer, 0, read); + } + image.close(); + return image.toByteArray(); + } finally { + if (input != null) { + input.close(); + } + } + } + + // End + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return new Dimension2DDouble(image.getWidth(), image.getHeight()); + } + + public double getStartingAltitude(StringBounder stringBounder) { + return 0; + } + + public void drawU(UGraphic ug) { + // final double h = calculateDimension(ug.getStringBounder()).getHeight(); + ug.draw(new UImage(image)); + // tileImage.drawU(ug.apply(new UTranslate(0, -h))); + } + +} diff --git a/src/net/sourceforge/plantuml/creole/AtomSprite.java b/src/net/sourceforge/plantuml/creole/AtomSprite.java new file mode 100644 index 000000000..86b86a9c9 --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/AtomSprite.java @@ -0,0 +1,62 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.ugraphic.UGraphic; + +public class AtomSprite implements Atom { + + private final TextBlock sprite; + + public AtomSprite(TextBlock sprite) { + this.sprite = sprite; + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return sprite.calculateDimension(stringBounder); + } + + public double getStartingAltitude(StringBounder stringBounder) { + return 0; + } + + public void drawU(UGraphic ug) { + sprite.drawU(ug); + } + +} diff --git a/src/net/sourceforge/plantuml/creole/AtomTable.java b/src/net/sourceforge/plantuml/creole/AtomTable.java new file mode 100644 index 000000000..ca267e656 --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/AtomTable.java @@ -0,0 +1,208 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.awt.geom.Dimension2D; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class AtomTable implements Atom { + + class Line { + private final List cells = new ArrayList(); + + public void add(Atom cell) { + cells.add(cell); + } + + public int size() { + return cells.size(); + } + + @Override + public String toString() { + return super.toString() + " " + cells.size(); + } + } + + private final List lines = new ArrayList(); + private final Map positions = new HashMap(); + private final HtmlColor lineColor; + + public AtomTable(HtmlColor lineColor) { + this.lineColor = lineColor; + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + initMap(stringBounder); + final double width = getEndingX(getNbCols() - 1); + final double height = getEndingY(getNbLines() - 1); + return new Dimension2DDouble(width, height); + } + + public double getStartingAltitude(StringBounder stringBounder) { + return 0; + } + + public void drawU(UGraphic ug) { + initMap(ug.getStringBounder()); + for (Line line : lines) { + for (Atom cell : line.cells) { + final Position pos = positions.get(cell); + cell.drawU(ug.apply(pos.getTranslate())); + } + } + ug = ug.apply(new UChangeColor(lineColor)); + final ULine hline = new ULine(getEndingX(getNbCols() - 1), 0); + for (int i = 0; i <= getNbLines(); i++) { + ug.apply(new UTranslate(0, getStartingY(i))).draw(hline); + } + final ULine vline = new ULine(0, getEndingY(getNbLines() - 1)); + for (int i = 0; i <= getNbCols(); i++) { + ug.apply(new UTranslate(getStartingX(i), 0)).draw(vline); + } + + } + + private void initMap(StringBounder stringBounder) { + if (positions.size() > 0) { + return; + } + for (Line line : lines) { + for (Atom cell : line.cells) { + final Dimension2D dim = cell.calculateDimension(stringBounder); + final Position pos = new Position(0, 0, dim); + positions.put(cell, pos); + } + } + for (int i = 0; i < lines.size(); i++) { + for (int j = 0; j < lines.get(i).size(); j++) { + final Atom cell = lines.get(i).cells.get(j); + final Dimension2D dim = cell.calculateDimension(stringBounder); + final double x = getStartingX(j); + final double y = getStartingY(i); + final Position pos = new Position(x, y, dim); + positions.put(cell, pos); + } + } + } + + private double getStartingX(int col) { + double result = 0; + for (int i = 0; i < col; i++) { + result += getColWidth(i); + } + return result; + } + + private double getEndingX(int col) { + double result = 0; + for (int i = 0; i <= col; i++) { + result += getColWidth(i); + } + return result; + } + + private double getStartingY(int line) { + double result = 0; + for (int i = 0; i < line; i++) { + result += getLineHeight(i); + } + return result; + } + + private double getEndingY(int line) { + double result = 0; + for (int i = 0; i <= line; i++) { + result += getLineHeight(i); + } + return result; + } + + private double getColWidth(int col) { + double result = 0; + for (int i = 0; i < getNbLines(); i++) { + final double width = getPosition(i, col).getWidth(); + result = Math.max(result, width); + } + return result; + } + + private double getLineHeight(int line) { + double result = 0; + for (int i = 0; i < getNbCols(); i++) { + final double height = getPosition(line, i).getHeight(); + result = Math.max(result, height); + } + return result; + } + + private Position getPosition(int line, int col) { + final Line l = lines.get(line); + final Atom atom = l.cells.get(col); + return positions.get(atom); + } + + private int getNbCols() { + return lines.get(0).size(); + } + + private int getNbLines() { + return lines.size(); + } + + private Line lastLine() { + return lines.get(lines.size() - 1); + } + + public void addCell(Atom cell) { + lastLine().add(cell); + positions.clear(); + } + + public void newLine() { + lines.add(new Line()); + } + +} diff --git a/src/net/sourceforge/plantuml/creole/AtomText.java b/src/net/sourceforge/plantuml/creole/AtomText.java new file mode 100644 index 000000000..74b869763 --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/AtomText.java @@ -0,0 +1,213 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.awt.font.LineMetrics; +import java.awt.geom.Dimension2D; +import java.util.StringTokenizer; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.Log; +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UText; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class AtomText implements Atom { + + interface DelayedDouble { + public double getDouble(StringBounder stringBounder); + } + + private static DelayedDouble ZERO = new DelayedDouble() { + public double getDouble(StringBounder stringBounder) { + return 0; + } + }; + + private final FontConfiguration fontConfiguration; + private final String text; + private final DelayedDouble marginLeft; + private final DelayedDouble marginRight; + private final Url url; + + public static AtomText create(String text, FontConfiguration fontConfiguration) { + return new AtomText(text, fontConfiguration, null, ZERO, ZERO); + } + + public static Atom createUrl(Url url, FontConfiguration fontConfiguration) { + return new AtomText(url.getLabel(), fontConfiguration, url, ZERO, ZERO); + } + + public static AtomText createHeading(String text, FontConfiguration fontConfiguration, int order) { + if (order == 0) { + fontConfiguration = fontConfiguration.bigger(4).bold(); + } else if (order == 1) { + fontConfiguration = fontConfiguration.bigger(2).bold(); + } else if (order == 2) { + fontConfiguration = fontConfiguration.bigger(1).bold(); + } else { + fontConfiguration = fontConfiguration.italic(); + } + return new AtomText(text, fontConfiguration, null, ZERO, ZERO); + } + + public static Atom createListNumber(final FontConfiguration fontConfiguration, final int order, int localNumber) { + final DelayedDouble left = new DelayedDouble() { + public double getDouble(StringBounder stringBounder) { + final Dimension2D dim = stringBounder.calculateDimension(fontConfiguration.getFont(), "9. "); + return dim.getWidth() * order; + } + }; + final DelayedDouble right = new DelayedDouble() { + public double getDouble(StringBounder stringBounder) { + final Dimension2D dim = stringBounder.calculateDimension(fontConfiguration.getFont(), "."); + return dim.getWidth(); + } + }; + return new AtomText("" + (localNumber + 1) + ".", fontConfiguration, null, left, right); + } + + @Override + public String toString() { + return text + " " + fontConfiguration; + } + + private AtomText(String text, FontConfiguration style, Url url, DelayedDouble marginLeft, DelayedDouble marginRight) { + this.marginLeft = marginLeft; + this.marginRight = marginRight; + this.text = text; + this.fontConfiguration = style; + this.url = url; + } + + public final String getText() { + return text; + } + + public FontConfiguration getFontConfiguration() { + return fontConfiguration; + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + final Dimension2D rect = stringBounder.calculateDimension(fontConfiguration.getFont(), text); + Log.debug("g2d=" + rect); + Log.debug("Size for " + text + " is " + rect); + double h = rect.getHeight(); + if (h < 10) { + h = 10; + } + final double width = text.indexOf('\t') == -1 ? rect.getWidth() : getWidth(stringBounder); + final double left = marginLeft.getDouble(stringBounder); + final double right = marginRight.getDouble(stringBounder); + + return new Dimension2DDouble(width + left + right, h); + } + + private double getDescent() { + final LineMetrics fm = TextBlockUtils.getLineMetrics(fontConfiguration.getFont(), text); + final double descent = fm.getDescent(); + return descent; + } + + public double getFontSize2D() { + return fontConfiguration.getFont().getSize2D(); + } + + public double getStartingAltitude(StringBounder stringBounder) { + return fontConfiguration.getSpace(); + } + + double getTabSize(StringBounder stringBounder) { + return stringBounder.calculateDimension(fontConfiguration.getFont(), " ").getWidth(); + } + + public void drawU(UGraphic ug) { + if (url != null) { + ug.startUrl(url); + } + ug = ug.apply(new UChangeColor(fontConfiguration.getColor())); + if (marginLeft != ZERO) { + ug = ug.apply(new UTranslate(marginLeft.getDouble(ug.getStringBounder()), 0)); + } + + final StringTokenizer tokenizer = new StringTokenizer(text, "\t", true); + + double x = 0; + // final int ypos = fontConfiguration.getSpace(); + final Dimension2D rect = ug.getStringBounder().calculateDimension(fontConfiguration.getFont(), text); + final double descent = getDescent(); + final double ypos = rect.getHeight() - descent; + if (tokenizer.hasMoreTokens()) { + final double tabSize = getTabSize(ug.getStringBounder()); + while (tokenizer.hasMoreTokens()) { + final String s = tokenizer.nextToken(); + if (s.equals("\t")) { + final double remainder = x % tabSize; + x += tabSize - remainder; + } else { + final UText utext = new UText(s, fontConfiguration); + final Dimension2D dim = ug.getStringBounder().calculateDimension(fontConfiguration.getFont(), s); + ug.apply(new UTranslate(x, ypos)).draw(utext); + x += dim.getWidth(); + } + } + } + if (url != null) { + ug.closeAction(); + } + } + + double getWidth(StringBounder stringBounder) { + final StringTokenizer tokenizer = new StringTokenizer(text, "\t", true); + final double tabSize = getTabSize(stringBounder); + double x = 0; + while (tokenizer.hasMoreTokens()) { + final String s = tokenizer.nextToken(); + if (s.equals("\t")) { + final double remainder = x % tabSize; + x += tabSize - remainder; + } else { + final Dimension2D dim = stringBounder.calculateDimension(fontConfiguration.getFont(), s); + x += dim.getWidth(); + } + } + return x; + } + +} diff --git a/src/net/sourceforge/plantuml/creole/AtomWithMargin.java b/src/net/sourceforge/plantuml/creole/AtomWithMargin.java new file mode 100644 index 000000000..8f0ba4eb8 --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/AtomWithMargin.java @@ -0,0 +1,67 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +class AtomWithMargin implements Atom { + + private final double marginY1; + private final double marginY2; + private final Atom atom; + + public AtomWithMargin(Atom atom, double marginY1, double marginY2) { + this.atom = atom; + this.marginY1 = marginY1; + this.marginY2 = marginY2; + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return Dimension2DDouble.delta(atom.calculateDimension(stringBounder), 0, marginY1 + marginY2); + } + + public double getStartingAltitude(StringBounder stringBounder) { + return atom.getStartingAltitude(stringBounder); + } + + public void drawU(UGraphic ug) { + atom.drawU(ug.apply(new UTranslate(0, marginY1))); + } + +} diff --git a/src/net/sourceforge/plantuml/creole/Bullet.java b/src/net/sourceforge/plantuml/creole/Bullet.java new file mode 100644 index 000000000..4307e648f --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/Bullet.java @@ -0,0 +1,109 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UEllipse; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UStroke; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class Bullet implements Atom { + + private final FontConfiguration fontConfiguration; + private final int order; + + public Bullet(FontConfiguration fontConfiguration, int order) { + this.fontConfiguration = fontConfiguration; + this.order = order; + } + + private double getWidth(StringBounder stringBounder) { + final Dimension2D dim = stringBounder.calculateDimension(fontConfiguration.getFont(), "W"); + return dim.getWidth() * (order + 1); + } + + public void drawU(UGraphic ug) { + if (order == 0) { + drawU0(ug); + } else { + drawU1(ug); + } + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + if (order == 0) { + return calculateDimension0(stringBounder); + } + return calculateDimension1(stringBounder); + } + + private void drawU0(UGraphic ug) { + final HtmlColor color = fontConfiguration.getColor(); + ug = ug.apply(new UChangeColor(color)).apply(new UChangeBackColor(color)).apply(new UStroke(0)); + // final double width = getWidth(ug.getStringBounder()); + ug = ug.apply(new UTranslate(3, 0)); + ug.draw(new UEllipse(5, 5)); + } + + public double getStartingAltitude(StringBounder stringBounder) { + return -5; + } + + private Dimension2D calculateDimension0(StringBounder stringBounder) { + return new Dimension2DDouble(getWidth(stringBounder), 5); + } + + private void drawU1(UGraphic ug) { + final HtmlColor color = fontConfiguration.getColor(); + ug = ug.apply(new UChangeColor(color)).apply(new UChangeBackColor(color)).apply(new UStroke(0)); + final double width = getWidth(ug.getStringBounder()); + ug = ug.apply(new UTranslate(width - 5, 0)); + ug.draw(new URectangle(3.5, 3.5)); + } + + private Dimension2D calculateDimension1(StringBounder stringBounder) { + return new Dimension2DDouble(getWidth(stringBounder), 3); + } + + +} diff --git a/src/net/sourceforge/plantuml/creole/Command.java b/src/net/sourceforge/plantuml/creole/Command.java new file mode 100644 index 000000000..5b01953d9 --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/Command.java @@ -0,0 +1,41 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +public interface Command { + + public int matchingSize(String line); + + public String executeAndGetRemaining(String line, StripeSimple stripe); +} diff --git a/src/net/sourceforge/plantuml/creole/CommandCreoleColorAndSizeChange.java b/src/net/sourceforge/plantuml/creole/CommandCreoleColorAndSizeChange.java new file mode 100644 index 000000000..08a7d3a1e --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/CommandCreoleColorAndSizeChange.java @@ -0,0 +1,94 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; + +public class CommandCreoleColorAndSizeChange implements Command { + + private final Pattern pattern; + + public static final String fontPattern = "\\"; + + public static Command create() { + return new CommandCreoleColorAndSizeChange("^(?i)(" + fontPattern + "(.*?)\\)"); + } + + public static Command createEol() { + return new CommandCreoleColorAndSizeChange("^(?i)(" + fontPattern + "(.*))$"); + } + + private CommandCreoleColorAndSizeChange(String p) { + this.pattern = Pattern.compile(p); + + } + + public int matchingSize(String line) { + final Matcher m = pattern.matcher(line); + if (m.find() == false) { + return 0; + } + return m.group(1).length(); + } + + public String executeAndGetRemaining(String line, StripeSimple stripe) { + final Matcher m = pattern.matcher(line); + if (m.find() == false) { + throw new IllegalStateException(); + } + // for (int i = 1; i <= m.groupCount(); i++) { + // System.err.println("i=" + i + " " + m.group(i)); + // } + + final FontConfiguration fc1 = stripe.getActualFontConfiguration(); + FontConfiguration fc2 = fc1; + if (m.group(2) != null) { + fc2 = fc2.changeSize(Integer.parseInt(m.group(2))); + } + if (m.group(3) != null) { + final HtmlColor color = HtmlColorUtils.getColorIfValid(m.group(3)); + fc2 = fc2.changeColor(color); + } + + stripe.setActualFontConfiguration(fc2); + stripe.analyzeAndAdd(m.group(4)); + stripe.setActualFontConfiguration(fc1); + return line.substring(m.group(1).length()); + } +} diff --git a/src/net/sourceforge/plantuml/creole/CommandCreoleColorChange.java b/src/net/sourceforge/plantuml/creole/CommandCreoleColorChange.java new file mode 100644 index 000000000..9e15cd5a4 --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/CommandCreoleColorChange.java @@ -0,0 +1,83 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.Splitter; + +public class CommandCreoleColorChange implements Command { + + private final Pattern pattern; + + public static Command create() { + return new CommandCreoleColorChange("^(?i)(" + Splitter.fontColorPattern2 + "(.*?)\\)"); + } + + public static Command createEol() { + return new CommandCreoleColorChange("^(?i)(" + Splitter.fontColorPattern2 + "(.*)$)"); + } + + private CommandCreoleColorChange(String p) { + this.pattern = Pattern.compile(p); + + } + + public int matchingSize(String line) { + final Matcher m = pattern.matcher(line); + if (m.find() == false) { + return 0; + } + return m.group(2).length(); + } + + public String executeAndGetRemaining(String line, StripeSimple stripe) { + final Matcher m = pattern.matcher(line); + if (m.find() == false) { + throw new IllegalStateException(); + } + final FontConfiguration fc1 = stripe.getActualFontConfiguration(); + final HtmlColor color = HtmlColorUtils.getColorIfValid(m.group(2)); + final FontConfiguration fc2 = fc1.changeColor(color); + stripe.setActualFontConfiguration(fc2); + stripe.analyzeAndAdd(m.group(3)); + stripe.setActualFontConfiguration(fc1); + return line.substring(m.group(1).length()); + } + +} diff --git a/src/net/sourceforge/plantuml/creole/CommandCreoleExposantChange.java b/src/net/sourceforge/plantuml/creole/CommandCreoleExposantChange.java new file mode 100644 index 000000000..9df66208c --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/CommandCreoleExposantChange.java @@ -0,0 +1,83 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.FontPosition; + +public class CommandCreoleExposantChange implements Command { + + private final Pattern pattern; + private final FontPosition position; + + private CommandCreoleExposantChange(String p, FontPosition position) { + this.pattern = Pattern.compile(p); + this.position = position; + } + + public static Command create(FontPosition position) { + return new CommandCreoleExposantChange("^(?i)(" + "\\<" + position.getHtmlTag() + "\\>" + "(.*?)\\)", position); + } + + // public static Command createLegacyEol(FontStyle style) { + // return new CommandCreoleExposantChange("^(" + style.getActivationPattern() + "(.+))$", style); + // } + + public int matchingSize(String line) { + final Matcher m = pattern.matcher(line); + if (m.find() == false) { + return 0; + } + return m.group(2).length(); + } + + public String executeAndGetRemaining(String line, StripeSimple stripe) { + final Matcher m = pattern.matcher(line); + if (m.find() == false) { + throw new IllegalStateException(); + } + final FontConfiguration fc1 = stripe.getActualFontConfiguration(); + final FontConfiguration fc2 = fc1.changeFontPosition(position); + + stripe.setActualFontConfiguration(fc2); + stripe.analyzeAndAdd(m.group(2)); + stripe.setActualFontConfiguration(fc1); + return line.substring(m.group(1).length()); + } + +} diff --git a/src/net/sourceforge/plantuml/creole/CommandCreoleFontFamilyChange.java b/src/net/sourceforge/plantuml/creole/CommandCreoleFontFamilyChange.java new file mode 100644 index 000000000..0c8f7567b --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/CommandCreoleFontFamilyChange.java @@ -0,0 +1,81 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.Splitter; + +public class CommandCreoleFontFamilyChange implements Command { + + private final Pattern pattern; + + public static Command create() { + return new CommandCreoleFontFamilyChange("^(?i)(" + Splitter.fontFamilyPattern + "(.*?)\\)"); + } + + public static Command createEol() { + return new CommandCreoleFontFamilyChange("^(?i)(" + Splitter.fontFamilyPattern + "(.*)$)"); + } + + private CommandCreoleFontFamilyChange(String p) { + this.pattern = Pattern.compile(p); + + } + + public int matchingSize(String line) { + final Matcher m = pattern.matcher(line); + if (m.find() == false) { + return 0; + } + return m.group(1).length(); + } + + public String executeAndGetRemaining(String line, StripeSimple stripe) { + final Matcher m = pattern.matcher(line); + if (m.find() == false) { + throw new IllegalStateException(); + } + final FontConfiguration fc1 = stripe.getActualFontConfiguration(); + final String family = m.group(2); + final FontConfiguration fc2 = fc1.changeFamily(family); + stripe.setActualFontConfiguration(fc2); + stripe.analyzeAndAdd(m.group(3)); + stripe.setActualFontConfiguration(fc1); + return line.substring(m.group(1).length()); + } + +} diff --git a/src/net/sourceforge/plantuml/creole/CommandCreoleImg.java b/src/net/sourceforge/plantuml/creole/CommandCreoleImg.java new file mode 100644 index 000000000..87d330703 --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/CommandCreoleImg.java @@ -0,0 +1,77 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import net.sourceforge.plantuml.graphic.Splitter; + +public class CommandCreoleImg implements Command { + + private final Pattern pattern; + + private CommandCreoleImg(String p) { + this.pattern = Pattern.compile(p); + } + + public static Command create() { + return new CommandCreoleImg("^(?i)(" + Splitter.imgPatternNoSrcColon + ")"); + } + + public int matchingSize(String line) { + final Matcher m = pattern.matcher(line); + if (m.find() == false) { + return 0; + } + return m.group(1).length(); + } + + public String executeAndGetRemaining(String line, StripeSimple stripe) { + final Matcher m = pattern.matcher(line); + if (m.find() == false) { + throw new IllegalStateException(); + } + // final int size = Integer.parseInt(m.group(2)); + // final FontConfiguration fc1 = stripe.getActualFontConfiguration(); + // final FontConfiguration fc2 = fc1.changeSize(size); + // stripe.setActualFontConfiguration(fc2); + // stripe.analyzeAndAdd(m.group(3)); + final String src = m.group(2); + stripe.addImage(src); + // stripe.setActualFontConfiguration(fc1); + return line.substring(m.group(1).length()); + } + +} diff --git a/src/net/sourceforge/plantuml/creole/CommandCreoleMonospaced.java b/src/net/sourceforge/plantuml/creole/CommandCreoleMonospaced.java new file mode 100644 index 000000000..cdface389 --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/CommandCreoleMonospaced.java @@ -0,0 +1,75 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import net.sourceforge.plantuml.graphic.FontConfiguration; + +public class CommandCreoleMonospaced implements Command { + + private final Pattern pattern; + + public static Command create() { + return new CommandCreoleMonospaced("^(?i)(\"\"(.*?)\"\")"); + } + + private CommandCreoleMonospaced(String p) { + this.pattern = Pattern.compile(p); + + } + + public int matchingSize(String line) { + final Matcher m = pattern.matcher(line); + if (m.find() == false) { + return 0; + } + return m.group(1).length(); + } + + public String executeAndGetRemaining(String line, StripeSimple stripe) { + final Matcher m = pattern.matcher(line); + if (m.find() == false) { + throw new IllegalStateException(); + } + final FontConfiguration fc1 = stripe.getActualFontConfiguration(); + final FontConfiguration fc2 = fc1.changeFamily("monospaced"); + stripe.setActualFontConfiguration(fc2); + stripe.analyzeAndAdd(m.group(2)); + stripe.setActualFontConfiguration(fc1); + return line.substring(m.group(1).length()); + } + +} diff --git a/src/net/sourceforge/plantuml/creole/CommandCreoleSizeChange.java b/src/net/sourceforge/plantuml/creole/CommandCreoleSizeChange.java new file mode 100644 index 000000000..9c0d11759 --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/CommandCreoleSizeChange.java @@ -0,0 +1,82 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.Splitter; + +public class CommandCreoleSizeChange implements Command { + + private final Pattern pattern; + + public static Command create() { + return new CommandCreoleSizeChange("^(?i)(" + Splitter.fontSizePattern2 + "(.*?)\\)"); + } + + public static Command createEol() { + return new CommandCreoleSizeChange("^(?i)(" + Splitter.fontSizePattern2 + "(.*)$)"); + } + + private CommandCreoleSizeChange(String p) { + this.pattern = Pattern.compile(p); + + } + + public int matchingSize(String line) { + final Matcher m = pattern.matcher(line); + if (m.find() == false) { + return 0; + } + return m.group(2).length(); + } + + public String executeAndGetRemaining(String line, StripeSimple stripe) { + final Matcher m = pattern.matcher(line); + if (m.find() == false) { + throw new IllegalStateException(); + } + final int size = Integer.parseInt(m.group(2)); + final FontConfiguration fc1 = stripe.getActualFontConfiguration(); + final FontConfiguration fc2 = fc1.changeSize(size); + // final FontConfiguration fc2 = new AddStyle(style, null).apply(fc1); + stripe.setActualFontConfiguration(fc2); + stripe.analyzeAndAdd(m.group(3)); + stripe.setActualFontConfiguration(fc1); + return line.substring(m.group(1).length()); + } + +} diff --git a/src/net/sourceforge/plantuml/creole/CommandCreoleSprite.java b/src/net/sourceforge/plantuml/creole/CommandCreoleSprite.java new file mode 100644 index 000000000..19df8e80c --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/CommandCreoleSprite.java @@ -0,0 +1,71 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import net.sourceforge.plantuml.graphic.Splitter; + +public class CommandCreoleSprite implements Command { + + private final Pattern pattern; + + private CommandCreoleSprite(String p) { + this.pattern = Pattern.compile(p); + } + + public static Command create() { + return new CommandCreoleSprite("^(?i)(" + Splitter.spritePattern2 + ")"); + } + + public int matchingSize(String line) { + final Matcher m = pattern.matcher(line); + if (m.find() == false) { + return 0; + } + return m.group(1).length(); + } + + public String executeAndGetRemaining(String line, StripeSimple stripe) { + final Matcher m = pattern.matcher(line); + if (m.find() == false) { + throw new IllegalStateException(); + } + final String src = m.group(2); + stripe.addSprite(src); + return line.substring(m.group(1).length()); + } + +} diff --git a/src/net/sourceforge/plantuml/creole/CommandCreoleStyle.java b/src/net/sourceforge/plantuml/creole/CommandCreoleStyle.java new file mode 100644 index 000000000..0b51f2fa6 --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/CommandCreoleStyle.java @@ -0,0 +1,100 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import net.sourceforge.plantuml.graphic.AddStyle; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.FontStyle; +import net.sourceforge.plantuml.graphic.HtmlColor; + +public class CommandCreoleStyle implements Command { + + private final Pattern p; + private final FontStyle style; + private final boolean tryExtendedColor; + + public static CommandCreoleStyle createCreole(FontStyle style) { + return new CommandCreoleStyle("^(" + style.getCreoleSyntax() + "(.+?)" + style.getCreoleSyntax() + ")", style, + false); + } + + public static Command createLegacy(FontStyle style) { + return new CommandCreoleStyle("^((" + style.getActivationPattern() + ")(.+?)" + style.getDeactivationPattern() + + ")", style, style.canHaveExtendedColor()); + } + + public static Command createLegacyEol(FontStyle style) { + return new CommandCreoleStyle("^((" + style.getActivationPattern() + ")(.+))$", style, + style.canHaveExtendedColor()); + } + + private CommandCreoleStyle(String p, FontStyle style, boolean tryExtendedColor) { + this.p = Pattern.compile(p); + this.style = style; + this.tryExtendedColor = tryExtendedColor; + } + + private HtmlColor getExtendedColor(Matcher m) { + if (tryExtendedColor) { + return style.getExtendedColor(m.group(2)); + } + return null; + } + + public String executeAndGetRemaining(final String line, StripeSimple stripe) { + final Matcher m = p.matcher(line); + if (m.find() == false) { + throw new IllegalStateException(); + } + final FontConfiguration fc1 = stripe.getActualFontConfiguration(); + final FontConfiguration fc2 = new AddStyle(style, getExtendedColor(m)).apply(fc1); + stripe.setActualFontConfiguration(fc2); + final int groupCount = m.groupCount(); + stripe.analyzeAndAdd(m.group(groupCount)); + stripe.setActualFontConfiguration(fc1); + return line.substring(m.group(1).length()); + } + + public int matchingSize(String line) { + final Matcher m = p.matcher(line); + if (m.find() == false) { + return 0; + } + return m.group(1).length(); + } + +} diff --git a/src/net/sourceforge/plantuml/creole/CommandCreoleUrl.java b/src/net/sourceforge/plantuml/creole/CommandCreoleUrl.java new file mode 100644 index 000000000..2631940a1 --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/CommandCreoleUrl.java @@ -0,0 +1,85 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.UrlBuilder; +import net.sourceforge.plantuml.UrlBuilder.ModeUrl; + +public class CommandCreoleUrl implements Command { + + private final Pattern pattern; + private final ISkinParam skinParam; + + public static Command create(ISkinParam skinParam) { + return new CommandCreoleUrl(skinParam, "^(" + UrlBuilder.getRegexp() + ")"); + } + + private CommandCreoleUrl(ISkinParam skinParam, String p) { + this.pattern = Pattern.compile(p); + this.skinParam = skinParam; + + } + + public int matchingSize(String line) { + final Matcher m = pattern.matcher(line); + if (m.find() == false) { + return 0; + } + return m.group(1).length(); + } + + public String executeAndGetRemaining(String line, StripeSimple stripe) { + final Matcher m = pattern.matcher(line); + if (m.find() == false) { + throw new IllegalStateException(); + } + final UrlBuilder urlBuilder = new UrlBuilder(skinParam.getValue("topurl"), ModeUrl.STRICT); + final Url url = urlBuilder.getUrl(m.group(1)); + stripe.addUrl(url); + +// final int size = Integer.parseInt(m.group(2)); +// final FontConfiguration fc1 = stripe.getActualFontConfiguration(); +// final FontConfiguration fc2 = fc1.changeSize(size); +// // final FontConfiguration fc2 = new AddStyle(style, null).apply(fc1); +// stripe.setActualFontConfiguration(fc2); + // stripe.analyzeAndAdd("AZERTY"); +// stripe.setActualFontConfiguration(fc1); + return line.substring(m.group(1).length()); + } +} diff --git a/src/net/sourceforge/plantuml/creole/CreoleContext.java b/src/net/sourceforge/plantuml/creole/CreoleContext.java new file mode 100644 index 000000000..6a78e7384 --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/CreoleContext.java @@ -0,0 +1,60 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.util.ArrayList; +import java.util.List; + +public class CreoleContext { + + private final List stack = new ArrayList(); + + public int getLocalNumber(int order) { + ensureStackOk(order); + final int n = stack.get(order); + stack.set(order, n + 1); + return n; + } + + private void ensureStackOk(int order) { + while (stack.size() <= order) { + stack.add(0); + } + while (stack.size() > order + 1) { + stack.remove(order + 1); + } + + } + +} diff --git a/src/net/sourceforge/plantuml/creole/CreoleHorizontalLine.java b/src/net/sourceforge/plantuml/creole/CreoleHorizontalLine.java new file mode 100644 index 000000000..c64e822bd --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/CreoleHorizontalLine.java @@ -0,0 +1,106 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UHorizontalLine; +import net.sourceforge.plantuml.ugraphic.UStroke; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class CreoleHorizontalLine implements Atom { + + private final FontConfiguration fontConfiguration; + private final String line; + private final char style; + private final ISkinParam skinParam; + + public static CreoleHorizontalLine create(FontConfiguration fontConfiguration, String line, char style, + ISkinParam skinParam) { + return new CreoleHorizontalLine(fontConfiguration, line, style, skinParam); + } + + private CreoleHorizontalLine(FontConfiguration fontConfiguration, String line, char style, ISkinParam skinParam) { + this.fontConfiguration = fontConfiguration; + this.line = line; + this.style = style; + this.skinParam = skinParam; + } + + private UHorizontalLine getHorizontalLine() { + if (line.length() == 0) { + return UHorizontalLine.infinite(0, 0, style); + } + final TextBlock tb = getTitle(); + return UHorizontalLine.infinite(0, 0, tb, style); + } + + private TextBlock getTitle() { + if (line.length() == 0) { + return TextBlockUtils.empty(0, 0); + } + final CreoleParser parser = new CreoleParser(fontConfiguration, skinParam); + final Sheet sheet = parser.createSheet(Display.getWithNewlines(line)); + final TextBlock tb = new SheetBlock(sheet, null, new UStroke()); + return tb; + } + + public void drawU(UGraphic ug) { + // ug = ug.apply(new UChangeColor(fontConfiguration.getColor())); + final Dimension2D dim = calculateDimension(ug.getStringBounder()); + ug = ug.apply(new UTranslate(0, dim.getHeight() / 2)); + ug.draw(getHorizontalLine()); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + if (line.length() == 0) { + return new Dimension2DDouble(10, 10); + } + final TextBlock tb = getTitle(); + return tb.calculateDimension(stringBounder); + } + + public double getStartingAltitude(StringBounder stringBounder) { + return 0; + } + +} diff --git a/src/net/sourceforge/plantuml/creole/CreoleParser.java b/src/net/sourceforge/plantuml/creole/CreoleParser.java new file mode 100644 index 000000000..3873ea8ed --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/CreoleParser.java @@ -0,0 +1,72 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.FontConfiguration; + +public class CreoleParser { + + private final FontConfiguration fontConfiguration; + private final ISkinParam skinParam; + + public CreoleParser(FontConfiguration fontConfiguration, ISkinParam skinParam) { + this.fontConfiguration = fontConfiguration; + this.skinParam = skinParam; + } + + private Stripe createStripe(String line, CreoleContext context, Stripe lastStripe) { + if (lastStripe instanceof StripeTable && line.startsWith("|") && line.endsWith("|")) { + final StripeTable table = (StripeTable) lastStripe; + table.analyzeAndAddNormal(line); + return null; + } else if (line.startsWith("|=") && line.endsWith("|")) { + return new StripeTable(fontConfiguration, skinParam, line); + } + return new CreoleStripeSimpleParser(line, fontConfiguration, skinParam).createStripe(context); + } + + public Sheet createSheet(Display display) { + final Sheet sheet = new Sheet(); + final CreoleContext context = new CreoleContext(); + for (CharSequence cs : display) { + final Stripe stripe = createStripe(cs.toString(), context, sheet.getLastStripe()); + if (stripe != null) { + sheet.add(stripe); + } + } + return sheet; + } +} diff --git a/src/net/sourceforge/plantuml/creole/CreoleStripeSimpleParser.java b/src/net/sourceforge/plantuml/creole/CreoleStripeSimpleParser.java new file mode 100644 index 000000000..8def0d65d --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/CreoleStripeSimpleParser.java @@ -0,0 +1,124 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.graphic.FontConfiguration; + +public class CreoleStripeSimpleParser { + + final private String line; + final private StripeStyle style; + + private final FontConfiguration fontConfiguration; + private final ISkinParam skinParam; + + public CreoleStripeSimpleParser(String line, FontConfiguration fontConfiguration, ISkinParam skinParam) { + this.fontConfiguration = fontConfiguration; + this.skinParam = skinParam; + + final Pattern p4 = Pattern.compile("^--([^-]*)--$"); + final Matcher m4 = p4.matcher(line); + if (m4.find()) { + this.line = m4.group(1); + this.style = new StripeStyle(StripeStyleType.HORIZONTAL_LINE, 0, '-'); + return; + } + + final Pattern p5 = Pattern.compile("^==([^=]*)==$"); + final Matcher m5 = p5.matcher(line); + if (m5.find()) { + this.line = m5.group(1); + this.style = new StripeStyle(StripeStyleType.HORIZONTAL_LINE, 0, '='); + return; + } + + final Pattern p6 = Pattern.compile("^__([^_]*)__$"); + final Matcher m6 = p6.matcher(line); + if (m6.find()) { + this.line = m6.group(1); + this.style = new StripeStyle(StripeStyleType.HORIZONTAL_LINE, 0, '_'); + return; + } + + final Pattern p7 = Pattern.compile("^\\.\\.([^\\.]*)\\.\\.$"); + final Matcher m7 = p7.matcher(line); + if (m7.find()) { + this.line = m7.group(1); + this.style = new StripeStyle(StripeStyleType.HORIZONTAL_LINE, 0, '.'); + return; + } + + final Pattern p1 = Pattern.compile("^(\\*+)([^*]+)$"); + final Matcher m1 = p1.matcher(line); + if (m1.find()) { + this.line = m1.group(2).trim(); + final int order = m1.group(1).length() - 1; + this.style = new StripeStyle(StripeStyleType.LIST_WITHOUT_NUMBER, order, '\0'); + return; + } + + final Pattern p2 = Pattern.compile("^(#+)([^*]+)$"); + final Matcher m2 = p2.matcher(line); + if (m2.find()) { + this.line = m2.group(2).trim(); + final int order = m2.group(1).length() - 1; + this.style = new StripeStyle(StripeStyleType.LIST_WITH_NUMBER, order, '\0'); + return; + } + + final Pattern p3 = Pattern.compile("^(=+)([^*]+)$"); + final Matcher m3 = p3.matcher(line); + if (m3.find()) { + this.line = m3.group(2).trim(); + final int order = m3.group(1).length() - 1; + this.style = new StripeStyle(StripeStyleType.HEADING, order, '\0'); + return; + } + + this.line = line; + this.style = new StripeStyle(StripeStyleType.NORMAL, 0, '\0'); + + } + + public Stripe createStripe(CreoleContext context) { + final StripeSimple result = new StripeSimple(fontConfiguration, style, context, skinParam); + result.analyzeAndAdd(line); + return result; + } + +} diff --git a/src/net/sourceforge/plantuml/creole/PSystemCreole.java b/src/net/sourceforge/plantuml/creole/PSystemCreole.java new file mode 100644 index 000000000..40f45be99 --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/PSystemCreole.java @@ -0,0 +1,86 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.creole; + +import java.awt.Font; +import java.awt.geom.Dimension2D; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.plantuml.AbstractPSystem; +import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.api.ImageDataSimple; +import net.sourceforge.plantuml.core.DiagramDescription; +import net.sourceforge.plantuml.core.DiagramDescriptionImpl; +import net.sourceforge.plantuml.core.ImageData; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public class PSystemCreole extends AbstractPSystem { + + private final List lines = new ArrayList(); + + public PSystemCreole() { + } + + public DiagramDescription getDescription() { + return new DiagramDescriptionImpl("(Creole)", getClass()); + } + + public void doCommandLine(String line) { + lines.add(line); + } + + public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException { + final Display display = new Display(lines); + final UFont font = new UFont("Serif", Font.PLAIN, 14); + final FontConfiguration fontConfiguration = new FontConfiguration(font, HtmlColorUtils.BLACK); + final Sheet sheet = new CreoleParser(fontConfiguration, null).createSheet(display); + final SheetBlock sheetBlock = new SheetBlock(sheet, null, new UStroke()); + final Dimension2D dim = TextBlockUtils.getDimension(sheetBlock); + final UGraphic ug = fileFormat.createUGraphic(new ColorMapperIdentity(), 1, dim, null, false); + // sheetBlock.drawU(ug.apply(new UTranslate(0, 10))); + sheetBlock.drawU(ug); + ug.writeImage(os, null, 96); + return new ImageDataSimple(dim); + } +} diff --git a/src/net/sourceforge/plantuml/creole/PSystemCreoleFactory.java b/src/net/sourceforge/plantuml/creole/PSystemCreoleFactory.java new file mode 100644 index 000000000..6ac2fb88e --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/PSystemCreoleFactory.java @@ -0,0 +1,59 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 3830 $ + * + */ +package net.sourceforge.plantuml.creole; + +import net.sourceforge.plantuml.command.PSystemBasicFactory; +import net.sourceforge.plantuml.core.DiagramType; + +public class PSystemCreoleFactory extends PSystemBasicFactory { + + public PSystemCreoleFactory() { + super(DiagramType.CREOLE); + } + + public PSystemCreole init(String startLine) { + if (getDiagramType() == DiagramType.CREOLE) { + return new PSystemCreole(); + } + + return null; + } + + @Override + public PSystemCreole executeLine(PSystemCreole system, String line) { + system.doCommandLine(line); + return system; + } + +} diff --git a/src/net/sourceforge/plantuml/creole/Position.java b/src/net/sourceforge/plantuml/creole/Position.java new file mode 100644 index 000000000..82c1f1492 --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/Position.java @@ -0,0 +1,122 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.ugraphic.MinMax; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class Position { + + private final double x; + private final double y; + private final Dimension2D dim; + + public Position(double x, double y, Dimension2D dim) { + this.x = x; + this.y = y; + this.dim = dim; + if (dim.getHeight() == 0) { + throw new IllegalArgumentException(); + } + if (dim.getWidth() == 0) { + throw new IllegalArgumentException(); + } + } + + @Override + public String toString() { + return "x=" + x + " y=" + y + " dim=" + dim; + } + + public Position align(double height) { + final double dy = height - dim.getHeight(); + return translateY(dy); + } + + // public final double getX() { + // return x; + // } + // + public final double getMinY() { + return y; + } + + public final double getMaxY() { + return y + getHeight(); + } + + // + // public final Dimension2D getDim() { + // return dim; + // } + // + public UGraphic translate(UGraphic ug) { + return ug.apply(new UTranslate(x, y)); + } + + public Position translateY(double dy) { + return new Position(x, y + dy, dim); + } + + public MinMax update(MinMax minMax) { + return minMax.addPoint(x + dim.getWidth(), y + dim.getHeight()); + } + + public void drawDebug(UGraphic ug) { + // ug = ug.apply(new UChangeColor(HtmlColorUtils.BLACK)).apply(new UChangeBackColor(HtmlColorUtils.LIGHT_GRAY)); + ug = ug.apply(new UChangeColor(HtmlColorUtils.BLACK)).apply(new UChangeBackColor(null)); + ug = ug.apply(new UTranslate(x, y)); + ug.draw(new URectangle(dim)); + } + + public double getHeight() { + return dim.getHeight(); + } + + public double getWidth() { + return dim.getWidth(); + } + + public UTranslate getTranslate() { + return new UTranslate(x, y); + } + +} diff --git a/src/net/sourceforge/plantuml/creole/Sea.java b/src/net/sourceforge/plantuml/creole/Sea.java new file mode 100644 index 000000000..4c1034d37 --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/Sea.java @@ -0,0 +1,125 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.awt.geom.Dimension2D; +import java.util.HashMap; +import java.util.Map; + +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.ugraphic.MinMax; + +public class Sea { + + private double currentX; + private final Map positions = new HashMap(); + private final StringBounder stringBounder; + + public Sea(StringBounder stringBounder) { + this.stringBounder = stringBounder; + } + + public void add(Atom atom) { + final Dimension2D dim = atom.calculateDimension(stringBounder); + final double y = 0; + final Position position = new Position(currentX, y, dim); + positions.put(atom, position); + currentX += dim.getWidth(); + } + + public Position getPosition(Atom atom) { + return positions.get(atom); + } + + public void doAlign() { + for (Map.Entry ent : new HashMap(positions).entrySet()) { + final Position pos = ent.getValue(); + final Atom atom = ent.getKey(); + final double height = atom.calculateDimension(stringBounder).getHeight(); + final Position newPos = pos.translateY(-height + atom.getStartingAltitude(stringBounder)); + positions.put(atom, newPos); + } + } + + public void translateMinYto(double newValue) { + final double delta = newValue - getMinY(); + for (Map.Entry ent : new HashMap(positions).entrySet()) { + final Position pos = ent.getValue(); + final Atom atom = ent.getKey(); + positions.put(atom, pos.translateY(delta)); + } + } + + public void exportAllPositions(Map destination) { + destination.putAll(positions); + } + + public double getMinY() { + if (positions.size() == 0) { + throw new IllegalStateException(); + } + double result = Double.MAX_VALUE; + for (Position pos : positions.values()) { + if (result > pos.getMinY()) { + result = pos.getMinY(); + } + } + return result; + } + + public double getMaxY() { + if (positions.size() == 0) { + throw new IllegalStateException(); + } + double result = -Double.MAX_VALUE; + for (Position pos : positions.values()) { + if (result < pos.getMaxY()) { + result = pos.getMaxY(); + } + } + return result; + } + + public double getHeight() { + return getMaxY() - getMinY(); + } + + public MinMax update(MinMax minMax) { + for (Position position : positions.values()) { + minMax = position.update(minMax); + } + return minMax; + } + +} diff --git a/src/net/sourceforge/plantuml/creole/Sheet.java b/src/net/sourceforge/plantuml/creole/Sheet.java new file mode 100644 index 000000000..63955bce0 --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/Sheet.java @@ -0,0 +1,59 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class Sheet implements Iterable { + + private final List stripes = new ArrayList(); + + public void add(Stripe stripe) { + stripes.add(stripe); + } + + public Iterator iterator() { + return stripes.iterator(); + } + + public Stripe getLastStripe() { + final int size = stripes.size(); + if (size == 0) { + return null; + } + return stripes.get(size - 1); + } +} diff --git a/src/net/sourceforge/plantuml/creole/SheetBlock.java b/src/net/sourceforge/plantuml/creole/SheetBlock.java new file mode 100644 index 000000000..e144bbf92 --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/SheetBlock.java @@ -0,0 +1,109 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.awt.geom.Dimension2D; +import java.util.LinkedHashMap; +import java.util.Map; + +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.ugraphic.MinMax; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UGraphicStencil; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public class SheetBlock implements TextBlock, Atom { + + private final Sheet sheet; + private final UStroke defaultStroke; + private final Stencil stencil; + private Map heights; + private Map positions; + private MinMax minMax; + + public SheetBlock(Sheet sheet, Stencil stencil, UStroke defaultStroke) { + this.sheet = sheet; + this.stencil = stencil; + this.defaultStroke = defaultStroke; + } + + private void initMap(StringBounder stringBounder) { + if (positions != null) { + return; + } + positions = new LinkedHashMap(); + heights = new LinkedHashMap(); + minMax = MinMax.getEmpty(true); + double y = 0; + for (Stripe stripe : sheet) { + if (stripe.getAtoms().size() == 0) { + continue; + } + final Sea sea = new Sea(stringBounder); + for (Atom atom : stripe.getAtoms()) { + sea.add(atom); + } + sea.doAlign(); + sea.translateMinYto(y); + sea.exportAllPositions(positions); + minMax = sea.update(minMax); + final double height = sea.getHeight(); + heights.put(stripe, height); + y += height; + } + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + initMap(stringBounder); + return minMax.getDimension(); + } + + public void drawU(UGraphic ug) { + if (stencil != null) { + ug = new UGraphicStencil(ug, stencil, defaultStroke); + } + for (Stripe stripe : sheet) { + for (Atom atom : stripe.getAtoms()) { + final Position position = positions.get(atom); + atom.drawU(position.translate(ug)); + // position.drawDebug(ug); + } + } + } + + public double getStartingAltitude(StringBounder stringBounder) { + return 0; + } +} diff --git a/src/net/sourceforge/plantuml/svek/UDrawable2.java b/src/net/sourceforge/plantuml/creole/Stencil.java similarity index 76% rename from src/net/sourceforge/plantuml/svek/UDrawable2.java rename to src/net/sourceforge/plantuml/creole/Stencil.java index 31c642e86..89316fdf7 100644 --- a/src/net/sourceforge/plantuml/svek/UDrawable2.java +++ b/src/net/sourceforge/plantuml/creole/Stencil.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,18 +28,17 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3836 $ + * Revision $Revision: 11025 $ * */ -package net.sourceforge.plantuml.svek; - -import java.awt.geom.Dimension2D; +package net.sourceforge.plantuml.creole; import net.sourceforge.plantuml.graphic.StringBounder; -import net.sourceforge.plantuml.skin.UDrawable; -public interface UDrawable2 extends UDrawable { +public interface Stencil { - Dimension2D getDimension(StringBounder stringBounder); + public double getStartingX(StringBounder stringBounder, double y); + + public double getEndingX(StringBounder stringBounder, double y); } diff --git a/src/net/sourceforge/plantuml/creole/Stripe.java b/src/net/sourceforge/plantuml/creole/Stripe.java new file mode 100644 index 000000000..13cb3ec26 --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/Stripe.java @@ -0,0 +1,42 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.util.List; + +public interface Stripe { + + public List getAtoms(); + +} diff --git a/src/net/sourceforge/plantuml/creole/StripeSimple.java b/src/net/sourceforge/plantuml/creole/StripeSimple.java new file mode 100644 index 000000000..8c5d37edb --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/StripeSimple.java @@ -0,0 +1,178 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.FontPosition; +import net.sourceforge.plantuml.graphic.FontStyle; +import net.sourceforge.plantuml.graphic.ImgValign; +import net.sourceforge.plantuml.ugraphic.Sprite; + +public class StripeSimple implements Stripe { + + final private List atoms = new ArrayList(); + private final List commands = new ArrayList(); + + private FontConfiguration fontConfiguration; + + final private StripeStyle style; + + final private ISkinParam skinParam; + + public StripeSimple(FontConfiguration fontConfiguration, StripeStyle style, CreoleContext context, + ISkinParam skinParam) { + this.fontConfiguration = fontConfiguration; + this.style = style; + this.skinParam = skinParam; + + // class Splitter + this.commands.add(CommandCreoleStyle.createCreole(FontStyle.BOLD)); + this.commands.add(CommandCreoleStyle.createLegacy(FontStyle.BOLD)); + this.commands.add(CommandCreoleStyle.createLegacyEol(FontStyle.BOLD)); + this.commands.add(CommandCreoleStyle.createCreole(FontStyle.ITALIC)); + this.commands.add(CommandCreoleStyle.createLegacy(FontStyle.ITALIC)); + this.commands.add(CommandCreoleStyle.createLegacyEol(FontStyle.ITALIC)); + this.commands.add(CommandCreoleStyle.createCreole(FontStyle.UNDERLINE)); + this.commands.add(CommandCreoleStyle.createLegacy(FontStyle.UNDERLINE)); + this.commands.add(CommandCreoleStyle.createLegacyEol(FontStyle.UNDERLINE)); + this.commands.add(CommandCreoleStyle.createCreole(FontStyle.STRIKE)); + this.commands.add(CommandCreoleStyle.createLegacy(FontStyle.STRIKE)); + this.commands.add(CommandCreoleStyle.createLegacyEol(FontStyle.STRIKE)); + this.commands.add(CommandCreoleStyle.createCreole(FontStyle.WAVE)); + this.commands.add(CommandCreoleStyle.createLegacy(FontStyle.WAVE)); + this.commands.add(CommandCreoleStyle.createLegacyEol(FontStyle.WAVE)); + this.commands.add(CommandCreoleStyle.createLegacy(FontStyle.BACKCOLOR)); + this.commands.add(CommandCreoleStyle.createLegacyEol(FontStyle.BACKCOLOR)); + this.commands.add(CommandCreoleSizeChange.create()); + this.commands.add(CommandCreoleSizeChange.createEol()); + this.commands.add(CommandCreoleColorChange.create()); + this.commands.add(CommandCreoleColorAndSizeChange.create()); + this.commands.add(CommandCreoleColorAndSizeChange.createEol()); + this.commands.add(CommandCreoleExposantChange.create(FontPosition.EXPOSANT)); + this.commands.add(CommandCreoleExposantChange.create(FontPosition.INDICE)); + this.commands.add(CommandCreoleImg.create()); + this.commands.add(CommandCreoleSprite.create()); + this.commands.add(CommandCreoleFontFamilyChange.create()); + this.commands.add(CommandCreoleFontFamilyChange.createEol()); + this.commands.add(CommandCreoleMonospaced.create()); + this.commands.add(CommandCreoleUrl.create(skinParam)); + + final Atom header = style.getHeader(fontConfiguration, context); + + if (header != null) { + atoms.add(header); + } + } + + public List getAtoms() { + return Collections.unmodifiableList(atoms); + } + + public FontConfiguration getActualFontConfiguration() { + return fontConfiguration; + } + + public void setActualFontConfiguration(FontConfiguration fontConfiguration) { + this.fontConfiguration = fontConfiguration; + } + + public void analyzeAndAdd(String line) { + if (line == null) { + throw new IllegalArgumentException(); + } + if (style.getType() == StripeStyleType.HEADING) { + atoms.add(AtomText.createHeading(line, fontConfiguration, style.getOrder())); + } else if (style.getType() == StripeStyleType.HORIZONTAL_LINE) { + atoms.add(CreoleHorizontalLine.create(fontConfiguration, line, style.getStyle(), skinParam)); + } else { + modifyStripe(line); + } + } + + public void addImage(String src) { + atoms.add(AtomImg.create(src, ImgValign.TOP, 0)); + } + + public void addUrl(Url url) { + atoms.add(AtomText.createUrl(url, fontConfiguration)); + } + + public void addSprite(String src) { + final Sprite sprite = skinParam.getSprite(src); + if (sprite != null) { + atoms.add(new AtomSprite(sprite.asTextBlock(fontConfiguration.getColor()))); + } + } + + private void modifyStripe(String line) { + final StringBuilder pending = new StringBuilder(); + + while (line.length() > 0) { + final Command cmd = searchCommand(line); + if (cmd == null) { + pending.append(line.charAt(0)); + line = line.substring(1); + } else { + addPending(pending); + line = cmd.executeAndGetRemaining(line, this); + } + } + addPending(pending); + } + + private void addPending(StringBuilder pending) { + if (pending.length() == 0) { + return; + } + atoms.add(AtomText.create(pending.toString(), fontConfiguration)); + pending.setLength(0); + } + + private Command searchCommand(String line) { + for (Command cmd : commands) { + final int i = cmd.matchingSize(line); + if (i != 0) { + return cmd; + } + } + return null; + } + +} diff --git a/src/net/sourceforge/plantuml/creole/StripeStyle.java b/src/net/sourceforge/plantuml/creole/StripeStyle.java new file mode 100644 index 000000000..9e9ad71e2 --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/StripeStyle.java @@ -0,0 +1,72 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import net.sourceforge.plantuml.graphic.FontConfiguration; + +public class StripeStyle { + + private final StripeStyleType type; + private final int order; + private final char style; + + public StripeStyle(StripeStyleType type, int order, char style) { + this.type = type; + this.order = order; + this.style = style; + } + + public final StripeStyleType getType() { + return type; + } + + public Atom getHeader(FontConfiguration fontConfiguration, CreoleContext context) { + if (type == StripeStyleType.LIST_WITHOUT_NUMBER) { + return new Bullet(fontConfiguration, order); + } + if (type == StripeStyleType.LIST_WITH_NUMBER) { + final int localNumber = context.getLocalNumber(order); + return AtomText.createListNumber(fontConfiguration, order, localNumber); + } + return null; + } + + public final int getOrder() { + return order; + } + + public char getStyle() { + return style; + } +} diff --git a/src/net/sourceforge/plantuml/creole/StripeStyleType.java b/src/net/sourceforge/plantuml/creole/StripeStyleType.java new file mode 100644 index 000000000..5cc9e16ce --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/StripeStyleType.java @@ -0,0 +1,38 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +public enum StripeStyleType { + NORMAL, HEADING, LIST_WITHOUT_NUMBER, LIST_WITH_NUMBER, HORIZONTAL_LINE +} diff --git a/src/net/sourceforge/plantuml/creole/StripeTable.java b/src/net/sourceforge/plantuml/creole/StripeTable.java new file mode 100644 index 000000000..f984e8175 --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/StripeTable.java @@ -0,0 +1,99 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import java.util.Collections; +import java.util.List; +import java.util.StringTokenizer; + +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public class StripeTable implements Stripe { + + static enum Mode { + HEADER, NORMAL + }; + + private FontConfiguration fontConfiguration; + final private ISkinParam skinParam; + final private AtomTable table; + final private Atom marged; + final private StripeStyle stripeStyle = new StripeStyle(StripeStyleType.NORMAL, 0, '\0'); + + public StripeTable(FontConfiguration fontConfiguration, ISkinParam skinParam, String line) { + this.fontConfiguration = fontConfiguration; + this.skinParam = skinParam; + this.table = new AtomTable(fontConfiguration.getColor()); + this.marged = new AtomWithMargin(table, 4, 4); + analyzeAndAddInternal(line, Mode.HEADER); + } + + public List getAtoms() { + return Collections. singletonList(marged); + } + + private static Atom asAtom(StripeSimple stripe) { + final Sheet sheet = new Sheet(); + sheet.add(stripe); + return new SheetBlock(sheet, null, new UStroke()); + } + + private void analyzeAndAddInternal(String line, Mode mode) { + table.newLine(); + for (final StringTokenizer st = new StringTokenizer(line, "|"); st.hasMoreTokens();) { + String v = st.nextToken(); + if (mode == Mode.HEADER && v.startsWith("=")) { + v = v.substring(1); + } + final StripeSimple cell = new StripeSimple(getFontConfiguration(mode), stripeStyle, new CreoleContext(), + skinParam); + cell.analyzeAndAdd(v); + table.addCell(asAtom(cell)); + } + } + + private FontConfiguration getFontConfiguration(Mode mode) { + if (mode == Mode.NORMAL) { + return fontConfiguration; + } + return fontConfiguration.bold(); + } + + public void analyzeAndAddNormal(String line) { + analyzeAndAddInternal(line, Mode.NORMAL); + } + +} diff --git a/src/net/sourceforge/plantuml/creole/Table.java b/src/net/sourceforge/plantuml/creole/Table.java new file mode 100644 index 000000000..7663ba069 --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/Table.java @@ -0,0 +1,39 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + + + +public class Table { +} diff --git a/src/net/sourceforge/plantuml/creole/UCreole.java b/src/net/sourceforge/plantuml/creole/UCreole.java new file mode 100644 index 000000000..296740162 --- /dev/null +++ b/src/net/sourceforge/plantuml/creole/UCreole.java @@ -0,0 +1,40 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11025 $ + * + */ +package net.sourceforge.plantuml.creole; + +import net.sourceforge.plantuml.ugraphic.UShape; + + +public interface UCreole extends UShape { +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/BlockMember.java b/src/net/sourceforge/plantuml/cucadiagram/BlockMember.java new file mode 100644 index 000000000..2eab5bccf --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/BlockMember.java @@ -0,0 +1,44 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 4749 $ + * + */ +package net.sourceforge.plantuml.cucadiagram; + +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.graphic.TextBlock; + +public interface BlockMember { + + public TextBlock asTextBlock(FontParam fontParam, ISkinParam skinParam); + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/BlockMemberImpl.java b/src/net/sourceforge/plantuml/cucadiagram/BlockMemberImpl.java new file mode 100644 index 000000000..4591b8067 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/BlockMemberImpl.java @@ -0,0 +1,63 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 4749 $ + * + */ +package net.sourceforge.plantuml.cucadiagram; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockLineBefore; +import net.sourceforge.plantuml.graphic.TextBlockUtils; + +public class BlockMemberImpl implements BlockMember { + + private final List members = new ArrayList(); + + public BlockMemberImpl(List members) { + this.members.addAll(members); + } + + public List getAll() { + return Collections.unmodifiableList(members); + } + + public TextBlock asTextBlock(FontParam fontParam, ISkinParam skinParam) { + return new TextBlockLineBefore(TextBlockUtils.withMargin((TextBlock) new MethodsOrFieldsArea(members, + fontParam, skinParam), 6, 4)); + } + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/Bodier.java b/src/net/sourceforge/plantuml/cucadiagram/Bodier.java new file mode 100644 index 000000000..527a9c95a --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/Bodier.java @@ -0,0 +1,154 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7755 $ + * + */ +package net.sourceforge.plantuml.cucadiagram; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.skin.VisibilityModifier; + +public class Bodier { + + private final List rawBody = new ArrayList(); + private final Set hides; + private final LeafType type; + private List methodsToDisplay; + private List fieldsToDisplay; + private final boolean manageModifier; + + public Bodier(LeafType type, Set hides) { + this.hides = hides; + this.type = type; + this.manageModifier = type == null ? false : type.manageModifier(); + } + + public void addFieldOrMethod(String s) { + // Empty cache + methodsToDisplay = null; + fieldsToDisplay = null; + rawBody.add(s); + } + + public boolean isBodyEnhanced() { + for (String s : rawBody) { + if (BodyEnhanced.isBlockSeparator(s)) { + return true; + } + } + return false; + } + + public BlockMember getBodyEnhanced() { + return new BlockMember() { + public TextBlock asTextBlock(FontParam fontParam, ISkinParam skinParam) { + final BodyEnhanced result = new BodyEnhanced(rawBody, fontParam, skinParam, manageModifier); + return result; + } + }; + } + + private LeafType getEntityType() { + return type; + } + + private boolean isMethod(String s) { + if (getEntityType() == LeafType.ANNOTATION || getEntityType() == LeafType.ABSTRACT_CLASS + || getEntityType() == LeafType.CLASS || getEntityType() == LeafType.INTERFACE + || getEntityType() == LeafType.ENUM) { + return StringUtils.isMethod(s); + } + return false; + } + + public List getMethodsToDisplay() { + if (methodsToDisplay == null) { + methodsToDisplay = new ArrayList(); + for (int i = 0; i < rawBody.size(); i++) { + final String s = rawBody.get(i); + if (isMethod(i, rawBody) == false) { + continue; + } + if (s.length() == 0 && methodsToDisplay.size() == 0) { + continue; + } + final Member m = new MemberImpl(s, true, manageModifier); + if (hides == null || hides.contains(m.getVisibilityModifier()) == false) { + methodsToDisplay.add(m); + } + } + removeFinalEmptyMembers(methodsToDisplay); + } + return Collections.unmodifiableList(methodsToDisplay); + } + + private boolean isMethod(int i, List rawBody) { + if (i > 0 && i < rawBody.size() - 1 && rawBody.get(i).length() == 0 && isMethod(rawBody.get(i - 1)) + && isMethod(rawBody.get(i + 1))) { + return true; + } + return isMethod(rawBody.get(i)); + } + + public List getFieldsToDisplay() { + if (fieldsToDisplay == null) { + fieldsToDisplay = new ArrayList(); + for (String s : rawBody) { + if (isMethod(s) == true) { + continue; + } + if (s.length() == 0 && fieldsToDisplay.size() == 0) { + continue; + } + final Member m = new MemberImpl(s, false, manageModifier); + if (hides == null || hides.contains(m.getVisibilityModifier()) == false) { + fieldsToDisplay.add(m); + } + } + removeFinalEmptyMembers(fieldsToDisplay); + } + return Collections.unmodifiableList(fieldsToDisplay); + } + + private void removeFinalEmptyMembers(List result) { + while (result.size() > 0 && result.get(result.size() - 1).getDisplay(false).trim().length() == 0) { + result.remove(result.size() - 1); + } + } +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/BodyEnhanced.java b/src/net/sourceforge/plantuml/cucadiagram/BodyEnhanced.java new file mode 100644 index 000000000..28e7cc227 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/BodyEnhanced.java @@ -0,0 +1,186 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7637 $ + * + */ +package net.sourceforge.plantuml.cucadiagram; + +import java.awt.geom.Dimension2D; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.SpriteContainer; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockLineBefore; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.graphic.TextBlockVertical2; +import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.ugraphic.UGraphic; + +public class BodyEnhanced implements TextBlock { + + private TextBlock area2; + private final FontConfiguration titleConfig; + private final List rawBody; + private final FontParam fontParam; + private final ISkinParam skinParam; + private final boolean lineFirst; + private final HorizontalAlignment align; + private final boolean manageHorizontalLine; + private final boolean manageModifier; + private final List urls = new ArrayList(); + + public BodyEnhanced(List rawBody, FontParam fontParam, ISkinParam skinParam, boolean manageModifier) { + this.rawBody = new ArrayList(rawBody); + this.fontParam = fontParam; + this.skinParam = skinParam; + + this.titleConfig = new FontConfiguration(skinParam.getFont(fontParam, null), new Rose().getFontColor(skinParam, + fontParam)); + this.lineFirst = true; + this.align = HorizontalAlignment.LEFT; + this.manageHorizontalLine = true; + this.manageModifier = manageModifier; + } + + public BodyEnhanced(Display display, FontParam fontParam, ISkinParam skinParam, HorizontalAlignment align, + Stereotype stereotype, boolean manageHorizontalLine, boolean manageModifier) { + this.rawBody = new ArrayList(); + for (CharSequence s : display) { + this.rawBody.add(s.toString()); + } + this.fontParam = fontParam; + this.skinParam = skinParam; + + this.titleConfig = new FontConfiguration(skinParam, fontParam, stereotype); + this.lineFirst = false; + this.align = align; + this.manageHorizontalLine = manageHorizontalLine; + this.manageModifier = manageModifier; + + } + + private TextBlock decorate(StringBounder stringBounder, TextBlock b, char separator, TextBlock title) { + if (separator == 0) { + return b; + } + if (title == null) { + return new TextBlockLineBefore(TextBlockUtils.withMargin(b, 6, 4), separator); + } + final Dimension2D dimTitle = title.calculateDimension(stringBounder); + final TextBlock raw = new TextBlockLineBefore(TextBlockUtils.withMargin(b, 6, 6, dimTitle.getHeight() / 2, 4), + separator, title); + return TextBlockUtils.withMargin(raw, 0, 0, dimTitle.getHeight() / 2, 0); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return getArea(stringBounder).calculateDimension(stringBounder); + } + + private TextBlock getArea(StringBounder stringBounder) { + if (area2 != null) { + return area2; + } + urls.clear(); + final List blocks = new ArrayList(); + + char separator = lineFirst ? '_' : 0; + TextBlock title = null; + List members = new ArrayList(); + for (String s : rawBody) { + if (manageHorizontalLine && isBlockSeparator(s)) { + blocks.add(decorate(stringBounder, new MethodsOrFieldsArea(members, fontParam, skinParam, align), + separator, title)); + separator = s.charAt(0); + title = getTitle(s, skinParam); + members = new ArrayList(); + } else { + final Member m = new MemberImpl(s, StringUtils.isMethod(s), manageModifier); + members.add(m); + if (m.getUrl() != null) { + urls.add(m.getUrl()); + } + } + } + blocks.add(decorate(stringBounder, new MethodsOrFieldsArea(members, fontParam, skinParam, align), separator, + title)); + + if (blocks.size() == 1) { + this.area2 = blocks.get(0); + } else { + this.area2 = new TextBlockVertical2(blocks, align); + } + + return area2; + } + + public static boolean isBlockSeparator(String s) { + if (s.startsWith("--") && s.endsWith("--")) { + return true; + } + if (s.startsWith("==") && s.endsWith("==")) { + return true; + } + if (s.startsWith("..") && s.endsWith("..")) { + return true; + } + if (s.startsWith("__") && s.endsWith("__")) { + return true; + } + return false; + } + + private TextBlock getTitle(String s, SpriteContainer spriteContainer) { + if (s.length() <= 4) { + return null; + } + s = s.substring(2, s.length() - 2).trim(); + return TextBlockUtils.create(Display.getWithNewlines(s), titleConfig, HorizontalAlignment.LEFT, + spriteContainer); + } + + public void drawU(UGraphic ug) { + getArea(ug.getStringBounder()).drawU(ug); + } + + public List getUrls() { + return Collections.unmodifiableList(urls); + } + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/BodyEnhanced2.java b/src/net/sourceforge/plantuml/cucadiagram/BodyEnhanced2.java new file mode 100644 index 000000000..229622b75 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/BodyEnhanced2.java @@ -0,0 +1,156 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7637 $ + * + */ +package net.sourceforge.plantuml.cucadiagram; + +import java.awt.geom.Dimension2D; +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.SpriteContainer; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockLineBefore; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.graphic.TextBlockVertical2; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UGraphic; + +public class BodyEnhanced2 implements TextBlock { + + private TextBlock area2; + private final FontConfiguration titleConfig; + private final Display rawBody2; + private final SpriteContainer spriteContainer; + + private final HorizontalAlignment align; + + // private final List urls = new ArrayList(); + + public BodyEnhanced2(Display rawBody, FontParam fontParam, SpriteContainer spriteContainer, + HorizontalAlignment align, UFont fontNote, HtmlColor fontColor) { + this.rawBody2 = rawBody; + // this.fontParam = fontParam; + this.spriteContainer = spriteContainer; + + this.titleConfig = new FontConfiguration(fontNote, fontColor); + this.align = align; + } + + private TextBlock decorate(StringBounder stringBounder, TextBlock b, char separator, TextBlock title) { + if (separator == 0) { + return b; + } + if (title == null) { + return new TextBlockLineBefore(TextBlockUtils.withMargin(b, 0, 4), separator); + } + final Dimension2D dimTitle = title.calculateDimension(stringBounder); + final TextBlock raw = new TextBlockLineBefore(TextBlockUtils.withMargin(b, 0, 6, dimTitle.getHeight() / 2, 4), + separator, title); + return TextBlockUtils.withMargin(raw, 0, 0, dimTitle.getHeight() / 2, 0); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return getArea(stringBounder).calculateDimension(stringBounder); + } + + private TextBlock getArea(StringBounder stringBounder) { + if (area2 != null) { + return area2; + } + // urls.clear(); + final List blocks = new ArrayList(); + + char separator = 0; + TextBlock title = null; + Display members2 = new Display(); + for (CharSequence s : rawBody2) { + if (isBlockSeparator(s.toString())) { + blocks.add(decorate(stringBounder, getTextBlock(members2, stringBounder), separator, title)); + separator = s.charAt(0); + title = getTitle(s.toString(), spriteContainer); + members2 = new Display(); + } else { + members2 = members2.add(s); + } + } + blocks.add(decorate(stringBounder, getTextBlock(members2, stringBounder), separator, title)); + + if (blocks.size() == 1) { + this.area2 = blocks.get(0); + } else { + this.area2 = new TextBlockVertical2(blocks, align); + } + + return area2; + } + + private TextBlock getTextBlock(Display members2, StringBounder stringBounder) { + final TextBlock result = TextBlockUtils.create(members2, titleConfig, align, spriteContainer); + return result; + } + + public static boolean isBlockSeparator(String s) { + if (s.startsWith("--") && s.endsWith("--")) { + return true; + } + if (s.startsWith("==") && s.endsWith("==")) { + return true; + } + if (s.startsWith("..") && s.endsWith("..")) { + return true; + } + if (s.startsWith("__") && s.endsWith("__")) { + return true; + } + return false; + } + + private TextBlock getTitle(String s, SpriteContainer spriteContainer) { + if (s.length() <= 4) { + return null; + } + s = s.substring(2, s.length() - 2).trim(); + return TextBlockUtils + .create(Display.getWithNewlines(s), titleConfig, HorizontalAlignment.LEFT, spriteContainer); + } + + public void drawU(UGraphic ug) { + getArea(ug.getStringBounder()).drawU(ug); + } + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/Code.java b/src/net/sourceforge/plantuml/cucadiagram/Code.java new file mode 100644 index 000000000..9ec752813 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/Code.java @@ -0,0 +1,138 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8770 $ + * + */ +package net.sourceforge.plantuml.cucadiagram; + +import java.util.Map; + +import net.sourceforge.plantuml.StringUtils; + +public class Code implements Comparable { + + private final String code; + + private Code(String code) { + if (code == null) { + throw new IllegalArgumentException(); + } + this.code = code; + } + + public static Code of(String code) { + if (code == null) { + return null; + } + return new Code(code); + } + + public final String getCode() { + return code; + } + + @Override + public String toString() { + return code; + } + + @Override + public int hashCode() { + return code.hashCode(); + } + + @Override + public boolean equals(Object obj) { + final Code other = (Code) obj; + return this.code.equals(other.code); + } + + public Code addSuffix(String suffix) { + return new Code(code + suffix); + } + + public int compareTo(Code other) { + return this.code.compareTo(other.code); + } + + public Code eventuallyRemoveStartingAndEndingDoubleQuote() { + return Code.of(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(code)); + } + + public final String getNamespace(Map leafs, String namespaceSeparator) { + String code = this.getCode(); + if (namespaceSeparator == null) { + throw new IllegalArgumentException(); + } + do { + final int x = code.lastIndexOf(namespaceSeparator); + if (x == -1) { + return null; + } + code = code.substring(0, x); + } while (leafs.containsKey(Code.of(code))); + return code; + } + + public final Code getShortName(Map leafs, String namespaceSeparator) { + if (namespaceSeparator == null) { + throw new IllegalArgumentException(); + } + final String code = this.getCode(); + final String namespace = getNamespace(leafs, namespaceSeparator); + if (namespace == null) { + return Code.of(code); + } + return Code.of(code.substring(namespace.length() + namespaceSeparator.length())); + } + + public final Code getFullyQualifiedCode(IGroup g, String namespaceSeparator) { + if (namespaceSeparator == null) { + throw new IllegalArgumentException(); + } + final String code = this.getCode(); + if (code.startsWith(namespaceSeparator)) { + return Code.of(code.substring(namespaceSeparator.length())); + } + if (code.contains(namespaceSeparator)) { + return Code.of(code); + } + if (EntityUtils.groupRoot(g)) { + return Code.of(code); + } + final String namespace = g.getNamespace(); + if (namespace == null) { + return Code.of(code); + } + return Code.of(namespace + namespaceSeparator + code); + } + +} diff --git a/src/net/sourceforge/plantuml/usecasediagram/UsecaseDiagram.java b/src/net/sourceforge/plantuml/cucadiagram/Code2.java similarity index 50% rename from src/net/sourceforge/plantuml/usecasediagram/UsecaseDiagram.java rename to src/net/sourceforge/plantuml/cucadiagram/Code2.java index 0fb21391d..aff801229 100644 --- a/src/net/sourceforge/plantuml/usecasediagram/UsecaseDiagram.java +++ b/src/net/sourceforge/plantuml/cucadiagram/Code2.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -27,38 +27,51 @@ * in the United States and other countries.] * * Original Author: Arnaud Roques + * + * Revision $Revision: 8770 $ * */ -package net.sourceforge.plantuml.usecasediagram; +package net.sourceforge.plantuml.cucadiagram; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.UmlDiagramType; -import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram; -import net.sourceforge.plantuml.cucadiagram.EntityType; -import net.sourceforge.plantuml.cucadiagram.IEntity; -import net.sourceforge.plantuml.cucadiagram.Rankdir; +public class Code2 { -public class UsecaseDiagram extends AbstractEntityDiagram { + private final Namespace namespace; + private final String unqualifiedCode; - public UsecaseDiagram() { - setRankdir(Rankdir.TOP_TO_BOTTOM); + private Code2(Namespace namespace, String unqualifiedCode) { + if (namespace == null) { + throw new IllegalArgumentException(); + } + if (unqualifiedCode == null) { + throw new IllegalArgumentException(); + } + this.namespace = namespace; + this.unqualifiedCode = unqualifiedCode; + } + + public final Namespace getNamespace() { + return namespace; + } + + public final String getUnqualifiedCode() { + return unqualifiedCode; + } + + public final String getFullQualifiedCode() { + if (namespace.isMain()) { + return unqualifiedCode; + } + return namespace.getNamespace() + "." + unqualifiedCode; } @Override - public IEntity getOrCreateClass(String code) { - if (code.startsWith("(") && code.endsWith(")")) { - return getOrCreateEntity(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(code), EntityType.USECASE); - } - if (code.startsWith(":") && code.endsWith(":")) { - return getOrCreateEntity(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(code), EntityType.ACTOR); - } - return getOrCreateEntity(code, EntityType.ACTOR); + public int hashCode() { + return namespace.hashCode() + 43 * unqualifiedCode.hashCode(); } - + @Override - public UmlDiagramType getUmlDiagramType() { - return UmlDiagramType.USECASE; + public boolean equals(Object obj) { + final Code2 other = (Code2) obj; + return this.unqualifiedCode.equals(other.unqualifiedCode) && this.namespace.equals(other.namespace); } - - } diff --git a/src/net/sourceforge/plantuml/cucadiagram/CucaDiagram.java b/src/net/sourceforge/plantuml/cucadiagram/CucaDiagram.java index 36ffbd9f0..17304079f 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/CucaDiagram.java +++ b/src/net/sourceforge/plantuml/cucadiagram/CucaDiagram.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,45 +28,36 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 7135 $ + * Revision $Revision: 11914 $ * */ package net.sourceforge.plantuml.cucadiagram; import java.awt.image.BufferedImage; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedHashMap; import java.util.List; -import java.util.ListIterator; import java.util.Map; import java.util.Set; -import java.util.TreeMap; import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.FileFormatOption; import net.sourceforge.plantuml.Log; +import net.sourceforge.plantuml.OptionFlags; import net.sourceforge.plantuml.UmlDiagram; import net.sourceforge.plantuml.UmlDiagramType; -import net.sourceforge.plantuml.cucadiagram.dot.CucaDiagramFileMaker; -import net.sourceforge.plantuml.cucadiagram.dot.CucaDiagramFileMakerBeta; -import net.sourceforge.plantuml.cucadiagram.dot.CucaDiagramPngMaker3; +import net.sourceforge.plantuml.api.ImageDataSimple; +import net.sourceforge.plantuml.core.ImageData; import net.sourceforge.plantuml.cucadiagram.dot.CucaDiagramTxtMaker; -import net.sourceforge.plantuml.cucadiagram.dot.DrawFile; -import net.sourceforge.plantuml.cucadiagram.dot.ICucaDiagramFileMaker; -import net.sourceforge.plantuml.png.PngSplitter; +import net.sourceforge.plantuml.cucadiagram.entity.EntityFactory; +import net.sourceforge.plantuml.hector.CucaDiagramFileMakerHectorB2; import net.sourceforge.plantuml.skin.VisibilityModifier; +import net.sourceforge.plantuml.svek.CucaDiagramFileMaker; import net.sourceforge.plantuml.svek.CucaDiagramFileMakerSvek; import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.xmi.CucaDiagramXmiMaker; @@ -76,189 +67,158 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, private int horizontalPages = 1; private int verticalPages = 1; - private final Map entities = new LinkedHashMap(); - // private final Map entities = new TreeMap(); - private final Map nbLinks = new HashMap(); + private final EntityFactory entityFactory = new EntityFactory(); + private IGroup currentGroup = entityFactory.getRootGroup(); - private final List links = new ArrayList(); - - private final Map groups = new LinkedHashMap(); - - private Group currentGroup = null; private Rankdir rankdir = Rankdir.TOP_TO_BOTTOM; private boolean visibilityModifierPresent; + public abstract IEntity getOrCreateLeaf(Code code, LeafType type); + + @Override public boolean hasUrl() { - for (IEntity entity : entities.values()) { - if (entity.getUrl() != null) { + for (IEntity entity : getGroups(true)) { + if (entity.hasUrl()) { + return true; + } + } + for (IEntity entity : getLeafs().values()) { + if (entity.hasUrl()) { + return true; + } + } + for (Link link : getLinks()) { + if (link.hasUrl()) { return true; } } return false; } - public IEntity getOrCreateEntity(String code, EntityType defaultType) { - IEntity result = entities.get(code); - if (result == null) { - result = createEntityInternal(code, code, defaultType, getCurrentGroup()); + // public ILeaf getOrCreateLeaf1(Code code, LeafType type) { + // return getOrCreateLeaf1Default(code, type); + // } + + final protected ILeaf getOrCreateLeafDefault(Code code, LeafType type) { + if (type == null) { + throw new IllegalArgumentException(); } + ILeaf result = getLeafs().get(code); + if (result == null) { + result = createLeafInternal(code, Display.getWithNewlines(code), type, getCurrentGroup()); + } + this.lastEntity = result; return result; } - public Entity createEntity(String code, String display, EntityType type) { - if (entities.containsKey(code)) { + public ILeaf createLeaf(Code code, Display display, LeafType type) { + if (getLeafs().containsKey(code)) { throw new IllegalArgumentException("Already known: " + code); } - return createEntityInternal(code, display, type, getCurrentGroup()); + return createLeafInternal(code, display, type, getCurrentGroup()); } - final protected Entity createEntityInternal(String code, String display, EntityType type, Group group) { + final protected ILeaf createLeafInternal(Code code, Display display, LeafType type, IGroup group) { if (display == null) { - display = code; + display = Display.getWithNewlines(code); } - final Entity entity = new Entity(code, display, type, group, getHides()); - entities.put(code, entity); - nbLinks.put(entity, 0); - return entity; + final ILeaf leaf = entityFactory.createLeaf(code, display, type, group, getHides()); + entityFactory.addLeaf(leaf); + this.lastEntity = leaf; + return leaf; } - public boolean entityExist(String code) { - return entities.containsKey(code); + public boolean leafExist(Code code) { + return getLeafs().containsKey(code); } - public void overideGroup(Group g, Entity proxy) { - if (groups.containsValue(g) == false) { - throw new IllegalArgumentException(); - } - if (entities.containsKey(proxy.getCode())) { - throw new IllegalArgumentException(); - } - if (entities.containsValue(proxy)) { - throw new IllegalArgumentException(); - } - for (final ListIterator it = links.listIterator(); it.hasNext();) { - final Link link = it.next(); - final Link newLink = link.mute(g, proxy); - if (newLink == null) { - it.remove(); - } else if (newLink != link) { - it.set(newLink); + final public Collection getChildrenGroups(IGroup parent) { + final Collection result = new ArrayList(); + for (IGroup gg : getGroups(false)) { + if (gg.getParentContainer() == parent) { + result.add(gg); } } - groups.remove(g.getCode()); - assert groups.containsValue(g) == false; - - for (final Iterator it = entities.values().iterator(); it.hasNext();) { - final IEntity ent = it.next(); - if (ent.getParent() == g) { - it.remove(); - } - } - entities.put(proxy.getCode(), proxy); - // if (proxy.getImageFile() != null) { - // proxy.addSubImage(proxy.getImageFile()); - // } - } - - final public Collection getChildrenGroups(Group parent) { - final Collection result = new ArrayList(); - for (Group g : groups.values()) { - if (g.getParent() == parent) { - result.add(g); - } - } - // assert parent == null || result.size() == - // parent.getChildren().size(); return Collections.unmodifiableCollection(result); } - public final Group getOrCreateGroup(String code, String display, String namespace, GroupType type, Group parent) { - final Group g = getOrCreateGroupInternal(code, display, namespace, type, parent); + public final IGroup getOrCreateGroup(Code code, Display display, String namespace, GroupType type, IGroup parent) { + final IGroup g = getOrCreateGroupInternal(code, display, namespace, type, parent); currentGroup = g; return g; } - protected final Group getOrCreateGroupInternal(String code, String display, String namespace, GroupType type, - Group parent) { - // if (entityExist(code)) { - // throw new IllegalArgumentException("code=" + code); - // } - Group g = groups.get(code); - if (g == null) { - g = new Group(code, display, namespace, type, parent); - groups.put(code, g); - - Entity entityGroup = entities.get(code); - if (entityGroup == null) { - entityGroup = new Entity("$$" + code, code, EntityType.GROUP, g, getHides()); - } else { - entityGroup.muteToCluster(g); - } - g.setEntityCluster(entityGroup); - nbLinks.put(entityGroup, 0); + protected final IGroup getOrCreateGroupInternal(Code code, Display display, String namespace, GroupType type, + IGroup parent) { + IGroup result = entityFactory.getGroups().get(code); + if (result != null) { + return result; } - return g; + if (entityFactory.getLeafs().containsKey(code)) { + result = entityFactory.muteToGroup(code, namespace, type, parent); + result.setDisplay(display); + } else { + result = entityFactory.createGroup(code, display, namespace, type, parent, getHides()); + } + entityFactory.addGroup(result); + return result; } - public final Group getCurrentGroup() { + public final IGroup getCurrentGroup() { return currentGroup; } - public final Group getGroup(String code) { - final Group p = groups.get(code); + public final IGroup getGroup(Code code) { + final IGroup p = entityFactory.getGroups().get(code); if (p == null) { - return null; + throw new IllegalArgumentException(); + // return null; } return p; } public void endGroup() { - if (currentGroup == null) { + if (EntityUtils.groupRoot(currentGroup)) { Log.error("No parent group"); return; } - currentGroup = currentGroup.getParent(); + currentGroup = currentGroup.getParentContainer(); } - public final boolean isGroup(String code) { - return groups.containsKey(code); + public final boolean isGroup(Code code) { + return entityFactory.getGroups().containsKey(code); } - public final Collection getGroups() { - return Collections.unmodifiableCollection(groups.values()); - } - - final public Map entities() { - if (getSkinParam().isSvek()) { - return Collections.unmodifiableMap(entities); + public final Collection getGroups(boolean withRootGroup) { + if (withRootGroup == false) { + return entityFactory.getGroups().values(); } - return Collections.unmodifiableMap(new TreeMap(entities)); + final Collection result = new ArrayList(); + result.add(getRootGroup()); + result.addAll(entityFactory.getGroups().values()); + return Collections.unmodifiableCollection(result); + } + + public IGroup getRootGroup() { + return entityFactory.getRootGroup(); + + } + + final public Map getLeafs() { + return entityFactory.getLeafs(); } final public void addLink(Link link) { - links.add(link); - inc(link.getEntity1()); - inc(link.getEntity2()); + entityFactory.addLink(link); } final protected void removeLink(Link link) { - final boolean ok = links.remove(link); - if (ok == false) { - throw new IllegalStateException(); - } - } - - private void inc(IEntity ent) { - if (ent == null) { - throw new IllegalArgumentException(); - } - nbLinks.put(ent, nbLinks.get(ent) + 1); + entityFactory.removeLink(link); } final public List getLinks() { - return Collections.unmodifiableList(links); + return entityFactory.getLinks(); } final public int getHorizontalPages() { @@ -277,15 +237,15 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, this.verticalPages = verticalPages; } - final public List createPng2(File pngFile) throws IOException, InterruptedException { - final CucaDiagramPngMaker3 maker = new CucaDiagramPngMaker3(this); - return maker.createPng(pngFile); - } - - final public void createPng2(OutputStream os) throws IOException { - final CucaDiagramPngMaker3 maker = new CucaDiagramPngMaker3(this); - maker.createPng(os); - } +// final public List createPng2(File pngFile) throws IOException, InterruptedException { +// final CucaDiagramPngMaker3 maker = new CucaDiagramPngMaker3(this); +// return maker.createPng(pngFile); +// } +// +// final public void createPng2(OutputStream os) throws IOException { +// final CucaDiagramPngMaker3 maker = new CucaDiagramPngMaker3(this); +// maker.createPng(os); +// } abstract protected List getDotStrings(); @@ -296,136 +256,64 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, result.add(s); } } + final String aspect = getPragma().getValue("aspect"); + if (aspect != null) { + result.add("aspect=" + aspect + ";"); + } return result.toArray(new String[result.size()]); } - // final public List createFiles(File suggestedFile, FileFormatOption - // fileFormatOption) throws IOException, - // InterruptedException { - // - // final FileFormat fileFormat = fileFormatOption.getFileFormat(); - // - // if (fileFormat == FileFormat.ATXT || fileFormat == FileFormat.UTXT) { - // return createFilesTxt(suggestedFile, fileFormat); - // } - // - // if (fileFormat.name().startsWith("XMI")) { - // return createFilesXmi(suggestedFile, fileFormat); - // } - // - // if (OptionFlags.getInstance().useJavaInsteadOfDot()) { - // return createPng2(suggestedFile); - // } - // if (getUmlDiagramType() == UmlDiagramType.COMPOSITE || (BETA && - // getUmlDiagramType() == UmlDiagramType.CLASS)) { - // final CucaDiagramFileMakerBeta maker = new - // CucaDiagramFileMakerBeta(this); - // return maker.createFile(suggestedFile, getDotStrings(), fileFormat); - // } - // final CucaDiagramFileMaker maker = new CucaDiagramFileMaker(this); - // return maker.createFile(suggestedFile, getDotStrings(), - // fileFormatOption); - // } - private void createFilesXmi(OutputStream suggestedFile, FileFormat fileFormat) throws IOException { final CucaDiagramXmiMaker maker = new CucaDiagramXmiMaker(this, fileFormat); maker.createFiles(suggestedFile); } - private List createFilesTxt(File suggestedFile, FileFormat fileFormat) throws IOException { - final CucaDiagramTxtMaker maker = new CucaDiagramTxtMaker(this, fileFormat); - return maker.createFiles(suggestedFile); - } - - public static boolean BETA; - @Override - public List exportDiagrams(File suggestedFile, FileFormatOption fileFormat) throws IOException, - InterruptedException { - if (suggestedFile.exists() && suggestedFile.isDirectory()) { - throw new IllegalArgumentException("File is a directory " + suggestedFile); - } - - final StringBuilder cmap = new StringBuilder(); - OutputStream os = null; - try { - os = new BufferedOutputStream(new FileOutputStream(suggestedFile)); - this.exportDiagram(os, cmap, 0, fileFormat); - } finally { - if (os != null) { - os.close(); - } - } - List result = Arrays.asList(suggestedFile); - - if (this.hasUrl() && cmap.length() > 0) { - exportCmap(suggestedFile, cmap); - } - - if (fileFormat.getFileFormat() == FileFormat.PNG) { - result = new PngSplitter(suggestedFile, this.getHorizontalPages(), this.getVerticalPages(), this - .getMetadata(), this.getDpi(fileFormat)).getFiles(); - } - return result; - - } - - @Override - final protected void exportDiagramInternal(OutputStream os, StringBuilder cmap, int index, - FileFormatOption fileFormatOption, List flashcodes) throws IOException { + final protected ImageData exportDiagramInternal(OutputStream os, int index, FileFormatOption fileFormatOption, + List flashcodes) throws IOException { final FileFormat fileFormat = fileFormatOption.getFileFormat(); + if (fileFormat == FileFormat.ATXT || fileFormat == FileFormat.UTXT) { try { createFilesTxt(os, index, fileFormat); } catch (Throwable t) { t.printStackTrace(new PrintStream(os)); } - return; + return new ImageDataSimple(); } if (fileFormat.name().startsWith("XMI")) { createFilesXmi(os, fileFormat); - return; - } - // - // if (OptionFlags.getInstance().useJavaInsteadOfDot()) { - // return createPng2(suggestedFile); - // } - if (getUmlDiagramType() == UmlDiagramType.COMPOSITE || (BETA && getUmlDiagramType() == UmlDiagramType.CLASS)) { - final CucaDiagramFileMakerBeta maker = new CucaDiagramFileMakerBeta(this); - try { - maker.createFile(os, getDotStrings(), fileFormat); - } catch (InterruptedException e) { - throw new IOException(e.toString()); - } - return; + return new ImageDataSimple(); } if (getUmlDiagramType() == UmlDiagramType.COMPOSITE) { - final CucaDiagramFileMakerBeta maker = new CucaDiagramFileMakerBeta(this); - try { - maker.createFile(os, getDotStrings(), fileFormat); - } catch (InterruptedException e) { - e.printStackTrace(); - throw new IOException(e.toString()); - } - return; + throw new UnsupportedOperationException(); } - final ICucaDiagramFileMaker maker; - if (getSkinParam().isSvek()) { - maker = new CucaDiagramFileMakerSvek(this, flashcodes); - } else { - maker = new CucaDiagramFileMaker(this, flashcodes); + + final CucaDiagramFileMaker maker = OptionFlags.USE_HECTOR ? new CucaDiagramFileMakerHectorB2(this) + : new CucaDiagramFileMakerSvek(this, flashcodes); + final ImageData result = maker.createFile(os, getDotStrings(), fileFormatOption); + + if (result == null) { + return new ImageDataSimple(); } - try { - final String cmapResult = maker.createFile(os, getDotStrings(), fileFormatOption); - if (cmapResult != null && cmap != null) { - cmap.append(cmapResult); - } - } catch (InterruptedException e) { - Log.error(e.toString()); - throw new IOException(e.toString()); + this.warningOrError = result.getWarningOrError(); + return result; + } + + private String warningOrError; + + @Override + public String getWarningOrError() { + final String generalWarningOrError = super.getWarningOrError(); + if (warningOrError == null) { + return generalWarningOrError; } + if (generalWarningOrError == null) { + return warningOrError; + } + return generalWarningOrError + "\n" + warningOrError; } private void createFilesTxt(OutputStream os, int index, FileFormat fileFormat) throws IOException { @@ -441,44 +329,33 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, this.rankdir = rankdir; } - public boolean isAutarkic(Group g) { - if (g.getType() == GroupType.PACKAGE) { + public boolean isAutarkic(IGroup g) { + if (g.getGroupType() == GroupType.PACKAGE) { return false; } - if (g.getType() == GroupType.INNER_ACTIVITY) { + if (g.getGroupType() == GroupType.INNER_ACTIVITY) { return true; } - if (g.getType() == GroupType.CONCURRENT_ACTIVITY) { + if (g.getGroupType() == GroupType.CONCURRENT_ACTIVITY) { return true; } - if (g.getType() == GroupType.CONCURRENT_STATE) { + if (g.getGroupType() == GroupType.CONCURRENT_STATE) { return true; } if (getChildrenGroups(g).size() > 0) { return false; } - for (Link link : links) { - final IEntity e1 = link.getEntity1(); - final IEntity e2 = link.getEntity2(); - if (e1.getParent() != g && e2.getParent() == g && e2.getType() != EntityType.GROUP) { + for (Link link : getLinks()) { + if (EntityUtils.isPureInnerLink3(g, link) == false) { return false; } - if (e2.getParent() != g && e1.getParent() == g && e1.getType() != EntityType.GROUP) { + } + for (ILeaf leaf : g.getLeafsDirect()) { + if (leaf.getEntityPosition() != EntityPosition.NORMAL) { return false; } - if (link.isAutolink(g)) { - continue; - } - if (e1.getType() == EntityType.GROUP && e2.getParent() == e1.getParent() && e1.getParent() == g) { - return false; - } - if (e2.getType() == EntityType.GROUP && e2.getParent() == e1.getParent() && e1.getParent() == g) { - return false; - } - } return true; - // return false; } private static boolean isNumber(String s) { @@ -524,16 +401,16 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, return "25"; } - final public boolean isEmpty(Group gToTest) { - for (Group g : groups.values()) { - if (g == gToTest) { + final public boolean isEmpty(IGroup gToTest) { + for (IEntity gg : getGroups(false)) { + if (gg == gToTest) { continue; } - if (g.getParent() == gToTest) { + if (gg.getParentContainer() == gToTest) { return false; } } - return gToTest.entities().size() == 0; + return gToTest.size() == 0; } public final boolean isVisibilityModifierPresent() { @@ -544,23 +421,10 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, this.visibilityModifierPresent = visibilityModifierPresent; } - private boolean isAutonom(Group g) { - for (Link link : links) { - final CrossingType type = g.getCrossingType(link); - if (type == CrossingType.CUT) { - return false; - } + public final boolean showPortion(EntityPortion portion, ILeaf entity) { + if (getSkinParam().strictUmlStyle() && portion == EntityPortion.CIRCLED_CHARACTER) { + return false; } - return true; - } - - public final void computeAutonomyOfGroups() { - for (Group g : groups.values()) { - g.setAutonom(isAutonom(g)); - } - } - - public final boolean showPortion(EntityPortion portion, IEntity entity) { boolean result = true; for (HideOrShow cmd : hideOrShows) { if (cmd.portion == portion && cmd.gender.contains(entity)) { @@ -584,6 +448,10 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, } } + public void hideOrShow(ILeaf leaf, boolean show) { + leaf.setRemoved(!show); + } + private final List hideOrShows = new ArrayList(); private final Set hides = new HashSet(); @@ -608,44 +476,84 @@ public abstract class CucaDiagram extends UmlDiagram implements GroupHierarchy, return Collections.unmodifiableSet(hides); } - public void clean() throws IOException { - for (Imaged entity : entities().values()) { - cleanTemporaryFiles(entity); - } - for (Imaged entity : getLinks()) { - cleanTemporaryFiles(entity); - } - for (Group g : groups.values()) { - final IEntity entity = g.getEntityCluster(); - if (entity != null) { - cleanTemporaryFiles(entity); - } - } - for (DrawFile f : ensureDeletes) { - f.deleteDrawFile(); - } - } - - private void cleanTemporaryFiles(Imaged entity) { - if (entity.getImageFile() != null) { - entity.getImageFile().deleteDrawFile(); - } - if (entity instanceof Entity) { - ((Entity) entity).cleanSubImage(); - } - } - - private final Set ensureDeletes = new HashSet(); - - public void ensureDelete(DrawFile imageFile) { - if (imageFile == null) { - throw new IllegalArgumentException(); - } - ensureDeletes.add(imageFile); - } - public ColorMapper getColorMapper() { return getSkinParam().getColorMapper(); } + final public boolean isStandalone(IEntity ent) { + for (final Link link : getLinks()) { + if (link.getEntity1() == ent || link.getEntity2() == ent) { + return false; + } + } + return true; + } + + final public Link getLastLink() { + final List links = getLinks(); + for (int i = links.size() - 1; i >= 0; i--) { + final Link link = links.get(i); + if (link.getEntity1().getEntityType() != LeafType.NOTE + && link.getEntity2().getEntityType() != LeafType.NOTE) { + return link; + } + } + return null; + } + + private ILeaf lastEntity = null; + + final public ILeaf getLastEntity() { + // for (final Iterator it = getLeafs().values().iterator(); it.hasNext();) { + // final ILeaf ent = it.next(); + // if (it.hasNext() == false) { + // return ent; + // } + // } + // return null; + return lastEntity; + } + + final public EntityFactory getEntityFactory() { + return entityFactory; + } + + public void applySingleStrategy() { + final MagmaList magmaList = new MagmaList(); + + for (IGroup g : getGroups(true)) { + final List standalones = new ArrayList(); + // final SingleStrategy singleStrategy = g.getSingleStrategy(); + + for (ILeaf ent : g.getLeafsDirect()) { + if (isStandalone(ent)) { + standalones.add(ent); + } + } + if (standalones.size() < 3) { + continue; + } + final Magma magma = new Magma(this, standalones); + magma.putInSquare(); + magmaList.add(magma); + + // for (Link link : singleStrategy.generateLinks(standalones)) { + // addLink(link); + // } + } + + for (IGroup g : getGroups(true)) { + final MagmaList magmas = magmaList.getMagmas(g); + if (magmas.size() < 3) { + continue; + } + magmas.putInSquare(); + } + + } + + public boolean isHideEmptyDescriptionForState() { + return false; + } + } diff --git a/src/net/sourceforge/plantuml/cucadiagram/Display.java b/src/net/sourceforge/plantuml/cucadiagram/Display.java new file mode 100644 index 000000000..44aede120 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/Display.java @@ -0,0 +1,223 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8218 $ + * + */ +package net.sourceforge.plantuml.cucadiagram; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.UrlBuilder; +import net.sourceforge.plantuml.UrlBuilder.ModeUrl; + +public class Display implements Iterable { + + private final List display = new ArrayList(); + + private Display(Display other) { + this.display.addAll(other.display); + } + + public Display() { + } + + public Display(List other) { + this.display.addAll(other); + } + + public Display underlined() { + final List result = new ArrayList(); + for (CharSequence line : display) { + result.add("" + line); + } + return new Display(result); + } + + @Override + public String toString() { + return display.toString(); + } + + @Override + public int hashCode() { + return display.hashCode(); + } + + @Override + public boolean equals(Object other) { + return this.display.equals(((Display) other).display); + } + + public Display addAll(Display other) { + final Display result = new Display(this); + result.display.addAll(other.display); + return result; + } + + public Display addFirst(CharSequence s) { + final Display result = new Display(this); + result.display.add(0, s); + return result; + } + + public Display add(CharSequence s) { + final Display result = new Display(this); + result.display.add(s); + return result; + } + + private boolean firstColumnRemovable() { + boolean allEmpty = true; + for (CharSequence s : this) { + if (s.length() == 0) { + continue; + } + allEmpty = false; + final char c = s.charAt(0); + if (c != ' ' && c != '\t') { + return false; + } + } + return allEmpty == false; + } + + public Display removeEmptyColumns() { + if (firstColumnRemovable() == false) { + return this; + } + final Display result = new Display(this); + do { + for (int i = 0; i < result.size(); i++) { + final CharSequence s = result.get(i); + if (s.length() > 0) { + result.display.set(i, s.toString().substring(1)); + } + } + } while (result.firstColumnRemovable()); + return result; + } + + public int size() { + return display.size(); + } + + public CharSequence get(int i) { + return display.get(i); + } + + public Iterator iterator() { + return Collections.unmodifiableList(display).iterator(); + } + + public Display subList(int i, int size) { + return new Display(display.subList(i, size)); + } + + public static Display asList(CharSequence... s) { + return new Display(Arrays.asList(s)); + } + + public static Display emptyList() { + return new Display(); + } + + public List as() { + return Collections.unmodifiableList(display); + } + + public static Display getWithNewlines(Code s) { + return getWithNewlines(s.getCode()); + } + + public static Display getWithNewlines(String s) { + if (s == null) { + return null; + } + final Display result = new Display(); + final StringBuilder current = new StringBuilder(); + for (int i = 0; i < s.length(); i++) { + final char c = s.charAt(i); + if (c == '\\' && i < s.length() - 1) { + final char c2 = s.charAt(i + 1); + i++; + if (c2 == 'n') { + result.display.add(current.toString()); + current.setLength(0); + } else if (c2 == 't') { + current.append('\t'); + } else if (c2 == '\\') { + current.append(c2); + } else { + current.append(c); + current.append(c2); + } + } else { + current.append(c); + } + } + result.display.add(current.toString()); + return result; + } + + public Url initUrl() { + if (this.size() == 0) { + return null; + } + final UrlBuilder urlBuilder = new UrlBuilder(null, ModeUrl.AT_START); + return urlBuilder.getUrl(this.get(0).toString().trim()); + } + + public Display removeUrl(Url url) { + if (url == null) { + return this; + } + final Display result = new Display(); + result.display.add(UrlBuilder.purgeUrl(this.get(0).toString())); + result.display.addAll(this.subList(1, this.size()).display); + return result; + } + + public boolean hasUrl() { + final UrlBuilder urlBuilder = new UrlBuilder(null, ModeUrl.ANYWHERE); + for (CharSequence s : this) { + if (urlBuilder.getUrl(s.toString()) != null) { + return true; + } + } + return false; + } + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/Entity.java b/src/net/sourceforge/plantuml/cucadiagram/Entity.java deleted file mode 100644 index e2b5e1cab..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/Entity.java +++ /dev/null @@ -1,341 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6923 $ - * - */ -package net.sourceforge.plantuml.cucadiagram; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.UniqueSequence; -import net.sourceforge.plantuml.Url; -import net.sourceforge.plantuml.cucadiagram.dot.DrawFile; -import net.sourceforge.plantuml.graphic.HtmlColor; -import net.sourceforge.plantuml.skin.VisibilityModifier; -import net.sourceforge.plantuml.svek.IEntityImage; - -public class Entity implements IEntity { - - private final String code; - private List display2; - - private final String uid; - private EntityType type; - - private Stereotype stereotype; - - private final List fields = new ArrayList(); - private final List methods = new ArrayList(); - private final Set hides; - - private Group container; - - private DrawFile imageFile; - private Url url2; - - private boolean top; - - public final boolean isTop() { - return top; - } - - public final void setTop(boolean top) { - this.top = top; - } - - public Entity(String code, String display, EntityType type, Group entityPackage, Set hides) { - this("cl", UniqueSequence.getValue(), code, display, type, entityPackage, hides); - } - - public Entity(String uid1, int uid2, String code, String display, EntityType type, Group entityPackage, - Set hides) { - this(uid1, uid2, code, StringUtils.getWithNewlines(display), type, entityPackage, hides); - } - - public Entity(String uid1, int uid2, String code, List display, EntityType type, Group entityPackage, - Set hides) { - if (code == null || code.length() == 0) { - throw new IllegalArgumentException(); - } - if (display == null /* || display.length() == 0 */) { - throw new IllegalArgumentException(); - } - this.hides = hides; - this.uid = StringUtils.getUid(uid1, uid2); - this.type = type; - this.code = code; - this.display2 = display; - this.container = entityPackage; - if (entityPackage != null && type != EntityType.GROUP) { - entityPackage.addEntity(this); - } - } - - public void setEntityPackage(Group entityPackage) { - if (entityPackage == null) { - throw new IllegalArgumentException(); - } - if (this.container != null) { - throw new IllegalStateException(); - } - this.container = entityPackage; - entityPackage.addEntity(this); - } - - public void addFieldOrMethod(String s) { - if (isMethod(s)) { - methods.add(new Member(s, true)); - } else { - addField(s); - } - } - - public void addField(String s) { - fields.add(new Member(s, false)); - } - - public void addField(Member s) { - fields.add(s); - } - - private boolean isMethod(String s) { - return s.contains("(") || s.contains(")"); - } - - public List getMethodsToDisplay() { - if (hides == null || hides.size() == 0) { - return Collections.unmodifiableList(methods); - } - final List result = new ArrayList(); - for (Member m : methods) { - if (hides.contains(m.getVisibilityModifier()) == false) { - result.add(m); - } - } - return Collections.unmodifiableList(result); - } - - public List getFieldsToDisplay() { - if (hides == null || hides.size() == 0) { - return Collections.unmodifiableList(fields); - } - final List result = new ArrayList(); - for (Member m : fields) { - if (hides.contains(m.getVisibilityModifier()) == false) { - result.add(m); - } - } - return Collections.unmodifiableList(result); - } - - public EntityType getType() { - return type; - } - - public void muteToType(EntityType newType) { - if (type != EntityType.ABSTRACT_CLASS && type != EntityType.CLASS && type != EntityType.ENUM - && type != EntityType.INTERFACE) { - throw new IllegalArgumentException("type=" + type); - } - if (newType != EntityType.ABSTRACT_CLASS && newType != EntityType.CLASS && newType != EntityType.ENUM - && newType != EntityType.INTERFACE) { - throw new IllegalArgumentException("newtype=" + newType); - } - this.type = newType; - } - - public String getCode() { - return code; - } - - public List getDisplay2() { - return display2; - } - - public void setDisplay2(String display) { - this.display2 = StringUtils.getWithNewlines(display); - } - - public void setDisplay2(List display) { - this.display2 = display; - } - - public String getUid() { - return uid; - } - - public Stereotype getStereotype() { - return stereotype; - } - - public final void setStereotype(Stereotype stereotype) { - this.stereotype = stereotype; - } - - public final Group getParent() { - return container; - } - - @Override - public String toString() { - if (type == EntityType.GROUP) { - return display2 + "(" + getType() + ")" + this.container; - } - return display2 + "(" + getType() + ") " + xposition + " " + getUid(); - } - - public void muteToCluster(Group newGroup) { - if (type == EntityType.GROUP) { - throw new IllegalStateException(); - } - this.type = EntityType.GROUP; - this.container = newGroup; - } - - public void moveTo(Group dest) { - this.container = dest; - dest.addEntity(this); - } - - public final DrawFile getImageFile() { - return imageFile; - } - - public final void setImageFile(DrawFile imageFile) { - this.imageFile = imageFile; - } - - private HtmlColor specificBackcolor; - - public HtmlColor getSpecificBackColor() { - return specificBackcolor; - } - - public void setSpecificBackcolor(HtmlColor color) { - this.specificBackcolor = color; - } - - public final Url getUrl() { - return url2; - } - - public final void setUrl(Url url) { - this.url2 = url; - } - - @Override - public int hashCode() { - return uid.hashCode(); - } - - @Override - public boolean equals(Object obj) { - if (obj == null) { - return false; - } - final IEntity other = (IEntity) obj; - return uid.equals(other.getUid()); - } - - private final Set subImages = new HashSet(); - - public void addSubImage(DrawFile subImage) { - if (subImage == null) { - throw new IllegalArgumentException(); - } - subImages.add(subImage); - } - - public void addSubImage(Entity other) { - subImages.addAll(other.subImages); - } - - public DrawFile getImageFile(File searched) throws IOException { - if (imageFile != null && imageFile.getPng().getCanonicalFile().equals(searched)) { - return imageFile; - } - for (DrawFile f : subImages) { - if (f.getPng().getCanonicalFile().equals(searched)) { - return f; - } - } - return null; - } - - public void cleanSubImage() { - for (DrawFile f : subImages) { - f.deleteDrawFile(); - } - } - - private boolean nearDecoration = false; - - public final boolean hasNearDecoration() { - return nearDecoration; - } - - public final void setNearDecoration(boolean nearDecoration) { - this.nearDecoration = nearDecoration; - } - - public int compareTo(IEntity other) { - return getUid().compareTo(other.getUid()); - } - - private int xposition; - - public int getXposition() { - return xposition; - } - - public void setXposition(int pos) { - xposition = pos; - } - - private IEntityImage svekImage; - - public final IEntityImage getSvekImage() { - return svekImage; - } - - public final void setSvekImage(IEntityImage svekImage) { - this.svekImage = svekImage; - } - -} diff --git a/src/net/sourceforge/plantuml/cucadiagram/EntityGender.java b/src/net/sourceforge/plantuml/cucadiagram/EntityGender.java index de49ecad2..8d6753c66 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/EntityGender.java +++ b/src/net/sourceforge/plantuml/cucadiagram/EntityGender.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/cucadiagram/EntityGenderUtils.java b/src/net/sourceforge/plantuml/cucadiagram/EntityGenderUtils.java index a1b70fa45..ec4835126 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/EntityGenderUtils.java +++ b/src/net/sourceforge/plantuml/cucadiagram/EntityGenderUtils.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -35,10 +35,10 @@ package net.sourceforge.plantuml.cucadiagram; public class EntityGenderUtils { - static public EntityGender byEntityType(final EntityType type) { + static public EntityGender byEntityType(final LeafType type) { return new EntityGender() { public boolean contains(IEntity test) { - return test.getType() == type; + return test.getEntityType() == type; } }; } @@ -46,7 +46,7 @@ public class EntityGenderUtils { static public EntityGender byEntityAlone(final IEntity entity) { return new EntityGender() { public boolean contains(IEntity test) { - return test == entity; + return test.getUid().equals(entity.getUid()); } }; } @@ -62,16 +62,16 @@ public class EntityGenderUtils { }; } - static public EntityGender byPackage(final Group group) { - if (group == null) { + static public EntityGender byPackage(final IGroup group) { + if (EntityUtils.groupRoot(group)) { throw new IllegalArgumentException(); } return new EntityGender() { public boolean contains(IEntity test) { - if (test.getParent() == null) { + if (EntityUtils.groupRoot(test.getParentContainer())) { return false; } - if (group == test.getParent()) { + if (group == test.getParentContainer()) { return true; } return false; diff --git a/src/net/sourceforge/plantuml/cucadiagram/EntityPortion.java b/src/net/sourceforge/plantuml/cucadiagram/EntityPortion.java index 2dac4464c..aa5e36bc5 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/EntityPortion.java +++ b/src/net/sourceforge/plantuml/cucadiagram/EntityPortion.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/cucadiagram/CrossingType.java b/src/net/sourceforge/plantuml/cucadiagram/EntityPosition.java similarity index 83% rename from src/net/sourceforge/plantuml/cucadiagram/CrossingType.java rename to src/net/sourceforge/plantuml/cucadiagram/EntityPosition.java index 10e6decc7..4d266f3b4 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/CrossingType.java +++ b/src/net/sourceforge/plantuml/cucadiagram/EntityPosition.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,12 +28,12 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4994 $ + * Revision $Revision: 8140 $ * */ package net.sourceforge.plantuml.cucadiagram; -public enum CrossingType { - INSIDE, OUTSIDE, CUT, TOUCH_OUTSIDE, TOUCH_INSIDE, SELF +public enum EntityPosition { + NORMAL, ENTRY_POINT, EXIT_POINT } diff --git a/src/net/sourceforge/plantuml/cucadiagram/EntityUtils.java b/src/net/sourceforge/plantuml/cucadiagram/EntityUtils.java index b98fce0d8..40d7febbe 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/EntityUtils.java +++ b/src/net/sourceforge/plantuml/cucadiagram/EntityUtils.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,126 +33,61 @@ */ package net.sourceforge.plantuml.cucadiagram; -import java.io.File; -import java.io.IOException; -import java.util.List; - -import net.sourceforge.plantuml.Url; -import net.sourceforge.plantuml.cucadiagram.dot.DrawFile; -import net.sourceforge.plantuml.graphic.HtmlColor; -import net.sourceforge.plantuml.svek.IEntityImage; public abstract class EntityUtils { - private static IEntity withNoParent(final IEntity ent) { - if (ent.getType() == EntityType.GROUP) { - throw new IllegalArgumentException(); + public static boolean groupRoot(IGroup g) { + if (g == null) { + throw new IllegalStateException(); } - return new IEntity() { - public List getFieldsToDisplay() { - return ent.getFieldsToDisplay(); - } - - public List getDisplay2() { - return ent.getDisplay2(); - } - - public Group getParent() { - return null; - } - - public Stereotype getStereotype() { - return ent.getStereotype(); - } - - public void setStereotype(Stereotype stereotype) { - ent.setStereotype(stereotype); - } - - public EntityType getType() { - return ent.getType(); - } - - public String getUid() { - return ent.getUid(); - } - - public Url getUrl() { - return ent.getUrl(); - } - - public List getMethodsToDisplay() { - return ent.getMethodsToDisplay(); - } - - public DrawFile getImageFile() { - return ent.getImageFile(); - } - - public HtmlColor getSpecificBackColor() { - return ent.getSpecificBackColor(); - } - - public void setSpecificBackcolor(HtmlColor specificBackcolor) { - throw new UnsupportedOperationException(); - } - - @Override - public int hashCode() { - return ent.hashCode(); - } - - @Override - public boolean equals(Object obj) { - return ent.equals(obj); - } - - @Override - public String toString() { - return "NoParent " + ent.toString(); - } - - public String getCode() { - return ent.getCode(); - } - - public DrawFile getImageFile(File searched) throws IOException { - return ent.getImageFile(searched); - } - - public boolean isTop() { - return ent.isTop(); - } - - public void setTop(boolean top) { - ent.setTop(top); - } - - public boolean hasNearDecoration() { - return ent.hasNearDecoration(); - } - - public void setNearDecoration(boolean nearDecoration) { - ent.setNearDecoration(nearDecoration); - } - - public int compareTo(IEntity other) { - return ent.compareTo(other); - } - - public int getXposition() { - return ent.getXposition(); - } - - public void setXposition(int pos) { - ent.setXposition(pos); - } - - public IEntityImage getSvekImage() { - return ent.getSvekImage(); - } - - }; + return g instanceof GroupRoot; } + private static boolean isParent(IGroup groupToBeTested, IGroup parentGroup) { + if (groupToBeTested.isGroup() == false) { + // Very strange! + return false; + } + if (groupToBeTested.isGroup() == false) { + throw new IllegalArgumentException(); + } + while (EntityUtils.groupRoot(groupToBeTested) == false) { + if (groupToBeTested == parentGroup) { + return true; + } + groupToBeTested = groupToBeTested.getParentContainer(); + if (groupToBeTested.isGroup() == false) { + throw new IllegalStateException(); + } + } + return false; + } + + public static boolean isPureInnerLink12(IGroup group, Link link) { + if (group.isGroup() == false) { + throw new IllegalArgumentException(); + } + final IEntity e1 = link.getEntity1(); + final IEntity e2 = link.getEntity2(); + final IGroup group1 = e1.getParentContainer(); + final IGroup group2 = e2.getParentContainer(); + if (isParent(group1, group) && isParent(group2, group)) { + return true; + } + return false; + } + + public static boolean isPureInnerLink3(IGroup group, Link link) { + if (group.isGroup() == false) { + throw new IllegalArgumentException(); + } + final IEntity e1 = link.getEntity1(); + final IEntity e2 = link.getEntity2(); + final IGroup group1 = e1.getParentContainer(); + final IGroup group2 = e2.getParentContainer(); + if (isParent(group2, group) == isParent(group1, group)) { + return true; + } + return false; + } } diff --git a/src/net/sourceforge/plantuml/cucadiagram/Group.java b/src/net/sourceforge/plantuml/cucadiagram/Group.java deleted file mode 100644 index 45183fb85..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/Group.java +++ /dev/null @@ -1,282 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6709 $ - * - */ -package net.sourceforge.plantuml.cucadiagram; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; - -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.UniqueSequence; -import net.sourceforge.plantuml.graphic.HtmlColor; - -public class Group { - - private final Map entities = new LinkedHashMap(); - private final String code; - private final String display; - private final String namespace; - - private HtmlColor backColor; - private final Group parent; - private final Collection children = new ArrayList(); - - private boolean dashed; - private boolean rounded; - private boolean bold; - - private final GroupType type; - - private IEntity entityCluster; - private boolean autonom = true; - private Rankdir rankdir = Rankdir.TOP_TO_BOTTOM; - - private final int cpt = UniqueSequence.getValue(); - - public Group(String code, String display, String namespace, GroupType type, Group parent) { - if (type == null) { - throw new IllegalArgumentException(); - } - if (code == null || code.length() == 0) { - throw new IllegalArgumentException(); - } - if (parent != null) { - if (parent.children.contains(this)) { - throw new IllegalArgumentException(); - } - parent.children.add(this); - } - this.namespace = namespace; - this.type = type; - this.parent = parent; - this.code = code; - this.display = display; - } - - @Override - public String toString() { - return "G[code=" + code + "]" + entities + " autonom=" + isAutonom(); - } - - public void addEntity(Entity entity) { - if (entities.containsValue(entity)) { - throw new IllegalArgumentException(); - } - if (entities.containsKey(entity.getCode())) { - throw new IllegalArgumentException(entity.getCode()); - } - if (entity.getType() == EntityType.GROUP) { - throw new IllegalArgumentException(); - } - entities.put(entity.getCode(), entity); - } - - // private boolean containsFully(Link link) { - // return contains((Entity) link.getEntity1()) && contains((Entity) - // link.getEntity2()); - // } - - public boolean contains(IEntity entity) { - if (entity == null) { - throw new IllegalArgumentException(); - } - if (entity.equals(entityCluster)) { - throw new IllegalArgumentException(); - } - if (entities.containsValue(entity)) { - return true; - } - for (Group child : getChildren()) { - if (child.contains(entity)) { - return true; - } - } - return false; - } - - public CrossingType getCrossingType(Link link) { - if (link.getEntity1().equals(this.entityCluster) && link.getEntity2().equals(this.entityCluster)) { - return CrossingType.SELF; - } - if (link.getEntity1().equals(this.entityCluster)) { - if (contains(link.getEntity2())) { - return CrossingType.TOUCH_INSIDE; - } - return CrossingType.TOUCH_OUTSIDE; - } - if (link.getEntity2().equals(this.entityCluster)) { - if (contains(link.getEntity1())) { - return CrossingType.TOUCH_INSIDE; - } - return CrossingType.TOUCH_OUTSIDE; - } - final boolean contains1 = contains(link.getEntity1()); - final boolean contains2 = contains(link.getEntity2()); - if (contains1 && contains2) { - return CrossingType.INSIDE; - } - if (contains1 == false && contains2 == false) { - return CrossingType.OUTSIDE; - } - return CrossingType.CUT; - - } - - public Map entities() { - return Collections.unmodifiableMap(entities); - } - - public String getCode() { - return code; - } - - public String getUid() { - return StringUtils.getUid(getUid1(), getUid2()); - } - - public String getUid1() { - return "cluster"; - } - - public int getUid2() { - return cpt; - } - - public final HtmlColor getBackColor() { - return backColor; - } - - public final void setBackColor(HtmlColor backColor) { - this.backColor = backColor; - } - - public final Group getParent() { - return parent; - } - - public final boolean isDashed() { - return dashed; - } - - public final void setDashed(boolean dashed) { - this.dashed = dashed; - } - - public final boolean isRounded() { - return rounded; - } - - public final void setRounded(boolean rounded) { - this.rounded = rounded; - } - - public GroupType getType() { - return type; - } - - public final IEntity getEntityCluster() { - if (entityCluster == null) { - throw new IllegalStateException(); - } - return entityCluster; - } - - public final void setEntityCluster(IEntity entityCluster) { - if (entityCluster == null) { - throw new IllegalArgumentException(); - } - this.entityCluster = entityCluster; - } - - // public boolean isEmpty() { - // return entities.isEmpty(); - // } - - public String getDisplay() { - return display; - } - - public boolean isBold() { - return bold; - } - - public void setBold(boolean bold) { - this.bold = bold; - } - - public void moveEntitiesTo(Group dest) { - for (IEntity ent : entities.values()) { - ((Entity) ent).moveTo(dest); - } - entities.clear(); - - } - - public String getNamespace() { - return namespace; - } - - public final Collection getChildren() { - return Collections.unmodifiableCollection(children); - } - - public final boolean isAutonom() { - return autonom; - } - - public final void setAutonom(boolean autonom) { - this.autonom = autonom; - } - - public final Rankdir getRankdir() { - return rankdir; - } - - public final void setRankdir(Rankdir rankdir) { - this.rankdir = rankdir; - } - - private String stereotype; - - public final void setStereotype(String stereotype) { - this.stereotype = stereotype; - } - - public final String getStereotype() { - return stereotype; - } - -} diff --git a/src/net/sourceforge/plantuml/cucadiagram/GroupHierarchy.java b/src/net/sourceforge/plantuml/cucadiagram/GroupHierarchy.java index ade2a5ed7..2da248829 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/GroupHierarchy.java +++ b/src/net/sourceforge/plantuml/cucadiagram/GroupHierarchy.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4192 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.cucadiagram; @@ -37,7 +37,7 @@ import java.util.Collection; public interface GroupHierarchy { - public Collection getChildrenGroups(Group parent); + public Collection getChildrenGroups(IGroup parent); - public boolean isEmpty(Group g); + public boolean isEmpty(IGroup g); } diff --git a/src/net/sourceforge/plantuml/cucadiagram/GroupPrinter.java b/src/net/sourceforge/plantuml/cucadiagram/GroupPrinter.java new file mode 100644 index 000000000..28e0b5de2 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/GroupPrinter.java @@ -0,0 +1,96 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8218 $ + * + */ +package net.sourceforge.plantuml.cucadiagram; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; + +public class GroupPrinter { + + private final PrintWriter pw; + + private GroupPrinter(PrintWriter pw) { + this.pw = pw; + } + + private void printGroup(IGroup group) { + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + pw.println(""); + if (group.getChildren().size() > 0) { + pw.println(""); + pw.println(""); + pw.println(""); + } + pw.println("
"); + pw.println(group.getCode()); + pw.println("
"); + if (group.getLeafsDirect().size() == 0) { + pw.println("No direct leaf"); + } else { + for (ILeaf leaf : group.getLeafsDirect()) { + pw.println("
    "); + printLeaf(leaf); + pw.println("
"); + } + } + pw.println("
"); + for (IGroup g : group.getChildren()) { + pw.println("
"); + printGroup(g); + pw.println("
"); + } + pw.println("
"); + } + + private void printLeaf(ILeaf leaf) { + pw.println("

  • " + leaf.getCode()); + } + + public static void print(File f, IGroup rootGroup) { + try { + final PrintWriter pw = new PrintWriter(f); + pw.println(""); + new GroupPrinter(pw).printGroup(rootGroup); + pw.println(""); + pw.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/GroupRoot.java b/src/net/sourceforge/plantuml/cucadiagram/GroupRoot.java new file mode 100644 index 000000000..18c5dae19 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/GroupRoot.java @@ -0,0 +1,261 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8218 $ + * + */ +package net.sourceforge.plantuml.cucadiagram; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.cucadiagram.entity.EntityFactory; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.USymbol; +import net.sourceforge.plantuml.svek.IEntityImage; +import net.sourceforge.plantuml.svek.PackageStyle; +import net.sourceforge.plantuml.svek.SingleStrategy; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public class GroupRoot implements IGroup { + + private final EntityFactory entityFactory; + + public GroupRoot(EntityFactory entityFactory) { + this.entityFactory = entityFactory; + } + + public Collection getLeafsDirect() { + final List result = new ArrayList(); + for (ILeaf ent : entityFactory.getLeafs().values()) { + if (ent.getParentContainer() == this) { + result.add(ent); + } + } + return Collections.unmodifiableCollection(result); + + } + + public boolean isGroup() { + return true; + } + + public Display getDisplay() { + throw new UnsupportedOperationException(); + + } + + public void setDisplay(Display display) { + throw new UnsupportedOperationException(); + + } + + public LeafType getEntityType() { + throw new UnsupportedOperationException(); + + } + + public String getUid() { + throw new UnsupportedOperationException(); + + } + + public Url getUrl99() { + return null; + + } + + public Stereotype getStereotype() { + throw new UnsupportedOperationException(); + + } + + public void setStereotype(Stereotype stereotype) { + throw new UnsupportedOperationException(); + + } + + public List getFieldsToDisplay() { + throw new UnsupportedOperationException(); + + } + + public List getMethodsToDisplay() { + throw new UnsupportedOperationException(); + + } + + public BlockMember getBody(PortionShower portionShower) { + throw new UnsupportedOperationException(); + + } + + public Code getCode() { + return Code.of("__ROOT__"); + } + + public BlockMember getMouseOver() { + throw new UnsupportedOperationException(); + } + + public void addFieldOrMethod(String s) { + throw new UnsupportedOperationException(); + + } + + public void mouseOver(String s) { + throw new UnsupportedOperationException(); + + } + + public void addUrl(Url url) { + throw new UnsupportedOperationException(); + + } + + public HtmlColor getSpecificBackColor() { + throw new UnsupportedOperationException(); + + } + + public void setSpecificBackcolor(HtmlColor specificBackcolor) { + throw new UnsupportedOperationException(); + + } + + public IGroup getParentContainer() { + return null; + } + + public boolean containsLeafRecurse(ILeaf entity) { + throw new UnsupportedOperationException(); + + } + + public Collection getChildren() { + final List result = new ArrayList(); + for (IGroup ent : entityFactory.getGroups().values()) { + if (ent.getParentContainer() == this) { + result.add(ent); + } + } + return Collections.unmodifiableCollection(result); + } + + public void moveEntitiesTo(IGroup dest) { + throw new UnsupportedOperationException(); + } + + public int size() { + throw new UnsupportedOperationException(); + } + + public GroupType getGroupType() { + return null; + } + + public String getNamespace() { + throw new UnsupportedOperationException(); + + } + + public boolean isAutonom() { + throw new UnsupportedOperationException(); + + } + + public void setAutonom(boolean autonom) { + throw new UnsupportedOperationException(); + + } + + public Rankdir getRankdir() { + throw new UnsupportedOperationException(); + + } + + public void setRankdir(Rankdir rankdir) { + throw new UnsupportedOperationException(); + + } + + public PackageStyle getPackageStyle() { + throw new UnsupportedOperationException(); + + } + + public void overideImage(IEntityImage img, LeafType state) { + throw new UnsupportedOperationException(); + } + + public boolean isHidden() { + return false; + } + + public USymbol getUSymbol() { + throw new UnsupportedOperationException(); + } + + public void setUSymbol(USymbol symbol) { + throw new UnsupportedOperationException(); + } + + public SingleStrategy getSingleStrategy() { + return SingleStrategy.SQUARRE; + } + + public boolean isRemoved() { + return false; + } + + public HtmlColor getSpecificLineColor() { + return null; + } + + public void setSpecificLineColor(HtmlColor specificLinecolor) { + throw new UnsupportedOperationException(); + } + + public UStroke getSpecificLineStroke() { + return null; + } + + public void setSpecificLineStroke(UStroke specificLineStoke) { + throw new UnsupportedOperationException(); + } + + public boolean hasUrl() { + return false; + } + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/GroupType.java b/src/net/sourceforge/plantuml/cucadiagram/GroupType.java index 9ba5fe1a6..2569cc1a1 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/GroupType.java +++ b/src/net/sourceforge/plantuml/cucadiagram/GroupType.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5190 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.cucadiagram; diff --git a/src/net/sourceforge/plantuml/cucadiagram/IEntity.java b/src/net/sourceforge/plantuml/cucadiagram/IEntity.java index 80d5f66f2..e9c2f3ee5 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/IEntity.java +++ b/src/net/sourceforge/plantuml/cucadiagram/IEntity.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,56 +28,60 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4749 $ + * Revision $Revision: 8218 $ * */ package net.sourceforge.plantuml.cucadiagram; -import java.io.File; -import java.io.IOException; import java.util.List; +import net.sourceforge.plantuml.Hideable; +import net.sourceforge.plantuml.LineConfigurable; +import net.sourceforge.plantuml.Removeable; import net.sourceforge.plantuml.SpecificBackcolorable; import net.sourceforge.plantuml.Url; -import net.sourceforge.plantuml.cucadiagram.dot.DrawFile; -import net.sourceforge.plantuml.svek.IEntityImage; +import net.sourceforge.plantuml.graphic.USymbol; -public interface IEntity extends Imaged, SpecificBackcolorable, Comparable { +public interface IEntity extends SpecificBackcolorable, Hideable, Removeable, LineConfigurable { - public Group getParent(); + public USymbol getUSymbol(); - public List getDisplay2(); + public void setUSymbol(USymbol symbol); - public EntityType getType(); + public LeafType getEntityType(); + + public Display getDisplay(); + + public IGroup getParentContainer(); + + public void setDisplay(Display display); public String getUid(); - public Url getUrl(); - - public List getFieldsToDisplay(); + public Url getUrl99(); public Stereotype getStereotype(); public void setStereotype(Stereotype stereotype); + public List getFieldsToDisplay(); + public List getMethodsToDisplay(); - public String getCode(); + public BlockMember getBody(PortionShower portionShower); - public DrawFile getImageFile(File searched) throws IOException; + public Code getCode(); - public boolean isTop(); + public BlockMember getMouseOver(); - public void setTop(boolean top); + public void addFieldOrMethod(String s); - public boolean hasNearDecoration(); + public void mouseOver(String s); - public void setNearDecoration(boolean nearDecoration); + public void addUrl(Url url); - public int getXposition(); + public boolean isGroup(); - public void setXposition(int pos); - - public IEntityImage getSvekImage(); + public boolean hasUrl(); } diff --git a/src/net/sourceforge/plantuml/cucadiagram/IGroup.java b/src/net/sourceforge/plantuml/cucadiagram/IGroup.java new file mode 100644 index 000000000..b000766b4 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/IGroup.java @@ -0,0 +1,71 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8218 $ + * + */ +package net.sourceforge.plantuml.cucadiagram; + +import java.util.Collection; + +import net.sourceforge.plantuml.svek.IEntityImage; +import net.sourceforge.plantuml.svek.PackageStyle; +import net.sourceforge.plantuml.svek.SingleStrategy; + +public interface IGroup extends IEntity { + + public boolean containsLeafRecurse(ILeaf entity); + + public Collection getLeafsDirect(); + + public Collection getChildren(); + + public void moveEntitiesTo(IGroup dest); + + public int size(); + + public GroupType getGroupType(); + + public String getNamespace(); + + public boolean isAutonom(); + + public void setAutonom(boolean autonom); + + public Rankdir getRankdir(); + + public void setRankdir(Rankdir rankdir); + + public PackageStyle getPackageStyle(); + + public void overideImage(IEntityImage img, LeafType state); + + public SingleStrategy getSingleStrategy(); +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/ILeaf.java b/src/net/sourceforge/plantuml/cucadiagram/ILeaf.java new file mode 100644 index 000000000..c6561727c --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/ILeaf.java @@ -0,0 +1,68 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 4749 $ + * + */ +package net.sourceforge.plantuml.cucadiagram; + +import net.sourceforge.plantuml.svek.IEntityImage; + +public interface ILeaf extends IEntity { + + public EntityPosition getEntityPosition(); + + public void setContainer(IGroup container); + + public boolean isTop(); + + public void setTop(boolean top); + + public boolean hasNearDecoration(); + + public void setNearDecoration(boolean nearDecoration); + + public int getXposition(); + + public void setXposition(int pos); + + public IEntityImage getSvekImage(); + + public String getGeneric(); + + public void muteToType(LeafType newType); + + public void setGeneric(String generic); + + public void setSvekImage(IEntityImage svekImage); + + public void setRemoved(boolean removed); + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/LeafType.java b/src/net/sourceforge/plantuml/cucadiagram/LeafType.java new file mode 100644 index 000000000..235e17398 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/LeafType.java @@ -0,0 +1,83 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11254 $ + * + */ +package net.sourceforge.plantuml.cucadiagram; + +import net.sourceforge.plantuml.StringUtils; + +public enum LeafType { + + EMPTY_PACKAGE, + + ABSTRACT_CLASS, CLASS, INTERFACE, ANNOTATION, LOLLIPOP, ENUM, ACTOR, USECASE, COMPONENT, CIRCLE_INTERFACE, NOTE, OBJECT, ASSOCIATION, + + BOUNDARY, CONTROL, ENTITY_DOMAIN, + + COMPONENT2, + + ARC_CIRCLE, + + ACTIVITY, BRANCH, SYNCHRO_BAR, CIRCLE_START, CIRCLE_END, POINT_FOR_ASSOCIATION, ACTIVITY_CONCURRENT, + + STATE, STATE_CONCURRENT, PSEUDO_STATE, STATE_CHOICE, STATE_FORK_JOIN, + + BLOCK, + + STILL_UNKNOWN; + + public static LeafType getLeafType(String arg0) { + arg0 = arg0.toUpperCase(); + if (arg0.startsWith("ABSTRACT")) { + return LeafType.ABSTRACT_CLASS; + } + return LeafType.valueOf(arg0); + } + + public boolean isLikeClass() { + return this == LeafType.ANNOTATION || this == LeafType.ABSTRACT_CLASS || this == LeafType.CLASS + || this == LeafType.INTERFACE || this == LeafType.ENUM; + } + + public String toHtml() { + final String html = toString().replace('_', ' ').toLowerCase(); + return StringUtils.capitalize(html); + } + + public boolean manageModifier() { + if (this == ANNOTATION || this == ABSTRACT_CLASS || this == CLASS || this == INTERFACE || this == ENUM + || this == OBJECT) { + return true; + } + return false; + } +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/Link.java b/src/net/sourceforge/plantuml/cucadiagram/Link.java index 90ee242cf..62f2aba7d 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/Link.java +++ b/src/net/sourceforge/plantuml/cucadiagram/Link.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,44 +28,43 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 7221 $ + * Revision $Revision: 11477 $ * */ package net.sourceforge.plantuml.cucadiagram; import java.awt.geom.Dimension2D; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.Hideable; +import net.sourceforge.plantuml.Removeable; +import net.sourceforge.plantuml.SpriteContainer; import net.sourceforge.plantuml.UniqueSequence; +import net.sourceforge.plantuml.Url; import net.sourceforge.plantuml.command.Position; -import net.sourceforge.plantuml.cucadiagram.dot.DrawFile; import net.sourceforge.plantuml.graphic.FontConfiguration; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; import net.sourceforge.plantuml.ugraphic.UFont; -public class Link implements Imaged { +public class Link implements Hideable, Removeable { final private IEntity cl1; final private IEntity cl2; - final private LinkType type; - final private String label; + private LinkType type; + final private Display label; private int length; final private String qualifier1; final private String qualifier2; final private String uid = "LNK" + UniqueSequence.getValue(); - private DrawFile imageFile; - - private List note; + private Display note; private Position notePosition; + private HtmlColor noteColor; private boolean invis = false; private double weight = 1.0; @@ -76,32 +75,43 @@ public class Link implements Imaged { private HtmlColor specificColor; private boolean constraint = true; private boolean inverted = false; + private LinkArrow linkArrow = LinkArrow.NONE; - public final boolean isInverted() { - return inverted; - } + private boolean opale; + private boolean horizontalSolitary; - public Link(IEntity cl1, IEntity cl2, LinkType type, String label, int length) { + private Url url; + + public Link(IEntity cl1, IEntity cl2, LinkType type, Display label, int length) { this(cl1, cl2, type, label, length, null, null, null, null, null); } - public Link(IEntity cl1, IEntity cl2, LinkType type, String label, int length, String qualifier1, + public Link(IEntity cl1, IEntity cl2, LinkType type, Display label, int length, String qualifier1, String qualifier2, String labeldistance, String labelangle) { this(cl1, cl2, type, label, length, qualifier1, qualifier2, labeldistance, labelangle, null); } - public Link(IEntity cl1, IEntity cl2, LinkType type, String label, int length, String qualifier1, + public Link(IEntity cl1, IEntity cl2, LinkType type, Display label, int length, String qualifier1, String qualifier2, String labeldistance, String labelangle, HtmlColor specificColor) { if (length < 1) { throw new IllegalArgumentException(); } - if (cl1 == null || cl2 == null) { + if (cl1 == null) { throw new IllegalArgumentException(); } + if (cl2 == null) { + throw new IllegalArgumentException(); + } + this.cl1 = cl1; this.cl2 = cl2; this.type = type; - this.label = label; + if (label == null) { + this.label = null; + } else { + this.url = label.initUrl(); + this.label = label.removeUrl(url); + } this.length = length; this.qualifier1 = qualifier1; this.qualifier2 = qualifier2; @@ -109,10 +119,10 @@ public class Link implements Imaged { this.labelangle = labelangle; this.specificColor = specificColor; if (qualifier1 != null) { - cl1.setNearDecoration(true); + ((ILeaf) cl1).setNearDecoration(true); } if (qualifier2 != null) { - cl2.setNearDecoration(true); + ((ILeaf) cl2).setNearDecoration(true); } } @@ -121,25 +131,28 @@ public class Link implements Imaged { // final int x = cl1.getXposition(); // cl2.setXposition(x-1); // } - final Link result = new Link(cl2, cl1, getType().getInv(), label, length, qualifier2, qualifier1, + final Link result = new Link(cl2, cl1, getType().getInversed(), label, length, qualifier2, qualifier1, labeldistance, labelangle, specificColor); result.inverted = true; return result; } - public Link getDashed() { - return new Link(cl1, cl2, getType().getDashed(), label, length, qualifier1, qualifier2, labeldistance, - labelangle, specificColor); + public void goDashed() { + type = type.getDashed(); } - public Link getDotted() { - return new Link(cl1, cl2, getType().getDotted(), label, length, qualifier1, qualifier2, labeldistance, - labelangle, specificColor); + public void goDotted() { + type = type.getDotted(); } - public Link getBold() { - return new Link(cl1, cl2, getType().getBold(), label, length, qualifier1, qualifier2, labeldistance, - labelangle, specificColor); + private boolean hidden = false; + + public void goHidden() { + this.hidden = true; + } + + public void goBold() { + type = type.getBold(); } public String getLabeldistance() { @@ -157,6 +170,9 @@ public class Link implements Imaged { } public final boolean isInvis() { + if (type.isInvisible()) { + return true; + } return invis; } @@ -164,26 +180,6 @@ public class Link implements Imaged { this.invis = invis; } - private static IEntity muteProxy(IEntity ent, Group g, IEntity proxy) { - if (ent.getParent() == g) { - return proxy; - } - return ent; - } - - public Link mute(Group g, Entity proxy) { - if (cl1.getParent() == g && cl1.getType() != EntityType.GROUP && cl2.getParent() == g - && cl2.getType() != EntityType.GROUP) { - return null; - } - final IEntity ent1 = muteProxy(cl1, g, proxy); - final IEntity ent2 = muteProxy(cl2, g, proxy); - if (this.cl1 == ent1 && this.cl2 == ent2) { - return this; - } - return new Link(ent1, ent2, getType(), label, length, qualifier1, qualifier2, labeldistance, labelangle); - } - public boolean isBetween(IEntity cl1, IEntity cl2) { if (cl1.equals(this.cl1) && cl2.equals(this.cl2)) { return true; @@ -214,7 +210,7 @@ public class Link implements Imaged { return type; } - public String getLabel() { + public Display getLabel() { return label; } @@ -242,73 +238,45 @@ public class Link implements Imaged { this.weight = weight; } - public final List getNote() { + public final Display getNote() { return note; } + public final HtmlColor getNoteColor() { + return noteColor; + } + public final Position getNotePosition() { return notePosition; } - public final void addNote(List note, Position position) { + public final void addNote(Display note, Position position, HtmlColor noteColor) { this.note = note; this.notePosition = position; + this.noteColor = noteColor; } - public final void addNote(String n, Position position) { - this.note = StringUtils.getWithNewlines(n); + public final void addNote(String n, Position position, HtmlColor noteColor) { + this.note = Display.getWithNewlines(n); this.notePosition = position; + this.noteColor = noteColor; } - public DrawFile getImageFile() { - return imageFile; - } - - public void setImageFile(DrawFile imageFile) { - this.imageFile = imageFile; - } - - public boolean isAutolink(Group g) { - if (getEntity1() == g.getEntityCluster() && getEntity2() == g.getEntityCluster()) { + public boolean isAutoLinkOfAGroup() { + if (getEntity1().isGroup() == false) { + return false; + } + if (getEntity2().isGroup() == false) { + return false; + } + if (getEntity1() == getEntity2()) { return true; } return false; } - public boolean isToEdgeLink(Group g) { - if (getEntity1().getParent() != g || getEntity2().getParent() != g) { - return false; - } - assert getEntity1().getParent() == g && getEntity2().getParent() == g; - if (isAutolink(g)) { - return false; - } - - if (getEntity2().getType() == EntityType.GROUP) { - assert getEntity1().getType() != EntityType.GROUP; - return true; - } - return false; - } - - public boolean isFromEdgeLink(Group g) { - if (getEntity1().getParent() != g || getEntity2().getParent() != g) { - return false; - } - assert getEntity1().getParent() == g && getEntity2().getParent() == g; - if (isAutolink(g)) { - return false; - } - - if (getEntity1().getType() == EntityType.GROUP) { - assert getEntity2().getType() != EntityType.GROUP; - return true; - } - return false; - } - - public boolean containsType(EntityType type) { - if (getEntity1().getType() == type || getEntity2().getType() == type) { + public boolean containsType(LeafType type) { + if (getEntity1().getEntityType() == type || getEntity2().getEntityType() == type) { return true; } return false; @@ -321,22 +289,33 @@ public class Link implements Imaged { return false; } - public double getMarginDecors1(StringBounder stringBounder, UFont fontQualif) { - final double q = getQualifierMargin(stringBounder, fontQualif, qualifier1); + public IEntity getOther(IEntity entity) { + if (getEntity1() == entity) { + return getEntity2(); + } + if (getEntity2() == entity) { + return getEntity1(); + } + throw new IllegalArgumentException(); + } + + public double getMarginDecors1(StringBounder stringBounder, UFont fontQualif, SpriteContainer spriteContainer) { + final double q = getQualifierMargin(stringBounder, fontQualif, qualifier1, spriteContainer); final LinkDecor decor = getType().getDecor1(); - return decor.getSize() + q; + return decor.getMargin() + q; } - public double getMarginDecors2(StringBounder stringBounder, UFont fontQualif) { - final double q = getQualifierMargin(stringBounder, fontQualif, qualifier2); + public double getMarginDecors2(StringBounder stringBounder, UFont fontQualif, SpriteContainer spriteContainer) { + final double q = getQualifierMargin(stringBounder, fontQualif, qualifier2, spriteContainer); final LinkDecor decor = getType().getDecor2(); - return decor.getSize() + q; + return decor.getMargin() + q; } - private double getQualifierMargin(StringBounder stringBounder, UFont fontQualif, String qualif) { + private double getQualifierMargin(StringBounder stringBounder, UFont fontQualif, String qualif, + SpriteContainer spriteContainer) { if (qualif != null) { - final TextBlock b = TextBlockUtils.create(Arrays.asList(qualif), new FontConfiguration(fontQualif, - HtmlColor.BLACK), HorizontalAlignement.LEFT); + final TextBlock b = TextBlockUtils.create(Display.asList(qualif), new FontConfiguration(fontQualif, + HtmlColorUtils.BLACK), HorizontalAlignment.LEFT, spriteContainer); final Dimension2D dim = b.calculateDimension(stringBounder); return Math.max(dim.getWidth(), dim.getHeight()); } @@ -348,7 +327,7 @@ public class Link implements Imaged { } public void setSpecificColor(String s) { - this.specificColor = HtmlColor.getColorIfValid(s); + this.specificColor = HtmlColorUtils.getColorIfValid(s); } public final boolean isConstraint() { @@ -359,23 +338,86 @@ public class Link implements Imaged { this.constraint = constraint; } - private boolean opale; - public void setOpale(boolean opale) { this.opale = opale; } - static public boolean onlyOneLink(IEntity ent, Collection links) { - int nb = 0; - for (Link link : links) { - if (link.contains(ent)) { - nb++; - } - if (nb > 1) { - return false; - } - } - return nb == 1; + public final void setHorizontalSolitary(boolean horizontalSolitary) { + this.horizontalSolitary = horizontalSolitary; } + public final boolean isHorizontalSolitary() { + return horizontalSolitary; + } + + public final LinkArrow getLinkArrow() { + if (inverted) { + return linkArrow.reverse(); + } + return linkArrow; + } + + public final void setLinkArrow(LinkArrow linkArrow) { + this.linkArrow = linkArrow; + } + + public final boolean isInverted() { + return inverted; + } + + public boolean hasEntryPoint() { + return (getEntity1().isGroup() == false && ((ILeaf) getEntity1()).getEntityPosition() != EntityPosition.NORMAL) + || (getEntity2().isGroup() == false && ((ILeaf) getEntity2()).getEntityPosition() != EntityPosition.NORMAL); + } + + public boolean hasTwoEntryPointsSameContainer() { + return getEntity1().isGroup() == false && getEntity2().isGroup() == false + && ((ILeaf) getEntity1()).getEntityPosition() != EntityPosition.NORMAL + && ((ILeaf) getEntity2()).getEntityPosition() != EntityPosition.NORMAL + && getEntity1().getParentContainer() == getEntity2().getParentContainer(); + } + + public Url getUrl() { + return url; + } + + public void setUrl(Url url) { + this.url = url; + } + + public boolean isHidden() { + return hidden || cl1.isHidden() || cl2.isHidden(); + } + + public boolean sameConnections(Link other) { + if (this.cl1 == other.cl1 && this.cl2 == other.cl2) { + return true; + } + if (this.cl1 == other.cl2 && this.cl2 == other.cl1) { + return true; + } + return false; + } + + public boolean isRemoved() { + return cl1.isRemoved() || cl2.isRemoved(); + } + + public boolean hasUrl() { + if (label != null && label.hasUrl()) { + return true; + } + return getUrl() != null; + } + + // private Group containerEntryPoint; + // + // public void setEntryPoint(Group container) { + // containerEntryPoint = container; + // } + // + // public Group getEntryPoint() { + // return containerEntryPoint; + // } + } diff --git a/src/net/sourceforge/plantuml/cucadiagram/LinkArrow.java b/src/net/sourceforge/plantuml/cucadiagram/LinkArrow.java new file mode 100644 index 000000000..8c17738b5 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/LinkArrow.java @@ -0,0 +1,50 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7601 $ + * + */ +package net.sourceforge.plantuml.cucadiagram; + +public enum LinkArrow { + + NONE, DIRECT_NORMAL, BACKWARD; + + public LinkArrow reverse() { + if (this == DIRECT_NORMAL) { + return BACKWARD; + } + if (this == BACKWARD) { + return DIRECT_NORMAL; + } + return NONE; + } + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/LinkDecor.java b/src/net/sourceforge/plantuml/cucadiagram/LinkDecor.java index f311ec9eb..f22e35e6e 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/LinkDecor.java +++ b/src/net/sourceforge/plantuml/cucadiagram/LinkDecor.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,60 +33,76 @@ */ package net.sourceforge.plantuml.cucadiagram; +import net.sourceforge.plantuml.svek.extremity.ExtremityFactory; +import net.sourceforge.plantuml.svek.extremity.ExtremityFactoryArrow; +import net.sourceforge.plantuml.svek.extremity.ExtremityFactoryArrowAndCircle; +import net.sourceforge.plantuml.svek.extremity.ExtremityFactoryCircle; +import net.sourceforge.plantuml.svek.extremity.ExtremityFactoryCircleConnect; +import net.sourceforge.plantuml.svek.extremity.ExtremityFactoryCircleCross; +import net.sourceforge.plantuml.svek.extremity.ExtremityFactoryDiamond; +import net.sourceforge.plantuml.svek.extremity.ExtremityFactoryParenthesis; +import net.sourceforge.plantuml.svek.extremity.ExtremityFactoryPlus; +import net.sourceforge.plantuml.svek.extremity.ExtremityFactorySquarre; +import net.sourceforge.plantuml.svek.extremity.ExtremityFactoryTriangle; + public enum LinkDecor { - NONE(2, false), EXTENDS(30, false), COMPOSITION(15, true), AGREGATION(15, false), ARROW(10, true), PLUS(0, false), SQUARRE(30, false); - - private final int size; + NONE(2, false, 0), EXTENDS(30, false, 2), COMPOSITION(15, true, 1.3), AGREGATION(15, false, 1.3), + + ARROW(10, true, 0.5), ARROW_TRIANGLE(10, true, 0.8), ARROW_AND_CIRCLE(10, false, 0.5), + + CIRCLE(0, false, 0.5), CIRCLE_CONNECT(0, false, 0.5), PARENTHESIS(0, false, 1.0), SQUARRE(0, false, 0.5), + + CIRCLE_CROSS(0, false, 0.5), PLUS(0, false, 1.5), SQUARRE_toberemoved(30, false, 0); + + private final double arrowSize; + private final int margin; private final boolean fill; - - private LinkDecor(int size, boolean fill) { - this.size = size; + + private LinkDecor(int margin, boolean fill, double arrowSize) { + this.margin = margin; this.fill = fill; + this.arrowSize = arrowSize; } - public String getArrowDot() { - if (this == LinkDecor.NONE) { - return "none"; - } else if (this == LinkDecor.EXTENDS) { - return "empty"; - } else if (this == LinkDecor.COMPOSITION) { - return "diamond"; - } else if (this == LinkDecor.AGREGATION) { - return "ediamond"; - } else if (this == LinkDecor.ARROW) { - return "open"; - } else if (this == LinkDecor.PLUS) { - return "odot"; - } else { - throw new UnsupportedOperationException(); - } + public int getMargin() { + return margin; } - public String getArrowDotSvek() { - if (this == LinkDecor.NONE) { - return "none"; - } else if (this == LinkDecor.EXTENDS) { - return "empty"; - } else if (this == LinkDecor.COMPOSITION) { - return "diamond"; - } else if (this == LinkDecor.AGREGATION) { - return "ediamond"; - } else if (this == LinkDecor.ARROW) { - return "open"; - } else if (this == LinkDecor.PLUS) { - return "empty"; - } else { - throw new UnsupportedOperationException(); - } - } - - public int getSize() { - return size; - } - public boolean isFill() { return fill; } + public double getArrowSize() { + return arrowSize; + } + + public ExtremityFactory getExtremityFactory() { + if (this == LinkDecor.PLUS) { + return new ExtremityFactoryPlus(); + } else if (this == LinkDecor.ARROW_TRIANGLE) { + return new ExtremityFactoryTriangle(); + } else if (this == LinkDecor.CIRCLE_CROSS) { + return new ExtremityFactoryCircleCross(); + } else if (this == LinkDecor.ARROW) { + return new ExtremityFactoryArrow(); + } else if (this == LinkDecor.ARROW_AND_CIRCLE) { + return new ExtremityFactoryArrowAndCircle(); + } else if (this == LinkDecor.AGREGATION) { + return new ExtremityFactoryDiamond(false); + } else if (this == LinkDecor.COMPOSITION) { + return new ExtremityFactoryDiamond(true); + } else if (this == LinkDecor.CIRCLE) { + return new ExtremityFactoryCircle(); + } else if (this == LinkDecor.SQUARRE) { + return new ExtremityFactorySquarre(); + } else if (this == LinkDecor.PARENTHESIS) { + return new ExtremityFactoryParenthesis(); + } else if (this == LinkDecor.CIRCLE_CONNECT) { + return new ExtremityFactoryCircleConnect(); + } + + return null; + } + } diff --git a/src/net/sourceforge/plantuml/cucadiagram/LinkHat.java b/src/net/sourceforge/plantuml/cucadiagram/LinkHat.java new file mode 100644 index 000000000..510269461 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/LinkHat.java @@ -0,0 +1,52 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 4604 $ + * + */ +package net.sourceforge.plantuml.cucadiagram; + + +public enum LinkHat { + + NONE /*, SQUARRE, CIRCLE, CIRCLE_CONNECT; + + public ExtremityFactory getExtremityFactory() { + if (this == LinkHat.CIRCLE) { + return new ExtremityFactoryCircle(); + } + if (this == LinkHat.CIRCLE_CONNECT) { + return new ExtremityFactoryCircleConnect(); + } + return null; + } + */ + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/LinkMiddleDecor.java b/src/net/sourceforge/plantuml/cucadiagram/LinkMiddleDecor.java new file mode 100644 index 000000000..65307f3a2 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/LinkMiddleDecor.java @@ -0,0 +1,61 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 4604 $ + * + */ +package net.sourceforge.plantuml.cucadiagram; + +import net.sourceforge.plantuml.svek.extremity.MiddleCircleCircledMode; +import net.sourceforge.plantuml.svek.extremity.MiddleFactory; +import net.sourceforge.plantuml.svek.extremity.MiddleFactoryCircle; +import net.sourceforge.plantuml.svek.extremity.MiddleFactoryCircleCircled; + +public enum LinkMiddleDecor { + + NONE, CIRCLE, CIRCLE_CIRCLED, CIRCLE_CIRCLED1, CIRCLE_CIRCLED2; + + public MiddleFactory getMiddleFactory() { + if (this == CIRCLE) { + return new MiddleFactoryCircle(); + } + if (this == CIRCLE_CIRCLED) { + return new MiddleFactoryCircleCircled(MiddleCircleCircledMode.BOTH); + } + if (this == CIRCLE_CIRCLED1) { + return new MiddleFactoryCircleCircled(MiddleCircleCircledMode.MODE1); + } + if (this == CIRCLE_CIRCLED2) { + return new MiddleFactoryCircleCircled(MiddleCircleCircledMode.MODE2); + } + throw new UnsupportedOperationException(); + } + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/LinkStyle.java b/src/net/sourceforge/plantuml/cucadiagram/LinkStyle.java index 7187a9bf9..4e25c9c86 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/LinkStyle.java +++ b/src/net/sourceforge/plantuml/cucadiagram/LinkStyle.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -35,6 +35,8 @@ package net.sourceforge.plantuml.cucadiagram; public enum LinkStyle { - NORMAL, DASHED, INTERFACE_PROVIDER, INTERFACE_USER, DOTTED, BOLD; + NORMAL, DASHED, DOTTED, BOLD, INVISIBLE, + + DOUBLE_tobedone, __toremove_INTERFACE_PROVIDER, __toremove_INTERFACE_USER; } diff --git a/src/net/sourceforge/plantuml/cucadiagram/LinkType.java b/src/net/sourceforge/plantuml/cucadiagram/LinkType.java index 75e94a39e..018c983e4 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/LinkType.java +++ b/src/net/sourceforge/plantuml/cucadiagram/LinkType.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -37,18 +37,25 @@ import net.sourceforge.plantuml.ugraphic.UStroke; public class LinkType { + private final LinkHat hat1; private final LinkDecor decor1; private final LinkStyle style; private final LinkDecor decor2; + private final LinkHat hat2; + private final LinkMiddleDecor middleDecor; public LinkType(LinkDecor decor1, LinkDecor decor2) { - this(decor1, LinkStyle.NORMAL, decor2); + this(LinkHat.NONE, decor1, decor2, LinkHat.NONE); } - public boolean contains(LinkDecor decors) { - return decor1 == decors || decor2 == decors; + public LinkType(LinkHat hat1, LinkDecor decor1, LinkDecor decor2, LinkHat hat2) { + this(hat1, decor1, LinkStyle.NORMAL, LinkMiddleDecor.NONE, decor2, hat2); } + // public boolean contains(LinkDecor decors) { + // return decor1 == decors || decor2 == decors; + // } + @Override public String toString() { return decor1 + "-" + style + "-" + decor2; @@ -65,10 +72,14 @@ public class LinkType { return this.decor1 == other.decor1 && this.decor2 == other.decor2 && this.style == other.style; } - private LinkType(LinkDecor decor1, LinkStyle style, LinkDecor decor2) { + private LinkType(LinkHat hat1, LinkDecor decor1, LinkStyle style, LinkMiddleDecor middleDecor, LinkDecor decor2, + LinkHat hat2) { this.decor1 = decor1; this.style = style; this.decor2 = decor2; + this.middleDecor = middleDecor; + this.hat1 = hat1; + this.hat2 = hat2; } public boolean isDashed() { @@ -83,97 +94,94 @@ public class LinkType { return style == LinkStyle.BOLD; } + public boolean isInvisible() { + return style == LinkStyle.INVISIBLE; + } + public LinkType getDashed() { - return new LinkType(decor1, LinkStyle.DASHED, decor2); + return new LinkType(hat1, decor1, LinkStyle.DASHED, middleDecor, decor2, hat2); } public LinkType getDotted() { - return new LinkType(decor1, LinkStyle.DOTTED, decor2); + return new LinkType(hat1, decor1, LinkStyle.DOTTED, middleDecor, decor2, hat2); } public LinkType getBold() { - return new LinkType(decor1, LinkStyle.BOLD, decor2); + return new LinkType(hat1, decor1, LinkStyle.BOLD, middleDecor, decor2, hat2); } public LinkType getInterfaceProvider() { - return new LinkType(decor1, LinkStyle.INTERFACE_PROVIDER, decor2); + return new LinkType(hat1, decor1, LinkStyle.__toremove_INTERFACE_PROVIDER, middleDecor, decor2, hat2); } public LinkType getInterfaceUser() { - return new LinkType(decor1, LinkStyle.INTERFACE_USER, decor2); + return new LinkType(hat1, decor1, LinkStyle.__toremove_INTERFACE_USER, middleDecor, decor2, hat2); } - public LinkType getInv() { - return new LinkType(decor2, style, decor1); + public LinkType getInversed() { + return new LinkType(hat2, decor2, style, middleDecor, decor1, hat1); } - public String getSpecificDecoration() { - final StringBuilder sb = new StringBuilder(); + public LinkType withMiddleCircle() { + return new LinkType(hat1, decor1, style, LinkMiddleDecor.CIRCLE, decor2, hat2); + } - if (decor1 == LinkDecor.NONE && decor2 != LinkDecor.NONE) { - sb.append("dir=back,"); - } - if (decor1 != LinkDecor.NONE && decor2 != LinkDecor.NONE) { - sb.append("dir=both,"); - } + public LinkType withMiddleCircleCircled() { + return new LinkType(hat1, decor1, style, LinkMiddleDecor.CIRCLE_CIRCLED, decor2, hat2); + } - sb.append("arrowtail="); - sb.append(decor2.getArrowDot()); - sb.append(",arrowhead="); - sb.append(decor1.getArrowDot()); + public LinkType withMiddleCircleCircled1() { + return new LinkType(hat1, decor1, style, LinkMiddleDecor.CIRCLE_CIRCLED1, decor2, hat2); + } - if (decor1 == LinkDecor.EXTENDS || decor2 == LinkDecor.EXTENDS) { - sb.append(",arrowsize=2"); - } - if (decor1 == LinkDecor.PLUS || decor2 == LinkDecor.PLUS) { - sb.append(",arrowsize=1.5"); - } + public LinkType withMiddleCircleCircled2() { + return new LinkType(hat1, decor1, style, LinkMiddleDecor.CIRCLE_CIRCLED2, decor2, hat2); + } - if (style == LinkStyle.DASHED) { - sb.append(",style=dashed"); - } - if (style == LinkStyle.DOTTED) { - sb.append(",style=dotted,"); - } - if (style == LinkStyle.BOLD) { - sb.append(",style=bold,"); - } - - return sb.toString(); + public LinkType getInvisible() { + return new LinkType(hat1, decor1, LinkStyle.INVISIBLE, middleDecor, decor2, hat2); } public String getSpecificDecorationSvek() { final StringBuilder sb = new StringBuilder(); - if (decor1 == LinkDecor.NONE && decor2 != LinkDecor.NONE) { - sb.append("dir=back,"); - } - if (decor1 != LinkDecor.NONE && decor2 != LinkDecor.NONE) { + final boolean isEmpty1 = decor1 == LinkDecor.NONE && hat1 == LinkHat.NONE; + final boolean isEmpty2 = decor2 == LinkDecor.NONE && hat2 == LinkHat.NONE; + + if (isEmpty1 && isEmpty2) { + sb.append("arrowtail=none"); + sb.append(",arrowhead=none"); + } else if (isEmpty1 == false && isEmpty2 == false) { sb.append("dir=both,"); + sb.append("arrowtail=empty"); + sb.append(",arrowhead=empty"); + } else if (isEmpty1 && isEmpty2 == false) { + sb.append("arrowtail=empty"); + sb.append(",arrowhead=none"); + sb.append(",dir=back"); + } else if (isEmpty1 == false && isEmpty2) { + sb.append("arrowtail=none"); + sb.append(",arrowhead=empty"); } - sb.append("arrowtail="); - sb.append(decor2.getArrowDotSvek()); - sb.append(",arrowhead="); - sb.append(decor1.getArrowDotSvek()); + // if (decor1 == LinkDecor.NONE && decor2 != LinkDecor.NONE) { + // sb.append("dir=back,"); + // } + // if (decor1 != LinkDecor.NONE && decor2 != LinkDecor.NONE) { + // sb.append("dir=both,"); + // } + // + // sb.append("dir=both,"); + // + // sb.append("arrowtail="); + // sb.append(decor2.getArrowDotSvek()); + // sb.append(",arrowhead="); + // sb.append(decor1.getArrowDotSvek()); - if (decor1 == LinkDecor.EXTENDS || decor2 == LinkDecor.EXTENDS) { - sb.append(",arrowsize=2"); + final double arrowsize = Math.max(decor1.getArrowSize(), decor2.getArrowSize()); + if (arrowsize > 0) { + sb.append(",arrowsize=" + arrowsize); } - if (decor1 == LinkDecor.PLUS || decor2 == LinkDecor.PLUS) { - sb.append(",arrowsize=1.5"); - } - -// if (style == LinkStyle.DASHED) { -// sb.append(",style=dashed"); -// } -// if (style == LinkStyle.DOTTED) { -// sb.append(",style=dotted,"); -// } -// if (style == LinkStyle.BOLD) { -// sb.append(",style=bold,"); -// } - return sb.toString(); } @@ -207,11 +215,11 @@ public class LinkType { } public LinkType getPart1() { - return new LinkType(decor1, style, LinkDecor.NONE); + return new LinkType(hat1, decor1, style, middleDecor, LinkDecor.NONE, LinkHat.NONE); } public LinkType getPart2() { - return new LinkType(LinkDecor.NONE, style, decor2); + return new LinkType(LinkHat.NONE, LinkDecor.NONE, style, middleDecor, decor2, hat2); } public UStroke getStroke() { @@ -226,4 +234,17 @@ public class LinkType { } return new UStroke(); } + + public LinkMiddleDecor getMiddleDecor() { + return middleDecor; + } + + public LinkHat getHat1() { + return hat1; + } + + public LinkHat getHat2() { + return hat2; + } + } diff --git a/src/net/sourceforge/plantuml/cucadiagram/Magma.java b/src/net/sourceforge/plantuml/cucadiagram/Magma.java new file mode 100644 index 000000000..4b538bc14 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/Magma.java @@ -0,0 +1,110 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 10006 $ + * + */ +package net.sourceforge.plantuml.cucadiagram; + +import java.util.List; + +class Magma { + + private final CucaDiagram system; + private final List standalones; + private final LinkType linkType = new LinkType(LinkDecor.NONE, LinkDecor.NONE).getInvisible(); + + public Magma(CucaDiagram system, List standalones) { + this.system = system; + this.standalones = standalones; + } + + public void putInSquare() { + final SquareLinker linker = new SquareLinker() { + public void topDown(ILeaf top, ILeaf down) { + system.addLink(new Link(top, down, linkType, null, 2)); + } + + public void leftRight(ILeaf left, ILeaf right) { + system.addLink(new Link(left, right, linkType, null, 1)); + } + }; + new SquareMaker().putInSquare(standalones, linker); + } + + public IGroup getContainer() { + final IGroup parent = standalones.get(0).getParentContainer(); + if (parent == null) { + return null; + } + return parent.getParentContainer(); + } + + public boolean isComplete() { + final IGroup parent = getContainer(); + if (parent == null) { + return false; + } + return parent.size() == standalones.size(); + } + + private int squareSize() { + return SquareMaker.computeBranch(standalones.size()); + } + + private ILeaf getTopLeft() { + return standalones.get(0); + } + + private ILeaf getBottomLeft() { + int result = SquareMaker.getBottomLeft(standalones.size()); + return standalones.get(result); + } + + private ILeaf getTopRight() { + final int s = squareSize(); + return standalones.get(s - 1); + } + + @Override + public String toString() { + return standalones.get(0).getParentContainer() + " " + standalones.toString() + " " + isComplete(); + } + + public void linkToDown(Magma down) { + system.addLink(new Link(this.getBottomLeft(), down.getTopLeft(), linkType, null, 2)); + + } + + public void linkToRight(Magma right) { + system.addLink(new Link(this.getTopRight(), right.getTopLeft(), linkType, null, 1)); + } + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/MagmaList.java b/src/net/sourceforge/plantuml/cucadiagram/MagmaList.java new file mode 100644 index 000000000..86841e7d3 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/MagmaList.java @@ -0,0 +1,75 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 10006 $ + * + */ +package net.sourceforge.plantuml.cucadiagram; + +import java.util.ArrayList; +import java.util.List; + +class MagmaList { + + private final List all = new ArrayList(); + + public void add(Magma magma) { + all.add(magma); + } + + public MagmaList getMagmas(IGroup group) { + final MagmaList result = new MagmaList(); + for (Magma m : all) { + if (m.getContainer() == group) { + result.add(m); + } + } + return result; + } + + public int size() { + return all.size(); + } + + public void putInSquare() { + final SquareLinker linker = new SquareLinker() { + public void topDown(Magma top, Magma down) { + top.linkToDown(down); + } + + public void leftRight(Magma left, Magma right) { + left.linkToRight(right); + } + }; + new SquareMaker().putInSquare(all, linker); + + } + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/Member.java b/src/net/sourceforge/plantuml/cucadiagram/Member.java index 94db7c9fb..a8ff6b75d 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/Member.java +++ b/src/net/sourceforge/plantuml/cucadiagram/Member.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,108 +33,19 @@ */ package net.sourceforge.plantuml.cucadiagram; +import net.sourceforge.plantuml.Url; import net.sourceforge.plantuml.skin.VisibilityModifier; -public class Member { +public interface Member { - private String display; - private final boolean staticModifier; - private final boolean abstractModifier; + public String getDisplay(boolean withVisibilityChar); - private final VisibilityModifier visibilityModifier; + public boolean isStatic(); - public Member(String display, boolean isMethod) { - final String lower = display.toLowerCase(); - this.staticModifier = lower.contains("{static}") || lower.contains("{classifier}"); - this.abstractModifier = lower.contains("{abstract}"); - final String displayClean = display.replaceAll("(?i)\\{(static|classifier|abstract)\\}", "").trim(); + public boolean isAbstract(); - if (VisibilityModifier.isVisibilityCharacter(displayClean.charAt(0))) { - visibilityModifier = VisibilityModifier.getVisibilityModifier(display.charAt(0), isMethod == false); - this.display = displayClean.substring(1).trim(); - } else { - this.display = displayClean; - visibilityModifier = null; - } - // assert - // VisibilityModifier.isVisibilityCharacter(this.display.charAt(0)) == - // false; + public VisibilityModifier getVisibilityModifier(); - } - - public String getDisplay(boolean withVisibilityChar) { - if (withVisibilityChar) { - return getDisplayWithVisibilityChar(); - } - return getDisplayWithoutVisibilityChar(); - } - - public String getDisplayWithoutVisibilityChar() { - assert VisibilityModifier.isVisibilityCharacter(display.charAt(0)) == false; - return display; - } - - public String getDisplayWithVisibilityChar() { - if (isPrivate()) { - return "-" + display; - } - if (isPublic()) { - return "+" + display; - } - if (isPackagePrivate()) { - return "~" + display; - } - if (isProtected()) { - return "#" + display; - } - return display; - } - - @Override - public boolean equals(Object obj) { - final Member other = (Member) obj; - return this.display.equals(other.display); - } - - @Override - public int hashCode() { - return display.hashCode(); - } - - public final boolean isStatic() { - return staticModifier; - } - - public final boolean isAbstract() { - return abstractModifier; - } - - public final boolean isVisibilityModified() { - return visibilityModifier != null; - } - - public final boolean isPrivate() { - return visibilityModifier == VisibilityModifier.PRIVATE_FIELD - || visibilityModifier == VisibilityModifier.PRIVATE_METHOD; - } - - public final boolean isProtected() { - return visibilityModifier == VisibilityModifier.PROTECTED_FIELD - || visibilityModifier == VisibilityModifier.PROTECTED_METHOD; - } - - public final boolean isPublic() { - return visibilityModifier == VisibilityModifier.PUBLIC_FIELD - || visibilityModifier == VisibilityModifier.PUBLIC_METHOD; - } - - public final boolean isPackagePrivate() { - return visibilityModifier == VisibilityModifier.PACKAGE_PRIVATE_FIELD - || visibilityModifier == VisibilityModifier.PACKAGE_PRIVATE_METHOD; - } - - public final VisibilityModifier getVisibilityModifier() { - return visibilityModifier; - } + public Url getUrl(); } diff --git a/src/net/sourceforge/plantuml/cucadiagram/MemberImpl.java b/src/net/sourceforge/plantuml/cucadiagram/MemberImpl.java new file mode 100644 index 000000000..3252bd99c --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/MemberImpl.java @@ -0,0 +1,171 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 4749 $ + * + */ +package net.sourceforge.plantuml.cucadiagram; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.UrlBuilder; +import net.sourceforge.plantuml.UrlBuilder.ModeUrl; +import net.sourceforge.plantuml.skin.VisibilityModifier; + +public class MemberImpl implements Member { + + private final String display; + private final boolean staticModifier; + private final boolean abstractModifier; + private final Url url; + + private final VisibilityModifier visibilityModifier; + + public MemberImpl(String display, boolean isMethod, boolean manageModifier) { + // manageModifier = true; + final Pattern p = Pattern.compile("^(.*)(" + UrlBuilder.getRegexp() + ")(.*)$"); + final Matcher m = p.matcher(display); + + if (m.matches()) { + if (m.groupCount() != 6) { + throw new IllegalStateException(); + } + final UrlBuilder urlBuilder = new UrlBuilder(null, ModeUrl.STRICT); + url = urlBuilder.getUrl(m.group(2)); + url.setMember(true); + display = m.group(1).trim() + m.group(m.groupCount()).trim(); + } else { + url = null; + } + + final String lower = display.toLowerCase(); + + if (manageModifier) { + this.staticModifier = lower.contains("{static}") || lower.contains("{classifier}"); + this.abstractModifier = lower.contains("{abstract}"); + String displayClean = display.replaceAll("(?i)\\{(static|classifier|abstract)\\}", "").trim(); + if (displayClean.length() == 0) { + displayClean = " "; + } + + if (VisibilityModifier.isVisibilityCharacter(displayClean.charAt(0))) { + visibilityModifier = VisibilityModifier.getVisibilityModifier(display.charAt(0), isMethod == false); + this.display = displayClean.substring(1).trim(); + } else { + this.display = displayClean; + visibilityModifier = null; + } + } else { + this.staticModifier = false; + this.visibilityModifier = null; + this.abstractModifier = false; + display = display.trim(); + this.display = display.length() == 0 ? " " : display.trim(); + } + } + + public String getDisplay(boolean withVisibilityChar) { + if (withVisibilityChar) { + return getDisplayWithVisibilityChar(); + } + return getDisplayWithoutVisibilityChar(); + } + + public String getDisplayWithoutVisibilityChar() { + // assert display.length() == 0 || VisibilityModifier.isVisibilityCharacter(display.charAt(0)) == false; + return display; + } + + public String getDisplayWithVisibilityChar() { + if (isPrivate()) { + return "-" + display; + } + if (isPublic()) { + return "+" + display; + } + if (isPackagePrivate()) { + return "~" + display; + } + if (isProtected()) { + return "#" + display; + } + return display; + } + + @Override + public boolean equals(Object obj) { + final MemberImpl other = (MemberImpl) obj; + return this.display.equals(other.display); + } + + @Override + public int hashCode() { + return display.hashCode(); + } + + public final boolean isStatic() { + return staticModifier; + } + + public final boolean isAbstract() { + return abstractModifier; + } + + private boolean isPrivate() { + return visibilityModifier == VisibilityModifier.PRIVATE_FIELD + || visibilityModifier == VisibilityModifier.PRIVATE_METHOD; + } + + private boolean isProtected() { + return visibilityModifier == VisibilityModifier.PROTECTED_FIELD + || visibilityModifier == VisibilityModifier.PROTECTED_METHOD; + } + + private boolean isPublic() { + return visibilityModifier == VisibilityModifier.PUBLIC_FIELD + || visibilityModifier == VisibilityModifier.PUBLIC_METHOD; + } + + private boolean isPackagePrivate() { + return visibilityModifier == VisibilityModifier.PACKAGE_PRIVATE_FIELD + || visibilityModifier == VisibilityModifier.PACKAGE_PRIVATE_METHOD; + } + + public final VisibilityModifier getVisibilityModifier() { + return visibilityModifier; + } + + public final Url getUrl() { + return url; + } + +} diff --git a/src/net/sourceforge/plantuml/graph/MethodsOrFieldsArea2.java b/src/net/sourceforge/plantuml/cucadiagram/MethodsOrFieldsArea.java similarity index 53% rename from src/net/sourceforge/plantuml/graph/MethodsOrFieldsArea2.java rename to src/net/sourceforge/plantuml/cucadiagram/MethodsOrFieldsArea.java index 4673c7033..e35ce5f95 100644 --- a/src/net/sourceforge/plantuml/graph/MethodsOrFieldsArea2.java +++ b/src/net/sourceforge/plantuml/cucadiagram/MethodsOrFieldsArea.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,50 +28,56 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5608 $ + * Revision $Revision: 4749 $ * */ -package net.sourceforge.plantuml.graph; +package net.sourceforge.plantuml.cucadiagram; -import java.awt.Graphics2D; import java.awt.geom.Dimension2D; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.FontParam; import net.sourceforge.plantuml.ISkinParam; -import net.sourceforge.plantuml.cucadiagram.Member; +import net.sourceforge.plantuml.Url; import net.sourceforge.plantuml.graphic.FontConfiguration; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.graphic.TextBlockWidth; import net.sourceforge.plantuml.skin.VisibilityModifier; import net.sourceforge.plantuml.skin.rose.Rose; -import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.ugraphic.PlacementStrategy; import net.sourceforge.plantuml.ugraphic.PlacementStrategyVisibility; +import net.sourceforge.plantuml.ugraphic.PlacementStrategyY1Y2Center; import net.sourceforge.plantuml.ugraphic.PlacementStrategyY1Y2Left; import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; -import net.sourceforge.plantuml.ugraphic.UGroup; +import net.sourceforge.plantuml.ugraphic.ULayoutGroup; -public class MethodsOrFieldsArea2 implements TextBlock { +public class MethodsOrFieldsArea implements TextBlockWidth, TextBlock { private final UFont font; - private final List members = new ArrayList(); private final ISkinParam skinParam; private final HtmlColor color; private final Rose rose = new Rose(); + private final List members = new ArrayList(); + private final HorizontalAlignment align; - public MethodsOrFieldsArea2(List attributes, FontParam fontParam, ISkinParam skinParam) { - this.members.addAll(attributes); + public MethodsOrFieldsArea(List members, FontParam fontParam, ISkinParam skinParam) { + this(members, fontParam, skinParam, HorizontalAlignment.LEFT); + } + + public MethodsOrFieldsArea(List members, FontParam fontParam, ISkinParam skinParam, + HorizontalAlignment align) { + this.align = align; this.skinParam = skinParam; this.font = skinParam.getFont(fontParam, null); - this.color = rose.getFontColor(skinParam, FontParam.CLASS_ATTRIBUTE); - + this.color = rose.getFontColor(skinParam, fontParam); + this.members.addAll(members); } private boolean hasSmallIcon() { @@ -87,68 +93,68 @@ public class MethodsOrFieldsArea2 implements TextBlock { } public Dimension2D calculateDimension(StringBounder stringBounder) { + double smallIcon = 0; + if (hasSmallIcon()) { + smallIcon = skinParam.getCircledCharacterRadius() + 3; + } double x = 0; double y = 0; for (Member m : members) { - final String s = getDisplay(m); - final TextBlock bloc = createTextBlock(s); + final TextBlock bloc = createTextBlock(m); final Dimension2D dim = bloc.calculateDimension(stringBounder); - y += dim.getHeight(); x = Math.max(dim.getWidth(), x); + y += dim.getHeight(); } - if (hasSmallIcon()) { - x += skinParam.getCircledCharacterRadius() + 3; - } + x += smallIcon; return new Dimension2DDouble(x, y); } - private TextBlock createTextBlock(String s) { - return TextBlockUtils.create(Arrays.asList(s), new FontConfiguration(font, color), HorizontalAlignement.LEFT); + private TextBlock createTextBlock(Member m) { + final boolean withVisibilityChar = skinParam.classAttributeIconSize() == 0; + final String s = m.getDisplay(withVisibilityChar); + FontConfiguration config = new FontConfiguration(font, color); + if (m.isAbstract()) { + config = config.italic(); + } + if (m.isStatic()) { + config = config.underline(); + } + final TextBlock bloc = TextBlockUtils.create(Display.getWithNewlines(s), config, align, skinParam); + return new TextBlockTracer(m, bloc); } - public void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { - throw new UnsupportedOperationException(); - } + static class TextBlockTracer implements TextBlock { - public void drawU(UGraphic ug, double x, double y) { - final Dimension2D dim = calculateDimension(ug.getStringBounder()); - final UGroup group; - if (hasSmallIcon()) { - group = new UGroup(new PlacementStrategyVisibility(ug.getStringBounder(), skinParam - .getCircledCharacterRadius() + 3)); - for (Member att : members) { - final String s = getDisplay(att); - final TextBlock bloc = createTextBlock(s); - final VisibilityModifier modifier = att.getVisibilityModifier(); - group.add(getUBlock(modifier)); - group.add(bloc); + private final TextBlock bloc; + private final Url url; + + public TextBlockTracer(Member m, TextBlock bloc) { + this.bloc = bloc; + this.url = m.getUrl(); + } + + public void drawU(UGraphic ug) { + if (url != null) { + ug.startUrl(url); } - } else { - group = new UGroup(new PlacementStrategyY1Y2Left(ug.getStringBounder())); - for (Member att : members) { - final String s = getDisplay(att); - final TextBlock bloc = createTextBlock(s); - group.add(bloc); + bloc.drawU(ug); + if (url != null) { + ug.closeAction(); } } - group.drawU(ug, x, y, dim.getWidth(), dim.getHeight()); - } + public Dimension2D calculateDimension(StringBounder stringBounder) { + final Dimension2D dim = bloc.calculateDimension(stringBounder); + return dim; + } - private String getDisplay(Member att) { - final boolean withVisibilityChar = skinParam.classAttributeIconSize() == 0; - return att.getDisplay(withVisibilityChar); } private TextBlock getUBlock(final VisibilityModifier modifier) { if (modifier == null) { return new TextBlock() { - public void drawU(UGraphic ug, double x, double y) { - } - - public void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { - throw new UnsupportedOperationException(); + public void drawU(UGraphic ug) { } public Dimension2D calculateDimension(StringBounder stringBounder) { @@ -156,12 +162,54 @@ public class MethodsOrFieldsArea2 implements TextBlock { } }; } - final HtmlColor back = modifier.getBackground() == null ? null : rose.getHtmlColor(skinParam, modifier - .getBackground()); + final HtmlColor back = modifier.getBackground() == null ? null : rose.getHtmlColor(skinParam, + modifier.getBackground()); final HtmlColor fore = rose.getHtmlColor(skinParam, modifier.getForeground()); final TextBlock uBlock = modifier.getUBlock(skinParam.classAttributeIconSize(), fore, back); return uBlock; } + public TextBlock asTextBlock(final double widthToUse) { + return new TextBlock() { + + public void drawU(UGraphic ug) { + MethodsOrFieldsArea.this.drawU(ug); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return MethodsOrFieldsArea.this.calculateDimension(stringBounder); + } + }; + } + + public void drawU(UGraphic ug) { + final Dimension2D dim = calculateDimension(ug.getStringBounder()); + final ULayoutGroup group; + if (hasSmallIcon()) { + group = new ULayoutGroup(new PlacementStrategyVisibility(ug.getStringBounder(), + skinParam.getCircledCharacterRadius() + 3)); + for (Member att : members) { + final TextBlock bloc = createTextBlock(att); + final VisibilityModifier modifier = att.getVisibilityModifier(); + group.add(getUBlock(modifier)); + group.add(bloc); + } + } else { + final PlacementStrategy placementStrategy; + if (align == HorizontalAlignment.LEFT) { + placementStrategy = new PlacementStrategyY1Y2Left(ug.getStringBounder()); + } else if (align == HorizontalAlignment.CENTER) { + placementStrategy = new PlacementStrategyY1Y2Center(ug.getStringBounder()); + } else { + throw new IllegalStateException(); + } + group = new ULayoutGroup(placementStrategy); + for (Member att : members) { + final TextBlock bloc = createTextBlock(att); + group.add(bloc); + } + } + group.drawU(ug, 0, 0, dim.getWidth(), dim.getHeight()); + } } diff --git a/src/net/sourceforge/plantuml/cucadiagram/Namespace.java b/src/net/sourceforge/plantuml/cucadiagram/Namespace.java new file mode 100644 index 000000000..e57eb2907 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/Namespace.java @@ -0,0 +1,70 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8770 $ + * + */ +package net.sourceforge.plantuml.cucadiagram; + +public class Namespace { + + private final String namespace; + + private Namespace(String namespace) { + if (namespace == null) { + throw new IllegalArgumentException(); + } + this.namespace = namespace; + } + + public final String getNamespace() { + return namespace; + } + + public static Namespace of(String namespace) { + return new Namespace(namespace); + } + + @Override + public int hashCode() { + return namespace.hashCode(); + } + + @Override + public boolean equals(Object obj) { + final Namespace other = (Namespace) obj; + return this.namespace.equals(other.namespace); + } + + public boolean isMain() { + return namespace.length() == 0; + } + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/PortionShower.java b/src/net/sourceforge/plantuml/cucadiagram/PortionShower.java index d6adc8762..471ca9ebe 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/PortionShower.java +++ b/src/net/sourceforge/plantuml/cucadiagram/PortionShower.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -36,5 +36,5 @@ package net.sourceforge.plantuml.cucadiagram; public interface PortionShower { - boolean showPortion(EntityPortion portion, IEntity entity); + boolean showPortion(EntityPortion portion, ILeaf entity); } diff --git a/src/net/sourceforge/plantuml/cucadiagram/Rankdir.java b/src/net/sourceforge/plantuml/cucadiagram/Rankdir.java index eeba9c4f6..d2883e26e 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/Rankdir.java +++ b/src/net/sourceforge/plantuml/cucadiagram/Rankdir.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3829 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.cucadiagram; diff --git a/src/net/sourceforge/plantuml/cucadiagram/RuleType.java b/src/net/sourceforge/plantuml/cucadiagram/RuleType.java index fa6710c95..20d7ab419 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/RuleType.java +++ b/src/net/sourceforge/plantuml/cucadiagram/RuleType.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/cucadiagram/Imaged.java b/src/net/sourceforge/plantuml/cucadiagram/SquareLinker.java similarity index 81% rename from src/net/sourceforge/plantuml/cucadiagram/Imaged.java rename to src/net/sourceforge/plantuml/cucadiagram/SquareLinker.java index f4f76e3d5..dec7d455d 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/Imaged.java +++ b/src/net/sourceforge/plantuml/cucadiagram/SquareLinker.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,14 +28,15 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4003 $ + * Revision $Revision: 10006 $ * */ package net.sourceforge.plantuml.cucadiagram; -import net.sourceforge.plantuml.cucadiagram.dot.DrawFile; +interface SquareLinker { -public interface Imaged { + public void leftRight(O left, O right); + + public void topDown(O top, O down); - public DrawFile getImageFile(); } diff --git a/src/net/sourceforge/plantuml/cucadiagram/SquareMaker.java b/src/net/sourceforge/plantuml/cucadiagram/SquareMaker.java new file mode 100644 index 000000000..68b89696e --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/SquareMaker.java @@ -0,0 +1,82 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 10006 $ + * + */ +package net.sourceforge.plantuml.cucadiagram; + +import java.util.List; + +class SquareMaker { + + public void putInSquare(List data, SquareLinker linker) { + final int branch = computeBranch(data.size()); + int headBranch = 0; + for (int i = 1; i < data.size(); i++) { + final int dist = i - headBranch; + final O ent2 = data.get(i); + if (dist == branch) { + final O ent1 = data.get(headBranch); + linker.topDown(ent1, ent2); + headBranch = i; + } else { + final O ent1 = data.get(i - 1); + linker.leftRight(ent1, ent2); + } + } + + } + + static int computeBranch(final int size) { + final double sqrt = Math.sqrt(size); + final int r = (int) sqrt; + if (r * r == size) { + return r; + } + return r + 1; + } + + static int getBottomLeft(final int size) { + final int s = computeBranch(size); + final int line = (size - 1) / s; + return line * s; + } + + // static int getBottomLeft(final int size) { + // final int s = computeBranch(size); + // int result = s * (s - 1); + // while (result >= size) { + // result -= s; + // } + // return result; + // } + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/Stereotype.java b/src/net/sourceforge/plantuml/cucadiagram/Stereotype.java index 4c6a0d911..b66ccb157 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/Stereotype.java +++ b/src/net/sourceforge/plantuml/cucadiagram/Stereotype.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,64 +28,96 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6934 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.cucadiagram; import java.util.ArrayList; import java.util.Collections; +import java.util.EnumSet; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import net.sourceforge.plantuml.Hideable; import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.svek.PackageStyle; import net.sourceforge.plantuml.ugraphic.UFont; -public class Stereotype implements CharSequence { - - private final static Pattern circle = Pattern +public class Stereotype implements CharSequence, Hideable { + private final static Pattern circleChar = Pattern .compile("\\<\\<\\s*\\(?(\\S)\\s*,\\s*(#[0-9a-fA-F]{6}|\\w+)\\s*(?:[),](.*?))?\\>\\>"); + private final static Pattern circleSprite = Pattern + .compile("\\<\\<\\s*\\(?\\$([\\p{L}0-9_]+)\\s*(?:,\\s*(#[0-9a-fA-F]{6}|\\w+))?\\s*(?:[),](.*?))?\\>\\>"); private final String label; private final HtmlColor htmlColor; private final char character; + private final String sprite; private final double radius; private final UFont circledFont; + private final boolean automaticPackageStyle; public Stereotype(String label, double radius, UFont circledFont) { + this(label, radius, circledFont, true); + } + + public Stereotype(String label, double radius, UFont circledFont, boolean automaticPackageStyle) { if (label == null) { throw new IllegalArgumentException(); } if (label.startsWith("<<") == false || label.endsWith(">>") == false) { throw new IllegalArgumentException(label); } + this.automaticPackageStyle = automaticPackageStyle; this.radius = radius; this.circledFont = circledFont; - final Matcher m = circle.matcher(label); - if (m.find()) { - if (StringUtils.isNotEmpty(m.group(3))) { - this.label = "<<" + m.group(3) + ">>"; + final Matcher mCircleChar = circleChar.matcher(label); + final Matcher mCircleSprite = circleSprite.matcher(label); + if (mCircleSprite.find()) { + if (StringUtils.isNotEmpty(mCircleSprite.group(3))) { + this.label = "<<" + mCircleSprite.group(3) + ">>"; } else { this.label = null; } - final String colName = m.group(2); - this.htmlColor = HtmlColor.getColorIfValid(colName); - this.character = m.group(1).charAt(0); + final String colName = mCircleSprite.group(2); + final HtmlColor col = HtmlColorUtils.getColorIfValid(colName); + this.htmlColor = col == null ? HtmlColorUtils.BLACK : col; + this.sprite = mCircleSprite.group(1); + this.character = '\0'; + } else if (mCircleChar.find()) { + if (StringUtils.isNotEmpty(mCircleChar.group(3))) { + this.label = "<<" + mCircleChar.group(3) + ">>"; + } else { + this.label = null; + } + final String colName = mCircleChar.group(2); + this.htmlColor = HtmlColorUtils.getColorIfValid(colName); + this.character = mCircleChar.group(1).charAt(0); + this.sprite = null; } else { this.label = label; this.character = '\0'; this.htmlColor = null; + this.sprite = null; } } - public Stereotype(String stereotype) { - this.label = stereotype; + public Stereotype(String label) { + this(label, true); + } + + public Stereotype(String label, boolean automaticPackageStyle) { + this.automaticPackageStyle = automaticPackageStyle; + this.label = label; this.htmlColor = null; this.character = '\0'; this.radius = 0; this.circledFont = null; + this.sprite = null; } public HtmlColor getHtmlColor() { @@ -96,8 +128,19 @@ public class Stereotype implements CharSequence { return character; } + public final String getSprite() { + return sprite; + } + + public boolean isWithOOSymbol() { + return "<>".equalsIgnoreCase(label); + } + public String getLabel() { assert label == null || label.length() > 0; + if (isWithOOSymbol()) { + return null; + } return label; } @@ -137,16 +180,33 @@ public class Stereotype implements CharSequence { } public List getLabels() { - if (label==null) { + if (getLabel() == null) { return null; } final List result = new ArrayList(); final Pattern p = Pattern.compile("\\<\\<.*?\\>\\>"); - final Matcher m = p.matcher(label); + final Matcher m = p.matcher(getLabel()); while (m.find()) { result.add(m.group()); } return Collections.unmodifiableList(result); } + public PackageStyle getPackageStyle() { + if (automaticPackageStyle == false) { + return null; + } + for (PackageStyle p : EnumSet.allOf(PackageStyle.class)) { + if (("<<" + p + ">>").equalsIgnoreCase(label)) { + return p; + } + } + return null; + } + + public boolean isHidden() { + return "<>".equalsIgnoreCase(label); + } + + } diff --git a/src/net/sourceforge/plantuml/cucadiagram/EntityType.java b/src/net/sourceforge/plantuml/cucadiagram/UnparsableGraphvizException.java similarity index 62% rename from src/net/sourceforge/plantuml/cucadiagram/EntityType.java rename to src/net/sourceforge/plantuml/cucadiagram/UnparsableGraphvizException.java index 8e8dd6308..a8dd1aba1 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/EntityType.java +++ b/src/net/sourceforge/plantuml/cucadiagram/UnparsableGraphvizException.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -27,32 +27,31 @@ * in the United States and other countries.] * * Original Author: Arnaud Roques - * - * Revision $Revision: 6924 $ + * + * Revision $Revision: 9631 $ * */ package net.sourceforge.plantuml.cucadiagram; -public enum EntityType { +public class UnparsableGraphvizException extends RuntimeException { - EMPTY_PACKAGE, + private final String graphvizVersion; + private final String svg; + private final String diagramSource; - ABSTRACT_CLASS, CLASS, INTERFACE, LOLLIPOP, ENUM, ACTOR, USECASE, COMPONENT, CIRCLE_INTERFACE, NOTE, OBJECT, ASSOCIATION, + public UnparsableGraphvizException(Exception cause, String graphvizVersion, String svg, String diagramSource) { + super(cause); + this.graphvizVersion = graphvizVersion; + this.svg = svg; + this.diagramSource = diagramSource; + } - ACTIVITY, BRANCH, SYNCHRO_BAR, CIRCLE_START, CIRCLE_END, POINT_FOR_ASSOCIATION, ACTIVITY_CONCURRENT, + public String getGraphvizVersion() { + return graphvizVersion; + } - STATE, STATE_CONCURRENT, PSEUDO_STATE, - - BLOCK, - - GROUP; - - public static EntityType getEntityType(String arg0) { - arg0 = arg0.toUpperCase(); - if (arg0.startsWith("ABSTRACT")) { - return EntityType.ABSTRACT_CLASS; - } - return EntityType.valueOf(arg0); + public final String getDebugData() { + return "SVG=" + svg + "\r\nDIAGRAM=" + diagramSource; } } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/AbstractGraphviz.java b/src/net/sourceforge/plantuml/cucadiagram/dot/AbstractGraphviz.java index 374ee3b03..231206953 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/AbstractGraphviz.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/AbstractGraphviz.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,24 +28,19 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6711 $ + * Revision $Revision: 12064 $ * */ package net.sourceforge.plantuml.cucadiagram.dot; import java.io.File; -import java.io.IOException; import java.io.OutputStream; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.FileFormatOption; import net.sourceforge.plantuml.Log; import net.sourceforge.plantuml.OptionFlags; import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.graphic.GraphicStrings; abstract class AbstractGraphviz implements Graphviz { @@ -81,25 +76,27 @@ abstract class AbstractGraphviz implements Graphviz { abstract protected File specificDotExe(); - final public void createFile(OutputStream os) throws IOException, InterruptedException { + final public ProcessState createFile3(OutputStream os) { if (dotString == null) { throw new IllegalArgumentException(); } if (illegalDotExe()) { - createPngNoGraphviz(os, new FileFormatOption(FileFormat.valueOf(type[0].toUpperCase()))); - return; + // createPngNoGraphviz(os, new FileFormatOption(FileFormat.valueOf(type[0].toUpperCase()))); + throw new IllegalStateException(); } - final String cmd = getCommandLine(); + final String cmd[] = getCommandLine(); ProcessRunner p = null; + ProcessState state = null; try { - Log.info("Starting Graphviz process " + cmd); + Log.info("Starting Graphviz process " + Arrays.asList(cmd)); Log.info("DotString size: " + dotString.length()); p = new ProcessRunner(cmd); - p.run(dotString.getBytes(), os); + state = p.run2(dotString.getBytes(), os); +// if (state == ProcessState.TERMINATED_OK) { +// result = true; +// } Log.info("Ending process ok"); - } catch (InterruptedException e) { - Log.error("Interrupted"); } catch (Throwable e) { e.printStackTrace(); Log.error("Error: " + e); @@ -122,26 +119,24 @@ abstract class AbstractGraphviz implements Graphviz { throw new IllegalStateException("Dot out " + p.getOut()); } } - + return state; } private boolean illegalDotExe() { return dotExe == null || dotExe.isFile() == false || dotExe.canRead() == false; } - final public String dotVersion() throws IOException, InterruptedException { - final String cmd = getCommandLineVersion(); + final public String dotVersion() { + final String cmd[] = getCommandLineVersion(); return executeCmd(cmd); } - public String testFile(String dotfilename, String outfile) throws IOException, InterruptedException { - final String cmd = getCommandLine() + "-o" + outfile + " " + dotfilename; - return executeCmd(cmd); - } - - private String executeCmd(final String cmd) throws IOException, InterruptedException { + private String executeCmd(final String cmd[]) { final ProcessRunner p = new ProcessRunner(cmd); - p.run(null, null); + final ProcessState state = p.run2(null, null); + if (state != ProcessState.TERMINATED_OK) { + return "?"; + } final StringBuilder sb = new StringBuilder(); if (StringUtils.isNotEmpty(p.getOut())) { sb.append(p.getOut()); @@ -155,47 +150,23 @@ abstract class AbstractGraphviz implements Graphviz { return sb.toString().replace('\n', ' ').trim(); } - final private void createPngNoGraphviz(OutputStream os, FileFormatOption format) throws IOException { - final List msg = new ArrayList(); - msg.add("Dot Executable: " + dotExe); - if (dotExe != null) { - if (dotExe.exists() == false) { - msg.add("File does not exist"); - } else if (dotExe.isDirectory()) { - msg.add("It should be an executable, not a directory"); - } else if (dotExe.isFile() == false) { - msg.add("Not a valid file"); - } else if (dotExe.canRead() == false) { - msg.add("File cannot be read"); - } + final String[] getCommandLine() { + final String[] result = new String[type.length + 1]; + result[0] = getDotExe().getAbsolutePath(); + for (int i = 0; i < type.length; i++) { + result[i + 1] = "-T" + type[i]; } - msg.add("Cannot find Graphviz. You should try"); - msg.add(" "); - msg.add("@startuml"); - msg.add("testdot"); - msg.add("@enduml"); - msg.add(" "); - msg.add(" or "); - msg.add(" "); - msg.add("java -jar plantuml.jar -testdot"); - final GraphicStrings errorResult = new GraphicStrings(msg); - errorResult.writeImage(os, format); + return result; } - abstract String getCommandLine(); - - abstract String getCommandLineVersion(); + final String[] getCommandLineVersion() { + return new String[] { getDotExe().getAbsolutePath(), "-V" }; + } public final File getDotExe() { return dotExe; } - protected final void appendImageType(final StringBuilder sb) { - for (String t : type) { - sb.append(" -T" + t + " "); - } - } - public final String getDotString() { return dotString; } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/AbstractGraphviz2.java b/src/net/sourceforge/plantuml/cucadiagram/dot/AbstractGraphviz2.java deleted file mode 100644 index bf8b1d4d2..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/AbstractGraphviz2.java +++ /dev/null @@ -1,190 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6104 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.io.File; -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.List; - -import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.FileFormatOption; -import net.sourceforge.plantuml.Log; -import net.sourceforge.plantuml.OptionFlags; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.graphic.GraphicStrings; - -class AbstractGraphviz2 implements Graphviz { - - private final OS os; - private final GraphvizLayoutStrategy strategy; - private final String dotString; - private final String[] type; - - - AbstractGraphviz2(OS os, GraphvizLayoutStrategy strategy, String dotString, String... type) { - if (type == null) { - throw new IllegalArgumentException(); - } - this.os = os; - this.strategy = strategy; - this.dotString = dotString; - this.type = type; - throw new UnsupportedOperationException("not used yet"); - } - - - final public void createFile(OutputStream os) throws IOException, InterruptedException { - if (dotString == null) { - throw new IllegalArgumentException(); - } - - if (illegalDotExe()) { - createPngNoGraphviz(os, new FileFormatOption(FileFormat.valueOf(type[0].toUpperCase()))); - return; - } - final String cmd = getCommandLine(); - ProcessRunner p = null; - try { - Log.info("Starting Graphviz process " + cmd); - Log.info("DotString size: " + dotString.length()); - p = new ProcessRunner(cmd); - p.run(dotString.getBytes(), os); - Log.info("Ending process ok"); - } catch (Throwable e) { - e.printStackTrace(); - Log.error("Error: " + e); - Log.error("The command was " + cmd); - Log.error(""); - Log.error("Try java -jar plantuml.jar -testdot to figure out the issue"); - Log.error(""); - } finally { - Log.info("Ending Graphviz process"); - } - if (OptionFlags.getInstance().isCheckDotError() && p != null && p.getError().length() > 0) { - Log.error("GraphViz error stream : " + p.getError()); - if (OptionFlags.getInstance().isCheckDotError()) { - throw new IllegalStateException("Dot error " + p.getError()); - } - } - if (OptionFlags.getInstance().isCheckDotError() && p != null && p.getOut().length() > 0) { - Log.error("GraphViz out stream : " + p.getOut()); - if (OptionFlags.getInstance().isCheckDotError()) { - throw new IllegalStateException("Dot out " + p.getOut()); - } - } - - } - - - private String getCommandLine() { - final StringBuilder sb = new StringBuilder(); - sb.append(os.getCommand(strategy)); - appendImageType(sb); - return sb.toString(); - } - - - public String dotVersion() throws IOException, InterruptedException { - final String cmd = os.getCommand(strategy)+" -V"; - return executeCmd(cmd); - } - - - public File getDotExe() { - return os.getExecutable(strategy); - } - - private boolean illegalDotExe() { - final File exe = getDotExe(); - return exe == null || exe.isFile() == false || exe.canRead() == false; - } - - private String executeCmd(final String cmd) throws IOException, InterruptedException { - final ProcessRunner p = new ProcessRunner(cmd); - p.run(null, null); - final StringBuilder sb = new StringBuilder(); - if (StringUtils.isNotEmpty(p.getOut())) { - sb.append(p.getOut()); - } - if (StringUtils.isNotEmpty(p.getError())) { - if (sb.length() > 0) { - sb.append(' '); - } - sb.append(p.getError()); - } - return sb.toString().replace('\n', ' ').trim(); - } - - final private void createPngNoGraphviz(OutputStream os, FileFormatOption format) throws IOException { - final List msg = new ArrayList(); - final File exe = getDotExe(); - msg.add("Dot Executable: " + exe); - if (exe != null) { - if (exe.exists() == false) { - msg.add("File does not exist"); - } else if (exe.isDirectory()) { - msg.add("It should be an executable, not a directory"); - } else if (exe.isFile() == false) { - msg.add("Not a valid file"); - } else if (exe.canRead() == false) { - msg.add("File cannot be read"); - } - } - msg.add("Cannot find Graphviz. You should try"); - msg.add(" "); - msg.add("@startuml"); - msg.add("testdot"); - msg.add("@enduml"); - msg.add(" "); - msg.add(" or "); - msg.add(" "); - msg.add("java -jar plantuml.jar -testdot"); - final GraphicStrings errorResult = new GraphicStrings(msg); - errorResult.writeImage(os, format); - } - - private final void appendImageType(final StringBuilder sb) { - for (String t : type) { - sb.append(" -T" + t + " "); - } - } - - - public String testFile(String filename, String outfile) throws IOException, InterruptedException { - throw new UnsupportedOperationException(); - } - -} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramFileMaker.java b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramFileMaker.java deleted file mode 100644 index 7ef7031c6..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramFileMaker.java +++ /dev/null @@ -1,1069 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6939 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.awt.Color; -import java.awt.Dimension; -import java.awt.Graphics2D; -import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.StringTokenizer; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.imageio.ImageIO; - -import net.sourceforge.plantuml.ColorParam; -import net.sourceforge.plantuml.EmptyImageBuilder; -import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.FileFormatOption; -import net.sourceforge.plantuml.FileUtils; -import net.sourceforge.plantuml.FontParam; -import net.sourceforge.plantuml.ISkinParam; -import net.sourceforge.plantuml.Log; -import net.sourceforge.plantuml.OptionFlags; -import net.sourceforge.plantuml.Scale; -import net.sourceforge.plantuml.SkinParamBackcolored; -import net.sourceforge.plantuml.StringUtils; -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.IEntity; -import net.sourceforge.plantuml.cucadiagram.Link; -import net.sourceforge.plantuml.cucadiagram.Stereotype; -import net.sourceforge.plantuml.eps.EpsGraphics; -import net.sourceforge.plantuml.eps.EpsStrategy; -import net.sourceforge.plantuml.eps.EpsTitler; -import net.sourceforge.plantuml.graphic.CircledCharacter; -import net.sourceforge.plantuml.graphic.GraphicStrings; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; -import net.sourceforge.plantuml.graphic.HtmlColor; -import net.sourceforge.plantuml.graphic.StringBounder; -import net.sourceforge.plantuml.graphic.StringBounderUtils; -import net.sourceforge.plantuml.graphic.VerticalPosition; -import net.sourceforge.plantuml.png.PngFlashcoder; -import net.sourceforge.plantuml.png.PngIO; -import net.sourceforge.plantuml.png.PngRotation; -import net.sourceforge.plantuml.png.PngScaler; -import net.sourceforge.plantuml.png.PngSizer; -import net.sourceforge.plantuml.png.PngTitler; -import net.sourceforge.plantuml.skin.CircleInterface; -import net.sourceforge.plantuml.skin.Component; -import net.sourceforge.plantuml.skin.ComponentType; -import net.sourceforge.plantuml.skin.SimpleContext2D; -import net.sourceforge.plantuml.skin.StickMan; -import net.sourceforge.plantuml.skin.rose.Rose; -import net.sourceforge.plantuml.statediagram.StateDiagram; -import net.sourceforge.plantuml.svg.SvgData; -import net.sourceforge.plantuml.svg.SvgTitler; -import net.sourceforge.plantuml.ugraphic.UFont; -import net.sourceforge.plantuml.ugraphic.eps.UGraphicEps; -import net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d; -import net.sourceforge.plantuml.ugraphic.svg.UGraphicSvg; - -public final class CucaDiagramFileMaker implements ICucaDiagramFileMaker { - - private final CucaDiagram diagram; - private final List flashcodes; - private final StaticFilesMap staticFilesMap; - private final Rose rose = new Rose(); - - static private final StringBounder stringBounder; - - static { - final EmptyImageBuilder builder = new EmptyImageBuilder(10, 10, Color.WHITE); - stringBounder = StringBounderUtils.asStringBounder(builder.getGraphics2D()); - } - - public CucaDiagramFileMaker(CucaDiagram diagram, List flashcodes) throws IOException { - // HtmlColor.setForceMonochrome(diagram.getSkinParam().isMonochrome()); - this.diagram = diagram; - this.flashcodes = flashcodes; - if (diagram.getUmlDiagramType() == UmlDiagramType.CLASS || diagram.getUmlDiagramType() == UmlDiagramType.OBJECT) { - this.staticFilesMap = new StaticFilesMap(diagram.getSkinParam(), diagram.getDpiFactor(null)); - } else { - this.staticFilesMap = null; - } - } - - static private void traceDotString(String dotString) throws IOException { - final File f = new File("dottmpfile" + UniqueSequence.getValue() + ".tmp"); - PrintWriter pw = null; - try { - pw = new PrintWriter(new FileWriter(f)); - pw.print(dotString); - Log.info("Creating file " + f); - } finally { - if (pw != null) { - pw.close(); - } - } - - } - - public String createFile(OutputStream os, List dotStrings, FileFormatOption fileFormatOption) - throws IOException, InterruptedException { - final FileFormat fileFormat = fileFormatOption.getFileFormat(); - if (fileFormat == FileFormat.PNG) { - return createPng(os, dotStrings, fileFormatOption); - } else if (fileFormat == FileFormat.SVG) { - return createSvg(os, dotStrings, fileFormatOption); - } else if (fileFormat == FileFormat.EPS_TEXT) { - return createEps(os, dotStrings, fileFormatOption); - } else if (fileFormat == FileFormat.EPS) { - return createEps(os, dotStrings, fileFormatOption); - } else if (fileFormat == FileFormat.DOT) { - return createDot(os, dotStrings, fileFormatOption); - } else { - throw new UnsupportedOperationException(); - } - - } - - private double deltaY; - - private String createSvg(OutputStream os, List dotStrings, FileFormatOption fileFormatOption) - throws IOException, InterruptedException { - - final StringBuilder cmap = new StringBuilder(); - try { - deltaY = 0; - String svg4 = getSvgData(dotStrings, fileFormatOption, cmap); - - SvgData svgData = SvgData.fromGraphViz(svg4); - - if (svgData != null) { - - final SvgTitler title = getTitleSvgTitler(); - final SvgTitler header = getHeaderSvgTitler(); - final SvgTitler footer = getFooterSvgTitler(); - - svgData = title.addTitle(svgData); - svgData = header.addTitle(svgData); - svgData = footer.addTitle(svgData); - - // double supH = getTitleSvgHeight(svg); - // supH += getHeaderSvgHeight(svg); - // supH += getFooterSvgHeight(svg); - // - // svg = removeSvgXmlHeader1(svg); - // - // svg = addTitleSvg(svg, dim.getWidth(), dim.getHeight()); - // svg = addHeaderSvg(svg, dim.getWidth(), dim.getHeight()); - // svg = addFooterSvg(svg, dim.getWidth(), dim.getHeight()); - // - // svg = modifySvgXmlHeader(svg, dim.getWidth(), dim.getHeight() - // + supH, -50, 0); - - // Image management - final Pattern pImage = Pattern.compile("(?i)]*>"); - - svg4 = svgData.getSvg(); - boolean changed; - do { - changed = false; - final Matcher mImage = pImage.matcher(svg4); - final StringBuffer sb = new StringBuffer(); - while (mImage.find()) { - final String image = mImage.group(0); - final String href = getValue(image, "href"); - final double widthSvg = Double.parseDouble(getValuePx(image, "width")); - final double heightSvg = Double.parseDouble(getValuePx(image, "height")); - final double x = Double.parseDouble(getValue(image, "x")); - final double y = Double.parseDouble(getValue(image, "y")); - final DrawFile drawFile = getDrawFileFromHref(href); - if (drawFile == null) { - mImage.appendReplacement(sb, image); - } else { - final int widthPng = drawFile.getWidthPng(); - final int heightPng = drawFile.getHeightPng(); - String svg2 = drawFile.getSvg(); - final String scale = getScale(widthSvg, heightSvg, widthPng, heightPng); - svg2 = svg2.replaceFirst("<[gG]>", ""); - svg2 = "" + svg2 + ""; - mImage.appendReplacement(sb, svg2); - changed = true; - } - } - mImage.appendTail(sb); - svg4 = sb.toString(); - } while (changed); - } - - os.write(svg4.getBytes("UTF-8")); - - // final ByteArrayInputStream bais = new - // ByteArrayInputStream(baos.toByteArray()); - // BufferedImage im = ImageIO.read(bais); - // bais.close(); - // if (isUnderline) { - // new UnderlineTrick(im, new Color(Integer.parseInt("FEFECF", 16)), - // Color.BLACK).process(); - // } - // - // final Color background = - // diagram.getSkinParam().getBackgroundColor().getColor(); - // im = addTitle(im, background); - // im = addFooter(im, background); - // im = addHeader(im, background); - // - // if (diagram.isRotation()) { - // im = PngRotation.process(im); - // } - // im = PngSizer.process(im, diagram.getMinwidth()); - // - // PngIO.write(im, os, diagram.getMetadata()); - } finally { - clean(); - } - if (cmap.length() > 0) { - return translateXY(cmap.toString(), 0, (int) Math.round(deltaY)); - } - return null; - } - - static String translateXY(String cmap, int deltaX, int deltaY) { - if (deltaY == 0) { - return cmap; - } - final Pattern p = Pattern.compile("coords=\"(\\d+),(\\d+),(\\d+),(\\d+)\""); - final Matcher m = p.matcher(cmap); - - final StringBuffer sb = new StringBuffer(); - while (m.find()) { - final int x1 = Integer.parseInt(m.group(1)) + deltaX; - final int y1 = Integer.parseInt(m.group(2)) + deltaY; - final int x2 = Integer.parseInt(m.group(3)) + deltaX; - final int y2 = Integer.parseInt(m.group(4)) + deltaY; - m.appendReplacement(sb, "coords=\"" + x1 + "," + y1 + "," + x2 + "," + y2 + "\""); - } - m.appendTail(sb); - return sb.toString(); - } - - private String getSvgData(List dotStrings, FileFormatOption fileFormatOption, StringBuilder cmap) - throws IOException, InterruptedException, UnsupportedEncodingException { - final GraphvizMaker dotMaker = populateImagesAndCreateGraphvizMaker(dotStrings, fileFormatOption); - final String dotString = dotMaker.createDotString(); - - if (OptionFlags.getInstance().isKeepTmpFiles()) { - traceDotString(dotString); - } - // if (diagram.hasUrl()) { - // final Graphviz graphviz = GraphvizUtils.create(dotString, "cmapx", - // "svg"); - // - // final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - // graphviz.createPng(baos); - // baos.close(); - // dotMaker.clean(); - // - // final String cmapAndSvg = new String(baos.toByteArray(), - // "UTF-8").replace('\\', '/'); - // final int x = cmapAndSvg.indexOf(" entities) throws IOException { - for (IEntity ent : entities) { - final DrawFile df = ent.getImageFile(searched); - if (df != null) { - assert df.getPng().getCanonicalFile().equals(searched.getCanonicalFile()); - return df; - } - } - return null; - - } - - private DrawFile getDrawFileFromHref(final String href) throws IOException { - if (diagram.getUmlDiagramType() == UmlDiagramType.CLASS || diagram.getUmlDiagramType() == UmlDiagramType.OBJECT) { - final DrawFile drawFile = staticFilesMap.getDrawFile(href); - if (drawFile != null) { - return drawFile; - } - } - final File searched = new File(href).getCanonicalFile(); - - final DrawFile result = searchImageFile(searched, diagram.entities().values()); - if (result != null) { - return result; - } - - for (Link ent : diagram.getLinks()) { - final DrawFile df = ent.getImageFile(); - if (df == null) { - continue; - } - if (df.getPng().getCanonicalFile().equals(searched)) { - return df; - } - } - Log.error("Cannot find " + href); - return null; - } - - private static String getScale(double widthSvg, double heightSvg, double widthPng, double heightPng) { - final double v1 = heightSvg / heightPng; - final double v2 = widthSvg / widthPng; - final double min = Math.min(v1, v2); - return "scale(" + format(min) + " " + format(min) + ")"; - } - - private static String format(double x) { - return EpsGraphics.format(x); - } - - private static String getValue(String s, String param) { - final Pattern p = Pattern.compile("(?i)" + param + "=\"([^\"]+)\""); - final Matcher m = p.matcher(s); - m.find(); - return m.group(1); - } - - private static String getValuePx(String s, String param) { - final Pattern p = Pattern.compile("(?i)" + param + "=\"([^\"]+?)(?:px)?\""); - final Matcher m = p.matcher(s); - m.find(); - return m.group(1); - } - - private String createPng(OutputStream os, List dotStrings, FileFormatOption fileFormatOption) - throws IOException, InterruptedException { - - final StringBuilder cmap = new StringBuilder(); - double supX = 0; - double supY = 0; - try { - final GraphvizMaker dotMaker = populateImagesAndCreateGraphvizMaker(dotStrings, fileFormatOption); - final String dotString = dotMaker.createDotString(); - - if (OptionFlags.getInstance().isKeepTmpFiles()) { - traceDotString(dotString); - } - - final byte[] imageData = getImageData(dotString, cmap); - - if (imageData.length == 0) { - createError(os, imageData.length, new FileFormatOption(FileFormat.PNG), "imageData.length == 0"); - return null; - } - - if (isPngHeader(imageData, 0) == false) { - createError(os, imageData.length, new FileFormatOption(FileFormat.PNG), "No PNG header found", - "Try -forcegd or -forcecairo flag"); - return null; - } - - final ByteArrayInputStream bais = new ByteArrayInputStream(imageData); - BufferedImage im = ImageIO.read(bais); - if (im == null) { - createError(os, imageData.length, new FileFormatOption(FileFormat.PNG), "im == null"); - return null; - } - bais.close(); - dotMaker.clean(); - - final boolean isUnderline = dotMaker.isUnderline(); - if (isUnderline) { - new UnderlineTrick(im, new Color(Integer.parseInt("FEFECF", 16)), Color.BLACK).process(); - } - - final HtmlColor background = diagram.getSkinParam().getBackgroundColor(); - - supY = getTitlePngHeight(stringBounder); - supY += getHeaderPngHeight(stringBounder); - - supX = getOffsetX(stringBounder, im.getWidth()); - - im = addTitle(im, background); - im = addFooter(im, background); - im = addHeader(im, background); - im = scaleImage(im, diagram.getScale()); - - if (diagram.isRotation()) { - im = PngRotation.process(im); - } - im = PngSizer.process(im, diagram.getMinwidth()); - - im = addFlashcode(im, diagram.getColorMapper().getMappedColor(background)); - - PngIO.write(im, os, diagram.getMetadata(), diagram.getDpi(fileFormatOption)); - } finally { - clean(); - } - - if (cmap.length() > 0) { - return translateXY(cmap.toString(), (int) Math.round(supX), (int) Math.round(supY)); - } - return null; - } - - private BufferedImage addFlashcode(BufferedImage im, Color background) { - if (flashcodes == null) { - return im; - } - return new PngFlashcoder(flashcodes).processImage(im, background); - } - - private String createDot(OutputStream os, List dotStrings, FileFormatOption fileFormatOption) - throws IOException, InterruptedException { - final GraphvizMaker dotMaker = populateImagesAndCreateGraphvizMaker(dotStrings, fileFormatOption); - final String dotString = dotMaker.createDotString(); - os.write(dotString.getBytes()); - return null; - } - - private BufferedImage scaleImage(BufferedImage im, Scale scale) { - if (scale == null) { - return im; - } - return PngScaler.scale(im, scale.getScale(im.getWidth(), im.getHeight())); - } - - private byte[] getImageDataCmap(final String dotString, StringBuilder cmap2) throws IOException, - InterruptedException { - final Graphviz graphviz = GraphvizUtils.create(dotString, "cmapx", getPngType()); - - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - graphviz.createFile(baos); - baos.close(); - - final byte[] allData = baos.toByteArray(); - Log.info("Reading " + allData.length + " bytes from dot"); - - final int pngStart = getPngStart(allData); - - final String cmap = new String(allData, 0, pngStart, "UTF8"); - Log.info("CMAP is " + cmap.length() + " long"); - cmap2.append(cmap); - - final byte[] imageData = new byte[allData.length - pngStart]; - System.arraycopy(allData, pngStart, imageData, 0, imageData.length); - - Log.info("PNG is " + imageData.length + " bytes from dot"); - return imageData; - } - - private int getPngStart(byte[] allData) throws IOException { - for (int i = 0; i < allData.length - 8; i++) { - if (isPngHeader(allData, i)) { - return i; - } - } - throw new IOException("Cannot find PNG header"); - } - - private boolean isPngHeader(byte[] allData, int i) { - if (i + 7 >= allData.length) { - return false; - } - return allData[i] == (byte) 0x89 && allData[i + 1] == (byte) 0x50 && allData[i + 2] == (byte) 0x4E - && allData[i + 3] == (byte) 0x47 && allData[i + 4] == (byte) 0x0D && allData[i + 5] == (byte) 0x0A - && allData[i + 6] == (byte) 0x1A && allData[i + 7] == (byte) 0x0A; - } - - private byte[] getImageData(final String dotString, StringBuilder cmap) throws IOException, InterruptedException { - if (diagram.hasUrl()) { - return getImageDataCmap(dotString, cmap); - } - final Graphviz graphviz = GraphvizUtils.create(dotString, getPngType()); - - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - graphviz.createFile(baos); - baos.close(); - - final byte[] imageData = baos.toByteArray(); - // final byte[] imageData = new byte[0]; - Log.info("Reading " + imageData.length + " bytes from dot"); - return imageData; - } - - private String getPngType() { - if (OptionFlags.getInstance().isForceCairo()) { - return "png:cairo"; - } - if (OptionFlags.getInstance().isForceGd()) { - return "png:gd"; - } - return "png"; - } - - void createError(OutputStream os, int length, FileFormatOption fileFormat, String... supp) throws IOException { - final List msg = new ArrayList(); - msg.add("Error: Reading " + length + " byte(s) from dot"); - msg.add("Error reading the generated image"); - for (String s : supp) { - msg.add(s); - } - final GraphicStrings errorResult = new GraphicStrings(msg); - errorResult.writeImage(os, fileFormat); - } - - private BufferedImage addTitle(BufferedImage im, final HtmlColor background) { - final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.TITLE, null); - final UFont font = getSkinParam().getFont(FontParam.TITLE, null); - final String fontFamily = font.getFamily(null); - final int fontSize = font.getSize(); - final PngTitler pngTitler = new PngTitler(diagram.getColorMapper(), titleColor, diagram.getTitle(), fontSize, - fontFamily, HorizontalAlignement.CENTER, VerticalPosition.TOP); - return pngTitler.processImage(im, background, 3); - } - - private double getTitlePngHeight(StringBounder stringBounder) throws IOException { - final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.TITLE, null); - final UFont font = getSkinParam().getFont(FontParam.TITLE, null); - final String fontFamily = font.getFamily(null); - final int fontSize = font.getSize(); - final PngTitler pngTitler = new PngTitler(diagram.getColorMapper(), titleColor, diagram.getTitle(), fontSize, - fontFamily, HorizontalAlignement.CENTER, VerticalPosition.TOP); - return pngTitler.getOffsetY(stringBounder); - } - - private double getOffsetX(StringBounder stringBounder, double imWidth) throws IOException { - final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.TITLE, null); - final UFont font = getSkinParam().getFont(FontParam.TITLE, null); - final String fontFamily = font.getFamily(null); - final int fontSize = font.getSize(); - final PngTitler pngTitler = new PngTitler(diagram.getColorMapper(), titleColor, diagram.getTitle(), fontSize, - fontFamily, HorizontalAlignement.CENTER, VerticalPosition.TOP); - return pngTitler.getOffsetX(imWidth, stringBounder); - } - - private SvgTitler getTitleSvgTitler() throws IOException { - final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.TITLE, null); - final UFont font = getSkinParam().getFont(FontParam.TITLE, null); - final String fontFamily = font.getFamily(null); - final int fontSize = font.getSize(); - - return new SvgTitler(diagram.getColorMapper(), titleColor, diagram.getTitle(), fontSize, fontFamily, - HorizontalAlignement.CENTER, VerticalPosition.TOP, 3); - } - - private SvgTitler getHeaderSvgTitler() throws IOException { - final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.HEADER, null); - final UFont font = getSkinParam().getFont(FontParam.HEADER, null); - final String fontFamily = font.getFamily(null); - final int fontSize = font.getSize(); - return new SvgTitler(diagram.getColorMapper(), titleColor, diagram.getHeader(), fontSize, fontFamily, diagram - .getHeaderAlignement(), VerticalPosition.TOP, 3); - } - - private SvgTitler getFooterSvgTitler() throws IOException { - final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.FOOTER, null); - final UFont font = getSkinParam().getFont(FontParam.FOOTER, null); - final String fontFamily = font.getFamily(null); - final int fontSize = font.getSize(); - return new SvgTitler(diagram.getColorMapper(), titleColor, diagram.getFooter(), fontSize, fontFamily, diagram - .getFooterAlignement(), VerticalPosition.BOTTOM, 3); - } - - private String addTitleEps(EpsStrategy epsStrategy, String eps) throws IOException { - final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.TITLE, null); - final UFont font = getSkinParam().getFont(FontParam.TITLE, null); - final String fontFamily = font.getFamily(null); - final int fontSize = font.getSize(); - - final EpsTitler epsTitler = new EpsTitler(diagram.getColorMapper(), epsStrategy, titleColor, - diagram.getTitle(), fontSize, fontFamily, HorizontalAlignement.CENTER, VerticalPosition.TOP, 3); - this.deltaY += epsTitler.getHeight(); - return epsTitler.addTitleEps(eps); - } - - private String addFooterEps(EpsStrategy epsStrategy, String eps) throws IOException { - final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.FOOTER, null); - final UFont font = getSkinParam().getFont(FontParam.FOOTER, null); - final String fontFamily = font.getFamily(null); - final int fontSize = font.getSize(); - final EpsTitler epsTitler = new EpsTitler(diagram.getColorMapper(), epsStrategy, titleColor, diagram - .getFooter(), fontSize, fontFamily, diagram.getFooterAlignement(), VerticalPosition.BOTTOM, 3); - return epsTitler.addTitleEps(eps); - } - - private String addHeaderEps(EpsStrategy epsStrategy, String eps) throws IOException { - final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.HEADER, null); - final UFont font = getSkinParam().getFont(FontParam.HEADER, null); - final String fontFamily = font.getFamily(null); - final int fontSize = font.getSize(); - final EpsTitler epsTitler = new EpsTitler(diagram.getColorMapper(), epsStrategy, titleColor, diagram - .getHeader(), fontSize, fontFamily, diagram.getHeaderAlignement(), VerticalPosition.TOP, 3); - this.deltaY += epsTitler.getHeight(); - return epsTitler.addTitleEps(eps); - } - - private BufferedImage addFooter(BufferedImage im, final HtmlColor background) { - final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.FOOTER, null); - final UFont font = getSkinParam().getFont(FontParam.FOOTER, null); - final String fontFamily = font.getFamily(null); - final int fontSize = font.getSize(); - final PngTitler pngTitler = new PngTitler(diagram.getColorMapper(), titleColor, diagram.getFooter(), fontSize, - fontFamily, diagram.getFooterAlignement(), VerticalPosition.BOTTOM); - return pngTitler.processImage(im, background, 3); - } - - private BufferedImage addHeader(BufferedImage im, final HtmlColor background) throws IOException { - final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.HEADER, null); - final UFont font = getSkinParam().getFont(FontParam.HEADER, null); - final String fontFamily = font.getFamily(null); - final int fontSize = font.getSize(); - final PngTitler pngTitler = new PngTitler(diagram.getColorMapper(), titleColor, diagram.getHeader(), fontSize, - fontFamily, diagram.getHeaderAlignement(), VerticalPosition.TOP); - return pngTitler.processImage(im, background, 3); - } - - private double getHeaderPngHeight(StringBounder stringBounder) throws IOException { - final HtmlColor titleColor = diagram.getSkinParam().getFontHtmlColor(FontParam.HEADER, null); - final UFont font = getSkinParam().getFont(FontParam.HEADER, null); - final String fontFamily = font.getFamily(null); - final int fontSize = font.getSize(); - final PngTitler pngTitler = new PngTitler(diagram.getColorMapper(), titleColor, diagram.getHeader(), fontSize, - fontFamily, diagram.getHeaderAlignement(), VerticalPosition.TOP); - return pngTitler.getOffsetY(stringBounder); - } - - DrawFile createImage(Entity entity, FileFormatOption option) throws IOException { - final double dpiFactor = diagram.getDpiFactor(option); - if (entity.getType() == EntityType.NOTE) { - return createImageForNote(entity.getDisplay2(), entity.getSpecificBackColor(), option, entity.getParent()); - } - if (entity.getType() == EntityType.ACTOR) { - return createImageForActor(entity, dpiFactor); - } - if (entity.getType() == EntityType.CIRCLE_INTERFACE) { - return createImageForCircleInterface(entity, dpiFactor); - } - if (entity.getType() == EntityType.ABSTRACT_CLASS || entity.getType() == EntityType.CLASS - || entity.getType() == EntityType.ENUM || entity.getType() == EntityType.INTERFACE) { - return createImageForCircleCharacter(entity, dpiFactor); - } - return null; - } - - private DrawFile createImageForNote(List display2, HtmlColor noteBackColor, final FileFormatOption option, - Group parent) throws IOException { - - final Rose skin = new Rose(); - - final ISkinParam skinParam = new SkinParamBackcolored(getSkinParam(), noteBackColor); - final Component comp = skin - .createComponent(ComponentType.NOTE, skinParam, display2); - - final double dpiFactor = diagram.getDpiFactor(option); - final int width = (int) (comp.getPreferredWidth(stringBounder) * dpiFactor); - final int height = (int) (comp.getPreferredHeight(stringBounder) * dpiFactor); - final int dpi = diagram.getDpi(option); - HtmlColor backgroundColor = diagram.getSkinParam().getBackgroundColor(); - if (parent != null && parent.getBackColor() != null) { - backgroundColor = parent.getBackColor(); - } - final Color background = diagram.getColorMapper().getMappedColor(backgroundColor); - - final Lazy lpng = new Lazy() { - - public File getNow() throws IOException { - final File fPng = FileUtils.createTempFile("plantumlB", ".png"); - final EmptyImageBuilder builder = new EmptyImageBuilder(width, height, background); - final BufferedImage im = builder.getBufferedImage(); - final Graphics2D g2d = builder.getGraphics2D(); - - comp.drawU(new UGraphicG2d(diagram.getColorMapper(), g2d, null, dpiFactor), - new Dimension(width, height), new SimpleContext2D(false)); - PngIO.write(im, fPng, dpi); - g2d.dispose(); - return fPng; - } - }; - - final Lazy lsvg = new Lazy() { - public String getNow() throws IOException { - final UGraphicSvg ug = new UGraphicSvg(getSkinParam().getColorMapper(), true); - comp.drawU(ug, new Dimension(width, height), new SimpleContext2D(false)); - return getSvg(ug); - } - }; - - final Lazy leps = new Lazy() { - public File getNow() throws IOException { - final File fEps = FileUtils.createTempFile("plantumlB", ".eps"); - final PrintWriter pw = new PrintWriter(fEps); - final UGraphicEps uEps = new UGraphicEps(getSkinParam().getColorMapper(), getEpsStrategy(option - .getFileFormat())); - comp.drawU(uEps, new Dimension(width, height), new SimpleContext2D(false)); - pw.print(uEps.getEPSCode()); - pw.close(); - return fEps; - } - }; - return DrawFile.create(lpng, lsvg, leps, null); - } - - static public String getSvg(UGraphicSvg ug) throws IOException { - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - ug.createXml(baos); - baos.close(); - final String s = new String(baos.toByteArray(), "UTF-8"); - final Pattern p = Pattern.compile("(?i)"); - final Matcher m = p.matcher(s); - m.find(); - return m.group(0); - } - - private DrawFile createImageForActivity(Entity entity) throws IOException { - return null; - } - - private DrawFile createImageForCircleInterface(Entity entity, final double dpiFactor) throws IOException { - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - final HtmlColor interfaceBackground = rose.getHtmlColor(getSkinParam(), - ColorParam.componentInterfaceBackground, stereo); - final HtmlColor interfaceBorder = rose - .getHtmlColor(getSkinParam(), ColorParam.componentInterfaceBorder, stereo); - final HtmlColor background = rose.getHtmlColor(getSkinParam(), ColorParam.background, stereo); - final CircleInterface circleInterface = new CircleInterface(interfaceBackground, interfaceBorder); - - final Lazy lpng = new Lazy() { - - public File getNow() throws IOException { - final EmptyImageBuilder builder = new EmptyImageBuilder(circleInterface.getPreferredWidth(null) - * dpiFactor, circleInterface.getPreferredHeight(null) * dpiFactor, diagram.getColorMapper() - .getMappedColor(background)); - - final BufferedImage im = builder.getBufferedImage(); - final Graphics2D g2d = builder.getGraphics2D(); - - circleInterface.drawU(new UGraphicG2d(diagram.getColorMapper(), g2d, null, 1.0)); - - final File png = FileUtils.createTempFile("circleinterface", ".png"); - ImageIO.write(im, "png", png); - return png; - } - }; - - final Lazy leps = new Lazy() { - public File getNow() throws IOException { - final File epsFile = FileUtils.createTempFile("circleinterface", ".eps"); - UGraphicEps.copyEpsToFile(getSkinParam().getColorMapper(), circleInterface, epsFile); - return epsFile; - } - }; - - final Lazy lsvg = new Lazy() { - public String getNow() throws IOException { - return UGraphicG2d.getSvgString(getSkinParam().getColorMapper(), circleInterface); - } - - }; - - final Object signature = Arrays.asList("circleinterface", interfaceBackground, interfaceBorder, background, - dpiFactor); - - return DrawFile.create(lpng, lsvg, leps, signature); - } - - private DrawFile createImageForActor(Entity entity, final double dpiFactor) throws IOException { - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - final HtmlColor actorBackground = rose.getHtmlColor(getSkinParam(), ColorParam.usecaseActorBackground, stereo); - final HtmlColor actorBorder = rose.getHtmlColor(getSkinParam(), ColorParam.usecaseActorBorder, stereo); - final HtmlColor background = rose.getHtmlColor(getSkinParam(), ColorParam.background, stereo); - final StickMan stickMan = new StickMan(actorBackground, actorBorder); - - final Lazy lpng = new Lazy() { - public File getNow() throws IOException { - final EmptyImageBuilder builder = new EmptyImageBuilder(stickMan.getPreferredWidth(null) * dpiFactor, - stickMan.getPreferredHeight(null) * dpiFactor, diagram.getColorMapper().getMappedColor( - background)); - - final BufferedImage im = builder.getBufferedImage(); - final Graphics2D g2d = builder.getGraphics2D(); - - stickMan.drawU(new UGraphicG2d(diagram.getColorMapper(), g2d, null, dpiFactor)); - - final File png = FileUtils.createTempFile("actor", ".png"); - ImageIO.write(im, "png", png); - return png; - } - }; - final Lazy leps = new Lazy() { - public File getNow() throws IOException { - final File epsFile = FileUtils.createTempFile("actor", ".eps"); - UGraphicEps.copyEpsToFile(getSkinParam().getColorMapper(), stickMan, epsFile); - return epsFile; - } - }; - - final Lazy lsvg = new Lazy() { - public String getNow() throws IOException { - return UGraphicG2d.getSvgString(getSkinParam().getColorMapper(), stickMan); - } - - }; - - final Object signature = Arrays.asList("actor", actorBackground, actorBorder, background, dpiFactor); - - return DrawFile.create(lpng, lsvg, leps, signature); - } - - private DrawFile createImageForCircleCharacter(Entity entity, double dpiFactor) throws IOException { - final Stereotype stereotype = entity.getStereotype(); - - if (stereotype == null || stereotype.getHtmlColor() == null) { - return null; - } - - final String stereo = stereotype.getLabel(); - - final HtmlColor classBorder = rose.getHtmlColor(getSkinParam(), ColorParam.classBorder, stereo); - final HtmlColor classBackground = rose.getHtmlColor(getSkinParam(), ColorParam.classBackground, stereo); - final UFont font = diagram.getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, stereo); - final CircledCharacter circledCharacter = new CircledCharacter(stereotype.getCharacter(), getSkinParam() - .getCircledCharacterRadius(), font, stereotype.getHtmlColor(), classBorder, HtmlColor.BLACK); - return circledCharacter.generateCircleCharacter(diagram.getColorMapper(), classBackground, dpiFactor); - } - - private ISkinParam getSkinParam() { - return diagram.getSkinParam(); - } - - private EpsStrategy getEpsStrategy(FileFormat format) { - if (format == FileFormat.EPS_TEXT) { - return EpsStrategy.WITH_MACRO_AND_TEXT; - } - return EpsStrategy.getDefault2(); - } - - private String createEps(OutputStream os, List dotStrings, FileFormatOption fileFormatOption) - throws IOException, InterruptedException { - - try { - deltaY = 0; - final GraphvizMaker dotMaker = populateImagesAndCreateGraphvizMaker(dotStrings, fileFormatOption); - final String dotString = dotMaker.createDotString(); - - if (OptionFlags.getInstance().isKeepTmpFiles()) { - traceDotString(dotString); - } - - // final boolean isUnderline = dotMaker.isUnderline(); - final Graphviz graphviz = GraphvizUtils.create(dotString, "eps"); - - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - graphviz.createFile(baos); - baos.close(); - - dotMaker.clean(); - - final boolean isUnderline = dotMaker.isUnderline(); - String eps = new String(baos.toByteArray(), "UTF-8"); - eps = cleanStrangeCharacter(eps); - if (isUnderline) { - eps = new UnderlineTrickEps(eps).getString(); - } - - if (diagram.getTitle() != null) { - eps = addTitleEps(getEpsStrategy(fileFormatOption.getFileFormat()), eps); - } - if (diagram.getFooter() != null) { - eps = addFooterEps(getEpsStrategy(fileFormatOption.getFileFormat()), eps); - } - if (diagram.getHeader() != null) { - eps = addHeaderEps(getEpsStrategy(fileFormatOption.getFileFormat()), eps); - } - - os.write(eps.getBytes("UTF-8")); - - // final Dimension2D dim = getDimensionSvg(svg); - // - // svg = svg - // .replaceFirst( - // "(?i)]*>", - // ""); - // - // svg = addTitleSvg(svg, dim.getWidth(), dim.getHeight()); - // svg = addHeaderSvg(svg, dim.getWidth(), dim.getHeight()); - // svg = addFooterSvg(svg, dim.getWidth(), dim.getHeight()); - // - // // Image management - // final Pattern pImage = Pattern.compile("(?i)]*>"); - // final Matcher mImage = pImage.matcher(svg); - // final StringBuffer sb = new StringBuffer(); - // while (mImage.find()) { - // final String image = mImage.group(0); - // final String href = getValue(image, "href"); - // final double widthSvg = Double.parseDouble(getValuePx(image, - // "width")); - // final double heightSvg = Double.parseDouble(getValuePx(image, - // "height")); - // final double x = Double.parseDouble(getValue(image, "x")); - // final double y = Double.parseDouble(getValue(image, "y")); - // final DrawFile drawFile = getDrawFileFromHref(href); - // final int widthPng = drawFile.getWidthPng(); - // final int heightPng = drawFile.getHeightPng(); - // String svg2 = drawFile.getSvg(); - // final String scale = getScale(widthSvg, heightSvg, widthPng, - // heightPng); - // svg2 = svg2.replaceFirst("<[gG]>", ""); - // mImage.appendReplacement(sb, svg2); - // } - // mImage.appendTail(sb); - // svg = sb.toString(); - - } finally { - clean(); - } - return null; - } - - private void clean() throws IOException { - if (OptionFlags.getInstance().isKeepTmpFiles() == false) { - diagram.clean(); - if (staticFilesMap != null) { - staticFilesMap.clean(); - } - } - } - - private GraphvizMaker populateImagesAndCreateGraphvizMaker(List dotStrings, - FileFormatOption fileFormatOption) throws IOException, InterruptedException { - populateImages(fileFormatOption); - populateImagesLink(fileFormatOption); - final GraphvizMaker dotMaker = createDotMaker(dotStrings, fileFormatOption); - return dotMaker; - } - - private GraphvizMaker createDotMaker(List dotStrings, FileFormatOption fileFormatOption) - throws IOException, InterruptedException { - - final FileFormat fileFormat = fileFormatOption.getFileFormat(); - if (diagram.getUmlDiagramType() == UmlDiagramType.STATE - || diagram.getUmlDiagramType() == UmlDiagramType.ACTIVITY) { - new CucaDiagramSimplifier(diagram, dotStrings, fileFormat); - } - final DotData dotData = new DotData(null, diagram.getLinks(), diagram.entities(), diagram.getUmlDiagramType(), - diagram.getSkinParam(), diagram.getRankdir(), diagram, diagram, diagram.getColorMapper()); - - dotData.setDpi(diagram.getDpi(fileFormatOption)); - - if (diagram.getUmlDiagramType() == UmlDiagramType.CLASS || diagram.getUmlDiagramType() == UmlDiagramType.OBJECT) { - dotData.setStaticImagesMap(staticFilesMap); - if (diagram.isVisibilityModifierPresent()) { - dotData.setVisibilityModifierPresent(true); - } - } - - if (diagram.getUmlDiagramType() == UmlDiagramType.STATE) { - dotData.setHideEmptyDescription(((StateDiagram) diagram).isHideEmptyDescription()); - } - - return diagram.getSkinParam().getStrategy().getGraphvizMaker(dotData, dotStrings, fileFormat); - // return new DotMaker(dotData, dotStrings, fileFormat); - } - - private void populateImages(FileFormatOption option) throws IOException { - for (Entity entity : diagram.entities().values()) { - final DrawFile f = createImage(entity, option); - if (f != null) { - entity.setImageFile(f); - } - } - } - - private void populateImagesLink(FileFormatOption option) throws IOException { - for (Link link : diagram.getLinks()) { - final List note = link.getNote(); - if (note == null) { - continue; - } - final DrawFile f = createImageForNote(note, null, option, null); - if (f != null) { - link.setImageFile(f); - } - } - } - - static String cleanStrangeCharacter(String eps) { - final StringBuilder sb = new StringBuilder(); - final StringTokenizer st = new StringTokenizer(eps, "\r\n"); - while (st.hasMoreTokens()) { - String s = st.nextToken(); - if (s.equals(EpsGraphics.END_OF_FILE)) { - sb.append(s); - sb.append("\n"); - s = st.nextToken(); - if (s.equalsIgnoreCase("grestore") == false && st.hasMoreTokens()) { - s = st.nextToken(); - if (s.equalsIgnoreCase("grestore") == false) { - throw new IllegalStateException(); - } - } - } - sb.append(s); - sb.append("\n"); - } - return sb.toString(); - } - -} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramFileMakerBeta.java b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramFileMakerBeta.java deleted file mode 100644 index cb03b1947..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramFileMakerBeta.java +++ /dev/null @@ -1,183 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 4302 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.awt.Color; -import java.awt.Graphics2D; -import java.awt.geom.Dimension2D; -import java.awt.image.BufferedImage; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; - -import net.sourceforge.plantuml.EmptyImageBuilder; -import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.Log; -import net.sourceforge.plantuml.cucadiagram.CucaDiagram; -import net.sourceforge.plantuml.cucadiagram.Group; -import net.sourceforge.plantuml.cucadiagram.IEntity; -import net.sourceforge.plantuml.cucadiagram.Link; -import net.sourceforge.plantuml.png.PngIO; -import net.sourceforge.plantuml.png.PngSplitter; -import net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d; - -public final class CucaDiagramFileMakerBeta { - - private final CucaDiagram diagram; - - public CucaDiagramFileMakerBeta(CucaDiagram diagram) throws IOException { - this.diagram = diagram; - } - - public List createFile(File suggested, List dotStrings, FileFormat fileFormat) throws IOException, - InterruptedException { - OutputStream os = null; - try { - os = new BufferedOutputStream(new FileOutputStream(suggested)); - createFile(os, dotStrings, fileFormat); - } finally { - if (os != null) { - os.close(); - } - } - - if (fileFormat == FileFormat.PNG) { - final List result = new PngSplitter(suggested, diagram.getHorizontalPages(), diagram - .getVerticalPages(), diagram.getMetadata(), 96).getFiles(); - for (File f : result) { - Log.info("Creating file: " + f); - } - return result; - } - Log.info("Creating file: " + suggested); - return Arrays.asList(suggested); - } - - public void createFile(OutputStream os, List dotStrings, FileFormat fileFormat) throws IOException, - InterruptedException { - if (fileFormat == FileFormat.PNG) { - createPng(os, dotStrings); - // } else if (fileFormat == FileFormat.SVG) { - // createSvg(os, dotStrings); - // } else if (fileFormat == FileFormat.EPS) { - // createEps(os, dotStrings); - } else { - throw new UnsupportedOperationException(); - } - - } - - private void createPng(OutputStream os, List dotStrings) throws IOException, InterruptedException { - - final Color background = diagram.getColorMapper().getMappedColor(diagram.getSkinParam().getBackgroundColor()); - EmptyImageBuilder builder = new EmptyImageBuilder(10, 10, background); - BufferedImage im = builder.getBufferedImage(); - Graphics2D g2d = builder.getGraphics2D(); - UGraphicG2d ug = new UGraphicG2d(diagram.getColorMapper(), g2d, im, 1.0); - final PlayField playField = new PlayField(diagram.getSkinParam()); - - final Collection entities = getFirstLevelEntities(); - // System.err.println("entities=" + entities); - // final Collection links = getLinks(entities); - final Collection links = diagram.getLinks(); - - playField.initInternal(entities, links, ug.getStringBounder()); - g2d.dispose(); - - final Dimension2D dim = playField.solve(); - - builder = new EmptyImageBuilder(dim.getWidth() + 1, dim.getHeight() + 1, background); - im = builder.getBufferedImage(); - g2d = builder.getGraphics2D(); - g2d.translate(10, 0); - ug = new UGraphicG2d(diagram.getColorMapper(), g2d, im, 1.0); - - playField.drawInternal(ug); - - PngIO.write(im, os, 96); - - } - - // private List getLinks(Collection entities) { - // final List result = new ArrayList(); - // for (Link link : diagram.getLinks()) { - // if (entities.contains(link.getEntity1()) && - // entities.contains(link.getEntity2())) { - // result.add(link); - // } - // } - // return result; - // } - - private Collection getFirstLevelEntities() { - final Collection result = new HashSet(); - diagram.computeAutonomyOfGroups(); -// System.err.println("diagramEntities = " + diagram.entities()); -// System.err.println("diagramGroups = " + diagram.getGroups()); - addEntitiesOfGroup(result, null); - return result; - } - - private void addEntitiesOfGroup(final Collection result, Group parent) { -// System.err.println("addEntitiesOfGroup parent=" + parent); - for (IEntity ent : diagram.entities().values()) { - if (ent.getParent() == parent) { - result.add(ent); - // System.err.println("addingA " + ent); - } - } - final Collection groups = parent == null ? diagram.getGroups() : parent.getChildren(); - for (Group g : groups) { - // System.err.println("g=" + g + " parent = " + g.getParent()); - if (g.isAutonom() == false) { - addEntitiesOfGroup(result, g); - result.add(g.getEntityCluster()); - // System.err.println("addingB " + g.getEntityCluster()); - } else if (g.getParent() == parent) { - assert g.isAutonom(); - assert result.contains(g.getEntityCluster()) == false; - result.add(g.getEntityCluster()); - // System.err.println("addingC " + g.getEntityCluster()); - } - - } - } - -} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramPngMaker2.java b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramPngMaker2.java deleted file mode 100644 index d7d88c9e2..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramPngMaker2.java +++ /dev/null @@ -1,184 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6710 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.awt.Color; -import java.awt.Graphics2D; -import java.awt.geom.AffineTransform; -import java.awt.geom.Dimension2D; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import javax.imageio.ImageIO; - -import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.EmptyImageBuilder; -import net.sourceforge.plantuml.Log; -import net.sourceforge.plantuml.cucadiagram.CucaDiagram; -import net.sourceforge.plantuml.cucadiagram.Entity; -import net.sourceforge.plantuml.cucadiagram.Link; -import net.sourceforge.plantuml.graph.ANode; -import net.sourceforge.plantuml.graph.ANodeImpl; -import net.sourceforge.plantuml.graph.Board; -import net.sourceforge.plantuml.graph.BoardExplorer; -import net.sourceforge.plantuml.graph.Graph2; -import net.sourceforge.plantuml.graph.Heap; -import net.sourceforge.plantuml.graph.Zoda1; -import net.sourceforge.plantuml.graph.Zoda2; -import net.sourceforge.plantuml.png.PngSplitter; - -public final class CucaDiagramPngMaker2 { - - private final CucaDiagram diagram; - - public CucaDiagramPngMaker2(CucaDiagram diagram) { - this.diagram = diagram; - } - - public void createPng(OutputStream os) throws IOException { - final Zoda2 zoda2 = new Zoda2(); - - for (Link link : diagram.getLinks()) { - final String s = link.getEntity1().getCode() + "->" + link.getEntity2().getCode(); - System.err.println("CucaDiagramPngMaker2:: " + s); - final int diffHeight = link.getLength() - 1; - System.err.println("CucaDiagramPngMaker2:: " + s + " " + diffHeight); - zoda2.addLink(s, diffHeight, link); - } - for (Entity ent : diagram.entities().values()) { - ANode n = zoda2.getNode(ent.getCode()); - if (n == null) { - n = zoda2.createAloneNode(ent.getCode()); - } - ((ANodeImpl) n).setUserData(ent); - } - - final List graphs = getGraphs2(zoda2.getHeaps()); - - final Dimension2D totalDim = getTotalDimension(graphs); - final EmptyImageBuilder im = new EmptyImageBuilder(totalDim.getWidth(), totalDim.getHeight(), Color.WHITE); - - double x = 0; - - final Graphics2D g2d = im.getGraphics2D(); - - for (Graph2 g : graphs) { - g2d.setTransform(new AffineTransform()); - g2d.translate(x, 0); - g.draw(g2d); - x += g.getDimension().getWidth(); - } - - ImageIO.write(im.getBufferedImage(), "png", os); - } - - private Dimension2D getTotalDimension(List graphs) { - double width = 0; - double height = 0; - for (Graph2 g : graphs) { - width += g.getDimension().getWidth(); - height = Math.max(height, g.getDimension().getHeight()); - } - return new Dimension2DDouble(width, height); - - } - - private List getGraphs2(Collection heaps) { - final List result = new ArrayList(); - for (Heap h : heaps) { - h.computeRows(); - Board board = new Board(h.getNodes(), h.getLinks()); - - final BoardExplorer boardExplorer = new BoardExplorer(board); - final long start = System.currentTimeMillis(); - for (int i = 0; i < 400; i++) { - final boolean finished = boardExplorer.onePass(); - if (finished) { - break; - } - if (i % 100 == 0) { - Log.info("" + i + " boardExplorer.getBestCost()=" + boardExplorer.getBestCost() + " " - + boardExplorer.collectionSize()); - } - } - Log.info("################# DURATION = " + (System.currentTimeMillis() - start)); - board = boardExplorer.getBestBoard(); - - result.add(new Graph2(board)); - } - return result; - } - - private void createPngOld(OutputStream os) throws IOException { - final Zoda1 zoda1 = new Zoda1(); - if (diagram.getLinks().size() == 0) { - return; - } - for (Link link : diagram.getLinks()) { - final String s = link.getEntity1().getCode() + "->" + link.getEntity2().getCode(); - // System.err.println("CucaDiagramPngMaker2:: " + s); - zoda1.addLink(s); - } - for (Entity ent : diagram.entities().values()) { - final ANodeImpl n = zoda1.getExistingNode(ent.getCode()); - n.setUserData(ent); - } - zoda1.computeRows(); - final Board board = new Board(zoda1.getNodes(), zoda1.getLinks()); - // final BufferedImage im = new Graph2(board).createBufferedImage(); - // ImageIO.write(im, "png", os); - - } - - public List createPng(File pngFile) throws IOException { - OutputStream os = null; - try { - os = new BufferedOutputStream(new FileOutputStream(pngFile)); - createPng(os); - } finally { - if (os != null) { - os.close(); - } - } - - return new PngSplitter(pngFile, diagram.getHorizontalPages(), diagram.getVerticalPages(), - diagram.getMetadata(), 96).getFiles(); - } -} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramPngMaker3.java b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramPngMaker3.java index 99b86b4fc..602b1b114 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramPngMaker3.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramPngMaker3.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6710 $ + * Revision $Revision: 11914 $ * */ package net.sourceforge.plantuml.cucadiagram.dot; @@ -37,9 +37,6 @@ import java.awt.Color; import java.awt.Graphics2D; import java.awt.geom.AffineTransform; import java.awt.geom.Dimension2D; -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; @@ -52,7 +49,7 @@ import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.EmptyImageBuilder; import net.sourceforge.plantuml.Log; import net.sourceforge.plantuml.cucadiagram.CucaDiagram; -import net.sourceforge.plantuml.cucadiagram.Entity; +import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.cucadiagram.Link; import net.sourceforge.plantuml.graph.ANode; import net.sourceforge.plantuml.graph.ANodeImpl; @@ -61,7 +58,6 @@ import net.sourceforge.plantuml.graph.BoardExplorer; import net.sourceforge.plantuml.graph.Graph5; import net.sourceforge.plantuml.graph.Heap; import net.sourceforge.plantuml.graph.Zoda2; -import net.sourceforge.plantuml.png.PngSplitter; public final class CucaDiagramPngMaker3 { @@ -81,10 +77,10 @@ public final class CucaDiagramPngMaker3 { // Log.error("CucaDiagramPngMaker3:: " + s + " " + diffHeight); zoda2.addLink(s, diffHeight, link); } - for (Entity ent : diagram.entities().values()) { - ANode n = zoda2.getNode(ent.getCode()); + for (IEntity ent : diagram.getLeafs().values()) { + ANode n = zoda2.getNode(ent.getCode().getCode()); if (n == null) { - n = zoda2.createAloneNode(ent.getCode()); + n = zoda2.createAloneNode(ent.getCode().getCode()); } ((ANodeImpl) n).setUserData(ent); } @@ -146,18 +142,18 @@ public final class CucaDiagramPngMaker3 { return result; } - public List createPng(File pngFile) throws IOException { - OutputStream os = null; - try { - os = new BufferedOutputStream(new FileOutputStream(pngFile)); - createPng(os); - } finally { - if (os != null) { - os.close(); - } - } - - return new PngSplitter(pngFile, diagram.getHorizontalPages(), diagram.getVerticalPages(), diagram.getMetadata(), 96) - .getFiles(); - } +// public List createPng(File pngFile) throws IOException { +// OutputStream os = null; +// try { +// os = new BufferedOutputStream(new FileOutputStream(pngFile)); +// createPng(os); +// } finally { +// if (os != null) { +// os.close(); +// } +// } +// +// return new PngSplitter(pngFile, diagram.getHorizontalPages(), diagram.getVerticalPages(), diagram.getMetadata(), 96) +// .getFiles(); +// } } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramSimplifier.java b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramSimplifier.java deleted file mode 100644 index cfa087781..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramSimplifier.java +++ /dev/null @@ -1,171 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6710 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import net.sourceforge.plantuml.ColorParam; -import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.FileUtils; -import net.sourceforge.plantuml.OptionFlags; -import net.sourceforge.plantuml.cucadiagram.CucaDiagram; -import net.sourceforge.plantuml.cucadiagram.Entity; -import net.sourceforge.plantuml.cucadiagram.EntityType; -import net.sourceforge.plantuml.cucadiagram.Group; -import net.sourceforge.plantuml.cucadiagram.GroupType; -import net.sourceforge.plantuml.cucadiagram.IEntity; -import net.sourceforge.plantuml.cucadiagram.Member; -import net.sourceforge.plantuml.cucadiagram.Stereotype; -import net.sourceforge.plantuml.graphic.HtmlColor; -import net.sourceforge.plantuml.skin.rose.Rose; - -public final class CucaDiagramSimplifier { - - private final CucaDiagram diagram; - private final FileFormat fileFormat; - - public CucaDiagramSimplifier(CucaDiagram diagram, List dotStrings, FileFormat fileFormat) - throws IOException, InterruptedException { - this.diagram = diagram; - this.fileFormat = fileFormat; - boolean changed; - do { - changed = false; - final Collection groups = new ArrayList(diagram.getGroups()); - for (Group g : groups) { - if (diagram.isAutarkic(g)) { - final EntityType type; - if (g.getType() == GroupType.CONCURRENT_STATE) { - type = EntityType.STATE_CONCURRENT; - } else if (g.getType() == GroupType.STATE) { - type = EntityType.STATE; - } else if (g.getType() == GroupType.INNER_ACTIVITY) { - type = EntityType.ACTIVITY; - } else if (g.getType() == GroupType.CONCURRENT_ACTIVITY) { - type = EntityType.ACTIVITY_CONCURRENT; - } else { - throw new IllegalStateException(); - } - final Entity proxy = new Entity("#" + g.getCode(), g.getDisplay(), type, g.getParent(), - diagram.getHides()); - if (type == EntityType.STATE) { - manageBackColorForState(diagram, g, proxy); - } - for (Member field : g.getEntityCluster().getFieldsToDisplay()) { - proxy.addField(field); - } - computeImageGroup(g, proxy, dotStrings); - diagram.overideGroup(g, proxy); - if (proxy.getImageFile() != null) { - diagram.ensureDelete(proxy.getImageFile()); - } - -// final IEntity entityCluster = g.getEntityCluster(); -// if (entityCluster != null && entityCluster.getImageFile() != null) { -// proxy.addSubImage(entityCluster.getImageFile()); -// } -// if (entityCluster != null) { -// proxy.addSubImage((Entity) entityCluster); -// } - - for (IEntity sub : g.entities().values()) { - final DrawFile subImage = sub.getImageFile(); - if (subImage != null) { - proxy.addSubImage(subImage); - } - } - - changed = true; - } - } - } while (changed); - } - - private void computeImageGroup(final Group group, final Entity entity, List dotStrings) throws IOException, - FileNotFoundException, InterruptedException { - if (group.entities().size()==0) { - return; - } - final GroupPngMaker maker = new GroupPngMaker(diagram, group, fileFormat); - final File f = FileUtils.createTempFile("inner", ".png"); - OutputStream fos = null; - try { - fos = new BufferedOutputStream(new FileOutputStream(f)); - maker.createPng(fos, dotStrings); - final String svg = maker.createSvg(dotStrings); - // final Pattern pImage = Pattern.compile("(?i)]*>"); - // final Matcher mImage = pImage.matcher(svg); - // if (mImage.find()) { - // throw new IllegalStateException(); - // } - entity.setImageFile(DrawFile.createFromFile(f, svg, null)); - } finally { - if (fos != null) { - fos.close(); - } - } - } - - private void manageBackColorForState(CucaDiagram diagram, Group g, final Entity proxy) { - if (OptionFlags.PBBACK == false) { - return; - } - if (g.getBackColor() != null) { - proxy.setSpecificBackcolor(g.getBackColor()); - return; - } - assert g.getBackColor() == null; - if (g.getStereotype() != null) { - proxy.setStereotype(new Stereotype(g.getStereotype())); - } - // PBBACK - final Rose rose = new Rose(); - final HtmlColor back = rose.getHtmlColor(diagram.getSkinParam(), ColorParam.stateBackground, g.getStereotype()); - // final HtmlColor back = diagram.getSkinParam().getHtmlColor(ColorParam.stateBackground, g.getStereotype()); - // if (back != null) { - // proxy.setSpecificBackcolor(back.getAsHtml()); - // } - assert g.getBackColor() == null; - g.setBackColor(back); - } - -} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramSimplifier2.java b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramSimplifier2.java deleted file mode 100644 index ad65edf52..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramSimplifier2.java +++ /dev/null @@ -1,115 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6710 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import net.sourceforge.plantuml.cucadiagram.CucaDiagram; -import net.sourceforge.plantuml.cucadiagram.Entity; -import net.sourceforge.plantuml.cucadiagram.EntityType; -import net.sourceforge.plantuml.cucadiagram.Group; -import net.sourceforge.plantuml.cucadiagram.GroupType; -import net.sourceforge.plantuml.cucadiagram.IEntity; -import net.sourceforge.plantuml.cucadiagram.Member; -import net.sourceforge.plantuml.svek.GroupPngMaker2; - -public final class CucaDiagramSimplifier2 { - - private final CucaDiagram diagram; - - public CucaDiagramSimplifier2(CucaDiagram diagram, List dotStrings) throws IOException, InterruptedException { - this.diagram = diagram; - boolean changed; - do { - changed = false; - final Collection groups = new ArrayList(diagram.getGroups()); - for (Group g : groups) { - if (diagram.isAutarkic(g)) { - final EntityType type; - if (g.getType() == GroupType.CONCURRENT_STATE) { - type = EntityType.STATE_CONCURRENT; - } else if (g.getType() == GroupType.STATE) { - type = EntityType.STATE; - } else if (g.getType() == GroupType.INNER_ACTIVITY) { - type = EntityType.ACTIVITY; - } else if (g.getType() == GroupType.CONCURRENT_ACTIVITY) { - type = EntityType.ACTIVITY_CONCURRENT; - } else { - throw new IllegalStateException(); - } - final Entity proxy = new Entity("#" + g.getCode(), g.getDisplay(), type, g.getParent(), diagram - .getHides()); - // if (type == EntityType.STATE) { - // manageBackColorForState(diagram, g, proxy); - // } - for (Member field : g.getEntityCluster().getFieldsToDisplay()) { - proxy.addField(field); - } - computeImageGroup(g, proxy, dotStrings); - diagram.overideGroup(g, proxy); - if (proxy.getImageFile() != null) { - diagram.ensureDelete(proxy.getImageFile()); - } - - // final IEntity entityCluster = g.getEntityCluster(); - // if (entityCluster != null && entityCluster.getImageFile() - // != null) { - // proxy.addSubImage(entityCluster.getImageFile()); - // } - // if (entityCluster != null) { - // proxy.addSubImage((Entity) entityCluster); - // } - - for (IEntity sub : g.entities().values()) { - final DrawFile subImage = sub.getImageFile(); - if (subImage != null) { - proxy.addSubImage(subImage); - } - } - - changed = true; - } - } - } while (changed); - } - - private void computeImageGroup(Group g, Entity proxy, List dotStrings) throws IOException, InterruptedException { - final GroupPngMaker2 maker = new GroupPngMaker2(diagram, g); - proxy.setSvekImage(maker.getImage()); - } - -} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramSimplifierActivity.java b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramSimplifierActivity.java new file mode 100644 index 000000000..ccc762878 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramSimplifierActivity.java @@ -0,0 +1,89 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 6710 $ + * + */ +package net.sourceforge.plantuml.cucadiagram.dot; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import net.sourceforge.plantuml.cucadiagram.CucaDiagram; +import net.sourceforge.plantuml.cucadiagram.IGroup; +import net.sourceforge.plantuml.cucadiagram.LeafType; +import net.sourceforge.plantuml.svek.GroupPngMakerActivity; +import net.sourceforge.plantuml.svek.IEntityImage; + +public final class CucaDiagramSimplifierActivity { + + private final CucaDiagram diagram; + + public CucaDiagramSimplifierActivity(CucaDiagram diagram, List dotStrings) throws IOException, + InterruptedException { + this.diagram = diagram; + boolean changed; + do { + changed = false; + final Collection groups = new ArrayList(diagram.getGroups(false)); + for (IGroup g : groups) { + if (diagram.isAutarkic(g)) { +// final EntityType type; +// if (g.zgetGroupType() == GroupType.INNER_ACTIVITY) { +// type = EntityType.ACTIVITY; +// } else if (g.zgetGroupType() == GroupType.CONCURRENT_ACTIVITY) { +// type = EntityType.ACTIVITY_CONCURRENT; +// } else { +// throw new IllegalStateException(); +// } + + final IEntityImage img = computeImage(g); + g.overideImage(img, LeafType.ACTIVITY); + + changed = true; + } + } + } while (changed); + } + +// private void computeImageGroup(EntityMutable g, EntityMutable proxy, List dotStrings) throws IOException, +// InterruptedException { +// final GroupPngMakerActivity maker = new GroupPngMakerActivity(diagram, g); +// proxy.setSvekImage(maker.getImage()); +// } + + private IEntityImage computeImage(IGroup g) throws IOException, InterruptedException { + final GroupPngMakerActivity maker = new GroupPngMakerActivity(diagram, g); + return maker.getImage(); + } + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramSimplifierState.java b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramSimplifierState.java new file mode 100644 index 000000000..c3fb43d71 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramSimplifierState.java @@ -0,0 +1,94 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 6710 $ + * + */ +package net.sourceforge.plantuml.cucadiagram.dot; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import net.sourceforge.plantuml.cucadiagram.CucaDiagram; +import net.sourceforge.plantuml.cucadiagram.GroupType; +import net.sourceforge.plantuml.cucadiagram.IGroup; +import net.sourceforge.plantuml.cucadiagram.LeafType; +import net.sourceforge.plantuml.svek.GroupPngMakerState; +import net.sourceforge.plantuml.svek.IEntityImage; + +public final class CucaDiagramSimplifierState { + + private final CucaDiagram diagram; + + public CucaDiagramSimplifierState(CucaDiagram diagram, List dotStrings) throws IOException, + InterruptedException { + this.diagram = diagram; + boolean changed; + do { + changed = false; + final Collection groups = putConcurrentStateAtEnd(diagram.getGroups(false)); + for (IGroup g : groups) { + if (diagram.isAutarkic(g)) { + final IEntityImage img = computeImage(g); + // final List urls = new ArrayList(g.getUrlsTOBEREMOVED()); + // for (IEntity ent : g.getLeafsDirect()) { + // urls.addAll(ent.getUrlsTOBEREMOVED()); + // } + g.overideImage(img, g.getGroupType() == GroupType.CONCURRENT_STATE ? LeafType.STATE_CONCURRENT + : LeafType.STATE); + + changed = true; + } + } + } while (changed); + } + + private Collection putConcurrentStateAtEnd(Collection groups) { + final List result = new ArrayList(); + final List end = new ArrayList(); + for (IGroup g : groups) { + if (g.getGroupType() == GroupType.CONCURRENT_STATE) { + end.add(g); + } else { + result.add(g); + } + } + result.addAll(end); + return result; + } + + private IEntityImage computeImage(IGroup g) throws IOException, InterruptedException { + final GroupPngMakerState maker = new GroupPngMakerState(diagram, g); + return maker.getImage(); + } + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramTxtMaker.java b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramTxtMaker.java index f03579682..792558048 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramTxtMaker.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/CucaDiagramTxtMaker.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,7 +33,6 @@ */ package net.sourceforge.plantuml.cucadiagram.dot; -import java.awt.geom.Dimension2D; import java.awt.geom.Point2D; import java.io.File; import java.io.IOException; @@ -49,20 +48,22 @@ import java.util.Map; import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.StringUtils; import net.sourceforge.plantuml.cucadiagram.CucaDiagram; -import net.sourceforge.plantuml.cucadiagram.Entity; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.cucadiagram.Link; import net.sourceforge.plantuml.cucadiagram.Member; import net.sourceforge.plantuml.posimo.Block; import net.sourceforge.plantuml.posimo.Cluster; import net.sourceforge.plantuml.posimo.GraphvizSolverB; import net.sourceforge.plantuml.posimo.Path; +import net.sourceforge.plantuml.ugraphic.UTranslate; import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt; public final class CucaDiagramTxtMaker { - private final CucaDiagram diagram; + // private final CucaDiagram diagram; private final FileFormat fileFormat; - private final UGraphicTxt ug = new UGraphicTxt(); + private final UGraphicTxt globalUg = new UGraphicTxt(); private static double getXPixelPerChar() { return 5; @@ -73,15 +74,15 @@ public final class CucaDiagramTxtMaker { } public CucaDiagramTxtMaker(CucaDiagram diagram, FileFormat fileFormat) throws IOException { - this.diagram = diagram; + // this.diagram = diagram; this.fileFormat = fileFormat; final Cluster root = new Cluster(null, 0, 0); int uid = 0; - final Map blocks = new HashMap(); + final Map blocks = new HashMap(); - for (Entity ent : diagram.entities().values()) { + for (IEntity ent : diagram.getLeafs().values()) { // printClass(ent); // ug.translate(0, getHeight(ent) + 1); final double width = getWidth(ent) * getXPixelPerChar(); @@ -92,49 +93,45 @@ public final class CucaDiagramTxtMaker { } final GraphvizSolverB solver = new GraphvizSolverB(); - try { - final Collection paths = new ArrayList(); - for (Link link : diagram.getLinks()) { - final Block b1 = blocks.get(link.getEntity1()); - final Block b2 = blocks.get(link.getEntity2()); - paths.add(new Path(b1, b2, null, link.getLength())); - } - final Dimension2D dim = solver.solve(root, paths); - for (Path p : paths) { - ug.setTranslate(0, 0); - p.getDotPath().draw(ug.getCharArea(), getXPixelPerChar(), getYPixelPerChar()); - } - for (Entity ent : diagram.entities().values()) { - final Block b = blocks.get(ent); - final Point2D p = b.getPosition(); - ug.setTranslate(p.getX() / getXPixelPerChar(), p.getY() / getYPixelPerChar()); - printClass(ent); - } - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + final Collection paths = new ArrayList(); + for (Link link : diagram.getLinks()) { + final Block b1 = blocks.get(link.getEntity1()); + final Block b2 = blocks.get(link.getEntity2()); + paths.add(new Path(b1, b2, null, link.getLength())); + } + solver.solve(root, paths); + for (Path p : paths) { + p.getDotPath().draw(globalUg.getCharArea(), getXPixelPerChar(), getYPixelPerChar()); + } + for (IEntity ent : diagram.getLeafs().values()) { + final Block b = blocks.get(ent); + final Point2D p = b.getPosition(); + printClass( + ent, + (UGraphicTxt) globalUg.apply(new UTranslate(p.getX() / getXPixelPerChar(), p.getY() + / getYPixelPerChar()))); } } - private void printClass(final Entity ent) { + private void printClass(final IEntity ent, UGraphicTxt ug) { final int w = getWidth(ent); final int h = getHeight(ent); ug.getCharArea().drawBoxSimple(0, 0, w, h); - ug.getCharArea().drawStringsLR(ent.getDisplay2(), 1, 1); + ug.getCharArea().drawStringsLR(ent.getDisplay().as(), 1, 1); int y = 2; ug.getCharArea().drawHLine('-', y, 1, w - 1); y++; for (Member att : ent.getFieldsToDisplay()) { - final List disp = StringUtils.getWithNewlines(att.getDisplayWithVisibilityChar()); + final List disp = StringUtils.getWithNewlines2(att.getDisplay(true)); ug.getCharArea().drawStringsLR(disp, 1, y); y += StringUtils.getHeight(disp); } ug.getCharArea().drawHLine('-', y, 1, w - 1); y++; for (Member att : ent.getMethodsToDisplay()) { - final List disp = StringUtils.getWithNewlines(att.getDisplayWithVisibilityChar()); + final List disp = StringUtils.getWithNewlines2(att.getDisplay(true)); ug.getCharArea().drawStringsLR(disp, 1, y); y += StringUtils.getHeight(disp); } @@ -142,34 +139,34 @@ public final class CucaDiagramTxtMaker { public List createFiles(File suggestedFile) throws IOException { if (fileFormat == FileFormat.UTXT) { - ug.getCharArea().print(new PrintStream(suggestedFile, "UTF-8")); + globalUg.getCharArea().print(new PrintStream(suggestedFile, "UTF-8")); } else { - ug.getCharArea().print(new PrintStream(suggestedFile)); + globalUg.getCharArea().print(new PrintStream(suggestedFile)); } return Collections.singletonList(suggestedFile); } - private int getHeight(Entity entity) { - int result = StringUtils.getHeight(entity.getDisplay2()); + private int getHeight(IEntity entity) { + int result = StringUtils.getHeight(entity.getDisplay()); for (Member att : entity.getMethodsToDisplay()) { - result += StringUtils.getHeight(StringUtils.getWithNewlines(att.getDisplayWithVisibilityChar())); + result += StringUtils.getHeight(Display.getWithNewlines(att.getDisplay(true))); } for (Member att : entity.getFieldsToDisplay()) { - result += StringUtils.getHeight(StringUtils.getWithNewlines(att.getDisplayWithVisibilityChar())); + result += StringUtils.getHeight(Display.getWithNewlines(att.getDisplay(true))); } return result + 4; } - private int getWidth(Entity entity) { - int result = StringUtils.getWidth(entity.getDisplay2()); + private int getWidth(IEntity entity) { + int result = StringUtils.getWidth(entity.getDisplay()); for (Member att : entity.getMethodsToDisplay()) { - final int w = StringUtils.getWidth(StringUtils.getWithNewlines(att.getDisplayWithVisibilityChar())); + final int w = StringUtils.getWidth(Display.getWithNewlines(att.getDisplay(true))); if (w > result) { result = w; } } for (Member att : entity.getFieldsToDisplay()) { - final int w = StringUtils.getWidth(StringUtils.getWithNewlines(att.getDisplayWithVisibilityChar())); + final int w = StringUtils.getWidth(Display.getWithNewlines(att.getDisplay(true))); if (w > result) { result = w; } @@ -178,7 +175,7 @@ public final class CucaDiagramTxtMaker { } public void createFiles(OutputStream os, int index) { - ug.getCharArea().print(new PrintStream(os)); + globalUg.getCharArea().print(new PrintStream(os)); } } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/DebugTrace.java b/src/net/sourceforge/plantuml/cucadiagram/dot/DebugTrace.java new file mode 100644 index 000000000..70d92f2a4 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/DebugTrace.java @@ -0,0 +1,69 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 10765 $ + * + */ +package net.sourceforge.plantuml.cucadiagram.dot; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; + +public class DebugTrace { + + private static final File out = new File("debug" + System.currentTimeMillis() + ".txt"); + + private static PrintWriter pw; + + private synchronized static PrintWriter getPrintWriter() { + if (pw == null) { + try { + pw = new PrintWriter(out); + } catch (FileNotFoundException e) { + + } + } + return pw; + } + + public synchronized static void DEBUG(String s) { + final PrintWriter pw = getPrintWriter(); + pw.println(s); + pw.flush(); + } + + public synchronized static void DEBUG(String s, Throwable t) { + DEBUG(s); + t.printStackTrace(pw); + pw.flush(); + } + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/DotCommon.java b/src/net/sourceforge/plantuml/cucadiagram/dot/DotCommon.java deleted file mode 100644 index 8ea72c7ed..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/DotCommon.java +++ /dev/null @@ -1,307 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6295 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; -import java.util.Collection; - -import javax.imageio.ImageIO; - -import net.sourceforge.plantuml.ColorParam; -import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.FontParam; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.cucadiagram.EntityPortion; -import net.sourceforge.plantuml.cucadiagram.EntityType; -import net.sourceforge.plantuml.cucadiagram.Group; -import net.sourceforge.plantuml.cucadiagram.IEntity; -import net.sourceforge.plantuml.cucadiagram.Member; -import net.sourceforge.plantuml.cucadiagram.Stereotype; -import net.sourceforge.plantuml.graphic.HtmlColor; -import net.sourceforge.plantuml.skin.rose.Rose; -import net.sourceforge.plantuml.ugraphic.ColorMapper; - -abstract class DotCommon { - - private final DotData data; - private final FileFormat fileFormat; - private boolean underline; - - private final Rose rose = new Rose(); - - DotCommon(FileFormat fileFormat, DotData data) { - this.fileFormat = fileFormat; - this.data = data; - } - - protected final Stereotype getStereotype(IEntity entity) { - if (data.showPortion(EntityPortion.STEREOTYPE, entity) == false) { - return null; - } - return entity.getStereotype(); - } - - protected final ColorMapper getColorMapper() { - return data.getColorMapper(); - } - - protected final boolean isThereLabel(final Stereotype stereotype) { - return stereotype != null && stereotype.getLabel() != null; - } - - protected final double getMagicFactorForImageDpi() { - return 10500 / 100000.0; - } - - protected final void appendLabelAndStereotype(IEntity entity, final StringBuilder sb, boolean classes) { - final Stereotype stereotype = getStereotype(entity); - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - if (isThereLabel(stereotype)) { - sb.append("
    "); - for (String st : stereotype.getLabels()) { - sb.append(manageHtmlIB(st, classes ? FontParam.CLASS_STEREOTYPE : FontParam.OBJECT_STEREOTYPE, stereo)); - sb.append("
    "); - } - } - String display = StringUtils.getMergedLines(entity.getDisplay2()); - final boolean italic = entity.getType() == EntityType.ABSTRACT_CLASS - || entity.getType() == EntityType.INTERFACE; - if (italic) { - display = "" + display; - } - sb.append(manageHtmlIB(display, classes ? FontParam.CLASS : FontParam.OBJECT, stereo)); - } - - protected final String manageHtmlIB(String s, FontParam param, String stereotype) { - s = unicode(s); - final int fontSize = data.getSkinParam().getFont(param, stereotype).getSize(); - final int style = data.getSkinParam().getFont(param, stereotype).getStyle(); - final String fontFamily = data.getSkinParam().getFont(param, stereotype).getFamily(null); - final DotExpression dotExpression = new DotExpression(getColorMapper(), s, fontSize, getFontHtmlColor(param, - stereotype), fontFamily, style, fileFormat); - final String result = dotExpression.getDotHtml(); - if (dotExpression.isUnderline()) { - underline = true; - } - return result; - } - - protected final HtmlColor getFontHtmlColor(FontParam fontParam, String stereotype) { - return data.getSkinParam().getFontHtmlColor(fontParam, stereotype); - } - - static String unicode(String s) { - final StringBuilder result = new StringBuilder(); - for (char c : s.toCharArray()) { - if (c > 127 || c == '&' || c == '|') { - // if (c > 127 || c == '&') { - final int i = c; - result.append("&#" + i + ";"); - } else { - result.append(c); - } - } - return result.toString(); - } - - protected final void addTdImageBugB1983(final StringBuilder sb, final String absolutePath) throws IOException { - // http://www.graphviz.org/bugs/b1983.html - final BufferedImage im = ImageIO.read(new File(absolutePath)); - final int height = im.getHeight(); - final int width = im.getWidth(); - final double f = 1.0 / data.getDpiFactor(); - final int w = (int) (width * f); - final int h = (int) (height * f); - final int w2 = (int) (width * getMagicFactorForImageDpi()); - final int h2 = (int) (height * getMagicFactorForImageDpi()); - sb.append(getTdHeaderForDpi(w, h)); - sb.append(""); - sb.append(""); - sb.append(getTdHeaderForDpi(w2, h2)); - sb.append(""); - sb.append(""); - sb.append(""); - sb.append("
    "); - sb.append(""); - } - - protected final String getTdHeaderForDpi(final double w, final double h) { - // return ""; - return ""; - } - - public final boolean isUnderline() { - return underline; - } - - protected final DotData getData() { - return data; - } - - protected final FileFormat getFileFormat() { - return fileFormat; - } - - protected final void setUnderline(boolean underline) { - this.underline = underline; - } - - protected final int getLongestMethods(IEntity entity) { - int result = 0; - for (Member att : entity.getMethodsToDisplay()) { - final int size = att.getDisplayWithVisibilityChar().length(); - if (size > result) { - result = size; - } - } - return result; - - } - - protected final int getLongestField(IEntity entity) { - int result = 0; - for (Member att : entity.getFieldsToDisplay()) { - final int size = att.getDisplayWithVisibilityChar().length(); - if (size > result) { - result = size; - } - } - return result; - } - - protected final String getWitdh55() { - if (getData().getDpi() == 96) { - return "WIDTH=\"55\""; - } - return "WIDTH=\"55\""; - } - - protected final int computeSpring(final int current, final int maximum, int maxSpring) { - if (maximum <= current) { - return 0; - } - final int spring = maximum - current; - if (spring > maxSpring) { - return maxSpring; - } - return spring; - } - - protected final int getLonguestHeader(IEntity entity) { - int result = StringUtils.getMergedLines(entity.getDisplay2()).length(); - final Stereotype stereotype = getStereotype(entity); - if (isThereLabel(stereotype)) { - final int size = stereotype.getLabel().length(); - if (size > result) { - result = size; - } - } - return result; - } - - protected final String getColorString(ColorParam colorParam, String stereotype) { - return "\"" + getAsHtml(rose.getHtmlColor(getData().getSkinParam(), colorParam, stereotype)) + "\""; - } - - protected final String getAsHtml(HtmlColor htmlColor) { - return StringUtils.getAsHtml(getColorMapper().getMappedColor(htmlColor)); - } - - protected final int getLongestFieldOrAttribute(IEntity entity) { - return Math.max(getLongestField(entity), getLongestMethods(entity)); - } - - protected final boolean hasStatic(Collection attributes) { - for (Member att : attributes) { - if (att.isStatic()) { - return true; - } - } - return false; - } - - protected final String manageHtmlIBspecial(Member att, FontParam param, boolean hasStatic, String backColor, - boolean withVisibilityChar) { - String prefix = ""; - if (hasStatic) { - prefix = "_"; - } - if (att.isAbstract()) { - return prefix + manageHtmlIB("" + att.getDisplay(withVisibilityChar), param, null); - } - if (att.isStatic()) { - return manageHtmlIB("" + att.getDisplay(withVisibilityChar), param, null); - } - return prefix + manageHtmlIB(att.getDisplay(withVisibilityChar), param, null); - } - - final protected String getBackColorAroundEntity(IEntity entity) { - String backColor = getSpecificBackColor(entity); - if (backColor == null) { - backColor = getColorString(ColorParam.background, null); - } - return backColor; - } - - private String getSpecificBackColor(IEntity entity) { - final Group parent = entity.getParent(); - if (parent == null) { - return null; - } - if (parent.getBackColor() == null) { - return null; - } - return "\"" + getAsHtml(parent.getBackColor()) + "\""; - } - - final protected void appendImageAsTD(StringBuilder sb, String circleAbsolutePath) throws IOException { - if (circleAbsolutePath.endsWith(".png")) { - if (getData().getDpi() == 96) { - final BufferedImage im = ImageIO.read(new File(circleAbsolutePath)); - final int height = im.getHeight(); - final int width = im.getWidth(); - sb.append(""); - } else { - addTdImageBugB1983(sb, circleAbsolutePath); - } - } else if (circleAbsolutePath.endsWith(".eps")) { - sb.append(""); - } - } - -} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/DotData.java b/src/net/sourceforge/plantuml/cucadiagram/dot/DotData.java index 54504c285..72428f18a 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/DotData.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/DotData.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,107 +28,72 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6577 $ + * Revision $Revision: 12087 $ * */ package net.sourceforge.plantuml.cucadiagram.dot; -import java.io.IOException; -import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; import java.util.List; -import java.util.Map; -import java.util.Set; import net.sourceforge.plantuml.ISkinParam; import net.sourceforge.plantuml.UmlDiagramType; import net.sourceforge.plantuml.cucadiagram.EntityPortion; -import net.sourceforge.plantuml.cucadiagram.EntityType; -import net.sourceforge.plantuml.cucadiagram.Group; import net.sourceforge.plantuml.cucadiagram.GroupHierarchy; -import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.IGroup; +import net.sourceforge.plantuml.cucadiagram.ILeaf; import net.sourceforge.plantuml.cucadiagram.Link; import net.sourceforge.plantuml.cucadiagram.PortionShower; import net.sourceforge.plantuml.cucadiagram.Rankdir; -import net.sourceforge.plantuml.skin.VisibilityModifier; +import net.sourceforge.plantuml.cucadiagram.entity.EntityFactory; +import net.sourceforge.plantuml.svek.DotMode; import net.sourceforge.plantuml.ugraphic.ColorMapper; final public class DotData implements PortionShower { final private List links; - final private Map entities; + final private Collection leafs; final private UmlDiagramType umlDiagramType; final private ISkinParam skinParam; final private Rankdir rankdir; final private GroupHierarchy groupHierarchy; - final private Group topParent; + final private IGroup topParent; final private PortionShower portionShower; - private int dpi = 96; + final private boolean isHideEmptyDescriptionForState; + final private DotMode dotMode; - private StaticFilesMap staticFilesMap; - private boolean visibilityModifierPresent; private final ColorMapper colorMapper; + private final EntityFactory entityFactory; - public DotData(Group topParent, List links, Map entities, - UmlDiagramType umlDiagramType, ISkinParam skinParam, Rankdir rankdir, GroupHierarchy groupHierarchy, - PortionShower portionShower, ColorMapper colorMapper) { + public DotData(IGroup topParent, List links, Collection leafs, UmlDiagramType umlDiagramType, + ISkinParam skinParam, Rankdir rankdir, GroupHierarchy groupHierarchy, PortionShower portionShower, + ColorMapper colorMapper, EntityFactory entityFactory, boolean isHideEmptyDescriptionForState, + DotMode dotMode) { this.topParent = topParent; + if (topParent == null) { + throw new IllegalArgumentException(); + } + this.dotMode = dotMode; + this.isHideEmptyDescriptionForState = isHideEmptyDescriptionForState; this.colorMapper = colorMapper; this.links = links; - this.entities = entities; + this.leafs = leafs; this.umlDiagramType = umlDiagramType; this.skinParam = skinParam; this.rankdir = rankdir; this.groupHierarchy = groupHierarchy; this.portionShower = portionShower; + this.entityFactory = entityFactory; } - public DotData(Group topParent, List links, Map entities, - UmlDiagramType umlDiagramType, ISkinParam skinParam, Rankdir rankdir, GroupHierarchy groupHierarchy, - ColorMapper colorMapper) { - this(topParent, links, entities, umlDiagramType, skinParam, rankdir, groupHierarchy, new PortionShower() { - public boolean showPortion(EntityPortion portion, IEntity entity) { + public DotData(IGroup topParent, List links, Collection leafs, UmlDiagramType umlDiagramType, + ISkinParam skinParam, Rankdir rankdir, GroupHierarchy groupHierarchy, ColorMapper colorMapper, + EntityFactory entityFactory, boolean isHideEmptyDescriptionForState, DotMode dotMode) { + this(topParent, links, leafs, umlDiagramType, skinParam, rankdir, groupHierarchy, new PortionShower() { + public boolean showPortion(EntityPortion portion, ILeaf entity) { return true; } - }, colorMapper); - } - - public boolean hasUrl() { - return true; - } - - public DrawFile getStaticImages(EntityType type, String stereo) throws IOException { - checkObjectOrClassDiagram(); - assert type == EntityType.ABSTRACT_CLASS || type == EntityType.CLASS || type == EntityType.ENUM - || type == EntityType.INTERFACE || type == EntityType.LOLLIPOP; - return staticFilesMap.getStaticFiles(stereo).getStaticImages(type); - } - - public DrawFile getVisibilityImages(VisibilityModifier visibilityModifier, String stereo) throws IOException { - checkObjectOrClassDiagram(); - return staticFilesMap.getStaticFiles(stereo).getVisibilityImages(visibilityModifier); - } - - public boolean isThereVisibilityImages() { - return visibilityModifierPresent; - } - - public void setVisibilityModifierPresent(boolean b) { - checkObjectOrClassDiagram(); - this.visibilityModifierPresent = b; - } - - public void setStaticImagesMap(StaticFilesMap staticFilesMap) { - checkObjectOrClassDiagram(); - this.staticFilesMap = staticFilesMap; - } - - private void checkObjectOrClassDiagram() { - if (umlDiagramType != UmlDiagramType.CLASS && umlDiagramType != UmlDiagramType.OBJECT) { - throw new IllegalStateException(); - } + }, colorMapper, entityFactory, isHideEmptyDescriptionForState, dotMode); } public UmlDiagramType getUmlDiagramType() { @@ -151,132 +116,36 @@ final public class DotData implements PortionShower { return links; } - public Map getEntities() { - return entities; + public Collection getLeafs() { + return leafs; } - public final Set getAllLinkedTo(final IEntity ent1) { - final Set result = new HashSet(); - result.add(ent1); - int size = 0; - do { - size = result.size(); - for (IEntity ent : entities.values()) { - if (isDirectyLinked(ent, result)) { - result.add(ent); - } - } - } while (size != result.size()); - result.remove(ent1); - return Collections.unmodifiableSet(result); - } - - public final Set getAllLinkedDirectedTo(final IEntity ent1) { - final Set result = new HashSet(); - for (IEntity ent : entities.values()) { - if (isDirectlyLinkedSlow(ent, ent1)) { - result.add(ent); - } - } - return Collections.unmodifiableSet(result); - } - - private boolean isDirectyLinked(IEntity ent1, Collection others) { - for (IEntity ent2 : others) { - if (isDirectlyLinkedSlow(ent1, ent2)) { - return true; - } - } - return false; - } - - private boolean isDirectlyLinkedSlow(IEntity ent1, IEntity ent2) { - for (Link link : links) { - if (link.isBetween(ent1, ent2)) { - return true; - } - } - return false; - } - - public boolean isThereLink(Group g) { - for (Link l : links) { - if (l.getEntity1() == g.getEntityCluster() || l.getEntity2() == g.getEntityCluster()) { - return true; - } - } - return false; - } - - public List getAutoLinks(Group g) { - final List result = new ArrayList(); - for (Link l : links) { - if (l.isAutolink(g)) { - result.add(l); - } - } - return Collections.unmodifiableList(result); - } - - public List getToEdgeLinks(Group g) { - final List result = new ArrayList(); - for (Link l : links) { - if (l.isToEdgeLink(g)) { - result.add(l); - } - } - return Collections.unmodifiableList(result); - } - - public List getFromEdgeLinks(Group g) { - final List result = new ArrayList(); - for (Link l : links) { - if (l.isFromEdgeLink(g)) { - result.add(l); - } - } - return Collections.unmodifiableList(result); - } - - public final Group getTopParent() { + public final IGroup getTopParent() { return topParent; } - public boolean isEmpty(Group g) { + public boolean isEmpty(IGroup g) { return groupHierarchy.isEmpty(g); } - public boolean showPortion(EntityPortion portion, IEntity entity) { + public boolean showPortion(EntityPortion portion, ILeaf entity) { return portionShower.showPortion(portion, entity); } - public final int getDpi() { - return dpi; - } - - public double getDpiFactor() { - if (dpi == 96) { - return 1.0; - } - return dpi / 96.0; - } - - public final void setDpi(int dpi) { - this.dpi = dpi; - } - - private boolean hideEmptyDescription = false; - - public final void setHideEmptyDescription(boolean hideEmptyDescription) { - this.hideEmptyDescription = hideEmptyDescription; - } - - public final boolean isHideEmptyDescription() { - return hideEmptyDescription; - } - public final ColorMapper getColorMapper() { return colorMapper; } + public IGroup getRootGroup() { + return entityFactory.getRootGroup(); + } + + public final boolean isHideEmptyDescriptionForState() { + return isHideEmptyDescriptionForState; + } + + public final DotMode getDotMode() { + return dotMode; + } + } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/DotExpression.java b/src/net/sourceforge/plantuml/cucadiagram/dot/DotExpression.java deleted file mode 100644 index c5a63225e..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/DotExpression.java +++ /dev/null @@ -1,253 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6932 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.awt.Font; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.FileSystem; -import net.sourceforge.plantuml.Log; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.graphic.FontChange; -import net.sourceforge.plantuml.graphic.FontConfiguration; -import net.sourceforge.plantuml.graphic.FontStyle; -import net.sourceforge.plantuml.graphic.HtmlColor; -import net.sourceforge.plantuml.graphic.HtmlCommand; -import net.sourceforge.plantuml.graphic.Img; -import net.sourceforge.plantuml.graphic.Splitter; -import net.sourceforge.plantuml.graphic.Text; -import net.sourceforge.plantuml.ugraphic.ColorMapper; -import net.sourceforge.plantuml.ugraphic.UFont; - -public final class DotExpression { - - private final StringBuilder sb = new StringBuilder(); - - private final UFont normalFont; - - private FontConfiguration fontConfiguration; - - private final boolean underline; - - private final String fontFamily; - - private final FileFormat fileFormat; - - private final ColorMapper colorMapper; - - private boolean hasImg; - - public DotExpression(ColorMapper colorMapper, String html, int defaultFontSize, HtmlColor color, String fontFamily, - int style, FileFormat fileFormat) { - if (html.contains("\n")) { - throw new IllegalArgumentException(html); - } - this.colorMapper = colorMapper; - this.fontFamily = fontFamily; - this.normalFont = new UFont("SansSerif", Font.PLAIN, defaultFontSize); - this.fontConfiguration = new FontConfiguration(normalFont, color); - this.fileFormat = fileFormat; - - if ((style & Font.ITALIC) != 0) { - html = "" + html; - } - - if ((style & Font.BOLD) != 0) { - html = "" + html; - } - - html = html.replaceAll(" \\<[uU]\\>", ""); - html = html.replaceAll("\\ ", ""); - underline = html.contains("") || html.contains(""); - final Splitter splitter = new Splitter(html); - List htmlCommands = splitter.getHtmlCommands(false); - for (HtmlCommand command : htmlCommands) { - if (command instanceof Img) { - hasImg = true; - } - } - if (hasImg) { - htmlCommands = splitter.getHtmlCommands(true); - sb.append(""); - for (Collection cmds : split(htmlCommands)) { - sb.append(""); - } - sb.append("
    "); - manageCommands(cmds); - sb.append("
    "); - } else { - manageCommands(htmlCommands); - } - } - - private static List> split(Collection all) { - final List> result = new ArrayList>(); - Collection current = null; - for (HtmlCommand c : all) { - if (c instanceof Text && ((Text) c).isNewline()) { - current = null; - } else { - if (current == null) { - current = new ArrayList(); - result.add(current); - } - current.add(c); - } - } - return result; - } - - private void manageCommands(Collection htmlCommands) { - for (HtmlCommand command : htmlCommands) { - if (command instanceof Text) { - manage((Text) command); - } else if (command instanceof FontChange) { - manage((FontChange) command); - } else if (command instanceof Img) { - manageImage((Img) command); - } else { - Log.error("Cannot manage " + command); - } - } - } - - private void manageImage(Img img) { - try { - final File f = FileSystem.getInstance().getFile(img.getFilePath()); - if (f.exists() == false) { - throw new IOException(); - } - sb.append(""); - } catch (IOException e) { - sb.append("File Not Found"); - } - } - - private void manage(FontChange command) { - fontConfiguration = command.apply(fontConfiguration); - } - - private void manage(Text command) { - if (hasImg) { - sb.append(""); - } - underline(false); - sb.append(getFontTag()); - - String text = command.getText(); - text = text.replace("<", "<"); - text = text.replace(">", ">"); - - if (hasImg == false) { - text = text.replace("\\n", "
    "); - } - - sb.append(text); - sb.append(""); - underline(true); - if (hasImg) { - sb.append(""); - if (text.contains("\\n")) { - throw new IllegalStateException(); - } - } - } - - private String getFontTag() { - final int size = fontConfiguration.getFont().getSize(); - final StringBuilder sb = new StringBuilder(""); - return sb.toString(); - } - - private void appendFontWithFamily(final StringBuilder sb) { - String modifier = null; - if (fontConfiguration.containsStyle(FontStyle.ITALIC)) { - modifier = "italic"; - } else if (fontConfiguration.containsStyle(FontStyle.BOLD)) { - modifier = "bold"; - } - appendFace(sb, fontFamily, modifier); - } - - private static void appendFace(StringBuilder sb, String fontFamily, String modifier) { - if (fontFamily == null && modifier == null) { - return; - } - sb.append("FACE=\""); - if (fontFamily != null && modifier != null) { - sb.append(fontFamily + " " + modifier); - } else if (fontFamily != null) { - assert modifier == null; - sb.append(fontFamily); - } else if (modifier != null) { - assert fontFamily == null; - sb.append(modifier); - } else { - assert false; - } - sb.append("\""); - } - - private void underline(boolean closing) { - if (fontConfiguration.containsStyle(FontStyle.UNDERLINE)) { - String special = "_"; - if (closing && fileFormat == FileFormat.EPS) { - special = "_!"; - } - sb.append("" + special + ""); - } - } - - public String getDotHtml() { - return sb.toString(); - - } - - boolean isUnderline() { - return underline; - } - -} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/DotMaker.java b/src/net/sourceforge/plantuml/cucadiagram/dot/DotMaker.java deleted file mode 100644 index c7c1f6749..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/DotMaker.java +++ /dev/null @@ -1,1499 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6939 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import net.sourceforge.plantuml.ColorParam; -import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.FileUtils; -import net.sourceforge.plantuml.FontParam; -import net.sourceforge.plantuml.Log; -import net.sourceforge.plantuml.OptionFlags; -import net.sourceforge.plantuml.SignatureUtils; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.UmlDiagramType; -import net.sourceforge.plantuml.Url; -import net.sourceforge.plantuml.command.Position; -import net.sourceforge.plantuml.cucadiagram.Entity; -import net.sourceforge.plantuml.cucadiagram.EntityType; -import net.sourceforge.plantuml.cucadiagram.Group; -import net.sourceforge.plantuml.cucadiagram.GroupType; -import net.sourceforge.plantuml.cucadiagram.IEntity; -import net.sourceforge.plantuml.cucadiagram.Link; -import net.sourceforge.plantuml.cucadiagram.LinkType; -import net.sourceforge.plantuml.cucadiagram.Member; -import net.sourceforge.plantuml.cucadiagram.Rankdir; -import net.sourceforge.plantuml.cucadiagram.Stereotype; -import net.sourceforge.plantuml.graphic.FontConfiguration; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; -import net.sourceforge.plantuml.graphic.HtmlColor; -import net.sourceforge.plantuml.graphic.TextBlock; -import net.sourceforge.plantuml.graphic.TextBlockUtils; -import net.sourceforge.plantuml.skin.UDrawable; -import net.sourceforge.plantuml.ugraphic.UFont; -import net.sourceforge.plantuml.ugraphic.UGraphic; -import net.sourceforge.plantuml.ugraphic.eps.UGraphicEps; - -final public class DotMaker extends DotCommon implements GraphvizMaker { - - private static boolean isJunit = false; - - private final List dotStrings; - - private static String lastDotSignature; - - private final FileFormat fileFormat; - - private final boolean isVisibilityModifierPresent; - - // http://www.graphviz.org/bugs/b2114.html - private static final boolean TURN_AROUND_B2114 = false; - - private static final boolean NOLABEL = false; - - private final Set hasAlreadyOneIncommingArrowLenghtOne; - - final private Set rankMin = new HashSet(); - - public static void goJunit() { - isJunit = true; - } - - public DotMaker(DotData data, List dotStrings, FileFormat fileFormat) { - super(fileFormat, data); - this.dotStrings = dotStrings; - this.fileFormat = fileFormat; - if (data.getSkinParam().classAttributeIconSize() > 0) { - this.isVisibilityModifierPresent = data.isThereVisibilityImages(); - } else { - this.isVisibilityModifierPresent = false; - } - this.hasAlreadyOneIncommingArrowLenghtOne = TURN_AROUND_B2114 ? new HashSet() : null; - } - - public String createDotString() throws IOException { - - final StringBuilder sb = new StringBuilder(); - - initPrintWriter(sb); - printGroups(sb, null); - printEntities(sb, getUnpackagedEntities()); - printLinks(sb, getData().getLinks()); - printRanking(sb); - sb.append("}"); - - // System.err.println(sb); - if (isJunit) { - lastDotSignature = SignatureUtils.getSignatureWithoutImgSrc(sb.toString()); - } - return sb.toString(); - } - - private void printRanking(StringBuilder sb) { - if (rankMin.size() == 0) { - return; - } - sb.append("{ rank = min;"); - for (String id : rankMin) { - sb.append(id); - sb.append(";"); - } - sb.append("}"); - - } - - private void initPrintWriter(StringBuilder sb) { - - Log.info("Entities = " + getData().getEntities().size()); - final boolean huge = getData().getEntities().size() > 800; - - sb.append("digraph unix {"); - for (String s : dotStrings) { - sb.append(s); - } - sb.append("bgcolor=\"" + getAsHtml(getData().getSkinParam().getBackgroundColor()) + "\";"); - if (huge) { - sb.append("size=\"400,400;\""); - } else { - sb.append("ratio=auto;"); - // sb.append("concentrate=true;"); - } - // sb.append("ordering=out;"); - sb.append("compound=true;"); - final DotSplines dotSplines = getData().getSkinParam().getDotSplines(); - final GraphvizLayoutStrategy strategy = getData().getSkinParam().getStrategy(); - if (dotSplines == DotSplines.ORTHO) { - sb.append("splines=ortho;"); - } else if (dotSplines == DotSplines.POLYLINE) { - sb.append("splines=polyline;"); - } else if (strategy != GraphvizLayoutStrategy.DOT) { - sb.append("splines=true;"); - } - - // if (strategy == GraphvizLayoutStrategy.NEATO) { - // sb.append("overlap=false;"); - // } - if (strategy != GraphvizLayoutStrategy.DOT) { - sb.append("layout=" + strategy.name().toLowerCase() + ";"); - sb.append("overlap=false;"); - } - - sb.append("remincross=true;"); - sb.append("searchsize=500;"); - if (getData().getRankdir() == Rankdir.LEFT_TO_RIGHT) { - sb.append("rankdir=LR;"); - } - - if (getData().getDpi() != 96) { - sb.append("dpi=" + getData().getDpi() + ";"); - sb.append("imagescale=both;"); - } - } - - private Collection getUnpackagedEntities() { - final List result = new ArrayList(); - for (IEntity ent : getData().getEntities().values()) { - if (ent.getParent() == getData().getTopParent()) { - result.add(ent); - } - } - return result; - } - - private void printGroups(StringBuilder sb, Group parent) throws IOException { - for (Group g : getData().getGroupHierarchy().getChildrenGroups(parent)) { - if (getData().isEmpty(g) && g.getType() == GroupType.PACKAGE) { - final IEntity folder = new Entity(g.getUid1(), g.getUid2(), g.getCode(), g.getDisplay(), - EntityType.EMPTY_PACKAGE, null, null); - printEntity(sb, folder); - } else { - printGroup(sb, g); - } - } - } - - private void printGroup(StringBuilder sb, Group g) throws IOException { - if (g.getType() == GroupType.CONCURRENT_STATE) { - return; - } - - if (isSpecialGroup(g)) { - printGroupSpecial(sb, g); - } else { - printGroupNormal(sb, g); - } - } - - private void printGroupNormal(StringBuilder sb, Group g) throws IOException { - - final String stereo = g.getStereotype(); - - sb.append("subgraph " + g.getUid() + " {"); - // sb.append("margin=10;"); - - final UFont font = getData().getSkinParam().getFont(getFontParamForGroup(), stereo); - sb.append("fontsize=\"" + font.getSize() + "\";"); - final String fontFamily = font.getFamily(null); - if (fontFamily != null) { - sb.append("fontname=\"" + fontFamily + "\";"); - } - - if (g.getDisplay() != null) { - sb.append("label=<" + manageHtmlIB(g.getDisplay(), getFontParamForGroup(), stereo) + ">;"); - } - final String fontColor = getAsHtml(getData().getSkinParam().getFontHtmlColor(getFontParamForGroup(), stereo)); - sb.append("fontcolor=\"" + fontColor + "\";"); - - if (getGroupBackColor(g) != null) { - sb.append("fillcolor=\"" + getAsHtml(getGroupBackColor(g)) + "\";"); - } - - if (g.getType() == GroupType.STATE) { - sb.append("color=" + getColorString(ColorParam.stateBorder, stereo) + ";"); - } else { - sb.append("color=" + getColorString(ColorParam.packageBorder, stereo) + ";"); - } - sb.append("style=\"" + getStyle(g) + "\";"); - - printGroups(sb, g); - - this.printEntities(sb, g.entities().values()); - for (Link link : getData().getLinks()) { - eventuallySameRank(sb, g, link); - } - sb.append("}"); - } - - private HtmlColor getGroupBackColor(Group g) { - HtmlColor value = g.getBackColor(); - if (value == null) { - value = getData().getSkinParam().getHtmlColor(ColorParam.packageBackground, null); - // value = rose.getHtmlColor(this.getData().getSkinParam(), - // ColorParam.packageBackground); - } - return value; - } - - private void printGroupSpecial(StringBuilder sb, Group g) throws IOException { - - sb.append("subgraph " + g.getUid() + "a {"); - if (OptionFlags.getInstance().isDebugDot()) { - sb.append("style=dotted;"); - sb.append("label=\"a\";"); - } else { - sb.append("style=invis;"); - sb.append("label=\"\";"); - } - - sb.append("subgraph " + g.getUid() + "v {"); - sb.append("style=solid;"); - // sb.append("margin=10;"); - - final List autolinks = getData().getAutoLinks(g); - final List toEdgeLinks = getData().getToEdgeLinks(g); - final List fromEdgeLinks = getData().getFromEdgeLinks(g); - final boolean autoLabel = autolinks.size() == 1; - - final List nodesHiddenUidOut = getNodesHiddenUidOut(g); - final List nodesHiddenUidIn = getNodesHiddenUidIn(g); - final List nodesHiddenUid = new ArrayList(nodesHiddenUidOut); - nodesHiddenUid.addAll(nodesHiddenUidIn); - for (Link link : nodesHiddenUid) { - final String uid = getHiddenNodeUid(g, link); - // sb.append("subgraph " + g.getUid() + "k" + uid + " {"); - if (OptionFlags.getInstance().isDebugDot()) { - sb.append("style=dotted;"); - sb.append("label=\"k" + uid + "\";"); - } else { - sb.append("style=invis;"); - sb.append("label=\"\";"); - } - if (OptionFlags.getInstance().isDebugDot()) { - sb.append(uid + ";"); - } else { - sb.append(uid + " [shape=point,width=.01,style=invis,label=\"\"];"); - } - // sb.append("}"); // end of k - } - - for (int j = 1; j < nodesHiddenUidOut.size(); j++) { - for (int i = 0; i < j; i++) { - final Link linki = nodesHiddenUidOut.get(i); - final Link linkj = nodesHiddenUidOut.get(j); - if (linki.getEntity2() != linkj.getEntity2()) { - continue; - } - final String uidi = getHiddenNodeUid(g, linki); - final String uidj = getHiddenNodeUid(g, linkj); - if (OptionFlags.getInstance().isDebugDot()) { - sb.append(uidi + "->" + uidj + ";"); - } else { - sb.append(uidi + "->" + uidj + " [style=invis,arrowtail=none,arrowhead=none];"); - } - - } - } - - if (autoLabel /* || toEdgeLinks.size() > 0 || fromEdgeLinks.size() > 0 */) { - if (OptionFlags.getInstance().isDebugDot()) { - sb.append(g.getUid() + "lmin;"); - sb.append(g.getUid() + "lmax;"); - sb.append(g.getUid() + "lmin->" + g.getUid() + "lmax [minlen=2]; "); - } else { - sb.append(g.getUid() + "lmin [shape=point,width=.01,style=invis,label=\"\"];"); - sb.append(g.getUid() + "lmax [shape=point,width=.01,style=invis,label=\"\"];"); - sb.append(g.getUid() + "lmin->" + g.getUid() - + "lmax [minlen=2,style=invis,arrowtail=none,arrowhead=none]; "); - } - } - // sb.append(g.getUid() + "min->" + g.getUid() + "max;"); - - final UFont font = getData().getSkinParam().getFont(getFontParamForGroup(), null); - sb.append("fontsize=\"" + font.getSize() + "\";"); - final String fontFamily = font.getFamily(null); - if (fontFamily != null) { - sb.append("fontname=\"" + fontFamily + "\";"); - } - - if (g.getDisplay() != null) { - final StringBuilder label = new StringBuilder(manageHtmlIB(g.getDisplay(), getFontParamForGroup(), null)); - if (g.getEntityCluster().getFieldsToDisplay().size() > 0) { - label.append("
    "); - for (Member att : g.getEntityCluster().getFieldsToDisplay()) { - label.append(manageHtmlIB(" " + att.getDisplayWithVisibilityChar() + " ", - FontParam.STATE_ATTRIBUTE, null)); - label.append("
    "); - } - } - sb.append("label=<" + label + ">;"); - } - - final String fontColor = getAsHtml(getData().getSkinParam().getFontHtmlColor(getFontParamForGroup(), null)); - sb.append("fontcolor=\"" + fontColor + "\";"); - final HtmlColor groupBackColor = getGroupBackColor(g); - if (groupBackColor != null) { - sb.append("fillcolor=\"" + getAsHtml(groupBackColor) + "\";"); - } - if (g.getType() == GroupType.STATE) { - sb.append("color=" + getColorString(ColorParam.stateBorder, null) + ";"); - } else { - sb.append("color=" + getColorString(ColorParam.packageBorder, null) + ";"); - } - sb.append("style=\"" + getStyle(g) + "\";"); - - sb.append("subgraph " + g.getUid() + "i {"); - sb.append("label=\"i\";"); - if (OptionFlags.getInstance().isDebugDot()) { - sb.append("style=dotted;"); - sb.append("label=\"i\";"); - } else { - - if (groupBackColor == null) { - sb.append("style=invis;"); - } else { - final String colorBack = getColorString(ColorParam.background, null); - sb.append("fillcolor=" + colorBack + ";"); - sb.append("color=" + colorBack + ";"); - sb.append("style=\"filled,rounded\";"); - } - sb.append("label=\"\";"); - - } - - printGroups(sb, g); - - this.printEntities(sb, g.entities().values()); - for (Link link : getData().getLinks()) { - eventuallySameRank(sb, g, link); - } - - for (int i = 0; i < fromEdgeLinks.size(); i++) { - if (OptionFlags.getInstance().isDebugDot()) { - sb.append("eds" + i + ";"); - } else { - sb.append("eds" + i + " [shape=point,width=.01,style=invis,label=\"\"];"); - } - sb.append("eds" + i + " ->" + fromEdgeLinks.get(i).getEntity2().getUid() - + " [minlen=2,style=invis,arrowtail=none,arrowhead=none]; "); - - } - - sb.append("}"); // end of i - sb.append("}"); // end of v - - if (autoLabel) { - sb.append("subgraph " + g.getUid() + "l {"); - if (OptionFlags.getInstance().isDebugDot()) { - sb.append("style=dotted;"); - sb.append("label=\"l\";"); - } else { - sb.append("style=invis;"); - sb.append("label=\"\";"); - } - final String decorationColor = ",color=" + getColorString(getArrowColorParam(), null); - - sb.append(g.getUid() + "lab0 [shape=point,width=.01,label=\"\"" + decorationColor + "]"); - String autolabel = autolinks.get(0).getLabel(); - if (autolabel == null) { - autolabel = ""; - } - sb.append(g.getUid() + "lab1 [label=<" + manageHtmlIB(autolabel, getArrowFontParam(), null) - + ">,shape=plaintext,margin=0];"); - sb.append(g.getUid() + "lab0 -> " + g.getUid() + "lab1 [minlen=0,style=invis];"); - sb.append("}"); // end of l - - sb.append(g.getUid() + "lmin -> " + g.getUid() + "lab0 [ltail=" + g.getUid() - + "v,arrowtail=none,arrowhead=none" + decorationColor + "];"); - sb.append(g.getUid() + "lab0 -> " + g.getUid() + "lmax [lhead=" + g.getUid() - + "v,arrowtail=none,arrowhead=open" + decorationColor + "];"); - } - - for (int i = 0; i < fromEdgeLinks.size(); i++) { - sb.append("subgraph " + g.getUid() + "ed" + i + " {"); - if (OptionFlags.getInstance().isDebugDot()) { - sb.append("style=dotted;"); - sb.append("label=\"ed" + i + "\";"); - } else { - sb.append("style=invis;"); - sb.append("label=\"\";"); - } - final String decorationColor = ",color=" + getColorString(getArrowColorParam(), null); - String label = fromEdgeLinks.get(i).getLabel(); - if (label == null) { - label = ""; - } - - sb.append(g.getUid() + "fedge" + i + " [shape=point,width=.01,label=\"\"" + decorationColor + "]"); - sb.append("}"); // end of ed - sb.append("eds" + i + " -> " + g.getUid() + "fedge" + i + " [ltail=" + g.getUid() - + "v,arrowtail=none,arrowhead=none" + decorationColor + "];"); - sb.append(g.getUid() + "fedge" + i + " -> " + fromEdgeLinks.get(i).getEntity2().getUid() - + "[arrowtail=none,arrowhead=open" + decorationColor); - sb.append(",label=<" + manageHtmlIB(label, getArrowFontParam(), null) + ">];"); - - } - sb.append("}"); // end of a - } - - private FontParam getFontParamForGroup() { - if (getData().getUmlDiagramType() == UmlDiagramType.STATE) { - return FontParam.STATE; - } - return FontParam.PACKAGE; - } - - private String getStyle(Group g) { - final StringBuilder sb = new StringBuilder(); - if (g.isBold()) { - sb.append("bold"); - } else if (g.isDashed()) { - sb.append("dashed"); - } else { - sb.append("solid"); - - } - if (getGroupBackColor(g) != null) { - sb.append(",filled"); - } - if (g.isRounded()) { - sb.append(",rounded"); - } - return sb.toString(); - } - - private void printLinks(StringBuilder sb, List links) throws IOException { - for (Link link : appendPhantomLink(links)) { - final IEntity entity1 = link.getEntity1(); - final IEntity entity2 = link.getEntity2(); - if (entity1 == entity2 && entity1.getType() == EntityType.GROUP) { - continue; - } - if (entity1.getType() == EntityType.GROUP && entity2.getParent() == entity1.getParent()) { - continue; - } - if (entity2.getType() == EntityType.GROUP && entity1.getParent() == entity2.getParent()) { - continue; - } - if (entity1.getType() == EntityType.LOLLIPOP || entity2.getType() == EntityType.LOLLIPOP) { - continue; - } - // System.err.println("outing " + link); - printLink(sb, link); - } - } - - private void printLink(StringBuilder sb, Link link) throws IOException { - final StringBuilder decoration = getLinkDecoration(link); - - if (link.getWeight() > 1) { - decoration.append("weight=" + link.getWeight() + ","); - } - if (link.getLabeldistance() != null) { - decoration.append("labeldistance=" + link.getLabeldistance() + ","); - } - if (link.getLabelangle() != null) { - decoration.append("labelangle=" + link.getLabelangle() + ","); - } - if (link.isConstraint() == false) { - decoration.append("constraint=false,"); - } - - final DrawFile noteLink = link.getImageFile(); - - boolean hasLabel = false; - - if (link.getLabel() != null && noteLink != null) { - decoration.append("label=<" - + getHtmlForLinkNote(noteLink.getPngOrEps(fileFormat), manageHtmlIB(link.getLabel(), - getArrowFontParam(), null), link.getNotePosition()) + ">,"); - hasLabel = true; - } else if (link.getLabel() != null) { - decoration.append("label=<" + manageHtmlIB(link.getLabel(), getArrowFontParam(), null) + ">,"); - hasLabel = true; - } else if (noteLink != null) { - decoration.append("label=<" + getHtmlForLinkNote(noteLink.getPngOrEps(fileFormat)) + ">,"); - hasLabel = true; - } - - if (link.getQualifier1() != null) { - decoration.append("taillabel=<" + manageHtmlIB(link.getQualifier1(), getArrowFontParam(), null) + ">,"); - } - if (link.getQualifier2() != null) { - decoration.append("headlabel=<" + manageHtmlIB(link.getQualifier2(), getArrowFontParam(), null) + ">,"); - } - final int len = link.getLength(); - String uid1 = link.getEntity1().getUid(); - String uid2 = link.getEntity2().getUid(); - LinkType typeToDraw = link.getType(); - if (TURN_AROUND_B2114 && len == 1 && hasAlreadyOneIncommingArrowLenghtOne.contains(uid2) && hasLabel) { - typeToDraw = typeToDraw.getInv(); - } - if (TURN_AROUND_B2114 && len == 1) { - hasAlreadyOneIncommingArrowLenghtOne.add(uid2); - } - decoration.append(typeToDraw.getSpecificDecoration()); - if (link.isInvis()) { - decoration.append(",style=invis"); - } - - final String lenString = len >= 3 ? ",minlen=" + (len - 1) : ""; - - if (link.getEntity1().getType() == EntityType.GROUP) { - uid1 = getHiddenNodeUid(link.getEntity1().getParent(), link); - decoration.append(",ltail=" + link.getEntity1().getParent().getUid() + "v"); - } - if (link.getEntity2().getType() == EntityType.GROUP) { - uid2 = getHiddenNodeUid(link.getEntity2().getParent(), link); - decoration.append(",lhead=" + link.getEntity2().getParent().getUid() + "v"); - } - - final boolean margin1 = MODE_MARGIN && link.getEntity1().hasNearDecoration(); - final boolean margin2 = MODE_MARGIN && link.getEntity2().hasNearDecoration(); - - sb.append(uid1); - if (margin1) { - sb.append(":h"); - } - sb.append(" -> "); - sb.append(uid2); - if (margin2) { - sb.append(":h"); - } - sb.append(decoration); - sb.append(lenString + "];"); - eventuallySameRank(sb, getData().getTopParent(), link); - } - - private List getNodesHiddenUidOut(Group g) { - final List result = new ArrayList(); - for (Link link : getData().getLinks()) { - if (link.getEntity1().getParent() == link.getEntity2().getParent()) { - continue; - } - if (link.getEntity1().getType() == EntityType.GROUP && link.getEntity1().getParent() == g) { - result.add(link); - } - } - return Collections.unmodifiableList(result); - } - - private List getNodesHiddenUidIn(Group g) { - final List result = new ArrayList(); - for (Link link : getData().getLinks()) { - if (link.getEntity1().getParent() == link.getEntity2().getParent()) { - continue; - } - if (link.getEntity2().getType() == EntityType.GROUP && link.getEntity2().getParent() == g) { - result.add(link); - } - } - return Collections.unmodifiableList(result); - } - - private String getHiddenNodeUid(Group g, Link link) { - if (getData().isEmpty(g) && g.getType() == GroupType.PACKAGE) { - return g.getUid(); - } - return g.getUid() + "_" + link.getUid(); - } - - private StringBuilder getLinkDecoration(Link link) { - final StringBuilder decoration = new StringBuilder("[color="); - if (link.getSpecificColor() == null) { - decoration.append(getColorString(getArrowColorParam(), null)); - } else { - decoration.append("\"" + getAsHtml(link.getSpecificColor()) + "\""); - } - decoration.append(","); - - decoration.append("fontcolor=" + getFontColorString(getArrowFontParam(), null) + ","); - final UFont font = getData().getSkinParam().getFont(getArrowFontParam(), null); - decoration.append("fontsize=\"" + font.getSize() + "\","); - - final String fontName = font.getFamily(null); - if (fontName != null) { - decoration.append("fontname=\"" + fontName + "\","); - } - return decoration; - } - - private List appendPhantomLink(List links) { - final List result = new ArrayList(links); - for (Link link : links) { - if (link.getLength() != 1) { - continue; - } - final DrawFile noteLink = link.getImageFile(); - if (noteLink == null) { - continue; - } - final Link phantom = new Link(link.getEntity1(), link.getEntity2(), link.getType(), null, link.getLength()); - phantom.setInvis(true); - result.add(phantom); - } - return result; - } - - private String getHtmlForLinkNote(File image) { - final String circleInterfaceAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(image); - final StringBuilder sb = new StringBuilder(); - sb.append(""); - sb.append(""); - sb.append("
    "); - return sb.toString(); - - } - - private String getHtmlForLinkNote(File image, String labelHtml, Position position) { - final String imagePath = StringUtils.getPlateformDependentAbsolutePath(image); - final StringBuilder sb = new StringBuilder(); - sb.append(""); - switch (position) { - case TOP: - sb.append(""); - sb.append(""); - break; - case RIGHT: - sb.append(""); - sb.append(""); - break; - case LEFT: - sb.append(""); - sb.append(""); - break; - default: - sb.append(""); - sb.append(""); - break; - } - sb.append("
    " + labelHtml + "
    " + labelHtml + "
    " + labelHtml + "
    " + labelHtml + "
    "); - return sb.toString(); - - } - - private FontParam getArrowFontParam() { - if (getData().getUmlDiagramType() == UmlDiagramType.CLASS) { - return FontParam.CLASS_ARROW; - } else if (getData().getUmlDiagramType() == UmlDiagramType.OBJECT) { - return FontParam.OBJECT_ARROW; - } else if (getData().getUmlDiagramType() == UmlDiagramType.USECASE) { - return FontParam.USECASE_ARROW; - } else if (getData().getUmlDiagramType() == UmlDiagramType.ACTIVITY) { - return FontParam.ACTIVITY_ARROW; - } else if (getData().getUmlDiagramType() == UmlDiagramType.COMPONENT) { - return FontParam.COMPONENT_ARROW; - } else if (getData().getUmlDiagramType() == UmlDiagramType.STATE) { - return FontParam.STATE_ARROW; - } - throw new IllegalStateException(); - } - - private ColorParam getArrowColorParam() { - if (getData().getUmlDiagramType() == UmlDiagramType.CLASS) { - return ColorParam.classArrow; - } else if (getData().getUmlDiagramType() == UmlDiagramType.OBJECT) { - return ColorParam.objectArrow; - } else if (getData().getUmlDiagramType() == UmlDiagramType.USECASE) { - return ColorParam.usecaseArrow; - } else if (getData().getUmlDiagramType() == UmlDiagramType.ACTIVITY) { - return ColorParam.activityArrow; - } else if (getData().getUmlDiagramType() == UmlDiagramType.COMPONENT) { - return ColorParam.componentArrow; - } else if (getData().getUmlDiagramType() == UmlDiagramType.STATE) { - return ColorParam.stateArrow; - } - throw new IllegalStateException(); - } - - private String getFontColorString(FontParam fontParam, String stereotype) { - return "\"" + getAsHtml(getFontHtmlColor(fontParam, stereotype)) + "\""; - } - - private void eventuallySameRank(StringBuilder sb, Group entityPackage, Link link) { - final int len = link.getLength(); - if (len == 1 && link.getEntity1().getParent() == entityPackage - && link.getEntity2().getParent() == entityPackage) { - if (link.getEntity1().getType() == EntityType.GROUP) { - throw new IllegalArgumentException(); - } - if (link.getEntity2().getType() == EntityType.GROUP) { - throw new IllegalArgumentException(); - } - sb.append("{rank=same; " + link.getEntity1().getUid() + "; " + link.getEntity2().getUid() + "}"); - } - } - - private boolean MODE_LOLLIPOP_BETA = false; - - class EntityComparator implements Comparator { - public int compare(IEntity e1, IEntity e2) { - final int xpos1 = e1.getXposition(); - final int xpos2 = e2.getXposition(); - if (xpos1 < xpos2) { - return -1; - } - if (xpos1 > xpos2) { - return 1; - } - return e1.compareTo(e2); - } - } - - class EntityComparator2 implements Comparator { - private final Map map; - - public EntityComparator2(Map map) { - this.map = map; - } - - public int compare(IEntity e1, IEntity e2) { - final Integer b1 = map.get(e1); - final Integer b2 = map.get(e2); - final int cmp = b1.compareTo(b2); - if (cmp != 0) { - return -cmp; - } - return e1.compareTo(e2); - } - } - - private Map getMap(Collection entities2) { - final Map map = new HashMap(); - for (IEntity ent : entities2) { - map.put(ent, Integer.valueOf(0)); - } - for (Link link : getData().getLinks()) { - if (link.isConstraint() == false) { - map.put(link.getEntity2(), Integer.valueOf(1)); - } else if (link.getLength() == 1 && link.isInverted()) { - // map.put(link.getEntity2(), true); - map.put(link.getEntity1(), Integer.valueOf(1)); - } - - } - return map; - } - - private void printEntities(StringBuilder sb, Collection entities2) throws IOException { - final List entities = new ArrayList(entities2); - // Collections.sort(entities, new EntityComparator()); - // if (getData().getUmlDiagramType() == UmlDiagramType.ACTIVITY) { - Collections.sort(entities, new EntityComparator2(getMap(entities2))); - // } - // Collections.sort(entities); - final Set lollipops = new HashSet(); - final Set lollipopsFriends = new HashSet(); - for (IEntity entity : entities) { - if (entity.getType() == EntityType.LOLLIPOP) { - lollipops.add(entity); - if (MODE_LOLLIPOP_BETA == false) { - lollipopsFriends.add(getConnectedToLollipop(entity)); - } - } - } - - if (MODE_LOLLIPOP_BETA) { - for (IEntity entity : entities) { - if (lollipops.contains(entity)) { - continue; - } - printEntity(sb, entity); - } - } else { - for (IEntity entity : entities) { - if (lollipops.contains(entity) || lollipopsFriends.contains(entity)) { - continue; - } - printEntity(sb, entity); - } - - for (IEntity ent : lollipopsFriends) { - sb.append("subgraph cluster" + ent.getUid() + "lol {"); - sb.append("style=invis;"); - sb.append("label=\"\";"); - printEntity(sb, ent); - for (IEntity lollipop : getAllLollipop(ent)) { - final Link link = getLinkLollipop(lollipop, ent); - final String headOrTail = getHeadOrTail(lollipop, link); - printEntity(sb, lollipop, headOrTail); - printLink(sb, link); - } - sb.append("}"); - } - } - - } - - private Collection getAllLollipop(IEntity entity) { - final Collection result = new ArrayList(); - for (IEntity lollipop : getData().getAllLinkedDirectedTo(entity)) { - if (lollipop.getType() == EntityType.LOLLIPOP) { - result.add(lollipop); - } - } - return result; - } - - private IEntity getConnectedToLollipop(IEntity lollipop) { - assert lollipop.getType() == EntityType.LOLLIPOP; - final Collection linked = getData().getAllLinkedDirectedTo(lollipop); - if (linked.size() != 1) { - throw new IllegalStateException("size=" + linked.size()); - } - return linked.iterator().next(); - } - - private Link getLinkLollipop(IEntity lollipop, IEntity ent) { - assert lollipop.getType() == EntityType.LOLLIPOP; - for (Link link : getData().getLinks()) { - if (link.isBetween(lollipop, ent)) { - return link; - } - } - throw new IllegalArgumentException(); - } - - private void printEntity(StringBuilder sb, IEntity entity, String headOrTail) throws IOException { - final EntityType type = entity.getType(); - if (type == EntityType.LOLLIPOP) { - final String color1 = getColorString(ColorParam.classBackground, null); - final String color2 = getColorString(ColorParam.classBorder, null); - final String colorBack = getColorString(ColorParam.background, null); - final String labelLo = manageHtmlIB(StringUtils.getMergedLines(entity.getDisplay2()), - FontParam.CLASS_ATTRIBUTE, null); - sb.append(entity.getUid() + " [fillcolor=" + color1 + ",color=" + color2 + ",style=\"filled\"," - + "shape=circle,width=0.12,height=0.12,label=\"\"];"); - sb.append(entity.getUid() + " -> " + entity.getUid() + "[color=" + colorBack - + ",arrowtail=none,arrowhead=none," + headOrTail + "=<" + labelLo + ">];"); - } else { - throw new IllegalStateException(type.toString() + " " + getData().getUmlDiagramType()); - } - - } - - static final boolean MODE_MARGIN = true; - static public final boolean MODE_BRANCHE_CLUSTER = false; - - private void printEntity(StringBuilder sb, IEntity entity) throws IOException { - final EntityType type = entity.getType(); - final String label = NOLABEL ? "label=\"" + entity.getUid() + "\"" : getLabel(entity); - if (type == EntityType.GROUP) { - return; - } - boolean closeBracket = false; - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - if (type == EntityType.ABSTRACT_CLASS || type == EntityType.CLASS || type == EntityType.INTERFACE - || type == EntityType.ENUM) { - String dec; - if (MODE_MARGIN && entity.hasNearDecoration() || MODE_LOLLIPOP_BETA) { - dec = " [fontcolor=" + getFontColorString(FontParam.CLASS, stereo) + "color=" - + getBackColorAroundEntity(entity) + ",margin=0,style=filled,shape=plaintext," + label; - } else { - dec = " [fontcolor=" + getFontColorString(FontParam.CLASS, stereo) + ",margin=0,fillcolor=" - + getColorString(ColorParam.classBackground, stereo) + ",color=" - + getColorString(ColorParam.classBorder, stereo) + ",style=filled,shape=box," + label; - - } - sb.append(entity.getUid() + dec); - } else if (type == EntityType.OBJECT) { - sb.append(entity.getUid() + " [fontcolor=" + getFontColorString(FontParam.CLASS, stereo) - + ",margin=0,fillcolor=" + getColorString(ColorParam.classBackground, stereo) + ",color=" - + getColorString(ColorParam.classBorder, stereo) + ",style=filled,shape=record," + label); - } else if (type == EntityType.USECASE) { - sb.append(entity.getUid() + " [fontcolor=" + getFontColorString(FontParam.USECASE, stereo) + ",fillcolor=" - + getColorString(ColorParam.usecaseBackground, stereo) + ",color=" - + getColorString(ColorParam.usecaseBorder, stereo) + ",style=filled," + label); - } else if (type == EntityType.ACTOR) { - sb.append(entity.getUid() + " [fontcolor=" + getFontColorString(FontParam.USECASE_ACTOR, stereo) - + ",margin=0,shape=plaintext," + label); - } else if (type == EntityType.CIRCLE_INTERFACE) { - sb.append(entity.getUid() + " [margin=0,shape=plaintext," + label); - } else if (type == EntityType.COMPONENT) { - sb.append(entity.getUid() + " [margin=0.2,fontcolor=" + getFontColorString(FontParam.COMPONENT, stereo) - + ",fillcolor=" + getColorString(ColorParam.componentBackground, stereo) + ",color=" - + getColorString(ColorParam.componentBorder, stereo) + ",style=filled,shape=component," + label); - } else if (type == EntityType.NOTE && getData().getDpi() != 96) { - sb.append(entity.getUid() + " [margin=0,pad=0,shape=plaintext,label=" + getLabelForNoteDpi(entity)); - } else if (type == EntityType.NOTE) { - final DrawFile file = entity.getImageFile(); - if (file == null) { - throw new IllegalStateException("No file for NOTE"); - } - if (file.getPngOrEps(fileFormat).exists() == false) { - throw new IllegalStateException(); - } - final String absolutePath = StringUtils.getPlateformDependentAbsolutePath(file.getPngOrEps(fileFormat)); - sb.append(entity.getUid() + " [margin=0,pad=0," + label + ",shape=none,image=\"" + absolutePath + "\""); - } else if (type == EntityType.ACTIVITY) { - String shape = "octagon"; - if (getData().getSkinParam().useOctagonForActivity() == false || entity.getImageFile() != null) { - shape = "rect"; - } - sb.append(entity.getUid() + " [fontcolor=" + getFontColorString(FontParam.ACTIVITY, stereo) + ",fillcolor=" - + getBackColorOfEntity(entity) + ",color=" + getColorString(ColorParam.activityBorder, stereo) - + ",style=\"rounded,filled\",shape=" + shape + "," + label); - } else if (type == EntityType.BRANCH) { - if (MODE_BRANCHE_CLUSTER) { - sb.append("subgraph cluster" + entity.getUid() + "br {"); - sb.append("label=<" - + manageHtmlIB(StringUtils.getMergedLines(entity.getDisplay2()), FontParam.ACTIVITY, null) - + ">;"); - sb.append("color=" + getColorString(ColorParam.background, null) + ";"); - } - sb.append(entity.getUid() + " [fillcolor=" + getBackColorOfEntity(entity) + ",color=" - + getColorString(ColorParam.activityBorder, stereo) - + ",style=\"filled\",shape=diamond,height=.25,width=.25,label=\"\""); - if (MODE_BRANCHE_CLUSTER) { - closeBracket = true; - } - // if (StringUtils.isNotEmpty(entity.getDisplay())) { - // sb.append(entity.getUid() + "->" + entity.getUid() + - // "[taillabel=\"" + entity.getDisplay() - // + "\",arrowtail=none,arrowhead=none,color=\"white\"];"); - // } - } else if (type == EntityType.ASSOCIATION) { - sb.append(entity.getUid() + " [fillcolor=" + getColorString(ColorParam.classBackground, stereo) + ",color=" - + getColorString(ColorParam.classBorder, stereo) - + ",style=\"filled\",shape=diamond,height=.25,width=.25,label=\"\""); - } else if (type == EntityType.SYNCHRO_BAR) { - final String color = getColorString(ColorParam.activityBar, null); - sb.append(entity.getUid() + " [fillcolor=" + color + ",color=" + color + ",style=\"filled\"," - + "shape=rect,height=.08,width=1.30,label=\"\""); - } else if (type == EntityType.CIRCLE_START) { - final String color = getColorString(getStartColorParam(), null); - sb.append(entity.getUid() + " [fillcolor=" + color + ",color=" + color + ",style=\"filled\"," - + "shape=circle,width=.20,height=.20,label=\"\""); - } else if (type == EntityType.CIRCLE_END) { - final String color = getColorString(getEndColorParam(), null); - sb.append(entity.getUid() + " [fillcolor=" + color + ",color=" + color + ",style=\"filled\"," - + "shape=doublecircle,width=.13,height=.13,label=\"\""); - } else if (type == EntityType.PSEUDO_STATE) { - final String color = getColorString(getStartColorParam(), null); - sb.append(entity.getUid() + " [color=" + color + "," + "shape=circle,width=.01,height=.01," + label); - } else if (type == EntityType.POINT_FOR_ASSOCIATION) { - sb - .append(entity.getUid() + " [width=.05,shape=point,color=" - + getColorString(ColorParam.classBorder, null)); - } else if (type == EntityType.STATE) { - sb.append(entity.getUid() + " [color=" + getColorString(ColorParam.stateBorder, stereo) - + ",shape=record,style=\"rounded,filled\",color=" + getColorString(ColorParam.stateBorder, stereo)); - if (entity.getImageFile() == null) { - sb.append(",fillcolor=" + getBackColorOfEntity(entity)); - } else { - sb.append(",fillcolor=" + getBackColorOfEntity(entity)); - // sb.append(",fillcolor=\"" + - // getData().getSkinParam().getBackgroundColor().getAsHtml() + - // "\""); - } - sb.append("," + label); - } else if (type == EntityType.STATE_CONCURRENT) { - final DrawFile file = entity.getImageFile(); - if (file == null) { - throw new IllegalStateException(); - } - if (file.getPng().exists() == false) { - throw new IllegalStateException(); - } - final String absolutePath = StringUtils.getPlateformDependentAbsolutePath(file.getPng()); - sb.append(entity.getUid() + " [margin=1,pad=1," + label + ",style=dashed,shape=box,image=\"" + absolutePath - + "\""); - } else if (type == EntityType.ACTIVITY_CONCURRENT) { - final DrawFile file = entity.getImageFile(); - if (file == null) { - throw new IllegalStateException(); - } - if (file.getPng().exists() == false) { - throw new IllegalStateException(); - } - final String absolutePath = StringUtils.getPlateformDependentAbsolutePath(file.getPng()); - sb.append(entity.getUid() + " [margin=0,pad=0," + label + ",style=dashed,shape=box,image=\"" + absolutePath - + "\""); - } else if (type == EntityType.EMPTY_PACKAGE) { - sb.append(entity.getUid() + " [margin=0.2,fontcolor=" + getFontColorString(FontParam.PACKAGE, null) - + ",fillcolor=" + getColorString(ColorParam.packageBackground, null) + ",color=" - + getColorString(ColorParam.packageBorder, null) + ",style=filled,shape=tab," + label); - } else { - throw new IllegalStateException(type.toString() + " " + getData().getUmlDiagramType()); - } - - if (this.getData().hasUrl() && entity.getUrl() != null) { - final Url url = entity.getUrl(); - sb.append(",URL=\"" + url.getUrl() + "\""); - sb.append(",tooltip=\"" + url.getTooltip() + "\""); - } - - sb.append("];"); - if (closeBracket) { - sb.append("}"); - } - - if (entity.isTop()) { - rankMin.add(entity.getUid()); - } - - } - - private ColorParam getEndColorParam() { - if (getData().getUmlDiagramType() == UmlDiagramType.ACTIVITY) { - return ColorParam.activityEnd; - } - if (getData().getUmlDiagramType() == UmlDiagramType.STATE) { - return ColorParam.stateEnd; - } - throw new IllegalStateException(getData().getUmlDiagramType().toString()); - } - - private ColorParam getStartColorParam() { - if (getData().getUmlDiagramType() == UmlDiagramType.ACTIVITY) { - return ColorParam.activityStart; - } - if (getData().getUmlDiagramType() == UmlDiagramType.STATE) { - return ColorParam.stateStart; - } - throw new IllegalStateException(getData().getUmlDiagramType().toString()); - } - - private String getHeadOrTail(IEntity lollipop, Link link) { - assert lollipop.getType() == EntityType.LOLLIPOP; - if (link.getLength() > 1 && link.getEntity1() == lollipop) { - return "taillabel"; - } - return "headlabel"; - } - - private String getLabel(IEntity entity) throws IOException { - if (entity.getType() == EntityType.ABSTRACT_CLASS || entity.getType() == EntityType.CLASS - || entity.getType() == EntityType.INTERFACE || entity.getType() == EntityType.ENUM) { - return "label=" + getLabelForClassOrInterfaceOrEnum(entity); - } else if (entity.getType() == EntityType.LOLLIPOP) { - return "label=" + getLabelForLollipop(entity); - } else if (entity.getType() == EntityType.OBJECT) { - return "label=" + getLabelForObject(entity); - } else if (entity.getType() == EntityType.ACTOR) { - return "label=" + getLabelForActor(entity); - } else if (entity.getType() == EntityType.CIRCLE_INTERFACE) { - return "label=" + getLabelForCircleInterface(entity); - } else if (entity.getType() == EntityType.NOTE) { - return "label=\"\""; - } else if (entity.getType() == EntityType.STATE_CONCURRENT) { - return "label=\"\""; - } else if (entity.getType() == EntityType.ACTIVITY_CONCURRENT) { - return "label=\"\""; - } else if (entity.getType() == EntityType.COMPONENT) { - return "label=" + getLabelForComponent(entity); - } else if (entity.getType() == EntityType.ACTIVITY) { - final DrawFile drawFile = entity.getImageFile(); - if (drawFile != null) { - final String path = StringUtils.getPlateformDependentAbsolutePath(drawFile.getPng()); - final String bgcolor = "\"" + getAsHtml(getData().getSkinParam().getBackgroundColor()) + "\""; - final StringBuilder sb = new StringBuilder("label=<"); - sb.append(""); - sb.append(""); - sb.append(""); - sb.append("
    "); - sb.append("
    "); - sb.append(">"); - return sb.toString(); - } - final String stereotype = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - return "label=" + getSimpleLabelAsHtml(entity, FontParam.ACTIVITY, stereotype); - } else if (entity.getType() == EntityType.EMPTY_PACKAGE) { - return "label=" + getSimpleLabelAsHtml(entity, getFontParamForGroup(), null); - } else if (entity.getType() == EntityType.USECASE) { - return "label=" + getLabelForUsecase(entity); - } else if (entity.getType() == EntityType.STATE) { - return "label=" + getLabelForState(entity); - } else if (entity.getType() == EntityType.BRANCH) { - return "label=\"\""; - } else if (entity.getType() == EntityType.PSEUDO_STATE) { - return "label=\"H\""; - } - return "label=\"" + StringUtils.getMergedLines(entity.getDisplay2()) + "\""; - } - - private String getSimpleLabelAsHtml(IEntity entity, FontParam param, String stereotype) { - return "<" + manageHtmlIB(StringUtils.getMergedLines(entity.getDisplay2()), param, stereotype) + ">"; - } - - private String getBackColorOfEntity(IEntity entity) { - if (entity.getSpecificBackColor() != null) { - return "\"" + getAsHtml(entity.getSpecificBackColor()) + "\""; - } - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - if (entity.getType() == EntityType.STATE || entity.getType() == EntityType.STATE_CONCURRENT) { - return getColorString(ColorParam.stateBackground, stereo); - } - if (entity.getType() == EntityType.ACTIVITY || entity.getType() == EntityType.ACTIVITY_CONCURRENT - || entity.getType() == EntityType.BRANCH) { - return getColorString(ColorParam.activityBackground, stereo); - } - throw new IllegalArgumentException(entity.getType().toString()); - } - - private String getLabelForState(IEntity entity) throws IOException { - final DrawFile cFile = entity.getImageFile(); - final String stateBgcolor = getBackColorOfEntity(entity); - - final String stereotype = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - - final StringBuilder sb = new StringBuilder("<{"); - sb.append(""); - sb.append("
    " - + manageHtmlIB(StringUtils.getMergedLines(entity.getDisplay2()), FontParam.STATE, stereotype) - + "
    "); - - if (entity.getFieldsToDisplay().size() > 0) { - sb.append("|"); - for (Member att : entity.getFieldsToDisplay()) { - sb.append(manageHtmlIB(att.getDisplayWithVisibilityChar(), FontParam.STATE_ATTRIBUTE, stereotype)); - sb.append("
    "); - } - } - - if (cFile != null) { - sb.append("|"); - final String path = StringUtils.getPlateformDependentAbsolutePath(cFile.getPng()); - final String bgcolor; - if (OptionFlags.PBBACK) { - bgcolor = stateBgcolor; - } else { - bgcolor = "\"" + getAsHtml(getData().getSkinParam().getBackgroundColor()) + "\""; - } - // PBBACK - - sb.append(""); - sb.append(""); - sb.append(""); - sb.append("
    "); - sb.append("
    "); - } - - if (getData().isHideEmptyDescription() == false && entity.getFieldsToDisplay().size() == 0 && cFile == null) { - sb.append("|"); - } - - sb.append("}>"); - - return sb.toString(); - } - - private String getLabelForUsecase(IEntity entity) { - final Stereotype stereotype = getStereotype(entity); - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - if (stereotype == null) { - return getSimpleLabelAsHtml(entity, FontParam.USECASE, stereo); - } - final StringBuilder sb = new StringBuilder("<"); - if (isThereLabel(stereotype)) { - sb.append(""); - } - sb.append(""); - sb.append("
    " + manageHtmlIB(stereotype.getLabel(), FontParam.USECASE_STEREOTYPE, stereo) - + "
    " - + manageHtmlIB(StringUtils.getMergedLines(entity.getDisplay2()), FontParam.USECASE, stereo) - + "
    >"); - return sb.toString(); - } - - private String getLabelForComponent(IEntity entity) { - final Stereotype stereotype = getStereotype(entity); - if (stereotype == null) { - return getSimpleLabelAsHtml(entity, FontParam.COMPONENT, null); - } - final String stereo = stereotype.getLabel(); - final StringBuilder sb = new StringBuilder("<"); - if (isThereLabel(stereotype)) { - sb.append(""); - } - sb.append(""); - sb.append("
    " + manageHtmlIB(stereotype.getLabel(), FontParam.COMPONENT_STEREOTYPE, stereo) - + "
    " - + manageHtmlIB(StringUtils.getMergedLines(entity.getDisplay2()), FontParam.COMPONENT, stereo) - + "
    >"); - return sb.toString(); - } - - private String getLabelForNoteDpi(IEntity entity) throws IOException { - final DrawFile file = entity.getImageFile(); - if (file == null) { - throw new IllegalStateException("No file for NOTE"); - } - if (file.getPngOrEps(fileFormat).exists() == false) { - throw new IllegalStateException(); - } - final String absolutePath = StringUtils.getPlateformDependentAbsolutePath(file.getPngOrEps(fileFormat)); - - final StringBuilder sb = new StringBuilder("<"); - sb.append(""); - addTdImageBugB1983(sb, absolutePath); - sb.append(""); - sb.append("
    >"); - return sb.toString(); - } - - private String getLabelForActor(IEntity entity) throws IOException { - final String actorAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(entity.getImageFile() - .getPngOrEps(fileFormat)); - final Stereotype stereotype = getStereotype(entity); - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - - final StringBuilder sb = new StringBuilder("<"); - if (isThereLabel(stereotype)) { - sb.append(""); - } - if (getData().getDpi() == 96) { - sb.append(""); - } else { - sb.append(""); - addTdImageBugB1983(sb, actorAbsolutePath); - sb.append(""); - } - sb.append(""); - sb.append("
    " + manageHtmlIB(stereotype.getLabel(), FontParam.USECASE_ACTOR_STEREOTYPE, stereo) - + "
    " - + manageHtmlIB(StringUtils.getMergedLines(entity.getDisplay2()), FontParam.USECASE_ACTOR, stereo) - + "
    >"); - return sb.toString(); - - } - - private String getLabelForCircleInterface(IEntity entity) throws IOException { - final String circleInterfaceAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(entity.getImageFile() - .getPngOrEps(fileFormat)); - final Stereotype stereotype = getStereotype(entity); - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - - final StringBuilder sb = new StringBuilder("<"); - if (isThereLabel(stereotype)) { - sb.append(""); - } - sb.append(""); - if (getData().getDpi() == 96) { - sb.append(""); - } else { - addTdImageBugB1983(sb, circleInterfaceAbsolutePath); - } - sb.append(""); - sb.append(""); - sb.append("
    " + manageHtmlIB(stereotype.getLabel(), FontParam.COMPONENT_STEREOTYPE, stereo) - + "
    " - + manageHtmlIB(StringUtils.getMergedLines(entity.getDisplay2()), FontParam.COMPONENT, stereo) - + "
    >"); - return sb.toString(); - - } - - private String getLabelForLollipop(IEntity entity) throws IOException { - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - final String circleInterfaceAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(getData() - .getStaticImages(EntityType.LOLLIPOP, stereo).getPngOrEps(fileFormat)); - final Stereotype stereotype = getStereotype(entity); - - final StringBuilder sb = new StringBuilder("<"); - if (isThereLabel(stereotype)) { - sb.append(""); - } - sb.append(""); - if (getData().getDpi() == 96) { - sb.append(""); - } else { - addTdImageBugB1983(sb, circleInterfaceAbsolutePath); - } - sb.append(""); - sb.append(""); - sb.append("
    " + manageHtmlIB(stereotype.getLabel(), FontParam.CLASS, null) + "
    " + manageHtmlIB(StringUtils.getMergedLines(entity.getDisplay2()), FontParam.CLASS, null) - + "
    >"); - return sb.toString(); - - } - - private String getLabelForClassOrInterfaceOrEnum(IEntity entity) throws IOException { - if (isVisibilityModifierPresent) { - return getLabelForClassOrInterfaceOrEnumWithVisibilityImage(entity); - } - return getLabelForClassOrInterfaceOrEnumOld(entity); - - } - - private String getLabelForClassOrInterfaceOrEnumOld(IEntity entity) throws IOException { - LabelBuilder builder = new LabelBuilderClassOld(getFileFormat(), getData(), entity); - if (MODE_LOLLIPOP_BETA) { - final DrawFile cFile = getData().getStaticImages(entity.getType(), null); - final String northPath = StringUtils.getPlateformDependentAbsolutePath(cFile.getPngOrEps(getFileFormat())); - final String southPath = northPath; - final String eastPath = northPath; - final String westPath = northPath; - builder = new LabelBuilderTableLollipopDecorator(getFileFormat(), getData(), entity, builder, northPath, - southPath, eastPath, westPath, getAllLollipop(entity)); - } else if (MODE_MARGIN && entity.hasNearDecoration()) { - builder = new LabelBuilderTableNineDecorator(getFileFormat(), getData(), entity, builder); - } - final StringBuilder sb = new StringBuilder(); - sb.append("<"); - builder.appendLabel(sb); - if (builder.isUnderline()) { - setUnderline(true); - } - sb.append(">"); - return sb.toString(); - } - - final private List fileToClean = new ArrayList(); - - private String addFieldsEps(List members, boolean withVisibilityChar) throws IOException { - final List texts = new ArrayList(); - for (Member att : members) { - String s = att.getDisplay(withVisibilityChar); - if (att.isAbstract()) { - s = "" + s + ""; - } - if (att.isStatic()) { - s = "" + s + ""; - } - texts.add(s); - } - final UFont font = getData().getSkinParam().getFont(FontParam.CLASS_ATTRIBUTE, null); - final HtmlColor color = getFontHtmlColor(FontParam.CLASS_ATTRIBUTE, null); - final TextBlock text = TextBlockUtils.create(texts, new FontConfiguration(font, color), - HorizontalAlignement.LEFT); - final File feps = FileUtils.createTempFile("member", ".eps"); - UGraphicEps.copyEpsToFile(getData().getColorMapper(), new UDrawable() { - public void drawU(UGraphic ug) { - text.drawU(ug, 0, 0); - } - }, feps); - fileToClean.add(feps); - - final String path = StringUtils.getPlateformDependentAbsolutePath(feps); - - return "" + "" - + "" + "" + "
    " + "
    "; - } - - private String getLabelForClassOrInterfaceOrEnumWithVisibilityImage(IEntity entity) throws IOException { - LabelBuilder builder = new LabelBuilderClassWithVisibilityImage(fileFormat, getData(), entity); - if (MODE_MARGIN && entity.hasNearDecoration()) { - builder = new LabelBuilderTableNineDecorator(getFileFormat(), getData(), entity, builder); - } - final StringBuilder sb = new StringBuilder(); - sb.append("<"); - builder.appendLabel(sb); - if (builder.isUnderline()) { - setUnderline(true); - } - sb.append(">"); - return sb.toString(); - } - - private String getLabelForObject(IEntity entity) throws IOException { - if (isVisibilityModifierPresent) { - return getLabelForObjectWithVisibilityImage(entity); - } - return getLabelForObjectOld(entity); - } - - private String getLabelForObjectWithVisibilityImage(IEntity entity) throws IOException { - final LabelBuilder builder = new LabelBuilderObjectWithVisibilityImage(getFileFormat(), getData(), entity); - final StringBuilder sb = new StringBuilder(); - builder.appendLabel(sb); - if (builder.isUnderline()) { - setUnderline(true); - } - return sb.toString(); - - } - - private String getLabelForObjectOld(IEntity entity) throws IOException { - final LabelBuilder builder = new LabelBuilderObjectOld(getFileFormat(), getData(), entity); - final StringBuilder sb = new StringBuilder(); - builder.appendLabel(sb); - if (builder.isUnderline()) { - setUnderline(true); - } - return sb.toString(); - - } - - private boolean isSpecialGroup(Group g) { - if (g.getType() == GroupType.STATE) { - return true; - } - if (g.getType() == GroupType.CONCURRENT_STATE) { - throw new IllegalStateException(); - } - if (getData().isThereLink(g)) { - return true; - } - return false; - } - - private static final String getLastDotSignature() { - return lastDotSignature; - } - - public static final void reset() { - lastDotSignature = null; - } - - public void clean() { - if (OptionFlags.getInstance().isKeepTmpFiles()) { - return; - } - for (File f : fileToClean) { - Log.info("Deleting temporary file " + f); - final boolean ok = f.delete(); - if (ok == false) { - Log.error("Cannot delete: " + f); - } - } - } - - public static final boolean isJunit() { - return isJunit; - } - -} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/Unlazy.java b/src/net/sourceforge/plantuml/cucadiagram/dot/DotMaker2.java similarity index 78% rename from src/net/sourceforge/plantuml/cucadiagram/dot/Unlazy.java rename to src/net/sourceforge/plantuml/cucadiagram/dot/DotMaker2.java index 286d6fc34..e693f551e 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/Unlazy.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/DotMaker2.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,20 +28,21 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3977 $ + * Revision $Revision: 7899 $ * */ package net.sourceforge.plantuml.cucadiagram.dot; -public class Unlazy implements Lazy { - - private final O data; - - public Unlazy(O data) { - this.data = data; +final public class DotMaker2 { + + private static boolean isJunit = false; + + public static void goJunit() { + isJunit = true; } - - public O getNow() { - return data; + + public static final boolean isJunit() { + return isJunit; } + } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/DotSplines.java b/src/net/sourceforge/plantuml/cucadiagram/dot/DotSplines.java index 3422ec97d..6c5dea2ee 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/DotSplines.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/DotSplines.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/DrawFile.java b/src/net/sourceforge/plantuml/cucadiagram/dot/DrawFile.java deleted file mode 100644 index 4b74fe045..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/DrawFile.java +++ /dev/null @@ -1,300 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 3977 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - -import javax.imageio.ImageIO; - -import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.Log; -import net.sourceforge.plantuml.OptionFlags; - -public class DrawFile { - - private static final Map cache = new HashMap(); - private static final Collection toDelete = new HashSet(); - - private final LazyFile png2; - private final LazyCached svg2; - private final LazyFile eps2; - private final String toStringValue; - private final boolean cached; - - private final AtomicInteger useCounter = new AtomicInteger(0); - private final AtomicInteger totalUse = new AtomicInteger(0); - private final AtomicBoolean useable = new AtomicBoolean(true); - - private int widthPng = -1; - private int heightPng = -1; - - static { - addHook(); - } - - public static boolean isCacheClean() { - synchronized (toDelete) { - for (DrawFile f : toDelete) { - if (f.useCounter.get() != 0) { - Log.error("Remaining " + f); - return false; - } - } - for (DrawFile f : cache.values()) { - if (f.useCounter.get() != 0) { - Log.error("Remaining " + f); - return false; - } - } - } - return true; - } - - public static DrawFile create(Lazy png, Lazy svg, Lazy eps, Object signature) { - DrawFile result = null; - synchronized (toDelete) { - if (signature != null) { - result = cache.get(signature); - } - if (result == null) { - result = new DrawFile(png, svg, eps, signature == null ? null : signature.toString(), signature != null); - if (signature != null) { - cache.put(signature, result); - Log.info("DrawFile cache size = " + cache.size()); - } - deleteOnExit(result); - } - result.useCounter.addAndGet(1); - result.totalUse.addAndGet(1); - // checkCacheSize(); - } - return result; - } - - private static void checkCacheSize() { - int min = Integer.MAX_VALUE; - for (DrawFile f : cache.values()) { - final int score = f.totalUse.get(); - if (score < min) { - min = score; - } - } - for (final Iterator it = cache.values().iterator(); it.hasNext();) { - final DrawFile f = it.next(); - if (f.useCounter.get() == 0 && f.totalUse.get() == min) { - it.remove(); - } - - } - } - - @Override - public String toString() { - if (toStringValue == null) { - return super.toString() + " " + useCounter.get() + " " + totalUse.get(); - } - return toStringValue + " " + useCounter.get() + " " + totalUse.get(); - } - - public static DrawFile createFromFile(File fPng, String svg, File fEps) { - final DrawFile result = new DrawFile(fPng, svg, fEps, fPng.getName(), false); - result.useCounter.addAndGet(1); - deleteOnExit(result); - return result; - } - - private static void deleteOnExit(DrawFile file) { - synchronized (toDelete) { - toDelete.add(file); - } - } - - private DrawFile(Lazy png, Lazy svg, Lazy eps, String signature, boolean cached) { - this.png2 = new LazyFile(png); - this.svg2 = new LazyCached(svg); - this.eps2 = new LazyFile(eps); - this.toStringValue = signature; - this.cached = cached; - } - - private DrawFile(File fPng, String svg, File fEps, String signature, boolean cached) { - this(new Unlazy(fPng), new Unlazy(svg), new Unlazy(fEps), signature, cached); - // if (svg.contains("\\")) { - // System.err.println("svg="+svg); - // throw new IllegalArgumentException(); - // } - } - - public File getPngOrEps(FileFormat format) throws IOException { - checkUseable(); - if (format.isEps()) { - if (eps2 == null) { - throw new UnsupportedOperationException("No eps for " + getPng().getAbsolutePath()); - } - return getEps(); - } - return getPng(); - } - - private void checkUseable() { - if (useable.get() == false) { - throw new IllegalStateException("Useable false"); - } - } - - public synchronized File getPng() throws IOException { - checkUseable(); - return png2.getNow(); - } - - public synchronized String getSvg() throws IOException { - checkUseable(); - return svg2.getNow(); - } - - public synchronized File getEps() throws IOException { - checkUseable(); - return eps2.getNow(); - } - - private synchronized void initSize() throws IOException { - checkUseable(); - final BufferedImage im = ImageIO.read(getPng()); - widthPng = im.getWidth(); - heightPng = im.getHeight(); - } - - public synchronized void deleteDrawFile() { - if (useable.get() == false) { - return; - } - // checkUseable(); - final int count = useCounter.addAndGet(-1); - if (count == 0) { - if (cached && isCacheTooBig() == false) { - return; - } - synchronized (toDelete) { - deleteNow(); - if (cached) { - final boolean removedCache = cache.values().remove(this); - if (removedCache == false) { - Log.error("Not found in cache " + this); - } - } - final boolean removedToDelete = toDelete.remove(this); - if (removedToDelete == false) { - Log.error("Not found in delete list " + this); - } - } - } - } - - private static boolean isCacheTooBig() { - return true; - } - - private synchronized void deleteNow() { - useable.set(false); - if (png2 != null && png2.isLoaded()) { - try { - Log.info("Deleting temporary file " + png2.getNow()); - final boolean ok = png2.getNow().delete(); - if (ok == false) { - Log.error("Cannot delete: " + png2.getNow()); - } - } catch (IOException e) { - e.printStackTrace(); - Log.error("Problem deleting PNG file"); - } - } - if (eps2 != null && eps2.isLoaded()) { - try { - Log.info("Deleting temporary file " + eps2.getNow()); - final boolean ok2 = eps2.getNow().delete(); - if (ok2 == false) { - Log.error("Cannot delete: " + eps2.getNow()); - } - } catch (IOException e) { - e.printStackTrace(); - Log.error("Problem deleting EPS file"); - } - } - } - - public final int getWidthPng() throws IOException { - checkUseable(); - if (widthPng == -1) { - initSize(); - } - return widthPng; - } - - public final int getHeightPng() throws IOException { - checkUseable(); - if (widthPng == -1) { - initSize(); - } - return heightPng; - } - - private static void addHook() { - Runtime.getRuntime().addShutdownHook(new Thread() { - @Override - public void run() { - if (OptionFlags.getInstance().isKeepTmpFiles() == false) { - synchronized (toDelete) { - for (DrawFile f : toDelete) { - final int cnt = f.useCounter.get(); - if (cnt != 0) { - Log.info("Warning: useCounter " + cnt + " for " + f); - } - f.deleteNow(); - } - } - } - } - }); - } - -} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/DrawFileFactory.java b/src/net/sourceforge/plantuml/cucadiagram/dot/DrawFileFactory.java deleted file mode 100644 index 132a1e089..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/DrawFileFactory.java +++ /dev/null @@ -1,84 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 3977 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.awt.Color; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; - -import javax.imageio.ImageIO; - -import net.sourceforge.plantuml.EmptyImageBuilder; -import net.sourceforge.plantuml.FileUtils; -import net.sourceforge.plantuml.skin.UDrawable; -import net.sourceforge.plantuml.ugraphic.ColorMapper; -import net.sourceforge.plantuml.ugraphic.eps.UGraphicEps; -import net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d; - -public class DrawFileFactory { - - public static DrawFile create(final ColorMapper colorMapper, final UDrawable drawable, final double width, final double height, - final double dpiFactor, final Color backgground, Object signature) { - - final Lazy lpng = new Lazy() { - public File getNow() throws IOException { - final File png = FileUtils.createTempFile("visi", ".png"); - final EmptyImageBuilder builder = new EmptyImageBuilder(width * dpiFactor, height * dpiFactor, - backgground); - final BufferedImage im = builder.getBufferedImage(); - drawable.drawU(new UGraphicG2d(colorMapper, builder.getGraphics2D(), im, dpiFactor)); - ImageIO.write(im, "png", png); - return png; - } - }; - - final Lazy leps = new Lazy() { - public File getNow() throws IOException { - final File eps = FileUtils.createTempFile("visi", ".eps"); - UGraphicEps.copyEpsToFile(colorMapper, drawable, eps); - return eps; - } - }; - - final Lazy lsvg = new Lazy() { - public String getNow() throws IOException { - return UGraphicG2d.getSvgString(colorMapper, drawable); - } - }; - - return DrawFile.create(lpng, lsvg, leps, signature); - } - -} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/Executable.java b/src/net/sourceforge/plantuml/cucadiagram/dot/Executable.java deleted file mode 100644 index 297102b17..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/Executable.java +++ /dev/null @@ -1,135 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6104 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.io.File; -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.List; - -import net.sourceforge.plantuml.FileFormatOption; -import net.sourceforge.plantuml.OptionFlags; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.graphic.GraphicStrings; - -abstract class Executable { - - private final File dotExe; - - static boolean isWindows() { - return File.separatorChar == '\\'; - } - - Executable(String dotString, String... type) { - if (type == null) { - throw new IllegalArgumentException(); - } - this.dotExe = searchDotExe(); - } - - private File searchDotExe() { - if (OptionFlags.getInstance().getDotExecutable() == null) { - final String getenv = GraphvizUtils.getenvGraphvizDot(); - if (getenv == null) { - return specificDotExe(); - } - return new File(getenv); - } - - return new File(OptionFlags.getInstance().getDotExecutable()); - - } - - abstract protected File specificDotExe(); - - - final public String dotVersion() throws IOException, InterruptedException { - final String cmd = getCommandLineVersion(); - return executeCmd(cmd); - } - - private String executeCmd(final String cmd) throws IOException, InterruptedException { - final ProcessRunner p = new ProcessRunner(cmd); - p.run(null, null); - final StringBuilder sb = new StringBuilder(); - if (StringUtils.isNotEmpty(p.getOut())) { - sb.append(p.getOut()); - } - if (StringUtils.isNotEmpty(p.getError())) { - if (sb.length() > 0) { - sb.append(' '); - } - sb.append(p.getError()); - } - return sb.toString().replace('\n', ' ').trim(); - } - - final private void createPngNoGraphviz(OutputStream os, FileFormatOption format) throws IOException { - final List msg = new ArrayList(); - msg.add("Dot Executable: " + dotExe); - if (dotExe != null) { - if (dotExe.exists() == false) { - msg.add("File does not exist"); - } else if (dotExe.isDirectory()) { - msg.add("It should be an executable, not a directory"); - } else if (dotExe.isFile() == false) { - msg.add("Not a valid file"); - } else if (dotExe.canRead() == false) { - msg.add("File cannot be read"); - } - } - msg.add("Cannot find Graphviz. You should try"); - msg.add(" "); - msg.add("@startuml"); - msg.add("testdot"); - msg.add("@enduml"); - msg.add(" "); - msg.add(" or "); - msg.add(" "); - msg.add("java -jar plantuml.jar -testdot"); - final GraphicStrings errorResult = new GraphicStrings(msg); - errorResult.writeImage(os, format); - } - - abstract String getCommandLine(); - - abstract String getCommandLineVersion(); - - public final File getDotExe() { - return dotExe; - } - - -} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/Graphviz.java b/src/net/sourceforge/plantuml/cucadiagram/dot/Graphviz.java index d12a20570..0850caa72 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/Graphviz.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/Graphviz.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,22 +28,19 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6711 $ + * Revision $Revision: 12064 $ * */ package net.sourceforge.plantuml.cucadiagram.dot; import java.io.File; -import java.io.IOException; import java.io.OutputStream; public interface Graphviz { - void createFile(OutputStream os) throws IOException, InterruptedException; + ProcessState createFile3(OutputStream os); File getDotExe(); - String dotVersion() throws IOException, InterruptedException; - - String testFile(String dotfilename, String outfile) throws IOException, InterruptedException; + String dotVersion(); } \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizCached.java b/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizCached.java deleted file mode 100644 index 7465e7293..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizCached.java +++ /dev/null @@ -1,113 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6711 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.io.BufferedOutputStream; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.PrintWriter; -import java.util.List; - -import net.sourceforge.plantuml.FileUtils; -import net.sourceforge.plantuml.Log; -import net.sourceforge.plantuml.SignatureUtils; - -public class GraphvizCached implements Graphviz { - - private final AbstractGraphviz graphviz; - - public GraphvizCached(AbstractGraphviz graphviz) { - this.graphviz = graphviz; - } - - public void createFile(OutputStream os) throws IOException, InterruptedException { - final File f = getCachedFile(); - - if (f.exists()) { - Log.info("Using " + f); - FileUtils.copyToStream(f, os); - return; - } - - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - graphviz.createFile(baos); - baos.close(); - final byte data[] = baos.toByteArray(); - - Log.info("Creating " + f); - final OutputStream fos = new BufferedOutputStream(new FileOutputStream(f)); - fos.write(data); - fos.close(); - - final InputStream is = new ByteArrayInputStream(data); - FileUtils.copyToStream(is, os); - is.close(); - } - - private File getCachedFile() throws FileNotFoundException { - final String dot = graphviz.getDotString(); - final List types = graphviz.getType(); - final String sign = SignatureUtils.getSignature(dot + types); - - final File source = new File("__graphviz", sign + ".txt"); - source.getParentFile().mkdirs(); - final PrintWriter pw = new PrintWriter(source); - pw.println(types.toString()); - pw.println(dot); - pw.close(); - - final File result = new File("__graphviz", sign); - result.getParentFile().mkdirs(); - return result; - } - - public String dotVersion() throws IOException, InterruptedException { - return graphviz.dotVersion(); - } - - public File getDotExe() { - return graphviz.getDotExe(); - } - - public String testFile(String dotfilename, String outfile) throws IOException, InterruptedException { - return graphviz.testFile(dotfilename, outfile); - } - -} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizLayoutStrategy.java b/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizLayoutStrategy.java index e072c8b16..137095dfd 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizLayoutStrategy.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizLayoutStrategy.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -34,27 +34,14 @@ package net.sourceforge.plantuml.cucadiagram.dot; import java.io.File; -import java.util.List; -import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.OptionFlags; public enum GraphvizLayoutStrategy { DOT, NEATO, FDP, TWOPI, CIRCO; - public GraphvizMaker getGraphvizMaker(DotData data, - List dotStrings, FileFormat fileFormat) { -// if (this == DOT) { - return new DotMaker(data, dotStrings, fileFormat); -// } -// throw new UnsupportedOperationException(this.toString()); - } - public File getSystemForcedExecutable() { -// if (this == DOT) { - return getSystemForcedDot(); -// } -// throw new UnsupportedOperationException(this.toString()); + return getSystemForcedDot(); } private File getSystemForcedDot() { diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizLinux.java b/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizLinux.java index b7f1c952a..19eab7474 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizLinux.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizLinux.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4826 $ + * Revision $Revision: 10765 $ * */ package net.sourceforge.plantuml.cucadiagram.dot; @@ -52,20 +52,4 @@ class GraphvizLinux extends AbstractGraphviz { return usrBinDot; } - @Override - String getCommandLine() { - final StringBuilder sb = new StringBuilder(); - sb.append(getDotExe().getAbsolutePath()); - appendImageType(sb); - return sb.toString(); - } - - @Override - String getCommandLineVersion() { - final StringBuilder sb = new StringBuilder(); - sb.append(getDotExe().getAbsolutePath()); - sb.append(" -V"); - return sb.toString(); - } - } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizUtils.java b/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizUtils.java index 733f23e3f..ec2ffd616 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizUtils.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizUtils.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,28 +28,24 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6713 $ + * Revision $Revision: 12064 $ * */ package net.sourceforge.plantuml.cucadiagram.dot; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -import javax.imageio.ImageIO; - -import net.sourceforge.plantuml.OptionFlags; import net.sourceforge.plantuml.StringUtils; public class GraphvizUtils { - private static final String TMP_TEST_FILENAME = "testdottmp42"; private static int DOT_VERSION_LIMIT = 226; private static boolean isWindows() { @@ -64,9 +60,9 @@ public class GraphvizUtils { } else { result = new GraphvizLinux(dotString, type); } - if (OptionFlags.GRAPHVIZCACHE && DotMaker.isJunit()) { - return new GraphvizCached(result); - } + // if (OptionFlags.GRAPHVIZCACHE) { + // return new GraphvizCached(result); + // } return result; } @@ -82,9 +78,13 @@ public class GraphvizUtils { public static String getenvGraphvizDot() { final String env = System.getProperty("GRAPHVIZ_DOT"); if (StringUtils.isNotEmpty(env)) { - return env; + return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(env); } - return System.getenv("GRAPHVIZ_DOT"); + final String getenv = System.getenv("GRAPHVIZ_DOT"); + if (StringUtils.isNotEmpty(getenv)) { + return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(getenv); + } + return null; } public static String getenvLogData() { @@ -169,17 +169,15 @@ public class GraphvizUtils { final int v = GraphvizUtils.getDotVersion(); if (v == -1) { result.add("Warning : cannot determine dot version"); + } else if (v < DOT_VERSION_LIMIT) { + result.add(bold + "Warning : Your dot installation seems old"); + result.add(bold + "Some diagrams may have issues"); } else { - if (v < DOT_VERSION_LIMIT) { - result.add(bold + "Warning : Your dot installation seems old"); - result.add(bold + "Some diagrams may have issues"); + final String err = getTestCreateSimpleFile(); + if (err == null) { + result.add(bold + "Installation seems OK. File generation OK"); } else { - String err = getTestCreateSimpleFile(); - if (err == null) { - result.add(bold + "Installation seems OK. PNG generation OK"); - } else { - result.add(red + err); - } + result.add(red + err); } } } catch (Exception e) { @@ -193,33 +191,24 @@ public class GraphvizUtils { return Collections.unmodifiableList(result); } - static String getTestCreateSimpleFile() throws IOException, InterruptedException { - final Graphviz graphviz = GraphvizUtils.create("", "png"); - final File f = new File(TMP_TEST_FILENAME + ".dot"); - final File fout = new File(TMP_TEST_FILENAME + ".png"); - f.delete(); - fout.delete(); - try { - final PrintWriter pw = new PrintWriter(f); - pw.println("digraph foo { test; }"); - pw.close(); - graphviz.testFile(f.getName(), fout.getName()); - f.delete(); - if (fout.exists() == false) { - return "Error: dot cannot generated PNG file. Check you dot installation."; - } - if (fout.length() == 0) { - return "Error: dot generates empty PNG file. Check you dot installation."; - } - try { - ImageIO.read(fout); - } catch (IOException e) { - return "Error: dot generates unreadable PNG file. Check you dot installation."; - } - return null; - } finally { - fout.delete(); + static String getTestCreateSimpleFile() throws IOException { + final Graphviz graphviz2 = GraphvizUtils.create("digraph foo { test; }", "svg"); + final ByteArrayOutputStream baos = new ByteArrayOutputStream(); + final ProcessState state = graphviz2.createFile3(baos); + if (state != ProcessState.TERMINATED_OK) { + return "Error: timeout " + state; } + + final byte data[] = baos.toByteArray(); + + if (data.length == 0) { + return "Error: dot generates empty file. Check you dot installation."; + } + final String s = new String(data); + if (s.indexOf(" map = new HashMap(); - private final ISkinParam param; - private final double dpiFactor; + final private File dotExe; - public StaticFilesMap(ISkinParam param, double dpiFactor) { - this.param = param; - this.dpiFactor = dpiFactor; + public GraphvizVersionFinder(File dotExe) { + this.dotExe = dotExe; } - public StaticFiles getStaticFiles(String stereotype) throws IOException { - StaticFiles result = map.get(stereotype); - if (result == null) { - result = new StaticFiles(param, stereotype, dpiFactor); - map.put(stereotype, result); + public GraphvizVersion getVersion() { + final String s = dotVersion(); + if (s.contains("2.34.0")) { + return GraphvizVersion.V2_34_0; } - return result; + return GraphvizVersion.COMMON; } - public DrawFile getDrawFile(String href) throws IOException { - for (StaticFiles staticFiles : map.values()) { - final DrawFile drawFile = staticFiles.getDrawFile(href); - if (drawFile != null) { - return drawFile; + public String dotVersion() { + final String cmd[] = getCommandLine(); + + final ProcessRunner p = new ProcessRunner(cmd); + final ProcessState state = p.run2(null, null); + if (state != ProcessState.TERMINATED_OK) { + return "?"; + } + final StringBuilder sb = new StringBuilder(); + if (StringUtils.isNotEmpty(p.getOut())) { + sb.append(p.getOut()); + } + if (StringUtils.isNotEmpty(p.getError())) { + if (sb.length() > 0) { + sb.append(' '); } + sb.append(p.getError()); } - return null; + return sb.toString().replace('\n', ' ').trim(); } - public void clean() { - for (StaticFiles staticFiles : map.values()) { - staticFiles.clean(); - } + private String[] getCommandLine() { + return new String[] { dotExe.getAbsolutePath(), "-V" }; } } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizVersions.java b/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizVersions.java new file mode 100644 index 000000000..5a2a1fec8 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizVersions.java @@ -0,0 +1,71 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 11325 $ + * + */ +package net.sourceforge.plantuml.cucadiagram.dot; + +import java.io.File; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +public class GraphvizVersions { + + private final static GraphvizVersions singleton = new GraphvizVersions(); + + private final Map map = new ConcurrentHashMap(); + + private GraphvizVersions() { + } + + public static GraphvizVersions getInstance() { + return singleton; + } + + public GraphvizVersion getVersion(File f) { + if (f == null) { + return null; + } + GraphvizVersion result = map.get(f); + if (result != null) { + return result; + } + result = checkVersionSlow(f.getAbsolutePath()); + map.put(f, result); + return result; + } + + static GraphvizVersion checkVersionSlow(String pathExecutable) { + final GraphvizVersionFinder finder = new GraphvizVersionFinder(new File(pathExecutable)); + return finder.getVersion(); + } + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizWindows.java b/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizWindows.java index dc4d31670..bc88553a0 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizWindows.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/GraphvizWindows.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4826 $ + * Revision $Revision: 10765 $ * */ package net.sourceforge.plantuml.cucadiagram.dot; @@ -84,28 +84,4 @@ class GraphvizWindows extends AbstractGraphviz { super(dotString, type); } - @Override - String getCommandLine() { - final StringBuilder sb = new StringBuilder(); - appendDoubleQuoteOnWindows(sb); - sb.append(getDotExe().getAbsolutePath()); - appendDoubleQuoteOnWindows(sb); - appendImageType(sb); - return sb.toString(); - } - - private static void appendDoubleQuoteOnWindows(final StringBuilder sb) { - sb.append('\"'); - } - - @Override - String getCommandLineVersion() { - final StringBuilder sb = new StringBuilder(); - appendDoubleQuoteOnWindows(sb); - sb.append(getDotExe().getAbsolutePath()); - appendDoubleQuoteOnWindows(sb); - sb.append(" -V"); - return sb.toString(); - } - } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/GroupPngMaker.java b/src/net/sourceforge/plantuml/cucadiagram/dot/GroupPngMaker.java deleted file mode 100644 index adcc2017c..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/GroupPngMaker.java +++ /dev/null @@ -1,234 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6711 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.awt.image.BufferedImage; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.imageio.ImageIO; - -import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.FileUtils; -import net.sourceforge.plantuml.ISkinParam; -import net.sourceforge.plantuml.OptionFlags; -import net.sourceforge.plantuml.SkinParamBackcolored; -import net.sourceforge.plantuml.cucadiagram.CucaDiagram; -import net.sourceforge.plantuml.cucadiagram.Entity; -import net.sourceforge.plantuml.cucadiagram.EntityType; -import net.sourceforge.plantuml.cucadiagram.Group; -import net.sourceforge.plantuml.cucadiagram.GroupHierarchy; -import net.sourceforge.plantuml.cucadiagram.IEntity; -import net.sourceforge.plantuml.cucadiagram.Link; -import net.sourceforge.plantuml.png.PngIO; - -public final class GroupPngMaker { - - private final CucaDiagram diagram; - private final Group group; - private final FileFormat fileFormat; - - class InnerGroupHierarchy implements GroupHierarchy { - - public Collection getChildrenGroups(Group parent) { - if (parent == null) { - return diagram.getChildrenGroups(group); - } - return diagram.getChildrenGroups(parent); - } - - public boolean isEmpty(Group g) { - return diagram.isEmpty(g); - } - - } - - public GroupPngMaker(CucaDiagram diagram, Group group, FileFormat fileFormat) throws IOException { - this.diagram = diagram; - this.group = group; - this.fileFormat = fileFormat; - } - - public void createPng(OutputStream os, List dotStrings) throws IOException, InterruptedException { - final Map imageFiles = new HashMap(); - // final Map imagesLink = new HashMap(); - try { - // populateImages(imageFiles); - // populateImagesLink(imagesLink); - final GraphvizMaker dotMaker = createDotMaker(dotStrings); - final String dotString = dotMaker.createDotString(); - - // if (OptionFlags.getInstance().isKeepTmpFiles()) { - // traceDotString(dotString); - // } - - // final boolean isUnderline = dotMaker.isUnderline(); - final Graphviz graphviz = GraphvizUtils.create(dotString, "png"); - - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - graphviz.createFile(baos); - baos.close(); - - final ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); - final BufferedImage im = ImageIO.read(bais); - bais.close(); - // if (isUnderline) { - // new UnderlineTrick(im, new Color(Integer.parseInt("FEFECF", 16)), - // Color.BLACK).process(); - // } - - PngIO.write(im, os, diagram.getMetadata(), 96); - } finally { - cleanTemporaryFiles(imageFiles); - } - } - - public String createSvg(List dotStrings) throws IOException, InterruptedException { - final Map imageFiles = new HashMap(); - // final Map imagesLink = new HashMap(); - try { - // populateImages(imageFiles); - // populateImagesLink(imagesLink); - final GraphvizMaker dotMaker = createDotMaker(dotStrings); - final String dotString = dotMaker.createDotString(); - - // if (OptionFlags.getInstance().isKeepTmpFiles()) { - // traceDotString(dotString); - // } - - // final boolean isUnderline = dotMaker.isUnderline(); - final Graphviz graphviz = GraphvizUtils.create(dotString, "svg"); - - final ByteArrayOutputStream baos = new ByteArrayOutputStream(); - graphviz.createFile(baos); - baos.close(); - - String svg = new String(baos.toByteArray(), "UTF-8"); - svg = removeSvgXmlHeader(svg); - - // // Image management - // final Pattern pImage = Pattern.compile("(?i)]*>"); - // final Matcher mImage = pImage.matcher(svg); - // final StringBuffer sb = new StringBuffer(); - // while (mImage.find()) { - // final String image = mImage.group(0); - // final String href = CucaDiagramFileMaker.getValue(image, "href"); - // final double widthSvg = - // Double.parseDouble(CucaDiagramFileMaker.getValuePx(image, - // "width")); - // final double heightSvg = - // Double.parseDouble(CucaDiagramFileMaker.getValuePx(image, - // "height")); - // final double x = - // Double.parseDouble(CucaDiagramFileMaker.getValue(image, "x")) + - // 20; - // final double y = - // Double.parseDouble(CucaDiagramFileMaker.getValue(image, "y")) + - // 20; - // // final DrawFile drawFile = getDrawFileFromHref(href); - // // final int widthPng = drawFile.getWidthPng(); - // // final int heightPng = drawFile.getHeightPng(); - // // String svg2 = drawFile.getSvg(); - // // final String scale = CucaDiagramFileMaker.getScale(widthSvg, - // heightSvg, widthPng, heightPng); - // // svg2 = svg2 - // // .replaceFirst("<[gG]>", ""); - // String svg2 = "toto"; - // svg2 = "" + svg2 + ""; - // mImage.appendReplacement(sb, svg2); - // } - // mImage.appendTail(sb); - // svg = sb.toString(); - - return svg.replace('\\', '/'); - - } finally { - cleanTemporaryFiles(imageFiles); - } - } - - private static String removeSvgXmlHeader(String svg) { - svg = svg.replaceFirst("(?i)<\\?xml[\\s\\S]*?]*>", ""); - svg = svg.replaceFirst("(?i)", ""); - - return svg; - } - - private void cleanTemporaryFiles(final Map imageFiles) { - if (OptionFlags.getInstance().isKeepTmpFiles() == false) { - for (File f : imageFiles.values()) { - FileUtils.delete(f); - } - } - } - - GraphvizMaker createDotMaker(List dotStrings) { - final List links = getPureInnerLinks(); - ISkinParam skinParam = diagram.getSkinParam(); - if (OptionFlags.PBBACK && group.getBackColor() != null) { - skinParam = new SkinParamBackcolored(skinParam, null, group.getBackColor()); - } - final DotData dotData = new DotData(group, links, group.entities(), diagram.getUmlDiagramType(), skinParam, - group.getRankdir(), new InnerGroupHierarchy(), diagram.getColorMapper()); - // dotData.putAllImages(images); - // dotData.putAllStaticImages(staticImages); - // dotData.putAllImagesLink(imagesLink); - - // return new DotMaker(dotData, dotStrings, fileFormat); - return diagram.getSkinParam().getStrategy().getGraphvizMaker(dotData, dotStrings, fileFormat); - } - - private List getPureInnerLinks() { - final List result = new ArrayList(); - for (Link link : diagram.getLinks()) { - final IEntity e1 = link.getEntity1(); - final IEntity e2 = link.getEntity2(); - if (e1.getParent() == group && e1.getType() != EntityType.GROUP && e2.getParent() == group - && e2.getType() != EntityType.GROUP) { - result.add(link); - } - } - return result; - } - -} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderClassOld.java b/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderClassOld.java deleted file mode 100644 index a99c22ef1..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderClassOld.java +++ /dev/null @@ -1,131 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6295 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.io.IOException; - -import net.sourceforge.plantuml.ColorParam; -import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.FontParam; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.cucadiagram.EntityPortion; -import net.sourceforge.plantuml.cucadiagram.IEntity; -import net.sourceforge.plantuml.cucadiagram.Member; - -class LabelBuilderClassOld extends LabelBuilderObjectOrClass implements LabelBuilder { - - private BorderMode mode = BorderMode.NO_BORDER_CELLSPACING_OLD; - - LabelBuilderClassOld(FileFormat fileFormat, DotData data, IEntity entity) { - super(fileFormat, data, entity); - } - - public void appendLabel(StringBuilder sb) throws IOException { - DrawFile cFile = getEntity().getImageFile(); - if (cFile == null) { - final String stereo = getEntity().getStereotype() == null ? null : getEntity().getStereotype().getLabel(); - cFile = getData().getStaticImages(getEntity().getType(), stereo); - } - if (cFile == null) { - throw new IllegalStateException(); - } - final String circleAbsolutePath; - if (getData().showPortion(EntityPortion.CIRCLED_CHARACTER, getEntity())) { - circleAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(cFile.getPngOrEps(getFileFormat())); - } else { - circleAbsolutePath = null; - } - - // sb.append("<"); - - final boolean showFields = getData().showPortion(EntityPortion.FIELD, getEntity()); - final boolean showMethods = getData().showPortion(EntityPortion.METHOD, getEntity()); - - final String stereo = getEntity().getStereotype() == null ? null : getEntity().getStereotype().getLabel(); - - if (showFields == false && showMethods == false) { - sb.append(getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(getEntity(), circleAbsolutePath, 1, true, - mode)); - } else { - sb.append(""); - sb.append(""); - - if (showFields) { - // if (fileFormat == FileFormat.EPS) { - // sb.append(addFieldsEps(getEntity().fields2(), true)); - // } else { - final boolean hasStatic = hasStatic(getEntity().getFieldsToDisplay()); - sb.append(""); - // } - } - if (showMethods) { - // if (fileFormat == FileFormat.EPS) { - // sb.append(addFieldsEps(getEntity().methods2(), true)); - // } else { - final boolean hasStatic = hasStatic(getEntity().getMethodsToDisplay()); - sb.append(""); - // } - } - sb.append("
    "); - final int longuestFieldOrAttribute = getLongestFieldOrAttribute(getEntity()); - final int longuestHeader = getLonguestHeader(getEntity()); - final int spring = computeSpring(longuestHeader, longuestFieldOrAttribute, 30); - - sb.append(getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(getEntity(), circleAbsolutePath, spring, - true, BorderMode.NO_BORDER)); - - sb.append("
    "); - for (Member att : getEntity().getFieldsToDisplay()) { - sb.append(manageHtmlIBspecial(att, FontParam.CLASS_ATTRIBUTE, hasStatic, getColorString( - ColorParam.classBackground, stereo), true)); - sb.append("
    "); - } - sb.append("
    "); - for (Member att : getEntity().getMethodsToDisplay()) { - sb.append(manageHtmlIBspecial(att, FontParam.CLASS_ATTRIBUTE, hasStatic, getColorString( - ColorParam.classBackground, stereo), true)); - sb.append("
    "); - } - sb.append("
    "); - } - // sb.append(">"); - } - - public void patch() { - mode = BorderMode.NO_BORDER_CELLSPACING_NEW; - } - -} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderClassWithVisibilityImage.java b/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderClassWithVisibilityImage.java deleted file mode 100644 index 7a4302727..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderClassWithVisibilityImage.java +++ /dev/null @@ -1,110 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6295 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.io.IOException; - -import net.sourceforge.plantuml.ColorParam; -import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.cucadiagram.EntityPortion; -import net.sourceforge.plantuml.cucadiagram.IEntity; - -class LabelBuilderClassWithVisibilityImage extends LabelBuilderObjectOrClass implements LabelBuilder { - - LabelBuilderClassWithVisibilityImage(FileFormat fileFormat, DotData data, IEntity entity) { - super(fileFormat, data, entity); - } - - public void appendLabel(StringBuilder sb) throws IOException { - DrawFile cFile = getEntity().getImageFile(); - if (cFile == null) { - final String stereo = getEntity().getStereotype() == null ? null : getEntity().getStereotype().getLabel(); - cFile = getData().getStaticImages(getEntity().getType(), stereo); - } - if (cFile == null) { - throw new IllegalStateException(); - } - final String circleAbsolutePath; - if (getData().showPortion(EntityPortion.CIRCLED_CHARACTER, getEntity())) { - circleAbsolutePath = StringUtils.getPlateformDependentAbsolutePath(cFile.getPngOrEps(getFileFormat())); - } else { - circleAbsolutePath = null; - } - - final boolean showFields = getData().showPortion(EntityPortion.FIELD, getEntity()); - final boolean showMethods = getData().showPortion(EntityPortion.METHOD, getEntity()); - - // sb.append("<"); - if (showFields == false && showMethods == false) { - sb.append(getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(getEntity(), circleAbsolutePath, 1, true, - BorderMode.NO_BORDER_CELLSPACING_OLD)); - } else { - final String stereo = getEntity().getStereotype() == null ? null : getEntity().getStereotype().getLabel(); - final int longuestHeader = getLonguestHeader(getEntity()); - final int spring = computeSpring(longuestHeader, getLongestFieldOrAttribute(getEntity()), 30); - final int springField = computeSpring(getLongestField(getEntity()), Math.max(longuestHeader, - getLongestMethods(getEntity())), 30); - final int springMethod = computeSpring(getLongestMethods(getEntity()), Math.max(longuestHeader, - getLongestField(getEntity())), 30); - - sb.append(""); - sb.append(""); - - if (showFields) { - sb.append(""); - } - if (showMethods) { - sb.append(""); - } - sb.append("
    "); - - sb.append(getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(getEntity(), circleAbsolutePath, spring, - true, BorderMode.NO_BORDER)); - sb.append("
    "); - if (getEntity().getFieldsToDisplay().size() > 0) { - buildTableVisibility(getEntity(), true, sb, springField); - } - sb.append("
    "); - if (getEntity().getMethodsToDisplay().size() > 0) { - buildTableVisibility(getEntity(), false, sb, springMethod); - } - sb.append("
    "); - } - // sb.append(">"); - } - -} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderHtmlHeaderTableForObjectOrClass.java b/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderHtmlHeaderTableForObjectOrClass.java deleted file mode 100644 index e7258f1c4..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderHtmlHeaderTableForObjectOrClass.java +++ /dev/null @@ -1,132 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6295 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.io.IOException; - -import net.sourceforge.plantuml.ColorParam; -import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.cucadiagram.IEntity; - -class LabelBuilderHtmlHeaderTableForObjectOrClass extends DotCommon implements LabelBuilder { - - private final IEntity entity; - private final String circleAbsolutePath; - private final int spring; - private final BorderMode borderMode; - private final boolean classes; - - LabelBuilderHtmlHeaderTableForObjectOrClass(FileFormat fileFormat, DotData data, IEntity entity, - final String circleAbsolutePath, int spring, boolean classes, BorderMode borderMode) { - super(fileFormat, data); - this.entity = entity; - this.circleAbsolutePath = circleAbsolutePath; - this.classes = classes; - this.borderMode = borderMode; - this.spring = spring; - - } - - public void appendLabel(StringBuilder sb) throws IOException { - if (spring == 0) { - htmlHeaderTableForObjectOrClassOrInterfaceOrEnumNoSpring(sb, 0); - return; - } - - if (borderMode == BorderMode.NO_BORDER) { - sb.append(""); - } else if (borderMode == BorderMode.NO_BORDER_CELLSPACING_OLD) { - sb.append("
    "); - } else if (borderMode == BorderMode.NO_BORDER_CELLSPACING_NEW) { - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - sb.append("
    "); - } else if (borderMode == BorderMode.BORDER_1_WITHOUT_COLOR) { - sb.append("
    "); - } else if (borderMode == BorderMode.BORDER_1_WITH_COLOR) { - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - sb.append("
    "); - } else { - throw new IllegalStateException(); - } - sb.append(""); - - for (int i = 0; i < spring; i++) { - sb.append(""); - } - - if (circleAbsolutePath != null) { - appendImageAsTD(sb, circleAbsolutePath); - } - - sb.append(""); - - for (int i = 0; i < spring; i++) { - sb.append(""); - } - sb.append("
    "); - appendLabelAndStereotype(entity, sb, classes); - sb.append("
    "); - - } - - private void htmlHeaderTableForObjectOrClassOrInterfaceOrEnumNoSpring(StringBuilder sb, int cellSpacing) - throws IOException { - sb.append(""); - sb.append(""); - if (circleAbsolutePath == null) { - sb.append(""); - } else { - addTdImageBugB1983(sb, circleAbsolutePath); - } - sb.append("
    "); - } else { - if (getData().getDpi() == 96) { - sb.append(""); - sb.append(""); - } - - appendLabelAndStereotype(entity, sb, classes); - sb.append("
    "); - - } - -} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderObjectOld.java b/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderObjectOld.java deleted file mode 100644 index b0c059e13..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderObjectOld.java +++ /dev/null @@ -1,80 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6295 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.io.IOException; - -import net.sourceforge.plantuml.ColorParam; -import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.FontParam; -import net.sourceforge.plantuml.cucadiagram.IEntity; -import net.sourceforge.plantuml.cucadiagram.Member; - -class LabelBuilderObjectOld extends LabelBuilderObjectOrClass implements LabelBuilder { - - LabelBuilderObjectOld(FileFormat fileFormat, DotData data, IEntity entity) { - super(fileFormat, data, entity); - } - - public void appendLabel(StringBuilder sb) throws IOException { - final String stereo = getEntity().getStereotype() == null ? null : getEntity().getStereotype().getLabel(); - - sb.append("<"); - sb.append(""); - sb.append(""); - sb.append("
    "); - - final int longuestFieldOrAttribute = getLongestFieldOrAttribute(getEntity()); - final int longuestHeader = getLonguestHeader(getEntity()); - final int spring = computeSpring(longuestHeader, longuestFieldOrAttribute, 30); - - sb.append(getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(getEntity(), null, spring, false, BorderMode.NO_BORDER)); - - sb.append("
    "); - - if (getEntity().getFieldsToDisplay().size() == 0) { - sb.append(manageHtmlIB(" ", FontParam.OBJECT_ATTRIBUTE, stereo)); - } else { - for (Member att : getEntity().getFieldsToDisplay()) { - sb.append(manageHtmlIB(att.getDisplayWithVisibilityChar(), FontParam.OBJECT_ATTRIBUTE, stereo)); - sb.append("
    "); - } - } - - sb.append("
    >"); - - } - -} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderObjectOrClass.java b/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderObjectOrClass.java deleted file mode 100644 index b18c62478..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderObjectOrClass.java +++ /dev/null @@ -1,78 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6295 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.io.IOException; - -import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.cucadiagram.IEntity; - -abstract class LabelBuilderObjectOrClass extends DotCommon implements LabelBuilder { - - private final IEntity entity; - - LabelBuilderObjectOrClass(FileFormat fileFormat, DotData data, IEntity entity) { - super(fileFormat, data); - this.entity = entity; - } - - - protected final void buildTableVisibility(IEntity entity, boolean isField, final StringBuilder sb, int spring) - throws IOException { - final LabelBuilder builder = new LabelBuilderTableVisibility(getFileFormat(), getData(), entity, isField, - spring); - builder.appendLabel(sb); - if (builder.isUnderline()) { - setUnderline(true); - } - } - - protected final String getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(IEntity entity, final String circleAbsolutePath, - int spring, boolean classes, BorderMode border) throws IOException { - final LabelBuilder builder = new LabelBuilderHtmlHeaderTableForObjectOrClass(getFileFormat(), getData(), - entity, circleAbsolutePath, spring, classes, border); - final StringBuilder sb = new StringBuilder(); - builder.appendLabel(sb); - if (builder.isUnderline()) { - setUnderline(true); - } - return sb.toString(); - } - - - protected final IEntity getEntity() { - return entity; - } - -} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderObjectWithVisibilityImage.java b/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderObjectWithVisibilityImage.java deleted file mode 100644 index b0ff5efee..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderObjectWithVisibilityImage.java +++ /dev/null @@ -1,75 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6295 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.io.IOException; - -import net.sourceforge.plantuml.ColorParam; -import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.FontParam; -import net.sourceforge.plantuml.cucadiagram.IEntity; - -class LabelBuilderObjectWithVisibilityImage extends LabelBuilderObjectOrClass implements LabelBuilder { - - LabelBuilderObjectWithVisibilityImage(FileFormat fileFormat, DotData data, IEntity entity) { - super(fileFormat, data, entity); - } - - public void appendLabel(StringBuilder sb) throws IOException { - final int longuestHeader = getLonguestHeader(getEntity()); - final int spring = computeSpring(longuestHeader, getLongestFieldOrAttribute(getEntity()), 30); - final int springField = computeSpring(getLongestField(getEntity()), Math.max(longuestHeader, - getLongestMethods(getEntity())), 30); - - final String stereo = getEntity().getStereotype() == null ? null : getEntity().getStereotype().getLabel(); - - sb.append("<"); - sb.append(""); - sb.append(""); - sb.append("
    "); - - sb.append(getHtmlHeaderTableForObjectOrClassOrInterfaceOrEnum(getEntity(), null, spring, false, BorderMode.NO_BORDER)); - - sb.append("
    "); - - if (getEntity().getFieldsToDisplay().size() == 0) { - sb.append(manageHtmlIB(" ", FontParam.OBJECT_ATTRIBUTE, stereo)); - } else { - buildTableVisibility(getEntity(), true, sb, springField); - } - - sb.append("
    >"); - } -} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderTableLollipopDecorator.java b/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderTableLollipopDecorator.java deleted file mode 100644 index b6592bc43..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderTableLollipopDecorator.java +++ /dev/null @@ -1,127 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6295 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; -import java.util.Collection; - -import javax.imageio.ImageIO; - -import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.cucadiagram.IEntity; - -class LabelBuilderTableLollipopDecorator extends LabelBuilderObjectOrClass implements LabelBuilder { - - private final LabelBuilder builder; - - private final String northPath; - private final String southPath; - private final String eastPath; - private final String westPath; - - LabelBuilderTableLollipopDecorator(FileFormat fileFormat, DotData data, IEntity entity, LabelBuilder builder, - String northPath, String southPath, String eastPath, String westPath, Collection collection) { - super(fileFormat, data, entity); - this.builder = builder; - this.northPath = northPath; - this.southPath = southPath; - this.eastPath = eastPath; - this.westPath = westPath; - - } - - public void appendLabel(StringBuilder sb) throws IOException { - final String backColor = getBackColorAroundEntity(getEntity()); - // backColor="\"#EE0000\""; - sb.append(""); - sb.append(""); - sb.append(""); - appendBlankOrImage(sb, northPath, Orientation.NORTH); - sb.append(""); - sb.append(""); - sb.append(""); - appendBlankOrImage(sb, westPath, Orientation.WEST); - sb.append(""); - appendBlankOrImage(sb, eastPath, Orientation.EAST); - sb.append(""); - sb.append(""); - sb.append(""); - appendBlankOrImage(sb, southPath, Orientation.SOUTH); - sb.append(""); - sb.append(""); - sb.append("
    "); - sb.append(" "); - sb.append(""); - sb.append(" "); - sb.append("
    "); - - builder.appendLabel(sb); - if (builder.isUnderline()) { - setUnderline(true); - } - - sb.append("
    "); - sb.append(" "); - sb.append(""); - sb.append(" "); - sb.append("
    "); - } - - private void appendBlankOrImage(StringBuilder sb, String path, Orientation orientation) throws IOException { - if (path == null) { - sb.append(""); - sb.append(" "); - sb.append(""); - } else if (path.endsWith(".png")) { - if (getData().getDpi() == 96) { - final BufferedImage im = ImageIO.read(new File(path)); - final int height = im.getHeight(); - final int width = im.getWidth(); - // sb.append(""); - sb.append(""); - } else { - addTdImageBugB1983(sb, path); - } - } else if (path.endsWith(".eps")) { - sb.append(""); - } - - } - -} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderTableNineDecorator.java b/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderTableNineDecorator.java deleted file mode 100644 index 8e8bd88e8..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderTableNineDecorator.java +++ /dev/null @@ -1,101 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6295 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.io.IOException; - -import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.cucadiagram.IEntity; - -class LabelBuilderTableNineDecorator extends LabelBuilderObjectOrClass implements LabelBuilder { - - private final LabelBuilder builder; - - LabelBuilderTableNineDecorator(FileFormat fileFormat, DotData data, IEntity entity, LabelBuilder builder) { - super(fileFormat, data, entity); - this.builder = builder; - if (builder instanceof LabelBuilderClassOld) { - ((LabelBuilderClassOld)builder).patch(); - } - - } - - public void appendLabel(StringBuilder sb) throws IOException { - final String backColor = getBackColorAroundEntity(getEntity()); - // backColor="\"#EE0000\""; - sb.append(""); - sb.append(""); - sb.append(""); - sb.append(""); - sb.append(""); - sb.append(""); - sb.append(""); - sb.append(""); - sb.append(""); - sb.append(""); - sb.append(""); - sb.append(""); - sb.append(""); - sb.append(""); - sb.append(""); - sb.append(""); - sb.append("
    "); - sb.append(" "); - sb.append(""); - sb.append(" "); - sb.append(""); - sb.append(" "); - sb.append("
    "); - sb.append(" "); - sb.append(""); - - builder.appendLabel(sb); - if (builder.isUnderline()) { - setUnderline(true); - } - - sb.append(""); - sb.append(" "); - sb.append("
    "); - sb.append(" "); - sb.append(""); - sb.append(" "); - sb.append(""); - sb.append(" "); - sb.append("
    "); - } - - -} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderTableVisibility.java b/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderTableVisibility.java deleted file mode 100644 index b493cd27a..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/LabelBuilderTableVisibility.java +++ /dev/null @@ -1,98 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6295 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.io.IOException; - -import net.sourceforge.plantuml.ColorParam; -import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.FontParam; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.cucadiagram.IEntity; -import net.sourceforge.plantuml.cucadiagram.Member; -import net.sourceforge.plantuml.skin.VisibilityModifier; - -class LabelBuilderTableVisibility extends DotCommon implements LabelBuilder { - - private final IEntity entity; - private final boolean isField; - private final int spring; - - LabelBuilderTableVisibility(FileFormat fileFormat, DotData data, IEntity entity, boolean isField, int spring) { - super(fileFormat, data); - this.entity = entity; - this.isField = isField; - this.spring = spring; - } - - public void appendLabel(StringBuilder sb) throws IOException { - sb.append(""); - - final boolean hasStatic = hasStatic(entity.getMethodsToDisplay()); - final boolean dpiNormal = getData().getDpi() == 96; - for (Member att : isField ? entity.getFieldsToDisplay() : entity.getMethodsToDisplay()) { - sb.append(""); - if (dpiNormal) { - sb.append(""); - } - sb.append(""); - for (int i = 0; i < spring; i++) { - sb.append(""); - } - sb.append(""); - } - sb.append("
    "); - } - String s = att.getDisplayWithVisibilityChar(); - final VisibilityModifier visibilityModifier = VisibilityModifier - .getVisibilityModifier(s.charAt(0), isField); - if (visibilityModifier != null) { - final String stereo = entity.getStereotype() == null ? null : entity.getStereotype().getLabel(); - final String modifierFile = StringUtils.getPlateformDependentAbsolutePath(getData() - .getVisibilityImages(visibilityModifier, stereo).getPngOrEps(getFileFormat())); - if (dpiNormal) { - sb.append(""); - } else { - addTdImageBugB1983(sb, modifierFile); - } - s = s.substring(1); - } - if (dpiNormal) { - sb.append(""); - sb.append(manageHtmlIBspecial(att, FontParam.CLASS_ATTRIBUTE, hasStatic, getColorString( - ColorParam.classBackground, null), false)); - sb.append("
    "); - } - -} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/OS.java b/src/net/sourceforge/plantuml/cucadiagram/dot/OS.java index 65885e7b3..248b712d1 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/OS.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/OS.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/OSLinux.java b/src/net/sourceforge/plantuml/cucadiagram/dot/OSLinux.java index 5979c42e5..e1291e457 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/OSLinux.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/OSLinux.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -39,7 +39,7 @@ class OSLinux extends OS { @Override File getExecutable(GraphvizLayoutStrategy strategy) { - File result = strategy.getSystemForcedExecutable(); + final File result = strategy.getSystemForcedExecutable(); if (result != null) { return result; } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/OSWindows.java b/src/net/sourceforge/plantuml/cucadiagram/dot/OSWindows.java index b6cddcefd..975d11928 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/OSWindows.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/OSWindows.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/PlayField.java b/src/net/sourceforge/plantuml/cucadiagram/dot/PlayField.java deleted file mode 100644 index 41878a4e1..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/PlayField.java +++ /dev/null @@ -1,327 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 4302 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.awt.geom.Dimension2D; -import java.awt.geom.Point2D; -import java.awt.geom.Rectangle2D; -import java.io.IOException; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; -import java.util.Map; - -import net.sourceforge.plantuml.ColorParam; -import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.FontParam; -import net.sourceforge.plantuml.ISkinParam; -import net.sourceforge.plantuml.OptionFlags; -import net.sourceforge.plantuml.StringUtils; -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.LinkType; -import net.sourceforge.plantuml.graphic.FontConfiguration; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; -import net.sourceforge.plantuml.graphic.HtmlColor; -import net.sourceforge.plantuml.graphic.StringBounder; -import net.sourceforge.plantuml.graphic.TextBlock; -import net.sourceforge.plantuml.graphic.TextBlockUtils; -import net.sourceforge.plantuml.posimo.Block; -import net.sourceforge.plantuml.posimo.Cluster; -import net.sourceforge.plantuml.posimo.EntityImageBlock; -import net.sourceforge.plantuml.posimo.EntityImageClass2; -import net.sourceforge.plantuml.posimo.EntityImageNote2; -import net.sourceforge.plantuml.posimo.Frame; -import net.sourceforge.plantuml.posimo.GraphvizSolverB; -import net.sourceforge.plantuml.posimo.IEntityImageBlock; -import net.sourceforge.plantuml.posimo.Label; -import net.sourceforge.plantuml.posimo.LabelImage; -import net.sourceforge.plantuml.posimo.MargedBlock; -import net.sourceforge.plantuml.posimo.Path; -import net.sourceforge.plantuml.posimo.PathDrawerInterface; -import net.sourceforge.plantuml.posimo.PositionableUtils; -import net.sourceforge.plantuml.skin.rose.Rose; -import net.sourceforge.plantuml.ugraphic.UFont; -import net.sourceforge.plantuml.ugraphic.UGraphic; -import net.sourceforge.plantuml.ugraphic.URectangle; - -public final class PlayField { - - private final Rose rose = new Rose(); - private final ISkinParam skinParam; - - private final Cluster root = new Cluster(null, 0, 0); - private final Map paths = new LinkedHashMap(); - - private final Map blocks = new HashMap(); - private final Map clusters = new HashMap(); - private final Map frames = new HashMap(); - - final private double marginLabel = 6; - final private UFont fontQualif; - - public PlayField(ISkinParam skinParam) { - this.skinParam = skinParam; - this.fontQualif = skinParam.getFont(FontParam.CLASS_ARROW, null); - } - - public void initInternal(Collection entities, Collection links, StringBounder stringBounder) { - if (blocks.size() != 0 || paths.size() != 0 /* || images.size() != 0 */ - || clusters.size() != 0) { - throw new IllegalStateException(); - } - if (entities.size() != new HashSet(entities).size()) { - throw new IllegalArgumentException("Duplicate entities"); - } - if (links.size() != new HashSet(links).size()) { - throw new IllegalArgumentException("Duplicate entities"); - } - - for (IEntity ent : entities) { - if (ent.getType() == EntityType.GROUP && ent.getParent().isAutonom() == false) { - // final IEntityImageBlock title = createClusterTitle(); - // final Frame frame = new Frame(StringUtils.getWithNewlines(ent.getDisplay()), Color.BLACK, skinParam - // .getFont(FontParam.CLASS), rose.getHtmlColor(skinParam, ColorParam.classBorder).getColor()); - final Frame frame = new Frame(ent.getDisplay2(), skinParam); - frames.put(ent, frame); - // final Dimension2D dimTitle = - // title.getDimension(stringBounder); - final Dimension2D dimTitle = frame.getTextDim(stringBounder); - clusters.put(ent, new Cluster(root, dimTitle.getWidth(), dimTitle.getHeight())); - } - } - - for (IEntity ent : entities) { - // System.err.println("ENT=" + ent); - if (ent.getType() == EntityType.GROUP && ent.getParent().isAutonom() == false) { - assert clusters.containsKey(ent); - continue; - } - assert clusters.containsKey(ent) == false; - Cluster parentCluster = root; - if (ent.getType() != EntityType.GROUP && ent.getParent() != null) { - parentCluster = clusters.get(ent.getParent().getEntityCluster()); - if (parentCluster == null) { - parentCluster = root; - } - } - final IEntityImageBlock entityImageBlock = createEntityImageBlock(links, ent); - // final Dimension2D d = - // entityImageBlock.getDimension(stringBounder); - // final Block b = new Block(uid++, d.getWidth() + 2 * - // marginDecorator, d.getHeight() + 2 * marginDecorator); - final MargedBlock b = new MargedBlock(stringBounder, entityImageBlock, - getMargin(stringBounder, ent, links), parentCluster); - - blocks.put(ent, b); - // images.put(ent, entityImageBlock); - parentCluster.addBloc(b.getBlock()); - } - - for (Cluster cl : clusters.values()) { - if (cl.getContents().size() == 0) { - throw new IllegalStateException(); - } - } - - for (Link link : links) { - // System.err.println("LINK=" + link); - if (entities.contains(link.getEntity1()) && entities.contains(link.getEntity2())) { - final Block b1 = getToto(link.getEntity1()); - final Block b2 = getToto(link.getEntity2()); - final Label label; - if (link.getLabel() == null) { - label = null; - } else { - final LabelImage labelImage = new LabelImage(link, rose, skinParam); - final Dimension2D dim = Dimension2DDouble - .delta(labelImage.getDimension(stringBounder), marginLabel); - label = new Label(dim.getWidth(), dim.getHeight()); - } - final Path p = new Path(b1, b2, label, link.getLength()); - paths.put(p, link); - } - } - } - - private double getMargin(StringBounder stringBounder, IEntity ent, Collection links) { - double result = 0; - for (Link link : links) { - if (link.getEntity2() == ent) { - // final LinkDecor decor = link.getType().getDecor1(); - result = Math.max(result, link.getMarginDecors2(stringBounder, fontQualif)); - } - if (link.getEntity1() == ent) { - // final LinkDecor decor = link.getType().getDecor2(); - result = Math.max(result, link.getMarginDecors1(stringBounder, fontQualif)); - } - - } - return result; - // return 40; - } - - private Block getToto(IEntity ent) { - final MargedBlock result = blocks.get(ent); - if (result != null) { - return result.getBlock(); - } - if (clusters.containsKey(ent) == false) { - throw new IllegalArgumentException(); - } - return blocks.get(getOneOf(ent.getParent())).getBlock(); - } - - private IEntity getOneOf(Group gr) { - assert gr != null; - return gr.entities().values().iterator().next(); - } - - public void drawInternal(UGraphic ug) { - - for (Map.Entry ent : clusters.entrySet()) { - final Frame frame = frames.get(ent.getKey()); - final Rectangle2D rect = PositionableUtils.convert(ent.getValue()); - final double oldX = ug.getTranslateX(); - final double oldY = ug.getTranslateY(); - ug.translate(rect.getX(), rect.getY()); - frame.drawU(ug, new Dimension2DDouble(rect.getWidth(), rect.getHeight()), null); - ug.setTranslate(oldX, oldY); - } - - for (Map.Entry ent : paths.entrySet()) { - final LinkType type = ent.getValue().getType(); - final PathDrawerInterface pathDrawer = PathDrawerInterface.create(skinParam, type); - final Path p = ent.getKey(); - ug.getParam().setColor(rose.getHtmlColor(skinParam, ColorParam.classBorder)); - // pathDrawer.drawPathBefore(ug, PositionableUtils.addMargin(p - // .getStart(), -marginDecorator, -marginDecorator), - // PositionableUtils.addMargin(p.getEnd(), -marginDecorator, - // -marginDecorator), p); - if (p.getLabel() != null) { - ug.getParam().setColor(HtmlColor.BLACK); - drawLabel(ug, p); - } - } - - for (Map.Entry ent : blocks.entrySet()) { - final MargedBlock b = ent.getValue(); - final Point2D pos = b.getImagePosition().getPosition(); - b.getImageBlock().drawU(ug, pos.getX(), pos.getY(), 0, 0); - } - - for (Map.Entry ent : paths.entrySet()) { - final Link link = ent.getValue(); - final LinkType type = link.getType(); - final PathDrawerInterface pathDrawer = PathDrawerInterface.create(skinParam, type); - final Path p = ent.getKey(); - ug.getParam().setColor(rose.getHtmlColor(skinParam, ColorParam.classBorder)); - // pathDrawer.drawPathAfter(ug, PositionableUtils.addMargin(p - // .getStart(), -marginDecorator, -marginDecorator), - // PositionableUtils.addMargin(p.getEnd(), -marginDecorator, - // -marginDecorator), p); - pathDrawer.drawPathAfter(ug, getMargedBlock(p.getStart()).getImagePosition(), getMargedBlock(p.getEnd()) - .getImagePosition(), p); - - final String qual1 = link.getQualifier1(); - if (qual1 != null) { - final TextBlock b = TextBlockUtils.create(Arrays.asList(qual1), new FontConfiguration(fontQualif, - skinParam.getFontHtmlColor(FontParam.CLASS_ARROW, null)), HorizontalAlignement.LEFT); - final Point2D pos = p.getDotPath().getStartPoint(); - b.drawU(ug, pos.getX(), pos.getY()); - } - - final String qual2 = link.getQualifier2(); - if (qual2 != null) { - final TextBlock b = TextBlockUtils.create(Arrays.asList(qual2), new FontConfiguration(fontQualif, - skinParam.getFontHtmlColor(FontParam.CLASS_ARROW, null)), HorizontalAlignement.LEFT); - final Point2D pos = p.getDotPath().getEndPoint(); - b.drawU(ug, pos.getX(), pos.getY()); - } - - } - } - - private MargedBlock getMargedBlock(Block b) { - for (MargedBlock margedBlock : blocks.values()) { - if (margedBlock.getBlock() == b) { - return margedBlock; - } - } - throw new IllegalArgumentException(); - } - - public Dimension2D solve() throws IOException, InterruptedException { - final GraphvizSolverB solver = new GraphvizSolverB(); - // System.err.println("sub=" + root.getSubClusters()); - final Dimension2D dim = Dimension2DDouble.delta(solver.solve(root, paths.keySet()), 20); - return dim; - } - - private void drawLabel(UGraphic ug, Path p) { - final Label label = p.getLabel(); - final Point2D pos = label.getPosition(); - if (OptionFlags.getInstance().isDebugDot()) { - ug.getParam().setColor(HtmlColor.GREEN); - ug.getParam().setBackcolor(null); - final Dimension2D dim = label.getSize(); - ug.draw(pos.getX(), pos.getY(), new URectangle(dim.getWidth(), dim.getHeight())); - final LabelImage labelImage = new LabelImage(paths.get(p), rose, skinParam); - final Dimension2D dimImage = labelImage.getDimension(ug.getStringBounder()); - ug.draw(pos.getX(), pos.getY(), new URectangle(dimImage.getWidth(), dimImage.getHeight())); - } - final LabelImage labelImage = new LabelImage(paths.get(p), rose, skinParam); - labelImage.drawU(ug, pos.getX(), pos.getY()); - } - - private IEntityImageBlock createEntityImageBlock(Collection links, IEntity ent) { - if (ent.getType() == EntityType.CLASS || ent.getType() == EntityType.ABSTRACT_CLASS - || ent.getType() == EntityType.INTERFACE || ent.getType() == EntityType.ENUM) { - return new EntityImageClass2(ent, skinParam, links); - } - if (ent.getType() == EntityType.NOTE) { - return new EntityImageNote2(ent, skinParam, links); - } - return new EntityImageBlock(ent, rose, skinParam, links, FontParam.PACKAGE); - } - - private IEntityImageBlock createClusterTitle() { - return null; - } - -} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/ProcessRunner.java b/src/net/sourceforge/plantuml/cucadiagram/dot/ProcessRunner.java index d015956f2..c2d3832be 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/ProcessRunner.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/ProcessRunner.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6107 $ + * Revision $Revision: 10765 $ * */ package net.sourceforge.plantuml.cucadiagram.dot; @@ -37,74 +37,217 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; - -import net.sourceforge.plantuml.Log; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; public class ProcessRunner { + // http://steveliles.github.io/invoking_processes_from_java.html - private final String cmd; + private static final long TIMEOUT_MINUTE = 15; + + private final String[] cmd; private String error; private String out; - public ProcessRunner(String cmd) { + private volatile ProcessState state = ProcessState.INIT; + private final Lock changeState = new ReentrantLock(); + + public ProcessRunner(String[] cmd) { this.cmd = cmd; } - static private int cpt = 0; - - public void run(byte in[], OutputStream redirection) throws IOException, InterruptedException { - run(in, redirection, null); + public ProcessState run2(byte in[], OutputStream redirection) { + return run2(in, redirection, null); } - public void run(byte in[], OutputStream redirection, File dir) throws IOException, InterruptedException { - final Process process = Runtime.getRuntime().exec(cmd, null, dir); - final ThreadStream errorStream = new ThreadStream(process.getErrorStream(), null); - final ThreadStream outStream = new ThreadStream(process.getInputStream(), redirection); - errorStream.start(); - outStream.start(); - if (in != null) { - final OutputStream os = process.getOutputStream(); - os.write(in); - os.close(); + public ProcessState run2(byte in[], OutputStream redirection, File dir) { + if (this.state != ProcessState.INIT) { + throw new IllegalStateException(); } - process.waitFor(); - errorStream.join(10000L); - outStream.join(10000L); - this.out = outStream.sb.toString(); - this.error = errorStream.sb.toString(); - Log.info("RUN nb = " + (++cpt)); + this.state = ProcessState.RUNNING; + final MainThread mainThread = new MainThread(cmd, dir, redirection, in); + try { + mainThread.start(); + mainThread.join(TIMEOUT_MINUTE * 60 * 1000L); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + changeState.lock(); + try { + if (state == ProcessState.RUNNING) { + state = ProcessState.TIMEOUT; + mainThread.cancel(); + } + } finally { + changeState.unlock(); + } + } + if (state == ProcessState.TERMINATED_OK) { + assert mainThread != null; + this.error = mainThread.getError(); + this.out = mainThread.getOut(); + } + return state; } - static class ThreadStream extends Thread { + class MainThread extends Thread { - private final InputStream streamToRead; + private final String[] cmd; + private final File dir; private final OutputStream redirection; - private final StringBuilder sb = new StringBuilder(); + private final byte[] in; + private volatile Process process; + private volatile ThreadStream errorStream; + private volatile ThreadStream outStream; + + public MainThread(String[] cmd, File dir, OutputStream redirection, byte[] in) { + this.cmd = cmd; + this.dir = dir; + this.redirection = redirection; + this.in = in; + } + + public String getOut() { + return outStream.getString(); + } + + public String getError() { + return errorStream.getString(); + } + + @Override + public void run() { + try { + runInternal(); + if (state == ProcessState.RUNNING) { + final int result = joinInternal(); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + changeState.lock(); + try { + if (state == ProcessState.RUNNING) { + state = ProcessState.TERMINATED_OK; + } + } finally { + changeState.unlock(); + } + if (process != null) { + process.destroy(); + close(process.getErrorStream()); + close(process.getOutputStream()); + close(process.getInputStream()); + } + } + + } + + private void cancel() { + // The changeState lock is ok + assert changeState.tryLock(); + assert state == ProcessState.TIMEOUT; + if (process != null) { + errorStream.cancel(); + outStream.cancel(); + process.destroy(); + interrupt(); + close(process.getErrorStream()); + close(process.getOutputStream()); + close(process.getInputStream()); + } + } + + public void runInternal() { + try { + process = Runtime.getRuntime().exec(cmd, null, dir); + } catch (IOException e) { + changeState.lock(); + try { + state = ProcessState.IO_EXCEPTION1; + } finally { + changeState.unlock(); + } + e.printStackTrace(); + return; + } + errorStream = new ThreadStream(process.getErrorStream(), null); + outStream = new ThreadStream(process.getInputStream(), redirection); + errorStream.start(); + outStream.start(); + if (in != null) { + final OutputStream os = process.getOutputStream(); + try { + try { + os.write(in); + } finally { + os.close(); + } + } catch (IOException e) { + changeState.lock(); + try { + state = ProcessState.IO_EXCEPTION2; + } finally { + changeState.unlock(); + } + e.printStackTrace(); + } + } + } + + public int joinInternal() throws InterruptedException { + errorStream.join(); + outStream.join(); + final int result = process.waitFor(); + return result; + } + + } + + class ThreadStream extends Thread { + + private volatile InputStream streamToRead; + private volatile OutputStream redirection; + private volatile StringBuffer sb = new StringBuffer(); ThreadStream(InputStream streamToRead, OutputStream redirection) { this.streamToRead = streamToRead; this.redirection = redirection; } + public String getString() { + return sb.toString(); + } + + public void cancel() { + assert state == ProcessState.TIMEOUT; + this.interrupt(); + sb = null; + streamToRead = null; + redirection = null; + // Because of this, some NPE may occurs in run() method, but we do not care + } + @Override public void run() { - Log.debug("STARTING " + this); int read = 0; try { while ((read = streamToRead.read()) != -1) { + if (state == ProcessState.TIMEOUT) { + return; + } if (redirection == null) { sb.append((char) read); } else { redirection.write(read); } } - } catch (IOException e) { + } catch (Throwable e) { e.printStackTrace(); sb.append('\n'); sb.append(e.toString()); } - Log.debug("FINISHING " + this); } } @@ -116,4 +259,24 @@ public class ProcessRunner { return out; } + private void close(InputStream is) { + try { + if (is != null) { + is.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + private void close(OutputStream os) { + try { + if (os != null) { + os.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/ProcessRunnerDebug.java b/src/net/sourceforge/plantuml/cucadiagram/dot/ProcessRunnerDebug.java new file mode 100644 index 000000000..80f0d1afd --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/ProcessRunnerDebug.java @@ -0,0 +1,374 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 10765 $ + * + */ +package net.sourceforge.plantuml.cucadiagram.dot; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.Date; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; + +public class ProcessRunnerDebug { + // http://steveliles.github.io/invoking_processes_from_java.html + + public static boolean DEBUG = false; + private static final AtomicInteger CPT = new AtomicInteger(); + + private void DEBUG(String s) { + if (DEBUG == false) { + return; + } + final StringBuilder sb = new StringBuilder(); + final int activeCount = Thread.activeCount(); + final long freeMemory = Runtime.getRuntime().freeMemory() / 1024L / 1024L; + final long totalMemory = Runtime.getRuntime().totalMemory() / 1024L / 1024L; + sb.append(new Date().toGMTString() + " {"); + sb.append(ident + "} " + freeMemory + "/" + totalMemory + "/" + activeCount + " " + s); + DebugTrace.DEBUG(sb.toString()); + } + + private void DEBUG(String s, Throwable t) { + if (DEBUG == false) { + return; + } + DebugTrace.DEBUG(s, t); + } + + private static final long TIMEOUT_MINUTE = 15; + + private final String[] cmd; + private final String ident = myFormat(CPT.getAndIncrement()); + + private static String myFormat(int v) { + final StringBuilder sb = new StringBuilder(Integer.toHexString(v).toUpperCase()); + while (sb.length() < 5) { + sb.insert(0, '0'); + } + return sb.toString(); + } + + private String error; + private String out; + + private volatile ProcessState state = ProcessState.INIT; + private final Lock changeState = new ReentrantLock(); + + public ProcessRunnerDebug(String[] cmd) { + this.cmd = cmd; + } + + public ProcessState run2(byte in[], OutputStream redirection) { + return run2(in, redirection, null); + } + + public ProcessState run2(byte in[], OutputStream redirection, File dir) { + if (this.state != ProcessState.INIT) { + throw new IllegalStateException(); + } + this.state = ProcessState.RUNNING; + DEBUG("run A100"); + final MainThread mainThread = new MainThread(cmd, dir, redirection, in); + DEBUG("run A200"); + try { + mainThread.start(); + DEBUG("run A300"); + mainThread.join(TIMEOUT_MINUTE * 60 * 1000L); + DEBUG("run A400"); + } catch (InterruptedException e) { + e.printStackTrace(); + DEBUG("run A500", e); + } finally { + DEBUG("run A600"); + changeState.lock(); + DEBUG("run A700"); + try { + if (state == ProcessState.RUNNING) { + state = ProcessState.TIMEOUT; + DEBUG("run A800"); + mainThread.cancel(); + DEBUG("run A900"); + } + } finally { + changeState.unlock(); + } + } + if (state == ProcessState.TERMINATED_OK) { + DEBUG("run A1000"); + // Ok! + assert mainThread != null; + this.error = mainThread.getError(); + this.out = mainThread.getOut(); + } else { + DEBUG("run A1100"); + } + return state; + } + + class MainThread extends Thread { + + private final String[] cmd; + private final File dir; + private final OutputStream redirection; + private final byte[] in; + private volatile Process process; + private volatile ThreadStream errorStream; + private volatile ThreadStream outStream; + + public MainThread(String[] cmd, File dir, OutputStream redirection, byte[] in) { + this.cmd = cmd; + this.dir = dir; + this.redirection = redirection; + this.in = in; + } + + public String getOut() { + return outStream.getString(); + } + + public String getError() { + return errorStream.getString(); + } + + @Override + public void run() { + try { + DEBUG("MainThread B100"); + runInternal(); + DEBUG("MainThread B200"); + if (state == ProcessState.RUNNING) { + final int result = joinInternal(); + DEBUG("MainThread B300 " + result); + } + } catch (InterruptedException e) { + e.printStackTrace(); + DEBUG("MainThread B400", e); + } finally { + changeState.lock(); + try { + if (state == ProcessState.RUNNING) { + DEBUG("MainThread B500"); + state = ProcessState.TERMINATED_OK; + } else { + DEBUG("MainThread B600"); + } + } finally { + changeState.unlock(); + } + if (process != null) { + DEBUG("MainThread B700"); + process.destroy(); + DEBUG("MainThread B800"); + close(process.getErrorStream()); + DEBUG("MainThread B900"); + close(process.getOutputStream()); + DEBUG("MainThread B1000"); + close(process.getInputStream()); + } + } + + } + + private void cancel() { + // The changeState lock is ok + assert changeState.tryLock(); + assert state == ProcessState.TIMEOUT; + DEBUG("MainThread B2000"); + if (process != null) { + DEBUG("MainThread B2000"); + errorStream.cancel(); + DEBUG("MainThread B2000"); + outStream.cancel(); + DEBUG("MainThread B2000"); + process.destroy(); + DEBUG("MainThread B2000"); + interrupt(); + DEBUG("MainThread B2000"); + close(process.getErrorStream()); + DEBUG("MainThread B2000"); + close(process.getOutputStream()); + DEBUG("MainThread B2000"); + close(process.getInputStream()); + DEBUG("MainThread B2000"); + } else { + DEBUG("MainThread B2000"); + } + } + + public void runInternal() { + try { + DEBUG("MainThread runInternal B3010"); + process = Runtime.getRuntime().exec(cmd, null, dir); + DEBUG("MainThread runInternal B3020"); + } catch (IOException e) { + DEBUG("MainThread runInternal B3030", e); + changeState.lock(); + try { + state = ProcessState.IO_EXCEPTION1; + } finally { + changeState.unlock(); + } + e.printStackTrace(); + return; + } + DEBUG("MainThread runInternal B3040"); + errorStream = new ThreadStream(process.getErrorStream(), null); + DEBUG("MainThread runInternal B3050"); + outStream = new ThreadStream(process.getInputStream(), redirection); + DEBUG("MainThread runInternal B3060"); + errorStream.start(); + DEBUG("MainThread runInternal B3070"); + outStream.start(); + if (in != null) { + DEBUG("MainThread runInternal B3080"); + final OutputStream os = process.getOutputStream(); + DEBUG("MainThread runInternal B3090"); + try { + try { + DEBUG("MainThread runInternal B3100"); + os.write(in); + DEBUG("MainThread runInternal B3110"); + } finally { + os.close(); + } + } catch (IOException e) { + DEBUG("MainThread runInternal B3120", e); + changeState.lock(); + try { + state = ProcessState.IO_EXCEPTION2; + } finally { + changeState.unlock(); + } + e.printStackTrace(); + } + } + } + + public int joinInternal() throws InterruptedException { + DEBUG("MainThread joinInternal B4000"); + errorStream.join(); + DEBUG("MainThread joinInternal B4010"); + outStream.join(); + DEBUG("MainThread joinInternal B4020"); + final int result = process.waitFor(); + DEBUG("MainThread joinInternal B4030 r=" + result); + return result; + } + + } + + class ThreadStream extends Thread { + + private volatile InputStream streamToRead; + private volatile OutputStream redirection; + private volatile StringBuffer sb = new StringBuffer(); + + ThreadStream(InputStream streamToRead, OutputStream redirection) { + this.streamToRead = streamToRead; + this.redirection = redirection; + } + + public String getString() { + return sb.toString(); + } + + public void cancel() { + assert state == ProcessState.TIMEOUT; + this.interrupt(); + sb = null; + streamToRead = null; + redirection = null; + // Because of this, some NPE may occurs in run() method, but we do not care + } + + @Override + public void run() { + int read = 0; + try { + while ((read = streamToRead.read()) != -1) { + if (state == ProcessState.TIMEOUT) { + DEBUG("ThreadStream TIMEOUT"); + return; + } + if (redirection == null) { + sb.append((char) read); + } else { + redirection.write(read); + } + } + DEBUG("ThreadStream end ok"); + } catch (Throwable e) { + DEBUG("ThreadStream BB1", e); + e.printStackTrace(); + sb.append('\n'); + sb.append(e.toString()); + } + } + } + + public final String getError() { + return error; + } + + public final String getOut() { + return out; + } + + private void close(InputStream is) { + try { + if (is != null) { + is.close(); + DEBUG("closing AA1 ok"); + } + } catch (IOException e) { + DEBUG("closing error AA2", e); + e.printStackTrace(); + } + } + + private void close(OutputStream os) { + try { + if (os != null) { + os.close(); + DEBUG("closing BB1 ok"); + } + } catch (IOException e) { + DEBUG("closing error BB1", e); + e.printStackTrace(); + } + } + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/ProcessRunnerOld.java b/src/net/sourceforge/plantuml/cucadiagram/dot/ProcessRunnerOld.java new file mode 100644 index 000000000..6b2b9ce06 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/ProcessRunnerOld.java @@ -0,0 +1,120 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 10765 $ + * + */ +package net.sourceforge.plantuml.cucadiagram.dot; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import net.sourceforge.plantuml.Log; + +public class ProcessRunnerOld { + + private final String[] cmd; + + private String error; + private String out; + + public ProcessRunnerOld(String[] cmd) { + this.cmd = cmd; + } + + static private int cpt = 0; + + public void run(byte in[], OutputStream redirection) throws IOException, InterruptedException { + run(in, redirection, null); + } + + public void run(byte in[], OutputStream redirection, File dir) throws IOException, InterruptedException { + final Process process = Runtime.getRuntime().exec(cmd, null, dir); + final ThreadStream errorStream = new ThreadStream(process.getErrorStream(), null); + final ThreadStream outStream = new ThreadStream(process.getInputStream(), redirection); + errorStream.start(); + outStream.start(); + if (in != null) { + final OutputStream os = process.getOutputStream(); + os.write(in); + os.close(); + } + process.waitFor(); + errorStream.join(10000L); + outStream.join(10000L); + this.out = outStream.sb.toString(); + this.error = errorStream.sb.toString(); + cpt++; + Log.info("RUN nb = " + cpt); + } + + static class ThreadStream extends Thread { + + private final InputStream streamToRead; + private final OutputStream redirection; + private final StringBuilder sb = new StringBuilder(); + + ThreadStream(InputStream streamToRead, OutputStream redirection) { + this.streamToRead = streamToRead; + this.redirection = redirection; + } + + @Override + public void run() { + Log.debug("STARTING " + this); + int read = 0; + try { + while ((read = streamToRead.read()) != -1) { + if (redirection == null) { + sb.append((char) read); + } else { + redirection.write(read); + } + } + } catch (IOException e) { + e.printStackTrace(); + sb.append('\n'); + sb.append(e.toString()); + } + Log.debug("FINISHING " + this); + } + } + + public final String getError() { + return error; + } + + public final String getOut() { + return out; + } + +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/BorderMode.java b/src/net/sourceforge/plantuml/cucadiagram/dot/ProcessState.java similarity index 80% rename from src/net/sourceforge/plantuml/cucadiagram/dot/BorderMode.java rename to src/net/sourceforge/plantuml/cucadiagram/dot/ProcessState.java index 01faf183f..5b8e6217a 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/BorderMode.java +++ b/src/net/sourceforge/plantuml/cucadiagram/dot/ProcessState.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,18 +28,11 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6295 $ + * Revision $Revision: 10765 $ * */ package net.sourceforge.plantuml.cucadiagram.dot; - -enum BorderMode { - - NO_BORDER, - NO_BORDER_CELLSPACING_OLD, - NO_BORDER_CELLSPACING_NEW, - BORDER_1_WITH_COLOR, - BORDER_1_WITHOUT_COLOR; - +public enum ProcessState { + INIT, RUNNING, TERMINATED_OK, TIMEOUT, IO_EXCEPTION1, IO_EXCEPTION2; } diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/StaticFiles.java b/src/net/sourceforge/plantuml/cucadiagram/dot/StaticFiles.java deleted file mode 100644 index 29d75683d..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/StaticFiles.java +++ /dev/null @@ -1,246 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6590 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.awt.Graphics2D; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; -import java.util.Arrays; -import java.util.EnumMap; -import java.util.EnumSet; -import java.util.Map; - -import javax.imageio.ImageIO; - -import net.sourceforge.plantuml.ColorParam; -import net.sourceforge.plantuml.EmptyImageBuilder; -import net.sourceforge.plantuml.FileUtils; -import net.sourceforge.plantuml.FontParam; -import net.sourceforge.plantuml.ISkinParam; -import net.sourceforge.plantuml.cucadiagram.EntityType; -import net.sourceforge.plantuml.graphic.CircledCharacter; -import net.sourceforge.plantuml.graphic.HtmlColor; -import net.sourceforge.plantuml.skin.CircleInterface; -import net.sourceforge.plantuml.skin.UDrawable; -import net.sourceforge.plantuml.skin.VisibilityModifier; -import net.sourceforge.plantuml.skin.rose.Rose; -import net.sourceforge.plantuml.ugraphic.ColorMapper; -import net.sourceforge.plantuml.ugraphic.UFont; -import net.sourceforge.plantuml.ugraphic.eps.UGraphicEps; -import net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d; - -public class StaticFiles { - - private final HtmlColor interfaceBorder; - private final HtmlColor classborder; - private final HtmlColor classBackground; - private final HtmlColor interfaceBackground; - private final HtmlColor background; - - final private UFont circledFont; - final private double radius; - - private final Map staticImages = new EnumMap(EntityType.class); - private final Map visibilityImages = new EnumMap( - VisibilityModifier.class); - - private final Map foregroundColor = new EnumMap( - VisibilityModifier.class); - private final Map backgroundColor = new EnumMap( - VisibilityModifier.class); - - private final double dpiFactor; - private final ColorMapper colorMapper; - - public StaticFiles(ISkinParam param, String stereotype, double dpiFactor) throws IOException { - this.colorMapper = param.getColorMapper(); - final Rose rose = new Rose(); - this.dpiFactor = dpiFactor; - - radius = param.getCircledCharacterRadius(); - circledFont = param.getFont(FontParam.CIRCLED_CHARACTER, stereotype); - - classborder = rose.getHtmlColor(param, ColorParam.classBorder, stereotype); - interfaceBorder = rose.getHtmlColor(param, ColorParam.componentInterfaceBorder, stereotype); - interfaceBackground = rose.getHtmlColor(param, ColorParam.componentInterfaceBackground, stereotype); - classBackground = rose.getHtmlColor(param, ColorParam.classBackground, stereotype); - final HtmlColor stereotypeCBackground = rose.getHtmlColor(param, ColorParam.stereotypeCBackground, stereotype); - final HtmlColor stereotypeABackground = rose.getHtmlColor(param, ColorParam.stereotypeABackground, stereotype); - final HtmlColor stereotypeIBackground = rose.getHtmlColor(param, ColorParam.stereotypeIBackground, stereotype); - final HtmlColor stereotypeEBackground = rose.getHtmlColor(param, ColorParam.stereotypeEBackground, stereotype); - - background = param.getBackgroundColor(); - - final File dir = FileUtils.getTmpDir(); - staticImages.put(EntityType.LOLLIPOP, getLollipop()); - staticImages.put(EntityType.ABSTRACT_CLASS, getCircledCharacter('A', stereotypeABackground)); - staticImages.put(EntityType.CLASS, getCircledCharacter('C', stereotypeCBackground)); - staticImages.put(EntityType.INTERFACE, getCircledCharacter('I', stereotypeIBackground)); - staticImages.put(EntityType.ENUM, getCircledCharacter('E', stereotypeEBackground)); - - if (param.classAttributeIconSize() > 0) { - for (VisibilityModifier modifier : EnumSet.allOf(VisibilityModifier.class)) { - - final HtmlColor back = modifier.getBackground() == null ? null : rose.getHtmlColor(param, - modifier.getBackground(), stereotype); - final HtmlColor fore = rose.getHtmlColor(param, modifier.getForeground(), stereotype); - - backgroundColor.put(modifier, back); - foregroundColor.put(modifier, fore); - visibilityImages.put(modifier, - getVisibilityModifier(modifier, dir, param.classAttributeIconSize(), dpiFactor)); - } - } - } - - private DrawFile getLollipop() throws IOException { - - final CircleInterface circleInterface = new CircleInterface(interfaceBackground, interfaceBorder, 10, 2); - - final Lazy lpng = new Lazy() { - - public File getNow() throws IOException { - final EmptyImageBuilder builder = new EmptyImageBuilder(circleInterface.getPreferredWidth(null), - circleInterface.getPreferredHeight(null), colorMapper.getMappedColor(background)); - - final BufferedImage im = builder.getBufferedImage(); - final Graphics2D g2d = builder.getGraphics2D(); - - circleInterface.drawU(new UGraphicG2d(colorMapper, g2d, null, dpiFactor)); - - final File result = FileUtils.createTempFile("lollipop", ".png"); - ImageIO.write(im, "png", result); - return result; - } - }; - - final Lazy leps = new Lazy() { - public File getNow() throws IOException { - final File epsFile = FileUtils.createTempFile("lollipop", ".eps"); - UGraphicEps.copyEpsToFile(colorMapper, circleInterface, epsFile); - return epsFile; - } - }; - - final Lazy lsvg = new Lazy() { - public String getNow() throws IOException { - return UGraphicG2d.getSvgString(colorMapper, circleInterface); - } - }; - - final Object signature = Arrays.asList("lollipop", interfaceBackground, interfaceBorder, background); - - return DrawFile.create(lpng, lsvg, leps, signature); - - } - - private DrawFile getCircledCharacter(char c, HtmlColor background) throws IOException { - final CircledCharacter circledCharacter = new CircledCharacter(c, radius, circledFont, background, classborder, - HtmlColor.BLACK); - return circledCharacter.generateCircleCharacter(colorMapper, classBackground, dpiFactor); - } - - public DrawFile getStaticImages(EntityType type) { - return staticImages.get(type); - } - - public final DrawFile getVisibilityImages(VisibilityModifier visibilityModifier) { - return visibilityImages.get(visibilityModifier); - } - - public DrawFile getDrawFile(String pngPath) throws IOException { - final File searched = new File(pngPath).getCanonicalFile(); - for (DrawFile drawFile : staticImages.values()) { - final File png = drawFile.getPng().getCanonicalFile(); - if (png.equals(searched)) { - return drawFile; - } - } - for (DrawFile drawFile : visibilityImages.values()) { - final File png = drawFile.getPng().getCanonicalFile(); - if (png.equals(searched)) { - return drawFile; - } - } - return null; - } - - private DrawFile getVisibilityModifier(final VisibilityModifier modifier, final File dir, final int size, - final double dpiFactor) throws IOException { - final UDrawable drawable = modifier.getUDrawable(size, foregroundColor.get(modifier), - backgroundColor.get(modifier)); - - final Lazy lpng = new Lazy() { - public File getNow() throws IOException { - final File png = FileUtils.createTempFile("visi", ".png"); - final EmptyImageBuilder builder = new EmptyImageBuilder(size * dpiFactor, size * dpiFactor, - colorMapper.getMappedColor(classBackground)); - final BufferedImage im = builder.getBufferedImage(); - drawable.drawU(new UGraphicG2d(colorMapper, builder.getGraphics2D(), im, dpiFactor)); - ImageIO.write(im, "png", png); - return png; - } - }; - - final Lazy leps = new Lazy() { - public File getNow() throws IOException { - final File eps = FileUtils.createTempFile("visi", ".eps"); - UGraphicEps.copyEpsToFile(colorMapper, drawable, eps); - return eps; - } - }; - - final Lazy lsvg = new Lazy() { - public String getNow() throws IOException { - return UGraphicG2d.getSvgString(colorMapper, drawable); - } - }; - - final Object signature = Arrays.asList("visi", modifier, foregroundColor.get(modifier), - backgroundColor.get(modifier), size, classBackground); - - return DrawFile.create(lpng, lsvg, leps, signature); - } - - public void clean() { - for (DrawFile f : staticImages.values()) { - f.deleteDrawFile(); - } - for (DrawFile f : visibilityImages.values()) { - f.deleteDrawFile(); - } - } - -} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/UnderlineTrick.java b/src/net/sourceforge/plantuml/cucadiagram/dot/UnderlineTrick.java deleted file mode 100644 index 06fd868b6..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/UnderlineTrick.java +++ /dev/null @@ -1,134 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 3829 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.awt.Color; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; - -import javax.imageio.ImageIO; - -public class UnderlineTrick { - - static class Segment { - final private int start; - final private int end; - - Segment(int start, int end) { - this.start = start; - this.end = end; - } - - @Override - public String toString() { - return "" + start + "-" + end; - } - } - - public static void main(String[] args) throws IOException { - if (args.length == 0) { - System.err.println("Usage: fileName searchedColor underlineColor"); - System.exit(0); - } - final File f = new File(args[0]); - final BufferedImage im = ImageIO.read(f); - final Color searchedColor = new Color(Integer.parseInt(args[1], 16)); - final Color underlineColor = new Color(Integer.parseInt(args[2], 16)); - new UnderlineTrick(im, searchedColor, underlineColor).process(); - ImageIO.write(im, "png", f); - - } - - private final BufferedImage im; - private final int searchedColor; - private final int underlineColor; - - public UnderlineTrick(BufferedImage im, Color searchedColor, Color underlineColor) { - this.im = im; - this.searchedColor = searchedColor.getRGB(); - this.underlineColor = underlineColor.getRGB(); - } - - public void process() { - for (int line = 0; line < im.getHeight(); line++) { - int x = 0; - while (x < im.getWidth()) { - final Segment segStart = searchSegment(x, line); - if (segStart == null) { - break; - } - final Segment segEnd = searchSegment(segStart.end + 1, line); - if (segEnd == null) { - break; - } - drawLine(segStart.end, segEnd.start, line); - x = segEnd.end + 1; - } - - } - } - - private void drawLine(int start, int end, int line) { - for (int i = start; i < end; i++) { - im.setRGB(i, line, underlineColor); - } - } - - private Segment searchSegment(final int i, final int line) { - for (int nb = i; nb < im.getWidth(); nb++) { - final Segment seg = searchSegmentExact(nb, line); - if (seg != null) { - return seg; - } - } - return null; - - } - - private Segment searchSegmentExact(final int i, final int line) { - for (int nb = 0; nb < 6; nb++) { - if (im.getRGB(i + nb, line) != searchedColor) { - return null; - } - } - for (int end = i; end < im.getWidth(); end++) { - if (im.getRGB(end, line) != searchedColor) { - return new Segment(i, end - 1); - } - } - return new Segment(i, im.getWidth() - 1); - } - -} diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/UnderlineTrickEps.java b/src/net/sourceforge/plantuml/cucadiagram/dot/UnderlineTrickEps.java deleted file mode 100644 index a5014966e..000000000 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/UnderlineTrickEps.java +++ /dev/null @@ -1,92 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 3829 $ - * - */ -package net.sourceforge.plantuml.cucadiagram.dot; - -import java.util.ArrayList; -import java.util.List; -import java.util.StringTokenizer; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -public class UnderlineTrickEps { - - private final StringBuilder result = new StringBuilder(); - - public UnderlineTrickEps(String eps) { - final List list = new ArrayList(); - StringTokenizer st = new StringTokenizer(eps, "\n"); - while (st.hasMoreTokens()) { - final String s = st.nextToken(); - list.add(s); - if (s.contains("(_!)")) { - final String other = list.get(list.size() - 4); - final String modified = changeToUnderscore(other); - if (modified != null) { - list.add(list.size() - 4, modified); - } - } - } - - for (String s : list) { - result.append(s); - result.append('\n'); - } - } - - static String changeToUnderscore(String s) { - final Pattern p = Pattern.compile("\\((.*)\\)"); - final Matcher m = p.matcher(s); - - final StringBuffer result = new StringBuffer(); - - if (m.find() == false) { - return null; - } - - final StringBuilder underscores = new StringBuilder("("); - for (int i = 0; i < m.group(1).length(); i++) { - underscores.append('_'); - } - underscores.append(')'); - - m.appendReplacement(result, underscores.toString()); - m.appendTail(result); - return result.toString(); - } - - public String getString() { - return result.toString(); - } - -} diff --git a/src/net/sourceforge/plantuml/cucadiagram/entity/EntityFactory.java b/src/net/sourceforge/plantuml/cucadiagram/entity/EntityFactory.java new file mode 100644 index 000000000..c38fddf7c --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/entity/EntityFactory.java @@ -0,0 +1,215 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7736 $ + * + */ +package net.sourceforge.plantuml.cucadiagram.entity; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import net.sourceforge.plantuml.cucadiagram.Bodier; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.GroupRoot; +import net.sourceforge.plantuml.cucadiagram.GroupType; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.IGroup; +import net.sourceforge.plantuml.cucadiagram.ILeaf; +import net.sourceforge.plantuml.cucadiagram.LeafType; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.skin.VisibilityModifier; + +public class EntityFactory { + + private final Map leafs = new Protect(new LinkedHashMap()); + private final List links = new ArrayList(); + private final Map groups = new Protect(new LinkedHashMap()); + + private final IGroup rootGroup = new GroupRoot(this); + + public ILeaf createLeaf(Code code, Display display, LeafType entityType, IGroup parentContainer, + Set hides) { + if (entityType == null) { + throw new IllegalArgumentException(); + } + final Bodier bodier = new Bodier(entityType, hides); + final EntityImpl result = new EntityImpl(this, code, bodier, parentContainer, entityType); + result.setDisplay(display); + return result; + } + + public IGroup createGroup(Code code, Display display, String namespace, GroupType groupType, + IGroup parentContainer, Set hides) { + if (groupType == null) { + throw new IllegalArgumentException(); + } + final Bodier bodier = new Bodier(null, hides); + final EntityImpl result = new EntityImpl(this, code, bodier, parentContainer, groupType, namespace); + if (display != null) { + result.setDisplay(display); + } + return result; + } + + public IGroup getRootGroup() { + return rootGroup; + } + + public final Map getLeafs() { + return Collections.unmodifiableMap(leafs); + } + + public void addLeaf(ILeaf entity) { + leafs.put(entity.getCode(), entity); + } + + void removeLeaf(Code code) { + final IEntity removed = leafs.remove(code); + if (removed == null) { + throw new IllegalArgumentException(); + } + } + + public void addGroup(IGroup group) { + groups.put(group.getCode(), group); + } + + void removeGroup(Code code) { + final IEntity removed = groups.remove(code); + if (removed == null) { + throw new IllegalArgumentException(); + } + } + + public final Map getGroups() { + return Collections.unmodifiableMap(groups); + } + + public final List getLinks() { + return Collections.unmodifiableList(links); + } + + public void addLink(Link link) { + links.add(link); + } + + public void removeLink(Link link) { + final boolean ok = links.remove(link); + if (ok == false) { + throw new IllegalArgumentException(); + } + } + + public IGroup muteToGroup(Code code, String namespace, GroupType type, IGroup parent) { + final ILeaf leaf = getLeafs().get(code); + ((EntityImpl) leaf).muteToGroup(namespace, type, parent); + final IGroup result = (IGroup) leaf; + removeLeaf(code); + return result; + } + + static class Protect implements Map { + + private final Map m; + + public Protect(Map data) { + this.m = data; + } + + public O remove(Object key) { + if (key instanceof Code == false) { + throw new IllegalArgumentException(); + } + return m.remove(key); + } + + public O get(Object key) { + if (key instanceof Code == false) { + throw new IllegalArgumentException(); + } + return m.get(key); + } + + public Set keySet() { + return m.keySet(); + } + + public void putAll(Map m) { + this.m.putAll(m); + } + + public boolean containsKey(Object key) { + if (key instanceof Code == false) { + throw new IllegalArgumentException(); + } + return m.containsKey(key); + } + + public boolean isEmpty() { + return m.isEmpty(); + } + + public O put(Code key, O value) { + if (key instanceof Code == false) { + throw new IllegalArgumentException(); + } + return m.put(key, value); + } + + public boolean containsValue(Object value) { + return m.containsValue(value); + } + + public Set> entrySet() { + return m.entrySet(); + } + + public Collection values() { + return m.values(); + } + + public void clear() { + m.clear(); + + } + + public int size() { + return m.size(); + } + + } +} diff --git a/src/net/sourceforge/plantuml/cucadiagram/entity/EntityImpl.java b/src/net/sourceforge/plantuml/cucadiagram/entity/EntityImpl.java new file mode 100644 index 000000000..832f448e5 --- /dev/null +++ b/src/net/sourceforge/plantuml/cucadiagram/entity/EntityImpl.java @@ -0,0 +1,597 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7755 $ + * + */ +package net.sourceforge.plantuml.cucadiagram.entity; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.UniqueSequence; +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.cucadiagram.BlockMember; +import net.sourceforge.plantuml.cucadiagram.BlockMemberImpl; +import net.sourceforge.plantuml.cucadiagram.Bodier; +import net.sourceforge.plantuml.cucadiagram.BodyEnhanced; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.EntityPortion; +import net.sourceforge.plantuml.cucadiagram.EntityPosition; +import net.sourceforge.plantuml.cucadiagram.EntityUtils; +import net.sourceforge.plantuml.cucadiagram.GroupType; +import net.sourceforge.plantuml.cucadiagram.IGroup; +import net.sourceforge.plantuml.cucadiagram.ILeaf; +import net.sourceforge.plantuml.cucadiagram.LeafType; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.cucadiagram.Member; +import net.sourceforge.plantuml.cucadiagram.PortionShower; +import net.sourceforge.plantuml.cucadiagram.Rankdir; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockVertical2; +import net.sourceforge.plantuml.graphic.USymbol; +import net.sourceforge.plantuml.svek.IEntityImage; +import net.sourceforge.plantuml.svek.PackageStyle; +import net.sourceforge.plantuml.svek.SingleStrategy; +import net.sourceforge.plantuml.ugraphic.UStroke; + +class EntityImpl implements ILeaf, IGroup { + + private final EntityFactory entityFactory; + + // Entity + private final Code code; + private Url url; + + private final Bodier bodier; + private final String uid = StringUtils.getUid("cl", UniqueSequence.getValue()); + private Display display = new Display(); + + private LeafType leafType; + private Stereotype stereotype; + private String generic; + private IGroup parentContainer; + + private boolean top; + + private final List mouseOver = new ArrayList(); + + // Group + private String namespace; + + private GroupType groupType; + + private boolean autonom = true; + private Rankdir rankdir = Rankdir.TOP_TO_BOTTOM; + + // Other + + private HtmlColor specificBackcolor; + private boolean nearDecoration = false; + private int xposition; + private IEntityImage svekImage; + + private boolean removed = false; + private HtmlColor specificLineColor; + private UStroke specificStroke; + + // Back to Entity + public final boolean isTop() { + checkNotGroup(); + return top; + } + + public final void setTop(boolean top) { + checkNotGroup(); + this.top = top; + } + + private EntityImpl(EntityFactory entityFactory, Code code, Bodier bodier, IGroup parentContainer) { + if (code == null) { + throw new IllegalArgumentException(); + } + this.entityFactory = entityFactory; + this.bodier = bodier; + this.code = code; + this.parentContainer = parentContainer; + } + + EntityImpl(EntityFactory entityFactory, Code code, Bodier bodier, IGroup parentContainer, LeafType leafType) { + this(entityFactory, code, bodier, parentContainer); + this.leafType = leafType; + } + + EntityImpl(EntityFactory entityFactory, Code code, Bodier bodier, IGroup parentContainer, GroupType groupType, + String namespace) { + this(entityFactory, code, bodier, parentContainer); + this.groupType = groupType; + this.namespace = namespace; + } + + public void setContainer(IGroup container) { + checkNotGroup(); + if (container == null) { + throw new IllegalArgumentException(); + } + this.parentContainer = container; + } + + public LeafType getEntityType() { + return leafType; + } + + public void muteToType(LeafType newType) { + checkNotGroup(); + if (newType == null) { + throw new IllegalArgumentException(); + } + if (leafType != LeafType.STILL_UNKNOWN) { + if (leafType != LeafType.ANNOTATION && leafType != LeafType.ABSTRACT_CLASS && leafType != LeafType.CLASS + && leafType != LeafType.ENUM && leafType != LeafType.INTERFACE) { + throw new IllegalArgumentException("type=" + leafType); + } + if (newType != LeafType.ANNOTATION && newType != LeafType.ABSTRACT_CLASS && newType != LeafType.CLASS + && newType != LeafType.ENUM && newType != LeafType.INTERFACE) { + throw new IllegalArgumentException("newtype=" + newType); + } + } + this.leafType = newType; + } + + public Code getCode() { + return code; + } + + public Display getDisplay() { + return display; + } + + public void setDisplay(Display display) { + this.display = display; + } + + public String getUid() { + return uid; + } + + public Stereotype getStereotype() { + return stereotype; + } + + public final void setStereotype(Stereotype stereotype) { + this.stereotype = stereotype; + } + + public final IGroup getParentContainer() { + if (parentContainer == null) { + throw new IllegalArgumentException(); + } + return parentContainer; + } + + @Override + public String toString() { + return code + " " + display + "(" + leafType + ") " + xposition + " " + getUid(); + } + + public HtmlColor getSpecificBackColor() { + return specificBackcolor; + } + + public void setSpecificBackcolor(HtmlColor color) { + this.specificBackcolor = color; + } + + public final Url getUrl99() { + return url; + } + + public boolean hasUrl() { + if (display != null && display.hasUrl()) { + return true; + } + return url != null; + } + + public final void addUrl(Url url) { + this.url = url; + } + + public final boolean hasNearDecoration() { + checkNotGroup(); + return nearDecoration; + } + + public final void setNearDecoration(boolean nearDecoration) { + checkNotGroup(); + this.nearDecoration = nearDecoration; + } + + public int getXposition() { + checkNotGroup(); + return xposition; + } + + public void setXposition(int pos) { + checkNotGroup(); + xposition = pos; + } + + public final IEntityImage getSvekImage() { + checkNotGroup(); + return svekImage; + } + + public final void setSvekImage(IEntityImage svekImage) { + checkNotGroup(); + this.svekImage = svekImage; + } + + public final void setGeneric(String generic) { + checkNotGroup(); + this.generic = generic; + } + + public final String getGeneric() { + checkNotGroup(); + return generic; + } + + public BlockMember getBody(final PortionShower portionShower) { + checkNotGroup(); + final boolean showMethods = portionShower.showPortion(EntityPortion.METHOD, EntityImpl.this); + final boolean showFields = portionShower.showPortion(EntityPortion.FIELD, EntityImpl.this); + if (getEntityType().isLikeClass() && bodier.isBodyEnhanced()) { + if (showMethods && showFields) { + return bodier.getBodyEnhanced(); + } + return new BlockMember() { + public TextBlock asTextBlock(FontParam fontParam, ISkinParam skinParam) { + return null; + } + }; + } + return new BlockMember() { + public TextBlock asTextBlock(FontParam fontParam, ISkinParam skinParam) { + if (getEntityType().isLikeClass()) { + + if (showFields && showMethods) { + return new TextBlockVertical2(new BlockMemberImpl(getFieldsToDisplay()).asTextBlock(fontParam, + skinParam), + new BlockMemberImpl(getMethodsToDisplay()).asTextBlock(fontParam, skinParam), + HorizontalAlignment.LEFT); + } else if (showFields) { + return new BlockMemberImpl(getFieldsToDisplay()).asTextBlock(fontParam, skinParam); + } else if (showMethods) { + return new BlockMemberImpl(getMethodsToDisplay()).asTextBlock(fontParam, skinParam); + } + return null; + } + if (getEntityType() == LeafType.OBJECT) { + return new BlockMemberImpl(getFieldsToDisplay()).asTextBlock(fontParam, skinParam); + } + throw new UnsupportedOperationException(); + } + }; + } + + public BlockMember getMouseOver() { + if (mouseOver.size() == 0) { + return null; + } + return new BlockMember() { + public TextBlock asTextBlock(FontParam fontParam, ISkinParam skinParam) { + return new BodyEnhanced(mouseOver, fontParam, skinParam, leafType.manageModifier()); + } + }; + } + + public void mouseOver(String s) { + mouseOver.add(s); + } + + public List getFieldsToDisplay() { + // checkNotGroup(); + return bodier.getFieldsToDisplay(); + } + + public List getMethodsToDisplay() { + // checkNotGroup(); + return bodier.getMethodsToDisplay(); + } + + public void addFieldOrMethod(String s) { + // checkNotGroup(); + bodier.addFieldOrMethod(s); + } + + public EntityPosition getEntityPosition() { + checkNotGroup(); + if (leafType != LeafType.STATE) { + return EntityPosition.NORMAL; + } + final Stereotype stereotype = getStereotype(); + if (stereotype == null) { + return EntityPosition.NORMAL; + } + final String label = stereotype.getLabel(); + if ("<>".equalsIgnoreCase(label)) { + return EntityPosition.ENTRY_POINT; + } + if ("<>".equalsIgnoreCase(label)) { + return EntityPosition.EXIT_POINT; + } + return EntityPosition.NORMAL; + + } + + // ---------- + + private void checkGroup() { + if (isGroup() == false) { + throw new UnsupportedOperationException(); + } + } + + private void checkNotGroup() { + if (isGroup()) { + throw new UnsupportedOperationException(); + } + } + + public boolean containsLeafRecurse(ILeaf leaf) { + if (leaf == null) { + throw new IllegalArgumentException(); + } + if (leaf.isGroup()) { + throw new IllegalArgumentException(); + } + checkGroup(); + if (leaf.getParentContainer() == this) { + return true; + } + for (IGroup child : getChildren()) { + if (child.containsLeafRecurse(leaf)) { + return true; + } + } + return false; + } + + public Collection getLeafsDirect() { + checkGroup(); + final List result = new ArrayList(); + for (ILeaf ent : entityFactory.getLeafs().values()) { + if (ent.isGroup()) { + throw new IllegalStateException(); + } + if (ent.getParentContainer() == this) { + result.add(ent); + } + } + return Collections.unmodifiableCollection(result); + } + + public Collection getChildren() { + checkGroup(); + final Collection result = new ArrayList(); + for (IGroup g : entityFactory.getGroups().values()) { + if (g != this && g.getParentContainer() == this) { + result.add(g); + } + } + return Collections.unmodifiableCollection(result); + } + + public void moveEntitiesTo(IGroup dest) { + checkGroup(); + if (dest.isGroup() == false) { + throw new UnsupportedOperationException(); + } + for (ILeaf ent : getLeafsDirect()) { + ((EntityImpl) ent).parentContainer = dest; + } + for (IGroup g : dest.getChildren()) { + // ((EntityImpl) g).parentContainer = dest; + throw new IllegalStateException(); + } + + for (IGroup g : getChildren()) { + if (g == dest) { + continue; + } + ((EntityImpl) g).parentContainer = dest; + } + + } + + public int size() { + checkGroup(); + return getLeafsDirect().size(); + } + + public GroupType getGroupType() { + checkGroup(); + return groupType; + } + + public String getNamespace() { + checkGroup(); + return namespace; + } + + public boolean isAutonom() { + checkGroup(); + return autonom; + } + + public void setAutonom(boolean autonom) { + this.autonom = autonom; + + } + + public Rankdir getRankdir() { + checkGroup(); + return rankdir; + } + + public void setRankdir(Rankdir rankdir) { + checkGroup(); + this.rankdir = rankdir; + } + + public PackageStyle getPackageStyle() { + checkGroup(); + if (stereotype == null) { + return null; + } + return stereotype.getPackageStyle(); + } + + public boolean isGroup() { + if (groupType != null && leafType != null) { + throw new IllegalStateException(); + } + if (groupType != null) { + return true; + } + if (leafType != null) { + return false; + } + throw new IllegalStateException(); + } + + // ---- other + + public void overideImage(IEntityImage img, LeafType leafType) { + checkGroup(); + this.svekImage = img; + this.url = null; + + for (final Link link : new ArrayList(entityFactory.getLinks())) { + if (EntityUtils.isPureInnerLink12(this, link)) { + entityFactory.removeLink(link); + } + } + + entityFactory.removeGroup(this.getCode()); + for (ILeaf ent : new ArrayList(entityFactory.getLeafs().values())) { + if (this != ent && this == ent.getParentContainer()) { + entityFactory.removeLeaf(ent.getCode()); + } + } + + entityFactory.addLeaf(this); + this.groupType = null; + this.leafType = leafType; + } + + void muteToGroup(String namespace, GroupType groupType, IGroup parentContainer) { + checkNotGroup(); + if (parentContainer.isGroup() == false) { + throw new IllegalArgumentException(); + } + this.namespace = namespace; + this.groupType = groupType; + this.leafType = null; + this.parentContainer = parentContainer; + } + + public boolean isHidden() { + if (stereotype != null) { + return stereotype.isHidden(); + } + return false; + } + + private USymbol symbol; + + public USymbol getUSymbol() { + return symbol; + } + + public void setUSymbol(USymbol symbol) { + this.symbol = symbol; + } + + public SingleStrategy getSingleStrategy() { + return SingleStrategy.SQUARRE; + } + + public boolean isRemoved() { + if (isGroup()) { + if (getLeafsDirect().size() == 0) { + return false; + } + for (ILeaf leaf : getLeafsDirect()) { + if (leaf.isRemoved() == false) { + return false; + } + } + for (IGroup g : getChildren()) { + if (g.isRemoved() == false) { + return false; + } + } + return true; + } + return removed; + } + + public void setRemoved(boolean removed) { + this.removed = removed; + } + + public HtmlColor getSpecificLineColor() { + return specificLineColor; + } + + public void setSpecificLineColor(HtmlColor specificLinecolor) { + this.specificLineColor = specificLinecolor; + } + + public UStroke getSpecificLineStroke() { + return specificStroke; + } + + public void setSpecificLineStroke(UStroke specificLineStroke) { + this.specificStroke = specificLineStroke; + } + +} diff --git a/src/net/sourceforge/plantuml/descdiagram/DescriptionDiagram.java b/src/net/sourceforge/plantuml/descdiagram/DescriptionDiagram.java new file mode 100644 index 000000000..016eddff2 --- /dev/null +++ b/src/net/sourceforge/plantuml/descdiagram/DescriptionDiagram.java @@ -0,0 +1,117 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8532 $ + * + */ +package net.sourceforge.plantuml.descdiagram; + +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.UmlDiagramType; +import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.ILeaf; +import net.sourceforge.plantuml.cucadiagram.LeafType; +import net.sourceforge.plantuml.graphic.USymbol; + +public class DescriptionDiagram extends AbstractEntityDiagram { + + @Override + public ILeaf getOrCreateLeaf(Code code, LeafType type) { + if (type == null) { + String code2 = code.getCode(); + if (code2.startsWith("[") && code2.endsWith("]")) { + return getOrCreateLeafDefault(code.eventuallyRemoveStartingAndEndingDoubleQuote(), LeafType.COMPONENT); + } + if (code2.startsWith(":") && code2.endsWith(":")) { + return getOrCreateLeafDefault(code.eventuallyRemoveStartingAndEndingDoubleQuote(), LeafType.ACTOR); + } + if (code2.startsWith("()")) { + code2 = code2.substring(2).trim(); + code2 = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(code2); + return getOrCreateLeafDefault(Code.of(code2), LeafType.CIRCLE_INTERFACE); + } + code = code.eventuallyRemoveStartingAndEndingDoubleQuote(); + return getOrCreateLeafDefault(code, LeafType.STILL_UNKNOWN); + } + return getOrCreateLeafDefault(code, type); + } + +// @Override +// public ILeaf createLeaf(Code code, List display, LeafType type) { +// if (type != LeafType.COMPONENT) { +// return super.createLeaf(code, display, type); +// } +// code = code.getFullyQualifiedCode(getCurrentGroup()); +// if (super.leafExist(code)) { +// throw new IllegalArgumentException("Already known: " + code); +// } +// return createEntityWithNamespace(code, display, type); +// } + +// private ILeaf createEntityWithNamespace(Code fullyCode, List display, LeafType type) { +// IGroup group = getCurrentGroup(); +// final String namespace = fullyCode.getNamespace(getLeafs()); +// if (namespace != null && (EntityUtils.groupRoot(group) || group.getCode().equals(namespace) == false)) { +// group = getOrCreateGroupInternal(Code.of(namespace), StringUtils.getWithNewlines(namespace), namespace, +// GroupType.PACKAGE, getRootGroup()); +// } +// return createLeafInternal(fullyCode, +// display == null ? StringUtils.getWithNewlines(fullyCode.getShortName(getLeafs())) : display, type, +// group); +// } + + private boolean isUsecase() { + for (ILeaf leaf : getLeafs().values()) { + final LeafType type = leaf.getEntityType(); + final USymbol usymbol = leaf.getUSymbol(); + if (type == LeafType.USECASE || usymbol == USymbol.ACTOR) { + return true; + } + } + return false; + } + + @Override + public void makeDiagramReady() { + final LeafType defaultType = isUsecase() ? LeafType.ACTOR : LeafType.CIRCLE_INTERFACE; + for (ILeaf leaf : getLeafs().values()) { + if (leaf.getEntityType() == LeafType.STILL_UNKNOWN) { + leaf.muteToType(defaultType); + } + } + } + + @Override + public UmlDiagramType getUmlDiagramType() { + return UmlDiagramType.DESCRIPTION; + } + +} diff --git a/src/net/sourceforge/plantuml/descdiagram/DescriptionDiagramFactory.java b/src/net/sourceforge/plantuml/descdiagram/DescriptionDiagramFactory.java new file mode 100644 index 000000000..8a97aa5ec --- /dev/null +++ b/src/net/sourceforge/plantuml/descdiagram/DescriptionDiagramFactory.java @@ -0,0 +1,123 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7920 $ + * + */ +package net.sourceforge.plantuml.descdiagram; + +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.plantuml.AbstractPSystem; +import net.sourceforge.plantuml.classdiagram.command.CommandUrl; +import net.sourceforge.plantuml.command.Command; +import net.sourceforge.plantuml.command.CommandEndPackage; +import net.sourceforge.plantuml.command.CommandPackage; +import net.sourceforge.plantuml.command.CommandPage; +import net.sourceforge.plantuml.command.CommandRankDir; +import net.sourceforge.plantuml.command.UmlDiagramFactory; +import net.sourceforge.plantuml.command.note.FactoryNoteCommand; +import net.sourceforge.plantuml.command.note.FactoryNoteOnEntityCommand; +import net.sourceforge.plantuml.command.note.FactoryNoteOnLinkCommand; +import net.sourceforge.plantuml.command.regex.RegexLeaf; +import net.sourceforge.plantuml.command.regex.RegexOr; +import net.sourceforge.plantuml.descdiagram.command.CommandCreateElementFull; +import net.sourceforge.plantuml.descdiagram.command.CommandCreateElementMultilines; +import net.sourceforge.plantuml.descdiagram.command.CommandLinkElement; +import net.sourceforge.plantuml.descdiagram.command.CommandNewpage; +import net.sourceforge.plantuml.descdiagram.command.CommandPackageWithUSymbol; + +public class DescriptionDiagramFactory extends UmlDiagramFactory { + + @Override + public DescriptionDiagram createEmptyDiagram() { + return new DescriptionDiagram(); + } + + @Override + protected List createCommands() { + final List cmds = new ArrayList(); + + cmds.add(new CommandRankDir()); + cmds.add(new CommandNewpage(this)); + addCommonCommands(cmds); + + cmds.add(new CommandPage()); + cmds.add(new CommandLinkElement()); + // + cmds.add(new CommandPackageWithUSymbol()); + cmds.add(new CommandPackage()); + cmds.add(new CommandEndPackage()); + // addCommand(new CommandNamespace()); + // addCommand(new CommandEndNamespace()); + final FactoryNoteCommand factoryNoteCommand = new FactoryNoteCommand(); + cmds.add(factoryNoteCommand.createMultiLine()); + + final FactoryNoteOnEntityCommand factoryNoteOnEntityCommand = new FactoryNoteOnEntityCommand(new RegexOr( + "ENTITY", // + new RegexLeaf("[\\p{L}0-9_.]+"), // + new RegexLeaf("\\(\\)\\s*[\\p{L}0-9_.]+"), // + new RegexLeaf("\\(\\)\\s*\"[^\"]+\""), // + new RegexLeaf("\\[[^\\]*]+[^\\]]*\\]"), // + new RegexLeaf("\\((?!\\*\\))[^\\)]+\\)"), // + new RegexLeaf(":[^:]+:"), // + new RegexLeaf("\"[^\"]+\"") // + )); + cmds.add(factoryNoteOnEntityCommand.createSingleLine()); + + cmds.add(factoryNoteCommand.createSingleLine()); + cmds.add(new CommandUrl()); + // addCommand(new CommandCreateComponent2()); + cmds.add(new CommandCreateElementFull()); + cmds.add(new CommandCreateElementMultilines()); + // addCommand(new CommandCreateElementTyped()); + // addCommand(new CommandCreateCircleInterface()); + // addCommand(new CommandCreateActorInComponent()); + + cmds.add(factoryNoteOnEntityCommand.createMultiLine()); + cmds.add(factoryNoteCommand.createMultiLine()); + + final FactoryNoteOnLinkCommand factoryNoteOnLinkCommand = new FactoryNoteOnLinkCommand(); + cmds.add(factoryNoteOnLinkCommand.createSingleLine()); + cmds.add(factoryNoteOnLinkCommand.createMultiLine()); + + return cmds; + } + + @Override + public String checkFinalError(AbstractPSystem system) { + if (system instanceof DescriptionDiagram) { + ((DescriptionDiagram) system).applySingleStrategy(); + } + return super.checkFinalError(system); + } + +} diff --git a/src/net/sourceforge/plantuml/descdiagram/command/CommandCreateElementFull.java b/src/net/sourceforge/plantuml/descdiagram/command/CommandCreateElementFull.java new file mode 100644 index 000000000..1c1c49f3b --- /dev/null +++ b/src/net/sourceforge/plantuml/descdiagram/command/CommandCreateElementFull.java @@ -0,0 +1,219 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7715 $ + * + */ +package net.sourceforge.plantuml.descdiagram.command; + +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.UrlBuilder; +import net.sourceforge.plantuml.UrlBuilder.ModeUrl; +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.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.LeafType; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.descdiagram.DescriptionDiagram; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.USymbol; + +public class CommandCreateElementFull extends SingleLineCommand2 { + + public CommandCreateElementFull() { + super(getRegexConcat()); + } + + private static RegexConcat getRegexConcat() { + return new RegexConcat( + new RegexLeaf("^"), // + new RegexLeaf("SYMBOL", "(?:(artifact|actor|folder|rect|node|frame|cloud|database|storage|agent|usecase|component|boundary|control|entity|interface|\\(\\))\\s+)?"), // + new RegexLeaf("\\s*"), // + new RegexOr(// + new RegexLeaf("CODE1", CODE_WITH_QUOTE), // + new RegexConcat(// + new RegexLeaf("DISPLAY2", DISPLAY), // + new RegexLeaf("STEREOTYPE2", "(?:\\s+(\\<\\<.+\\>\\>))?"), // + new RegexLeaf("\\s*as\\s+"), // + new RegexLeaf("CODE2", CODE)), // + new RegexConcat(// + new RegexLeaf("CODE3", CODE), // + new RegexLeaf("STEREOTYPE3", "(?:\\s+(\\<\\<.+\\>\\>))?"), // + new RegexLeaf("\\s+as\\s*"), // + new RegexLeaf("DISPLAY3", DISPLAY)), // + new RegexConcat(// + new RegexLeaf("DISPLAY4", DISPLAY_WITHOUT_QUOTE), // + new RegexLeaf("STEREOTYPE4", "(?:\\s+(\\<\\<.+\\>\\>))?"), // + new RegexLeaf("\\s*as\\s+"), // + new RegexLeaf("CODE4", CODE)) // + ), // + new RegexLeaf("STEREOTYPE", "(?:\\s*(\\<\\<.+\\>\\>))?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("URL", "(" + UrlBuilder.getRegexp() + ")?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("COLOR", "(#\\w+[-\\\\|/]?\\w+)?"), // + new RegexLeaf("$")); + } + + private static final String CODE_CORE = "[\\p{L}0-9_.]+|\\(\\)\\s*[\\p{L}0-9_.]+|\\(\\)\\s*\"[^\"]+\"|:[^:]+:|\\([^()]+\\)|\\[[^\\[\\]]+\\]"; + private static final String CODE = "(" + CODE_CORE + ")"; + private static final String CODE_WITH_QUOTE = "(" + CODE_CORE + "|\"[^\"]+\")"; + + private static final String DISPLAY_CORE = "\"[^\"]+\"|:[^:]+:|\\([^()]+\\)|\\[[^\\[\\]]+\\]"; + private static final String DISPLAY = "(" + DISPLAY_CORE + ")"; + private static final String DISPLAY_WITHOUT_QUOTE = "(" + DISPLAY_CORE + "|[\\p{L}0-9_.]+)"; + + @Override + final protected boolean isForbidden(String line) { + if (line.matches("^[\\p{L}0-9_.]+$")) { + return true; + } + return false; + } + + @Override + protected CommandExecutionResult executeArg(DescriptionDiagram system, RegexResult arg) { + String codeRaw = arg.getLazzy("CODE", 0); + final String displayRaw = arg.getLazzy("DISPLAY", 0); + final char codeChar = getCharEncoding(codeRaw); + final char codeDisplay = getCharEncoding(displayRaw); + final String symbol; + if (codeRaw.startsWith("()")) { + symbol = "interface"; + codeRaw = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(codeRaw.substring(2).trim()); + } else if (codeChar == '(' || codeDisplay == '(') { + symbol = "usecase"; + } else if (codeChar == ':' || codeDisplay == ':') { + symbol = "actor"; + } else if (codeChar == '[' || codeDisplay == '[') { + symbol = "component"; + } else { + symbol = arg.get("SYMBOL", 0); + } + + final LeafType type; + final USymbol usymbol; + + if (symbol == null) { + type = LeafType.COMPONENT2; + usymbol = USymbol.ACTOR; + } else if (symbol.equalsIgnoreCase("artifact")) { + type = LeafType.COMPONENT2; + usymbol = USymbol.ARTIFACT; + } else if (symbol.equalsIgnoreCase("folder")) { + type = LeafType.COMPONENT2; + usymbol = USymbol.FOLDER; + } else if (symbol.equalsIgnoreCase("rect")) { + type = LeafType.COMPONENT2; + usymbol = USymbol.RECT; + } else if (symbol.equalsIgnoreCase("node")) { + type = LeafType.COMPONENT2; + usymbol = USymbol.NODE; + } else if (symbol.equalsIgnoreCase("frame")) { + type = LeafType.COMPONENT2; + usymbol = USymbol.FRAME; + } else if (symbol.equalsIgnoreCase("cloud")) { + type = LeafType.COMPONENT2; + usymbol = USymbol.CLOUD; + } else if (symbol.equalsIgnoreCase("database")) { + type = LeafType.COMPONENT2; + usymbol = USymbol.DATABASE; + } else if (symbol.equalsIgnoreCase("storage")) { + type = LeafType.COMPONENT2; + usymbol = USymbol.STORAGE; + } else if (symbol.equalsIgnoreCase("agent")) { + type = LeafType.COMPONENT2; + usymbol = USymbol.RECT; + } else if (symbol.equalsIgnoreCase("actor")) { + type = LeafType.COMPONENT2; + usymbol = USymbol.ACTOR; + } else if (symbol.equalsIgnoreCase("component")) { + type = LeafType.COMPONENT2; + usymbol = system.getSkinParam().useUml2ForComponent() ? USymbol.COMPONENT2 : USymbol.COMPONENT1; + } else if (symbol.equalsIgnoreCase("boundary")) { + type = LeafType.COMPONENT2; + usymbol = USymbol.BOUNDARY; + } else if (symbol.equalsIgnoreCase("control")) { + type = LeafType.COMPONENT2; + usymbol = USymbol.CONTROL; + } else if (symbol.equalsIgnoreCase("entity")) { + type = LeafType.COMPONENT2; + usymbol = USymbol.ENTITY_DOMAIN; + } else if (symbol.equalsIgnoreCase("interface")) { + type = LeafType.COMPONENT2; + usymbol = USymbol.INTERFACE; + } else if (symbol.equalsIgnoreCase("()")) { + type = LeafType.COMPONENT2; + usymbol = USymbol.INTERFACE; + } else if (symbol.equalsIgnoreCase("usecase")) { + type = LeafType.USECASE; + usymbol = null; + } else { + throw new IllegalStateException(); + } + + final Code code = Code.of(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(codeRaw)); + String display = displayRaw; + if (display == null) { + display = code.getCode(); + } + display = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(display); + final String stereotype = arg.getLazzy("STEREOTYPE", 0); + final IEntity entity = system.getOrCreateLeaf(code, type); + entity.setDisplay(Display.getWithNewlines(display)); + entity.setUSymbol(usymbol); + if (stereotype != null) { + entity.setStereotype(new Stereotype(stereotype, system.getSkinParam().getCircledCharacterRadius(), + system.getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null))); + } + + final String urlString = arg.get("URL", 0); + if (urlString != null) { + final UrlBuilder urlBuilder = new UrlBuilder(system.getSkinParam().getValue("topurl"), ModeUrl.STRICT); + final Url url = urlBuilder.getUrl(urlString); + entity.addUrl(url); + } + + entity.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(arg.get("COLOR", 0))); + return CommandExecutionResult.ok(); + } + + private char getCharEncoding(final String codeRaw) { + return codeRaw != null && codeRaw.length() > 2 ? codeRaw.charAt(0) : 0; + } +} diff --git a/src/net/sourceforge/plantuml/descdiagram/command/CommandCreateElementMultilines.java b/src/net/sourceforge/plantuml/descdiagram/command/CommandCreateElementMultilines.java new file mode 100644 index 000000000..b87e4e85d --- /dev/null +++ b/src/net/sourceforge/plantuml/descdiagram/command/CommandCreateElementMultilines.java @@ -0,0 +1,128 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.descdiagram.command; + +import java.util.List; +import java.util.regex.Pattern; + +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.CommandMultilines2; +import net.sourceforge.plantuml.command.MultilinesStrategy; +import net.sourceforge.plantuml.command.regex.RegexConcat; +import net.sourceforge.plantuml.command.regex.RegexLeaf; +import net.sourceforge.plantuml.command.regex.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.ILeaf; +import net.sourceforge.plantuml.cucadiagram.LeafType; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.descdiagram.DescriptionDiagram; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.USymbol; + +public class CommandCreateElementMultilines extends CommandMultilines2 { + + enum Mode { + EXTENDS, IMPLEMENTS + }; + + public CommandCreateElementMultilines() { + super(getRegexConcat(), MultilinesStrategy.REMOVE_STARTING_QUOTE); + } + + @Override + public String getPatternEnd() { + return "(?i)^(.*)\"$"; + } + + private static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("TYPE", "(usecase|database)\\s+"), // + new RegexLeaf("CODE", "([\\p{L}0-9_.]+)"), // + new RegexLeaf("\\s*"), // + // new RegexLeaf("STEREO", "(?:\\s*(\\<\\<.+\\>\\>))?"), // + new RegexLeaf("STEREO", "(\\<\\<.+\\>\\>)?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("COLOR", "(#\\w+[-\\\\|/]?\\w+)?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("DESC", "as\\s*\"(.*)$")); + } + + public CommandExecutionResult executeNow(DescriptionDiagram system, List lines) { + StringUtils.trim(lines, false); + final RegexResult line0 = getStartingPattern().matcher(lines.get(0).trim()); + final String symbol = line0.get("TYPE", 0).toUpperCase(); + final LeafType type; + final USymbol usymbol; + + if (symbol.equalsIgnoreCase("usecase")) { + type = LeafType.USECASE; + usymbol = null; + } else if (symbol.equalsIgnoreCase("database")) { + type = LeafType.COMPONENT2; + usymbol = USymbol.DATABASE; + } else { + throw new IllegalStateException(); + } + + final Code code = Code.of(line0.get("CODE", 0)); + Display display = new Display(lines.subList(1, lines.size() - 1)); + final String descStart = line0.get("DESC", 0); + if (StringUtils.isNotEmpty(descStart)) { + display = display.addFirst(descStart); + } + + final List lineLast = StringUtils.getSplit(Pattern.compile(getPatternEnd()), + lines.get(lines.size() - 1)); + if (StringUtils.isNotEmpty(lineLast.get(0))) { + display = display.add(lineLast.get(0)); + } + + final String stereotype = line0.get("STEREO", 0); + + final ILeaf result = system.createLeaf(code, display, type); + result.setUSymbol(usymbol); + if (stereotype != null) { + result.setStereotype(new Stereotype(stereotype, system.getSkinParam().getCircledCharacterRadius(), system + .getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null))); + } + + result.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(line0.get("COLOR", 0))); + + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/descdiagram/command/CommandLinkElement.java b/src/net/sourceforge/plantuml/descdiagram/command/CommandLinkElement.java new file mode 100644 index 000000000..01ea46ef4 --- /dev/null +++ b/src/net/sourceforge/plantuml/descdiagram/command/CommandLinkElement.java @@ -0,0 +1,321 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.descdiagram.command; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import net.sourceforge.plantuml.Direction; +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.classdiagram.command.CommandLinkClass; +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.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.ILeaf; +import net.sourceforge.plantuml.cucadiagram.LeafType; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.cucadiagram.LinkDecor; +import net.sourceforge.plantuml.cucadiagram.LinkType; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.descdiagram.DescriptionDiagram; + +public class CommandLinkElement extends SingleLineCommand2 { + + public CommandLinkElement() { + super(getRegexConcat()); + } + + static RegexConcat getRegexConcat() { + return new RegexConcat( + new RegexLeaf("^"), // + getGroup("ENT1"), // + new RegexLeaf("\\s*"), new RegexLeaf("LABEL1", "(?:\"([^\"]+)\")?"), + new RegexLeaf("\\s*"), + new RegexLeaf("HEAD2", "(0\\)|<<|[<^*+#0)]|<\\|| +o)?"), // + new RegexLeaf("BODY1", "([-=.~]+)"), // + new RegexLeaf("ARROW_STYLE1", + "(?:\\[((?:#\\w+|dotted|dashed|bold|hidden)(?:,#\\w+|,dotted|,dashed|,bold|,hidden)*)\\])?"), + new RegexLeaf("DIRECTION", "(?:(left|right|up|down|le?|ri?|up?|do?)(?=[-=.~0()]))?"), // + new RegexLeaf("INSIDE", "(?:(0|\\(0\\)|\\(0|0\\))(?=[-=.~]))?"), // + new RegexLeaf("ARROW_STYLE2", + "(?:\\[((?:#\\w+|dotted|dashed|bold|hidden)(?:,#\\w+|,dotted|,dashed|,bold|,hidden)*)\\])?"), + new RegexLeaf("BODY2", "([-=.~]*)"), // + new RegexLeaf("HEAD1", "(\\(0|>>|[>^*+#0(]|\\|>|o +)?"), // + new RegexLeaf("\\s*"), new RegexLeaf("LABEL2", "(?:\"([^\"]+)\")?"), new RegexLeaf("\\s*"), // + getGroup("ENT2"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("LABEL_LINK", "(?::\\s*(.+))?$")); + } + + private LinkType getLinkType(RegexResult arg) { + final String head1 = trimAndLowerCase(arg.get("HEAD1", 0)); + final String head2 = trimAndLowerCase(arg.get("HEAD2", 0)); + LinkDecor d1 = LinkDecor.NONE; + LinkDecor d2 = LinkDecor.NONE; + + if (head1.equals("(0")) { + d1 = LinkDecor.CIRCLE_CONNECT; + } else if (head1.equals("#")) { + d1 = LinkDecor.SQUARRE; + } else if (head1.equals("0")) { + d1 = LinkDecor.CIRCLE; + } else if (head1.equals("(")) { + d1 = LinkDecor.PARENTHESIS; + } else if (head1.equals(">")) { + d1 = LinkDecor.ARROW; + } else if (head1.equals("*")) { + d1 = LinkDecor.COMPOSITION; + } else if (head1.equals("o")) { + d1 = LinkDecor.AGREGATION; + } else if (head1.equals("+")) { + d1 = LinkDecor.PLUS; + } else if (head1.equals(">>")) { + d1 = LinkDecor.ARROW_TRIANGLE; + } else if (head1.equals("^")) { + d1 = LinkDecor.EXTENDS; + } else if (head1.equals("|>")) { + d1 = LinkDecor.EXTENDS; + } + + if (head2.equals("0)")) { + d2 = LinkDecor.CIRCLE_CONNECT; + } else if (head2.equals("#")) { + d2 = LinkDecor.SQUARRE; + } else if (head2.equals("0")) { + d2 = LinkDecor.CIRCLE; + } else if (head2.equals(")")) { + d2 = LinkDecor.PARENTHESIS; + } else if (head2.equals("<")) { + d2 = LinkDecor.ARROW; + } else if (head2.equals("*")) { + d2 = LinkDecor.COMPOSITION; + } else if (head2.equals("o")) { + d2 = LinkDecor.AGREGATION; + } else if (head2.equals("+")) { + d2 = LinkDecor.PLUS; + } else if (head2.equals("<<")) { + d2 = LinkDecor.ARROW_TRIANGLE; + } else if (head2.equals("^")) { + d2 = LinkDecor.EXTENDS; + } else if (head2.equals("<|")) { + d2 = LinkDecor.EXTENDS; + } + + LinkType result = new LinkType(d1, d2); + final String queue = getQueue(arg); + if (queue.contains(".")) { + result = result.getDashed(); + } else if (queue.contains("~")) { + result = result.getDotted(); + } else if (queue.contains("=")) { + result = result.getBold(); + } + + final String middle = arg.get("INSIDE", 0); + if ("0".equals(middle)) { + result = result.withMiddleCircle(); + } else if ("0)".equals(middle)) { + result = result.withMiddleCircleCircled1(); + } else if ("(0".equals(middle)) { + result = result.withMiddleCircleCircled2(); + } else if ("(0)".equals(middle)) { + result = result.withMiddleCircleCircled(); + } + return result; + } + + private static String trimAndLowerCase(String s) { + if (s == null) { + return ""; + } + return s.trim().toLowerCase(); + } + + private Direction getDirection(RegexResult arg) { + final String dir = arg.get("DIRECTION", 0); + if (dir == null) { + return StringUtils.getQueueDirection(getQueue(arg)); + // return Direction.DOWN; + } + return StringUtils.getQueueDirection(dir); + } + + private String getQueue(RegexResult arg) { + return arg.get("BODY1", 0) + arg.get("BODY2", 0); + } + + private static RegexLeaf getGroup(String name) { + return new RegexLeaf( + name, + "([\\p{L}0-9_.]+|\\(\\)\\s*[\\p{L}0-9_.]+|\\(\\)\\s*\"[^\"]+\"|:[^:]+:|(?!\\[\\*\\])\\[[^\\[\\]]+\\]|\\((?!\\*\\))[^)]+\\))(?:\\s*(\\<\\<.*\\>\\>))?"); + } + + static class Labels { + private String firstLabel; + private String secondLabel; + private String labelLink; + + Labels(RegexResult arg) { + firstLabel = arg.get("LABEL1", 0); + secondLabel = arg.get("LABEL2", 0); + labelLink = arg.get("LABEL_LINK", 0); + + if (labelLink != null) { + if (firstLabel == null && secondLabel == null) { + init(); + } + labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(labelLink); + } + + } + + private void init() { + final Pattern p1 = Pattern.compile("^\"([^\"]+)\"([^\"]+)\"([^\"]+)\"$"); + final Matcher m1 = p1.matcher(labelLink); + if (m1.matches()) { + firstLabel = m1.group(1); + labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m1.group(2).trim()).trim(); + secondLabel = m1.group(3); + return; + } + final Pattern p2 = Pattern.compile("^\"([^\"]+)\"([^\"]+)$"); + final Matcher m2 = p2.matcher(labelLink); + if (m2.matches()) { + firstLabel = m2.group(1); + labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m2.group(2).trim()).trim(); + secondLabel = null; + return; + } + final Pattern p3 = Pattern.compile("^([^\"]+)\"([^\"]+)\"$"); + final Matcher m3 = p3.matcher(labelLink); + if (m3.matches()) { + firstLabel = null; + labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m3.group(1).trim()).trim(); + secondLabel = m3.group(2); + } + } + + } + + @Override + protected CommandExecutionResult executeArg(DescriptionDiagram diagram, RegexResult arg) { + final Code ent1 = Code.of(arg.get("ENT1", 0)); + final Code ent2 = Code.of(arg.get("ENT2", 0)); + + if (diagram.isGroup(ent1) && diagram.isGroup(ent2)) { + return executePackageLink(diagram, arg); + } + // if (diagram.isGroup(ent1) || diagram.isGroup(ent2)) { + // return CommandExecutionResult.error("Package can be only linked to other package"); + // } + + final IEntity cl1 = diagram.isGroup(ent1) ? diagram.getGroup(Code.of(arg.get("ENT1", 0))) : getOrCreateLeaf( + diagram, ent1); + final IEntity cl2 = diagram.isGroup(ent2) ? diagram.getGroup(Code.of(arg.get("ENT2", 0))) : getOrCreateLeaf( + diagram, ent2); + + if (arg.get("ENT1", 1) != null) { + cl1.setStereotype(new Stereotype(arg.get("ENT1", 1))); + } + if (arg.get("ENT2", 1) != null) { + cl2.setStereotype(new Stereotype(arg.get("ENT2", 1))); + } + + 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); + } + + final Labels labels = new Labels(arg); + + Link link = new Link(cl1, cl2, linkType, Display.getWithNewlines(labels.labelLink), queue.length(), + labels.firstLabel, labels.secondLabel, diagram.getLabeldistance(), diagram.getLabelangle()); + + if (dir == Direction.LEFT || dir == Direction.UP) { + link = link.getInv(); + } + CommandLinkClass.applyStyle(arg.getLazzy("ARROW_STYLE", 0), link); + + diagram.addLink(link); + return CommandExecutionResult.ok(); + } + + private ILeaf getOrCreateLeaf(DescriptionDiagram diagram, final Code code2) { + final String code = code2.getCode(); + if (code.startsWith("()")) { + return diagram.getOrCreateLeaf( + Code.of(StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(code.substring(2).trim())), + LeafType.CIRCLE_INTERFACE); + } + final char codeChar = code.length() > 2 ? code.charAt(0) : 0; + if (codeChar == '(') { + return diagram.getOrCreateLeaf(code2.eventuallyRemoveStartingAndEndingDoubleQuote(), LeafType.USECASE); + } else if (codeChar == ':') { + return diagram.getOrCreateLeaf(code2.eventuallyRemoveStartingAndEndingDoubleQuote(), LeafType.ACTOR); + } else if (codeChar == '[') { + return diagram.getOrCreateLeaf(code2.eventuallyRemoveStartingAndEndingDoubleQuote(), LeafType.COMPONENT); + } + + return diagram.getOrCreateLeaf(code2, null); + } + + private CommandExecutionResult executePackageLink(DescriptionDiagram diagram, RegexResult arg) { + final IEntity cl1 = diagram.getGroup(Code.of(arg.get("ENT1", 0))); + final IEntity cl2 = diagram.getGroup(Code.of(arg.get("ENT2", 0))); + + 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, cl2, linkType, Display.getWithNewlines(arg.get("LABEL_LINK", 0)), queue.length()); + if (dir == Direction.LEFT || dir == Direction.UP) { + link = link.getInv(); + } + diagram.addLink(link); + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/descdiagram/command/CommandNewpage.java b/src/net/sourceforge/plantuml/descdiagram/command/CommandNewpage.java new file mode 100644 index 000000000..c4f6e5bf4 --- /dev/null +++ b/src/net/sourceforge/plantuml/descdiagram/command/CommandNewpage.java @@ -0,0 +1,65 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7800 $ + * + */ +package net.sourceforge.plantuml.descdiagram.command; + +import net.sourceforge.plantuml.AbstractPSystem; +import net.sourceforge.plantuml.NewpagedDiagram; +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.SingleLineCommand2; +import net.sourceforge.plantuml.command.UmlDiagramFactory; +import net.sourceforge.plantuml.command.regex.RegexConcat; +import net.sourceforge.plantuml.command.regex.RegexLeaf; +import net.sourceforge.plantuml.command.regex.RegexResult; + +public class CommandNewpage extends SingleLineCommand2 { + + private final UmlDiagramFactory factory; + + public CommandNewpage(UmlDiagramFactory factory) { + super(getRegexConcat()); + this.factory = factory; + } + + static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("newpage"), // + new RegexLeaf("$")); + } + + @Override + protected CommandExecutionResult executeArg(AbstractPSystem diagram, RegexResult arg) { + NewpagedDiagram result = NewpagedDiagram.newpage(diagram, factory.createEmptyDiagram()); + return CommandExecutionResult.newDiagram(result); + } +} diff --git a/src/net/sourceforge/plantuml/descdiagram/command/CommandPackageWithUSymbol.java b/src/net/sourceforge/plantuml/descdiagram/command/CommandPackageWithUSymbol.java new file mode 100644 index 000000000..0caa5e6cf --- /dev/null +++ b/src/net/sourceforge/plantuml/descdiagram/command/CommandPackageWithUSymbol.java @@ -0,0 +1,107 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7800 $ + * + */ +package net.sourceforge.plantuml.descdiagram.command; + +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.UniqueSequence; +import net.sourceforge.plantuml.UrlBuilder; +import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram; +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.RegexResult; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.GroupType; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.IGroup; +import net.sourceforge.plantuml.cucadiagram.Stereotype; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.USymbol; + +public class CommandPackageWithUSymbol extends SingleLineCommand2 { + + public CommandPackageWithUSymbol() { + super(getRegexConcat()); + } + + private static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("SYMBOL", "(package|rectangle|node|artifact|folder|frame|cloud|database|storage|component)"), // + new RegexLeaf("\\s+"), // + new RegexLeaf("NAME", "(\"[^\"]+\"|[^#\\s{}]*)"), // + new RegexLeaf("AS", "(?:\\s+as\\s+([\\p{L}0-9_.]+))?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("STEREOTYPE", "(\\<\\<.*\\>\\>)?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("URL", "(" + UrlBuilder.getRegexp() + ")?"), // + new RegexLeaf("\\s*"), // + new RegexLeaf("COLOR", "(#\\w+[-\\\\|/]?\\w+)?"), // + new RegexLeaf("\\s*\\{$")); + } + + @Override + protected CommandExecutionResult executeArg(AbstractEntityDiagram diagram, RegexResult arg) { + final Code code; + final String display; + final String name = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("NAME", 0)); + if (arg.get("AS", 0) == null) { + if (name.length() == 0) { + code = UniqueSequence.getCode("##"); + display = null; + } else { + code = Code.of(name); + display = code.getCode(); + } + } else { + display = name; + code = Code.of(arg.get("AS", 0)); + } + final IGroup currentPackage = diagram.getCurrentGroup(); + final IEntity p = diagram.getOrCreateGroup(code, Display.getWithNewlines(display), null, + GroupType.PACKAGE, currentPackage); + p.setUSymbol(USymbol.getFromString(arg.get("SYMBOL", 0))); + final String stereotype = arg.get("STEREOTYPE", 0); + if (stereotype != null) { + p.setStereotype(new Stereotype(stereotype, false)); + } + final String color = arg.get("COLOR", 0); + if (color != null) { + p.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(color)); + } + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/directdot/DotText.java b/src/net/sourceforge/plantuml/directdot/DotText.java deleted file mode 100644 index 1d3fb507b..000000000 --- a/src/net/sourceforge/plantuml/directdot/DotText.java +++ /dev/null @@ -1,103 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6780 $ - * - */ -package net.sourceforge.plantuml.directdot; - -import java.awt.Font; -import java.util.List; - -import net.sourceforge.plantuml.FileFormat; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.cucadiagram.dot.DotExpression; -import net.sourceforge.plantuml.graphic.HtmlColor; -import net.sourceforge.plantuml.ugraphic.ColorMapper; -import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity; - -public class DotText { - - private final HtmlColor background; - - private final HtmlColor textcolor; - - private final List strings; - - private final ColorMapper colorMapper = new ColorMapperIdentity(); - - public DotText(List strings, HtmlColor textcolor, HtmlColor background) { - this.strings = strings; - this.textcolor = textcolor; - this.background = background; - } - - public void generateDot(StringBuilder sb) { - - sb.append("digraph unix {\n"); - sb.append("bgcolor=\"" + getAsHtml(background) + "\";"); - sb.append("foo ["); - sb.append("shape=box;"); - - final StringBuilder html = new StringBuilder(); - if (strings.size() == 1) { - appendOneLine(html, strings.get(0)); - } else { - html.append(""); - for (String s : strings) { - html.append(""); - html.append(""); - html.append(""); - } - html.append("
    "); - appendOneLine(html, s); - html.append("
    "); - } - - sb.append("label=<"); - sb.append(html); - sb.append(">"); - - sb.append("]"); - sb.append("}"); - - } - - private void appendOneLine(final StringBuilder html, String s) { - final DotExpression dotExpression = new DotExpression(colorMapper, s, 14, textcolor, "Times-Roman", Font.PLAIN, - FileFormat.PNG); - html.append(dotExpression.getDotHtml()); - } - - protected final String getAsHtml(HtmlColor htmlColor) { - return StringUtils.getAsHtml(colorMapper.getMappedColor(htmlColor)); - } - -} diff --git a/src/net/sourceforge/plantuml/directdot/PSystemDot.java b/src/net/sourceforge/plantuml/directdot/PSystemDot.java index 78b4691d8..584812b36 100644 --- a/src/net/sourceforge/plantuml/directdot/PSystemDot.java +++ b/src/net/sourceforge/plantuml/directdot/PSystemDot.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,35 +33,36 @@ package net.sourceforge.plantuml.directdot; import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import net.sourceforge.plantuml.AbstractPSystem; import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.api.ImageDataSimple; +import net.sourceforge.plantuml.core.DiagramDescription; +import net.sourceforge.plantuml.core.DiagramDescriptionImpl; +import net.sourceforge.plantuml.core.ImageData; import net.sourceforge.plantuml.cucadiagram.dot.Graphviz; import net.sourceforge.plantuml.cucadiagram.dot.GraphvizUtils; +import net.sourceforge.plantuml.cucadiagram.dot.ProcessState; public class PSystemDot extends AbstractPSystem { private final String data; - public PSystemDot(String data) throws UnsupportedEncodingException { + public PSystemDot(String data) { this.data = data; } - public String getDescription() { - return "(Dot)"; + public DiagramDescription getDescription() { + return new DiagramDescriptionImpl("(Dot)", getClass()); } - public void exportDiagram(OutputStream os, StringBuilder cmap, int index, FileFormatOption fileFormatOption) - throws IOException { - final Graphviz graphviz = GraphvizUtils.create(data, fileFormatOption.getFileFormat().name().toLowerCase()); - try { - graphviz.createFile(os); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - throw new IOException(e.toString()); + public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException { + final Graphviz graphviz = GraphvizUtils.create(data, fileFormat.getFileFormat().name().toLowerCase()); + final ProcessState state = graphviz.createFile3(os); + if (state != ProcessState.TERMINATED_OK) { + throw new IllegalStateException("Timeout1 " + state); } + return new ImageDataSimple(); } } diff --git a/src/net/sourceforge/plantuml/directdot/PSystemDotFactory.java b/src/net/sourceforge/plantuml/directdot/PSystemDotFactory.java index cdbc43013..13e83c982 100644 --- a/src/net/sourceforge/plantuml/directdot/PSystemDotFactory.java +++ b/src/net/sourceforge/plantuml/directdot/PSystemDotFactory.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -31,52 +31,35 @@ */ package net.sourceforge.plantuml.directdot; -import java.io.UnsupportedEncodingException; +import net.sourceforge.plantuml.command.PSystemBasicFactory; +import net.sourceforge.plantuml.core.DiagramType; -import net.sourceforge.plantuml.DiagramType; -import net.sourceforge.plantuml.PSystemBasicFactory; - -public class PSystemDotFactory implements PSystemBasicFactory { +public class PSystemDotFactory extends PSystemBasicFactory { private StringBuilder data; - private boolean first; - private final DiagramType diagramType; public PSystemDotFactory(DiagramType diagramType) { - this.diagramType = diagramType; + super(diagramType); } - public void init(String startLine) { + @Override + public PSystemDot init(String startLine) { data = null; - first = true; + return null; } - public boolean executeLine(String line) { - if (first && line.matches("digraph\\s+\\w+\\s+\\{")) { + @Override + public PSystemDot executeLine(PSystemDot system, String line) { + if (system == null && line.matches("(di)?graph\\s+\\w+\\s+\\{")) { data = new StringBuilder(line); data.append("\n"); - return true; + return new PSystemDot(data.toString()); } - first = false; - if (data == null) { - return false; + if (data == null || system == null) { + return null; } data.append(line); data.append("\n"); - return true; + return new PSystemDot(data.toString()); } - - public PSystemDot getSystem() { - try { - return new PSystemDot(data.toString()); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); - return null; - } - } - - public DiagramType getDiagramType() { - return diagramType; - } - } diff --git a/src/net/sourceforge/plantuml/ditaa/PSystemDitaa.java b/src/net/sourceforge/plantuml/ditaa/PSystemDitaa.java index 3fac7b986..c1b5c5ea1 100644 --- a/src/net/sourceforge/plantuml/ditaa/PSystemDitaa.java +++ b/src/net/sourceforge/plantuml/ditaa/PSystemDitaa.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -34,12 +34,16 @@ package net.sourceforge.plantuml.ditaa; import java.awt.image.BufferedImage; import java.io.IOException; import java.io.OutputStream; -import java.io.UnsupportedEncodingException; import javax.imageio.ImageIO; import net.sourceforge.plantuml.AbstractPSystem; +import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.api.ImageDataSimple; +import net.sourceforge.plantuml.core.DiagramDescription; +import net.sourceforge.plantuml.core.DiagramDescriptionImpl; +import net.sourceforge.plantuml.core.ImageData; import org.stathissideris.ascii2image.core.ConversionOptions; import org.stathissideris.ascii2image.core.ProcessingOptions; @@ -49,26 +53,39 @@ import org.stathissideris.ascii2image.text.TextGrid; public class PSystemDitaa extends AbstractPSystem { - private final TextGrid grid = new TextGrid(); private final ProcessingOptions processingOptions = new ProcessingOptions(); + private final boolean dropShadows; + private final String data; - public PSystemDitaa(String data, boolean performSeparationOfCommonEdges) throws UnsupportedEncodingException { - grid.initialiseWithText(data, null); - processingOptions.setPerformSeparationOfCommonEdges(performSeparationOfCommonEdges); + public PSystemDitaa(String data, boolean performSeparationOfCommonEdges, boolean dropShadows) { + this.data = data; + this.dropShadows = dropShadows; + this.processingOptions.setPerformSeparationOfCommonEdges(performSeparationOfCommonEdges); } - public String getDescription() { - return "(Ditaa)"; + PSystemDitaa add(String line) { + return new PSystemDitaa(data + line + "\n", processingOptions.performSeparationOfCommonEdges(), dropShadows); } - public void exportDiagram(OutputStream os, StringBuilder cmap, int index, FileFormatOption fileFormatOption) - throws IOException { + public DiagramDescription getDescription() { + return new DiagramDescriptionImpl("(Ditaa)", getClass()); + } + public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException { + if (fileFormat.getFileFormat() == FileFormat.ATXT) { + os.write(getSource().getPlainString().getBytes()); + return new ImageDataSimple(); + } + // ditaa can only export png so file format is mostly ignored final ConversionOptions options = new ConversionOptions(); + options.setDropShadows(dropShadows); + final TextGrid grid = new TextGrid(); + grid.initialiseWithText(data, null); final Diagram diagram = new Diagram(grid, options, processingOptions); final BufferedImage image = (BufferedImage) new BitmapRenderer().renderToImage(diagram, options.renderingOptions); ImageIO.write(image, "png", os); + return new ImageDataSimple(image.getWidth(), image.getHeight()); } diff --git a/src/net/sourceforge/plantuml/ditaa/PSystemDitaaFactory.java b/src/net/sourceforge/plantuml/ditaa/PSystemDitaaFactory.java index 1b8032c0a..9f6597412 100644 --- a/src/net/sourceforge/plantuml/ditaa/PSystemDitaaFactory.java +++ b/src/net/sourceforge/plantuml/ditaa/PSystemDitaaFactory.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -31,68 +31,57 @@ */ package net.sourceforge.plantuml.ditaa; -import java.io.UnsupportedEncodingException; +import net.sourceforge.plantuml.command.PSystemBasicFactory; +import net.sourceforge.plantuml.core.DiagramType; -import net.sourceforge.plantuml.DiagramType; -import net.sourceforge.plantuml.PSystemBasicFactory; +public class PSystemDitaaFactory extends PSystemBasicFactory { -public class PSystemDitaaFactory implements PSystemBasicFactory { - - private StringBuilder data; - private boolean first; - // -E,--no-separation - private boolean performSeparationOfCommonEdges; - - private final DiagramType diagramType; + // private StringBuilder data; + // // -E,--no-separation + // private boolean performSeparationOfCommonEdges; + // + // // -S,--no-shadows + // private boolean dropShadows; public PSystemDitaaFactory(DiagramType diagramType) { - this.diagramType = diagramType; + super(diagramType); } - public void init(String startLine) { - data = null; - performSeparationOfCommonEdges = true; + public PSystemDitaa init(String startLine) { + boolean performSeparationOfCommonEdges = true; if (startLine != null && (startLine.contains("-E") || startLine.contains("--no-separation"))) { performSeparationOfCommonEdges = false; } - if (diagramType == DiagramType.UML) { - first = true; - } else if (diagramType == DiagramType.DITAA) { - first = false; - data = new StringBuilder(); + boolean dropShadows = true; + if (startLine != null && (startLine.contains("-S") || startLine.contains("--no-shadows"))) { + dropShadows = false; + } + if (getDiagramType() == DiagramType.UML) { + return null; + } else if (getDiagramType() == DiagramType.DITAA) { + return new PSystemDitaa("", performSeparationOfCommonEdges, dropShadows); } else { - throw new IllegalStateException(diagramType.name()); + throw new IllegalStateException(getDiagramType().name()); } } - public boolean executeLine(String line) { - if (first && (line.equals("ditaa") || line.startsWith("ditaa("))) { - data = new StringBuilder(); + @Override + public PSystemDitaa executeLine(PSystemDitaa system, String line) { + if (system == null && (line.equals("ditaa") || line.startsWith("ditaa("))) { + boolean performSeparationOfCommonEdges = true; if (line.contains("-E") || line.contains("--no-separation")) { performSeparationOfCommonEdges = false; } - return true; + boolean dropShadows = true; + if (line.contains("-S") || line.contains("--no-shadows")) { + dropShadows = false; + } + return new PSystemDitaa("", performSeparationOfCommonEdges, dropShadows); } - first = false; - if (data == null) { - return false; - } - data.append(line); - data.append("\n"); - return true; - } - - public PSystemDitaa getSystem() { - try { - return new PSystemDitaa(data.toString(), performSeparationOfCommonEdges); - } catch (UnsupportedEncodingException e) { - e.printStackTrace(); + if (system == null) { return null; } - } - - public DiagramType getDiagramType() { - return diagramType; + return system.add(line); } } diff --git a/src/net/sourceforge/plantuml/donors/PSystemDonors.java b/src/net/sourceforge/plantuml/donors/PSystemDonors.java new file mode 100644 index 000000000..270a049b0 --- /dev/null +++ b/src/net/sourceforge/plantuml/donors/PSystemDonors.java @@ -0,0 +1,88 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.donors; + +import java.awt.Font; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.StringTokenizer; + +import net.sourceforge.plantuml.AbstractPSystem; +import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.code.Transcoder; +import net.sourceforge.plantuml.code.TranscoderImpl; +import net.sourceforge.plantuml.core.DiagramDescription; +import net.sourceforge.plantuml.core.DiagramDescriptionImpl; +import net.sourceforge.plantuml.core.ImageData; +import net.sourceforge.plantuml.graphic.GraphicPosition; +import net.sourceforge.plantuml.graphic.GraphicStrings; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.ugraphic.UAntiAliasing; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.version.PSystemVersion; + +public class PSystemDonors extends AbstractPSystem { + + public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException { + return getGraphicStrings().exportDiagram(os, fileFormat); + } + + private GraphicStrings getGraphicStrings() throws IOException { + final List lines = new ArrayList(); + lines.add("Special thanks to our sponsors and donors !"); + lines.add(" "); + final Transcoder t = new TranscoderImpl(); + final String s = t + .decode("UDfLZb4A0Z4CHF_d5FtkBG92GHOHrWjaDOk5DO6sAwodNmLBz7rbo2GpjCGlKd2M9YMGDjFCLrmaElR0O2vB1VLJdf2AhsJ3A1FNbbd3oUuAqfkLa4pQIpxZFByTtSwAWN-2jE6GkyWBo5_R4-Fg5JQa7FzHmx6tN2js5iStZG00"); + final StringTokenizer st = new StringTokenizer(s, "\n"); + while (st.hasMoreTokens()) { + lines.add(st.nextToken()); + } + lines.add(" "); + final UFont font = new UFont("SansSerif", Font.PLAIN, 12); + return new GraphicStrings(lines, font, HtmlColorUtils.BLACK, HtmlColorUtils.WHITE, + PSystemVersion.getPlantumlImage(), GraphicPosition.BACKGROUND_CORNER, UAntiAliasing.ANTI_ALIASING_ON); + } + + public DiagramDescription getDescription() { + return new DiagramDescriptionImpl("(Donors)", getClass()); + } + + public static PSystemDonors create() { + return new PSystemDonors(); + } + +} diff --git a/src/net/sourceforge/plantuml/donors/PSystemDonorsFactory.java b/src/net/sourceforge/plantuml/donors/PSystemDonorsFactory.java new file mode 100644 index 000000000..03afe1b8a --- /dev/null +++ b/src/net/sourceforge/plantuml/donors/PSystemDonorsFactory.java @@ -0,0 +1,49 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 3837 $ + * + */ +package net.sourceforge.plantuml.donors; + +import net.sourceforge.plantuml.AbstractPSystem; +import net.sourceforge.plantuml.command.PSystemSingleLineFactory; + +public class PSystemDonorsFactory extends PSystemSingleLineFactory { + + @Override + protected AbstractPSystem executeLine(String line) { + if (line.matches("(?i)^(donors)\\s*$")) { + return PSystemDonors.create(); + } + return null; + } + +} diff --git a/src/net/sourceforge/plantuml/eggs/EggUtils.java b/src/net/sourceforge/plantuml/eggs/EggUtils.java index d172fe280..35eb19cfe 100644 --- a/src/net/sourceforge/plantuml/eggs/EggUtils.java +++ b/src/net/sourceforge/plantuml/eggs/EggUtils.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.eggs; diff --git a/src/net/sourceforge/plantuml/eggs/GraphicsPath.java b/src/net/sourceforge/plantuml/eggs/GraphicsPath.java index 48a4e0e4c..ef3945685 100644 --- a/src/net/sourceforge/plantuml/eggs/GraphicsPath.java +++ b/src/net/sourceforge/plantuml/eggs/GraphicsPath.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -40,9 +40,12 @@ import java.io.IOException; import java.io.OutputStream; import net.sourceforge.plantuml.EmptyImageBuilder; -import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.api.ImageDataSimple; +import net.sourceforge.plantuml.core.ImageData; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; import net.sourceforge.plantuml.png.PngIO; import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.ugraphic.UChangeColor; import net.sourceforge.plantuml.ugraphic.UMotif; import net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d; @@ -51,29 +54,26 @@ public class GraphicsPath { private final String path; private final ColorMapper colorMapper; - // private final Font numberFont = new Font("SansSerif", Font.BOLD, 20); - // private final Font font = new Font("SansSerif", Font.PLAIN, 11); - public GraphicsPath(ColorMapper colorMapper, String path) { this.path = path; this.colorMapper = colorMapper; } - public void writeImage(OutputStream os) throws IOException { + public ImageData writeImage(OutputStream os) throws IOException { final BufferedImage im = createImage(); PngIO.write(im, os, 96); + return new ImageDataSimple(im.getWidth(), im.getHeight()); } private BufferedImage createImage() { - final EmptyImageBuilder builder = new EmptyImageBuilder(50, 50, - Color.WHITE); + final EmptyImageBuilder builder = new EmptyImageBuilder(50, 50, Color.WHITE); final BufferedImage im = builder.getBufferedImage(); final Graphics2D g2d = builder.getGraphics2D(); - - final UGraphicG2d ug = new UGraphicG2d(colorMapper, g2d, im, 1.0); - ug.getParam().setColor(HtmlColor.BLACK); + + final UGraphicG2d ug = new UGraphicG2d(colorMapper, g2d, 1.0); + ug.setBufferedImage(im); final UMotif motif = new UMotif(path); - motif.drawHorizontal(ug, 20, 20, 1); + motif.drawHorizontal(ug.apply(new UChangeColor(HtmlColorUtils.BLACK)), 20, 20, 1); g2d.dispose(); return im; diff --git a/src/net/sourceforge/plantuml/eggs/PSystemAppleTwo.java b/src/net/sourceforge/plantuml/eggs/PSystemAppleTwo.java new file mode 100644 index 000000000..b1bdeaf0a --- /dev/null +++ b/src/net/sourceforge/plantuml/eggs/PSystemAppleTwo.java @@ -0,0 +1,725 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.eggs; + +import java.awt.Font; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +import javax.imageio.ImageIO; + +import net.sourceforge.plantuml.AbstractPSystem; +import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.core.DiagramDescription; +import net.sourceforge.plantuml.core.DiagramDescriptionImpl; +import net.sourceforge.plantuml.core.ImageData; +import net.sourceforge.plantuml.graphic.GraphicPosition; +import net.sourceforge.plantuml.graphic.GraphicStrings; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.ugraphic.UAntiAliasing; +import net.sourceforge.plantuml.ugraphic.UFont; + +public class PSystemAppleTwo extends AbstractPSystem { + + private final List strings = new ArrayList(); + private final BufferedImage image; + + public PSystemAppleTwo() throws IOException { + strings.add(" Apple //e for ever!"); + strings.add(" "); + + final InputStream is = new ByteArrayInputStream(imm); + image = ImageIO.read(is); + is.close(); + } + + public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException { + return getGraphicStrings().exportDiagram(os, fileFormat); + } + + private GraphicStrings getGraphicStrings() throws IOException { + final UFont font = new UFont("SansSerif", Font.PLAIN, 12); + final GraphicStrings result = new GraphicStrings(strings, font, HtmlColorUtils.BLACK, HtmlColorUtils.WHITE, + image, GraphicPosition.BOTTOM, UAntiAliasing.ANTI_ALIASING_ON); + result.setMinWidth(200); + return result; + } + + public DiagramDescription getDescription() { + return new DiagramDescriptionImpl("(Apple //e)", getClass()); + } + + private static final byte imm[] = new byte[] { (byte) 255, (byte) 216, (byte) 255, (byte) 224, (byte) 0, (byte) 16, + (byte) 74, (byte) 70, (byte) 73, (byte) 70, (byte) 0, (byte) 1, (byte) 1, (byte) 1, (byte) 0, (byte) 96, + (byte) 0, (byte) 96, (byte) 0, (byte) 0, (byte) 255, (byte) 219, (byte) 0, (byte) 67, (byte) 0, (byte) 10, + (byte) 7, (byte) 7, (byte) 8, (byte) 7, (byte) 6, (byte) 10, (byte) 8, (byte) 8, (byte) 8, (byte) 11, + (byte) 10, (byte) 10, (byte) 11, (byte) 14, (byte) 24, (byte) 16, (byte) 14, (byte) 13, (byte) 13, + (byte) 14, (byte) 29, (byte) 21, (byte) 22, (byte) 17, (byte) 24, (byte) 35, (byte) 31, (byte) 37, + (byte) 36, (byte) 34, (byte) 31, (byte) 34, (byte) 33, (byte) 38, (byte) 43, (byte) 55, (byte) 47, + (byte) 38, (byte) 41, (byte) 52, (byte) 41, (byte) 33, (byte) 34, (byte) 48, (byte) 65, (byte) 49, + (byte) 52, (byte) 57, (byte) 59, (byte) 62, (byte) 62, (byte) 62, (byte) 37, (byte) 46, (byte) 68, + (byte) 73, (byte) 67, (byte) 60, (byte) 72, (byte) 55, (byte) 61, (byte) 62, (byte) 59, (byte) 255, + (byte) 219, (byte) 0, (byte) 67, (byte) 1, (byte) 10, (byte) 11, (byte) 11, (byte) 14, (byte) 13, + (byte) 14, (byte) 28, (byte) 16, (byte) 16, (byte) 28, (byte) 59, (byte) 40, (byte) 34, (byte) 40, + (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, + (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, + (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, + (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, + (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, + (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 59, (byte) 255, (byte) 192, (byte) 0, (byte) 17, + (byte) 8, (byte) 0, (byte) 136, (byte) 0, (byte) 200, (byte) 3, (byte) 1, (byte) 34, (byte) 0, (byte) 2, + (byte) 17, (byte) 1, (byte) 3, (byte) 17, (byte) 1, (byte) 255, (byte) 196, (byte) 0, (byte) 31, (byte) 0, + (byte) 0, (byte) 1, (byte) 5, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 0, + (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 1, (byte) 2, (byte) 3, + (byte) 4, (byte) 5, (byte) 6, (byte) 7, (byte) 8, (byte) 9, (byte) 10, (byte) 11, (byte) 255, (byte) 196, + (byte) 0, (byte) 181, (byte) 16, (byte) 0, (byte) 2, (byte) 1, (byte) 3, (byte) 3, (byte) 2, (byte) 4, + (byte) 3, (byte) 5, (byte) 5, (byte) 4, (byte) 4, (byte) 0, (byte) 0, (byte) 1, (byte) 125, (byte) 1, + (byte) 2, (byte) 3, (byte) 0, (byte) 4, (byte) 17, (byte) 5, (byte) 18, (byte) 33, (byte) 49, (byte) 65, + (byte) 6, (byte) 19, (byte) 81, (byte) 97, (byte) 7, (byte) 34, (byte) 113, (byte) 20, (byte) 50, + (byte) 129, (byte) 145, (byte) 161, (byte) 8, (byte) 35, (byte) 66, (byte) 177, (byte) 193, (byte) 21, + (byte) 82, (byte) 209, (byte) 240, (byte) 36, (byte) 51, (byte) 98, (byte) 114, (byte) 130, (byte) 9, + (byte) 10, (byte) 22, (byte) 23, (byte) 24, (byte) 25, (byte) 26, (byte) 37, (byte) 38, (byte) 39, + (byte) 40, (byte) 41, (byte) 42, (byte) 52, (byte) 53, (byte) 54, (byte) 55, (byte) 56, (byte) 57, + (byte) 58, (byte) 67, (byte) 68, (byte) 69, (byte) 70, (byte) 71, (byte) 72, (byte) 73, (byte) 74, + (byte) 83, (byte) 84, (byte) 85, (byte) 86, (byte) 87, (byte) 88, (byte) 89, (byte) 90, (byte) 99, + (byte) 100, (byte) 101, (byte) 102, (byte) 103, (byte) 104, (byte) 105, (byte) 106, (byte) 115, (byte) 116, + (byte) 117, (byte) 118, (byte) 119, (byte) 120, (byte) 121, (byte) 122, (byte) 131, (byte) 132, (byte) 133, + (byte) 134, (byte) 135, (byte) 136, (byte) 137, (byte) 138, (byte) 146, (byte) 147, (byte) 148, (byte) 149, + (byte) 150, (byte) 151, (byte) 152, (byte) 153, (byte) 154, (byte) 162, (byte) 163, (byte) 164, (byte) 165, + (byte) 166, (byte) 167, (byte) 168, (byte) 169, (byte) 170, (byte) 178, (byte) 179, (byte) 180, (byte) 181, + (byte) 182, (byte) 183, (byte) 184, (byte) 185, (byte) 186, (byte) 194, (byte) 195, (byte) 196, (byte) 197, + (byte) 198, (byte) 199, (byte) 200, (byte) 201, (byte) 202, (byte) 210, (byte) 211, (byte) 212, (byte) 213, + (byte) 214, (byte) 215, (byte) 216, (byte) 217, (byte) 218, (byte) 225, (byte) 226, (byte) 227, (byte) 228, + (byte) 229, (byte) 230, (byte) 231, (byte) 232, (byte) 233, (byte) 234, (byte) 241, (byte) 242, (byte) 243, + (byte) 244, (byte) 245, (byte) 246, (byte) 247, (byte) 248, (byte) 249, (byte) 250, (byte) 255, (byte) 196, + (byte) 0, (byte) 31, (byte) 1, (byte) 0, (byte) 3, (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 1, + (byte) 1, (byte) 1, (byte) 1, (byte) 1, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0, + (byte) 1, (byte) 2, (byte) 3, (byte) 4, (byte) 5, (byte) 6, (byte) 7, (byte) 8, (byte) 9, (byte) 10, + (byte) 11, (byte) 255, (byte) 196, (byte) 0, (byte) 181, (byte) 17, (byte) 0, (byte) 2, (byte) 1, (byte) 2, + (byte) 4, (byte) 4, (byte) 3, (byte) 4, (byte) 7, (byte) 5, (byte) 4, (byte) 4, (byte) 0, (byte) 1, + (byte) 2, (byte) 119, (byte) 0, (byte) 1, (byte) 2, (byte) 3, (byte) 17, (byte) 4, (byte) 5, (byte) 33, + (byte) 49, (byte) 6, (byte) 18, (byte) 65, (byte) 81, (byte) 7, (byte) 97, (byte) 113, (byte) 19, + (byte) 34, (byte) 50, (byte) 129, (byte) 8, (byte) 20, (byte) 66, (byte) 145, (byte) 161, (byte) 177, + (byte) 193, (byte) 9, (byte) 35, (byte) 51, (byte) 82, (byte) 240, (byte) 21, (byte) 98, (byte) 114, + (byte) 209, (byte) 10, (byte) 22, (byte) 36, (byte) 52, (byte) 225, (byte) 37, (byte) 241, (byte) 23, + (byte) 24, (byte) 25, (byte) 26, (byte) 38, (byte) 39, (byte) 40, (byte) 41, (byte) 42, (byte) 53, + (byte) 54, (byte) 55, (byte) 56, (byte) 57, (byte) 58, (byte) 67, (byte) 68, (byte) 69, (byte) 70, + (byte) 71, (byte) 72, (byte) 73, (byte) 74, (byte) 83, (byte) 84, (byte) 85, (byte) 86, (byte) 87, + (byte) 88, (byte) 89, (byte) 90, (byte) 99, (byte) 100, (byte) 101, (byte) 102, (byte) 103, (byte) 104, + (byte) 105, (byte) 106, (byte) 115, (byte) 116, (byte) 117, (byte) 118, (byte) 119, (byte) 120, (byte) 121, + (byte) 122, (byte) 130, (byte) 131, (byte) 132, (byte) 133, (byte) 134, (byte) 135, (byte) 136, (byte) 137, + (byte) 138, (byte) 146, (byte) 147, (byte) 148, (byte) 149, (byte) 150, (byte) 151, (byte) 152, (byte) 153, + (byte) 154, (byte) 162, (byte) 163, (byte) 164, (byte) 165, (byte) 166, (byte) 167, (byte) 168, (byte) 169, + (byte) 170, (byte) 178, (byte) 179, (byte) 180, (byte) 181, (byte) 182, (byte) 183, (byte) 184, (byte) 185, + (byte) 186, (byte) 194, (byte) 195, (byte) 196, (byte) 197, (byte) 198, (byte) 199, (byte) 200, (byte) 201, + (byte) 202, (byte) 210, (byte) 211, (byte) 212, (byte) 213, (byte) 214, (byte) 215, (byte) 216, (byte) 217, + (byte) 218, (byte) 226, (byte) 227, (byte) 228, (byte) 229, (byte) 230, (byte) 231, (byte) 232, (byte) 233, + (byte) 234, (byte) 242, (byte) 243, (byte) 244, (byte) 245, (byte) 246, (byte) 247, (byte) 248, (byte) 249, + (byte) 250, (byte) 255, (byte) 218, (byte) 0, (byte) 12, (byte) 3, (byte) 1, (byte) 0, (byte) 2, (byte) 17, + (byte) 3, (byte) 17, (byte) 0, (byte) 63, (byte) 0, (byte) 246, (byte) 106, (byte) 40, (byte) 162, + (byte) 128, (byte) 10, (byte) 40, (byte) 162, (byte) 128, (byte) 43, (byte) 221, (byte) 92, (byte) 253, + (byte) 153, (byte) 3, (byte) 121, (byte) 79, (byte) 41, (byte) 39, (byte) 133, (byte) 66, (byte) 185, + (byte) 253, (byte) 72, (byte) 21, (byte) 145, (byte) 115, (byte) 173, (byte) 106, (byte) 157, (byte) 45, + (byte) 180, (byte) 146, (byte) 191, (byte) 237, (byte) 73, (byte) 42, (byte) 31, (byte) 208, (byte) 55, + (byte) 245, (byte) 173, (byte) 59, (byte) 225, (byte) 157, (byte) 159, (byte) 83, (byte) 92, (byte) 61, + (byte) 182, (byte) 181, (byte) 169, (byte) 181, (byte) 149, (byte) 188, (byte) 243, (byte) 223, (byte) 91, + (byte) 71, (byte) 44, (byte) 209, (byte) 171, (byte) 149, (byte) 54, (byte) 228, (byte) 129, (byte) 144, + (byte) 9, (byte) 254, (byte) 44, (byte) 247, (byte) 245, (byte) 172, (byte) 165, (byte) 39, (byte) 114, + (byte) 210, (byte) 69, (byte) 251, (byte) 155, (byte) 239, (byte) 19, (byte) 78, (byte) 113, (byte) 135, + (byte) 133, (byte) 79, (byte) 240, (byte) 196, (byte) 168, (byte) 63, (byte) 92, (byte) 147, (byte) 250, + (byte) 213, (byte) 80, (byte) 254, (byte) 34, (byte) 67, (byte) 129, (byte) 53, (byte) 222, (byte) 115, + (byte) 221, (byte) 203, (byte) 127, (byte) 141, (byte) 52, (byte) 107, (byte) 183, (byte) 185, (byte) 192, + (byte) 213, (byte) 180, (byte) 188, (byte) 142, (byte) 205, (byte) 106, (byte) 223, (byte) 252, (byte) 120, + (byte) 84, (byte) 131, (byte) 90, (byte) 212, (byte) 63, (byte) 232, (byte) 41, (byte) 164, (byte) 127, + (byte) 224, (byte) 51, (byte) 127, (byte) 241, (byte) 250, (byte) 139, (byte) 190, (byte) 229, (byte) 104, + (byte) 39, (byte) 159, (byte) 226, (byte) 64, (byte) 120, (byte) 158, (byte) 232, (byte) 255, (byte) 0, + (byte) 192, (byte) 88, (byte) 255, (byte) 0, (byte) 74, (byte) 67, (byte) 121, (byte) 226, (byte) 96, + (byte) 121, (byte) 158, (byte) 243, (byte) 131, (byte) 198, (byte) 32, (byte) 110, (byte) 127, (byte) 241, + (byte) 202, (byte) 144, (byte) 107, (byte) 119, (byte) 223, (byte) 244, (byte) 16, (byte) 210, (byte) 88, + (byte) 250, (byte) 8, (byte) 136, (byte) 255, (byte) 0, (byte) 218, (byte) 198, (byte) 158, (byte) 53, + (byte) 203, (byte) 220, (byte) 224, (byte) 73, (byte) 167, (byte) 183, (byte) 209, (byte) 138, (byte) 255, + (byte) 0, (byte) 83, (byte) 74, (byte) 236, (byte) 44, (byte) 66, (byte) 53, (byte) 63, (byte) 18, + (byte) 131, (byte) 180, (byte) 205, (byte) 121, (byte) 248, (byte) 218, (byte) 31, (byte) 254, (byte) 34, + (byte) 156, (byte) 53, (byte) 143, (byte) 16, (byte) 142, (byte) 179, (byte) 207, (byte) 199, (byte) 247, + (byte) 173, (byte) 64, (byte) 254, (byte) 105, (byte) 86, (byte) 6, (byte) 181, (byte) 169, (byte) 127, + (byte) 207, (byte) 173, (byte) 131, (byte) 255, (byte) 0, (byte) 219, (byte) 211, (byte) 47, (byte) 254, + (byte) 211, (byte) 52, (byte) 241, (byte) 172, (byte) 234, (byte) 196, (byte) 241, (byte) 166, (byte) 88, + (byte) 48, (byte) 246, (byte) 191, (byte) 147, (byte) 255, (byte) 0, (byte) 140, (byte) 83, (byte) 187, + (byte) 2, (byte) 161, (byte) 215, (byte) 181, (byte) 213, (byte) 25, (byte) 55, (byte) 79, (byte) 248, + (byte) 194, (byte) 131, (byte) 255, (byte) 0, (byte) 101, (byte) 163, (byte) 254, (byte) 18, (byte) 61, + (byte) 100, (byte) 114, (byte) 110, (byte) 112, (byte) 61, (byte) 227, (byte) 65, (byte) 253, (byte) 42, + (byte) 231, (byte) 246, (byte) 206, (byte) 168, (byte) 57, (byte) 109, (byte) 46, (byte) 215, (byte) 254, + (byte) 3, (byte) 122, (byte) 231, (byte) 255, (byte) 0, (byte) 104, (byte) 138, (byte) 81, (byte) 175, + (byte) 95, (byte) 15, (byte) 189, (byte) 166, (byte) 1, (byte) 254, (byte) 237, (byte) 206, (byte) 127, + (byte) 154, (byte) 138, (byte) 46, (byte) 251, (byte) 133, (byte) 151, (byte) 98, (byte) 160, (byte) 241, + (byte) 54, (byte) 172, (byte) 188, (byte) 153, (byte) 227, (byte) 56, (byte) 245, (byte) 9, (byte) 82, + (byte) 47, (byte) 136, (byte) 181, (byte) 210, (byte) 55, (byte) 36, (byte) 45, (byte) 34, (byte) 255, + (byte) 0, (byte) 121, (byte) 45, (byte) 139, (byte) 143, (byte) 204, (byte) 86, (byte) 134, (byte) 153, + (byte) 172, (byte) 46, (byte) 177, (byte) 101, (byte) 117, (byte) 34, (byte) 197, (byte) 36, (byte) 45, + (byte) 4, (byte) 175, (byte) 4, (byte) 138, (byte) 236, (byte) 15, (byte) 204, (byte) 160, (byte) 19, + (byte) 211, (byte) 168, (byte) 230, (byte) 132, (byte) 211, (byte) 165, (byte) 142, (byte) 118, (byte) 104, + (byte) 239, (byte) 25, (byte) 119, (byte) 73, (byte) 189, (byte) 129, (byte) 81, (byte) 202, (byte) 231, + (byte) 59, (byte) 126, (byte) 152, (byte) 226, (byte) 142, (byte) 103, (byte) 220, (byte) 44, (byte) 140, + (byte) 209, (byte) 226, (byte) 173, (byte) 88, (byte) 16, (byte) 79, (byte) 144, (byte) 65, (byte) 231, + (byte) 5, (byte) 63, (byte) 250, (byte) 249, (byte) 167, (byte) 127, (byte) 194, (byte) 95, (byte) 169, + (byte) 47, (byte) 38, (byte) 43, (byte) 102, (byte) 3, (byte) 146, (byte) 54, (byte) 48, (byte) 255, + (byte) 0, (byte) 217, (byte) 171, (byte) 50, (byte) 225, (byte) 118, (byte) 201, (byte) 34, (byte) 246, + (byte) 87, (byte) 35, (byte) 167, (byte) 185, (byte) 170, (byte) 237, (byte) 83, (byte) 205, (byte) 46, + (byte) 227, (byte) 178, (byte) 61, (byte) 58, (byte) 55, (byte) 89, (byte) 35, (byte) 87, (byte) 83, + (byte) 149, (byte) 97, (byte) 144, (byte) 125, (byte) 69, (byte) 62, (byte) 178, (byte) 252, (byte) 61, + (byte) 113, (byte) 246, (byte) 141, (byte) 14, (byte) 217, (byte) 179, (byte) 146, (byte) 139, (byte) 229, + (byte) 159, (byte) 248, (byte) 9, (byte) 199, (byte) 242, (byte) 197, (byte) 106, (byte) 87, (byte) 74, + (byte) 119, (byte) 70, (byte) 33, (byte) 69, (byte) 20, (byte) 83, (byte) 0, (byte) 162, (byte) 138, + (byte) 40, (byte) 0, (byte) 162, (byte) 138, (byte) 40, (byte) 0, (byte) 162, (byte) 138, (byte) 40, + (byte) 0, (byte) 162, (byte) 138, (byte) 40, (byte) 2, (byte) 181, (byte) 224, (byte) 253, (byte) 218, + (byte) 253, (byte) 107, (byte) 202, (byte) 245, (byte) 112, (byte) 97, (byte) 142, (byte) 201, (byte) 84, + (byte) 227, (byte) 98, (byte) 178, (byte) 140, (byte) 123, (byte) 96, (byte) 127, (byte) 74, (byte) 245, + (byte) 91, (byte) 177, (byte) 152, (byte) 135, (byte) 177, (byte) 175, (byte) 46, (byte) 241, (byte) 26, + (byte) 20, (byte) 158, (byte) 37, (byte) 56, (byte) 225, (byte) 229, (byte) 0, (byte) 99, (byte) 253, + (byte) 161, (byte) 88, (byte) 207, (byte) 114, (byte) 227, (byte) 177, (byte) 199, (byte) 94, (byte) 11, + (byte) 155, (byte) 251, (byte) 249, (byte) 101, (byte) 121, (byte) 164, (byte) 42, (byte) 174, (byte) 81, + (byte) 20, (byte) 49, (byte) 194, (byte) 237, (byte) 249, (byte) 78, (byte) 7, (byte) 185, (byte) 6, + (byte) 180, (byte) 52, (byte) 125, (byte) 58, (byte) 53, (byte) 156, (byte) 25, (byte) 162, (byte) 71, + (byte) 207, (byte) 247, (byte) 192, (byte) 111, (byte) 231, (byte) 78, (byte) 181, (byte) 69, (byte) 49, + (byte) 22, (byte) 199, (byte) 223, (byte) 146, (byte) 70, (byte) 252, (byte) 221, (byte) 143, (byte) 245, + (byte) 171, (byte) 208, (byte) 29, (byte) 146, (byte) 2, (byte) 43, (byte) 101, (byte) 162, (byte) 49, + (byte) 111, (byte) 83, (byte) 164, (byte) 131, (byte) 72, (byte) 181, (byte) 104, (byte) 195, (byte) 44, + (byte) 17, (byte) 129, (byte) 140, (byte) 240, (byte) 130, (byte) 164, (byte) 146, (byte) 194, (byte) 203, + (byte) 162, (byte) 194, (byte) 83, (byte) 28, (byte) 96, (byte) 128, (byte) 217, (byte) 231, (byte) 175, + (byte) 229, (byte) 69, (byte) 133, (byte) 223, (byte) 238, (byte) 128, (byte) 207, (byte) 106, (byte) 145, + (byte) 229, (byte) 6, (byte) 168, (byte) 30, (byte) 166, (byte) 117, (byte) 214, (byte) 159, (byte) 0, + (byte) 145, (byte) 188, (byte) 164, (byte) 194, (byte) 103, (byte) 140, (byte) 129, (byte) 156, (byte) 126, + (byte) 21, (byte) 151, (byte) 113, (byte) 96, (byte) 64, (byte) 37, (byte) 93, (byte) 212, (byte) 255, + (byte) 0, (byte) 178, (byte) 228, (byte) 127, (byte) 90, (byte) 218, (byte) 185, (byte) 151, (byte) 142, + (byte) 43, (byte) 53, (byte) 230, (byte) 39, (byte) 140, (byte) 210, (byte) 29, (byte) 236, (byte) 97, + (byte) 77, (byte) 29, (byte) 228, (byte) 71, (byte) 228, (byte) 185, (byte) 153, (byte) 123, (byte) 242, + (byte) 217, (byte) 254, (byte) 117, (byte) 99, (byte) 64, (byte) 188, (byte) 212, (byte) 134, (byte) 187, + (byte) 107, (byte) 12, (byte) 215, (byte) 38, (byte) 104, (byte) 100, (byte) 44, (byte) 25, (byte) 89, + (byte) 20, (byte) 17, (byte) 242, (byte) 147, (byte) 144, (byte) 64, (byte) 29, (byte) 197, (byte) 93, + (byte) 145, (byte) 65, (byte) 228, (byte) 210, (byte) 105, (byte) 113, (byte) 168, (byte) 214, (byte) 109, + (byte) 155, (byte) 28, (byte) 135, (byte) 63, (byte) 250, (byte) 9, (byte) 169, (byte) 146, (byte) 86, + (byte) 8, (byte) 201, (byte) 220, (byte) 234, (byte) 124, (byte) 34, (byte) 127, (byte) 119, (byte) 173, + (byte) 199, (byte) 233, (byte) 168, (byte) 74, (byte) 223, (byte) 154, (byte) 175, (byte) 248, (byte) 87, + (byte) 79, (byte) 92, (byte) 199, (byte) 132, (byte) 191, (byte) 227, (byte) 243, (byte) 93, (byte) 143, + (byte) 176, (byte) 187, (byte) 45, (byte) 215, (byte) 212, (byte) 176, (byte) 254, (byte) 149, (byte) 211, + (byte) 175, (byte) 32, (byte) 31, (byte) 106, (byte) 230, (byte) 55, (byte) 56, (byte) 219, (byte) 209, + (byte) 139, (byte) 139, (byte) 128, (byte) 58, (byte) 9, (byte) 152, (byte) 126, (byte) 166, (byte) 170, + (byte) 53, (byte) 93, (byte) 212, (byte) 70, (byte) 46, (byte) 238, (byte) 127, (byte) 235, (byte) 187, + (byte) 255, (byte) 0, (byte) 232, (byte) 77, (byte) 84, (byte) 24, (byte) 212, (byte) 148, (byte) 117, + (byte) 126, (byte) 12, (byte) 184, (byte) 6, (byte) 11, (byte) 155, (byte) 98, (byte) 126, (byte) 235, + (byte) 135, (byte) 25, (byte) 247, (byte) 24, (byte) 254, (byte) 131, (byte) 243, (byte) 174, (byte) 162, + (byte) 184, (byte) 63, (byte) 10, (byte) 220, (byte) 121, (byte) 26, (byte) 226, (byte) 33, (byte) 56, + (byte) 19, (byte) 163, (byte) 39, (byte) 63, (byte) 159, (byte) 244, (byte) 174, (byte) 238, (byte) 186, + (byte) 105, (byte) 187, (byte) 196, (byte) 202, (byte) 75, (byte) 81, (byte) 104, (byte) 162, (byte) 138, + (byte) 178, (byte) 66, (byte) 138, (byte) 40, (byte) 160, (byte) 2, (byte) 138, (byte) 40, (byte) 160, + (byte) 2, (byte) 138, (byte) 40, (byte) 160, (byte) 2, (byte) 138, (byte) 40, (byte) 160, (byte) 10, + (byte) 247, (byte) 127, (byte) 234, (byte) 9, (byte) 244, (byte) 34, (byte) 188, (byte) 215, (byte) 197, + (byte) 75, (byte) 139, (byte) 248, (byte) 135, (byte) 253, (byte) 52, (byte) 148, (byte) 127, (byte) 227, + (byte) 194, (byte) 189, (byte) 50, (byte) 228, (byte) 102, (byte) 221, (byte) 171, (byte) 205, (byte) 124, + (byte) 87, (byte) 197, (byte) 236, (byte) 39, (byte) 254, (byte) 154, (byte) 74, (byte) 127, (byte) 85, + (byte) 172, (byte) 103, (byte) 185, (byte) 113, (byte) 216, (byte) 229, (byte) 108, (byte) 159, (byte) 253, + (byte) 10, (byte) 220, (byte) 250, (byte) 198, (byte) 191, (byte) 202, (byte) 174, (byte) 198, (byte) 220, + (byte) 138, (byte) 205, (byte) 180, (byte) 56, (byte) 180, (byte) 128, (byte) 122, (byte) 32, (byte) 31, + (byte) 149, (byte) 91, (byte) 141, (byte) 186, (byte) 86, (byte) 199, (byte) 59, (byte) 220, (byte) 232, + (byte) 109, (byte) 37, (byte) 2, (byte) 33, (byte) 207, (byte) 52, (byte) 247, (byte) 185, (byte) 219, + (byte) 222, (byte) 179, (byte) 160, (byte) 124, (byte) 39, (byte) 90, (byte) 116, (byte) 143, (byte) 129, + (byte) 78, (byte) 227, (byte) 38, (byte) 146, (byte) 125, (byte) 245, (byte) 3, (byte) 250, (byte) 211, + (byte) 21, (byte) 179, (byte) 77, (byte) 145, (byte) 248, (byte) 160, (byte) 67, (byte) 36, (byte) 147, + (byte) 60, (byte) 84, (byte) 186, (byte) 79, (byte) 58, (byte) 189, (byte) 184, (byte) 245, (byte) 111, + (byte) 232, (byte) 106, (byte) 163, (byte) 18, (byte) 77, (byte) 90, (byte) 210, (byte) 71, (byte) 252, + (byte) 77, (byte) 109, (byte) 191, (byte) 223, (byte) 254, (byte) 148, (byte) 158, (byte) 195, (byte) 91, + (byte) 157, (byte) 79, (byte) 132, (byte) 255, (byte) 0, (byte) 228, (byte) 51, (byte) 174, (byte) 175, + (byte) 253, (byte) 54, (byte) 67, (byte) 249, (byte) 188, (byte) 191, (byte) 225, (byte) 93, (byte) 60, + (byte) 99, (byte) 247, (byte) 106, (byte) 79, (byte) 112, (byte) 43, (byte) 150, (byte) 240, (byte) 153, + (byte) 198, (byte) 187, (byte) 173, (byte) 251, (byte) 200, (byte) 191, (byte) 250, (byte) 28, (byte) 191, + (byte) 227, (byte) 93, (byte) 76, (byte) 103, (byte) 247, (byte) 72, (byte) 48, (byte) 79, (byte) 202, + (byte) 58, (byte) 125, (byte) 43, (byte) 152, (byte) 232, (byte) 103, (byte) 35, (byte) 170, (byte) 140, + (byte) 94, (byte) 220, (byte) 15, (byte) 250, (byte) 106, (byte) 199, (byte) 245, (byte) 53, (byte) 154, + (byte) 213, (byte) 161, (byte) 172, (byte) 200, (byte) 201, (byte) 172, (byte) 79, (byte) 27, (byte) 40, + (byte) 40, (byte) 228, (byte) 237, (byte) 97, (byte) 215, (byte) 119, (byte) 4, (byte) 254, (byte) 24, + (byte) 34, (byte) 179, (byte) 92, (byte) 212, (byte) 50, (byte) 209, (byte) 53, (byte) 140, (byte) 205, + (byte) 14, (byte) 161, (byte) 109, (byte) 34, (byte) 156, (byte) 21, (byte) 153, (byte) 79, (byte) 235, + (byte) 94, (byte) 159, (byte) 94, (byte) 79, (byte) 19, (byte) 133, (byte) 184, (byte) 141, (byte) 137, + (byte) 198, (byte) 28, (byte) 28, (byte) 231, (byte) 222, (byte) 189, (byte) 96, (byte) 86, (byte) 244, + (byte) 182, (byte) 51, (byte) 152, (byte) 180, (byte) 81, (byte) 69, (byte) 106, (byte) 64, (byte) 81, + (byte) 69, (byte) 20, (byte) 0, (byte) 81, (byte) 69, (byte) 20, (byte) 0, (byte) 81, (byte) 69, (byte) 20, + (byte) 0, (byte) 81, (byte) 69, (byte) 20, (byte) 1, (byte) 28, (byte) 195, (byte) 48, (byte) 191, + (byte) 210, (byte) 188, (byte) 215, (byte) 198, (byte) 3, (byte) 253, (byte) 34, (byte) 31, (byte) 247, + (byte) 165, (byte) 255, (byte) 0, (byte) 217, (byte) 107, (byte) 210, (byte) 228, (byte) 25, (byte) 141, + (byte) 135, (byte) 168, (byte) 175, (byte) 55, (byte) 241, (byte) 136, (byte) 255, (byte) 0, (byte) 72, + (byte) 132, (byte) 255, (byte) 0, (byte) 181, (byte) 39, (byte) 254, (byte) 201, (byte) 89, (byte) 79, + (byte) 114, (byte) 226, (byte) 112, (byte) 240, (byte) 182, (byte) 17, (byte) 151, (byte) 251, (byte) 146, + (byte) 200, (byte) 191, (byte) 147, (byte) 176, (byte) 171, (byte) 49, (byte) 190, (byte) 42, (byte) 175, + (byte) 221, (byte) 185, (byte) 158, (byte) 62, (byte) 226, (byte) 82, (byte) 199, (byte) 254, (byte) 5, + (byte) 134, (byte) 255, (byte) 0, (byte) 217, (byte) 170, (byte) 236, (byte) 54, (byte) 238, (byte) 216, + (byte) 35, (byte) 161, (byte) 173, (byte) 86, (byte) 198, (byte) 13, (byte) 106, (byte) 93, (byte) 134, + (byte) 76, (byte) 12, (byte) 158, (byte) 148, (byte) 231, (byte) 155, (byte) 119, (byte) 21, (byte) 25, + (byte) 2, (byte) 40, (byte) 241, (byte) 222, (byte) 171, (byte) 249, (byte) 148, (byte) 192, (byte) 176, + (byte) 37, (byte) 197, (byte) 33, (byte) 147, (byte) 53, (byte) 84, (byte) 189, (byte) 39, (byte) 155, + (byte) 72, (byte) 46, (byte) 88, (byte) 105, (byte) 0, (byte) 171, (byte) 122, (byte) 83, (byte) 143, + (byte) 237, (byte) 75, (byte) 111, (byte) 250, (byte) 232, (byte) 5, (byte) 101, (byte) 51, (byte) 213, + (byte) 253, (byte) 24, (byte) 238, (byte) 213, (byte) 109, (byte) 6, (byte) 122, (byte) 201, (byte) 252, + (byte) 129, (byte) 63, (byte) 210, (byte) 147, (byte) 216, (byte) 22, (byte) 231, (byte) 85, (byte) 225, + (byte) 118, (byte) 199, (byte) 136, (byte) 245, (byte) 81, (byte) 234, (byte) 73, (byte) 252, (byte) 164, + (byte) 111, (byte) 241, (byte) 174, (byte) 186, (byte) 48, (byte) 60, (byte) 181, (byte) 200, (byte) 228, + (byte) 10, (byte) 227, (byte) 60, (byte) 52, (byte) 216, (byte) 241, (byte) 93, (byte) 242, (byte) 250, + (byte) 199, (byte) 43, (byte) 126, (byte) 82, (byte) 175, (byte) 248, (byte) 215, (byte) 103, (byte) 23, + (byte) 220, (byte) 252, (byte) 127, (byte) 173, (byte) 115, (byte) 35, (byte) 162, (byte) 71, (byte) 39, + (byte) 173, (byte) 32, (byte) 26, (byte) 165, (byte) 219, (byte) 115, (byte) 146, (byte) 16, (byte) 117, + (byte) 246, (byte) 83, (byte) 254, (byte) 126, (byte) 130, (byte) 177, (byte) 166, (byte) 32, (byte) 119, + (byte) 226, (byte) 182, (byte) 124, (byte) 69, (byte) 32, (byte) 139, (byte) 81, (byte) 186, (byte) 245, + (byte) 33, (byte) 14, (byte) 63, (byte) 5, (byte) 172, (byte) 24, (byte) 109, (byte) 47, (byte) 53, + (byte) 55, (byte) 253, (byte) 218, (byte) 236, (byte) 132, (byte) 28, (byte) 25, (byte) 24, (byte) 113, + (byte) 248, (byte) 122, (byte) 159, (byte) 242, (byte) 113, (byte) 72, (byte) 181, (byte) 177, (byte) 93, + (byte) 167, (byte) 253, (byte) 224, (byte) 84, (byte) 203, (byte) 49, (byte) 56, (byte) 0, (byte) 117, + (byte) 39, (byte) 210, (byte) 189, (byte) 58, (byte) 231, (byte) 196, (byte) 54, (byte) 176, (byte) 79, + (byte) 229, (byte) 162, (byte) 60, (byte) 216, (byte) 234, (byte) 202, (byte) 64, (byte) 31, (byte) 175, + (byte) 90, (byte) 229, (byte) 116, (byte) 253, (byte) 34, (byte) 11, (byte) 33, (byte) 242, (byte) 21, + (byte) 18, (byte) 145, (byte) 204, (byte) 178, (byte) 2, (byte) 73, (byte) 250, (byte) 96, (byte) 112, + (byte) 61, (byte) 191, (byte) 60, (byte) 213, (byte) 209, (byte) 106, (byte) 63, (byte) 231, (byte) 162, + (byte) 49, (byte) 250, (byte) 31, (byte) 234, (byte) 42, (byte) 226, (byte) 218, (byte) 37, (byte) 171, + (byte) 238, (byte) 110, (byte) 175, (byte) 136, (byte) 45, (byte) 207, (byte) 222, (byte) 133, (byte) 199, + (byte) 210, (byte) 88, (byte) 207, (byte) 254, (byte) 205, (byte) 82, (byte) 13, (byte) 114, (byte) 212, + (byte) 255, (byte) 0, (byte) 4, (byte) 191, (byte) 130, (byte) 134, (byte) 254, (byte) 68, (byte) 215, + (byte) 62, (byte) 45, (byte) 155, (byte) 213, (byte) 63, (byte) 25, (byte) 20, (byte) 127, (byte) 51, + (byte) 71, (byte) 217, (byte) 155, (byte) 217, (byte) 190, (byte) 142, (byte) 15, (byte) 245, (byte) 167, + (byte) 207, (byte) 33, (byte) 114, (byte) 163, (byte) 164, (byte) 26, (byte) 189, (byte) 169, (byte) 237, + (byte) 48, (byte) 250, (byte) 192, (byte) 255, (byte) 0, (byte) 225, (byte) 75, (byte) 253, (byte) 175, + (byte) 99, (byte) 156, (byte) 25, (byte) 246, (byte) 159, (byte) 246, (byte) 145, (byte) 135, (byte) 243, + (byte) 21, (byte) 203, (byte) 152, (byte) 121, (byte) 195, (byte) 46, (byte) 8, (byte) 235, (byte) 145, + (byte) 72, (byte) 242, (byte) 164, (byte) 67, (byte) 229, (byte) 33, (byte) 219, (byte) 182, (byte) 41, + (byte) 169, (byte) 177, (byte) 114, (byte) 163, (byte) 174, (byte) 183, (byte) 189, (byte) 182, (byte) 186, + (byte) 37, (byte) 96, (byte) 157, (byte) 36, (byte) 101, (byte) 25, (byte) 32, (byte) 30, (byte) 69, + (byte) 21, (byte) 129, (byte) 225, (byte) 167, (byte) 102, (byte) 212, (byte) 102, (byte) 220, (byte) 73, + (byte) 38, (byte) 46, (byte) 191, (byte) 66, (byte) 63, (byte) 198, (byte) 138, (byte) 210, (byte) 46, + (byte) 234, (byte) 228, (byte) 181, (byte) 99, (byte) 168, (byte) 162, (byte) 138, (byte) 42, (byte) 132, + (byte) 20, (byte) 81, (byte) 69, (byte) 0, (byte) 53, (byte) 134, (byte) 65, (byte) 30, (byte) 162, + (byte) 184, (byte) 63, (byte) 17, (byte) 216, (byte) 75, (byte) 125, (byte) 118, (byte) 60, (byte) 160, + (byte) 27, (byte) 203, (byte) 39, (byte) 43, (byte) 144, (byte) 51, (byte) 144, (byte) 190, (byte) 191, + (byte) 74, (byte) 239, (byte) 24, (byte) 133, (byte) 4, (byte) 146, (byte) 0, (byte) 3, (byte) 36, + (byte) 154, (byte) 228, (byte) 117, (byte) 41, (byte) 188, (byte) 61, (byte) 125, (byte) 40, (byte) 55, + (byte) 83, (byte) 72, (byte) 207, (byte) 16, (byte) 40, (byte) 36, (byte) 141, (byte) 102, (byte) 78, + (byte) 255, (byte) 0, (byte) 222, (byte) 80, (byte) 1, (byte) 233, (byte) 235, (byte) 89, (byte) 84, + (byte) 42, (byte) 39, (byte) 23, (byte) 123, (byte) 225, (byte) 171, (byte) 201, (byte) 231, (byte) 19, + (byte) 165, (byte) 179, (byte) 68, (byte) 224, (byte) 96, (byte) 149, (byte) 145, (byte) 8, (byte) 108, + (byte) 116, (byte) 200, (byte) 207, (byte) 63, (byte) 134, (byte) 63, (byte) 149, (byte) 39, (byte) 246, + (byte) 118, (byte) 167, (byte) 18, (byte) 5, (byte) 22, (byte) 146, (byte) 57, (byte) 232, (byte) 74, + (byte) 198, (byte) 216, (byte) 253, (byte) 51, (byte) 93, (byte) 71, (byte) 217, (byte) 124, (byte) 49, + (byte) 252, (byte) 26, (byte) 244, (byte) 144, (byte) 158, (byte) 152, (byte) 125, (byte) 102, (byte) 81, + (byte) 250, (byte) 59, (byte) 212, (byte) 145, (byte) 233, (byte) 118, (byte) 115, (byte) 241, (byte) 103, + (byte) 226, (byte) 121, (byte) 219, (byte) 61, (byte) 60, (byte) 185, (byte) 160, (byte) 155, (byte) 255, + (byte) 0, (byte) 66, (byte) 86, (byte) 169, (byte) 83, (byte) 104, (byte) 171, (byte) 38, (byte) 113, + (byte) 83, (byte) 218, (byte) 223, (byte) 15, (byte) 191, (byte) 105, (byte) 34, (byte) 253, (byte) 84, + (byte) 143, (byte) 253, (byte) 8, (byte) 10, (byte) 164, (byte) 203, (byte) 42, (byte) 253, (byte) 232, + (byte) 219, (byte) 240, (byte) 32, (byte) 255, (byte) 0, (byte) 42, (byte) 244, (byte) 143, (byte) 248, + (byte) 71, (byte) 245, (byte) 56, (byte) 190, (byte) 104, (byte) 245, (byte) 105, (byte) 95, (byte) 143, + (byte) 249, (byte) 109, (byte) 111, (byte) 30, (byte) 63, (byte) 241, (byte) 213, (byte) 90, (byte) 67, + (byte) 166, (byte) 107, (byte) 153, (byte) 255, (byte) 0, (byte) 143, (byte) 251, (byte) 22, (byte) 29, + (byte) 54, (byte) 155, (byte) 103, (byte) 255, (byte) 0, (byte) 227, (byte) 148, (byte) 253, (byte) 161, + (byte) 62, (byte) 205, (byte) 30, (byte) 108, (byte) 86, (byte) 99, (byte) 210, (byte) 9, (byte) 143, + (byte) 210, (byte) 38, (byte) 255, (byte) 0, (byte) 10, (byte) 102, (byte) 38, (byte) 255, (byte) 0, + (byte) 158, (byte) 19, (byte) 127, (byte) 223, (byte) 166, (byte) 255, (byte) 0, (byte) 10, (byte) 244, + (byte) 71, (byte) 211, (byte) 117, (byte) 126, (byte) 127, (byte) 208, (byte) 52, (byte) 185, (byte) 207, + (byte) 171, (byte) 59, (byte) 39, (byte) 254, (byte) 200, (byte) 213, (byte) 3, (byte) 216, (byte) 234, + (byte) 73, (byte) 247, (byte) 252, (byte) 57, (byte) 167, (byte) 185, (byte) 207, (byte) 252, (byte) 177, + (byte) 185, (byte) 25, (byte) 253, (byte) 98, (byte) 20, (byte) 253, (byte) 160, (byte) 189, (byte) 154, + (byte) 56, (byte) 34, (byte) 179, (byte) 127, (byte) 207, (byte) 9, (byte) 191, (byte) 239, (byte) 211, + (byte) 127, (byte) 133, (byte) 106, (byte) 248, (byte) 126, (byte) 25, (byte) 155, (byte) 92, (byte) 180, + (byte) 38, (byte) 25, (byte) 2, (byte) 161, (byte) 102, (byte) 102, (byte) 101, (byte) 35, (byte) 31, + (byte) 35, (byte) 122, (byte) 245, (byte) 231, (byte) 21, (byte) 209, (byte) 73, (byte) 107, (byte) 56, + (byte) 255, (byte) 0, (byte) 91, (byte) 225, (byte) 75, (byte) 156, (byte) 122, (byte) 197, (byte) 60, + (byte) 68, (byte) 127, (byte) 232, (byte) 98, (byte) 155, (byte) 11, (byte) 219, (byte) 90, (byte) 74, + (byte) 37, (byte) 254, (byte) 195, (byte) 213, (byte) 33, (byte) 96, (byte) 15, (byte) 34, (byte) 35, + (byte) 39, (byte) 111, (byte) 246, (byte) 93, (byte) 168, (byte) 117, (byte) 52, (byte) 26, (byte) 133, + (byte) 152, (byte) 190, (byte) 26, (byte) 111, (byte) 248, (byte) 172, (byte) 46, (byte) 125, (byte) 224, + (byte) 159, (byte) 255, (byte) 0, (byte) 70, (byte) 199, (byte) 93, (byte) 188, (byte) 127, (byte) 112, + (byte) 253, (byte) 79, (byte) 243, (byte) 174, (byte) 19, (byte) 195, (byte) 2, (byte) 87, (byte) 241, + (byte) 91, (byte) 74, (byte) 109, (byte) 174, (byte) 163, (byte) 83, (byte) 4, (byte) 191, (byte) 52, + (byte) 182, (byte) 242, (byte) 70, (byte) 57, (byte) 116, (byte) 56, (byte) 249, (byte) 128, (byte) 231, + (byte) 143, (byte) 210, (byte) 187, (byte) 57, (byte) 110, (byte) 227, (byte) 180, (byte) 143, (byte) 116, + (byte) 188, (byte) 41, (byte) 220, (byte) 217, (byte) 200, (byte) 236, (byte) 195, (byte) 143, (byte) 215, + (byte) 244, (byte) 172, (byte) 139, (byte) 145, (byte) 201, (byte) 248, (byte) 171, (byte) 82, (byte) 139, + (byte) 79, (byte) 213, (byte) 247, (byte) 203, (byte) 100, (byte) 46, (byte) 132, (byte) 135, (byte) 104, + (byte) 87, (byte) 144, (byte) 168, (byte) 27, (byte) 85, (byte) 14, (byte) 72, (byte) 193, (byte) 207, + (byte) 222, (byte) 233, (byte) 237, (byte) 223, (byte) 60, (byte) 81, (byte) 79, (byte) 25, (byte) 67, + (byte) 128, (byte) 26, (byte) 192, (byte) 160, (byte) 3, (byte) 133, (byte) 73, (byte) 65, (byte) 254, + (byte) 130, (byte) 163, (byte) 248, (byte) 147, (byte) 58, (byte) 90, (byte) 223, (byte) 219, (byte) 187, + (byte) 134, (byte) 101, (byte) 33, (byte) 219, (byte) 228, (byte) 93, (byte) 199, (byte) 145, (byte) 24, + (byte) 254, (byte) 149, (byte) 196, (byte) 255, (byte) 0, (byte) 107, (byte) 91, (byte) 19, (byte) 203, + (byte) 72, (byte) 163, (byte) 253, (byte) 168, (byte) 95, (byte) 252, (byte) 43, (byte) 120, (byte) 194, + (byte) 45, (byte) 106, (byte) 67, (byte) 108, (byte) 239, (byte) 215, (byte) 198, (byte) 186, (byte) 104, + (byte) 225, (byte) 237, (byte) 238, (byte) 198, (byte) 61, (byte) 21, (byte) 63, (byte) 248, (byte) 161, + (byte) 82, (byte) 199, (byte) 227, (byte) 13, (byte) 33, (byte) 241, (byte) 151, (byte) 120, (byte) 243, + (byte) 211, (byte) 112, (byte) 207, (byte) 254, (byte) 131, (byte) 154, (byte) 224, (byte) 132, (byte) 158, + (byte) 110, (byte) 217, (byte) 85, (byte) 91, (byte) 100, (byte) 136, (byte) 25, (byte) 24, (byte) 169, + (byte) 27, (byte) 128, (byte) 102, (byte) 25, (byte) 25, (byte) 247, (byte) 4, (byte) 126, (byte) 6, + (byte) 131, (byte) 46, (byte) 196, (byte) 203, (byte) 182, (byte) 213, (byte) 4, (byte) 100, (byte) 147, + (byte) 199, (byte) 90, (byte) 175, (byte) 103, (byte) 17, (byte) 115, (byte) 51, (byte) 209, (byte) 87, + (byte) 196, (byte) 250, (byte) 43, (byte) 112, (byte) 47, (byte) 9, (byte) 63, (byte) 245, (byte) 198, + (byte) 79, (byte) 234, (byte) 181, (byte) 98, (byte) 29, (byte) 91, (byte) 79, (byte) 185, (byte) 144, + (byte) 71, (byte) 21, (byte) 204, (byte) 108, (byte) 228, (byte) 18, (byte) 23, (byte) 112, (byte) 207, + (byte) 3, (byte) 39, (byte) 3, (byte) 169, (byte) 224, (byte) 19, (byte) 248, (byte) 87, (byte) 155, + (byte) 69, (byte) 34, (byte) 56, (byte) 249, (byte) 27, (byte) 119, (byte) 161, (byte) 21, (byte) 167, + (byte) 161, (byte) 182, (byte) 221, (byte) 102, (byte) 220, (byte) 247, (byte) 219, (byte) 40, (byte) 252, + (byte) 227, (byte) 97, (byte) 253, (byte) 105, (byte) 58, (byte) 106, (byte) 195, (byte) 82, (byte) 103, + (byte) 111, (byte) 52, (byte) 172, (byte) 252, (byte) 46, (byte) 85, (byte) 125, (byte) 61, (byte) 106, + (byte) 12, (byte) 96, (byte) 99, (byte) 240, (byte) 169, (byte) 202, (byte) 212, (byte) 101, (byte) 107, + (byte) 3, (byte) 67, (byte) 83, (byte) 195, (byte) 7, (byte) 254, (byte) 38, (byte) 50, (byte) 231, + (byte) 254, (byte) 120, (byte) 159, (byte) 253, (byte) 8, (byte) 81, (byte) 75, (byte) 225, (byte) 180, + (byte) 35, (byte) 82, (byte) 118, (byte) 231, (byte) 2, (byte) 18, (byte) 9, (byte) 199, (byte) 251, + (byte) 75, (byte) 69, (byte) 111, (byte) 13, (byte) 140, (byte) 158, (byte) 231, (byte) 83, (byte) 69, + (byte) 20, (byte) 85, (byte) 8, (byte) 41, (byte) 172, (byte) 202, (byte) 168, (byte) 89, (byte) 136, + (byte) 10, (byte) 7, (byte) 36, (byte) 210, (byte) 59, (byte) 172, (byte) 104, (byte) 89, (byte) 206, + (byte) 0, (byte) 234, (byte) 107, (byte) 50, (byte) 123, (byte) 212, (byte) 153, (byte) 202, (byte) 188, + (byte) 37, (byte) 226, (byte) 237, (byte) 243, (byte) 17, (byte) 248, (byte) 241, (byte) 82, (byte) 221, + (byte) 134, (byte) 149, (byte) 200, (byte) 239, (byte) 47, (byte) 26, (byte) 228, (byte) 152, (byte) 227, + (byte) 202, (byte) 197, (byte) 233, (byte) 221, (byte) 170, (byte) 151, (byte) 151, (byte) 20, (byte) 201, + (byte) 204, (byte) 104, (byte) 87, (byte) 28, (byte) 54, (byte) 7, (byte) 205, (byte) 255, (byte) 0, + (byte) 214, (byte) 255, (byte) 0, (byte) 61, (byte) 58, (byte) 217, (byte) 117, (byte) 180, (byte) 158, + (byte) 65, (byte) 31, (byte) 149, (byte) 60, (byte) 104, (byte) 6, (byte) 231, (byte) 97, (byte) 200, + (byte) 62, (byte) 220, (byte) 245, (byte) 255, (byte) 0, (byte) 235, (byte) 115, (byte) 193, (byte) 230, + (byte) 95, (byte) 46, (byte) 208, (byte) 253, (byte) 219, (byte) 163, (byte) 207, (byte) 170, (byte) 19, + (byte) 89, (byte) 61, (byte) 77, (byte) 17, (byte) 158, (byte) 108, (byte) 237, (byte) 143, (byte) 88, + (byte) 23, (byte) 240, (byte) 36, (byte) 127, (byte) 42, (byte) 175, (byte) 54, (byte) 143, (byte) 167, + (byte) 78, (byte) 49, (byte) 37, (byte) 170, (byte) 48, (byte) 247, (byte) 231, (byte) 249, (byte) 230, + (byte) 181, (byte) 205, (byte) 164, (byte) 103, (byte) 238, (byte) 221, (byte) 196, (byte) 126, (byte) 191, + (byte) 45, (byte) 31, (byte) 96, (byte) 145, (byte) 190, (byte) 228, (byte) 145, (byte) 55, (byte) 209, + (byte) 243, (byte) 253, (byte) 41, (byte) 89, (byte) 133, (byte) 209, (byte) 203, (byte) 220, (byte) 105, + (byte) 30, (byte) 28, (byte) 177, (byte) 144, (byte) 44, (byte) 162, (byte) 218, (byte) 217, (byte) 200, + (byte) 200, (byte) 201, (byte) 69, (byte) 63, (byte) 94, (byte) 153, (byte) 20, (byte) 244, (byte) 181, + (byte) 211, (byte) 179, (byte) 182, (byte) 13, (byte) 126, (byte) 72, (byte) 200, (byte) 63, (byte) 118, + (byte) 27, (byte) 246, (byte) 31, (byte) 160, (byte) 113, (byte) 90, (byte) 18, (byte) 120, (byte) 78, + (byte) 79, (byte) 53, (byte) 230, (byte) 89, (byte) 239, (byte) 11, (byte) 200, (byte) 114, (byte) 205, + (byte) 231, (byte) 1, (byte) 159, (byte) 110, (byte) 48, (byte) 106, (byte) 164, (byte) 158, (byte) 18, + (byte) 186, (byte) 199, (byte) 55, (byte) 37, (byte) 143, (byte) 253, (byte) 52, (byte) 181, (byte) 14, + (byte) 127, (byte) 70, (byte) 231, (byte) 252, (byte) 105, (byte) 217, (byte) 245, (byte) 27, (byte) 113, + (byte) 182, (byte) 132, (byte) 137, (byte) 166, (byte) 94, (byte) 227, (byte) 117, (byte) 174, (byte) 175, + (byte) 118, (byte) 71, (byte) 247, (byte) 153, (byte) 203, (byte) 255, (byte) 0, (byte) 232, (byte) 91, + (byte) 169, (byte) 77, (byte) 182, (byte) 186, (byte) 135, (byte) 141, (byte) 105, (byte) 155, (byte) 31, + (byte) 194, (byte) 97, (byte) 139, (byte) 255, (byte) 0, (byte) 141, (byte) 131, (byte) 250, (byte) 214, + (byte) 115, (byte) 248, (byte) 70, (byte) 97, (byte) 255, (byte) 0, (byte) 44, (byte) 108, (byte) 206, + (byte) 14, (byte) 114, (byte) 208, (byte) 24, (byte) 255, (byte) 0, (byte) 161, (byte) 173, (byte) 29, + (byte) 39, (byte) 74, (byte) 26, (byte) 126, (byte) 247, (byte) 149, (byte) 209, (byte) 166, (byte) 147, + (byte) 130, (byte) 35, (byte) 56, (byte) 69, (byte) 95, (byte) 65, (byte) 211, (byte) 63, (byte) 92, + (byte) 127, (byte) 92, (byte) 161, (byte) 33, (byte) 124, (byte) 207, (byte) 17, (byte) 39, (byte) 11, + (byte) 45, (byte) 148, (byte) 131, (byte) 214, (byte) 72, (byte) 73, (byte) 63, (byte) 163, (byte) 143, + (byte) 229, (byte) 74, (byte) 47, (byte) 245, (byte) 216, (byte) 190, (byte) 245, (byte) 157, (byte) 180, + (byte) 196, (byte) 127, (byte) 207, (byte) 48, (byte) 201, (byte) 253, (byte) 90, (byte) 180, (byte) 48, + (byte) 126, (byte) 180, (byte) 224, (byte) 15, (byte) 231, (byte) 72, (byte) 101, (byte) 1, (byte) 173, + (byte) 106, (byte) 163, (byte) 253, (byte) 102, (byte) 134, (byte) 20, (byte) 122, (byte) 173, (byte) 211, + (byte) 31, (byte) 231, (byte) 24, (byte) 254, (byte) 116, (byte) 198, (byte) 215, (byte) 81, (byte) 198, + (byte) 219, (byte) 173, (byte) 26, (byte) 241, (byte) 186, (byte) 224, (byte) 175, (byte) 150, (byte) 71, + (byte) 39, (byte) 61, (byte) 75, (byte) 131, (byte) 255, (byte) 0, (byte) 234, (byte) 173, (byte) 46, + (byte) 248, (byte) 252, (byte) 205, (byte) 57, (byte) 229, (byte) 16, (byte) 199, (byte) 187, (byte) 156, + (byte) 14, (byte) 128, (byte) 127, (byte) 42, (byte) 5, (byte) 99, (byte) 138, (byte) 241, (byte) 77, + (byte) 192, (byte) 212, (byte) 110, (byte) 32, (byte) 157, (byte) 109, (byte) 228, (byte) 137, (byte) 22, + (byte) 63, (byte) 44, (byte) 9, (byte) 217, (byte) 50, (byte) 79, (byte) 83, (byte) 209, (byte) 142, + (byte) 56, (byte) 199, (byte) 83, (byte) 216, (byte) 215, (byte) 57, (byte) 60, (byte) 16, (byte) 164, + (byte) 139, (byte) 27, (byte) 199, (byte) 9, (byte) 103, (byte) 206, (byte) 54, (byte) 149, (byte) 113, + (byte) 198, (byte) 123, (byte) 174, (byte) 64, (byte) 233, (byte) 252, (byte) 143, (byte) 66, (byte) 43, + (byte) 168, (byte) 215, (byte) 230, (byte) 55, (byte) 183, (byte) 10, (byte) 3, (byte) 65, (byte) 186, + (byte) 55, (byte) 70, (byte) 223, (byte) 59, (byte) 98, (byte) 54, (byte) 251, (byte) 223, (byte) 41, + (byte) 245, (byte) 206, (byte) 56, (byte) 3, (byte) 168, (byte) 13, (byte) 233, (byte) 85, (byte) 103, + (byte) 179, (byte) 188, (byte) 189, (byte) 71, (byte) 242, (byte) 116, (byte) 171, (byte) 50, (byte) 204, + (byte) 191, (byte) 122, (byte) 198, (byte) 9, (byte) 64, (byte) 31, (byte) 48, (byte) 111, (byte) 226, + (byte) 24, (byte) 29, (byte) 8, (byte) 227, (byte) 28, (byte) 55, (byte) 126, (byte) 49, (byte) 211, + (byte) 77, (byte) 251, (byte) 166, (byte) 82, (byte) 90, (byte) 156, (byte) 133, (byte) 236, (byte) 12, + (byte) 183, (byte) 150, (byte) 235, (byte) 109, (byte) 251, (byte) 165, (byte) 116, (byte) 145, (byte) 164, + (byte) 218, (byte) 163, (byte) 230, (byte) 198, (byte) 192, (byte) 58, (byte) 143, (byte) 246, (byte) 169, + (byte) 5, (byte) 169, (byte) 152, (byte) 136, (byte) 166, (byte) 145, (byte) 165, (byte) 141, (byte) 136, + (byte) 12, (byte) 164, (byte) 46, (byte) 15, (byte) 62, (byte) 192, (byte) 86, (byte) 244, (byte) 186, + (byte) 93, (byte) 228, (byte) 92, (byte) 203, (byte) 28, (byte) 113, (byte) 251, (byte) 60, (byte) 241, + (byte) 131, (byte) 249, (byte) 110, (byte) 205, (byte) 71, (byte) 30, (byte) 159, (byte) 117, (byte) 47, + (byte) 250, (byte) 171, (byte) 57, (byte) 165, (byte) 199, (byte) 59, (byte) 162, (byte) 132, (byte) 183, + (byte) 234, (byte) 5, (byte) 105, (byte) 161, (byte) 55, (byte) 118, (byte) 51, (byte) 101, (byte) 209, + (byte) 45, (byte) 47, (byte) 103, (byte) 6, (byte) 68, (byte) 105, (byte) 102, (byte) 147, (byte) 10, + (byte) 25, (byte) 216, (byte) 51, (byte) 30, (byte) 138, (byte) 6, (byte) 79, (byte) 62, (byte) 128, + (byte) 126, (byte) 21, (byte) 111, (byte) 64, (byte) 210, (byte) 109, (byte) 173, (byte) 53, (byte) 120, + (byte) 37, (byte) 129, (byte) 202, (byte) 228, (byte) 227, (byte) 29, (byte) 71, (byte) 63, (byte) 141, + (byte) 109, (byte) 233, (byte) 26, (byte) 129, (byte) 209, (byte) 94, (byte) 113, (byte) 117, (byte) 246, + (byte) 155, (byte) 101, (byte) 152, (byte) 47, (byte) 42, (byte) 160, (byte) 19, (byte) 130, (byte) 120, + (byte) 33, (byte) 177, (byte) 235, (byte) 80, (byte) 45, (byte) 228, (byte) 55, (byte) 94, (byte) 35, + (byte) 89, (byte) 161, (byte) 152, (byte) 202, (byte) 178, (byte) 93, (byte) 33, (byte) 220, (byte) 196, + (byte) 100, (byte) 229, (byte) 134, (byte) 123, (byte) 250, (byte) 231, (byte) 30, (byte) 216, (byte) 168, + (byte) 247, (byte) 155, (byte) 105, (byte) 173, (byte) 7, (byte) 100, (byte) 146, (byte) 119, (byte) 215, + (byte) 177, (byte) 214, (byte) 176, (byte) 228, (byte) 213, (byte) 121, (byte) 164, (byte) 218, (byte) 226, + (byte) 56, (byte) 212, (byte) 201, (byte) 41, (byte) 25, (byte) 10, (byte) 14, (byte) 49, (byte) 238, + (byte) 79, (byte) 97, (byte) 254, (byte) 7, (byte) 0, (byte) 224, (byte) 225, (byte) 210, (byte) 76, + (byte) 242, (byte) 187, (byte) 69, (byte) 109, (byte) 141, (byte) 192, (byte) 225, (byte) 229, (byte) 35, + (byte) 33, (byte) 61, (byte) 135, (byte) 171, (byte) 126, (byte) 131, (byte) 190, (byte) 113, (byte) 180, + (byte) 190, (byte) 24, (byte) 86, (byte) 8, (byte) 202, (byte) 140, (byte) 156, (byte) 156, (byte) 150, + (byte) 39, (byte) 37, (byte) 142, (byte) 7, (byte) 39, (byte) 215, (byte) 255, (byte) 0, (byte) 172, + (byte) 43, (byte) 152, (byte) 216, (byte) 185, (byte) 225, (byte) 200, (byte) 60, (byte) 173, (byte) 87, + (byte) 204, (byte) 119, (byte) 50, (byte) 74, (byte) 209, (byte) 48, (byte) 45, (byte) 140, (byte) 0, + (byte) 50, (byte) 188, (byte) 1, (byte) 216, (byte) 127, (byte) 128, (byte) 201, (byte) 39, (byte) 154, + (byte) 42, (byte) 93, (byte) 12, (byte) 255, (byte) 0, (byte) 196, (byte) 208, (byte) 127, (byte) 184, + (byte) 194, (byte) 138, (byte) 214, (byte) 27, (byte) 25, (byte) 189, (byte) 206, (byte) 158, (byte) 152, + (byte) 238, (byte) 168, (byte) 165, (byte) 152, (byte) 224, (byte) 10, (byte) 29, (byte) 213, (byte) 20, + (byte) 179, (byte) 28, (byte) 1, (byte) 89, (byte) 151, (byte) 51, (byte) 180, (byte) 242, (byte) 99, + (byte) 149, (byte) 3, (byte) 166, (byte) 123, (byte) 127, (byte) 245, (byte) 255, (byte) 0, (byte) 207, + (byte) 213, (byte) 202, (byte) 86, (byte) 4, (byte) 174, (byte) 54, (byte) 230, (byte) 225, (byte) 238, + (byte) 31, (byte) 28, (byte) 170, (byte) 131, (byte) 211, (byte) 211, (byte) 255, (byte) 0, (byte) 175, + (byte) 254, (byte) 126, (byte) 180, (byte) 53, (byte) 43, (byte) 248, (byte) 244, (byte) 219, (byte) 38, + (byte) 153, (byte) 204, (byte) 69, (byte) 254, (byte) 236, (byte) 105, (byte) 38, (byte) 62, (byte) 118, + (byte) 244, (byte) 232, (byte) 79, (byte) 191, (byte) 3, (byte) 160, (byte) 53, (byte) 120, (byte) 0, + (byte) 56, (byte) 3, (byte) 35, (byte) 182, (byte) 43, (byte) 151, (byte) 214, (byte) 32, (byte) 186, + (byte) 184, (byte) 251, (byte) 68, (byte) 177, (byte) 45, (byte) 203, (byte) 179, (byte) 137, (byte) 4, + (byte) 34, (byte) 9, (byte) 140, (byte) 160, (byte) 28, (byte) 124, (byte) 167, (byte) 98, (byte) 18, + (byte) 6, (byte) 62, (byte) 92, (byte) 241, (byte) 233, (byte) 156, (byte) 214, (byte) 90, (byte) 189, + (byte) 77, (byte) 52, (byte) 71, (byte) 63, (byte) 172, (byte) 107, (byte) 115, (byte) 107, (byte) 22, + (byte) 242, (byte) 51, (byte) 181, (byte) 178, (byte) 136, (byte) 207, (byte) 151, (byte) 19, (byte) 67, + (byte) 41, (byte) 92, (byte) 177, (byte) 56, (byte) 222, (byte) 20, (byte) 156, (byte) 119, (byte) 199, + (byte) 174, (byte) 51, (byte) 239, (byte) 78, (byte) 142, (byte) 246, (byte) 255, (byte) 0, (byte) 251, + (byte) 68, (byte) 132, (byte) 184, (byte) 188, (byte) 40, (byte) 97, (byte) 12, (byte) 203, (byte) 21, + (byte) 217, (byte) 113, (byte) 184, (byte) 177, (byte) 231, (byte) 61, (byte) 73, (byte) 249, (byte) 72, + (byte) 252, (byte) 61, (byte) 14, (byte) 40, (byte) 184, (byte) 211, (byte) 210, (byte) 214, (byte) 91, + (byte) 85, (byte) 197, (byte) 223, (byte) 151, (byte) 2, (byte) 54, (byte) 67, (byte) 68, (byte) 9, + (byte) 83, (byte) 133, (byte) 11, (byte) 213, (byte) 112, (byte) 6, (byte) 55, (byte) 113, (byte) 236, + (byte) 181, (byte) 71, (byte) 201, (byte) 141, (byte) 173, (byte) 164, (byte) 6, (byte) 72, (byte) 196, + (byte) 211, (byte) 92, (byte) 130, (byte) 223, (byte) 185, (byte) 31, (byte) 42, (byte) 121, (byte) 157, + (byte) 114, (byte) 15, (byte) 63, (byte) 39, (byte) 59, (byte) 70, (byte) 59, (byte) 129, (byte) 72, + (byte) 11, (byte) 208, (byte) 107, (byte) 186, (byte) 180, (byte) 80, (byte) 89, (byte) 187, (byte) 92, + (byte) 207, (byte) 153, (byte) 78, (byte) 11, (byte) 60, (byte) 10, (byte) 251, (byte) 151, (byte) 4, + (byte) 228, (byte) 119, (byte) 35, (byte) 145, (byte) 201, (byte) 237, (byte) 223, (byte) 140, (byte) 84, + (byte) 237, (byte) 226, (byte) 205, (byte) 66, (byte) 56, (byte) 238, (byte) 143, (byte) 155, (byte) 4, + (byte) 173, (byte) 9, (byte) 253, (byte) 216, (byte) 146, (byte) 50, (byte) 9, (byte) 24, (byte) 29, + (byte) 74, (byte) 225, (byte) 122, (byte) 231, (byte) 211, (byte) 159, (byte) 65, (byte) 129, (byte) 84, + (byte) 163, (byte) 130, (byte) 36, (byte) 189, (byte) 105, (byte) 35, (byte) 104, (byte) 22, (byte) 59, + (byte) 120, (byte) 151, (byte) 203, (byte) 0, (byte) 186, (byte) 6, (byte) 56, (byte) 108, (byte) 237, + (byte) 4, (byte) 17, (byte) 156, (byte) 96, (byte) 115, (byte) 237, (byte) 239, (byte) 76, (byte) 91, + (byte) 105, (byte) 222, (byte) 210, (byte) 218, (byte) 220, (byte) 202, (byte) 210, (byte) 53, (byte) 227, + (byte) 111, (byte) 153, (byte) 86, (byte) 225, (byte) 91, (byte) 113, (byte) 10, (byte) 9, (byte) 220, + (byte) 27, (byte) 1, (byte) 79, (byte) 11, (byte) 199, (byte) 177, (byte) 29, (byte) 133, (byte) 49, + (byte) 155, (byte) 145, (byte) 120, (byte) 190, (byte) 228, (byte) 92, (byte) 172, (byte) 97, (byte) 108, + (byte) 217, (byte) 36, (byte) 66, (byte) 200, (byte) 233, (byte) 33, (byte) 64, (byte) 57, (byte) 28, + (byte) 100, (byte) 245, (byte) 56, (byte) 201, (byte) 237, (byte) 248, (byte) 98, (byte) 172, (byte) 65, + (byte) 227, (byte) 137, (byte) 140, (byte) 16, (byte) 74, (byte) 246, (byte) 115, (byte) 42, (byte) 203, + (byte) 32, (byte) 143, (byte) 11, (byte) 114, (byte) 25, (byte) 129, (byte) 44, (byte) 71, (byte) 76, + (byte) 122, (byte) 14, (byte) 228, (byte) 117, (byte) 252, (byte) 107, (byte) 157, (byte) 144, (byte) 92, + (byte) 43, (byte) 222, (byte) 223, (byte) 58, (byte) 22, (byte) 22, (byte) 160, (byte) 196, (byte) 26, + (byte) 72, (byte) 17, (byte) 151, (byte) 43, (byte) 134, (byte) 195, (byte) 31, (byte) 169, (byte) 198, + (byte) 125, (byte) 198, (byte) 15, (byte) 81, (byte) 81, (byte) 53, (byte) 160, (byte) 133, (byte) 45, + (byte) 237, (byte) 36, (byte) 72, (byte) 198, (byte) 73, (byte) 146, (byte) 67, (byte) 36, (byte) 82, + (byte) 70, (byte) 207, (byte) 131, (byte) 247, (byte) 88, (byte) 117, (byte) 193, (byte) 207, (byte) 233, + (byte) 138, (byte) 44, (byte) 35, (byte) 179, (byte) 143, (byte) 199, (byte) 10, (byte) 30, (byte) 84, + (byte) 146, (byte) 43, (byte) 196, (byte) 120, (byte) 66, (byte) 153, (byte) 23, (byte) 201, (byte) 86, + (byte) 218, (byte) 8, (byte) 39, (byte) 57, (byte) 207, (byte) 160, (byte) 255, (byte) 0, (byte) 12, + (byte) 243, (byte) 86, (byte) 35, (byte) 241, (byte) 197, (byte) 131, (byte) 136, (byte) 183, (byte) 220, + (byte) 5, (byte) 89, (byte) 64, (byte) 43, (byte) 230, (byte) 196, (byte) 70, (byte) 114, (byte) 51, + (byte) 142, (byte) 7, (byte) 167, (byte) 225, (byte) 232, (byte) 77, (byte) 112, (byte) 161, (byte) 227, + (byte) 243, (byte) 47, (byte) 38, (byte) 85, (byte) 82, (byte) 71, (byte) 238, (byte) 149, (byte) 97, + (byte) 148, (byte) 118, (byte) 249, (byte) 115, (byte) 176, (byte) 142, (byte) 65, (byte) 36, (byte) 30, + (byte) 123, (byte) 103, (byte) 165, (byte) 77, (byte) 30, (byte) 200, (byte) 18, (byte) 218, (byte) 216, + (byte) 153, (byte) 62, (byte) 210, (byte) 177, (byte) 147, (byte) 27, (byte) 9, (byte) 183, (byte) 34, + (byte) 54, (byte) 210, (byte) 48, (byte) 48, (byte) 64, (byte) 3, (byte) 57, (byte) 29, (byte) 248, + (byte) 35, (byte) 182, (byte) 40, (byte) 11, (byte) 30, (byte) 133, (byte) 105, (byte) 173, (byte) 217, + (byte) 95, (byte) 150, (byte) 16, (byte) 165, (byte) 188, (byte) 204, (byte) 167, (byte) 5, (byte) 76, + (byte) 101, (byte) 24, (byte) 113, (byte) 232, (byte) 220, (byte) 254, (byte) 149, (byte) 108, (byte) 205, + (byte) 22, (byte) 15, (byte) 250, (byte) 24, (byte) 83, (byte) 219, (byte) 14, (byte) 71, (byte) 242, + (byte) 172, (byte) 15, (byte) 11, (byte) 104, (byte) 247, (byte) 54, (byte) 22, (byte) 242, (byte) 94, + (byte) 94, (byte) 51, (byte) 139, (byte) 155, (byte) 189, (byte) 164, (byte) 198, (byte) 78, (byte) 54, + (byte) 168, (byte) 233, (byte) 145, (byte) 221, (byte) 185, (byte) 231, (byte) 250, (byte) 115, (byte) 157, + (byte) 226, (byte) 63, (byte) 217, (byte) 95, (byte) 251, (byte) 228, (byte) 127, (byte) 133, (byte) 23, + (byte) 21, (byte) 134, (byte) 198, (byte) 246, (byte) 113, (byte) 68, (byte) 136, (byte) 240, (byte) 200, + (byte) 48, (byte) 48, (byte) 88, (byte) 177, (byte) 228, (byte) 250, (byte) 253, (byte) 127, (byte) 198, + (byte) 178, (byte) 53, (byte) 235, (byte) 216, (byte) 6, (byte) 32, (byte) 183, (byte) 82, (byte) 175, + (byte) 143, (byte) 152, (byte) 150, (byte) 206, (byte) 1, (byte) 254, (byte) 167, (byte) 249, (byte) 84, + (byte) 154, (byte) 165, (byte) 202, (byte) 136, (byte) 252, (byte) 161, (byte) 134, (byte) 207, (byte) 64, + (byte) 123, (byte) 251, (byte) 214, (byte) 20, (byte) 185, (byte) 98, (byte) 89, (byte) 137, (byte) 44, + (byte) 78, (byte) 73, (byte) 39, (byte) 169, (byte) 160, (byte) 102, (byte) 7, (byte) 138, (byte) 142, + (byte) 52, (byte) 66, (byte) 115, (byte) 130, (byte) 110, (byte) 98, (byte) 239, (byte) 232, (byte) 178, + (byte) 255, (byte) 0, (byte) 241, (byte) 85, (byte) 201, (byte) 196, (byte) 98, (byte) 126, (byte) 89, + (byte) 85, (byte) 143, (byte) 184, (byte) 174, (byte) 195, (byte) 196, (byte) 177, (byte) 121, (byte) 186, + (byte) 28, (byte) 153, (byte) 255, (byte) 0, (byte) 150, (byte) 114, (byte) 43, (byte) 244, (byte) 247, + (byte) 11, (byte) 255, (byte) 0, (byte) 179, (byte) 87, (byte) 22, (byte) 150, (byte) 11, (byte) 213, + (byte) 102, (byte) 157, (byte) 125, (byte) 196, (byte) 135, (byte) 250, (byte) 154, (byte) 222, (byte) 27, + (byte) 25, (byte) 200, (byte) 212, (byte) 183, (byte) 185, (byte) 184, (byte) 135, (byte) 30, (byte) 69, + (byte) 204, (byte) 208, (byte) 143, (byte) 250, (byte) 98, (byte) 251, (byte) 127, (byte) 149, (byte) 91, + (byte) 254, (byte) 209, (byte) 191, (byte) 63, (byte) 52, (byte) 151, (byte) 215, (byte) 19, (byte) 96, + (byte) 103, (byte) 247, (byte) 242, (byte) 180, (byte) 159, (byte) 204, (byte) 226, (byte) 178, (byte) 213, + (byte) 150, (byte) 217, (byte) 34, (byte) 71, (byte) 18, (byte) 76, (byte) 207, (byte) 38, (byte) 208, + (byte) 217, (byte) 203, (byte) 156, (byte) 140, (byte) 128, (byte) 121, (byte) 0, (byte) 1, (byte) 180, + (byte) 246, (byte) 207, (byte) 60, (byte) 231, (byte) 140, (byte) 77, (byte) 43, (byte) 19, (byte) 19, + (byte) 132, (byte) 141, (byte) 214, (byte) 77, (byte) 135, (byte) 104, (byte) 32, (byte) 156, (byte) 156, + (byte) 113, (byte) 156, (byte) 86, (byte) 150, (byte) 68, (byte) 154, (byte) 209, (byte) 107, (byte) 26, + (byte) 132, (byte) 35, (byte) 17, (byte) 204, (byte) 136, (byte) 63, (byte) 217, (byte) 130, (byte) 32, + (byte) 127, (byte) 61, (byte) 185, (byte) 253, (byte) 106, (byte) 253, (byte) 134, (byte) 181, (byte) 117, + (byte) 115, (byte) 168, (byte) 90, (byte) 219, (byte) 204, (byte) 161, (byte) 214, (byte) 73, (byte) 146, + (byte) 51, (byte) 151, (byte) 144, (byte) 99, (byte) 115, (byte) 1, (byte) 192, (byte) 12, (byte) 6, + (byte) 121, (byte) 244, (byte) 197, (byte) 114, (byte) 210, (byte) 182, (byte) 162, (byte) 187, (byte) 124, + (byte) 152, (byte) 226, (byte) 101, (byte) 11, (byte) 243, (byte) 229, (byte) 246, (byte) 252, (byte) 222, + (byte) 221, (byte) 120, (byte) 171, (byte) 218, (byte) 20, (byte) 215, (byte) 103, (byte) 95, (byte) 211, + (byte) 146, (byte) 107, (byte) 95, (byte) 45, (byte) 126, (byte) 215, (byte) 15, (byte) 204, (byte) 31, + (byte) 112, (byte) 255, (byte) 0, (byte) 88, (byte) 190, (byte) 194, (byte) 165, (byte) 164, (byte) 23, + (byte) 61, (byte) 49, (byte) 34, (byte) 72, (byte) 163, (byte) 84, (byte) 69, (byte) 10, (byte) 160, + (byte) 96, (byte) 40, (byte) 24, (byte) 0, (byte) 82, (byte) 17, (byte) 252, (byte) 234, (byte) 96, + (byte) 50, (byte) 128, (byte) 251, (byte) 85, (byte) 123, (byte) 169, (byte) 225, (byte) 182, (byte) 129, + (byte) 230, (byte) 158, (byte) 69, (byte) 138, (byte) 40, (byte) 198, (byte) 89, (byte) 152, (byte) 224, + (byte) 10, (byte) 230, (byte) 53, (byte) 47, (byte) 104, (byte) 132, (byte) 13, (byte) 81, (byte) 51, + (byte) 221, (byte) 88, (byte) 15, (byte) 202, (byte) 138, (byte) 161, (byte) 225, (byte) 221, (byte) 62, + (byte) 255, (byte) 0, (byte) 87, (byte) 212, (byte) 33, (byte) 213, (byte) 231, (byte) 243, (byte) 44, + (byte) 244, (byte) 248, (byte) 78, (byte) 235, (byte) 104, (byte) 72, (byte) 195, (byte) 206, (byte) 113, + (byte) 141, (byte) 205, (byte) 232, (byte) 190, (byte) 131, (byte) 243, (byte) 246, (byte) 43, (byte) 88, + (byte) 232, (byte) 181, (byte) 33, (byte) 157, (byte) 85, (byte) 237, (byte) 220, (byte) 22, (byte) 216, + (byte) 251, (byte) 66, (byte) 72, (byte) 83, (byte) 25, (byte) 222, (byte) 177, (byte) 150, (byte) 11, + (byte) 245, (byte) 199, (byte) 74, (byte) 170, (byte) 154, (byte) 158, (byte) 143, (byte) 41, (byte) 194, + (byte) 222, (byte) 70, (byte) 173, (byte) 220, (byte) 59, (byte) 21, (byte) 35, (byte) 240, (byte) 61, + (byte) 43, (byte) 86, (byte) 177, (byte) 117, (byte) 63, (byte) 13, (byte) 165, (byte) 235, (byte) 249, + (byte) 182, (byte) 183, (byte) 114, (byte) 88, (byte) 200, (byte) 78, (byte) 91, (byte) 98, (byte) 171, + (byte) 163, (byte) 127, (byte) 192, (byte) 72, (byte) 224, (byte) 253, (byte) 49, (byte) 78, (byte) 200, + (byte) 69, (byte) 216, (byte) 141, (byte) 165, (byte) 193, (byte) 255, (byte) 0, (byte) 71, (byte) 186, + (byte) 142, (byte) 67, (byte) 219, (byte) 99, (byte) 131, (byte) 252, (byte) 169, (byte) 205, (byte) 103, + (byte) 201, (byte) 109, (byte) 192, (byte) 177, (byte) 234, (byte) 72, (byte) 228, (byte) 215, (byte) 51, + (byte) 55, (byte) 133, (byte) 181, (byte) 193, (byte) 247, (byte) 47, (byte) 244, (byte) 251, (byte) 128, + (byte) 58, (byte) 9, (byte) 173, (byte) 221, (byte) 79, (byte) 232, (byte) 216, (byte) 253, (byte) 42, + (byte) 31, (byte) 236, (byte) 175, (byte) 18, (byte) 218, (byte) 255, (byte) 0, (byte) 171, (byte) 211, + (byte) 173, (byte) 155, (byte) 31, (byte) 197, (byte) 109, (byte) 122, (byte) 99, (byte) 63, (byte) 150, + (byte) 223, (byte) 235, (byte) 71, (byte) 42, (byte) 29, (byte) 217, (byte) 208, (byte) 79, (byte) 161, + (byte) 199, (byte) 60, (byte) 134, (byte) 82, (byte) 89, (byte) 93, (byte) 186, (byte) 178, (byte) 185, + (byte) 244, (byte) 199, (byte) 126, (byte) 59, (byte) 85, (byte) 89, (byte) 60, (byte) 58, (byte) 88, + (byte) 96, (byte) 79, (byte) 43, (byte) 15, (byte) 250, (byte) 106, (byte) 21, (byte) 135, (byte) 233, + (byte) 138, (byte) 199, (byte) 55, (byte) 190, (byte) 35, (byte) 182, (byte) 63, (byte) 61, (byte) 142, + (byte) 176, (byte) 152, (byte) 234, (byte) 35, (byte) 242, (byte) 231, (byte) 95, (byte) 204, (byte) 146, + (byte) 105, (byte) 195, (byte) 197, (byte) 247, (byte) 86, (byte) 223, (byte) 241, (byte) 242, (byte) 215, + (byte) 49, (byte) 30, (byte) 255, (byte) 0, (byte) 104, (byte) 177, (byte) 112, (byte) 63, (byte) 48, + (byte) 160, (byte) 126, (byte) 180, (byte) 185, (byte) 16, (byte) 249, (byte) 153, (byte) 106, (byte) 79, + (byte) 11, (byte) 47, (byte) 95, (byte) 46, (byte) 217, (byte) 207, (byte) 253, (byte) 123, (byte) 108, + (byte) 253, (byte) 121, (byte) 170, (byte) 146, (byte) 120, (byte) 85, (byte) 59, (byte) 219, (byte) 64, + (byte) 73, (byte) 254, (byte) 228, (byte) 207, (byte) 159, (byte) 200, (byte) 224, (byte) 85, (byte) 136, + (byte) 188, (byte) 117, (byte) 1, (byte) 225, (byte) 174, (byte) 244, (byte) 246, (byte) 99, (byte) 252, + (byte) 38, (byte) 79, (byte) 44, (byte) 254, (byte) 68, (byte) 154, (byte) 209, (byte) 139, (byte) 196, + (byte) 194, (byte) 84, (byte) 207, (byte) 216, (byte) 252, (byte) 193, (byte) 216, (byte) 67, (byte) 40, + (byte) 124, (byte) 254, (byte) 96, (byte) 15, (byte) 214, (byte) 151, (byte) 32, (byte) 115, (byte) 28, + (byte) 228, (byte) 190, (byte) 18, (byte) 5, (byte) 24, (byte) 27, (byte) 107, (byte) 133, (byte) 82, + (byte) 48, (byte) 64, (byte) 146, (byte) 50, (byte) 63, (byte) 46, (byte) 77, (byte) 55, (byte) 73, + (byte) 240, (byte) 230, (byte) 172, (byte) 111, (byte) 110, (byte) 110, (byte) 103, (byte) 185, (byte) 48, + (byte) 172, (byte) 108, (byte) 241, (byte) 192, (byte) 38, (byte) 82, (byte) 204, (byte) 232, (byte) 72, + (byte) 231, (byte) 253, (byte) 145, (byte) 242, (byte) 143, (byte) 199, (byte) 61, (byte) 59, (byte) 245, + (byte) 81, (byte) 248, (byte) 130, (byte) 193, (byte) 254, (byte) 253, (byte) 172, (byte) 209, (byte) 99, + (byte) 174, (byte) 228, (byte) 94, (byte) 63, (byte) 34, (byte) 106, (byte) 117, (byte) 213, (byte) 180, + (byte) 167, (byte) 255, (byte) 0, (byte) 150, (byte) 165, (byte) 127, (byte) 222, (byte) 71, (byte) 31, + (byte) 210, (byte) 151, (byte) 35, (byte) 31, (byte) 49, (byte) 206, (byte) 71, (byte) 225, (byte) 235, + (byte) 232, (byte) 99, (byte) 49, (byte) 175, (byte) 216, (byte) 221, (byte) 76, (byte) 143, (byte) 38, + (byte) 30, (byte) 70, (byte) 234, (byte) 204, (byte) 91, (byte) 166, (byte) 223, (byte) 124, (byte) 126, + (byte) 21, (byte) 47, (byte) 135, (byte) 188, (byte) 48, (byte) 154, (byte) 76, (byte) 179, (byte) 93, + (byte) 207, (byte) 181, (byte) 238, (byte) 100, (byte) 118, (byte) 217, (byte) 180, (byte) 252, (byte) 177, + (byte) 169, (byte) 61, (byte) 184, (byte) 228, (byte) 145, (byte) 140, (byte) 159, (byte) 192, (byte) 119, + (byte) 39, (byte) 163, (byte) 91, (byte) 189, (byte) 57, (byte) 248, (byte) 75, (byte) 216, (byte) 24, + (byte) 158, (byte) 194, (byte) 85, (byte) 205, (byte) 76, (byte) 45, (byte) 209, (byte) 134, (byte) 84, + (byte) 130, (byte) 15, (byte) 124, (byte) 102, (byte) 151, (byte) 43, (byte) 14, (byte) 100, (byte) 84, + (byte) 219, (byte) 207, (byte) 184, (byte) 170, (byte) 151, (byte) 247, (byte) 43, (byte) 12, (byte) 100, + (byte) 117, (byte) 61, (byte) 14, (byte) 63, (byte) 149, (byte) 106, (byte) 61, (byte) 190, (byte) 216, + (byte) 216, (byte) 134, (byte) 3, (byte) 3, (byte) 60, (byte) 10, (byte) 229, (byte) 238, (byte) 93, + (byte) 166, (byte) 148, (byte) 147, (byte) 156, (byte) 3, (byte) 128, (byte) 42, (byte) 90, (byte) 177, + (byte) 73, (byte) 220, (byte) 169, (byte) 41, (byte) 105, (byte) 92, (byte) 187, (byte) 117, (byte) 53, + (byte) 3, (byte) 165, (byte) 91, (byte) 43, (byte) 219, (byte) 244, (byte) 172, (byte) 248, (byte) 228, + (byte) 187, (byte) 214, (byte) 47, (byte) 26, (byte) 195, (byte) 68, (byte) 69, (byte) 145, (byte) 208, + (byte) 226, (byte) 107, (byte) 182, (byte) 25, (byte) 138, (byte) 15, (byte) 254, (byte) 41, (byte) 189, + (byte) 191, (byte) 62, (byte) 132, (byte) 80, (byte) 149, (byte) 193, (byte) 153, (byte) 186, (byte) 246, + (byte) 211, (byte) 164, (byte) 94, (byte) 219, (byte) 161, (byte) 221, (byte) 57, (byte) 133, (byte) 29, + (byte) 34, (byte) 31, (byte) 120, (byte) 129, (byte) 52, (byte) 121, (byte) 56, (byte) 244, (byte) 255, + (byte) 0, (byte) 3, (byte) 88, (byte) 87, (byte) 54, (byte) 90, (byte) 91, (byte) 70, (byte) 162, + (byte) 29, (byte) 118, (byte) 25, (byte) 153, (byte) 3, (byte) 62, (byte) 193, (byte) 98, (byte) 97, + (byte) 125, (byte) 193, (byte) 51, (byte) 140, (byte) 224, (byte) 100, (byte) 18, (byte) 161, (byte) 112, + (byte) 79, (byte) 4, (byte) 231, (byte) 28, (byte) 147, (byte) 94, (byte) 181, (byte) 166, (byte) 120, + (byte) 67, (byte) 75, (byte) 177, (byte) 179, (byte) 120, (byte) 102, (byte) 139, (byte) 237, (byte) 147, + (byte) 79, (byte) 131, (byte) 61, (byte) 196, (byte) 220, (byte) 188, (byte) 135, (byte) 235, (byte) 216, + (byte) 123, (byte) 10, (byte) 124, (byte) 222, (byte) 19, (byte) 211, (byte) 93, (byte) 54, (byte) 196, + (byte) 247, (byte) 80, (byte) 127, (byte) 185, (byte) 59, (byte) 17, (byte) 244, (byte) 195, (byte) 100, + (byte) 126, (byte) 149, (byte) 180, (byte) 116, (byte) 86, (byte) 51, (byte) 111, (byte) 83, (byte) 197, + (byte) 26, (byte) 12, (byte) 188, (byte) 108, (byte) 73, (byte) 83, (byte) 27, (byte) 110, (byte) 7, + (byte) 29, (byte) 240, (byte) 71, (byte) 245, (byte) 171, (byte) 34, (byte) 95, (byte) 246, (byte) 114, + (byte) 58, (byte) 115, (byte) 197, (byte) 122, (byte) 140, (byte) 190, (byte) 2, (byte) 183, (byte) 111, + (byte) 185, (byte) 120, (byte) 157, (byte) 115, (byte) 137, (byte) 44, (byte) 45, (byte) 219, (byte) 245, + (byte) 8, (byte) 15, (byte) 235, (byte) 84, (byte) 102, (byte) 248, (byte) 124, (byte) 255, (byte) 0, + (byte) 193, (byte) 253, (byte) 157, (byte) 39, (byte) 185, (byte) 142, (byte) 116, (byte) 63, (byte) 248, + (byte) 236, (byte) 184, (byte) 253, (byte) 42, (byte) 249, (byte) 137, (byte) 177, (byte) 196, (byte) 232, + (byte) 250, (byte) 116, (byte) 26, (byte) 133, (byte) 196, (byte) 177, (byte) 207, (byte) 36, (byte) 232, + (byte) 171, (byte) 30, (byte) 71, (byte) 145, (byte) 24, (byte) 115, (byte) 156, (byte) 129, (byte) 158, + (byte) 189, (byte) 6, (byte) 106, (byte) 118, (byte) 183, (byte) 142, (byte) 203, (byte) 197, (byte) 22, + (byte) 241, (byte) 195, (byte) 191, (byte) 202, (byte) 23, (byte) 49, (byte) 58, (byte) 110, (byte) 77, + (byte) 188, (byte) 22, (byte) 7, (byte) 212, (byte) 156, (byte) 3, (byte) 145, (byte) 215, (byte) 181, + (byte) 116, (byte) 167, (byte) 193, (byte) 23, (byte) 246, (byte) 239, (byte) 190, (byte) 11, (byte) 82, + (byte) 174, (byte) 58, (byte) 61, (byte) 174, (byte) 163, (byte) 229, (byte) 159, (byte) 195, (byte) 116, + (byte) 68, (byte) 255, (byte) 0, (byte) 227, (byte) 213, (byte) 93, (byte) 188, (byte) 35, (byte) 173, + (byte) 155, (byte) 184, (byte) 238, (byte) 166, (byte) 183, (byte) 184, (byte) 118, (byte) 71, (byte) 83, + (byte) 243, (byte) 92, (byte) 164, (byte) 206, (byte) 66, (byte) 158, (byte) 57, (byte) 37, (byte) 106, + (byte) 44, (byte) 249, (byte) 249, (byte) 175, (byte) 167, (byte) 99, (byte) 75, (byte) 195, (byte) 146, + (byte) 214, (byte) 215, (byte) 189, (byte) 255, (byte) 0, (byte) 67, (byte) 110, (byte) 238, (byte) 242, + (byte) 223, (byte) 79, (byte) 178, (byte) 251, (byte) 69, (byte) 204, (byte) 155, (byte) 16, (byte) 0, + (byte) 56, (byte) 25, (byte) 44, (byte) 79, (byte) 64, (byte) 7, (byte) 114, (byte) 125, (byte) 41, + (byte) 52, (byte) 127, (byte) 14, (byte) 220, (byte) 106, (byte) 247, (byte) 17, (byte) 234, (byte) 154, + (byte) 236, (byte) 94, (byte) 92, (byte) 40, (byte) 119, (byte) 91, (byte) 88, (byte) 30, (byte) 139, + (byte) 232, (byte) 242, (byte) 122, (byte) 183, (byte) 183, (byte) 111, (byte) 207, (byte) 55, (byte) 52, + (byte) 95, (byte) 13, (byte) 204, (byte) 247, (byte) 73, (byte) 171, (byte) 107, (byte) 155, (byte) 94, + (byte) 237, (byte) 127, (byte) 212, (byte) 91, (byte) 41, (byte) 204, (byte) 118, (byte) 163, (byte) 219, + (byte) 213, (byte) 189, (byte) 91, (byte) 250, (byte) 99, (byte) 29, (byte) 53, (byte) 76, (byte) 99, + (byte) 97, (byte) 54, (byte) 0, (byte) 1, (byte) 192, (byte) 224, (byte) 81, (byte) 75, (byte) 69, + (byte) 89, (byte) 33, (byte) 69, (byte) 20, (byte) 80, (byte) 1, (byte) 73, (byte) 69, (byte) 20, (byte) 0, + (byte) 180, (byte) 152, (byte) 207, (byte) 90, (byte) 40, (byte) 160, (byte) 10, (byte) 243, (byte) 88, + (byte) 89, (byte) 220, (byte) 12, (byte) 77, (byte) 105, (byte) 4, (byte) 128, (byte) 255, (byte) 0, + (byte) 122, (byte) 48, (byte) 107, (byte) 54, (byte) 111, (byte) 7, (byte) 120, (byte) 114, (byte) 115, + (byte) 185, (byte) 244, (byte) 123, (byte) 96, (byte) 222, (byte) 168, (byte) 155, (byte) 79, (byte) 233, + (byte) 69, (byte) 20, (byte) 1, (byte) 89, (byte) 188, (byte) 17, (byte) 165, (byte) 143, (byte) 248, + (byte) 247, (byte) 184, (byte) 212, (byte) 45, (byte) 135, (byte) 101, (byte) 138, (byte) 241, (byte) 246, + (byte) 143, (byte) 192, (byte) 146, (byte) 42, (byte) 7, (byte) 240, (byte) 93, (byte) 194, (byte) 255, + (byte) 0, (byte) 199, (byte) 182, (byte) 191, (byte) 118, (byte) 163, (byte) 178, (byte) 205, (byte) 20, + (byte) 114, (byte) 126, (byte) 187, (byte) 115, (byte) 69, (byte) 20, (byte) 92, (byte) 8, (byte) 31, + (byte) 194, (byte) 254, (byte) 32, (byte) 143, (byte) 136, (byte) 181, (byte) 27, (byte) 9, (byte) 215, + (byte) 210, (byte) 88, (byte) 29, (byte) 79, (byte) 232, (byte) 216, (byte) 253, (byte) 42, (byte) 164, + (byte) 154, (byte) 39, (byte) 136, (byte) 225, (byte) 231, (byte) 251, (byte) 54, (byte) 218, (byte) 95, + (byte) 246, (byte) 173, (byte) 175, (byte) 154, (byte) 35, (byte) 255, (byte) 0, (byte) 160, (byte) 231, + (byte) 245, (byte) 162, (byte) 138, (byte) 119, (byte) 1, (byte) 26, (byte) 125, (byte) 122, (byte) 216, + (byte) 98, (byte) 77, (byte) 47, (byte) 88, (byte) 140, (byte) 142, (byte) 134, (byte) 23, (byte) 89, + (byte) 64, (byte) 252, (byte) 11, (byte) 16, (byte) 127, (byte) 21, (byte) 52, (byte) 209, (byte) 173, + (byte) 100, (byte) 236, (byte) 187, (byte) 211, (byte) 111, (byte) 195, (byte) 147, (byte) 247, (byte) 163, + (byte) 178, (byte) 144, (byte) 17, (byte) 245, (byte) 24, (byte) 193, (byte) 247, (byte) 32, (byte) 253, + (byte) 5, (byte) 20, (byte) 82, (byte) 105, (byte) 49, (byte) 167, (byte) 97, (byte) 214, (byte) 218, + (byte) 62, (byte) 163, (byte) 226, (byte) 89, (byte) 74, (byte) 186, (byte) 207, (byte) 167, (byte) 105, + (byte) 32, (byte) 225, (byte) 153, (byte) 148, (byte) 164, (byte) 247, (byte) 62, (byte) 192, (byte) 117, + (byte) 69, (byte) 253, (byte) 79, (byte) 183, (byte) 34, (byte) 187, (byte) 75, (byte) 13, (byte) 62, + (byte) 211, (byte) 75, (byte) 179, (byte) 142, (byte) 210, (byte) 202, (byte) 4, (byte) 130, (byte) 24, + (byte) 198, (byte) 21, (byte) 84, (byte) 81, (byte) 69, (byte) 36, (byte) 172, (byte) 13, (byte) 220, + (byte) 181, (byte) 69, (byte) 20, (byte) 83, (byte) 16, (byte) 81, (byte) 69, (byte) 20, (byte) 0, + (byte) 148, (byte) 81, (byte) 69, (byte) 0, (byte) 45, (byte) 20, (byte) 81, (byte) 64, (byte) 5, + (byte) 20, (byte) 81, (byte) 64, (byte) 31, (byte) 255, (byte) 217 + + }; + +} diff --git a/src/net/sourceforge/plantuml/eggs/PSystemAppleTwoFactory.java b/src/net/sourceforge/plantuml/eggs/PSystemAppleTwoFactory.java new file mode 100644 index 000000000..f9468b39e --- /dev/null +++ b/src/net/sourceforge/plantuml/eggs/PSystemAppleTwoFactory.java @@ -0,0 +1,59 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 3830 $ + * + */ +package net.sourceforge.plantuml.eggs; + +import java.io.IOException; + +import net.sourceforge.plantuml.AbstractPSystem; +import net.sourceforge.plantuml.Log; +import net.sourceforge.plantuml.command.PSystemSingleLineFactory; + +public class PSystemAppleTwoFactory extends PSystemSingleLineFactory { + + @Override + protected AbstractPSystem executeLine(String line) { + if (line.equalsIgnoreCase("apple //e") || line.equalsIgnoreCase("apple ][") + || line.equalsIgnoreCase("apple II") || line.equalsIgnoreCase("Steve Jobs") + || line.equalsIgnoreCase("Steve Wozniak")) { + try { + return new PSystemAppleTwo(); + } catch (IOException e) { + Log.error("Error " + e); + e.printStackTrace(); + } + } + return null; + } + +} diff --git a/src/net/sourceforge/plantuml/eggs/PSystemEgg.java b/src/net/sourceforge/plantuml/eggs/PSystemEgg.java index d86d1fdd2..91027a243 100644 --- a/src/net/sourceforge/plantuml/eggs/PSystemEgg.java +++ b/src/net/sourceforge/plantuml/eggs/PSystemEgg.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6710 $ + * Revision $Revision: 12053 $ * */ package net.sourceforge.plantuml.eggs; @@ -42,8 +42,12 @@ import java.util.StringTokenizer; import net.sourceforge.plantuml.AbstractPSystem; import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.core.DiagramDescription; +import net.sourceforge.plantuml.core.DiagramDescriptionImpl; +import net.sourceforge.plantuml.core.ImageData; import net.sourceforge.plantuml.graphic.GraphicStrings; -import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.ugraphic.UAntiAliasing; import net.sourceforge.plantuml.ugraphic.UFont; public class PSystemEgg extends AbstractPSystem { @@ -57,17 +61,17 @@ public class PSystemEgg extends AbstractPSystem { } } - public void exportDiagram(OutputStream os, StringBuilder cmap, int index, FileFormatOption fileFormat) throws IOException { - getGraphicStrings().writeImage(os, fileFormat); + public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException { + return getGraphicStrings().exportDiagram(os, fileFormat); } private GraphicStrings getGraphicStrings() throws IOException { final UFont font = new UFont("SansSerif", Font.PLAIN, 12); - return new GraphicStrings(strings, font, HtmlColor.BLACK, HtmlColor.WHITE, false); + return new GraphicStrings(strings, font, HtmlColorUtils.BLACK, HtmlColorUtils.WHITE, UAntiAliasing.ANTI_ALIASING_ON); } - public String getDescription() { - return "(Easter Eggs)"; + public DiagramDescription getDescription() { + return new DiagramDescriptionImpl("(Easter Eggs)", getClass()); } } diff --git a/src/net/sourceforge/plantuml/eggs/PSystemEggFactory.java b/src/net/sourceforge/plantuml/eggs/PSystemEggFactory.java index 95396b14e..1d8d2e8d8 100644 --- a/src/net/sourceforge/plantuml/eggs/PSystemEggFactory.java +++ b/src/net/sourceforge/plantuml/eggs/PSystemEggFactory.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6750 $ + * Revision $Revision: 10298 $ * */ package net.sourceforge.plantuml.eggs; @@ -37,45 +37,30 @@ import java.io.UnsupportedEncodingException; import java.util.Arrays; import java.util.List; -import net.sourceforge.plantuml.DiagramType; -import net.sourceforge.plantuml.PSystemBasicFactory; +import net.sourceforge.plantuml.AbstractPSystem; +import net.sourceforge.plantuml.command.PSystemSingleLineFactory; -public class PSystemEggFactory implements PSystemBasicFactory { - - private PSystemEgg system; - - public void init(String startLine) { - } +public class PSystemEggFactory extends PSystemSingleLineFactory { final static private List all = Arrays - .asList( - EggUtils - .toByteArrays("56092d35fce86a0dd88047a766c1d6541a7c5fd5ba212fa02db9a32a463422febd71a75a934eb135dec7d6c6325ddd17fd2fa437eba863462b28e3e92514998306a72790d93501335ed6b1262ea46ab79573142c28f8e92508978255a533d9cf7903394f9ab73a33b230a2b273033633adf16044888243b92f9bd8351f3d4f9aa2302fb264afa37546368424fa6a07919152bd2990d935092e49d9a02038b437aeb528"), + .asList(EggUtils + .toByteArrays("56092d35fce86a0dd88047a766c1d6541a7c5fd5ba212fa02db9a32a463422febd71a75a934eb135dec7d6c6325ddd17fd2fa437eba863462b28e3e92514998306a72790d93501335ed6b1262ea46ab79573142c28f8e92508978255a533d9cf7903394f9ab73a33b230a2b273033633adf16044888243b92f9bd8351f3d4f9aa2302fb264afa37546368424fa6a07919152bd2990d935092e49d9a02038b437aeb528"), EggUtils.toByteArrays("421e5b773c5df733a1194f716f18e8842155196b3b")); - public boolean executeLine(String line) { + @Override + protected AbstractPSystem executeLine(String line) { try { for (byte[] crypted : all) { final SentenceDecoder decoder = new SentenceDecoder(line, crypted); if (decoder.isOk()) { - system = new PSystemEgg(decoder.getSecret()); - return true; + return new PSystemEgg(decoder.getSecret()); } } } catch (UnsupportedEncodingException e) { - return false; + return null; } - return false; + return null; } - public PSystemEgg getSystem() { - return system; - } - - public DiagramType getDiagramType() { - return DiagramType.UML; - } - - } diff --git a/src/net/sourceforge/plantuml/eggs/PSystemLost.java b/src/net/sourceforge/plantuml/eggs/PSystemLost.java index 509cbb55d..5fcd80358 100644 --- a/src/net/sourceforge/plantuml/eggs/PSystemLost.java +++ b/src/net/sourceforge/plantuml/eggs/PSystemLost.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -41,8 +41,12 @@ import java.util.List; import net.sourceforge.plantuml.AbstractPSystem; import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.core.DiagramDescription; +import net.sourceforge.plantuml.core.DiagramDescriptionImpl; +import net.sourceforge.plantuml.core.ImageData; import net.sourceforge.plantuml.graphic.GraphicStrings; -import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.ugraphic.UAntiAliasing; import net.sourceforge.plantuml.ugraphic.UFont; public class PSystemLost extends AbstractPSystem { @@ -53,17 +57,18 @@ public class PSystemLost extends AbstractPSystem { strings.add("Thank you for choosing Oceanic Airlines."); } - public void exportDiagram(OutputStream os, StringBuilder cmap, int index, FileFormatOption fileFormat) throws IOException { - getGraphicStrings().writeImage(os, fileFormat); + public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException { + return getGraphicStrings().exportDiagram(os, fileFormat); } private GraphicStrings getGraphicStrings() throws IOException { final UFont font = new UFont("SansSerif", Font.PLAIN, 12); - return new GraphicStrings(strings, font, HtmlColor.BLACK, HtmlColor.WHITE, null, null, false); + return new GraphicStrings(strings, font, HtmlColorUtils.BLACK, HtmlColorUtils.WHITE, null, null, + UAntiAliasing.ANTI_ALIASING_ON); } - public String getDescription() { - return "(Lost)"; + public DiagramDescription getDescription() { + return new DiagramDescriptionImpl("(Lost)", getClass()); } } diff --git a/src/net/sourceforge/plantuml/eggs/PSystemLostFactory.java b/src/net/sourceforge/plantuml/eggs/PSystemLostFactory.java index 4bef187bf..31dfb3bc4 100644 --- a/src/net/sourceforge/plantuml/eggs/PSystemLostFactory.java +++ b/src/net/sourceforge/plantuml/eggs/PSystemLostFactory.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,31 +33,17 @@ */ package net.sourceforge.plantuml.eggs; -import net.sourceforge.plantuml.DiagramType; -import net.sourceforge.plantuml.PSystemBasicFactory; +import net.sourceforge.plantuml.AbstractPSystem; +import net.sourceforge.plantuml.command.PSystemSingleLineFactory; -public class PSystemLostFactory implements PSystemBasicFactory { +public class PSystemLostFactory extends PSystemSingleLineFactory { - private PSystemLost system; - - public void init(String startLine) { - } - - public boolean executeLine(String line) { + @Override + protected AbstractPSystem executeLine(String line) { if (line.matches("^4\\D+8\\D+15\\D+16\\D+23\\D+42")) { - system = new PSystemLost(); - return true; + return new PSystemLost(); } - return false; + return null; } - public PSystemLost getSystem() { - return system; - } - - public DiagramType getDiagramType() { - return DiagramType.UML; - } - - } diff --git a/src/net/sourceforge/plantuml/eggs/PSystemPath.java b/src/net/sourceforge/plantuml/eggs/PSystemPath.java index 9375b9744..b730f4528 100644 --- a/src/net/sourceforge/plantuml/eggs/PSystemPath.java +++ b/src/net/sourceforge/plantuml/eggs/PSystemPath.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -38,6 +38,9 @@ import java.io.OutputStream; import net.sourceforge.plantuml.AbstractPSystem; import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.core.DiagramDescription; +import net.sourceforge.plantuml.core.DiagramDescriptionImpl; +import net.sourceforge.plantuml.core.ImageData; import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity; public class PSystemPath extends AbstractPSystem { @@ -49,13 +52,15 @@ public class PSystemPath extends AbstractPSystem { } - public void exportDiagram(OutputStream os, StringBuilder cmap, int index, FileFormatOption fileFormat) throws IOException { - path.writeImage(os); + public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException { + return path.writeImage(os); } - public String getDescription() { - return "(Path)"; + public DiagramDescription getDescription() { + return new DiagramDescriptionImpl("(Path)", getClass()); } + + } diff --git a/src/net/sourceforge/plantuml/eggs/PSystemPathFactory.java b/src/net/sourceforge/plantuml/eggs/PSystemPathFactory.java index 58c314d82..58a698420 100644 --- a/src/net/sourceforge/plantuml/eggs/PSystemPathFactory.java +++ b/src/net/sourceforge/plantuml/eggs/PSystemPathFactory.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -36,35 +36,20 @@ package net.sourceforge.plantuml.eggs; import java.util.regex.Matcher; import java.util.regex.Pattern; -import net.sourceforge.plantuml.DiagramType; -import net.sourceforge.plantuml.PSystemBasicFactory; +import net.sourceforge.plantuml.AbstractPSystem; +import net.sourceforge.plantuml.command.PSystemSingleLineFactory; -public class PSystemPathFactory implements PSystemBasicFactory { +public class PSystemPathFactory extends PSystemSingleLineFactory { - private PSystemPath system; + final private static Pattern p = Pattern.compile("(?i)^path\\s+([0-9A-Za-z]+)$"); - public void init(String startLine) { - } - - final private static Pattern p = Pattern - .compile("(?i)^path\\s+([0-9A-Za-z]+)$"); - - public boolean executeLine(String line) { + @Override + protected AbstractPSystem executeLine(String line) { final Matcher m = p.matcher(line); if (m.find() == false) { - return false; + return null; } - system = new PSystemPath(m.group(1)); - return true; + return new PSystemPath(m.group(1)); } - public PSystemPath getSystem() { - return system; - } - - public DiagramType getDiagramType() { - return DiagramType.UML; - } - - } diff --git a/src/net/sourceforge/plantuml/eggs/PSystemRIP.java b/src/net/sourceforge/plantuml/eggs/PSystemRIP.java index 84302bc0d..b5a845399 100644 --- a/src/net/sourceforge/plantuml/eggs/PSystemRIP.java +++ b/src/net/sourceforge/plantuml/eggs/PSystemRIP.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -46,9 +46,13 @@ import javax.imageio.ImageIO; import net.sourceforge.plantuml.AbstractPSystem; import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.core.DiagramDescription; +import net.sourceforge.plantuml.core.DiagramDescriptionImpl; +import net.sourceforge.plantuml.core.ImageData; import net.sourceforge.plantuml.graphic.GraphicPosition; import net.sourceforge.plantuml.graphic.GraphicStrings; -import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.ugraphic.UAntiAliasing; import net.sourceforge.plantuml.ugraphic.UFont; public class PSystemRIP extends AbstractPSystem { @@ -73,17 +77,20 @@ public class PSystemRIP extends AbstractPSystem { is.close(); } - public void exportDiagram(OutputStream os, StringBuilder cmap, int index, FileFormatOption fileFormat) throws IOException { - getGraphicStrings().writeImage(os, fileFormat); + + public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException { + return getGraphicStrings().exportDiagram(os, fileFormat); } + private GraphicStrings getGraphicStrings() throws IOException { final UFont font = new UFont("SansSerif", Font.PLAIN, 12); - return new GraphicStrings(strings, font, HtmlColor.BLACK, HtmlColor.WHITE, image, GraphicPosition.BOTTOM, false); + return new GraphicStrings(strings, font, HtmlColorUtils.BLACK, HtmlColorUtils.WHITE, image, + GraphicPosition.BOTTOM, UAntiAliasing.ANTI_ALIASING_ON); } - public String getDescription() { - return "(RIP)"; + public DiagramDescription getDescription() { + return new DiagramDescriptionImpl("(RIP)", getClass()); } private static final byte imm[] = new byte[] { (byte) 255, (byte) 216, (byte) 255, (byte) 224, (byte) 0, (byte) 16, @@ -452,4 +459,5 @@ public class PSystemRIP extends AbstractPSystem { }; + } diff --git a/src/net/sourceforge/plantuml/eggs/PSystemRIPFactory.java b/src/net/sourceforge/plantuml/eggs/PSystemRIPFactory.java index 215bd70e9..2464d6825 100644 --- a/src/net/sourceforge/plantuml/eggs/PSystemRIPFactory.java +++ b/src/net/sourceforge/plantuml/eggs/PSystemRIPFactory.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -35,38 +35,23 @@ package net.sourceforge.plantuml.eggs; import java.io.IOException; -import net.sourceforge.plantuml.DiagramType; +import net.sourceforge.plantuml.AbstractPSystem; import net.sourceforge.plantuml.Log; -import net.sourceforge.plantuml.PSystemBasicFactory; +import net.sourceforge.plantuml.command.PSystemSingleLineFactory; -public class PSystemRIPFactory implements PSystemBasicFactory { +public class PSystemRIPFactory extends PSystemSingleLineFactory { - private PSystemRIP system; - - public void init(String startLine) { - } - - public boolean executeLine(String line) { + @Override + protected AbstractPSystem executeLine(String line) { if (line.equalsIgnoreCase("jean canouet")) { try { - system = new PSystemRIP(); - return true; + return new PSystemRIP(); } catch (IOException e) { Log.error("Error " + e); e.printStackTrace(); - return false; } } - return false; + return null; } - public PSystemRIP getSystem() { - return system; - } - - public DiagramType getDiagramType() { - return DiagramType.UML; - } - - } diff --git a/src/net/sourceforge/plantuml/eggs/SentenceDecoder.java b/src/net/sourceforge/plantuml/eggs/SentenceDecoder.java index f695f1db4..c9f729be6 100644 --- a/src/net/sourceforge/plantuml/eggs/SentenceDecoder.java +++ b/src/net/sourceforge/plantuml/eggs/SentenceDecoder.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.eggs; diff --git a/src/net/sourceforge/plantuml/eggs/SentenceProducer.java b/src/net/sourceforge/plantuml/eggs/SentenceProducer.java index 74f889cf6..ef084a983 100644 --- a/src/net/sourceforge/plantuml/eggs/SentenceProducer.java +++ b/src/net/sourceforge/plantuml/eggs/SentenceProducer.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.eggs; diff --git a/src/net/sourceforge/plantuml/eps/EpsGraphics.java b/src/net/sourceforge/plantuml/eps/EpsGraphics.java index e90dac133..4a2660dfa 100644 --- a/src/net/sourceforge/plantuml/eps/EpsGraphics.java +++ b/src/net/sourceforge/plantuml/eps/EpsGraphics.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -40,12 +40,14 @@ import java.util.Date; import java.util.Locale; import java.util.StringTokenizer; +import net.sourceforge.plantuml.Log; +import net.sourceforge.plantuml.graphic.HtmlColorGradient; import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.ShadowManager; -import net.sourceforge.plantuml.ugraphic.UGradient; import net.sourceforge.plantuml.ugraphic.UPath; import net.sourceforge.plantuml.ugraphic.USegment; import net.sourceforge.plantuml.ugraphic.USegmentType; +import net.sourceforge.plantuml.version.Version; public class EpsGraphics { @@ -71,7 +73,11 @@ public class EpsGraphics { public EpsGraphics() { header.append("%!PS-Adobe-3.0 EPSF-3.0\n"); - header.append("%%Creator: PlantUML\n"); + String v = Version.versionString(); + if (v.endsWith("beta") == false) { + v += " "; + } + header.append("%%Creator: PlantUML v" + v + "\n"); header.append("%%Title: noTitle\n"); header.append("%%CreationDate: " + new Date() + "\n"); setcolorgradient.add(new PostScriptCommandRaw("3 index 7 index sub 1 index mul 7 index add", true)); @@ -188,7 +194,8 @@ public class EpsGraphics { private double dashVisible = 0; private double dashSpace = 0; - public void newpathDot(boolean dashed) { + public void newpathDot() { + final boolean dashed = dashVisible != 0 || dashSpace != 0; checkCloseDone(); append(strokeWidth + " setlinewidth", true); appendColor(color); @@ -199,7 +206,8 @@ public class EpsGraphics { append("newpath", true); } - public void closepathDot(boolean dashed) { + public void closepathDot() { + final boolean dashed = dashVisible != 0 || dashSpace != 0; append("stroke", true); if (dashed) { append("[] 0 setdash", true); @@ -221,7 +229,7 @@ public class EpsGraphics { } else if (y1 == y2) { epsVLine(y1, Math.min(x1, x2), Math.max(x1, x2)); } - append("closepath stroke", true); + append("stroke", true); ensureVisible(Math.max(x1, x2), Math.max(y1, y2)); } @@ -272,12 +280,12 @@ public class EpsGraphics { } else if (type == USegmentType.SEG_CLOSE) { // Nothing } else { - System.err.println("unknown " + seg); + Log.println("unknown " + seg); } } append("closepath eofill", true); } - + if (color != null) { append(strokeWidth + " setlinewidth", true); appendColor(color); @@ -296,10 +304,10 @@ public class EpsGraphics { } else if (type == USegmentType.SEG_CLOSE) { // Nothing } else { - System.err.println("unknown " + seg); + Log.println("unknown " + seg); } } - append("closepath stroke", true); + append("stroke", true); } } @@ -371,8 +379,8 @@ public class EpsGraphics { append("/ANN pdfmark", true); } - public void epsRectangle(double x, double y, double width, double height, double rx, double ry, UGradient gr, - ColorMapper mapper) { + public void epsRectangle(double x, double y, double width, double height, double rx, double ry, + HtmlColorGradient gr, ColorMapper mapper) { checkCloseDone(); ensureVisible(x, y); ensureVisible(x + width, y + height); @@ -458,13 +466,16 @@ public class EpsGraphics { public void epsEllipse(double x, double y, double xRadius, double yRadius) { checkCloseDone(); ensureVisible(x + xRadius, y + yRadius); + double scale = 1; if (xRadius != yRadius) { - throw new UnsupportedOperationException(); + scale = yRadius / xRadius; + append("gsave", true); + append("1 " + format(scale) + " scale", true); } if (fillcolor != null) { appendColor(fillcolor); append("newpath", true); - append(format(x) + " " + format(y) + " " + format(xRadius) + " 0 360 arc", true); + append(format(x) + " " + format(y / scale) + " " + format(xRadius) + " 0 360 arc", true); append("closepath eofill", true); } @@ -472,9 +483,14 @@ public class EpsGraphics { append(strokeWidth + " setlinewidth", true); appendColor(color); append("newpath", true); - append(format(x) + " " + format(y) + " " + format(xRadius) + " 0 360 arc", true); + append(format(x) + " " + format(y / scale) + " " + format(xRadius) + " 0 360 arc", true); append("closepath stroke", true); } + + if (scale != 1) { + append("grestore", true); + } + } protected void appendColor(Color c) { diff --git a/src/net/sourceforge/plantuml/eps/EpsGraphicsMacro.java b/src/net/sourceforge/plantuml/eps/EpsGraphicsMacro.java index 22ea6b97b..0b92f819d 100644 --- a/src/net/sourceforge/plantuml/eps/EpsGraphicsMacro.java +++ b/src/net/sourceforge/plantuml/eps/EpsGraphicsMacro.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/eps/EpsGraphicsMacroAndText.java b/src/net/sourceforge/plantuml/eps/EpsGraphicsMacroAndText.java index 240aad4d2..5bce6812a 100644 --- a/src/net/sourceforge/plantuml/eps/EpsGraphicsMacroAndText.java +++ b/src/net/sourceforge/plantuml/eps/EpsGraphicsMacroAndText.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -87,7 +87,7 @@ public class EpsGraphicsMacroAndText extends EpsGraphicsMacro { try { final byte b[] = s.getBytes("ISO-8859-1"); if (b.length == 1) { - final int code = (b[0] & 0xFF); + final int code = b[0] & 0xFF; sb.append("\\" + Integer.toOctalString(code)); } else { sb.append('?'); diff --git a/src/net/sourceforge/plantuml/eps/EpsStrategy.java b/src/net/sourceforge/plantuml/eps/EpsStrategy.java index c90f85e63..3ae304621 100644 --- a/src/net/sourceforge/plantuml/eps/EpsStrategy.java +++ b/src/net/sourceforge/plantuml/eps/EpsStrategy.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/eps/EpsTitler.java b/src/net/sourceforge/plantuml/eps/EpsTitler.java index 9013c170b..8ba7574b9 100644 --- a/src/net/sourceforge/plantuml/eps/EpsTitler.java +++ b/src/net/sourceforge/plantuml/eps/EpsTitler.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -39,40 +39,44 @@ import java.io.IOException; import java.util.List; import java.util.StringTokenizer; +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.graphic.FontConfiguration; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; import net.sourceforge.plantuml.graphic.HtmlColor; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; import net.sourceforge.plantuml.graphic.VerticalPosition; import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UTranslate; import net.sourceforge.plantuml.ugraphic.eps.UGraphicEps; public final class EpsTitler { private final List text; - private final HorizontalAlignement horizontalAlignement; + private final HorizontalAlignment horizontalAlignment; private final VerticalPosition verticalPosition; private final int margin; private final TextBlock textBloc; private final EpsStrategy epsStrategy; private final ColorMapper colorMapper; - public EpsTitler(ColorMapper colorMapper, EpsStrategy epsStrategy, HtmlColor textColor, List text, int fontSize, String fontFamily, - HorizontalAlignement horizontalAlignement, VerticalPosition verticalPosition, int margin) { + public EpsTitler(ColorMapper colorMapper, EpsStrategy epsStrategy, HtmlColor textColor, + List text, int fontSize, String fontFamily, + HorizontalAlignment horizontalAlignment, VerticalPosition verticalPosition, int margin) { this.text = text; this.colorMapper = colorMapper; this.epsStrategy = epsStrategy; - this.horizontalAlignement = horizontalAlignement; + this.horizontalAlignment = horizontalAlignment; this.verticalPosition = verticalPosition; this.margin = margin; if (text == null || text.size() == 0) { textBloc = null; } else { final UFont normalFont = new UFont(fontFamily, Font.PLAIN, fontSize); - textBloc = TextBlockUtils.create(text, new FontConfiguration(normalFont, textColor), - HorizontalAlignement.LEFT); + textBloc = TextBlockUtils.create(new Display(text), new FontConfiguration(normalFont, textColor), + HorizontalAlignment.LEFT, new SpriteContainerEmpty()); } } @@ -80,7 +84,8 @@ public final class EpsTitler { if (textBloc == null) { return 0; } - return textBloc.calculateDimension(new UGraphicEps(colorMapper, epsStrategy).getStringBounder()).getHeight() + margin; + return textBloc.calculateDimension(new UGraphicEps(colorMapper, epsStrategy).getStringBounder()).getHeight() + + margin; } public String addTitleEps(String eps) throws IOException { @@ -107,11 +112,11 @@ public final class EpsTitler { final Dimension2D dimText = textBloc.calculateDimension(uGraphicEps.getStringBounder()); final double xpos; - if (horizontalAlignement == HorizontalAlignement.LEFT) { + if (horizontalAlignment == HorizontalAlignment.LEFT) { xpos = 2; - } else if (horizontalAlignement == HorizontalAlignement.RIGHT) { + } else if (horizontalAlignment == HorizontalAlignment.RIGHT) { xpos = width - dimText.getWidth() - 2; - } else if (horizontalAlignement == HorizontalAlignement.CENTER) { + } else if (horizontalAlignment == HorizontalAlignment.CENTER) { xpos = (width - dimText.getWidth()) / 2; } else { xpos = 0; @@ -126,7 +131,7 @@ public final class EpsTitler { yText = height + margin; } - textBloc.drawU(uGraphicEps, xpos, yText); + textBloc.drawU(uGraphicEps.apply(new UTranslate(xpos, yText))); final double yImage; if (verticalPosition == VerticalPosition.TOP) { diff --git a/src/net/sourceforge/plantuml/eps/PostScriptCommand.java b/src/net/sourceforge/plantuml/eps/PostScriptCommand.java index aa937d3bf..15aeabfa3 100644 --- a/src/net/sourceforge/plantuml/eps/PostScriptCommand.java +++ b/src/net/sourceforge/plantuml/eps/PostScriptCommand.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/eps/PostScriptCommandCurveTo.java b/src/net/sourceforge/plantuml/eps/PostScriptCommandCurveTo.java index 8a6447dba..8d1a72882 100644 --- a/src/net/sourceforge/plantuml/eps/PostScriptCommandCurveTo.java +++ b/src/net/sourceforge/plantuml/eps/PostScriptCommandCurveTo.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/eps/PostScriptCommandLineTo.java b/src/net/sourceforge/plantuml/eps/PostScriptCommandLineTo.java index d240f150c..759c188e4 100644 --- a/src/net/sourceforge/plantuml/eps/PostScriptCommandLineTo.java +++ b/src/net/sourceforge/plantuml/eps/PostScriptCommandLineTo.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/eps/PostScriptCommandMacro.java b/src/net/sourceforge/plantuml/eps/PostScriptCommandMacro.java index 2bb932925..3417f5b6f 100644 --- a/src/net/sourceforge/plantuml/eps/PostScriptCommandMacro.java +++ b/src/net/sourceforge/plantuml/eps/PostScriptCommandMacro.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/eps/PostScriptCommandMoveTo.java b/src/net/sourceforge/plantuml/eps/PostScriptCommandMoveTo.java index b84e39153..1517fe92a 100644 --- a/src/net/sourceforge/plantuml/eps/PostScriptCommandMoveTo.java +++ b/src/net/sourceforge/plantuml/eps/PostScriptCommandMoveTo.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/eps/PostScriptCommandQuadTo.java b/src/net/sourceforge/plantuml/eps/PostScriptCommandQuadTo.java index db65eb43b..933d3415c 100644 --- a/src/net/sourceforge/plantuml/eps/PostScriptCommandQuadTo.java +++ b/src/net/sourceforge/plantuml/eps/PostScriptCommandQuadTo.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/eps/PostScriptCommandRaw.java b/src/net/sourceforge/plantuml/eps/PostScriptCommandRaw.java index df7e73d3e..ad1fa16db 100644 --- a/src/net/sourceforge/plantuml/eps/PostScriptCommandRaw.java +++ b/src/net/sourceforge/plantuml/eps/PostScriptCommandRaw.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/eps/PostScriptData.java b/src/net/sourceforge/plantuml/eps/PostScriptData.java index 6f6226477..958f39025 100644 --- a/src/net/sourceforge/plantuml/eps/PostScriptData.java +++ b/src/net/sourceforge/plantuml/eps/PostScriptData.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/flashcode/FlashCodeFactory.java b/src/net/sourceforge/plantuml/flashcode/FlashCodeFactory.java new file mode 100644 index 000000000..cbd6ce9ef --- /dev/null +++ b/src/net/sourceforge/plantuml/flashcode/FlashCodeFactory.java @@ -0,0 +1,52 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8515 $ + * + */ +package net.sourceforge.plantuml.flashcode; + +public class FlashCodeFactory { + + public static FlashCodeUtils getFlashCodeUtils() { + final String name = "net.sourceforge.plantuml.flashcode.FlashCodeUtilsZxing"; + try { + final Class cl = Class.forName(name); + return (FlashCodeUtils) cl.newInstance(); + } catch (ClassNotFoundException e) { + return new FlashCodeUtilsNone(); + } catch (InstantiationException e) { + return new FlashCodeUtilsNone(); + } catch (IllegalAccessException e) { + return new FlashCodeUtilsNone(); + } + } + +} diff --git a/src/net/sourceforge/plantuml/flashcode/FlashCodeUtils.java b/src/net/sourceforge/plantuml/flashcode/FlashCodeUtils.java new file mode 100644 index 000000000..f82a01556 --- /dev/null +++ b/src/net/sourceforge/plantuml/flashcode/FlashCodeUtils.java @@ -0,0 +1,48 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8515 $ + * + */ +package net.sourceforge.plantuml.flashcode; + +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.util.List; + +public interface FlashCodeUtils { + + public List exportFlashcodeSimple(String s) throws IOException; + + public List exportFlashcodeCompress(String s) throws IOException; + + public List exportSplitCompress(String s) throws IOException; + +} diff --git a/src/net/sourceforge/plantuml/PSystem.java b/src/net/sourceforge/plantuml/flashcode/FlashCodeUtilsNone.java similarity index 66% rename from src/net/sourceforge/plantuml/PSystem.java rename to src/net/sourceforge/plantuml/flashcode/FlashCodeUtilsNone.java index d8021a7dd..94a1cda4f 100644 --- a/src/net/sourceforge/plantuml/PSystem.java +++ b/src/net/sourceforge/plantuml/flashcode/FlashCodeUtilsNone.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,28 +28,27 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6513 $ + * Revision $Revision: 8515 $ * */ -package net.sourceforge.plantuml; +package net.sourceforge.plantuml.flashcode; -import java.io.File; +import java.awt.image.BufferedImage; import java.io.IOException; -import java.io.OutputStream; import java.util.List; -public interface PSystem { +public class FlashCodeUtilsNone implements FlashCodeUtils { - List exportDiagrams(File suggestedFile, FileFormatOption fileFormatOption) throws IOException, InterruptedException; + public List exportFlashcodeSimple(String s) throws IOException { + return null; + } - void exportDiagram(OutputStream os, StringBuilder cmap, int index, FileFormatOption fileFormatOption) throws IOException; - - int getNbImages(); + public List exportFlashcodeCompress(String s) throws IOException { + return null; + } - String getDescription(); - - String getMetadata(); - - UmlSource getSource(); + public List exportSplitCompress(String s) throws IOException { + return null; + } } diff --git a/src/net/sourceforge/plantuml/flashcode/FlashCodeUtilsZxing.java b/src/net/sourceforge/plantuml/flashcode/FlashCodeUtilsZxing.java new file mode 100644 index 000000000..dc68cb4a2 --- /dev/null +++ b/src/net/sourceforge/plantuml/flashcode/FlashCodeUtilsZxing.java @@ -0,0 +1,148 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8515 $ + * + */ +package net.sourceforge.plantuml.flashcode; + +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Hashtable; +import java.util.List; + +import net.sourceforge.plantuml.code.Compression; +import net.sourceforge.plantuml.code.CompressionZlib; + +import com.google.zxing.BarcodeFormat; +import com.google.zxing.EncodeHintType; +import com.google.zxing.WriterException; +import com.google.zxing.client.j2se.MatrixToImageWriter; +import com.google.zxing.common.BitMatrix; +import com.google.zxing.qrcode.QRCodeWriter; +import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; + +public class FlashCodeUtilsZxing implements FlashCodeUtils { + + public List exportFlashcodeSimple(String s) throws IOException { + try { + final QRCodeWriter writer = new QRCodeWriter(); + final Hashtable hints = new Hashtable(); + hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); + final int multiple = 1; + final BitMatrix bit = writer.encode(s, BarcodeFormat.QR_CODE, multiple); + final BufferedImage im = MatrixToImageWriter.toBufferedImage(bit); + return Arrays.asList(im); + } catch (WriterException e) { + throw new IOException("WriterException"); + } + } + + public List exportFlashcodeCompress(String s) throws IOException { + try { + final QRCodeWriter writer = new QRCodeWriter(); + final Hashtable hints = new Hashtable(); + hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); + + final Compression comp = new CompressionZlib(); + final byte data[] = comp.compress(s.getBytes("UTF-8")); + + // Encoder.DEFAULT_BYTE_MODE_ENCODING + final int multiple = 1; + final BitMatrix bit = writer.encode(new String(data, "ISO-8859-1"), BarcodeFormat.QR_CODE, multiple); + final BufferedImage im = MatrixToImageWriter.toBufferedImage(bit); + return Arrays.asList(im); + } catch (WriterException e) { + throw new IOException("WriterException"); + } + } + + public List exportSplitCompress(String s) throws IOException { + final QRCodeWriter writer = new QRCodeWriter(); + final Hashtable hints = new Hashtable(); + hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); + + final Compression comp = new CompressionZlib(); + final byte data[] = comp.compress(s.getBytes("UTF-8")); + + final List result = new ArrayList(); + + final List blocs = new ArrayList(); + for (int i = 0; i < 4; i++) { + blocs.add(getSplited(data, i, 4)); + } + + blocs.add(xor(blocs)); + + try { + final int multiple = 1; + for (byte d[] : blocs) { + // Encoder.DEFAULT_BYTE_MODE_ENCODING + final BitMatrix bit = writer.encode(new String(d, "ISO-8859-1"), BarcodeFormat.QR_CODE, multiple); + result.add(MatrixToImageWriter.toBufferedImage(bit)); + } + } catch (WriterException e) { + throw new IOException("WriterException"); + } + + return Collections.unmodifiableList(result); + } + + static byte[] xor(List blocs) { + final byte result[] = new byte[blocs.get(0).length]; + for (int i = 0; i < result.length; i++) { + result[i] = xor(blocs, i); + } + return result; + } + + static byte xor(List blocs, int nb) { + byte result = 0; + for (byte[] bloc : blocs) { + result = (byte) (result ^ bloc[nb]); + } + return result; + } + + static byte[] getSplited(byte[] data, int n, int total) { + final int size = (data.length + total - 1) / total; + assert size * total >= data.length; + final byte result[] = new byte[size + 1]; + result[0] = (byte) (1 << n); + for (int i = 0; (i < size) && (n * total + i < data.length); i++) { + result[i + 1] = data[n * total + i]; + } + return result; + } + +} diff --git a/src/net/sourceforge/plantuml/flowdiagram/ActivityBox.java b/src/net/sourceforge/plantuml/flowdiagram/ActivityBox.java new file mode 100644 index 000000000..fc2007fa8 --- /dev/null +++ b/src/net/sourceforge/plantuml/flowdiagram/ActivityBox.java @@ -0,0 +1,109 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.flowdiagram; + +import java.awt.Font; +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.golem.Tile; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.Shadowable; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UStroke; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class ActivityBox implements TextBlock { + + private static final int CORNER = 25; + private static final int MARGIN = 10; + + private final Tile tile; + private final String id; + private final String label; + private final TextBlock tb; + + public ActivityBox(Tile tile, String id, String label) { + this.tile = tile; + this.id = id; + this.label = label; + final UFont font = new UFont("Serif", Font.PLAIN, 14); + final FontConfiguration fc = new FontConfiguration(font, HtmlColorUtils.BLACK); + tb = TextBlockUtils.create(Display.asList(label), fc, HorizontalAlignment.LEFT, new SpriteContainerEmpty()); + } + + public Tile getTile() { + return tile; + } + + public String getId() { + return id; + } + + public String getLabel() { + return label; + } + + public void drawU(UGraphic ug) { + final Dimension2D dimTotal = calculateDimension(ug.getStringBounder()); + // final Dimension2D dimDesc = tb.calculateDimension(ug.getStringBounder()); + + final double widthTotal = dimTotal.getWidth(); + final double heightTotal = dimTotal.getHeight(); + final Shadowable rect = new URectangle(widthTotal, heightTotal, CORNER, CORNER); + ug = ug.apply(new UChangeColor(HtmlColorUtils.getColorIfValid("#A80036"))); + ug = ug.apply(new UChangeBackColor(HtmlColorUtils.getColorIfValid("#FEFECE"))); + ug.apply(new UStroke(1.5)).draw(rect); + + tb.drawU(ug.apply(new UTranslate(MARGIN, MARGIN))); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + final Dimension2D dim = tb.calculateDimension(stringBounder); + + return Dimension2DDouble.delta(dim, 2 * MARGIN, 2 * MARGIN); + } + +} diff --git a/src/net/sourceforge/plantuml/flowdiagram/CommandLineSimple.java b/src/net/sourceforge/plantuml/flowdiagram/CommandLineSimple.java new file mode 100644 index 000000000..654df175e --- /dev/null +++ b/src/net/sourceforge/plantuml/flowdiagram/CommandLineSimple.java @@ -0,0 +1,71 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.flowdiagram; + +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.RegexResult; +import net.sourceforge.plantuml.golem.TileGeometry; + +public class CommandLineSimple extends SingleLineCommand2 { + + public CommandLineSimple() { + super(getRegexConcat()); + } + + private static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("ORIENTATION", "(?:([nsew])\\s+)?"), // + new RegexLeaf("ID_DEST", "(\\w+)"), // + new RegexLeaf("\\s+"), // + new RegexLeaf("LABEL", "\"(.*)\""), // + new RegexLeaf("$")); + } + + @Override + protected CommandExecutionResult executeArg(FlowDiagram diagram, RegexResult arg) { + final String idDest = arg.get("ID_DEST", 0); + final String label = arg.get("LABEL", 0); + final String orientationString = arg.get("ORIENTATION", 0); + TileGeometry orientation = TileGeometry.SOUTH; + if (orientationString != null) { + orientation = TileGeometry.fromString(orientationString); + } + diagram.lineSimple(orientation, idDest, label); + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/flowdiagram/CommandLink.java b/src/net/sourceforge/plantuml/flowdiagram/CommandLink.java new file mode 100644 index 000000000..1953257a6 --- /dev/null +++ b/src/net/sourceforge/plantuml/flowdiagram/CommandLink.java @@ -0,0 +1,68 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.flowdiagram; + +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.RegexResult; +import net.sourceforge.plantuml.golem.TileGeometry; + +public class CommandLink extends SingleLineCommand2 { + + public CommandLink() { + super(getRegexConcat()); + } + + private static RegexConcat getRegexConcat() { + return new RegexConcat(new RegexLeaf("^"), // + new RegexLeaf("ORIENTATION", "(?:([nsew])\\s+)?"), // + new RegexLeaf("ID_DEST", "(\\w+)"), // + new RegexLeaf("$")); + } + + @Override + protected CommandExecutionResult executeArg(FlowDiagram system, RegexResult arg) { + final String idDest = arg.get("ID_DEST", 0); + final String orientationString = arg.get("ORIENTATION", 0); + TileGeometry orientation = TileGeometry.SOUTH; + if (orientationString != null) { + orientation = TileGeometry.fromString(orientationString); + } + system.linkSimple(orientation, idDest); + return CommandExecutionResult.ok(); + } + +} diff --git a/src/net/sourceforge/plantuml/flowdiagram/FlowDiagram.java b/src/net/sourceforge/plantuml/flowdiagram/FlowDiagram.java new file mode 100644 index 000000000..e3426283e --- /dev/null +++ b/src/net/sourceforge/plantuml/flowdiagram/FlowDiagram.java @@ -0,0 +1,206 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.flowdiagram; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.OutputStream; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.UmlDiagram; +import net.sourceforge.plantuml.UmlDiagramType; +import net.sourceforge.plantuml.api.ImageDataSimple; +import net.sourceforge.plantuml.core.DiagramDescription; +import net.sourceforge.plantuml.core.DiagramDescriptionImpl; +import net.sourceforge.plantuml.core.ImageData; +import net.sourceforge.plantuml.golem.MinMaxGolem; +import net.sourceforge.plantuml.golem.Path; +import net.sourceforge.plantuml.golem.Position; +import net.sourceforge.plantuml.golem.Tile; +import net.sourceforge.plantuml.golem.TileArea; +import net.sourceforge.plantuml.golem.TileGeometry; +import net.sourceforge.plantuml.golem.TilesField; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UEllipse; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UGraphicUtils; +import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.UShape; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class FlowDiagram extends UmlDiagram implements TextBlock { + + private static double SINGLE_SIZE_X = 100; + private static double SINGLE_SIZE_Y = 35; + + private TilesField field; + private final Map tilesBoxes = new HashMap(); + private Tile lastTile; + + public DiagramDescription getDescription() { + return new DiagramDescriptionImpl("Flow Diagram", getClass()); + } + + @Override + public UmlDiagramType getUmlDiagramType() { + return UmlDiagramType.FLOW; + } + + public void lineSimple(TileGeometry orientation, String idDest, String label) { + final Tile newTile; + if (field == null) { + field = new TilesField(); + tilesBoxes.clear(); + newTile = field.getRoot(); + } else { + newTile = field.createTile(lastTile, orientation); + } + final ActivityBox box = new ActivityBox(newTile, idDest, label); + tilesBoxes.put(newTile, box); + lastTile = newTile; + return; + } + + public void linkSimple(TileGeometry orientation, String idDest) { + final Tile tile = getTileById(idDest); + field.addPath(lastTile, tile, orientation); + } + + private Tile getTileById(String id) { + for (Map.Entry ent : tilesBoxes.entrySet()) { + if (ent.getValue().getId().equals(id)) { + return ent.getKey(); + } + } + throw new IllegalArgumentException(id); + } + + @Override + protected ImageData exportDiagramInternal(OutputStream os, int index, FileFormatOption fileFormatOption, + List flashcodes) throws IOException { + UGraphicUtils.writeImage(os, null, fileFormatOption, new ColorMapperIdentity(), HtmlColorUtils.WHITE, this); + return new ImageDataSimple(); + } + + public void drawU(UGraphic ug) { + double x = 0; + double y = 0; + final MinMaxGolem minMax = getMinMax(); + x -= minMax.getMinX() * SINGLE_SIZE_X; + y -= minMax.getMinY() * SINGLE_SIZE_Y; + final StringBounder stringBounder = ug.getStringBounder(); + for (Map.Entry ent : tilesBoxes.entrySet()) { + final Tile tile = ent.getKey(); + final Position pos = field.getPosition(tile); + final int xmin = pos.getXmin(); + final int ymin = pos.getYmin(); + final ActivityBox box = ent.getValue(); + final Dimension2D dimBox = box.calculateDimension(stringBounder); + final double deltaX = SINGLE_SIZE_X * 2 - dimBox.getWidth(); + final double deltaY = SINGLE_SIZE_Y * 2 - dimBox.getHeight(); + box.drawU(ug.apply(new UTranslate((x + xmin * SINGLE_SIZE_X + deltaX / 2), (y + ymin + * SINGLE_SIZE_Y + deltaY / 2)))); + } + ug = ug.apply(new UChangeColor(HtmlColorUtils.getColorIfValid("#A80036"))); + ug = ug.apply(new UChangeBackColor(HtmlColorUtils.getColorIfValid("#A80036"))); + final UShape arrow = new UEllipse(7, 7); + for (Path p : field.getPaths()) { + final TileArea start = p.getStart(); + final TileArea dest = p.getDest(); + final Point2D pStart = movePoint(getCenter(start), start.getTile(), start.getGeometry(), stringBounder); + final Point2D pDest = movePoint(getCenter(dest), dest.getTile(), dest.getGeometry(), stringBounder); + final ULine line = new ULine(pDest.getX() - pStart.getX(), pDest.getY() - pStart.getY()); + ug.apply(new UTranslate(x + pStart.getX(), y + pStart.getY())).draw(line); + ug.apply(new UTranslate(x + pDest.getX() - 3, y + pDest.getY() - 3)).draw(arrow); + + } + } + + private Point2D getCenter(TileArea area) { + final Tile tile = area.getTile(); + final Position position = field.getPosition(tile); + final double x = position.getCenterX(); + final double y = position.getCenterY(); + return new Point2D.Double(x * SINGLE_SIZE_X, y * SINGLE_SIZE_Y); + } + + private Point2D movePoint(Point2D pt, Tile tile, TileGeometry tileGeometry, StringBounder stringBounder) { + final Dimension2D dim = tilesBoxes.get(tile).calculateDimension(stringBounder); + final double width = dim.getWidth(); + final double height = dim.getHeight(); + double x = pt.getX(); + double y = pt.getY(); + switch (tileGeometry) { + case SOUTH: + y += height / 2; + break; + case NORTH: + y -= height / 2; + break; + case EAST: + x += width / 2; + break; + case WEST: + x -= width / 2; + break; + default: + throw new IllegalStateException(); + } + return new Point2D.Double(x, y); + } + + private MinMaxGolem getMinMax() { + final MinMaxGolem minMax = new MinMaxGolem(); + for (Tile tile : tilesBoxes.keySet()) { + minMax.manage(field.getPosition(tile)); + } + return minMax; + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + final MinMaxGolem minMax = getMinMax(); + return new Dimension2DDouble(minMax.getWidth() * SINGLE_SIZE_X, minMax.getHeight() * SINGLE_SIZE_Y); + } +} diff --git a/src/net/sourceforge/plantuml/flowdiagram/FlowDiagramFactory.java b/src/net/sourceforge/plantuml/flowdiagram/FlowDiagramFactory.java new file mode 100644 index 000000000..7dc5af3fe --- /dev/null +++ b/src/net/sourceforge/plantuml/flowdiagram/FlowDiagramFactory.java @@ -0,0 +1,62 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8475 $ + * + */ +package net.sourceforge.plantuml.flowdiagram; + +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.plantuml.command.Command; +import net.sourceforge.plantuml.command.UmlDiagramFactory; +import net.sourceforge.plantuml.core.DiagramType; + +public class FlowDiagramFactory extends UmlDiagramFactory { + + public FlowDiagramFactory() { + super(DiagramType.FLOW); + } + + @Override + public FlowDiagram createEmptyDiagram() { + return new FlowDiagram(); + } + + @Override + protected List createCommands() { + final List cmds = new ArrayList(); + cmds.add(new CommandLineSimple()); + cmds.add(new CommandLink()); + return cmds; + } + +} diff --git a/src/net/sourceforge/plantuml/font/PSystemListFonts.java b/src/net/sourceforge/plantuml/font/PSystemListFonts.java new file mode 100644 index 000000000..6ba3e412f --- /dev/null +++ b/src/net/sourceforge/plantuml/font/PSystemListFonts.java @@ -0,0 +1,87 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.font; + +import java.awt.Font; +import java.awt.GraphicsEnvironment; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.plantuml.AbstractPSystem; +import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.core.DiagramDescription; +import net.sourceforge.plantuml.core.DiagramDescriptionImpl; +import net.sourceforge.plantuml.core.ImageData; +import net.sourceforge.plantuml.graphic.GraphicStrings; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.ugraphic.UAntiAliasing; +import net.sourceforge.plantuml.ugraphic.UFont; + +public class PSystemListFonts extends AbstractPSystem { + + private final List strings = new ArrayList(); + + public PSystemListFonts(String text) { + strings.add(" Fonts available:"); + strings.add(" "); + // final Font fonts[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts(); + // for (Font f : fonts) { + // strings.add("f=" + f + "/" + f.getPSName() + "/" + f.getName() + "/" + f.getFontName() + "/" + // + f.getFamily()); + // } + final String name[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); + for (String n : name) { + strings.add(n + " : " + text); + } + + } + + public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException { + return getGraphicStrings().exportDiagram(os, fileFormat); + } + + private GraphicStrings getGraphicStrings() throws IOException { + final UFont font = new UFont("SansSerif", Font.PLAIN, 12); + final GraphicStrings result = new GraphicStrings(strings, font, HtmlColorUtils.BLACK, HtmlColorUtils.WHITE, + UAntiAliasing.ANTI_ALIASING_ON); + return result; + } + + public DiagramDescription getDescription() { + return new DiagramDescriptionImpl("(List fonts)", getClass()); + } + +} diff --git a/src/net/sourceforge/plantuml/font/PSystemListFontsFactory.java b/src/net/sourceforge/plantuml/font/PSystemListFontsFactory.java new file mode 100644 index 000000000..5bfe82997 --- /dev/null +++ b/src/net/sourceforge/plantuml/font/PSystemListFontsFactory.java @@ -0,0 +1,52 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 3830 $ + * + */ +package net.sourceforge.plantuml.font; + +import net.sourceforge.plantuml.AbstractPSystem; +import net.sourceforge.plantuml.command.PSystemSingleLineFactory; + +public class PSystemListFontsFactory extends PSystemSingleLineFactory { + + @Override + protected AbstractPSystem executeLine(String line) { + final String lineLower = line.toLowerCase(); + if (lineLower.equals("listfont") || lineLower.equals("listfonts") || lineLower.startsWith("listfont ") + || lineLower.startsWith("listfonts ")) { + final int idx = line.indexOf(' '); + return new PSystemListFonts(idx == -1 ? "This is a test" : line.substring(idx).trim()); + } + return null; + } + +} diff --git a/src/net/sourceforge/plantuml/ftp/FtpConnexion.java b/src/net/sourceforge/plantuml/ftp/FtpConnexion.java index cffe3ad61..97d2d9ba3 100644 --- a/src/net/sourceforge/plantuml/ftp/FtpConnexion.java +++ b/src/net/sourceforge/plantuml/ftp/FtpConnexion.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -45,6 +45,7 @@ import java.util.Map; import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.FileFormatOption; import net.sourceforge.plantuml.SourceStringReader; +import net.sourceforge.plantuml.core.DiagramDescription; public class FtpConnexion { @@ -62,12 +63,11 @@ public class FtpConnexion { } incoming.put(fileName, data); } - + public void removeOutgoing(String fileName) { outgoing.remove(fileName); } - public synchronized Collection getFiles() { final List result = new ArrayList(incoming.keySet()); result.addAll(outgoing.keySet()); @@ -111,14 +111,27 @@ public class FtpConnexion { final SourceStringReader sourceStringReader = new SourceStringReader(incoming.get(fileName)); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final FileFormat format = FileFormat.PNG; + final DiagramDescription desc = sourceStringReader.generateDiagramDescription(baos, new FileFormatOption(format)); final String pngFileName = format.changeName(fileName, 0); - final String ok = sourceStringReader.generateImage(baos, new FileFormatOption(format)); - if (ok != null) { + final String errorFileName = pngFileName.substring(0, pngFileName.length() - 4) + ".err"; + outgoing.remove(pngFileName); + outgoing.remove(errorFileName); + if (desc != null && desc.getDescription() != null) { synchronized (this) { outgoing.put(pngFileName, baos.toByteArray()); + if (desc.getDescription().startsWith("(Error)")) { + final ByteArrayOutputStream errBaos = new ByteArrayOutputStream(); + sourceStringReader.generateImage(errBaos, new FileFormatOption(FileFormat.ATXT)); + errBaos.close(); + outgoing.put(errorFileName, errBaos.toByteArray()); + } } } } + public synchronized void delete(String fileName) { + incoming.remove(fileName); + outgoing.remove(fileName); + } } diff --git a/src/net/sourceforge/plantuml/ftp/FtpLoop.java b/src/net/sourceforge/plantuml/ftp/FtpLoop.java index d79185d57..083c06d74 100644 --- a/src/net/sourceforge/plantuml/ftp/FtpLoop.java +++ b/src/net/sourceforge/plantuml/ftp/FtpLoop.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -70,7 +70,7 @@ class FtpLoop implements Runnable { public FtpLoop(Socket socket, FtpServer ftpServer) throws IOException { this.incoming = socket; this.ftpServer = ftpServer; - this.br = new BufferedReader(new InputStreamReader(incoming.getInputStream())); + this.br = new BufferedReader(new InputStreamReader(incoming.getInputStream(), ftpServer.getCharset())); this.pw = new PrintWriter(incoming.getOutputStream(), true); } @@ -157,7 +157,12 @@ class FtpLoop implements Runnable { } else { retrPassif(cmd); } + } else if (upper.startsWith("DELE")) { + final String file = cmd.substring("DELE ".length()); + connexion.delete(file); + myOut("200 Command okay."); } else if (upper.startsWith("QUIT")) { + myOut("221 Goodbye."); return true; } else if (upper.startsWith("SYST")) { myOut("215 UNIX Type: L8."); @@ -233,7 +238,7 @@ class FtpLoop implements Runnable { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); FileUtils.copyToStream(is, baos); myOut("226 Transfer complete."); - final String data = new String(baos.toByteArray()); + final String data = new String(baos.toByteArray(), ftpServer.getCharset()); final FileFormat format = FileFormat.PNG; final String pngFileName = format.changeName(fileName, 0); connexion.removeOutgoing(pngFileName); diff --git a/src/net/sourceforge/plantuml/ftp/FtpServer.java b/src/net/sourceforge/plantuml/ftp/FtpServer.java index 1df71a931..20c1a7dd8 100644 --- a/src/net/sourceforge/plantuml/ftp/FtpServer.java +++ b/src/net/sourceforge/plantuml/ftp/FtpServer.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -48,6 +48,7 @@ public class FtpServer { private final Map datas = new TreeMap(); private final ExecutorService exeImage = Executors.newFixedThreadPool(2); + private final String charset = "UTF-8"; private final int listenPort; @@ -60,7 +61,7 @@ public class FtpServer { public synchronized int getFreePort() { portFree++; - System.err.println("port=" + portFree); +// Log.println("port=" + portFree); return portFree; } @@ -100,7 +101,7 @@ public class FtpServer { System.out.println("Server Started..."); System.out.println("Waiting for connections..."); System.out.println(" "); - new FtpServer(100).go(); + new FtpServer(24242).go(); } public void processImage(final FtpConnexion connexion, final String name) { @@ -115,4 +116,8 @@ public class FtpServer { }); } + public final String getCharset() { + return charset; + } + } diff --git a/src/net/sourceforge/plantuml/geom/AbstractFigure.java b/src/net/sourceforge/plantuml/geom/AbstractFigure.java index 6f75eba05..5c26672ba 100644 --- a/src/net/sourceforge/plantuml/geom/AbstractFigure.java +++ b/src/net/sourceforge/plantuml/geom/AbstractFigure.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom; @@ -40,6 +40,8 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import net.sourceforge.plantuml.Log; + abstract class AbstractFigure { private final Set segments = new HashSet(); @@ -115,7 +117,7 @@ abstract class AbstractFigure { public Polyline addDirectLink(Point2DInt start, Point2DInt end) { final LineSegmentInt direct = new LineSegmentInt(start, end); addSegment(direct); - System.err.println("AbstractFigure::addDirectLink " + direct); + Log.println("AbstractFigure::addDirectLink " + direct); return new PolylineImpl(start, end); } @@ -142,8 +144,8 @@ abstract class AbstractFigure { } private Polyline findBestPath(Pointable start, Pointable end) { - System.err.println("start=" + start.getPosition()); - System.err.println("end=" + end.getPosition()); + Log.println("start=" + start.getPosition()); + Log.println("end=" + end.getPosition()); final Set points = getAllPoints(); if (points.contains(start.getPosition()) == false || points.contains(end.getPosition()) == false) { throw new IllegalArgumentException(); @@ -155,10 +157,10 @@ abstract class AbstractFigure { neighborhoods.addAll(getSingularity(p).getNeighborhoods()); } for (int i = 0; i < neighborhoods.size(); i++) { - System.err.println("N" + (i + 1) + " " + neighborhoods.get(i)); + Log.println("N" + (i + 1) + " " + neighborhoods.get(i)); } final Dijkstra dijkstra = new Dijkstra(neighborhoods.size() + 2); - System.err.println("size=" + dijkstra.getSize()); + Log.println("size=" + dijkstra.getSize()); for (int i = 0; i < neighborhoods.size(); i++) { if (isConnectable(start.getPosition(), neighborhoods.get(i))) { dijkstra.addLink(0, i + 1, distance(start.getPosition(), neighborhoods.get(i).getCenter())); @@ -187,7 +189,7 @@ abstract class AbstractFigure { } assert path.size() > 2; - System.err.println("PATH=" + path); + Log.println("PATH=" + path); final List usedNeighborhoods = new ArrayList(); for (int i = 1; i < path.size() - 1; i++) { final int idx = path.get(i) - 1; @@ -201,15 +203,15 @@ abstract class AbstractFigure { .println("findApproximatePath " + start.getPosition() + " " + end.getPosition() + " " + neighborhoods); final PolylineImpl result = new PolylineImpl(start, end); for (Neighborhood n : neighborhoods) { - System.err.println("Neighborhood =" + n); + Log.println("Neighborhood =" + n); final double d = getProximaDistance(n.getCenter()) / 2; final double a = n.getMiddle(); - System.err.println("d=" + d); - System.err.println("a=" + a * 180 / Math.PI); + Log.println("d=" + d); + Log.println("a=" + a * 180 / Math.PI); final double deltaX = d * Math.cos(a); final double deltaY = d * Math.sin(a); assert d > 0; - System.err.println("Result = " + n.getCenter().translate((int) deltaX, (int) deltaY)); + Log.println("Result = " + n.getCenter().translate((int) deltaX, (int) deltaY)); result.addIntermediate(n.getCenter().translate((int) deltaX, (int) deltaY)); } return result; @@ -277,13 +279,13 @@ abstract class AbstractFigure { continue; } if (seg.doesIntersect(direct)) { - System.err.println("seg=" + seg); - System.err.println("direct=" + direct); - System.err.println("AbstractFigure::hasIntersectionStrict true"); + Log.println("seg=" + seg); + Log.println("direct=" + direct); + Log.println("AbstractFigure::hasIntersectionStrict true"); return true; } } - System.err.println("AbstractFigure::hasIntersectionStrict false"); + Log.println("AbstractFigure::hasIntersectionStrict false"); return false; } diff --git a/src/net/sourceforge/plantuml/geom/AbstractLineSegment.java b/src/net/sourceforge/plantuml/geom/AbstractLineSegment.java index 8886bd65f..05c957918 100644 --- a/src/net/sourceforge/plantuml/geom/AbstractLineSegment.java +++ b/src/net/sourceforge/plantuml/geom/AbstractLineSegment.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 11271 $ * */ package net.sourceforge.plantuml.geom; @@ -101,7 +101,7 @@ public abstract class AbstractLineSegment extends Line2D { return isBetween(toTest.getX(), pos1.getX(), pos2.getX()) && isBetween(toTest.getY(), pos1.getY(), pos2.getY()); } - private double getIntersectionVertical(double xOther) { + public double getIntersectionVertical(double xOther) { final double coef = getP2().getX() - getP1().getX(); if (coef == 0) { return java.lang.Double.NaN; @@ -109,7 +109,7 @@ public abstract class AbstractLineSegment extends Line2D { return (xOther - getP1().getX()) / coef; } - private double getIntersectionHorizontal(double yOther) { + public double getIntersectionHorizontal(double yOther) { final double coef = getP2().getY() - getP1().getY(); if (coef == 0) { return java.lang.Double.NaN; diff --git a/src/net/sourceforge/plantuml/geom/AbstractPolyline.java b/src/net/sourceforge/plantuml/geom/AbstractPolyline.java index 5b0994b96..bdbfd2329 100644 --- a/src/net/sourceforge/plantuml/geom/AbstractPolyline.java +++ b/src/net/sourceforge/plantuml/geom/AbstractPolyline.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom; diff --git a/src/net/sourceforge/plantuml/geom/Box.java b/src/net/sourceforge/plantuml/geom/Box.java index 932cc407a..fba2f4924 100644 --- a/src/net/sourceforge/plantuml/geom/Box.java +++ b/src/net/sourceforge/plantuml/geom/Box.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom; @@ -108,8 +108,8 @@ public class Box implements XMoveable, Pointable { if (seg.side(this) != 0) { return new Point2DInt[0]; } - // System.err.println("THIS=" + this); - // System.err.println("LineSegment=" + seg); + // Log.println("THIS=" + this); + // Log.println("LineSegment=" + seg); final Point2DInt corners[] = getCorners(); final LineSegmentInt seg1 = new LineSegmentInt(corners[0], corners[1]); final LineSegmentInt seg2 = new LineSegmentInt(corners[1], corners[2]); @@ -120,10 +120,10 @@ public class Box implements XMoveable, Pointable { Point2DInt i3 = seg.getSegIntersection(seg3); Point2DInt i4 = seg.getSegIntersection(seg4); - // System.err.println("i1="+i1); - // System.err.println("i2="+i2); - // System.err.println("i3="+i3); - // System.err.println("i4="+i4); + // Log.println("i1="+i1); + // Log.println("i2="+i2); + // Log.println("i3="+i3); + // Log.println("i4="+i4); if (i2 != null && i2.equals(i1)) { i2 = null; diff --git a/src/net/sourceforge/plantuml/geom/ClosedArea.java b/src/net/sourceforge/plantuml/geom/ClosedArea.java index b54004153..48951554f 100644 --- a/src/net/sourceforge/plantuml/geom/ClosedArea.java +++ b/src/net/sourceforge/plantuml/geom/ClosedArea.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom; diff --git a/src/net/sourceforge/plantuml/geom/CollectionUtils.java b/src/net/sourceforge/plantuml/geom/CollectionUtils.java index f5e266d67..4ed400ffd 100644 --- a/src/net/sourceforge/plantuml/geom/CollectionUtils.java +++ b/src/net/sourceforge/plantuml/geom/CollectionUtils.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom; diff --git a/src/net/sourceforge/plantuml/geom/Dijkstra.java b/src/net/sourceforge/plantuml/geom/Dijkstra.java index 0ff33c2f3..891bfc184 100644 --- a/src/net/sourceforge/plantuml/geom/Dijkstra.java +++ b/src/net/sourceforge/plantuml/geom/Dijkstra.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom; @@ -60,7 +60,7 @@ public class Dijkstra { } public void addLink(int n1, int n2, double d) { - System.err.println("Adding " + n1 + " " + n2 + " " + d); +// Log.println("Adding " + n1 + " " + n2 + " " + d); if (n1 == n2) { throw new IllegalArgumentException(); } diff --git a/src/net/sourceforge/plantuml/geom/InflateData.java b/src/net/sourceforge/plantuml/geom/InflateData.java index 872fa207e..6c52bb313 100644 --- a/src/net/sourceforge/plantuml/geom/InflateData.java +++ b/src/net/sourceforge/plantuml/geom/InflateData.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom; diff --git a/src/net/sourceforge/plantuml/geom/InflationTransform.java b/src/net/sourceforge/plantuml/geom/InflationTransform.java index 39a359757..f38bdc28e 100644 --- a/src/net/sourceforge/plantuml/geom/InflationTransform.java +++ b/src/net/sourceforge/plantuml/geom/InflationTransform.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom; @@ -88,9 +88,9 @@ public class InflationTransform { Collection cutPoints(LineSegmentInt original) { - // System.err.println("original=" + original); - // System.err.println("inflateX=" + inflateX); - // System.err.println("inflateY=" + inflateY); + // Log.println("original=" + original); + // Log.println("inflateX=" + inflateX); + // Log.println("inflateY=" + inflateY); final SortedSet result = new TreeSet(new Point2DIntComparatorDistance(original.getP1())); diff --git a/src/net/sourceforge/plantuml/geom/Kingdom.java b/src/net/sourceforge/plantuml/geom/Kingdom.java index 99bbf11cc..12f955746 100644 --- a/src/net/sourceforge/plantuml/geom/Kingdom.java +++ b/src/net/sourceforge/plantuml/geom/Kingdom.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom; diff --git a/src/net/sourceforge/plantuml/geom/LineSegmentDouble.java b/src/net/sourceforge/plantuml/geom/LineSegmentDouble.java index 830fb67d4..a468e381a 100644 --- a/src/net/sourceforge/plantuml/geom/LineSegmentDouble.java +++ b/src/net/sourceforge/plantuml/geom/LineSegmentDouble.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 11289 $ * */ package net.sourceforge.plantuml.geom; @@ -36,6 +36,10 @@ package net.sourceforge.plantuml.geom; import java.awt.geom.Point2D; import java.util.Locale; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.UTranslate; + public class LineSegmentDouble extends AbstractLineSegment { private final Point2D p1; @@ -43,7 +47,7 @@ public class LineSegmentDouble extends AbstractLineSegment { @Override public String toString() { - return String.format(Locale.US, "( %d,%d - %d,%d )", getP1().getX(), getP1().getY(), getP2().getX(), getP2() + return String.format(Locale.US, "( %.2f,%.2f - %.2f,%.2f )", getP1().getX(), getP1().getY(), getP2().getX(), getP2() .getY()); } @@ -92,4 +96,14 @@ public class LineSegmentDouble extends AbstractLineSegment { return p2.getY(); } + public void draw(UGraphic ug) { + final double x1 = p1.getX(); + final double y1 = p1.getY(); + final double x2 = p2.getX(); + final double y2 = p2.getY(); + ug = ug.apply(new UTranslate(x1, y1)); + ug.draw(new ULine(x2 - x1, y2 - y1)); + + } + } diff --git a/src/net/sourceforge/plantuml/geom/LineSegmentInt.java b/src/net/sourceforge/plantuml/geom/LineSegmentInt.java index 67d541dda..6690e2d03 100644 --- a/src/net/sourceforge/plantuml/geom/LineSegmentInt.java +++ b/src/net/sourceforge/plantuml/geom/LineSegmentInt.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom; diff --git a/src/net/sourceforge/plantuml/geom/Neighborhood.java b/src/net/sourceforge/plantuml/geom/Neighborhood.java index fe16f357b..eed81723a 100644 --- a/src/net/sourceforge/plantuml/geom/Neighborhood.java +++ b/src/net/sourceforge/plantuml/geom/Neighborhood.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom; diff --git a/src/net/sourceforge/plantuml/geom/Orientation.java b/src/net/sourceforge/plantuml/geom/Orientation.java index c4dde8adb..b0082e2c0 100644 --- a/src/net/sourceforge/plantuml/geom/Orientation.java +++ b/src/net/sourceforge/plantuml/geom/Orientation.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom; diff --git a/src/net/sourceforge/plantuml/geom/Point2DInt.java b/src/net/sourceforge/plantuml/geom/Point2DInt.java index 0009cb317..2a62f1a45 100644 --- a/src/net/sourceforge/plantuml/geom/Point2DInt.java +++ b/src/net/sourceforge/plantuml/geom/Point2DInt.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom; diff --git a/src/net/sourceforge/plantuml/geom/Pointable.java b/src/net/sourceforge/plantuml/geom/Pointable.java index cac4261b1..1aae2b6b7 100644 --- a/src/net/sourceforge/plantuml/geom/Pointable.java +++ b/src/net/sourceforge/plantuml/geom/Pointable.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom; diff --git a/src/net/sourceforge/plantuml/geom/Polyline.java b/src/net/sourceforge/plantuml/geom/Polyline.java index 6bc4b5ad4..423a2b556 100644 --- a/src/net/sourceforge/plantuml/geom/Polyline.java +++ b/src/net/sourceforge/plantuml/geom/Polyline.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom; diff --git a/src/net/sourceforge/plantuml/geom/PolylineBreakeable.java b/src/net/sourceforge/plantuml/geom/PolylineBreakeable.java index b421d1706..f14c6d17a 100644 --- a/src/net/sourceforge/plantuml/geom/PolylineBreakeable.java +++ b/src/net/sourceforge/plantuml/geom/PolylineBreakeable.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom; diff --git a/src/net/sourceforge/plantuml/geom/PolylineImpl.java b/src/net/sourceforge/plantuml/geom/PolylineImpl.java index fcc44e721..b5912bce6 100644 --- a/src/net/sourceforge/plantuml/geom/PolylineImpl.java +++ b/src/net/sourceforge/plantuml/geom/PolylineImpl.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom; @@ -84,7 +84,7 @@ public class PolylineImpl extends AbstractPolyline implements Polyline { // } final List segments = transform.inflate(this.segments()); - // System.err.println("segments="+segments); + // Log.println("segments="+segments); intermediates.clear(); for (int i = 1; i < segments.size() - 1; i++) { addIntermediate(segments.get(i).getP1()); diff --git a/src/net/sourceforge/plantuml/geom/Singularity.java b/src/net/sourceforge/plantuml/geom/Singularity.java index ceabfd204..5aa386de2 100644 --- a/src/net/sourceforge/plantuml/geom/Singularity.java +++ b/src/net/sourceforge/plantuml/geom/Singularity.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom; diff --git a/src/net/sourceforge/plantuml/geom/SpiderWeb.java b/src/net/sourceforge/plantuml/geom/SpiderWeb.java index 286637407..5cb8d9e7f 100644 --- a/src/net/sourceforge/plantuml/geom/SpiderWeb.java +++ b/src/net/sourceforge/plantuml/geom/SpiderWeb.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom; @@ -88,15 +88,15 @@ public class SpiderWeb { result.add(new Point2DInt((int) Math.round(x1), (int) Math.round(y1))); } } - // System.err.println("getHangPoints="+result); + // Log.println("getHangPoints="+result); return result; } public PolylineBreakeable addPolyline(int row1, int col1, int row2, int col2) { - // System.err.println("SpiderWeb : adding " + row1 + "," + col1 + " - " + // Log.println("SpiderWeb : adding " + row1 + "," + col1 + " - " // + row2 + "," + col2); final PolylineBreakeable result = computePolyline(row1, col1, row2, col2); - // System.err.println("SpiderWeb : adding " + result); + // Log.println("SpiderWeb : adding " + result); if (result != null) { lines.add(result); } @@ -117,10 +117,10 @@ public class SpiderWeb { nbCol = col2; } if (directLinkPossibleForGeometry(row1, col1, row2, col2)) { - // System.err.println("Geom OK"); + // Log.println("Geom OK"); final PolylineBreakeable direct = new PolylineBreakeable(getMainPoint(row1, col1), getMainPoint(row2, col2)); if (isCompatible(direct)) { - // System.err.println("Direct OK"); + // Log.println("Direct OK"); return direct; } } diff --git a/src/net/sourceforge/plantuml/geom/XMoveable.java b/src/net/sourceforge/plantuml/geom/XMoveable.java index 755dd76d1..92bea6416 100644 --- a/src/net/sourceforge/plantuml/geom/XMoveable.java +++ b/src/net/sourceforge/plantuml/geom/XMoveable.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3830 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom; diff --git a/src/net/sourceforge/plantuml/geom/kinetic/Frame.java b/src/net/sourceforge/plantuml/geom/kinetic/Frame.java index 29d64411a..226dace7c 100644 --- a/src/net/sourceforge/plantuml/geom/kinetic/Frame.java +++ b/src/net/sourceforge/plantuml/geom/kinetic/Frame.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3831 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom.kinetic; diff --git a/src/net/sourceforge/plantuml/geom/kinetic/MoveObserver.java b/src/net/sourceforge/plantuml/geom/kinetic/MoveObserver.java index a495a21d0..59ac797ab 100644 --- a/src/net/sourceforge/plantuml/geom/kinetic/MoveObserver.java +++ b/src/net/sourceforge/plantuml/geom/kinetic/MoveObserver.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3831 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom.kinetic; diff --git a/src/net/sourceforge/plantuml/geom/kinetic/Path.java b/src/net/sourceforge/plantuml/geom/kinetic/Path.java index 6cecb3c05..597a5df2b 100644 --- a/src/net/sourceforge/plantuml/geom/kinetic/Path.java +++ b/src/net/sourceforge/plantuml/geom/kinetic/Path.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3831 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom.kinetic; diff --git a/src/net/sourceforge/plantuml/geom/kinetic/Point2DCharge.java b/src/net/sourceforge/plantuml/geom/kinetic/Point2DCharge.java index 427501bf9..db49d1d3a 100644 --- a/src/net/sourceforge/plantuml/geom/kinetic/Point2DCharge.java +++ b/src/net/sourceforge/plantuml/geom/kinetic/Point2DCharge.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,13 +28,15 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3831 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom.kinetic; import java.awt.geom.Point2D; +import net.sourceforge.plantuml.Log; + public class Point2DCharge extends Point2D.Double { private double charge = 1.0; @@ -51,7 +53,7 @@ public class Point2DCharge extends Point2D.Double { } public void apply(VectorForce value) { - System.err.println("Applying " + value); + Log.println("Applying " + value); x += value.getX(); y += value.getY(); if (moveObserver != null) { diff --git a/src/net/sourceforge/plantuml/geom/kinetic/Quadrant.java b/src/net/sourceforge/plantuml/geom/kinetic/Quadrant.java index af236a9af..f2f709769 100644 --- a/src/net/sourceforge/plantuml/geom/kinetic/Quadrant.java +++ b/src/net/sourceforge/plantuml/geom/kinetic/Quadrant.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3831 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom.kinetic; diff --git a/src/net/sourceforge/plantuml/geom/kinetic/QuadrantMapper.java b/src/net/sourceforge/plantuml/geom/kinetic/QuadrantMapper.java index 7cc74a516..12541c6ba 100644 --- a/src/net/sourceforge/plantuml/geom/kinetic/QuadrantMapper.java +++ b/src/net/sourceforge/plantuml/geom/kinetic/QuadrantMapper.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3831 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom.kinetic; diff --git a/src/net/sourceforge/plantuml/geom/kinetic/SegmentCutter.java b/src/net/sourceforge/plantuml/geom/kinetic/SegmentCutter.java index b745bbeee..02169199a 100644 --- a/src/net/sourceforge/plantuml/geom/kinetic/SegmentCutter.java +++ b/src/net/sourceforge/plantuml/geom/kinetic/SegmentCutter.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3831 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom.kinetic; diff --git a/src/net/sourceforge/plantuml/geom/kinetic/VectorForce.java b/src/net/sourceforge/plantuml/geom/kinetic/VectorForce.java index 53f7a467c..efff6b693 100644 --- a/src/net/sourceforge/plantuml/geom/kinetic/VectorForce.java +++ b/src/net/sourceforge/plantuml/geom/kinetic/VectorForce.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3831 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom.kinetic; diff --git a/src/net/sourceforge/plantuml/geom/kinetic/World.java b/src/net/sourceforge/plantuml/geom/kinetic/World.java index 1da50ca03..249606290 100644 --- a/src/net/sourceforge/plantuml/geom/kinetic/World.java +++ b/src/net/sourceforge/plantuml/geom/kinetic/World.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3831 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.geom.kinetic; @@ -93,7 +93,7 @@ public class World implements MoveObserver { return new VectorForce(0, 0); } final VectorForce result = new VectorForce(byThis.getX() - onThis.getX(), byThis.getY() - onThis.getY()); - double v = 100.0 * onThis.getCharge() * byThis.getCharge() / dist / dist; + final double v = 100.0 * onThis.getCharge() * byThis.getCharge() / dist / dist; return result.normaliseTo(v); } diff --git a/src/net/sourceforge/plantuml/golem/Magnet.java b/src/net/sourceforge/plantuml/golem/Magnet.java new file mode 100644 index 000000000..f80d1d492 --- /dev/null +++ b/src/net/sourceforge/plantuml/golem/Magnet.java @@ -0,0 +1,37 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7715 $ + * + */ +package net.sourceforge.plantuml.golem; + +public class Magnet { +} diff --git a/src/net/sourceforge/plantuml/golem/MinMaxDouble.java b/src/net/sourceforge/plantuml/golem/MinMaxDouble.java new file mode 100644 index 000000000..dbbd78356 --- /dev/null +++ b/src/net/sourceforge/plantuml/golem/MinMaxDouble.java @@ -0,0 +1,82 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.golem; + +public class MinMaxDouble { + + private double minX = Double.MAX_VALUE; + private double minY = Double.MAX_VALUE; + private double maxX = -Double.MAX_VALUE; + private double maxY = -Double.MAX_VALUE; + + public void manage(double x, double y) { + if (x < minX) { + minX = x; + } + if (y < minY) { + minY = y; + } + if (x > maxX) { + maxX = x; + } + if (y > maxY) { + maxY = y; + } + } + + public double getMinX() { + return minX; + } + + public double getMinY() { + return minY; + } + + public double getMaxX() { + return maxX; + } + + public double getMaxY() { + return maxY; + } + + public double getWidth() { + return maxX - minX + 1; + } + + public double getHeight() { + return maxY - minY + 1; + } + +} diff --git a/src/net/sourceforge/plantuml/golem/MinMaxGolem.java b/src/net/sourceforge/plantuml/golem/MinMaxGolem.java new file mode 100644 index 000000000..368265c00 --- /dev/null +++ b/src/net/sourceforge/plantuml/golem/MinMaxGolem.java @@ -0,0 +1,79 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.golem; + +public class MinMaxGolem { + + private int minX = Integer.MAX_VALUE; + private int minY = Integer.MAX_VALUE; + private int maxX = Integer.MIN_VALUE; + private int maxY = Integer.MIN_VALUE; + + public void manage(int x, int y) { + if (x < minX) { + minX = x; + } + if (y < minY) { + minY = y; + } + if (x > maxX) { + maxX = x; + } + if (y > maxY) { + maxY = y; + } + } + + public void manage(Position position) { + manage(position.getXmin(), position.getYmin()); + manage(position.getXmax(), position.getYmax()); + } + + public int getMinX() { + return minX; + } + + public int getMinY() { + return minY; + } + + public int getWidth() { + return maxX - minX + 1; + } + + public int getHeight() { + return maxY - minY + 1; + } + +} diff --git a/src/net/sourceforge/plantuml/golem/Path.java b/src/net/sourceforge/plantuml/golem/Path.java new file mode 100644 index 000000000..4f4382560 --- /dev/null +++ b/src/net/sourceforge/plantuml/golem/Path.java @@ -0,0 +1,60 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7715 $ + * + */ +package net.sourceforge.plantuml.golem; + +import java.util.ArrayList; +import java.util.List; + +public class Path { + + private final List all = new ArrayList(); + + public static Path build(TileArea start, TileArea dest) { + return new Path(start, dest); + } + + private Path(TileArea start, TileArea dest) { + this.all.add(start); + this.all.add(dest); + } + + public TileArea getStart() { + return all.get(0); + } + + public TileArea getDest() { + return all.get(all.size() - 1); + } + +} diff --git a/src/net/sourceforge/plantuml/golem/Position.java b/src/net/sourceforge/plantuml/golem/Position.java new file mode 100644 index 000000000..120206bad --- /dev/null +++ b/src/net/sourceforge/plantuml/golem/Position.java @@ -0,0 +1,113 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7715 $ + * + */ +package net.sourceforge.plantuml.golem; + +public class Position { + + private final int xmin; + private final int ymin; + private final int xmax; + private final int ymax; + + public Position(int xmin, int ymin, int xmax, int ymax) { + this.xmin = xmin; + this.ymin = ymin; + this.xmax = xmax; + this.ymax = ymax; + } + + @Override + public boolean equals(Object o) { + final Position other = (Position) o; + return this.xmin == other.xmin && this.xmax == other.xmax && this.ymin == other.ymin && this.ymax == other.ymax; + } + + @Override + public int hashCode() { + return xmin + ymin << 8 + xmax << 16 + ymax << 24; + } + + @Override + public String toString() { + return "(" + xmin + "," + ymin + ")-(" + xmax + "," + ymax + ")"; + } + + public Position move(TileGeometry position, int sizeMove) { + if (position == null || position == TileGeometry.CENTER) { + throw new IllegalArgumentException(); + } + switch (position) { + case NORTH: + return new Position(xmin, ymin - sizeMove, xmax, ymax - sizeMove); + case SOUTH: + return new Position(xmin, ymin + sizeMove, xmax, ymax + sizeMove); + case WEST: + return new Position(xmin - sizeMove, ymin, xmax - sizeMove, ymax); + case EAST: + return new Position(xmin + sizeMove, ymin, xmax + sizeMove, ymax); + default: + throw new IllegalStateException(); + } + } + + public int getXmin() { + return xmin; + } + + public int getXmax() { + return xmax; + } + + public int getYmin() { + return ymin; + } + + public int getYmax() { + return ymax; + } + + public int getCenterX() { + if ((xmin + xmax + 1) % 2 != 0) { + throw new IllegalStateException(); + } + return (xmin + xmax + 1) / 2; + } + + public int getCenterY() { + if ((ymin + ymax + 1) % 2 != 0) { + throw new IllegalStateException(); + } + return (ymin + ymax + 1) / 2; + } +} diff --git a/src/net/sourceforge/plantuml/golem/Square.java b/src/net/sourceforge/plantuml/golem/Square.java new file mode 100644 index 000000000..1ef60d709 --- /dev/null +++ b/src/net/sourceforge/plantuml/golem/Square.java @@ -0,0 +1,37 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7715 $ + * + */ +package net.sourceforge.plantuml.golem; + +public class Square { +} diff --git a/src/net/sourceforge/plantuml/golem/Tile.java b/src/net/sourceforge/plantuml/golem/Tile.java new file mode 100644 index 000000000..9ea1da673 --- /dev/null +++ b/src/net/sourceforge/plantuml/golem/Tile.java @@ -0,0 +1,99 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7715 $ + * + */ +package net.sourceforge.plantuml.golem; + +import java.awt.Font; +import java.awt.geom.Dimension2D; +import java.util.Collections; +import java.util.EnumMap; +import java.util.Map; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.graphic.FontConfiguration; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UEllipse; +import net.sourceforge.plantuml.ugraphic.UFont; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class Tile implements TextBlock { + + private static double SIZE = 40; + private final int num; + + private final UFont numberFont = new UFont("Monospaced", Font.PLAIN, 11); + private final FontConfiguration fc = new FontConfiguration(numberFont, HtmlColorUtils.BLACK); + private final Map geometries; + + Tile(int num) { + this.num = num; + final Map tmp = new EnumMap(TileGeometry.class); + for (TileGeometry g : TileGeometry.values()) { + tmp.put(g, new TileArea(this, g)); + } + this.geometries = Collections.unmodifiableMap(tmp); + } + + public TileArea getArea(TileGeometry geometry) { + return this.geometries.get(geometry); + } + + public void drawU(UGraphic ug) { + ug = ug.apply(new UChangeColor(HtmlColorUtils.BLACK)); + final TextBlock n = TextBlockUtils.create(Display.asList("" + num), fc, HorizontalAlignment.LEFT, + new SpriteContainerEmpty()); + final Dimension2D dimNum = n.calculateDimension(ug.getStringBounder()); + final Dimension2D dimTotal = calculateDimension(ug.getStringBounder()); + final double diffx = dimTotal.getWidth() - dimNum.getWidth(); + final double diffy = dimTotal.getHeight() - dimNum.getHeight(); + final double radius = Math.max(dimNum.getWidth(), dimNum.getHeight()); + final double diffx2 = dimTotal.getWidth() - radius; + final double diffy2 = dimTotal.getHeight() - radius; + n.drawU(ug.apply(new UTranslate((diffx / 2), (diffy / 2)))); + ug.draw(new URectangle(SIZE, SIZE)); + ug.apply(new UTranslate(diffx2 / 2, diffy2 / 2)).draw(new UEllipse(radius, radius)); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return new Dimension2DDouble(SIZE, SIZE); + } +} diff --git a/src/net/sourceforge/plantuml/golem/TileArea.java b/src/net/sourceforge/plantuml/golem/TileArea.java new file mode 100644 index 000000000..d58b4a041 --- /dev/null +++ b/src/net/sourceforge/plantuml/golem/TileArea.java @@ -0,0 +1,53 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7715 $ + * + */ +package net.sourceforge.plantuml.golem; + +public class TileArea { + + private final Tile tile; + private final TileGeometry position; + + TileArea(Tile tile, TileGeometry position) { + this.tile = tile; + this.position = position; + } + + public Tile getTile() { + return tile; + } + + public TileGeometry getGeometry() { + return position; + } +} diff --git a/src/net/sourceforge/plantuml/golem/TileGeometry.java b/src/net/sourceforge/plantuml/golem/TileGeometry.java new file mode 100644 index 000000000..522461320 --- /dev/null +++ b/src/net/sourceforge/plantuml/golem/TileGeometry.java @@ -0,0 +1,71 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7715 $ + * + */ +package net.sourceforge.plantuml.golem; + +public enum TileGeometry { + NORTH, SOUTH, EAST, WEST, CENTER; + + public TileGeometry opposite() { + switch (this) { + case NORTH: + return SOUTH; + case SOUTH: + return NORTH; + case EAST: + return WEST; + case WEST: + return EAST; + case CENTER: + default: + throw new UnsupportedOperationException(); + } + } + + public static TileGeometry fromString(String s) { + final char c = Character.toUpperCase(s.charAt(0)); + switch (c) { + case 'N': + return NORTH; + case 'S': + return SOUTH; + case 'E': + return EAST; + case 'W': + return WEST; + default: + throw new IllegalArgumentException(); + } + } + +} diff --git a/src/net/sourceforge/plantuml/golem/TilesField.java b/src/net/sourceforge/plantuml/golem/TilesField.java new file mode 100644 index 000000000..96dbabe94 --- /dev/null +++ b/src/net/sourceforge/plantuml/golem/TilesField.java @@ -0,0 +1,301 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7715 $ + * + */ +package net.sourceforge.plantuml.golem; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.StringBounder; +import net.sourceforge.plantuml.graphic.TextBlock; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class TilesField implements TextBlock { + + private int size = 1; + private final Tile root = new Tile(0); + private final Map positions = new HashMap(); + private final List paths = new ArrayList(); + + public TilesField() { + positions.put(root, new Position(0, 0, 1, 1)); + } + + public Tile getRoot() { + return root; + } + + public Tile createTile(Tile start, TileGeometry position) { + final Tile result = new Tile(size++); + final Position p = getFreePosition(start, position); + positions.put(result, p); + paths.add(buildPath(start.getArea(position), result.getArea(position.opposite()))); + return result; + } + + public void addPath(Tile start, Tile dest, TileGeometry startDirection) { + paths.add(buildPath(start.getArea(startDirection), dest.getArea(startDirection.opposite()))); + } + + private Path buildPath(TileArea tileArea1, TileArea tileArea2) { + if (isAdjoining(tileArea1, tileArea2)) { + return Path.build(tileArea1, tileArea2); + } + final Tile tile1 = tileArea1.getTile(); + final Tile tile2 = tileArea2.getTile(); + final Position pos1 = getPosition(tile1); + final Position pos2 = getPosition(tile2); + final TileGeometry geom1 = tileArea1.getGeometry(); + final TileGeometry geom2 = tileArea2.getGeometry(); + if (pos1.getYmin() == pos2.getYmin() && pos1.getYmax() == pos2.getYmax() && geom1 == TileGeometry.WEST + && geom2 == TileGeometry.EAST) { + return Path.build(tileArea1, tileArea2); + + } + throw new IllegalArgumentException(); + } + + private boolean isAdjoining(TileArea tileArea1, TileArea tileArea2) { + final Tile tile1 = tileArea1.getTile(); + final Tile tile2 = tileArea2.getTile(); + final Position pos1 = getPosition(tile1); + final Position pos2 = getPosition(tile2); + final TileGeometry geom1 = tileArea1.getGeometry(); + final TileGeometry geom2 = tileArea2.getGeometry(); + if (pos1.equals(pos2)) { + assert tile1 == tile2; + if (geom1 == geom2) { + throw new IllegalArgumentException(); + } + return true; + } + if (geom1.equals(geom2.opposite()) == false) { + return false; + } + switch (geom1) { + case EAST: + return pos1.getYmin() == pos2.getYmin() && pos1.getYmax() == pos2.getYmax() + && pos1.getXmax() + 1 == pos2.getXmin(); + case WEST: + return pos1.getYmin() == pos2.getYmin() && pos1.getYmax() == pos2.getYmax() + && pos1.getXmin() == pos2.getXmax() + 1; + case SOUTH: + return pos1.getXmin() == pos2.getXmin() && pos1.getXmax() == pos2.getXmax() + && pos1.getYmax() + 1 == pos2.getYmin(); + case NORTH: + return pos1.getXmin() == pos2.getXmin() && pos1.getXmax() == pos2.getXmax() + && pos1.getYmin() == pos2.getYmax() + 1; + case CENTER: + return false; + + default: + throw new IllegalStateException(); + } + + } + + private Tile getTileAt(Position p) { + for (Map.Entry ent : positions.entrySet()) { + if (p.equals(ent.getValue())) { + return ent.getKey(); + } + } + return null; + } + + private Position getFreePosition(Tile start, TileGeometry position) { + final Position p = getPosition(start).move(position, 2); + while (isOccuped(p)) { + // p = p.move(TileGeometry.EAST, 2); + moveAllToEast(p); + } + return p; + } + + private void moveAllToEast(Position startingPosition) { + final List toMove = new ArrayList(); + for (Position p : positions.values()) { + if (p.getXmax() < startingPosition.getXmin()) { + continue; + } + if (p.getYmax() < startingPosition.getYmin()) { + continue; + } + toMove.add(p); + } + for (Position p : toMove) { + positions.put(getTileAt(p), p.move(TileGeometry.EAST, 2)); + } + + } + + private boolean isOccuped(Position test) { + for (Position p : positions.values()) { + if (p.equals(test)) { + return true; + } + } + return false; + } + + public Position getPosition(Tile tile) { + final Position result = positions.get(tile); + if (result == null) { + throw new IllegalArgumentException(); + } + return result; + } + + private int getXmin() { + int result = Integer.MAX_VALUE; + for (Position p : positions.values()) { + final int v = p.getXmin(); + if (v < result) { + result = v; + } + } + return result; + } + + private int getYmin() { + int result = Integer.MAX_VALUE; + for (Position p : positions.values()) { + final int v = p.getYmin(); + if (v < result) { + result = v; + } + } + return result; + } + + private int getXmax() { + int result = Integer.MIN_VALUE; + for (Position p : positions.values()) { + final int v = p.getXmax(); + if (v > result) { + result = v; + } + } + return result; + } + + private int getYmax() { + int result = Integer.MIN_VALUE; + for (Position p : positions.values()) { + final int v = p.getYmax(); + if (v > result) { + result = v; + } + } + return result; + } + + public List getPaths() { + return Collections.unmodifiableList(paths); + } + + // ----------- + public void drawU(UGraphic ug) { + double x = 0; + double y = 0; + final int xmin = getXmin(); + final int ymin = getYmin(); + final Dimension2D dimSingle = root.calculateDimension(ug.getStringBounder()); + x -= xmin * dimSingle.getWidth() / 2; + y -= ymin * dimSingle.getHeight() / 2; + for (Map.Entry ent : positions.entrySet()) { + final Position p = ent.getValue(); + final Tile t = ent.getKey(); + final double xt = p.getXmin() * dimSingle.getWidth() / 2; + final double yt = p.getYmin() * dimSingle.getHeight() / 2; + t.drawU(ug.apply(new UTranslate((x + xt), (y + yt)))); + } + ug = ug.apply(new UChangeColor(HtmlColorUtils.RED)); + for (Path p : paths) { + final TileArea start = p.getStart(); + final TileArea dest = p.getDest(); + final Point2D pstart = getPoint2D(dimSingle, start); + final Point2D pdest = getPoint2D(dimSingle, dest); + ug.apply(new UTranslate(x + pstart.getX(), y + pstart.getY())).draw(new ULine(pdest.getX() - pstart.getX(), pdest.getY() + - pstart.getY())); + } + } + + private Point2D getPoint2D(Dimension2D dimSingle, TileArea area) { + final Position p = getPosition(area.getTile()); + double xt = p.getXmin() * dimSingle.getWidth() / 2; + double yt = p.getYmin() * dimSingle.getHeight() / 2; + xt += dimSingle.getWidth() / 2; + yt += dimSingle.getHeight() / 2; + final double coef = 0.33; + switch (area.getGeometry()) { + case NORTH: + yt -= dimSingle.getHeight() * coef; + break; + case SOUTH: + yt += dimSingle.getHeight() * coef; + break; + case EAST: + xt += dimSingle.getWidth() * coef; + break; + case WEST: + xt -= dimSingle.getWidth() * coef; + break; + default: + throw new IllegalStateException(); + } + return new Point2D.Double(xt, yt); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + final int xmin = getXmin(); + final int xmax = getXmax(); + final int ymin = getYmin(); + final int ymax = getYmax(); + final int width = (xmax - xmin) / 2 + 1; + final int height = (ymax - ymin) / 2 + 1; + final Dimension2D dimSingle = root.calculateDimension(stringBounder); + return new Dimension2DDouble(width * dimSingle.getWidth(), height * dimSingle.getHeight()); + } + +} diff --git a/src/net/sourceforge/plantuml/graph/ALink.java b/src/net/sourceforge/plantuml/graph/ALink.java index d259fcc4b..5190eabc1 100644 --- a/src/net/sourceforge/plantuml/graph/ALink.java +++ b/src/net/sourceforge/plantuml/graph/ALink.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3831 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; diff --git a/src/net/sourceforge/plantuml/graph/ALinkImpl.java b/src/net/sourceforge/plantuml/graph/ALinkImpl.java index c1dd65ece..7fd560844 100644 --- a/src/net/sourceforge/plantuml/graph/ALinkImpl.java +++ b/src/net/sourceforge/plantuml/graph/ALinkImpl.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3831 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; diff --git a/src/net/sourceforge/plantuml/graph/ANode.java b/src/net/sourceforge/plantuml/graph/ANode.java index a8136dd95..9b5b96499 100644 --- a/src/net/sourceforge/plantuml/graph/ANode.java +++ b/src/net/sourceforge/plantuml/graph/ANode.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3831 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; diff --git a/src/net/sourceforge/plantuml/graph/ANodeImpl.java b/src/net/sourceforge/plantuml/graph/ANodeImpl.java index a56c8ef2c..2b62b12ce 100644 --- a/src/net/sourceforge/plantuml/graph/ANodeImpl.java +++ b/src/net/sourceforge/plantuml/graph/ANodeImpl.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3831 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; diff --git a/src/net/sourceforge/plantuml/graph/AbstractEntityImage.java b/src/net/sourceforge/plantuml/graph/AbstractEntityImage.java index 7fd1de0f9..4c70efcc9 100644 --- a/src/net/sourceforge/plantuml/graph/AbstractEntityImage.java +++ b/src/net/sourceforge/plantuml/graph/AbstractEntityImage.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6591 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; @@ -37,29 +37,30 @@ import java.awt.Font; import java.awt.Graphics2D; import java.awt.geom.Dimension2D; -import net.sourceforge.plantuml.cucadiagram.Entity; +import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UFont; abstract class AbstractEntityImage { - private final Entity entity; + private final IEntity entity; - final private HtmlColor red = HtmlColor.getColorIfValid("#A80036"); + final private HtmlColor red = HtmlColorUtils.getColorIfValid("#A80036"); - final private HtmlColor yellow = HtmlColor.getColorIfValid("#FEFECE"); - private final HtmlColor yellowNote = HtmlColor.getColorIfValid("#FBFB77"); + final private HtmlColor yellow = HtmlColorUtils.getColorIfValid("#FEFECE"); + private final HtmlColor yellowNote = HtmlColorUtils.getColorIfValid("#FBFB77"); final private UFont font14 = new UFont("SansSerif", Font.PLAIN, 14); final private UFont font17 = new UFont("Courier", Font.BOLD, 17); - final private HtmlColor green = HtmlColor.getColorIfValid("#ADD1B2"); - final private HtmlColor violet = HtmlColor.getColorIfValid("#B4A7E5"); - final private HtmlColor blue = HtmlColor.getColorIfValid("#A9DCDF"); - final private HtmlColor rose = HtmlColor.getColorIfValid("#EB937F"); + final private HtmlColor green = HtmlColorUtils.getColorIfValid("#ADD1B2"); + final private HtmlColor violet = HtmlColorUtils.getColorIfValid("#B4A7E5"); + final private HtmlColor blue = HtmlColorUtils.getColorIfValid("#A9DCDF"); + final private HtmlColor rose = HtmlColorUtils.getColorIfValid("#EB937F"); - public AbstractEntityImage(Entity entity) { + public AbstractEntityImage(IEntity entity) { if (entity == null) { throw new IllegalArgumentException("entity null"); } @@ -70,7 +71,7 @@ abstract class AbstractEntityImage { public abstract void draw(ColorMapper colorMapper, Graphics2D g2d); - protected final Entity getEntity() { + protected final IEntity getEntity() { return entity; } diff --git a/src/net/sourceforge/plantuml/graph/Board.java b/src/net/sourceforge/plantuml/graph/Board.java index af01b8552..f536fd444 100644 --- a/src/net/sourceforge/plantuml/graph/Board.java +++ b/src/net/sourceforge/plantuml/graph/Board.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3831 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; diff --git a/src/net/sourceforge/plantuml/graph/BoardCollection.java b/src/net/sourceforge/plantuml/graph/BoardCollection.java index ca35e3629..83e4f7eef 100644 --- a/src/net/sourceforge/plantuml/graph/BoardCollection.java +++ b/src/net/sourceforge/plantuml/graph/BoardCollection.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3831 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; @@ -45,10 +45,10 @@ public class BoardCollection { public Entry(Board b, CostComputer costComputer) { this.board = b; - if (costComputer != null) { - this.cost = costComputer.getCost(b); - } else { + if (costComputer == null) { this.cost = 0; + } else { + this.cost = costComputer.getCost(b); } } @@ -86,7 +86,7 @@ public class BoardCollection { if (ent.explored == false) { ent.explored = true; assert costComputer.getCost(ent.board) == ent.cost; - // System.err.println("Peeking " + ent.cost); + // Log.println("Peeking " + ent.cost); return ent.board; } } diff --git a/src/net/sourceforge/plantuml/graph/BoardExplorer.java b/src/net/sourceforge/plantuml/graph/BoardExplorer.java index e5e41e4f6..91895d3bc 100644 --- a/src/net/sourceforge/plantuml/graph/BoardExplorer.java +++ b/src/net/sourceforge/plantuml/graph/BoardExplorer.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3831 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; diff --git a/src/net/sourceforge/plantuml/graph/CostComputer.java b/src/net/sourceforge/plantuml/graph/CostComputer.java index a6a362789..e7585e582 100644 --- a/src/net/sourceforge/plantuml/graph/CostComputer.java +++ b/src/net/sourceforge/plantuml/graph/CostComputer.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3831 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; diff --git a/src/net/sourceforge/plantuml/graph/Elastane.java b/src/net/sourceforge/plantuml/graph/Elastane.java index 7d398aa4b..e45694838 100644 --- a/src/net/sourceforge/plantuml/graph/Elastane.java +++ b/src/net/sourceforge/plantuml/graph/Elastane.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6591 $ + * Revision $Revision: 11153 $ * */ package net.sourceforge.plantuml.graph; @@ -39,7 +39,6 @@ import java.awt.Shape; import java.awt.geom.AffineTransform; import java.awt.geom.Dimension2D; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; @@ -50,7 +49,9 @@ import java.util.Set; import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.Log; -import net.sourceforge.plantuml.cucadiagram.Entity; +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.cucadiagram.Link; import net.sourceforge.plantuml.geom.Box; import net.sourceforge.plantuml.geom.CollectionUtils; @@ -58,8 +59,8 @@ import net.sourceforge.plantuml.geom.Point2DInt; import net.sourceforge.plantuml.geom.PolylineBreakeable; import net.sourceforge.plantuml.geom.XMoveable; import net.sourceforge.plantuml.graphic.FontConfiguration; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; -import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; import net.sourceforge.plantuml.graphic.StringBounderUtils; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; @@ -143,7 +144,7 @@ public class Elastane { final double dist = polyline.getDistance(b); assert dist >= 0; assert dist != Double.MAX_VALUE; - // System.err.println("dist=" + dist + " exp=" + (100000 - + // Log.println("dist=" + dist + " exp=" + (100000 - // dist)); result += 100000 - dist; } @@ -183,7 +184,7 @@ public class Elastane { } // if (trace) { // final double diff = getCost() - initCost; - // System.err.println("moving " + boxes + " " + delta + " diff=" + + // Log.println("moving " + boxes + " " + delta + " diff=" + // diff); // } // for (Map.Entry entry : lines.entrySet()) { @@ -223,7 +224,7 @@ public class Elastane { assert getCost() <= initCost; } - // System.err.println("COSTB=" + getCost()); + // Log.println("COSTB=" + getCost()); return changed; } @@ -265,14 +266,15 @@ public class Elastane { final PolylineBreakeable polyline = ent.getValue(); final Shape shape = factory.getLink(polyline, b1, b2); - final String label = l.getLabel(); + final String label = l.getLabel().get(0).toString(); if (label != null) { - final Point2DInt center = polyline.getFirst().getCenter(); - final TextBlock textBlock = TextBlockUtils.create(Arrays.asList(label), - new FontConfiguration(UFont.getCurrentFont(g2d), HtmlColor.BLACK), HorizontalAlignement.LEFT); - final Dimension2D dim = textBlock.calculateDimension(StringBounderUtils.asStringBounder(g2d)); - textBlock.drawTOBEREMOVED(new ColorMapperIdentity(), g2d, center.getXint() - dim.getWidth() / 2, - center.getYint() - dim.getHeight() / 2); + // polyline.getFirst().getCenter(); + final TextBlock textBlock = TextBlockUtils.create(Display.asList(label), + new FontConfiguration(UFont.getCurrentFont(g2d), HtmlColorUtils.BLACK), + HorizontalAlignment.LEFT, new SpriteContainerEmpty()); + textBlock.calculateDimension(StringBounderUtils.asStringBounder(g2d)); + // textBlock.drawTOBEREMOVED(new ColorMapperIdentity(), g2d, center.getXint() - dim.getWidth() / 2, + // center.getYint() - dim.getHeight() / 2); } g2d.setColor(red); @@ -310,7 +312,7 @@ public class Elastane { for (Map.Entry entry : lines.entrySet()) { final PolylineBreakeable p = entry.getValue(); final List freedoms = p.getFreedoms(); - // System.err.println("freedoms=" + freedoms); + // Log.println("freedoms=" + freedoms); if (freedoms.size() > 0) { linkMoveables.put(entry.getKey(), freedoms); // xmoveableGroups.addAll(CollectionUtils.selectUpTo(freedoms, @@ -352,7 +354,7 @@ public class Elastane { if (n == null) { return null; } - return new EntityImageFactory().createEntityImage((Entity) n.getUserData()); + return new EntityImageFactory().createEntityImage((IEntity) n.getUserData()); } public Dimension2D getDimension() { diff --git a/src/net/sourceforge/plantuml/graph/ElectricCharge.java b/src/net/sourceforge/plantuml/graph/ElectricCharge.java index 4d273e8e4..c437502d4 100644 --- a/src/net/sourceforge/plantuml/graph/ElectricCharge.java +++ b/src/net/sourceforge/plantuml/graph/ElectricCharge.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3831 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; diff --git a/src/net/sourceforge/plantuml/graph/ElectricWord.java b/src/net/sourceforge/plantuml/graph/ElectricWord.java index d6134f206..9f1a9999f 100644 --- a/src/net/sourceforge/plantuml/graph/ElectricWord.java +++ b/src/net/sourceforge/plantuml/graph/ElectricWord.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3831 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; diff --git a/src/net/sourceforge/plantuml/graph/EntityImageActivity.java b/src/net/sourceforge/plantuml/graph/EntityImageActivity.java index 036df725a..28c131cae 100644 --- a/src/net/sourceforge/plantuml/graph/EntityImageActivity.java +++ b/src/net/sourceforge/plantuml/graph/EntityImageActivity.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6923 $ + * Revision $Revision: 11153 $ * */ package net.sourceforge.plantuml.graph; @@ -39,11 +39,11 @@ import java.awt.Polygon; import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.cucadiagram.Entity; +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.graphic.FontConfiguration; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; -import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounderUtils; import net.sourceforge.plantuml.graphic.TextBlock; @@ -57,10 +57,10 @@ class EntityImageActivity extends AbstractEntityImage { private final int xMargin = 10; private final int yMargin = 6; - public EntityImageActivity(Entity entity) { + public EntityImageActivity(IEntity entity) { super(entity); - this.text = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( - getFont14(), HtmlColor.BLACK), HorizontalAlignement.CENTER); + this.text = TextBlockUtils.create(entity.getDisplay(), new FontConfiguration( + getFont14(), HtmlColorUtils.BLACK), HorizontalAlignment.CENTER, new SpriteContainerEmpty()); } @Override @@ -97,7 +97,7 @@ class EntityImageActivity extends AbstractEntityImage { g2d.draw(p); // g2d.drawRect(0, 0, width - 1, height - 1); g2d.setColor(Color.BLACK); - text.drawTOBEREMOVED(colorMapper, g2d, xMargin, yMargin); +// text.drawTOBEREMOVED(colorMapper, g2d, xMargin, yMargin); } } diff --git a/src/net/sourceforge/plantuml/graph/EntityImageActivityBar.java b/src/net/sourceforge/plantuml/graph/EntityImageActivityBar.java index c79a12b4e..889ae0623 100644 --- a/src/net/sourceforge/plantuml/graph/EntityImageActivityBar.java +++ b/src/net/sourceforge/plantuml/graph/EntityImageActivityBar.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6577 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; @@ -38,7 +38,7 @@ import java.awt.Graphics2D; import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.cucadiagram.Entity; +import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.ugraphic.ColorMapper; @@ -47,7 +47,7 @@ class EntityImageActivityBar extends AbstractEntityImage { private final int width = 100; private final int height = 8; - public EntityImageActivityBar(Entity entity) { + public EntityImageActivityBar(IEntity entity) { super(entity); } diff --git a/src/net/sourceforge/plantuml/graph/EntityImageActivityBranch.java b/src/net/sourceforge/plantuml/graph/EntityImageActivityBranch.java index 818b7ed59..fecb26f37 100644 --- a/src/net/sourceforge/plantuml/graph/EntityImageActivityBranch.java +++ b/src/net/sourceforge/plantuml/graph/EntityImageActivityBranch.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6577 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; @@ -38,7 +38,7 @@ import java.awt.Polygon; import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.cucadiagram.Entity; +import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.ugraphic.ColorMapper; @@ -46,7 +46,7 @@ class EntityImageActivityBranch extends AbstractEntityImage { private final int size = 10; - public EntityImageActivityBranch(Entity entity) { + public EntityImageActivityBranch(IEntity entity) { super(entity); } diff --git a/src/net/sourceforge/plantuml/graph/EntityImageActivityCircle.java b/src/net/sourceforge/plantuml/graph/EntityImageActivityCircle.java index 42ebffa3e..a24cb9657 100644 --- a/src/net/sourceforge/plantuml/graph/EntityImageActivityCircle.java +++ b/src/net/sourceforge/plantuml/graph/EntityImageActivityCircle.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6577 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; @@ -38,7 +38,7 @@ import java.awt.Graphics2D; import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.cucadiagram.Entity; +import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.ugraphic.ColorMapper; @@ -47,7 +47,7 @@ class EntityImageActivityCircle extends AbstractEntityImage { private final int diameterExternal; private final int diameterInternal; - public EntityImageActivityCircle(Entity entity, int diameterExternal, int diameterInternal) { + public EntityImageActivityCircle(IEntity entity, int diameterExternal, int diameterInternal) { super(entity); this.diameterExternal = diameterExternal; this.diameterInternal = diameterInternal; diff --git a/src/net/sourceforge/plantuml/graph/EntityImageActor.java b/src/net/sourceforge/plantuml/graph/EntityImageActor.java index cb3ebc8d4..0125a783c 100644 --- a/src/net/sourceforge/plantuml/graph/EntityImageActor.java +++ b/src/net/sourceforge/plantuml/graph/EntityImageActor.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,67 +28,58 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6923 $ + * Revision $Revision: 11154 $ * */ package net.sourceforge.plantuml.graph; -import java.awt.Color; import java.awt.Graphics2D; import java.awt.geom.Dimension2D; -import java.awt.geom.Rectangle2D; -import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.cucadiagram.Entity; -import net.sourceforge.plantuml.graphic.FontConfiguration; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; -import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.graphic.StringBounder; -import net.sourceforge.plantuml.graphic.StringBounderUtils; -import net.sourceforge.plantuml.graphic.TextBlock; -import net.sourceforge.plantuml.graphic.TextBlockUtils; -import net.sourceforge.plantuml.skin.StickMan; import net.sourceforge.plantuml.ugraphic.ColorMapper; class EntityImageActor extends AbstractEntityImage { - final private TextBlock name; - final private StickMan stickman; - - public EntityImageActor(Entity entity) { +// final private TextBlock name; +// final private StickMan stickman; +// + public EntityImageActor(IEntity entity) { super(entity); - this.name = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( - getFont14(), HtmlColor.BLACK), HorizontalAlignement.CENTER); - this.stickman = new StickMan(getYellow(), getRed()); +// this.name = TextBlockUtils.create(entity.getDisplay(), new FontConfiguration( +// getFont14(), HtmlColorUtils.BLACK), HorizontalAlignment.CENTER, new SpriteContainerEmpty()); +// this.stickman = new StickMan(getYellow(), getRed()); } - +// @Override public Dimension2D getDimension(StringBounder stringBounder) { - final Dimension2D nameDim = name.calculateDimension(stringBounder); - final double manWidth = stickman.getPreferredWidth(stringBounder); - final double manHeight = stickman.getPreferredHeight(stringBounder); - return new Dimension2DDouble(Math.max(manWidth, nameDim.getWidth()), manHeight + nameDim.getHeight()); +// final Dimension2D nameDim = name.calculateDimension(stringBounder); +// final double manWidth = stickman.getPreferredWidth(); +// final double manHeight = stickman.getPreferredHeight(); +// return new Dimension2DDouble(Math.max(manWidth, nameDim.getWidth()), manHeight + nameDim.getHeight()); + throw new UnsupportedOperationException(); } - +// @Override public void draw(ColorMapper colorMapper, Graphics2D g2d) { - final Dimension2D dimTotal = getDimension(StringBounderUtils.asStringBounder(g2d)); - final Dimension2D nameDim = name.calculateDimension(StringBounderUtils.asStringBounder(g2d)); - - final double manWidth = stickman.getPreferredWidth(StringBounderUtils.asStringBounder(g2d)); - final double manHeight = stickman.getPreferredHeight(StringBounderUtils.asStringBounder(g2d)); - - final double manX = (dimTotal.getWidth() - manWidth) / 2; - - g2d.setColor(Color.WHITE); - g2d.fill(new Rectangle2D.Double(0, 0, dimTotal.getWidth(), dimTotal.getHeight())); - - g2d.translate(manX, 0); - // stickman.draw(g2d); - g2d.translate(-manX, 0); - - g2d.setColor(Color.BLACK); - name.drawTOBEREMOVED(colorMapper, g2d, (dimTotal.getWidth() - nameDim.getWidth()) / 2, manHeight); +// final Dimension2D dimTotal = getDimension(StringBounderUtils.asStringBounder(g2d)); +// final Dimension2D nameDim = name.calculateDimension(StringBounderUtils.asStringBounder(g2d)); +// +// final double manWidth = stickman.getPreferredWidth(); +// final double manHeight = stickman.getPreferredHeight(); +// +// final double manX = (dimTotal.getWidth() - manWidth) / 2; +// +// g2d.setColor(Color.WHITE); +// g2d.fill(new Rectangle2D.Double(0, 0, dimTotal.getWidth(), dimTotal.getHeight())); +// +// g2d.translate(manX, 0); +// // stickman.draw(g2d); +// g2d.translate(-manX, 0); +// +// g2d.setColor(Color.BLACK); +//// name.drawTOBEREMOVED(colorMapper, g2d, (dimTotal.getWidth() - nameDim.getWidth()) / 2, manHeight); + throw new UnsupportedOperationException(); } } diff --git a/src/net/sourceforge/plantuml/graph/EntityImageCircleInterface.java b/src/net/sourceforge/plantuml/graph/EntityImageCircleInterface.java index 1e72506af..63149884f 100644 --- a/src/net/sourceforge/plantuml/graph/EntityImageCircleInterface.java +++ b/src/net/sourceforge/plantuml/graph/EntityImageCircleInterface.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6923 $ + * Revision $Revision: 11153 $ * */ package net.sourceforge.plantuml.graph; @@ -37,11 +37,11 @@ import java.awt.Graphics2D; import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.cucadiagram.Entity; +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.graphic.FontConfiguration; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; -import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; @@ -53,10 +53,10 @@ class EntityImageCircleInterface extends AbstractEntityImage { final private TextBlock name; final private CircleInterface circleInterface; - public EntityImageCircleInterface(Entity entity) { + public EntityImageCircleInterface(IEntity entity) { super(entity); - this.name = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( - getFont14(), HtmlColor.BLACK), HorizontalAlignement.CENTER); + this.name = TextBlockUtils.create(entity.getDisplay(), new FontConfiguration( + getFont14(), HtmlColorUtils.BLACK), HorizontalAlignment.CENTER, new SpriteContainerEmpty()); this.circleInterface = new CircleInterface(getYellow(), getRed()); } diff --git a/src/net/sourceforge/plantuml/graph/EntityImageClass.java b/src/net/sourceforge/plantuml/graph/EntityImageClass.java deleted file mode 100644 index c9d4e762e..000000000 --- a/src/net/sourceforge/plantuml/graph/EntityImageClass.java +++ /dev/null @@ -1,157 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009, Arnaud Roques - * - * Project Info: http://plantuml.sourceforge.net - * - * This file is part of PlantUML. - * - * PlantUML is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * PlantUML distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public - * License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. - * - * [Java is a trademark or registered trademark of Sun Microsystems, Inc. - * in the United States and other countries.] - * - * Original Author: Arnaud Roques - * - * Revision $Revision: 6923 $ - * - */ -package net.sourceforge.plantuml.graph; - -import java.awt.Color; -import java.awt.Graphics2D; -import java.awt.geom.Dimension2D; - -import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.cucadiagram.Entity; -import net.sourceforge.plantuml.cucadiagram.EntityType; -import net.sourceforge.plantuml.graphic.CircledCharacter; -import net.sourceforge.plantuml.graphic.FontConfiguration; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; -import net.sourceforge.plantuml.graphic.HtmlColor; -import net.sourceforge.plantuml.graphic.StringBounder; -import net.sourceforge.plantuml.graphic.StringBounderUtils; -import net.sourceforge.plantuml.graphic.TextBlock; -import net.sourceforge.plantuml.graphic.TextBlockUtils; -import net.sourceforge.plantuml.ugraphic.ColorMapper; -import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity; - -class EntityImageClass extends AbstractEntityImage { - - final private TextBlock name; - final private MethodsOrFieldsArea methods; - final private MethodsOrFieldsArea fields; - final private CircledCharacter circledCharacter; - - private final int xMargin = 10; - private final int yMargin = 6; - - public EntityImageClass(Entity entity) { - super(entity); - this.name = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( - getFont14(), HtmlColor.BLACK), HorizontalAlignement.CENTER); - this.methods = new MethodsOrFieldsArea(entity.getMethodsToDisplay(), getFont14()); - this.fields = new MethodsOrFieldsArea(entity.getFieldsToDisplay(), getFont14()); - - circledCharacter = getCircledCharacter(entity); - - } - - private CircledCharacter getCircledCharacter(Entity entity) { - // if (entity.getStereotype() != null) { - // return new CircledCharacter(entity.getStereotype().getCharacter(), - // font, entity.getStereotype().getColor(), - // red, Color.BLACK); - // } - final double radius = 10; - if (entity.getType() == EntityType.ABSTRACT_CLASS) { - return new CircledCharacter('A', radius, getFont17(), getBlue(), getRed(), HtmlColor.BLACK); - } - if (entity.getType() == EntityType.CLASS) { - return new CircledCharacter('C', radius, getFont17(), getGreen(), getRed(), HtmlColor.BLACK); - } - if (entity.getType() == EntityType.INTERFACE) { - return new CircledCharacter('I', radius, getFont17(), getViolet(), getRed(), HtmlColor.BLACK); - } - if (entity.getType() == EntityType.ENUM) { - return new CircledCharacter('E', radius, getFont17(), getRose(), getRed(), HtmlColor.BLACK); - } - assert false; - return null; - } - - @Override - public Dimension2D getDimension(StringBounder stringBounder) { - final Dimension2D dimName = getNameDimension(stringBounder); - final Dimension2D dimMethods = methods.calculateDimension(stringBounder); - final Dimension2D dimFields = fields.calculateDimension(stringBounder); - final double width = Math.max(Math.max(dimMethods.getWidth(), dimFields.getWidth()), dimName.getWidth()) + 2 - * xMargin; - final double height = dimMethods.getHeight() + dimFields.getHeight() + dimName.getHeight() + 6 * yMargin; - return new Dimension2DDouble(width, height); - } - - private Dimension2D getNameDimension(StringBounder stringBounder) { - final Dimension2D nameDim = name.calculateDimension(stringBounder); - if (circledCharacter == null) { - return nameDim; - } - return new Dimension2DDouble(nameDim.getWidth() + getCircledWidth(stringBounder), Math.max(nameDim.getHeight(), - circledCharacter.getPreferredHeight(stringBounder))); - } - - private double getCircledWidth(StringBounder stringBounder) { - if (circledCharacter == null) { - return 0; - } - return circledCharacter.getPreferredWidth(stringBounder) + 3; - } - - @Override - public void draw(ColorMapper colorMapper, Graphics2D g2d) { - final Dimension2D dimTotal = getDimension(StringBounderUtils.asStringBounder(g2d)); - final Dimension2D dimName = getNameDimension(StringBounderUtils.asStringBounder(g2d)); - final Dimension2D dimFields = fields.calculateDimension(StringBounderUtils.asStringBounder(g2d)); - - final int width = (int) dimTotal.getWidth(); - final int height = (int) dimTotal.getHeight(); - g2d.setColor(colorMapper.getMappedColor(getYellow())); - g2d.fillRect(0, 0, width, height); - - g2d.setColor(colorMapper.getMappedColor(getRed())); - g2d.drawRect(0, 0, width - 1, height - 1); - - final double line1 = dimName.getHeight() + 2 * yMargin; - final double line2 = dimName.getHeight() + dimFields.getHeight() + 4 * yMargin; - - g2d.drawLine(0, (int) line1, width, (int) line1); - g2d.drawLine(0, (int) line2, width, (int) line2); - - final double circledWidth = getCircledWidth(StringBounderUtils.asStringBounder(g2d)); - g2d.setColor(Color.BLACK); - name.drawTOBEREMOVED(colorMapper, g2d, xMargin + circledWidth, yMargin); - fields.drawTOBEREMOVED(colorMapper, g2d, xMargin, line1 + yMargin); - methods.drawTOBEREMOVED(colorMapper, g2d, xMargin, line2 + yMargin); - - if (circledCharacter != null) { - circledCharacter.draw(new ColorMapperIdentity(), g2d, xMargin, yMargin, 1.0); - } - - } -} diff --git a/src/net/sourceforge/plantuml/graph/EntityImageComponent.java b/src/net/sourceforge/plantuml/graph/EntityImageComponent.java index 778f44347..6e4d305ee 100644 --- a/src/net/sourceforge/plantuml/graph/EntityImageComponent.java +++ b/src/net/sourceforge/plantuml/graph/EntityImageComponent.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6923 $ + * Revision $Revision: 11153 $ * */ package net.sourceforge.plantuml.graph; @@ -41,11 +41,11 @@ import java.awt.geom.Dimension2D; import java.awt.geom.Rectangle2D; import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.cucadiagram.Entity; +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.graphic.FontConfiguration; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; -import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounderUtils; import net.sourceforge.plantuml.graphic.TextBlock; @@ -57,10 +57,10 @@ class EntityImageComponent extends AbstractEntityImage { final private TextBlock name; private final float thickness = (float) 1.6; - public EntityImageComponent(Entity entity) { + public EntityImageComponent(IEntity entity) { super(entity); - this.name = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( - getFont14(), HtmlColor.BLACK), HorizontalAlignement.CENTER); + this.name = TextBlockUtils.create(entity.getDisplay(), new FontConfiguration( + getFont14(), HtmlColorUtils.BLACK), HorizontalAlignment.CENTER, new SpriteContainerEmpty()); } @Override @@ -83,14 +83,14 @@ class EntityImageComponent extends AbstractEntityImage { @Override public void draw(ColorMapper colorMapper, Graphics2D g2d) { final Dimension2D dimTotal = getDimension(StringBounderUtils.asStringBounder(g2d)); - final Dimension2D nameDim = name.calculateDimension(StringBounderUtils.asStringBounder(g2d)); + name.calculateDimension(StringBounderUtils.asStringBounder(g2d)); drawRect(colorMapper, g2d, 6, 0, dimTotal.getWidth(), dimTotal.getHeight()); drawRect(colorMapper, g2d, 0, 7, 12, 6); drawRect(colorMapper, g2d, 0, dimTotal.getHeight() - 7 - 6, 12, 6); g2d.setColor(Color.BLACK); - name.drawTOBEREMOVED(colorMapper, g2d, 6 + (dimTotal.getWidth() - nameDim.getWidth()) / 2, - (dimTotal.getHeight() - nameDim.getHeight()) / 2); +// name.drawTOBEREMOVED(colorMapper, g2d, 6 + (dimTotal.getWidth() - nameDim.getWidth()) / 2, +// (dimTotal.getHeight() - nameDim.getHeight()) / 2); } } diff --git a/src/net/sourceforge/plantuml/graph/EntityImageDefault.java b/src/net/sourceforge/plantuml/graph/EntityImageDefault.java index 447f3dfc3..46804cce2 100644 --- a/src/net/sourceforge/plantuml/graph/EntityImageDefault.java +++ b/src/net/sourceforge/plantuml/graph/EntityImageDefault.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6923 $ + * Revision $Revision: 11153 $ * */ package net.sourceforge.plantuml.graph; @@ -36,13 +36,13 @@ package net.sourceforge.plantuml.graph; import java.awt.Color; import java.awt.Graphics2D; import java.awt.geom.Dimension2D; -import java.util.Arrays; import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.cucadiagram.Entity; +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.graphic.FontConfiguration; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; -import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounderUtils; import net.sourceforge.plantuml.graphic.TextBlock; @@ -53,10 +53,10 @@ class EntityImageDefault extends AbstractEntityImage { final private TextBlock textBlock; - public EntityImageDefault(Entity entity) { + public EntityImageDefault(IEntity entity) { super(entity); - this.textBlock = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration(getFont14(), - HtmlColor.BLACK), HorizontalAlignement.CENTER); + this.textBlock = TextBlockUtils.create(entity.getDisplay(), new FontConfiguration(getFont14(), + HtmlColorUtils.BLACK), HorizontalAlignment.CENTER, new SpriteContainerEmpty()); } @Override @@ -72,6 +72,6 @@ class EntityImageDefault extends AbstractEntityImage { final int height = (int) dim.getHeight(); g2d.setColor(Color.BLACK); g2d.drawRect(0, 0, width, height); - textBlock.drawTOBEREMOVED(colorMapper, g2d, 0, 0); +// textBlock.drawTOBEREMOVED(colorMapper, g2d, 0, 0); } } diff --git a/src/net/sourceforge/plantuml/graph/EntityImageFactory.java b/src/net/sourceforge/plantuml/graph/EntityImageFactory.java index 6c5174a94..6030f5e1d 100644 --- a/src/net/sourceforge/plantuml/graph/EntityImageFactory.java +++ b/src/net/sourceforge/plantuml/graph/EntityImageFactory.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,55 +28,56 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3831 $ + * Revision $Revision: 11321 $ * */ package net.sourceforge.plantuml.graph; -import net.sourceforge.plantuml.cucadiagram.Entity; -import net.sourceforge.plantuml.cucadiagram.EntityType; +import net.sourceforge.plantuml.cucadiagram.IEntity; public class EntityImageFactory { - public AbstractEntityImage createEntityImage(Entity entity) { - if (entity.getType() == EntityType.CLASS || entity.getType() == EntityType.ABSTRACT_CLASS - || entity.getType() == EntityType.INTERFACE || entity.getType() == EntityType.ENUM) { - return new EntityImageClass(entity); - } - if (entity.getType() == EntityType.ACTIVITY) { - return new EntityImageActivity(entity); - } - if (entity.getType() == EntityType.NOTE) { - return new EntityImageNote(entity); - } - if (entity.getType() == EntityType.POINT_FOR_ASSOCIATION) { - return new EntityImageActivityCircle(entity, 4, 4); - } - if (entity.getType() == EntityType.CIRCLE_START) { - return new EntityImageActivityCircle(entity, 18, 18); - } - if (entity.getType() == EntityType.CIRCLE_END) { - return new EntityImageActivityCircle(entity, 18, 11); - } - if (entity.getType() == EntityType.BRANCH) { - return new EntityImageActivityBranch(entity); - } - if (entity.getType() == EntityType.SYNCHRO_BAR) { - return new EntityImageActivityBar(entity); - } - if (entity.getType() == EntityType.USECASE) { - return new EntityImageUsecase(entity); - } - if (entity.getType() == EntityType.ACTOR) { - return new EntityImageActor(entity); - } - if (entity.getType() == EntityType.CIRCLE_INTERFACE) { - return new EntityImageCircleInterface(entity); - } - if (entity.getType() == EntityType.COMPONENT) { - return new EntityImageComponent(entity); - } - return new EntityImageDefault(entity); + public AbstractEntityImage createEntityImage(IEntity entity) { + throw new UnsupportedOperationException(); +// if (entity.getEntityType() == LeafType.CLASS || entity.getEntityType() == LeafType.ANNOTATION +// || entity.getEntityType() == LeafType.ABSTRACT_CLASS || entity.getEntityType() == LeafType.INTERFACE +// || entity.getEntityType() == LeafType.ENUM) { +// return new EntityImageClass(entity); +// } +// if (entity.getEntityType() == LeafType.ACTIVITY) { +// return new EntityImageActivity(entity); +// } +// if (entity.getEntityType() == LeafType.NOTE) { +// return new EntityImageNote(entity); +// } +// if (entity.getEntityType() == LeafType.POINT_FOR_ASSOCIATION) { +// return new EntityImageActivityCircle(entity, 4, 4); +// } +// if (entity.getEntityType() == LeafType.CIRCLE_START) { +// return new EntityImageActivityCircle(entity, 18, 18); +// } +// if (entity.getEntityType() == LeafType.CIRCLE_END) { +// return new EntityImageActivityCircle(entity, 18, 11); +// } +// if (entity.getEntityType() == LeafType.BRANCH) { +// return new EntityImageActivityBranch(entity); +// } +// if (entity.getEntityType() == LeafType.SYNCHRO_BAR) { +// return new EntityImageActivityBar(entity); +// } +// if (entity.getEntityType() == LeafType.USECASE) { +// return new EntityImageUsecase(entity); +// } +// if (entity.getEntityType() == LeafType.ACTOR) { +// return new EntityImageActor(entity); +// } +// if (entity.getEntityType() == LeafType.CIRCLE_INTERFACE) { +// return new EntityImageCircleInterface(entity); +// } +// if (entity.getEntityType() == LeafType.COMPONENT) { +// return new EntityImageComponent(entity); +// } +// return new EntityImageDefault(entity); } } diff --git a/src/net/sourceforge/plantuml/graph/EntityImageNote.java b/src/net/sourceforge/plantuml/graph/EntityImageNote.java index 211e36f54..e27b0921f 100644 --- a/src/net/sourceforge/plantuml/graph/EntityImageNote.java +++ b/src/net/sourceforge/plantuml/graph/EntityImageNote.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6923 $ + * Revision $Revision: 11153 $ * */ package net.sourceforge.plantuml.graph; @@ -39,11 +39,11 @@ import java.awt.Polygon; import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.cucadiagram.Entity; +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.graphic.FontConfiguration; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; -import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounderUtils; import net.sourceforge.plantuml.graphic.TextBlock; @@ -57,10 +57,10 @@ class EntityImageNote extends AbstractEntityImage { private final int xMargin = 10; private final int yMargin = 10; - public EntityImageNote(Entity entity) { + public EntityImageNote(IEntity entity) { super(entity); - this.text = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( - getFont14(), HtmlColor.BLACK), HorizontalAlignement.CENTER); + this.text = TextBlockUtils.create(entity.getDisplay(), new FontConfiguration( + getFont14(), HtmlColorUtils.BLACK), HorizontalAlignment.CENTER, new SpriteContainerEmpty()); } @Override @@ -92,7 +92,7 @@ class EntityImageNote extends AbstractEntityImage { g2d.drawLine(width - xMargin, yMargin, width, yMargin); g2d.setColor(Color.BLACK); - text.drawTOBEREMOVED(colorMapper, g2d, xMargin, yMargin); +// text.drawTOBEREMOVED(colorMapper, g2d, xMargin, yMargin); } } diff --git a/src/net/sourceforge/plantuml/graph/EntityImageUsecase.java b/src/net/sourceforge/plantuml/graph/EntityImageUsecase.java index 94b8efd16..c57adf3c1 100644 --- a/src/net/sourceforge/plantuml/graph/EntityImageUsecase.java +++ b/src/net/sourceforge/plantuml/graph/EntityImageUsecase.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,25 +28,23 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6923 $ + * Revision $Revision: 11153 $ * */ package net.sourceforge.plantuml.graph; import java.awt.Color; import java.awt.Graphics2D; -import java.awt.Shape; import java.awt.geom.Dimension2D; import java.awt.geom.GeneralPath; import java.awt.geom.QuadCurve2D; -import java.awt.geom.Rectangle2D; import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.cucadiagram.Entity; +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.graphic.FontConfiguration; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; -import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; import net.sourceforge.plantuml.graphic.StringBounder; import net.sourceforge.plantuml.graphic.StringBounderUtils; import net.sourceforge.plantuml.graphic.TextBlock; @@ -57,10 +55,10 @@ class EntityImageUsecase extends AbstractEntityImage { final private TextBlock name; - public EntityImageUsecase(Entity entity) { + public EntityImageUsecase(IEntity entity) { super(entity); - this.name = TextBlockUtils.create(entity.getDisplay2(), new FontConfiguration( - getFont14(), HtmlColor.BLACK), HorizontalAlignement.CENTER); + this.name = TextBlockUtils.create(entity.getDisplay(), new FontConfiguration( + getFont14(), HtmlColorUtils.BLACK), HorizontalAlignment.CENTER, new SpriteContainerEmpty()); } @Override @@ -95,13 +93,13 @@ class EntityImageUsecase extends AbstractEntityImage { g2d.setColor(colorMapper.getMappedColor(getRed())); g2d.draw(ellipse); - final Dimension2D nameDim = name.calculateDimension(StringBounderUtils.asStringBounder(g2d)); - final double posx = (w - nameDim.getWidth()) / 2; - final double posy = (h - nameDim.getHeight()) / 2; - final Shape rect = new Rectangle2D.Double(posx, posy, nameDim.getWidth(), nameDim.getHeight()); +// final Dimension2D nameDim = name.calculateDimension(StringBounderUtils.asStringBounder(g2d)); +// final double posx = (w - nameDim.getWidth()) / 2; +// final double posy = (h - nameDim.getHeight()) / 2; + // final Shape rect = new Rectangle2D.Double(posx, posy, nameDim.getWidth(), nameDim.getHeight()); // g2d.draw(rect); g2d.setColor(Color.BLACK); - name.drawTOBEREMOVED(colorMapper, g2d, posx, posy); + // name.drawTOBEREMOVED(colorMapper, g2d, posx, posy); } } diff --git a/src/net/sourceforge/plantuml/graph/Galaxy4.java b/src/net/sourceforge/plantuml/graph/Galaxy4.java index 2bafad66a..3d78b2fe7 100644 --- a/src/net/sourceforge/plantuml/graph/Galaxy4.java +++ b/src/net/sourceforge/plantuml/graph/Galaxy4.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; diff --git a/src/net/sourceforge/plantuml/graph/GeneralPathFactory.java b/src/net/sourceforge/plantuml/graph/GeneralPathFactory.java index bd5dac758..b19dd22b6 100644 --- a/src/net/sourceforge/plantuml/graph/GeneralPathFactory.java +++ b/src/net/sourceforge/plantuml/graph/GeneralPathFactory.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 4625 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; diff --git a/src/net/sourceforge/plantuml/graph/Graph1.java b/src/net/sourceforge/plantuml/graph/Graph1.java index 3a9859374..9895e4b3e 100644 --- a/src/net/sourceforge/plantuml/graph/Graph1.java +++ b/src/net/sourceforge/plantuml/graph/Graph1.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; diff --git a/src/net/sourceforge/plantuml/graph/Graph2.java b/src/net/sourceforge/plantuml/graph/Graph2.java index 32f2c05f7..cf432ac0a 100644 --- a/src/net/sourceforge/plantuml/graph/Graph2.java +++ b/src/net/sourceforge/plantuml/graph/Graph2.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; @@ -41,7 +41,7 @@ import java.util.Collections; import java.util.List; import net.sourceforge.plantuml.EmptyImageBuilder; -import net.sourceforge.plantuml.cucadiagram.Entity; +import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.graphic.StringBounderUtils; public class Graph2 { @@ -84,7 +84,7 @@ public class Graph2 { } private AbstractEntityImage images(ANode n) { - return new EntityImageFactory().createEntityImage(((Entity) n.getUserData())); + return new EntityImageFactory().createEntityImage((IEntity)n.getUserData()); } public Dimension2D getDimension() { diff --git a/src/net/sourceforge/plantuml/graph/Graph3.java b/src/net/sourceforge/plantuml/graph/Graph3.java index 891a4f357..e3cbee8ca 100644 --- a/src/net/sourceforge/plantuml/graph/Graph3.java +++ b/src/net/sourceforge/plantuml/graph/Graph3.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6577 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; @@ -49,7 +49,7 @@ import java.util.Set; import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.EmptyImageBuilder; import net.sourceforge.plantuml.Log; -import net.sourceforge.plantuml.cucadiagram.Entity; +import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.geom.InflationTransform; import net.sourceforge.plantuml.geom.Kingdom; import net.sourceforge.plantuml.geom.LineSegmentInt; @@ -233,21 +233,21 @@ public class Graph3 { final Pointable pp1 = nodePoints.get(link.getNode1()); final Pointable pp2 = nodePoints.get(link.getNode2()); if (kingdom.isSimpleSegmentPossible(pp1.getPosition(), pp2.getPosition())) { - System.err.println("OK for " + link); + Log.println("OK for " + link); kingdom.addDirectLink(pp1.getPosition(), pp2.getPosition()); polylines.add(new PolylineImpl(pp1, pp2)); } else { - System.err.println("Latter for " + link); + Log.println("Latter for " + link); latter.add(link); } } - System.err.println("latters=" + latter.size()); + Log.println("latters=" + latter.size()); for (ALink link : latter) { - System.err.println("Alatter=" + link); + Log.println("Alatter=" + link); } for (ALink link : latter) { - System.err.println("Blatter=" + link); + Log.println("Blatter=" + link); final Pointable pp1 = nodePoints.get(link.getNode1()); final Pointable pp2 = nodePoints.get(link.getNode2()); polylines.add((PolylineImpl) kingdom.getPath(pp1, pp2)); @@ -257,14 +257,14 @@ public class Graph3 { private void manyPasses(Board board) { final Collection> xmoveableGroups = getXMoveables(board); - System.err.println("COST_INIT=" + getCost()); + Log.println("COST_INIT=" + getCost()); for (int i = 0; i < 300; i++) { final boolean changed = onePass(xmoveableGroups); if (changed == false) { break; } } - System.err.println("COST_FIN=" + getCost()); + Log.println("COST_FIN=" + getCost()); } private Collection> getXMoveables(Board board) { @@ -317,7 +317,7 @@ public class Graph3 { assert getCost() <= initCost; } - // System.err.println("COSTB=" + getCost()); + // Log.println("COSTB=" + getCost()); return changed; } @@ -411,9 +411,8 @@ public class Graph3 { } public Dimension2D getDimension() { - final double width = spaceWidth * maxCol;// + boxWidth * (maxCol + - // 1); - final int height = spaceWidth * maxRow;// + boxHeight * (maxRow + 1); + final double width = spaceWidth * maxCol; + final int height = spaceWidth * maxRow; // + boxHeight * (maxRow + 1); return new Dimension2DDouble(width + 2 * margin + addedWidth, height + 2 * margin + addedHeight); } @@ -449,20 +448,18 @@ public class Graph3 { g2d.setColor(Color.BLUE); for (Polyline p : polylines) { if (p == null) { - System.err.println("Polyline NULL!!"); + Log.println("Polyline NULL!!"); continue; } for (LineSegmentInt seg : p.segments()) { - g2d - .drawLine(seg.getP1().getXint(), seg.getP1().getYint(), seg.getP2().getXint(), seg.getP2() - .getYint()); + g2d.drawLine(seg.getP1().getXint(), seg.getP1().getYint(), seg.getP2().getXint(), seg.getP2().getYint()); } } g2d.setColor(Color.GREEN); for (ANodePoint nodePoint : nodePoints.values()) { final Point2DInt p = nodePoint.getPosition(); - // System.err.println("p=" + p); + // Log.println("p=" + p); final AbstractEntityImage image = getImage(nodePoint.getNode()); final int width = (int) (image.getDimension(StringBounderUtils.asStringBounder(g2d)).getWidth()); final int height = (int) (image.getDimension(StringBounderUtils.asStringBounder(g2d)).getHeight()); @@ -475,7 +472,7 @@ public class Graph3 { } private AbstractEntityImage getImage(ANode n) { - return new EntityImageFactory().createEntityImage((Entity) n.getUserData()); + return new EntityImageFactory().createEntityImage((IEntity) n.getUserData()); } } diff --git a/src/net/sourceforge/plantuml/graph/Graph4.java b/src/net/sourceforge/plantuml/graph/Graph4.java index a9bc6b7d4..5533e05c8 100644 --- a/src/net/sourceforge/plantuml/graph/Graph4.java +++ b/src/net/sourceforge/plantuml/graph/Graph4.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6577 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; @@ -48,7 +48,8 @@ import java.util.Map; import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.EmptyImageBuilder; -import net.sourceforge.plantuml.cucadiagram.Entity; +import net.sourceforge.plantuml.Log; +import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.geom.InflationTransform; import net.sourceforge.plantuml.geom.Point2DInt; import net.sourceforge.plantuml.geom.Pointable; @@ -190,8 +191,8 @@ public class Graph4 { alreadyCurve.add(line); line.draw(g2d); } - final long TPS5 = System.currentTimeMillis() - start; - System.err.println("TPS5 = " + TPS5); + final long tps5 = System.currentTimeMillis() - start; + Log.println("TPS5 = " + tps5); g2d.setColor(Color.GREEN); for (ANodePoint nodePoint : nodePoints.values()) { @@ -258,7 +259,7 @@ public class Graph4 { } private AbstractEntityImage getImage(ANode n) { - return new EntityImageFactory().createEntityImage((Entity) n.getUserData()); + return new EntityImageFactory().createEntityImage((IEntity) n.getUserData()); } } diff --git a/src/net/sourceforge/plantuml/graph/Graph5.java b/src/net/sourceforge/plantuml/graph/Graph5.java index edfab375b..f8b92201a 100644 --- a/src/net/sourceforge/plantuml/graph/Graph5.java +++ b/src/net/sourceforge/plantuml/graph/Graph5.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6577 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; @@ -47,7 +47,7 @@ import java.util.Map; import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.EmptyImageBuilder; -import net.sourceforge.plantuml.cucadiagram.Entity; +import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.graph2.IInflationTransform; import net.sourceforge.plantuml.graph2.InflationTransform2; import net.sourceforge.plantuml.graph2.Plan; @@ -79,7 +79,7 @@ public class Graph5 { } private AbstractEntityImage getImage(ANode n) { - return new EntityImageFactory().createEntityImage((Entity) n.getUserData()); + return new EntityImageFactory().createEntityImage((IEntity) n.getUserData()); } public Graph5(Board board) { @@ -90,7 +90,7 @@ public class Graph5 { maxCol = Math.max(maxCol, board.getCol(n)); final Point2D.Double pos = getPosition(n); plan.addPoint2D(pos); - // System.err.println("n=" + n + " pos=" + pos); + // Log.println("n=" + n + " pos=" + pos); } for (ANode n : board.getNodes()) { final AbstractEntityImage image = getImage(n); @@ -103,7 +103,7 @@ public class Graph5 { inflationTransform.addInflationY(pos.getY(), heightCell); } - // System.err.println("inflationTransform=" + inflationTransform); + // Log.println("inflationTransform=" + inflationTransform); } diff --git a/src/net/sourceforge/plantuml/graph/Heap.java b/src/net/sourceforge/plantuml/graph/Heap.java index ba440a372..6620c506e 100644 --- a/src/net/sourceforge/plantuml/graph/Heap.java +++ b/src/net/sourceforge/plantuml/graph/Heap.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; diff --git a/src/net/sourceforge/plantuml/graph/KenavoCostComputer.java b/src/net/sourceforge/plantuml/graph/KenavoCostComputer.java index d8a7c28e0..e37dff1ab 100644 --- a/src/net/sourceforge/plantuml/graph/KenavoCostComputer.java +++ b/src/net/sourceforge/plantuml/graph/KenavoCostComputer.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; diff --git a/src/net/sourceforge/plantuml/graph/LenghtLinkComparator.java b/src/net/sourceforge/plantuml/graph/LenghtLinkComparator.java index a25ca123d..3f52dc22d 100644 --- a/src/net/sourceforge/plantuml/graph/LenghtLinkComparator.java +++ b/src/net/sourceforge/plantuml/graph/LenghtLinkComparator.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; diff --git a/src/net/sourceforge/plantuml/graph/LinkString.java b/src/net/sourceforge/plantuml/graph/LinkString.java index 159b2abb6..ff25db1f2 100644 --- a/src/net/sourceforge/plantuml/graph/LinkString.java +++ b/src/net/sourceforge/plantuml/graph/LinkString.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; diff --git a/src/net/sourceforge/plantuml/graph/MethodsOrFieldsArea.java b/src/net/sourceforge/plantuml/graph/MethodsOrFieldsArea.java index 787f4f338..9fa549493 100644 --- a/src/net/sourceforge/plantuml/graph/MethodsOrFieldsArea.java +++ b/src/net/sourceforge/plantuml/graph/MethodsOrFieldsArea.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,30 +28,29 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6590 $ + * Revision $Revision: 11153 $ * */ package net.sourceforge.plantuml.graph; -import java.awt.Graphics2D; import java.awt.geom.Dimension2D; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.cucadiagram.Member; import net.sourceforge.plantuml.graphic.FontConfiguration; -import net.sourceforge.plantuml.graphic.HorizontalAlignement; -import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HorizontalAlignment; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; import net.sourceforge.plantuml.graphic.StringBounder; -import net.sourceforge.plantuml.graphic.StringBounderUtils; import net.sourceforge.plantuml.graphic.TextBlock; import net.sourceforge.plantuml.graphic.TextBlockUtils; import net.sourceforge.plantuml.skin.VisibilityModifier; -import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; public class MethodsOrFieldsArea { @@ -61,7 +60,7 @@ public class MethodsOrFieldsArea { public MethodsOrFieldsArea(List attributes, UFont font) { this.font = font; for (Member att : attributes) { - this.strings.add(att.getDisplayWithoutVisibilityChar()); + this.strings.add(att.getDisplay(false)); } } @@ -82,22 +81,14 @@ public class MethodsOrFieldsArea { } private TextBlock createTextBlock(String s) { - return TextBlockUtils.create(Arrays.asList(s), new FontConfiguration(font, HtmlColor.BLACK), - HorizontalAlignement.LEFT); - } - - public void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { - for (String s : strings) { - final TextBlock bloc = createTextBlock(s); - bloc.drawTOBEREMOVED(colorMapper, g2d, x, y); - y += bloc.calculateDimension(StringBounderUtils.asStringBounder(g2d)).getHeight(); - } + return TextBlockUtils.create(Display.asList(s), new FontConfiguration(font, HtmlColorUtils.BLACK), + HorizontalAlignment.LEFT, new SpriteContainerEmpty()); } public void draw(UGraphic ug, double x, double y) { for (String s : strings) { final TextBlock bloc = createTextBlock(s); - bloc.drawU(ug, x, y); + bloc.drawU(ug.apply(new UTranslate(x, y))); y += bloc.calculateDimension(ug.getStringBounder()).getHeight(); } } diff --git a/src/net/sourceforge/plantuml/graph/Move.java b/src/net/sourceforge/plantuml/graph/Move.java index d6337bb1a..9b8baecd2 100644 --- a/src/net/sourceforge/plantuml/graph/Move.java +++ b/src/net/sourceforge/plantuml/graph/Move.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; diff --git a/src/net/sourceforge/plantuml/graph/Oven.java b/src/net/sourceforge/plantuml/graph/Oven.java index 3e3dc5960..04b0485ec 100644 --- a/src/net/sourceforge/plantuml/graph/Oven.java +++ b/src/net/sourceforge/plantuml/graph/Oven.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; @@ -50,7 +50,7 @@ public class Oven { Board bestBoard = board.copy(); for (int i = 0; i < nbTic; i++) { final double current = tic(board, rnd); - // System.err.println("current=" + current + " best=" + best); + // Log.println("current=" + current + " best=" + best); if (current < best) { best = current; bestBoard = board.copy(); @@ -61,30 +61,30 @@ public class Oven { } public double tic(Board board, Random rnd) { - // System.err.println("Oven::tic"); + // Log.println("Oven::tic"); final double costBefore = costComputer.getCost(board); - final Move move = null;// board.getRandomMove(rnd); + final Move move = null; // board.getRandomMove(rnd); board.applyMove(move); final double costAfter = costComputer.getCost(board); final double delta = costAfter - costBefore; - // System.err.println("delta=" + delta); + // Log.println("delta=" + delta); if (delta <= 0) { return costAfter; } assert delta > 0; assert costAfter > costBefore; - // System.err.println("temp=" + temp); + // Log.println("temp=" + temp); if (temp > 0) { final double probability = Math.exp(-delta / temp); final double dice = rnd.nextDouble(); - // System.err.println("probability=" + probability + " dice=" + + // Log.println("probability=" + probability + " dice=" + // dice); if (dice < probability) { - // System.err.println("We keep it"); + // Log.println("We keep it"); return costAfter; } } - // System.err.println("Roolback"); + // Log.println("Roolback"); board.applyMove(move.getBackMove()); assert costBefore == costComputer.getCost(board); return costBefore; diff --git a/src/net/sourceforge/plantuml/graph/SimpleCostComputer.java b/src/net/sourceforge/plantuml/graph/SimpleCostComputer.java index 5b47c5f35..2dbc91f79 100644 --- a/src/net/sourceforge/plantuml/graph/SimpleCostComputer.java +++ b/src/net/sourceforge/plantuml/graph/SimpleCostComputer.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; diff --git a/src/net/sourceforge/plantuml/graph/SortedCollection.java b/src/net/sourceforge/plantuml/graph/SortedCollection.java index 93e645c06..dcad4fb48 100644 --- a/src/net/sourceforge/plantuml/graph/SortedCollection.java +++ b/src/net/sourceforge/plantuml/graph/SortedCollection.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; diff --git a/src/net/sourceforge/plantuml/graph/SortedCollectionArrayList.java b/src/net/sourceforge/plantuml/graph/SortedCollectionArrayList.java index f445be251..11ac49b6e 100644 --- a/src/net/sourceforge/plantuml/graph/SortedCollectionArrayList.java +++ b/src/net/sourceforge/plantuml/graph/SortedCollectionArrayList.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; diff --git a/src/net/sourceforge/plantuml/graph/SortedCollectionLinked.java b/src/net/sourceforge/plantuml/graph/SortedCollectionLinked.java index cfd3312d7..323fee25e 100644 --- a/src/net/sourceforge/plantuml/graph/SortedCollectionLinked.java +++ b/src/net/sourceforge/plantuml/graph/SortedCollectionLinked.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; diff --git a/src/net/sourceforge/plantuml/graph/Zoda1.java b/src/net/sourceforge/plantuml/graph/Zoda1.java index 539d2a7a5..307fe488d 100644 --- a/src/net/sourceforge/plantuml/graph/Zoda1.java +++ b/src/net/sourceforge/plantuml/graph/Zoda1.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; diff --git a/src/net/sourceforge/plantuml/graph/Zoda2.java b/src/net/sourceforge/plantuml/graph/Zoda2.java index 5ee584bb1..48f756be4 100644 --- a/src/net/sourceforge/plantuml/graph/Zoda2.java +++ b/src/net/sourceforge/plantuml/graph/Zoda2.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph; diff --git a/src/net/sourceforge/plantuml/graph2/CubicCurveFactory.java b/src/net/sourceforge/plantuml/graph2/CubicCurveFactory.java index 6b2d6ff1f..af8015ff1 100644 --- a/src/net/sourceforge/plantuml/graph2/CubicCurveFactory.java +++ b/src/net/sourceforge/plantuml/graph2/CubicCurveFactory.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph2; @@ -70,8 +70,8 @@ public class CubicCurveFactory { for (Rectangle2D.Double rect : forbiddenRect) { all.addAll(MagicPointsFactory.get(rect)); } - System.err.println("s1 " + all.size()); - final long t1 = System.currentTimeMillis(); +// Log.println("s1 " + all.size()); +// final long t1 = System.currentTimeMillis(); double min = Double.MAX_VALUE; for (Point2D.Double p1 : all) { for (Point2D.Double p2 : all) { @@ -84,10 +84,10 @@ public class CubicCurveFactory { } } } - final long t2 = System.currentTimeMillis() - t1; - System.err.println("s2 = " + t2); - System.err.println("TPS1 = " + RectanglesCollection.TPS1); - System.err.println("TPS2 = " + RectanglesCollection.TPS2); +// final long t2 = System.currentTimeMillis() - t1; +// Log.println("s2 = " + t2); +// Log.println("TPS1 = " + RectanglesCollection.TPS1); +// Log.println("TPS2 = " + RectanglesCollection.TPS2); } return result; } diff --git a/src/net/sourceforge/plantuml/graph2/Dijkstra.java b/src/net/sourceforge/plantuml/graph2/Dijkstra.java index 8d8025101..58da44db5 100644 --- a/src/net/sourceforge/plantuml/graph2/Dijkstra.java +++ b/src/net/sourceforge/plantuml/graph2/Dijkstra.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph2; diff --git a/src/net/sourceforge/plantuml/graph2/GeomUtils.java b/src/net/sourceforge/plantuml/graph2/GeomUtils.java index efd8e6255..5ac1fc1db 100644 --- a/src/net/sourceforge/plantuml/graph2/GeomUtils.java +++ b/src/net/sourceforge/plantuml/graph2/GeomUtils.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 7205 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph2; diff --git a/src/net/sourceforge/plantuml/graph2/IInflationTransform.java b/src/net/sourceforge/plantuml/graph2/IInflationTransform.java index 428318b6d..3c36cacdc 100644 --- a/src/net/sourceforge/plantuml/graph2/IInflationTransform.java +++ b/src/net/sourceforge/plantuml/graph2/IInflationTransform.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph2; diff --git a/src/net/sourceforge/plantuml/graph2/IdentityInflationTransform.java b/src/net/sourceforge/plantuml/graph2/IdentityInflationTransform.java index 7bb8f6838..32291f41d 100644 --- a/src/net/sourceforge/plantuml/graph2/IdentityInflationTransform.java +++ b/src/net/sourceforge/plantuml/graph2/IdentityInflationTransform.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph2; diff --git a/src/net/sourceforge/plantuml/graph2/InflateData2.java b/src/net/sourceforge/plantuml/graph2/InflateData2.java index 5bfb823ef..315017ff5 100644 --- a/src/net/sourceforge/plantuml/graph2/InflateData2.java +++ b/src/net/sourceforge/plantuml/graph2/InflateData2.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph2; diff --git a/src/net/sourceforge/plantuml/graph2/InflationTransform2.java b/src/net/sourceforge/plantuml/graph2/InflationTransform2.java index 80c83c454..a669e9247 100644 --- a/src/net/sourceforge/plantuml/graph2/InflationTransform2.java +++ b/src/net/sourceforge/plantuml/graph2/InflationTransform2.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph2; diff --git a/src/net/sourceforge/plantuml/graph2/MagicPointsFactory.java b/src/net/sourceforge/plantuml/graph2/MagicPointsFactory.java index 0d013b9aa..3b05d859a 100644 --- a/src/net/sourceforge/plantuml/graph2/MagicPointsFactory.java +++ b/src/net/sourceforge/plantuml/graph2/MagicPointsFactory.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph2; diff --git a/src/net/sourceforge/plantuml/graph2/MagicPointsFactory2.java b/src/net/sourceforge/plantuml/graph2/MagicPointsFactory2.java index 2de346839..b4d4802ac 100644 --- a/src/net/sourceforge/plantuml/graph2/MagicPointsFactory2.java +++ b/src/net/sourceforge/plantuml/graph2/MagicPointsFactory2.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph2; diff --git a/src/net/sourceforge/plantuml/graph2/Measurer.java b/src/net/sourceforge/plantuml/graph2/Measurer.java index 5f3c6e96d..b558a8867 100644 --- a/src/net/sourceforge/plantuml/graph2/Measurer.java +++ b/src/net/sourceforge/plantuml/graph2/Measurer.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph2; diff --git a/src/net/sourceforge/plantuml/graph2/MyCurve.java b/src/net/sourceforge/plantuml/graph2/MyCurve.java index 0017aba94..e5d789c85 100644 --- a/src/net/sourceforge/plantuml/graph2/MyCurve.java +++ b/src/net/sourceforge/plantuml/graph2/MyCurve.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph2; diff --git a/src/net/sourceforge/plantuml/graph2/Neighborhood2.java b/src/net/sourceforge/plantuml/graph2/Neighborhood2.java index 2b85f97ed..ce99438de 100644 --- a/src/net/sourceforge/plantuml/graph2/Neighborhood2.java +++ b/src/net/sourceforge/plantuml/graph2/Neighborhood2.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph2; diff --git a/src/net/sourceforge/plantuml/graph2/Plan.java b/src/net/sourceforge/plantuml/graph2/Plan.java index b25e0e5e5..b147e035b 100644 --- a/src/net/sourceforge/plantuml/graph2/Plan.java +++ b/src/net/sourceforge/plantuml/graph2/Plan.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph2; @@ -41,6 +41,7 @@ import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import net.sourceforge.plantuml.Log; import net.sourceforge.plantuml.graph2.Dijkstra.Vertex; public class Plan { @@ -56,12 +57,12 @@ public class Plan { } public void debugPrint() { - System.err.println("PLAN PRINT"); + Log.println("PLAN PRINT"); for (Singularity2 s : points.values()) { - System.err.println(s); + Log.println("s="+s); } for (Line2D.Double l : lines) { - System.err.println(GeomUtils.toString(l)); + Log.println(GeomUtils.toString(l)); } } @@ -124,7 +125,7 @@ public class Plan { final double dist = n1.getCenter().distance(n2.getCenter()); v1.addAdjacencies(v2, dist); v2.addAdjacencies(v1, dist); - // System.err.println("=(" + n1 + ") (" + n2 + ") " + dist); + // Log.println("=(" + n1 + ") (" + n2 + ") " + dist); } } @@ -140,21 +141,21 @@ public class Plan { } public List getIntermediatePoints(Point2D start, Point2D end) { - // System.err.println("start=" + start + " end=" + end); + // Log.println("start=" + start + " end=" + end); final List result = new ArrayList(); final List list = getShortestPathToInternal(start, end); - // System.err.println("Neighborhood2 = " + list); + // Log.println("Neighborhood2 = " + list); for (int i = 1; i < list.size() - 1; i++) { final Neighborhood2 n = list.get(i); final Point2D.Double before = list.get(i - 1).getCenter(); final Point2D.Double after = list.get(i + 1).getCenter(); - // System.err.println("before="+before); - // System.err.println("after="+after); - // System.err.println("n.getCenter()="+n.getCenter()); - // System.err.println("getMindist(n.getCenter())="+getMindist(n.getCenter())); + // Log.println("before="+before); + // Log.println("after="+after); + // Log.println("n.getCenter()="+n.getCenter()); + // Log.println("getMindist(n.getCenter())="+getMindist(n.getCenter())); final Point2D.Double pointInNeighborhood = n.getPointInNeighborhood(getMindist(n.getCenter()) / 2, before, after); - // System.err.println("pointInNeighborhood="+pointInNeighborhood); + // Log.println("pointInNeighborhood="+pointInNeighborhood); result.add(pointInNeighborhood); } return result; @@ -246,7 +247,7 @@ public class Plan { if (result == 0) { throw new IllegalStateException(); } - // System.err.println("getMindist=" + result); + // Log.println("getMindist=" + result); return result; } } diff --git a/src/net/sourceforge/plantuml/graph2/Polyline2.java b/src/net/sourceforge/plantuml/graph2/Polyline2.java index 0a73cad0c..4242f9ead 100644 --- a/src/net/sourceforge/plantuml/graph2/Polyline2.java +++ b/src/net/sourceforge/plantuml/graph2/Polyline2.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph2; @@ -53,7 +53,7 @@ public class Polyline2 { } public void addLine(Line2D.Double newLine) { - // System.err.println("# Polyline2::addLine " + + // Log.println("# Polyline2::addLine " + // GeomUtils.toString(newLine)); if (lastCurrent.equals(newLine.getP1()) == false) { lines.add(new Line2D.Double(lastCurrent, newLine.getP1())); diff --git a/src/net/sourceforge/plantuml/graph2/RectanglesCollection.java b/src/net/sourceforge/plantuml/graph2/RectanglesCollection.java index 33b635b89..da18086f3 100644 --- a/src/net/sourceforge/plantuml/graph2/RectanglesCollection.java +++ b/src/net/sourceforge/plantuml/graph2/RectanglesCollection.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph2; @@ -107,8 +107,8 @@ public class RectanglesCollection implements Iterable { return intersectSeveral(other, this); } - static public long TPS1; - static public long TPS2; + static private long TPS1; + static private long TPS2; private static boolean intersectSeveral(RectanglesCollection large, RectanglesCollection compact) { assert large.size() >= compact.size(); diff --git a/src/net/sourceforge/plantuml/graph2/Singularity2.java b/src/net/sourceforge/plantuml/graph2/Singularity2.java index f24ef7c11..1f3ba58f2 100644 --- a/src/net/sourceforge/plantuml/graph2/Singularity2.java +++ b/src/net/sourceforge/plantuml/graph2/Singularity2.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph2; diff --git a/src/net/sourceforge/plantuml/graph2/SortedList.java b/src/net/sourceforge/plantuml/graph2/SortedList.java index 377e48c11..2016ef35e 100644 --- a/src/net/sourceforge/plantuml/graph2/SortedList.java +++ b/src/net/sourceforge/plantuml/graph2/SortedList.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph2; diff --git a/src/net/sourceforge/plantuml/graph2/SortedListImpl.java b/src/net/sourceforge/plantuml/graph2/SortedListImpl.java index dbda3b5aa..2a6e7e17b 100644 --- a/src/net/sourceforge/plantuml/graph2/SortedListImpl.java +++ b/src/net/sourceforge/plantuml/graph2/SortedListImpl.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3833 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graph2; diff --git a/src/net/sourceforge/plantuml/graphic/AddStyle.java b/src/net/sourceforge/plantuml/graphic/AddStyle.java index 35e248479..ffb50879c 100644 --- a/src/net/sourceforge/plantuml/graphic/AddStyle.java +++ b/src/net/sourceforge/plantuml/graphic/AddStyle.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,18 +28,18 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6570 $ + * Revision $Revision: 11535 $ * */ package net.sourceforge.plantuml.graphic; -class AddStyle implements FontChange { +public class AddStyle implements FontChange { private final FontStyle style; private final HtmlColor extendedColor; - AddStyle(FontStyle style, HtmlColor extendedColor) { + public AddStyle(FontStyle style, HtmlColor extendedColor) { this.style = style; this.extendedColor = extendedColor; } diff --git a/src/net/sourceforge/plantuml/graphic/CircledCharacter.java b/src/net/sourceforge/plantuml/graphic/CircledCharacter.java index 989bea296..5c1ece172 100644 --- a/src/net/sourceforge/plantuml/graphic/CircledCharacter.java +++ b/src/net/sourceforge/plantuml/graphic/CircledCharacter.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,40 +28,23 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6780 $ + * Revision $Revision: 11873 $ * */ package net.sourceforge.plantuml.graphic; -import java.awt.Graphics2D; -import java.awt.Shape; -import java.awt.font.FontRenderContext; -import java.awt.font.TextLayout; import java.awt.geom.Dimension2D; -import java.awt.geom.PathIterator; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; -import java.util.Arrays; - -import javax.imageio.ImageIO; import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.EmptyImageBuilder; -import net.sourceforge.plantuml.FileUtils; -import net.sourceforge.plantuml.cucadiagram.dot.DrawFile; -import net.sourceforge.plantuml.cucadiagram.dot.Lazy; -import net.sourceforge.plantuml.skin.UDrawable; -import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.ugraphic.UCenteredCharacter; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; import net.sourceforge.plantuml.ugraphic.UEllipse; import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; -import net.sourceforge.plantuml.ugraphic.UPath; -import net.sourceforge.plantuml.ugraphic.USegmentType; -import net.sourceforge.plantuml.ugraphic.eps.UGraphicEps; -import net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d; +import net.sourceforge.plantuml.ugraphic.UTranslate; -public class CircledCharacter implements UDrawable, TextBlock { +public class CircledCharacter implements TextBlock { private final String c; private final UFont font; @@ -80,21 +63,20 @@ public class CircledCharacter implements UDrawable, TextBlock { this.fontColor = fontColor; } - public void draw(ColorMapper colorMapper, Graphics2D g2d, int x, int y, double dpiFactor) { - drawU(new UGraphicG2d(colorMapper, g2d, null, 1.0), x, y); - } - - public void drawU(UGraphic ug, double x, double y) { + // public void draw(ColorMapper colorMapper, Graphics2D g2d, int x, int y, double dpiFactor) { + // drawU(new UGraphicG2d(colorMapper, g2d, null, 1.0), x, y); + // } + public void drawU(UGraphic ug) { if (circle != null) { - ug.getParam().setColor(circle); + ug = ug.apply(new UChangeColor(circle)); } - ug.getParam().setBackcolor(innerCircle); - ug.draw(x, y, new UEllipse(radius * 2, radius * 2)); - ug.getParam().setColor(fontColor); - ug.centerChar(x + radius, y + radius, c.charAt(0), font); - ug.getParam().setBackcolor(null); - + // final HtmlColor back = ug.getParam().getBackcolor(); + ug = ug.apply(new UChangeBackColor(innerCircle)); + ug.draw(new UEllipse(radius * 2, radius * 2)); + ug = ug.apply(new UChangeColor(fontColor)); + ug = ug.apply(new UTranslate(radius, radius)); + ug.draw(new UCenteredCharacter(c.charAt(0), font)); } final public double getPreferredWidth(StringBounder stringBounder) { @@ -105,80 +87,28 @@ public class CircledCharacter implements UDrawable, TextBlock { return 2 * radius; } - public void drawU(UGraphic ug) { - drawU(ug, 0, 0); - } - - private PathIterator getPathIteratorCharacter(FontRenderContext frc) { - final TextLayout textLayout = new TextLayout(c, font.getFont(), frc); - final Shape s = textLayout.getOutline(null); - return s.getPathIterator(null); - } - - public UPath getUPath(FontRenderContext frc) { - final UPath result = new UPath(); - - final PathIterator path = getPathIteratorCharacter(frc); - - final double coord[] = new double[6]; - while (path.isDone() == false) { - final int code = path.currentSegment(coord); - result.add(coord, USegmentType.getByCode(code)); - path.next(); - } - - return result; - } + // private PathIterator getPathIteratorCharacter(FontRenderContext frc) { + // final TextLayout textLayout = new TextLayout(c, font.getFont(), frc); + // final Shape s = textLayout.getOutline(null); + // return s.getPathIterator(null); + // } + // + // private UPath getUPath(FontRenderContext frc) { + // final UPath result = new UPath(); + // + // final PathIterator path = getPathIteratorCharacter(frc); + // + // final double coord[] = new double[6]; + // while (path.isDone() == false) { + // final int code = path.currentSegment(coord); + // result.add(coord, USegmentType.getByCode(code)); + // path.next(); + // } + // + // return result; + // } public Dimension2D calculateDimension(StringBounder stringBounder) { return new Dimension2DDouble(getPreferredWidth(stringBounder), getPreferredHeight(stringBounder)); } - - public void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { - throw new UnsupportedOperationException(); - } - - public DrawFile generateCircleCharacter(final ColorMapper colorMapper, final HtmlColor background, - final double dpiFactor) throws IOException { - - final Lazy lpng = new Lazy() { - - public File getNow() throws IOException { - final File png = FileUtils.createTempFile("circle", ".png"); - final EmptyImageBuilder builder = new EmptyImageBuilder((int) (60 * dpiFactor), (int) (60 * dpiFactor), - colorMapper.getMappedColor(background), dpiFactor); - BufferedImage im = builder.getBufferedImage(); - final Graphics2D g2d = builder.getGraphics2D(); - final StringBounder stringBounder = StringBounderUtils.asStringBounder(g2d); - - draw(colorMapper, g2d, 0, 0, dpiFactor); - im = im.getSubimage(0, 0, (int) (getPreferredWidth(stringBounder) * dpiFactor) + 5, - (int) (getPreferredHeight(stringBounder) * dpiFactor) + 1); - - ImageIO.write(im, "png", png); - return png; - } - }; - - final Lazy leps = new Lazy() { - public File getNow() throws IOException { - final File epsFile = FileUtils.createTempFile("circle", ".eps"); - UGraphicEps.copyEpsToFile(colorMapper, CircledCharacter.this, epsFile); - return epsFile; - } - }; - - final Lazy lsvg = new Lazy() { - public String getNow() throws IOException { - return UGraphicG2d.getSvgString(colorMapper, CircledCharacter.this); - } - - }; - - final Object signature = Arrays.asList("circle", c, font, innerCircle, circle, fontColor, radius, background, - dpiFactor); - - return DrawFile.create(lpng, lsvg, leps, signature); - } - } diff --git a/src/net/sourceforge/plantuml/graphic/ColorAndSizeChange.java b/src/net/sourceforge/plantuml/graphic/ColorAndSizeChange.java index 9ceb5d8a2..55d3c9530 100644 --- a/src/net/sourceforge/plantuml/graphic/ColorAndSizeChange.java +++ b/src/net/sourceforge/plantuml/graphic/ColorAndSizeChange.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5983 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graphic; @@ -48,7 +48,7 @@ class ColorAndSizeChange implements FontChange { ColorAndSizeChange(String s) { final Matcher matcherColor = colorPattern.matcher(s); if (matcherColor.find()) { - color = HtmlColor.getColorIfValid(matcherColor.group(1)); + color = HtmlColorUtils.getColorIfValid(matcherColor.group(1)); } else { color = null; } diff --git a/src/net/sourceforge/plantuml/graphic/ColorChange.java b/src/net/sourceforge/plantuml/graphic/ColorChange.java index c41b088a5..4074381af 100644 --- a/src/net/sourceforge/plantuml/graphic/ColorChange.java +++ b/src/net/sourceforge/plantuml/graphic/ColorChange.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -47,7 +47,7 @@ class ColorChange implements FontChange { if (matcherColor.find() == false) { throw new IllegalArgumentException(); } - this.color = HtmlColor.getColorIfValid(matcherColor.group(1)); + this.color = HtmlColorUtils.getColorIfValid(matcherColor.group(1)); } HtmlColor getColor() { diff --git a/src/net/sourceforge/plantuml/graphic/DateEventUtils.java b/src/net/sourceforge/plantuml/graphic/DateEventUtils.java new file mode 100644 index 000000000..131e44c68 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/DateEventUtils.java @@ -0,0 +1,81 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 10930 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.Font; +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Arrays; +import java.util.Date; +import java.util.List; + +import net.sourceforge.plantuml.SpriteContainerEmpty; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.ugraphic.UFont; + +public class DateEventUtils { + + public static TextBlock addEvent(TextBlock textBlock, HtmlColor color) { + final DateFormat dateFormat = new SimpleDateFormat("MM-dd"); + final String today = dateFormat.format(new Date()); + + if ("11-05".equals(today)) { + final List asList = Arrays.asList("November 5th, 1955", + "Doc Brown's discovery of the Flux Capacitor, that makes time-travel possible."); + return TextBlockUtils.mergeTB(textBlock, getComment(asList, color), HorizontalAlignment.LEFT); + } else if ("08-29".equals(today)) { + final List asList = Arrays.asList("August 29th, 1997", + "Skynet becomes self-aware at 02:14 AM Eastern Time."); + return TextBlockUtils.mergeTB(textBlock, getComment(asList, color), HorizontalAlignment.LEFT); + } else if ("06-29".equals(today)) { + final List asList = Arrays.asList("June 29th, 1975", + "\"It was the first time in history that anyone had typed", + "a character on a keyboard and seen it show up on their", + "own computer’s screen right in front of them.\"", "\t\t\t\t\t\t\t\t\t\tSteve Wozniak"); + return TextBlockUtils.mergeTB(textBlock, getComment(asList, color), HorizontalAlignment.LEFT); + } + + return textBlock; + } + + private static TextBlock getComment(final List asList, HtmlColor color) { + final UFont font = new UFont("SansSerif", Font.BOLD, 14); + TextBlock comment = TextBlockUtils.create(new Display(asList), new FontConfiguration(font, color), + HorizontalAlignment.LEFT, new SpriteContainerEmpty()); + comment = TextBlockUtils.withMargin(comment, 4, 4); + comment = new TextBlockBordered(comment, color); + comment = TextBlockUtils.withMargin(comment, 10, 10); + return comment; + } +} diff --git a/src/net/sourceforge/plantuml/graphic/DisplayUtils.java b/src/net/sourceforge/plantuml/graphic/DisplayUtils.java new file mode 100644 index 000000000..a1d93ea3e --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/DisplayUtils.java @@ -0,0 +1,54 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 10307 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import net.sourceforge.plantuml.SpriteContainer; +import net.sourceforge.plantuml.cucadiagram.Display; + +public class DisplayUtils { + + private static Display breakLines(Display texts, FontConfiguration fontConfiguration, + SpriteContainer spriteContainer, double maxWidth) { + if (texts.size() != 1) { + return texts; + } + final CharSequence s = texts.get(0); + Display result = new Display(); + final int nb = s.length() / 2; + result = result.add(s.subSequence(0, nb)); + result = result.add(s.subSequence(nb + 1, s.length())); + return result; + } + +} diff --git a/src/net/sourceforge/plantuml/graphic/EmbededSystemLine.java b/src/net/sourceforge/plantuml/graphic/EmbededSystemLine.java index b998694dd..535af04a4 100644 --- a/src/net/sourceforge/plantuml/graphic/EmbededSystemLine.java +++ b/src/net/sourceforge/plantuml/graphic/EmbededSystemLine.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,7 +33,6 @@ */ package net.sourceforge.plantuml.graphic; -import java.awt.Graphics2D; import java.awt.geom.Dimension2D; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; @@ -48,18 +47,17 @@ import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.EmbededDiagram; import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.FileFormatOption; -import net.sourceforge.plantuml.PSystem; -import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.core.Diagram; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UImage; import net.sourceforge.plantuml.ugraphic.UShape; class EmbededSystemLine implements Line { - final List lines; + final private List lines; public EmbededSystemLine(EmbededDiagram sys) { - this.lines = sys.getLines(); + this.lines = sys.getLines().as(); } public Dimension2D calculateDimension(StringBounder stringBounder) { @@ -74,15 +72,11 @@ class EmbededSystemLine implements Line { return new Dimension2DDouble(42, 42); } - public void draw(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { - throw new UnsupportedOperationException(); - } - - public void drawU(UGraphic ug, double x, double y) { + public void drawU(UGraphic ug) { try { final BufferedImage im = getImage(); final UShape image = new UImage(im); - ug.draw(x, y, image); + ug.draw(image); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { @@ -92,9 +86,9 @@ class EmbededSystemLine implements Line { } private BufferedImage getImage() throws IOException, InterruptedException { - final PSystem system = getSystem(); + final Diagram system = getSystem(); final ByteArrayOutputStream os = new ByteArrayOutputStream(); - system.exportDiagram(os, null, 0, new FileFormatOption(FileFormat.PNG)); + system.exportDiagram(os, 0, new FileFormatOption(FileFormat.PNG)); os.close(); final ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray()); final BufferedImage im = ImageIO.read(is); @@ -102,14 +96,13 @@ class EmbededSystemLine implements Line { return im; } - public HorizontalAlignement getHorizontalAlignement() { - return HorizontalAlignement.LEFT; + public HorizontalAlignment getHorizontalAlignment() { + return HorizontalAlignment.LEFT; } - private PSystem getSystem() throws IOException, InterruptedException { + private Diagram getSystem() throws IOException, InterruptedException { final BlockUml blockUml = new BlockUml(lines); - return blockUml.getSystem(); + return blockUml.getDiagram(); } - } diff --git a/src/net/sourceforge/plantuml/graphic/ExposantChange.java b/src/net/sourceforge/plantuml/graphic/ExposantChange.java new file mode 100644 index 000000000..e0e5ad839 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/ExposantChange.java @@ -0,0 +1,48 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 3834 $ + * + */ +package net.sourceforge.plantuml.graphic; + +class ExposantChange implements FontChange { + + private final FontPosition fontPosition; + + ExposantChange(FontPosition fontPosition) { + this.fontPosition = fontPosition; + } + + public FontConfiguration apply(FontConfiguration initial) { + return initial.changeFontPosition(fontPosition); + } + +} diff --git a/src/net/sourceforge/plantuml/graphic/FontChange.java b/src/net/sourceforge/plantuml/graphic/FontChange.java index b75d7b055..1d60b0b0d 100644 --- a/src/net/sourceforge/plantuml/graphic/FontChange.java +++ b/src/net/sourceforge/plantuml/graphic/FontChange.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3834 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graphic; diff --git a/src/net/sourceforge/plantuml/graphic/FontConfiguration.java b/src/net/sourceforge/plantuml/graphic/FontConfiguration.java index 21b7233d2..bfd0cec5e 100644 --- a/src/net/sourceforge/plantuml/graphic/FontConfiguration.java +++ b/src/net/sourceforge/plantuml/graphic/FontConfiguration.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,13 +28,18 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6837 $ + * Revision $Revision: 11799 $ * */ package net.sourceforge.plantuml.graphic; import java.util.EnumSet; +import java.util.Map; +import net.sourceforge.plantuml.FontParam; +import net.sourceforge.plantuml.ISkinParam; +import net.sourceforge.plantuml.SkinParamUtils; +import net.sourceforge.plantuml.cucadiagram.Stereotype; import net.sourceforge.plantuml.ugraphic.UFont; public class FontConfiguration { @@ -45,9 +50,16 @@ public class FontConfiguration { private final HtmlColor motherColor; private final HtmlColor currentColor; private final HtmlColor extendedColor; + private final FontPosition fontPosition; + private final SvgAttributes svgAttributes; public FontConfiguration(UFont font, HtmlColor color) { - this(getStyles(font), font, color, font, color, null); + this(getStyles(font), font, color, font, color, null, FontPosition.NORMAL, new SvgAttributes()); + } + + public FontConfiguration(ISkinParam skinParam, FontParam fontParam, Stereotype stereo) { + this(SkinParamUtils.getFont(skinParam, fontParam, stereo), SkinParamUtils.getFontColor(skinParam, fontParam, + stereo)); } private static EnumSet getStyles(UFont font) { @@ -71,46 +83,80 @@ public class FontConfiguration { } private FontConfiguration(EnumSet styles, UFont motherFont, HtmlColor motherColor, UFont currentFont, - HtmlColor currentColor, HtmlColor extendedColor) { + HtmlColor currentColor, HtmlColor extendedColor, FontPosition fontPosition, SvgAttributes svgAttributes) { this.styles = styles; this.currentFont = currentFont; this.motherFont = motherFont; this.currentColor = currentColor; this.motherColor = motherColor; this.extendedColor = extendedColor; + this.fontPosition = fontPosition; + this.svgAttributes = svgAttributes; } - FontConfiguration changeColor(HtmlColor htmlColor) { - return new FontConfiguration(styles, motherFont, motherColor, currentFont, htmlColor, extendedColor); + FontConfiguration changeAttributes(SvgAttributes toBeAdded) { + return new FontConfiguration(styles, motherFont, motherColor, currentFont, currentColor, extendedColor, + fontPosition, svgAttributes.add(toBeAdded)); + } + + public FontConfiguration changeColor(HtmlColor htmlColor) { + return new FontConfiguration(styles, motherFont, motherColor, currentFont, htmlColor, extendedColor, + fontPosition, svgAttributes); } FontConfiguration changeExtendedColor(HtmlColor newExtendedColor) { - return new FontConfiguration(styles, motherFont, motherColor, currentFont, currentColor, newExtendedColor); + return new FontConfiguration(styles, motherFont, motherColor, currentFont, currentColor, newExtendedColor, + fontPosition, svgAttributes); } - FontConfiguration changeSize(float size) { + public FontConfiguration changeSize(float size) { return new FontConfiguration(styles, motherFont, motherColor, currentFont.deriveSize(size), currentColor, - extendedColor); + extendedColor, fontPosition, svgAttributes); + } + + public FontConfiguration bigger(double delta) { + return changeSize((float) (currentFont.getSize() + delta)); + } + + public FontConfiguration changeFontPosition(FontPosition fontPosition) { + return new FontConfiguration(styles, motherFont, motherColor, currentFont, currentColor, extendedColor, + fontPosition, svgAttributes); + } + + public FontConfiguration changeFamily(String family) { + return new FontConfiguration(styles, motherFont, motherColor, new UFont(family, currentFont.getStyle(), + currentFont.getSize()), currentColor, extendedColor, fontPosition, svgAttributes); } public FontConfiguration resetFont() { - return new FontConfiguration(styles, motherFont, motherColor, motherFont, motherColor, null); + return new FontConfiguration(styles, motherFont, motherColor, motherFont, motherColor, null, + FontPosition.NORMAL, new SvgAttributes()); } FontConfiguration add(FontStyle style) { final EnumSet r = styles.clone(); r.add(style); - return new FontConfiguration(r, motherFont, motherColor, currentFont, currentColor, extendedColor); + return new FontConfiguration(r, motherFont, motherColor, currentFont, currentColor, extendedColor, + fontPosition, svgAttributes); } public FontConfiguration italic() { return add(FontStyle.ITALIC); } + public FontConfiguration bold() { + return add(FontStyle.BOLD); + } + + public FontConfiguration underline() { + return add(FontStyle.UNDERLINE); + } + FontConfiguration remove(FontStyle style) { final EnumSet r = styles.clone(); r.remove(style); - return new FontConfiguration(r, motherFont, motherColor, currentFont, currentColor, extendedColor); + return new FontConfiguration(r, motherFont, motherColor, currentFont, currentColor, extendedColor, + fontPosition, svgAttributes); } public UFont getFont() { @@ -118,7 +164,7 @@ public class FontConfiguration { for (FontStyle style : styles) { result = style.mutateFont(result); } - return result; + return fontPosition.mute(result); } public HtmlColor getColor() { @@ -133,4 +179,12 @@ public class FontConfiguration { return styles.contains(style); } + public int getSpace() { + return fontPosition.getSpace(); + } + + public Map getAttributes() { + return svgAttributes.attributes(); + } + } diff --git a/src/net/sourceforge/plantuml/graphic/FontFamilyChange.java b/src/net/sourceforge/plantuml/graphic/FontFamilyChange.java new file mode 100644 index 000000000..0d1e6f262 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/FontFamilyChange.java @@ -0,0 +1,57 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 3834 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +class FontFamilyChange implements FontChange { + + static private final Pattern colorPattern = Pattern.compile("(?i)" + Splitter.fontFamilyPattern); + + private final String family; + + FontFamilyChange(String s) { + final Matcher matcherColor = colorPattern.matcher(s); + if (matcherColor.find() == false) { + throw new IllegalArgumentException(); + } + this.family = matcherColor.group(1).trim(); + } + + public FontConfiguration apply(FontConfiguration initial) { + return initial.changeFamily(family); + } + +} diff --git a/src/net/sourceforge/plantuml/graphic/FontPosition.java b/src/net/sourceforge/plantuml/graphic/FontPosition.java new file mode 100644 index 000000000..3456eb97a --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/FontPosition.java @@ -0,0 +1,72 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7951 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import net.sourceforge.plantuml.ugraphic.UFont; + +public enum FontPosition { + NORMAL, EXPOSANT, INDICE; + + public int getSpace() { + if (this == EXPOSANT) { + return -6; + } + if (this == INDICE) { + return 3; + } + return 0; + } + + public UFont mute(UFont font) { + if (this == NORMAL) { + return font; + } + int size = font.getSize() - 3; + if (size < 2) { + size = 2; + } + return font.deriveSize((float) size); + } + + public String getHtmlTag() { + if (this == EXPOSANT) { + return "sup"; + } + if (this == INDICE) { + return "sub"; + } + throw new UnsupportedOperationException(); + } + +} diff --git a/src/net/sourceforge/plantuml/graphic/FontStyle.java b/src/net/sourceforge/plantuml/graphic/FontStyle.java index 397cc62c0..502c42902 100644 --- a/src/net/sourceforge/plantuml/graphic/FontStyle.java +++ b/src/net/sourceforge/plantuml/graphic/FontStyle.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6590 $ + * Revision $Revision: 11838 $ * */ package net.sourceforge.plantuml.graphic; @@ -74,15 +74,51 @@ public enum FontStyle { } return null; } + + public boolean canHaveExtendedColor() { + if (this == UNDERLINE) { + return true; + } + if (this == WAVE) { + return true; + } + if (this == BACKCOLOR) { + return true; + } + if (this == STRIKE) { + return true; + } + return false; + } - HtmlColor getExtendedColor(String s) { + + public String getCreoleSyntax() { + if (this == ITALIC) { + return "//"; + } + if (this == BOLD) { + return "\\*\\*"; + } + if (this == UNDERLINE) { + return "__"; + } + if (this == WAVE) { + return "~~"; + } + if (this == STRIKE) { + return "--"; + } + throw new UnsupportedOperationException(); + } + + public HtmlColor getExtendedColor(String s) { final Matcher m = Pattern.compile(getActivationPattern()).matcher(s); if (m.find() == false || m.groupCount() != 1) { return null; } final String color = m.group(1); - if (color!= null && HtmlColor.isValid(color)) { - return HtmlColor.getColorIfValid(color); + if (HtmlColorUtils.getColorIfValid(color) != null) { + return HtmlColorUtils.getColorIfValid(color); } return null; } @@ -121,4 +157,5 @@ public enum FontStyle { throw new IllegalArgumentException(line); } + } diff --git a/src/net/sourceforge/plantuml/graphic/GraphicPosition.java b/src/net/sourceforge/plantuml/graphic/GraphicPosition.java index 47ab343dc..219e4e68d 100644 --- a/src/net/sourceforge/plantuml/graphic/GraphicPosition.java +++ b/src/net/sourceforge/plantuml/graphic/GraphicPosition.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/graphic/GraphicStrings.java b/src/net/sourceforge/plantuml/graphic/GraphicStrings.java index 65c8400dc..1b8bc4405 100644 --- a/src/net/sourceforge/plantuml/graphic/GraphicStrings.java +++ b/src/net/sourceforge/plantuml/graphic/GraphicStrings.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,14 +28,13 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 7144 $ + * Revision $Revision: 11914 $ * */ package net.sourceforge.plantuml.graphic; import java.awt.Font; import java.awt.Graphics2D; -import java.awt.RenderingHints; import java.awt.geom.Dimension2D; import java.awt.image.BufferedImage; import java.io.IOException; @@ -47,17 +46,22 @@ import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.EmptyImageBuilder; import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.SpriteContainerEmpty; import net.sourceforge.plantuml.StringUtils; -import net.sourceforge.plantuml.directdot.DotText; +import net.sourceforge.plantuml.api.ImageDataSimple; +import net.sourceforge.plantuml.core.ImageData; +import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.eps.EpsStrategy; import net.sourceforge.plantuml.png.PngIO; import net.sourceforge.plantuml.svek.IEntityImage; import net.sourceforge.plantuml.svek.ShapeType; import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.ColorMapperIdentity; +import net.sourceforge.plantuml.ugraphic.UAntiAliasing; import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UImage; +import net.sourceforge.plantuml.ugraphic.UTranslate; import net.sourceforge.plantuml.ugraphic.eps.UGraphicEps; import net.sourceforge.plantuml.ugraphic.g2d.UGraphicG2d; import net.sourceforge.plantuml.ugraphic.svg.UGraphicSvg; @@ -77,112 +81,148 @@ public class GraphicStrings implements IEntityImage { private final GraphicPosition position; - private final boolean disableTextAliasing; + private final UAntiAliasing antiAliasing; private final ColorMapper colorMapper = new ColorMapperIdentity(); public GraphicStrings(List strings) { - this(strings, new UFont("SansSerif", Font.BOLD, 14), HtmlColor.getColorIfValid("#33FF02"), HtmlColor.BLACK, - null, null, false); + this(strings, new UFont("SansSerif", Font.BOLD, 14), HtmlColorUtils.getColorIfValid("#33FF02"), + HtmlColorUtils.BLACK, null, null, UAntiAliasing.ANTI_ALIASING_ON); } public GraphicStrings(List strings, BufferedImage image) { - this(strings, new UFont("SansSerif", Font.BOLD, 14), HtmlColor.getColorIfValid("#33FF02"), HtmlColor.BLACK, - image, null, false); + this(strings, new UFont("SansSerif", Font.BOLD, 14), HtmlColorUtils.getColorIfValid("#33FF02"), + HtmlColorUtils.BLACK, image, null, UAntiAliasing.ANTI_ALIASING_ON); } public GraphicStrings(List strings, UFont font, HtmlColor green, HtmlColor background, - boolean disableTextAliasing) { - this(strings, font, green, background, null, null, disableTextAliasing); + UAntiAliasing antiAliasing) { + this(strings, font, green, background, null, null, antiAliasing); } public GraphicStrings(List strings, UFont font, HtmlColor green, HtmlColor background, BufferedImage image, - GraphicPosition position, boolean disableTextAliasing) { + GraphicPosition position, UAntiAliasing antiAliasing) { this.strings = strings; this.font = font; this.green = green; this.background = background; this.image = image; this.position = position; - this.disableTextAliasing = disableTextAliasing; + this.antiAliasing = antiAliasing; } - public void writeImage(OutputStream os, FileFormatOption fileFormat) throws IOException { - writeImage(os, null, fileFormat); - } - - public void writeImage(OutputStream os, String metadata, FileFormatOption fileFormatOption) throws IOException { + public void writeImage(OutputStream os, FileFormatOption fileFormatOption, String debugData) throws IOException { final FileFormat fileFormat = fileFormatOption.getFileFormat(); if (fileFormat == FileFormat.PNG) { final BufferedImage im = createImage(); - PngIO.write(im, os, metadata, 96); + PngIO.write(im, os, null, 96, debugData); } else if (fileFormat == FileFormat.SVG) { final UGraphicSvg svg = new UGraphicSvg(colorMapper, StringUtils.getAsHtml(colorMapper - .getMappedColor(background)), false); - drawU(svg); + .getMappedColor(background)), false, 1.0); + drawAndGetSize(svg); svg.createXml(os); } else if (fileFormat == FileFormat.ATXT || fileFormat == FileFormat.UTXT) { final UGraphicTxt txt = new UGraphicTxt(); - drawU(txt); + drawAndGetSize(txt); txt.getCharArea().print(new PrintStream(os)); } else if (fileFormat == FileFormat.EPS) { final UGraphicEps ug = new UGraphicEps(colorMapper, EpsStrategy.getDefault2()); - drawU(ug); + drawAndGetSize(ug); os.write(ug.getEPSCode().getBytes()); - } else if (fileFormat == FileFormat.DOT) { - final DotText dotText = new DotText(strings, HtmlColor.getColorIfValid("#33FF02"), HtmlColor.BLACK); - final StringBuilder sb = new StringBuilder(); - dotText.generateDot(sb); - os.write(sb.toString().getBytes()); } else { throw new UnsupportedOperationException(); } } + public ImageData exportDiagram(OutputStream os, FileFormatOption fileFormatOption) throws IOException { + return exportDiagram(os, null, fileFormatOption); + } + + public ImageData exportDiagram(OutputStream os, String metadata, FileFormatOption fileFormatOption) + throws IOException { + final FileFormat fileFormat = fileFormatOption.getFileFormat(); + if (fileFormat == FileFormat.PNG) { + final BufferedImage im = createImage(); + PngIO.write(im, os, fileFormatOption.isWithMetadata() ? metadata : null, 96); + } else if (fileFormat == FileFormat.SVG) { + final UGraphicSvg svg = new UGraphicSvg(colorMapper, StringUtils.getAsHtml(colorMapper + .getMappedColor(background)), false, 1.0); + drawAndGetSize(svg); + svg.createXml(os); + } else if (fileFormat == FileFormat.ATXT || fileFormat == FileFormat.UTXT) { + final UGraphicTxt txt = new UGraphicTxt(); + drawAndGetSize(txt); + txt.getCharArea().print(new PrintStream(os)); + } else if (fileFormat == FileFormat.EPS) { + final UGraphicEps ug = new UGraphicEps(colorMapper, EpsStrategy.getDefault2()); + drawAndGetSize(ug); + os.write(ug.getEPSCode().getBytes()); + } else { + throw new UnsupportedOperationException(); + } + return new ImageDataSimple(); + } + private BufferedImage createImage() { EmptyImageBuilder builder = new EmptyImageBuilder(10, 10, colorMapper.getMappedColor(background)); - // BufferedImage im = builder.getBufferedImage(); Graphics2D g2d = builder.getGraphics2D(); - final Dimension2D size = drawU(new UGraphicG2d(colorMapper, g2d, null, 1.0)); + final Dimension2D size = drawAndGetSize(new UGraphicG2d(colorMapper, g2d, 1.0)); g2d.dispose(); builder = new EmptyImageBuilder(size.getWidth(), size.getHeight(), colorMapper.getMappedColor(background)); final BufferedImage im = builder.getBufferedImage(); g2d = builder.getGraphics2D(); - if (disableTextAliasing) { - g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); - } - drawU(new UGraphicG2d(colorMapper, g2d, null, 1.0)); + drawAndGetSize(new UGraphicG2d(colorMapper, g2d, 1.0).apply(antiAliasing)); g2d.dispose(); return im; } - public Dimension2D drawU(final UGraphic ug) { - final TextBlock textBlock = TextBlockUtils.create(strings, new FontConfiguration(font, green), - HorizontalAlignement.LEFT); - Dimension2D size = textBlock.calculateDimension(ug.getStringBounder()); - textBlock.drawU(ug, 0, 0); + private double minWidth; + + public void setMinWidth(double minWidth) { + this.minWidth = minWidth; + } + + private Dimension2D getSizeWithMin(Dimension2D dim) { + if (minWidth == 0) { + return dim; + } + if (dim.getWidth() < minWidth) { + return new Dimension2DDouble(minWidth, dim.getHeight()); + } + return dim; + } + + private Dimension2D drawAndGetSize(final UGraphic ug) { + TextBlock textBlock = TextBlockUtils.create(new Display(strings), new FontConfiguration(font, green), + HorizontalAlignment.LEFT, new SpriteContainerEmpty()); + textBlock = DateEventUtils.addEvent(textBlock, green); + + Dimension2D size = getSizeWithMin(textBlock.calculateDimension(ug.getStringBounder())); + textBlock.drawU(ug); if (image != null) { if (position == GraphicPosition.BOTTOM) { - ug.draw((size.getWidth() - image.getWidth()) / 2, size.getHeight(), new UImage(image)); + ug.apply(new UTranslate((size.getWidth() - image.getWidth()) / 2, size.getHeight())).draw( + new UImage(image)); size = new Dimension2DDouble(size.getWidth(), size.getHeight() + image.getHeight()); } else if (position == GraphicPosition.BACKGROUND_CORNER) { - ug.draw(size.getWidth() - image.getWidth(), size.getHeight() - image.getHeight(), new UImage(image)); + ug.apply(new UTranslate(size.getWidth() - image.getWidth(), size.getHeight() - image.getHeight())) + .draw(new UImage(image)); } } return size; } - public void drawU(UGraphic ug, double theoricalPosition, double theoricalPosition2) { - drawU(ug); + public void drawU(UGraphic ug) { + drawAndGetSize(ug); } - public Dimension2D getDimension(StringBounder stringBounder) { - final TextBlock textBlock = TextBlockUtils.create(strings, new FontConfiguration(font, green), - HorizontalAlignement.LEFT); - return textBlock.calculateDimension(stringBounder); + public Dimension2D calculateDimension(StringBounder stringBounder) { + final TextBlock textBlock = TextBlockUtils.create(new Display(strings), new FontConfiguration(font, green), + HorizontalAlignment.LEFT, new SpriteContainerEmpty()); + return getSizeWithMin(textBlock.calculateDimension(stringBounder)); } public ShapeType getShapeType() { @@ -197,4 +237,8 @@ public class GraphicStrings implements IEntityImage { return 0; } + public boolean isHidden() { + return false; + } + } diff --git a/src/net/sourceforge/plantuml/graphic/HorizontalAlignement.java b/src/net/sourceforge/plantuml/graphic/HorizontalAlignment.java similarity index 85% rename from src/net/sourceforge/plantuml/graphic/HorizontalAlignement.java rename to src/net/sourceforge/plantuml/graphic/HorizontalAlignment.java index 3715c4d28..c7e50ba29 100644 --- a/src/net/sourceforge/plantuml/graphic/HorizontalAlignement.java +++ b/src/net/sourceforge/plantuml/graphic/HorizontalAlignment.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,16 +28,16 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6557 $ + * Revision $Revision: 11153 $ * */ package net.sourceforge.plantuml.graphic; -public enum HorizontalAlignement { +public enum HorizontalAlignment { LEFT, CENTER, RIGHT; - public static HorizontalAlignement fromString(String s) { + public static HorizontalAlignment fromString(String s) { if (LEFT.name().equalsIgnoreCase(s)) { return LEFT; } diff --git a/src/net/sourceforge/plantuml/graphic/HtmlColor.java b/src/net/sourceforge/plantuml/graphic/HtmlColor.java index 09ed9e091..1150ca6fe 100644 --- a/src/net/sourceforge/plantuml/graphic/HtmlColor.java +++ b/src/net/sourceforge/plantuml/graphic/HtmlColor.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,254 +28,13 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6983 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graphic; -import java.awt.Color; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; -import net.sourceforge.plantuml.ugraphic.ColorChangerMonochrome; +public interface HtmlColor { -public class HtmlColor { - private static final Map htmlNames; - private static final Set names; - - static { - // Taken from http://perl.wikipedia.com/wiki/Named_colors ? - htmlNames = new HashMap(); - names = new TreeSet(); - register("AliceBlue", "#F0F8FF"); - register("AntiqueWhite", "#FAEBD7"); - register("Aqua", "#00FFFF"); - register("Aquamarine", "#7FFFD4"); - register("Azure", "#F0FFFF"); - register("Beige", "#F5F5DC"); - register("Bisque", "#FFE4C4"); - register("Black", "#000000"); - register("BlanchedAlmond", "#FFEBCD"); - register("Blue", "#0000FF"); - register("BlueViolet", "#8A2BE2"); - register("Brown", "#A52A2A"); - register("BurlyWood", "#DEB887"); - register("CadetBlue", "#5F9EA0"); - register("Chartreuse", "#7FFF00"); - register("Chocolate", "#D2691E"); - register("Coral", "#FF7F50"); - register("CornflowerBlue", "#6495ED"); - register("Cornsilk", "#FFF8DC"); - register("Crimson", "#DC143C"); - register("Cyan", "#00FFFF"); - register("DarkBlue", "#00008B"); - register("DarkCyan", "#008B8B"); - register("DarkGoldenRod", "#B8860B"); - register("DarkGray", "#A9A9A9"); - register("DarkGrey", "#A9A9A9"); - register("DarkGreen", "#006400"); - register("DarkKhaki", "#BDB76B"); - register("DarkMagenta", "#8B008B"); - register("DarkOliveGreen", "#556B2F"); - register("Darkorange", "#FF8C00"); - register("DarkOrchid", "#9932CC"); - register("DarkRed", "#8B0000"); - register("DarkSalmon", "#E9967A"); - register("DarkSeaGreen", "#8FBC8F"); - register("DarkSlateBlue", "#483D8B"); - register("DarkSlateGray", "#2F4F4F"); - register("DarkSlateGrey", "#2F4F4F"); - register("DarkTurquoise", "#00CED1"); - register("DarkViolet", "#9400D3"); - register("DeepPink", "#FF1493"); - register("DeepSkyBlue", "#00BFFF"); - register("DimGray", "#696969"); - register("DimGrey", "#696969"); - register("DodgerBlue", "#1E90FF"); - register("FireBrick", "#B22222"); - register("FloralWhite", "#FFFAF0"); - register("ForestGreen", "#228B22"); - register("Fuchsia", "#FF00FF"); - register("Gainsboro", "#DCDCDC"); - register("GhostWhite", "#F8F8FF"); - register("Gold", "#FFD700"); - register("GoldenRod", "#DAA520"); - register("Gray", "#808080"); - register("Grey", "#808080"); - register("Green", "#008000"); - register("GreenYellow", "#ADFF2F"); - register("HoneyDew", "#F0FFF0"); - register("HotPink", "#FF69B4"); - register("IndianRed", "#CD5C5C"); - register("Indigo", "#4B0082"); - register("Ivory", "#FFFFF0"); - register("Khaki", "#F0E68C"); - register("Lavender", "#E6E6FA"); - register("LavenderBlush", "#FFF0F5"); - register("LawnGreen", "#7CFC00"); - register("LemonChiffon", "#FFFACD"); - register("LightBlue", "#ADD8E6"); - register("LightCoral", "#F08080"); - register("LightCyan", "#E0FFFF"); - register("LightGoldenRodYellow", "#FAFAD2"); - register("LightGray", "#D3D3D3"); - register("LightGrey", "#D3D3D3"); - register("LightGreen", "#90EE90"); - register("LightPink", "#FFB6C1"); - register("LightSalmon", "#FFA07A"); - register("LightSeaGreen", "#20B2AA"); - register("LightSkyBlue", "#87CEFA"); - register("LightSlateGray", "#778899"); - register("LightSlateGrey", "#778899"); - register("LightSteelBlue", "#B0C4DE"); - register("LightYellow", "#FFFFE0"); - register("Lime", "#00FF00"); - register("LimeGreen", "#32CD32"); - register("Linen", "#FAF0E6"); - register("Magenta", "#FF00FF"); - register("Maroon", "#800000"); - register("MediumAquaMarine", "#66CDAA"); - register("MediumBlue", "#0000CD"); - register("MediumOrchid", "#BA55D3"); - register("MediumPurple", "#9370D8"); - register("MediumSeaGreen", "#3CB371"); - register("MediumSlateBlue", "#7B68EE"); - register("MediumSpringGreen", "#00FA9A"); - register("MediumTurquoise", "#48D1CC"); - register("MediumVioletRed", "#C71585"); - register("MidnightBlue", "#191970"); - register("MintCream", "#F5FFFA"); - register("MistyRose", "#FFE4E1"); - register("Moccasin", "#FFE4B5"); - register("NavajoWhite", "#FFDEAD"); - register("Navy", "#000080"); - register("OldLace", "#FDF5E6"); - register("Olive", "#808000"); - register("OliveDrab", "#6B8E23"); - register("Orange", "#FFA500"); - register("OrangeRed", "#FF4500"); - register("Orchid", "#DA70D6"); - register("PaleGoldenRod", "#EEE8AA"); - register("PaleGreen", "#98FB98"); - register("PaleTurquoise", "#AFEEEE"); - register("PaleVioletRed", "#D87093"); - register("PapayaWhip", "#FFEFD5"); - register("PeachPuff", "#FFDAB9"); - register("Peru", "#CD853F"); - register("Pink", "#FFC0CB"); - register("Plum", "#DDA0DD"); - register("PowderBlue", "#B0E0E6"); - register("Purple", "#800080"); - register("Red", "#FF0000"); - register("RosyBrown", "#BC8F8F"); - register("RoyalBlue", "#4169E1"); - register("SaddleBrown", "#8B4513"); - register("Salmon", "#FA8072"); - register("SandyBrown", "#F4A460"); - register("SeaGreen", "#2E8B57"); - register("SeaShell", "#FFF5EE"); - register("Sienna", "#A0522D"); - register("Silver", "#C0C0C0"); - register("SkyBlue", "#87CEEB"); - register("SlateBlue", "#6A5ACD"); - register("SlateGray", "#708090"); - register("SlateGrey", "#708090"); - register("Snow", "#FFFAFA"); - register("SpringGreen", "#00FF7F"); - register("SteelBlue", "#4682B4"); - register("Tan", "#D2B48C"); - register("Teal", "#008080"); - register("Thistle", "#D8BFD8"); - register("Tomato", "#FF6347"); - register("Turquoise", "#40E0D0"); - register("Violet", "#EE82EE"); - register("Wheat", "#F5DEB3"); - register("White", "#FFFFFF"); - register("WhiteSmoke", "#F5F5F5"); - register("Yellow", "#FFFF00"); - register("YellowGreen", "#9ACD32"); - } - - private static void register(String s, String color) { - htmlNames.put(s.toLowerCase(), color); - names.add(s); - } - - private final Color color; - private final boolean monochrome; - - public static final HtmlColor BLACK = HtmlColor.getColorIfValid("black"); - public static final HtmlColor WHITE = HtmlColor.getColorIfValid("white"); - public static final HtmlColor RED = HtmlColor.getColorIfValid("#FF0000"); - public static final HtmlColor GREEN = HtmlColor.getColorIfValid("#00FF00"); - public static final HtmlColor BLUE = HtmlColor.getColorIfValid("#0000FF"); - public static final HtmlColor GRAY = HtmlColor.getColorIfValid("#808080"); - public static final HtmlColor LIGHT_GRAY = HtmlColor.getColorIfValid("#C0C0C0"); - - private HtmlColor(String s) { - if (s.matches("#[0-9A-Fa-f]{6}")) { - color = new Color(Integer.parseInt(s.substring(1), 16)); - } else { - s = removeFirstDieseAndToLowercase(s); - final String value = htmlNames.get(s); - if (value == null) { - throw new IllegalArgumentException(s); - } - color = new Color(Integer.parseInt(value.substring(1), 16)); - } - monochrome = false; - assert isValid(s); - } - - private HtmlColor(Color c, boolean monochrome) { - this.color = c; - this.monochrome = monochrome; - } - - static public boolean isValid(String s) { - if (s.matches("#[0-9A-Fa-f]{6}")) { - return true; - } - s = removeFirstDieseAndToLowercase(s); - if (htmlNames.containsKey(s)) { - return true; - } - return false; - - } - - static public HtmlColor getColorIfValid(String s) { - if (s == null || isValid(s) == false) { - return null; - } - return new HtmlColor(s); - } - - static private String removeFirstDieseAndToLowercase(String s) { - s = s.toLowerCase(); - if (s.startsWith("#")) { - s = s.substring(1); - } - return s; - } - - public Color getColor999() { - return color; - } - - public HtmlColor asMonochrome() { - if (monochrome) { - throw new IllegalStateException(); - } - return new HtmlColor(new ColorChangerMonochrome().getChangedColor(color), true); - } - - public static Collection names() { - return Collections.unmodifiableSet(names); - } } diff --git a/src/net/sourceforge/plantuml/ugraphic/UGradient.java b/src/net/sourceforge/plantuml/graphic/HtmlColorGradient.java similarity index 82% rename from src/net/sourceforge/plantuml/ugraphic/UGradient.java rename to src/net/sourceforge/plantuml/graphic/HtmlColorGradient.java index 59a36a4e4..0d6c7eb0d 100644 --- a/src/net/sourceforge/plantuml/ugraphic/UGradient.java +++ b/src/net/sourceforge/plantuml/graphic/HtmlColorGradient.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -29,23 +29,25 @@ * Original Author: Arnaud Roques * */ -package net.sourceforge.plantuml.ugraphic; +package net.sourceforge.plantuml.graphic; import java.awt.Color; -import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.ugraphic.ColorMapper; -public class UGradient { +public class HtmlColorGradient implements HtmlColor { private final HtmlColor color1; private final HtmlColor color2; + private final char policy; - public UGradient(HtmlColor color1, HtmlColor color2) { + public HtmlColorGradient(HtmlColor color1, HtmlColor color2, char policy) { if (color1 == null || color2 == null) { throw new IllegalArgumentException(); } this.color1 = color1; this.color2 = color2; + this.policy = policy; } public final HtmlColor getColor1() { @@ -74,4 +76,8 @@ public class UGradient { } + public final char getPolicy() { + return policy; + } + } diff --git a/src/net/sourceforge/plantuml/graphic/HtmlColorSimple.java b/src/net/sourceforge/plantuml/graphic/HtmlColorSimple.java new file mode 100644 index 000000000..8b60b4833 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/HtmlColorSimple.java @@ -0,0 +1,77 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7946 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.Color; + +import net.sourceforge.plantuml.ugraphic.ColorChangerMonochrome; + +public class HtmlColorSimple implements HtmlColor { + + + private final Color color; + private final boolean monochrome; + + @Override + public int hashCode() { + return color.hashCode(); + } + + @Override + public boolean equals(Object other) { + if (other instanceof HtmlColorSimple == false) { + return false; + } + return this.color.equals(((HtmlColorSimple) other).color); + } + + + HtmlColorSimple(Color c, boolean monochrome) { + this.color = c; + this.monochrome = monochrome; + } + + + public Color getColor999() { + return color; + } + + public HtmlColorSimple asMonochrome() { + if (monochrome) { + throw new IllegalStateException(); + } + return new HtmlColorSimple(new ColorChangerMonochrome().getChangedColor(color), true); + } + +} diff --git a/src/net/sourceforge/plantuml/graphic/HtmlColorTransparent.java b/src/net/sourceforge/plantuml/graphic/HtmlColorTransparent.java new file mode 100644 index 000000000..5abd420cb --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/HtmlColorTransparent.java @@ -0,0 +1,36 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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.graphic; + +public class HtmlColorTransparent implements HtmlColor { + +} diff --git a/src/net/sourceforge/plantuml/graphic/HtmlColorUtils.java b/src/net/sourceforge/plantuml/graphic/HtmlColorUtils.java new file mode 100644 index 000000000..4495381b6 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/HtmlColorUtils.java @@ -0,0 +1,290 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7946 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.Color; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class HtmlColorUtils { + + private static final Map htmlNames; + private static final Set names; + + static { + // Taken from http://perl.wikipedia.com/wiki/Named_colors ? + // http://www.w3schools.com/HTML/html_colornames.asp + htmlNames = new HashMap(); + names = new TreeSet(); + register("AliceBlue", "#F0F8FF"); + register("AntiqueWhite", "#FAEBD7"); + register("Aqua", "#00FFFF"); + register("Aquamarine", "#7FFFD4"); + register("Azure", "#F0FFFF"); + register("Beige", "#F5F5DC"); + register("Bisque", "#FFE4C4"); + register("Black", "#000000"); + register("BlanchedAlmond", "#FFEBCD"); + register("Blue", "#0000FF"); + register("BlueViolet", "#8A2BE2"); + register("Brown", "#A52A2A"); + register("BurlyWood", "#DEB887"); + register("CadetBlue", "#5F9EA0"); + register("Chartreuse", "#7FFF00"); + register("Chocolate", "#D2691E"); + register("Coral", "#FF7F50"); + register("CornflowerBlue", "#6495ED"); + register("Cornsilk", "#FFF8DC"); + register("Crimson", "#DC143C"); + register("Cyan", "#00FFFF"); + register("DarkBlue", "#00008B"); + register("DarkCyan", "#008B8B"); + register("DarkGoldenRod", "#B8860B"); + register("DarkGray", "#A9A9A9"); + register("DarkGrey", "#A9A9A9"); + register("DarkGreen", "#006400"); + register("DarkKhaki", "#BDB76B"); + register("DarkMagenta", "#8B008B"); + register("DarkOliveGreen", "#556B2F"); + register("Darkorange", "#FF8C00"); + register("DarkOrchid", "#9932CC"); + register("DarkRed", "#8B0000"); + register("DarkSalmon", "#E9967A"); + register("DarkSeaGreen", "#8FBC8F"); + register("DarkSlateBlue", "#483D8B"); + register("DarkSlateGray", "#2F4F4F"); + register("DarkSlateGrey", "#2F4F4F"); + register("DarkTurquoise", "#00CED1"); + register("DarkViolet", "#9400D3"); + register("DeepPink", "#FF1493"); + register("DeepSkyBlue", "#00BFFF"); + register("DimGray", "#696969"); + register("DimGrey", "#696969"); + register("DodgerBlue", "#1E90FF"); + register("FireBrick", "#B22222"); + register("FloralWhite", "#FFFAF0"); + register("ForestGreen", "#228B22"); + register("Fuchsia", "#FF00FF"); + register("Gainsboro", "#DCDCDC"); + register("GhostWhite", "#F8F8FF"); + register("Gold", "#FFD700"); + register("GoldenRod", "#DAA520"); + register("Gray", "#808080"); + register("Grey", "#808080"); + register("Green", "#008000"); + register("GreenYellow", "#ADFF2F"); + register("HoneyDew", "#F0FFF0"); + register("HotPink", "#FF69B4"); + register("IndianRed", "#CD5C5C"); + register("Indigo", "#4B0082"); + register("Ivory", "#FFFFF0"); + register("Khaki", "#F0E68C"); + register("Lavender", "#E6E6FA"); + register("LavenderBlush", "#FFF0F5"); + register("LawnGreen", "#7CFC00"); + register("LemonChiffon", "#FFFACD"); + register("LightBlue", "#ADD8E6"); + register("LightCoral", "#F08080"); + register("LightCyan", "#E0FFFF"); + register("LightGoldenRodYellow", "#FAFAD2"); + register("LightGray", "#D3D3D3"); + register("LightGrey", "#D3D3D3"); + register("LightGreen", "#90EE90"); + register("LightPink", "#FFB6C1"); + register("LightSalmon", "#FFA07A"); + register("LightSeaGreen", "#20B2AA"); + register("LightSkyBlue", "#87CEFA"); + register("LightSlateGray", "#778899"); + register("LightSlateGrey", "#778899"); + register("LightSteelBlue", "#B0C4DE"); + register("LightYellow", "#FFFFE0"); + register("Lime", "#00FF00"); + register("LimeGreen", "#32CD32"); + register("Linen", "#FAF0E6"); + register("Magenta", "#FF00FF"); + register("Maroon", "#800000"); + register("MediumAquaMarine", "#66CDAA"); + register("MediumBlue", "#0000CD"); + register("MediumOrchid", "#BA55D3"); + register("MediumPurple", "#9370D8"); + register("MediumSeaGreen", "#3CB371"); + register("MediumSlateBlue", "#7B68EE"); + register("MediumSpringGreen", "#00FA9A"); + register("MediumTurquoise", "#48D1CC"); + register("MediumVioletRed", "#C71585"); + register("MidnightBlue", "#191970"); + register("MintCream", "#F5FFFA"); + register("MistyRose", "#FFE4E1"); + register("Moccasin", "#FFE4B5"); + register("NavajoWhite", "#FFDEAD"); + register("Navy", "#000080"); + register("OldLace", "#FDF5E6"); + register("Olive", "#808000"); + register("OliveDrab", "#6B8E23"); + register("Orange", "#FFA500"); + register("OrangeRed", "#FF4500"); + register("Orchid", "#DA70D6"); + register("PaleGoldenRod", "#EEE8AA"); + register("PaleGreen", "#98FB98"); + register("PaleTurquoise", "#AFEEEE"); + register("PaleVioletRed", "#D87093"); + register("PapayaWhip", "#FFEFD5"); + register("PeachPuff", "#FFDAB9"); + register("Peru", "#CD853F"); + register("Pink", "#FFC0CB"); + register("Plum", "#DDA0DD"); + register("PowderBlue", "#B0E0E6"); + register("Purple", "#800080"); + register("Red", "#FF0000"); + register("RosyBrown", "#BC8F8F"); + register("RoyalBlue", "#4169E1"); + register("SaddleBrown", "#8B4513"); + register("Salmon", "#FA8072"); + register("SandyBrown", "#F4A460"); + register("SeaGreen", "#2E8B57"); + register("SeaShell", "#FFF5EE"); + register("Sienna", "#A0522D"); + register("Silver", "#C0C0C0"); + register("SkyBlue", "#87CEEB"); + register("SlateBlue", "#6A5ACD"); + register("SlateGray", "#708090"); + register("SlateGrey", "#708090"); + register("Snow", "#FFFAFA"); + register("SpringGreen", "#00FF7F"); + register("SteelBlue", "#4682B4"); + register("Tan", "#D2B48C"); + register("Teal", "#008080"); + register("Thistle", "#D8BFD8"); + register("Tomato", "#FF6347"); + register("Turquoise", "#40E0D0"); + register("Violet", "#EE82EE"); + register("Wheat", "#F5DEB3"); + register("White", "#FFFFFF"); + register("WhiteSmoke", "#F5F5F5"); + register("Yellow", "#FFFF00"); + register("YellowGreen", "#9ACD32"); + } + + private static void register(String s, String color) { + htmlNames.put(s.toLowerCase(), color); + names.add(s); + } + + public static final HtmlColor BLACK = HtmlColorUtils.getColorIfValid("black"); + public static final HtmlColor WHITE = HtmlColorUtils.getColorIfValid("white"); + public static final HtmlColor RED = HtmlColorUtils.getColorIfValid("#FF0000"); + public static final HtmlColor GREEN = HtmlColorUtils.getColorIfValid("#00FF00"); + public static final HtmlColor BLUE = HtmlColorUtils.getColorIfValid("#0000FF"); + public static final HtmlColor GRAY = HtmlColorUtils.getColorIfValid("#808080"); + public static final HtmlColor LIGHT_GRAY = HtmlColorUtils.getColorIfValid("#C0C0C0"); + public static final HtmlColor TRANSPARENT = new HtmlColorTransparent(); + + private static HtmlColor build(String s) { + + s = removeFirstDieseAndToLowercase(s); + final Color color; + if (s.equalsIgnoreCase("transparent")) { + return TRANSPARENT; + } else if (s.matches("[0-9A-Fa-f]{6}")) { + color = new Color(Integer.parseInt(s, 16)); + } else { + final String value = htmlNames.get(s); + if (value == null) { + throw new IllegalArgumentException(s); + } + color = new Color(Integer.parseInt(value.substring(1), 16)); + } + return new HtmlColorSimple(color, false); + } + + static private boolean isValid(String s, boolean acceptTransparent) { + s = removeFirstDieseAndToLowercase(s); + if (s.matches("[0-9A-Fa-f]{6}")) { + return true; + } + if (acceptTransparent && s.equalsIgnoreCase("transparent")) { + return true; + } + if (htmlNames.containsKey(s)) { + return true; + } + return false; + + } + + static public HtmlColor getColorIfValid(String s) { + return getColorIfValid(s, false); + } + + static public HtmlColor getColorIfValid(String s, boolean acceptTransparent) { + if (s == null) { + return null; + } + final Matcher m = Pattern.compile("[-\\\\|/]").matcher(s); + if (m.find()) { + final char sep = m.group(0).charAt(0); + final int idx = s.indexOf(sep); + final String s1 = s.substring(0, idx); + final String s2 = s.substring(idx + 1); + if (isValid(s1, false) == false || isValid(s2, false) == false) { + return null; + } + return new HtmlColorGradient(build(s1), build(s2), sep); + // return getColorIfValid(s2); + } + if (isValid(s, acceptTransparent) == false) { + return null; + } + return build(s); + } + + static private String removeFirstDieseAndToLowercase(String s) { + s = s.toLowerCase(); + if (s.startsWith("#")) { + s = s.substring(1); + } + return s; + } + + public static Collection names() { + return Collections.unmodifiableSet(names); + } + +} diff --git a/src/net/sourceforge/plantuml/graphic/HtmlCommand.java b/src/net/sourceforge/plantuml/graphic/HtmlCommand.java index 90154ed82..4e51b2d1f 100644 --- a/src/net/sourceforge/plantuml/graphic/HtmlCommand.java +++ b/src/net/sourceforge/plantuml/graphic/HtmlCommand.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3834 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graphic; diff --git a/src/net/sourceforge/plantuml/graphic/HtmlCommandFactory.java b/src/net/sourceforge/plantuml/graphic/HtmlCommandFactory.java index d3166bf28..5f54a806a 100644 --- a/src/net/sourceforge/plantuml/graphic/HtmlCommandFactory.java +++ b/src/net/sourceforge/plantuml/graphic/HtmlCommandFactory.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5506 $ + * Revision $Revision: 11337 $ * */ package net.sourceforge.plantuml.graphic; @@ -36,6 +36,10 @@ package net.sourceforge.plantuml.graphic; import java.util.EnumSet; import java.util.regex.Pattern; +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.UrlBuilder; +import net.sourceforge.plantuml.UrlBuilder.ModeUrl; + class HtmlCommandFactory { static final Pattern addStyle; @@ -68,15 +72,14 @@ class HtmlCommandFactory { return new Text(s); } if (s.matches(Splitter.imgPattern)) { - return Img.getInstance(s); + return Img.getInstance(s, true); } - - if (s.matches(Splitter.imgPattern2)) { - return Img.getInstance2(s); + + if (s.matches(Splitter.imgPatternNoSrcColon)) { + return Img.getInstance(s, false); } - + if (addStyle.matcher(s).matches()) { - //return new AddStyle(FontStyle.getStyle(s)); return new AddStyle(s); } if (removeStyle.matcher(s).matches()) { @@ -95,10 +98,41 @@ class HtmlCommandFactory { return new SizeChange(s); } + if (s.matches(Splitter.fontSup)) { + return new ExposantChange(FontPosition.EXPOSANT); + } + + if (s.matches(Splitter.fontSub)) { + return new ExposantChange(FontPosition.INDICE); + } + if (s.matches(Splitter.endFontPattern)) { return new ResetFont(); } + if (s.matches(Splitter.endSupSub)) { + return new ExposantChange(FontPosition.NORMAL); + } + + if (s.matches(Splitter.fontFamilyPattern)) { + return new FontFamilyChange(s); + } + + if (s.matches(Splitter.spritePattern)) { + return new SpriteCommand(s); + } + + if (s.matches(Splitter.linkPattern)) { + final UrlBuilder urlBuilder = new UrlBuilder(null, ModeUrl.STRICT); + final Url url = urlBuilder.getUrl(s); + url.setMember(true); + return new TextLink(url); + } + + if (s.matches(Splitter.svgAttributePattern)) { + return new SvgAttributesChange(s); + } + return null; } diff --git a/src/net/sourceforge/plantuml/graphic/Img.java b/src/net/sourceforge/plantuml/graphic/Img.java index 2022b14ba..f23736a63 100644 --- a/src/net/sourceforge/plantuml/graphic/Img.java +++ b/src/net/sourceforge/plantuml/graphic/Img.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,13 +28,19 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5697 $ + * Revision $Revision: 11788 $ * */ package net.sourceforge.plantuml.graphic; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -47,14 +53,12 @@ public class Img implements HtmlCommand { final static private Pattern srcPattern = Pattern.compile("(?i)src\\s*=\\s*[\"']?([^ \">]+)[\"']?"); final static private Pattern vspacePattern = Pattern.compile("(?i)vspace\\s*=\\s*[\"']?(\\d+)[\"']?"); final static private Pattern valignPattern = Pattern.compile("(?i)valign\\s*=\\s*[\"']?(top|bottom|middle)[\"']?"); - final static private Pattern srcPattern2 = Pattern.compile("(?i)" + Splitter.imgPattern2); + final static private Pattern noSrcColonPattern = Pattern.compile("(?i)" + Splitter.imgPatternNoSrcColon); - private final TileImage tileImage; - private final String filePath; + private final TextBlock tileImage; - private Img(TileImage image, String filePath) throws IOException { + private Img(TextBlock image) { this.tileImage = image; - this.filePath = filePath; } static int getVspace(String html) { @@ -73,27 +77,18 @@ public class Img implements HtmlCommand { return ImgValign.valueOf(m.group(1).toUpperCase()); } - static HtmlCommand getInstance(String html) { - final Matcher m = srcPattern.matcher(html); - if (m.find() == false) { - return new Text("(SYNTAX ERROR)"); - } - final String src = m.group(1); - try { - final File f = FileSystem.getInstance().getFile(src); - if (f.exists() == false) { - return new Text("(File not found: " + f + ")"); - } + static HtmlCommand getInstance(String html, boolean withSrc) { + if (withSrc) { + final Matcher m = srcPattern.matcher(html); final int vspace = getVspace(html); final ImgValign valign = getValign(html); - return new Img(new TileImage(ImageIO.read(f), valign, vspace), src); - } catch (IOException e) { - return new Text("ERROR " + e.toString()); + return build(m, valign, vspace); } + final Matcher m = noSrcColonPattern.matcher(html); + return build(m, ImgValign.TOP, 0); } - static HtmlCommand getInstance2(String html) { - final Matcher m = srcPattern2.matcher(html); + private static HtmlCommand build(final Matcher m, final ImgValign valign, final int vspace) { if (m.find() == false) { return new Text("(SYNTAX ERROR)"); } @@ -101,19 +96,55 @@ public class Img implements HtmlCommand { try { final File f = FileSystem.getInstance().getFile(src); if (f.exists() == false) { + // Check if valid URL + if (src.startsWith("http:") || src.startsWith("https:")) { + final byte image[] = getFile(src); + final BufferedImage read = ImageIO.read(new ByteArrayInputStream(image)); + if (read == null) { + return new Text("(Cannot decode: " + src + ")"); + } + return new Img(new TileImage(read, valign, vspace)); + } return new Text("(File not found: " + f + ")"); } - return new Img(new TileImage(ImageIO.read(f), ImgValign.TOP, 0), src); + if (f.getName().endsWith(".svg")) { + return new Img(new TileImageSvg(f)); + } + final BufferedImage read = ImageIO.read(f); + if (read == null) { + return new Text("(Cannot decode: " + f + ")"); + } + return new Img(new TileImage(ImageIO.read(f), valign, vspace)); } catch (IOException e) { return new Text("ERROR " + e.toString()); } } - public TileImage createMonoImage() { + public TextBlock createMonoImage() { return tileImage; } - public final String getFilePath() { - return filePath; + // Added by Alain Corbiere + static byte[] getFile(String host) throws IOException { + final ByteArrayOutputStream image = new ByteArrayOutputStream(); + InputStream input = null; + try { + final URL url = new URL(host); + final URLConnection connection = url.openConnection(); + input = connection.getInputStream(); + final byte[] buffer = new byte[1024]; + int read; + while ((read = input.read(buffer)) > 0) { + image.write(buffer, 0, read); + } + image.close(); + return image.toByteArray(); + } finally { + if (input != null) { + input.close(); + } + } } + // End + } diff --git a/src/net/sourceforge/plantuml/graphic/ImgValign.java b/src/net/sourceforge/plantuml/graphic/ImgValign.java index dc9ac5dc3..089ff2653 100644 --- a/src/net/sourceforge/plantuml/graphic/ImgValign.java +++ b/src/net/sourceforge/plantuml/graphic/ImgValign.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,11 +28,11 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3834 $ + * Revision $Revision: 11788 $ * */ package net.sourceforge.plantuml.graphic; -enum ImgValign { +public enum ImgValign { TOP, BOTTOM, MIDDLE } diff --git a/src/net/sourceforge/plantuml/graphic/Line.java b/src/net/sourceforge/plantuml/graphic/Line.java index fdb3d6693..1e864573c 100644 --- a/src/net/sourceforge/plantuml/graphic/Line.java +++ b/src/net/sourceforge/plantuml/graphic/Line.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,25 +28,13 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6577 $ + * Revision $Revision: 11154 $ * */ package net.sourceforge.plantuml.graphic; -import java.awt.Graphics2D; -import java.awt.geom.Dimension2D; -import net.sourceforge.plantuml.ugraphic.ColorMapper; -import net.sourceforge.plantuml.ugraphic.UGraphic; - -interface Line { - - Dimension2D calculateDimension(StringBounder stringBounder); - - void draw(ColorMapper colorMapper, Graphics2D g2d, double x, double y); - - void drawU(UGraphic ug, double x, double y); - - HorizontalAlignement getHorizontalAlignement(); +interface Line extends TextBlock { + HorizontalAlignment getHorizontalAlignment(); } \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/QuoteUtils.java b/src/net/sourceforge/plantuml/graphic/QuoteUtils.java new file mode 100644 index 000000000..837dec4c3 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/QuoteUtils.java @@ -0,0 +1,114 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 10930 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.util.Arrays; +import java.util.List; + +public class QuoteUtils { + + private static final List quotes = Arrays.asList(// + "He's dead, Jim.", // + "By Grabthar's hammer, by the sons of Worvan, you shall be avenged.", // + "Roads? Where we're going, we don't need roads.", // + "The time is out of joint.", // + "C'est curieux chez les marins ce besoin de faire des phrases.", // + "I'm talking about the other Peter, the one on the other side.", // + "May the Force be with you!", // + "Never give up, never surrender...", // + "Hasta la vista, baby.", // + "Hey, Doc, we better back up. We don't have enough road to get up to 88.", // + "Greetings, Professor Falken. Shall we play a game?", // + "I can't change the law of physics!", // + "A strange game. The only winning move is not to play.", // + "I'm the Gatekeeper, are you the Keymaster?", // + "I am the Master Control Program. No one User wrote me.", // + "Life? Don't talk to me about life.", // + "I always thought something was fundamentally wrong with the universe.", // + "A robot may not injure a human being or, through inaction, allow a human being to come to harm.", // + "Surrender may be our only option.", // + "Six by nine. Forty two.", // + "It's life, Jim, but not as we know it.", // + "Don't Panic!", // + "What do you mean? An African or European swallow?", // + "You forgot to say please...", // + "You have died of dysentery.", // + "Wouldn't you prefer a nice game of chess?", // + "When you have eliminated the impossible, whatever remains, however improbable, must be the truth.", // + "I know now why you cry. But it's something I can never do.", // + "Resistance is futile. You will be assimilated.", // + "Anything different is good.", // + "Cracked by Aldo Reset and Laurent Rueil.", // + "I'm both. I'm a celebrity in an emergency.", // + "Do you know this great great polish actor, Joseph Tura?", // + "To infinity and beyond!", // + "Space: the final frontier...", // + "Sur mon billet, tenez, y a ecrit Saint-Lazare, c'est mes yeux ou quoi ?", // + "The boy is important. He has to live.", // + "Once upon a time in a galaxy far, far away...", // + "And you know there's a long long way ahead of you...", // + "An allergy to oxygen? Elm blight?", // + "But alors you are French!", // + "N'ai-je donc tant vecu que pour cette infamie?", // + "Something is rotten in the State of Denmark.", // + "Hey, what do you want? Miracles?", // + "1.21 gigawatts! 1.21 gigawatts. Great Scott! ", // + "What the hell is a gigawatt?", // + "I need a vacation.", // + "On devrait jamais quitter Montauban.", // + "My force is a platform that you can climb on...", // + "There's something weird, and it don't look good...", // + "Et rien vraiment ne change mais tout est different", // + "Beam me up, Scotty.", // + "There is no spoon.", // + "Follow the white rabbit.", // + "Never send a human to do a machine's job.", // + "Guru meditation. Press left mouse button to continue.", // + "I don't think we're in Kansas anymore.", // + "Luke, I am your father.", // + "Blood, Sweat and Tears", // + "Houston, we have a problem.", // + "Boot failure, press any key to continue", // + "Big mistake!"); + // Creativity : how many? + // How many folksingers does it take to change a lightbulb ? + + private QuoteUtils() { + } + + public static String getSomeQuote() { + final int v = (int) (System.currentTimeMillis() / 1000L); + return quotes.get(v % quotes.size()); + } +} diff --git a/src/net/sourceforge/plantuml/graphic/RemoveStyle.java b/src/net/sourceforge/plantuml/graphic/RemoveStyle.java index 089288eef..5d5b2144a 100644 --- a/src/net/sourceforge/plantuml/graphic/RemoveStyle.java +++ b/src/net/sourceforge/plantuml/graphic/RemoveStyle.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3834 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graphic; diff --git a/src/net/sourceforge/plantuml/graphic/ResetFont.java b/src/net/sourceforge/plantuml/graphic/ResetFont.java index fdee2a7c4..854b0e6b4 100644 --- a/src/net/sourceforge/plantuml/graphic/ResetFont.java +++ b/src/net/sourceforge/plantuml/graphic/ResetFont.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3834 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graphic; diff --git a/src/net/sourceforge/plantuml/graphic/SingleLine.java b/src/net/sourceforge/plantuml/graphic/SingleLine.java index 80ac7bb0b..a48288a0c 100644 --- a/src/net/sourceforge/plantuml/graphic/SingleLine.java +++ b/src/net/sourceforge/plantuml/graphic/SingleLine.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,38 +28,51 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6577 $ + * Revision $Revision: 11873 $ * */ package net.sourceforge.plantuml.graphic; -import java.awt.Graphics2D; import java.awt.geom.Dimension2D; import java.util.ArrayList; import java.util.List; import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.SpriteContainer; +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.ugraphic.Sprite; import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; class SingleLine implements Line { - private final List blocs = new ArrayList(); - private final HorizontalAlignement horizontalAlignement; + private final List blocs = new ArrayList(); + private final HorizontalAlignment horizontalAlignment; - public SingleLine(String text, FontConfiguration fontConfiguration, HorizontalAlignement horizontalAlignement) { + public SingleLine(String text, FontConfiguration fontConfiguration, HorizontalAlignment horizontalAlignment, + SpriteContainer spriteContainer) { if (text.length() == 0) { text = " "; } - this.horizontalAlignement = horizontalAlignement; + this.horizontalAlignment = horizontalAlignment; final Splitter lineSplitter = new Splitter(text); for (HtmlCommand cmd : lineSplitter.getHtmlCommands(false)) { if (cmd instanceof Text) { final String s = ((Text) cmd).getText(); - blocs.add(new TileText(s, fontConfiguration)); + blocs.add(new TileText(s, fontConfiguration, null)); + } else if (cmd instanceof TextLink) { + final String s = ((TextLink) cmd).getText(); + final Url url = ((TextLink) cmd).getUrl(); + // blocs.add(new TileText(s, fontConfiguration.add(FontStyle.UNDERLINE), url)); + blocs.add(new TileText(s, fontConfiguration, url)); } else if (cmd instanceof Img) { blocs.add(((Img) cmd).createMonoImage()); + } else if (cmd instanceof SpriteCommand) { + final Sprite sprite = spriteContainer.getSprite(((SpriteCommand) cmd).getSprite()); + if (sprite != null) { + blocs.add(sprite.asTextBlock(fontConfiguration.getColor())); + } } else if (cmd instanceof FontChange) { fontConfiguration = ((FontChange) cmd).apply(fontConfiguration); } @@ -69,7 +82,7 @@ class SingleLine implements Line { public Dimension2D calculateDimension(StringBounder stringBounder) { double width = 0; double height = 0; - for (Tile b : blocs) { + for (TextBlock b : blocs) { final Dimension2D size2D = b.calculateDimension(stringBounder); width += size2D.getWidth(); height = Math.max(height, size2D.getHeight()); @@ -77,24 +90,24 @@ class SingleLine implements Line { return new Dimension2DDouble(width, height); } - private double maxDeltaY(Graphics2D g2d) { - double result = 0; - final Dimension2D dim = calculateDimension(StringBounderUtils.asStringBounder(g2d)); - for (Tile b : blocs) { - if (b instanceof TileText == false) { - continue; - } - final Dimension2D dimBloc = b.calculateDimension(StringBounderUtils.asStringBounder(g2d)); - final double deltaY = dim.getHeight() - dimBloc.getHeight() + ((TileText) b).getFontSize2D(); - result = Math.max(result, deltaY); - } - return result; - } + // private double maxDeltaY(Graphics2D g2d) { + // double result = 0; + // final Dimension2D dim = calculateDimension(StringBounderUtils.asStringBounder(g2d)); + // for (TextBlock b : blocs) { + // if (b instanceof TileText == false) { + // continue; + // } + // final Dimension2D dimBloc = b.calculateDimension(StringBounderUtils.asStringBounder(g2d)); + // final double deltaY = dim.getHeight() - dimBloc.getHeight() + ((TileText) b).getFontSize2D(); + // result = Math.max(result, deltaY); + // } + // return result; + // } private double maxDeltaY(UGraphic ug) { double result = 0; final Dimension2D dim = calculateDimension(ug.getStringBounder()); - for (Tile b : blocs) { + for (TextBlock b : blocs) { if (b instanceof TileText == false) { continue; } @@ -105,31 +118,23 @@ class SingleLine implements Line { return result; } - public void draw(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { - final double deltaY = maxDeltaY(g2d); - for (Tile b : blocs) { - if (b instanceof TileImage) { - b.draw(colorMapper, g2d, x, y); - } else { - b.draw(colorMapper, g2d, x, y + deltaY); - } - x += b.calculateDimension(StringBounderUtils.asStringBounder(g2d)).getWidth(); - } - } - - public void drawU(UGraphic ug, double x, double y) { + public void drawU(UGraphic ug) { final double deltaY = maxDeltaY(ug); - for (Tile b : blocs) { - if (b instanceof TileImage) { - b.drawU(ug, x, y); + final StringBounder stringBounder = ug.getStringBounder(); + final Dimension2D dim = calculateDimension(stringBounder); + double x = 0; + for (TextBlock b : blocs) { + if (b instanceof TileText) { + b.drawU(ug.apply(new UTranslate(x, deltaY))); } else { - b.drawU(ug, x, y + deltaY); + final double dy = dim.getHeight() - b.calculateDimension(stringBounder).getHeight(); + b.drawU(ug.apply(new UTranslate(x, dy))); } - x += b.calculateDimension(ug.getStringBounder()).getWidth(); + x += b.calculateDimension(stringBounder).getWidth(); } } - public HorizontalAlignement getHorizontalAlignement() { - return horizontalAlignement; + public HorizontalAlignment getHorizontalAlignment() { + return horizontalAlignment; } } diff --git a/src/net/sourceforge/plantuml/graphic/SizeChange.java b/src/net/sourceforge/plantuml/graphic/SizeChange.java index 17a665b0c..e013fae2c 100644 --- a/src/net/sourceforge/plantuml/graphic/SizeChange.java +++ b/src/net/sourceforge/plantuml/graphic/SizeChange.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/graphic/Splitter.java b/src/net/sourceforge/plantuml/graphic/Splitter.java index af2b10c7d..bbedd35a5 100644 --- a/src/net/sourceforge/plantuml/graphic/Splitter.java +++ b/src/net/sourceforge/plantuml/graphic/Splitter.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5705 $ + * Revision $Revision: 12105 $ * */ package net.sourceforge.plantuml.graphic; @@ -45,14 +45,23 @@ import net.sourceforge.plantuml.StringUtils; public class Splitter { - static final String endFontPattern = "\\|\\|\\"; - static final String fontPattern = "\\"; - static final String fontColorPattern2 = "\\"; - static final String fontSizePattern2 = "\\"; - static final String imgPattern = "]+['\"]?\\s*|vspace\\s*=\\s*['\"]?\\d+['\"]?\\s*|valign\\s*=\\s*['\"]?(top|middle|bottom)['\"]?\\s*)+>"; - static final String imgPattern2 = "]+)/?>"; + static final String endFontPattern = "\\|\\|\\|\\"; + static final String endSupSub = "\\|\\"; + public static final String fontPattern = "\\"; + public static final String fontColorPattern2 = "\\"; + public static final String fontSizePattern2 = "\\"; + static final String fontSup = "\\"; + static final String fontSub = "\\"; + static final String imgPattern = "\\]+['\"]?\\s*|vspace\\s*=\\s*['\"]?\\d+['\"]?\\s*|valign\\s*=\\s*['\"]?(top|middle|bottom)['\"]?\\s*)+\\>"; + public static final String imgPatternNoSrcColon = "\\]+)/?\\>"; + public static final String fontFamilyPattern = "\\]+)/?\\>"; + static final String svgAttributePattern = "\\]+)/?\\>"; + public static final String spritePattern = "\\<\\$[\\p{L}0-9_]+\\>"; + public static final String spritePattern2 = "\\<\\$([\\p{L}0-9_]+)\\>"; static final String htmlTag; + static final String linkPattern = "\\[\\[([^\\[\\]]+)\\]\\]"; + private static final Pattern tagOrText; static { @@ -73,11 +82,25 @@ public class Splitter { sb.append('|'); sb.append(fontSizePattern2); sb.append('|'); + sb.append(fontSup); + sb.append('|'); + sb.append(fontSub); + sb.append('|'); sb.append(endFontPattern); sb.append('|'); + sb.append(endSupSub); + sb.append('|'); sb.append(imgPattern); sb.append('|'); - sb.append(imgPattern2); + sb.append(imgPatternNoSrcColon); + sb.append('|'); + sb.append(fontFamilyPattern); + sb.append('|'); + sb.append(spritePattern); + sb.append('|'); + sb.append(linkPattern); + sb.append('|'); + sb.append(svgAttributePattern); htmlTag = sb.toString(); tagOrText = Pattern.compile(htmlTag + "|.+?(?=" + htmlTag + ")|.+$", Pattern.CASE_INSENSITIVE); @@ -116,7 +139,7 @@ public class Splitter { String s = cmd.getText(); final Collection result = new ArrayList(); while (true) { - int x = s.indexOf(Text.NEWLINE.getText()); + final int x = s.indexOf(Text.NEWLINE.getText()); if (x == -1) { result.add(new Text(s)); return result; diff --git a/src/net/sourceforge/plantuml/graphic/SpriteCommand.java b/src/net/sourceforge/plantuml/graphic/SpriteCommand.java new file mode 100644 index 000000000..bf1e5930b --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/SpriteCommand.java @@ -0,0 +1,57 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 5705 $ + * + */ +package net.sourceforge.plantuml.graphic; + +public class SpriteCommand implements HtmlCommand { + + private final String sprite; + + SpriteCommand(String sprite) { + if (sprite == null) { + throw new IllegalArgumentException(); + } + if (sprite.startsWith("<$") == false) { + throw new IllegalArgumentException(); + } + if (sprite.endsWith(">") == false) { + throw new IllegalArgumentException(); + } + this.sprite = sprite.substring(2, sprite.length() - 1).trim(); + } + + public String getSprite() { + return sprite; + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/StringBounder.java b/src/net/sourceforge/plantuml/graphic/StringBounder.java index 3b9cbc64c..1b6003664 100644 --- a/src/net/sourceforge/plantuml/graphic/StringBounder.java +++ b/src/net/sourceforge/plantuml/graphic/StringBounder.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6590 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graphic; diff --git a/src/net/sourceforge/plantuml/graphic/StringBounderUtils.java b/src/net/sourceforge/plantuml/graphic/StringBounderUtils.java index ea407dc80..60bbd5d5b 100644 --- a/src/net/sourceforge/plantuml/graphic/StringBounderUtils.java +++ b/src/net/sourceforge/plantuml/graphic/StringBounderUtils.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 7060 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graphic; diff --git a/src/net/sourceforge/plantuml/graphic/SvgAttributes.java b/src/net/sourceforge/plantuml/graphic/SvgAttributes.java new file mode 100644 index 000000000..83b8fc431 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/SvgAttributes.java @@ -0,0 +1,79 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8096 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.util.Collections; +import java.util.Map; +import java.util.TreeMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import net.sourceforge.plantuml.StringUtils; + +public class SvgAttributes { + + private final Map attributes = new TreeMap(); + + public SvgAttributes() { + } + + private SvgAttributes(SvgAttributes other) { + this.attributes.putAll(other.attributes); + } + + public SvgAttributes(String args) { + final Pattern p = Pattern.compile("(\\w+)\\s*=\\s*(\"[^\"]*\"|(?:\\w+))"); + final Matcher m = p.matcher(args); + while (m.find()) { + attributes.put(m.group(1), StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m.group(2))); + } + } + + public Map attributes() { + return Collections.unmodifiableMap(attributes); + } + + public SvgAttributes add(String key, String value) { + final SvgAttributes result = new SvgAttributes(this); + result.attributes.put(key, value); + return result; + } + + public SvgAttributes add(SvgAttributes toBeAdded) { + final SvgAttributes result = new SvgAttributes(this); + result.attributes.putAll(toBeAdded.attributes); + return result; + } + +} diff --git a/src/net/sourceforge/plantuml/graphic/SvgAttributesChange.java b/src/net/sourceforge/plantuml/graphic/SvgAttributesChange.java new file mode 100644 index 000000000..7302196eb --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/SvgAttributesChange.java @@ -0,0 +1,56 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 3834 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +class SvgAttributesChange implements FontChange { + + static final Pattern pattern = Pattern.compile(Splitter.svgAttributePattern); + private final SvgAttributes attributes; + + SvgAttributesChange(String s) { + final Matcher m = pattern.matcher(s); + if (m.find() == false) { + throw new IllegalStateException(); + } + attributes = new SvgAttributes(m.group(1)); + } + + public FontConfiguration apply(FontConfiguration initial) { + return initial.changeAttributes(attributes); + } + +} diff --git a/src/net/sourceforge/plantuml/graphic/SymbolContext.java b/src/net/sourceforge/plantuml/graphic/SymbolContext.java new file mode 100644 index 000000000..e2a09efcd --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/SymbolContext.java @@ -0,0 +1,90 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8066 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public class SymbolContext { + + private final HtmlColor backColor; + private final HtmlColor foreColor; + private final UStroke stroke; + private final boolean shadowing; + + private SymbolContext(HtmlColor backColor, HtmlColor foreColor, UStroke stroke, boolean shadowing) { + this.backColor = backColor; + this.foreColor = foreColor; + this.stroke = stroke; + this.shadowing = shadowing; +// if (backColor instanceof HtmlColorTransparent) { +// throw new UnsupportedOperationException(); +// } + } + + final public UGraphic apply(UGraphic ug) { + return ug.apply(new UChangeColor(foreColor)).apply(new UChangeBackColor(backColor)).apply(stroke); + } + + public SymbolContext(HtmlColor backColor, HtmlColor foreColor) { + this(backColor, foreColor, new UStroke(), false); + } + + public SymbolContext withShadow(boolean newShadow) { + return new SymbolContext(backColor, foreColor, stroke, newShadow); + } + + public SymbolContext withStroke(UStroke newStroke) { + return new SymbolContext(backColor, foreColor, newStroke, shadowing); + } + + public HtmlColor getBackColor() { + return backColor; + } + + public HtmlColor getForeColor() { + return foreColor; + } + + public UStroke getStroke() { + return stroke; + } + + public boolean isShadowing() { + return shadowing; + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/Text.java b/src/net/sourceforge/plantuml/graphic/Text.java index 29fd812d1..215678a8b 100644 --- a/src/net/sourceforge/plantuml/graphic/Text.java +++ b/src/net/sourceforge/plantuml/graphic/Text.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 5705 $ + * Revision $Revision: 11341 $ * */ package net.sourceforge.plantuml.graphic; @@ -40,7 +40,7 @@ public class Text implements HtmlCommand { public static final Text NEWLINE = new Text("\\n"); Text(String text) { - this.text = text; + this.text = text.replaceAll("\\\\\\[", "[").replaceAll("\\\\\\]", "]"); if (text.indexOf('\n') != -1) { throw new IllegalArgumentException(); } diff --git a/src/net/sourceforge/plantuml/graphic/TextBlock.java b/src/net/sourceforge/plantuml/graphic/TextBlock.java index aa74e8dd6..d87769f39 100644 --- a/src/net/sourceforge/plantuml/graphic/TextBlock.java +++ b/src/net/sourceforge/plantuml/graphic/TextBlock.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,19 +28,17 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 7163 $ + * Revision $Revision: 11863 $ * */ package net.sourceforge.plantuml.graphic; -import java.awt.Graphics2D; import java.awt.geom.Dimension2D; -import net.sourceforge.plantuml.ugraphic.ColorMapper; +public interface TextBlock extends UDrawable { -public interface TextBlock extends UDrawable3 { + public abstract Dimension2D calculateDimension(StringBounder stringBounder); - Dimension2D calculateDimension(StringBounder stringBounder); + // public abstract List getUrlsTOBEREMOVED(StringBounder stringBounder); - void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y); } \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockArrow.java b/src/net/sourceforge/plantuml/graphic/TextBlockArrow.java new file mode 100644 index 000000000..62a56058d --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/TextBlockArrow.java @@ -0,0 +1,109 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7163 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.Direction; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UPolygon; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class TextBlockArrow implements TextBlock { + + private final double size; + private final Direction arrow; + private final HtmlColor color; + + public TextBlockArrow(Direction arrow, FontConfiguration fontConfiguration) { + if (arrow == null) { + throw new IllegalArgumentException(); + } + this.arrow = arrow; + // this.size = fontConfiguration.getFont().getSize2D() * 0 + 30; + this.size = fontConfiguration.getFont().getSize2D(); + this.color = fontConfiguration.getColor(); + + } + + public void drawU(UGraphic ug) { + ug = ug.apply(new UChangeBackColor(color)); + ug = ug.apply(new UChangeColor(color)); + int triSize = (int) (size * .8 - 3); + if (triSize % 2 == 1) { + triSize--; + } + final UPolygon triangle = getTriangle(triSize); + if (arrow == Direction.RIGHT || arrow == Direction.LEFT) { + ug.apply(new UTranslate(2, (size - triSize) - 2)).draw(triangle); + } else { + ug.apply(new UTranslate(2, (size - triSize) - 2)).draw(triangle); + } + } + + private UPolygon getTriangle(int triSize) { + final UPolygon triangle = new UPolygon(); + if (arrow == Direction.RIGHT) { + triangle.addPoint(0, 0); + triangle.addPoint(triSize, triSize / 2); + triangle.addPoint(0, triSize); + triangle.addPoint(0, 0); + } else if (arrow == Direction.LEFT) { + triangle.addPoint(triSize, 0); + triangle.addPoint(0, triSize / 2); + triangle.addPoint(triSize, triSize); + triangle.addPoint(triSize, 0); + } else if (arrow == Direction.UP) { + triangle.addPoint(0, triSize); + triangle.addPoint(triSize / 2, 0); + triangle.addPoint(triSize, triSize); + triangle.addPoint(0, triSize); + } else if (arrow == Direction.DOWN) { + triangle.addPoint(0, 0); + triangle.addPoint(triSize / 2, triSize); + triangle.addPoint(triSize, 0); + triangle.addPoint(0, 0); + } else { + throw new IllegalStateException(); + } + return triangle; + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return new Dimension2DDouble(size, size); + } +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockVertical.java b/src/net/sourceforge/plantuml/graphic/TextBlockBordered.java similarity index 60% rename from src/net/sourceforge/plantuml/graphic/TextBlockVertical.java rename to src/net/sourceforge/plantuml/graphic/TextBlockBordered.java index 803a3750c..733b68d67 100644 --- a/src/net/sourceforge/plantuml/graphic/TextBlockVertical.java +++ b/src/net/sourceforge/plantuml/graphic/TextBlockBordered.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,37 +33,32 @@ */ package net.sourceforge.plantuml.graphic; -import java.awt.Graphics2D; import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.ugraphic.UChangeColor; import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UTranslate; -public class TextBlockVertical implements TextBlock { +class TextBlockBordered implements TextBlock { - private final TextBlock b1; - private final TextBlock b2; + private final TextBlock textBlock; + private final HtmlColor color; - public TextBlockVertical(TextBlock b1, TextBlock b2) { - this.b1 = b1; - this.b2 = b2; + public TextBlockBordered(TextBlock textBlock, HtmlColor color) { + this.textBlock = textBlock; + this.color = color; } public Dimension2D calculateDimension(StringBounder stringBounder) { - final Dimension2D dim1 = b1.calculateDimension(stringBounder); - final Dimension2D dim2 = b2.calculateDimension(stringBounder); - return Dimension2DDouble.mergeTB(dim1, dim2); + final Dimension2D dim = textBlock.calculateDimension(stringBounder); + return Dimension2DDouble.delta(dim, 1, 1); } - public void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { - throw new UnsupportedOperationException(); + public void drawU(UGraphic ug) { + final Dimension2D dim = textBlock.calculateDimension(ug.getStringBounder()); + textBlock.drawU(ug.apply(new UTranslate(1, 1))); + ug.apply(new UChangeColor(color)).draw(new URectangle(dim.getWidth(), dim.getHeight())); } - - public void drawU(UGraphic ug, double x, double y) { - b1.drawU(ug, x, y); - final Dimension2D dim1 = b1.calculateDimension(ug.getStringBounder()); - b2.drawU(ug, x, y + dim1.getHeight()); - } - } \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockCompressed.java b/src/net/sourceforge/plantuml/graphic/TextBlockCompressed.java new file mode 100644 index 000000000..b65de0510 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/TextBlockCompressed.java @@ -0,0 +1,72 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 10266 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ugraphic.CompressionTransform; +import net.sourceforge.plantuml.ugraphic.SlotFinder; +import net.sourceforge.plantuml.ugraphic.SlotSet; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UGraphicCompress; + +public class TextBlockCompressed implements TextBlock { + + private final TextBlock textBlock; + + public TextBlockCompressed(TextBlock textBlock) { + this.textBlock = textBlock; + } + + public void drawU(final UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + final CompressionTransform compressionTransform = getCompressionTransform(stringBounder); + textBlock.drawU(new UGraphicCompress(ug, compressionTransform)); + } + + private CompressionTransform getCompressionTransform(final StringBounder stringBounder) { + final SlotFinder slotFinder = new SlotFinder(stringBounder); + textBlock.drawU(slotFinder); + final SlotSet ysSlotSet = slotFinder.getYSlotSet().reverse().smaller(5.0); + final CompressionTransform compressionTransform = new CompressionTransform(ysSlotSet); + return compressionTransform; + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + final CompressionTransform compressionTransform = getCompressionTransform(stringBounder); + final Dimension2D dim = textBlock.calculateDimension(stringBounder); + return new Dimension2DDouble(dim.getWidth(), compressionTransform.transform(dim.getHeight())); + } +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockEmpty.java b/src/net/sourceforge/plantuml/graphic/TextBlockEmpty.java index a8ff7ecd4..cfe8377dd 100644 --- a/src/net/sourceforge/plantuml/graphic/TextBlockEmpty.java +++ b/src/net/sourceforge/plantuml/graphic/TextBlockEmpty.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,23 +33,42 @@ */ package net.sourceforge.plantuml.graphic; -import java.awt.Graphics2D; import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UGraphic; -public class TextBlockEmpty implements TextBlock { +public class TextBlockEmpty implements TextBlockWidth, TextBlock { + + private final double width; + private final double height; + + public TextBlockEmpty(double width, double height) { + this.width = width; + this.height = height; + } + + public TextBlockEmpty() { + this(0, 0); + } public Dimension2D calculateDimension(StringBounder stringBounder) { - return new Dimension2DDouble(0, 0); + return new Dimension2DDouble(width, height); } - public void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { + public void drawU(UGraphic ug) { } - public void drawU(UGraphic ug, double x, double y) { + public TextBlock asTextBlock(final double widthToUse) { + return new TextBlock() { + + public void drawU(UGraphic ug) { + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return TextBlockEmpty.this.calculateDimension(stringBounder); + } + }; } } \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockGeneric.java b/src/net/sourceforge/plantuml/graphic/TextBlockGeneric.java new file mode 100644 index 000000000..ae14b2a13 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/TextBlockGeneric.java @@ -0,0 +1,70 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 6577 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UStroke; + +public class TextBlockGeneric implements TextBlock { + + private final TextBlock textBlock; + private final HtmlColor background; + private final HtmlColor border; + + public TextBlockGeneric(TextBlock textBlock, HtmlColor background, HtmlColor border) { + this.textBlock = textBlock; + this.border = border; + this.background = background; + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + final Dimension2D dim = textBlock.calculateDimension(stringBounder); + return dim; + } + + public void drawU(UGraphic ug) { + ug = ug.apply(new UChangeBackColor(background)); + ug = ug.apply(new UChangeColor(border)); + final Dimension2D dim = calculateDimension(ug.getStringBounder()); + ug.apply(new UStroke(2, 2, 1)).draw(new URectangle(dim.getWidth(), dim.getHeight())); + + textBlock.drawU(ug); + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockHorizontal.java b/src/net/sourceforge/plantuml/graphic/TextBlockHorizontal.java index 227fd7442..3e1381be5 100644 --- a/src/net/sourceforge/plantuml/graphic/TextBlockHorizontal.java +++ b/src/net/sourceforge/plantuml/graphic/TextBlockHorizontal.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,21 +33,22 @@ */ package net.sourceforge.plantuml.graphic; -import java.awt.Graphics2D; import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; -public class TextBlockHorizontal implements TextBlock { +class TextBlockHorizontal implements TextBlock { private final TextBlock b1; private final TextBlock b2; + private final VerticalAlignment alignment; - public TextBlockHorizontal(TextBlock b1, TextBlock b2) { + public TextBlockHorizontal(TextBlock b1, TextBlock b2, VerticalAlignment alignment) { this.b1 = b1; this.b2 = b2; + this.alignment = alignment; } public Dimension2D calculateDimension(StringBounder stringBounder) { @@ -56,14 +57,18 @@ public class TextBlockHorizontal implements TextBlock { return Dimension2DDouble.mergeLR(dim1, dim2); } - public void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { - throw new UnsupportedOperationException(); - } - - public void drawU(UGraphic ug, double x, double y) { - b1.drawU(ug, x, y); + public void drawU(UGraphic ug) { + final Dimension2D dim = calculateDimension(ug.getStringBounder()); + final Dimension2D dimb1 = b1.calculateDimension(ug.getStringBounder()); + final Dimension2D dimb2 = b2.calculateDimension(ug.getStringBounder()); final Dimension2D dim1 = b1.calculateDimension(ug.getStringBounder()); - b2.drawU(ug, x + dim1.getWidth(), y); + if (alignment == VerticalAlignment.CENTER) { + b1.drawU(ug.apply(new UTranslate(0, ((dim.getHeight() - dimb1.getHeight()) / 2)))); + b2.drawU(ug.apply(new UTranslate(dim1.getWidth(), ((dim.getHeight() - dimb2.getHeight()) / 2)))); + } else { + b1.drawU(ug); + b2.drawU(ug.apply(new UTranslate(dim1.getWidth(), 0))); + } } } \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockInterceptorTextBlockable.java b/src/net/sourceforge/plantuml/graphic/TextBlockInterceptorTextBlockable.java new file mode 100644 index 000000000..9d2b3ccd1 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/TextBlockInterceptorTextBlockable.java @@ -0,0 +1,57 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 10266 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.ugraphic.UGraphic; + +public class TextBlockInterceptorTextBlockable implements TextBlock { + + private final TextBlock textBlock; + + public TextBlockInterceptorTextBlockable(TextBlock textBlock) { + this.textBlock = textBlock; + } + + public void drawU(UGraphic ug) { + textBlock.drawU(new UGraphicInterceptorTextBlockable(ug)); + ug.flushUg(); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return TextBlockUtils.getMinMax(this, stringBounder).getDimension(); + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockLineBefore.java b/src/net/sourceforge/plantuml/graphic/TextBlockLineBefore.java new file mode 100644 index 000000000..90e1a4796 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/TextBlockLineBefore.java @@ -0,0 +1,84 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 6577 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UHorizontalLine; + +public class TextBlockLineBefore implements TextBlock { + + private final TextBlock textBlock; + private final char separator; + private final TextBlock title; + + public TextBlockLineBefore(TextBlock textBlock, char separator, TextBlock title) { + this.textBlock = textBlock; + this.separator = separator; + this.title = title; + } + + public TextBlockLineBefore(TextBlock textBlock, char separator) { + this(textBlock, separator, null); + } + + public TextBlockLineBefore(TextBlock textBlock) { + this(textBlock, '\0'); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + final Dimension2D dim = textBlock.calculateDimension(stringBounder); + if (title != null) { + final Dimension2D dimTitle = title.calculateDimension(stringBounder); + return Dimension2DDouble.atLeast(dim, dimTitle.getWidth() + 8, dimTitle.getHeight()); + } + return dim; + } + + public void drawU(UGraphic ug) { + final HtmlColor color = ug.getParam().getColor(); + if (title == null) { + UHorizontalLine.infinite(1, 1, separator).drawMe(ug); + } + textBlock.drawU(ug); + ug = ug.apply(new UChangeColor(color)); + if (title != null) { + UHorizontalLine.infinite(1, 1, title, separator).drawMe(ug); + } + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockMarged.java b/src/net/sourceforge/plantuml/graphic/TextBlockMarged.java index 3e0ba2d2b..5f983d48c 100644 --- a/src/net/sourceforge/plantuml/graphic/TextBlockMarged.java +++ b/src/net/sourceforge/plantuml/graphic/TextBlockMarged.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -33,14 +33,13 @@ */ package net.sourceforge.plantuml.graphic; -import java.awt.Graphics2D; import java.awt.geom.Dimension2D; import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; -public class TextBlockMarged implements TextBlock { +class TextBlockMarged implements TextBlock { private final TextBlock textBlock; private final double x1; @@ -61,12 +60,8 @@ public class TextBlockMarged implements TextBlock { return Dimension2DDouble.delta(dim, x1 + x2, y1 + y2); } - public void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { - throw new UnsupportedOperationException(); - } - - public void drawU(UGraphic ug, double x, double y) { - textBlock.drawU(ug, x + x1, y + y1); + public void drawU(UGraphic ug) { + textBlock.drawU(ug.apply(new UTranslate(x1, y1))); } } \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockMinWidth.java b/src/net/sourceforge/plantuml/graphic/TextBlockMinWidth.java new file mode 100644 index 000000000..5fbd388d2 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/TextBlockMinWidth.java @@ -0,0 +1,70 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 6577 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +class TextBlockMinWidth implements TextBlock { + + private final TextBlock textBlock; + private final double minWidth; + private final HorizontalAlignment horizontalAlignment; + + public TextBlockMinWidth(TextBlock textBlock, double minWidth, HorizontalAlignment horizontalAlignment) { + this.textBlock = textBlock; + this.minWidth = minWidth; + this.horizontalAlignment = horizontalAlignment; + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + final Dimension2D dim = textBlock.calculateDimension(stringBounder); + return Dimension2DDouble.atLeast(dim, minWidth, 0); + } + + public void drawU(UGraphic ug) { + if (horizontalAlignment == HorizontalAlignment.LEFT) { + textBlock.drawU(ug); + } else if (horizontalAlignment == HorizontalAlignment.RIGHT) { + final Dimension2D dim = textBlock.calculateDimension(ug.getStringBounder()); + final double diffx = minWidth - dim.getWidth(); + textBlock.drawU(ug.apply(new UTranslate(diffx, 0))); + } else { + throw new UnsupportedOperationException(); + } + } +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockRecentred.java b/src/net/sourceforge/plantuml/graphic/TextBlockRecentred.java new file mode 100644 index 000000000..77ba3c919 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/TextBlockRecentred.java @@ -0,0 +1,60 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 10266 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.ugraphic.MinMax; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class TextBlockRecentred implements TextBlock { + + private final TextBlock textBlock; + + public TextBlockRecentred(TextBlock textBlock) { + this.textBlock = textBlock; + } + + public void drawU(final UGraphic ug) { + final MinMax minMax = TextBlockUtils.getMinMax(textBlock); + textBlock.drawU(ug.apply(new UTranslate(-minMax.getMinX(), -minMax.getMinY()))); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + final MinMax minMax = TextBlockUtils.getMinMax(textBlock); + return minMax.getDimension(); + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockSimple.java b/src/net/sourceforge/plantuml/graphic/TextBlockSimple.java index c6d84a17d..f8bfd8f60 100644 --- a/src/net/sourceforge/plantuml/graphic/TextBlockSimple.java +++ b/src/net/sourceforge/plantuml/graphic/TextBlockSimple.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,46 +28,126 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6936 $ + * Revision $Revision: 11873 $ * */ package net.sourceforge.plantuml.graphic; -import java.awt.Graphics2D; import java.awt.geom.Dimension2D; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.StringTokenizer; import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.EmbededDiagram; +import net.sourceforge.plantuml.SpriteContainer; +import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.cucadiagram.Stereotype; -import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; class TextBlockSimple implements TextBlock { - private final List lines = new ArrayList(); + private List lines2; - protected TextBlockSimple(List texts, FontConfiguration fontConfiguration, - HorizontalAlignement horizontalAlignement) { - for (CharSequence s : texts) { - if (s instanceof Stereotype) { - lines.addAll(createLinesForStereotype(fontConfiguration, (Stereotype) s, horizontalAlignement)); - } else if (s instanceof EmbededDiagram) { - lines.add(new EmbededSystemLine((EmbededDiagram) s)); - } else { - lines.add(new SingleLine(s.toString(), fontConfiguration, horizontalAlignement)); + private final Display texts; + private final FontConfiguration fontConfiguration; + private final HorizontalAlignment horizontalAlignment; + private final SpriteContainer spriteContainer; + private final double maxMessageSize; + + protected TextBlockSimple(Display texts, FontConfiguration fontConfiguration, + HorizontalAlignment horizontalAlignment, SpriteContainer spriteContainer, double maxMessageSize) { + this.texts = texts; + this.fontConfiguration = fontConfiguration; + this.horizontalAlignment = horizontalAlignment; + this.spriteContainer = spriteContainer; + this.maxMessageSize = maxMessageSize; + } + + private List getLines(StringBounder stringBounder) { + if (lines2 == null) { + if (stringBounder == null) { + throw new IllegalStateException(); } + this.lines2 = new ArrayList(); + for (CharSequence s : texts) { + if (s instanceof Stereotype) { + lines2.addAll(createLinesForStereotype(fontConfiguration, (Stereotype) s, horizontalAlignment, + spriteContainer)); + } else if (s instanceof EmbededDiagram) { + lines2.add(new EmbededSystemLine((EmbededDiagram) s)); + } else { + addInLines(stringBounder, s.toString()); + } + } + } + return lines2; + } + + private void addInLines(StringBounder stringBounder, String s) { + if (maxMessageSize == 0) { + addSingleLine(s); + } else if (maxMessageSize > 0) { + final StringTokenizer st = new StringTokenizer(s, " ", true); + final StringBuilder currentLine = new StringBuilder(); + while (st.hasMoreTokens()) { + final String token = st.nextToken(); + final double w = getTextWidth(stringBounder, currentLine + token); + if (w > maxMessageSize) { + addSingleLineNoSpace(currentLine.toString()); + currentLine.setLength(0); + if (token.startsWith(" ") == false) { + currentLine.append(token); + } + } else { + currentLine.append(token); + } + } + addSingleLineNoSpace(currentLine.toString()); + } else if (maxMessageSize < 0) { + final StringBuilder currentLine = new StringBuilder(); + for (int i = 0; i < s.length(); i++) { + final char c = s.charAt(i); + final double w = getTextWidth(stringBounder, currentLine.toString() + c); + if (w > -maxMessageSize) { + addSingleLineNoSpace(currentLine.toString()); + currentLine.setLength(0); + if (c != ' ') { + currentLine.append(c); + } + } else { + currentLine.append(c); + } + } + addSingleLineNoSpace(currentLine.toString()); } } + private void addSingleLineNoSpace(String s) { + if (s.length() == 0 || s.matches("^\\s*$ ")) { + return; + } + lines2.add(new SingleLine(s, fontConfiguration, horizontalAlignment, spriteContainer)); + } + + private void addSingleLine(String s) { + lines2.add(new SingleLine(s, fontConfiguration, horizontalAlignment, spriteContainer)); + } + + private double getTextWidth(StringBounder stringBounder, String s) { + final Line line = new SingleLine(s, fontConfiguration, horizontalAlignment, spriteContainer); + return line.calculateDimension(stringBounder).getWidth(); + } + private List createLinesForStereotype(FontConfiguration fontConfiguration, Stereotype s, - HorizontalAlignement horizontalAlignement) { + HorizontalAlignment horizontalAlignment, SpriteContainer spriteContainer) { assert s.getLabel() != null; final List result = new ArrayList(); for (String st : s.getLabels()) { - result.add(new SingleLine(st, fontConfiguration.add(FontStyle.ITALIC), horizontalAlignement)); + result.add(new SingleLine(st, fontConfiguration.add(FontStyle.ITALIC), horizontalAlignment, + spriteContainer)); } return Collections.unmodifiableList(result); } @@ -79,7 +159,7 @@ class TextBlockSimple implements TextBlock { protected final Dimension2D getTextDimension(StringBounder stringBounder) { double width = 0; double height = 0; - for (Line line : lines) { + for (Line line : getLines(stringBounder)) { final Dimension2D size2D = line.calculateDimension(stringBounder); height += size2D.getHeight(); width = Math.max(width, size2D.getWidth()); @@ -87,33 +167,21 @@ class TextBlockSimple implements TextBlock { return new Dimension2DDouble(width, height); } - public void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { - final Dimension2D dimText = getTextDimension(StringBounderUtils.asStringBounder(g2d)); - - for (Line line : lines) { - final HorizontalAlignement lineHorizontalAlignement = line.getHorizontalAlignement(); - double deltaX = 0; - if (lineHorizontalAlignement == HorizontalAlignement.CENTER) { - final double diff = dimText.getWidth() - - line.calculateDimension(StringBounderUtils.asStringBounder(g2d)).getWidth(); - deltaX = diff / 2.0; - } - line.draw(colorMapper, g2d, x + deltaX, y); - y += line.calculateDimension(StringBounderUtils.asStringBounder(g2d)).getHeight(); - } - } - - public void drawU(UGraphic ug, double x, double y) { + public void drawU(UGraphic ug) { + double y = 0; final Dimension2D dimText = getTextDimension(ug.getStringBounder()); - for (Line line : lines) { - final HorizontalAlignement lineHorizontalAlignement = line.getHorizontalAlignement(); + for (Line line : getLines(ug.getStringBounder())) { + final HorizontalAlignment lineHorizontalAlignment = line.getHorizontalAlignment(); double deltaX = 0; - if (lineHorizontalAlignement == HorizontalAlignement.CENTER) { + if (lineHorizontalAlignment == HorizontalAlignment.CENTER) { final double diff = dimText.getWidth() - line.calculateDimension(ug.getStringBounder()).getWidth(); deltaX = diff / 2.0; + } else if (lineHorizontalAlignment == HorizontalAlignment.RIGHT) { + final double diff = dimText.getWidth() - line.calculateDimension(ug.getStringBounder()).getWidth(); + deltaX = diff; } - line.drawU(ug, x + deltaX, y); + line.drawU(ug.apply(new UTranslate(deltaX, y))); y += line.calculateDimension(ug.getStringBounder()).getHeight(); } } diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockSpotted.java b/src/net/sourceforge/plantuml/graphic/TextBlockSpotted.java index 863b23634..176f811db 100644 --- a/src/net/sourceforge/plantuml/graphic/TextBlockSpotted.java +++ b/src/net/sourceforge/plantuml/graphic/TextBlockSpotted.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,26 +28,26 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6577 $ + * Revision $Revision: 11154 $ * */ package net.sourceforge.plantuml.graphic; -import java.awt.Graphics2D; import java.awt.geom.Dimension2D; -import java.util.List; import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.SpriteContainer; +import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; class TextBlockSpotted extends TextBlockSimple { private final CircledCharacter circledCharacter; - public TextBlockSpotted(CircledCharacter circledCharacter, List texts, - FontConfiguration fontConfiguration, HorizontalAlignement horizontalAlignement) { - super(texts, fontConfiguration, horizontalAlignement); + public TextBlockSpotted(CircledCharacter circledCharacter, Display texts, FontConfiguration fontConfiguration, + HorizontalAlignment horizontalAlignment, SpriteContainer spriteContainer) { + super(texts, fontConfiguration, horizontalAlignment, spriteContainer, 0); this.circledCharacter = circledCharacter; } @@ -66,46 +66,15 @@ class TextBlockSpotted extends TextBlockSimple { } @Override - public void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { - // final AffineTransform at = g2d.getTransform(); - // final StringBounder stringBounder = StringBounderUtils.asStringBounder(g2d); - // - // final double deltaY = calculateDimension(StringBounderUtils.asStringBounder(g2d)).getHeight() - // - circledCharacter.getPreferredHeight(stringBounder); - // - // // g2d.translate(x, y + deltaY / 2.0); - // circledCharacter.draw(g2d, (int) x, (int) (y + deltaY / 2.0)); - // // circledCharacter.draw(g2d); - // - // g2d.setTransform(at); - // final double widthCircledCharacter = getCircledCharacterWithAndMargin(stringBounder); - // g2d.translate(widthCircledCharacter, 0); - // - // super.drawTOBEREMOVED(g2d, x, y); - // - // g2d.setTransform(at); - throw new UnsupportedOperationException(); - } - - @Override - public void drawU(UGraphic ug, double x, double y) { - final double atX = ug.getTranslateX(); - final double atY = ug.getTranslateY(); + public void drawU(UGraphic ug) { final StringBounder stringBounder = ug.getStringBounder(); - // final double deltaY = calculateDimension(stringBounder).getHeight() - // - circledCharacter.getPreferredHeight(stringBounder); + circledCharacter.drawU(ug); - // circledCharacter.drawU(ug, (int) x, (int) (y + deltaY / 2.0)); - circledCharacter.drawU(ug, x, y); - - ug.setTranslate(atX, atY); final double widthCircledCharacter = getCircledCharacterWithAndMargin(stringBounder); - ug.translate(widthCircledCharacter, 0); - super.drawU(ug, x, y); - - ug.setTranslate(atX, atY); + super.drawU(ug.apply(new UTranslate(widthCircledCharacter, 0))); } + } diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockUtils.java b/src/net/sourceforge/plantuml/graphic/TextBlockUtils.java index ecbf794a4..db6adb31f 100644 --- a/src/net/sourceforge/plantuml/graphic/TextBlockUtils.java +++ b/src/net/sourceforge/plantuml/graphic/TextBlockUtils.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,96 +28,172 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 7157 $ + * Revision $Revision: 11995 $ * */ package net.sourceforge.plantuml.graphic; +import java.awt.Font; +import java.awt.FontMetrics; import java.awt.Graphics2D; +import java.awt.font.FontRenderContext; +import java.awt.font.LineMetrics; import java.awt.geom.Dimension2D; import java.awt.geom.Point2D; -import java.util.List; +import java.awt.image.BufferedImage; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.SpriteContainer; +import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.cucadiagram.Stereotype; import net.sourceforge.plantuml.posimo.Positionable; import net.sourceforge.plantuml.posimo.PositionableImpl; import net.sourceforge.plantuml.sequencediagram.MessageNumber; -import net.sourceforge.plantuml.svek.IEntityImage; import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.ugraphic.LimitFinder; +import net.sourceforge.plantuml.ugraphic.MinMax; +import net.sourceforge.plantuml.ugraphic.UFont; import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; public class TextBlockUtils { - public static TextBlock create(List texts, FontConfiguration fontConfiguration, - HorizontalAlignement horizontalAlignement) { - if (texts.size() > 0 && texts.get(0) instanceof Stereotype) { - return createStereotype(texts, fontConfiguration, horizontalAlignement); + public static TextBlock create(Display texts, FontConfiguration fontConfiguration, + HorizontalAlignment horizontalAlignment, SpriteContainer spriteContainer) { + if (texts == null) { + return empty(0, 0); } - if (texts.size() > 0 && texts.get(0) instanceof MessageNumber) { - return createMessageNumber(texts, fontConfiguration, horizontalAlignement); - } - return new TextBlockSimple(texts, fontConfiguration, horizontalAlignement); + return create(texts, fontConfiguration, horizontalAlignment, spriteContainer, 0); } - private static TextBlock createMessageNumber(List texts, - FontConfiguration fontConfiguration, HorizontalAlignement horizontalAlignement) { + public static TextBlock create(Display texts, FontConfiguration fontConfiguration, + HorizontalAlignment horizontalAlignment, SpriteContainer spriteContainer, double maxMessageSize) { + if (texts.size() > 0) { + if (texts.get(0) instanceof Stereotype) { + return createStereotype(texts, fontConfiguration, horizontalAlignment, spriteContainer, 0); + } + if (texts.get(texts.size() - 1) instanceof Stereotype) { + return createStereotype(texts, fontConfiguration, horizontalAlignment, spriteContainer, + texts.size() - 1); + } + if (texts.get(0) instanceof MessageNumber) { + return createMessageNumber(texts, fontConfiguration, horizontalAlignment, spriteContainer, + maxMessageSize); + } + } + return new TextBlockSimple(texts, fontConfiguration, horizontalAlignment, spriteContainer, maxMessageSize); + } + + private static TextBlock createMessageNumber(Display texts, FontConfiguration fontConfiguration, + HorizontalAlignment horizontalAlignment, SpriteContainer spriteContainer, double maxMessageSize) { final MessageNumber number = (MessageNumber) texts.get(0); return new TextBlockWithNumber(number.getNumber(), texts.subList(1, texts.size()), fontConfiguration, - horizontalAlignement); + horizontalAlignment, spriteContainer, maxMessageSize); } - private static TextBlock createStereotype(List texts, FontConfiguration fontConfiguration, - HorizontalAlignement horizontalAlignement) { - final Stereotype stereotype = (Stereotype) texts.get(0); + private static TextBlock createStereotype(Display texts, FontConfiguration fontConfiguration, + HorizontalAlignment horizontalAlignment, SpriteContainer spriteContainer, int position) { + final Stereotype stereotype = (Stereotype) texts.get(position); if (stereotype.isSpotted()) { - final CircledCharacter circledCharacter = new CircledCharacter(stereotype.getCharacter(), stereotype - .getRadius(), stereotype.getCircledFont(), stereotype.getHtmlColor(), null, fontConfiguration - .getColor()); + final CircledCharacter circledCharacter = new CircledCharacter(stereotype.getCharacter(), + stereotype.getRadius(), stereotype.getCircledFont(), stereotype.getHtmlColor(), null, + fontConfiguration.getColor()); if (stereotype.getLabel() == null) { return new TextBlockSpotted(circledCharacter, texts.subList(1, texts.size()), fontConfiguration, - horizontalAlignement); + horizontalAlignment, spriteContainer); } - return new TextBlockSpotted(circledCharacter, texts, fontConfiguration, horizontalAlignement); + return new TextBlockSpotted(circledCharacter, texts, fontConfiguration, horizontalAlignment, + spriteContainer); } - return new TextBlockSimple(texts, fontConfiguration, horizontalAlignement); + return new TextBlockSimple(texts, fontConfiguration, horizontalAlignment, spriteContainer, 0); } public static TextBlock withMargin(TextBlock textBlock, double marginX, double marginY) { return new TextBlockMarged(textBlock, marginX, marginX, marginY, marginY); } - // static private Font deriveForCircleCharacter(Font font) { - // final float size = font.getSize2D(); - // return font.deriveFont(size - 1).deriveFont(Font.BOLD); - // } + public static TextBlock withMinWidth(TextBlock textBlock, double minWidth, HorizontalAlignment horizontalAlignment) { + return new TextBlockMinWidth(textBlock, minWidth, horizontalAlignment); + } + + public static TextBlock withMargin(TextBlock textBlock, double marginX1, double marginX2, double marginY1, + double marginY2) { + return new TextBlockMarged(textBlock, marginX1, marginX2, marginY1, marginY2); + } + + public static TextBlock empty(final double width, final double height) { + return new TextBlock() { + public void drawU(UGraphic ug) { + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return new Dimension2DDouble(width, height); + } + }; + } public static Positionable asPositionable(TextBlock textBlock, StringBounder stringBounder, Point2D pt) { return new PositionableImpl(pt, textBlock.calculateDimension(stringBounder)); } - public static TextBlock fromIEntityImage(final IEntityImage image) { - return new TextBlock() { - public Dimension2D calculateDimension(StringBounder stringBounder) { - return image.getDimension(stringBounder); - } - - public void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { - throw new UnsupportedOperationException(); - } - - public void drawU(UGraphic ug, double x, double y) { - image.drawU(ug, x, y); - } - }; + public static TextBlock mergeLR(TextBlock b1, TextBlock b2, VerticalAlignment verticallAlignment) { + return new TextBlockHorizontal(b1, b2, verticallAlignment); } - public static TextBlock mergeLR(TextBlock b1, TextBlock b2) { - return new TextBlockHorizontal(b1, b2); + public static TextBlock mergeTB(TextBlock b1, TextBlock b2, HorizontalAlignment horizontalAlignment) { + return new TextBlockVertical2(b1, b2, horizontalAlignment); } - public static TextBlock mergeTB(TextBlock b1, TextBlock b2) { - return new TextBlockVertical(b1, b2); + public static MinMax getMinMax(TextBlock tb, StringBounder stringBounder) { + final LimitFinder limitFinder = new LimitFinder(stringBounder, false); + tb.drawU(limitFinder); + return limitFinder.getMinMax(); + } + + private static final Graphics2D gg; + private static final StringBounder dummyStringBounder; + + static { + final BufferedImage imDummy = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB); + gg = imDummy.createGraphics(); + dummyStringBounder = StringBounderUtils.asStringBounder(gg); + } + + public static StringBounder getDummyStringBounder() { + return dummyStringBounder; + } + + public static FontRenderContext getFontRenderContext() { + return gg.getFontRenderContext(); + } + + public static UGraphic getPrinted(TextBlock tb, FileFormatOption fileFormatOption, ColorMapper colorMapper, + double dpiFactor, HtmlColor mybackcolor, double margin) { + final MinMax minmax = getMinMax(tb, dummyStringBounder); + final UGraphic ug = fileFormatOption.createUGraphic(colorMapper, dpiFactor, + Dimension2DDouble.delta(minmax.getDimension(), 2 * margin), mybackcolor, false); + final double dx = -minmax.getMinX() + margin; + final double dy = -minmax.getMinY() + margin; + tb.drawU(ug.apply(new UTranslate(dx, dy))); + return ug; + } + + public static MinMax getMinMax(TextBlock tb) { + return getMinMax(tb, dummyStringBounder); + } + + public static Dimension2D getDimension(TextBlock tb) { + return tb.calculateDimension(dummyStringBounder); + } + + public static LineMetrics getLineMetrics(UFont font, String text) { + return font.getLineMetrics(gg, text); + } + + public static FontMetrics getFontMetrics(Font font) { + return gg.getFontMetrics(font); } } diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockVertical2.java b/src/net/sourceforge/plantuml/graphic/TextBlockVertical2.java new file mode 100644 index 000000000..7eae7df40 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/TextBlockVertical2.java @@ -0,0 +1,88 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 6577 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.geom.Dimension2D; +import java.util.ArrayList; +import java.util.List; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class TextBlockVertical2 implements TextBlock { + + private final List blocks = new ArrayList(); + private final HorizontalAlignment horizontalAlignment; + + public TextBlockVertical2(TextBlock b1, TextBlock b2, HorizontalAlignment horizontalAlignment) { + this.blocks.add(b1); + this.blocks.add(b2); + this.horizontalAlignment = horizontalAlignment; + } + + public TextBlockVertical2(List all, HorizontalAlignment horizontalAlignment) { + if (all.size() < 2) { + throw new IllegalArgumentException(); + } + this.blocks.addAll(all); + this.horizontalAlignment = horizontalAlignment; + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + Dimension2D dim = blocks.get(0).calculateDimension(stringBounder); + for (int i = 1; i < blocks.size(); i++) { + dim = Dimension2DDouble.mergeTB(dim, blocks.get(i).calculateDimension(stringBounder)); + } + return dim; + } + + public void drawU(UGraphic ug) { + double y = 0; + final Dimension2D dimtotal = calculateDimension(ug.getStringBounder()); + for (TextBlock b : blocks) { + final Dimension2D dimb = b.calculateDimension(ug.getStringBounder()); + if (horizontalAlignment == HorizontalAlignment.LEFT) { + b.drawU(ug.apply(new UTranslate(0, y))); + } else if (horizontalAlignment == HorizontalAlignment.CENTER) { + final double dx = (dimtotal.getWidth() - dimb.getWidth()) / 2; + b.drawU(ug.apply(new UTranslate(dx, y))); + } else { + throw new UnsupportedOperationException(); + } + y += dimb.getHeight(); + } + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockWidth.java b/src/net/sourceforge/plantuml/graphic/TextBlockWidth.java new file mode 100644 index 000000000..0a1f39e0f --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/TextBlockWidth.java @@ -0,0 +1,43 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7163 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.geom.Dimension2D; + +public interface TextBlockWidth { + + Dimension2D calculateDimension(StringBounder stringBounder); + + TextBlock asTextBlock(double widthToUse); +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockWidthAdapter.java b/src/net/sourceforge/plantuml/graphic/TextBlockWidthAdapter.java new file mode 100644 index 000000000..bd2d427d1 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/TextBlockWidthAdapter.java @@ -0,0 +1,62 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7163 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.ugraphic.UGraphic; + +public class TextBlockWidthAdapter implements TextBlock { + + private final TextBlockWidth textBlockWidth; + private final double width; + + // public final void setWidth(double width) { + // this.width = width; + // } + + public TextBlockWidthAdapter(TextBlockWidth textBlockWidth, double widthToUse) { + this.textBlockWidth = textBlockWidth; + this.width = widthToUse; + } + + public void drawU(UGraphic ug) { + textBlockWidth.asTextBlock(width).drawU(ug); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return textBlockWidth.calculateDimension(stringBounder); + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockWithNumber.java b/src/net/sourceforge/plantuml/graphic/TextBlockWithNumber.java index 1b539ec0e..16fbc8c66 100644 --- a/src/net/sourceforge/plantuml/graphic/TextBlockWithNumber.java +++ b/src/net/sourceforge/plantuml/graphic/TextBlockWithNumber.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,28 +28,28 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6577 $ + * Revision $Revision: 11154 $ * */ package net.sourceforge.plantuml.graphic; -import java.awt.Graphics2D; import java.awt.geom.Dimension2D; -import java.util.Arrays; -import java.util.List; import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.SpriteContainer; +import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; class TextBlockWithNumber extends TextBlockSimple { private final TextBlock numText; - public TextBlockWithNumber(String number, List texts, FontConfiguration fontConfiguration, - HorizontalAlignement horizontalAlignement) { - super(texts, fontConfiguration, horizontalAlignement); - this.numText = TextBlockUtils.create(Arrays.asList(number), fontConfiguration, HorizontalAlignement.LEFT); + public TextBlockWithNumber(String number, Display texts, FontConfiguration fontConfiguration, + HorizontalAlignment horizontalAlignment, SpriteContainer spriteContainer, double maxMessageSize) { + super(texts, fontConfiguration, horizontalAlignment, spriteContainer, maxMessageSize); + this.numText = TextBlockUtils.create(Display.asList(number), fontConfiguration, HorizontalAlignment.LEFT, + spriteContainer); } @Override @@ -67,25 +67,15 @@ class TextBlockWithNumber extends TextBlockSimple { } @Override - public void drawTOBEREMOVED(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { - final StringBounder stringBounder = StringBounderUtils.asStringBounder(g2d); - final double heightNum = numText.calculateDimension(stringBounder).getHeight(); - - final double deltaY = calculateDimension(stringBounder).getHeight() - heightNum; - - numText.drawTOBEREMOVED(colorMapper, g2d, x, y + deltaY / 2.0); - super.drawTOBEREMOVED(colorMapper, g2d, x + getNumberWithAndMargin(stringBounder), y); - } - - @Override - public void drawU(UGraphic ug, double x, double y) { + public void drawU(UGraphic ug) { final StringBounder stringBounder = ug.getStringBounder(); final double heightNum = numText.calculateDimension(stringBounder).getHeight(); - + final double deltaY = calculateDimension(stringBounder).getHeight() - heightNum; - - numText.drawU(ug, x, y + deltaY / 2.0); - super.drawU(ug, x + getNumberWithAndMargin(stringBounder), y); + + numText.drawU(ug.apply(new UTranslate(0, deltaY / 2.0))); + super.drawU(ug.apply(new UTranslate(getNumberWithAndMargin(stringBounder), 0))); } + } diff --git a/src/net/sourceforge/plantuml/graphic/TextBlockable.java b/src/net/sourceforge/plantuml/graphic/TextBlockable.java new file mode 100644 index 000000000..dd882fc82 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/TextBlockable.java @@ -0,0 +1,44 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 10266 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import net.sourceforge.plantuml.ugraphic.UShape; + +public interface TextBlockable extends UShape { + + public TextBlock asTextBlock(); + + + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/TextLink.java b/src/net/sourceforge/plantuml/graphic/TextLink.java new file mode 100644 index 000000000..990867a7e --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/TextLink.java @@ -0,0 +1,57 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 7715 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import net.sourceforge.plantuml.Url; + +public class TextLink implements HtmlCommand { + + private final Url url; + + TextLink(Url url) { + if (url == null) { + throw new IllegalArgumentException(); + } + this.url = url; + } + + public String getText() { + return url.getLabel(); + } + + public Url getUrl() { + return url; + } + +} diff --git a/src/net/sourceforge/plantuml/graphic/TileImage.java b/src/net/sourceforge/plantuml/graphic/TileImage.java index a03cd3014..11780fb10 100644 --- a/src/net/sourceforge/plantuml/graphic/TileImage.java +++ b/src/net/sourceforge/plantuml/graphic/TileImage.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,26 +28,28 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6577 $ + * Revision $Revision: 11873 $ * */ package net.sourceforge.plantuml.graphic; -import java.awt.Graphics2D; import java.awt.geom.Dimension2D; import java.awt.image.BufferedImage; import net.sourceforge.plantuml.Dimension2DDouble; -import net.sourceforge.plantuml.ugraphic.ColorMapper; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UImage; +import net.sourceforge.plantuml.ugraphic.UTranslate; -class TileImage implements Tile { +public class TileImage implements TextBlock { private final BufferedImage image; private final int vspace; public TileImage(BufferedImage image, ImgValign valign, int vspace) { + if (image == null) { + throw new IllegalArgumentException(); + } this.image = image; this.vspace = vspace; } @@ -56,12 +58,8 @@ class TileImage implements Tile { return new Dimension2DDouble(image.getWidth(), image.getHeight() + 2 * vspace); } - public void draw(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { - g2d.drawImage(image, (int) x, (int) y + vspace, null); - } - - public void drawU(UGraphic ug, double x, double y) { - ug.draw(x, y + vspace, new UImage(image)); + public void drawU(UGraphic ug) { + ug.apply(new UTranslate(0, vspace)).draw(new UImage(image)); } } diff --git a/src/net/sourceforge/plantuml/graphic/TileImageSvg.java b/src/net/sourceforge/plantuml/graphic/TileImageSvg.java new file mode 100644 index 000000000..5f9769001 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/TileImageSvg.java @@ -0,0 +1,73 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 10269 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.geom.Dimension2D; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UImageSvg; + +public class TileImageSvg implements TextBlock { + + private final UImageSvg svg; + + public TileImageSvg(File svgFile) throws IOException { + this.svg = createSvg(svgFile); + } + + private UImageSvg createSvg(File svgFile) throws IOException { + final BufferedReader br = new BufferedReader(new FileReader(svgFile)); + final StringBuilder sb = new StringBuilder(); + String s; + while ((s = br.readLine()) != null) { + sb.append(s); + } + br.close(); + return new UImageSvg(sb.toString()); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return new Dimension2DDouble(svg.getWidth(), svg.getHeight()); + } + + public void drawU(UGraphic ug) { + ug.draw(svg); + } + +} diff --git a/src/net/sourceforge/plantuml/graphic/TileText.java b/src/net/sourceforge/plantuml/graphic/TileText.java index 2d7839b71..61d767ff7 100644 --- a/src/net/sourceforge/plantuml/graphic/TileText.java +++ b/src/net/sourceforge/plantuml/graphic/TileText.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,35 +28,37 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6590 $ + * Revision $Revision: 11873 $ * */ package net.sourceforge.plantuml.graphic; -import java.awt.BasicStroke; -import java.awt.FontMetrics; -import java.awt.Graphics2D; import java.awt.geom.Dimension2D; import java.util.StringTokenizer; import net.sourceforge.plantuml.Dimension2DDouble; import net.sourceforge.plantuml.Log; -import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.ugraphic.UChangeColor; import net.sourceforge.plantuml.ugraphic.UGraphic; import net.sourceforge.plantuml.ugraphic.UText; +import net.sourceforge.plantuml.ugraphic.UTranslate; -class TileText implements Tile { +public class TileText implements TextBlock { private final String text; private final FontConfiguration fontConfiguration; + private final Url url; - public TileText(String text, FontConfiguration fontConfiguration) { + public TileText(String text, FontConfiguration fontConfiguration, Url url) { this.fontConfiguration = fontConfiguration; this.text = text; + this.url = url; } public Dimension2D calculateDimension(StringBounder stringBounder) { final Dimension2D rect = stringBounder.calculateDimension(fontConfiguration.getFont(), text); + final int spaceBottom = Math.abs(fontConfiguration.getSpace()); Log.debug("g2d=" + rect); Log.debug("Size for " + text + " is " + rect); double h = rect.getHeight(); @@ -64,42 +66,23 @@ class TileText implements Tile { h = 10; } final double width = text.indexOf('\t') == -1 ? rect.getWidth() : getWidth(stringBounder); - return new Dimension2DDouble(width, h); + return new Dimension2DDouble(width, h + spaceBottom); } public double getFontSize2D() { return fontConfiguration.getFont().getSize2D(); } - public void draw(ColorMapper colorMapper, Graphics2D g2d, double x, double y) { - // TO be removed - g2d.setFont(fontConfiguration.getFont().getFont()); - g2d.setPaint(colorMapper.getMappedColor(fontConfiguration.getColor())); - g2d.drawString(text, (float) x, (float) y); - - if (fontConfiguration.containsStyle(FontStyle.UNDERLINE)) { - final Dimension2D dim = calculateDimension(StringBounderUtils.asStringBounder(g2d)); - final int ypos = (int) (y + 2.5); - g2d.setStroke(new BasicStroke((float) 1.3)); - g2d.drawLine((int) x, ypos, (int) (x + dim.getWidth()), ypos); - g2d.setStroke(new BasicStroke()); - } - if (fontConfiguration.containsStyle(FontStyle.STRIKE)) { - final Dimension2D dim = calculateDimension(StringBounderUtils.asStringBounder(g2d)); - final FontMetrics fm = g2d.getFontMetrics(fontConfiguration.getFont().getFont()); - final int ypos = (int) (y - fm.getDescent() - 0.5); - g2d.setStroke(new BasicStroke((float) 1.5)); - g2d.drawLine((int) x, ypos, (int) (x + dim.getWidth()), ypos); - g2d.setStroke(new BasicStroke()); - } - } - double getTabSize(StringBounder stringBounder) { return stringBounder.calculateDimension(fontConfiguration.getFont(), " ").getWidth(); } - public void drawU(UGraphic ug, double x, double y) { - ug.getParam().setColor(fontConfiguration.getColor()); + public void drawU(UGraphic ug) { + double x = 0; + if (url != null) { + ug.startUrl(url); + } + ug = ug.apply(new UChangeColor(fontConfiguration.getColor())); final StringTokenizer tokenizer = new StringTokenizer(text, "\t", true); @@ -112,12 +95,22 @@ class TileText implements Tile { x += tabSize - remainder; } else { final UText utext = new UText(s, fontConfiguration); - ug.draw(x, y, utext); final Dimension2D dim = ug.getStringBounder().calculateDimension(fontConfiguration.getFont(), s); + final int space = fontConfiguration.getSpace(); + final double ypos; + if (space < 0) { + ypos = space /*- getFontSize2D() - space*/; + } else { + ypos = space; + } + ug.apply(new UTranslate(x, ypos)).draw(utext); x += dim.getWidth(); } } } + if (url != null) { + ug.closeAction(); + } } double getWidth(StringBounder stringBounder) { diff --git a/src/net/sourceforge/plantuml/skin/UDrawable.java b/src/net/sourceforge/plantuml/graphic/UDrawable.java similarity index 87% rename from src/net/sourceforge/plantuml/skin/UDrawable.java rename to src/net/sourceforge/plantuml/graphic/UDrawable.java index 30862730c..1296683aa 100644 --- a/src/net/sourceforge/plantuml/skin/UDrawable.java +++ b/src/net/sourceforge/plantuml/graphic/UDrawable.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,10 +28,10 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3836 $ + * Revision $Revision: 6577 $ * */ -package net.sourceforge.plantuml.skin; +package net.sourceforge.plantuml.graphic; import net.sourceforge.plantuml.ugraphic.UGraphic; @@ -39,4 +39,4 @@ public interface UDrawable { public void drawU(UGraphic ug); -} +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/UGraphicDelegator.java b/src/net/sourceforge/plantuml/graphic/UGraphicDelegator.java new file mode 100644 index 000000000..b09b0be5a --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/UGraphicDelegator.java @@ -0,0 +1,89 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 10266 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.io.IOException; +import java.io.OutputStream; + +import net.sourceforge.plantuml.Url; +import net.sourceforge.plantuml.ugraphic.ColorMapper; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UParam; +import net.sourceforge.plantuml.ugraphic.UShape; + +public abstract class UGraphicDelegator implements UGraphic { + + final private UGraphic ug; + + public UGraphicDelegator(UGraphic ug) { + this.ug = ug; + } + + public StringBounder getStringBounder() { + return ug.getStringBounder(); + } + + public UParam getParam() { + return ug.getParam(); + } + + public void draw(UShape shape) { + ug.draw(shape); + } + + public ColorMapper getColorMapper() { + return ug.getColorMapper(); + } + + public void startUrl(Url url) { + ug.startUrl(url); + } + + public void closeAction() { + ug.closeAction(); + } + + public void writeImage(OutputStream os, String metadata, int dpi) throws IOException { + ug.writeImage(os, metadata, dpi); + } + + protected UGraphic getUg() { + return ug; + } + + public void flushUg() { + ug.flushUg(); + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/UGraphicInterceptorTextBlockable.java b/src/net/sourceforge/plantuml/graphic/UGraphicInterceptorTextBlockable.java new file mode 100644 index 000000000..2341ef1c0 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/UGraphicInterceptorTextBlockable.java @@ -0,0 +1,63 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 10266 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import net.sourceforge.plantuml.ugraphic.UChange; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UShape; + +public class UGraphicInterceptorTextBlockable extends UGraphicDelegator { + + public UGraphicInterceptorTextBlockable(UGraphic ug) { + super(ug); + } + + public void draw(UShape shape) { + if (shape instanceof TextBlockable) { + final TextBlock textBlock = ((TextBlockable) shape).asTextBlock(); + textBlock.drawU(this); + } else if (shape instanceof UDrawable) { + final UDrawable drawable = (UDrawable) shape; + drawable.drawU(this); + } else { + getUg().draw(shape); + } + + } + + public UGraphic apply(UChange change) { + return new UGraphicInterceptorTextBlockable(getUg().apply(change)); + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/USymbol.java b/src/net/sourceforge/plantuml/graphic/USymbol.java new file mode 100644 index 000000000..2dc8362b0 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/USymbol.java @@ -0,0 +1,123 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8066 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.geom.Dimension2D; +import java.util.HashMap; +import java.util.Map; + +import net.sourceforge.plantuml.Dimension2DDouble; + +public abstract class USymbol { + + private static final Map all = new HashMap(); + + public final static USymbol STORAGE = record("STORAGE", new USymbolStorage()); + public final static USymbol DATABASE = record("DATABASE", new USymbolDatabase()); + public final static USymbol CLOUD = record("CLOUD", new USymbolCloud()); + public final static USymbol FRAME = record("FRAME", new USymbolFrame()); + public final static USymbol NODE = record("NODE", new USymbolNode()); + public final static USymbol ARTIFACT = record("ARTIFACT", new USymbolArtifact()); + public final static USymbol PACKAGE = record("PACKAGE", new USymbolFolder()); + public final static USymbol FOLDER = record("FOLDER", new USymbolFolder()); + public final static USymbol RECT = record("RECT", new USymbolRect()); + public final static USymbol RECTANGLE = record("RECTANGLE", new USymbolRect()); + public final static USymbol ACTOR = record("ACTOR", new USymbolActor()); + public final static USymbol COMPONENT1 = record("COMPONENT1", new USymbolComponent1()); + public final static USymbol COMPONENT2 = record("COMPONENT2", new USymbolComponent2()); + public final static USymbol BOUNDARY = record("BOUNDARY", new USymbolBoundary()); + public final static USymbol ENTITY_DOMAIN = record("ENTITY_DOMAIN", new USymbolEntityDomain(2)); + public final static USymbol CONTROL = record("CONTROL", new USymbolControl(2)); + public final static USymbol INTERFACE = record("INTERFACE", new USymbolInterface()); + + public static USymbol getFromString(String s) { + final USymbol result = all.get(s.toUpperCase()); + if (result == null) { + if (s.equalsIgnoreCase("component")) { + return COMPONENT2; + } + throw new IllegalArgumentException("s=" + s); + } + return result; + } + + private static USymbol record(String code, USymbol symbol) { + all.put(code.toUpperCase(), symbol); + return symbol; + } + + public abstract TextBlock asSmall(TextBlock label, TextBlock stereotype, SymbolContext symbolContext); + + public abstract TextBlock asBig(TextBlock label, TextBlock stereotype, double width, double height, + SymbolContext symbolContext); + + static class Margin { + private final double x1; + private final double x2; + private final double y1; + private final double y2; + + Margin(double x1, double x2, double y1, double y2) { + this.x1 = x1; + this.x2 = x2; + this.y1 = y1; + this.y2 = y2; + } + + double getWidth() { + return x1 + x2; + } + + double getHeight() { + return y1 + y2; + } + + public Dimension2D addDimension(Dimension2D dim) { + return new Dimension2DDouble(dim.getWidth() + x1 + x2, dim.getHeight() + y1 + y2); + } + + public double getX1() { + return x1; + } + + public double getY1() { + return y1; + } + } + + public boolean manageHorizontalLine() { + return false; + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/cucadiagram/dot/LazyFile.java b/src/net/sourceforge/plantuml/graphic/USymbolActor.java similarity index 70% rename from src/net/sourceforge/plantuml/cucadiagram/dot/LazyFile.java rename to src/net/sourceforge/plantuml/graphic/USymbolActor.java index 2050bc823..537ae35bb 100644 --- a/src/net/sourceforge/plantuml/cucadiagram/dot/LazyFile.java +++ b/src/net/sourceforge/plantuml/graphic/USymbolActor.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,28 +28,19 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3977 $ + * Revision $Revision: 8066 $ * */ -package net.sourceforge.plantuml.cucadiagram.dot; +package net.sourceforge.plantuml.graphic; -import java.io.File; +import net.sourceforge.plantuml.skin.StickMan; -public class LazyFile extends LazyCached { - - public LazyFile(Lazy f) { - super(f); - } +class USymbolActor extends USymbolSimpleAbstract { @Override - public boolean isLoaded() { - if (super.isLoaded() == false) { - return false; - } - if (getRowData().exists() == false) { - return false; - } - return true; + protected TextBlock getDrawing(SymbolContext symbolContext) { + return new StickMan(symbolContext.getBackColor(), symbolContext.getForeColor(), + symbolContext.isShadowing() ? 4.0 : 0.0); } -} +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/USymbolArtifact.java b/src/net/sourceforge/plantuml/graphic/USymbolArtifact.java new file mode 100644 index 000000000..a74789364 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/USymbolArtifact.java @@ -0,0 +1,125 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8066 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.UPolygon; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +class USymbolArtifact extends USymbol { + + private void drawArtifact(UGraphic ug, double widthTotal, double heightTotal, boolean shadowing) { + + final URectangle form = new URectangle(widthTotal, heightTotal); + if (shadowing) { + form.setDeltaShadow(4); + } + + ug.draw(form); + + final UPolygon polygon = new UPolygon(); + polygon.addPoint(0, 0); + final double heightSymbol = 14; + polygon.addPoint(0, heightSymbol); + final double widthSymbol = 12; + polygon.addPoint(widthSymbol, heightSymbol); + final int cornersize = 6; + polygon.addPoint(widthSymbol, cornersize); + polygon.addPoint(widthSymbol - cornersize, 0); + polygon.addPoint(0, 0); + // if (shadowing) { + // polygon.setDeltaShadow(3.0); + // } + + final double xSymbol = widthTotal - widthSymbol - 5; + final double ySymbol = 5; + + ug.apply(new UTranslate(xSymbol, ySymbol)).draw(polygon); + ug.apply(new UTranslate(xSymbol + widthSymbol - cornersize, ySymbol)).draw(new ULine(0, cornersize)); + ug.apply(new UTranslate(xSymbol + widthSymbol, ySymbol + cornersize)).draw(new ULine(-cornersize, 0)); + + } + + private Margin getMargin() { + return new Margin(10, 10 + 10, 10 + 3, 10); + } + + public TextBlock asSmall(final TextBlock label, final TextBlock stereotype, final SymbolContext symbolContext) { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final Dimension2D dim = calculateDimension(ug.getStringBounder()); + ug = symbolContext.apply(ug); + drawArtifact(ug, dim.getWidth(), dim.getHeight(), symbolContext.isShadowing()); + final Margin margin = getMargin(); + final TextBlock tb = TextBlockUtils.mergeTB(stereotype, label, HorizontalAlignment.CENTER); + tb.drawU(ug.apply(new UTranslate(margin.getX1(), margin.getY1()))); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + final Dimension2D dimLabel = label.calculateDimension(stringBounder); + final Dimension2D dimStereo = stereotype.calculateDimension(stringBounder); + return getMargin().addDimension(Dimension2DDouble.mergeTB(dimStereo, dimLabel)); + } + }; + } + + public TextBlock asBig(final TextBlock title, final TextBlock stereotype, final double width, final double height, + final SymbolContext symbolContext) { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final Dimension2D dim = calculateDimension(ug.getStringBounder()); + ug = symbolContext.apply(ug); + drawArtifact(ug, dim.getWidth(), dim.getHeight(), symbolContext.isShadowing()); + final Dimension2D dimStereo = stereotype.calculateDimension(ug.getStringBounder()); + final double posStereo = (width - dimStereo.getWidth()) / 2; + stereotype.drawU(ug.apply(new UTranslate(posStereo, 2))); + final Dimension2D dimTitle = title.calculateDimension(ug.getStringBounder()); + final double posTitle = (width - dimTitle.getWidth()) / 2; + title.drawU(ug.apply(new UTranslate(posTitle, 2 + dimStereo.getHeight()))); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return new Dimension2DDouble(width, height); + } + }; + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/USymbolBoundary.java b/src/net/sourceforge/plantuml/graphic/USymbolBoundary.java new file mode 100644 index 000000000..2d665b71d --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/USymbolBoundary.java @@ -0,0 +1,45 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8066 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import net.sourceforge.plantuml.svek.Boundary; + +class USymbolBoundary extends USymbolSimpleAbstract { + + @Override + protected TextBlock getDrawing(final SymbolContext symbolContext) { + return new Boundary(symbolContext.getBackColor(), symbolContext.getForeColor(), + symbolContext.isShadowing() ? 4.0 : 0.0, 2); + } +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/USymbolCloud.java b/src/net/sourceforge/plantuml/graphic/USymbolCloud.java new file mode 100644 index 000000000..fe5dfaa43 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/USymbolCloud.java @@ -0,0 +1,125 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8066 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UPath; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +class USymbolCloud extends USymbol { + + private void drawCloud(UGraphic ug, double width, double height, boolean shadowing) { + final UPath shape = getSpecificFrontierForCloud(width, height); + if (shadowing) { + shape.setDeltaShadow(3.0); + } + ug.apply(new UTranslate(3, -3)).draw(shape); + } + + private UPath getSpecificFrontierForCloud(double width, double height) { + final UPath path = new UPath(); + path.moveTo(0, 10); + double x = 0; + for (int i = 0; i < width - 9; i += 10) { + path.cubicTo(i, -3 + 10, 2 + i, -5 + 10, 5 + i, -5 + 10); + path.cubicTo(8 + i, -5 + 10, 10 + i, -3 + 10, 10 + i, 10); + x = i + 10; + } + double y = 0; + for (int j = 10; j < height - 9; j += 10) { + path.cubicTo(x + 3, j, x + 5, 2 + j, x + 5, 5 + j); + path.cubicTo(x + 5, 8 + j, x + 3, 10 + j, x, 10 + j); + y = j + 10; + } + for (int i = 0; i < width - 9; i += 10) { + path.cubicTo(x - i, y + 3, x - 3 - i, y + 5, x - 5 - i, y + 5); + path.cubicTo(x - 8 - i, y + 5, x - 10 - i, y + 3, x - 10 - i, y); + } + for (int j = 0; j < height - 9 - 10; j += 10) { + path.cubicTo(-3, y - j, -5, y - 2 - j, -5, y - 5 - j); + path.cubicTo(-5, y - 8 - j, -3, y - 10 - j, 0, y - 10 - j); + } + return path; + } + + private Margin getMargin() { + return new Margin(10, 10, 10, 10); + } + + public TextBlock asSmall(final TextBlock label, final TextBlock stereotype, final SymbolContext symbolContext) { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final Dimension2D dim = calculateDimension(ug.getStringBounder()); + ug = symbolContext.apply(ug); + drawCloud(ug, dim.getWidth(), dim.getHeight(), symbolContext.isShadowing()); + final Margin margin = getMargin(); + final TextBlock tb = TextBlockUtils.mergeTB(stereotype, label, HorizontalAlignment.CENTER); + tb.drawU(ug.apply(new UTranslate(margin.getX1(), margin.getY1()))); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + final Dimension2D dimLabel = label.calculateDimension(stringBounder); + final Dimension2D dimStereo = stereotype.calculateDimension(stringBounder); + return getMargin().addDimension(Dimension2DDouble.mergeTB(dimStereo, dimLabel)); + } + }; + } + + public TextBlock asBig(final TextBlock title, final TextBlock stereotype, final double width, final double height, + final SymbolContext symbolContext) { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final Dimension2D dim = calculateDimension(ug.getStringBounder()); + ug = symbolContext.apply(ug); + drawCloud(ug, dim.getWidth(), dim.getHeight(), symbolContext.isShadowing()); + final Dimension2D dimStereo = stereotype.calculateDimension(ug.getStringBounder()); + final double posStereo = (width - dimStereo.getWidth()) / 2; + stereotype.drawU(ug.apply(new UTranslate(posStereo, 13))); + final Dimension2D dimTitle = title.calculateDimension(ug.getStringBounder()); + final double posTitle = (width - dimTitle.getWidth()) / 2; + title.drawU(ug.apply(new UTranslate(posTitle, 13 + dimStereo.getHeight()))); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return new Dimension2DDouble(width, height); + } + }; + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/USymbolComponent1.java b/src/net/sourceforge/plantuml/graphic/USymbolComponent1.java new file mode 100644 index 000000000..44ff2aae7 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/USymbolComponent1.java @@ -0,0 +1,92 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8066 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UShape; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +class USymbolComponent1 extends USymbol { + + private void drawNode(UGraphic ug, double widthTotal, double heightTotal, boolean shadowing) { + + final URectangle form = new URectangle(widthTotal, heightTotal); + if (shadowing) { + form.setDeltaShadow(4); + } + + ug.draw(form); + final UShape small = new URectangle(10, 5); + + // UML 1 Component Notation + ug.apply(new UTranslate(-5, 5)).draw(small); + ug.apply(new UTranslate(-5, heightTotal - 10)).draw(small); + + } + + private Margin getMargin() { + return new Margin(10, 10, 10, 10); + } + + public TextBlock asSmall(final TextBlock label, final TextBlock stereotype, final SymbolContext symbolContext) { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + final Dimension2D dimTotal = calculateDimension(stringBounder); + ug = symbolContext.apply(ug); + drawNode(ug, dimTotal.getWidth(), dimTotal.getHeight(), symbolContext.isShadowing()); + final Margin margin = getMargin(); + final TextBlock tb = TextBlockUtils.mergeTB(stereotype, label, HorizontalAlignment.CENTER); + tb.drawU(ug.apply(new UTranslate(margin.getX1(), margin.getY1()))); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + final Dimension2D dimLabel = label.calculateDimension(stringBounder); + final Dimension2D dimStereo = stereotype.calculateDimension(stringBounder); + return getMargin().addDimension(Dimension2DDouble.mergeTB(dimStereo, dimLabel)); + } + }; + } + + public TextBlock asBig(final TextBlock title, TextBlock stereotype, final double width, final double height, + final SymbolContext symbolContext) { + throw new UnsupportedOperationException(); + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/USymbolComponent2.java b/src/net/sourceforge/plantuml/graphic/USymbolComponent2.java new file mode 100644 index 000000000..1e2b47721 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/USymbolComponent2.java @@ -0,0 +1,105 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8066 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UShape; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +class USymbolComponent2 extends USymbol { + + private void drawNode(UGraphic ug, double widthTotal, double heightTotal, boolean shadowing) { + + final URectangle form = new URectangle(widthTotal, heightTotal); + if (shadowing) { + form.setDeltaShadow(4); + } + + final UShape small = new URectangle(15, 10); + final UShape tiny = new URectangle(4, 2); + + ug.draw(form); + + // UML 2 Component Notation + ug.apply(new UTranslate(widthTotal - 20, 5)).draw(small); + ug.apply(new UTranslate(widthTotal - 22, 7)).draw(tiny); + ug.apply(new UTranslate(widthTotal - 22, 11)).draw(tiny); + + } + + private Margin getMargin() { + return new Margin(10 + 5, 20 + 5, 15 + 5, 5 + 5); + } + + public TextBlock asSmall(final TextBlock label, TextBlock stereotype, final SymbolContext symbolContext) { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final Dimension2D dim = calculateDimension(ug.getStringBounder()); + ug = symbolContext.apply(ug); + drawNode(ug, dim.getWidth(), dim.getHeight(), symbolContext.isShadowing()); + final Margin margin = getMargin(); + label.drawU(ug.apply(new UTranslate(margin.getX1(), margin.getY1()))); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + final Dimension2D dim = label.calculateDimension(stringBounder); + return getMargin().addDimension(dim); + } + }; + } + + public TextBlock asBig(final TextBlock title, TextBlock stereotype, final double width, final double height, + final SymbolContext symbolContext) { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final Dimension2D dim = calculateDimension(ug.getStringBounder()); + ug = symbolContext.apply(ug); + drawNode(ug, dim.getWidth(), dim.getHeight(), symbolContext.isShadowing()); + title.drawU(ug.apply(new UTranslate(3, 13))); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return new Dimension2DDouble(width, height); + } + + }; + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/USymbolControl.java b/src/net/sourceforge/plantuml/graphic/USymbolControl.java new file mode 100644 index 000000000..f9c5c7d54 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/USymbolControl.java @@ -0,0 +1,52 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8066 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import net.sourceforge.plantuml.svek.Control; + +class USymbolControl extends USymbolSimpleAbstract { + + private final double thickness; + + public USymbolControl(double thickness) { + this.thickness = thickness; + } + + @Override + protected TextBlock getDrawing(final SymbolContext symbolContext) { + return new Control(symbolContext.getBackColor(), symbolContext.getForeColor(), + symbolContext.isShadowing() ? 4.0 : 0.0, thickness); + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/USymbolDatabase.java b/src/net/sourceforge/plantuml/graphic/USymbolDatabase.java new file mode 100644 index 000000000..52459c49b --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/USymbolDatabase.java @@ -0,0 +1,152 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8066 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ugraphic.AbstractUGraphicHorizontalLine; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UHorizontalLine; +import net.sourceforge.plantuml.ugraphic.UPath; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +class USymbolDatabase extends USymbol { + + private void drawDatabase(UGraphic ug, double width, double height, boolean shadowing) { + final UPath shape = new UPath(); + if (shadowing) { + shape.setDeltaShadow(3.0); + } + shape.moveTo(0, 10); + shape.cubicTo(0, 0, width / 2, 0, width / 2, 0); + shape.cubicTo(width / 2, 0, width, 0, width, 10); + shape.lineTo(width, height - 10); + shape.cubicTo(width, height, width / 2, height, width / 2, height); + shape.cubicTo(width / 2, height, 0, height, 0, height - 10); + shape.lineTo(0, 10); + + ug.draw(shape); + + final UPath closing = getClosingPath(width); + ug.apply(new UChangeBackColor(null)).draw(closing); + + } + + private UPath getClosingPath(double width) { + final UPath closing = new UPath(); + closing.moveTo(0, 10); + closing.cubicTo(0, 20, width / 2, 20, width / 2, 20); + closing.cubicTo(width / 2, 20, width, 20, width, 10); + return closing; + } + + class MyUGraphicDatabase extends AbstractUGraphicHorizontalLine { + + private final double endingX; + + @Override + protected AbstractUGraphicHorizontalLine copy(UGraphic ug) { + return new MyUGraphicDatabase(ug, endingX); + } + + public MyUGraphicDatabase(UGraphic ug, double endingX) { + super(ug); + this.endingX = endingX; + } + + @Override + protected void drawHline(UGraphic ug, UHorizontalLine line, UTranslate translate) { + final UPath closing = getClosingPath(endingX); + ug = ug.apply(translate); + ug.apply(line.getStroke()).apply(new UChangeBackColor(null)).apply(new UTranslate(0, -15)).draw(closing); + line.drawTitleInternal(ug, 0, endingX, 0, true); + } + + } + + private Margin getMargin() { + return new Margin(10, 10, 20, 5); + } + + public TextBlock asSmall(final TextBlock label, final TextBlock stereotype, final SymbolContext symbolContext) { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final Dimension2D dim = calculateDimension(ug.getStringBounder()); + ug = symbolContext.apply(ug); + drawDatabase(ug, dim.getWidth(), dim.getHeight(), symbolContext.isShadowing()); + final Margin margin = getMargin(); + final TextBlock tb = TextBlockUtils.mergeTB(stereotype, label, HorizontalAlignment.CENTER); + final UGraphic ug2 = new MyUGraphicDatabase(ug, dim.getWidth()); + tb.drawU(ug2.apply(new UTranslate(margin.getX1(), margin.getY1()))); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + final Dimension2D dimLabel = label.calculateDimension(stringBounder); + final Dimension2D dimStereo = stereotype.calculateDimension(stringBounder); + return getMargin().addDimension(Dimension2DDouble.mergeTB(dimStereo, dimLabel)); + } + }; + } + + public TextBlock asBig(final TextBlock title, final TextBlock stereotype, final double width, final double height, + final SymbolContext symbolContext) { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final Dimension2D dim = calculateDimension(ug.getStringBounder()); + ug = symbolContext.apply(ug); + drawDatabase(ug, dim.getWidth(), dim.getHeight(), symbolContext.isShadowing()); + final Dimension2D dimStereo = stereotype.calculateDimension(ug.getStringBounder()); + final double posStereo = (width - dimStereo.getWidth()) / 2; + stereotype.drawU(ug.apply(new UTranslate(posStereo, 0))); + + final Dimension2D dimTitle = title.calculateDimension(ug.getStringBounder()); + final double posTitle = (width - dimTitle.getWidth()) / 2; + title.drawU(ug.apply(new UTranslate(posTitle, 21))); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return new Dimension2DDouble(width, height); + } + }; + } + + public boolean manageHorizontalLine() { + return true; + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/USymbolEntityDomain.java b/src/net/sourceforge/plantuml/graphic/USymbolEntityDomain.java new file mode 100644 index 000000000..635e5430b --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/USymbolEntityDomain.java @@ -0,0 +1,52 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8066 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import net.sourceforge.plantuml.svek.EntityDomain; + +class USymbolEntityDomain extends USymbolSimpleAbstract { + + private final double thickness; + + public USymbolEntityDomain(double thickness) { + this.thickness = thickness; + } + + @Override + protected TextBlock getDrawing(final SymbolContext symbolContext) { + return new EntityDomain(symbolContext.getBackColor(), symbolContext.getForeColor(), + symbolContext.isShadowing() ? 4.0 : 0.0, thickness); + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/USymbolFolder.java b/src/net/sourceforge/plantuml/graphic/USymbolFolder.java new file mode 100644 index 000000000..769688296 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/USymbolFolder.java @@ -0,0 +1,138 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8066 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.UPolygon; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +class USymbolFolder extends USymbol { + + private final static int marginTitleX1 = 3; + private final static int marginTitleX2 = 3; + private final static int marginTitleX3 = 7; + private final static int marginTitleY0 = 0; + private final static int marginTitleY1 = 3; + private final static int marginTitleY2 = 3; + + private void drawFolder(UGraphic ug, double width, double height, Dimension2D dimTitle, boolean shadowing) { + + final double wtitle; + if (dimTitle.getWidth() == 0) { + wtitle = Math.max(30, width / 4); + } else { + wtitle = dimTitle.getWidth() + marginTitleX1 + marginTitleX2; + } + final double htitle = getHTitle(dimTitle); + + final UPolygon shape = new UPolygon(); + shape.addPoint(0, 0); + shape.addPoint(wtitle, 0); + + shape.addPoint(wtitle + marginTitleX3, htitle); + shape.addPoint(width, htitle); + shape.addPoint(width, height); + shape.addPoint(0, height); + shape.addPoint(0, 0); + if (shadowing) { + shape.setDeltaShadow(3.0); + } + ug.draw(shape); + ug.apply(new UTranslate(0, htitle)).draw(new ULine(wtitle + marginTitleX3, 0)); + } + + private double getHTitle(Dimension2D dimTitle) { + final double htitle; + if (dimTitle.getWidth() == 0) { + htitle = 10; + } else { + htitle = dimTitle.getHeight() + marginTitleY1 + marginTitleY2; + } + return htitle; + } + + private Margin getMargin() { + return new Margin(10, 10 + 10, 10 + 3, 10); + } + + public TextBlock asSmall(final TextBlock label, final TextBlock stereotype, final SymbolContext symbolContext) { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final Dimension2D dim = calculateDimension(ug.getStringBounder()); + ug = symbolContext.apply(ug); + drawFolder(ug, dim.getWidth(), dim.getHeight(), new Dimension2DDouble(0, 0), + symbolContext.isShadowing()); + final Margin margin = getMargin(); + final TextBlock tb = TextBlockUtils.mergeTB(stereotype, label, HorizontalAlignment.CENTER); + tb.drawU(ug.apply(new UTranslate(margin.getX1(), margin.getY1()))); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + final Dimension2D dimLabel = label.calculateDimension(stringBounder); + final Dimension2D dimStereo = stereotype.calculateDimension(stringBounder); + return getMargin().addDimension(Dimension2DDouble.mergeTB(dimStereo, dimLabel)); + } + }; + } + + public TextBlock asBig(final TextBlock title, final TextBlock stereotype, final double width, final double height, + final SymbolContext symbolContext) { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + final Dimension2D dim = calculateDimension(stringBounder); + ug = symbolContext.apply(ug); + final Dimension2D dimTitle = title.calculateDimension(stringBounder); + drawFolder(ug, dim.getWidth(), dim.getHeight(), dimTitle, symbolContext.isShadowing()); + title.drawU(ug.apply(new UTranslate(4, 2))); + final Dimension2D dimStereo = stereotype.calculateDimension(stringBounder); + final double posStereo = (width - dimStereo.getWidth()) / 2; + + stereotype.drawU(ug.apply(new UTranslate(4 + posStereo, 2 + getHTitle(dimTitle)))); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return new Dimension2DDouble(width, height); + } + + }; + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/USymbolFrame.java b/src/net/sourceforge/plantuml/graphic/USymbolFrame.java new file mode 100644 index 000000000..f28aac88d --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/USymbolFrame.java @@ -0,0 +1,131 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8066 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UPath; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +class USymbolFrame extends USymbol { + + private void drawFrame(UGraphic ug, double width, double height, Dimension2D dimTitle, boolean shadowing) { + final URectangle shape = new URectangle(width, height); + if (shadowing) { + shape.setDeltaShadow(3.0); + } + + ug.draw(shape); + + final double textWidth; + final int cornersize; + if (dimTitle.getWidth() == 0) { + textWidth = width / 3; + cornersize = 7; + } else { + textWidth = dimTitle.getWidth() + 10; + cornersize = 10; + } + final double textHeight = getYpos(dimTitle); + + final UPath polygon = new UPath(); + polygon.moveTo(textWidth, 1); + + polygon.lineTo(textWidth, textHeight - cornersize); + polygon.lineTo(textWidth - cornersize, textHeight); + + polygon.lineTo(0, textHeight); + ug.draw(polygon); + + } + + private double getYpos(Dimension2D dimTitle) { + if (dimTitle.getWidth() == 0) { + return 12; + } + return dimTitle.getHeight() + 3; + } + + private Margin getMargin() { + return new Margin(10 + 5, 20 + 5, 15 + 5, 5 + 5); + } + + public TextBlock asSmall(final TextBlock label, final TextBlock stereotype, final SymbolContext symbolContext) { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final Dimension2D dim = calculateDimension(ug.getStringBounder()); + ug = symbolContext.apply(ug); + drawFrame(ug, dim.getWidth(), dim.getHeight(), new Dimension2DDouble(0, 0), symbolContext.isShadowing()); + final Margin margin = getMargin(); + final TextBlock tb = TextBlockUtils.mergeTB(stereotype, label, HorizontalAlignment.CENTER); + tb.drawU(ug.apply(new UTranslate(margin.getX1(), margin.getY1()))); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + final Dimension2D dimLabel = label.calculateDimension(stringBounder); + final Dimension2D dimStereo = stereotype.calculateDimension(stringBounder); + return getMargin().addDimension(Dimension2DDouble.mergeTB(dimStereo, dimLabel)); + } + }; + } + + public TextBlock asBig(final TextBlock title, final TextBlock stereotype, final double width, final double height, + final SymbolContext symbolContext) { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + final Dimension2D dim = calculateDimension(stringBounder); + ug = symbolContext.apply(ug); + final Dimension2D dimTitle = title.calculateDimension(stringBounder); + drawFrame(ug, dim.getWidth(), dim.getHeight(), dimTitle, symbolContext.isShadowing()); + title.drawU(ug.apply(new UTranslate(3, 1))); + + final Dimension2D dimStereo = stereotype.calculateDimension(stringBounder); + final double posStereo = (width - dimStereo.getWidth()) / 2; + + stereotype.drawU(ug.apply(new UTranslate(4 + posStereo, 2 + getYpos(dimTitle)))); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return new Dimension2DDouble(width, height); + } + }; + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/USymbolInterface.java b/src/net/sourceforge/plantuml/graphic/USymbolInterface.java new file mode 100644 index 000000000..bf3bfccf3 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/USymbolInterface.java @@ -0,0 +1,46 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8066 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import net.sourceforge.plantuml.svek.CircleInterface2; + +class USymbolInterface extends USymbolSimpleAbstract { + + @Override + protected TextBlock getDrawing(SymbolContext symbolContext) { + return new CircleInterface2(symbolContext.getBackColor(), symbolContext.getForeColor(), + symbolContext.isShadowing() ? 4.0 : 0.0); + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/USymbolNode.java b/src/net/sourceforge/plantuml/graphic/USymbolNode.java new file mode 100644 index 000000000..8f1b85421 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/USymbolNode.java @@ -0,0 +1,113 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8066 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.UPath; +import net.sourceforge.plantuml.ugraphic.UPolygon; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +class USymbolNode extends USymbol { + + private void drawNode(UGraphic ug, double width, double height, boolean shadowing) { + final UPolygon shape = new UPolygon(); + shape.addPoint(0, 10); + shape.addPoint(10, 0); + shape.addPoint(width, 0); + shape.addPoint(width, height - 10); + shape.addPoint(width - 10, height); + shape.addPoint(0, height); + shape.addPoint(0, 10); + if (shadowing) { + shape.setDeltaShadow(2); + } + ug.draw(shape); + + ug.apply(new UTranslate(width - 10, 10)).draw(new ULine(9, -9)); + ug.apply(new UTranslate(0, 10)).draw(new ULine(width - 10, 0)); + ug.apply(new UTranslate(width - 10, 10)).draw(new ULine(0, height - 10)); + + } + + private Margin getMargin() { + return new Margin(10 + 5, 20 + 5, 15 + 5, 5 + 5); + } + + public TextBlock asSmall(final TextBlock label, final TextBlock stereotype, final SymbolContext symbolContext) { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final Dimension2D dim = calculateDimension(ug.getStringBounder()); + ug = symbolContext.apply(ug); + drawNode(ug, dim.getWidth(), dim.getHeight(), symbolContext.isShadowing()); + final Margin margin = getMargin(); + final TextBlock tb = TextBlockUtils.mergeTB(stereotype, label, HorizontalAlignment.CENTER); + tb.drawU(ug.apply(new UTranslate(margin.getX1(), margin.getY1()))); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + final Dimension2D dimLabel = label.calculateDimension(stringBounder); + final Dimension2D dimStereo = stereotype.calculateDimension(stringBounder); + return getMargin().addDimension(Dimension2DDouble.mergeTB(dimStereo, dimLabel)); + } + }; + } + + public TextBlock asBig(final TextBlock title, final TextBlock stereotype, final double width, final double height, + final SymbolContext symbolContext) { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final Dimension2D dim = calculateDimension(ug.getStringBounder()); + ug = symbolContext.apply(ug); + drawNode(ug, dim.getWidth(), dim.getHeight(), symbolContext.isShadowing()); + title.drawU(ug.apply(new UTranslate(3, 13))); + + final Dimension2D dimStereo = stereotype.calculateDimension(ug.getStringBounder()); + final double posStereo = (width - dimStereo.getWidth()) / 2; + final Dimension2D dimTitle = title.calculateDimension(ug.getStringBounder()); + stereotype.drawU(ug.apply(new UTranslate(posStereo, dimTitle.getHeight() + 13))); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return new Dimension2DDouble(width, height); + } + }; + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/USymbolRect.java b/src/net/sourceforge/plantuml/graphic/USymbolRect.java new file mode 100644 index 000000000..444349c66 --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/USymbolRect.java @@ -0,0 +1,99 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8066 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +class USymbolRect extends USymbol { + + private void drawRect(UGraphic ug, double width, double height, boolean shadowing) { + final URectangle shape = new URectangle(width, height); + if (shadowing) { + shape.setDeltaShadow(3.0); + } + ug.draw(shape); + } + + private Margin getMargin() { + return new Margin(10, 10, 10, 10); + } + + public TextBlock asSmall(final TextBlock label, final TextBlock stereotype, final SymbolContext symbolContext) { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final Dimension2D dim = calculateDimension(ug.getStringBounder()); + ug = symbolContext.apply(ug); + drawRect(ug, dim.getWidth(), dim.getHeight(), symbolContext.isShadowing()); + final Margin margin = getMargin(); + final TextBlock tb = TextBlockUtils.mergeTB(stereotype, label, HorizontalAlignment.CENTER); + tb.drawU(ug.apply(new UTranslate(margin.getX1(), margin.getY1()))); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + final Dimension2D dimLabel = label.calculateDimension(stringBounder); + final Dimension2D dimStereo = stereotype.calculateDimension(stringBounder); + return getMargin().addDimension(Dimension2DDouble.mergeTB(dimStereo, dimLabel)); + } + }; + } + + public TextBlock asBig(final TextBlock title, final TextBlock stereotype, final double width, final double height, + final SymbolContext symbolContext) { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final Dimension2D dim = calculateDimension(ug.getStringBounder()); + ug = symbolContext.apply(ug); + drawRect(ug, dim.getWidth(), dim.getHeight(), symbolContext.isShadowing()); + final Dimension2D dimStereo = stereotype.calculateDimension(ug.getStringBounder()); + final double posStereo = (width - dimStereo.getWidth()) / 2; + stereotype.drawU(ug.apply(new UTranslate(posStereo, 2))); + final Dimension2D dimTitle = title.calculateDimension(ug.getStringBounder()); + final double posTitle = (width - dimTitle.getWidth()) / 2; + title.drawU(ug.apply(new UTranslate(posTitle, 2 + dimStereo.getHeight()))); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return new Dimension2DDouble(width, height); + } + }; + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/USymbolSimpleAbstract.java b/src/net/sourceforge/plantuml/graphic/USymbolSimpleAbstract.java new file mode 100644 index 000000000..c9dd5fd6d --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/USymbolSimpleAbstract.java @@ -0,0 +1,85 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8066 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +abstract class USymbolSimpleAbstract extends USymbol { + + public TextBlock asSmall(final TextBlock label, final TextBlock stereotype, final SymbolContext symbolContext) { + if (stereotype == null) { + throw new IllegalArgumentException(); + } + final TextBlock stickman = getDrawing(symbolContext); + return new TextBlock() { + + public void drawU(UGraphic ug) { + final StringBounder stringBounder = ug.getStringBounder(); + final Dimension2D dimName = label.calculateDimension(stringBounder); + final Dimension2D dimStereo = stereotype.calculateDimension(stringBounder); + final Dimension2D dimStickMan = stickman.calculateDimension(stringBounder); + final Dimension2D dimTotal = calculateDimension(stringBounder); + final double stickmanX = (dimTotal.getWidth() - dimStickMan.getWidth()) / 2; + final double stickmanY = dimStereo.getHeight(); + ug = symbolContext.apply(ug); + stickman.drawU(ug.apply(new UTranslate(stickmanX, stickmanY))); + final double labelX = (dimTotal.getWidth() - dimName.getWidth()) / 2; + final double labelY = dimStickMan.getHeight() + dimStereo.getHeight(); + label.drawU(ug.apply(new UTranslate(labelX, labelY))); + + final double stereoX = (dimTotal.getWidth() - dimStereo.getWidth()) / 2; + stereotype.drawU(ug.apply(new UTranslate(stereoX, 0))); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + final Dimension2D dimName = label.calculateDimension(stringBounder); + final Dimension2D dimStereo = stereotype.calculateDimension(stringBounder); + final Dimension2D dimActor = stickman.calculateDimension(stringBounder); + return Dimension2DDouble.mergeLayoutT12B3(dimStereo, dimActor, dimName); + } + }; + } + + abstract protected TextBlock getDrawing(final SymbolContext symbolContext); + + public TextBlock asBig(final TextBlock title, TextBlock stereotype, final double width, final double height, + final SymbolContext symbolContext) { + throw new UnsupportedOperationException(); + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/USymbolStorage.java b/src/net/sourceforge/plantuml/graphic/USymbolStorage.java new file mode 100644 index 000000000..5743fbdcc --- /dev/null +++ b/src/net/sourceforge/plantuml/graphic/USymbolStorage.java @@ -0,0 +1,100 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 8066 $ + * + */ +package net.sourceforge.plantuml.graphic; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +class USymbolStorage extends USymbol { + + private void drawStorage(UGraphic ug, double width, double height, boolean shadowing) { + final URectangle shape = new URectangle(width, height, 70, 70); + if (shadowing) { + shape.setDeltaShadow(3.0); + } + ug.draw(shape); + } + + private Margin getMargin() { + return new Margin(10, 10, 10, 10); + } + + public TextBlock asSmall(final TextBlock label, final TextBlock stereotype, final SymbolContext symbolContext) { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final Dimension2D dim = calculateDimension(ug.getStringBounder()); + ug = symbolContext.apply(ug); + drawStorage(ug, dim.getWidth(), dim.getHeight(), symbolContext.isShadowing()); + final Margin margin = getMargin(); + final TextBlock tb = TextBlockUtils.mergeTB(stereotype, label, HorizontalAlignment.CENTER); + tb.drawU(ug.apply(new UTranslate(margin.getX1(), margin.getY1()))); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + final Dimension2D dimLabel = label.calculateDimension(stringBounder); + final Dimension2D dimStereo = stereotype.calculateDimension(stringBounder); + return getMargin().addDimension(Dimension2DDouble.mergeTB(dimStereo, dimLabel)); + } + }; + } + + public TextBlock asBig(final TextBlock title, final TextBlock stereotype, final double width, final double height, + final SymbolContext symbolContext) { + return new TextBlock() { + + public void drawU(UGraphic ug) { + final Dimension2D dim = calculateDimension(ug.getStringBounder()); + ug = symbolContext.apply(ug); + drawStorage(ug, dim.getWidth(), dim.getHeight(), symbolContext.isShadowing()); + + final Dimension2D dimStereo = stereotype.calculateDimension(ug.getStringBounder()); + final double posStereo = (width - dimStereo.getWidth()) / 2; + stereotype.drawU(ug.apply(new UTranslate(posStereo, 5))); + final Dimension2D dimTitle = title.calculateDimension(ug.getStringBounder()); + final double posTitle = (width - dimTitle.getWidth()) / 2; + title.drawU(ug.apply(new UTranslate(posTitle, 7 + dimStereo.getHeight()))); + } + + public Dimension2D calculateDimension(StringBounder stringBounder) { + return new Dimension2DDouble(width, height); + } + }; + } + +} \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/UnusedSpace.java b/src/net/sourceforge/plantuml/graphic/UnusedSpace.java index e37f3872a..f3c3890fe 100644 --- a/src/net/sourceforge/plantuml/graphic/UnusedSpace.java +++ b/src/net/sourceforge/plantuml/graphic/UnusedSpace.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public diff --git a/src/net/sourceforge/plantuml/graphic/UDrawable3.java b/src/net/sourceforge/plantuml/graphic/VerticalAlignment.java similarity index 80% rename from src/net/sourceforge/plantuml/graphic/UDrawable3.java rename to src/net/sourceforge/plantuml/graphic/VerticalAlignment.java index 489604d3f..9bd2a10f2 100644 --- a/src/net/sourceforge/plantuml/graphic/UDrawable3.java +++ b/src/net/sourceforge/plantuml/graphic/VerticalAlignment.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,15 +28,11 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6577 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graphic; -import net.sourceforge.plantuml.ugraphic.UGraphic; - -public interface UDrawable3 { - - void drawU(UGraphic ug, double x, double y); - +public enum VerticalAlignment { + TOP, CENTER; } \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/graphic/VerticalPosition.java b/src/net/sourceforge/plantuml/graphic/VerticalPosition.java index c5da11e9e..3c15be203 100644 --- a/src/net/sourceforge/plantuml/graphic/VerticalPosition.java +++ b/src/net/sourceforge/plantuml/graphic/VerticalPosition.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 3834 $ + * Revision $Revision: 9786 $ * */ package net.sourceforge.plantuml.graphic; diff --git a/src/net/sourceforge/plantuml/hector/Box2D.java b/src/net/sourceforge/plantuml/hector/Box2D.java new file mode 100644 index 000000000..732fe13ce --- /dev/null +++ b/src/net/sourceforge/plantuml/hector/Box2D.java @@ -0,0 +1,79 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 9786 $ + * + */ +package net.sourceforge.plantuml.hector; + +import java.awt.geom.Dimension2D; + +import net.sourceforge.plantuml.geom.LineSegmentDouble; + +public class Box2D { + + final private double x1; + final private double y1; + final private double x2; + final private double y2; + + private Box2D(double x1, double y1, double x2, double y2) { + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; + } + + public static Box2D create(double x, double y, Dimension2D dim) { + return new Box2D(x, y, x + dim.getWidth(), y + dim.getHeight()); + } + + @Override + public String toString() { + return "Box [" + x1 + "," + y1 + "] [" + x2 + "," + y2 + "]"; + } + + public boolean doesIntersect(LineSegmentDouble seg) { + if (seg.doesIntersect(new LineSegmentDouble(x1, y1, x2, y1))) { + return true; + } + if (seg.doesIntersect(new LineSegmentDouble(x2, y1, x2, y2))) { + return true; + } + if (seg.doesIntersect(new LineSegmentDouble(x2, y2, x1, y2))) { + return true; + } + if (seg.doesIntersect(new LineSegmentDouble(x1, y2, x1, y1))) { + return true; + } + return false; + } + +} diff --git a/src/net/sourceforge/plantuml/hector/CucaDiagramFileMakerHector.java b/src/net/sourceforge/plantuml/hector/CucaDiagramFileMakerHector.java new file mode 100644 index 000000000..7c69920ab --- /dev/null +++ b/src/net/sourceforge/plantuml/hector/CucaDiagramFileMakerHector.java @@ -0,0 +1,104 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 6711 $ + * + */ +package net.sourceforge.plantuml.hector; + +import java.awt.geom.Dimension2D; +import java.io.IOException; +import java.io.OutputStream; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.api.ImageDataSimple; +import net.sourceforge.plantuml.core.ImageData; +import net.sourceforge.plantuml.cucadiagram.CucaDiagram; +import net.sourceforge.plantuml.cucadiagram.ILeaf; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.svek.CucaDiagramFileMaker; +import net.sourceforge.plantuml.svek.CucaDiagramFileMakerSvek2; +import net.sourceforge.plantuml.svek.IEntityImage; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class CucaDiagramFileMakerHector implements CucaDiagramFileMaker { + + private final CucaDiagram diagram; + + public CucaDiagramFileMakerHector(CucaDiagram diagram) { + this.diagram = diagram; + } + + final private Map images = new LinkedHashMap(); + + public ImageData createFile(OutputStream os, List dotStrings, FileFormatOption fileFormatOption) + throws IOException { + double singleWidth = 0; + double singleHeight = 0; + int nb = 0; + for (ILeaf leaf : diagram.getLeafs().values()) { + final IEntityImage image = computeImage(leaf); + final Dimension2D dim = TextBlockUtils.getDimension(image); + if (dim.getWidth() > singleWidth) { + singleWidth = dim.getWidth(); + } + if (dim.getHeight() > singleHeight) { + singleHeight = dim.getHeight(); + } + images.put(leaf, image); + nb++; + } + final double margin = 10; + final Dimension2D dim = new Dimension2DDouble(2 * margin + nb * singleWidth, singleHeight + 2 * margin); + UGraphic ug = fileFormatOption.createUGraphic(diagram.getColorMapper(), diagram.getDpiFactor(fileFormatOption), + dim, null, false); + ug = ug.apply(new UTranslate(margin, margin)); + + double pos = 0; + for (IEntityImage im : images.values()) { + im.drawU(ug.apply(new UTranslate(pos, 0))); + pos += singleWidth; + } + + ug.writeImage(os, null, diagram.getDpi(fileFormatOption)); + return new ImageDataSimple(dim); + } + + private IEntityImage computeImage(final ILeaf leaf) { + final IEntityImage image = CucaDiagramFileMakerSvek2.createEntityImageBlock(leaf, diagram.getSkinParam(), + false, diagram, null); + return image; + } +} diff --git a/src/net/sourceforge/plantuml/hector/CucaDiagramFileMakerHector2.java b/src/net/sourceforge/plantuml/hector/CucaDiagramFileMakerHector2.java new file mode 100644 index 000000000..2f3e01deb --- /dev/null +++ b/src/net/sourceforge/plantuml/hector/CucaDiagramFileMakerHector2.java @@ -0,0 +1,178 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 6711 $ + * + */ +package net.sourceforge.plantuml.hector; + +import java.awt.geom.Dimension2D; +import java.io.IOException; +import java.io.OutputStream; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.api.ImageDataSimple; +import net.sourceforge.plantuml.core.ImageData; +import net.sourceforge.plantuml.cucadiagram.CucaDiagram; +import net.sourceforge.plantuml.cucadiagram.ILeaf; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.svek.CucaDiagramFileMaker; +import net.sourceforge.plantuml.svek.CucaDiagramFileMakerSvek2; +import net.sourceforge.plantuml.svek.IEntityImage; +import net.sourceforge.plantuml.ugraphic.MinMax; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.UStroke; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class CucaDiagramFileMakerHector2 implements CucaDiagramFileMaker { + + private final CucaDiagram diagram; + private SkeletonConfiguration configuration; + + private double singleWidth; + private double singleHeight; + private double nodeMargin = 40; + + public CucaDiagramFileMakerHector2(CucaDiagram diagram) { + this.diagram = diagram; + } + + final private Map images = new LinkedHashMap(); + + final private Map links = new LinkedHashMap(); + + private double getX(Pin pin) { + return singleWidth * configuration.getCol(pin); + } + + private double getY(Pin pin) { + return singleHeight * pin.getRow(); + } + + private double getCenterX(Pin pin) { + return singleWidth * configuration.getCol(pin) + singleWidth / 2.0; + } + + private double getCenterY(Pin pin) { + return singleHeight * pin.getRow() + singleHeight / 2.0; + } + + public ImageData createFile(OutputStream os, List dotStrings, FileFormatOption fileFormatOption) + throws IOException { + final PinFactory pinFactory = new PinFactory(); + final SkeletonBuilder skeletonBuilder = new SkeletonBuilder(); + for (Link link : diagram.getLinks()) { + final PinLink pinLink = pinFactory.createPinLink(link); + links.put(link, pinLink); + skeletonBuilder.add(pinLink); + } + + final Skeleton skeleton = skeletonBuilder.createSkeletons().get(0); + this.configuration = SkeletonConfiguration.getDefault(skeleton); + + this.singleWidth = 0; + this.singleHeight = 0; + + for (Pin pin : skeleton.getPins()) { + final ILeaf leaf = (ILeaf) pin.getUserData(); + final IEntityImage image = computeImage(leaf); + final Dimension2D dim = TextBlockUtils.getDimension(image); + if (dim.getWidth() > singleWidth) { + singleWidth = dim.getWidth(); + } + if (dim.getHeight() > singleHeight) { + singleHeight = dim.getHeight(); + } + images.put(pin, image); + } + singleHeight += nodeMargin; + singleWidth += nodeMargin; + + MinMax minMax = MinMax.getEmpty(false); + for (Pin pin : skeleton.getPins()) { + minMax = minMax.addPoint(getX(pin), getY(pin)); + minMax = minMax.addPoint(getX(pin) + singleWidth, getY(pin) + singleHeight); + } + + final double borderMargin = 10; + + final Dimension2D dimTotal = new Dimension2DDouble(2 * borderMargin + minMax.getMaxX(), 2 * borderMargin + + minMax.getMaxY()); + UGraphic ug = fileFormatOption.createUGraphic(diagram.getColorMapper(), diagram.getDpiFactor(fileFormatOption), + dimTotal, null, false); + ug = ug.apply(new UTranslate(borderMargin, borderMargin)); + + for (PinLink pinLink : skeleton.getPinLinks()) { + drawPinLink(ug, pinLink); + } + + for (Map.Entry ent : images.entrySet()) { + final Pin pin = ent.getKey(); + final IEntityImage im = ent.getValue(); + final double x = getX(pin); + final double y = getY(pin); + final Dimension2D dimImage = im.calculateDimension(ug.getStringBounder()); + im.drawU(ug.apply(new UTranslate(x + (singleWidth - dimImage.getWidth()) / 2, y + + (singleHeight - dimImage.getHeight()) / 2))); + } + + ug.writeImage(os, null, diagram.getDpi(fileFormatOption)); + return new ImageDataSimple(dimTotal); + } + + private void drawPinLink(UGraphic ug, PinLink pinLink) { + final Rose rose = new Rose(); + final HtmlColor color = rose.getHtmlColor(diagram.getSkinParam(), ColorParam.classArrow); + ug = ug.apply(new UChangeColor(color)).apply(new UStroke(1.5)); + final double x1 = getCenterX(pinLink.getPin1()); + final double y1 = getCenterY(pinLink.getPin1()); + final double x2 = getCenterX(pinLink.getPin2()); + final double y2 = getCenterY(pinLink.getPin2()); + ug = ug.apply(new UTranslate(x1, y1)); + ug.draw(new ULine(x2 - x1, y2 - y1)); + + } + + private IEntityImage computeImage(final ILeaf leaf) { + final IEntityImage image = CucaDiagramFileMakerSvek2.createEntityImageBlock(leaf, diagram.getSkinParam(), + false, diagram, null); + return image; + } +} diff --git a/src/net/sourceforge/plantuml/hector/CucaDiagramFileMakerHector3.java b/src/net/sourceforge/plantuml/hector/CucaDiagramFileMakerHector3.java new file mode 100644 index 000000000..ea1b0d885 --- /dev/null +++ b/src/net/sourceforge/plantuml/hector/CucaDiagramFileMakerHector3.java @@ -0,0 +1,178 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 6711 $ + * + */ +package net.sourceforge.plantuml.hector; + +import java.awt.geom.Dimension2D; +import java.io.IOException; +import java.io.OutputStream; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.api.ImageDataSimple; +import net.sourceforge.plantuml.core.ImageData; +import net.sourceforge.plantuml.cucadiagram.CucaDiagram; +import net.sourceforge.plantuml.cucadiagram.ILeaf; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.svek.CucaDiagramFileMaker; +import net.sourceforge.plantuml.svek.CucaDiagramFileMakerSvek2; +import net.sourceforge.plantuml.svek.IEntityImage; +import net.sourceforge.plantuml.ugraphic.MinMax; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.ULine; +import net.sourceforge.plantuml.ugraphic.UStroke; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class CucaDiagramFileMakerHector3 implements CucaDiagramFileMaker { + + private final CucaDiagram diagram; + private SkeletonConfiguration configuration; + + private double singleWidth; + private double singleHeight; + private double nodeMargin = 40; + + public CucaDiagramFileMakerHector3(CucaDiagram diagram) { + this.diagram = diagram; + } + + final private Map images = new LinkedHashMap(); + + final private Map links = new LinkedHashMap(); + + private double getX(Pin pin) { + return singleWidth * configuration.getCol(pin); + } + + private double getY(Pin pin) { + return singleHeight * pin.getRow(); + } + + private double getCenterX(Pin pin) { + return singleWidth * configuration.getCol(pin) + singleWidth / 2.0; + } + + private double getCenterY(Pin pin) { + return singleHeight * pin.getRow() + singleHeight / 2.0; + } + + public ImageData createFile(OutputStream os, List dotStrings, FileFormatOption fileFormatOption) + throws IOException { + final PinFactory pinFactory = new PinFactory(); + final SkeletonBuilder skeletonBuilder = new SkeletonBuilder(); + for (Link link : diagram.getLinks()) { + final PinLink pinLink = pinFactory.createPinLink(link); + links.put(link, pinLink); + skeletonBuilder.add(pinLink); + } + + final Skeleton skeleton = skeletonBuilder.createSkeletons().get(0); + this.configuration = SkeletonConfiguration.getDefault(skeleton); + + this.singleWidth = 0; + this.singleHeight = 0; + + for (Pin pin : skeleton.getPins()) { + final ILeaf leaf = (ILeaf) pin.getUserData(); + final IEntityImage image = computeImage(leaf); + final Dimension2D dim = TextBlockUtils.getDimension(image); + if (dim.getWidth() > singleWidth) { + singleWidth = dim.getWidth(); + } + if (dim.getHeight() > singleHeight) { + singleHeight = dim.getHeight(); + } + images.put(pin, image); + } + singleHeight += nodeMargin; + singleWidth += nodeMargin; + + MinMax minMax = MinMax.getEmpty(false); + for (Pin pin : skeleton.getPins()) { + minMax = minMax.addPoint(getX(pin), getY(pin)); + minMax = minMax.addPoint(getX(pin) + singleWidth, getY(pin) + singleHeight); + } + + final double borderMargin = 10; + + final Dimension2D dimTotal = new Dimension2DDouble(2 * borderMargin + minMax.getMaxX(), 2 * borderMargin + + minMax.getMaxY()); + UGraphic ug = fileFormatOption.createUGraphic(diagram.getColorMapper(), diagram.getDpiFactor(fileFormatOption), + dimTotal, null, false); + ug = ug.apply(new UTranslate(borderMargin, borderMargin)); + + for (PinLink pinLink : skeleton.getPinLinks()) { + drawPinLink(ug, pinLink); + } + + for (Map.Entry ent : images.entrySet()) { + final Pin pin = ent.getKey(); + final IEntityImage im = ent.getValue(); + final double x = getX(pin); + final double y = getY(pin); + final Dimension2D dimImage = im.calculateDimension(ug.getStringBounder()); + im.drawU(ug.apply(new UTranslate(x + (singleWidth - dimImage.getWidth()) / 2, y + + (singleHeight - dimImage.getHeight()) / 2))); + } + + ug.writeImage(os, null, diagram.getDpi(fileFormatOption)); + return new ImageDataSimple(dimTotal); + } + + private void drawPinLink(UGraphic ug, PinLink pinLink) { + final Rose rose = new Rose(); + final HtmlColor color = rose.getHtmlColor(diagram.getSkinParam(), ColorParam.classArrow); + ug = ug.apply(new UChangeColor(color)).apply(new UStroke(1.5)); + final double x1 = getCenterX(pinLink.getPin1()); + final double y1 = getCenterY(pinLink.getPin1()); + final double x2 = getCenterX(pinLink.getPin2()); + final double y2 = getCenterY(pinLink.getPin2()); + ug = ug.apply(new UTranslate(x1, y1)); + ug.draw(new ULine(x2 - x1, y2 - y1)); + + } + + private IEntityImage computeImage(final ILeaf leaf) { + final IEntityImage image = CucaDiagramFileMakerSvek2.createEntityImageBlock(leaf, diagram.getSkinParam(), + false, diagram, null); + return image; + } +} diff --git a/src/net/sourceforge/plantuml/hector/CucaDiagramFileMakerHector4.java b/src/net/sourceforge/plantuml/hector/CucaDiagramFileMakerHector4.java new file mode 100644 index 000000000..e28e76d3a --- /dev/null +++ b/src/net/sourceforge/plantuml/hector/CucaDiagramFileMakerHector4.java @@ -0,0 +1,194 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 6711 $ + * + */ +package net.sourceforge.plantuml.hector; + +import java.awt.geom.Dimension2D; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.api.ImageDataSimple; +import net.sourceforge.plantuml.core.ImageData; +import net.sourceforge.plantuml.cucadiagram.CucaDiagram; +import net.sourceforge.plantuml.cucadiagram.ILeaf; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.svek.CucaDiagramFileMaker; +import net.sourceforge.plantuml.svek.CucaDiagramFileMakerSvek2; +import net.sourceforge.plantuml.svek.IEntityImage; +import net.sourceforge.plantuml.ugraphic.MinMax; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class CucaDiagramFileMakerHector4 implements CucaDiagramFileMaker { + + private final CucaDiagram diagram; + private SkeletonConfiguration configuration; + + private double singleWidth; + private double singleHeight; + private double nodeMargin = 40; + + public CucaDiagramFileMakerHector4(CucaDiagram diagram) { + this.diagram = diagram; + } + + final private Map images = new LinkedHashMap(); + final private Map boxes = new LinkedHashMap(); + + final private Map links = new LinkedHashMap(); + + final private List forbidden = new ArrayList(); + + private double getX(Pin pin) { + return singleWidth * configuration.getCol(pin); + } + + private double getY(Pin pin) { + return singleHeight * pin.getRow(); + } + + private double getCenterX(Pin pin) { + return singleWidth * configuration.getCol(pin) + singleWidth / 2.0; + } + + private double getCenterY(Pin pin) { + return singleHeight * pin.getRow() + singleHeight / 2.0; + } + + public ImageData createFile(OutputStream os, List dotStrings, FileFormatOption fileFormatOption) + throws IOException { + final PinFactory pinFactory = new PinFactory(); + final SkeletonBuilder skeletonBuilder = new SkeletonBuilder(); + links.clear(); + for (Link link : diagram.getLinks()) { + final PinLink pinLink = pinFactory.createPinLink(link); + links.put(link, pinLink); + skeletonBuilder.add(pinLink); + } + + final Skeleton skeleton = skeletonBuilder.createSkeletons().get(0); + this.configuration = SkeletonConfigurationUtils.getBest(skeleton); + + this.singleWidth = 0; + this.singleHeight = 0; + + images.clear(); + for (Pin pin : skeleton.getPins()) { + final ILeaf leaf = (ILeaf) pin.getUserData(); + final IEntityImage image = computeImage(leaf); + final Dimension2D dim = TextBlockUtils.getDimension(image); + if (dim.getWidth() > singleWidth) { + singleWidth = dim.getWidth(); + } + if (dim.getHeight() > singleHeight) { + singleHeight = dim.getHeight(); + } + images.put(pin, image); + } + singleHeight += nodeMargin; + singleWidth += nodeMargin; + + MinMax minMax = MinMax.getEmpty(false); + for (Pin pin : skeleton.getPins()) { + minMax = minMax.addPoint(getX(pin), getY(pin)); + minMax = minMax.addPoint(getX(pin) + singleWidth, getY(pin) + singleHeight); + } + + final double borderMargin = 10; + + final Dimension2D dimTotal = new Dimension2DDouble(2 * borderMargin + minMax.getMaxX(), 2 * borderMargin + + minMax.getMaxY()); + UGraphic ug = fileFormatOption.createUGraphic(diagram.getColorMapper(), diagram.getDpiFactor(fileFormatOption), + dimTotal, null, false); + ug = ug.apply(new UTranslate(borderMargin, borderMargin)); + + forbidden.clear(); + for (Map.Entry ent : images.entrySet()) { + final Pin pin = ent.getKey(); + final IEntityImage im = ent.getValue(); + final Dimension2D dimImage = im.calculateDimension(ug.getStringBounder()); + final double x = getX(pin) + (singleWidth - dimImage.getWidth()) / 2; + final double y = getY(pin) + (singleHeight - dimImage.getHeight()) / 2; + final Box2D box = Box2D.create(x, y, dimImage); + boxes.put(pin, box); + forbidden.add(box); + } + + for (PinLink pinLink : skeleton.getPinLinks()) { + drawPinLink(ug, pinLink); + } + + for (Map.Entry ent : images.entrySet()) { + final Pin pin = ent.getKey(); + final IEntityImage im = ent.getValue(); + final Dimension2D dimImage = im.calculateDimension(ug.getStringBounder()); + final double x = getX(pin) + (singleWidth - dimImage.getWidth()) / 2; + final double y = getY(pin) + (singleHeight - dimImage.getHeight()) / 2; + im.drawU(ug.apply(new UTranslate(x, y))); + } + + ug.writeImage(os, null, diagram.getDpi(fileFormatOption)); + return new ImageDataSimple(dimTotal); + } + + private void drawPinLink(UGraphic ug, PinLink pinLink) { + final double x1 = getCenterX(pinLink.getPin1()); + final double y1 = getCenterY(pinLink.getPin1()); + final double x2 = getCenterX(pinLink.getPin2()); + final double y2 = getCenterY(pinLink.getPin2()); + + final Rose rose = new Rose(); + final HtmlColor color = rose.getHtmlColor(diagram.getSkinParam(), ColorParam.classArrow); + final List b = new ArrayList(forbidden); + b.remove(boxes.get(pinLink.getPin1())); + b.remove(boxes.get(pinLink.getPin2())); + final SmartConnection connection = new SmartConnection(x1, y1, x2, y2, b); + connection.draw(ug, color); + } + + private IEntityImage computeImage(final ILeaf leaf) { + final IEntityImage image = CucaDiagramFileMakerSvek2.createEntityImageBlock(leaf, diagram.getSkinParam(), + false, diagram, null); + return image; + } +} diff --git a/src/net/sourceforge/plantuml/hector/CucaDiagramFileMakerHectorB1.java b/src/net/sourceforge/plantuml/hector/CucaDiagramFileMakerHectorB1.java new file mode 100644 index 000000000..e161572c6 --- /dev/null +++ b/src/net/sourceforge/plantuml/hector/CucaDiagramFileMakerHectorB1.java @@ -0,0 +1,166 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 6711 $ + * + */ +package net.sourceforge.plantuml.hector; + +import java.awt.geom.Dimension2D; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.api.ImageDataSimple; +import net.sourceforge.plantuml.core.ImageData; +import net.sourceforge.plantuml.cucadiagram.CucaDiagram; +import net.sourceforge.plantuml.cucadiagram.ILeaf; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.svek.CucaDiagramFileMaker; +import net.sourceforge.plantuml.svek.CucaDiagramFileMakerSvek2; +import net.sourceforge.plantuml.svek.IEntityImage; +import net.sourceforge.plantuml.ugraphic.MinMax; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UEllipse; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class CucaDiagramFileMakerHectorB1 implements CucaDiagramFileMaker { + + private final CucaDiagram diagram; + private SkeletonConfiguration configuration; + + // private double singleWidth; + // private double singleHeight; + private double nodeMargin = 40; + + public CucaDiagramFileMakerHectorB1(CucaDiagram diagram) { + this.diagram = diagram; + } + + // final private Map images = new LinkedHashMap(); + // final private Map boxes = new LinkedHashMap(); + + final private Map links = new LinkedHashMap(); + + // final private List forbidden = new ArrayList(); + + private double getX(Pin pin) { + return nodeMargin * configuration.getCol(pin); + } + + private double getY(Pin pin) { + return nodeMargin * pin.getRow(); + } + + // private double getCenterX(Pin pin) { + // return singleWidth * configuration.getCol(pin) + singleWidth / 2.0; + // } + // + // private double getCenterY(Pin pin) { + // return singleHeight * pin.getRow() + singleHeight / 2.0; + // } + + public ImageData createFile(OutputStream os, List dotStrings, FileFormatOption fileFormatOption) + throws IOException { + final PinFactory pinFactory = new PinFactory(); + final SkeletonBuilder skeletonBuilder = new SkeletonBuilder(); + links.clear(); + for (Link link : diagram.getLinks()) { + final PinLink pinLink = pinFactory.createPinLink(link); + links.put(link, pinLink); + skeletonBuilder.add(pinLink); + } + + final Skeleton skeleton = skeletonBuilder.createSkeletons().get(0); + this.configuration = SkeletonConfigurationUtils.getBest(skeleton); + + MinMax minMax = MinMax.getEmpty(false); + for (Pin pin : skeleton.getPins()) { + minMax = minMax.addPoint(getX(pin), getY(pin)); + } + + final double borderMargin = 10; + + final Dimension2D dimTotal = new Dimension2DDouble(2 * borderMargin + minMax.getMaxX(), 2 * borderMargin + + minMax.getMaxY()); + UGraphic ug = fileFormatOption.createUGraphic(diagram.getColorMapper(), diagram.getDpiFactor(fileFormatOption), + dimTotal, null, false); + ug = ug.apply(new UTranslate(borderMargin, borderMargin)); + + for (PinLink pinLink : skeleton.getPinLinks()) { + drawPinLink(ug, pinLink); + } + + for (Pin pin : skeleton.getPins()) { + drawPin(ug, pin); + } + + ug.writeImage(os, null, diagram.getDpi(fileFormatOption)); + return new ImageDataSimple(dimTotal); + } + + private void drawPin(UGraphic ug, Pin pin) { + final double x = getX(pin); + final double y = getY(pin); + final UEllipse circle = new UEllipse(6, 6); + ug.apply(new UChangeColor(HtmlColorUtils.BLACK)).apply(new UChangeBackColor(HtmlColorUtils.BLACK)) + .apply(new UTranslate(x - 3, y - 3)).draw(circle); + } + + private void drawPinLink(UGraphic ug, PinLink pinLink) { + final double x1 = getX(pinLink.getPin1()); + final double y1 = getY(pinLink.getPin1()); + final double x2 = getX(pinLink.getPin2()); + final double y2 = getY(pinLink.getPin2()); + + final Rose rose = new Rose(); + final HtmlColor color = rose.getHtmlColor(diagram.getSkinParam(), ColorParam.classArrow); + final List b = new ArrayList(); + final SmartConnection connection = new SmartConnection(x1, y1, x2, y2, b); + connection.draw(ug, color); + } + + private IEntityImage computeImage(final ILeaf leaf) { + final IEntityImage image = CucaDiagramFileMakerSvek2.createEntityImageBlock(leaf, diagram.getSkinParam(), + false, diagram, null); + return image; + } +} diff --git a/src/net/sourceforge/plantuml/hector/CucaDiagramFileMakerHectorB2.java b/src/net/sourceforge/plantuml/hector/CucaDiagramFileMakerHectorB2.java new file mode 100644 index 000000000..210c342b5 --- /dev/null +++ b/src/net/sourceforge/plantuml/hector/CucaDiagramFileMakerHectorB2.java @@ -0,0 +1,200 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * [Java is a trademark or registered trademark of Sun Microsystems, Inc. + * in the United States and other countries.] + * + * Original Author: Arnaud Roques + * + * Revision $Revision: 6711 $ + * + */ +package net.sourceforge.plantuml.hector; + +import java.awt.geom.Dimension2D; +import java.awt.geom.Point2D; +import java.io.IOException; +import java.io.OutputStream; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import net.sourceforge.plantuml.ColorParam; +import net.sourceforge.plantuml.Dimension2DDouble; +import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.api.ImageDataSimple; +import net.sourceforge.plantuml.core.ImageData; +import net.sourceforge.plantuml.cucadiagram.CucaDiagram; +import net.sourceforge.plantuml.cucadiagram.ILeaf; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.graphic.TextBlockUtils; +import net.sourceforge.plantuml.skin.rose.Rose; +import net.sourceforge.plantuml.svek.CucaDiagramFileMaker; +import net.sourceforge.plantuml.svek.CucaDiagramFileMakerSvek2; +import net.sourceforge.plantuml.svek.IEntityImage; +import net.sourceforge.plantuml.ugraphic.MinMax; +import net.sourceforge.plantuml.ugraphic.UChangeBackColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.URectangle; +import net.sourceforge.plantuml.ugraphic.UShape; +import net.sourceforge.plantuml.ugraphic.UTranslate; + +public class CucaDiagramFileMakerHectorB2 implements CucaDiagramFileMaker { + + private final CucaDiagram diagram; + private SkeletonConfiguration configuration; + + private double singleWidth; + private double singleHeight; + private double nodeDistanceX = 30; + private double nodeDistanceY = 50; + + private UnlinarCompressedPlan unlinarCompressedPlan; + + public CucaDiagramFileMakerHectorB2(CucaDiagram diagram) { + this.diagram = diagram; + } + + final private Map images = new LinkedHashMap(); + // final private Map boxes = new LinkedHashMap(); + + final private Map links = new LinkedHashMap(); + + // final private List forbidden = new ArrayList(); + + private double getX(Pin pin) { + return nodeDistanceX * configuration.getCol(pin); + } + + private double getY(Pin pin) { + return nodeDistanceY * pin.getRow(); + } + + private Point2D getPoint(Pin pin) { + return new Point2D.Double(getX(pin), getY(pin)); + } + + // private double getCenterX(Pin pin) { + // return singleWidth * configuration.getCol(pin) + singleWidth / 2.0; + // } + // + // private double getCenterY(Pin pin) { + // return singleHeight * pin.getRow() + singleHeight / 2.0; + // } + + public ImageData createFile(OutputStream os, List dotStrings, FileFormatOption fileFormatOption) + throws IOException { + final PinFactory pinFactory = new PinFactory(); + final SkeletonBuilder skeletonBuilder = new SkeletonBuilder(); + links.clear(); + for (Link link : diagram.getLinks()) { + final PinLink pinLink = pinFactory.createPinLink(link); + links.put(link, pinLink); + skeletonBuilder.add(pinLink); + } + + final Skeleton skeleton = skeletonBuilder.createSkeletons().get(0); + this.configuration = SkeletonConfigurationUtils.getBest(skeleton); + + this.singleWidth = 0; + this.singleHeight = 0; + + images.clear(); + for (Pin pin : skeleton.getPins()) { + final ILeaf leaf = (ILeaf) pin.getUserData(); + final IEntityImage image = computeImage(leaf); + final Dimension2D dim = TextBlockUtils.getDimension(image); + if (dim.getWidth() > singleWidth) { + singleWidth = dim.getWidth(); + } + if (dim.getHeight() > singleHeight) { + singleHeight = dim.getHeight(); + } + images.put(pin, image); + } + + unlinarCompressedPlan = new UnlinarCompressedPlan(singleWidth, nodeDistanceX, singleHeight, nodeDistanceY); + + MinMax minMax = MinMax.getEmpty(false); + for (Pin pin : skeleton.getPins()) { + minMax = minMax.addPoint(unlinarCompressedPlan.uncompress(getX(pin), getY(pin), + UnlinearCompression.Rounding.BORDER_2)); + } + + final double borderMargin = 10; + + final Dimension2D dimTotal = new Dimension2DDouble(2 * borderMargin + minMax.getMaxX(), 2 * borderMargin + + minMax.getMaxY()); + UGraphic ug = fileFormatOption.createUGraphic(diagram.getColorMapper(), diagram.getDpiFactor(fileFormatOption), + dimTotal, null, false); + ug = ug.apply(new UTranslate(borderMargin, borderMargin)); + + for (PinLink pinLink : skeleton.getPinLinks()) { + drawPinLink(ug, pinLink); + } + + for (Pin pin : skeleton.getPins()) { + drawPin(ug, pin); + } + + ug.writeImage(os, null, diagram.getDpi(fileFormatOption)); + return new ImageDataSimple(dimTotal); + } + + private void drawPin(UGraphic ug, Pin pin) { + final Point2D pt = unlinarCompressedPlan.uncompress(getPoint(pin), UnlinearCompression.Rounding.BORDER_1); + + final double x = pt.getX(); + final double y = pt.getY(); + final UShape rect = new URectangle(unlinarCompressedPlan.getInnerX(), unlinarCompressedPlan.getInnerY()); + ug.apply(new UChangeColor(HtmlColorUtils.BLACK)).apply(new UChangeBackColor(HtmlColorUtils.BLACK)).apply( + new UTranslate(x, y)).draw(rect); + } + + private void drawPinLink(UGraphic ug, PinLink pinLink) { + final Point2D pp1 = getPoint(pinLink.getPin1()); + final Point2D pp2 = getPoint(pinLink.getPin2()); + + final Rose rose = new Rose(); + final HtmlColor color = rose.getHtmlColor(diagram.getSkinParam(), ColorParam.classArrow); + + final HectorPath path = unlinarCompressedPlan.uncompressSegment(pp1, pp2); + path.draw(ug, color); + +// final Point2D p1 = unlinarCompressedPlan.uncompress(pp1, UnlinearCompression.Rounding.CENTRAL); +// final Point2D p2 = unlinarCompressedPlan.uncompress(pp2, UnlinearCompression.Rounding.CENTRAL); +// final SmartConnection connection = new SmartConnection(p1, p2, new ArrayList()); +// connection.draw(ug, color); + } + + private IEntityImage computeImage(final ILeaf leaf) { + final IEntityImage image = CucaDiagramFileMakerSvek2.createEntityImageBlock(leaf, diagram.getSkinParam(), + false, diagram, null); + return image; + } +} diff --git a/src/net/sourceforge/plantuml/hector/GrowingTree.java b/src/net/sourceforge/plantuml/hector/GrowingTree.java new file mode 100644 index 000000000..b243a2152 --- /dev/null +++ b/src/net/sourceforge/plantuml/hector/GrowingTree.java @@ -0,0 +1,173 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 5079 $ + * + */ +package net.sourceforge.plantuml.hector; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class GrowingTree { + + private final List all = new ArrayList(); + private final Map> directlyAfter = new HashMap>(); + + public Skeleton createSkeleton() { + final Set pins = new LinkedHashSet(); + for (PinLink link : all) { + pins.add(link.getPin1()); + pins.add(link.getPin2()); + } + normalizeRowToZero(pins); + return new Skeleton(new ArrayList(pins), new ArrayList(all)); + } + + private void normalizeRowToZero(Collection pins) { + int minRow = Integer.MAX_VALUE; + for (Pin p : pins) { + final int r = p.getRow(); + if (r == Integer.MAX_VALUE) { + throw new IllegalStateException(); + } + if (r < minRow) { + minRow = r; + } + } + for (Pin p : pins) { + p.push(-minRow); + } + } + + public boolean canBeAdded(PinLink candidat) { + if (all.size() == 0) { + return true; + } + final Pin p1 = candidat.getPin1(); + final Pin p2 = candidat.getPin2(); + if (p1.getRow() == Integer.MAX_VALUE && p2.getRow() == Integer.MAX_VALUE) { + return false; + } + return true; + } + + public void add(PinLink newPinLink) { + final Pin p1 = newPinLink.getPin1(); + final Pin p2 = newPinLink.getPin2(); + if (all.size() == 0) { + newPinLink.getPin1().setRow(0); + simpleRowComputation(newPinLink); + } else if (isPartiallyNew(newPinLink)) { + simpleRowComputation(newPinLink); + } else if (p1.getRow() != Integer.MAX_VALUE && p2.getRow() != Integer.MAX_VALUE) { + final int actualRowDiff = p2.getRow() - p1.getRow(); + final int neededPushForP2 = newPinLink.getLengthStandard() - actualRowDiff; + push(p2, neededPushForP2); + } else { + throw new IllegalArgumentException(); + } + all.add(newPinLink); + getDirectlyAfter(p1).add(p2); + } + + private List getDirectlyAfter(Pin p) { + ArrayList result = directlyAfter.get(p); + if (result == null) { + result = new ArrayList(); + directlyAfter.put(p, result); + } + return result; + } + + private Collection getIndirectlyAfter(Pin pin) { + final Set result = new HashSet(getDirectlyAfter(pin)); + int lastSize = result.size(); + while (true) { + for (Pin p : new ArrayList(result)) { + result.addAll(getDirectlyAfter(p)); + } + if (result.size() == lastSize) { + return result; + } + lastSize = result.size(); + } + } + + private void push(Pin p, int push) { + if (push <= 0) { + return; + } + final Collection after = getIndirectlyAfter(p); + if (after.contains(p)) { + throw new IllegalStateException(); + } + p.push(push); + for (Pin pp : after) { + pp.push(push); + } + } + + private void simpleRowComputation(PinLink link) { + final Pin p1 = link.getPin1(); + final Pin p2 = link.getPin2(); + if (p1.getRow() == Integer.MAX_VALUE && p2.getRow() != Integer.MAX_VALUE) { + p1.setRow(p2.getRow() - link.getLengthStandard()); + } else if (p1.getRow() != Integer.MAX_VALUE && p2.getRow() == Integer.MAX_VALUE) { + p2.setRow(p1.getRow() + link.getLengthStandard()); + } else { + throw new IllegalArgumentException(); + } + } + + private boolean isPartiallyNew(PinLink link) { + final Pin p1 = link.getPin1(); + final Pin p2 = link.getPin2(); + if (p1.getRow() == Integer.MAX_VALUE && p2.getRow() != Integer.MAX_VALUE) { + return true; + } else if (p1.getRow() != Integer.MAX_VALUE && p2.getRow() == Integer.MAX_VALUE) { + return true; + } else { + return false; + } + } + + public void normalizeRowToZero() { + // TODO Auto-generated method stub + + } + +} diff --git a/src/net/sourceforge/plantuml/command/CommandCreateNote.java b/src/net/sourceforge/plantuml/hector/HectorPath.java similarity index 55% rename from src/net/sourceforge/plantuml/command/CommandCreateNote.java rename to src/net/sourceforge/plantuml/hector/HectorPath.java index 1a4463c2b..10f00166d 100644 --- a/src/net/sourceforge/plantuml/command/CommandCreateNote.java +++ b/src/net/sourceforge/plantuml/hector/HectorPath.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,32 +28,43 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 6575 $ + * Revision $Revision: 5079 $ * */ -package net.sourceforge.plantuml.command; +package net.sourceforge.plantuml.hector; +import java.awt.geom.Point2D; +import java.util.ArrayList; import java.util.List; -import net.sourceforge.plantuml.classdiagram.AbstractEntityDiagram; -import net.sourceforge.plantuml.cucadiagram.Entity; -import net.sourceforge.plantuml.cucadiagram.EntityType; +import net.sourceforge.plantuml.geom.LineSegmentDouble; import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UStroke; -public class CommandCreateNote extends SingleLineCommand { +public class HectorPath { - public CommandCreateNote(AbstractEntityDiagram diagram) { - super(diagram, "(?i)^note\\s+\"([^\"]+)\"\\s+as\\s+([\\p{L}0-9_.]+)\\s*(#\\w+)?$"); + private final List segments = new ArrayList(); + + public void add(LineSegmentDouble seg) { + this.segments.add(seg); + } + + public void add(Point2D p1, Point2D p2) { + add(new LineSegmentDouble(p1, p2)); } @Override - protected CommandExecutionResult executeArg(List arg) { - final String display = arg.get(0); - final String code = arg.get(1); - final Entity entity = getSystem().createEntity(code, display, EntityType.NOTE); - assert entity != null; - entity.setSpecificBackcolor(HtmlColor.getColorIfValid(arg.get(2))); - return CommandExecutionResult.ok(); + public String toString() { + return segments.toString(); + } + + public void draw(UGraphic ug, HtmlColor color) { + ug = ug.apply(new UChangeColor(color)).apply(new UStroke(1.5)); + for (LineSegmentDouble seg : segments) { + seg.draw(ug); + } } } diff --git a/src/net/sourceforge/plantuml/hector/Pin.java b/src/net/sourceforge/plantuml/hector/Pin.java new file mode 100644 index 000000000..c06533c74 --- /dev/null +++ b/src/net/sourceforge/plantuml/hector/Pin.java @@ -0,0 +1,76 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 5079 $ + * + */ +package net.sourceforge.plantuml.hector; + + +public class Pin { + + private int row; + private int uid = -1; + + private final Object userData; + + public Pin(int row, Object userData) { + this.row = row; + this.userData = userData; + } + + public void setUid(int uid) { + if (this.uid != -1) { + throw new IllegalStateException(); + } + this.uid = uid; + } + + public int getRow() { + return row; + } + + public int getUid() { + return uid; + } + + public Object getUserData() { + return userData; + } + + public void setRow(int row) { + this.row = row; + } + + public void push(int push) { + setRow(getRow() + push); + } + +} diff --git a/src/net/sourceforge/plantuml/activitydiagram2/PendingLink.java b/src/net/sourceforge/plantuml/hector/PinFactory.java similarity index 58% rename from src/net/sourceforge/plantuml/activitydiagram2/PendingLink.java rename to src/net/sourceforge/plantuml/hector/PinFactory.java index 8b77ce61b..bbc5d7661 100644 --- a/src/net/sourceforge/plantuml/activitydiagram2/PendingLink.java +++ b/src/net/sourceforge/plantuml/hector/PinFactory.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -27,41 +27,40 @@ * in the United States and other countries.] * * Original Author: Arnaud Roques - * - * Revision $Revision: 5721 $ + * + * Revision $Revision: 5079 $ * */ -package net.sourceforge.plantuml.activitydiagram2; +package net.sourceforge.plantuml.hector; -import net.sourceforge.plantuml.cucadiagram.IEntity; +import java.util.HashMap; +import java.util.Map; -public class PendingLink { +import net.sourceforge.plantuml.cucadiagram.Link; - private final IEntity entityFrom; - private final String gotoLabel; - private final String linkLabel; +public class PinFactory { - public PendingLink(IEntity entityFrom, String gotoLabel, String linkLabel) { - this.entityFrom = entityFrom; - this.gotoLabel = gotoLabel; - this.linkLabel = linkLabel; + private final Map pins = new HashMap(); + + Pin create(Object userData) { + return create(Integer.MAX_VALUE, userData); } - public final IEntity getEntityFrom() { - return entityFrom; + Pin create(int row, Object userData) { + if (userData == null) { + return new Pin(row, userData); + } + Pin result = pins.get(userData); + if (result == null) { + result = new Pin(row, userData); + pins.put(userData, result); + } + return result; } - public final String getGotoLabel() { - return gotoLabel; - } - - public final String getLinkLabel() { - return linkLabel; - } - - @Override - public String toString() { - return entityFrom + " -> " + gotoLabel + " " + linkLabel; + public PinLink createPinLink(Link link) { + final PinLink result = new PinLink(create(link.getEntity1()), create(link.getEntity2()), link.getLength(), link); + return result; } } diff --git a/src/net/sourceforge/plantuml/hector/PinLink.java b/src/net/sourceforge/plantuml/hector/PinLink.java new file mode 100644 index 000000000..8c1d8a827 --- /dev/null +++ b/src/net/sourceforge/plantuml/hector/PinLink.java @@ -0,0 +1,76 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 5079 $ + * + */ +package net.sourceforge.plantuml.hector; + +public class PinLink { + + private final Pin pin1; + private final Pin pin2; + private final Object userData; + private final int length; + + public PinLink(Pin pin1, Pin pin2, int length, Object userData) { + if (length < 1) { + throw new IllegalArgumentException(); + } + this.pin1 = pin1; + this.pin2 = pin2; + this.userData = userData; + this.length = length; + } + + public boolean contains(Pin pin) { + return pin == pin1 || pin == pin2; + } + + public boolean doesTouch(PinLink other) { + return other.contains(pin1) || other.contains(pin2); + } + + public Pin getPin1() { + return pin1; + } + + public Pin getPin2() { + return pin2; + } + + public int getLengthDot() { + return length; + } + + public int getLengthStandard() { + return length - 1; + } +} diff --git a/src/net/sourceforge/plantuml/hector/PinLinksContinuousSet.java b/src/net/sourceforge/plantuml/hector/PinLinksContinuousSet.java new file mode 100644 index 000000000..705e6f6a8 --- /dev/null +++ b/src/net/sourceforge/plantuml/hector/PinLinksContinuousSet.java @@ -0,0 +1,102 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 5079 $ + * + */ +package net.sourceforge.plantuml.hector; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; + +public class PinLinksContinuousSet { + + private final Collection all = new ArrayList(); + + public Skeleton createSkeleton() { + final GrowingTree tree = new GrowingTree(); + final Collection pendings = new ArrayList(all); + while (pendings.size() > 0) { + for (Iterator it = pendings.iterator(); it.hasNext();) { + final PinLink candidat = it.next(); + if (tree.canBeAdded(candidat)) { + tree.add(candidat); + it.remove(); + } + } + } + return tree.createSkeleton(); + + } + + public void add(PinLink newPinLink) { + if (all.size() == 0) { + all.add(newPinLink); + return; + } + if (all.contains(newPinLink)) { + throw new IllegalArgumentException("already"); + } + for (PinLink aLink : all) { + if (newPinLink.doesTouch(aLink)) { + all.add(newPinLink); + return; + } + } + throw new IllegalArgumentException("not connex"); + } + + public void addAll(PinLinksContinuousSet other) { + if (doesTouch(other) == false) { + throw new IllegalArgumentException(); + } + this.all.addAll(other.all); + } + + public boolean doesTouch(PinLink other) { + for (PinLink aLink : all) { + if (other.doesTouch(aLink)) { + return true; + } + } + return false; + } + + public boolean doesTouch(PinLinksContinuousSet otherSet) { + for (PinLink otherLink : otherSet.all) { + if (doesTouch(otherLink)) { + return true; + } + } + return false; + } + +} diff --git a/src/net/sourceforge/plantuml/hector/Skeleton.java b/src/net/sourceforge/plantuml/hector/Skeleton.java new file mode 100644 index 000000000..d0c9edf96 --- /dev/null +++ b/src/net/sourceforge/plantuml/hector/Skeleton.java @@ -0,0 +1,83 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 5079 $ + * + */ +package net.sourceforge.plantuml.hector; + +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; + +public class Skeleton { + + private final List pins; + private final List pinLinks; + private final SortedSet rows = new TreeSet(); + + public Skeleton(List pins, List pinLinks) { + this.pins = pins; + this.pinLinks = pinLinks; + int uid = 0; + for (Pin pin : pins) { + pin.setUid(uid++); + rows.add(pin.getRow()); + } + } + + public SortedSet getRows() { + return rows; + } + + public List getPins() { + return pins; + } + + public Collection getPinsOfRow(int row) { + final Set result = new LinkedHashSet(); + for (Pin pin : pins) { + if (pin.getRow() == row) { + result.add(pin); + } + } + return result; + } + + public List getPinLinks() { + return pinLinks; + } + + + +} diff --git a/src/net/sourceforge/plantuml/hector/SkeletonBuilder.java b/src/net/sourceforge/plantuml/hector/SkeletonBuilder.java new file mode 100644 index 000000000..d5cbc2976 --- /dev/null +++ b/src/net/sourceforge/plantuml/hector/SkeletonBuilder.java @@ -0,0 +1,83 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 5079 $ + * + */ +package net.sourceforge.plantuml.hector; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public class SkeletonBuilder { + + private List sets = new ArrayList(); + + public void add(PinLink pinLink) { + addInternal(pinLink); + merge(); + + } + + private void merge() { + for (int i = 0; i < sets.size() - 1; i++) { + for (int j = i + 1; j < sets.size(); j++) { + if (sets.get(i).doesTouch(sets.get(j))) { + sets.get(i).addAll(sets.get(j)); + sets.remove(j); + return; + } + } + } + } + + private void addInternal(PinLink pinLink) { + for (PinLinksContinuousSet set : sets) { + if (set.doesTouch(pinLink)) { + set.add(pinLink); + return; + } + } + final PinLinksContinuousSet newSet = new PinLinksContinuousSet(); + newSet.add(pinLink); + sets.add(newSet); + } + + public List createSkeletons() { + final List result = new ArrayList(); + + for (PinLinksContinuousSet set : sets) { + result.add(set.createSkeleton()); + } + + return Collections.unmodifiableList(result); + } +} diff --git a/src/net/sourceforge/plantuml/hector/SkeletonConfiguration.java b/src/net/sourceforge/plantuml/hector/SkeletonConfiguration.java new file mode 100644 index 000000000..d09100dda --- /dev/null +++ b/src/net/sourceforge/plantuml/hector/SkeletonConfiguration.java @@ -0,0 +1,254 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 5079 $ + * + */ +package net.sourceforge.plantuml.hector; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +public class SkeletonConfiguration { + + private final int position[]; + private final Skeleton skeleton; + + public static SkeletonConfiguration getDefault(Skeleton skeleton) { + final Collection rows = skeleton.getRows(); + final Map free = new HashMap(); + for (Integer i : rows) { + free.put(i, 0); + } + final Collection pins = skeleton.getPins(); + final int position[] = new int[pins.size()]; + for (Pin pin : pins) { + final int f = free.get(pin.getRow()); + position[pin.getUid()] = f; + free.put(pin.getRow(), f + 1); + } + return new SkeletonConfiguration(skeleton, position); + } + + @Override + public int hashCode() { + int result = 0; + for (int v : position) { + result = result * 37 + v; + } + return result; + } + + @Override + public boolean equals(Object other) { + final SkeletonConfiguration this2 = (SkeletonConfiguration) other; + if (this.skeleton != this2.skeleton) { + throw new IllegalArgumentException(); + } + if (this.position.length != this2.position.length) { + throw new IllegalArgumentException(); + } + for (int i = 0; i < position.length; i++) { + if (this.position[i] != this2.position[i]) { + return false; + } + } + return true; + } + + @Override + public String toString() { + final int minRow = skeleton.getRows().first(); + final int maxRow = skeleton.getRows().last(); + int minCol = Integer.MAX_VALUE; + int maxCol = Integer.MIN_VALUE; + for (int c : position) { + if (c > maxCol) { + maxCol = c; + } + if (c < minCol) { + minCol = c; + } + } + final StringBuilder result = new StringBuilder(); + for (int r = minRow; r <= maxRow; r++) { + appendRow(result, r, minCol, maxCol); + if (r < maxRow) { + result.append(" "); + } + } + return result.toString(); + } + + private void appendRow(StringBuilder result, int row, int minCol, int maxCol) { + result.append("("); + boolean first = true; + for (int c = minCol; c <= maxCol; c++) { + if (first == false) { + result.append("-"); + } + final Pin pin = getPin(row, c); + if (pin == null) { + result.append("."); + } else { + result.append(pin.getUid()); + } + first = false; + } + result.append(")"); + + } + + private Pin getPin(int row, int col) { + for (Pin p : skeleton.getPinsOfRow(row)) { + if (getCol(p) == col) { + return p; + } + } + return null; + } + + public int getCol(Pin pin) { + return position[pin.getUid()]; + } + + private SkeletonConfiguration(Skeleton skeleton, int position[]) { + this.position = position; + this.skeleton = skeleton; + } + + class Switch implements SkeletonMutation { + private final SkeletonConfiguration newConfiguration; + + public Switch(Pin pin1, Pin pin2) { + if (pin1 == pin2) { + throw new IllegalArgumentException(); + } + final int copy[] = new int[position.length]; + for (int i = 0; i < position.length; i++) { + if (i == pin1.getUid()) { + copy[i] = position[pin2.getUid()]; + } else if (i == pin2.getUid()) { + copy[i] = position[pin1.getUid()]; + } else { + copy[i] = position[i]; + } + } + this.newConfiguration = new SkeletonConfiguration(skeleton, copy); + } + + public SkeletonConfiguration mutate() { + return newConfiguration; + } + } + + class Move implements SkeletonMutation { + private final SkeletonConfiguration newConfiguration; + + public Move(Pin pin, int deltaX) { + final int copy[] = new int[position.length]; + for (int i = 0; i < position.length; i++) { + if (i == pin.getUid()) { + copy[i] = position[i] + deltaX; + } else { + copy[i] = position[i]; + } + } + this.newConfiguration = new SkeletonConfiguration(skeleton, copy); + } + + public SkeletonConfiguration mutate() { + return newConfiguration; + } + } + + private Collection getMutationForRow(int row) { + final Collection pins = skeleton.getPinsOfRow(row); + final Collection usedCols = new HashSet(); + for (Pin pin : pins) { + usedCols.add(getCol(pin)); + } + final Collection result = new ArrayList(); + for (Pin pin1 : pins) { + final int c = getCol(pin1); + if (usedCols.contains(c + 1) == false) { + result.add(new Move(pin1, 1)); + } + if (usedCols.contains(c - 1) == false) { + result.add(new Move(pin1, -1)); + } + for (Pin pin2 : pins) { + if (pin1 == pin2) { + continue; + } + if (getCol(pin1) > getCol(pin2)) { + continue; + } + if (getCol(pin1) == getCol(pin2)) { + throw new IllegalStateException(); + } + result.add(new Switch(pin1, pin2)); + } + } + return result; + } + + public Set getSomeMuteds() { + final Set result = new HashSet(); + for (Integer row : skeleton.getRows()) { + for (SkeletonMutation mutation : getMutationForRow(row)) { + result.add(mutation.mutate()); + } + + } + return result; + } + + public List getPinLinks() { + return skeleton.getPinLinks(); + } + + public double getLength(PinLink link) { + final double x1 = getCol(link.getPin1()); + final double y1 = link.getPin1().getRow(); + final double x2 = getCol(link.getPin2()); + final double y2 = link.getPin2().getRow(); + final double dx = x2 - x1; + final double dy = y2 - y1; + return Math.sqrt(dx * dx + dy * dy); + } + + +} diff --git a/src/net/sourceforge/plantuml/hector/SkeletonConfigurationComparator.java b/src/net/sourceforge/plantuml/hector/SkeletonConfigurationComparator.java new file mode 100644 index 000000000..94d66a55a --- /dev/null +++ b/src/net/sourceforge/plantuml/hector/SkeletonConfigurationComparator.java @@ -0,0 +1,58 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 5079 $ + * + */ +package net.sourceforge.plantuml.hector; + +import java.util.Comparator; + +public class SkeletonConfigurationComparator implements Comparator { + + private final SkeletonConfigurationEvaluator evaluator; + + public SkeletonConfigurationComparator(SkeletonConfigurationEvaluator evaluator) { + this.evaluator = evaluator; + } + + public int compare(SkeletonConfiguration sc1, SkeletonConfiguration sc2) { + final double price1 = evaluator.getPrice(sc1); + final double price2 = evaluator.getPrice(sc2); + if (price1 > price2) { + return 1; + } + if (price1 < price2) { + return -1; + } + return 0; + } + +} diff --git a/src/net/sourceforge/plantuml/hector/SkeletonConfigurationEvaluator.java b/src/net/sourceforge/plantuml/hector/SkeletonConfigurationEvaluator.java new file mode 100644 index 000000000..e7ae36ea6 --- /dev/null +++ b/src/net/sourceforge/plantuml/hector/SkeletonConfigurationEvaluator.java @@ -0,0 +1,40 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 5079 $ + * + */ +package net.sourceforge.plantuml.hector; + +public interface SkeletonConfigurationEvaluator { + + public double getPrice(SkeletonConfiguration configuration); + +} diff --git a/src/net/sourceforge/plantuml/hector/SkeletonConfigurationEvaluatorLineLenght.java b/src/net/sourceforge/plantuml/hector/SkeletonConfigurationEvaluatorLineLenght.java new file mode 100644 index 000000000..33c3558bb --- /dev/null +++ b/src/net/sourceforge/plantuml/hector/SkeletonConfigurationEvaluatorLineLenght.java @@ -0,0 +1,46 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 5079 $ + * + */ +package net.sourceforge.plantuml.hector; + +public class SkeletonConfigurationEvaluatorLineLenght implements SkeletonConfigurationEvaluator { + + public double getPrice(SkeletonConfiguration configuration) { + double result = 0; + for (PinLink link : configuration.getPinLinks()) { + result += configuration.getLength(link); + } + return result; + } + +} diff --git a/src/net/sourceforge/plantuml/hector/SkeletonConfigurationSet.java b/src/net/sourceforge/plantuml/hector/SkeletonConfigurationSet.java new file mode 100644 index 000000000..928e99db4 --- /dev/null +++ b/src/net/sourceforge/plantuml/hector/SkeletonConfigurationSet.java @@ -0,0 +1,88 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 5079 $ + * + */ +package net.sourceforge.plantuml.hector; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +public class SkeletonConfigurationSet implements Iterable { + + private final List all; + private final SkeletonConfigurationComparator comparator; + private final int limitSize; + + public SkeletonConfigurationSet(int limitSize, SkeletonConfigurationEvaluator evaluator) { + this.comparator = new SkeletonConfigurationComparator(evaluator); + this.all = new ArrayList(); + this.limitSize = limitSize; + } + + public void add(SkeletonConfiguration skeletonConfiguration) { + this.all.add(skeletonConfiguration); + sortAndTruncate(); + } + + public void addAll(Collection others) { + all.addAll(others); + sortAndTruncate(); + } + + private void sortAndTruncate() { + Collections.sort(all, comparator); + while (all.size() > limitSize) { + all.remove(all.size() - 1); + } + } + + @Override + public String toString() { + return all.toString(); + } + + public int size() { + return all.size(); + } + + public Iterator iterator() { + return new ArrayList(all).iterator(); + } + + public SkeletonConfiguration first() { + return all.get(0); + } + +} diff --git a/src/net/sourceforge/plantuml/hector/SkeletonConfigurationUtils.java b/src/net/sourceforge/plantuml/hector/SkeletonConfigurationUtils.java new file mode 100644 index 000000000..7e41674e4 --- /dev/null +++ b/src/net/sourceforge/plantuml/hector/SkeletonConfigurationUtils.java @@ -0,0 +1,55 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 5079 $ + * + */ +package net.sourceforge.plantuml.hector; + +public class SkeletonConfigurationUtils { + + public static SkeletonConfiguration getBest(Skeleton skeleton) { + SkeletonConfiguration config = SkeletonConfiguration.getDefault(skeleton); + + final SkeletonConfigurationSet set = new SkeletonConfigurationSet(200, + new SkeletonConfigurationEvaluatorLineLenght()); + set.add(config); + + for (int i = 0; i < 10; i++) { + System.err.println("before size=" + set.size()); + for (SkeletonConfiguration sk : set) { + set.addAll(sk.getSomeMuteds()); + } + System.err.println("after size=" + set.size()); + } + return set.first(); + } + +} diff --git a/src/net/sourceforge/plantuml/hector/SkeletonConfigurations.java b/src/net/sourceforge/plantuml/hector/SkeletonConfigurations.java new file mode 100644 index 000000000..99b262a2c --- /dev/null +++ b/src/net/sourceforge/plantuml/hector/SkeletonConfigurations.java @@ -0,0 +1,38 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 5079 $ + * + */ +package net.sourceforge.plantuml.hector; + +public class SkeletonConfigurations { + +} diff --git a/src/net/sourceforge/plantuml/hector/SkeletonMutation.java b/src/net/sourceforge/plantuml/hector/SkeletonMutation.java new file mode 100644 index 000000000..600b9aeba --- /dev/null +++ b/src/net/sourceforge/plantuml/hector/SkeletonMutation.java @@ -0,0 +1,40 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 5079 $ + * + */ +package net.sourceforge.plantuml.hector; + +interface SkeletonMutation { + + public SkeletonConfiguration mutate(); + +} diff --git a/src/net/sourceforge/plantuml/hector/SmartConnection.java b/src/net/sourceforge/plantuml/hector/SmartConnection.java new file mode 100644 index 000000000..2fa5c941e --- /dev/null +++ b/src/net/sourceforge/plantuml/hector/SmartConnection.java @@ -0,0 +1,109 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 5079 $ + * + */ +package net.sourceforge.plantuml.hector; + +import java.awt.geom.Point2D; +import java.util.List; + +import net.sourceforge.plantuml.geom.LineSegmentDouble; +import net.sourceforge.plantuml.graphic.HtmlColor; +import net.sourceforge.plantuml.graphic.HtmlColorUtils; +import net.sourceforge.plantuml.ugraphic.UChangeColor; +import net.sourceforge.plantuml.ugraphic.UGraphic; +import net.sourceforge.plantuml.ugraphic.UPath; +import net.sourceforge.plantuml.ugraphic.UStroke; + +class SmartConnection { + + private final double x1; + private final double y1; + private final double x2; + private final double y2; + private final List forbidden; + + public SmartConnection(double x1, double y1, double x2, double y2, List forbidden) { + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; + this.forbidden = forbidden; + } + + public SmartConnection(Point2D p1, Point2D p2, List b) { + this(p1.getX(), p1.getY(), p2.getX(), p2.getY(), b); + } + + public void draw(UGraphic ug, HtmlColor color) { + final LineSegmentDouble seg = new LineSegmentDouble(x1, y1, x2, y2); + boolean clash = intersect(seg); + if (clash) { + ug = ug.apply(new UChangeColor(HtmlColorUtils.BLACK)).apply(new UStroke(1.0)); + } else { + ug = ug.apply(new UChangeColor(color)).apply(new UStroke(1.5)); + } + seg.draw(ug); + } + + private boolean intersect(LineSegmentDouble seg) { + for (Box2D box : forbidden) { + if (box.doesIntersect(seg)) { + return true; + } + } + return false; + } + + public void drawEx1(UGraphic ug, HtmlColor color) { + ug = ug.apply(new UChangeColor(color)).apply(new UStroke(1.5)); + final double orthoX = -(y2 - y1); + final double orthoY = x2 - x1; + for (int i = -10; i <= 10; i++) { + for (int j = -10; j <= 10; j++) { + final double d1x = orthoX * i / 10.0; + final double d1y = orthoY * i / 10.0; + final double c1x = (x1 + x2) / 2 + d1x; + final double c1y = (y1 + y2) / 2 + d1y; + final double d2x = orthoX * j / 10.0; + final double d2y = orthoY * j / 10.0; + final double c2x = (x1 + x2) / 2 + d2x; + final double c2y = (y1 + y2) / 2 + d2y; + final UPath path = new UPath(); + path.moveTo(x1, y1); + path.cubicTo(c1x, c1y, c2x, c2y, x2, y2); + ug.draw(path); + } + } + } + +} diff --git a/src/net/sourceforge/plantuml/hector/UnlinarCompressedPlan.java b/src/net/sourceforge/plantuml/hector/UnlinarCompressedPlan.java new file mode 100644 index 000000000..31f48f4a4 --- /dev/null +++ b/src/net/sourceforge/plantuml/hector/UnlinarCompressedPlan.java @@ -0,0 +1,142 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 5079 $ + * + */ +package net.sourceforge.plantuml.hector; + +import java.awt.geom.Point2D; + +import net.sourceforge.plantuml.geom.LineSegmentDouble; +import net.sourceforge.plantuml.hector.UnlinearCompression.Rounding; + +class UnlinarCompressedPlan { + + private final UnlinearCompression compX; + private final UnlinearCompression compY; + + public UnlinarCompressedPlan(double inner, double outer) { + this(inner, outer, inner, outer); + } + + public UnlinarCompressedPlan(double innerx, double outerx, double innery, double outery) { + this.compX = new UnlinearCompression(innerx, outerx); + this.compY = new UnlinearCompression(innery, outery); + } + + public double getInnerX() { + return compX.innerSize(); + } + + public double getInnerY() { + return compY.innerSize(); + } + + public HectorPath uncompressSegmentSimple(Point2D pp1, Point2D pp2) { + final HectorPath result = new HectorPath(); + result.add(new LineSegmentDouble(uncompress(pp1, UnlinearCompression.Rounding.CENTRAL), uncompress(pp2, + UnlinearCompression.Rounding.CENTRAL))); + return result; + } + + public HectorPath uncompressSegment(Point2D pp1, Point2D pp2) { + double x1 = pp1.getX(); + double y1 = pp1.getY(); + final double x2 = pp2.getX(); + final double y2 = pp2.getY(); + final HectorPath result = new HectorPath(); + final double y[] = compY.encounteredSingularities(y1, y2); + if (y.length == 0 || x1 == x2) { + result.add(new LineSegmentDouble(uncompress(pp1, UnlinearCompression.Rounding.CENTRAL), uncompress(pp2, + UnlinearCompression.Rounding.CENTRAL))); + return result; + } + System.err.println("len=" + y.length); + final LineSegmentDouble segment = new LineSegmentDouble(pp1, pp2); + for (int i = 0; i < y.length; i++) { + final double x = segment.getIntersectionHorizontal(y[i]); + final Rounding r = i == 0 ? UnlinearCompression.Rounding.CENTRAL : UnlinearCompression.Rounding.BORDER_2; + result.add(uncompress(x1, y1, r), uncompress(x, y[i], UnlinearCompression.Rounding.BORDER_1)); + x1 = x; + y1 = y[i]; + } + result.add(uncompress(x1, y1, UnlinearCompression.Rounding.BORDER_2), uncompress(x2, y2, + UnlinearCompression.Rounding.CENTRAL)); + return result; + + } + + public HectorPath uncompress(LineSegmentDouble segment) { + double x1 = segment.getX1(); + double y1 = segment.getY1(); + final double x2 = segment.getX2(); + final double y2 = segment.getY2(); + final HectorPath result = new HectorPath(); + final double x[] = compX.encounteredSingularities(x1, x2); + if (x.length == 0) { + result.add(getUncompressedSegment(x1, y1, x2, y2, UnlinearCompression.Rounding.BORDER_2)); + return result; + } + for (int i = 0; i < x.length; i++) { + final double y = segment.getIntersectionVertical(x[i]); + result.add(getUncompressedSegment(x1, y1, x[i], y, UnlinearCompression.Rounding.BORDER_2)); + x1 = x[i]; + y1 = y; + } + result.add(getUncompressedSegment(x1, y1, x2, y2, UnlinearCompression.Rounding.BORDER_2)); + return result; + } + + public Point2D uncompress(Point2D pt, UnlinearCompression.Rounding rounding) { + return uncompress(pt.getX(), pt.getY(), rounding); + } + + public Point2D uncompress(double x, double y, UnlinearCompression.Rounding rounding) { + return new Point2D.Double(compX.uncompress(x, rounding), compY.uncompress(y, rounding)); + } + + private LineSegmentDouble getUncompressedSegment(final double x1, final double y1, final double x2, + final double y2, UnlinearCompression.Rounding rounding) { + final LineSegmentDouble un1 = new LineSegmentDouble(compX.uncompress(x1, rounding), compY.uncompress(y1, + rounding), compX.uncompress(x2, rounding), compY.uncompress(y2, rounding)); + return un1; + } + + // private LineSegmentDouble getUncompressedSegmentRoundBefore(final double + // x1, final double y1, final double x2, + // final double y2) { + // final LineSegmentDouble un1 = new LineSegmentDouble(compX.uncompress(x1), + // compY.uncompress(y1), + // compX.uncompress(x2) - compX.innerSize(), compY.uncompress(y2)); + // return un1; + // } + +} diff --git a/src/net/sourceforge/plantuml/hector/UnlinearCompression.java b/src/net/sourceforge/plantuml/hector/UnlinearCompression.java new file mode 100644 index 000000000..685faf082 --- /dev/null +++ b/src/net/sourceforge/plantuml/hector/UnlinearCompression.java @@ -0,0 +1,110 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 5079 $ + * + */ +package net.sourceforge.plantuml.hector; + +class UnlinearCompression { + + static enum Rounding { + BORDER_1, CENTRAL, BORDER_2; + } + + private final double inner; + private final double outer; + + public UnlinearCompression(double inner, double outer) { + this.inner = inner; + this.outer = outer; + } + + public double compress(double x) { + final double pour = x / (inner + outer); + final double pourInter = Math.floor(pour); + x -= pourInter * (inner + outer); + if (x < inner) { + return pourInter * outer; + } + return x - inner + pourInter * outer; + } + + public double uncompress(double x, Rounding rounding) { + final int pourInter = nbOuterBefore(x); + final boolean onBorder = equals(x, pourInter * outer); + if (onBorder && rounding == Rounding.BORDER_1) { + // Nothing + } else if (onBorder && rounding == Rounding.CENTRAL) { + x += inner / 2.0; + } else { + x += inner; + } + x += pourInter * inner; + return x; + } + + private static boolean equals(double d1, double d2) { + return Math.abs(d1 - d2) < .001; + } + + private int nbOuterBefore(double x) { + final double pour = x / outer; + final int pourInter = (int) Math.floor(pour); + return pourInter; + } + + public double[] encounteredSingularities(double from, double to) { + final int outer1 = nbOuterBefore(from) + 1; + int outer2 = nbOuterBefore(to) + 1; + if (equals(to, (outer2 - 1) * outer)) { + outer2--; + } + final double result[]; + if (from <= to) { + result = new double[outer2 - outer1]; + for (int i = 0; i < result.length; i++) { + result[i] = (outer1 + i) * outer; + } + } else { + result = new double[outer1 - outer2]; + for (int i = 0; i < result.length; i++) { + result[i] = (outer1 - 1 - i) * outer; + } + + } + return result; + } + + public double innerSize() { + return inner; + } + +} diff --git a/src/net/sourceforge/plantuml/html/CucaDiagramHtmlMaker.java b/src/net/sourceforge/plantuml/html/CucaDiagramHtmlMaker.java new file mode 100644 index 000000000..71bd02046 --- /dev/null +++ b/src/net/sourceforge/plantuml/html/CucaDiagramHtmlMaker.java @@ -0,0 +1,223 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 5079 $ + * + */ +package net.sourceforge.plantuml.html; + +import java.io.File; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.cucadiagram.Code; +import net.sourceforge.plantuml.cucadiagram.CucaDiagram; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.LeafType; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.cucadiagram.Member; +import net.sourceforge.plantuml.cucadiagram.Stereotype; + +public final class CucaDiagramHtmlMaker { + + private final CucaDiagram diagram; + private final File dir; + + public CucaDiagramHtmlMaker(CucaDiagram diagram, File dir) { + this.diagram = diagram; + this.dir = dir; + } + + public List create() throws IOException { + dir.mkdirs(); + if (dir.exists() == false) { + throw new IOException("Cannot create " + dir); + } + final File f = new File(dir, "index.html"); + final PrintWriter pw = new PrintWriter(f); + pw.println(""); + printAllType(pw, LeafType.ENUM); + printAllType(pw, LeafType.INTERFACE); + printAllType(pw, LeafType.ANNOTATION); + printAllType(pw, LeafType.ABSTRACT_CLASS); + printAllType(pw, LeafType.CLASS); + htmlClose(pw); + return Arrays.asList(dir); + } + + private void printAllType(final PrintWriter pw, LeafType type) throws IOException { + if (hasSome(type)) { + pw.println("

    " + type.toHtml() + "

    "); + for (Map.Entry ent : new TreeMap(diagram.getLeafs()).entrySet()) { + if (ent.getValue().getEntityType() != type) { + continue; + } + export(ent.getValue()); + pw.println("
  • "); + pw.println(LinkHtmlPrinter.htmlLink(ent.getValue())); + pw.println("
  • "); + } + } + } + + private boolean hasSome(final LeafType type) { + for (IEntity ent : diagram.getLeafs().values()) { + if (ent.getEntityType() == type) { + return true; + } + } + return false; + } + + private void export(IEntity entity) throws IOException { + final File f = new File(dir, LinkHtmlPrinter.urlOf(entity)); + final PrintWriter pw = new PrintWriter(f); + pw.println(""); + pw.println("" + StringUtils.unicodeForHtml(entity.getCode().getCode()) + ""); + pw.println("

    " + entity.getEntityType().toHtml() + "

    "); + for (CharSequence s : entity.getDisplay()) { + pw.println(StringUtils.unicodeForHtml(s.toString())); + pw.println("
    "); + } + final Stereotype stereotype = entity.getStereotype(); + if (stereotype != null) { + pw.println("
    "); + pw.println("

    Stereotype

    "); + for (String s : stereotype.getLabels()) { + pw.println(s); + pw.println("
    "); + } + } + + pw.println("
    "); + if (entity.getFieldsToDisplay().size() == 0) { + pw.println("

    No fields

    "); + } else { + pw.println("

    Fields:

    "); + pw.println("
      "); + for (Member m : entity.getFieldsToDisplay()) { + pw.println("
    • "); + pw.println(StringUtils.unicodeForHtml(m.getDisplay(true))); + pw.println("
    • "); + } + pw.println("
    "); + } + + pw.println("
    "); + if (entity.getMethodsToDisplay().size() == 0) { + pw.println("

    No methods

    "); + } else { + pw.println("

    Methods:

    "); + pw.println("
      "); + for (Member m : entity.getMethodsToDisplay()) { + pw.println("
    • "); + pw.println(StringUtils.unicodeForHtml(m.getDisplay(true))); + pw.println("
    • "); + } + pw.println("
    "); + } + + pw.println("
    "); + final Collection links = getLinksButNotes(entity); + if (links.size() == 0) { + pw.println("

    No links

    "); + } else { + pw.println("

    Links:

    "); + pw.println("
      "); + for (Link l : links) { + pw.println("
    • "); + new LinkHtmlPrinter(l, entity).printLink(pw); + pw.println("
    • "); + } + pw.println("
    "); + } + + final Collection notes = getNotes(entity); + if (notes.size() > 0) { + pw.println("
    "); + pw.println("

    Notes:

    "); + pw.println("
      "); + for (IEntity note : notes) { + pw.println("
    • "); + for (CharSequence s : note.getDisplay()) { + pw.println(StringUtils.unicodeForHtml(s.toString())); + pw.println("
      "); + } + pw.println("
    • "); + } + pw.println("
    "); + + } + + htmlClose(pw); + } + + private void htmlClose(final PrintWriter pw) { + pw.println("
    "); + pw.println("Back to index"); + pw.println(""); + pw.close(); + } + + private Collection getNotes(IEntity ent) { + final List result = new ArrayList(); + for (Link link : diagram.getLinks()) { + if (link.contains(ent) == false) { + continue; + } + if (link.getEntity1().getEntityType() == LeafType.NOTE || link.getEntity2().getEntityType() == LeafType.NOTE) { + result.add(link.getOther(ent)); + } + } + return Collections.unmodifiableList(result); + } + + private Collection getLinksButNotes(IEntity ent) { + final List result = new ArrayList(); + for (Link link : diagram.getLinks()) { + if (link.contains(ent) == false) { + continue; + } + if (link.getEntity1().getEntityType() == LeafType.NOTE || link.getEntity2().getEntityType() == LeafType.NOTE) { + continue; + } + result.add(link); + } + return Collections.unmodifiableList(result); + } +} diff --git a/src/net/sourceforge/plantuml/html/LinkHtmlPrinter.java b/src/net/sourceforge/plantuml/html/LinkHtmlPrinter.java new file mode 100644 index 000000000..4e48bc170 --- /dev/null +++ b/src/net/sourceforge/plantuml/html/LinkHtmlPrinter.java @@ -0,0 +1,186 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 5079 $ + * + */ +package net.sourceforge.plantuml.html; + +import java.io.PrintWriter; + +import net.sourceforge.plantuml.StringUtils; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.LeafType; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.cucadiagram.LinkDecor; + +public final class LinkHtmlPrinter { + + private final Link link; + // private final Entity entity; + private final boolean chiral; + + public LinkHtmlPrinter(Link link, IEntity entity) { + this.link = link; + if (link.getEntity1() == entity) { + this.chiral = false; + } else if (link.getEntity2() == entity) { + this.chiral = true; + } else { + throw new IllegalArgumentException(); + } + } + + void printLink(PrintWriter pw) { + final String ent1h; + final String ent2h; + if (chiral) { + ent1h = htmlLink(link.getEntity1()); + ent2h = "" + StringUtils.unicodeForHtml(link.getEntity2().getCode().getCode()) + ""; + } else { + ent1h = "" + StringUtils.unicodeForHtml(link.getEntity1().getCode().getCode()) + ""; + ent2h = htmlLink(link.getEntity2()); + } + String label = link.getLabel() == null ? null : StringUtils.unicodeForHtml(link.getLabel()); + String ent1 = ent1h; + String ent2 = ent2h; + if (link.getQualifier1() != null) { + ent1 = ent1 + " (" + link.getQualifier1() + ")"; + if (label != null) { + label = "(" + link.getQualifier1() + " " + ent1h + ") " + label; + } + } + if (link.getQualifier2() != null) { + ent2 = ent2 + " (" + link.getQualifier2() + ")"; + if (label != null) { + label = label + " (" + link.getQualifier2() + " " + ent2h + ")"; + } + } + if (chiral) { + pw.println(getHtmlChiral(ent1, ent2)); + } else { + pw.println(getHtml(ent1, ent2)); + } + if (label != null) { + pw.println(" : "); + pw.println(label); + } + } + + private String getHtml(String ent1, String ent2) { + final LinkDecor decor1 = link.getType().getDecor1(); + final LinkDecor decor2 = link.getType().getDecor2(); + + if (decor1 == LinkDecor.NONE && decor2 == LinkDecor.NONE) { + return ent1 + " is linked to " + ent2; + } + if (decor1 == LinkDecor.NONE && decor2 == LinkDecor.EXTENDS) { + return ent1 + " is extended by " + ent2; + } + if (decor1 == LinkDecor.EXTENDS && decor2 == LinkDecor.NONE) { + return ent1 + " extends " + ent2; + } + if (decor2 == LinkDecor.AGREGATION) { + return ent1 + " is aggregated by " + ent2; + } + if (decor1 == LinkDecor.AGREGATION) { + return ent1 + " aggregates " + ent2; + } + if (decor2 == LinkDecor.COMPOSITION) { + return ent1 + " is composed by " + ent2; + } + if (decor1 == LinkDecor.COMPOSITION) { + return ent1 + " composes " + ent2; + } + if (decor1 == LinkDecor.NONE && decor2 == LinkDecor.ARROW) { + return ent1 + " is navigable from " + ent2; + } + if (decor1 == LinkDecor.ARROW && decor2 == LinkDecor.NONE) { + return ent1 + " navigates to " + ent2; + } + return ent1 + " " + decor1 + "-" + decor2 + " " + ent2; + + } + + private String getHtmlChiral(String ent1, String ent2) { + final LinkDecor decor1 = link.getType().getDecor1(); + final LinkDecor decor2 = link.getType().getDecor2(); + + if (decor1 == LinkDecor.NONE && decor2 == LinkDecor.NONE) { + return ent2 + " is linked to " + ent1; + } + if (decor1 == LinkDecor.NONE && decor2 == LinkDecor.EXTENDS) { + return ent2 + " extends " + ent1; + } + if (decor1 == LinkDecor.EXTENDS && decor2 == LinkDecor.NONE) { + return ent2 + " is extended by " + ent1; + } + if (decor2 == LinkDecor.AGREGATION) { + return ent2 + " aggregates " + ent1; + } + if (decor1 == LinkDecor.AGREGATION) { + return ent2 + " is aggregated by " + ent1; + } + if (decor2 == LinkDecor.COMPOSITION) { + return ent2 + " composes " + ent1; + } + if (decor1 == LinkDecor.COMPOSITION) { + return ent2 + " is composed by " + ent1; + } + if (decor1 == LinkDecor.NONE && decor2 == LinkDecor.ARROW) { + return ent2 + " navigates to " + ent1; + } + if (decor1 == LinkDecor.ARROW && decor2 == LinkDecor.NONE) { + return ent2 + " is navigable from " + ent1; + } + return ent1 + " " + decor1 + "-" + decor2 + " " + ent2; + } + + static String htmlLink(IEntity ent) { + final StringBuilder sb = new StringBuilder(); + sb.append(""); + sb.append(StringUtils.unicodeForHtml(ent.getCode().getCode())); + sb.append(""); + return sb.toString(); + } + + static String urlOf(IEntity ent) { + if (ent.getEntityType() == LeafType.NOTE) { + throw new IllegalArgumentException(); + } + if (ent.getCode().getCode().matches("[-\\w_ .]+")) { + return StringUtils.unicodeForHtml(ent.getCode().getCode()) + ".html"; + } + return StringUtils.unicodeForHtml(ent.getUid()) + ".html"; + } + +} diff --git a/src/net/sourceforge/plantuml/jasic/Jasic.java b/src/net/sourceforge/plantuml/jasic/Jasic.java new file mode 100644 index 000000000..9b96c86da --- /dev/null +++ b/src/net/sourceforge/plantuml/jasic/Jasic.java @@ -0,0 +1,891 @@ +package net.sourceforge.plantuml.jasic; + + +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * This defines a single class that contains an entire interpreter for a + * language very similar to the original BASIC. Everything is here (albeit in + * very simplified form): tokenizing, parsing, and interpretation. The file is + * organized in phases, with each appearing roughly in the order that they + * occur when a program is run. You should be able to read this top-down to walk + * through the entire process of loading and running a program. + * + * Jasic language syntax + * --------------------- + * + * Comments start with ' and proceed to the end of the line: + * + * print "hi there" ' this is a comment + * + * Numbers and strings are supported. Strings should be in "double quotes", and + * only positive integers can be parsed (though numbers are double internally). + * + * Variables are identified by name which must start with a letter and can + * contain letters or numbers. Case is significant for names and keywords. + * + * Each statement is on its own line. Optionally, a line may have a label before + * the statement. A label is a name that ends with a colon: + * + * foo: + * + * + * The following statements are supported: + * + * = + * Evaluates the expression and assigns the result to the given named + * variable. All variables are globally scoped. + * + * pi = (314159 / 10000) + * + * print + * Evaluates the expression and prints the result. + * + * print "hello, " + "world" + * + * input + * Reads in a line of input from the user and stores it in the variable with + * the given name. + * + * input guess + * + * goto
    "); + strings.add("Maybe you should set your proxy ?"); + strings.add("@startuml"); + strings.add("checkversion(proxy=myproxy.com,port=8080)"); + strings.add("@enduml"); + lim = 9; + } else if (lastversion == 0) { + strings.add("Error"); + strings.add("Cannot retrieve last version from http://plantuml.sourceforge.net/
    "); + } else { + strings.add("Last available version for download : " + lastversion); + strings.add(" "); + if (Version.version() >= lastversion) { + strings.add("Your version is up to date."); + } else { + strings.add("A newer version is available for download."); + } + } + + while (strings.size() < lim) { + strings.add(" "); + } + + return new PSystemVersion(true, strings); + } + + public static int extractDownloadableVersion(String host, String port) { + if (host != null && port != null) { + System.setProperty("http.proxyHost", host); + System.setProperty("http.proxyPort", port); + } + + try { + final URL url = new URL("http://plantuml.sourceforge.net/download.html"); + final HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); + urlConnection.setUseCaches(false); + urlConnection.connect(); + if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) { + final BufferedReader in = new BufferedReader(new InputStreamReader(urlConnection.getInputStream())); + final int lastversion = extractVersion(in); + in.close(); + urlConnection.disconnect(); + return lastversion; + } + } catch (IOException e) { + Log.error(e.toString()); + } + return -1; + } + + private static int extractVersion(BufferedReader in) throws IOException { + String s; + final Pattern p = Pattern.compile(".*\\.(\\d{4,5})\\..*"); + while ((s = in.readLine()) != null) { + final Matcher m = p.matcher(s); + if (m.matches()) { + final String v = m.group(1); + return Integer.parseInt(v); + } + } + return 0; + } + public static PSystemVersion createTestDot() throws IOException { final List strings = new ArrayList(); strings.addAll(GraphvizUtils.getTestDotStrings(true)); @@ -112,14 +241,16 @@ public class PSystemVersion extends AbstractPSystem { private GraphicStrings getGraphicStrings() throws IOException { final UFont font = new UFont("SansSerif", Font.PLAIN, 12); - return new GraphicStrings(strings, font, HtmlColor.BLACK, HtmlColor.WHITE, image, - GraphicPosition.BACKGROUND_CORNER, false); - // return new GraphicStrings(strings, font, Color.BLACK, Color.WHITE, - // false); + return new GraphicStrings(strings, font, HtmlColorUtils.BLACK, HtmlColorUtils.WHITE, image, + GraphicPosition.BACKGROUND_CORNER, UAntiAliasing.ANTI_ALIASING_ON); } - public String getDescription() { - return "(Version)"; + public DiagramDescription getDescription() { + return new DiagramDescriptionImpl("(Version)", getClass()); + } + + public List getLines() { + return Collections.unmodifiableList(strings); } } diff --git a/src/net/sourceforge/plantuml/version/PSystemVersionFactory.java b/src/net/sourceforge/plantuml/version/PSystemVersionFactory.java index 85ea6b395..ee2e3186b 100644 --- a/src/net/sourceforge/plantuml/version/PSystemVersionFactory.java +++ b/src/net/sourceforge/plantuml/version/PSystemVersionFactory.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -32,46 +32,49 @@ package net.sourceforge.plantuml.version; import java.io.IOException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; -import net.sourceforge.plantuml.DiagramType; +import net.sourceforge.plantuml.AbstractPSystem; import net.sourceforge.plantuml.Log; -import net.sourceforge.plantuml.PSystemBasicFactory; +import net.sourceforge.plantuml.command.PSystemSingleLineFactory; -public class PSystemVersionFactory implements PSystemBasicFactory { +public class PSystemVersionFactory extends PSystemSingleLineFactory { - private PSystemVersion system; - - public void init(String startLine) { - } - - public boolean executeLine(String line) { + @Override + protected AbstractPSystem executeLine(String line) { try { if (line.matches("(?i)^(authors?|about)\\s*$")) { - system = PSystemVersion.createShowAuthors(); - return true; + return PSystemVersion.createShowAuthors(); } if (line.matches("(?i)^version\\s*$")) { - system = PSystemVersion.createShowVersion(); - return true; + return PSystemVersion.createShowVersion(); } if (line.matches("(?i)^testdot\\s*$")) { - system = PSystemVersion.createTestDot(); - return true; + return PSystemVersion.createTestDot(); + } + if (line.matches("(?i)^checkversion\\s*$")) { + return PSystemVersion.createCheckVersions(null, null); + } + final Pattern p1 = Pattern.compile("(?i)^checkversion\\(proxy=([\\w.]+),port=(\\d+)\\)$"); + final Matcher m1 = p1.matcher(line); + if (m1.matches()) { + final String host = m1.group(1); + final String port = m1.group(2); + return PSystemVersion.createCheckVersions(host, port); + } + final Pattern p2 = Pattern.compile("(?i)^checkversion\\(proxy=([\\w.]+)\\)$"); + final Matcher m2 = p2.matcher(line); + if (m2.matches()) { + final String host = m2.group(1); + final String port = "80"; + return PSystemVersion.createCheckVersions(host, port); } } catch (IOException e) { Log.error("Error " + e); } - return false; + return null; } - public PSystemVersion getSystem() { - return system; - } - - public DiagramType getDiagramType() { - return DiagramType.UML; - } - - } diff --git a/src/net/sourceforge/plantuml/version/Version.java b/src/net/sourceforge/plantuml/version/Version.java index 6551a5b60..9cac684a6 100644 --- a/src/net/sourceforge/plantuml/version/Version.java +++ b/src/net/sourceforge/plantuml/version/Version.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -28,7 +28,7 @@ * * Original Author: Arnaud Roques * - * Revision $Revision: 7233 $ + * Revision $Revision: 12116 $ * */ package net.sourceforge.plantuml.version; @@ -36,11 +36,22 @@ package net.sourceforge.plantuml.version; public class Version { public static int version() { - return 7232; + return 7988; + } + + public static String versionString() { + if (beta()) { + return "" + (version() + 1) + "beta"; + } + return "" + version(); + } + + public static boolean beta() { + return false; } public static long compileTime() { - return 1315477780453L; + return 1386694921635L; } } diff --git a/src/net/sourceforge/plantuml/version/favicon.png b/src/net/sourceforge/plantuml/version/favicon.png new file mode 100644 index 000000000..f01b74a2c Binary files /dev/null and b/src/net/sourceforge/plantuml/version/favicon.png differ diff --git a/src/net/sourceforge/plantuml/xmi/CucaDiagramXmiMaker.java b/src/net/sourceforge/plantuml/xmi/CucaDiagramXmiMaker.java index 70c547b8c..354485e0c 100644 --- a/src/net/sourceforge/plantuml/xmi/CucaDiagramXmiMaker.java +++ b/src/net/sourceforge/plantuml/xmi/CucaDiagramXmiMaker.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -56,7 +56,16 @@ public final class CucaDiagramXmiMaker { public void createFiles(OutputStream fos) throws IOException { try { - final XmiClassDiagram xmi = new XmiClassDiagram((ClassDiagram) diagram, fileFormat); + final IXmiClassDiagram xmi; + if (fileFormat == FileFormat.XMI_STANDARD) { + xmi = new XmiClassDiagramStandard((ClassDiagram) diagram); + } else if (fileFormat == FileFormat.XMI_ARGO) { + xmi = new XmiClassDiagramArgo((ClassDiagram) diagram); + } else if (fileFormat == FileFormat.XMI_STAR) { + xmi = new XmiClassDiagramStar((ClassDiagram) diagram); + } else { + throw new UnsupportedOperationException(); + } xmi.transformerXml(fos); // fos.close(); // return Collections.singletonList(suggestedFile); diff --git a/src/net/sourceforge/plantuml/xmi/IXmiClassDiagram.java b/src/net/sourceforge/plantuml/xmi/IXmiClassDiagram.java new file mode 100644 index 000000000..09e57d563 --- /dev/null +++ b/src/net/sourceforge/plantuml/xmi/IXmiClassDiagram.java @@ -0,0 +1,45 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 5616 $ + * + */ +package net.sourceforge.plantuml.xmi; + +import java.io.OutputStream; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerException; + +public interface IXmiClassDiagram { + + void transformerXml(OutputStream os) throws TransformerException, ParserConfigurationException; + +} diff --git a/src/net/sourceforge/plantuml/xmi/XmiClassDiagram.java b/src/net/sourceforge/plantuml/xmi/XmiClassDiagramArgo.java similarity index 72% rename from src/net/sourceforge/plantuml/xmi/XmiClassDiagram.java rename to src/net/sourceforge/plantuml/xmi/XmiClassDiagramArgo.java index 5da50fd5f..e4dd57dee 100644 --- a/src/net/sourceforge/plantuml/xmi/XmiClassDiagram.java +++ b/src/net/sourceforge/plantuml/xmi/XmiClassDiagramArgo.java @@ -2,7 +2,7 @@ * PlantUML : a free UML diagram generator * ======================================================================== * - * (C) Copyright 2009, Arnaud Roques + * (C) Copyright 2009-2013, Arnaud Roques * * Project Info: http://plantuml.sourceforge.net * @@ -15,7 +15,7 @@ * * 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 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public * License for more details. * * You should have received a copy of the GNU General Public @@ -49,32 +49,30 @@ import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; -import net.sourceforge.plantuml.FileFormat; import net.sourceforge.plantuml.UniqueSequence; import net.sourceforge.plantuml.classdiagram.ClassDiagram; -import net.sourceforge.plantuml.cucadiagram.Entity; +import net.sourceforge.plantuml.cucadiagram.Display; import net.sourceforge.plantuml.cucadiagram.IEntity; import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.cucadiagram.LinkDecor; import net.sourceforge.plantuml.cucadiagram.Member; import org.w3c.dom.Document; import org.w3c.dom.Element; -public class XmiClassDiagram { +public class XmiClassDiagramArgo implements IXmiClassDiagram { // http://pierre.ree7.fr/blog/?p=5 private final ClassDiagram classDiagram; - private final FileFormat fileFormat; private final Document document; private final Element ownedElement; private final Set done = new HashSet(); - public XmiClassDiagram(ClassDiagram classDiagram, FileFormat fileFormat) throws ParserConfigurationException { + public XmiClassDiagramArgo(ClassDiagram classDiagram) throws ParserConfigurationException { this.classDiagram = classDiagram; - this.fileFormat = fileFormat; final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); final DocumentBuilder builder = factory.newDocumentBuilder(); @@ -110,8 +108,8 @@ public class XmiClassDiagram { this.ownedElement = document.createElement("UML:Namespace.ownedElement"); model.appendChild(ownedElement); - for (final Entity ent : classDiagram.entities().values()) { - if (fileFormat == FileFormat.XMI_ARGO && isStandalone(ent) == false) { + for (final IEntity ent : classDiagram.getLeafs().values()) { + if (classDiagram.isStandalone(ent) == false) { continue; } final Element cla = createEntityNode(ent); @@ -119,42 +117,59 @@ public class XmiClassDiagram { done.add(ent); } - if (fileFormat != FileFormat.XMI_STANDARD) { - for (final Link link : classDiagram.getLinks()) { - addLink(link); - } + // if (fileFormat != FileFormat.XMI_STANDARD) { + for (final Link link : classDiagram.getLinks()) { + addLink(link); } + // } } - private boolean isStandalone(IEntity ent) { - for (final Link link : classDiagram.getLinks()) { - if (link.getEntity1() == ent || link.getEntity2() == ent) { - return false; - } - } - return true; + public static String forXMI(String s) { + return s.replace(':', ' '); + } + + public static String forXMI(Display s) { + return s.get(0).toString().replace(':', ' '); } private void addLink(Link link) { - final Element association = document.createElement("UML:Association"); final String assId = "ass" + UniqueSequence.getValue(); +// if ((link.getType().getDecor1() == LinkDecor.EXTENDS || link.getType().getDecor2() == LinkDecor.EXTENDS) +// && fileFormat == FileFormat.XMI_STAR) { +// addExtension(link, assId); +// return; +// } + final Element association = document.createElement("UML:Association"); association.setAttribute("xmi.id", assId); association.setAttribute("namespace", "model1"); + if (link.getLabel() != null) { + association.setAttribute("name", forXMI(link.getLabel())); + } final Element connection = document.createElement("UML:Association.connection"); final Element end1 = document.createElement("UML:AssociationEnd"); end1.setAttribute("xmi.id", "end" + UniqueSequence.getValue()); end1.setAttribute("association", assId); end1.setAttribute("type", link.getEntity1().getUid()); + if (link.getQualifier1() != null) { + end1.setAttribute("name", forXMI(link.getQualifier1())); + } final Element endparticipant1 = document.createElement("UML:AssociationEnd.participant"); - if (fileFormat == FileFormat.XMI_ARGO) { + // if (fileFormat == FileFormat.XMI_ARGO) { if (done.contains(link.getEntity1())) { endparticipant1.appendChild(createEntityNodeRef(link.getEntity1())); } else { endparticipant1.appendChild(createEntityNode(link.getEntity1())); done.add(link.getEntity1()); } - } +// } else if (fileFormat == FileFormat.XMI_STAR) { +// if (link.getType().getDecor2() == LinkDecor.COMPOSITION) { +// end1.setAttribute("aggregation", "composite"); +// } +// if (link.getType().getDecor2() == LinkDecor.AGREGATION) { +// end1.setAttribute("aggregation", "aggregate"); +// } +// } end1.appendChild(endparticipant1); connection.appendChild(end1); @@ -162,15 +177,25 @@ public class XmiClassDiagram { end2.setAttribute("xmi.id", "end" + UniqueSequence.getValue()); end2.setAttribute("association", assId); end2.setAttribute("type", link.getEntity2().getUid()); + if (link.getQualifier2() != null) { + end2.setAttribute("name", forXMI(link.getQualifier2())); + } final Element endparticipant2 = document.createElement("UML:AssociationEnd.participant"); - if (fileFormat == FileFormat.XMI_ARGO) { + // if (fileFormat == FileFormat.XMI_ARGO) { if (done.contains(link.getEntity2())) { endparticipant2.appendChild(createEntityNodeRef(link.getEntity2())); } else { endparticipant2.appendChild(createEntityNode(link.getEntity2())); done.add(link.getEntity2()); } - } + // } else if (fileFormat == FileFormat.XMI_STAR) { + // if (link.getType().getDecor1() == LinkDecor.COMPOSITION) { + // end2.setAttribute("aggregation", "composite"); + // } + // if (link.getType().getDecor1() == LinkDecor.AGREGATION) { + // end2.setAttribute("aggregation", "aggregate"); + // } + // } end2.appendChild(endparticipant2); connection.appendChild(end2); @@ -180,6 +205,26 @@ public class XmiClassDiagram { } + private void addExtension(Link link, String assId) { + final Element association = document.createElement("UML:Generalization"); + association.setAttribute("xmi.id", assId); + association.setAttribute("namespace", "model1"); + if (link.getLabel() != null) { + association.setAttribute("name", forXMI(link.getLabel())); + } + if (link.getType().getDecor1() == LinkDecor.EXTENDS) { + association.setAttribute("child", link.getEntity1().getUid()); + association.setAttribute("parent", link.getEntity2().getUid()); + } else if (link.getType().getDecor2() == LinkDecor.EXTENDS) { + association.setAttribute("child", link.getEntity2().getUid()); + association.setAttribute("parent", link.getEntity1().getUid()); + } else { + throw new IllegalStateException(); + } + ownedElement.appendChild(association); + + } + private Element createEntityNode(IEntity entity) { // final Element attribute = document.createElement("UML:Attribute"); attribute.setAttribute("xmi.id", "att" + UniqueSequence.getValue()); - attribute.setAttribute("name", m.getDisplayWithoutVisibilityChar()); + attribute.setAttribute("name", m.getDisplay(false)); feature.appendChild(attribute); } @@ -214,7 +259,7 @@ public class XmiClassDiagram { // isAbstract="false" specification="" owner="UMLClass.5"/> final Element operation = document.createElement("UML:Operation"); operation.setAttribute("xmi.id", "att" + UniqueSequence.getValue()); - operation.setAttribute("name", m.getDisplayWithoutVisibilityChar()); + operation.setAttribute("name", m.getDisplay(false)); feature.appendChild(operation); } return cla; diff --git a/src/net/sourceforge/plantuml/xmi/XmiClassDiagramStandard.java b/src/net/sourceforge/plantuml/xmi/XmiClassDiagramStandard.java new file mode 100644 index 000000000..e5e4fa0b3 --- /dev/null +++ b/src/net/sourceforge/plantuml/xmi/XmiClassDiagramStandard.java @@ -0,0 +1,296 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 5616 $ + * + */ +package net.sourceforge.plantuml.xmi; + +import java.io.OutputStream; +import java.util.HashSet; +import java.util.Set; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import net.sourceforge.plantuml.UniqueSequence; +import net.sourceforge.plantuml.classdiagram.ClassDiagram; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.cucadiagram.LinkDecor; +import net.sourceforge.plantuml.cucadiagram.Member; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class XmiClassDiagramStandard implements IXmiClassDiagram { + + // http://pierre.ree7.fr/blog/?p=5 + + private final ClassDiagram classDiagram; + private final Document document; + private final Element ownedElement; + + private final Set done = new HashSet(); + + public XmiClassDiagramStandard(ClassDiagram classDiagram) throws ParserConfigurationException { + this.classDiagram = classDiagram; + final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + + final DocumentBuilder builder = factory.newDocumentBuilder(); + this.document = builder.newDocument(); + document.setXmlVersion("1.0"); + document.setXmlStandalone(true); + + final Element xmi = document.createElement("XMI"); + xmi.setAttribute("xmi.version", "1.1"); + xmi.setAttribute("xmlns:UML", "href://org.omg/UML/1.3"); + document.appendChild(xmi); + + final Element header = document.createElement("XMI.header"); + xmi.appendChild(header); + + final Element metamodel = document.createElement("XMI.metamodel"); + metamodel.setAttribute("xmi.name", "UML"); + metamodel.setAttribute("xmi.version", "1.3"); + header.appendChild(metamodel); + + final Element content = document.createElement("XMI.content"); + xmi.appendChild(content); + + // + final Element model = document.createElement("UML:Model"); + model.setAttribute("xmi.id", "model1"); + model.setAttribute("name", "PlantUML"); + content.appendChild(model); + + // + this.ownedElement = document.createElement("UML:Namespace.ownedElement"); + model.appendChild(ownedElement); + + for (final IEntity ent : classDiagram.getLeafs().values()) { + // if (fileFormat == FileFormat.XMI_ARGO && isStandalone(ent) == false) { + // continue; + // } + final Element cla = createEntityNode(ent); + ownedElement.appendChild(cla); + done.add(ent); + } + + // if (fileFormat != FileFormat.XMI_STANDARD) { + // for (final Link link : classDiagram.getLinks()) { + // addLink(link); + // } + // } + } + +// private boolean isStandalone(IEntity ent) { +// for (final Link link : classDiagram.getLinks()) { +// if (link.getEntity1() == ent || link.getEntity2() == ent) { +// return false; +// } +// } +// return true; +// } + + public static String forXMI(String s) { + return s.replace(':', ' '); + } + + public static String forXMI(Display s) { + return s.get(0).toString().replace(':', ' '); + } + + private void addLink(Link link) { + final String assId = "ass" + UniqueSequence.getValue(); + // if ((link.getType().getDecor1() == LinkDecor.EXTENDS || link.getType().getDecor2() == LinkDecor.EXTENDS) + // && fileFormat == FileFormat.XMI_STAR) { + // addExtension(link, assId); + // return; + // } + final Element association = document.createElement("UML:Association"); + association.setAttribute("xmi.id", assId); + association.setAttribute("namespace", "model1"); + if (link.getLabel() != null) { + association.setAttribute("name", forXMI(link.getLabel())); + } + + final Element connection = document.createElement("UML:Association.connection"); + final Element end1 = document.createElement("UML:AssociationEnd"); + end1.setAttribute("xmi.id", "end" + UniqueSequence.getValue()); + end1.setAttribute("association", assId); + end1.setAttribute("type", link.getEntity1().getUid()); + if (link.getQualifier1() != null) { + end1.setAttribute("name", forXMI(link.getQualifier1())); + } + final Element endparticipant1 = document.createElement("UML:AssociationEnd.participant"); + // if (fileFormat == FileFormat.XMI_ARGO) { + // if (done.contains(link.getEntity1())) { + // endparticipant1.appendChild(createEntityNodeRef(link.getEntity1())); + // } else { + // endparticipant1.appendChild(createEntityNode(link.getEntity1())); + // done.add(link.getEntity1()); + // } + // } else if (fileFormat == FileFormat.XMI_STAR) { + // if (link.getType().getDecor2() == LinkDecor.COMPOSITION) { + // end1.setAttribute("aggregation", "composite"); + // } + // if (link.getType().getDecor2() == LinkDecor.AGREGATION) { + // end1.setAttribute("aggregation", "aggregate"); + // } + // } + end1.appendChild(endparticipant1); + connection.appendChild(end1); + + final Element end2 = document.createElement("UML:AssociationEnd"); + end2.setAttribute("xmi.id", "end" + UniqueSequence.getValue()); + end2.setAttribute("association", assId); + end2.setAttribute("type", link.getEntity2().getUid()); + if (link.getQualifier2() != null) { + end2.setAttribute("name", forXMI(link.getQualifier2())); + } + final Element endparticipant2 = document.createElement("UML:AssociationEnd.participant"); + // if (fileFormat == FileFormat.XMI_ARGO) { + // if (done.contains(link.getEntity2())) { + // endparticipant2.appendChild(createEntityNodeRef(link.getEntity2())); + // } else { + // endparticipant2.appendChild(createEntityNode(link.getEntity2())); + // done.add(link.getEntity2()); + // } + // } else if (fileFormat == FileFormat.XMI_STAR) { + // if (link.getType().getDecor1() == LinkDecor.COMPOSITION) { + // end2.setAttribute("aggregation", "composite"); + // } + // if (link.getType().getDecor1() == LinkDecor.AGREGATION) { + // end2.setAttribute("aggregation", "aggregate"); + // } + // } + end2.appendChild(endparticipant2); + connection.appendChild(end2); + + association.appendChild(connection); + + ownedElement.appendChild(association); + + } + + private void addExtension(Link link, String assId) { + final Element association = document.createElement("UML:Generalization"); + association.setAttribute("xmi.id", assId); + association.setAttribute("namespace", "model1"); + if (link.getLabel() != null) { + association.setAttribute("name", forXMI(link.getLabel())); + } + if (link.getType().getDecor1() == LinkDecor.EXTENDS) { + association.setAttribute("child", link.getEntity1().getUid()); + association.setAttribute("parent", link.getEntity2().getUid()); + } else if (link.getType().getDecor2() == LinkDecor.EXTENDS) { + association.setAttribute("child", link.getEntity2().getUid()); + association.setAttribute("parent", link.getEntity1().getUid()); + } else { + throw new IllegalStateException(); + } + ownedElement.appendChild(association); + + } + + private Element createEntityNode(IEntity entity) { + // + final Element cla = document.createElement("UML:Class"); + + cla.setAttribute("xmi.id", entity.getUid()); + cla.setAttribute("name", entity.getDisplay().get(0).toString()); + cla.setAttribute("namespace", "model1"); + + final Element feature = document.createElement("UML:Classifier.feature"); + cla.appendChild(feature); + + for (Member m : entity.getFieldsToDisplay()) { + // + final Element attribute = document.createElement("UML:Attribute"); + attribute.setAttribute("xmi.id", "att" + UniqueSequence.getValue()); + attribute.setAttribute("name", m.getDisplay(false)); + feature.appendChild(attribute); + } + + for (Member m : entity.getMethodsToDisplay()) { + // + final Element operation = document.createElement("UML:Operation"); + operation.setAttribute("xmi.id", "att" + UniqueSequence.getValue()); + operation.setAttribute("name", m.getDisplay(false)); + feature.appendChild(operation); + } + return cla; + } + + private Element createEntityNodeRef(IEntity entity) { + final Element cla = document.createElement("UML:Class"); + cla.setAttribute("xmi.idref", entity.getUid()); + return cla; + } + + public void transformerXml(OutputStream os) throws TransformerException, ParserConfigurationException { + final Source source = new DOMSource(document); + + final Result resultat = new StreamResult(os); + + final TransformerFactory fabrique = TransformerFactory.newInstance(); + final Transformer transformer = fabrique.newTransformer(); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + // transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1"); + transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + // tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + transformer.transform(source, resultat); + } + +} diff --git a/src/net/sourceforge/plantuml/xmi/XmiClassDiagramStar.java b/src/net/sourceforge/plantuml/xmi/XmiClassDiagramStar.java new file mode 100644 index 000000000..2d2eeda16 --- /dev/null +++ b/src/net/sourceforge/plantuml/xmi/XmiClassDiagramStar.java @@ -0,0 +1,293 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2013, 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 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: 5616 $ + * + */ +package net.sourceforge.plantuml.xmi; + +import java.io.OutputStream; +import java.util.HashSet; +import java.util.Set; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import net.sourceforge.plantuml.UniqueSequence; +import net.sourceforge.plantuml.classdiagram.ClassDiagram; +import net.sourceforge.plantuml.cucadiagram.Display; +import net.sourceforge.plantuml.cucadiagram.IEntity; +import net.sourceforge.plantuml.cucadiagram.Link; +import net.sourceforge.plantuml.cucadiagram.LinkDecor; +import net.sourceforge.plantuml.cucadiagram.Member; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class XmiClassDiagramStar implements IXmiClassDiagram { + + private final ClassDiagram classDiagram; + private final Document document; + private final Element ownedElement; + + private final Set done = new HashSet(); + + public XmiClassDiagramStar(ClassDiagram classDiagram) throws ParserConfigurationException { + this.classDiagram = classDiagram; + final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + + final DocumentBuilder builder = factory.newDocumentBuilder(); + this.document = builder.newDocument(); + document.setXmlVersion("1.0"); + document.setXmlStandalone(true); + + final Element xmi = document.createElement("XMI"); + xmi.setAttribute("xmi.version", "1.1"); + xmi.setAttribute("xmlns:UML", "href://org.omg/UML/1.3"); + document.appendChild(xmi); + + final Element header = document.createElement("XMI.header"); + xmi.appendChild(header); + + final Element metamodel = document.createElement("XMI.metamodel"); + metamodel.setAttribute("xmi.name", "UML"); + metamodel.setAttribute("xmi.version", "1.3"); + header.appendChild(metamodel); + + final Element content = document.createElement("XMI.content"); + xmi.appendChild(content); + + // + final Element model = document.createElement("UML:Model"); + model.setAttribute("xmi.id", "model1"); + model.setAttribute("name", "PlantUML"); + content.appendChild(model); + + // + this.ownedElement = document.createElement("UML:Namespace.ownedElement"); + model.appendChild(ownedElement); + + for (final IEntity ent : classDiagram.getLeafs().values()) { + // if (fileFormat == FileFormat.XMI_ARGO && isStandalone(ent) == false) { + // continue; + // } + final Element cla = createEntityNode(ent); + ownedElement.appendChild(cla); + done.add(ent); + } + + // if (fileFormat != FileFormat.XMI_STANDARD) { + for (final Link link : classDiagram.getLinks()) { + addLink(link); + } + // } + } + +// private boolean isStandalone(IEntity ent) { +// for (final Link link : classDiagram.getLinks()) { +// if (link.getEntity1() == ent || link.getEntity2() == ent) { +// return false; +// } +// } +// return true; +// } + + public static String forXMI(String s) { + return s.replace(':', ' '); + } + + public static String forXMI(Display s) { + return s.get(0).toString().replace(':', ' '); + } + + private void addLink(Link link) { + final String assId = "ass" + UniqueSequence.getValue(); + if (link.getType().getDecor1() == LinkDecor.EXTENDS || link.getType().getDecor2() == LinkDecor.EXTENDS) { + addExtension(link, assId); + return; + } + final Element association = document.createElement("UML:Association"); + association.setAttribute("xmi.id", assId); + association.setAttribute("namespace", "model1"); + if (link.getLabel() != null) { + association.setAttribute("name", forXMI(link.getLabel())); + } + + final Element connection = document.createElement("UML:Association.connection"); + final Element end1 = document.createElement("UML:AssociationEnd"); + end1.setAttribute("xmi.id", "end" + UniqueSequence.getValue()); + end1.setAttribute("association", assId); + end1.setAttribute("type", link.getEntity1().getUid()); + if (link.getQualifier1() != null) { + end1.setAttribute("name", forXMI(link.getQualifier1())); + } + final Element endparticipant1 = document.createElement("UML:AssociationEnd.participant"); + // if (fileFormat == FileFormat.XMI_ARGO) { + // if (done.contains(link.getEntity1())) { + // endparticipant1.appendChild(createEntityNodeRef(link.getEntity1())); + // } else { + // endparticipant1.appendChild(createEntityNode(link.getEntity1())); + // done.add(link.getEntity1()); + // } + // } else if (fileFormat == FileFormat.XMI_STAR) { + if (link.getType().getDecor2() == LinkDecor.COMPOSITION) { + end1.setAttribute("aggregation", "composite"); + } + if (link.getType().getDecor2() == LinkDecor.AGREGATION) { + end1.setAttribute("aggregation", "aggregate"); + } + // } + end1.appendChild(endparticipant1); + connection.appendChild(end1); + + final Element end2 = document.createElement("UML:AssociationEnd"); + end2.setAttribute("xmi.id", "end" + UniqueSequence.getValue()); + end2.setAttribute("association", assId); + end2.setAttribute("type", link.getEntity2().getUid()); + if (link.getQualifier2() != null) { + end2.setAttribute("name", forXMI(link.getQualifier2())); + } + final Element endparticipant2 = document.createElement("UML:AssociationEnd.participant"); + // if (fileFormat == FileFormat.XMI_ARGO) { + // if (done.contains(link.getEntity2())) { + // endparticipant2.appendChild(createEntityNodeRef(link.getEntity2())); + // } else { + // endparticipant2.appendChild(createEntityNode(link.getEntity2())); + // done.add(link.getEntity2()); + // } + // } else if (fileFormat == FileFormat.XMI_STAR) { + if (link.getType().getDecor1() == LinkDecor.COMPOSITION) { + end2.setAttribute("aggregation", "composite"); + } + if (link.getType().getDecor1() == LinkDecor.AGREGATION) { + end2.setAttribute("aggregation", "aggregate"); + } + // } + end2.appendChild(endparticipant2); + connection.appendChild(end2); + + association.appendChild(connection); + + ownedElement.appendChild(association); + + } + + private void addExtension(Link link, String assId) { + final Element association = document.createElement("UML:Generalization"); + association.setAttribute("xmi.id", assId); + association.setAttribute("namespace", "model1"); + if (link.getLabel() != null) { + association.setAttribute("name", forXMI(link.getLabel())); + } + if (link.getType().getDecor1() == LinkDecor.EXTENDS) { + association.setAttribute("child", link.getEntity1().getUid()); + association.setAttribute("parent", link.getEntity2().getUid()); + } else if (link.getType().getDecor2() == LinkDecor.EXTENDS) { + association.setAttribute("child", link.getEntity2().getUid()); + association.setAttribute("parent", link.getEntity1().getUid()); + } else { + throw new IllegalStateException(); + } + ownedElement.appendChild(association); + + } + + private Element createEntityNode(IEntity entity) { + // + final Element cla = document.createElement("UML:Class"); + + cla.setAttribute("xmi.id", entity.getUid()); + cla.setAttribute("name", entity.getDisplay().get(0).toString()); + cla.setAttribute("namespace", "model1"); + + final Element feature = document.createElement("UML:Classifier.feature"); + cla.appendChild(feature); + + for (Member m : entity.getFieldsToDisplay()) { + // + final Element attribute = document.createElement("UML:Attribute"); + attribute.setAttribute("xmi.id", "att" + UniqueSequence.getValue()); + attribute.setAttribute("name", m.getDisplay(false)); + feature.appendChild(attribute); + } + + for (Member m : entity.getMethodsToDisplay()) { + // + final Element operation = document.createElement("UML:Operation"); + operation.setAttribute("xmi.id", "att" + UniqueSequence.getValue()); + operation.setAttribute("name", m.getDisplay(false)); + feature.appendChild(operation); + } + return cla; + } + + private Element createEntityNodeRef(IEntity entity) { + final Element cla = document.createElement("UML:Class"); + cla.setAttribute("xmi.idref", entity.getUid()); + return cla; + } + + public void transformerXml(OutputStream os) throws TransformerException, ParserConfigurationException { + final Source source = new DOMSource(document); + + final Result resultat = new StreamResult(os); + + final TransformerFactory fabrique = TransformerFactory.newInstance(); + final Transformer transformer = fabrique.newTransformer(); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + // transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1"); + transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + // tf.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); + transformer.transform(source, resultat); + } + +} diff --git a/src/org/stathissideris/ascii2image/core/ConversionOptions.java b/src/org/stathissideris/ascii2image/core/ConversionOptions.java index 922c26da4..17df7a975 100644 --- a/src/org/stathissideris/ascii2image/core/ConversionOptions.java +++ b/src/org/stathissideris/ascii2image/core/ConversionOptions.java @@ -38,6 +38,10 @@ public class ConversionOptions { } public ConversionOptions(){} + + public void setDropShadows(boolean dropShadows) { + renderingOptions.setDropShadows(dropShadows); + } // public ConversionOptions(CommandLine cmdLine) throws UnsupportedEncodingException{ // diff --git a/src/org/stathissideris/ascii2image/graphics/BitmapRenderer.java b/src/org/stathissideris/ascii2image/graphics/BitmapRenderer.java index c2d1d0c70..5ac634ae8 100644 --- a/src/org/stathissideris/ascii2image/graphics/BitmapRenderer.java +++ b/src/org/stathissideris/ascii2image/graphics/BitmapRenderer.java @@ -43,10 +43,8 @@ import java.util.Iterator; import javax.imageio.ImageIO; -import org.stathissideris.ascii2image.core.ConversionOptions; import org.stathissideris.ascii2image.core.RenderingOptions; import org.stathissideris.ascii2image.core.Shape3DOrderingComparator; -import org.stathissideris.ascii2image.text.TextGrid; /** * diff --git a/src/overview.html b/src/overview.html new file mode 100644 index 000000000..da906cd27 --- /dev/null +++ b/src/overview.html @@ -0,0 +1,58 @@ + + + +

    PlantUML is an open-source component used to draw UML diagrams from their textual description.

    + +

    Overview

    +This documentation will not describe the PlantUML language description. +Please refer to PlantUML site for that. +

    +Here, some information about how PlantUML is implemented will be provided to help the +integration of PlantUML with other programs. +

    +Unfortunatly, here, we have to raise a warning: +
    +While PlantUML language description remains stable over version and follow ascending +compatibility, the implementation of PlantUML changes very often over time. +

    +So if you use classes described in this documentation, it's very likely that you will have +an issue someday, because thoses class may change without any notice. They could even be deleted. +

    It used to happen more often than you think over years, because we try to constantly improve the +general design of PlantUML, and this imply a continuous refactoring. +

    The only exception is the net.sourceforge.plantuml package, that we will keep +as stable as possible over time. +

    + + +