Commits

Tom Yeh committed abaa827

fixed all examples, using Canvas instead of ScreenPainter

  • Participants
  • Parent commits 74b386d

Comments (0)

Files changed (15)

File examples/src/main/java/org/sikuli/api/examples/CaptureImageExample.java

 import org.sikuli.api.robot.Mouse;
 import org.sikuli.api.robot.desktop.DesktopKeyboard;
 import org.sikuli.api.robot.desktop.DesktopMouse;
-import org.sikuli.api.visual.ScreenPainter;
+import org.sikuli.api.visual.Canvas;
+import org.sikuli.api.visual.DesktopCanvas;
 
 public class CaptureImageExample {
 	
 	static Mouse mouse = new DesktopMouse();
 	static Keyboard keyboard = new DesktopKeyboard();
-	static ScreenPainter painter = new ScreenPainter();
+	static Canvas canvas = new DesktopCanvas();
 
 	public static void main(String[] args) throws IOException {
 		DesktopScreenRegion smallRegion = new DesktopScreenRegion(500,500,400,200);
-		painter.box(smallRegion, 1000);
+		canvas.addBox(smallRegion).display(1);
 		
 		BufferedImage capturedImage = smallRegion.capture();
 		ImageIO.write(capturedImage, "png", new File("SavedCaptuedImage.png"));

File examples/src/main/java/org/sikuli/api/examples/ColorImageTargetExample.java

 
 import org.sikuli.api.ColorImageTarget;
 import org.sikuli.api.DesktopScreenRegion;
+import org.sikuli.api.Relative;
 import org.sikuli.api.ScreenRegion;
 import org.sikuli.api.Target;
 import org.sikuli.api.robot.Keyboard;
 import org.sikuli.api.robot.Mouse;
 import org.sikuli.api.robot.desktop.DesktopKeyboard;
 import org.sikuli.api.robot.desktop.DesktopMouse;
-import org.sikuli.api.visual.ScreenPainter;
+import org.sikuli.api.visual.Canvas;
+import org.sikuli.api.visual.DesktopCanvas;
 
 public class ColorImageTargetExample {
 
 	static Mouse mouse = new DesktopMouse();
 	static Keyboard keyboard = new DesktopKeyboard();
-	static ScreenPainter painter = new ScreenPainter();
+	static Canvas canvas = new DesktopCanvas();
 
 	static ScreenSimulator simulator = new ScreenSimulator(){
 		public void run(){
 			showImage(Images.ColorStars);
-			wait(5000);
+			pause();
 			showImage(Images.ColorBullets);
-			wait(5000);
+			pause();
 			close();
 		}
 	};
 		Rectangle b = simulator.getBounds();
 		
 		final DesktopScreenRegion s = new DesktopScreenRegion(b.x, b.y, b.width, b.height);
-		painter.box(s, 10000);
+
 
 		// Finding color stars
 
 		List<ScreenRegion> redTargetRegions = s.findAll(redTarget);
 		
 		for (ScreenRegion r : blueTargetRegions){
-			painter.box(r, 3000);
-			painter.label(r, "blue", 3000);
+			canvas.addBox(r);
+			canvas.addLabel(r, "blue");			
 		}
 
 		for (ScreenRegion r : redTargetRegions){
-			painter.box(r, 3000);
-			painter.label(r, "red", 3000);
+			canvas.addBox(r);
+			canvas.addLabel(r, "red");			
 		}
 
 		for (ScreenRegion r : greenTargetRegions){
-			painter.box(r, 3000);
-			painter.label(r, "green", 3000);
+			canvas.addBox(r);
+			canvas.addLabel(r, "green");			
 		}
-
-
+		canvas.display(3);
+		
+		simulator.resume();
+		
+		canvas.clear();
+		
 		// Finding color bullets
 		ScreenRegion greenBullet = s.wait(new ColorImageTarget(Images.GreenBullet),10000);
 		ScreenRegion redBullet = s.find(new ColorImageTarget(Images.RedBullet));
 		ScreenRegion silverBullet = s.find(new ColorImageTarget(Images.SilverBullet));
 		
-		painter.box(greenBullet, 3000);
-		painter.label(greenBullet, "g", 3000);
+		canvas.addBox(greenBullet);		
+		canvas.addLabel(Relative.to(greenBullet).topLeft().above(20).getScreenLocation(), "green");
+		
+		canvas.addBox(redBullet);
+		canvas.addLabel(Relative.to(redBullet).topLeft().above(20).getScreenLocation(), "red");
+		
+		canvas.addBox(silverBullet);
+		canvas.addLabel(Relative.to(silverBullet).topLeft().above(20).getScreenLocation(), "silver");
 		
-		painter.box(redBullet, 3000);
-		painter.label(redBullet, "r", 3000);
+		canvas.display(3);
 		
-		painter.box(silverBullet, 3000);
-		painter.label(silverBullet, "s", 3000);
+		simulator.resume();
 
 	}
 }

File examples/src/main/java/org/sikuli/api/examples/Images.java

 	static final URL EclipsePreferences2 = Images.class.getResource("EclipsePreferences2.png");
 	
 	static final URL ButtonOptions = Images.class.getResource("ButtonOptions.png");
+	
+	static final URL Calculator = Images.class.getResource("Calculator.png");
+	static final URL CalculatorButton = Images.class.getResource("CalculatorButton.png");
 
 }

