Example #1
0
  /**
   * Creates a new JpegEncoder object.
   *
   * @param image DOCUMENT ME!
   * @param quality DOCUMENT ME!
   * @param tOut DOCUMENT ME!
   */
  public JpegEncoder(Image image, int quality, OutputStream tOut) {
    MediaTracker tracker = new MediaTracker(this);
    tracker.addImage(image, 0);

    try {
      tracker.waitForID(0);
    } catch (InterruptedException e) {
      // Got to do something?
    }

    /*
     * Quality of the image.
     * 0 to 100 and from bad image quality, high compression to good
     * image quality low compression
     */
    Quality = quality;

    /*
     * Getting picture information
     * It takes the Width, Height and RGB scans of the image.
     */
    JpegObj = new JpegInfo(image);

    imageHeight = JpegObj.imageHeight;
    imageWidth = JpegObj.imageWidth;

    // CoHort: out could be an internal OutputStream, but pointless,
    //  since I pass it a OutputStream already.
    out = tOut;
    dct = new DCT(Quality);
    Huf = new Huffman(imageWidth, imageHeight);
  }
Example #2
0
  public void init() {
    try {
      this.imLogo = this.getImage("icon.png");
      tracker.addImage(this.imLogo, 0);
      tracker.waitForID(0);
    } catch (InterruptedException inex) {

    }
    try {
      this.imHelp = this.getImage("helpphoto.png");
      tracker.addImage(this.imHelp, 1);
      tracker.waitForID(1);
    } catch (InterruptedException ie) {
    }
    this.fontTitle = new Font("GB2312", Font.BOLD, 25);
    this.fontText = new Font("GB2312", Font.PLAIN, 18);
    this.setBackground(Color.BLACK);
    this.setForeground(Color.WHITE);
    this.timer =
        new Timer(
            500,
            new ActionListener() {
              public void actionPerformed(ActionEvent ev) {
                world = new OSCWorld();
                world.onEnter();
                repaint();
                timer.stop();
              }
            });
    this.timer.start();
  }
  /**
   * Create a splash screen (borderless graphic for display while other operations are taking
   * place).
   *
   * @param filename a class-relative path to the splash graphic
   * @param callingClass the class to which the graphic filename location is relative
   */
  public SplashScreen(String filename, Class callingClass) {
    super(new Frame());
    URL imageURL = callingClass.getResource(filename);
    image = Toolkit.getDefaultToolkit().createImage(imageURL);
    // Load the image
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(image, 0);
    try {
      mt.waitForID(0);
    } catch (InterruptedException ie) {
    }

    // Center the window on the screen
    int imgWidth = image.getWidth(this);
    int imgHeight = image.getHeight(this);
    setSize(imgWidth, imgHeight);
    Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
    setLocation((screenDim.width - imgWidth) / 2, (screenDim.height - imgHeight) / 2);

    setVisible(true);
    repaint();
    // if on a single processor machine, wait for painting (see Fast Java Splash Screen.pdf)
    if (!EventQueue.isDispatchThread()) {
      synchronized (this) {
        while (!this.paintCalled) {
          try {
            this.wait();
          } catch (InterruptedException e) {
          }
        }
      }
    }
  }
Example #4
0
  /**
   * Gets the image using the specified dimension.
   *
   * @param d The <code>Dimension</code> of the requested image. Rescaling will be performed if
   *     necessary.
   * @return The <code>Image</code> with the required dimension.
   */
  public Image getImage(Dimension d) {
    final Image im = getImage();
    if (im == null || (im.getWidth(null) == d.width && im.getHeight(null) == d.height)) return im;

    synchronized (loadingLock) {
      final Image cached = scaledImages.get(d);
      if (cached != null) return cached;

      MediaTracker mt = new MediaTracker(_c);
      try {
        // Use SCALE_REPLICATE instead of SCALE_SMOOTH to avoid
        // ClassCastException.
        // TODO (perhaps): find a better solution.
        Image scaled = im.getScaledInstance(d.width, d.height, Image.SCALE_REPLICATE);
        mt.addImage(scaled, 0, d.width, d.height);
        mt.waitForID(0);
        int result = mt.statusID(0, false);
        if (result == MediaTracker.COMPLETE) {
          scaledImages.put(d, scaled);
        } else {
          logger.warning("Scaling image: " + getResourceLocator() + " => " + result);
        }
        return scaled;
      } catch (Exception e) {
        logger.log(Level.WARNING, "Failed to scale image: " + getResourceLocator(), e);
      }
    }
    return null;
  }
