Beispiel #1
0
  private int calcMaxSegment() {
    String text = label.getText();
    char[] chars = text.toCharArray();
    int position = 0;
    int maxWidth = 0;

    for (int i = 0; i < chars.length; i++) {
      if (canBreakAfter(chars[i])) {
        int tempMaxWidth;
        String st = text.substring(position, i + 1);
        tempMaxWidth = FigureUtilities.getStringExtents(st, getFont()).width;

        if (tempMaxWidth > maxWidth) {
          maxWidth = tempMaxWidth;
        }
        position = i;
      }
    }
    String st = text.substring(position, chars.length);
    int tempMaxWidth = FigureUtilities.getStringExtents(st, getFont()).width;

    if (tempMaxWidth > maxWidth) {
      maxWidth = tempMaxWidth;
    }
    return maxWidth + getInsets().getWidth();
  }
  private void updateFigureVisibility(IFigure figure, int visibility) {

    switch (visibility) {
      case INVISIBLE:
        figure.setVisible(false);
        break;

      case VISIBLE:
        figure.setForegroundColor(ColorConstants.listForeground);
        figure.setBackgroundColor(ColorConstants.titleInactiveBackground);
        figure.setVisible(true);
        break;

      case FADED:
        figure.setForegroundColor(
            FigureUtilities.mixColors(
                ColorConstants.listForeground, ColorConstants.listBackground, 0.1));
        figure.setBackgroundColor(
            FigureUtilities.mixColors(
                ColorConstants.titleInactiveBackground, ColorConstants.listBackground, 0.1));
        figure.setVisible(true);
        break;

      default:
        return;
    }
  }
 /** @generated */
 public void relocate(CellEditor celleditor) {
   Text text = (Text) celleditor.getControl();
   Rectangle rect = getLabel().getTextBounds().getCopy();
   getLabel().translateToAbsolute(rect);
   int avr = FigureUtilities.getFontMetrics(text.getFont()).getAverageCharWidth();
   rect.setSize(new Dimension(text.computeSize(SWT.DEFAULT, SWT.DEFAULT)).expand(avr * 2, 0));
   if (!rect.equals(new Rectangle(text.getBounds()))) {
     text.setBounds(rect.x, rect.y, rect.width, rect.height);
   }
 }
 /**
  * Creates the figure used for feedback.
  *
  * @return the new feedback figure
  */
 protected IFigure createDragSourceFeedbackFigure() {
   // Use a ghost rectangle for feedback
   RectangleFigure r = new RectangleFigure();
   FigureUtilities.makeGhostShape(r);
   r.setLineStyle(Graphics.LINE_DOT);
   r.setForegroundColor(ColorConstants.white);
   r.setBounds(getInitialFeedbackBounds());
   addFeedback(r);
   return r;
 }
