Пример #1
0
  /**
   * Find a picture with the given URL in the panel. This should really only be used to discover if
   * the picture is still visible. There could be more than one picture with the given URL because
   * it may be partially obscured by another picture, in which case the pieces are each given their
   * own picture object, but all point at the same <code>URL</code> and <code>Image</code>.
   *
   * @param url The url to locate.
   * @return The first picture encountered in the panel, or null if the picture was not found.
   */
  public Picture find(final String url) {
    Enumeration enumeration;
    Picture picture;
    Picture ret;

    ret = null;
    enumeration = mMosaic.getPictures();
    while ((null == ret) && enumeration.hasMoreElements()) {
      picture = (Picture) enumeration.nextElement();
      if (url.equals(picture.getURL().toExternalForm())) ret = picture;
    }

    return (ret);
  }
Пример #2
0
  /**
   * Paints this component. Runs through the list of tiles and for every one that intersects the
   * clip region performs a <code>drawImage()</code>.
   *
   * @param graphics The graphics context used to paint with.
   */
  public void paint(final Graphics graphics) {
    Rectangle clip;
    Enumeration enumeration;
    HashSet set; // just so we don't draw things twice
    Picture picture;
    Image image;
    Point origin;
    int width;
    int height;

    adjustClipForInsets(graphics);
    clip = graphics.getClipBounds();
    synchronized (mMosaic) {
      if (0 == mMosaic.getSize()) super.paint(graphics);
      else {
        super.paint(graphics);
        enumeration = mMosaic.getPictures();
        set = new HashSet();
        while (enumeration.hasMoreElements()) {
          picture = (Picture) enumeration.nextElement();
          if ((null == clip) || (clip.intersects(picture))) {
            image = picture.getImage();
            if (!set.contains(image)) {
              origin = picture.getOrigin();
              width = image.getWidth(this);
              height = image.getHeight(this);
              graphics.drawImage(
                  picture.getImage(),
                  origin.x,
                  origin.y,
                  origin.x + width,
                  origin.y + height,
                  0,
                  0,
                  width,
                  height,
                  this);
              set.add(image);
            }
          }
        }
      }
    }
  }
Пример #3
0
  /**
   * Compute the preferred size of the component. Computes the minimum bounding rectangle covering
   * all the pictures in the panel. It then does some funky stuff to handle embedding in the view
   * port of a scroll pane, basically asking up the ancestor heirarchy what size is available, and
   * filling it.
   *
   * @return The optimal dimension for this component.
   */
  protected Dimension calculatePreferredSize() {
    Enumeration enumeration;
    int x;
    int y;
    Picture picture;
    Component parent;
    Insets insets;
    Dimension ret;

    enumeration = mMosaic.getPictures();
    x = 0;
    y = 0;
    picture = null;
    while (enumeration.hasMoreElements()) {
      picture = (Picture) enumeration.nextElement();
      if (picture.x + picture.width > x) x = picture.x + picture.width;
      if (picture.y + picture.height > y) y = picture.y + picture.height;
    }
    parent = getParent();
    if (parent instanceof JViewport) {
      ret = parent.getSize();
      insets = ((JViewport) parent).getInsets();
      ret.width -= insets.left + insets.right;
      ret.height -= insets.top + insets.bottom;
      if ((0 != ret.width) || (0 != ret.height))
        ret.width -= 2; // ... I dunno why, it just needs it
      if (ret.width < x) ret.width = x;
      if (ret.height < y) ret.height = y;
    } else {
      insets = getInsets();
      x += insets.left + insets.right;
      y += insets.top + insets.bottom;
      ret = new Dimension(x, y);
    }

    return (ret);
  }