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