Search in sources :

Example 41 with ImageIcon

use of javax.swing.ImageIcon in project zaproxy by zaproxy.

the class BreakPanelToolbarFactory method getBtnBreakRequest.

public JToggleButton getBtnBreakRequest() {
    ZapToggleButton btnBreakRequest;
    btnBreakRequest = new ZapToggleButton(breakRequestsButtonAction);
    btnBreakRequest.setSelectedIcon(new ImageIcon(BreakPanelToolbarFactory.class.getResource("/resource/icon/16/105r.png")));
    btnBreakRequest.setSelectedToolTipText(Constant.messages.getString("brk.toolbar.button.request.unset"));
    return btnBreakRequest;
}
Also used : ImageIcon(javax.swing.ImageIcon) ZapToggleButton(org.zaproxy.zap.view.ZapToggleButton)

Example 42 with ImageIcon

use of javax.swing.ImageIcon in project processing by processing.

the class PApplet method loadImage.

//  /**
//   * @param extension the type of image to load, for example "png", "gif", "jpg"
//   */
//  public PImage loadImage(String filename, String extension) {
//    return loadImage(filename, extension, null);
//  }
//  /**
//   * @nowebref
//   */
//  public PImage loadImage(String filename, Object params) {
//    return loadImage(filename, null, params);
//  }
/**
   * @param extension type of image to load, for example "png", "gif", "jpg"
   */
