コード例 #1
0
ファイル: ZoomManager.java プロジェクト: Reeny/zest
  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);
  }
コード例 #2
0
  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);
  }
コード例 #3
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;
  }
コード例 #4
0
  /**
   * 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;
      }
    }
  }
コード例 #5
0
  @Override
  protected Dimension calculatePreferredSize(IFigure container, int wHint, int hHint) {
    Insets insets = container.getInsets();
    if (isHorizontal()) {
      wHint = -1;
      if (hHint >= 0) {
        hHint = Math.max(0, hHint - insets.getHeight());
      }
    } else {
      hHint = -1;
      if (wHint >= 0) {
        wHint = Math.max(0, wHint - insets.getWidth());
      }
    }

    List children = container.getChildren();
    Dimension prefSize = calculateChildrenSize(children, wHint, hHint, true);
    // Do a second pass, if necessary
    if (wHint >= 0 && prefSize.width > wHint) {
      prefSize = calculateChildrenSize(children, prefSize.width, hHint, true);
    } else if (hHint >= 0 && prefSize.width > hHint) {
      prefSize = calculateChildrenSize(children, wHint, prefSize.width, true);
    }

    prefSize.height += Math.max(0, children.size() - 1) * spacing;
    return transposer
        .t(prefSize)
        .expand(insets.getWidth(), insets.getHeight())
        .union(getBorderPreferredSize(container));
  }
コード例 #6
0
  /**
   * Given a label figure object, this will calculate the correct Font needed to display into screen
   * coordinates, taking into account the current mapmode. This will typically be used by direct
   * edit cell editors that need to display independent of the zoom or any coordinate mapping that
   * is taking place on the drawing surface.
   *
   * @param label the label to use for the font calculation
   * @return the <code>Font</code> that is scaled to the screen coordinates. Note: the returned
   *     <code>Font</code> should not be disposed since it is cached by a common resource manager.
   */
  protected Font getScaledFont(IFigure label) {
    Font scaledFont = label.getFont();
    FontData data = scaledFont.getFontData()[0];
    Dimension fontSize = new Dimension(0, MapModeUtil.getMapMode(label).DPtoLP(data.getHeight()));
    label.translateToAbsolute(fontSize);

    if (Math.abs(data.getHeight() - fontSize.height) < 2) fontSize.height = data.getHeight();

    try {
      FontDescriptor fontDescriptor = FontDescriptor.createFrom(data);
      cachedFontDescriptors.add(fontDescriptor);
      return getResourceManager().createFont(fontDescriptor);
    } catch (DeviceResourceException e) {
      Trace.catching(
          DiagramUIPlugin.getInstance(),
          DiagramUIDebugOptions.EXCEPTIONS_CATCHING,
          getClass(),
          "getScaledFont",
          e); //$NON-NLS-1$
      Log.error(
          DiagramUIPlugin.getInstance(),
          DiagramUIStatusCodes.IGNORED_EXCEPTION_WARNING,
          "getScaledFont",
          e); //$NON-NLS-1$
    }
    return JFaceResources.getDefaultFont();
  }
コード例 #7
0
  /** {@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());
      }
    }
  }
コード例 #8
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;
  }
コード例 #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;
  }
コード例 #10
0
 /**
  * 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);
   }
 }
コード例 #11
0
  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);
  }
コード例 #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
  }
コード例 #13
0
  /* (non-Javadoc)
   * @see streamit.eclipse.debugger.graph.IStream#setHorizontalLocation(org.eclipse.draw2d.geometry.Point, int, int)
   */
  public int setHorizontalLocation(
      int currentHeight,
      boolean stretchTopChannel,
      boolean stretchBottomChannel,
      int stretchHeight,
      int currentWidth) {
    Dimension topSize = fTopChannel.getSize();
    Dimension pipelineSize = getSize();
    Dimension bottomSize = fBottomChannel.getSize();

    // expand channels
    if (stretchTopChannel) {
      topSize.height = stretchHeight - pipelineSize.height - bottomSize.height;
      fTopChannel.setSize(topSize);
    }
    if (stretchBottomChannel) {
      bottomSize.height = stretchHeight - pipelineSize.height - topSize.height;
      fBottomChannel.setSize(bottomSize);
    }

    setVerticalLocation(new Point(currentWidth + pipelineSize.width / 2, currentHeight), 0);
    currentWidth = currentWidth + pipelineSize.width + IStreamItGraphConstants.MARGIN / 2;
    return currentWidth;
  }
コード例 #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());
   }
 }
コード例 #15
0
ファイル: LabelFigure.java プロジェクト: GiorgioHuang/birt
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.draw2d.Figure#getMinimumSize(int, int)
   */
  private Dimension getMinimumSize(
      int wHint, int hHint, boolean isFix, boolean forceWidth, boolean forceHeight) {
    if (DesignChoiceConstants.DISPLAY_NONE.equals(display)) {
      return ZERO_DIMENSION;
    }

    int rx = recommendSize != null ? recommendSize.width : 0;
    int ry = recommendSize != null ? recommendSize.height : 0;

    rx = getRealRecommendSizeX(rx, wHint);

    if (wHint == -1 && hHint == -1) {
      int maxWidth = calcMaxSegment();

      // use recommend size if specified, otherwise use max segment size
      Dimension dim = super.getMinimumSize(rx == 0 ? maxWidth : rx, -1);

      dim.height = Math.max(dim.height, Math.max(getInsets().getHeight(), ry));

      return dim;
    }
    Dimension dim;
    // return the true minimum size with minimum width;
    if (isFix) {
      int tempHint = wHint;
      int maxWidth = calcMaxSegment();
      if (wHint < maxWidth && !forceWidth) {
        tempHint = maxWidth;
      }
      dim = super.getMinimumSize(tempHint <= 0 ? -1 : tempHint, hHint);

      return new Dimension(Math.max(dim.width, rx), Math.max(dim.height, ry));
    } else {
      dim = super.getMinimumSize(rx == 0 ? -1 : rx, hHint);
    }

    if (dim.width < wHint) {
      return new Dimension(Math.max(dim.width, rx), Math.max(dim.height, ry));
    }

    dim = super.getMinimumSize(wHint, hHint);

    return new Dimension(Math.max(dim.width, rx), Math.max(dim.height, ry));
  }
コード例 #16
0
 /**
  * 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;
 }
コード例 #17
0
ファイル: TankFigure.java プロジェクト: PRBonneau2/cs-studio
    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()));
      }
    }
コード例 #18
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);
 }
コード例 #19
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;
  }
コード例 #20
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);
    }
  }
コード例 #21
0
 public Dimension getPreferredSize(int wHint, int hHint) {
   Dimension size = super.getPreferredSize(wHint, hHint);
   size.height = Math.max(size.height, 10);
   return size;
 }
コード例 #22
0
ファイル: Column.java プロジェクト: Blueye1993/tdi-studio-se
  public void setElementName(String name) {
    this.columnName = name;
    size.height = 23;

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