/**
 * Created by frank on 22.05.14.
 *
 * Hello World 3 - Creates a ProcessEditor JPanel with a sample process and animation.
 */

import com.inubit.research.animation.AnimationFacade;
import net.frapu.code.visualization.ProcessEditor;
import net.frapu.code.visualization.bpmn.*;

import javax.swing.*;
import java.awt.*;

public class helloworld3 {

    public static void main(String args[]) {

        // Create a new BPMN model
        BPMNModel myModel = new BPMNModel("My Process");

        // Create a number of elements
        Task task1 = new Task(200,100, "Hello");
        Task task2 = new Task(400,100, "World");

        // Create a sequence flow connecting the elements
        SequenceFlow flow1 = new SequenceFlow(task1, task2);

        // Add elements and flow to the model
        myModel.addNode(task1);
        myModel.addNode(task2);
        myModel.addFlow(flow1);

        // Create a new Process Editor JPanel with your own model
        ProcessEditor editor = new ProcessEditor(myModel);

        // Do some Swing stuff to show the JPanel
        JFrame f = new JFrame("Hello World 3");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setSize(600,300);
        f.add(editor);
        f.setVisible(true);

        // Create another node
        StartEvent event1 = new StartEvent(100,100, "Start");
        // Enable animation effects in editor
        editor.setAnimationEnabled(true);
        // Add node after 1000ms with a 2000ms fade-in effect
        editor.getAnimator().addProcessNode(event1, 2000, 1000, AnimationFacade.Type.TYPE_FADE_IN);

        // Change properties, create copy of node
        StartEvent newProperties = new StartEvent();
        // Set background to red and change position
        newProperties.setBackground(Color.RED);
        newProperties.setPos(50,50);
        /* Add change request to animation queue, starting after 5000ms (since the first animation is
           still pending yet!
         */
        editor.getAnimator().animateNode(event1, newProperties, 2000, 5000);
    }
}
