private CommandExecutionResult executeInternal(
      RegexResult line0, AbstractEntityDiagram diagram, Url url, BlocLines lines) {

    final String pos = line0.get("POSITION", 0);

    final Code code = Code.of(line0.get("ENTITY", 0));
    final String member = line0.get("ENTITY", 1);
    if (code == null) {
      return CommandExecutionResult.error("Nothing to note to");
    }
    final IEntity cl1 = diagram.getOrCreateLeaf(code, null, null);
    final Position position =
        Position.valueOf(StringUtils.goUpperCase(pos))
            .withRankdir(diagram.getSkinParam().getRankdir());

    final Code codeTip = code.addSuffix("$$$" + position.name());
    IEntity tips = diagram.getLeafsget(codeTip);
    if (tips == null) {
      tips = diagram.getOrCreateLeaf(codeTip, LeafType.TIPS, null);
      final LinkType type = new LinkType(LinkDecor.NONE, LinkDecor.NONE).getInvisible();
      final Link link;
      if (position == Position.RIGHT) {
        link = new Link(cl1, (IEntity) tips, type, Display.NULL, 1);
      } else {
        link = new Link((IEntity) tips, cl1, type, Display.NULL, 1);
      }
      diagram.addLink(link);
    }
    tips.putTip(member, lines.toDisplay());

    // final IEntity note = diagram.createLeaf(UniqueSequence.getCode("GMN"), Display.create(s),
    // LeafType.NOTE,
    // null);
    // note.setSpecificBackcolor(diagram.getSkinParam().getIHtmlColorSet().getColorIfValid(line0.get("COLOR", 0)));
    // if (url != null) {
    // note.addUrl(url);
    // }
    //
    // final Position position = Position.valueOf(StringUtils.goUpperCase(pos)).withRankdir(
    // diagram.getSkinParam().getRankdir());
    // final Link link;
    //
    // final LinkType type = new LinkType(LinkDecor.NONE, LinkDecor.NONE).getDashed();
    // if (position == Position.RIGHT) {
    // link = new Link(cl1, note, type, null, 1);
    // link.setHorizontalSolitary(true);
    // } else if (position == Position.LEFT) {
    // link = new Link(note, cl1, type, null, 1);
    // link.setHorizontalSolitary(true);
    // } else if (position == Position.BOTTOM) {
    // link = new Link(cl1, note, type, null, 2);
    // } else if (position == Position.TOP) {
    // link = new Link(note, cl1, type, null, 2);
    // } else {
    // throw new IllegalArgumentException();
    // }
    // diagram.addLink(link);
    return CommandExecutionResult.ok();
  }
 static EntityType getTypeIfExisting(ActivityDiagram system, String code) {
   if (system.entityExist(code)) {
     final IEntity ent = system.entities().get(code);
     if (ent.getType() == EntityType.BRANCH) {
       return EntityType.BRANCH;
     }
   }
   return EntityType.ACTIVITY;
 }
  public CucaDiagramSimplifier2(CucaDiagram diagram, List<String> dotStrings)
      throws IOException, InterruptedException {
    this.diagram = diagram;
    boolean changed;
    do {
      changed = false;
      final Collection<Group> groups = new ArrayList<Group>(diagram.getGroups(false));
      for (Group g : groups) {
        if (diagram.isAutarkic(g)) {
          final EntityType type;
          if (g.getType() == GroupType.CONCURRENT_STATE) {
            type = EntityType.STATE_CONCURRENT;
          } else if (g.getType() == GroupType.STATE) {
            type = EntityType.STATE;
          } else if (g.getType() == GroupType.INNER_ACTIVITY) {
            type = EntityType.ACTIVITY;
          } else if (g.getType() == GroupType.CONCURRENT_ACTIVITY) {
            type = EntityType.ACTIVITY_CONCURRENT;
          } else {
            throw new IllegalStateException();
          }
          final Entity proxy =
              new Entity(
                  "#" + g.getCode(), g.getDisplay(), type, g.getParent(), diagram.getHides());
          // if (type == EntityType.STATE) {
          // manageBackColorForState(diagram, g, proxy);
          // }
          for (Member field : g.getEntityCluster().getFieldsToDisplay()) {
            proxy.addField(field);
          }
          computeImageGroup(g, proxy, dotStrings);
          diagram.overideGroup(g, proxy);
          if (proxy.getImageFile() != null) {
            diagram.ensureDelete(proxy.getImageFile());
          }

          // final IEntity entityCluster = g.getEntityCluster();
          // if (entityCluster != null && entityCluster.getImageFile()
          // != null) {
          // proxy.addSubImage(entityCluster.getImageFile());
          // }
          // if (entityCluster != null) {
          // proxy.addSubImage((Entity) entityCluster);
          // }

          for (IEntity sub : g.entities().values()) {
            final DrawFile subImage = sub.getImageFile();
            if (subImage != null) {
              proxy.addSubImage(subImage);
            }
          }

          changed = true;
        }
      }
    } while (changed);
  }
 @Override
 protected CommandExecutionResult executeArg(ClassDiagram diagram, List<String> arg) {
   final Code code = Code.of(arg.get(0));
   final String stereotype = arg.get(1);
   final IEntity entity = diagram.getOrCreateLeaf(code, null, null);
   entity.setStereotype(
       new Stereotype(
           stereotype,
           diagram.getSkinParam().getCircledCharacterRadius(),
           diagram.getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null, false),
           diagram.getSkinParam().getIHtmlColorSet()));
   return CommandExecutionResult.ok();
 }
  public void drawU(
      UGraphic ug,
      double xTheoricalPosition,
      double yTheoricalPosition,
      double marginWidth,
      double marginHeight) {
    final Dimension2D dim = getDimension(ug.getStringBounder());

    final double widthTotal = dim.getWidth() + 2 * marginWidth;
    final double heightTotal = dim.getHeight() + 2 * marginHeight;
    final URectangle rect = new URectangle(widthTotal, heightTotal);

    // if (entity.getParent() == null) {
    if (entity.getType() != EntityType.GROUP) {
      ug.getParam().setBackcolor(rose.getHtmlColor(param, ColorParam.classBackground));
      ug.getParam().setColor(rose.getHtmlColor(param, ColorParam.classBorder));
      ug.draw(xTheoricalPosition - marginWidth, yTheoricalPosition - marginHeight, rect);
      // name.drawU(ug, xTheoricalPosition + margin, yTheoricalPosition + margin);
      name.drawU(ug, xTheoricalPosition + 0, yTheoricalPosition + 0);
    } else {
      // final Frame frame = new Frame(StringUtils.getWithNewlines(entity.getDisplay()),
      // Color.BLACK, param
      // .getFont(FontParam.CLASS), rose.getHtmlColor(param, ColorParam.classBorder).getColor());
      final Frame frame = new Frame(entity.getDisplay2(), param);

      ug.getParam().setBackcolor(rose.getHtmlColor(param, ColorParam.background));
      ug.getParam().setColor(null);
      ug.draw(xTheoricalPosition - marginWidth, yTheoricalPosition - marginWidth, rect);

      final double oldX = ug.getTranslateX();
      final double oldY = ug.getTranslateY();
      ug.translate(xTheoricalPosition - marginWidth, yTheoricalPosition - marginHeight);
      frame.drawU(ug, new Area(new Dimension2DDouble(widthTotal, heightTotal)), null);
      // ug.translate(-xTheoricalPosition + marginWidth,
      // -yTheoricalPosition + marginHeight);
      ug.setTranslate(oldX, oldY);

      // playField.drawInternal(UGraphicUtils.translate(ug, xTheoricalPosition + margin,
      // yTheoricalPosition +
      // margin
      // + frame.getPreferredHeight(ug.getStringBounder())));
      playField.drawInternal(
          UGraphicUtils.translate(
              ug,
              xTheoricalPosition + 0,
              yTheoricalPosition + 0 + frame.getPreferredHeight(ug.getStringBounder())));
    }
  }
