All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sourceforge.plantuml.version.PSystemVersion Maven / Gradle / Ivy

There is a newer version: 1.2024.8
Show newest version
// THIS FILE HAS BEEN GENERATED BY A PREPROCESSOR.
package net.sourceforge.plantuml.version;

import static net.sourceforge.plantuml.klimt.geom.GraphicPosition.BACKGROUND_CORNER_BOTTOM_RIGHT;

import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import net.sourceforge.plantuml.OptionFlags;
import net.sourceforge.plantuml.OptionPrint;
import net.sourceforge.plantuml.PlainStringsDiagram;
import net.sourceforge.plantuml.Run;
import net.sourceforge.plantuml.core.DiagramDescription;
import net.sourceforge.plantuml.core.UmlSource;
import net.sourceforge.plantuml.dot.GraphvizUtils;
import net.sourceforge.plantuml.log.Logme;
import net.sourceforge.plantuml.preproc.Stdlib;
import net.sourceforge.plantuml.preproc2.PreprocessorUtils;
import net.sourceforge.plantuml.security.SFile;
import net.sourceforge.plantuml.security.SImageIO;
import net.sourceforge.plantuml.security.SecurityProfile;
import net.sourceforge.plantuml.security.SecurityUtils;
import net.sourceforge.plantuml.svek.GraphvizCrash;

public class PSystemVersion extends PlainStringsDiagram {

