protected void showChangeBoundsFeedback(ChangeBoundsRequest request) {
    IFigure feedback = getDragSourceFeedbackFigure();

    PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
    getHostFigure().translateToAbsolute(rect);
    rect.translate(request.getMoveDelta());
    rect.resize(request.getSizeDelta());

    IFigure f = getHostFigure();
    Dimension min = f.getMinimumSize().getCopy();
    Dimension max = f.getMaximumSize().getCopy();
    IMapMode mmode = MapModeUtil.getMapMode(f);
    min.height = mmode.LPtoDP(min.height);
    min.width = mmode.LPtoDP(min.width);
    max.height = mmode.LPtoDP(max.height);
    max.width = mmode.LPtoDP(max.width);

    if (min.width > rect.width) rect.width = min.width;
    else if (max.width < rect.width) rect.width = max.width;

    if (min.height > rect.height) rect.height = min.height;
    else if (max.height < rect.height) rect.height = max.height;

    feedback.translateToRelative(rect);
    feedback.setBounds(rect);
  }
Ejemplo n.º 2
0
  private double getFitXZoomLevel(int which) {
    IFigure fig = getScalableFigure();

    Dimension available = getViewport().getClientArea().getSize();
    Dimension desired;
    if (fig instanceof FreeformFigure) {
      desired = ((FreeformFigure) fig).getFreeformExtent().getCopy().union(0, 0).getSize();
    } else {
      desired = fig.getPreferredSize().getCopy();
    }

    desired.width -= fig.getInsets().getWidth();
    desired.height -= fig.getInsets().getHeight();

    while (fig != getViewport()) {
      available.width -= fig.getInsets().getWidth();
      available.height -= fig.getInsets().getHeight();
      fig = fig.getParent();
    }

    double scaleX = Math.min(available.width * zoom / desired.width, getMaxZoom());
    double scaleY = Math.min(available.height * zoom / desired.height, getMaxZoom());
    if (which == 0) {
      return scaleX;
    }
    if (which == 1) {
      return scaleY;
    }
    return Math.min(scaleX, scaleY);
  }
 /**
  * Calculate the best size for this label using the class's width to height ratio. This is done by
  * calculating the area that the text would occupy if it was in only one line, then calculate a
  * new width that would give the same area using the width to height ratio, and finally it sends
  * this width to the {@link FlowPage}'s {@link FlowPage#getPreferredSize(int, int)} method which
  * calculates the real height using line breaks.
  *
  * @return A close match to the size that this figure should have to match the required width to
  *     height ratio.
  */
 public Dimension calculateSize() {
   try {
     Dimension lineDimensions =
         TextUtilities.INSTANCE.getStringExtents(textFlow.getText(), getFont());
     double area = lineDimensions.width() * lineDimensions.height();
     double width = Math.sqrt(area / ratio) * ratio;
     invalidate();
     Dimension pSize = textFlow.getPreferredSize((int) width, -1).getCopy();
     if (pSize.width < OPPFigureConstants.MINIMUM_NODE_SIZE) pSize.width = pSize.height;
     return pSize;
   } catch (Exception e) {
     return new Dimension(0, 0);
   }
 }
  /**
   * Given an absolute point (pStart) and a list of EditParts, this method finds the closest
   * EditPart (except for the one to be excluded) in the given direction.
   *
   * @param siblings List of sibling EditParts
   * @param pStart The starting point (must be in absolute coordinates) from which the next sibling
   *     is to be found.
   * @param direction PositionConstants
   * @param exclude The EditPart to be excluded from the search
   */
  public IGraphicalEntityPart findSibling(
      List<?> siblings, Point pStart, int direction, EditPart exclude) {
    IGraphicalEntityPart epCurrent;
    IGraphicalEntityPart epFinal = null;
    IFigure figure;
    Point pCurrent;
    int distance = Integer.MAX_VALUE;

    Iterator<?> iter = siblings.iterator();
    while (iter.hasNext()) {
      epCurrent = (IGraphicalEntityPart) iter.next();
      if (epCurrent == exclude || !epCurrent.isSelectable()) continue;
      figure = epCurrent.getFigure();
      pCurrent = getNavigationPoint(figure);
      figure.translateToAbsolute(pCurrent);
      if (pStart.getPosition(pCurrent) != direction) continue;

      Dimension difference = pCurrent.getDifference(pStart);
      int d = Math.abs(difference.width()) + Math.abs(difference.height());
      if (d < distance) {
        distance = d;
        epFinal = epCurrent;
      }
    }
    return epFinal;
  }
  /**
   * Used inside the getSizeDeltaToFitAnchors operation. It's goal is to modify a SizeDelta in order
   * to keep fitting an anchor within the figureBounds
   *
   * @param anchor The anchor whose position will be kept
   * @param sizeDelta
   * @param preserveAxis
   * @param figureBounds
   */
  protected static void modifySizeDeltaToFitAnchor(
      IdentityAnchor anchor, Dimension sizeDelta, int preserveAxis, Rectangle figureBounds) {

    if (anchor == null) {
      return;
    }

    PrecisionPoint pp = BaseSlidableAnchor.parseTerminalString(anchor.getId());

    int margin = 6;

    if (preserveAxis == PRESERVE_Y || preserveAxis == PRESERVE_XY) {
      int anchorYPos = (int) Math.round(figureBounds.height * pp.preciseY);

      int newHeight = figureBounds.height + sizeDelta.height;

      if (anchorYPos + margin > newHeight) {
        sizeDelta.height = (anchorYPos - figureBounds.height) + margin;
      }
    }

    if (preserveAxis == PRESERVE_X || preserveAxis == PRESERVE_XY) {
      int anchorXPos = (int) Math.round(figureBounds.width * pp.preciseX);

      int newWidth = figureBounds.width + sizeDelta.width;

      if (anchorXPos + margin > newWidth) {
        sizeDelta.width = (anchorXPos - figureBounds.width) + margin;
      }
    }
  }
  /** {@inheritDoc} */
  @Override
  protected void updateTargetRequest() {

    super.updateTargetRequest();
    Dimension delta = getDragMoveDelta();

    if (getSourceEditPart() instanceof GraphicalEditPart) {
      Rectangle childRect = ((GraphicalEditPart) getSourceEditPart()).getFigure().getBounds();
      if (getSourceEditPart().getParent() instanceof GraphicalEditPart) {
        Rectangle parentRect =
            ((GraphicalEditPart) getSourceEditPart().getParent()).getFigure().getBounds();
        IFigure fig = ((GraphicalEditPart) getSourceEditPart().getParent()).getFigure();

        IFigure contentPane =
            ((GraphicalEditPart) getSourceEditPart().getParent()).getContentPane();

        // calculate the virtual position
        Rectangle virtualPosition = childRect.getCopy();
        virtualPosition.x = virtualPosition.x + delta.width;
        virtualPosition.y = virtualPosition.y + delta.height;

        if (virtualPosition.x < 0) {
          delta.width = 0 - childRect.x;
        }
        if (virtualPosition.y < 0) {
          delta.height = 0 - childRect.y;
        }

        if (virtualPosition.x + virtualPosition.width + getBorder() > parentRect.width) {
          delta.width = parentRect.width - childRect.width - childRect.x - getBorder();
        }

        if (virtualPosition.y + virtualPosition.height + 2 * getBorder() > parentRect.height) {
          delta.height = parentRect.height - childRect.height - childRect.y - 2 * getBorder();
        }
        ChangeBoundsRequest request = (ChangeBoundsRequest) getTargetRequest();
        Point moveDelta = new Point(delta.width, delta.height);
        request.setMoveDelta(moveDelta);

        // Very important the child element to block inside the container
        // if not test first the target editPart.
        // let the default algorithm if the target is not its parent.
        setTargetEditPart(getSourceEditPart().getParent());
      }
    }
  }
 @Override
 public Dimension getPreferredSize(int wHint, int hHint) {
   Dimension size = super.getPreferredSize(wHint, hHint);
   // FIXME
   if (size.width < DrawUtils.SPACING + getBorder().getPreferredSize(this).width)
     size.width =
         Math.max(size.width, DrawUtils.SPACING + getBorder().getPreferredSize(this).width);
   return size;
 }