Example #5
0
  /**
   * Get the image associated with the given location string. If the image has already been loaded,
   * it simply will return the image, otherwise it will load it from the specified location.
   *
   * <p>The imageLocation argument must be a valid resource string pointing to either (a) a valid
   * URL, (b) a file on the classpath, or (c) a file on the local filesystem. The location will be
   * resolved in that order.
   *
   * @param imageLocation the image location as a resource string.
   * @return the corresponding image, if available
   */
  public Image getImage(String imageLocation) {
    Image image = (Image) imageCache.get(imageLocation);
    if (image == null && !loadMap.containsKey(imageLocation)) {
      URL imageURL = IOLib.urlFromString(imageLocation);
      if (imageURL == null) {
        System.err.println("Null image: " + imageLocation);
        return null;
      }
      image = Toolkit.getDefaultToolkit().createImage(imageURL);

      // if set for synchronous mode, block for image to load.
      if (!m_asynch) {
        waitForImage(image);
        addImage(imageLocation, image);
      } else {
        int id = ++nextTrackerID;
        tracker.addImage(image, id);
        loadMap.put(imageLocation, new LoadMapEntry(id, image));
      }
    } else if (image == null && loadMap.containsKey(imageLocation)) {
      LoadMapEntry entry = (LoadMapEntry) loadMap.get(imageLocation);
      if (tracker.checkID(entry.id, true)) {
        addImage(imageLocation, entry.image);
        loadMap.remove(imageLocation);
        tracker.removeImage(entry.image, entry.id);
      }
    } else {
      return image;
    }
    return (Image) imageCache.get(imageLocation);
  }
Example #6
0
  public ToolButton(PaletteListener listener, String iconName, String name, Tool tool) {
    super(listener);
    tool.addToolListener(this);
    setEnabled(tool.isUsable());

    // use a Mediatracker to ensure that all the images are initially loaded
    Iconkit kit = Iconkit.instance();
    if (kit == null) {
      throw new JHotDrawRuntimeException("Iconkit instance isn't set");
    }

    Image im[] = new Image[3];
    im[0] = kit.loadImageResource(iconName + "1.gif");
    im[1] = kit.loadImageResource(iconName + "2.gif");
    im[2] = kit.loadImageResource(iconName + "3.gif");

    MediaTracker tracker = new MediaTracker(this);
    for (int i = 0; i < 3; i++) {
      tracker.addImage(im[i], i);
    }
    try {
      tracker.waitForAll();
    } catch (Exception e) {
      // ignore exception
    }

    fIcon = new PaletteIcon(new Dimension(24, 24), im[0], im[1], im[2]);
    fTool = tool;
    fName = name;

    setIcon(new ImageIcon(im[0]));
    setPressedIcon(new ImageIcon(im[1]));
    setSelectedIcon(new ImageIcon(im[2]));
    setToolTipText(name);
  }
Example #7
0
  /**
   * Returns a scaled instance of the tile image. Using a MediaTracker instance, this function waits
   * until the scaling operation is done.
   *
   * <p>Internally it caches the scaled image in order to optimize the common case, where the same
   * scale is requested as the last time.
   *
   * @param zo
   * @return Image
   */
  public Image getScaledImage(double zo) {
    Image scaledImage = null;
    if (zo == 1.0) {
      return getImage();
    } else if (zo == zoom && scaledImage != null) {
      return scaledImage;
    } else {
      Image img = getImage();
      //            System.out.println(getWidth());
      if (img != null) {
        scaledImage =
            img.getScaledInstance(
                (int) (getWidth() * zo), (int) (getHeight() * zo), BufferedImage.SCALE_SMOOTH);

        MediaTracker mediaTracker = new MediaTracker(new Canvas());
        mediaTracker.addImage(scaledImage, 0);
        try {
          mediaTracker.waitForID(0);
        } catch (InterruptedException ie) {
          System.err.println(ie);
        }
        mediaTracker.removeImage(scaledImage);
        zoom = zo;
        return scaledImage;
      }
    }

    return null;
  }
  public myImageFade() {
    myImage1 = Toolkit.getDefaultToolkit().getImage("d:/1.jpg");
    myImage2 = Toolkit.getDefaultToolkit().getImage("d:/ball.gif");

    myImage1_scaled = myImage1.getScaledInstance(500, 500, Image.SCALE_FAST);
    myImage2_scaled = myImage2.getScaledInstance(500, 500, Image.SCALE_FAST);
    repaint();

    try {
      MediaTracker mt = new MediaTracker(this);
      mt.addImage(myImage1, 0);
      mt.addImage(myImage2, 0);
      mt.waitForAll();

      PixelGrabber grab1 =
          new PixelGrabber(myImage1, 0, 0, picWidth, picHeight, m_Img1Pix, 0, picWidth);
      PixelGrabber grab2 =
          new PixelGrabber(myImage2, 0, 0, picWidth, picHeight, m_Img2Pix, 0, picWidth);

      grab1.grabPixels();
      grab2.grabPixels();

      System.out.println(m_Img1Pix.length);

      System.out.println(m_Img1Pix[18500]);

      m_ImgSrc = new MemoryImageSource(picWidth, picHeight, m_Pix, 0, picWidth);
      m_ImgSrc.setAnimated(true);
      m_Img = createImage(m_ImgSrc);
    } catch (InterruptedException e) {
    }
  }
