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

The following examples show how to use java.awt.MediaTracker#waitForAll() . 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: RuntimeBuiltinLeafInfoImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private BufferedImage convertToBufferedImage(Image image) throws IOException {
    if (image instanceof BufferedImage) {
        return (BufferedImage)image;

    } else {
        MediaTracker tracker = new MediaTracker(new Component(){}); // not sure if this is the right thing to do.
        tracker.addImage(image, 0);
        try {
            tracker.waitForAll();
        } catch (InterruptedException e) {
            throw new IOException(e.getMessage());
        }
        BufferedImage bufImage = new BufferedImage(
                image.getWidth(null),
                image.getHeight(null),
                BufferedImage.TYPE_INT_ARGB);

        Graphics g = bufImage.createGraphics();
        g.drawImage(image, 0, 0, null);
        return bufImage;
    }
}
 
Example 2
Source File: SwAOutInterceptor.java    From cxf with Apache License 2.0 6 votes vote down vote up
private BufferedImage convertToBufferedImage(Image image) throws IOException {
    if (image instanceof BufferedImage) {
        return (BufferedImage)image;
    }

    // Wait until the image is completely loaded
    MediaTracker tracker = new MediaTracker(new Component() {
        private static final long serialVersionUID = 6412221228374321325L;
    });
    tracker.addImage(image, 0);
    try {
        tracker.waitForAll();
    } catch (InterruptedException e) {
        throw new Fault(e);
    }

    // Create a BufferedImage so we can write it out later
    BufferedImage bufImage = new BufferedImage(
            image.getWidth(null),
            image.getHeight(null),
            BufferedImage.TYPE_INT_ARGB);

    Graphics g = bufImage.createGraphics();
    g.drawImage(image, 0, 0, null);
    return bufImage;
}
 
Example 3
Source File: ImageHelper.java    From cxf with Apache License 2.0 6 votes vote down vote up
private static BufferedImage convertToBufferedImage(Image image) throws IOException {
    if (image instanceof BufferedImage) {
        return (BufferedImage)image;
    }
    /*not sure how this is used*/
    MediaTracker tracker = new MediaTracker(null);
    tracker.addImage(image, 0);
    try {
        tracker.waitForAll();
    } catch (InterruptedException e) {
        throw new IOException(e.getMessage());
    }
    BufferedImage bufImage = new BufferedImage(
                                               image.getWidth(null),
                                               image.getHeight(null),
                                               BufferedImage.TYPE_INT_RGB);
    Graphics g = bufImage.createGraphics();
    g.drawImage(image, 0, 0, null);
    return bufImage;
}
 
Example 4
Source File: TileImageBreaker.java    From triplea with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Asks the user to select an image and then it loads it up into an Image object and returns it to
 * the calling class.
 *
 * @return The loaded image.
 */
private Image loadImage() {
  log.info("Select the map");
  final String mapName =
      new FileOpen("Select The Map", mapFolderLocation, ".gif", ".png").getPathString();
  if (mapName != null) {
    final Image img = Toolkit.getDefaultToolkit().createImage(mapName);
    final MediaTracker tracker = new MediaTracker(new Panel());
    tracker.addImage(img, 1);
    try {
      tracker.waitForAll();
      return img;
    } catch (final InterruptedException e) {
      Thread.currentThread().interrupt();
    }
  }
  return null;
}
 
Example 5
Source File: ReliefImageBreaker.java    From triplea with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Asks the user to select an image and then it loads it up into an Image object and returns it to
 * the calling class.
 *
 * @return The loaded image.
 */
private Image loadImage() {
  log.info("Select the map");
  final String mapName =
      new FileOpen("Select The Map", mapFolderLocation, ".gif", ".png").getPathString();
  if (mapName != null) {
    final Image img = Toolkit.getDefaultToolkit().createImage(mapName);
    final MediaTracker tracker = new MediaTracker(new Panel());
    tracker.addImage(img, 1);
    try {
      tracker.waitForAll();
      return img;
    } catch (final InterruptedException e) {
      Thread.currentThread().interrupt();
    }
  }
  return null;
}
 
