/**
  * Sets the name.
  *
  * @param name the new name
  */
 @Override
 public void setName(String name) {
   text.setText(name);
   textFigure.setSize(width, 10);
   text.setSize(width, 10);
   text.setLocation(getLocation());
   textFigure.setLocation(getLocation());
 }
  /**
   * Instantiates a new node figure.
   *
   * @param name the name
   * @param width the weight
   */
  public SimpleNodeFigure(Node node, int width, MouseListener mouseListener) {
    super();

    this.node = node;

    LineBorder b = new LineBorder();
    b.setColor(NodeUtil.FG_COLOR);
    setBorder(b);

    textFigure = new RectangleFigure();
    text = new Label(getNodeName());
    text.setForegroundColor(NodeUtil.FG_COLOR_DARK);

    setSize(width, 10);

    textFigure.add(text);

    hideButton = new RectangleFigure();

    hideSymbol = new Label(getSymbol());
    hideSymbol.setSize(10, 10);
    hideSymbol.setTextAlignment(PositionConstants.CENTER);

    hideSymbol.setFont(hideButtonFont);
    hideSymbol.setForegroundColor(NodeUtil.FG_COLOR_DARK);
    hideButton.add(hideSymbol);
    hideButton.setBackgroundColor(exitClor);
    hideButton.addMouseListener(mouseListener);
    hideButton.addMouseMotionListener(
        new MouseMotionListener() {

          @Override
          public void mouseMoved(MouseEvent me) {}

          @Override
          public void mouseHover(MouseEvent me) {}

          @Override
          public void mouseExited(MouseEvent me) {
            hideButton.setBackgroundColor(exitClor);
          }

          @Override
          public void mouseEntered(MouseEvent me) {
            hideButton.setBackgroundColor(entredClor);
          }

          @Override
          public void mouseDragged(MouseEvent me) {}
        });
    hideButton.setSize(10, 10);

    setLayoutManager(new XYLayout());

    add(textFigure);
  }
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.draw2d.Figure#repaint()
   */
  @Override
  public void repaint() {
    int x = getLocation().x;
    int y = getLocation().y;

    if (collapsing) {
      width = Constants.SIZE_16;
      height = Constants.SIZE_18;
      getBounds().height = height;
      getBounds().width = width;
    } else {

      if (hideButton != null) {

        if (hide) {
          super.setSize(width, 18);
        } else {
          super.setSize(width, height);
        }
        textFigure.setSize(width, 10);
        text.setSize(width, 15);
        text.setLocation(new Point(x, y));

        if (getChildren().size() > 1) {
          if (!textFigure.getChildren().contains(hideButton)) {
            textFigure.add(hideButton);
          }
          hideButton.setLocation(new Point(x + width - 11, y + 1));
        } else {
          if (textFigure.getChildren().contains(hideButton)) {
            textFigure.remove(hideButton);
          }
        }
      }

      for (int i = 0; i < getChildren().size(); i++) {
        IFigure figure = (IFigure) getChildren().get(i);

        if (figure == textFigure || hide) {
          figure.setSize(width, 16);
          figure.setLocation(new Point(x, y));
        } else {
          figure.setSize(width - 5, 15);
          figure.setLocation(new Point(x + 5, y + 16 + 15 * i));
        }
      }
    }

    super.repaint();
  }
예제 #4
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);
    }
  }