package com.rafkind.paintown.animator.events;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import org.swixml.SwingEngine;

import com.rafkind.paintown.animator.Animation;
import com.rafkind.paintown.animator.DrawArea;
import com.rafkind.paintown.Token;
import com.rafkind.paintown.animator.events.AnimationEvent;

public class UserDefinedEvent implements AnimationEvent {
    private String name;
    private String value;

    public UserDefinedEvent(){
    }
    
    public void loadToken(Token token){
		name = token.readString(0);
		value = token.readString(1);
    }
    
    public Token getToken(){
        Token temp = new Token("user");
		temp.addToken(new Token("user"));
		temp.addToken(new Token(name));
		temp.addToken(new Token(value));
		
		return temp;
    }
    
    public void interact(Animation animation){
    }
    
    public String getName(){
        return getToken().toString();
    }

    public JPanel getEditor(final Animation animation, final DrawArea area){

        SwingEngine engine = new SwingEngine( "animator/event-user.xml" );
		final JTextField namePanel = (JTextField) engine.find("name");
		final JTextField valuePanel = (JTextField) engine.find("value");

        namePanel.setText(name);
        valuePanel.setText(value);
        namePanel.addActionListener(new AbstractAction(){
            public void actionPerformed(ActionEvent e){
                name = namePanel.getText();
            }
        });

        valuePanel.addActionListener(new AbstractAction(){
            public void actionPerformed(ActionEvent e){
                value = valuePanel.getText();
            }
        });

        return (JPanel) engine.getRootComponent();

    }

    public void destroy(){
    }
}

@@ -498,22 +498,61 @@
 vent()%7B%0A
+        name = %22%22;%0A        value = %22%22;%0A
     %7D%0A
-
     %0A   
@@ -650,24 +650,188 @@
 ng(1);%0A    %7D
+%0A%0A    private String maybeString(String value)%7B%0A        if (value.indexOf(%22 %22) != -1)%7B%0A            return %22%5C%22%22 + value + %22%5C%22%22;%0A        %7D%0A        return value;%0A    %7D
 %0A    %0A    pu
@@ -959,14 +959,27 @@
 ken(
+maybeString(
 name))
+)
 ;%0A%09%09
@@ -1006,15 +1006,28 @@
 ken(
+maybeString(
 value))
+)
 ;%0A%09%09

quote strings