Example #9
0
    // This is used to create a CImage from a Image
    public CImage createFromImage(final Image image) {
      if (image == null) return null;

      MediaTracker mt = new MediaTracker(new Label());
      final int id = 0;
      mt.addImage(image, id);

      try {
        mt.waitForID(id);
      } catch (InterruptedException e) {
      }

      if (mt.isErrorID(id)) {
        return null;
      }

      int w = image.getWidth(null);
      int h = image.getHeight(null);
      BufferedImage bimg = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
      Graphics2D g2 = bimg.createGraphics();
      g2.setComposite(AlphaComposite.Src);
      g2.drawImage(image, 0, 0, null);
      g2.dispose();
      int[] buffer = ((DataBufferInt) bimg.getRaster().getDataBuffer()).getData();
      return new CImage(nativeCreateNSImageFromArray(buffer, w, h));
    }
Example #10
0
  DisplayCanvas() {
    setBackground(Color.white);
    setSize(450, 400);
    addMouseMotionListener(new MouseMotionHandler());

    Image image =
        getToolkit().getImage("D:\\Workspaces\\ADTJunoWorkspace\\Snippets\\images\\qr.png");

    MediaTracker mt = new MediaTracker(this);
    mt.addImage(image, 1);
    try {
      mt.waitForAll();
    } catch (Exception e) {
      System.out.println("Exception while loading image.");
    }

    if (image.getWidth(this) == -1) {
      System.out.println("no gif file");
      System.exit(0);
    }

    bi =
        new BufferedImage(image.getWidth(this), image.getHeight(this), BufferedImage.TYPE_INT_ARGB);
    Graphics2D big = bi.createGraphics();
    big.drawImage(image, 0, 0, this);
  }
  AnimationCanvas() {
    setBackground(Color.green);
    setSize(450, 400);

    image = getToolkit().getImage("largeJava2sLogo.gif");

    MediaTracker mt = new MediaTracker(this);
    mt.addImage(image, 1);
    try {
      mt.waitForAll();
    } catch (Exception e) {
      System.out.println("Exception while loading image.");
    }

    if (image.getWidth(this) == -1) {
      System.out.println("No gif file");
      System.exit(0);
    }

    rotate = (int) (Math.random() * 360);
    scale = Math.random() * 1.5;
    scaleDirection = DOWN;

    xi = 50.0;
    yi = 50.0;
  }
Example #12
0
  private void setup() throws IOException, UnsupportedAudioFileException, LineUnavailableException {
    startSounds();
    tracker = new MediaTracker(this);

    fishImages[0] = ImageIO.read(getClass().getResourceAsStream("fish1.gif"));
    tracker.addImage(fishImages[0], 0);

    fishImages[1] = ImageIO.read(getClass().getResourceAsStream("fish2.gif"));
    tracker.addImage(fishImages[1], 0);

    aquariumImage = ImageIO.read(getClass().getResourceAsStream("tank.png"));
    tracker.addImage(aquariumImage, 0);

    try {
      tracker.waitForID(0);
    } catch (Exception ex) {
      System.out.println(ex.getMessage());
    }

    setSize(aquariumImage.getWidth(this), aquariumImage.getHeight(this));
    setResizable(true);
    setVisible(true);
    memoryImage = createImage(getSize().width, getSize().height);
    memoryGraphics = memoryImage.getGraphics();
  }
