Пример #1
0
 @Override
 protected Dimension calculatePreferredSize(IFigure container, int w, int h) {
   Insets insets = container.getInsets();
   Dimension d = new Dimension(64, 4 * 64);
   d.expand(insets.getWidth(), insets.getHeight());
   return d;
 }
    /*
     * (non-Javadoc)
     *
     * @see org.eclipse.draw2d.ToolbarLayout#calculatePreferredSize(org.eclipse.draw2d.IFigure, int, int)
     */
    @Override
    protected Dimension calculatePreferredSize(IFigure container, int wHint, int hHint) {
      Insets insets = container.getInsets();
      Dimension prefSize = calculateChildrenSize(container.getChildren(), wHint, hHint);

      return prefSize
          .expand(insets.getWidth(), insets.getHeight())
          .union(getBorderPreferredSize(container));
    }
Пример #3
0
 private void refreshLabelBounds(IFigure figure, GraphLabel label) {
   Rectangle figureBounds = figure.getBounds();
   if (figureBounds.width * figureBounds.height > 0) {
     label.setText(label.getText()); // hack: resets label's size
     Dimension labelSize = label.getSize();
     labelSize.expand(-6, -4);
     Point anchorPoint = figure.getBounds().getBottomRight();
     anchorPoint.x -= labelSize.width / 2;
     anchorPoint.y -= labelSize.height / 2;
     Rectangle bounds = new Rectangle(anchorPoint, labelSize);
     label.setBounds(bounds);
     label.getParent().setConstraint(label, bounds);
   } else {
     label.getParent().setConstraint(label, new Rectangle(figureBounds.x, figureBounds.y, 0, 0));
     label.setBounds(new Rectangle(figureBounds.x, figureBounds.y, 0, 0));
   }
 }
  /** creates the command to move the shapes left or right. */
  protected Command getCommand() {
    if (_container == null) {
      return null;
    }
    CompoundCommand command = new CompoundCommand("Multiple Shape Move");
    TransactionalEditingDomain editingDomain = _container.getEditingDomain();

    Point moveDelta = ((ChangeBoundsRequest) getSourceRequest()).getMoveDelta().getCopy();
    Dimension spSizeDelta = new Dimension(moveDelta.x, moveDelta.y);
    ZoomManager zoomManager =
        ((DiagramRootEditPart) getCurrentViewer().getRootEditPart()).getZoomManager();
    spSizeDelta.scale(1 / zoomManager.getZoom());
    command.add(_container.getCommand(getSourceRequest()));

    for (IGraphicalEditPart sp : _subProcesses) {
      Dimension spDim = sp.getFigure().getBounds().getSize().getCopy();
      spDim.expand(spSizeDelta);
      SetBoundsCommand setBounds =
          new SetBoundsCommand(editingDomain, "MultipleShape Move", sp, spDim);
      command.add(new ICommandProxy(setBounds));
    }
    return command;
  }
  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;
  }
Пример #6
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);
    }
  }