Example #1
0
  /**
   * 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);
  }
Example #2
0
  /** Render a visual representation of the given edge. */
  public Connector render(Object edge, Site tailSite, Site headSite) {
    // FIXME: Find a way to set the curvature (the third argument).
    ArcConnector c = new ArcConnector(tailSite, headSite);
    Arrowhead arrow = new Arrowhead(headSite.getX(), headSite.getY(), headSite.getNormal());
    c.setHeadEnd(arrow);

    Object p = "edge"; // edge.getProperty("label");
    String label = p.toString();
    LabelFigure labelFigure = new LabelFigure(label);
    String fontname = labelFigure.getFont().getFontName();
    labelFigure.setFont(new Font(fontname, Font.ITALIC, 14));
    c.setLabelFigure(labelFigure);
    return c;
  }
Example #3
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;
  }
Example #4
0
  /**
   * Create a new Diva figure that visually represents this icon. The figure will be an instance of
   * LabelFigure that renders the values of the attributes of the container.
   *
   * @return A new CompositeFigure consisting of the label.
   */
  public Figure createFigure() {
    CompositeFigure result = (CompositeFigure) super.createFigure();
    String truncated = _displayString();

    // If there is no string to display now, then create a string
    // with a single blank.
    if (truncated == null) {
      truncated = " ";
    }

    // NOTE: This violates the Diva MVC architecture!
    // This attribute is part of the model, and should not have
    // a reference to this figure.  By doing so, it precludes the
    // possibility of having multiple views on this model.
    LabelFigure label = new LabelFigure(truncated, _labelFont, 1.0, SwingConstants.CENTER);
    Rectangle2D backBounds = result.getBackgroundFigure().getBounds();
    label.translateTo(backBounds.getCenterX(), backBounds.getCenterY());
    result.add(label);

    _addLiveFigure(label);
    return result;
  }