Java Code Examples for java.awt.MediaTracker#waitForID()

The following examples show how to use java.awt.MediaTracker#waitForID() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TilesetManager.java    From megamek with GNU General Public License v2.0 6 votes vote down vote up
/**
 *  Loads a preview image of the unit into the BufferedPanel.
 */
public Image loadPreviewImage(Entity entity, Image camo, int tint, Component bp) {
    Image base = mechTileset.imageFor(entity, boardview, -1);
    EntityImage entityImage = new EntityImage(base, tint, camo, bp);
    entityImage.loadFacings();
    Image preview = entityImage.getFacing(entity.getFacing());

    MediaTracker loadTracker = new MediaTracker(boardview);
    loadTracker.addImage(preview, 0);
    try {
        loadTracker.waitForID(0);
    } catch (InterruptedException e) {
        // should never come here

    }

    return preview;
}
 
Example 2
Source File: MultiResolutionImageTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static void testToolkitMultiResolutionImageLoad(Image image) throws Exception {

        MediaTracker tracker = new MediaTracker(new JPanel());
        tracker.addImage(image, 0);
        tracker.waitForID(0);
        if (tracker.isErrorAny()) {
            throw new RuntimeException("Error during image loading");
        }
        tracker.removeImage(image, 0);

        testImageLoaded(image);

        int w = image.getWidth(null);
        int h = image.getHeight(null);

        Image resolutionVariant = ((MultiResolutionImage) image)
                .getResolutionVariant(2 * w, 2 * h);

        if (image == resolutionVariant) {
            throw new RuntimeException("Resolution variant is not loaded");
        }

        testImageLoaded(resolutionVariant);
    }
 
Example 3
Source File: left_TilesetManager_1.22.java    From gumtree-spoon-ast-diff with Apache License 2.0 6 votes vote down vote up
public void loadPreviewImage(Entity entity, Image camo, int tint, BufferedPanel bp) {
Image base = mechTileset.imageFor(entity, comp);
EntityImage entityImage = new EntityImage(base, tint, camo, bp);
Image preview = entityImage.loadPreviewImage();

BackGroundDrawer bgdPreview = new BackGroundDrawer(preview);
bp.removeBgDrawers();
bp.addBgDrawer(bgdPreview);

MediaTracker tracker = new MediaTracker(comp);
tracker.addImage(preview, 0);
try {
	tracker.waitForID(0);
} catch (InterruptedException e) {
	;
}

  }
 
Example 4
Source File: MultiResolutionImageTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
static void testToolkitMultiResolutionImageLoad(Image image) throws Exception {

        MediaTracker tracker = new MediaTracker(new JPanel());
        tracker.addImage(image, 0);
        tracker.waitForID(0);
        if (tracker.isErrorAny()) {
            throw new RuntimeException("Error during image loading");
        }
        tracker.removeImage(image, 0);

        testImageLoaded(image);

        int w = image.getWidth(null);
        int h = image.getHeight(null);

        Image resolutionVariant = ((MultiResolutionImage) image)
                .getResolutionVariant(2 * w, 2 * h);

        if (image == resolutionVariant) {
            throw new RuntimeException("Resolution variant is not loaded");
        }

        testImageLoaded(resolutionVariant);
    }
 
Example 5
Source File: ImageModeCanvas.java    From niftyeditor with Apache License 2.0 6 votes vote down vote up
/**
 * Creates new form ImageModeCanvas
 */
public ImageModeCanvas(ImageModeModel model) {
    initComponents();
    this.model = model;
    MediaTracker tracker = new MediaTracker(this);
    this.image = Toolkit.getDefaultToolkit().createImage(this.model.getImage());
    tracker.addImage(image, 0);
    try {
        tracker.waitForID(0);
    } catch (InterruptedException ex) {
        Logger.getLogger(ImageModeCanvas.class.getName()).log(Level.SEVERE, null, ex);
    }
    this.painter = new ResizePainter((ResizeImageMode)model, image.getWidth(null), image.getHeight(null));
    this.addMouseListener(painter);
    this.addMouseMotionListener(painter);
}
 
Example 6
Source File: MultiResolutionImageTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static void testToolkitMultiResolutionImageLoad(Image image) throws Exception {

        MediaTracker tracker = new MediaTracker(new JPanel());
        tracker.addImage(image, 0);
        tracker.waitForID(0);
        if (tracker.isErrorAny()) {
            throw new RuntimeException("Error during image loading");
        }
        tracker.removeImage(image, 0);

        testImageLoaded(image);

        int w = image.getWidth(null);
        int h = image.getHeight(null);

        Image resolutionVariant = ((MultiResolutionImage) image)
                .getResolutionVariant(2 * w, 2 * h);

        if (image == resolutionVariant) {
            throw new RuntimeException("Resolution variant is not loaded");
        }

        testImageLoaded(resolutionVariant);
    }
 
