diff --git a/gradle.properties b/gradle.properties index 5151972fb..0073d3563 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ # Warning, "version" should be the same in gradle.properties and Version.java # Any idea anyone how to magically synchronize those :-) ? -version = 1.2023.10beta1 +version = 1.2023.10beta2 org.gradle.workers.max = 3 \ No newline at end of file diff --git a/src/net/sourceforge/plantuml/filesdiagram/FEntry.java b/src/net/sourceforge/plantuml/filesdiagram/FEntry.java new file mode 100644 index 000000000..eefc7d18e --- /dev/null +++ b/src/net/sourceforge/plantuml/filesdiagram/FEntry.java @@ -0,0 +1,162 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2024, Arnaud Roques + * + * Project Info: https://plantuml.com + * + * If you like this project or if you find it useful, you can support us at: + * + * https://plantuml.com/patreon (only 1$ per month!) + * https://plantuml.com/paypal + * + * 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.filesdiagram; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import net.sourceforge.plantuml.klimt.LineBreakStrategy; +import net.sourceforge.plantuml.klimt.UStroke; +import net.sourceforge.plantuml.klimt.UTranslate; +import net.sourceforge.plantuml.klimt.color.HColor; +import net.sourceforge.plantuml.klimt.creole.CreoleMode; +import net.sourceforge.plantuml.klimt.creole.Display; +import net.sourceforge.plantuml.klimt.creole.Sheet; +import net.sourceforge.plantuml.klimt.creole.SheetBlock1; +import net.sourceforge.plantuml.klimt.drawing.UGraphic; +import net.sourceforge.plantuml.klimt.font.FontConfiguration; +import net.sourceforge.plantuml.klimt.geom.HorizontalAlignment; +import net.sourceforge.plantuml.klimt.shape.TextBlock; +import net.sourceforge.plantuml.style.ISkinParam; +import net.sourceforge.plantuml.style.PName; +import net.sourceforge.plantuml.style.SName; +import net.sourceforge.plantuml.style.Style; +import net.sourceforge.plantuml.style.StyleSignatureBasic; +import net.sourceforge.plantuml.svek.image.Opale; + +public class FEntry implements Iterable { + + private final ISkinParam skinParam; + private final List note; + private final String name; + private FilesType type; + private List children = new ArrayList<>(); + + public static FEntry createRoot(ISkinParam skinParam) { + return new FEntry(null, "", FilesType.FOLDER, skinParam); + } + + private FEntry(List note, String name, FilesType type, ISkinParam skinParam) { + this.note = note; + this.name = name; + this.type = type; + this.skinParam = skinParam; + } + + public void addRawEntry(String raw, ISkinParam skinParam) { + final int x = raw.indexOf('/'); + if (x == -1) { + final FEntry result = new FEntry(null, raw, FilesType.DATA, skinParam); + children.add(result); + return; + } + final FEntry folder = getOrCreateFolder(raw.substring(0, x), skinParam); + final String remain = raw.substring(x + 1); + if (remain.length() != 0) + folder.addRawEntry(remain, skinParam); + } + + public void addNote(List note, ISkinParam skinParam) { + final FEntry result = new FEntry(note, "NONE", FilesType.NOTE, skinParam); + children.add(result); + } + + private FEntry getOrCreateFolder(String folderName, ISkinParam skinParam) { + for (FEntry child : children) + if (child.type == FilesType.FOLDER && child.getName().equals(folderName)) + return child; + + final FEntry result = new FEntry(null, folderName, FilesType.FOLDER, skinParam); + children.add(result); + return result; + } + + @Override + public Iterator iterator() { + return Collections.unmodifiableCollection(children).iterator(); + } + + public String getName() { + return name; + } + + public String getEmoticon() { + if (type == FilesType.FOLDER) + return "<:1f4c2:>"; + // return "<:1f4c1:>"; + return "<:1f4c4:>"; + } + + public UGraphic drawAndMove(UGraphic ug, FontConfiguration fontConfiguration, ISkinParam skinParam, double deltax) { + final TextBlock result = getTextBlock(fontConfiguration, skinParam); + result.drawU(ug.apply(UTranslate.dx(deltax))); + ug = ug.apply(UTranslate.dy(result.calculateDimension(ug.getStringBounder()).getHeight() + 2)); + for (FEntry child : children) + ug = child.drawAndMove(ug, fontConfiguration, skinParam, deltax + 21); + return ug; + } + + private TextBlock getTextBlock(FontConfiguration fontConfiguration, ISkinParam skinParam) { + if (type == FilesType.NOTE) + return createOpale(); + + final Display display = Display.getWithNewlines(getEmoticon() + getName()); + TextBlock result = display.create(fontConfiguration, HorizontalAlignment.LEFT, skinParam); + return result; + } + + private Opale createOpale() { + + final StyleSignatureBasic signature = StyleSignatureBasic.of(SName.root, SName.element, SName.timingDiagram, + SName.note); + final Style style = signature.getMergedStyle(skinParam.getCurrentStyleBuilder()); + + final FontConfiguration fc = FontConfiguration.create(skinParam, style); + final double shadowing = style.value(PName.Shadowing).asDouble(); + final HColor borderColor = style.value(PName.LineColor).asColor(skinParam.getIHtmlColorSet()); + final HColor noteBackgroundColor = style.value(PName.BackGroundColor).asColor(skinParam.getIHtmlColorSet()); + final UStroke stroke = style.getStroke(); + + final Sheet sheet = skinParam + .sheet(fc, skinParam.getDefaultTextAlignment(HorizontalAlignment.LEFT), CreoleMode.FULL) + .createSheet(Display.create(note)); + final SheetBlock1 sheet1 = new SheetBlock1(sheet, LineBreakStrategy.NONE, skinParam.getPadding()); + final Opale opale = new Opale(shadowing, borderColor, noteBackgroundColor, sheet1, false, stroke); + return opale; + } + +} diff --git a/src/net/sourceforge/plantuml/filesdiagram/FilesDiagram.java b/src/net/sourceforge/plantuml/filesdiagram/FilesDiagram.java index 4398a99a0..b5142b7c0 100644 --- a/src/net/sourceforge/plantuml/filesdiagram/FilesDiagram.java +++ b/src/net/sourceforge/plantuml/filesdiagram/FilesDiagram.java @@ -36,7 +36,10 @@ package net.sourceforge.plantuml.filesdiagram; import java.io.IOException; import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Collections; import java.util.Iterator; +import java.util.List; import net.sourceforge.plantuml.FileFormatOption; import net.sourceforge.plantuml.UmlDiagram; @@ -57,15 +60,27 @@ public class FilesDiagram extends UmlDiagram { final Iterator it = source.iterator2(); it.next(); - while (true) { + while (it.hasNext()) { final String line = it.next().getString(); - if (it.hasNext() == false) - break; - this.list.add(line); + if (line.startsWith("/")) + this.list.addRawEntry(line.substring(1)); + else if (line.startsWith("")) + this.list.addNote(getNote(it)); } } + private List getNote(Iterator it) { + final List result = new ArrayList(); + while (it.hasNext()) { + final String line = it.next().getString(); + if (line.startsWith("")) + return result; + result.add(line); + } + return Collections.unmodifiableList(result); + } + public DiagramDescription getDescription() { return new DiagramDescription("(Files)"); } diff --git a/src/net/sourceforge/plantuml/filesdiagram/FilesEntry.java b/src/net/sourceforge/plantuml/filesdiagram/FilesEntry.java deleted file mode 100644 index 744d49514..000000000 --- a/src/net/sourceforge/plantuml/filesdiagram/FilesEntry.java +++ /dev/null @@ -1,111 +0,0 @@ -/* ======================================================================== - * PlantUML : a free UML diagram generator - * ======================================================================== - * - * (C) Copyright 2009-2024, Arnaud Roques - * - * Project Info: https://plantuml.com - * - * If you like this project or if you find it useful, you can support us at: - * - * https://plantuml.com/patreon (only 1$ per month!) - * https://plantuml.com/paypal - * - * 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.filesdiagram; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import net.sourceforge.plantuml.klimt.UTranslate; -import net.sourceforge.plantuml.klimt.creole.Display; -import net.sourceforge.plantuml.klimt.drawing.UGraphic; -import net.sourceforge.plantuml.klimt.font.FontConfiguration; -import net.sourceforge.plantuml.klimt.geom.HorizontalAlignment; -import net.sourceforge.plantuml.klimt.shape.TextBlock; -import net.sourceforge.plantuml.style.ISkinParam; - -public class FilesEntry implements Iterable { - - private final String name; - private FilesType type; - private List children = new ArrayList<>(); - - public FilesEntry(String name, FilesType type) { - this.name = name; - this.type = type; - } - - public FilesEntry addRawEntry(String raw) { - final int x = raw.indexOf('/'); - if (x == -1) { - final FilesEntry result = new FilesEntry(raw, FilesType.DATA); - children.add(result); - return result; - } - final FilesEntry folder = getOrCreateFolder(raw.substring(0, x)); - final String remain = raw.substring(x + 1); - if (remain.length() == 0) - return folder; - return folder.addRawEntry(remain); - } - - private FilesEntry getOrCreateFolder(String folderName) { - for (FilesEntry child : children) - if (child.type == FilesType.FOLDER && child.getName().equals(folderName)) - return child; - - final FilesEntry result = new FilesEntry(folderName, FilesType.FOLDER); - children.add(result); - return result; - } - - @Override - public Iterator iterator() { - return Collections.unmodifiableCollection(children).iterator(); - } - - public String getName() { - return name; - } - - public String getEmoticon() { - if (type == FilesType.FOLDER) - return "<:1f4c2:>"; - // return "<:1f4c1:>"; - return "<:1f4c4:>"; - } - - public UGraphic drawAndMove(UGraphic ug, FontConfiguration fontConfiguration, ISkinParam skinParam, double deltax) { - final Display display = Display.getWithNewlines(getEmoticon() + getName()); - TextBlock result = display.create(fontConfiguration, HorizontalAlignment.LEFT, skinParam); - result.drawU(ug.apply(UTranslate.dx(deltax))); - ug = ug.apply(UTranslate.dy(result.calculateDimension(ug.getStringBounder()).getHeight() + 2)); - for (FilesEntry child : children) - ug = child.drawAndMove(ug, fontConfiguration, skinParam, deltax + 21); - return ug; - } - -} diff --git a/src/net/sourceforge/plantuml/filesdiagram/FilesListing.java b/src/net/sourceforge/plantuml/filesdiagram/FilesListing.java index 097e93e69..592a779a0 100644 --- a/src/net/sourceforge/plantuml/filesdiagram/FilesListing.java +++ b/src/net/sourceforge/plantuml/filesdiagram/FilesListing.java @@ -34,6 +34,8 @@ */ package net.sourceforge.plantuml.filesdiagram; +import java.util.List; + import net.sourceforge.plantuml.klimt.drawing.UGraphic; import net.sourceforge.plantuml.klimt.font.FontConfiguration; import net.sourceforge.plantuml.klimt.font.StringBounder; @@ -46,10 +48,11 @@ public class FilesListing extends AbstractTextBlock { private final ISkinParam skinParam; private final FontConfiguration fontConfiguration = FontConfiguration.blackBlueTrue(UFont.courier(14)); - private final FilesEntry root = new FilesEntry("", FilesType.FOLDER); + private final FEntry root; public FilesListing(ISkinParam skinParam) { this.skinParam = skinParam; + this.root = FEntry.createRoot(skinParam); } @Override @@ -59,13 +62,16 @@ public class FilesListing extends AbstractTextBlock { @Override public void drawU(UGraphic ug) { - for (FilesEntry ent : root) + for (FEntry ent : root) ug = ent.drawAndMove(ug, fontConfiguration, skinParam, 0); } - public void add(String line) { - if (line.startsWith("/")) - root.addRawEntry(line.substring(1)); + public void addRawEntry(String raw) { + root.addRawEntry(raw, skinParam); + } + + public void addNote(List note) { + root.addNote(note, skinParam); } } diff --git a/src/net/sourceforge/plantuml/filesdiagram/FilesType.java b/src/net/sourceforge/plantuml/filesdiagram/FilesType.java index 4c6d98615..8817ab1a5 100644 --- a/src/net/sourceforge/plantuml/filesdiagram/FilesType.java +++ b/src/net/sourceforge/plantuml/filesdiagram/FilesType.java @@ -35,6 +35,6 @@ package net.sourceforge.plantuml.filesdiagram; public enum FilesType { - FOLDER, DATA; + FOLDER, DATA, NOTE; } diff --git a/src/net/sourceforge/plantuml/klimt/font/UFont.java b/src/net/sourceforge/plantuml/klimt/font/UFont.java index 3816fd770..be9d36607 100644 --- a/src/net/sourceforge/plantuml/klimt/font/UFont.java +++ b/src/net/sourceforge/plantuml/klimt/font/UFont.java @@ -70,7 +70,9 @@ public class UFont { } public static UFont build(String fontFamily, int fontStyle, int fontSize) { - return new UFont(buildFont(fontFamily, fontStyle, fontSize), fontFamily); + final String family = getExistingFontFamily(fontFamily); + final Font font = new Font(family, fontStyle, fontSize); + return new UFont(font, fontFamily); } private UFont(Font font, String family) { @@ -78,16 +80,16 @@ public class UFont { this.family = family; } - private static Font buildFont(String fontFamily, int fontStyle, int fontSize) { - if (fontFamily.contains(",")) + public static String getExistingFontFamily(String fontFamily) { + if (fontFamily.contains(",")) { for (String name : fontFamily.split(",")) { name = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(name.trim()).trim(); if (doesFamilyExists(name)) - return new Font(name, fontStyle, fontSize); - + return name; } - - return new Font(fontFamily, fontStyle, fontSize); + return "SansSerif"; + } + return StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(fontFamily.trim()).trim(); } private static boolean doesFamilyExists(String name) { diff --git a/src/net/sourceforge/plantuml/style/Style.java b/src/net/sourceforge/plantuml/style/Style.java index b4c6a6f26..78e92f2de 100644 --- a/src/net/sourceforge/plantuml/style/Style.java +++ b/src/net/sourceforge/plantuml/style/Style.java @@ -58,7 +58,7 @@ import net.sourceforge.plantuml.klimt.shape.TextBlock; import net.sourceforge.plantuml.klimt.shape.TextBlockUtils; public class Style { - // ::remove file when __HAXE__ + // ::remove file when __HAXE__ private final Map map; private final StyleSignatureBasic signature; @@ -180,8 +180,8 @@ public class Style { } public UFont getUFont() { - final String family = StringUtils - .eventuallyRemoveStartingAndEndingDoubleQuote(value(PName.FontName).asString()); + final String fontName = value(PName.FontName).asString(); + final String family = UFont.getExistingFontFamily(fontName); final int fontStyle = value(PName.FontStyle).asFontStyle(); int size = value(PName.FontSize).asInt(true); if (size == -1) diff --git a/src/net/sourceforge/plantuml/version/Version.java b/src/net/sourceforge/plantuml/version/Version.java index 2b14add8e..8126a1583 100644 --- a/src/net/sourceforge/plantuml/version/Version.java +++ b/src/net/sourceforge/plantuml/version/Version.java @@ -46,7 +46,7 @@ public class Version { // Warning, "version" should be the same in gradle.properties and Version.java // Any idea anyone how to magically synchronize those :-) ? - private static final String version = "1.2023.10beta1"; + private static final String version = "1.2023.10beta2"; public static String versionString() { return version;