Example 6
Source File: MarsMap.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Constructs a MarsMap object
 * 
 * @param globeType   the type of globe: surface, topo or geo
 * @param displayArea the display component for the map
 */
public MarsMap(MarsMapType globeType, JComponent displayArea) {

	// Initialize Variables
	// this.globeType = globeType;
	this.displayArea = displayArea;
	centerCoords = new Coordinates(PI_half, PI_half);

	// Load Surface Map Image, which is now part of the globe enum
	String imageName = globeType.getPath();

	MediaTracker mtrack = new MediaTracker(displayArea);
	marsMap = ImageLoader.getImage(imageName);
	mtrack.addImage(marsMap, 0);
	try {
		mtrack.waitForAll();
	} catch (InterruptedException e) {
		logger.log(Level.SEVERE, Msg.getString("MarsMap.log.mediaTrackerError", e.toString())); //$NON-NLS-1$
	}

	// Prepare Sphere
	setupSphere();
}
 
Example 7
Source File: Util.java    From beanshell with Apache License 2.0 6 votes vote down vote up
public static void startSplashScreen()
{
    int width=275,height=148;
    Window win=new Window( new Frame() );
    win.pack();
    BshCanvas can=new BshCanvas();
    can.setSize( width, height ); // why is this necessary?
    Toolkit tk=Toolkit.getDefaultToolkit();
    Dimension dim=tk.getScreenSize();
    win.setBounds(
        dim.width/2-width/2, dim.height/2-height/2, width, height );
    win.add("Center", can);
    Image img=tk.getImage(
        Interpreter.class.getResource("/bsh/util/lib/splash.gif") );
    MediaTracker mt=new MediaTracker(can);
    mt.addImage(img,0);
    try { mt.waitForAll(); } catch ( Exception e ) { }
    Graphics gr=can.getBufferedGraphics();
    gr.drawImage(img, 0, 0, can);
    win.setVisible(true);
    win.toFront();
    splashScreen = win;
}
 
Example 8
Source File: RuntimeBuiltinLeafInfoImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private BufferedImage convertToBufferedImage(Image image) throws IOException {
    if (image instanceof BufferedImage) {
        return (BufferedImage)image;

    } else {
        MediaTracker tracker = new MediaTracker(new Component(){}); // not sure if this is the right thing to do.
        tracker.addImage(image, 0);
        try {
            tracker.waitForAll();
        } catch (InterruptedException e) {
            throw new IOException(e.getMessage());
        }
        BufferedImage bufImage = new BufferedImage(
                image.getWidth(null),
                image.getHeight(null),
                BufferedImage.TYPE_INT_ARGB);

        Graphics g = bufImage.createGraphics();
        g.drawImage(image, 0, 0, null);
        return bufImage;
    }
}
 
Example 9
Source File: RuntimeBuiltinLeafInfoImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private BufferedImage convertToBufferedImage(Image image) throws IOException {
    if (image instanceof BufferedImage) {
        return (BufferedImage)image;

    } else {
        MediaTracker tracker = new MediaTracker(new Component(){}); // not sure if this is the right thing to do.
        tracker.addImage(image, 0);
        try {
            tracker.waitForAll();
        } catch (InterruptedException e) {
            throw new IOException(e.getMessage());
        }
        BufferedImage bufImage = new BufferedImage(
                image.getWidth(null),
                image.getHeight(null),
                BufferedImage.TYPE_INT_ARGB);

        Graphics g = bufImage.createGraphics();
        g.drawImage(image, 0, 0, null);
        return bufImage;
    }
}
 
Example 10
Source File: RuntimeBuiltinLeafInfoImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private BufferedImage convertToBufferedImage(Image image) throws IOException {
    if (image instanceof BufferedImage) {
        return (BufferedImage)image;

    } else {
        MediaTracker tracker = new MediaTracker(new Component(){}); // not sure if this is the right thing to do.
        tracker.addImage(image, 0);
        try {
            tracker.waitForAll();
        } catch (InterruptedException e) {
            throw new IOException(e.getMessage());
        }
        BufferedImage bufImage = new BufferedImage(
                image.getWidth(null),
                image.getHeight(null),
                BufferedImage.TYPE_INT_ARGB);

        Graphics g = bufImage.createGraphics();
        g.drawImage(image, 0, 0, null);
        return bufImage;
    }
}
 