Example 7
Source File: right_TilesetManager_1.23.java    From gumtree-spoon-ast-diff with Apache License 2.0 6 votes vote down vote up
public void loadPreviewImage(Entity entity, Image camo, int tint, BufferedPanel bp) {
Image base = mechTileset.imageFor(entity, comp);
EntityImage entityImage = new EntityImage(base, tint, camo, bp);
Image preview = entityImage.loadPreviewImage();

BackGroundDrawer bgdPreview = new BackGroundDrawer(preview);
bp.removeBgDrawers();
bp.addBgDrawer(bgdPreview);

MediaTracker tracker = new MediaTracker(comp);
tracker.addImage(preview, 0);
try {
	tracker.waitForID(0);
} catch (InterruptedException e) {
	;
}

  }
 
Example 8
Source File: CannedMarsMap.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a 2D map at a given center point.
 * 
 * @param newCenter the new center location
 */
public void drawMap(Coordinates newCenter) {
	if ((newCenter != null) && (!newCenter.equals(currentCenter))) {
		mapImage = createMapImage(newCenter);

		MediaTracker mt = new MediaTracker(displayArea);
		mt.addImage(mapImage, 0);
		try {
			mt.waitForID(0);
		} catch (InterruptedException e) {
			logger.log(Level.SEVERE, Msg.getString("CannedMarsMap.log.mediaTrackerInterrupted") + e); //$NON-NLS-1$
		}
		mapImageDone = true;
		currentCenter = new Coordinates(newCenter);
	}
}
 
Example 9
Source File: MultiResolutionImageTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static void testToolkitMultiResolutionImageLoad(Image image) throws Exception {

        MediaTracker tracker = new MediaTracker(new JPanel());
        tracker.addImage(image, 0);
        tracker.waitForID(0);
        if (tracker.isErrorAny()) {
            throw new RuntimeException("Error during image loading");
        }
        tracker.removeImage(image, 0);

        testImageLoaded(image);

        int w = image.getWidth(null);
        int h = image.getHeight(null);

        Image resolutionVariant = ((MultiResolutionImage) image)
                .getResolutionVariant(2 * w, 2 * h);

        if (image == resolutionVariant) {
            throw new RuntimeException("Resolution variant is not loaded");
        }

        testImageLoaded(resolutionVariant);
    }
 
Example 10
Source File: MultiResolutionImageTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
static void testToolkitMultiResolutionImageLoad(Image image) throws Exception {

        MediaTracker tracker = new MediaTracker(new JPanel());
        tracker.addImage(image, 0);
        tracker.waitForID(0);
        if (tracker.isErrorAny()) {
            throw new RuntimeException("Error during image loading");
        }
        tracker.removeImage(image, 0);

        testImageLoaded(image);

        int w = image.getWidth(null);
        int h = image.getHeight(null);

        Image resolutionVariant = ((MultiResolutionImage) image)
                .getResolutionVariant(2 * w, 2 * h);

        if (image == resolutionVariant) {
            throw new RuntimeException("Resolution variant is not loaded");
        }

        testImageLoaded(resolutionVariant);
    }
 
Example 11
Source File: GraphicUtils.java    From Spark with Apache License 2.0 5 votes vote down vote up
/**
    * Loading an image via a MediaTracker
    * 
    * @param image
    * @throws InterruptedException
    * @throws IOException
    */
   public static void load(Image image) throws InterruptedException,
    IOException {
MediaTracker tracker = new MediaTracker(new Label()); // any component
						      // will do
tracker.addImage(image, 0);
tracker.waitForID(0);
if (tracker.isErrorID(0))
    throw new IOException("error loading image");
   }
 
Example 12
Source File: GraphicUtils.java    From xyTalk-pc with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
    * Loading an image via a MediaTracker
    * 
    * @param image
    * @throws InterruptedException
    * @throws IOException
    */
   public static void load(Image image) throws InterruptedException,
    IOException {
MediaTracker tracker = new MediaTracker(new Label()); // any component
						      // will do
tracker.addImage(image, 0);
tracker.waitForID(0);
if (tracker.isErrorID(0))
    throw new IOException("error loading image");
   }
 
