package org.openmhp.system;

import java.awt.*;
import org.havi.ui.*;
import java.awt.image.*;
import org.dvb.ui.*;
import org.openmhp.util.*;

import libopenmhp.Grabber; // miknov

/**
* This layer is the layer where the xlets are drawn. In the paint method
* java.awt.Graphics object is changed to org.dvb.ui.DVBGraphics.
* @author tejopa
*/
public class GraphicsLayer extends Container {

	static GraphicsLayer instance;
	private HScene hscene;
	BufferedImage preImage;

	Graphics graphics;

	protected GraphicsLayer() {
		super();
		setName(getClass().toString());
		setSize(720,576);
		setLayout(null);
		validate();
	}

	public static GraphicsLayer getInstance() {
		if (instance==null) {
			instance = new GraphicsLayer();
		}
		return instance;
	}


    public void paint(Graphics g) { // miknov: whole method
        Graphics gr = Grabber.getGraphics(Grabber.GRAPHICS_LAYER_INDEX);
        super.paint(gr);
        Grabber.share(Grabber.GRAPHICS_LAYER_INDEX);
    }



//	public void paint(Graphics g) {

//		super.paint(g);
/*
			graphics = g;
			DVBGraphicsImpl dvbg = new DVBGraphicsImpl(g);
			
			Component[] c = getComponents(); // get all child components
			for (int i=0;i<c.length;i++) {
  				c[i].paint((DVBGraphics)dvbg);
			}
*/			
			//super.paint((DVBGraphics)dvbg);
			
			
			//list(System.out,5);
			//System.out.println("g "+dvbg.toString());

/*
			if (preImage==null) preImage = new BufferedImage(720, 576, BufferedImage.TYPE_INT_ARGB);
			Graphics2D g2d = preImage.createGraphics();
			super.paint(g2d);
			g.drawImage(preImage,0,0,getWidth(),getHeight(),null);
*/
//	}

    public Graphics getGraphics() {
		Out.printMe(Out.TRACE);
		return new DVBGraphicsImpl(getParent().getGraphics());
	}


}