Example #6
0
  public EntityImageNote2(IEntity entity, ISkinParam skinParam, Collection<Link> links) {
    super(entity, skinParam);

    final Rose skin = new Rose();

    comp = skin.createComponent(ComponentType.NOTE, null, skinParam, entity.getDisplay());
  }
  private void initPlayField(StringBounder stringBounder) {
    if (playField != null || entity.getParent() == null || entity.getType() != EntityType.GROUP) {
      return;
    }
    this.playField = new PlayField(param);
    final Collection<IEntity> entities = new ArrayList<IEntity>();
    for (IEntity ent : entity.getParent().entities().values()) {
      // entities.add(EntityUtils.withNoParent(ent));
      entities.add(ent);
    }
    playField.initInternal(entities, links, stringBounder);

    // this.frame = new Frame(StringUtils.getWithNewlines(entity.getDisplay()), Color.BLACK, param
    // .getFont(FontParam.CLASS), rose.getHtmlColor(param, ColorParam.classBorder).getColor());
    this.frame = new Frame(entity.getDisplay2(), param);
  }
  private CommandExecutionResult executeInternal(
      ActivityDiagram system, RegexResult arg, IEntity note) {

    note.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(arg.get("COLOR", 0)));

    IEntity activity = system.getLastEntityConsulted();
    if (activity == null) {
      activity = system.getStart();
    }

    final Link link;

    final Position position =
        Position.valueOf(arg.get("POSITION", 0).toUpperCase()).withRankdir(system.getRankdir());

    final LinkType type = new LinkType(LinkDecor.NONE, LinkDecor.NONE).getDashed();

    if (position == Position.RIGHT) {
      link = new Link(activity, note, type, null, 1);
    } else if (position == Position.LEFT) {
      link = new Link(note, activity, type, null, 1);
    } else if (position == Position.BOTTOM) {
      link = new Link(activity, note, type, null, 2);
    } else if (position == Position.TOP) {
      link = new Link(note, activity, type, null, 2);
    } else {
      throw new IllegalArgumentException();
    }
    system.addLink(link);
    return CommandExecutionResult.ok();
  }
 public void executeElse(Collection<IEntity> pendingsToAdd) {
   if (this.hasElse) {
     throw new IllegalStateException();
   }
   this.hasElse = true;
   // Log.println("pend=" + pendings);
   if (pendings.size() == 0) {
     throw new IllegalStateException();
   }
   final Iterator<IEntity> it = pendings.iterator();
   final IEntity toRemove = it.next();
   if (toRemove.getEntityType() != EntityType.BRANCH) {
     throw new IllegalStateException();
   }
   it.remove();
   this.pendings.addAll(pendingsToAdd);
 }
  @Override
  protected CommandExecutionResult executeArg(RegexResult arg) {
    final Code g1 = Code.of(arg.get("G1", 0));
    final Code g2 = Code.of(arg.get("G2", 0));

    if (getSystem().isGroup(g1) && getSystem().isGroup(g2)) {
      return executePackageLink(arg);
    }
    if (getSystem().isGroup(g1) || getSystem().isGroup(g2)) {
      return CommandExecutionResult.error("Package can be only linked to other package");
    }

    final IEntity cl1 = getSystem().getOrCreateClass(g1);
    final IEntity cl2 = getSystem().getOrCreateClass(g2);

    if (arg.get("G1", 1) != null) {
      cl1.setStereotype(new Stereotype(arg.get("G1", 1)));
    }
    if (arg.get("G2", 1) != null) {
      cl2.setStereotype(new Stereotype(arg.get("G2", 1)));
    }

    final LinkType linkType;
    String queue;
    if (arg.get("AR_TO_RIGHT", 0) == null) {
      queue = arg.get("AR_TO_LEFT", 2) + arg.get("AR_TO_LEFT", 4);
      linkType = getLinkTypeNormal(queue, arg.get("AR_TO_LEFT", 1)).getInversed();
    } else {
      queue = arg.get("AR_TO_RIGHT", 1) + arg.get("AR_TO_RIGHT", 3);
      linkType = getLinkTypeNormal(queue, arg.get("AR_TO_RIGHT", 4));
    }
    final Direction dir = getDirection(arg);

    if (dir == Direction.LEFT || dir == Direction.RIGHT) {
      queue = "-";
    }

    Link link = new Link(cl1, cl2, linkType, arg.get("END", 0), queue.length());

    if (dir == Direction.LEFT || dir == Direction.UP) {
      link = link.getInv();
    }

    getSystem().addLink(link);
    return CommandExecutionResult.ok();
  }