Ejemplo n.º 8
0
    protected LayoutData getLayoutData() {
      Dimension initSize = initFigure.getPreferredSize();
      initSize.width = Math.min(initSize.width, MAX_BOX_WIDTH);
      Dimension methodoSize = methodoFigure.getPreferredSize();
      methodoSize.width = Math.min(methodoSize.width, MAX_BOX_WIDTH);
      Dimension processSize = processFigure.getPreferredSize();
      processSize.width = Math.min(processSize.width, MAX_BOX_WIDTH);
      Dimension endSize = endFigure.getPreferredSize();
      endSize.width = Math.min(endSize.width, MAX_BOX_WIDTH);

      LayoutData data = new LayoutData();

      // boxes
      int initY = BOX_SPACING;
      int methodoY = initY + initSize.height + BOX_SPACING;
      int processY = methodoY + methodoSize.height + BOX_SPACING;
      int endY = processY + processSize.height + BOX_SPACING;
      int gap = processSize.width - methodoSize.width;
      data.initBox = new Rectangle(processSize.width / 2, initY, initSize.width, initSize.height);
      data.methodoBox = new Rectangle(gap / 2, methodoY, methodoSize.width, methodoSize.height);
      data.processBox = new Rectangle(0, processY, processSize.width, processSize.height);
      data.endBox = new Rectangle(processSize.width / 2, endY, endSize.width, endSize.height);
      // points
      int pointH = data.initBox.x + data.initBox.width / 2;
      data.init2methodoPoints = new PointList(2);
      data.init2methodoPoints.addPoint(pointH, data.initBox.y + data.initBox.height);
      data.init2methodoPoints.addPoint(pointH, data.methodoBox.y);
      data.methodo2processPoints = new PointList(2);
      data.methodo2processPoints.addPoint(pointH, data.methodoBox.y + data.methodoBox.height);
      data.methodo2processPoints.addPoint(pointH, data.processBox.y);
      data.process2endPoints = new PointList(2);
      data.process2endPoints.addPoint(pointH, data.processBox.y + data.processBox.height);
      data.process2endPoints.addPoint(pointH, data.endBox.y);
      // logo and status
      Dimension logoSize = logoFigure.getPreferredSize();
      data.logoBox = new Rectangle(0, 0, logoSize.width, logoSize.height);
      Dimension statusSize = statusFigure.getPreferredSize();
      int statusX =
          Math.max(
              data.methodoBox.x + data.methodoBox.width - statusSize.width,
              data.processBox.x + data.processBox.width + BOX_SPACING);
      data.statusBox = new Rectangle(statusX, 0, statusSize.width, statusSize.height);
      return data;
    }
