Java Code Examples for com.alee.utils.ImageUtils

The following examples show how to use com.alee.utils.ImageUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: weblaf   Source File: AlphaLayerBackground.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns new {@link BufferedImage} containg alpha background texture of the specified size and colors.
 *
 * @param size       {@link Dimension} of a single cell, texture size will be double of this
 * @param darkColor  dark cells {@link Color}
 * @param lightColor light cells {@link Color}
 * @return new {@link BufferedImage} containg alpha background texture of the specified size and colors
 */
@NotNull
public static BufferedImage createAlphaBackgroundTexture ( @NotNull final Dimension size, @NotNull final Color darkColor,
                                                           @NotNull final Color lightColor )
{
    final BufferedImage image = ImageUtils.createCompatibleImage ( size.width * 2, size.height * 2, Transparency.OPAQUE );
    final Graphics2D g2d = image.createGraphics ();

    g2d.setPaint ( darkColor );
    g2d.fillRect ( 0, 0, size.width, size.height );
    g2d.fillRect ( size.width, size.height, size.width, size.height );

    g2d.setPaint ( lightColor );
    g2d.fillRect ( size.width, 0, size.width, size.height );
    g2d.fillRect ( 0, size.height, size.width, size.height );

    g2d.dispose ();
    return image;
}
 
Example 2
Source Project: weblaf   Source File: ThumbnailGenerator.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns thumbnail for image from the specified {@link File}.
 * Note that this method will generate {@link Icon} with a static image, so any GIF or other animated images will be static.
 *
 * @param file file to generate thumbnail for
 * @return thumbnail for image from the specified {@link File}
 */
@Nullable
protected Icon createThumbnailIcon ( @NotNull final File file )
{
    Icon thumbnail;
    try
    {
        final BufferedImage bufferedImage = ImageUtils.loadBufferedImage ( new FileResource ( file ) );
        final BufferedImage previewImage = ImageUtils.createImageThumbnail ( bufferedImage, Math.min ( size.width, size.height ) );
        final ImageIcon previewIcon = new ImageIcon ( previewImage );
        previewIcon.setDescription ( previewImage.getWidth () + "x" + previewImage.getHeight () );
        thumbnail = previewIcon;
    }
    catch ( final Exception e )
    {
        thumbnail = null;
    }
    return thumbnail;
}
 
Example 3
Source Project: weblaf   Source File: ThumbnailGenerator.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Applies generated thumbnail to the element.
 *
 * @param thumbnail thumbnail icon
 */
protected void applyThumbnail ( @NotNull final Icon thumbnail )
{
    if ( !aborted )
    {
        // Applying custom generated thumbnail icon
        synchronized ( element.getLock () )
        {
            if ( element.isThumbnailQueued () )
            {
                // We had to check that queue wasn't cancelled from outside
                element.setEnabledThumbnail ( thumbnail );
            }
        }
        if ( !aborted && disabled )
        {
            // Re-using enabled state thumbnail to generate disabled state one
            final Icon disabledThumbnail = ImageUtils.createDisabledCopy ( thumbnail );
            if ( !aborted && element.isDisabledThumbnailQueued () )
            {
                // We had to check that queue wasn't cancelled from outside
                element.setDisabledThumbnail ( disabledThumbnail );
            }
        }
    }
}
 
Example 4
@Override
public boolean filesDropped ( @NotNull final List<File> files )
{
    boolean added = false;
    if ( gallery != null )
    {
        for ( final File file : files )
        {
            if ( ImageUtils.isImageSupported ( file.getName () ) )
            {
                gallery.addImage ( new ImageIcon ( file.getAbsolutePath () ) );
                added = true;
            }
        }
    }
    return added;
}
 
Example 5
Source Project: weblaf   Source File: ImagePainter.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns preview image for specified insets.
 *
 * @param insets image component insets
 * @param image  image to preview
 * @return preview image
 */