Example #13
0
 /**
  * Load images (used for preloading images).
  *
  * @param images Array of <code>Image</code> instances to preload.
  * @param comp Component that will observe the loading state of the images.
  */
 public static void loadImages(Image[] images, Component comp) {
   MediaTracker tracker = new MediaTracker(comp);
   for (int i = 0; i < images.length; i++) tracker.addImage(images[i], 0);
   try {
     tracker.waitForID(0);
   } catch (InterruptedException ignore) {
   }
 }
Example #14
0
  /**
   * Обучение перцептрона
   *
   * @param path
   * @param n - количество циклов обучения
   */
  public void teach(String path, int n) {

    class JPGFilter implements FilenameFilter {
      public boolean accept(File dir, String name) {
        return (name.endsWith(".jpg"));
      }
    }

    // загрузка всех тестовых изображений в массив img[]
    String[] list = new File(path + "/").list(new JPGFilter());
    Image[] img = new Image[list.length];
    MediaTracker mediaTracker = new MediaTracker(new Container());
    int i = 0;
    for (String s : list) {
      img[i] = java.awt.Toolkit.getDefaultToolkit().createImage(path + "/" + s);

      mediaTracker.addImage(img[i], 0);
      try {
        mediaTracker.waitForAll();
      } catch (InterruptedException ex) {
        Logger.getLogger(Teacher.class.getName()).log(Level.SEVERE, null, ex);
      }

      i++;
    }

    // инициализация начальных весов, если ещё не были проинициализированы
    if (!perceptron.isWeightsWasInitialized()) {
      perceptron.initWeights();
    }

    // получение пиксельных массивов каждого изображения
    // и обучение n раз каждой выборке
    PixelGrabber pg;
    int[] pixels, x, y;
    int w, h, k = 0;
    while (n-- > 0) {
      for (int j = 0; j < img.length; j++) {
        w = img[j].getWidth(null);
        h = img[j].getHeight(null);

        if (w * h > perceptron.getM()) continue;

        pixels = new int[w * h];
        pg = new PixelGrabber(img[j], 0, 0, w, h, pixels, 0, w);
        try {
          pg.grabPixels();
        } catch (InterruptedException ex) {
          Logger.getLogger(Teacher.class.getName()).log(Level.SEVERE, null, ex);
        }

        // получение векторов и обучение перцептрона
        x = getInVector(pixels);
        y = getOutVector(Integer.parseInt(String.valueOf(list[j].charAt(0))));
        perceptron.teach(x, y);
      }
    }
  }
Example #15
0
 public static void waitForImage(Component component, Image image) {
   MediaTracker tracker = new MediaTracker(component);
   try {
     tracker.addImage(image, 0);
     tracker.waitForID(0);
   } catch (InterruptedException e) {
     Assert.isNotNull(null);
   }
 }
Example #16
0
  public void updateScreen() {
    boolean olay = false;

    int imageSize = 0;
    URL url = null;
    BufferedInputStream bs = null;
    DataInputStream ds = null;
    int i = 0;

    delay(1000);

    String imageName = new String();
    imageName = "initial.jpg";
    diskWidth = 512;
    diskHeight = 512;
    x = 0;
    y = 0;

    if (screenMode != 5) {
      olay = true;
      read_Overlay(0);
    } else {
      eraseAll();
      olay = false;
    }

    imageSize = diskWidth * diskHeight;

    try {
      url = new URL(codebase, imageName);
    } catch (MalformedURLException e1) {
      System.out.println("URL Error");
    }

    if (screenMode == 6) // Spectrum
    read_Overlay(1);
    else if (screenMode == 7) // X-Ray Map
    getJpegImage(url, x, y, diskWidth, diskHeight);
    else if (screenMode != 9) // All else
    readJpegImage(url, x, y, diskWidth, diskHeight);

    if (screenMode != 7) // Combine Mem and Overlay except for X-Ray Map
    combine_Mem_Olay(screenMode, olay);

    MemoryImageSource mis = new MemoryImageSource(512, 512, pixel, 0, 512);
    image = createImage(mis);
    tracker.addImage(image, 0, 512, 512);

    try {
      tracker.waitForAll();
    } catch (InterruptedException e) {
    }

    repaint();

    tracker.removeImage(image, 0);
  }
