Search in sources :

Example 46 with ImageIcon

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

the class JreForm 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 47 with ImageIcon

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

the class SingleInstanceForm 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 48 with ImageIcon

use of javax.swing.ImageIcon in project openblocks by mikaelhg.

the class JComponentDragHandler method createHandCursor.

private static Cursor createHandCursor(String location, String cursorName) {
    if (GraphicsEnvironment.isHeadless()) {
        // return default hand cursor if headless
        return Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
    }
    java.net.URL handURL = JComponentDragHandler.class.getResource(location);
    assert handURL != null : "Can not find hand cursor image " + cursorName;
    ImageIcon handicon = new ImageIcon(handURL);
    Dimension cursize = Toolkit.getDefaultToolkit().getBestCursorSize(handicon.getIconWidth(), handicon.getIconHeight());
    BufferedImage buffImg = GraphicsManager.gc.createCompatibleImage(cursize.width, cursize.height, Transparency.TRANSLUCENT);
    Graphics2D buffImgG2 = (Graphics2D) buffImg.getGraphics();
    Point cpoint = new Point(cursize.width / 2 - handicon.getIconWidth() / 2, cursize.height / 2 - handicon.getIconHeight() / 2);
    buffImgG2.drawImage(handicon.getImage(), cpoint.x, cpoint.y, null);
    return Toolkit.getDefaultToolkit().createCustomCursor(buffImg, new Point(cpoint.x + 5, cpoint.y), cursorName);
}
Also used : ImageIcon(javax.swing.ImageIcon) Dimension(java.awt.Dimension) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 49 with ImageIcon

use of javax.swing.ImageIcon in project openblocks by mikaelhg.

the class RenderableBlock method repositionBlockImages.

/**
     * Draws the BlockImageIcon instances of this onto itself
     * @param width the current width of the buffered image
     * @param height the current height of the buffered image
     */
private void repositionBlockImages(int width, int height) {
    int margin = 5;
    //TODO need to take other images into acct if we enable multiple block images
    for (BlockImageIcon img : imageMap.values()) {
        ImageIcon icon = img.getImageIcon();
        Point imgLoc = new Point(0, 0);
        if (img.getImageLocation() == BlockImageIcon.ImageLocation.CENTER) {
            imgLoc.setLocation((width - icon.getIconWidth()) / 2, (height - icon.getIconHeight()) / 2);
        } else if (img.getImageLocation() == ImageLocation.NORTH) {
            imgLoc.setLocation((width - icon.getIconWidth()) / 2, margin);
        } else if (img.getImageLocation() == ImageLocation.SOUTH) {
            imgLoc.setLocation((width - icon.getIconWidth()) / 2, height - margin - icon.getIconHeight());
        } else if (img.getImageLocation() == ImageLocation.EAST) {
            imgLoc.setLocation(width - margin - icon.getIconWidth(), (height - icon.getIconHeight()) / 2);
        } else if (img.getImageLocation() == ImageLocation.WEST) {
            imgLoc.setLocation(margin, (height - icon.getIconHeight()) / 2);
        } else if (img.getImageLocation() == ImageLocation.NORTHEAST) {
            imgLoc.setLocation(width - margin - icon.getIconWidth(), margin);
        } else if (img.getImageLocation() == ImageLocation.NORTHWEST) {
            imgLoc.setLocation(margin, margin);
        } else if (img.getImageLocation() == ImageLocation.SOUTHEAST) {
            imgLoc.setLocation(width - margin - icon.getIconWidth(), height - margin - icon.getIconHeight());
        } else if (img.getImageLocation() == BlockImageIcon.ImageLocation.SOUTHWEST) {
            //put in southwest corner
            imgLoc.setLocation(margin, height - (icon.getIconHeight() + margin));
        }
        if (getBlock().hasPlug() && (img.getImageLocation() != ImageLocation.EAST || img.getImageLocation() != ImageLocation.NORTHEAST || img.getImageLocation() != ImageLocation.SOUTHEAST))
            ;
        // need to nudge it a little more because of plug
        imgLoc.x += 4;
        img.setLocation(imgLoc.x, imgLoc.y);
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) Point(java.awt.Point) Point(java.awt.Point)

Example 50 with ImageIcon

use of javax.swing.ImageIcon in project jmonkeyengine by jMonkeyEngine.

the class RayTrace method show.

public void show() {
    frame = new JFrame("HDR View");
    label = new JLabel(new ImageIcon(image));
    frame.getContentPane().add(label);
    frame.setLayout(new FlowLayout());
    frame.pack();
    frame.setVisible(true);
}
Also used : ImageIcon(javax.swing.ImageIcon) FlowLayout(java.awt.FlowLayout) JFrame(javax.swing.JFrame) JLabel(javax.swing.JLabel)

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