package com.rafkind.paintown.animator.events;

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import com.rafkind.paintown.animator.Animation;
import com.rafkind.paintown.Token;
import com.rafkind.paintown.animator.events.AnimationEvent;
import org.swixml.SwingEngine;

public class OffsetEvent implements AnimationEvent
{
	private int _x;
	private int _y;
	
	public void loadToken(Token token){
		_x = token.readInt(0);
		_y = token.readInt(1);
	}
	
	public void interact( Animation animation ){
		animation.setOffsetX(_x);
		animation.setOffsetY(_y);
	}
	
	public String getName(){
		return getToken().toString();
	}
	
	public JDialog getEditor( Animation animation ){
		SwingEngine engine = new SwingEngine( "animator/eventoffset.xml" );
		((JDialog)engine.getRootComponent()).setSize(200,100);
		
		final JSpinner xspin = (JSpinner) engine.find( "x" );
		xspin.setValue(new Integer(_x));
		xspin.addChangeListener( new ChangeListener()
		{
			public void stateChanged(ChangeEvent changeEvent)
			{
				_x = ((Integer)xspin.getValue()).intValue();
			}
		});
		final JSpinner yspin = (JSpinner) engine.find( "y" );
		yspin.setValue(new Integer(_y));
		yspin.addChangeListener( new ChangeListener()
		{
			public void stateChanged(ChangeEvent changeEvent)
			{
				_y = ((Integer)yspin.getValue()).intValue();
			}
		});
		return (JDialog)engine.getRootComponent();
	}
	
	public Token getToken(){
		Token temp = new Token("offset");
		temp.addToken( new Token( "offset" ) );
		temp.addToken( new Token( String.valueOf( _x ) ) );
		temp.addToken( new Token( String.valueOf( _y ) ) );
		
		return temp;
	}
}

@@ -706,16 +706,22 @@
 tEditor(
+ final
  Animati
@@ -996,35 +996,32 @@
 ChangeListener()
-%0A%09%09
 %7B%0A%09%09%09public void
@@ -1054,28 +1054,24 @@
 changeEvent)
-%0A%09%09%09
 %7B%0A%09%09%09%09_x = (
@@ -1101,32 +1101,88 @@
 ()).intValue();%0A
+%09%09%09%09interact( animation );%0A%09%09%09%09animation.forceRedraw();%0A
 %09%09%09%7D%0A%09%09%7D);%0A%09%09fin
@@ -1176,16 +1176,17 @@
 %7D%0A%09%09%7D);%0A
+%0A
 %09%09final 
@@ -1315,19 +1315,16 @@
 stener()
-%0A%09%09
 %7B%0A%09%09%09pub
@@ -1369,20 +1369,16 @@
 geEvent)
-%0A%09%09%09
 %7B%0A%09%09%09%09_y
@@ -1416,24 +1416,80 @@
 intValue();%0A
+%09%09%09%09interact( animation );%0A%09%09%09%09animation.forceRedraw();%0A
 %09%09%09%7D%0A%09%09%7D);%0A%09

update offset on the fly