Package java.awt

Examples of java.awt.MediaTracker$TrackingImage


        }
        return out;
    }

    public Shape3D getModel(Image img, float alpha, boolean scale) {
        MediaTracker tracker = new MediaTracker(comp);

        // Fully load image before continuing
        tracker.addImage(img, 0);
        do {
            try { tracker.waitForID(0); } catch (InterruptedException e) { continue; }
        } while (false);
        tracker.removeImage(img);

        final int w = img.getWidth(null), h = img.getHeight(null);
        BufferedImage tmp = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

        Graphics2D tgr = tmp.createGraphics();
        tgr.drawImage(img, null, null);
        tgr.dispose();
        tgr = null;

        tracker.addImage(tmp, 1);
        do {
            try { tracker.waitForID(1); } catch (InterruptedException e) { continue; }
        } while (false);
        tracker.removeImage(tmp);

        Shape3D model = new ImageModel(tmp, scale);
        Appearance app = new Appearance();
        app.setTexture(getTexture(img, false, null, alpha, true));
        if (alpha != 1.0) app.setTransparencyAttributes(C.alphaTexture);
View Full Code Here


    private final Texture2D getTexture(Image base, boolean border, Color col, float alpha, boolean tile) {
        if (base == null) return null;

        Texture2D tex = textureCache.get(new ImageAlpha(base, alpha));
        if (tex == null) {
            MediaTracker tracker = new MediaTracker(comp);

            // Fully load image before continuing
            tracker.addImage(base, 0);
            do {
                try { tracker.waitForID(0); } catch (InterruptedException e) { continue; }
            } while (false);
            tracker.removeImage(base);

            final int w = base.getWidth(null), h = base.getHeight(null);
            BufferedImage tmp = new BufferedImage(w*2, h*2, BufferedImage.TYPE_INT_ARGB);
            Graphics2D tgr = tmp.createGraphics();
            if (col != null) {
                tgr.setColor(col);
                tgr.fillRect(0, 0, w*2, h*2);
            }
            tgr.translate(w/2, h/2);
            tgr.drawImage(base, null, null);
            if (tile) {
                // create an image of a hex with all 6 surrounding hexes to get
                // better interpolation at the borders
                tgr.translate(0, -h);
                tgr.drawImage(base, null, null);
                tgr.translate(0, 2*h);
                tgr.drawImage(base, null, null);
                tgr.translate(-3*w/4, -h/2);
                tgr.drawImage(base, null, null);
                tgr.translate(0, -h);
                tgr.drawImage(base, null, null);
                tgr.translate(3*w/2, 0);
                tgr.drawImage(base, null, null);
                tgr.translate(0, h);
                tgr.drawImage(base, null, null);
            }

            tracker.addImage(tmp, 1);
            do {
                try { tracker.waitForID(1); } catch (InterruptedException e) { continue; }
            } while (false);
            tracker.removeImage(tmp);

            // TODO: Make this configurable.
            // Cut outer pixel border? This removes the distinct tile border present in most tiles.
            int border_cut = 1;
            // Add our own pixel border? Higher quality (resolution) than the image's tile border.
View Full Code Here

            return base;
        }

        Image scaled = scaledImageCache.get(base);
        if (scaled == null) {
            MediaTracker tracker = new MediaTracker(this);
            if ((base.getWidth(null) == -1) || (base.getHeight(null) == -1)) {
                tracker.addImage(base, 0);
                try {
                    tracker.waitForID(0);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                tracker.removeImage(base);
            }
            int width = (int) (base.getWidth(null) * scale);
            int height = (int) (base.getHeight(null) * scale);

            //TODO: insert a check that width and height are > 0.

            scaled = scale(base, width, height);
            tracker.addImage(scaled, 1);
            // Wait for image to load
            try {
                tracker.waitForID(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            tracker.removeImage(scaled);

            scaledImageCache.put(base, scaled);
        }
        return scaled;
    }
View Full Code Here

        // initialize splash image
        Image imgSplash = frame.getToolkit().getImage(
                "data/images/misc/megamek-splash.jpg"); //$NON-NLS-1$

        // wait for splash image to load completely
        MediaTracker tracker = new MediaTracker(frame);
        tracker.addImage(imgSplash, 0);
        try {
            tracker.waitForID(0);
        } catch (InterruptedException e) {

        }
        // make splash image panel
        BufferedPanel panTitle = new BufferedPanel();
View Full Code Here

        // Have we loaded our image yet?
        if (imgTitleImage == null) {
            // Nope. Load it.
            Image image = frame.getToolkit().getImage(
                    "data/images/misc/megamek-splash2.gif"); //$NON-NLS-1$
            MediaTracker tracker = new MediaTracker(frame);
            tracker.addImage(image, 0);
            try {
                tracker.waitForID(0);
                imgTitleImage = image;
            } catch (InterruptedException exp) {
                exp.printStackTrace();
            }
        } // End load-imgTitleImage
View Full Code Here

        // Have we loaded our image yet?
        if (imgTitleImage == null) {
            // Nope. Load it.
            Image image = frame.getToolkit().getImage(
                    "data/images/misc/megamek-splash2.gif"); //$NON-NLS-1$
            MediaTracker tracker = new MediaTracker(frame);
            tracker.addImage(image, 0);
            try {
                tracker.waitForID(0);
                imgTitleImage = image;
            } catch (InterruptedException exp) {
                exp.printStackTrace();
            }
        } // End load-imgTitleImage
View Full Code Here

        setListeners();
        update();
    }

    private void setImages() {
        MediaTracker mt = new MediaTracker(this);
        Toolkit tk = getToolkit();
        idleImage[0] = tk.getImage(IMAGE_DIR + "/tab_general_idle.gif"); //$NON-NLS-1$
        idleImage[1] = tk.getImage(IMAGE_DIR + "/tab_armor_idle.gif"); //$NON-NLS-1$
        idleImage[2] = tk.getImage(IMAGE_DIR + "/tab_systems_idle.gif"); //$NON-NLS-1$
        idleImage[3] = tk.getImage(IMAGE_DIR + "/tab_weapon_idle.gif"); //$NON-NLS-1$
        idleImage[4] = tk.getImage(IMAGE_DIR + "/tab_extras_idle.gif"); //$NON-NLS-1$
        activeImage[0] = tk.getImage(IMAGE_DIR + "/tab_general_active.gif"); //$NON-NLS-1$
        activeImage[1] = tk.getImage(IMAGE_DIR + "/tab_armor_active.gif"); //$NON-NLS-1$
        activeImage[2] = tk.getImage(IMAGE_DIR + "/tab_systems_active.gif"); //$NON-NLS-1$
        activeImage[3] = tk.getImage(IMAGE_DIR + "/tab_weapon_active.gif"); //$NON-NLS-1$
        activeImage[4] = tk.getImage(IMAGE_DIR + "/tab_extras_active.gif"); //$NON-NLS-1$
        idleCorner = tk.getImage(IMAGE_DIR + "/idle_corner.gif"); //$NON-NLS-1$
        selectedCorner = tk.getImage(IMAGE_DIR + "/active_corner.gif"); //$NON-NLS-1$

        for (int i = 0; i < 5; i++) {
            mt.addImage(idleImage[i], 0);
            mt.addImage(activeImage[i], 0);
        }
        mt.addImage(idleCorner, 0);
        mt.addImage(selectedCorner, 0);
        try {
            mt.waitForAll();
        } catch (InterruptedException e) {
            System.out.println("TabStrip: Error while image loading."); //$NON-NLS-1$
        }
        if (mt.isErrorID(0)) {
            System.out.println("TabStrip: Could Not load Image."); //$NON-NLS-1$
        }
    }
View Full Code Here

        setListeners();
        update();
    }

    private void setImages() {
        MediaTracker mt = new MediaTracker(this);
        Toolkit tk = getToolkit();
        idleImage[0] = tk.getImage(IMAGE_DIR + "/tab_general_idle.gif"); //$NON-NLS-1$
        idleImage[1] = tk.getImage(IMAGE_DIR + "/tab_armor_idle.gif"); //$NON-NLS-1$
        idleImage[2] = tk.getImage(IMAGE_DIR + "/tab_systems_idle.gif"); //$NON-NLS-1$
        idleImage[3] = tk.getImage(IMAGE_DIR + "/tab_weapon_idle.gif"); //$NON-NLS-1$
        idleImage[4] = tk.getImage(IMAGE_DIR + "/tab_extras_idle.gif"); //$NON-NLS-1$
        activeImage[0] = tk.getImage(IMAGE_DIR + "/tab_general_active.gif"); //$NON-NLS-1$
        activeImage[1] = tk.getImage(IMAGE_DIR + "/tab_armor_active.gif"); //$NON-NLS-1$
        activeImage[2] = tk.getImage(IMAGE_DIR + "/tab_systems_active.gif"); //$NON-NLS-1$
        activeImage[3] = tk.getImage(IMAGE_DIR + "/tab_weapon_active.gif"); //$NON-NLS-1$
        activeImage[4] = tk.getImage(IMAGE_DIR + "/tab_extras_active.gif"); //$NON-NLS-1$
        idleCorner = tk.getImage(IMAGE_DIR + "/idle_corner.gif"); //$NON-NLS-1$
        selectedCorner = tk.getImage(IMAGE_DIR + "/active_corner.gif"); //$NON-NLS-1$

        for (int i = 0; i < 5; i++) {
            mt.addImage(idleImage[i], 0);
            mt.addImage(activeImage[i], 0);
        }
        mt.addImage(idleCorner, 0);
        mt.addImage(selectedCorner, 0);
        try {
            mt.waitForAll();
        } catch (InterruptedException e) {
            System.out.println("TabStrip: Error while image loading."); //$NON-NLS-1$
        }
        if (mt.isErrorID(0)) {
            System.out.println("TabStrip: Could Not load Image."); //$NON-NLS-1$
        }
    }
View Full Code Here

     *
     * @param comp
     */
    public TilesetManager(Component comp) throws java.io.IOException {
        this.comp = comp;
        tracker = new MediaTracker(comp);
        try {
            camos = new DirectoryItems(new File("data/images/camo"), "", //$NON-NLS-1$ //$NON-NLS-2$
                    ImageFileFactory.getInstance());
        } catch (Exception e) {
            camos = null;
View Full Code Here

            Component bp) {
        Image base = mechTileset.imageFor(entity, comp);
        EntityImage entityImage = new EntityImage(base, tint, camo, bp);
        Image preview = entityImage.loadPreviewImage();

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

        }
        return preview;
    }
View Full Code Here

TOP

Related Classes of java.awt.MediaTracker$TrackingImage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.