Beispiel #5
0
    @Override
    protected void paintClientArea(Graphics graphics) {
      if (support3d == null) support3d = GraphicsUtil.testPatternSupported(graphics);
      Rectangle clientArea = getClientArea();
      Rectangle square =
          new Rectangle(
              clientArea.x,
              clientArea.y + clientArea.height / 2 - BOX_SIZE / 2,
              BOX_SIZE,
              BOX_SIZE);
      graphics.pushState();
      if (support3d)
        graphics.setBackgroundPattern(
            GraphicsUtil.createScaledPattern(
                graphics,
                Display.getCurrent(),
                square.x,
                square.y + 1,
                square.x,
                square.y + square.height,
                ColorConstants.white,
                graphics.getBackgroundColor()));
      graphics.fillRoundRectangle(square, 4, 4);
      graphics.setForegroundColor(CustomMediaFactory.getInstance().getColor(130, 130, 130));
      graphics.drawRoundRectangle(square, 4, 4);

      if (boolValue) {
        graphics.translate(square.x, square.y);
        graphics.setLineWidth(3);
        graphics.setForegroundColor(selectedColor);

        graphics.drawPolyline(
            new int[] {
              3,
              (int) (BOX_SIZE * 0.45),
              (int) (BOX_SIZE * 0.45),
              BOX_SIZE * 3 / 4 - 1,
              BOX_SIZE - 2,
              3
            });
      }
      graphics.popState();
      Dimension textSize = FigureUtilities.getTextExtents(text, graphics.getFont());

      if (!isEnabled()) {
        graphics.translate(1, 1);
        graphics.setForegroundColor(ColorConstants.buttonLightest);
        graphics.drawText(text, square.getRight().getTranslated(GAP, -textSize.height / 2));
        graphics.translate(-1, -1);
        graphics.setForegroundColor(ColorConstants.buttonDarker);
      }
      graphics.drawText(text, square.getRight().getTranslated(GAP, -textSize.height / 2));

      super.paintClientArea(graphics);
    }
 private static int getFontAverageCharWidth(Font f) {
   StringBuffer buf = new StringBuffer(""); // $NON-NLS-1$
   for (int i = 'A'; i <= 'Z'; i++) {
     buf.append((char) i);
   }
   for (int i = 'a'; i <= 'z'; i++) {
     buf.append((char) i);
   }
   Dimension dim = FigureUtilities.getStringExtents(buf.toString(), f);
   return (int) div(dim.width, 52);
 }
  /**
   * Traverses to the closest EditPart in the given list that is also in the given direction.
   *
   * @param event the KeyEvent for the keys that were pressed to trigger this traversal
   * @param direction PositionConstants.* indicating the direction in which to traverse
   */
  boolean navigateNextSibling(KeyEvent event, int direction, List<?> list) {
    IEntityPart epStart = getFocusEntityPart();
    if (epStart instanceof ITextualEntityPart) {
      ITextualEntityPart textualEntityPart = (ITextualEntityPart) epStart;
      ITextualFigure textualFigure = textualEntityPart.getTextualFigure();
      String text = textualFigure.getText();
      int line = CaretUtils.getLineFromPosition(text, textualEntityPart.getCaretPosition());
      int lines = CaretUtils.getCaretLines(text);
      if ((direction == PositionConstants.WEST && textualEntityPart.getCaretPosition() > 0)
          || (direction == PositionConstants.EAST
              && textualEntityPart.getCaretPosition() < textualEntityPart.getCaretPositions())) {
        int position =
            textualEntityPart.getCaretPosition() + (direction == PositionConstants.WEST ? -1 : 1);
        CaretUpdater.sheduleSyncUpdate(
            getViewer(), textualEntityPart.getModelEntity(), position, true);
        return true;
      } else if ((direction == PositionConstants.NORTH && line > 0)
          || (direction == PositionConstants.SOUTH && line < lines)) {
        int dy =
            FigureUtilities.getFontMetrics(textualFigure.getFont()).getHeight()
                * (direction == PositionConstants.NORTH ? -1 : 1);
        Point location = textualFigure.getCaretBounds().getCenter().translate(0, dy);
        CaretUpdater.sheduleSyncUpdate(
            getViewer(), textualEntityPart.getModelEntity(), location, true);
        textualEntityPart.updateCaret(location);
        return true;
      }
    }
    if (!(epStart instanceof IGraphicalEntityPart)) return false;
    IFigure figure = ((IGraphicalEntityPart) epStart).getFigure();
    Point pStart = getNavigationPoint(figure);
    figure.translateToAbsolute(pStart);
    EditPart next =
        findSibling(
            list, pStart, direction, epStart); // parent.findSibling(pStart, direction, epStart);
    while (next == null) {
      if (!(epStart.getParent() instanceof IGraphicalEntityPart)) return false;

      epStart = (IGraphicalEntityPart) epStart.getParent();
      if (epStart == getViewer().getContents()
          || epStart.getParent() == getViewer().getContents()
          || epStart.getParent() == null) return false;

      list = epStart.getParent().getChildren();
      next = findSibling(list, pStart, direction, epStart);
    }

    // next = next.enter(pStart, direction, epStart);1+2
    navigateTo(next, event);
    return true;
  }
  protected void layoutForwards() {
    int start = 23;
    int width, maxWidth;
    int height = NodeFigure.LINK_HEIGHT;
    IForward forward;
    prefferedSize.height = 20;
    prefferedSize.width = getProcessItemModel().getBounds().width;

    if (prefferedSize.width == 0) {
      maxWidth =
          FigureUtilities.getTextExtents(
                      getProcessItemModel().getName(),
                      getProcessItemModel().getStrutsModel().getOptions().getActionFont())
                  .width
              + 38;
      for (int i = 0; i < getProcessItemModel().getForwardList().size(); i++) {
        forward = (IForward) getProcessItemModel().getForwardList().get(i);
        width =
            FigureUtilities.getTextExtents(
                        forward.getName(),
                        getProcessItemModel().getStrutsModel().getOptions().getForwardFont())
                    .width
                + 31;
        if (width > maxWidth) maxWidth = width;
      }
      if (maxWidth < 100) maxWidth = 100;
      prefferedSize.width = maxWidth;
    }

    for (int i = 0; i < getProcessItemModel().getForwardList().size(); i++) {
      forward = (IForward) getProcessItemModel().getForwardList().get(i);
      forward.setBounds(start, prefferedSize.height, prefferedSize.width - 24, height);
      prefferedSize.height += height;
    }
    prefferedSize.height += 5;
  }