Ejemplo n.º 9
0
  /*
   * (non-Javadoc)
   *
   * @see henshineditor.figure.condition.FormulaFigure#getPreferredDimension()
   */
  @Override
  protected Dimension getPreferredDimension() {
    Dimension dimension = super.getPreferredDimension();

    FormulaFigure<?> childFigure = getChildFigure();
    if (childFigure != null) {
      Dimension childDimension = childFigure.getPreferredDimension();
      dimension.height += childDimension.height;
      dimension.width = childDimension.width;
    }

    return dimension;
  }
Ejemplo n.º 10
0
  /**
   * Return the default draw2D dimension according to the specified DNode.
   *
   * @return the default draw2D dimension according to the specified DNode.
   */
  public Dimension getDefaultDimension() {
    final Dimension result = DEFAULT_NODE_DIMENSION.getCopy();

    if (node.getStyle() instanceof WorkspaceImage) {
      final WorkspaceImage workspaceImage = (WorkspaceImage) node.getStyle();
      final String path = workspaceImage.getWorkspacePath();
      final Image image;
      image = WorkspaceImageFigure.getImageInstanceFromPath(path);
      if (image != null) {
        // Use default image size
        if (node.getWidth() == null || Integer.valueOf(node.getWidth()) == -1) {
          result.width = image.getBounds().width;
          result.height = image.getBounds().height;
        } else {
          // width is already defined, adapt height thanks to
          // image ratio
          final double ratio = (double) image.getBounds().width / image.getBounds().height;
          double newHeight = node.getWidth().intValue() / ratio;

          // Adapt to draw2D
          result.width = node.getWidth().intValue() * LayoutUtils.SCALE;
          result.height = (int) (newHeight * LayoutUtils.SCALE);
        }
      }
    } else {
      if (node.getWidth() != null) {
        result.width = node.getWidth().intValue();
      }
      if (node.getHeight() != null) {
        result.height = node.getHeight().intValue();
      }

      // Adapt to draw2D
      result.width = result.width * LayoutUtils.SCALE;
      result.height = result.height * LayoutUtils.SCALE;
    }

    return result;
  }
  protected void showChangeBoundsFeedback(ChangeBoundsRequest request) {
    IFigure feedback = getDragSourceFeedbackFigure();

    PrecisionRectangle rect = new PrecisionRectangle(getInitialFeedbackBounds().getCopy());
    getHostFigure().translateToAbsolute(rect);

    // Only enable horizontal dragging on lifelines(except lifelines that are result of a create
    // message).
    // https://bugs.eclipse.org/bugs/show_bug.cgi?id=364688
    if (this.getHost() instanceof LifelineEditPart) {
      LifelineEditPart lifelineEP = (LifelineEditPart) this.getHost();
      if (!SequenceUtil.isCreateMessageEndLifeline(lifelineEP)) {
        request.getMoveDelta().y = 0;
      }
    }

    rect.translate(request.getMoveDelta());
    rect.resize(request.getSizeDelta());

    IFigure f = getHostFigure();
    Dimension min = f.getMinimumSize().getCopy();
    Dimension max = f.getMaximumSize().getCopy();
    IMapMode mmode = MapModeUtil.getMapMode(f);
    min.height = mmode.LPtoDP(min.height);
    min.width = mmode.LPtoDP(min.width);
    max.height = mmode.LPtoDP(max.height);
    max.width = mmode.LPtoDP(max.width);

    if (min.width > rect.width) rect.width = min.width;
    else if (max.width < rect.width) rect.width = max.width;

    if (min.height > rect.height) rect.height = min.height;
    else if (max.height < rect.height) rect.height = max.height;

    feedback.translateToRelative(rect);
    feedback.setBounds(rect);
  }
