Projects >> glg2d >>8c04cf71a1f200b747325d6397f567901a5ca33f

Chunk
Conflicting content
    return true;
  }

<<<<<<< HEAD
  protected Texture getTexture(Image image) {
    Texture texture = cache.get(image);
    if (texture == null) {
      texture = createTexture(image);
      cache.put(image, texture);
    }

    return texture;
  }

  protected Texture createTexture(Image image) {
    BufferedImage bufferedImage;
    if (image instanceof BufferedImage) {
      bufferedImage = (BufferedImage) image;
    } else {
      bufferedImage = new BufferedImage(image.getHeight(null), image.getWidth(null), BufferedImage.TYPE_3BYTE_BGR);
      bufferedImage.createGraphics().drawImage(image, null, null);
    }

    Texture texture = TextureIO.newTexture(bufferedImage, false);
    return texture;
  }

  @SuppressWarnings("serial")
  protected static class TextureCache extends HashMap, Texture> {
    private ReferenceQueue queue = new ReferenceQueue();

    public void expungeStaleEntries() {
      Reference ref = queue.poll();
      while (ref != null) {
        remove(ref).dispose();
        ref = queue.poll();
      }
    }

    public Texture get(Image image) {
      expungeStaleEntries();
      WeakKey key = new WeakKey(image, null);
      return get(key);
    }

    public Texture put(Image image, Texture texture) {
      expungeStaleEntries();
      WeakKey key = new WeakKey(image, queue);
      return put(key, texture);
    }
  }

  protected static class WeakKey extends WeakReference {
    private final int hash;

    public WeakKey(T value, ReferenceQueue queue) {
      super(value, queue);
      hash = value.hashCode();
    }

    @Override
    public int hashCode() {
      return hash;
    }

    @Override
    public boolean equals(Object obj) {
      if (this == obj) {
        return true;
      } else if (obj instanceof WeakKey) {
        WeakKey other = (WeakKey) obj;
        return other.hash == hash && get() == other.get();
      } else {
        return false;
      }
    }
=======
  public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) {
    if (!isImageReady(img)) {
      return false;
    }

    double imgHeight = img.getHeight(null);
    double imgWidth = img.getWidth(null);

    AffineTransform transform = AffineTransform.getScaleInstance(width / imgWidth, height / imgHeight);
    transform.translate(x, y);
    return drawImage(img, transform, observer);
  }

  protected boolean isImageReady(Image img) {
    return img.getHeight(null) >= 0 && img.getWidth(null) >= 0;
>>>>>>> 30ce8757d79d9cbef491f39d4da91e71f4ab9be6
  }
}
Solution content
    return true;
  }

  protected Texture getTexture(Image image) {
    Texture texture = cache.get(image);
    if (texture == null) {
      texture = createTexture(image);
      cache.put(image, texture);
    }

    return texture;
  }

  protected Texture createTexture(Image image) {
    BufferedImage bufferedImage;
    if (image instanceof BufferedImage) {
      bufferedImage = (BufferedImage) image;
    } else {
      bufferedImage = new BufferedImage(image.getHeight(null), image.getWidth(null), BufferedImage.TYPE_3BYTE_BGR);
      bufferedImage.createGraphics().drawImage(image, null, null);
    }

    Texture texture = TextureIO.newTexture(bufferedImage, false);
    return texture;
  }

  @SuppressWarnings("serial")
  protected static class TextureCache extends HashMap, Texture> {
    private ReferenceQueue queue = new ReferenceQueue();

    public void expungeStaleEntries() {
      Reference ref = queue.poll();
      while (ref != null) {
        remove(ref).dispose();
        ref = queue.poll();
      }
    }

    public Texture get(Image image) {
      expungeStaleEntries();
      WeakKey key = new WeakKey(image, null);
      return get(key);
    }

    public Texture put(Image image, Texture texture) {
      expungeStaleEntries();
      WeakKey key = new WeakKey(image, queue);
      return put(key, texture);
    }
  }

  protected static class WeakKey extends WeakReference {
    private final int hash;

    public WeakKey(T value, ReferenceQueue queue) {
      super(value, queue);
      hash = value.hashCode();
    }

    @Override
    public int hashCode() {
      return hash;
    }

    @Override
    public boolean equals(Object obj) {
      if (this == obj) {
        return true;
      } else if (obj instanceof WeakKey) {
        WeakKey other = (WeakKey) obj;
        return other.hash == hash && get() == other.get();
      } else {
        return false;
      }
    }
  }

  public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) {
    if (!isImageReady(img)) {
      return false;
    }

    double imgHeight = img.getHeight(null);
    double imgWidth = img.getWidth(null);

    AffineTransform transform = AffineTransform.getScaleInstance(width / imgWidth, height / imgHeight);
    transform.translate(x, y);
    return drawImage(img, transform, observer);
  }

  protected boolean isImageReady(Image img) {
    return img.getHeight(null) >= 0 && img.getWidth(null) >= 0;
  }
}
File
JOGLImageDrawer.java
Developer's decision
Concatenation
Kind of conflict
Annotation
Attribute
Class declaration
Class signature
Method declaration
Method invocation
Method signature
Return statement