From e739cd8f5dccfdac2cec085ca37e2f1081b16b5d Mon Sep 17 00:00:00 2001 From: Arnaud Roques Date: Sun, 19 Mar 2023 13:13:13 +0100 Subject: [PATCH] fix: restore some help commands https://github.com/plantuml/plantuml/issues/1331 https://github.com/plantuml/plantuml/issues/1232 --- .../sourceforge/plantuml/PSystemBuilder.java | 2 + .../plantuml/help/CommandHelpColor.java | 71 ++++++++++++ .../plantuml/help/CommandHelpFont.java | 73 +++++++++++++ .../plantuml/help/CommandHelpKeyword.java | 71 ++++++++++++ .../plantuml/help/CommandHelpTheme.java | 83 ++++++++++++++ .../plantuml/help/CommandHelpType.java | 71 ++++++++++++ src/net/sourceforge/plantuml/help/Help.java | 103 ++++++++++++++++++ .../plantuml/help/HelpFactory.java | 63 +++++++++++ .../sourceforge/plantuml/version/Version.java | 2 +- 9 files changed, 538 insertions(+), 1 deletion(-) create mode 100644 src/net/sourceforge/plantuml/help/CommandHelpColor.java create mode 100644 src/net/sourceforge/plantuml/help/CommandHelpFont.java create mode 100644 src/net/sourceforge/plantuml/help/CommandHelpKeyword.java create mode 100644 src/net/sourceforge/plantuml/help/CommandHelpTheme.java create mode 100644 src/net/sourceforge/plantuml/help/CommandHelpType.java create mode 100644 src/net/sourceforge/plantuml/help/Help.java create mode 100644 src/net/sourceforge/plantuml/help/HelpFactory.java diff --git a/src/net/sourceforge/plantuml/PSystemBuilder.java b/src/net/sourceforge/plantuml/PSystemBuilder.java index 1b2168aeb..14c2f6aba 100644 --- a/src/net/sourceforge/plantuml/PSystemBuilder.java +++ b/src/net/sourceforge/plantuml/PSystemBuilder.java @@ -74,6 +74,7 @@ import net.sourceforge.plantuml.flowdiagram.FlowDiagramFactory; import net.sourceforge.plantuml.font.PSystemListFontsFactory; import net.sourceforge.plantuml.gitlog.GitDiagramFactory; import net.sourceforge.plantuml.hcl.HclDiagramFactory; +import net.sourceforge.plantuml.help.HelpFactory; import net.sourceforge.plantuml.jcckit.PSystemJcckitFactory; import net.sourceforge.plantuml.jsondiagram.JsonDiagramFactory; import net.sourceforge.plantuml.klimt.creole.legacy.PSystemCreoleFactory; @@ -247,6 +248,7 @@ public class PSystemBuilder { factories.add(new TimingDiagramFactory()); // ::comment when __CORE__ + factories.add(new HelpFactory()); factories.add(new WireDiagramFactory()); // ::done diff --git a/src/net/sourceforge/plantuml/help/CommandHelpColor.java b/src/net/sourceforge/plantuml/help/CommandHelpColor.java new file mode 100644 index 000000000..bc2ccbe40 --- /dev/null +++ b/src/net/sourceforge/plantuml/help/CommandHelpColor.java @@ -0,0 +1,71 @@ +/* ======================================================================== + * 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.help; + +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.SingleLineCommand2; +import net.sourceforge.plantuml.klimt.color.HColorSet; +import net.sourceforge.plantuml.regex.IRegex; +import net.sourceforge.plantuml.regex.RegexConcat; +import net.sourceforge.plantuml.regex.RegexLeaf; +import net.sourceforge.plantuml.regex.RegexResult; +import net.sourceforge.plantuml.utils.LineLocation; + +public class CommandHelpColor extends SingleLineCommand2 { + + public CommandHelpColor() { + super(getRegexConcat()); + } + + static IRegex getRegexConcat() { + return RegexConcat.build(CommandHelpColor.class.getName(), RegexLeaf.start(), // + new RegexLeaf("help"), // + RegexLeaf.spaceOneOrMore(), // + new RegexLeaf("colors?"), RegexLeaf.end()); + } + + @Override + protected CommandExecutionResult executeArg(Help diagram, LineLocation location, RegexResult arg) { + diagram.add("Help on colors"); + diagram.add(" "); + diagram.add(" The possible colors are :"); + for (String type : HColorSet.instance().names()) { + diagram.add("* " + type); + } + + return CommandExecutionResult.ok(); + } +} diff --git a/src/net/sourceforge/plantuml/help/CommandHelpFont.java b/src/net/sourceforge/plantuml/help/CommandHelpFont.java new file mode 100644 index 000000000..eaf4d39aa --- /dev/null +++ b/src/net/sourceforge/plantuml/help/CommandHelpFont.java @@ -0,0 +1,73 @@ +/* ======================================================================== + * 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.help; + +import java.awt.GraphicsEnvironment; + +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.SingleLineCommand2; +import net.sourceforge.plantuml.regex.IRegex; +import net.sourceforge.plantuml.regex.RegexConcat; +import net.sourceforge.plantuml.regex.RegexLeaf; +import net.sourceforge.plantuml.regex.RegexResult; +import net.sourceforge.plantuml.utils.LineLocation; + +public class CommandHelpFont extends SingleLineCommand2 { + + public CommandHelpFont() { + super(getRegexConcat()); + } + + static IRegex getRegexConcat() { + return RegexConcat.build(CommandHelpFont.class.getName(), RegexLeaf.start(), // + new RegexLeaf("help"), // + RegexLeaf.spaceOneOrMore(), // + new RegexLeaf("fonts?"), RegexLeaf.end()); + } + + @Override + protected CommandExecutionResult executeArg(Help diagram, LineLocation location, RegexResult arg) { + diagram.add("Help on font"); + diagram.add(" "); + diagram.add(" The possible font on your system are :"); + final String name[] = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); + for (String n : name) { + diagram.add("* " + n); + } + + return CommandExecutionResult.ok(); + } +} diff --git a/src/net/sourceforge/plantuml/help/CommandHelpKeyword.java b/src/net/sourceforge/plantuml/help/CommandHelpKeyword.java new file mode 100644 index 000000000..dd7033e36 --- /dev/null +++ b/src/net/sourceforge/plantuml/help/CommandHelpKeyword.java @@ -0,0 +1,71 @@ +/* ======================================================================== + * 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.help; + +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.SingleLineCommand2; +import net.sourceforge.plantuml.regex.IRegex; +import net.sourceforge.plantuml.regex.RegexConcat; +import net.sourceforge.plantuml.regex.RegexLeaf; +import net.sourceforge.plantuml.regex.RegexResult; +import net.sourceforge.plantuml.syntax.LanguageDescriptor; +import net.sourceforge.plantuml.utils.LineLocation; + +public class CommandHelpKeyword extends SingleLineCommand2 { + + public CommandHelpKeyword() { + super(getRegexConcat()); + } + + static IRegex getRegexConcat() { + return RegexConcat.build(CommandHelpKeyword.class.getName(), RegexLeaf.start(), // + new RegexLeaf("help"), // + RegexLeaf.spaceOneOrMore(), // + new RegexLeaf("keywords?"), RegexLeaf.end()); + } + + @Override + protected CommandExecutionResult executeArg(Help diagram, LineLocation location, RegexResult arg) { + diagram.add("Help on keywords"); + diagram.add(" "); + diagram.add(" The possible keywords are :"); + for (String type : new LanguageDescriptor().getKeyword()) { + diagram.add("* " + type); + } + + return CommandExecutionResult.ok(); + } +} diff --git a/src/net/sourceforge/plantuml/help/CommandHelpTheme.java b/src/net/sourceforge/plantuml/help/CommandHelpTheme.java new file mode 100644 index 000000000..8faa9a419 --- /dev/null +++ b/src/net/sourceforge/plantuml/help/CommandHelpTheme.java @@ -0,0 +1,83 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2021, 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: Matthew Leather + * + * + */ +package net.sourceforge.plantuml.help; + +import java.io.IOException; + +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.SingleLineCommand2; +import net.sourceforge.plantuml.log.Logme; +import net.sourceforge.plantuml.regex.IRegex; +import net.sourceforge.plantuml.regex.RegexConcat; +import net.sourceforge.plantuml.regex.RegexLeaf; +import net.sourceforge.plantuml.regex.RegexResult; +import net.sourceforge.plantuml.theme.ThemeUtils; +import net.sourceforge.plantuml.utils.LineLocation; +import net.sourceforge.plantuml.utils.Log; + +public class CommandHelpTheme extends SingleLineCommand2 { + + public CommandHelpTheme() { + super(getRegexConcat()); + } + + static IRegex getRegexConcat() { + return RegexConcat.build(CommandHelpTheme.class.getName(), RegexLeaf.start(), // + new RegexLeaf("help"), // + RegexLeaf.spaceOneOrMore(), // + new RegexLeaf("themes?"), RegexLeaf.end()); + } + + @Override + protected CommandExecutionResult executeArg(Help diagram, LineLocation location, RegexResult arg) { + diagram.add("Help on themes"); + diagram.add(" "); + diagram.add(" The possible themes are :"); + + try { + for (String theme : ThemeUtils.getAllThemeNames()) { + diagram.add("* " + theme); + } + } catch (IOException e) { + final String message = "Unexpected error listing themes: " + e.getMessage(); + Log.error(message); + Logme.error(e); + return CommandExecutionResult.error(message); + } + + return CommandExecutionResult.ok(); + } +} diff --git a/src/net/sourceforge/plantuml/help/CommandHelpType.java b/src/net/sourceforge/plantuml/help/CommandHelpType.java new file mode 100644 index 000000000..f0b40a95f --- /dev/null +++ b/src/net/sourceforge/plantuml/help/CommandHelpType.java @@ -0,0 +1,71 @@ +/* ======================================================================== + * 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.help; + +import net.sourceforge.plantuml.command.CommandExecutionResult; +import net.sourceforge.plantuml.command.SingleLineCommand2; +import net.sourceforge.plantuml.regex.IRegex; +import net.sourceforge.plantuml.regex.RegexConcat; +import net.sourceforge.plantuml.regex.RegexLeaf; +import net.sourceforge.plantuml.regex.RegexResult; +import net.sourceforge.plantuml.syntax.LanguageDescriptor; +import net.sourceforge.plantuml.utils.LineLocation; + +public class CommandHelpType extends SingleLineCommand2 { + + public CommandHelpType() { + super(getRegexConcat()); + } + + static IRegex getRegexConcat() { + return RegexConcat.build(CommandHelpType.class.getName(), RegexLeaf.start(), // + new RegexLeaf("help"), // + RegexLeaf.spaceOneOrMore(), // + new RegexLeaf("types?"), RegexLeaf.end()); + } + + @Override + protected CommandExecutionResult executeArg(Help diagram, LineLocation location, RegexResult arg) { + diagram.add("Help on types"); + diagram.add(" "); + diagram.add(" The possible types are :"); + for (String type : new LanguageDescriptor().getType()) { + diagram.add("* " + type); + } + + return CommandExecutionResult.ok(); + } +} diff --git a/src/net/sourceforge/plantuml/help/Help.java b/src/net/sourceforge/plantuml/help/Help.java new file mode 100644 index 000000000..36962e0a5 --- /dev/null +++ b/src/net/sourceforge/plantuml/help/Help.java @@ -0,0 +1,103 @@ +/* ======================================================================== + * 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.help; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +import net.atmp.ImageBuilder; +import net.sourceforge.plantuml.FileFormatOption; +import net.sourceforge.plantuml.UmlDiagram; +import net.sourceforge.plantuml.core.DiagramDescription; +import net.sourceforge.plantuml.core.ImageData; +import net.sourceforge.plantuml.core.UmlSource; +import net.sourceforge.plantuml.klimt.LineBreakStrategy; +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.font.FontConfiguration; +import net.sourceforge.plantuml.klimt.font.UFont; +import net.sourceforge.plantuml.klimt.geom.HorizontalAlignment; +import net.sourceforge.plantuml.klimt.shape.TextBlock; +import net.sourceforge.plantuml.skin.UmlDiagramType; +import net.sourceforge.plantuml.style.ClockwiseTopRightBottomLeft; + +public class Help extends UmlDiagram { + + private final List lines = new ArrayList<>(); + + public DiagramDescription getDescription() { + return new DiagramDescription("(Help)"); + } + + public Help(UmlSource source) { + super(source, UmlDiagramType.HELP, null); + } + + @Override + public ImageBuilder createImageBuilder(FileFormatOption fileFormatOption) throws IOException { + return super.createImageBuilder(fileFormatOption).annotations(false); + } + + @Override + protected ImageData exportDiagramInternal(OutputStream os, int index, FileFormatOption fileFormat) + throws IOException { + final Display display = Display.create(lines); + final UFont font = UFont.serif(16); + final FontConfiguration fontConfiguration = FontConfiguration.blackBlueTrue(font); + final Sheet sheet = getSkinParam().sheet(fontConfiguration, HorizontalAlignment.LEFT, CreoleMode.FULL) + .createSheet(display); + final SheetBlock1 sheetBlock = new SheetBlock1(sheet, LineBreakStrategy.NONE, 0); + return createImageBuilder(fileFormat).drawable(sheetBlock).write(os); + } + + public void add(CharSequence line) { + this.lines.add(line); + } + + @Override + public ClockwiseTopRightBottomLeft getDefaultMargins() { + return ClockwiseTopRightBottomLeft.same(0); + } + + @Override + protected TextBlock getTextBlock() { + throw new UnsupportedOperationException(); + } + +} diff --git a/src/net/sourceforge/plantuml/help/HelpFactory.java b/src/net/sourceforge/plantuml/help/HelpFactory.java new file mode 100644 index 000000000..b4fe437f0 --- /dev/null +++ b/src/net/sourceforge/plantuml/help/HelpFactory.java @@ -0,0 +1,63 @@ +/* ======================================================================== + * 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.help; + +import java.util.List; +import java.util.Map; + +import net.sourceforge.plantuml.command.Command; +import net.sourceforge.plantuml.command.PSystemCommandFactory; +import net.sourceforge.plantuml.core.UmlSource; + +public class HelpFactory extends PSystemCommandFactory { + // ::comment when __CORE__ + // ::comment when __HAXE__ + + @Override + public Help createEmptyDiagram(UmlSource source, Map skinParam) { + return new Help(source); + } + + @Override + protected void initCommandsList(List cmds) { + cmds.add(new CommandHelpColor()); + cmds.add(new CommandHelpFont()); + cmds.add(new CommandHelpKeyword()); + cmds.add(new CommandHelpType()); + cmds.add(new CommandHelpTheme()); + } + +} diff --git a/src/net/sourceforge/plantuml/version/Version.java b/src/net/sourceforge/plantuml/version/Version.java index f9d74510e..00e3cfbe1 100644 --- a/src/net/sourceforge/plantuml/version/Version.java +++ b/src/net/sourceforge/plantuml/version/Version.java @@ -82,7 +82,7 @@ public class Version { } public static int beta() { - final int beta = 3; + final int beta = 4; return beta; }