Ejemplo n.º 12
0
  @Override
  protected void updateSourceRequest() {
    ChangeBoundsRequest request = (ChangeBoundsRequest) getSourceRequest();
    Dimension d = getDragMoveDelta();

    Point location = new Point(getLocation());
    Point moveDelta = new Point(0, 0);
    Dimension resizeDelta = new Dimension(0, 0);

    request.setConstrainedResize(false);

    request.setCenteredResize(getCurrentInput().isModKeyDown(SWT.MOD1));

    if ((getResizeDirection() & PositionConstants.NORTH) != 0) {
      moveDelta.y += d.height;
      resizeDelta.height -= d.height;
    }
    if ((getResizeDirection() & PositionConstants.SOUTH) != 0) {
      resizeDelta.height += d.height;
    }
    if ((getResizeDirection() & PositionConstants.WEST) != 0) {
      moveDelta.x += d.width;
      resizeDelta.width -= d.width;
    }
    if ((getResizeDirection() & PositionConstants.EAST) != 0) {
      resizeDelta.width += d.width;
    }

    request.setMoveDelta(moveDelta);
    request.setSizeDelta(resizeDelta);
    request.setLocation(location);
    request.setEditParts(getOperationSet());

    request.getExtendedData().clear();

    // TODO: snapping
  }
    /*
     * (non-Javadoc)
     *
     * @see org.eclipse.draw2d.ToolbarLayout#layout(org.eclipse.draw2d.IFigure)
     */
    @Override
    public void layout(IFigure parent) {
      final Rectangle clientArea = parent.getClientArea();
      int x = clientArea.x;
      int y = clientArea.y;
      final List children = parent.getChildren();
      int numChildren = children.size();

      int maxHeight = 0;
      for (int i = 0; i < numChildren; i++) {
        IFigure child = (IFigure) children.get(i);
        Dimension prefSize = getChildPreferredSize(child, clientArea.width, -1);
        maxHeight = Math.max(maxHeight, prefSize.height);
      }
      maxHeight = Math.max(maxHeight, clientArea.height);

      if (numChildren == 1) {
        IFigure child = (IFigure) children.get(0);
        Dimension prefSize = child.getPreferredSize(clientArea.width, -1);
        prefSize.width = Math.max(prefSize.width, clientArea.width);
        Rectangle newBounds = new Rectangle(x, y, prefSize.width, maxHeight);
        child.setBounds(newBounds);
      } else if (numChildren == 2) {
        int initExpressionWidth =
            (xmlTreePart.getViewer().getControl().getSize().x / 3 - 80 - 10) / 2;
        IFigure child = (IFigure) children.get(0);
        Rectangle newBounds = new Rectangle(x, y, initExpressionWidth, maxHeight);
        child.setBounds(newBounds);

        child = (IFigure) children.get(1);
        Dimension prefSize = child.getPreferredSize(clientArea.width, -1);
        prefSize.width = Math.max(prefSize.width, clientArea.width - initExpressionWidth);
        newBounds = new Rectangle(x + initExpressionWidth, y, prefSize.width, maxHeight);
        child.setBounds(newBounds);
      }
    }