Example 11
Source File: RuntimeBuiltinLeafInfoImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private BufferedImage convertToBufferedImage(Image image) throws IOException {
    if (image instanceof BufferedImage) {
        return (BufferedImage)image;

    } else {
        MediaTracker tracker = new MediaTracker(new Component(){}); // not sure if this is the right thing to do.
        tracker.addImage(image, 0);
        try {
            tracker.waitForAll();
        } catch (InterruptedException e) {
            throw new IOException(e.getMessage());
        }
        BufferedImage bufImage = new BufferedImage(
                image.getWidth(null),
                image.getHeight(null),
                BufferedImage.TYPE_INT_ARGB);

        Graphics g = bufImage.createGraphics();
        g.drawImage(image, 0, 0, null);
        return bufImage;
    }
}
 
Example 12
Source File: RuntimeBuiltinLeafInfoImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private BufferedImage convertToBufferedImage(Image image) throws IOException {
    if (image instanceof BufferedImage) {
        return (BufferedImage)image;

    } else {
        MediaTracker tracker = new MediaTracker(new Component(){}); // not sure if this is the right thing to do.
        tracker.addImage(image, 0);
        try {
            tracker.waitForAll();
        } catch (InterruptedException e) {
            throw new IOException(e.getMessage());
        }
        BufferedImage bufImage = new BufferedImage(
                image.getWidth(null),
                image.getHeight(null),
                BufferedImage.TYPE_INT_ARGB);

        Graphics g = bufImage.createGraphics();
        g.drawImage(image, 0, 0, null);
        return bufImage;
    }
}
 
Example 13
Source File: RuntimeBuiltinLeafInfoImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private BufferedImage convertToBufferedImage(Image image) throws IOException {
    if (image instanceof BufferedImage) {
        return (BufferedImage)image;

    } else {
        MediaTracker tracker = new MediaTracker(new Component(){}); // not sure if this is the right thing to do.
        tracker.addImage(image, 0);
        try {
            tracker.waitForAll();
        } catch (InterruptedException e) {
            throw new IOException(e.getMessage());
        }
        BufferedImage bufImage = new BufferedImage(
                image.getWidth(null),
                image.getHeight(null),
                BufferedImage.TYPE_INT_ARGB);

        Graphics g = bufImage.createGraphics();
        g.drawImage(image, 0, 0, null);
        return bufImage;
    }
}
 
Example 14
Source File: Util.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
public static void ensureImageLoaded(final Image anImage) {
  final MediaTracker tracker = new MediaTracker(component);
  tracker.addImage(anImage, 1);
  try {
    tracker.waitForAll();
    tracker.removeImage(anImage);
  } catch (final InterruptedException ignored) {
    Thread.currentThread().interrupt();
  }
}
 
Example 15
Source File: GoldToad.java    From javagame with MIT License 5 votes vote down vote up
/**
 * �^�̉摜�����[�h����B
 * 
 * @param panel MainPanel�ւ̎Q�ƁB
 */
