/*
   * (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();
  }
    @Override
    public void relocate(IFigure target) {
      Rectangle bounds;
      if (reference instanceof HandleBounds) {
        bounds = new PrecisionRectangle(((HandleBounds) reference).getHandleBounds());
      } else {
        bounds = new PrecisionRectangle(reference.getBounds());
        // authorized rectangle without handle bounds is smaller: if the icon would be exactly on
        // one of the corners,
        // it would trigger an enlargement of the figure, followed by a reposition, i.e. an endless
        // loop.
        bounds.x++;
        bounds.y++;
        bounds.width -= 2;
        bounds.height -= 2;
      }

      reference.translateToAbsolute(bounds);
      target.translateToRelative(bounds);

      Point pTR = bounds.getTopRight();
      Point pTL = bounds.getTopLeft();
      Point pDecoration = new Point(pTR);

      int decorationX = pTR.x - target.getSize().width - rightMargin;
      if (decorationX > pTL.x) {
        // only set position, if it is inside the figure, i.e. bigger than left margin
        pDecoration.setX(decorationX);
      } else {
        pDecoration.setX(pTL.x);
      }
      target.setLocation(pDecoration);
    }
예제 #3
0
 /*
  * (non-Javadoc)
  *
  * @see org.xmind.ui.tools.DummyCreateTool#doCreateDummy()
  */
 protected IFigure doCreateDummy() {
   if (branchDummy == null) {
     branchDummy = new BranchDummy(getTargetViewer(), true);
     branchDummy.getTopic().setTitleText(MindMapMessages.TitleText_FloatingTopic);
     pack();
   }
   IFigure figure = branchDummy.getBranch().getFigure();
   if (getCursorPosition() != null) {
     if (figure instanceof IReferencedFigure) {
       ((IReferencedFigure) figure).setReference(getCursorPosition());
     } else {
       Dimension size = figure.getSize();
       figure.setLocation(getCursorPosition().getTranslated(-size.width / 2, -size.height / 2));
     }
   }
   return figure;
 }