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);
}
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);
}
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);
}
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);
}
}
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);
}
Aggregations