2010-11-15 20:35:36 +00:00
|
|
|
/* ========================================================================
|
|
|
|
* PlantUML : a free UML diagram generator
|
|
|
|
* ========================================================================
|
|
|
|
*
|
2023-02-22 18:43:48 +00:00
|
|
|
* (C) Copyright 2009-2024, Arnaud Roques
|
2010-11-15 20:35:36 +00:00
|
|
|
*
|
2023-02-22 18:43:48 +00:00
|
|
|
* Project Info: https://plantuml.com
|
2010-11-15 20:35:36 +00:00
|
|
|
*
|
2017-03-15 19:13:31 +00:00
|
|
|
* If you like this project or if you find it useful, you can support us at:
|
|
|
|
*
|
2023-02-22 18:43:48 +00:00
|
|
|
* https://plantuml.com/patreon (only 1$ per month!)
|
|
|
|
* https://plantuml.com/paypal
|
2017-03-15 19:13:31 +00:00
|
|
|
*
|
2010-11-15 20:35:36 +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
|
2013-12-10 19:36:50 +00:00
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
|
2010-11-15 20:35:36 +00:00
|
|
|
* License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*/
|
2019-05-24 19:59:31 +00:00
|
|
|
package net.sourceforge.plantuml.error;
|
2010-11-15 20:35:36 +00:00
|
|
|
|
2017-03-15 19:13:31 +00:00
|
|
|
import java.awt.Color;
|
2018-09-23 12:15:14 +00:00
|
|
|
import java.awt.image.BufferedImage;
|
2010-11-15 20:35:36 +00:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.OutputStream;
|
|
|
|
import java.util.ArrayList;
|
2019-05-24 19:59:31 +00:00
|
|
|
import java.util.Arrays;
|
2010-11-15 20:35:36 +00:00
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
2023-02-22 18:43:48 +00:00
|
|
|
import net.atmp.ImageBuilder;
|
|
|
|
import net.atmp.PixelImage;
|
2019-05-24 19:59:31 +00:00
|
|
|
import net.sourceforge.plantuml.ErrorUml;
|
|
|
|
import net.sourceforge.plantuml.FileFormat;
|
|
|
|
import net.sourceforge.plantuml.FileFormatOption;
|
|
|
|
import net.sourceforge.plantuml.FileImageData;
|
2021-03-23 09:40:50 +00:00
|
|
|
import net.sourceforge.plantuml.PlainDiagram;
|
2015-04-07 18:18:37 +00:00
|
|
|
import net.sourceforge.plantuml.api.ImageDataSimple;
|
|
|
|
import net.sourceforge.plantuml.asciiart.UmlCharArea;
|
2013-12-10 19:36:50 +00:00
|
|
|
import net.sourceforge.plantuml.core.DiagramDescription;
|
|
|
|
import net.sourceforge.plantuml.core.ImageData;
|
2021-05-23 15:35:13 +00:00
|
|
|
import net.sourceforge.plantuml.core.UmlSource;
|
2017-03-15 19:13:31 +00:00
|
|
|
import net.sourceforge.plantuml.eggs.PSystemWelcome;
|
2018-09-23 12:15:14 +00:00
|
|
|
import net.sourceforge.plantuml.flashcode.FlashCodeFactory;
|
2023-02-22 18:43:48 +00:00
|
|
|
import net.sourceforge.plantuml.klimt.AffineTransformType;
|
2023-02-02 17:59:43 +00:00
|
|
|
import net.sourceforge.plantuml.klimt.UTranslate;
|
|
|
|
import net.sourceforge.plantuml.klimt.color.HColor;
|
|
|
|
import net.sourceforge.plantuml.klimt.color.HColorSet;
|
|
|
|
import net.sourceforge.plantuml.klimt.color.HColorSimple;
|
|
|
|
import net.sourceforge.plantuml.klimt.color.HColors;
|
2023-02-22 18:43:48 +00:00
|
|
|
import net.sourceforge.plantuml.klimt.creole.Display;
|
|
|
|
import net.sourceforge.plantuml.klimt.drawing.UGraphic;
|
|
|
|
import net.sourceforge.plantuml.klimt.drawing.txt.UGraphicTxt;
|
2023-02-02 17:59:43 +00:00
|
|
|
import net.sourceforge.plantuml.klimt.font.FontConfiguration;
|
|
|
|
import net.sourceforge.plantuml.klimt.font.StringBounder;
|
|
|
|
import net.sourceforge.plantuml.klimt.font.UFont;
|
2023-02-22 18:43:48 +00:00
|
|
|
import net.sourceforge.plantuml.klimt.geom.GraphicPosition;
|
2023-02-02 17:59:43 +00:00
|
|
|
import net.sourceforge.plantuml.klimt.geom.HorizontalAlignment;
|
|
|
|
import net.sourceforge.plantuml.klimt.geom.MinMax;
|
2023-02-22 18:43:48 +00:00
|
|
|
import net.sourceforge.plantuml.klimt.geom.VerticalAlignment;
|
|
|
|
import net.sourceforge.plantuml.klimt.geom.XDimension2D;
|
2023-02-26 18:51:17 +00:00
|
|
|
import net.sourceforge.plantuml.klimt.shape.AbstractTextBlock;
|
2023-02-22 18:43:48 +00:00
|
|
|
import net.sourceforge.plantuml.klimt.shape.GraphicStrings;
|
|
|
|
import net.sourceforge.plantuml.klimt.shape.TextBlock;
|
|
|
|
import net.sourceforge.plantuml.klimt.shape.TextBlockRaw;
|
|
|
|
import net.sourceforge.plantuml.klimt.shape.TextBlockUtils;
|
|
|
|
import net.sourceforge.plantuml.klimt.shape.UDrawable;
|
|
|
|
import net.sourceforge.plantuml.klimt.shape.UImage;
|
|
|
|
import net.sourceforge.plantuml.klimt.sprite.SpriteContainerEmpty;
|
2020-05-30 15:20:23 +00:00
|
|
|
import net.sourceforge.plantuml.security.SecurityUtils;
|
2020-06-28 12:40:33 +00:00
|
|
|
import net.sourceforge.plantuml.svek.GraphvizCrash;
|
2023-02-02 17:59:43 +00:00
|
|
|
import net.sourceforge.plantuml.text.BackSlash;
|
|
|
|
import net.sourceforge.plantuml.text.StringLocated;
|
2022-12-17 11:01:10 +00:00
|
|
|
import net.sourceforge.plantuml.utils.LineLocation;
|
2018-09-23 12:15:14 +00:00
|
|
|
import net.sourceforge.plantuml.version.LicenseInfo;
|
2017-03-15 19:13:31 +00:00
|
|
|
import net.sourceforge.plantuml.version.PSystemVersion;
|
2020-06-28 12:40:33 +00:00
|
|
|
import net.sourceforge.plantuml.version.Version;
|
2010-11-15 20:35:36 +00:00
|
|
|
|
2021-03-23 09:40:50 +00:00
|
|
|
public abstract class PSystemError extends PlainDiagram {
|
2021-09-13 16:22:02 +00:00
|
|
|
|
|
|
|
// Dodgy kludge for testing - we will need a different approach if we want to
|
|
|
|
// test addMessageDedication() etc.
|
2021-09-03 07:51:22 +00:00
|
|
|
private static boolean disableTimeBasedErrorDecorations = false;
|
|
|
|
|
|
|
|
public static void disableTimeBasedErrorDecorations() {
|
|
|
|
PSystemError.disableTimeBasedErrorDecorations = true;
|
|
|
|
}
|
2010-11-15 20:35:36 +00:00
|
|
|
|
2019-05-24 19:59:31 +00:00
|
|
|
protected List<StringLocated> trace;
|
|
|
|
protected ErrorUml singleError;
|
2015-05-31 18:56:03 +00:00
|
|
|
|
2021-05-23 15:35:13 +00:00
|
|
|
public PSystemError(UmlSource source) {
|
|
|
|
super(source);
|
|
|
|
}
|
|
|
|
|
2021-03-23 09:40:50 +00:00
|
|
|
@Override
|
2021-04-04 13:45:56 +00:00
|
|
|
public ImageBuilder createImageBuilder(FileFormatOption fileFormatOption) throws IOException {
|
2021-05-23 15:35:13 +00:00
|
|
|
return super.createImageBuilder(fileFormatOption).blackBackcolor().randomPixel().status(FileImageData.ERROR);
|
2021-03-23 09:40:50 +00:00
|
|
|
}
|
|
|
|
|
2019-05-24 19:59:31 +00:00
|
|
|
final protected StringLocated getLastLine() {
|
|
|
|
return trace.get(trace.size() - 1);
|
2015-05-31 18:56:03 +00:00
|
|
|
}
|
2010-11-15 20:35:36 +00:00
|
|
|
|
2019-05-24 19:59:31 +00:00
|
|
|
final public LineLocation getLineLocation() {
|
|
|
|
return getLastLine().getLocation();
|
|
|
|
}
|
2010-11-15 20:35:36 +00:00
|
|
|
|
2019-05-24 19:59:31 +00:00
|
|
|
final public Collection<ErrorUml> getErrorsUml() {
|
|
|
|
return Collections.singleton(singleError);
|
|
|
|
}
|
2011-01-13 21:52:37 +00:00
|
|
|
|
2021-03-18 13:12:00 +00:00
|
|
|
final public ErrorUml getFirstError() {
|
|
|
|
return singleError;
|
|
|
|
}
|
|
|
|
|
2019-05-24 19:59:31 +00:00
|
|
|
final public String getWarningOrError() {
|
|
|
|
final StringBuilder sb = new StringBuilder();
|
|
|
|
sb.append(getDescription());
|
|
|
|
sb.append(BackSlash.CHAR_NEWLINE);
|
|
|
|
for (CharSequence t : getTitle().getDisplay()) {
|
|
|
|
sb.append(t);
|
|
|
|
sb.append(BackSlash.CHAR_NEWLINE);
|
2011-01-09 19:00:05 +00:00
|
|
|
}
|
2019-05-24 19:59:31 +00:00
|
|
|
sb.append(BackSlash.CHAR_NEWLINE);
|
|
|
|
return sb.toString();
|
|
|
|
}
|
2011-01-09 19:00:05 +00:00
|
|
|
|
2023-02-26 18:51:17 +00:00
|
|
|
private TextBlock getGraphicalFormatted() {
|
2022-08-19 16:34:21 +00:00
|
|
|
final FontConfiguration fc0 = GraphicStrings.sansSerif14(HColors.BLACK).bold();
|
|
|
|
final FontConfiguration fc1 = GraphicStrings.sansSerif14(HColors.MY_GREEN).bold();
|
|
|
|
final FontConfiguration fc2 = GraphicStrings.sansSerif14(HColors.RED).bold();
|
|
|
|
final FontConfiguration fc4 = GraphicStrings.sansSerif12(HColors.MY_GREEN).bold().italic();
|
2019-05-24 19:59:31 +00:00
|
|
|
|
|
|
|
final List<String> fullBody = getTextFullBody();
|
|
|
|
final TextBlock result0 = TextBlockUtils.addBackcolor(
|
2022-08-19 16:34:21 +00:00
|
|
|
TextBlockUtils.withMargin(new TextBlockRaw(getTextFromStack(), fc0), 1, 1, 1, 4), HColors.MY_GREEN);
|
2019-05-24 19:59:31 +00:00
|
|
|
final TextBlock result1 = new TextBlockRaw(allButLast(fullBody), fc1);
|
2022-08-19 16:34:21 +00:00
|
|
|
final TextBlock result2 = new TextBlockRaw(onlyLast(fullBody), fc1.wave(HColors.RED));
|
2019-05-24 19:59:31 +00:00
|
|
|
final TextBlock result3 = new TextBlockRaw(getTextError(), fc2);
|
2020-06-28 12:40:33 +00:00
|
|
|
final TextBlock result4 = TextBlockUtils.withMargin(new TextBlockRaw(header(), fc4), 0, 2, 0, 8);
|
2019-05-24 19:59:31 +00:00
|
|
|
TextBlock result = result0;
|
|
|
|
result = TextBlockUtils.mergeTB(result, result1, HorizontalAlignment.LEFT);
|
|
|
|
result = TextBlockUtils.mergeTB(result, result2, HorizontalAlignment.LEFT);
|
|
|
|
result = TextBlockUtils.mergeTB(result, result3, HorizontalAlignment.LEFT);
|
2020-06-28 12:40:33 +00:00
|
|
|
result = TextBlockUtils.mergeTB(result4, result, HorizontalAlignment.LEFT);
|
2019-05-24 19:59:31 +00:00
|
|
|
result = TextBlockUtils.withMargin(result, 5, 5);
|
2022-08-19 16:34:21 +00:00
|
|
|
return TextBlockUtils.addBackcolor(result, HColors.BLACK);
|
2019-05-24 19:59:31 +00:00
|
|
|
}
|
|
|
|
|
2020-06-28 12:40:33 +00:00
|
|
|
private List<String> header() {
|
2021-05-14 08:42:57 +00:00
|
|
|
final List<String> result = new ArrayList<>();
|
2020-06-28 12:40:33 +00:00
|
|
|
result.add("PlantUML " + Version.versionString());
|
|
|
|
GraphvizCrash.checkOldVersionWarning(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2021-03-18 13:12:00 +00:00
|
|
|
public List<String> getPureAsciiFormatted() {
|
2019-05-24 19:59:31 +00:00
|
|
|
final List<String> result = getTextFromStack();
|
|
|
|
result.addAll(getTextFullBody());
|
|
|
|
result.add("^^^^^");
|
|
|
|
result.addAll(getTextError());
|
|
|
|
return result;
|
|
|
|
}
|
2010-11-15 20:35:36 +00:00
|
|
|
|
2019-05-24 19:59:31 +00:00
|
|
|
private List<String> getTextFromStack() {
|
|
|
|
LineLocation lineLocation = getLineLocation();
|
2021-05-14 08:42:57 +00:00
|
|
|
final List<String> result = new ArrayList<>();
|
2019-05-24 19:59:31 +00:00
|
|
|
if (lineLocation != null) {
|
|
|
|
append(result, lineLocation);
|
|
|
|
while (lineLocation.getParent() != null) {
|
|
|
|
lineLocation = lineLocation.getParent();
|
|
|
|
append(result, lineLocation);
|
|
|
|
}
|
2015-05-31 18:56:03 +00:00
|
|
|
}
|
2019-05-24 19:59:31 +00:00
|
|
|
return result;
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|
|
|
|
|
2020-10-12 20:56:58 +00:00
|
|
|
protected List<String> getTextFullBody() {
|
2021-05-14 08:42:57 +00:00
|
|
|
final List<String> result = new ArrayList<>();
|
2019-05-24 19:59:31 +00:00
|
|
|
result.add(" ");
|
|
|
|
final int traceSize = trace.size();
|
|
|
|
if (traceSize > 40) {
|
|
|
|
for (StringLocated s : trace.subList(0, 5)) {
|
|
|
|
addToResult(result, s);
|
|
|
|
}
|
|
|
|
result.add("...");
|
|
|
|
final int skipped = traceSize - 5 - 20;
|
|
|
|
result.add("... ( skipping " + skipped + " lines )");
|
|
|
|
result.add("...");
|
|
|
|
for (StringLocated s : trace.subList(traceSize - 20, traceSize)) {
|
|
|
|
addToResult(result, s);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (StringLocated s : trace) {
|
|
|
|
addToResult(result, s);
|
|
|
|
}
|
2015-05-31 18:56:03 +00:00
|
|
|
}
|
2019-05-24 19:59:31 +00:00
|
|
|
return result;
|
2015-05-31 18:56:03 +00:00
|
|
|
}
|
|
|
|
|
2019-05-24 19:59:31 +00:00
|
|
|
private void addToResult(final List<String> result, StringLocated s) {
|
|
|
|
String tmp = s.getString();
|
|
|
|
if (tmp.length() > 120) {
|
|
|
|
tmp = tmp.substring(0, 120) + " ...";
|
2015-05-31 18:56:03 +00:00
|
|
|
}
|
2019-05-24 19:59:31 +00:00
|
|
|
result.add(tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<String> getTextError() {
|
|
|
|
return Arrays.asList(" " + singleError.getError());
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|
|
|
|
|
2016-12-01 20:29:25 +00:00
|
|
|
@Override
|
2021-03-23 13:06:33 +00:00
|
|
|
final protected ImageData exportDiagramNow(OutputStream os, int num, FileFormatOption fileFormat)
|
2016-12-01 20:29:25 +00:00
|
|
|
throws IOException {
|
2023-02-06 21:04:53 +00:00
|
|
|
// ::comment when CORE
|
2015-04-07 18:18:37 +00:00
|
|
|
if (fileFormat.getFileFormat() == FileFormat.ATXT || fileFormat.getFileFormat() == FileFormat.UTXT) {
|
|
|
|
final UGraphicTxt ugt = new UGraphicTxt();
|
|
|
|
final UmlCharArea area = ugt.getCharArea();
|
2020-12-14 18:31:06 +00:00
|
|
|
area.drawStringsLRSimple(getPureAsciiFormatted(), 0, 0);
|
2020-05-30 15:20:23 +00:00
|
|
|
area.print(SecurityUtils.createPrintStream(os));
|
2015-04-07 18:18:37 +00:00
|
|
|
return new ImageDataSimple(1, 1);
|
|
|
|
|
|
|
|
}
|
2023-01-31 19:27:04 +00:00
|
|
|
// ::done
|
2021-03-23 13:06:33 +00:00
|
|
|
return super.exportDiagramNow(os, num, fileFormat);
|
2021-03-23 09:40:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected UDrawable getRootDrawable(FileFormatOption fileFormatOption) throws IOException {
|
2023-02-26 18:51:17 +00:00
|
|
|
final TextBlock result = getGraphicalFormatted();
|
2016-12-21 22:10:29 +00:00
|
|
|
|
2017-03-15 19:13:31 +00:00
|
|
|
TextBlock udrawable;
|
2020-10-12 20:56:58 +00:00
|
|
|
if (getSource().getTotalLineCountLessThan5()) {
|
2017-03-15 19:13:31 +00:00
|
|
|
udrawable = addWelcome(result);
|
2016-12-21 22:10:29 +00:00
|
|
|
} else {
|
|
|
|
udrawable = result;
|
|
|
|
}
|
2020-04-05 15:13:04 +00:00
|
|
|
final int min = (int) (System.currentTimeMillis() / 60000L) % 60;
|
|
|
|
// udrawable = addMessageAdopt(udrawable);
|
2021-09-03 07:51:22 +00:00
|
|
|
if (disableTimeBasedErrorDecorations) {
|
|
|
|
// do nothing
|
2021-09-13 16:22:02 +00:00
|
|
|
} else if (min == 1 || min == 8 || min == 13 || min == 55) {
|
2020-04-05 15:13:04 +00:00
|
|
|
udrawable = addMessagePatreon(udrawable);
|
|
|
|
} else if (min == 15) {
|
|
|
|
udrawable = addMessageLiberapay(udrawable);
|
|
|
|
} else if (min == 30 || min == 39 || min == 48) {
|
|
|
|
udrawable = addMessageDedication(udrawable);
|
2023-02-06 21:04:53 +00:00
|
|
|
// ::comment when CORE
|
2020-04-05 15:13:04 +00:00
|
|
|
} else if (getSource().containsIgnoreCase("arecibo")) {
|
|
|
|
udrawable = addMessageArecibo(udrawable);
|
2023-02-02 17:59:43 +00:00
|
|
|
// ::done
|
2020-04-05 15:13:04 +00:00
|
|
|
}
|
2021-03-23 09:40:50 +00:00
|
|
|
return udrawable;
|
2010-11-15 20:35:36 +00:00
|
|
|
}
|
|
|
|
|
2019-05-24 19:59:31 +00:00
|
|
|
private void append(List<String> result, LineLocation lineLocation) {
|
|
|
|
if (lineLocation.getDescription() != null) {
|
|
|
|
result.add("[From " + lineLocation.getDescription() + " (line " + (lineLocation.getPosition() + 1) + ") ]");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
final public DiagramDescription getDescription() {
|
|
|
|
return new DiagramDescription("(Error)");
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<String> allButLast(List<String> full) {
|
|
|
|
return full.subList(0, full.size() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
private List<String> onlyLast(List<String> full) {
|
|
|
|
return full.subList(full.size() - 1, full.size());
|
|
|
|
}
|
|
|
|
|
2023-02-26 18:51:17 +00:00
|
|
|
private TextBlock getWelcome() throws IOException {
|
2021-05-23 15:35:13 +00:00
|
|
|
return new PSystemWelcome(getSource(), GraphicPosition.BACKGROUND_CORNER_TOP_RIGHT).getGraphicStrings();
|
2017-03-15 19:13:31 +00:00
|
|
|
}
|
|
|
|
|
2023-02-26 18:51:17 +00:00
|
|
|
private TextBlock addWelcome(final TextBlock result) throws IOException {
|
|
|
|
final TextBlock welcome = getWelcome();
|
2017-03-15 19:13:31 +00:00
|
|
|
return TextBlockUtils.mergeTB(welcome, result, HorizontalAlignment.LEFT);
|
|
|
|
}
|
|
|
|
|
2018-11-26 18:46:22 +00:00
|
|
|
private TextBlock addMessageLiberapay(final TextBlock source) throws IOException {
|
2023-02-06 21:04:53 +00:00
|
|
|
// ::comment when CORE
|
2023-01-31 19:27:04 +00:00
|
|
|
if (LicenseInfo.retrieveNamedOrDistributorQuickIsValid())
|
2019-05-24 19:59:31 +00:00
|
|
|
return source;
|
2023-01-31 19:27:04 +00:00
|
|
|
// ::done
|
|
|
|
|
2018-11-26 18:46:22 +00:00
|
|
|
final TextBlock message = getMessageLiberapay();
|
|
|
|
TextBlock result = TextBlockUtils.mergeTB(message, source, HorizontalAlignment.LEFT);
|
|
|
|
result = TextBlockUtils.mergeTB(result, message, HorizontalAlignment.LEFT);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
private TextBlock addMessagePatreon(final TextBlock source) throws IOException {
|
2023-02-06 21:04:53 +00:00
|
|
|
// ::comment when CORE
|
2023-01-31 19:27:04 +00:00
|
|
|
if (LicenseInfo.retrieveNamedOrDistributorQuickIsValid())
|
2019-05-24 19:59:31 +00:00
|
|
|
return source;
|
2023-01-31 19:27:04 +00:00
|
|
|
// ::done
|
|
|
|
|
2018-11-26 18:46:22 +00:00
|
|
|
final TextBlock message = getMessagePatreon();
|
2017-03-15 19:13:31 +00:00
|
|
|
TextBlock result = TextBlockUtils.mergeTB(message, source, HorizontalAlignment.LEFT);
|
|
|
|
result = TextBlockUtils.mergeTB(result, message, HorizontalAlignment.LEFT);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-09-23 12:15:14 +00:00
|
|
|
private TextBlock addMessageDedication(final TextBlock source) throws IOException {
|
2023-02-06 21:04:53 +00:00
|
|
|
// ::comment when CORE
|
2023-01-31 19:27:04 +00:00
|
|
|
if (LicenseInfo.retrieveNamedOrDistributorQuickIsValid())
|
2019-05-24 19:59:31 +00:00
|
|
|
return source;
|
2023-01-31 19:27:04 +00:00
|
|
|
// ::done
|
|
|
|
|
2018-09-23 12:15:14 +00:00
|
|
|
final TextBlock message = getMessageDedication();
|
|
|
|
TextBlock result = TextBlockUtils.mergeTB(message, source, HorizontalAlignment.LEFT);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-02-06 21:04:53 +00:00
|
|
|
// ::comment when CORE
|
2018-12-22 11:11:40 +00:00
|
|
|
private TextBlock addMessageAdopt(final TextBlock source) throws IOException {
|
2019-05-24 19:59:31 +00:00
|
|
|
if (LicenseInfo.retrieveNamedOrDistributorQuickIsValid()) {
|
|
|
|
return source;
|
|
|
|
}
|
2018-12-22 11:11:40 +00:00
|
|
|
final TextBlock message = getMessageAdopt();
|
|
|
|
TextBlock result = TextBlockUtils.mergeTB(message, source, HorizontalAlignment.LEFT);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-11-26 18:46:22 +00:00
|
|
|
private TextBlock addMessageArecibo(final TextBlock source) throws IOException {
|
2020-06-07 10:03:18 +00:00
|
|
|
final UImage message = new UImage(
|
|
|
|
new PixelImage(PSystemVersion.getArecibo(), AffineTransformType.TYPE_BILINEAR));
|
2018-11-26 18:46:22 +00:00
|
|
|
TextBlock result = TextBlockUtils.mergeLR(source, TextBlockUtils.fromUImage(message), VerticalAlignment.TOP);
|
|
|
|
return result;
|
|
|
|
}
|
2023-02-02 17:59:43 +00:00
|
|
|
// ::done
|
2018-11-26 18:46:22 +00:00
|
|
|
|
2023-02-26 18:51:17 +00:00
|
|
|
private TextBlock getMessageDedication() {
|
2021-02-02 10:12:15 +00:00
|
|
|
final HColorSimple backColor = (HColorSimple) HColorSet.instance().getColorOrWhite("#eae2c9");
|
2018-09-23 12:15:14 +00:00
|
|
|
|
2023-02-06 21:04:53 +00:00
|
|
|
// ::comment when CORE
|
2023-01-31 19:27:04 +00:00
|
|
|
final BufferedImage qrcode = smaller(FlashCodeFactory.getFlashCodeUtils()
|
2023-02-22 18:43:48 +00:00
|
|
|
.exportFlashcode("https://plantuml.com/dedication", Color.BLACK, backColor.getAwtColor()));
|
2023-01-31 19:27:04 +00:00
|
|
|
// ::done
|
2018-11-26 18:46:22 +00:00
|
|
|
final Display disp = Display.create("<b>Add your own dedication into PlantUML", " ", "For just $5 per month!",
|
2021-11-15 18:27:27 +00:00
|
|
|
"Details on <i>[[https://plantuml.com/dedication]]");
|
2018-09-23 12:15:14 +00:00
|
|
|
|
|
|
|
final UFont font = UFont.sansSerif(14);
|
2022-10-05 20:32:57 +00:00
|
|
|
final FontConfiguration fc = FontConfiguration.create(font, HColors.BLACK, HColors.BLACK, null);
|
2020-03-18 10:50:02 +00:00
|
|
|
final TextBlock text = TextBlockUtils
|
|
|
|
.withMargin(disp.create(fc, HorizontalAlignment.LEFT, new SpriteContainerEmpty()), 10, 0);
|
2018-09-23 12:15:14 +00:00
|
|
|
final TextBlock result;
|
2023-02-06 21:04:53 +00:00
|
|
|
// ::comment when CORE
|
2018-09-23 12:15:14 +00:00
|
|
|
if (qrcode == null) {
|
2023-01-31 19:27:04 +00:00
|
|
|
// ::done
|
2018-09-23 12:15:14 +00:00
|
|
|
result = text;
|
2023-02-06 21:04:53 +00:00
|
|
|
// ::comment when CORE
|
2018-09-23 12:15:14 +00:00
|
|
|
} else {
|
2020-06-28 12:40:33 +00:00
|
|
|
final UImage qr = new UImage(new PixelImage(qrcode, AffineTransformType.TYPE_NEAREST_NEIGHBOR)).scale(3);
|
2018-09-23 12:15:14 +00:00
|
|
|
result = TextBlockUtils.mergeLR(text, TextBlockUtils.fromUImage(qr), VerticalAlignment.CENTER);
|
|
|
|
}
|
2023-01-31 19:27:04 +00:00
|
|
|
// ::done
|
2018-09-23 12:15:14 +00:00
|
|
|
return TextBlockUtils.addBackcolor(result, backColor);
|
2018-12-22 11:11:40 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-02-26 18:51:17 +00:00
|
|
|
private TextBlock getMessageAdopt() {
|
2022-08-23 16:39:27 +00:00
|
|
|
final HColor backColor = HColorSet.instance().getColorOrWhite("#eff4d2");
|
2018-12-22 11:11:40 +00:00
|
|
|
|
|
|
|
final Display disp = Display.create("<b>Adopt-a-Word and put your message here!", " ",
|
2023-02-22 18:43:48 +00:00
|
|
|
"Details on <i>[[https://plantuml.com/adopt]]", " ");
|
2018-12-22 11:11:40 +00:00
|
|
|
|
|
|
|
final UFont font = UFont.sansSerif(14);
|
2022-10-05 20:32:57 +00:00
|
|
|
final FontConfiguration fc = FontConfiguration.create(font, HColors.BLACK, HColors.BLACK, null);
|
2020-03-18 10:50:02 +00:00
|
|
|
final TextBlock text = TextBlockUtils
|
|
|
|
.withMargin(disp.create(fc, HorizontalAlignment.LEFT, new SpriteContainerEmpty()), 10, 0);
|
2018-12-22 11:11:40 +00:00
|
|
|
final TextBlock result;
|
|
|
|
result = text;
|
|
|
|
return TextBlockUtils.addBackcolor(result, backColor);
|
2018-09-23 12:15:14 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-02-26 18:51:17 +00:00
|
|
|
private TextBlock getMessagePatreon() {
|
2020-06-07 10:03:18 +00:00
|
|
|
final UImage message = new UImage(
|
|
|
|
new PixelImage(PSystemVersion.getTime01(), AffineTransformType.TYPE_BILINEAR));
|
|
|
|
final Color back = new Color(message.getImage(1).getRGB(0, 0));
|
2022-08-23 16:39:27 +00:00
|
|
|
final HColor backColor = HColors.simple(back);
|
2018-11-26 18:46:22 +00:00
|
|
|
|
2023-02-06 21:04:53 +00:00
|
|
|
// ::comment when CORE
|
2023-01-31 19:27:04 +00:00
|
|
|
final BufferedImage qrcode = smaller(FlashCodeFactory.getFlashCodeUtils()
|
2023-02-22 18:43:48 +00:00
|
|
|
.exportFlashcode("https://plantuml.com/patreon", Color.BLACK, Color.WHITE));
|
2023-01-31 19:27:04 +00:00
|
|
|
// ::done
|
2018-11-26 18:46:22 +00:00
|
|
|
|
|
|
|
final int scale = 2;
|
|
|
|
|
2023-01-31 19:27:04 +00:00
|
|
|
final double imWidth;
|
|
|
|
final double imHeight;
|
2023-02-06 21:04:53 +00:00
|
|
|
// ::comment when CORE
|
2023-01-31 19:27:04 +00:00
|
|
|
if (qrcode == null) {
|
|
|
|
// ::done
|
|
|
|
imWidth = message.getWidth();
|
|
|
|
imHeight = message.getHeight();
|
2023-02-06 21:04:53 +00:00
|
|
|
// ::comment when CORE
|
2023-01-31 19:27:04 +00:00
|
|
|
} else {
|
|
|
|
imWidth = message.getWidth() + qrcode.getWidth() * scale + 20;
|
|
|
|
imHeight = Math.max(message.getHeight(), qrcode.getHeight() * scale + 10);
|
|
|
|
}
|
|
|
|
// ::done
|
2023-02-26 18:51:17 +00:00
|
|
|
return new AbstractTextBlock() {
|
2018-11-26 18:46:22 +00:00
|
|
|
|
|
|
|
public void drawU(UGraphic ug) {
|
2023-02-06 21:04:53 +00:00
|
|
|
// ::comment when CORE
|
2018-11-26 18:46:22 +00:00
|
|
|
if (qrcode == null) {
|
2023-01-31 19:27:04 +00:00
|
|
|
// ::done
|
2018-11-26 18:46:22 +00:00
|
|
|
ug.apply(new UTranslate(1, 1)).draw(message);
|
2023-02-06 21:04:53 +00:00
|
|
|
// ::comment when CORE
|
2018-11-26 18:46:22 +00:00
|
|
|
} else {
|
2020-06-28 12:40:33 +00:00
|
|
|
final UImage qr = new UImage(new PixelImage(qrcode, AffineTransformType.TYPE_NEAREST_NEIGHBOR))
|
|
|
|
.scale(scale);
|
2018-11-26 18:46:22 +00:00
|
|
|
ug.apply(new UTranslate(1, (imHeight - message.getHeight()) / 2)).draw(message);
|
|
|
|
ug.apply(new UTranslate(1 + message.getWidth(), (imHeight - qr.getHeight()) / 2)).draw(qr);
|
|
|
|
}
|
2023-01-31 19:27:04 +00:00
|
|
|
// ::done
|
2018-11-26 18:46:22 +00:00
|
|
|
}
|
|
|
|
|
2022-09-12 20:08:34 +00:00
|
|
|
public XDimension2D calculateDimension(StringBounder stringBounder) {
|
|
|
|
return new XDimension2D(imWidth + 1, imHeight + 1);
|
2018-11-26 18:46:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public MinMax getMinMax(StringBounder stringBounder) {
|
|
|
|
return MinMax.fromMax(imWidth + 1, imHeight + 1);
|
|
|
|
}
|
|
|
|
|
2020-03-18 10:50:02 +00:00
|
|
|
public HColor getBackcolor() {
|
2018-11-26 18:46:22 +00:00
|
|
|
return backColor;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-02-26 18:51:17 +00:00
|
|
|
private TextBlock getMessageLiberapay() {
|
2020-06-07 10:03:18 +00:00
|
|
|
final UImage message = new UImage(
|
|
|
|
new PixelImage(PSystemVersion.getTime15(), AffineTransformType.TYPE_BILINEAR));
|
|
|
|
final Color back = new Color(message.getImage(1).getRGB(0, 0));
|
2022-08-23 16:39:27 +00:00
|
|
|
final HColor backColor = HColors.simple(back);
|
2018-09-23 12:15:14 +00:00
|
|
|
|
2023-02-06 21:04:53 +00:00
|
|
|
// ::comment when CORE
|
2023-01-31 19:27:04 +00:00
|
|
|
final BufferedImage qrcode = smaller(FlashCodeFactory.getFlashCodeUtils()
|
2023-02-22 18:43:48 +00:00
|
|
|
.exportFlashcode("https://plantuml.com/lp", Color.BLACK, Color.WHITE));
|
2023-01-31 19:27:04 +00:00
|
|
|
// ::done
|
2018-09-23 12:15:14 +00:00
|
|
|
|
|
|
|
final int scale = 2;
|
|
|
|
|
2023-01-31 19:27:04 +00:00
|
|
|
final double imWidth;
|
|
|
|
final double imHeight;
|
2023-02-06 21:04:53 +00:00
|
|
|
// ::comment when CORE
|
2023-01-31 19:27:04 +00:00
|
|
|
if (qrcode == null) {
|
|
|
|
// ::done
|
|
|
|
imWidth = message.getWidth();
|
|
|
|
imHeight = message.getHeight();
|
2023-02-06 21:04:53 +00:00
|
|
|
// ::comment when CORE
|
2023-01-31 19:27:04 +00:00
|
|
|
} else {
|
|
|
|
imWidth = message.getWidth() + qrcode.getWidth() * scale + 20;
|
|
|
|
imHeight = Math.max(message.getHeight(), qrcode.getHeight() * scale + 10);
|
|
|
|
}
|
|
|
|
// ::done
|
|
|
|
|
2023-02-26 18:51:17 +00:00
|
|
|
return new AbstractTextBlock() {
|
2017-03-15 19:13:31 +00:00
|
|
|
|
|
|
|
public void drawU(UGraphic ug) {
|
2023-02-06 21:04:53 +00:00
|
|
|
// ::comment when CORE
|
2018-09-23 12:15:14 +00:00
|
|
|
if (qrcode == null) {
|
2023-01-31 19:27:04 +00:00
|
|
|
// ::done
|
2018-09-23 12:15:14 +00:00
|
|
|
ug.apply(new UTranslate(1, 1)).draw(message);
|
2023-02-06 21:04:53 +00:00
|
|
|
// ::comment when CORE
|
2018-09-23 12:15:14 +00:00
|
|
|
} else {
|
2020-06-28 12:40:33 +00:00
|
|
|
final UImage qr = new UImage(new PixelImage(qrcode, AffineTransformType.TYPE_NEAREST_NEIGHBOR))
|
|
|
|
.scale(scale);
|
2018-09-23 12:15:14 +00:00
|
|
|
ug.apply(new UTranslate(1, (imHeight - message.getHeight()) / 2)).draw(message);
|
|
|
|
ug.apply(new UTranslate(1 + message.getWidth(), (imHeight - qr.getHeight()) / 2)).draw(qr);
|
|
|
|
}
|
2023-01-31 19:27:04 +00:00
|
|
|
// ::done
|
2017-03-15 19:13:31 +00:00
|
|
|
}
|
|
|
|
|
2022-09-12 20:08:34 +00:00
|
|
|
public XDimension2D calculateDimension(StringBounder stringBounder) {
|
|
|
|
return new XDimension2D(imWidth + 1, imHeight + 1);
|
2017-03-15 19:13:31 +00:00
|
|
|
}
|
|
|
|
|
2017-11-20 16:10:36 +00:00
|
|
|
public MinMax getMinMax(StringBounder stringBounder) {
|
|
|
|
return MinMax.fromMax(imWidth + 1, imHeight + 1);
|
|
|
|
}
|
|
|
|
|
2020-03-18 10:50:02 +00:00
|
|
|
public HColor getBackcolor() {
|
2018-09-23 12:15:14 +00:00
|
|
|
return backColor;
|
2017-03-15 19:13:31 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-02-02 10:12:15 +00:00
|
|
|
public int score() {
|
|
|
|
final int result = trace.size() * 10 + singleError.score();
|
|
|
|
return result;
|
2019-05-24 19:59:31 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 12:15:14 +00:00
|
|
|
private BufferedImage smaller(BufferedImage im) {
|
|
|
|
if (im == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
final int nb = 1;
|
|
|
|
return im.getSubimage(nb, nb, im.getWidth() - 2 * nb, im.getHeight() - 2 * nb);
|
|
|
|
}
|
|
|
|
|
2021-09-13 16:22:02 +00:00
|
|
|
}
|