File examples/src/main/java/org/sikuli/api/examples/MultiScreenExample.java

 import org.sikuli.api.robot.desktop.DesktopKeyboard;
 import org.sikuli.api.robot.desktop.DesktopMouse;
 import org.sikuli.api.robot.desktop.DesktopScreen;
-import org.sikuli.api.visual.ScreenPainter;
 
 public class MultiScreenExample {
 	
 	static Mouse mouse = new DesktopMouse();
 	static Keyboard keyboard = new DesktopKeyboard();
-	static ScreenPainter painter = new ScreenPainter();
+//	static ScreenPainter painter = new ScreenPainter();
 	
 	static ScreenSimulator simulator1 = new ScreenSimulator(){
 		public void run(){
 			showImage(Images.GoogleSearchPage);
-			wait(10000);
+			wait(1);
 			close();
 		}
 	};
 	static ScreenSimulator simulator2 = new ScreenSimulator(){
 		public void run(){
 			showImage(Images.OSXSystemPreferences);
-			wait(10000);
+			wait(1);
 			close();
 		}
 	};
 		DesktopScreenRegion s1 = new DesktopScreenRegion(30,30,800,500);
 		s1.setScreen(screen1);
 		
-		painter.box(s0, 10000);
-		painter.box(s1, 10000);
-		
+//		painter.box(s0, 10000);
+//		painter.box(s1, 10000);
+//		
 				
 		ScreenRegion r0 = s0.find(new ImageTarget(Images.GoogleSearchButton));
 		ScreenRegion r1 = s1.find(new ImageTarget(Images.OSXDockIcon));
 
-		painter.box(r0, 5000);
-		painter.box(r1, 5000);
-		
-		painter.label(r0,"Target in Screen0", 5000);
-		painter.label(r1,"Target in Screen1", 5000);
+//		painter.box(r0, 5000);
+//		painter.box(r1, 5000);
+//		
+//		painter.label(r0,"Target in Screen0", 5000);
+//		painter.label(r1,"Target in Screen1", 5000);
 				
 		
 	}

File examples/src/main/java/org/sikuli/api/examples/MultiStateTargetExample.java

 import org.sikuli.api.robot.desktop.DesktopMouse;
 import org.sikuli.api.visual.Canvas;
 import org.sikuli.api.visual.DesktopCanvas;