	PSystemVersion(UmlSource source, boolean withImage, List args) {
		super(source);
		this.strings.addAll(args);
		try {
			if (withImage) {
				this.image = getPlantumlImage();
				this.imagePosition = BACKGROUND_CORNER_BOTTOM_RIGHT;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private PSystemVersion(UmlSource source, List args, BufferedImage image) {
		super(source);
		this.strings.addAll(args);
		this.image = image;
		this.imagePosition = BACKGROUND_CORNER_BOTTOM_RIGHT;
	}

	public static BufferedImage getPlantumlImage() {
		return getImage("logo.png");
	}

	public static BufferedImage getTime01() {
		return getImage("time01.png");
	}

	public static BufferedImage getTime15() {
		return getImage("time15.png");
	}

	public static BufferedImage getCharlieImage() {
		return getImage("charlie.png");
	}

	public static BufferedImage getPlantumlSmallIcon() {
		return getImage("favicon.png");
	}

	// ::comment when __CORE__
	public static BufferedImage getArecibo() {
		return getImage("arecibo.png");
	}

	public static BufferedImage getDotc() {
		return getImage("dotc.png");
	}

	public static BufferedImage getDotd() {
		return getImage("dotd.png");
	}

	public static BufferedImage getApple2Image() {
		return getImageWebp("apple2.png");
	}

	private static BufferedImage getImage(final String name) {
		try {
			final InputStream is = PSystemVersion.class.getResourceAsStream(name);
			final BufferedImage image = SImageIO.read(is);
			is.close();
			return image;
		} catch (IOException e) {
			Logme.error(e);
		}
		return new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB);
	}

	// ::comment when __CORE__
	private static BufferedImage getImageWebp(final String name) {
		try (InputStream is = PSystemVersion.class.getResourceAsStream(name)) {
			return SFile.getBufferedImageFromWebpButHeader(is);
		} catch (IOException e) {
			Logme.error(e);
		}
		return new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB);
	}

	private static BufferedImage transparentIcon;

	public static BufferedImage getPlantumlSmallIcon2() {
		if (transparentIcon != null) {
			return transparentIcon;
		}
		final BufferedImage ico = getPlantumlSmallIcon();
		if (ico == null) {
			return new BufferedImage(10, 10, BufferedImage.TYPE_INT_ARGB);
		}
		transparentIcon = new BufferedImage(ico.getWidth(), ico.getHeight(), BufferedImage.TYPE_INT_ARGB_PRE);
		for (int i = 0; i < ico.getWidth(); i++) {
			for (int j = 0; j < ico.getHeight(); j++) {
				final int col = ico.getRGB(i, j);
				if (col != ico.getRGB(0, 0)) {
					transparentIcon.setRGB(i, j, col);
				}
			}
		}
		return transparentIcon;
	}

	public static PSystemVersion createShowVersion2(UmlSource source) {
		final List strings = new ArrayList<>();
		strings.add("PlantUML version " + Version.versionString() + " (" + Version.compileTimeString() + ")");
		strings.add("(" + License.getCurrent() + " source distribution)");
		// :: uncomment when __CORE__
//		strings.add(" ");
//		strings.add("Compiled with CheerpJ 2.3");
//		strings.add("Powered by CheerpJ, a Leaning Technologies Java tool");
		// :: comment when __CORE__
		GraphvizCrash.checkOldVersionWarning(strings);
		if (SecurityUtils.getSecurityProfile() == SecurityProfile.UNSECURE) {
			strings.add("Loaded from " + Version.getJarPath());

			if (OptionFlags.getInstance().isWord()) {
				strings.add("Word Mode");
				strings.add("Command Line: " + Run.getCommandLine());
				strings.add("Current Dir: " + new SFile(".").getAbsolutePath());
				strings.add("plantuml.include.path: " + PreprocessorUtils.getenv(SecurityUtils.PATHS_INCLUDES));
			}
		}
		strings.add(" ");

		GraphvizUtils.addDotStatus(strings, true);
		strings.add(" ");
		for (String name : OptionPrint.interestingProperties())
			strings.add(name);

		for (String v : OptionPrint.interestingValues())
			strings.add(v);


		return new PSystemVersion(source, true, strings);
	}

	// :: comment when __CORE__
	public static PSystemVersion createStdLib(UmlSource source) {
		final List strings = new ArrayList<>();
		Stdlib.addInfoVersion(strings, true);
		strings.add(" ");

		return new PSystemVersion(source, true, strings);
	}

	public static PSystemVersion createShowAuthors2(UmlSource source) {
		// Duplicate in OptionPrint
		final List strings = getAuthorsStrings(true);
		return new PSystemVersion(source, true, strings);
	}

	public static List getAuthorsStrings(boolean withTag) {
		final List strings = new ArrayList<>();
		add(strings, "PlantUML version " + Version.versionString() + " (" + Version.compileTimeString() + ")",
				withTag);
		add(strings, "(" + License.getCurrent() + " source distribution)", withTag);
		add(strings, " ", withTag);
		add(strings, "Original idea: Arnaud Roques", withTag);
		add(strings, "Word Macro: Alain Bertucat & Matthieu Sabatier", withTag);
		add(strings, "Word Add-in: Adriaan van den Brand", withTag);
		add(strings, "J2V8 & viz.js integration: Andreas Studer", withTag);
		add(strings, "Official Eclipse Plugin: Hallvard Tr\u00E6tteberg", withTag);
		add(strings, "Original Eclipse Plugin: Claude Durif & Anne Pecoil", withTag);
		add(strings, "Servlet & XWiki: Maxime Sinclair", withTag);
		add(strings, "Docker: David Ducatel", withTag);
		add(strings, "AWS lib: Chris Passarello", withTag);
		add(strings, "Stdlib Icons: tupadr3", withTag);
		add(strings, "Site design: Raphael Cotisson", withTag);
		add(strings, "Logo: Benjamin Croizet", withTag);
		add(strings, "Web Assembly: Sakir Temel", withTag);

		add(strings, " ", withTag);
		add(strings, "https://plantuml.com", withTag);
		add(strings, " ", withTag);
		return strings;
	}

	private static void add(List result, String s, boolean withTag) {
		if (withTag == false)
			s = s.replaceAll("\\", "");

		result.add(s);

	}

	// ::comment when __CORE__
	public static PSystemVersion createTestDot(UmlSource source) throws IOException {
		final List strings = new ArrayList<>();
		strings.add(Version.fullDescription());
		GraphvizUtils.addDotStatus(strings, true);
		return new PSystemVersion(source, false, strings);
	}

//	public static PSystemVersion createDumpStackTrace() throws IOException {
//		final List strings = new ArrayList<>();
//		final Throwable creationPoint = new Throwable();
//		creationPoint.fillInStackTrace();
//		for (StackTraceElement ste : creationPoint.getStackTrace()) {
//			strings.add(ste.toString());
//		}
//		return new PSystemVersion(false, strings);
//	}

	// ::comment when __CORE__
	public static PSystemVersion createKeyDistributor(UmlSource source) throws IOException {
		final LicenseInfo license = LicenseInfo.retrieveDistributor();
		BufferedImage im = null;
		final List strings = new ArrayList<>();
		if (license == null) {
			strings.add("No license found");
		} else {
			strings.add(license.getOwner());
			strings.add(license.getContext());
			strings.add(license.getGenerationDate().toString());
			strings.add(license.getExpirationDate().toString());
			im = LicenseInfo.retrieveDistributorImage(license);
		}
		return new PSystemVersion(source, strings, im);
	}

//	public static PSystemVersion createPath(UmlSource source) throws IOException {
//		final List strings = new ArrayList<>();
//		strings.add("Current Dir: " + new SFile(".").getPrintablePath());
//		strings.add(" ");
//		strings.add("Default path:");
//		for (SFile f : ImportedFiles.createImportedFiles(null).getPath()) {
//			strings.add(f.getPrintablePath());
//		}
//		return new PSystemVersion(source, true, strings);
//	}

	public DiagramDescription getDescription() {
		return new DiagramDescription("(Version)");
	}

	public List getLines() {
		return Collections.unmodifiableList(strings);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy