Beispiel #1
0
 /**
  * Gets an Image.
  *
  * @return the image
  */
 public Image getImage() {
   ImageIcon icon = getIcon();
   if (icon != null) {
     return icon.getImage();
   }
   return null;
 }
 public void squish(Graphics g, ImageIcon icon, int x, int y, double scale) {
   if (isVisible()) {
     g.drawImage(
         icon.getImage(),
         x,
         y,
         (int) (icon.getIconWidth() * scale),
         (int) (icon.getIconHeight() * scale),
         this);
   }
 }
 public void loadImage(File f) {
   if (f == null) {
     thumbnail = null;
   } else {
     ImageIcon tmpIcon = new ImageIcon(f.getPath());
     if (tmpIcon.getIconWidth() > 90) {
       thumbnail =
           new ImageIcon(tmpIcon.getImage().getScaledInstance(90, -1, Image.SCALE_DEFAULT));
     } else {
       thumbnail = tmpIcon;
     }
   }
 }
  public void paint(Graphics g) {
    super.paint(g);
    if (thumbnail != null) {
      int x = getWidth() / 2 - thumbnail.getIconWidth() / 2;
      int y = getHeight() / 2 - thumbnail.getIconHeight() / 2;
      if (y < 0) {
        y = 0;
      }

      if (x < 5) {
        x = 5;
      }
      thumbnail.paintIcon(this, g, x, y);
    }
  }
Beispiel #5
0
 /**
  * Gets an ImageIcon.
  *
  * @return the icon
  */
 public ImageIcon getIcon() {
   if (icon == null && isAnImage) {
     icon = new ImageIcon(getURL());
     if (icon.getIconWidth() < 1) {
       icon = null;
       isAnImage = false;
     }
   }
   return icon;
 }