1
0
mirror of https://github.com/octoleo/plantuml.git synced 2024-06-26 03:42:36 +00:00
plantuml/src/net/sourceforge/plantuml/classdiagram/ClassDiagramFactory.java

167 lines
6.1 KiB
Java
Raw Normal View History

2010-11-15 20:35:36 +00:00
/* ========================================================================
* PlantUML : a free UML diagram generator
* ========================================================================
*
2015-04-07 18:18:37 +00:00
* (C) Copyright 2009-2014, Arnaud Roques
2010-11-15 20:35:36 +00:00
*
* Project Info: http://plantuml.sourceforge.net
*
* 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
2013-12-10 19:36:50 +00:00
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
2010-11-15 20:35:36 +00:00
* 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.
*
* [Java is a trademark or registered trademark of Sun Microsystems, Inc.
* in the United States and other countries.]
*
* Original Author: Arnaud Roques
2013-12-10 19:36:50 +00:00
*
* Revision $Revision: 10006 $
2010-11-15 20:35:36 +00:00
*
*/
package net.sourceforge.plantuml.classdiagram;
2013-12-10 19:36:50 +00:00
import java.util.ArrayList;
import java.util.List;
import net.sourceforge.plantuml.AbstractPSystem;
import net.sourceforge.plantuml.UmlDiagramType;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.classdiagram.command.CommandAddMethod;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.classdiagram.command.CommandAllowMixing;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.classdiagram.command.CommandCreateClass;
import net.sourceforge.plantuml.classdiagram.command.CommandCreateClassMultilines;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.classdiagram.command.CommandCreateElementFull2;
import net.sourceforge.plantuml.classdiagram.command.CommandCreateElementFull2.Mode;
2011-08-08 17:48:29 +00:00
import net.sourceforge.plantuml.classdiagram.command.CommandDiamondAssociation;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.classdiagram.command.CommandHideShowSpecificClass;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.classdiagram.command.CommandImport;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.classdiagram.command.CommandLayoutNewLine;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.classdiagram.command.CommandLinkClass;
import net.sourceforge.plantuml.classdiagram.command.CommandLinkLollipop;
import net.sourceforge.plantuml.classdiagram.command.CommandMouseOver;
import net.sourceforge.plantuml.classdiagram.command.CommandNamespaceSeparator;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.classdiagram.command.CommandStereotype;
import net.sourceforge.plantuml.classdiagram.command.CommandUrl;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.command.Command;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.command.CommandEndPackage;
2015-04-07 18:18:37 +00:00
import net.sourceforge.plantuml.command.CommandFootboxIgnored;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.command.CommandNamespace;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.command.CommandPackage;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.command.CommandPackageEmpty;
2010-11-15 20:35:36 +00:00
import net.sourceforge.plantuml.command.CommandPage;
2013-12-10 19:36:50 +00:00
import net.sourceforge.plantuml.command.CommandRankDir;
import net.sourceforge.plantuml.command.UmlDiagramFactory;
import net.sourceforge.plantuml.command.note.FactoryNoteCommand;
import net.sourceforge.plantuml.command.note.FactoryNoteOnEntityCommand;
import net.sourceforge.plantuml.command.note.FactoryNoteOnLinkCommand;
import net.sourceforge.plantuml.command.regex.RegexLeaf;
import net.sourceforge.plantuml.cucadiagram.Link;
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
public class ClassDiagramFactory extends UmlDiagramFactory {
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
@Override
public ClassDiagram createEmptyDiagram() {
return new ClassDiagram();
2010-11-15 20:35:36 +00:00
}
@Override
2013-12-10 19:36:50 +00:00
protected List<Command> createCommands() {
final List<Command> cmds = new ArrayList<Command>();
2015-04-07 18:18:37 +00:00
cmds.add(new CommandFootboxIgnored());
2013-12-10 19:36:50 +00:00
addCommonCommands(cmds);
cmds.add(new CommandRankDir());
cmds.add(new CommandPage());
cmds.add(new CommandAddMethod());
cmds.add(new CommandCreateClass());
2015-04-07 18:18:37 +00:00
cmds.add(new CommandAllowMixing());
cmds.add(new CommandLayoutNewLine());
cmds.add(new CommandCreateElementFull2(Mode.NORMAL_KEYWORD));
cmds.add(new CommandCreateElementFull2(Mode.WITH_MIX_PREFIX));
2013-12-10 19:36:50 +00:00
final FactoryNoteCommand factoryNoteCommand = new FactoryNoteCommand();
cmds.add(factoryNoteCommand.createSingleLine());
cmds.add(new CommandPackage());
cmds.add(new CommandEndPackage());
cmds.add(new CommandPackageEmpty());
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
cmds.add(new CommandNamespace());
cmds.add(new CommandStereotype());
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
cmds.add(new CommandLinkClass(UmlDiagramType.CLASS));
cmds.add(new CommandLinkLollipop(UmlDiagramType.CLASS));
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
cmds.add(new CommandImport());
final FactoryNoteOnEntityCommand factoryNoteOnEntityCommand = new FactoryNoteOnEntityCommand(new RegexLeaf(
2015-04-07 18:18:37 +00:00
"ENTITY", "(" + CommandCreateClass.CODE + "|[%g][^%g]+[%g])"));
2013-12-10 19:36:50 +00:00
cmds.add(factoryNoteOnEntityCommand.createSingleLine());
cmds.add(new CommandUrl());
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
cmds.add(factoryNoteOnEntityCommand.createMultiLine());
cmds.add(factoryNoteCommand.createMultiLine());
cmds.add(new CommandCreateClassMultilines());
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
final FactoryNoteOnLinkCommand factoryNoteOnLinkCommand = new FactoryNoteOnLinkCommand();
cmds.add(factoryNoteOnLinkCommand.createSingleLine());
cmds.add(factoryNoteOnLinkCommand.createMultiLine());
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
cmds.add(new CommandDiamondAssociation());
cmds.add(new CommandMouseOver());
2011-08-08 17:48:29 +00:00
2013-12-10 19:36:50 +00:00
cmds.add(new CommandHideShowSpecificClass());
2011-08-08 17:48:29 +00:00
2013-12-10 19:36:50 +00:00
cmds.add(new CommandNamespaceSeparator());
2010-11-15 20:35:36 +00:00
2013-12-10 19:36:50 +00:00
return cmds;
2010-11-15 20:35:36 +00:00
}
2013-12-10 19:36:50 +00:00
@Override
public String checkFinalError(AbstractPSystem sys) {
final ClassDiagram system = (ClassDiagram) sys;
for (Link link : system.getLinks()) {
final int len = link.getLength();
if (len == 1) {
for (Link link2 : system.getLinks()) {
if (link2.sameConnections(link) && link2.getLength() != 1) {
link2.setLength(1);
}
}
}
}
system.applySingleStrategy();
2015-04-07 18:18:37 +00:00
// for (IGroup g : system.getGroups(true)) {
// final List<ILeaf> standalones = new ArrayList<ILeaf>();
// for (ILeaf ent : g.getLeafsDirect()) {
// if (system.isStandalone(ent)) {
// standalones.add(ent);
// }
// }
// if (standalones.size() < 3) {
// continue;
// }
// final Magma magma = new Magma(system, standalones);
// magma.putInSquare();
// }
2013-12-10 19:36:50 +00:00
return super.checkFinalError(system);
}
2010-11-15 20:35:36 +00:00
}