Java Code Examples for java.awt.MediaTracker#COMPLETE

The following examples show how to use java.awt.MediaTracker#COMPLETE . 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: BasemapLayer.java    From defense-solutions-proofs-of-concept with Apache License 2.0 5 votes vote down vote up
public BasemapLayer(Layer layer, String thumbnailFilename) {
    this.layer = layer;
    if (null == thumbnailFilename) {
        thumbnail = null;
    } else {
        ImageIcon imageIcon = new ImageIcon(thumbnailFilename);
        thumbnail = MediaTracker.COMPLETE == imageIcon.getImageLoadStatus() ? imageIcon : null;
    }
}
 
Example 2
Source File: AWTImageTools.java    From scifio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Ensures the given AWT image is fully loaded. */
public static boolean loadImage(final Image image) {
	if (image instanceof BufferedImage) return true;
	final MediaTracker tracker = new MediaTracker(OBS);
	tracker.addImage(image, 0);
	try {
		tracker.waitForID(0);
	}
	catch (final InterruptedException exc) {
		return false;
	}
	if (MediaTracker.COMPLETE != tracker.statusID(0, false)) return false;
	return true;
}
 
Example 3
Source File: MegamekBorder.java    From megamek with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Paints the border using the loaded corner icons and edge icons.
 */
public void paintBorder(Component c, Graphics g, int x, int y, int width, 
        int height) {
    // Do nothing if we don't want to draw a border
    if (noBorder) {
        return;
    }
    
    // If the icons didn't loaded, treat this as a regualar border
    if (!iconsLoaded) {
        super.paintBorder(c, g, x, y, width, height);
        return;
    }
    
    g.translate(x, y);
    
    // Draw Top Left Corner Icon
    if (tlCorner.getImageLoadStatus() == MediaTracker.COMPLETE){
        paintCorner(c, g, 0, 0, tlCorner);
    }
    
    // Draw Bottom Left Corner Icon
    if (blCorner.getImageLoadStatus() == MediaTracker.COMPLETE){
        paintCorner(c, g, 0, height - blCorner.getIconHeight(), blCorner);
    }
    
    // Draw Top Right Corner Icon
    if (trCorner.getImageLoadStatus() == MediaTracker.COMPLETE){
        paintCorner(c, g, width-trCorner.getIconWidth(), 0, trCorner);
    }
    
    // Draw Bottom Right Corner Icon
    if (brCorner.getImageLoadStatus() == MediaTracker.COMPLETE){
    paintCorner(c, g, width-brCorner.getIconWidth(), 
            height-brCorner.getIconHeight(), brCorner);
    }
    
    // Compute the width and height for the border edges       
    int edgeWidth = width - (insets.left + insets.right);
    int edgeHeight = height - (insets.top + insets.bottom);
    
    // Paint top edge icons
    paintEdge(c, g, topLine, insets.left, 0, edgeWidth, insets.top, false,
            topShouldTile, topNumTiledIcons, topStaticSpace);
    
    // Paint bottom edge icons
    paintEdge(c, g, bottomLine, insets.left, height - insets.bottom,
            edgeWidth, insets.bottom, false, bottomShouldTile,
            bottomNumTiledIcons, bottomStaticSpace);

    // Paint left edge icons
    paintEdge(c, g, leftLine, 0, insets.top, insets.left, edgeHeight, true,
            leftShouldTile, leftNumTiledIcons, leftStaticSpace);
    
    // Paint right edge icons
    paintEdge(c, g, rightLine, width - insets.right, insets.top,
            insets.right, edgeHeight, true, rightShouldTile,
            rightNumTiledIcons, rightStaticSpace);

    g.translate(-x, -y);
}
 
Example 4
Source File: MegamekBorder.java    From megamek with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Paints an edge for the border given a list of icons to paint.  We need
 * to know whether each icon should be tiled, how many tiled icons there 
 * are and how much space (width/height) needs to be filled by tiled icons.
 * 
 * @param c  The Component to pain on
 * @param g  The Graphics object to paint with 
 * @param isLeftRight Are we drawing a left or right edge?
 * @param icons The ImageIcons to draw
 * @param shouldTile  Denotes whether each icon should be tiled or not
 * @param numTiledIcons The number of tiled icons we have to draw with
 * @param staticSpace How much space needs to be filled with tiledi cons
 */
private void paintEdge(Component c, Graphics g, ArrayList<ImageIcon> icons, 
        int x, int y, int width, int height, boolean isLeftRight,
        ArrayList<Boolean> shouldTile, int numTiledIcons, int staticSpace){       
    g = g.create(x, y, width, height);
    
    // Determine how much width/height a tiled icons will get to consume
    int tiledWidth = isLeftRight ? width :
            (int)((width - staticSpace + 0.0) / numTiledIcons + 0.5);
    int tiledHeight = isLeftRight ? (int) ((height - staticSpace + 0.0)
            / numTiledIcons + 0.5) : height;
    
    x = 0; 
    y = 0;
    
    // Draw each icon
    for (int i = 0; i < icons.size(); i++){
        ImageIcon icon = icons.get(i);
        if (icon.getImageLoadStatus() != MediaTracker.COMPLETE){
            return;
        }
        if (shouldTile.get(i)){
            // Tile icons that should be tiled
            paintTiledIcon(c,g,icon,x,y,tiledWidth,tiledHeight);
            if (isLeftRight){
                y += tiledHeight;
            } else {
                x += tiledWidth;
            }
        } else {
            // Draw static icons once
            icons.get(i).paintIcon(c, g, x, y);
            if (isLeftRight){
                y+= icon.getIconHeight();
            } else {
                x+= icon.getIconWidth();
            }
        }
    }
    g.dispose();
}