2013-12-10 19:36:50 +00:00
|
|
|
/* ========================================================================
|
|
|
|
* PlantUML : a free UML diagram generator
|
|
|
|
* ========================================================================
|
|
|
|
*
|
2016-01-09 12:15:40 +00:00
|
|
|
* (C) Copyright 2009-2017, Arnaud Roques
|
2013-12-10 19:36:50 +00:00
|
|
|
*
|
2016-03-06 16:47:34 +00:00
|
|
|
* Project Info: http://plantuml.com
|
2013-12-10 19:36:50 +00:00
|
|
|
*
|
|
|
|
* This file is part of PlantUML.
|
|
|
|
*
|
|
|
|
* PlantUML is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* PlantUML distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
|
|
|
* License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
|
|
* USA.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Original Author: Arnaud Roques
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
package net.sourceforge.plantuml.svek;
|
|
|
|
|
|
|
|
import java.awt.Font;
|
2015-04-07 18:18:37 +00:00
|
|
|
import java.awt.geom.Dimension2D;
|
|
|
|
import java.awt.image.BufferedImage;
|
2013-12-10 19:36:50 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2015-04-07 18:18:37 +00:00
|
|
|
import net.sourceforge.plantuml.Dimension2DDouble;
|
|
|
|
import net.sourceforge.plantuml.cucadiagram.dot.GraphvizUtils;
|
|
|
|
import net.sourceforge.plantuml.flashcode.FlashCodeFactory;
|
|
|
|
import net.sourceforge.plantuml.flashcode.FlashCodeUtils;
|
|
|
|
import net.sourceforge.plantuml.fun.IconLoader;
|
2015-06-07 10:23:10 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.AbstractTextBlock;
|
2015-04-07 18:18:37 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.GraphicPosition;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.GraphicStrings;
|
2015-04-07 18:18:37 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.HtmlColor;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.HtmlColorUtils;
|
|
|
|
import net.sourceforge.plantuml.graphic.QuoteUtils;
|
2015-04-07 18:18:37 +00:00
|
|
|
import net.sourceforge.plantuml.graphic.StringBounder;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.UAntiAliasing;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UFont;
|
2015-04-07 18:18:37 +00:00
|
|
|
import net.sourceforge.plantuml.ugraphic.UGraphic;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UImage;
|
|
|
|
import net.sourceforge.plantuml.ugraphic.UTranslate;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.version.Version;
|
|
|
|
|
2015-06-07 10:23:10 +00:00
|
|
|
public class GraphvizCrash extends AbstractTextBlock implements IEntityImage {
|
2013-12-10 19:36:50 +00:00
|
|
|
|
|
|
|
private static final UFont font = new UFont("SansSerif", Font.PLAIN, 12);
|
|
|
|
|
2015-04-07 18:18:37 +00:00
|
|
|
private final GraphicStrings graphicStrings;
|
|
|
|
private final BufferedImage flashCode;
|
|
|
|
|
|
|
|
public GraphvizCrash(String text) {
|
|
|
|
final FlashCodeUtils utils = FlashCodeFactory.getFlashCodeUtils();
|
|
|
|
flashCode = utils.exportFlashcode(text);
|
|
|
|
this.graphicStrings = new GraphicStrings(init(), font, HtmlColorUtils.BLACK, HtmlColorUtils.WHITE,
|
|
|
|
UAntiAliasing.ANTI_ALIASING_ON, IconLoader.getRandom(), GraphicPosition.BACKGROUND_CORNER_TOP_RIGHT);
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|
|
|
|
|
2016-05-11 21:31:47 +00:00
|
|
|
public static List<String> anErrorHasOccured(Throwable exception) {
|
2013-12-10 19:36:50 +00:00
|
|
|
final List<String> strings = new ArrayList<String>();
|
2016-05-11 21:31:47 +00:00
|
|
|
if (exception == null) {
|
|
|
|
strings.add("An error has occured!");
|
|
|
|
} else {
|
|
|
|
strings.add("An error has occured : " + exception);
|
|
|
|
}
|
2013-12-10 19:36:50 +00:00
|
|
|
final String quote = QuoteUtils.getSomeQuote();
|
|
|
|
strings.add("<i>" + quote);
|
|
|
|
strings.add(" ");
|
2016-05-11 21:31:47 +00:00
|
|
|
return strings;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void checkOldVersionWarning(final List<String> strings) {
|
|
|
|
final long days = (System.currentTimeMillis() - Version.compileTime()) / 1000L / 3600 / 24;
|
|
|
|
if (days >= 90) {
|
|
|
|
strings.add("This version of PlantUML is " + days + " days old, so you should");
|
|
|
|
strings.add(" consider upgrading from http://plantuml.com/download.html");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void pleaseGoTo(final List<String> strings) {
|
|
|
|
strings.add(" ");
|
|
|
|
strings.add("Please go to http://plantuml.com/graphvizdot.html to check your GraphViz version.");
|
|
|
|
strings.add(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void youShouldSendThisDiagram(final List<String> strings) {
|
|
|
|
strings.add("You should send this diagram and this image to <b>plantuml@gmail.com</b> or");
|
|
|
|
strings.add("post to <b>http://plantuml.com/qa</b> to solve this issue.");
|
|
|
|
strings.add("You can try to turn arround this issue by simplifing your diagram.");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void thisMayBeCaused(final List<String> strings) {
|
|
|
|
strings.add("This may be caused by :");
|
|
|
|
strings.add(" - a bug in PlantUML");
|
|
|
|
strings.add(" - a problem in GraphViz");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<String> init() {
|
|
|
|
final List<String> strings = anErrorHasOccured(null);
|
2013-12-10 19:36:50 +00:00
|
|
|
strings.add("For some reason, dot/Graphviz has crashed.");
|
|
|
|
strings.add("This has been generated with PlantUML (" + Version.versionString() + ").");
|
2016-05-11 21:31:47 +00:00
|
|
|
checkOldVersionWarning(strings);
|
2013-12-10 19:36:50 +00:00
|
|
|
strings.add(" ");
|
2015-04-07 18:18:37 +00:00
|
|
|
addProperties(strings);
|
|
|
|
strings.add(" ");
|
|
|
|
try {
|
|
|
|
final String dotVersion = GraphvizUtils.dotVersion();
|
|
|
|
strings.add("Default dot version: " + dotVersion);
|
|
|
|
} catch (Throwable e) {
|
|
|
|
strings.add("Cannot determine dot version: " + e.toString());
|
|
|
|
}
|
2016-05-11 21:31:47 +00:00
|
|
|
pleaseGoTo(strings);
|
|
|
|
youShouldSendThisDiagram(strings);
|
2015-04-07 18:18:37 +00:00
|
|
|
if (flashCode != null) {
|
|
|
|
addDecodeHint(strings);
|
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
return strings;
|
|
|
|
}
|
|
|
|
|
2015-04-07 18:18:37 +00:00
|
|
|
public static void addDecodeHint(final List<String> strings) {
|
|
|
|
strings.add(" ");
|
|
|
|
strings.add(" Diagram source: (Use http://zxing.org/w/decode.jspx to decode the flashcode)");
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void addProperties(final List<String> strings) {
|
|
|
|
addTextProperty(strings, "os.version");
|
|
|
|
addTextProperty(strings, "os.name");
|
|
|
|
addTextProperty(strings, "java.vm.vendor");
|
|
|
|
addTextProperty(strings, "java.vm.version");
|
|
|
|
addTextProperty(strings, "java.version");
|
|
|
|
addTextProperty(strings, "user.language");
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void addTextProperty(final List<String> strings, String prop) {
|
|
|
|
strings.add(prop + ": " + System.getProperty(prop));
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isHidden() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public HtmlColor getBackcolor() {
|
|
|
|
return HtmlColorUtils.WHITE;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Dimension2D calculateDimension(StringBounder stringBounder) {
|
|
|
|
Dimension2D result = graphicStrings.calculateDimension(stringBounder);
|
|
|
|
if (flashCode != null) {
|
|
|
|
result = Dimension2DDouble.mergeTB(result,
|
|
|
|
new Dimension2DDouble(flashCode.getWidth(), flashCode.getHeight()));
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void drawU(UGraphic ug) {
|
|
|
|
graphicStrings.drawU(ug);
|
|
|
|
if (flashCode != null) {
|
|
|
|
final double h = graphicStrings.calculateDimension(ug.getStringBounder()).getHeight();
|
|
|
|
ug = ug.apply(new UTranslate(0, h));
|
|
|
|
ug.draw(new UImage(flashCode));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public ShapeType getShapeType() {
|
|
|
|
return ShapeType.RECTANGLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getShield() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-12-10 19:36:50 +00:00
|
|
|
}
|