Java ImageIcon initImageIcon(Class cl)

Here you can find the source of initImageIcon(Class cl)

Description

init Image Icon

License

Open Source License

Declaration

static void initImageIcon(Class cl) 

Method Source Code


//package com.java2s;
/*//ww w. j a v a  2  s  .co  m
 * Copyright (C) 2005  Alexis Miara (alexis.miara@licef.ca)
 *
 * This file is part of LomPad.
 *
 * LomPad is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * LomPad is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with LomPad; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

import javax.swing.*;
import java.awt.*;
import java.io.*;

public class Main {
    static Image imageApp;
    static Image imageEvaluate;
    static Image imageAbout;
    static ImageIcon imageIconCollapse;
    static ImageIcon imageIconExpand;
    static ImageIcon plusIcon;
    static ImageIcon minusIcon;
    static ImageIcon wizardIcon;
    static ImageIcon cancoreIcon;
    static ImageIcon normeticIcon;
    static ImageIcon normeticDisabledIcon;
    static ImageIcon redIcon;
    static ImageIcon yellowIcon;
    static ImageIcon greenIcon;
    static ImageIcon folderIcon;
    static ImageIcon fileIcon;

    static void initImageIcon(Class cl) {
        imageApp = getImage(cl, "app.gif");
        imageEvaluate = getImage(cl, "evaluateIcon.gif");
        imageAbout = getImage(cl, "about.gif");
        imageIconExpand = new ImageIcon(getImage(cl, "handleExpand.gif"));
        imageIconCollapse = new ImageIcon(getImage(cl, "handleCollapse.gif"));
        plusIcon = new ImageIcon(getImage(cl, "plus.gif"));
        minusIcon = new ImageIcon(getImage(cl, "minus.gif"));
        wizardIcon = new ImageIcon(getImage(cl, "wizard.gif"));
        cancoreIcon = new ImageIcon(getImage(cl, "cancore.gif"));
        normeticIcon = new ImageIcon(getImage(cl, "normetic.gif"));
        normeticDisabledIcon = new ImageIcon(getImage(cl, "normeticDisabled.gif"));
        redIcon = new ImageIcon(getImage(cl, "red.gif"));
        yellowIcon = new ImageIcon(getImage(cl, "yellow.gif"));
        greenIcon = new ImageIcon(getImage(cl, "green.gif"));
        folderIcon = new ImageIcon(getImage(cl, "folder.gif"));
        fileIcon = new ImageIcon(getImage(cl, "file.gif"));
    }

    public static Image getImage(Class cl, String name) {
        Image image = null;
        try {
            BufferedInputStream in = new BufferedInputStream(cl.getResourceAsStream("/images/" + name));
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            copy(in, out);
            image = Toolkit.getDefaultToolkit().createImage(out.toByteArray());
        } catch (Exception e) {
            return null;
        }
        return image;
    }

    public static void copy(InputStream in, OutputStream out) throws IOException {
        synchronized (in) {
            synchronized (out) {
                byte[] buffer = new byte[1024];
                while (true) {
                    int bytesRead = in.read(buffer);
                    if (bytesRead == -1)
                        break;
                    out.write(buffer, 0, bytesRead);
                }
            }
        }
    }

    public static void copy(Reader in, Writer out) throws IOException {
        synchronized (in) {
            synchronized (out) {
                char[] buffer = new char[1024];
                while (true) {
                    int charRead = in.read(buffer);
                    if (charRead == -1)
                        break;
                    out.write(buffer, 0, charRead);
                }
            }
        }
    }
}

Related

  1. grabRGB(ImageIcon icon)
  2. iconDefaultSize(ImageIcon imag)
  3. imageFlip(int w, int h, ImageIcon... icons)
  4. imageToBytes(ImageIcon icon)
  5. imageWithBackground(ImageIcon icon, Color colorBg)
  6. isValidImg(ImageIcon img)
  7. loadJavaInternal(ImageIcon r, Dimension d, boolean noStretch)
  8. makeDisabledImage(ImageIcon in)
  9. paintWithWatermarkHelper(JComponent component, ImageIcon watermark, Graphics g)