Package org.kite9.diagram.primitives

Examples of org.kite9.diagram.primitives.DiagramElement


   */
  public static Container getContainerFor(Object o, Relationship rel, InsertionInterface ii) {
    if (o == null)
      return null;

    DiagramElement within = ii.returnExisting(o);
    if (within == null) {
      // no context to place the element in, so put in the
      // diagram.
      return null;
    }
View Full Code Here


    for (Step s : provider.getSteps()) {
      System.out.println(s);
      if (s instanceof CallStep) {
        CallStep cs = (CallStep) s;
        DiagramElement from = elementStack.size() == 0 ? null : elementStack.peek();
        DiagramElement to = buildGlyph(c, cs.getTo(), cs.getToGroup(), stateMap, elementStack);

        if (from != null) {
          createLink(s, from, to, null);
        }
        elementStack.push(to);
      } else if (s instanceof ReturnStep) {
        DiagramElement from = elementStack.pop();
        if (((ReturnStep) s).isShow()) {
          DiagramElement to = elementStack.peek();
          createLink(s, from, to, null);
        }
      }
    }
  }
View Full Code Here

    super(ii, nf, a);
  }

  private DiagramElement buildGlyph(Container c, SimpleNoun from, SimpleNoun fromGroup,
      Map<Object, DiagramElement> stateMap, Stack<DiagramElement> elementStack) {
    DiagramElement existing = stateMap.get(from);
    if (existing != null) {
      return existing;
    }

    Container container = c;
    if (fromGroup != null) {
      container = (Container) stateMap.get(fromGroup);
      if (container == null) {
        container = (Container) ii.returnContext(c, fromGroup, new TextLine(fromGroup.getLabel()), true, null);
        stateMap.put(fromGroup, container);
      }
    }

    if (existing == null) {
      DiagramElement out = ii.returnGlyph(container, from, from.getLabel(), from.getStereotype());
      existing = out;
    }
   
    return existing;
  }
