package me.hammerle.supersnuvi.javafx;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

public class ResourceImage extends Image
{
    private javafx.scene.image.Image fxImage;
    
    public ResourceImage()
    {
        fxImage = null;
    }
    
    public void load(String path)
    {
        File f = new File(path);
        try
        {
            fxImage = new javafx.scene.image.Image(new FileInputStream(f));
        }
        catch(FileNotFoundException ex)
        {
            System.err.println("can't load image from '" + f.getPath() + "'");
        }
    }
    
    public void load(String path, double rw, double rh)
    {
        File f = new File(path);
        try
        {
            fxImage = new javafx.scene.image.Image(new FileInputStream(f), rw, rh, true, false);
        }
        catch(FileNotFoundException ex)
        {
            System.err.println("can't load image from '" + f.getPath() + "'");
        }
    }

    @Override
    protected javafx.scene.image.Image getImage() 
    {
        return fxImage;
    }

    @Override
    public double getWidth() 
    {
        return fxImage == null ? 0 : fxImage.getWidth();
    }

    @Override
    public double getHeight() 
    {
        return fxImage == null ? 0 : fxImage.getHeight();
    }
}