@NotNull
protected BufferedImage getPreviewImage ( @NotNull final BufferedImage image, @NotNull final Insets insets )
{
    final BufferedImage preview;
    final Dimension size = SwingUtils.shrink ( component.getSize (), insets );
    if ( image.getWidth () > size.width || image.getHeight () > size.height )
    {
        if ( lastPreviewImage == null || lastDimension != null && !lastDimension.equals ( size ) )
        {
            if ( lastPreviewImage != null )
            {
                lastPreviewImage.flush ();
                lastPreviewImage = null;
            }
            lastPreviewImage = ImageUtils.createImageThumbnail ( image, size );
            lastDimension = size;
        }
        preview = lastPreviewImage;
    }
    else
    {
        preview = image;
    }
    return preview;
}
 
Example 6
Source Project: weblaf   Source File: WebImageDrop.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Updates image preview.
 */
protected void updatePreview ()
{
    if ( image != null )
    {
        // Creating image preview
        image = ImageUtils.createImageThumbnail ( actualImage, width, height );

        // Restore decoration
        final BufferedImage f = ImageUtils.createCompatibleImage ( image.getWidth (), image.getHeight (), Transparency.TRANSLUCENT );
        final Graphics2D g2d = f.createGraphics ();
        GraphicsUtils.setupAntialias ( g2d );
        g2d.setPaint ( Color.WHITE );
        g2d.fillRoundRect ( 0, 0, image.getWidth (), image.getHeight (), round * 2, round * 2 );
        g2d.setComposite ( AlphaComposite.getInstance ( AlphaComposite.SRC_IN ) );
        g2d.drawImage ( image, 0, 0, null );
        g2d.dispose ();

        image.flush ();
        image = f;
    }
}
 
Example 7
private void chooseImage() {
    int state = mImgChooser.showOpenDialog(this);
    if (state != WebFileChooser.APPROVE_OPTION)
        return;

    File imgFile = mImgChooser.getSelectedFile();
    if (!imgFile.isFile())
        return;

    BufferedImage img = MediaUtils.readImage(imgFile).orElse(null);
    if (img == null)
        return;

    this.changeImage(ImageUtils.createPreviewImage(img, mSize));
}
 
Example 8
Source Project: weblaf   Source File: LazyIcon.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns disabled copy of original {@link Icon}.
 *
 * @return disabled copy of original {@link Icon}
 */
@NotNull
@Override
public Icon createDisabledCopy ()
{
    return ImageUtils.getDisabledCopy ( getIcon () );
}
 
Example 9
Source Project: weblaf   Source File: LazyIcon.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns semi-transparent copy of original {@link Icon}.
 *
 * @return semi-transparent copy of original {@link Icon}
 */
@NotNull
@Override
public Icon createTransparentCopy ( final float opacity )
{
    return ImageUtils.getTransparentCopy ( getIcon (), opacity );
}
 
Example 10
Source Project: weblaf   Source File: SimpleDragViewHandler.java    License: GNU General Public License v3.0 5 votes vote down vote up
@NotNull
@Override
public BufferedImage getView ( @NotNull final T object, @NotNull final DragSourceDragEvent event )
{
    final Icon icon = getIcon ( object );
    final Color foreground = getForeground ( object );
    final String title = LM.get ( getText ( object ) );

    final FontMetrics fm = getFontMetrics ( object );
    final int tm = margin.left + ( icon != null ? icon.getIconWidth () + 4 : textSideSpacing );
    final int em = margin.right + textSideSpacing;
    final int w = tm + fm.stringWidth ( title ) + em;
    final int h = margin.top + Math.max ( icon != null ? icon.getIconHeight () : 0, fm.getHeight () ) + margin.bottom;

    final BufferedImage image = ImageUtils.createCompatibleImage ( w, h, Transparency.TRANSLUCENT );
    final Graphics2D g2d = image.createGraphics ();
    GraphicsUtils.setupAlphaComposite ( g2d, 0.8f );
    GraphicsUtils.setupFont ( g2d, fm.getFont () );
    SwingUtils.setupTextAntialias ( g2d, TextRasterization.subpixel );
    g2d.setPaint ( Color.WHITE );
    g2d.fillRect ( 0, 0, w, h );
    g2d.setPaint ( Color.LIGHT_GRAY );
    g2d.drawRect ( 0, 0, w - 1, h - 1 );
    if ( icon != null )
    {
        icon.paintIcon ( null, g2d, margin.left, margin.top );
    }
    g2d.setPaint ( foreground != null ? foreground : Color.BLACK );
    g2d.drawString ( title, tm, margin.top + ( h - margin.top - margin.bottom ) / 2 + LafUtils.getTextCenterShiftY ( fm ) );
    g2d.dispose ();
    return image;
}
 