public PImage loadImage(String filename, String extension) {
    // If this runs on background, requestImage() already called await... on the main thread
    if (g != null && !Thread.currentThread().getName().startsWith(ASYNC_IMAGE_LOADER_THREAD_PREFIX)) {
        g.awaitAsyncSaveCompletion(filename);
    }
    if (extension == null) {
        String lower = filename.toLowerCase();
        int dot = filename.lastIndexOf('.');
        if (dot == -1) {
            // no extension found
            extension = "unknown";
        }
        extension = lower.substring(dot + 1);
        // check for, and strip any parameters on the url, i.e.
        // filename.jpg?blah=blah&something=that
        int question = extension.indexOf('?');
        if (question != -1) {
            extension = extension.substring(0, question);
        }
    }
    // just in case. them users will try anything!
    extension = extension.toLowerCase();
    if (extension.equals("tga")) {
        try {
            PImage image = loadImageTGA(filename);
            //        }
            return image;
        } catch (IOException e) {
            printStackTrace(e);
            return null;
        }
    }
    if (extension.equals("tif") || extension.equals("tiff")) {
        byte[] bytes = loadBytes(filename);
        PImage image = (bytes == null) ? null : PImage.loadTIFF(bytes);
        //      }
        return image;
    }
    // http://dev.processing.org/bugs/show_bug.cgi?id=392
    try {
        if (extension.equals("jpg") || extension.equals("jpeg") || extension.equals("gif") || extension.equals("png") || extension.equals("unknown")) {
            byte[] bytes = loadBytes(filename);
            if (bytes == null) {
                return null;
            } else {
                //Image awtImage = Toolkit.getDefaultToolkit().createImage(bytes);
                Image awtImage = new ImageIcon(bytes).getImage();
                if (awtImage instanceof BufferedImage) {
                    BufferedImage buffImage = (BufferedImage) awtImage;
                    int space = buffImage.getColorModel().getColorSpace().getType();
                    if (space == ColorSpace.TYPE_CMYK) {
                        System.err.println(filename + " is a CMYK image, " + "only RGB images are supported.");
                        return null;
                    /*
              // wishful thinking, appears to not be supported
              // https://community.oracle.com/thread/1272045?start=0&tstart=0
              BufferedImage destImage =
                new BufferedImage(buffImage.getWidth(),
                                  buffImage.getHeight(),
                                  BufferedImage.TYPE_3BYTE_BGR);
              ColorConvertOp op = new ColorConvertOp(null);
              op.filter(buffImage, destImage);
              image = new PImage(destImage);
              */
                    }
                }
                PImage image = new PImage(awtImage);
                if (image.width == -1) {
                    System.err.println("The file " + filename + " contains bad image data, or may not be an image.");
                }
                // if it's a .gif image, test to see if it has transparency
                if (extension.equals("gif") || extension.equals("png") || extension.equals("unknown")) {
                    image.checkAlpha();
                }
                //          if (params != null) {
                //            image.setParams(g, params);
                //          }
                image.parent = this;
                return image;
            }
        }
    } catch (Exception e) {
        // show error, but move on to the stuff below, see if it'll work
        printStackTrace(e);
    }
    if (loadImageFormats == null) {
        loadImageFormats = ImageIO.getReaderFormatNames();
    }
    if (loadImageFormats != null) {
        for (int i = 0; i < loadImageFormats.length; i++) {
            if (extension.equals(loadImageFormats[i])) {
                return loadImageIO(filename);
            //          PImage image = loadImageIO(filename);
            //          if (params != null) {
            //            image.setParams(g, params);
            //          }
            //          return image;
            }
        }
    }
    // failed, could not load image after all those attempts
    System.err.println("Could not find a method to load " + filename);
    return null;
}
Also used : ImageIcon(javax.swing.ImageIcon) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) BufferedImage(java.awt.image.BufferedImage) HeadlessException(java.awt.HeadlessException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 43 with ImageIcon

use of javax.swing.ImageIcon in project cogtool by cogtool.

the class ClassPathForm method loadImage.

/**
    * Helper method to load an image file from the CLASSPATH
    * @param imageName the package and name of the file to load relative to the CLASSPATH
    * @return an ImageIcon instance with the specified image file
    * @throws IllegalArgumentException if the image resource cannot be loaded.
    */
public ImageIcon loadImage(String imageName) {
    try {
        ClassLoader classloader = getClass().getClassLoader();
        java.net.URL url = classloader.getResource(imageName);
        if (url != null) {
            ImageIcon icon = new ImageIcon(url);
            return icon;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    throw new IllegalArgumentException("Unable to load image: " + imageName);
}
Also used : ImageIcon(javax.swing.ImageIcon)

Example 44 with ImageIcon

use of javax.swing.ImageIcon in project cogtool by cogtool.

the class ConfigForm method loadImage.

/**
    * Helper method to load an image file from the CLASSPATH
    * @param imageName the package and name of the file to load relative to the CLASSPATH
    * @return an ImageIcon instance with the specified image file
    * @throws IllegalArgumentException if the image resource cannot be loaded.
    */
public ImageIcon loadImage(String imageName) {
    try {
        ClassLoader classloader = getClass().getClassLoader();
        java.net.URL url = classloader.getResource(imageName);
        if (url != null) {
            ImageIcon icon = new ImageIcon(url);
            return icon;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    throw new IllegalArgumentException("Unable to load image: " + imageName);
}
Also used : ImageIcon(javax.swing.ImageIcon)

Example 45 with ImageIcon

use of javax.swing.ImageIcon in project cogtool by cogtool.

the class EnvironmentVarsForm method loadImage.

/**
    * Helper method to load an image file from the CLASSPATH
    * @param imageName the package and name of the file to load relative to the CLASSPATH
    * @return an ImageIcon instance with the specified image file
    * @throws IllegalArgumentException if the image resource cannot be loaded.
    */
public ImageIcon loadImage(String imageName) {
    try {
        ClassLoader classloader = getClass().getClassLoader();
        java.net.URL url = classloader.getResource(imageName);
        if (url != null) {
            ImageIcon icon = new ImageIcon(url);
            return icon;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    throw new IllegalArgumentException("Unable to load image: " + imageName);
}
Also used : ImageIcon(javax.swing.ImageIcon)

Aggregations

ImageIcon (javax.swing.ImageIcon)427 JButton (javax.swing.JButton)109 ActionEvent (java.awt.event.ActionEvent)83 ActionListener (java.awt.event.ActionListener)70 JLabel (javax.swing.JLabel)67 Dimension (java.awt.Dimension)62 BufferedImage (java.awt.image.BufferedImage)51 JPanel (javax.swing.JPanel)48 Insets (java.awt.Insets)42 Image (java.awt.Image)31 BorderLayout (java.awt.BorderLayout)28 IOException (java.io.IOException)28 URL (java.net.URL)26 GridBagLayout (java.awt.GridBagLayout)23 JMenuItem (javax.swing.JMenuItem)23 Color (java.awt.Color)21 Point (java.awt.Point)21 LogTypeHelper (com.cosylab.logging.engine.log.LogTypeHelper)20 JToggleButton (javax.swing.JToggleButton)20 JScrollPane (javax.swing.JScrollPane)19