public static void main(String[] args) {
simulator.start();
Rectangle b = simulator.getBounds();
ScreenRegion s = new DesktopScreenRegion(b.x, b.y, b.width, b.height);
List<ScreenRegion> rs;
Target target = new ImageTarget(Images.HollowRedStar);
target.setOrdering(Ordering.LEFT_RIGHT);
rs = s.findAll(target);
ScreenRegion left = rs.get(0);
ScreenRegion right = rs.get(1);
left = Relative.to(left).taller(30).wider(30).getScreenRegion();
right = Relative.to(right).taller(30).wider(30).getScreenRegion();
canvas.addBox(s);
canvas.addBox(left);
canvas.addLabel(left, "left");
canvas.addBox(right);
canvas.addLabel(right, "right");
canvas.display(3);
simulator.resume();
StateChangeListener l = new StateChangeListener(){
@Override
public void stateChanged(StateChangeEvent event) {
System.out.println(event.getScreenRegion() + "'s state is changed " +
"from {" + event.getOldState() + "} " +
" to {" + event.getNewState() + "}");
canvas.clear();
canvas.addLabel(event.getScreenRegion(), event.getOldState() + "->" + event.getNewState());
canvas.display(1);
}
};
left.addState(new ColorImageTarget(Images.HollowGreenStar), "GREEN");
left.addState(new ColorImageTarget(Images.HollowRedStar), "RED");
left.addState(new ColorImageTarget(Images.HollowBlueStar), "BLUE");
left.addStateChangeEventListener(l);
right.addState(new ColorImageTarget(Images.HollowGreenStar), "GREEN");
right.addState(new ColorImageTarget(Images.HollowRedStar), "RED");
right.addState(new ColorImageTarget(Images.HollowBlueStar), "BLUE");
right.addStateChangeEventListener(l);
}