plantuml/src/net/sourceforge/plantuml/version/PSystemLicense.java

122 lines
4.0 KiB
Java
Raw Normal View History

2013-12-10 19:36:50 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2023-02-22 18:43:48 +00:00
* (C) Copyright 2009-2024, Arnaud Roques
2013-12-10 19:36:50 +00:00
*
2023-02-22 18:43:48 +00:00
* Project Info: https://plantuml.com
2013-12-10 19:36:50 +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
*
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.version;
2018-12-22 11:11:40 +00:00
import java.awt.image.BufferedImage;
2013-12-10 19:36:50 +00:00
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
2023-02-22 18:43:48 +00:00
import net.atmp.PixelImage;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.FileFormatOption;
import net.sourceforge.plantuml.PlainDiagram;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.core.DiagramDescription;
2021-05-23 15:35:13 +00:00
import net.sourceforge.plantuml.core.UmlSource;
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;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.drawing.UGraphic;
import net.sourceforge.plantuml.klimt.shape.GraphicStrings;
2023-02-26 18:51:17 +00:00
import net.sourceforge.plantuml.klimt.shape.TextBlock;
2023-02-22 18:43:48 +00:00
import net.sourceforge.plantuml.klimt.shape.UDrawable;
import net.sourceforge.plantuml.klimt.shape.UImage;
2013-12-10 19:36:50 +00:00
public class PSystemLicense extends PlainDiagram implements UDrawable {
2013-12-10 19:36:50 +00:00
2016-12-01 20:29:25 +00:00
@Override
protected UDrawable getRootDrawable(FileFormatOption fileFormatOption) {
return this;
2013-12-10 19:36:50 +00:00
}
2021-05-23 15:35:13 +00:00
public static PSystemLicense create(UmlSource source) throws IOException {
return new PSystemLicense(source);
}
public PSystemLicense(UmlSource source) {
super(source);
2013-12-10 19:36:50 +00:00
}
2023-02-26 18:51:17 +00:00
private TextBlock getGraphicStrings(List<String> strings) {
2016-11-18 21:12:09 +00:00
return GraphicStrings.createBlackOnWhite(strings);
2013-12-10 19:36:50 +00:00
}
public DiagramDescription getDescription() {
2017-03-12 17:22:02 +00:00
return new DiagramDescription("(License)");
2013-12-10 19:36:50 +00:00
}
2023-02-22 18:43:48 +00:00
@Override
public void exportDiagramGraphic(UGraphic ug) {
final LicenseInfo licenseInfo = LicenseInfo.retrieveQuick();
getTextBlock(licenseInfo).drawU(ug);
}
2018-12-22 11:11:40 +00:00
public void drawU(UGraphic ug) {
final LicenseInfo licenseInfo = LicenseInfo.retrieveQuick();
2023-02-22 18:43:48 +00:00
// ::comment when CORE
2018-12-22 11:11:40 +00:00
final BufferedImage logo = LicenseInfo.retrieveDistributorImage(licenseInfo);
if (logo == null) {
// ::done
2023-02-22 18:43:48 +00:00
getTextBlock(licenseInfo).drawU(ug);
2023-02-06 21:04:53 +00:00
// ::comment when CORE
2018-12-22 11:11:40 +00:00
} else {
2021-05-14 08:42:57 +00:00
final List<String> strings1 = new ArrayList<>();
final List<String> strings2 = new ArrayList<>();
2018-12-22 11:11:40 +00:00
strings1.addAll(License.getCurrent().getText1(licenseInfo));
strings2.addAll(License.getCurrent().getText2(licenseInfo));
2023-02-26 18:51:17 +00:00
final TextBlock result1 = getGraphicStrings(strings1);
2018-12-22 11:11:40 +00:00
result1.drawU(ug);
2020-03-18 10:50:02 +00:00
ug = ug.apply(UTranslate.dy(4 + result1.calculateDimension(ug.getStringBounder()).getHeight()));
2020-06-07 10:03:18 +00:00
UImage im = new UImage(new PixelImage(logo, AffineTransformType.TYPE_BILINEAR));
2020-03-18 10:50:02 +00:00
ug.apply(UTranslate.dx(20)).draw(im);
2018-12-22 11:11:40 +00:00
2020-03-18 10:50:02 +00:00
ug = ug.apply(UTranslate.dy(im.getHeight()));
2023-02-26 18:51:17 +00:00
final TextBlock result2 = getGraphicStrings(strings2);
2018-12-22 11:11:40 +00:00
result2.drawU(ug);
}
// ::done
2018-12-22 11:11:40 +00:00
}
2023-02-22 18:43:48 +00:00
2023-02-26 18:51:17 +00:00
protected TextBlock getTextBlock(final LicenseInfo licenseInfo) {
2023-02-22 18:43:48 +00:00
final List<String> strings = new ArrayList<>();
strings.addAll(License.getCurrent().getText1(licenseInfo));
strings.addAll(License.getCurrent().getText2(licenseInfo));
return getGraphicStrings(strings);
}
2013-12-10 19:36:50 +00:00
}