plantuml/src/net/sourceforge/plantuml/project/GanttDiagramFactory.java

173 lines
6.4 KiB
Java
Raw Normal View History

2017-02-01 18:55:51 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2022-03-07 19:33:46 +00:00
* (C) Copyright 2009-2023, Arnaud Roques
2017-02-01 18:55:51 +00:00
*
* Project Info: http://plantuml.com
*
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
*
2017-02-01 18:55:51 +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
*
*
*/
2020-02-18 21:24:31 +00:00
package net.sourceforge.plantuml.project;
2017-02-01 18:55:51 +00:00
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
2022-09-20 20:35:41 +00:00
import java.util.Map;
2017-02-01 18:55:51 +00:00
import net.sourceforge.plantuml.command.Command;
import net.sourceforge.plantuml.command.CommandNope;
2022-01-28 21:45:34 +00:00
import net.sourceforge.plantuml.command.CommonCommands;
2022-02-10 18:16:18 +00:00
import net.sourceforge.plantuml.command.PSystemCommandFactory;
2017-02-01 18:55:51 +00:00
import net.sourceforge.plantuml.core.DiagramType;
2021-05-23 15:35:13 +00:00
import net.sourceforge.plantuml.core.UmlSource;
2020-04-26 18:31:41 +00:00
import net.sourceforge.plantuml.project.command.CommandColorTask;
2020-11-21 17:33:24 +00:00
import net.sourceforge.plantuml.project.command.CommandFootbox;
2020-02-18 21:24:31 +00:00
import net.sourceforge.plantuml.project.command.CommandGanttArrow;
import net.sourceforge.plantuml.project.command.CommandGanttArrow2;
2022-08-18 16:55:09 +00:00
import net.sourceforge.plantuml.project.command.CommandGroupEnd;
import net.sourceforge.plantuml.project.command.CommandGroupStart;
2022-10-05 20:32:57 +00:00
import net.sourceforge.plantuml.project.command.CommandHideResourceFootbox;
import net.sourceforge.plantuml.project.command.CommandHideResourceName;
2021-05-06 21:23:05 +00:00
import net.sourceforge.plantuml.project.command.CommandLabelOnColumn;
2021-06-27 16:50:40 +00:00
import net.sourceforge.plantuml.project.command.CommandLanguage;
2020-08-25 17:24:17 +00:00
import net.sourceforge.plantuml.project.command.CommandNoteBottom;
2020-02-18 21:24:31 +00:00
import net.sourceforge.plantuml.project.command.CommandPrintBetween;
import net.sourceforge.plantuml.project.command.CommandPrintScale;
import net.sourceforge.plantuml.project.command.CommandSeparator;
2021-04-07 18:02:23 +00:00
import net.sourceforge.plantuml.project.command.CommandWeekNumberStrategy;
2020-02-18 21:24:31 +00:00
import net.sourceforge.plantuml.project.command.NaturalCommand;
2020-08-25 17:24:17 +00:00
import net.sourceforge.plantuml.project.lang.SentenceAnd;
import net.sourceforge.plantuml.project.lang.SentenceAndAnd;
import net.sourceforge.plantuml.project.lang.SentenceSimple;
import net.sourceforge.plantuml.project.lang.Subject;
2020-02-18 21:24:31 +00:00
import net.sourceforge.plantuml.project.lang.SubjectDayAsDate;
import net.sourceforge.plantuml.project.lang.SubjectDayOfWeek;
import net.sourceforge.plantuml.project.lang.SubjectDaysAsDates;
import net.sourceforge.plantuml.project.lang.SubjectProject;
import net.sourceforge.plantuml.project.lang.SubjectResource;
2022-08-18 16:55:09 +00:00
import net.sourceforge.plantuml.project.lang.SubjectSeparator;
2020-02-18 21:24:31 +00:00
import net.sourceforge.plantuml.project.lang.SubjectTask;
import net.sourceforge.plantuml.project.lang.SubjectToday;
2020-08-25 17:24:17 +00:00
import net.sourceforge.plantuml.style.CommandStyleImport;
import net.sourceforge.plantuml.style.CommandStyleMultilinesCSS;
2017-02-01 18:55:51 +00:00
2020-09-30 20:57:58 +00:00
public class GanttDiagramFactory extends PSystemCommandFactory {
2017-02-01 18:55:51 +00:00
2020-08-25 17:24:17 +00:00
static private final List<Subject> subjects() {
return Arrays.<Subject>asList(new SubjectTask(), new SubjectProject(), new SubjectDayOfWeek(),
2022-08-18 16:55:09 +00:00
new SubjectDayAsDate(), new SubjectDaysAsDates(), new SubjectResource(), new SubjectToday(),
new SubjectSeparator());
2017-02-01 18:55:51 +00:00
}
2017-11-20 16:10:36 +00:00
public GanttDiagramFactory(DiagramType type) {
super(type);
2017-02-01 18:55:51 +00:00
}
@Override
protected List<Command> createCommands() {
2021-05-14 08:42:57 +00:00
final List<Command> cmds = new ArrayList<>();
2022-01-28 21:45:34 +00:00
CommonCommands.addTitleCommands(cmds);
CommonCommands.addCommonCommands2(cmds);
2020-08-25 17:24:17 +00:00
cmds.add(new CommandStyleMultilinesCSS());
cmds.add(new CommandStyleImport());
2017-02-01 18:55:51 +00:00
cmds.add(new CommandNope());
2022-08-18 16:55:09 +00:00
2019-07-14 20:09:26 +00:00
cmds.addAll(getLanguageCommands());
2022-08-18 16:55:09 +00:00
2017-11-20 16:10:36 +00:00
cmds.add(new CommandGanttArrow());
2018-04-06 20:36:30 +00:00
cmds.add(new CommandGanttArrow2());
2020-04-26 18:31:41 +00:00
cmds.add(new CommandColorTask());
2018-04-06 20:36:30 +00:00
cmds.add(new CommandSeparator());
2021-04-07 18:02:23 +00:00
cmds.add(new CommandWeekNumberStrategy());
2022-08-18 16:55:09 +00:00
cmds.add(new CommandGroupStart());
cmds.add(new CommandGroupEnd());
2018-04-06 20:36:30 +00:00
2021-06-27 16:50:40 +00:00
cmds.add(new CommandLanguage());
2020-02-18 21:24:31 +00:00
cmds.add(new CommandPrintScale());
cmds.add(new CommandPrintBetween());
2020-08-25 17:24:17 +00:00
cmds.add(new CommandNoteBottom());
2020-11-21 17:33:24 +00:00
cmds.add(new CommandFootbox());
2021-05-06 21:23:05 +00:00
cmds.add(new CommandLabelOnColumn());
2022-10-05 20:32:57 +00:00
cmds.add(new CommandHideResourceName());
cmds.add(new CommandHideResourceFootbox());
2020-08-25 17:24:17 +00:00
2017-02-01 18:55:51 +00:00
return cmds;
}
2021-05-14 08:42:57 +00:00
static private final Collection<Command> cache = new ArrayList<>();
2019-07-14 20:09:26 +00:00
2021-05-23 15:35:13 +00:00
public static void clearCache() {
cache.clear();
}
2019-03-29 22:14:07 +00:00
private static Collection<Command> getLanguageCommands() {
2021-05-23 15:35:13 +00:00
// Useless synchronized now
2019-07-14 20:09:26 +00:00
synchronized (cache) {
if (cache.size() == 0) {
2020-08-25 17:24:17 +00:00
for (Subject subject : subjects()) {
for (SentenceSimple sentenceA : subject.getSentences()) {
cache.add(NaturalCommand.create(sentenceA));
for (SentenceSimple sentenceB : subject.getSentences()) {
if (sentenceA.getVerbPattern().equals(sentenceB.getVerbPattern()) == false) {
cache.add(NaturalCommand.create(new SentenceAnd(sentenceA, sentenceB)));
2019-07-14 20:09:26 +00:00
}
2017-02-01 18:55:51 +00:00
}
2019-07-14 20:09:26 +00:00
}
}
2020-08-25 17:24:17 +00:00
for (Subject subject : subjects()) {
for (SentenceSimple sentenceA : subject.getSentences()) {
for (SentenceSimple sentenceB : subject.getSentences()) {
for (SentenceSimple sentenceC : subject.getSentences()) {
if (sentenceA.getVerbPattern().equals(sentenceB.getVerbPattern()) == false
&& sentenceA.getVerbPattern().equals(sentenceC.getVerbPattern()) == false
&& sentenceC.getVerbPattern().equals(sentenceB.getVerbPattern()) == false) {
cache.add(
NaturalCommand.create(new SentenceAndAnd(sentenceA, sentenceB, sentenceC)));
2017-02-01 18:55:51 +00:00
}
}
}
}
}
}
}
2019-07-14 20:09:26 +00:00
return cache;
2017-02-01 18:55:51 +00:00
}
@Override
2022-09-20 20:35:41 +00:00
public GanttDiagram createEmptyDiagram(UmlSource source, Map<String, String> skinParam) {
2022-09-18 17:08:06 +00:00
return new GanttDiagram(source);
2017-02-01 18:55:51 +00:00
}
}