Newer
Older
piccolo2d.java / examples / edu / umd / cs / piccolo / examples / TwoCanvasExample.java
@Jesse Grosjean Jesse Grosjean on 5 Oct 2006 1 KB piccolo java
package edu.umd.cs.piccolo.examples;
import java.awt.Color;

import edu.umd.cs.piccolo.PCamera;
import edu.umd.cs.piccolo.PCanvas;
import edu.umd.cs.piccolo.PLayer;
import edu.umd.cs.piccolo.PNode;
import edu.umd.cs.piccolo.PRoot;
import edu.umd.cs.piccolo.nodes.PPath;
import edu.umd.cs.piccolox.PFrame;
import edu.umd.cs.piccolox.handles.PBoundsHandle;

public class TwoCanvasExample extends PFrame {

	public TwoCanvasExample() {
		this(null);
	}
	
	public TwoCanvasExample(PCanvas aCanvas) {
		super("TwoCanvasExample", false, aCanvas);
	}
	
	public void initialize() {		
		PRoot root = getCanvas().getRoot();
		PLayer layer = getCanvas().getLayer();
		
		PNode n = PPath.createRectangle(0, 0, 100, 80);
		PNode sticky = PPath.createRectangle(0, 0, 50, 50);
		PBoundsHandle.addBoundsHandlesTo(n);
		sticky.setPaint(Color.YELLOW);
		PBoundsHandle.addBoundsHandlesTo(sticky);
		
		layer.addChild(n);
		getCanvas().getCamera().addChild(sticky);
				
		PCamera otherCamera = new PCamera();
		otherCamera.addLayer(layer);
		root.addChild(otherCamera); 	
		
		PCanvas other = new PCanvas();
		other.setCamera(otherCamera);
		PFrame result = new PFrame("TwoCanvasExample", false, other);
		result.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
		result.setLocation(500, 100);
	}

	public static void main(String[] args) {
		new TwoCanvasExample();
	}
}