コード例 #1
0
ファイル: ActorNameIcon.java プロジェクト: ptII/ptII
  /**
   * Create a new background figure. This overrides the base class to with a different display
   * height and hides the name of the container if it exists.
   *
   * @return A new figure.
   */
  public Figure createBackgroundFigure() {
    String displayString = _displayString();
    double width = 60;
    double height = 30;

    if (displayString != null) {
      // Measure width of the text.  Unfortunately, this
      // requires generating a label figure that we will not use.
      LabelFigure label = new LabelFigure(displayString, _labelFont, 1.0, SwingConstants.CENTER);
      Rectangle2D stringBounds = label.getBounds();

      // NOTE: Padding of 20. Quantize the height so that
      // snap to grid still works.
      width = Math.floor(stringBounds.getWidth()) + 20;
      height = Math.floor(stringBounds.getHeight()) + 20;

      // If the container name exists, hide it.
      if (displayString.trim().length() > 0) {
        try {
          SingletonParameter hideName = new SingletonParameter(this.getContainer(), "_hideName");
          hideName.setExpression("true");
        } catch (Exception e) {
          // Do nothing.
        }
      }
    }

    return new BasicRectangle(0, 0, width, height, Color.white, 1);
  }
コード例 #2
0
  /**
   * Create a new background figure. This overrides the base class to draw a box around the value
   * display, where the width of the box depends on the value.
   *
   * @return A new figure.
   */
  public Figure createBackgroundFigure() {
    String displayString = _displayString();
    double width = 60;
    double heigth = 30;

    if (displayString != null) {
      // Measure width of the text.  Unfortunately, this
      // requires generating a label figure that we will not use.
      LabelFigure label = new LabelFigure(displayString, _labelFont, 1.0, SwingConstants.CENTER);
      Rectangle2D stringBounds = label.getBounds();

      // NOTE: Padding of 20.
      width = stringBounds.getWidth() + 20;
      heigth = stringBounds.getHeight() + 10;
    }

    BasicRectangle result = new BasicRectangle(0, 0, width, heigth, Color.white, 1);

    // FIXME: Doesn't do the right thing.
    // result.setCentered(false);
    return result;
  }