<?php

class MainCtrl extends Ctrl {



	public function show() {
		$interval = new Input('interval');
		$interval->value = 1500;
		$runSingle = new Button();
		$runSingle->text = 'Single';
		$runMany = new Button();
		$runMany->text = 'Periodic';
		$stop = new Button();
		$stop->text = 'Cancel';
		$clock = $this->updateClock();

		$runSingle->addListener(new ClickListener(new Action('MainCtrl/single', $interval->valueReader())));
		$runMany->addListener(new ClickListener(new Action('MainCtrl/many', $interval->valueReader())));
		$stop->addListener(new ClickListener(new Action('MainCtrl/stop')));

		$v = new VBox();
		$v->addText('Interval in milliseconds: ');
		$v->add($interval);
		$v->add($runSingle);
		$v->add($runMany);
		$v->add($stop);
		$v->add($clock);

		return $v;
	}



	public function updateClock() {
		$c = new Label('clock');
		$c->text = date('h:m:s');
		$c->setEffect(new FadeInEffect());
		return $c;
	}



	public function single($interval) {
		if ($interval < 500 or $interval > 5000) {
			$this->response->alert("'Interval out of range (500-5000)'");
		} else {
			SynCron::start('tick', new Action('MainCtrl/updateClock'), $interval, false);
		}
	}



	public function many($interval) {
		if ($interval < 500 or $interval > 5000) {
			$this->response->alert("'Interval out of range (500-5000)'");
		} else {
			SynCron::start('tick', new Action('MainCtrl/updateClock'), $interval, true);
		}
	}



	public function stop() {
		SynCron::cancel('tick');
	}



} // class MainCtrl

?>