Example #1
0
  private String getDescr(Fig f) {
    if (f == null) {
      return null;
    }
    String className = f.getClass().getName();
    StringBuffer descr = new StringBuffer(className.substring(className.lastIndexOf(".") + 1));
    //        descr.append(" - paints=").append(f.getPaintCount());
    //        descr.append(" - damages=").append(f.getDamageCount());
    descr.append(
        " - bounds=[" + f.getX() + "," + f.getY() + "," + f.getWidth() + "," + f.getHeight() + "]");
    if (!f.isVisible()) {
      descr.append(" - INVISIBLE");
    }
    if (f.isFilled()) {
      descr.append(" - FILLED");
    }
    descr.append(
        " - fill=["
            + f.getFillColor().getRed()
            + ","
            + f.getFillColor().getGreen()
            + ","
            + f.getFillColor().getBlue()
            + "]");
    if (f.getOwner() != null) {
      descr.append(" - owner=").append(f.getOwner());
    }
    if (f instanceof FigText) {
      descr.append(" \"").append(((FigText) f).getText()).append("\"");
    }

    descr.append(" - lay=").append(toString(f.getLayer()));
    descr.append(" - grp=").append(toString(f.getGroup()));
    return descr.toString();
  }
  /**
   * The minimum width is the minimum width of the child with the widest miniumum width. The minimum
   * height is the total minimum height of all child figs plus a 2 pixel padding.
   *
   * @return the minimum width
   */
  @Override
  public Dimension getMinimumSize() {
    int minWidth = 0;
    int minHeight = 0;
    for (Fig fig : (Collection<Fig>) getFigs()) {
      if (fig.isVisible() && fig != getBigPort()) {
        int fw = fig.getMinimumSize().width;
        if (fw > minWidth) {
          minWidth = fw;
        }
        minHeight += fig.getMinimumSize().height;
      }
    }

    minHeight += 2; // 2 Pixel padding after compartment
    return new Dimension(minWidth, minHeight);
  }
  /*
   * @see org.tigris.gef.presentation.Fig#setBoundsImpl(int, int, int, int)
   */
  @Override
  protected void setBoundsImpl(int x, int y, int w, int h) {
    int newW = w;
    int newH = h;

    int fw;
    int yy = y;
    for (Fig fig : (Collection<Fig>) getFigs()) {
      if (fig.isVisible() && fig != getBigPort()) {
        fw = fig.getMinimumSize().width;
        // set new bounds for all included figs
        fig.setBounds(x + 1, yy + 1, fw, fig.getMinimumSize().height);
        if (newW < fw + 2) {
          newW = fw + 2;
        }
        yy += fig.getMinimumSize().height;
      }
    }
    getBigPort().setBounds(x, y, newW, newH);
    calcBounds();
  }
Example #4
0
  /**
   * On mouse release add the elements to the diagram
   *
   * @param me the mouse event
   */
  @Override
  public void mouseReleased(final MouseEvent me) {
    if (me.isConsumed()) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("MouseReleased but rejected as already consumed");
      }
      return;
    }
    // TODO: Use per-project undo manager, not global
    UndoManager.getInstance().addMementoLock(this);
    start();
    MutableGraphModel gm = (MutableGraphModel) editor.getGraphModel();

    final int x = me.getX();
    final int y = me.getY();
    editor.damageAll();
    final Point snapPt = new Point(x, y);
    editor.snap(snapPt);
    editor.damageAll();
    int count = 0;

    Layer lay = editor.getLayerManager().getActiveLayer();
    GraphNodeRenderer renderer = editor.getGraphNodeRenderer();

    final List<FigNode> placedFigs = new ArrayList<FigNode>(modelElements.size());

    ArgoDiagram diag = DiagramUtils.getActiveDiagram();
    if (diag instanceof UMLDiagram) {
      for (final Object node : modelElements) {
        if (((UMLDiagram) diag).doesAccept(node)) {
          final FigNode pers = renderer.getFigNodeFor(gm, lay, node, null);
          pers.setLocation(snapPt.x + (count++ * 100), snapPt.y);
          if (LOG.isDebugEnabled()) {
            LOG.debug("mouseMoved: Location set (" + pers.getX() + "," + pers.getY() + ")");
          }
          // TODO: Use per-project undo manager, not global
          UndoManager.getInstance().startChain();
          editor.add(pers);
          gm.addNode(node);
          if (addRelatedEdges) {
            gm.addNodeRelatedEdges(node);
          }

          Fig encloser = null;
          final Rectangle bbox = pers.getBounds();
          final List<Fig> otherFigs = lay.getContents();
          for (final Fig otherFig : otherFigs) {
            if (!(otherFig.getUseTrapRect())) {
              continue;
            }
            if (!(otherFig instanceof FigNode)) {
              continue;
            }
            if (!otherFig.isVisible()) {
              continue;
            }
            if (otherFig.equals(pers)) {
              continue;
            }
            final Rectangle trap = otherFig.getTrapRect();
            if (trap != null
                && trap.contains(bbox.x, bbox.y)
                && trap.contains(bbox.x + bbox.width, bbox.y + bbox.height)) {
              encloser = otherFig;
            }
          }
          pers.setEnclosingFig(encloser);

          placedFigs.add(pers);
        }
      }
    }

    // TODO: Use per-project undo manager, not global
    UndoManager.getInstance().removeMementoLock(this);
    if (UndoManager.getInstance().isGenerateMementos()) {
      AddToDiagramMemento memento = new AddToDiagramMemento(editor, placedFigs);
      UndoManager.getInstance().addMemento(memento);
    }
    UndoManager.getInstance().addMementoLock(this);
    editor.getSelectionManager().select(placedFigs);

    done();
    me.consume();
  }