Example #11
0
  public EntityImageBlock(
      IEntity entity, Rose rose, ISkinParam param, Collection<Link> links, FontParam titleParam) {
    this.entity = entity;
    this.param = param;
    this.rose = rose;
    this.links = links;

    if (StringUtils.isNotEmpty(entity.getDisplay2())) {
      this.name =
          TextBlockUtils.create(
              entity.getDisplay2(),
              new FontConfiguration(param.getFont(titleParam, null), HtmlColor.BLACK),
              HorizontalAlignement.CENTER,
              param);
    } else {
      this.name = null;
    }
  }
 public EntityImageDefault(IEntity entity) {
   super(entity);
   this.textBlock =
       entity
           .getDisplay()
           .create(
               new FontConfiguration(getFont14(), HtmlColorUtils.BLACK, HtmlColorUtils.BLUE, true),
               HorizontalAlignment.CENTER,
               new SpriteContainerEmpty());
 }
Example #13
0
 @Override
 protected CommandExecutionResult executeArg(List<String> arg) {
   final String code = arg.get(2);
   final String display = arg.get(1);
   final String stereotype = arg.get(3);
   if (getSystem().leafExist(code)) {
     return CommandExecutionResult.error("Object already exists : " + code);
   }
   final IEntity entity =
       getSystem().createLeaf(code, StringUtils.getWithNewlines(display), LeafType.OBJECT);
   if (stereotype != null) {
     entity.setStereotype(
         new Stereotype(
             stereotype,
             getSystem().getSkinParam().getCircledCharacterRadius(),
             getSystem().getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null)));
   }
   return CommandExecutionResult.ok();
 }
