use of java.awt.MediaTracker in project jdk8u_jdk by JetBrains.
the class MultiResolutionDisabledImageTest method testMRDisabledImage.
private static void testMRDisabledImage(Image image) throws Exception {
Image disabledImage = GrayFilter.createDisabledImage(image);
MediaTracker mediaTracker = new MediaTracker(new JLabel());
mediaTracker.addImage(disabledImage, 0);
mediaTracker.waitForID(0);
BufferedImage buffImage = new BufferedImage(IMAGE_SIZE, IMAGE_SIZE, BufferedImage.TYPE_INT_RGB);
int x = IMAGE_SIZE / 2;
int y = IMAGE_SIZE / 2;
Graphics2D g = buffImage.createGraphics();
g.scale(1, 1);
g.drawImage(disabledImage, 0, 0, null);
int rgb1x = buffImage.getRGB(x, y);
g.scale(2, 2);
g.drawImage(disabledImage, 0, 0, null);
int rgb2x = buffImage.getRGB(x, y);
g.dispose();
if (rgb1x == rgb2x) {
throw new RuntimeException("Disabled image is the same for the base" + "image and the resolution variant");
}
}
use of java.awt.MediaTracker in project JMRI by JMRI.
the class SplashWindow method splashWindowDisplay.
public void splashWindowDisplay(JPanel splashMsg) {
//super("JMRI");
this.setUndecorated(true);
// get the splash image
MediaTracker mt = new MediaTracker(this);
splashIm = Toolkit.getDefaultToolkit().getImage(FileUtil.findURL("resources/logo.gif", FileUtil.Location.INSTALLED));
mt.addImage(splashIm, 0);
try {
mt.waitForID(0);
} catch (InterruptedException ie) {
// retain if needed later
Thread.currentThread().interrupt();
}
JLabel l = new JLabel(new ImageIcon(splashIm, "JMRI splash screen"));
l.setOpaque(true);
if (splashMsg != null) {
JPanel full = new JPanel();
full.setLayout(new BoxLayout(full, BoxLayout.Y_AXIS));
l.setAlignmentX(CENTER_ALIGNMENT);
splashMsg.setAlignmentX(CENTER_ALIGNMENT);
full.add(l);
full.add(splashMsg);
getContentPane().add(full);
} else {
getContentPane().add(l);
}
pack();
/* Center the window and pad the frame size slightly to put some space
* between logo and frame border*/
Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
Rectangle winDim = getBounds();
winDim.height = winDim.height + 10;
winDim.width = winDim.width + 10;
setLocation((screenDim.width - winDim.width) / 2, (screenDim.height - winDim.height) / 2);
setSize(winDim.width, winDim.height);
// and show
setVisible(true);
}
use of java.awt.MediaTracker in project JMRI by JMRI.
the class NamedIcon method createRotatedImage.
/**
* The following was based on a text-rotating applet from David Risner,
* available at http://www.risner.org/java/rotate_text.html
*
* @param pImage Image to transform
* @param pComponent Component containing the image, needed to obtain a
* MediaTracker to process the image consistently with
* display
* @param pRotation 0-3 number of 90-degree rotations needed
* @return new Image object containing the rotated input image
*/
public Image createRotatedImage(Image pImage, Component pComponent, int pRotation) {
if (log.isDebugEnabled()) {
log.debug("createRotatedImage: pRotation= " + pRotation + ", mRotation= " + mRotation);
}
if (pRotation == 0) {
return pImage;
}
MediaTracker mt = new MediaTracker(pComponent);
mt.addImage(pImage, 0);
try {
mt.waitForAll();
} catch (InterruptedException ie) {
// retain if needed later
Thread.currentThread().interrupt();
}
int w = pImage.getWidth(null);
int h = pImage.getHeight(null);
int[] pixels = new int[w * h];
PixelGrabber pg = new PixelGrabber(pImage, 0, 0, w, h, pixels, 0, w);
try {
pg.grabPixels();
} catch (InterruptedException ie) {
}
int[] newPixels = new int[w * h];
// transform the pixels
MemoryImageSource imageSource = null;
switch(pRotation) {
case // 90 degrees
1:
for (int y = 0; y < h; ++y) {
for (int x = 0; x < w; ++x) {
newPixels[x * h + y] = pixels[y * w + (w - 1 - x)];
}
}
imageSource = new MemoryImageSource(h, w, ColorModel.getRGBdefault(), newPixels, 0, h);
break;
case // 180 degrees
2:
for (int y = 0; y < h; ++y) {
for (int x = 0; x < w; ++x) {
newPixels[x * h + y] = pixels[(w - 1 - x) * h + (h - 1 - y)];
}
}
imageSource = new MemoryImageSource(w, h, ColorModel.getRGBdefault(), newPixels, 0, w);
break;
case // 270 degrees
3:
for (int y = 0; y < h; ++y) {
for (int x = 0; x < w; ++x) {
newPixels[x * h + y] = pixels[(h - 1 - y) * w + x];
}
}
imageSource = new MemoryImageSource(h, w, ColorModel.getRGBdefault(), newPixels, 0, h);
break;
default:
log.warn("Unhandled rotation code: {}", pRotation);
break;
}
Image myImage = pComponent.createImage(imageSource);
mt.addImage(myImage, 1);
try {
mt.waitForAll();
} catch (InterruptedException ie) {
}
return myImage;
}
use of java.awt.MediaTracker in project JWildfire by thargor6.
the class ImageReader method loadImage.
public SimpleImage loadImage(String pFilename) throws Exception {
File file = new File(pFilename);
if (!file.exists())
throw new FileNotFoundException(pFilename);
Image fileImg = Toolkit.getDefaultToolkit().createImage(pFilename);
MediaTracker tracker = new MediaTracker(owner);
tracker.addImage(fileImg, 0);
tracker.waitForID(0);
int width = fileImg.getWidth(null);
int height = fileImg.getHeight(null);
BufferedImage bImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = bImg.getGraphics();
g.drawImage(fileImg, 0, 0, null);
fileImg = null;
return new SimpleImage(bImg, width, height);
}
use of java.awt.MediaTracker in project JWildfire by thargor6.
the class Launcher method getImage.
private SimpleImage getImage(String pName) throws Exception {
byte[] imgData = getImagedata(pName);
Image fileImg = Toolkit.getDefaultToolkit().createImage(imgData);
MediaTracker tracker = new MediaTracker(frame);
tracker.addImage(fileImg, 0);
tracker.waitForID(0);
int width = fileImg.getWidth(null);
int height = fileImg.getHeight(null);
BufferedImage bImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = bImg.getGraphics();
g.drawImage(fileImg, 0, 0, null);
fileImg = null;
return new SimpleImage(bImg, width, height);
}
Aggregations