Example 11
Source Project: weblaf   Source File: ExpandingShadow.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns newly created shadow {@link NinePatchIcon}.
 *
 * @param bounds  {@link NinePatchIcon} bounds
 * @param width   shadow width
 * @param opacity shadow opacity
 * @return newly created shadow {@link NinePatchIcon}
 */
@NotNull
protected NinePatchIcon createShadowIcon ( @NotNull final Rectangle bounds, final int width, final float opacity )
{
    // Creating shadow pattern
    final GeneralPath gp = new GeneralPath ( GeneralPath.WIND_EVEN_ODD );
    gp.moveTo ( bounds.x + width * 1.2, bounds.y + width * 1.2 );
    gp.lineTo ( bounds.x + bounds.width - width * 1.2, bounds.y + width * 1.2 );
    gp.lineTo ( bounds.x + bounds.width - width, bounds.y + bounds.height - width * 0.5 );
    gp.quadTo ( bounds.x + bounds.width / 2, bounds.y + bounds.height - width * 1.9,
            bounds.x + width, bounds.y + bounds.height - width * 0.5 );
    gp.closePath ();

    // Creating shadow image
    final BufferedImage shadowImage = ImageUtils.createShadowImage ( bounds.width, bounds.height, gp, width, opacity, false );

    // Creating nine-patch icon based on shadow image
    final int w = shadowImage.getWidth ();
    final int inner = width / 2;
    final NinePatchIcon ninePatchIcon = new NinePatchIcon ( shadowImage, false );
    ninePatchIcon.addHorizontalStretch ( 0, width + inner, true );
    ninePatchIcon.addHorizontalStretch ( width + inner + 1, w - width - inner - 1, false );
    ninePatchIcon.addHorizontalStretch ( w - width - inner, w, true );
    ninePatchIcon.addVerticalStretch ( 0, width + inner, true );
    ninePatchIcon.addVerticalStretch ( width + inner + 1, w - width - inner - 1, false );
    ninePatchIcon.addVerticalStretch ( w - width - inner, w, true );
    ninePatchIcon.setMargin ( width );
    return ninePatchIcon;
}
 
Example 12
Source Project: weblaf   Source File: WebShadow.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns shadow image based on provided shape.
 *
 * @param bounds  shadow bounds
 * @param width   shadow width
 * @param opacity shadow opacity
 * @param color   shadow color
 * @param shape   shadow shape
 * @return shadow image based on provided shape
 */
@NotNull
public static BufferedImage createShadowImage ( @NotNull final Rectangle bounds, final int width, final float opacity,
                                                @NotNull final Color color, @NotNull final Shape shape )
{
    // Creating template image
    final BufferedImage bi = ImageUtils.createCompatibleImage ( bounds.width, bounds.height, Transparency.TRANSLUCENT );
    final Graphics2D ig = bi.createGraphics ();
    GraphicsUtils.setupAntialias ( ig );
    ig.translate ( -bounds.x, -bounds.y );
    ig.setPaint ( Color.BLACK );
    ig.fill ( shape );
    ig.dispose ();

    // Creating shadow image
    final ShadowFilter sf = new ShadowFilter ( width, 0, 0, opacity );
    sf.setShadowColor ( Color.BLACK.getRGB () );
    final BufferedImage shadow = sf.filter ( bi, null );

    // Clipping shadow image
    final Graphics2D g2d = shadow.createGraphics ();
    GraphicsUtils.setupAntialias ( g2d );
    g2d.translate ( -bounds.x, -bounds.y );
    g2d.setComposite ( AlphaComposite.getInstance ( AlphaComposite.SRC_IN ) );
    g2d.setPaint ( ColorUtils.transparent () );
    g2d.fill ( shape );
    g2d.setPaint ( color );
    g2d.setComposite ( AlphaComposite.getInstance ( AlphaComposite.SRC_IN ) );
    g2d.fillRect ( 0, 0, bounds.width, bounds.height );
    g2d.dispose ();

    return shadow;
}
 