Beispiel #9
0
    public void layout(IFigure container) {
      Rectangle area = container.getClientArea();
      // calculate a virtual area

      if (scale != null && scale.isDirty())
        M =
            Math.max(
                    FigureUtilities.getTextWidth(
                        scale.format(scale.getRange().getLower()), scale.getFont()),
                    FigureUtilities.getTextWidth(
                        scale.format(scale.getRange().getUpper()), scale.getFont()))
                / 2;

      int h = area.height;
      int w = area.width;
      if (h > HW_RATIO * (w - 2 * M)) h = (int) (HW_RATIO * (w - 2 * M));
      // else if (w > h/HW_RATIO + 2*M)
      //	w = (int) (h/HW_RATIO + 2*M);
      double r = h / (1 - Math.sin(ALPHA) / 2);
      int x = (int) (area.x - r * (1.0 - Math.cos(ALPHA)) + M);
      int y = area.y;

      area = new Rectangle(x, y, (int) (2 * r), (int) (2 * r));
      Point center = area.getCenter();

      if (scale != null) {
        scale.setBounds(area);
      }

      if (ramp != null && ramp.isVisible()) {
        Rectangle rampBounds = area.getCopy();
        ramp.setBounds(
            rampBounds.shrink(
                area.width / 4 - ramp.getRampWidth(), area.height / 4 - ramp.getRampWidth()));
      }

      if (valueLabel != null) {
        Dimension labelSize = valueLabel.getPreferredSize();
        valueLabel.setBounds(
            new Rectangle(
                area.x + area.width / 2 - labelSize.width / 2,
                area.y
                    + area.height / 2
                    - area.height / 4
                    - (scale.getInnerRadius() - area.height / 4) / 2
                    - labelSize.height / 2,
                labelSize.width,
                labelSize.height));
      }

      if (needle != null && scale != null) {
        needlePoints.setPoint(
            new Point(center.x + area.width / 4, center.y - NEEDLE_WIDTH / 2 + 3), 0);
        scale.getScaleTickMarks();
        needlePoints.setPoint(
            new Point(center.x + scale.getInnerRadius() - GAP_BTW_NEEDLE_SCALE, center.y), 1);
        needlePoints.setPoint(
            new Point(center.x + area.width / 4, center.y + NEEDLE_WIDTH / 2 - 3), 2);

        double valuePosition = 360 - scale.getValuePosition(getCoercedValue(), false);
        if (maximum > minimum) {
          if (value > maximum) valuePosition += 8;
          else if (value < minimum) valuePosition -= 8;
        } else {
          if (value > minimum) valuePosition -= 8;
          else if (value < maximum) valuePosition += 8;
        }
        needlePoints.setPoint(
            PointsUtil.rotate(needlePoints.getPoint(0), valuePosition, center), 0);
        needlePoints.setPoint(
            PointsUtil.rotate(needlePoints.getPoint(1), valuePosition, center), 1);
        needlePoints.setPoint(
            PointsUtil.rotate(needlePoints.getPoint(2), valuePosition, center), 2);
        needle.setPoints(needlePoints);
      }

      //			if(needleCenter != null){
      //				needleCenter.setBounds(new Rectangle(center.x - area.width/4,
      //						center.y - area.height/4,
      //						area.width/2, area.height/2));
      //			}

    }
Beispiel #10
0
/**
 * A class to keep miscellaneous palette color utilities.
 *
 * @author crevells
 * @since 3.4
 */
public class PaletteColorUtil {

  public static final Color WIDGET_BACKGROUND = ColorConstants.button;

  public static final Color WIDGET_NORMAL_SHADOW = ColorConstants.buttonDarker;

  public static final Color WIDGET_DARK_SHADOW = ColorConstants.buttonDarkest;

  public static final Color WIDGET_LIST_BACKGROUND = ColorConstants.listBackground;

  public static final Color INFO_FOREGROUND = ColorConstants.tooltipForeground;

  public static final Color ARROW_HOVER = new Color(null, 229, 229, 219);

