package jp.riken.brain.ni.samuraigraph.base;

import java.awt.Component;
import java.awt.Graphics;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;

import javax.swing.JPanel;

public class SGPrintablePanel extends JPanel implements Printable {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -5904811006944374494L;

	public SGPrintablePanel( Component target, int width, int height )
	{
		super();
		setLayout(null);
		setSize( width, height );
		add(target);
		setOpaque(true);
		setBackground( target.getBackground() );
	}
	
	public int print( Graphics g, PageFormat pageFormat, int pageIndex )
    	throws PrinterException {
//		int x = (int)pageFormat.getImageableX();
//	    int y = (int)pageFormat.getImageableY();
//	    g.translate(x, y);
		if (pageIndex >= 1) {
			return Printable.NO_SUCH_PAGE;
		}
		printAll(g);
		return Printable.PAGE_EXISTS;
	}
	
}