Example 13
Source Project: weblaf   Source File: WebShadow.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns inner shadow image based on provided shape.
 *
 * @param bounds  shadow bounds
 * @param width   shadow width
 * @param opacity shadow opacity
 * @param color   shadow color
 * @param shape   shadow shape
 * @return inner shadow image based on provided shape
 */
@NotNull
public static BufferedImage createInnerShadowImage ( @NotNull final Rectangle bounds, final int width, final float opacity,
                                                     @NotNull final Color color, @NotNull final Shape shape )
{
    final Rectangle b = new Rectangle ( bounds.x - width * 2, bounds.y - width * 2,
            bounds.width + width * 4, bounds.height + width * 4 );

    // Creating template image
    final BufferedImage bi = ImageUtils.createCompatibleImage ( b.width, b.height, Transparency.TRANSLUCENT );
    final Graphics2D ig = bi.createGraphics ();
    GraphicsUtils.setupAntialias ( ig );
    ig.translate ( -b.x, -b.y );
    final Area area = new Area ( new Rectangle ( b.x, b.y, b.width, b.height ) );
    area.exclusiveOr ( new Area ( shape ) );
    ig.setPaint ( Color.BLACK );
    ig.fill ( area );
    ig.dispose ();

    // Creating inner shadow image
    final ShadowFilter sf = new ShadowFilter ( width, 0, 0, opacity );
    sf.setShadowColor ( Color.BLACK.getRGB () );
    final BufferedImage shadow = sf.filter ( bi, null );

    // Clipping inner shadow image
    final Graphics2D g2d = shadow.createGraphics ();
    GraphicsUtils.setupAntialias ( g2d );
    g2d.translate ( -b.x, -b.y );
    g2d.setComposite ( AlphaComposite.getInstance ( AlphaComposite.SRC_IN ) );
    g2d.setPaint ( ColorUtils.transparent () );
    g2d.fill ( area );
    g2d.setPaint ( color );
    g2d.setComposite ( AlphaComposite.getInstance ( AlphaComposite.SRC_IN ) );
    g2d.fillRect ( 0, 0, b.width, b.height );
    g2d.dispose ();

    return shadow.getSubimage ( width * 2, width * 2, b.width - width * 4, b.height - width * 4 );
}
 
Example 14
Source Project: weblaf   Source File: ThumbnailGenerator.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Generates standard thumbnail for the specified {@link File}.
 *
 * @param file    {@link File} to generate standard thumbnail for
 * @param preview whether should create thumbnail for image from the specified {@link File}
 */
protected void createStandardThumbnail ( @NotNull final File file, final boolean preview )
{
    // Using either image thumbnails or default file extension icons
    if ( preview && ImageUtils.isImageSupported ( file.getName () ) )
    {
        // If thumbnail was already specified we should re-use it
        // It will save us a lot of time if we simply need to generate disabled state in addition to enabled one
        final Icon thumb = element.getEnabledThumbnail () != null ? element.getEnabledThumbnail () :
                createThumbnailIcon ( file );
        if ( thumb != null )
        {
            // Applying standard image thumbnail
            applyThumbnail ( thumb );
        }
        else
        {
            // Applying standard extension icon
            applyStandardIcon ( file );
        }
    }
    else
    {
        // Applying standard extension icon
        applyStandardIcon ( file );
    }
}
 
Example 15
Source Project: weblaf   Source File: MixedIcon.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns new {@link MixedIcon} with disabled copies of originally mixed {@link Icon}s.
 *
 * @return new {@link MixedIcon} with disabled copies of originally mixed {@link Icon}s
 */
@Override
@NotNull
public I createDisabledCopy ()
{
    final Icon[] disabled = new Icon[ icons.length ];
    for ( int i = 0; i < icons.length; i++ )
    {
        disabled[ i ] = ImageUtils.getDisabledCopy ( icons[ i ] );
    }
    return newInstance ( disabled );
}
 
Example 16
Source Project: weblaf   Source File: MixedIcon.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns new {@link MixedIcon} with semi-transparent copies of originally mixed {@link Icon}s.
 *
 * @return new {@link MixedIcon} with semi-transparent copies of originally mixed {@link Icon}s
 */
@Override
@NotNull
public I createTransparentCopy ( final float opacity )
{
    final Icon[] transparent = new Icon[ icons.length ];
    for ( int i = 0; i < icons.length; i++ )
    {
        transparent[ i ] = ImageUtils.getTransparentCopy ( icons[ i ], opacity );
    }
    return newInstance ( transparent );
}
 
Example 17
Source Project: weblaf   Source File: ImagePainter.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Updates cached disabled image.
 */
protected void calculateDisabledImage ()
{
    final BufferedImage image = component.getImage ();
    disabledImage = image != null ? ImageUtils.createDisabledCopy ( image ) : null;
    lastPreviewImage = null;
}
 
Example 18
Source Project: weblaf   Source File: WebFileChooser.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets custom dialog icons.
 *
 * @param customIcons new custom dialog icons
 */
public void setDialogIcons ( @NotNull final List<? extends Icon> customIcons )
{
    this.customIcons = new ArrayList<Image> ( customIcons.size () );
    for ( final Icon icon : customIcons )
    {
        final Image image = ImageUtils.toBufferedImage ( icon );
        this.customIcons.add ( image );
    }
    updateWindowIcons ();
}
 
Example 19
Source Project: weblaf   Source File: PaletteColorChooser.java    License: GNU General Public License v3.0 5 votes vote down vote up
private Cursor createLoopCursor ()
{
    final Dimension dimension = Toolkit.getDefaultToolkit ().getBestCursorSize ( 14, 14 );

    final BufferedImage bufferedImage =
            ImageUtils.createCompatibleImage ( dimension.width, dimension.height, Transparency.TRANSLUCENT );

    final Graphics2D g2d = bufferedImage.createGraphics ();
    g2d.drawImage ( LOOP_ICON.getImage (), 0, 0, LOOP_ICON.getImageObserver () );
    g2d.dispose ();

    return Toolkit.getDefaultToolkit ().createCustomCursor ( bufferedImage, new Point ( 7, 7 ), "Loop Cursor" );
}
 