protected void loadImage(MainPanel panel) {
    MediaTracker tracker = new MediaTracker(panel);
    toadImage = Toolkit.getDefaultToolkit().getImage(
            getClass().getResource("gold_toad.gif"));
    tracker.addImage(toadImage, 0);
    try {
        tracker.waitForAll();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
 
Example 16
Source File: BlueToad.java    From javagame with MIT License 5 votes vote down vote up
/**
 * �^�̉摜�����[�h����B
 * 
 * @param panel MainPanel�ւ̎Q�ƁB
 */
protected void loadImage(MainPanel panel) {
    MediaTracker tracker = new MediaTracker(panel);
    toadImage = Toolkit.getDefaultToolkit().getImage(
            getClass().getResource("blue_toad.gif"));
    tracker.addImage(toadImage, 0);
    try {
        tracker.waitForAll();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
 
Example 17
Source File: SplashScreen.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
ImageCanvas(Image img_) throws InterruptedException {
  img = img_;
  MediaTracker mt = new MediaTracker(this);
  mt.addImage(img, 0);
  mt.waitForAll();
  setSize(img.getWidth(this), img.getHeight(this));
}
 
Example 18
Source File: NavButtonDisplay.java    From mars-sim with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Constructor.
 * @param parentNavigator the navigator window pane
 */
public NavButtonDisplay(NavigatorWindow parentNavigator) {

	// Set component size
	setPreferredSize(new Dimension(150, 150));
	setMaximumSize(getPreferredSize());
	setMinimumSize(getPreferredSize());

	// Set mouse listener
	addMouseListener(this);

	// Initialize globals
	centerCoords = new Coordinates(Math.PI / 2D, 0D);
	buttonLight = -1;
	lightUpButtons = new Image[9];
	this.parentNavigator = parentNavigator;

	// Load Button Images
	navMain = ImageLoader.getImage(Msg.getString("img.nav.main")); //$NON-NLS-1$
	lightUpButtons[0] = ImageLoader.getImage(Msg.getString("img.nav.plus.main")); //$NON-NLS-1$
	lightUpButtons[1] = ImageLoader.getImage(Msg.getString("img.nav.north")); //$NON-NLS-1$
	lightUpButtons[2] = ImageLoader.getImage(Msg.getString("img.nav.south")); //$NON-NLS-1$
	lightUpButtons[3] = ImageLoader.getImage(Msg.getString("img.nav.east")); //$NON-NLS-1$
	lightUpButtons[4] = ImageLoader.getImage(Msg.getString("img.nav.west")); //$NON-NLS-1$
	lightUpButtons[5] = ImageLoader.getImage(Msg.getString("img.nav.plus.north")); //$NON-NLS-1$
	lightUpButtons[6] = ImageLoader.getImage(Msg.getString("img.nav.plus.south")); //$NON-NLS-1$
	lightUpButtons[7] = ImageLoader.getImage(Msg.getString("img.nav.plus.east")); //$NON-NLS-1$
	lightUpButtons[8] = ImageLoader.getImage(Msg.getString("img.nav.plus.west")); //$NON-NLS-1$

	MediaTracker mtrack = new MediaTracker(this);

	mtrack.addImage(navMain, 0);
	for (int x = 0; x < 9; x++) {
		mtrack.addImage(lightUpButtons[x], x + 1);
	}

	try { mtrack.waitForAll(); }
	catch (InterruptedException e) {
		logger.log(Level.SEVERE,Msg.getString("NavButtonDisplay.log.mediaTrackerError", e.toString())); //$NON-NLS-1$
	}

	// Set hot spots for mouse clicks
	hotSpots = new Rectangle[9];
	hotSpots[0] = new Rectangle(45, 45, 60, 60);
	hotSpots[1] = new Rectangle(38, 16, 74, 21);
	hotSpots[2] = new Rectangle(38, 112, 74, 21);
	hotSpots[3] = new Rectangle(113, 38, 21, 74);
	hotSpots[4] = new Rectangle(17, 38, 21, 74);
	hotSpots[5] = new Rectangle(60, 0, 29, 14);
	hotSpots[6] = new Rectangle(60, 134, 29, 14);
	hotSpots[7] = new Rectangle(135, 61, 15, 28);
	hotSpots[8] = new Rectangle(0, 61, 15, 28);
}
 
Example 19
Source File: MechPanelTabStrip.java    From megamek with GNU General Public License v2.0 4 votes vote down vote up
private void setImages() {
    UnitDisplaySkinSpecification udSpec = SkinXMLHandler
            .getUnitDisplaySkin();
    MediaTracker mt = new MediaTracker(this);
    Toolkit tk = getToolkit();
    idleImage[0] = tk.getImage(new MegaMekFile(Configuration.widgetsDir(), udSpec.getGeneralTabIdle()).toString());
    idleImage[1] = tk.getImage(new MegaMekFile(Configuration.widgetsDir(), udSpec.getPilotTabIdle()).toString());
    idleImage[2] = tk.getImage(new MegaMekFile(Configuration.widgetsDir(), udSpec.getArmorTabIdle()).toString());
    idleImage[3] = tk.getImage(new MegaMekFile(Configuration.widgetsDir(), udSpec.getSystemsTabIdle()).toString());
    idleImage[4] = tk.getImage(new MegaMekFile(Configuration.widgetsDir(), udSpec.getWeaponsTabIdle()).toString());
    idleImage[5] = tk.getImage(new MegaMekFile(Configuration.widgetsDir(), udSpec.getExtrasTabIdle()).toString());
    activeImage[0] = tk.getImage(new MegaMekFile(Configuration.widgetsDir(), udSpec.getGeneralTabActive()).toString());
    activeImage[1] = tk.getImage(new MegaMekFile(Configuration.widgetsDir(), udSpec.getPilotTabActive()).toString());
    activeImage[2] = tk.getImage(new MegaMekFile(Configuration.widgetsDir(), udSpec.getArmorTabActive()).toString());
    activeImage[3] = tk.getImage(new MegaMekFile(Configuration.widgetsDir(), udSpec.getSystemsTabActive()).toString());
    activeImage[4] = tk.getImage(new MegaMekFile(Configuration.widgetsDir(), udSpec.getWeaponsTabActive()).toString());
    activeImage[5] = tk.getImage(new MegaMekFile(Configuration.widgetsDir(), udSpec.getExtraTabActive()).toString());
    idleCorner = tk.getImage(new MegaMekFile(Configuration.widgetsDir(), udSpec.getCornerIdle()).toString());
    selectedCorner = tk.getImage(new MegaMekFile(Configuration.widgetsDir(), udSpec.getCornerActive()).toString());

    // If we don't flush, we might have stale data
    idleCorner.flush();
    selectedCorner.flush();

    for (int i = 0; i < 6; i++) {
        // If we don't flush, we might have stale data
        idleImage[i].flush();
        activeImage[i].flush();
        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$
    }

    for (int i = 0; i < 6; i++) {
        if (idleImage[i].getWidth(null) != activeImage[i].getWidth(null)) {
            System.out.println("TabStrip Warning: idleImage and "
                    + "activeImage do not match widths for image " + i);
        }
        if (idleImage[i].getHeight(null) != activeImage[i].getHeight(null)) {
            System.out.println("TabStrip Warning: idleImage and "
                    + "activeImage do not match heights for image " + i);
        }
    }
    if (idleCorner.getWidth(null) != selectedCorner.getWidth(null)) {
        System.out.println("TabStrip Warning: idleCorner and "
                + "selectedCorner do not match widths!");
    }
    if (idleCorner.getHeight(null) != selectedCorner.getHeight(null)) {
        System.out.println("TabStrip Warning: idleCorner and "
                + "selectedCorner do not match heights!");
    }
}
 
Example 20
Source File: TN5250jSplashScreen.java    From tn5250j with GNU General Public License v2.0 4 votes vote down vote up
/**
    * Creates the Splash screen window and configures it.
    */
   protected void initialize(ImageIcon iimage) {

      image = iimage.getImage();
      // if no image, return
      if (image == null) {
         throw new IllegalArgumentException("Image specified is invalid.");
      }
//      System.out.println(" here in splash ");

      MediaTracker tracker = new MediaTracker(this);
      tracker.addImage(image,0);

      try {
         tracker.waitForAll();
      }
      catch(Exception e) {
         System.out.println(e.getMessage());
      }

      // create dialog window
      f = new Frame();
      dialog = new Window(f);
      dialog.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
      Dimension s = new Dimension(image.getWidth(this) + 2,
         image.getHeight(this) + 2);
      setSize(s);
      dialog.setLayout(new BorderLayout());
      dialog.setSize(s);

      dialog.add(this,BorderLayout.CENTER);
      dialog.pack();

      // position splash screen
      Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
      int x = (screen.width - s.width)/2;
      if (x < 0) {
         x = 0;
      }

      int y = (screen.height - s.height)/2;
      if (y < 0) {
         y = 0;
      }

      dialog.setLocation(x, y);
      dialog.validate();

   }