Ejemplo n.º 1
0
  /**
   * Create thumbnail for the image.
   *
   * @param image to scale.
   * @return the thumbnail image.
   */
  private static BufferedImage createThumbnail(BufferedImage image) {
    int width = image.getWidth();
    int height = image.getHeight();

    // Image smaller than the thumbnail size
    if (width < THUMB_WIDTH && height < THUMB_HEIGHT) return image;

    Image i;

    if (width > height) i = image.getScaledInstance(THUMB_WIDTH, -1, Image.SCALE_SMOOTH);
    else i = image.getScaledInstance(-1, THUMB_HEIGHT, Image.SCALE_SMOOTH);

    return ImageUtils.getBufferedImage(i);
  }
Ejemplo n.º 2
0
  /**
   * Action performed on various action links(buttons).
   *
   * @param e the action.
   */
  public void actionPerformed(ActionEvent e) {
    JButton src = (JButton) e.getSource();

    if (src instanceof SIPCommButton) {
      // Load image
      int index = Integer.parseInt(src.getName());
      BufferedImage image = AvatarStackManager.loadImage(index);

      // Set the new image
      setNewImage(image);
    } else if (src.getName().equals("chooseButton")) {
      // Open the image picker
      Image currentImage = this.avatarImage.getAvatar();

      ImagePickerDialog dialog = new ImagePickerDialog(96, 96);

      byte[] bimage = dialog.showDialog(currentImage);

      if (bimage == null) return;

      // New image
      BufferedImage image = ImageUtils.getBufferedImage(new ImageIcon(bimage).getImage());

      // Store image
      if (this.nextImageIndex == MAX_STORED_IMAGES) {
        // No more place to store images
        // Pop the first element (index 0)
        AvatarStackManager.popFirstImage(MAX_STORED_IMAGES);

        this.nextImageIndex = MAX_STORED_IMAGES - 1;
      }

      // Store the new image on hard drive
      AvatarStackManager.storeImage(image, this.nextImageIndex);

      // Inform protocols about the new image
      setNewImage(image);
    } else if (src.getName().equals("removeButton")) {
      // Removes the current photo.
      setNewImage(null);
    } else if (src.getName().equals("clearButton")) {
      clearRecentImages();
    }

    setVisible(false);
  }