Example 20
Source Project: weblaf   Source File: GifFrame.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns copy of this {@link GifFrame} with {@link #bufferedImage} made look disabled.
 *
 * @return copy of this {@link GifFrame} with {@link #bufferedImage} made look disabled
 */
@NotNull
@Override
public GifFrame createDisabledCopy ()
{
    return new GifFrame ( ImageUtils.createDisabledCopy ( bufferedImage ), delay );
}
 
Example 21
Source Project: weblaf   Source File: GifFrame.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns copy of this {@link GifFrame} with {@link #bufferedImage} made semi-transparent.
 *
 * @return copy of this {@link GifFrame} with {@link #bufferedImage} made semi-transparent
 */
@NotNull
@Override
public GifFrame createTransparentCopy ( final float opacity )
{
    return new GifFrame ( ImageUtils.createTransparentCopy ( bufferedImage, opacity ), delay );
}
 
Example 22
Source Project: weblaf   Source File: ImageIconSource.java    License: GNU General Public License v3.0 4 votes vote down vote up
@NotNull
@Override
public ImageIcon loadIcon ( @NotNull final Resource resource )
{
    return ImageUtils.loadImageIcon ( resource );
}
 
Example 23
Source Project: weblaf   Source File: NinePatchIcon.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructs new NinePatchIcon using the specified nine-patch image.
 *
 * @param image        {@link BufferedImage}
 * @param parsePatches whether or not information about patches should be parsed from the image
 */
public NinePatchIcon ( @NotNull final BufferedImage image, final boolean parsePatches )
{
    // Parsing patches or creating new 9-patch icon
    if ( parsePatches )
    {
        // Incorrect image
        if ( image.getWidth () < 3 || image.getHeight () < 3 )
        {
            throw new IllegalArgumentException ( "Buffered image must be atleast 3x3 pixels size" );
        }

        // Creating actual image in a compatible format
        final int w = image.getWidth () - 2;
        final int h = image.getHeight () - 2;
        rawImage = ImageUtils.createCompatibleImage ( w, h, image.getTransparency () );
        final Graphics2D g2d = rawImage.createGraphics ();
        g2d.drawImage ( image, 0, 0, w, h, 1, 1, image.getWidth () - 1, image.getHeight () - 1, null );
        g2d.dispose ();

        // Parsing stretch variables
        horizontalStretch = NinePatchUtils.parseIntervals ( image, NinePatchIntervalType.horizontalStretch );
        verticalStretch = NinePatchUtils.parseIntervals ( image, NinePatchIntervalType.verticalStretch );

        // Incorrect image
        if ( !( ( horizontalStretch.size () > 1 || horizontalStretch.size () == 1 && !horizontalStretch.get ( 0 ).isPixel () ) &&
                ( verticalStretch.size () > 1 || verticalStretch.size () == 1 && !verticalStretch.get ( 0 ).isPixel () ) ) )
        {
            throw new IllegalArgumentException ( "There must be stretch constraints specified on image" );
        }

        // Parsing content margins
        final List<NinePatchInterval> vc = NinePatchUtils.parseIntervals ( image, NinePatchIntervalType.verticalContent );
        final List<NinePatchInterval> hc = NinePatchUtils.parseIntervals ( image, NinePatchIntervalType.horizontalContent );
        final int top = vc.size () == 0 ? 0 : vc.get ( 0 ).getStart ();
        final int bottom = vc.size () == 0 ? 0 : rawImage.getHeight () - vc.get ( 0 ).getEnd () - 1;
        final int left = hc.size () == 0 ? 0 : hc.get ( 0 ).getStart ();
        final int right = hc.size () == 0 ? 0 : rawImage.getWidth () - hc.get ( 0 ).getEnd () - 1;
        margin = new Insets ( top, left, bottom, right );

        // Forcing cached data calculation on initialization
        getFixedPixelsWidth ( true );
        getFixedPixelsWidth ( false );
        getFixedPixelsHeight ( true );
        getFixedPixelsHeight ( false );
    }
    else
    {
        // Actual image
        this.rawImage = image;

        // Stretch variables
        horizontalStretch = new ArrayList<NinePatchInterval> ();
        verticalStretch = new ArrayList<NinePatchInterval> ();

        // Empty margin
        margin = new Insets ( 0, 0, 0, 0 );
    }
}
 
Example 24
Source Project: weblaf   Source File: AbstractMenuGenerator.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns {@link Icon} for the specified source {@link Object}.
 *
 * @param icon either {@link Icon}, {@link Image}, {@link Resource}, path, {@link File} or {@link URL}
 * @return {@link Icon} for the specified source {@link Object}
 */
@Nullable
protected Icon getIcon ( @Nullable final Object icon )
{
    final Icon result;
    if ( icon != null )
    {
        if ( icon instanceof Icon )
        {
            result = ( Icon ) icon;
        }
        else if ( icon instanceof Image )
        {
            result = new ImageIcon ( ( Image ) icon );
        }
        else
        {
            final Resource resource;
            if ( icon instanceof Resource )
            {
                resource = ( Resource ) icon;
            }
            else if ( icon instanceof String )
            {
                try
                {
                    if ( getNearClass () != null )
                    {
                        resource = new ClassResource ( getNearClass (), getPath () + icon + getExtension () );
                    }
                    else
                    {
                        resource = new FileResource ( new File ( getPath (), icon + getExtension () ) );
                    }
                }
                catch ( final Exception e )
                {
                    throw new UtilityException ( "Unable to find menu icon for path: " + getPath () + icon + getExtension (), e );
                }
            }
            else if ( icon instanceof File )
            {
                resource = new FileResource ( ( File ) icon );
            }
            else if ( icon instanceof URL )
            {
                resource = new UrlResource ( ( URL ) icon );
            }
            else
            {
                throw new UtilityException ( "Unknown icon object type provided: " + icon );
            }
            result = ImageUtils.loadImageIcon ( resource );
        }
    }
    else
    {
        result = null;
    }
    return result;
}
 
Example 25
@NotNull
@Override
protected BufferedImage createTextureImage ( @NotNull final C c, @NotNull final D d )
{
    return ImageUtils.toNonNullBufferedImage ( IconManager.getIcon ( getIconId ( c, d ) ) );
}
 
Example 26
Source Project: weblaf   Source File: WebDirectoryChooser.java    License: GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructs new directory chooser dialog with the specified parent window and title.
 *
 * @param parent parent window
 * @param title  dialog title
 */
public WebDirectoryChooser ( final Window parent, final String title )
{
    super ( parent, title != null ? title : "weblaf.ex.dirchooser.title" );
    setIconImage ( ImageUtils.toBufferedImage ( Icons.dir ) );

    // Default container settings
    getContentPane ().setLayout ( new BorderLayout ( 0, 0 ) );

    // Directory chooser itself
    directoryChooserPanel = new WebDirectoryChooserPanel ();
    directoryChooserPanel.addDirectoryChooserListener ( new DirectoryChooserAdapter ()
    {
        @Override
        public void accepted ( final File file )
        {
            result = OK_OPTION;
            WebDirectoryChooser.this.dispose ();
        }

        @Override
        public void cancelled ()
        {
            result = CANCEL_OPTION;
            WebDirectoryChooser.this.dispose ();
        }
    } );
    getContentPane ().add ( directoryChooserPanel, BorderLayout.CENTER );

    // Result saver
    addWindowListener ( new WindowAdapter ()
    {
        @Override
        public void windowClosed ( final WindowEvent e )
        {
            result = CLOSE_OPTION;
        }
    } );

    setDefaultCloseOperation ( JDialog.DISPOSE_ON_CLOSE );
    setModal ( true );
    pack ();
}
 
Example 27
Source Project: weblaf   Source File: WebDecoratedImage.java    License: GNU General Public License v3.0 4 votes vote down vote up
public WebDecoratedImage ( @NotNull final Resource resource )
{
    this ( ImageUtils.loadImageIcon ( resource ) );
}
 
Example 28
Source Project: weblaf   Source File: WebDecoratedImage.java    License: GNU General Public License v3.0 4 votes vote down vote up
public WebDecoratedImage ( @NotNull final Image image )
{
    this ( ImageUtils.toNonNullImageIcon ( image ) );
}
 
Example 29
Source Project: weblaf   Source File: WebDecoratedImage.java    License: GNU General Public License v3.0 4 votes vote down vote up
public WebDecoratedImage ( @NotNull final Icon icon )
{
    this ( ImageUtils.toNonNullImageIcon ( icon ) );
}
 
Example 30
Source Project: weblaf   Source File: WebDecoratedImage.java    License: GNU General Public License v3.0 4 votes vote down vote up
public void setImage ( @NotNull final Image image )
{
    setIcon ( ImageUtils.toNonNullImageIcon ( image ) );
}