Ejemplo n.º 14
0
 /** @see org.eclipse.draw2d.LayoutManager#layout(org.eclipse.draw2d.IFigure) */
 public void layout(IFigure container) {
   List children = container.getChildren();
   Rectangle rulerSize = container.getClientArea();
   for (int i = 0; i < children.size(); i++) {
     IFigure child = (IFigure) children.get(i);
     Dimension childSize = child.getPreferredSize();
     int position = ((Integer) getConstraint(child)).intValue();
     if (((RulerFigure) container).isHorizontal()) {
       childSize.height = rulerSize.height - 1;
       Rectangle.getSINGLETON().setLocation(position - (childSize.width / 2), rulerSize.y);
     } else {
       childSize.width = rulerSize.width - 1;
       Rectangle.getSINGLETON().setLocation(rulerSize.x, position - (childSize.height / 2));
     }
     Rectangle.getSINGLETON().setSize(childSize);
     child.setBounds(Rectangle.getSINGLETON());
   }
 }
 /**
  * Returns the size set specified by setPreferredImageSize() or the size specified by the image.
  * In the case of meta-images a preferred size of 32x32 is returned.
  */
 public Dimension getPreferredSize(int wHint, int hHint) {
   if (preferredSize.height == -1 && preferredSize.width == -1) {
     int extent = MapModeUtil.getMapMode(this).DPtoLP(32);
     preferredSize = new Dimension(extent, extent);
     if (getFlag(FLAG_USE_DEFAULT_IMAGESIZE)) {
       if (getRenderedImage() != null) {
         setRenderedImage(getRenderedImage(new Dimension(0, 0)));
         Image swtImage = null;
         if (getRenderedImage() != null) swtImage = getRenderedImage().getSWTImage();
         if (swtImage != null) {
           org.eclipse.swt.graphics.Rectangle imgRect = swtImage.getBounds();
           preferredSize.width = MapModeUtil.getMapMode(this).DPtoLP(imgRect.width);
           preferredSize.height = MapModeUtil.getMapMode(this).DPtoLP(imgRect.height);
         }
       }
     }
   }
   return preferredSize;
 }
Ejemplo n.º 16
0
    public void layout(IFigure container) {
      Rectangle area = container.getClientArea();
      area.height -= 1;
      Dimension scaleSize = new Dimension(0, 0);
      Dimension markerSize = new Dimension(0, 0);

      if (scale != null) {
        if (scale.isVisible()) {
          scaleSize = scale.getPreferredSize(-1, area.height);
          scale.setBounds(new Rectangle(area.x, area.y, scaleSize.width, scaleSize.height));
        } else {
          scaleSize = scale.getPreferredSize(-1, area.height + 2 * scale.getMargin());
          scale.setBounds(
              new Rectangle(area.x, area.y - scale.getMargin(), scaleSize.width, scaleSize.height));
          scaleSize.height = 0;
          scaleSize.width = 0;
        }
      }

      if (marker != null && marker.isVisible()) {
        markerSize = marker.getPreferredSize();
        marker.setBounds(
            new Rectangle(
                area.x + area.width - markerSize.width,
                marker.getScale().getBounds().y,
                markerSize.width,
                markerSize.height));
      }

      if (tank != null) {
        tank.setBounds(
            new Rectangle(
                area.x + scaleSize.width,
                scale.getValuePosition(scale.getRange().getUpper(), false),
                area.width - scaleSize.width - markerSize.width,
                scale.getTickLength() + tank.getLineWidth()));
      }
    }
