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); } }
public void paintComponent(Graphics g) { super.paintComponent(g); if (placer != null && index >= 0) { Dimension dim = placer.getModel().getSizeOf(index); ImageIcon icon, scaled_icon; // XXX: Come up with a cleaner way to do this. if (((ConfigElement) placer.getModel().getElement(index)) .getDefinition() .getToken() .equals(SURFACE_VIEWPORT_TYPE)) { icon = surfaceIcon; scaled_icon = scaledSurfaceIcon; } else { icon = simIcon; scaled_icon = scaledSimIcon; } // Check if we need to update the scaled image Image img = scaled_icon.getImage(); if ((scaled_icon.getIconWidth() != dim.width) || (scaled_icon.getIconHeight() != dim.height)) { img = icon.getImage().getScaledInstance(dim.width, dim.height, Image.SCALE_DEFAULT); scaled_icon.setImage(img); } // Sanity check in case our scale failed if (img != null) { g.drawImage(img, 0, 0, null); } // Highlight the window nicely if (selected) { g.setColor(getBackground()); } else { g.setColor(Color.white); } g.drawRect(0, 0, dim.width - 1, dim.height - 1); g.fillRect(0, 0, dim.width, 3); } }
public Dimension getPreferredSize() { return new Dimension(1 + image.getIconWidth(), 1 + image.getIconHeight()); }