Example 13
Source File: MultiResolutionDisabledImageTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
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");
        }

    }
 
Example 14
Source File: MultiResolutionDisabledImageTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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");
        }

    }
 
Example 15
Source File: JasperApp.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 */
public void fill() throws JRException
{
	long start = System.currentTimeMillis();
	//Preparing parameters
	Image image = 
		Toolkit.getDefaultToolkit().createImage(
			JRLoader.loadBytesFromResource("dukesign.jpg")
			);
	MediaTracker traker = new MediaTracker(new Panel());
	traker.addImage(image, 0);
	try
	{
		traker.waitForID(0);
	}
	catch (Exception e)
	{
		e.printStackTrace();
	}
	
	Map<String, Object> parameters = new HashMap<String, Object>();
	parameters.put("ReportTitle", "The First Jasper Report Ever");
	parameters.put("MaxOrderID", 10500);
	parameters.put("SummaryImage", image);
	
	JasperFillManager.fillReportToFile("build/reports/FirstJasper.jasper", parameters, getDemoHsqldbConnection());
	System.err.println("Filling time : " + (System.currentTimeMillis() - start));
}
 
Example 16
Source File: JRJdk13ImageReader.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Image readImage(byte[] bytes) throws JRException
{
	Image image = Toolkit.getDefaultToolkit().createImage(bytes);

	MediaTracker tracker = new MediaTracker(new Panel());
	tracker.addImage(image, 0);
	try
	{
		tracker.waitForID(0);
	}
	catch (Exception e)
	{
		//image = null;
		throw new JRException(e);
	}

	if(tracker.isErrorID(0)) 
	{
		throw 
		new JRException(
			EXCEPTION_MESSAGE_KEY_IMAGE_READ_FAILED,
			(Object[])null);
	}

	return image;
}
 