Ejemplo n.º 17
0
 /**
  * Shows or updates feedback for a change bounds request. The request is updated by the way so
  * that the shape stays a square.
  *
  * @param request the request
  */
 @Override
 protected void showChangeBoundsFeedback(ChangeBoundsRequest request) {
   // adapt the request for a square resize
   Point move = request.getMoveDelta();
   Dimension delta = request.getSizeDelta();
   int dH = delta.height;
   int dW = delta.width;
   int signum = 0;
   if (dH <= 0 && dW <= 0) {
     signum = -1;
   } else {
     signum = 1;
   }
   int positiveResize = Math.max(dH, dW);
   if (positiveResize <= 0) {
     if (dH == 0) {
       positiveResize = -dW;
     } else if (dW == 0) {
       positiveResize = -dH;
     } else {
       positiveResize = Math.min(-dH, -dW);
     }
   }
   int newDH = signum * positiveResize;
   int newDW = newDH;
   int dir = request.getResizeDirection();
   // adjust new position if impacted by resizing
   if ((dir & PositionConstants.NORTH) > 0) {
     move.y += dH - newDH;
   }
   if ((dir & PositionConstants.WEST) > 0) {
     move.x += dW - newDW;
   }
   request.setMoveDelta(move);
   delta.height = newDH;
   delta.width = newDW;
   super.showChangeBoundsFeedback(request);
 }
Ejemplo n.º 18
0
  protected Dimension calculatePreferredSize(IFigure container, int wHint, int hHint) {
    Dimension extent = null;

    for (Iterator i = container.getChildren().iterator(); i.hasNext(); ) {
      IFigure child = (IFigure) i.next();

      Dimension childSize = null;
      if (!(child instanceof FreeformFigure)) {
        childSize = child.getPreferredSize();
      }
      if (null != childSize) {
        if (null == extent) {
          extent = childSize.getCopy();
        } else {
          extent.width += childSize.width + getMinorSpacing();
          extent.height = Math.max(extent.height, childSize.height);
        }
      }
    }

    if (null != extent) {
      extent.union(container.getMinimumSize());
    } else {
      extent = container.getMinimumSize();
    }

    Insets insets = container.getInsets();
    if (null == extent) {
      extent = new Dimension(insets.getWidth(), insets.getHeight());
    } else {
      // compartment.translateToParent(extent);
      extent.expand(insets.getWidth(), insets.getHeight());
    }

    return extent;
  }