  private static final Color HOVER_COLOR = new Color(null, 252, 228, 179);

  private static final Color SELECTED_COLOR = new Color(null, 207, 227, 250);

  private static final Color HOVER_COLOR_HICONTRAST = new Color(null, 0, 128, 0);

  private static final Color SELECTED_COLOR_HICONTRAST = new Color(null, 128, 0, 128);

  public static final Color WIDGET_BACKGROUND_LIST_BACKGROUND_40 =
      FigureUtilities.mixColors(
          PaletteColorUtil.WIDGET_BACKGROUND, PaletteColorUtil.WIDGET_LIST_BACKGROUND, 0.4);

  public static final Color WIDGET_BACKGROUND_LIST_BACKGROUND_60 =
      FigureUtilities.mixColors(
          PaletteColorUtil.WIDGET_BACKGROUND, PaletteColorUtil.WIDGET_LIST_BACKGROUND, 0.6);

  public static final Color WIDGET_BACKGROUND_LIST_BACKGROUND_85 =
      FigureUtilities.mixColors(
          PaletteColorUtil.WIDGET_BACKGROUND, PaletteColorUtil.WIDGET_LIST_BACKGROUND, 0.85);

  public static final Color WIDGET_BACKGROUND_LIST_BACKGROUND_90 =
      FigureUtilities.mixColors(
          PaletteColorUtil.WIDGET_BACKGROUND, PaletteColorUtil.WIDGET_LIST_BACKGROUND, 0.9);

  public static final Color WIDGET_BACKGROUND_NORMAL_SHADOW_40 =
      FigureUtilities.mixColors(
          PaletteColorUtil.WIDGET_BACKGROUND, PaletteColorUtil.WIDGET_NORMAL_SHADOW, 0.4);

  public static final Color WIDGET_BACKGROUND_NORMAL_SHADOW_45 =
      FigureUtilities.mixColors(
          PaletteColorUtil.WIDGET_BACKGROUND, PaletteColorUtil.WIDGET_NORMAL_SHADOW, 0.45);

  public static final Color WIDGET_BACKGROUND_NORMAL_SHADOW_65 =
      FigureUtilities.mixColors(
          PaletteColorUtil.WIDGET_BACKGROUND, PaletteColorUtil.WIDGET_NORMAL_SHADOW, 0.65);

  public static final Color WIDGET_BACKGROUND_NORMAL_SHADOW_70 =
      FigureUtilities.mixColors(
          PaletteColorUtil.WIDGET_BACKGROUND, PaletteColorUtil.WIDGET_NORMAL_SHADOW, 0.7);

  public static final Color WIDGET_BACKGROUND_NORMAL_SHADOW_80 =
      FigureUtilities.mixColors(
          PaletteColorUtil.WIDGET_BACKGROUND, PaletteColorUtil.WIDGET_NORMAL_SHADOW, 0.8);

  public static final Color WIDGET_BACKGROUND_NORMAL_SHADOW_90 =
      FigureUtilities.mixColors(
          PaletteColorUtil.WIDGET_BACKGROUND, PaletteColorUtil.WIDGET_NORMAL_SHADOW, 0.9);

  public static final Color WIDGET_BACKGROUND_NORMAL_SHADOW_95 =
      FigureUtilities.mixColors(
          PaletteColorUtil.WIDGET_BACKGROUND, PaletteColorUtil.WIDGET_NORMAL_SHADOW, 0.95);

  /**
   * Gets the color to be used when hovering over palette items. The color differs in high contrast
   * mode.
   *
   * @return the hover color
   * @since 3.4
   */
  public static Color getHoverColor() {
    Display display = Display.getCurrent();
    if (display == null) {
      display = Display.getDefault();
    }
    if (display.getHighContrast()) {
      return HOVER_COLOR_HICONTRAST;
    }
    return HOVER_COLOR;
  }

  /**
   * Gets the color to be used when selecting palette items. The color differs in high contrast
   * mode.
   *
   * @return the selected color
   * @since 3.4
   */
  public static Color getSelectedColor() {
    Display display = Display.getCurrent();
    if (display == null) {
      display = Display.getDefault();
    }
    if (display.getHighContrast()) {
      return SELECTED_COLOR_HICONTRAST;
    }
    return SELECTED_COLOR;
  }
}
 private static int getFontHeight(Font f) {
   FontMetrics fm = FigureUtilities.getFontMetrics(f);
   return fm.getHeight();
 }
Beispiel #12
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);
    }
  }