-import org.sikuli.api.visual.ScreenPainter;
 
 public class MultiStateTargetExample {
 

File examples/src/main/java/org/sikuli/api/examples/RelativeExample.java

 import org.sikuli.api.robot.desktop.DesktopMouse;
 import org.sikuli.api.visual.Canvas;
 import org.sikuli.api.visual.DesktopCanvas;
-import org.sikuli.api.visual.ScreenPainter;
 
 public class RelativeExample {
 	static Mouse mouse = new DesktopMouse();

File examples/src/main/java/org/sikuli/api/examples/ScreenRegionRecordExample.java

 import org.sikuli.api.robot.Mouse;
 import org.sikuli.api.robot.desktop.DesktopKeyboard;
 import org.sikuli.api.robot.desktop.DesktopMouse;
-import org.sikuli.api.visual.ScreenPainter;
+import org.sikuli.api.visual.Canvas;
+import org.sikuli.api.visual.DesktopCanvas;
 
 public class ScreenRegionRecordExample {
 	
 	static Mouse mouse = new DesktopMouse();
 	static Keyboard keyboard = new DesktopKeyboard();
-	static ScreenPainter painter = new ScreenPainter();
+	static Canvas canvas = new DesktopCanvas();
 	
 	static ScreenSimulator simulator = new ScreenSimulator(){
 		public void run(){
 			showImage(Images.SceneEmpty);
-			wait(1000);
+			wait(1);
 			showImage(Images.SceneCat1);
-			wait(1000);
+			wait(1);
 			showImage(Images.SceneCat2);
-			wait(1000);       					
+			wait(1);       					
 			showImage(Images.SceneDogCat2);
-			wait(1000);
+			wait(1);
 			close();
 		}
 	};
 		
 		Rectangle b = simulator.getBounds(); 
 		DesktopScreenRegion s = new DesktopScreenRegion(b.x,b.y,b.width,b.height);	
-		painter.box(s, 50000);
+		canvas.addBox(s).display(5);
 		//s.record(new File("ScreenRegionRecordExampleVideo.mov"), 5000);
 		
 	}

File examples/src/main/java/org/sikuli/api/examples/ScreenSimulator.java

 
 import java.awt.Dimension;
 import java.awt.FlowLayout;
+import java.awt.Point;
 import java.awt.Rectangle;
 import java.awt.event.InputEvent;
 import java.awt.event.MouseEvent;
 import javax.swing.BoxLayout;
 import javax.swing.ImageIcon;
 import javax.swing.JButton;
+import javax.swing.JComponent;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JTextField;
 
 	private final Dimension DEFAULT_SIZE = new Dimension(640,480);
 	private ImageFrame frame = new ImageFrame();
-	
-	
+
+
 
 	public void run(){
-		
+
 	}
-	
+
 	public void start(){
 		Thread t = new Thread(){
 			public void run(){
 		};
 		t.setDaemon(true);
 		t.start();		
-		wait(1000);
+		wait(1);
 	}
-	
+
 	public void showImage(BufferedImage image){		
-		frame.image.setImage(image);
-		frame.setSize(image.getWidth(),image.getHeight());
-		frame.repaint();
-	}
-	
-	public void showImage(URL url) {
-		try {
-			frame.addImage(ImageIO.read(url));
-		} catch (IOException e) {
-		}
+		frame.addImage(image);
+		frame.pack();
+		frame.setLocationRelativeTo(null);
 	}
-	
-	public void addImageButton(URL url, String name){
-		try {
-			frame.addImageButton(ImageIO.read(url), name);
-		} catch (IOException e) {
-		}
+
+
+	public void showComponent(JComponent component){
+		frame.getContentPane().removeAll();
+		frame.getContentPane().add(component);
+		// not sure why this is needed for component to be shown...
+		frame.setVisible(true);
 	}
-	
-	public void addTextField(int x, int y) {
-		//JTextField f = new JTextField(20);
-		//PSwing s = new PSwing(f);
-		//frame.canvas.getLayer().addChild(s);
-		frame.addTextField(x,y);
+
+
+	public void showImage(URL imageUrl) {
+		JLabel imageLabel = new JLabel(new ImageIcon(imageUrl));
+		frame.getContentPane().removeAll();
+		frame.getContentPane().add(imageLabel);
+		frame.pack();
+		frame.setLocationRelativeTo(null);
 	}
-	
-	public void wait(int duration){
+
+	//	public void addImage(URL url) {
+	//		try {
+	//			frame.addImage(ImageIO.read(url));			
+	//		} catch (IOException e) {
+	//		}
+	//	}
+	//	
+	//	
+	//	public void addImageButton(URL url, String name){
+	//		try {
+	//			frame.addImageButton(ImageIO.read(url), name);
+	//		} catch (IOException e) {
+	//		}
+	//	}
+	//	
+	//	public void addTextField() {
+	//		frame.addTextField();
+	//	}
+
+	public void wait(int seconds){
 		try {
-			Thread.sleep(duration);
+			Thread.sleep(seconds*1000);
 		} catch (InterruptedException e) {
 		}		
 	}
-	
+
+	Object pauseObserver = new Object();
+	public void pause(){
+		synchronized(pauseObserver){
+			try {
+				pauseObserver.wait();
+			} catch (InterruptedException e) {
+			}
+		}
+	}
+
+	public void resume(){
+		synchronized(pauseObserver){
+			pauseObserver.notify();
+		}
+	}
+
 	Object clickObserver = new Object();
 	public void waitForClick(){
 		synchronized(clickObserver){
 	public void close(){
 		frame.setVisible(false);
 		frame.dispose();
-		
+
 		ScreenRegionRecorder.awaitTermination();
 		System.exit(0);
 	}
 
-
-	private class ImageButton extends JButton implements MouseListener {
-		private final String name; 
-		ImageButton(BufferedImage image, String name){
-			this.setIcon(new ImageIcon(image));
-			this.addMouseListener(this);
-			this.name = name;
-		}
-		
-		
-		private void log(MouseEvent e, String event){
-			String button = "";
-			if (e.getButton() == MouseEvent.BUTTON1){
-				button = "left";
-			}else if (e.getButton() == MouseEvent.BUTTON3){
-				button = "right";
-			}
-			System.out.println("[" + name + "] " +  button + " " + event );
-		}
-		
-		@Override
-		public void mouseClicked(MouseEvent arg0) {
-			log(arg0, "clicked");
-		}
-
-		@Override
-		public void mouseEntered(MouseEvent arg0) {
-		}
-
-		@Override
-		public void mouseExited(MouseEvent arg0) {
-		}
-
-		@Override
-		public void mousePressed(MouseEvent arg0) {
-			log(arg0, "pressed");			
-		}
-
-		@Override
-		public void mouseReleased(MouseEvent arg0) {
-			log(arg0, "released");			
-		}
-	}
-	
 	private class ImageFrame extends JFrame {
 
-		PImage image;
-		PCanvas canvas;
-		PSwing textField;
-		//static private final Rectangle DEFAULT_BOUNDS = new Rectangle(50,50,640,480);
-		
-		void addTextField(int x, int y){
-			JTextField f = new JTextField(20);
-			PSwing p = new PSwing(f);
-			p.setOffset(x, y);
-			canvas.getLayer().addChild(p);
-		}
-		
+		//		void clear(){
+		//			getContentPane().removeAll();
+		//		}
+		//		
+		//		void addTextField(){
+		//			JTextField f = new JTextField(20);
+		//			getContentPane().add(f);
+		//			//repaint();
+		//		}
+
 		void addImage(BufferedImage image){			
 			JLabel l = new JLabel(new ImageIcon(image));
-			getContentPane().removeAll();
-			getContentPane().setLayout(new FlowLayout());
 			getContentPane().add(l);
-			pack();
-		}		
-		
-		void addImageButton(BufferedImage image, String name){
-			JButton b = new ImageButton(image, name);
-			getContentPane().setLayout(new FlowLayout());
-			getContentPane().add(b);
-			pack();
-			
-//			canvas.getLayer().addChild(p);
-//			p.addInputEventListener(new PBasicInputEventHandler(){
-//
-//				@Override
-//				public void keyTyped(PInputEvent event) {
-//					super.keyTyped(event);
-//
-//					//System.out.println("Key typed: " + event.getKeyChar());
-//
-//				}
-//
-//				@Override
-//				public void keyPressed(PInputEvent event) {
-//					super.keyPressed(event);
-//					clickObserver.notify();
-//					//System.out.println("Key pressed: " + event.getKeyChar());
-//
-//				}
-//
-//				@Override
-//				public void mousePressed(PInputEvent event) {					
-//					super.mousePressed(event);
-////					synchronized(clickObserver){
-////						clickObserver.notify();
-////					}
-//					System.out.println("Mouse pressed: button " + event.getButton());
-//				}
-//
-//				@Override
-//				public void mouseReleased(PInputEvent event) {
-//					super.mouseReleased(event);
-//					//System.out.println("Mouse released: button " + event.getButton());
-//				}
-//
-//			});
-
-			
+			//			repaint();
 		}
+		//		
+		//		void addImageButton(BufferedImage image, String name){
+		//			JButton b = new ImageButton(image, name);
+		//			getContentPane().setLayout(new FlowLayout());
+		//			getContentPane().add(b);
+		//			pack();
+		//		}
 
 		ImageFrame() {
-			//canvas = new PCanvas();
-//			canvas = new PSwingCanvas();
-//			image = new PImage();
-//
-////			JTextField f = new JTextField(20);
-////			textField = new PSwing(f);
-////			textField.setVisible(false);
-////			//frame.canvas.getLayer().addChild(s);
-//
-//			//textField
-//			
-//			canvas.getLayer().addChild(image);
-//			//canvas.getLayer().addChild(textField);
-//			add(canvas);
-			//
-//			image.addInputEventListener(new PBasicInputEventHandler(){
-//
-//				@Override
-//				public void keyTyped(PInputEvent event) {
-//					super.keyTyped(event);
-//
-//					//System.out.println("Key typed: " + event.getKeyChar());
-//
-//				}
-//
-//				@Override
-//				public void keyPressed(PInputEvent event) {
-//					super.keyPressed(event);
-//					clickObserver.notify();
-//					//System.out.println("Key pressed: " + event.getKeyChar());
-//
-//				}
-//
-//				@Override
-//				public void mousePressed(PInputEvent event) {					
-//					super.mousePressed(event);
-//					synchronized(clickObserver){
-//						clickObserver.notify();
-//					}
-//					//System.out.println("Mouse pressed: button " + event.getButton());
-//				}
-//
-//				@Override
-//				public void mouseReleased(PInputEvent event) {
-//					super.mouseReleased(event);
-//					//System.out.println("Mouse released: button " + event.getButton());
-//				}
-//
-//			});
-
-
+			getContentPane().setLayout(new FlowLayout());			
 
 			setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 			setSize(DEFAULT_SIZE);
 			setResizable(false);
 			setLocationRelativeTo(null);
-			//setVisible(true);
 		}
 
 	}
 
-	public static void main(String[] args){
-
-		ScreenSimulator s = new ScreenSimulator(){
-			public void run(){
-				showImage(Images.GoogleSearchPage);
-				addTextField(20,20);
-				wait(3000);
-				showImage(Images.OSXDockPreferences);
-				wait(3000);
-				close();
-			}
-		};
-		s.start();
-	}
-
 	public void setSize(int width, int height){
 		frame.setSize(width, height);
 		frame.setLocationRelativeTo(null);
 	}
-	
+
 	public void setLocation(int x, int y){
 		frame.setLocation(x,y);
 	}

File examples/src/main/java/org/sikuli/api/examples/SpeakerExample.java

 import org.sikuli.api.robot.desktop.DesktopMouse;
 import org.sikuli.api.visual.DesktopCanvas;
 import org.sikuli.api.visual.Canvas;
-import org.sikuli.api.visual.ScreenPainter;
 
 public class SpeakerExample {
 	

File examples/src/main/java/org/sikuli/api/examples/StateChangeEventExample.java

 import org.sikuli.api.robot.Mouse;
 import org.sikuli.api.robot.desktop.DesktopKeyboard;
 import org.sikuli.api.robot.desktop.DesktopMouse;
-import org.sikuli.api.visual.ScreenPainter;
+import org.sikuli.api.visual.Canvas;
+import org.sikuli.api.visual.DesktopCanvas;
 
 public class StateChangeEventExample {
 
 	static Mouse mouse = new DesktopMouse();
 	static Keyboard keyboard = new DesktopKeyboard();
-	static ScreenPainter painter = new ScreenPainter();
+	static Canvas canvas = new DesktopCanvas();
 
 	static ScreenSimulator simulator = new ScreenSimulator(){
 		public void run(){
 		// TODO: test if remove works
 		//smallRegion.removeState(cat);
 
-		painter.box(smallRegion,10000);
+		canvas.addBox(smallRegion).display(10);
+		
 	}
 }

File examples/src/main/java/org/sikuli/api/examples/StyledRectangleExample.java

 package org.sikuli.api.examples;
 import java.awt.Rectangle;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.List;
 
 import org.sikuli.api.DesktopScreenRegion;
+import org.sikuli.api.ImageTarget;
 import org.sikuli.api.ScreenRegion;
 import org.sikuli.api.StyledRectangleTarget;
+import org.sikuli.api.Target;
+import org.sikuli.api.VisualModelFinder;
 import org.sikuli.api.robot.Keyboard;
 import org.sikuli.api.robot.Mouse;
 import org.sikuli.api.robot.desktop.DesktopKeyboard;
 import org.sikuli.api.robot.desktop.DesktopMouse;
-import org.sikuli.api.visual.ScreenPainter;
-
-import static org.sikuli.api.API.*;
+import org.sikuli.api.visual.Canvas;
+import org.sikuli.api.visual.DesktopCanvas;
+import org.sikuli.core.logging.ImageExplainer;
+import org.sikuli.core.logging.ImageExplainer.Level;
 
 public class StyledRectangleExample {
 	
 	static Mouse mouse = new DesktopMouse();
 	static Keyboard keyboard = new DesktopKeyboard();
-	static ScreenPainter painter = new ScreenPainter();
+	static Canvas canvas = new DesktopCanvas();
 
 	static ScreenSimulator simulator = new ScreenSimulator(){
 		public void run(){
-			showImage(Images.OSXNetworkPreferences);
-			wait(5000);
-			showImage(Images.GoogleSearchPage);
-			wait(5000);
+			showImage(Images.Calculator);
+//			try {
+//				//showImage(new URL("file:ButtonGroups.png"));
+////				showImage(new URL("file:swing-averager.jpg"));
+//			} catch (MalformedURLException e) {
+//				// TODO Auto-generated catch block
+//				e.printStackTrace();
+//			}
+			wait(10000);
 			close();
 		}
 	};
 
-	public static void main(String[] args) {
+	public static void main(String[] args) throws MalformedURLException {
 
-		simulator.setSize(800,800);
 		simulator.start();
+		ImageExplainer.getExplainer(VisualModelFinder.class).setLevel(Level.STEP);
 		
 		Rectangle b = simulator.getBounds();
 		ScreenRegion s = new DesktopScreenRegion(b.x,b.y,b.width,b.height);
 
-		StyledRectangleTarget target = new StyledRectangleTarget(Images.ButtonOptions);
+		StyledRectangleTarget target = new StyledRectangleTarget(Images.CalculatorButton);
+//		Target target = new StyledRectangleTarget(new URL("file:wally.png"));
+//		Target target = new ImageTarget(Images.CalculatorButton);
+		target.setLimit(20);
+		
 		List<ScreenRegion> rs = s.findAll(target);
+		
+				
 		for (ScreenRegion r : rs){
-			painter.box(r, 3000);
-		}
-
-		pause(5000);
-
-		target = new StyledRectangleTarget(Images.GoogleSearchButton);
-		rs = s.findAll(target);
-		for (ScreenRegion r : rs){
-			painter.box(r, 3000);
+			canvas.addBox(r);
 		}
+		canvas.display(3);				
 
 	}
 

File examples/src/main/java/org/sikuli/api/examples/TargetEventExample.java

 import org.sikuli.api.robot.Mouse;
 import org.sikuli.api.robot.desktop.DesktopKeyboard;
 import org.sikuli.api.robot.desktop.DesktopMouse;
-import org.sikuli.api.visual.ScreenPainter;
+import org.sikuli.api.visual.Canvas;
+import org.sikuli.api.visual.DesktopCanvas;
 
 public class TargetEventExample {
-	
+
 	static Mouse mouse = new DesktopMouse();
 	static Keyboard keyboard = new DesktopKeyboard();
-	static ScreenPainter painter = new ScreenPainter();
+	static Canvas canvas = new DesktopCanvas();
 
 	static ScreenSimulator simulator = new ScreenSimulator(){
 		public void run(){
 			close();
 		}
 	};
-	
+
 	public static void main(String[] args) {
 
 		simulator.start();       			
 			public void targetAppeared(TargetEvent event) {
 				System.out.println(event.getTarget() + " has appeared within " + event.getScreenRegion() + 
 						" at " + Relative.to(event.getTargetRegion()).topLeft().getScreenLocation());	
-				painter.box(event.getTargetRegion(), 1000);
-				painter.label(event.getTargetRegion(), "appeared", 1000);
+				canvas.clear().addBox(event.getTargetRegion());
+				canvas.addLabel(event.getTargetRegion(),"appeared");
+				canvas.display(1);
 			}
 
 			@Override
 			public void targetVanished(TargetEvent event) {
 				System.out.println(event.getTarget() + " has vanished from " + event.getScreenRegion());
-				painter.box(event.getTargetRegion(), 1000);
-				painter.label(event.getTargetRegion(), "vanished", 1000);
+				canvas.clear().addBox(event.getTargetRegion());
+				canvas.addLabel(event.getTargetRegion(),"vanished");
+				canvas.display(1);
 			}
 
 			@Override
 			public void targetMoved(TargetEvent event) {
 				System.out.println(event.getTarget() + " has moved to " + 
 						Relative.to(event.getTargetRegion()).topLeft().getScreenLocation());
-				painter.box(event.getTargetRegion(), 1000);
-				painter.label(event.getTargetRegion(), "moved", 1000);
+				canvas.clear().addBox(event.getTargetRegion());
+				canvas.addLabel(event.getTargetRegion(),"moved");
+				canvas.display(1);
 			}					
 		};
 
 		Target cat = new ImageTarget(Images.Cat);
 		Target dog = new ImageTarget(Images.Dog);
 		smallRegion.addTargetEventListener(dog, l);       			
-		smallRegion.addTargetEventListener(cat, l);       				
-		painter.box(smallRegion, 10000);
-
+		smallRegion.addTargetEventListener(cat, l); 
 	}
 }

File examples/src/main/java/org/sikuli/api/examples/TextTargetExample.java

 import org.sikuli.api.robot.Mouse;
 import org.sikuli.api.robot.desktop.DesktopKeyboard;
 import org.sikuli.api.robot.desktop.DesktopMouse;
-import org.sikuli.api.visual.ScreenPainter;
+import org.sikuli.api.visual.Canvas;
+import org.sikuli.api.visual.DesktopCanvas;
 import org.sikuli.core.cv.TextMap;
 import org.sikuli.core.logging.ImageExplainer;
 import org.sikuli.core.logging.ImageExplainer.Level;
 	
 	static Mouse mouse = new DesktopMouse();
 	static Keyboard keyboard = new DesktopKeyboard();
-	static ScreenPainter painter = new ScreenPainter();
+	static Canvas canvas = new DesktopCanvas();
 
 	static ScreenSimulator simulator = new ScreenSimulator(){
 		public void run(){
 		}
 	};
 	
+	
+	// TODO: This example is still not working ...
 	public static void main(String[] args) {
 		
 //		simulator.setSize(800,800);
 		for (String stringToFind : stringsToFind){		
 			Target textTarget = new TextTarget(stringToFind);
 			ScreenRegion r = s.find(textTarget);
-			painter.box(r,3000);
-			painter.label(r, stringToFind, 3000);		
-			mouse.click(r.getCenter());			
+			canvas.addBox(r);
+			canvas.addLabel(r, stringToFind);		
 		}		
+		canvas.display(5);
 	}
 }

File examples/src/main/java/org/sikuli/api/examples/TwoRegionColorStateChangeExample.java

 package org.sikuli.api.examples;
-import static org.sikuli.api.API.pause;
 
 import java.awt.Rectangle;
 import java.util.List;
 import org.sikuli.api.robot.Mouse;
 import org.sikuli.api.robot.desktop.DesktopKeyboard;
 import org.sikuli.api.robot.desktop.DesktopMouse;
-import org.sikuli.api.visual.ScreenPainter;
+import org.sikuli.api.visual.Canvas;
+import org.sikuli.api.visual.DesktopCanvas;
 
 public class TwoRegionColorStateChangeExample {
 
 	static Mouse mouse = new DesktopMouse();
 	static Keyboard keyboard = new DesktopKeyboard();
-	static ScreenPainter painter = new ScreenPainter();
+	static Canvas canvas = new DesktopCanvas();
 	
 	static ScreenSimulator simulator = new ScreenSimulator(){
 		public void run(){
 			showImage(Images.HollowColorStars1);
-			wait(5000);
+			pause();
+			
 			showImage(Images.HollowColorStars2);
-			wait(3000);
+			wait(3);
 			showImage(Images.HollowColorStars3);
-			wait(3000);       					
+			wait(3);       					
 			showImage(Images.HollowColorStars4);
-			wait(3000);
+			wait(3);
 			showImage(Images.HollowColorStars1);
-			wait(3000);
+			wait(3);
 			close();
 		}
 	};
 	public static void main(String[] args) {
 		
 		simulator.start();       			
-
 		Rectangle b = simulator.getBounds();
-
 		ScreenRegion s = new DesktopScreenRegion(b.x, b.y, b.width, b.height);
-		painter.box(s, 10000);
 
 		List<ScreenRegion> rs;
 		Target target = new ImageTarget(Images.HollowRedStar);
 		left = Relative.to(left).taller(30).wider(30).getScreenRegion();
 		right = Relative.to(right).taller(30).wider(30).getScreenRegion();
 
-		painter.box(left, 1000);
-		painter.label(left, "left", 1000);
-
-		painter.box(right,  1000);
-		painter.label(right, "right", 1000);
+		
+		canvas.addBox(s);
+		
+		canvas.addBox(left);
+		canvas.addLabel(left, "left");		
 
-		pause(3000);    			
+		canvas.addBox(right);
+		canvas.addLabel(right, "right");
+		canvas.display(3);
+		
+		simulator.resume();		
 
 		StateChangeListener l = new StateChangeListener(){       				
 
 						"from {" + event.getOldState() + "} " +
 						" to {" + event.getNewState() + "}");	
 				
-				painter.label(event.getScreenRegion(), event.getOldState() + "->" + event.getNewState(), 1000);
+				canvas.clear();
+				canvas.addLabel(event.getScreenRegion(), event.getOldState() + "->" + event.getNewState());
+				canvas.display(1);
 			}					
 		};
 

File examples/src/main/resources/log4j.properties

 log4j.appender.A1.layout=org.apache.log4j.PatternLayout
 log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
 
-log4j.logger.org.sikuli.core.search.algorithm.SearchByTextureAndColorAtOriginalResolution=TRACE
+# log4j.logger.org.sikuli.core.search.algorithm.SearchByTextureAndColorAtOriginalResolution=TRACE