Ejemplo n.º 19
0
  public PipelineWidget(
      StreamStructure model,
      String streamNameWithId,
      OptionData optionData,
      Figure parent,
      boolean forward,
      boolean verticalLayout,
      boolean lastChild,
      Dimension parentSize,
      StreamItViewFactory factoryInst)
      throws DebugException {
    super();
    fModel = (Pipeline) model;

    // create pipeline
    new StreamStructureSelector(this);
    String pipelineName = getNameWithRuntimeId();
    fExpanded = optionData.containsStream(pipelineName, false);
    Dimension pipelineSize = FigureUtilities.getTextExtents(pipelineName, factoryInst.getFont());

    // pipeline style
    if (optionData.isHideLines() && fExpanded) setOutline(false);
    else setBorder(new LineBorder());
    setOpaque(true);
    setForegroundColor(ColorConstants.menuForeground);
    setBackgroundColor(ColorConstants.white);

    // possible highlight
    if (streamNameWithId.equals(pipelineName)) StreamStructureSelector.setSelection(this);

    if (!fExpanded) {

      // collapsed content
      fHeader = new Label(pipelineName, factoryInst.getPlus());
      pipelineSize.expand(fHeader.getIconTextGap() + factoryInst.getImageWidth(), 0);
      factoryInst.roundUpEven(pipelineSize);
      fHeader.setSize(pipelineSize);
      add(fHeader);

      pipelineSize.expand(
          IStreamItGraphConstants.MARGIN,
          factoryInst.getArrowHeight() + IStreamItGraphConstants.MARGIN);
    } else {

      // expanded content
      fHeader = new Label(pipelineName, factoryInst.getMinus());
      pipelineSize.expand(fHeader.getIconTextGap() + factoryInst.getImageWidth(), 0);
      factoryInst.roundUpEven(pipelineSize);
      fHeader.setSize(pipelineSize);
      add(fHeader);

      // expanded children
      Vector children = fModel.getChildStreams();
      int last;
      if (forward) {
        last = children.size() - 1;
      } else {
        last = 0;
        Collections.reverse(children);
      }
      Dimension childrenSize =
          new Dimension(0, 0); // (width of widest child, total height of children)
      fChildren = new Vector();
      Object child;
      for (int i = 0; i < children.size(); i++) {
        child = children.get(i);
        if (child instanceof Filter) {
          fChildren.add(
              new FilterWidget(
                  (Filter) child,
                  streamNameWithId,
                  optionData,
                  this,
                  forward,
                  true,
                  i == last,
                  childrenSize,
                  factoryInst));
        } else if (child instanceof Pipeline) {
          fChildren.add(
              new PipelineWidget(
                  (Pipeline) child,
                  streamNameWithId,
                  optionData,
                  this,
                  forward,
                  true,
                  i == last,
                  childrenSize,
                  factoryInst));
        } else if (child instanceof SplitJoin) {
          fChildren.add(
              new SplitJoinWidget(
                  (SplitJoin) child,
                  streamNameWithId,
                  optionData,
                  this,
                  forward,
                  true,
                  i == last,
                  childrenSize,
                  factoryInst));
        } else if (child instanceof FeedbackLoop) {
          fChildren.add(
              new FeedbackLoopWidget(
                  (FeedbackLoop) child,
                  streamNameWithId,
                  optionData,
                  this,
                  forward,
                  true,
                  i == last,
                  childrenSize,
                  factoryInst));
        }
      }

      // expanded size
      if (fChildren.size() == 0) {
        pipelineSize.width =
            IStreamItGraphConstants.MARGIN * 2
                + Math.max(
                    childrenSize.width,
                    pipelineSize.width * 2 + IStreamItGraphConstants.MARGIN * 3);
        setOutline(true);
        setBorder(new LineBorder());
      } else {
        pipelineSize.width =
            IStreamItGraphConstants.MARGIN * 2
                + Math.max(
                    childrenSize.width,
                    pipelineSize.width * 2
                        + IStreamItGraphConstants.MARGIN * 3
                        + ((IStreamStructureWidget) fChildren.get(0)).getTopChannelToggleWidth()
                            * 2);
      }
      pipelineSize.height =
          Math.max(childrenSize.height, pipelineSize.height + factoryInst.getArrowHeight());
    }
    setSize(pipelineSize);

    // content arrow
    fArrow = new ImageFigure(factoryInst.getArrow(forward));
    fArrow.setSize(factoryInst.getArrowWidth(), factoryInst.getArrowHeight());
    add(fArrow);

    // create channels
    if (forward) {
      fTopChannel =
          new ChannelWidget(
              fModel.getInputChannel(),
              pipelineName + IStreamItGraphConstants.ONE_CHAR,
              parent,
              forward,
              lastChild,
              optionData,
              factoryInst);
      fBottomChannel =
          new ChannelWidget(
              fModel.getOutputChannel(),
              pipelineName + IStreamItGraphConstants.ZERO_CHAR,
              parent,
              forward,
              lastChild,
              optionData,
              factoryInst);

      fTopChannel.grayData(
          Integer.parseInt(fModel.getMaxPeeked()) - Integer.parseInt(fModel.getPopped()));
    } else {
      fBottomChannel =
          new ChannelWidget(
              fModel.getInputChannel(),
              pipelineName + IStreamItGraphConstants.ONE_CHAR,
              parent,
              forward,
              lastChild,
              optionData,
              factoryInst);
      fTopChannel =
          new ChannelWidget(
              fModel.getOutputChannel(),
              pipelineName + IStreamItGraphConstants.ZERO_CHAR,
              parent,
              forward,
              lastChild,
              optionData,
              factoryInst);

      fBottomChannel.grayData(
          Integer.parseInt(fModel.getMaxPeeked()) - Integer.parseInt(fModel.getPopped()));
    }

    fTopChannel.turnOff(fExpanded);
    fBottomChannel.turnOff(fExpanded);
    ((IStreamStructureWidget) parent)
        .setChannelExpanded(fTopChannel.isExpanded(), fBottomChannel.isExpanded());

    // parent content
    parent.add(this);

    // parent size
    if (verticalLayout) {
      // (total height of children, width of widest child)
      parentSize.height = parentSize.height + fTopChannel.getSize().height + pipelineSize.height;
      if (lastChild) parentSize.height += fBottomChannel.getSize().height;
      parentSize.width = Math.max(parentSize.width, pipelineSize.width);
    } else {
      // (height of tallest child, total width of children)
      parentSize.height =
          Math.max(
              parentSize.height,
              fTopChannel.getSize().height + pipelineSize.height + fBottomChannel.getSize().height);
      parentSize.width =
          parentSize.width + Math.max(pipelineSize.width, fTopChannel.getSize().width);
    }
  }
Ejemplo n.º 20
0
  public void setElementName(String name) {
    this.columnName = name;
    size.height = 23;

    size.width = Math.round(columnName.length() * 5.2f) + 45;
  }