Example #14
0
 public EntityImageDefault(IEntity entity) {
   super(entity);
   this.textBlock =
       entity
           .getDisplay()
           .create(
               FontConfiguration.blackBlueTrue(getFont14()),
               HorizontalAlignment.CENTER,
               new SpriteContainerEmpty());
 }
 public ConditionalContext2(
     ConditionalContext2 parent, IEntity branch, Direction direction, String when) {
   if (branch.getEntityType() != EntityType.BRANCH) {
     throw new IllegalArgumentException();
   }
   this.branch = branch;
   this.direction = direction;
   this.parent = parent;
   this.when = when;
   this.pendings.add(branch);
 }
  public final CommandExecutionResult execute(List<String> lines) {

    final List<String> line0 = StringUtils.getSplit(getStartingPattern(), lines.get(0).trim());
    final String pos = line0.get(0);

    final IEntity activity = getSystem().getLastEntityConsulted();
    if (activity == null) {
      // activity = getSystem().getStart();
      return CommandExecutionResult.error("No activity defined");
    }

    final List<String> strings = StringUtils.removeEmptyColumns(lines.subList(1, lines.size() - 1));
    //		final String s = StringUtils.getMergedLines(strings);

    final IEntity note =
        getSystem().createLeaf(UniqueSequence.getCode("GMN"), strings, LeafType.NOTE);
    note.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(line0.get(1)));

    final Link link;

    final Position position =
        Position.valueOf(pos.toUpperCase()).withRankdir(getSystem().getRankdir());

    final LinkType type = new LinkType(LinkDecor.NONE, LinkDecor.NONE).getDashed();

    if (position == Position.RIGHT) {
      link = new Link(activity, note, type, null, 1);
    } else if (position == Position.LEFT) {
      link = new Link(note, activity, type, null, 1);
    } else if (position == Position.BOTTOM) {
      link = new Link(activity, note, type, null, 2);
    } else if (position == Position.TOP) {
      link = new Link(note, activity, type, null, 2);
    } else {
      throw new IllegalArgumentException();
    }
    getSystem().addLink(link);
    return CommandExecutionResult.ok();
  }
  private Element createEntityNode(IEntity entity) {
    // <UML:Class xmi.id="UMLClass.5" name="Class1" visibility="public"
    // isSpecification="false"
    // namespace="UMLModel.4" isRoot="false" isLeaf="false"
    // isAbstract="false" participant="UMLAssociationEnd.11"
    // isActive="false">
    final Element cla = document.createElement("UML:Class");

    cla.setAttribute("xmi.id", entity.getUid());
    cla.setAttribute("name", entity.getDisplay2().get(0).toString());
    cla.setAttribute("namespace", "model1");

    final Element feature = document.createElement("UML:Classifier.feature");
    cla.appendChild(feature);

    for (Member m : entity.getFieldsToDisplay()) {
      // <UML:Attribute xmi.id="UMLAttribute.6" name="Attribute1"
      // visibility="public" isSpecification="false"
      // ownerScope="instance" changeability="changeable"
      // targetScope="instance" type="" owner="UMLClass.5"/>
      final Element attribute = document.createElement("UML:Attribute");
      attribute.setAttribute("xmi.id", "att" + UniqueSequence.getValue());
      attribute.setAttribute("name", m.getDisplayWithoutVisibilityChar());
      feature.appendChild(attribute);
    }

    for (Member m : entity.getMethodsToDisplay()) {
      // <UML:Operation xmi.id="UMLOperation.7" name="Operation1"
      // visibility="public" isSpecification="false"
      // ownerScope="instance" isQuery="false" concurrency="sequential"
      // isRoot="false" isLeaf="false"
      // isAbstract="false" specification="" owner="UMLClass.5"/>
      final Element operation = document.createElement("UML:Operation");
      operation.setAttribute("xmi.id", "att" + UniqueSequence.getValue());
      operation.setAttribute("name", m.getDisplayWithoutVisibilityChar());
      feature.appendChild(operation);
    }
    return cla;
  }
  @Override
  protected CommandExecutionResult executeArg(Map<String, RegexPartialMatch> arg2) {
    final IEntity entity1 = getEntity(getSystem(), arg2, true);
    if (entity1 == null) {
      return CommandExecutionResult.error("No such activity");
    }
    if (arg2.get("STEREOTYPE").get(0) != null) {
      entity1.setStereotype(new Stereotype(arg2.get("STEREOTYPE").get(0)));
    }
    if (arg2.get("BACKCOLOR").get(0) != null) {
      entity1.setSpecificBackcolor(arg2.get("BACKCOLOR").get(0));
    }

    final IEntity entity2 = getEntity(getSystem(), arg2, false);
    if (entity2 == null) {
      return CommandExecutionResult.error("No such activity");
    }
    if (arg2.get("BACKCOLOR2").get(0) != null) {
      entity2.setSpecificBackcolor(arg2.get("BACKCOLOR2").get(0));
    }
    if (arg2.get("STEREOTYPE2").get(0) != null) {
      entity2.setStereotype(new Stereotype(arg2.get("STEREOTYPE2").get(0)));
    }

    final String linkLabel = arg2.get("BRACKET").get(0);

    final String arrow = StringUtils.manageArrowForCuca(arg2.get("ARROW").get(0));
    final int lenght = arrow.length() - 1;

    Link link =
        new Link(
            entity1, entity2, new LinkType(LinkDecor.ARROW, LinkDecor.NONE), linkLabel, lenght);
    final Direction direction = StringUtils.getArrowDirection(arg2.get("ARROW").get(0));
    if (direction == Direction.LEFT || direction == Direction.UP) {
      link = link.getInv();
    }

    getSystem().addLink(link);

    return CommandExecutionResult.ok();
  }
  @Override
  protected CommandExecutionResult executeArg(RegexResult arg) {

    final Code ent1 = Code.of(arg.get("ENT1", 1));
    final Code ent2 = Code.of(arg.get("ENT2", 1));

    final IEntity cl1;
    final IEntity cl2;
    final IEntity normalEntity;

    final String suffix = "lol" + UniqueSequence.getValue();
    if (arg.get("LOL_THEN_ENT", 0) == null) {
      assert arg.get("ENT_THEN_LOL", 0) != null;
      cl1 = getSystem().getOrCreateClass(ent1);
      cl2 =
          getSystem()
              .createLeaf(
                  cl1.getCode().addSuffix(suffix),
                  StringUtils.getWithNewlines(ent2),
                  LeafType.LOLLIPOP);
      normalEntity = cl1;
    } else {
      cl2 = getSystem().getOrCreateClass(ent2);
      cl1 =
          getSystem()
              .createLeaf(
                  cl2.getCode().addSuffix(suffix),
                  StringUtils.getWithNewlines(ent1),
                  LeafType.LOLLIPOP);
      normalEntity = cl2;
    }

    final LinkType linkType = getLinkType(arg);
    final String queue = getQueue(arg);

    int length = queue.length();
    if (length == 1 && getSystem().getNbOfHozizontalLollipop(normalEntity) > 1) {
      length++;
    }

    String firstLabel = arg.get("FIRST_LABEL", 0);
    String secondLabel = arg.get("SECOND_LABEL", 0);

    String labelLink = null;

    if (arg.get("LABEL_LINK", 0) != null) {
      labelLink = arg.get("LABEL_LINK", 0);
      if (firstLabel == null && secondLabel == null) {
        final Pattern p1 = Pattern.compile("^\"([^\"]+)\"([^\"]+)\"([^\"]+)\"$");
        final Matcher m1 = p1.matcher(labelLink);
        if (m1.matches()) {
          firstLabel = m1.group(1);
          labelLink =
              StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m1.group(2).trim()).trim();
          secondLabel = m1.group(3);
        } else {
          final Pattern p2 = Pattern.compile("^\"([^\"]+)\"([^\"]+)$");
          final Matcher m2 = p2.matcher(labelLink);
          if (m2.matches()) {
            firstLabel = m2.group(1);
            labelLink =
                StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m2.group(2).trim()).trim();
            secondLabel = null;
          } else {
            final Pattern p3 = Pattern.compile("^([^\"]+)\"([^\"]+)\"$");
            final Matcher m3 = p3.matcher(labelLink);
            if (m3.matches()) {
              firstLabel = null;
              labelLink =
                  StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m3.group(1).trim())
                      .trim();
              secondLabel = m3.group(2);
            }
          }
        }
      }
      labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(labelLink);
    } /*
       * else if (arg.get("LABEL_LINK_XT").get(0) != null ||
       * arg.get("LABEL_LINK_XT").get(1) != null ||
       * arg.get("LABEL_LINK_XT").get(2) != null) { labelLink =
       * arg.get("LABEL_LINK_XT").get(1); firstLabel = merge(firstLabel,
       * arg.get("LABEL_LINK_XT").get(0)); secondLabel =
       * merge(arg.get("LABEL_LINK_XT").get(2), secondLabel); }
       */

    final Link link =
        new Link(
            cl1,
            cl2,
            linkType,
            labelLink,
            length,
            firstLabel,
            secondLabel,
            getSystem().getLabeldistance(),
            getSystem().getLabelangle());
    getSystem().resetPragmaLabel();
    addLink(link, arg.get("HEADER", 0));

    return CommandExecutionResult.ok();
  }
  public CommandExecutionResult execute(List<String> lines) {
    StringUtils.trim(lines, false);
    final RegexResult line0 = getStartingPattern().matcher(lines.get(0).trim());

    final IEntity entity1 = CommandLinkActivity.getEntity(getSystem(), line0, true);

    if (line0.get("STEREOTYPE", 0) != null) {
      entity1.setStereotype(new Stereotype(line0.get("STEREOTYPE", 0)));
    }
    if (line0.get("BACKCOLOR", 0) != null) {
      entity1.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(line0.get("BACKCOLOR", 0)));
    }
    final StringBuilder sb = new StringBuilder();

    final String desc0 = line0.get("DESC", 0);
    Url urlActivity = null;
    if (StringUtils.isNotEmpty(desc0)) {
      final UrlBuilder urlBuilder =
          new UrlBuilder(getSystem().getSkinParam().getValue("topurl"), true);
      urlActivity = urlBuilder.getUrl(desc0);
      if (urlActivity == null) {
        sb.append(desc0);
        sb.append("\\n");
      }
    }
    for (int i = 1; i < lines.size() - 1; i++) {
      if (i == 1 && urlActivity == null) {
        final UrlBuilder urlBuilder =
            new UrlBuilder(getSystem().getSkinParam().getValue("topurl"), true);
        urlActivity = urlBuilder.getUrl(lines.get(i));
        if (urlActivity != null) {
          continue;
        }
      }
      sb.append(lines.get(i));
      if (i < lines.size() - 2) {
        sb.append("\\n");
      }
    }

    final List<String> lineLast =
        StringUtils.getSplit(Pattern.compile(getPatternEnd()), lines.get(lines.size() - 1));
    if (StringUtils.isNotEmpty(lineLast.get(0))) {
      if (sb.length() > 0 && sb.toString().endsWith("\\n") == false) {
        sb.append("\\n");
      }
      sb.append(lineLast.get(0));
    }

    final String display = sb.toString();
    final Code code = Code.of(lineLast.get(1) == null ? display : lineLast.get(1));

    String partition = null;
    if (lineLast.get(3) != null) {
      partition = lineLast.get(3);
      partition = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(partition);
    }
    if (partition != null) {
      getSystem()
          .getOrCreateGroup(
              Code.of(partition),
              StringUtils.getWithNewlines(partition),
              null,
              GroupType.PACKAGE,
              null);
    }
    final IEntity entity2 =
        getSystem().createLeaf(code, StringUtils.getWithNewlines(display), LeafType.ACTIVITY);
    if (partition != null) {
      getSystem().endGroup();
    }
    if (urlActivity != null) {
      entity2.addUrl(urlActivity);
    }

    if (lineLast.get(2) != null) {
      entity2.setStereotype(new Stereotype(lineLast.get(2)));
    }
    if (lineLast.get(4) != null) {
      entity2.setSpecificBackcolor(HtmlColorUtils.getColorIfValid(lineLast.get(4)));
    }

    if (entity1 == null || entity2 == null) {
      return CommandExecutionResult.error("No such entity");
    }

    final String arrow = StringUtils.manageArrowForCuca(line0.get("ARROW", 0));
    final int lenght = arrow.length() - 1;

    final String linkLabel = line0.get("BRACKET", 0);

    LinkType type = new LinkType(LinkDecor.ARROW, LinkDecor.NONE);
    if (line0.get("ARROW", 0).contains(".")) {
      type = type.getDotted();
    }
    Link link = new Link(entity1, entity2, type, linkLabel, lenght);
    final Direction direction = StringUtils.getArrowDirection(line0.get("ARROW", 0));
    if (direction == Direction.LEFT || direction == Direction.UP) {
      link = link.getInv();
    }

    if (line0.get("URL", 0) != null) {
      final UrlBuilder urlBuilder =
          new UrlBuilder(getSystem().getSkinParam().getValue("topurl"), true);
      final Url urlLink = urlBuilder.getUrl(line0.get("URL", 0));
      link.setUrl(urlLink);
    }

    getSystem().addLink(link);

    return CommandExecutionResult.ok();
  }
  @Override
  protected CommandExecutionResult executeArg(
      AbstractClassOrObjectDiagram diagram, RegexResult arg) {
    Code ent1 = Code.of(arg.get("ENT1", 1));
    Code ent2 = Code.of(arg.get("ENT2", 1));
    if (ent1 == null) {
      return executeArgSpecial1(diagram, arg);
    }
    if (ent2 == null) {
      return executeArgSpecial2(diagram, arg);
    }
    ent1 = ent1.eventuallyRemoveStartingAndEndingDoubleQuote();
    ent2 = ent2.eventuallyRemoveStartingAndEndingDoubleQuote();
    if (diagram.isGroup(ent1) && diagram.isGroup(ent2)) {
      return executePackageLink(diagram, arg);
    }

    final IEntity cl1 =
        diagram.isGroup(ent1)
            ? diagram.getGroup(
                Code.of(
                    StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT1", 1))))
            : diagram.getOrCreateLeaf(ent1, null, null);
    final IEntity cl2 =
        diagram.isGroup(ent2)
            ? diagram.getGroup(
                Code.of(
                    StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(arg.get("ENT2", 1))))
            : diagram.getOrCreateLeaf(ent2, null, null);

    if (arg.get("ENT1", 0) != null) {
      final LeafType type = LeafType.getLeafType(arg.get("ENT1", 0));
      if (type != LeafType.OBJECT) {
        ((ILeaf) cl1).muteToType(type, null);
      }
    }
    if (arg.get("ENT2", 0) != null) {
      final LeafType type = LeafType.getLeafType(arg.get("ENT2", 0));
      if (type != LeafType.OBJECT) {
        ((ILeaf) cl2).muteToType(type, null);
      }
    }
    if (arg.get("ENT1", 2) != null) {
      cl1.setStereotype(
          new Stereotype(
              arg.get("ENT1", 2),
              diagram.getSkinParam().getCircledCharacterRadius(),
              diagram.getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null)));
    }
    if (arg.get("ENT2", 2) != null) {
      cl2.setStereotype(
          new Stereotype(
              arg.get("ENT2", 2),
              diagram.getSkinParam().getCircledCharacterRadius(),
              diagram.getSkinParam().getFont(FontParam.CIRCLED_CHARACTER, null)));
    }

    final LinkType linkType = getLinkType(arg);
    final Direction dir = getDirection(arg);
    final int queue;
    if (dir == Direction.LEFT || dir == Direction.RIGHT) {
      queue = 1;
    } else {
      queue = getQueueLength(arg);
    }

    String firstLabel = arg.get("FIRST_LABEL", 0);
    String secondLabel = arg.get("SECOND_LABEL", 0);

    String labelLink = null;

    if (arg.get("LABEL_LINK", 0) != null) {
      labelLink = arg.get("LABEL_LINK", 0);
      if (firstLabel == null && secondLabel == null) {
        final Pattern p1 = MyPattern.cmpile("^[%g]([^%g]+)[%g]([^%g]+)[%g]([^%g]+)[%g]$");
        final Matcher m1 = p1.matcher(labelLink);
        if (m1.matches()) {
          firstLabel = m1.group(1);
          labelLink =
              StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m1.group(2).trim()).trim();
          secondLabel = m1.group(3);
        } else {
          final Pattern p2 = MyPattern.cmpile("^[%g]([^%g]+)[%g]([^%g]+)$");
          final Matcher m2 = p2.matcher(labelLink);
          if (m2.matches()) {
            firstLabel = m2.group(1);
            labelLink =
                StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m2.group(2).trim()).trim();
            secondLabel = null;
          } else {
            final Pattern p3 = MyPattern.cmpile("^([^%g]+)[%g]([^%g]+)[%g]$");
            final Matcher m3 = p3.matcher(labelLink);
            if (m3.matches()) {
              firstLabel = null;
              labelLink =
                  StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(m3.group(1).trim())
                      .trim();
              secondLabel = m3.group(2);
            }
          }
        }
      }
      labelLink = StringUtils.eventuallyRemoveStartingAndEndingDoubleQuote(labelLink);
    }

    LinkArrow linkArrow = LinkArrow.NONE;
    if ("<".equals(labelLink)) {
      linkArrow = LinkArrow.BACKWARD;
      labelLink = null;
    } else if (">".equals(labelLink)) {
      linkArrow = LinkArrow.DIRECT_NORMAL;
      labelLink = null;
    } else if (labelLink != null && labelLink.startsWith("< ")) {
      linkArrow = LinkArrow.BACKWARD;
      labelLink = labelLink.substring(2).trim();
    } else if (labelLink != null && labelLink.startsWith("> ")) {
      linkArrow = LinkArrow.DIRECT_NORMAL;
      labelLink = labelLink.substring(2).trim();
    } else if (labelLink != null && labelLink.endsWith(" >")) {
      linkArrow = LinkArrow.DIRECT_NORMAL;
      labelLink = labelLink.substring(0, labelLink.length() - 2).trim();
    } else if (labelLink != null && labelLink.endsWith(" <")) {
      linkArrow = LinkArrow.BACKWARD;
      labelLink = labelLink.substring(0, labelLink.length() - 2).trim();
    }

    Link link =
        new Link(
            cl1,
            cl2,
            linkType,
            Display.getWithNewlines(labelLink),
            queue,
            firstLabel,
            secondLabel,
            diagram.getLabeldistance(),
            diagram.getLabelangle());

    if (dir == Direction.LEFT || dir == Direction.UP) {
      link = link.getInv();
    }
    link.setLinkArrow(linkArrow);
    applyStyle(arg.getLazzy("ARROW_STYLE", 0), link);

    addLink(diagram, link, arg.get("HEADER", 0));

    return CommandExecutionResult.ok();
  }
