/**
 *	djnn java addons
 *
 *	The copyright holders for the contents of this file are:
 *		Ecole Nationale de l'Aviation Civile, France (2012-2014)
 *	See file "license.terms" for the rights and conditions
 *	defined by copyright holders.
 *
 *  
 *	Contributors:
 *		Mathieu Magnaudet <mathieu.magnaudet@enac.fr>
 *
 */

package net.djnn.addons.interaction;

import net.djnn.addons.interaction.DoubleClick;
import net.djnn.addons.interaction.LongPress;
import net.djnn.java.base.FSM;
import net.djnn.java.base.Switch;
import net.djnn.java.core.Application;
import net.djnn.java.core.Component;
import net.djnn.java.core.Connector;
import net.djnn.java.core.Element;
import net.djnn.java.core.Module;
import net.djnn.java.gui.Frame;
import net.djnn.java.gui.Rectangle;
import net.djnn.java.gui.style.FillColor;

public class MouseInteraction
{
	public static void main (String[] args)
	{
		Application app = Application.getInstance();
		app.initModule (Module.BASE);
		app.initModule (Module.GUI);
		Component root = new Component (null, null);
		Element f = new Frame (root, "f", "dragging", 50, 50, 600, 500);

		// Elements of the scene graph
		Element r1 = new Component (root, "r1");
		new FillColor (r1, null, 230, 150, 20);
		new Rectangle (r1, "r", 30, 30, 150, 50, 0.5, 0.5);
		new LongPress (r1, "lp", r1.findElement ("r"), 250);

		Element sw = new Switch (r1, "sw1", "idle");
		new Component (sw, "idle");
		new Rectangle (sw, "r", 50, 80, 50, 50, 0, 0);

		FSM fsm = new FSM (r1, "fsm1");
		fsm.addState ("idle");
		fsm.addState ("r");
		fsm.addTransition (null, "idle", "r", r1.findElement ("lp/true"), null);
		fsm.addTransition (null, "r", "idle", f.findElement ("release"), null);

		new Connector (r1, null, "fsm1/state", "sw1/state");

		Element r2 = new Component (root, "r2");
		new FillColor (r2, null, 20, 150, 20);
		new Rectangle (r2, "r", 250, 30, 150, 50, 0.5, 0.5);
		new DoubleClick (r2, "dc", r2.findElement ("r"), 250);

		sw = new Switch (r2, "sw2", "idle");
		new Component (sw, "idle");
		new Rectangle (sw, "r", 300, 80, 50, 50, 0, 0);

		fsm = new FSM (r2, "fsm2");
		fsm.addState ("idle");
		fsm.addState ("r");
		fsm.addTransition (null, "idle", "r", r2.findElement ("dc/true"), null);
		fsm.addTransition (null, "r", "idle", sw.findElement ("r/press"), null);

		new Connector (r2, null, "fsm2/state", "sw2/state");
		root.run ();
		app.startSystemHook();
	}

}
