1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-03 09:00:48 +00:00
plantuml/src/net/sourceforge/plantuml/error/PSystemError.java

494 lines
19 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2019-01-16 18:34:41 +00:00
* (C) Copyright 2009-2020, Arnaud Roques
2010-11-15 20:35:36 +00:00
*
2016-03-06 16:47:34 +00:00
* Project Info: http://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:
*
* http://plantuml.com/patreon (only 1$ per month!)
* http://plantuml.com/paypal
*
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;
2016-12-21 22:10:29 +00:00
import java.awt.geom.Dimension2D;
2017-03-15 19:13:31 +00:00
import java.awt.geom.Rectangle2D;
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.io.PrintStream;
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;
2019-05-24 19:59:31 +00:00
import net.sourceforge.plantuml.AbstractPSystem;
import net.sourceforge.plantuml.BackSlash;
import net.sourceforge.plantuml.Dimension2DDouble;
import net.sourceforge.plantuml.ErrorUml;
import net.sourceforge.plantuml.FileFormat;
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.FileImageData;
import net.sourceforge.plantuml.LineLocation;
import net.sourceforge.plantuml.SpriteContainerEmpty;
import net.sourceforge.plantuml.StringLocated;
2018-05-01 17:26:04 +00:00
import net.sourceforge.plantuml.api.ImageDataAbstract;
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;
2018-09-23 12:15:14 +00:00
import net.sourceforge.plantuml.cucadiagram.Display;
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;
import net.sourceforge.plantuml.flashcode.FlashCodeUtils;
import net.sourceforge.plantuml.graphic.FontConfiguration;
2017-03-12 17:22:02 +00:00
import net.sourceforge.plantuml.graphic.GraphicPosition;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.graphic.GraphicStrings;
2017-03-15 19:13:31 +00:00
import net.sourceforge.plantuml.graphic.HorizontalAlignment;
2017-04-05 17:37:42 +00:00
import net.sourceforge.plantuml.graphic.InnerStrategy;
2017-03-15 19:13:31 +00:00
import net.sourceforge.plantuml.graphic.StringBounder;
import net.sourceforge.plantuml.graphic.TextBlock;
2019-05-24 19:59:31 +00:00
import net.sourceforge.plantuml.graphic.TextBlockRaw;
2017-03-15 19:13:31 +00:00
import net.sourceforge.plantuml.graphic.TextBlockUtils;
2018-09-23 12:15:14 +00:00
import net.sourceforge.plantuml.graphic.VerticalAlignment;
2016-11-18 21:12:09 +00:00
import net.sourceforge.plantuml.svek.TextBlockBackcolored;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.ugraphic.ImageBuilder;
2017-11-20 16:10:36 +00:00
import net.sourceforge.plantuml.ugraphic.MinMax;
2018-09-23 12:15:14 +00:00
import net.sourceforge.plantuml.ugraphic.UFont;
2016-12-21 22:10:29 +00:00
import net.sourceforge.plantuml.ugraphic.UGraphic;
2017-03-15 19:13:31 +00:00
import net.sourceforge.plantuml.ugraphic.UImage;
2016-12-21 22:10:29 +00:00
import net.sourceforge.plantuml.ugraphic.UTranslate;
2020-03-18 10:50:02 +00:00
import net.sourceforge.plantuml.ugraphic.color.ColorMapperIdentity;
import net.sourceforge.plantuml.ugraphic.color.HColor;
import net.sourceforge.plantuml.ugraphic.color.HColorSet;
import net.sourceforge.plantuml.ugraphic.color.HColorSimple;
import net.sourceforge.plantuml.ugraphic.color.HColorUtils;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.ugraphic.txt.UGraphicTxt;
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;
2010-11-15 20:35:36 +00:00
2019-05-24 19:59:31 +00:00
public abstract class PSystemError extends AbstractPSystem {
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
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
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
2019-05-24 19:59:31 +00:00
private TextBlockBackcolored getGraphicalFormatted() {
2020-03-18 10:50:02 +00:00
final FontConfiguration fc0 = GraphicStrings.sansSerif14(HColorUtils.BLACK).bold();
final FontConfiguration fc1 = GraphicStrings.sansSerif14(HColorUtils.MY_GREEN).bold();
final FontConfiguration fc2 = GraphicStrings.sansSerif14(HColorUtils.RED).bold();
2019-05-24 19:59:31 +00:00
final List<String> fullBody = getTextFullBody();
final TextBlock result0 = TextBlockUtils.addBackcolor(
2020-03-18 10:50:02 +00:00
TextBlockUtils.withMargin(new TextBlockRaw(getTextFromStack(), fc0), 1, 1, 1, 4), HColorUtils.MY_GREEN);
2019-05-24 19:59:31 +00:00
final TextBlock result1 = new TextBlockRaw(allButLast(fullBody), fc1);
2020-03-18 10:50:02 +00:00
final TextBlock result2 = new TextBlockRaw(onlyLast(fullBody), fc1.wave(HColorUtils.RED));
2019-05-24 19:59:31 +00:00
final TextBlock result3 = new TextBlockRaw(getTextError(), fc2);
TextBlock result = result0;
result = TextBlockUtils.mergeTB(result, result1, HorizontalAlignment.LEFT);
result = TextBlockUtils.mergeTB(result, result2, HorizontalAlignment.LEFT);
result = TextBlockUtils.mergeTB(result, result3, HorizontalAlignment.LEFT);
result = TextBlockUtils.withMargin(result, 5, 5);
2020-03-18 10:50:02 +00:00
return TextBlockUtils.addBackcolor(result, HColorUtils.BLACK);
2019-05-24 19:59:31 +00:00
}
private List<String> getPureAsciiFormatted() {
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();
final List<String> result = new ArrayList<String>();
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
}
2019-05-24 19:59:31 +00:00
private List<String> getTextFullBody() {
final List<String> result = new ArrayList<String>();
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
2017-04-19 18:30:16 +00:00
final protected ImageData exportDiagramNow(OutputStream os, int num, FileFormatOption fileFormat, long seed)
2016-12-01 20:29:25 +00:00
throws IOException {
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();
2019-05-24 19:59:31 +00:00
area.drawStringsLR(getPureAsciiFormatted(), 0, 0);
2015-04-07 18:18:37 +00:00
area.print(new PrintStream(os));
return new ImageDataSimple(1, 1);
}
2019-05-24 19:59:31 +00:00
final TextBlockBackcolored result = getGraphicalFormatted();
2016-12-21 22:10:29 +00:00
2017-03-15 19:13:31 +00:00
TextBlock udrawable;
2015-04-07 18:18:37 +00:00
final ImageBuilder imageBuilder = new ImageBuilder(new ColorMapperIdentity(), 1.0, result.getBackcolor(),
getMetadata(), null, 0, 0, null, false);
2019-09-14 18:12:04 +00:00
imageBuilder.setRandomPixel(true);
2017-03-15 19:13:31 +00:00
if (getSource().getTotalLineCount() < 5) {
udrawable = addWelcome(result);
2016-12-21 22:10:29 +00:00
} else {
udrawable = result;
}
2020-03-18 10:50:02 +00:00
udrawable = addMessageCoronavirus(udrawable);
// final int min = (int) (System.currentTimeMillis() / 60000L) % 60;
// if (min == 1 || min == 8 || min == 13 || min == 55) {
// udrawable = addMessagePatreon(udrawable);
// } else if (min == 15) {
// udrawable = addMessageLiberapay(udrawable);
// } else if (min == 30 || min == 39 || min == 48) {
// udrawable = addMessageDedication(udrawable);
// } else if (getSource().containsIgnoreCase("arecibo")) {
// udrawable = addMessageArecibo(udrawable);
// }
2016-12-21 22:10:29 +00:00
imageBuilder.setUDrawable(udrawable);
2018-05-01 17:26:04 +00:00
final ImageData imageData = imageBuilder.writeImageTOBEMOVED(fileFormat, seed(), os);
2018-05-21 13:07:09 +00:00
((ImageDataAbstract) imageData).setStatus(FileImageData.ERROR);
2018-05-01 17:26:04 +00:00
return imageData;
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());
}
2017-03-15 19:13:31 +00:00
private TextBlockBackcolored getWelcome() throws IOException {
return new PSystemWelcome(GraphicPosition.BACKGROUND_CORNER_TOP_RIGHT).getGraphicStrings();
}
private TextBlock addWelcome(final TextBlockBackcolored result) throws IOException {
final TextBlockBackcolored welcome = getWelcome();
return TextBlockUtils.mergeTB(welcome, result, HorizontalAlignment.LEFT);
}
2018-11-26 18:46:22 +00:00
private TextBlock addMessageLiberapay(final TextBlock source) throws IOException {
2019-05-24 19:59:31 +00:00
if (LicenseInfo.retrieveNamedOrDistributorQuickIsValid()) {
return source;
}
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 {
2019-05-24 19:59:31 +00:00
if (LicenseInfo.retrieveNamedOrDistributorQuickIsValid()) {
return source;
}
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;
}
2020-03-18 10:50:02 +00:00
private TextBlock addMessageCoronavirus(final TextBlock source) throws IOException {
final TextBlock message = getMessageCoronavirus();
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 {
2019-05-24 19:59:31 +00:00
if (LicenseInfo.retrieveNamedOrDistributorQuickIsValid()) {
return source;
}
2018-09-23 12:15:14 +00:00
final TextBlock message = getMessageDedication();
TextBlock result = TextBlockUtils.mergeTB(message, source, HorizontalAlignment.LEFT);
return result;
}
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 {
final UImage message = new UImage(PSystemVersion.getArecibo());
TextBlock result = TextBlockUtils.mergeLR(source, TextBlockUtils.fromUImage(message), VerticalAlignment.TOP);
return result;
}
2018-09-23 12:15:14 +00:00
private TextBlockBackcolored getMessageDedication() {
final FlashCodeUtils utils = FlashCodeFactory.getFlashCodeUtils();
2020-03-18 10:50:02 +00:00
final HColorSimple backColor = (HColorSimple) HColorSet.instance().getColorIfValid("#eae2c9");
2018-09-23 12:15:14 +00:00
2020-03-18 10:50:02 +00:00
final BufferedImage qrcode = smaller(
utils.exportFlashcode("http://plantuml.com/dedication", Color.BLACK, backColor.getColor999()));
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!",
"Details on <i>[[http://plantuml.com/dedication]]");
2018-09-23 12:15:14 +00:00
final UFont font = UFont.sansSerif(14);
2020-03-18 10:50:02 +00:00
final FontConfiguration fc = new FontConfiguration(font, HColorUtils.BLACK, HColorUtils.BLACK, false);
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;
if (qrcode == null) {
result = text;
} else {
final UImage qr = new UImage(qrcode).scaleNearestNeighbor(3);
result = TextBlockUtils.mergeLR(text, TextBlockUtils.fromUImage(qr), VerticalAlignment.CENTER);
}
return TextBlockUtils.addBackcolor(result, backColor);
2018-12-22 11:11:40 +00:00
}
private TextBlockBackcolored getMessageAdopt() {
2020-03-18 10:50:02 +00:00
final HColorSimple backColor = (HColorSimple) HColorSet.instance().getColorIfValid("#eff4d2");
2018-12-22 11:11:40 +00:00
final Display disp = Display.create("<b>Adopt-a-Word and put your message here!", " ",
"Details on <i>[[http://plantuml.com/adopt]]", " ");
final UFont font = UFont.sansSerif(14);
2020-03-18 10:50:02 +00:00
final FontConfiguration fc = new FontConfiguration(font, HColorUtils.BLACK, HColorUtils.BLACK, false);
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
}
2020-03-18 10:50:02 +00:00
private TextBlockBackcolored getMessageCoronavirus() {
final FlashCodeUtils utils = FlashCodeFactory.getFlashCodeUtils();
final HColorSimple backColor = (HColorSimple) HColorSet.instance().getColorIfValid("#fff");
final BufferedImage qrcode = smaller(utils.exportFlashcode(
"https://medium.com/@tomaspueyo/coronavirus-act-today-or-people-will-die-f4d3d9cd99ca", Color.BLACK,
backColor.getColor999()));
final Display disp = Display.create("<b>Coronavirus: Why You Must Act Now", " ",
"Please use the flashcode or go to", "https://plantuml/coronavirus", " ",
"If you live in UK, Europe, North & South America, Iran, Japan, Korea...",
" <b>please apply social distancing right now!", " ", "The coronavirus is coming to you.",
"Its coming at an exponential speed: gradually, and then suddenly.",
"Its a matter of days. Maybe a week or two.",
"When it does, your healthcare system will be overwhelmed.",
"Your fellow citizens will be treated in the hallways.",
"Exhausted healthcare workers will break down. Some will die.",
"They will have to decide which patient gets the oxygen and which one dies.",
"The only way to prevent this is social distancing today. Not tomorrow. Today.",
"That means keeping as many people home as possible, starting now.", " ");
final UFont font = UFont.sansSerif(14);
final FontConfiguration fc = new FontConfiguration(font, HColorUtils.BLACK, HColorUtils.BLACK, false);
final TextBlock text = TextBlockUtils
.withMargin(disp.create(fc, HorizontalAlignment.LEFT, new SpriteContainerEmpty()), 10, 0);
final TextBlock result;
if (qrcode == null) {
result = text;
} else {
final UImage qr = new UImage(qrcode).scaleNearestNeighbor(3);
result = TextBlockUtils.mergeLR(text, TextBlockUtils.fromUImage(qr), VerticalAlignment.CENTER);
}
return TextBlockUtils.addBackcolor(result, backColor);
}
2018-11-26 18:46:22 +00:00
private TextBlockBackcolored getMessagePatreon() {
final UImage message = new UImage(PSystemVersion.getTime01());
final Color back = new Color(message.getImage().getRGB(0, 0));
2020-03-18 10:50:02 +00:00
final HColor backColor = new HColorSimple(back, false);
2018-11-26 18:46:22 +00:00
final FlashCodeUtils utils = FlashCodeFactory.getFlashCodeUtils();
2020-03-18 10:50:02 +00:00
final BufferedImage qrcode = smaller(
utils.exportFlashcode("http://plantuml.com/patreon", Color.BLACK, Color.WHITE));
2018-11-26 18:46:22 +00:00
final int scale = 2;
final double imWidth = message.getWidth() + (qrcode == null ? 0 : qrcode.getWidth() * scale + 20);
2020-03-18 10:50:02 +00:00
final double imHeight = qrcode == null ? message.getHeight()
: Math.max(message.getHeight(), qrcode.getHeight() * scale + 10);
2018-11-26 18:46:22 +00:00
return new TextBlockBackcolored() {
public void drawU(UGraphic ug) {
if (qrcode == null) {
ug.apply(new UTranslate(1, 1)).draw(message);
} else {
final UImage qr = new UImage(qrcode).scaleNearestNeighbor(scale);
ug.apply(new UTranslate(1, (imHeight - message.getHeight()) / 2)).draw(message);
ug.apply(new UTranslate(1 + message.getWidth(), (imHeight - qr.getHeight()) / 2)).draw(qr);
}
}
public Rectangle2D getInnerPosition(String member, StringBounder stringBounder, InnerStrategy strategy) {
return null;
}
public Dimension2D calculateDimension(StringBounder stringBounder) {
return new Dimension2DDouble(imWidth + 1, imHeight + 1);
}
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;
}
};
}
private TextBlockBackcolored getMessageLiberapay() {
final UImage message = new UImage(PSystemVersion.getTime15());
2018-09-23 12:15:14 +00:00
final Color back = new Color(message.getImage().getRGB(0, 0));
2020-03-18 10:50:02 +00:00
final HColor backColor = new HColorSimple(back, false);
2018-09-23 12:15:14 +00:00
final FlashCodeUtils utils = FlashCodeFactory.getFlashCodeUtils();
2018-11-26 18:46:22 +00:00
final BufferedImage qrcode = smaller(utils.exportFlashcode("http://plantuml.com/lp", Color.BLACK, Color.WHITE));
2018-09-23 12:15:14 +00:00
final int scale = 2;
final double imWidth = message.getWidth() + (qrcode == null ? 0 : qrcode.getWidth() * scale + 20);
2020-03-18 10:50:02 +00:00
final double imHeight = qrcode == null ? message.getHeight()
: Math.max(message.getHeight(), qrcode.getHeight() * scale + 10);
2017-03-15 19:13:31 +00:00
return new TextBlockBackcolored() {
public void drawU(UGraphic ug) {
2018-09-23 12:15:14 +00:00
if (qrcode == null) {
ug.apply(new UTranslate(1, 1)).draw(message);
} else {
final UImage qr = new UImage(qrcode).scaleNearestNeighbor(scale);
ug.apply(new UTranslate(1, (imHeight - message.getHeight()) / 2)).draw(message);
ug.apply(new UTranslate(1 + message.getWidth(), (imHeight - qr.getHeight()) / 2)).draw(qr);
}
2017-03-15 19:13:31 +00:00
}
2017-04-05 17:37:42 +00:00
public Rectangle2D getInnerPosition(String member, StringBounder stringBounder, InnerStrategy strategy) {
2017-03-15 19:13:31 +00:00
return null;
}
public Dimension2D calculateDimension(StringBounder stringBounder) {
return new Dimension2DDouble(imWidth + 1, imHeight + 1);
}
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
}
};
}
2019-05-24 19:59:31 +00:00
public int size() {
return trace.size();
}
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);
}
2010-11-15 20:35:36 +00:00
}