Example 17
Source File: MultiResolutionImageTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
static void testToolkitMultiResolutionImage(Image image, boolean enableImageScaling)
        throws Exception {

    MediaTracker tracker = new MediaTracker(new JPanel());
    tracker.addImage(image, 0);
    tracker.waitForID(0);
    if (tracker.isErrorAny()) {
        throw new RuntimeException("Error during image loading");
    }

    final BufferedImage bufferedImage1x = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT,
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g1x = (Graphics2D) bufferedImage1x.getGraphics();
    setImageScalingHint(g1x, false);
    g1x.drawImage(image, 0, 0, null);
    checkColor(bufferedImage1x.getRGB(3 * IMAGE_WIDTH / 4, 3 * IMAGE_HEIGHT / 4), false);

    Image resolutionVariant = ((MultiResolutionImage) image).
            getResolutionVariant(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT);

    if (resolutionVariant == null) {
        throw new RuntimeException("Resolution variant is null");
    }

    MediaTracker tracker2x = new MediaTracker(new JPanel());
    tracker2x.addImage(resolutionVariant, 0);
    tracker2x.waitForID(0);
    if (tracker2x.isErrorAny()) {
        throw new RuntimeException("Error during scalable image loading");
    }

    final BufferedImage bufferedImage2x = new BufferedImage(2 * IMAGE_WIDTH,
            2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2x = (Graphics2D) bufferedImage2x.getGraphics();
    setImageScalingHint(g2x, enableImageScaling);
    g2x.drawImage(image, 0, 0, 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null);
    checkColor(bufferedImage2x.getRGB(3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling);

    if (!(image instanceof MultiResolutionImage)) {
        throw new RuntimeException("Not a MultiResolutionImage");
    }

    MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image;

    Image image1x = multiResolutionImage.getResolutionVariant(IMAGE_WIDTH, IMAGE_HEIGHT);
    Image image2x = multiResolutionImage.getResolutionVariant(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT);

    if (image1x.getWidth(null) * 2 != image2x.getWidth(null)
            || image1x.getHeight(null) * 2 != image2x.getHeight(null)) {
        throw new RuntimeException("Wrong resolution variant size");
    }
}
 
Example 18
Source File: MultiResolutionImageTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
static void testToolkitMultiResolutionImage(Image image, boolean enableImageScaling)
        throws Exception {

    MediaTracker tracker = new MediaTracker(new JPanel());
    tracker.addImage(image, 0);
    tracker.waitForID(0);
    if (tracker.isErrorAny()) {
        throw new RuntimeException("Error during image loading");
    }

    final BufferedImage bufferedImage1x = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT,
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g1x = (Graphics2D) bufferedImage1x.getGraphics();
    setImageScalingHint(g1x, false);
    g1x.drawImage(image, 0, 0, null);
    checkColor(bufferedImage1x.getRGB(3 * IMAGE_WIDTH / 4, 3 * IMAGE_HEIGHT / 4), false);

    Image resolutionVariant = ((MultiResolutionImage) image).
            getResolutionVariant(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT);

    if (resolutionVariant == null) {
        throw new RuntimeException("Resolution variant is null");
    }

    MediaTracker tracker2x = new MediaTracker(new JPanel());
    tracker2x.addImage(resolutionVariant, 0);
    tracker2x.waitForID(0);
    if (tracker2x.isErrorAny()) {
        throw new RuntimeException("Error during scalable image loading");
    }

    final BufferedImage bufferedImage2x = new BufferedImage(2 * IMAGE_WIDTH,
            2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2x = (Graphics2D) bufferedImage2x.getGraphics();
    setImageScalingHint(g2x, enableImageScaling);
    g2x.drawImage(image, 0, 0, 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null);
    checkColor(bufferedImage2x.getRGB(3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling);

    if (!(image instanceof MultiResolutionImage)) {
        throw new RuntimeException("Not a MultiResolutionImage");
    }

    MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image;

    Image image1x = multiResolutionImage.getResolutionVariant(IMAGE_WIDTH, IMAGE_HEIGHT);
    Image image2x = multiResolutionImage.getResolutionVariant(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT);

    if (image1x.getWidth(null) * 2 != image2x.getWidth(null)
            || image1x.getHeight(null) * 2 != image2x.getHeight(null)) {
        throw new RuntimeException("Wrong resolution variant size");
    }
}
 
Example 19
Source File: MultiResolutionImageTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
static void testToolkitMultiResolutionImage(Image image, boolean enableImageScaling)
        throws Exception {

    MediaTracker tracker = new MediaTracker(new JPanel());
    tracker.addImage(image, 0);
    tracker.waitForID(0);
    if (tracker.isErrorAny()) {
        throw new RuntimeException("Error during image loading");
    }

    final BufferedImage bufferedImage1x = new BufferedImage(IMAGE_WIDTH, IMAGE_HEIGHT,
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g1x = (Graphics2D) bufferedImage1x.getGraphics();
    setImageScalingHint(g1x, false);
    g1x.drawImage(image, 0, 0, null);
    checkColor(bufferedImage1x.getRGB(3 * IMAGE_WIDTH / 4, 3 * IMAGE_HEIGHT / 4), false);

    Image resolutionVariant = ((MultiResolutionImage) image).
            getResolutionVariant(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT);

    if (resolutionVariant == null) {
        throw new RuntimeException("Resolution variant is null");
    }

    MediaTracker tracker2x = new MediaTracker(new JPanel());
    tracker2x.addImage(resolutionVariant, 0);
    tracker2x.waitForID(0);
    if (tracker2x.isErrorAny()) {
        throw new RuntimeException("Error during scalable image loading");
    }

    final BufferedImage bufferedImage2x = new BufferedImage(2 * IMAGE_WIDTH,
            2 * IMAGE_HEIGHT, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2x = (Graphics2D) bufferedImage2x.getGraphics();
    setImageScalingHint(g2x, enableImageScaling);
    g2x.drawImage(image, 0, 0, 2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, null);
    checkColor(bufferedImage2x.getRGB(3 * IMAGE_WIDTH / 2, 3 * IMAGE_HEIGHT / 2), enableImageScaling);

    if (!(image instanceof MultiResolutionImage)) {
        throw new RuntimeException("Not a MultiResolutionImage");
    }

    MultiResolutionImage multiResolutionImage = (MultiResolutionImage) image;

    Image image1x = multiResolutionImage.getResolutionVariant(IMAGE_WIDTH, IMAGE_HEIGHT);
    Image image2x = multiResolutionImage.getResolutionVariant(2 * IMAGE_WIDTH, 2 * IMAGE_HEIGHT);

    if (image1x.getWidth(null) * 2 != image2x.getWidth(null)
            || image1x.getHeight(null) * 2 != image2x.getHeight(null)) {
        throw new RuntimeException("Wrong resolution variant size");
    }
}
 
Example 20
Source File: FixedImagePanel.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
private static Image loadImage(Image image, MediaTracker mTracker) throws InterruptedException {
    mTracker.addImage(image, 0);
    mTracker.waitForID(0);
    mTracker.removeImage(image, 0);
    return image;
}