Example #22
0
 protected final Stereotype getStereo() {
   return entity.getStereotype();
 }
 private Element createEntityNodeRef(IEntity entity) {
   final Element cla = document.createElement("UML:Class");
   cla.setAttribute("xmi.idref", entity.getUid());
   return cla;
 }
Example #24
0
  @Override
  protected CommandExecutionResult executeArg(StateDiagram diagram, RegexResult arg) {
    final String ent1 = arg.get("ENT1", 0);
    final String ent2 = arg.get("ENT2", 0);

    final IEntity cl1 = getEntityStart(diagram, ent1);
    if (cl1 == null) {
      return CommandExecutionResult.error(
          "The state "
              + ent1
              + " has been created in a concurrent state : it cannot be used here.");
    }
    final IEntity cl2 = getEntityEnd(diagram, ent2);
    if (cl2 == null) {
      return CommandExecutionResult.error(
          "The state "
              + ent2
              + " has been created in a concurrent state : it cannot be used here.");
    }

    if (arg.get("ENT1", 1) != null) {
      cl1.setStereotype(new Stereotype(arg.get("ENT1", 1)));
    }
    if (arg.get("ENT1", 2) != null) {
      cl1.setSpecificColorTOBEREMOVED(
          ColorType.BACK,
          diagram.getSkinParam().getIHtmlColorSet().getColorIfValid(arg.get("ENT1", 2)));
    }
    if (arg.get("ENT2", 1) != null) {
      cl2.setStereotype(new Stereotype(arg.get("ENT2", 1)));
    }
    if (arg.get("ENT2", 2) != null) {
      cl2.setSpecificColorTOBEREMOVED(
          ColorType.BACK,
          diagram.getSkinParam().getIHtmlColorSet().getColorIfValid(arg.get("ENT2", 2)));
    }

    String queue = arg.get("ARROW_BODY1", 0) + arg.get("ARROW_BODY2", 0);
    final Direction dir = getDirection(arg);

    if (dir == Direction.LEFT || dir == Direction.RIGHT) {
      queue = "-";
    }

    final int lenght = queue.length();

    final boolean crossStart = arg.get("ARROW_CROSS_START", 0) != null;
    final boolean circleEnd = arg.get("ARROW_CIRCLE_END", 0) != null;
    final LinkType linkType =
        new LinkType(
            circleEnd ? LinkDecor.ARROW_AND_CIRCLE : LinkDecor.ARROW,
            crossStart ? LinkDecor.CIRCLE_CROSS : LinkDecor.NONE);

    Link link = new Link(cl1, cl2, linkType, Display.getWithNewlines(arg.get("LABEL", 0)), lenght);
    if (dir == Direction.LEFT || dir == Direction.UP) {
      link = link.getInv();
    }
    CommandLinkClass.applyStyle(arg.getLazzy("ARROW_STYLE", 0), link);
    diagram.addLink(link);

    return CommandExecutionResult.ok();
  }