Example #17
0
 /**
  * Loads all images to be used by the GUI, and waits for them to be fully loaded before returning.
  */
 private void loadImages() {
   MediaTracker tracker = new MediaTracker(this);
   Toolkit tk = Toolkit.getDefaultToolkit();
   background = loadImage(tk, "images/background.gif", tracker);
   try {
     tracker.waitForID(0);
   } catch (InterruptedException ie) {
   }
 }
Example #18
0
 /**
  * Carica l'immagine
  *
  * @param img Immagine da caricare
  */
 private void loadImage(Image img) {
   try {
     MediaTracker track = new MediaTracker(this);
     track.addImage(img, 0);
     track.waitForID(0);
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
Example #19
0
 /** Waits for given image to load. Use before querying image height/width/colors. */
 private static void waitForImage(Image image) {
   try {
     tracker.addImage(image, 0);
     tracker.waitForID(0);
     tracker.removeImage(image, 0);
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
 }
Example #20
0
 private synchronized void waitForImage(java.awt.Image image) {
   if (mediaTracker == null) mediaTracker = new MediaTracker(new PdfGraphics2D.FakeComponent());
   mediaTracker.addImage(image, 0);
   try {
     mediaTracker.waitForID(0);
   } catch (InterruptedException e) {
     // empty on purpose
   }
   mediaTracker.removeImage(image);
 }
Example #21
0
 /**
  * Wait for an image to load.
  *
  * @param image the image to wait for
  */
 protected void waitForImage(Image image) {
   int id = ++nextTrackerID;
   tracker.addImage(image, id);
   try {
     tracker.waitForID(id, 0);
   } catch (InterruptedException e) {
     e.printStackTrace();
   }
   tracker.removeImage(image, id);
 }
  /**
   * @param bufInputStream
   * @param outputStream
   */
  private void writeScaledImage(BufferedInputStream bufInputStream, OutputStream outputStream) {

    long millis = System.currentTimeMillis();
    try {
      ByteArrayOutputStream bos = new ByteArrayOutputStream();

      int bytesRead = 0;
      byte[] buffer = new byte[8192];
      while ((bytesRead = bufInputStream.read(buffer, 0, 8192)) != -1) {
        bos.write(buffer, 0, bytesRead);
      }
      bos.close();

      byte[] imageBytes = bos.toByteArray();

      Image image = Toolkit.getDefaultToolkit().createImage(imageBytes);
      MediaTracker mediaTracker = new MediaTracker(new Container());
      mediaTracker.addImage(image, 0);
      mediaTracker.waitForID(0);
      // determine thumbnail size from WIDTH and HEIGHT
      int thumbWidth = 300;
      int thumbHeight = 200;
      double thumbRatio = (double) thumbWidth / (double) thumbHeight;
      int imageWidth = image.getWidth(null);
      int imageHeight = image.getHeight(null);
      double imageRatio = (double) imageWidth / (double) imageHeight;
      if (thumbRatio < imageRatio) {
        thumbHeight = (int) (thumbWidth / imageRatio);
      } else {
        thumbWidth = (int) (thumbHeight * imageRatio);
      }
      // draw original image to thumbnail image object and
      // scale it to the new size on-the-fly
      BufferedImage thumbImage =
          new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB);
      Graphics2D graphics2D = thumbImage.createGraphics();
      graphics2D.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
      graphics2D.drawImage(image, 0, 0, thumbWidth, thumbHeight, null);

      JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(outputStream);
      JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(thumbImage);
      int quality = 70;
      quality = Math.max(0, Math.min(quality, 100));
      param.setQuality((float) quality / 100.0f, false);
      encoder.setJPEGEncodeParam(param);
      encoder.encode(thumbImage);
    } catch (IOException ex) {
      log.error(ex.getMessage(), ex);
    } catch (InterruptedException ex) {
      log.error(ex.getMessage(), ex);
    } finally {
      log.debug("Time for thumbnail: " + (System.currentTimeMillis() - millis) + "ms");
    }
  }
Example #23
0
 public RotatePanel(Image image) {
   this.image = image;
   MediaTracker mt = new MediaTracker(this);
   mt.addImage(image, 0);
   try {
     mt.waitForID(0);
   }
   catch (Exception e) {
     e.printStackTrace();
   }
 }
 private static boolean waitForImage(Image image) {
   if (image == null) return false;
   if (image.getWidth(null) > 0) return true;
   MediaTracker mediatracker = new MediaTracker(ourComponent);
   mediatracker.addImage(image, 1);
   try {
     mediatracker.waitForID(1, 5000);
   } catch (InterruptedException ex) {
     LOG.info(ex);
   }
   return !mediatracker.isErrorID(1);
 }
Example #25
0
 /*		Konstruktor
  *
  *		arg:	fname = Dateiname des Bildes
  *				width, height = Breite und Hoehe der Icons in Pixels
  */
 public IconBitmap(Image img, int width, int height) {
   this.img = img;
   d = new Dimension(width, height);
   MediaTracker mt = new MediaTracker(this);
   mt.addImage(img, 0);
   try {
     mt.waitForAll();
   } catch (InterruptedException ex) {
     // nothing
   }
   cols = img.getWidth(this) / d.width;
   rows = img.getHeight(this) / d.height;
 }
Example #26
0
  /** Show the splash screen to the end user. */
  public void splash() {
    initImageAndTracker();
    setSize(fImage.getWidth(null), fImage.getHeight(null));
    center();

    fMediaTracker.addImage(fImage, 0);
    try {
      fMediaTracker.waitForID(0);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    new SplashWindow(this, fImage);
  }
  /**
   * converts an image resource to an AWT image.
   *
   * @param imageResource image resource
   * @return AWT image
   */
  private Image toAwtImage(Resource imageResource) {
    Image image = Toolkit.getDefaultToolkit().getImage(imageResource.toURL());
    MediaTracker mediaTracker = new MediaTracker(new Container());
    mediaTracker.addImage(image, 0);

    try {
      mediaTracker.waitForID(0);
    } catch (InterruptedException e) {
      throw new RuntimeException(e);
    }

    return image;
  }
  /** Retrieve all images. This thread will self-terminate once all are loaded. */
  public void run() {
    // The media Tracker ensures all images are fully loaded: This avoids the
    // arbitrary race conditions that may happen when running a plugin before all
    // images have been properly loaded,
    java.awt.MediaTracker mt = new java.awt.MediaTracker(peer);

    // Create a CardImages to house the deck of card images.
    CardImages ci = new CardImages();

    CardEnumeration ce = new CardEnumeration();
    int idx = 1;
    while (ce.hasMoreElements()) {
      Card c = (Card) ce.nextElement();
      String key = c.getName();

      // extract from resource file (prepend images directory)
      try {
        File f = new File(imageDirectory + deckType + "/" + key + ".gif");
        java.net.URL url = f.toURI().toURL();

        // java.net.URL url = this.getClass().getResource (str);
        Image img = java.awt.Toolkit.getDefaultToolkit().getImage(url);
        mt.addImage(img, idx++);
        ci.setCardImage(c, img);
      } catch (MalformedURLException mue) {
        return;
      }
    }

    // Also get Back (already in the images directory)
    try {
      File f = new File(imageDirectory + deckType + "/" + backResourceName + ".gif");
      java.net.URL url = f.toURI().toURL();
      Image img = java.awt.Toolkit.getDefaultToolkit().getImage(url);
      mt.addImage(img, idx++);
      ci.setCardReverse(img);
    } catch (MalformedURLException mue) {
      return;
    }

    try {
      mt.waitForAll();
    } catch (InterruptedException ie) {
    }

    // keep around so thread can return this value in synchronized method getLoadedCardImages
    loadedImages = ci;

    // we are done.
    readyStatus = true;
  }
Example #29
0
 private void ensureImageLoaded(final Image anImage) {
   if (anImage.getWidth(this) != -1) {
     return;
   }
   final MediaTracker tracker = new MediaTracker(this);
   tracker.addImage(anImage, 1);
   try {
     tracker.waitForAll(1);
   } catch (final InterruptedException ie) {
     ie.printStackTrace();
     System.err.println("<<<<<<<<<<<<<<<<<<<<<<>trying again to load Image");
     ensureImageLoaded(anImage);
   }
 }
Example #30
0
  /**
   * We need to load animated .gifs through this mechanism vs. getImage due to a number of bugs in
   * Java's image loading routines.
   *
   * @param name The path of the image
   * @param who The component that will use the image
   * @return the loaded image object
   */
  public static Image getDirectImage(String name, Component who) {
    Image image = null;

    // try to get the URL as a system resource
    URL url = ClassLoader.getSystemResource(name);
    try {
      image = Toolkit.getDefaultToolkit().createImage(url);
      MediaTracker tracker = new MediaTracker(who);
      tracker.addImage(image, 0);
      tracker.waitForAll();
    } catch (InterruptedException e) {
    }
    return image;
  }