public static Image scaledImage (Image image, int maxIconSize) { if (image == null) { return image; } ImageIcon icon = (ImageIcon)scaledIcon(new ImageIcon(image), maxIconSize); return icon.getImage(); }
public static JComponent fix (JComponent component, int size) { return fix(new JComponent[]{component}, size)[0]; }
/*************************************************************************** * * Returns an Image given its name. The icon is searched in the 'icons' * subfolder of the folder related to this package. * * @param iconName the name of the resource * @return the image * **************************************************************************/ protected Image findIcon (final String iconName) { return IconResizer.scaledImage(ImageUtilities.loadImage(basePath + iconName), ICON_SIZE); } }
@Override @Nonnull public Image getIcon (final int type) { final GeoCoderEntity geoCoderEntity = delegate.getLookup().lookup(GeoCoderEntity.class); Image image = null; if (geoCoderEntity != null) { final String code = geoCoderEntity.getCode(); if (geoCoderEntity.getType() == GeoCoderEntity.Type.COUNTRY) { image = ImageUtilities.loadImage("it/tidalwave/geo/node/flagsoftheworld/impl/icons/" + code + ".png"); if (image != null) { image = IconResizer.scaledImage(image, 16); } } else { final Node parentNode = getParentNode(); if (parentNode != null) { image = parentNode.getIcon(type); } } } return (image != null) ? image : delegate.getIcon(type); } }
public ResizableIcon (final @Nonnull Icon delegate, final @Nonnegative int defaultSize) { this.original = delegate; this.delegate = IconResizer.scaledIcon(original, defaultSize); }
@Nonnull public Icon resized (final @Nonnegative int size) { return IconResizer.scaledIcon(delegate, size); } }
@Override @Nonnull public synchronized Icon getIcon (final @Nonnegative int size) { Icon icon = iconCacheBySize.get(size); if (icon == null) { icon = IconResizer.scaledIcon(baseIcon, size); iconCacheBySize.put(size, icon); } return icon; } }
public static JComponent[] fix (JComponent[] components, int size) { for (int i = 0; i < components.length; i++) { if (components[i] instanceof AbstractButton) { AbstractButton button = (AbstractButton)components[i]; if (button.getIcon() != null) { button.setIcon(scaledIcon(button.getIcon(), size)); } if (button.getDisabledIcon() != null) { button.setDisabledIcon(scaledIcon(button.getDisabledIcon(), size)); } } } return components; }