Java Code Examples for java.awt.MediaTracker#isErrorID()
The following examples show how to use
java.awt.MediaTracker#isErrorID() .
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: PMUtil.java From megamek with GNU General Public License v2.0 | 6 votes |
/** * Ensures that Images is completely loaded */ public static boolean setImage(Image im, JComponent c) { boolean b = true; MediaTracker mt = new MediaTracker(c); mt.addImage(im, 0); try { mt.waitForID(0); } catch (InterruptedException e) { System.out.println("Error while image loading."); //$NON-NLS-1$ b = false; } if (mt.isErrorID(0)) { System.out.println("Could Not load Image."); //$NON-NLS-1$ b = false; } return b; }
Example 2
Source File: GraphicUtils.java From xyTalk-pc with GNU Affero General Public License v3.0 | 5 votes |
/** * 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 3
Source File: JRJdk13ImageReader.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
@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 4
Source File: ExtendedTGPanel.java From ontopia with Apache License 2.0 | 5 votes |
public Image getImage(String imageSource) { try { URL sourceURL = new URL(imageSource); if (sourceURL.getProtocol().equals("file") && !(new File(sourceURL.getPath())).exists()) { ErrorDialog.showError(this, "File not found: " + imageSource); return null; } Image other = Toolkit.getDefaultToolkit().createImage(sourceURL); MediaTracker tracker = new MediaTracker(this); int imageId = 0; tracker.addImage(other, imageId); tracker.waitForID(0); boolean isError = tracker.isErrorID(imageId); if (isError) { ErrorDialog.showError(this, "There were problems reading the background image: " + imageSource); return null; } return other; } catch (IOException e) { throw new OntopiaRuntimeException(e); } catch (InterruptedException ie) { throw new OntopiaRuntimeException("InterruptedException caused during" + " wallpaper_image error check.", ie); } }
Example 5
Source File: GraphicUtils.java From Spark with Apache License 2.0 | 5 votes |
/** * 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 6
Source File: MechPanelTabStrip.java From megamek with GNU General Public License v2.0 | 4 votes |
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!"); } }