View Full Code Here

   
    return existing;
  }

  protected void createLink(Step s, DiagramElement from, DiagramElement to, Direction d) {
    DiagramElement out = ii.returnConnection(from, to, s, null, null, true, d);
    System.out.println("Link from " + from + " to " + to + " in " + d);

    if (out instanceof Link) {
      Link l = (Link) out;
      Label fromLabel = buildFromLabel(s, l.getFromLabel());
View Full Code Here

    for (Step s : provider.getSteps()) {
      System.out.println(s);
      if (s instanceof CallStep) {
        CallStep cs = (CallStep) s;
        DiagramElement fromg = elementStack.size()==0 ? null : elementStack.peek();
        DiagramElement from = fromg == null ? null : getExtensionElement(((Contained)fromg).getContainer(), fromg, lastArrows, lengths, true);
        DiagramElement tog = buildGlyph(c, cs.getTo(), cs.getToGroup(), stateMap, headerGlyphs, rootElements, elementStack, elementDepth);
       
        if (from != null) {
          DiagramElement to  = getExtensionElement(((Contained)tog).getContainer(), tog, lastArrows, lengths, false);
          Direction d = getDirectionFor(getArrowDirection());
          boolean fromBefore = isFromBefore2(rootElements, elementDepth, fromg, tog);
          if (!fromBefore) {
            d = Direction.reverse(d);
          }
          createLink(s, from, to, d);
        }
        elementStack.push(tog);
      } else if (s instanceof ReturnStep) {
        DiagramElement fromg = elementStack.pop();
        if (((ReturnStep)s).isShow()) {
          DiagramElement from = getExtensionElement(((Contained)fromg).getContainer(), fromg, lastArrows, lengths, true);
          DiagramElement tog = elementStack.peek();
          DiagramElement to  = getExtensionElement(((Contained)tog).getContainer(), tog, lastArrows, lengths, false);
          Direction d = getDirectionFor(getArrowDirection());
         
          boolean fromBefore = isFromBefore2(rootElements, elementDepth, fromg, tog);
          if (!fromBefore) {
            d = Direction.reverse(d);
View Full Code Here

    }
  }

  private boolean isFromBefore2(Map<DiagramElement, DiagramElement> rootElements, Map<DiagramElement, Integer> elementDepth, DiagramElement fromg,
      DiagramElement tog) {
    DiagramElement fromr = rootElements.get(fromg);
    DiagramElement tor = rootElements.get(tog);
    if (fromr==tor) {
      // sub-call
      Integer fromd = elementDepth.get(fromg);
      fromd = fromd == null ? 0 : fromd;
      Integer tod = elementDepth.get(tog);
View Full Code Here

  private DiagramElement getExtensionElement(Container c, DiagramElement glyph,
      Map<DiagramElement, DiagramElement> lastArrows,
      Map<DiagramElement, Integer> lengths, boolean active) {

    DiagramElement existing = lastArrows.get(glyph) == null ? glyph : lastArrows.get(glyph);
    if ((existing instanceof Arrow) && (((Arrow)existing).getLinks().size()==0)) {
      // this one will do anyway
      return existing;
    }
    int newLength = lengths.get(glyph) == null ? 0 : lengths.get(glyph);

    DiagramElement extension = ii.returnConnectionBody(c, new ProjectStaticSimpleNoun(((IdentifiableDiagramElement)glyph).getID()+newLength, a), "");
    lengths.put(glyph, newLength + 1);
    lastArrows.put(glyph, extension);
    DiagramElement de = ii.returnConnection(existing, extension, null, null, null, false, getDirectionFor(getGlyphLayout()));

    if ((!active) && (de instanceof Link)) {
      ((Link)de).setShapeName(LinkLineStyle.DOTTED);
    }
   
View Full Code Here

   
    return extension;
  }

  private DiagramElement buildGlyph(Container c, SimpleNoun from, SimpleNoun fromGroup, Map<Object, DiagramElement> stateMap, Set<DiagramElement> headerGlyphs, Map<DiagramElement, DiagramElement> rootElements, Stack<DiagramElement> elementStack, Map<DiagramElement, Integer> elementDepth) {
    DiagramElement existing = stateMap.get(from);
    Container container = (Container) stateMap.get(fromGroup);
   
    if (container==null) {
      DiagramElement de = ii.returnContext(c, fromGroup, new TextLine(fromGroup.getLabel()), true, null);
      if (!(de instanceof Context)) {
        throw new Kite9ProcessingException(fromGroup + " already exists in the diagram as a " + de.getClass()
            + " (Context needed)");
      }
      stateMap.put(fromGroup, de);
      container = (Container) de;
    }

    if (existing != null) {
      if (elementStack.contains(existing)) {
        // need to create an arrow, as this is a
        // second/nth call
        DiagramElement out = ii.returnConnectionBody(container, new ProjectStaticSimpleNoun(from.getRepresented()+" SL="+elementStack.size(), a), "");

        // ensure ordering makes some kind of sense
        rootElements.put(out, existing);
        elementDepth.put(out, elementStack.size());   
        return out;
      } else {
        return existing;
      }
    } else {
      DiagramElement out = ii.returnGlyph(container, from, from.getLabel(), from.getStereotype());
      stateMap.put(from, out);
      headerGlyphs.add(out);
      rootElements.put(out, out);
      return out;
    }
View Full Code Here

      return out;
    }
  }

  protected void createLink(Step s, DiagramElement from, DiagramElement to, Direction d) {
    DiagramElement out = ii.returnConnection(from, to, s, null, null, true, d);
    System.out.println("Link from " + from + " to " + to + " in " + d);
   
    if (out instanceof Link) {
      Link l = (Link) out;
      Label fromLabel = buildFromLabel(s, l.getFromLabel());
View Full Code Here

      }

      public DiagramElement returnConnection(DiagramElement from,
          DiagramElement to, Object representing, Label fromLabel,
          Label toLabel, boolean arrowHead, Direction d) {
        DiagramElement out = representing == null ? null : contents
            .get(representing);

        if (out == null) {
          if ((from instanceof Connected)
              && (to instanceof Connected)) {
            Connected cfrom = (Connected) from;
            Connected cto = (Connected) to;
            out = new Link(cfrom, cto, null, fromLabel,
                arrowHead ? LinkEndStyle.ARROW : null, toLabel,
                d);
          } else {
            throw new Kite9ProcessingException(
                "Could not link between: " + from + " and "
                    + to);
          }
        }

        contents.put(representing, out);
        return out;
      }

      /**
       * Looks for an existing diagram element, or returns a new glyph
       */
      public DiagramElement returnGlyph(Container within,
          Object representing, String label, String stereo) {
        DiagramElement out = representing == null ? null : contents
            .get(representing);
        if (out == null) {
          within = within == null ? getDiagram() : within;
          String id = idHelper.getId(representing);
          out = new Glyph(id, stereo, label, null, null);
          contents.put(representing, out);
          within.getContents().add((Glyph) out);
          ((Glyph) out).setContainer(within);
        }
        return out;
      }

      public DiagramElement returnContext(Container within,
          Object representing, Label overrideLabel, boolean border,
          Layout d) {
        DiagramElement out = representing == null ? null : contents
            .get(representing);
        if (out == null) {
          within = within == null ? getDiagram() : within;
          String id = idHelper.getId(representing);
          out = new Context(id, null, border, border ? overrideLabel
              : null, d);
          contents.put(representing, out);
          within.getContents().add((Context) out);
          ((Context) out).setContainer(within);
        }
        return out;
      }

      public DiagramElement returnConnectionBody(Container within,
          Object representing, String label) {
        DiagramElement out = representing == null ? null : contents
            .get(representing);
        if (out == null) {
          within = within == null ? getDiagram() : within;
          String id = idHelper.getId(representing);
          out = new Arrow(id, label);
          contents.put(representing, out);
          within.getContents().add((Arrow) out);
          ((Arrow) out).setContainer(within);
        }
        return out;
      }

      public DiagramElement returnSymbol(DiagramElement container,
          Object representing, String text, String prefs) {
        DiagramElement out = representing == null ? null : contents
            .get(representing);
        if (out == null) {
          out = symbols.get(text);

          if (out == null) {
            Symbol s = kh.createSymbol(text, prefs);
            symbols.put(text, s);
            out = s;
          }

          SymbolTarget st = null;
          if (container instanceof Context) {
            st = (TextLine) ((Context) container).getLabel();
            if (st == null) {
              st = new TextLine();
              ((Context) container).setLabel((TextLine) st);
            }
          } else if (container instanceof SymbolTarget) {
            st = (Glyph) container;
          } else if (container instanceof Link) {
            // add to a label, eventually.
          }

          // add the symbol to the container
          if ((st != null) && (!st.getSymbols().contains(out))) {
            st.getSymbols().add((Symbol) out);
          }
        }

        return out;
      }

      public DiagramElement returnTextLine(Glyph container,
          Object representing, String text) {
        DiagramElement out = representing == null ? null : contents
            .get(representing);
        if (out == null) {
          TextLine tl = new TextLine(text);
          contents.put(representing, tl);
          container.getText().add(tl);
          return tl;
        }
        return out;
      }

      public DiagramElement extendTextLine(TextLine container,
          Object representing, String text) {
        DiagramElement out = representing == null ? null : contents
            .get(representing);
        if (out == null) {
          StyledText st = container.getText();
          container.setText(new StyledText(st.getText() + text, st.getStyle()));
          contents.put(representing, container);
View Full Code Here

TOP

Related Classes of org.kite9.diagram.primitives.DiagramElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.