Ejemplo n.º 1
0
  /**
   * Update the size of the preview according to the size of the node
   *
   * @param parent the parent container of the node preview
   */
  public void updateSize(Container parent) {
    if ((node != null) && (parent.getGraphics() != null)) {
      this.node.updateBounds(parent.getGraphics());
      int w = this.node.getBounds().width + 32;
      int h = this.node.getBounds().height + 32;

      if (w > MIN_WIDTH) {
        if (h > MIN_HEIGHT) {
          this.setSize(new Dimension(w, h));
          this.node.setLocation(16, 16);
        } else {
          this.setSize(new Dimension(w, MIN_HEIGHT));
          this.node.setLocation(16, (MIN_HEIGHT - (h - 32)) / 2);
        }
      } else {
        if (h > MIN_HEIGHT) {
          this.setSize(new Dimension(MIN_WIDTH, h));
          this.node.setLocation((MIN_WIDTH - (w - 32)) / 2, 16);
        } else {
          this.setSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
          this.node.setLocation((MIN_WIDTH - (w - 32)) / 2, (MIN_HEIGHT - (h - 32)) / 2);
        }
      }
    } else this.setSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));

    this.repaint();
  }