<commit_before>package com.rafkind.paintown.animator;

import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.io.*;

import org.swixml.SwingEngine;
import javax.swing.filechooser.FileFilter;

import com.rafkind.paintown.animator.CharacterStats;
import com.rafkind.paintown.animator.DrawArea;
import com.rafkind.paintown.exception.*;
import com.rafkind.paintown.*;

public final class Player{

    private JTextField nameField;
    private SwingEngine playerEditor;
    private CharacterStats character;
    private Animation currentAnimation;

    public SpecialPanel getEditor(){
        return new SpecialPanel((JPanel)playerEditor.getRootComponent(), nameField, character );
    }

    private JPanel createAnimation(){
        final JPanel panel = new JPanel();
        panel.setLayout(new GridBagLayout());
        GridBagConstraints constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.weightx = 1;
        constraints.weighty = 1;
        constraints.fill = GridBagConstraints.BOTH;
        constraints.anchor = GridBagConstraints.NORTHWEST;

        final DrawArea drawArea = new DrawArea(new Lambda0(){
            public Object invoke(){
                /* yes, this should be null unless something better
                 * can be put in the popup place
                 */
                return null;
            }
        });

        panel.add(drawArea, constraints);

        /*
        final JLabel scaleNum = (JLabel) playerEditor.find( "scale-num" );
        scaleNum.setText( "Scale: " + _drawArea.getScale() );
        final JSlider scale = (JSlider) playerEditor.find( "scale" );
        scale.setValue( (int)(_drawArea.getScale() * 5.0) );
        scale.addChangeListener( new ChangeListener(){
            public void stateChanged( ChangeEvent e ){
                _drawArea.setScale( scale.getValue() / 5.0 );
                scaleNum.setText( "Scale: " + _drawArea.getScale() );
            }
        });
        */

        return panel;
    }

    public Player(final Animator animator, final CharacterStats character){
        this.character = character;

        playerEditor = new SwingEngine( "animator/base.xml" );

        final SwingEngine contextEditor = new SwingEngine("animator/context.xml");
        final SwingEngine controlEditor = new SwingEngine("animator/controls.xml");

        //debugSwixml(playerEditor);
        //debugSwixml(contextEditor);

        final JSplitPane split = (JSplitPane) playerEditor.find("split");
        SwingUtilities.invokeLater(new Runnable(){
            public void run(){
                if ( split.getDividerLocation() != -1 ){
                    split.setDividerLocation(0.6);
                } else {
                    SwingUtilities.invokeLater(this);
                }
            }

        });

        final JPanel context = (JPanel) playerEditor.find( "context" );
        final JTabbedPane animations = (JTabbedPane) playerEditor.find("animations");

        final Lambda2 changeName = new Lambda2(){
            public Object invoke(Object self, Object name){
                animations.setTitleAt(animations.indexOfComponent((JComponent) self), (String) name);
                return this;
            }
        };

        final JButton addAnimation = (JButton) playerEditor.find("add-animation");
        addAnimation.addActionListener(new AbstractAction(){
            public void actionPerformed(ActionEvent event){
                // animations.add("New animation", createAnimation());
                animations.add("New animation", new CharacterAnimation(character, new Animation(), changeName));
            }
        });

        for (Animation animation : character.getAnimations()){
            animations.add(animation.getName(), new CharacterAnimation(character, animation, changeName));
	}

        /*
        // final JPanel canvas = (JPanel) playerEditor.find( "canvas" );

        final DrawArea _drawArea = new DrawArea(new Lambda0(){
            public Object invoke(){
                / * yes, this should be null unless something better
                 * can be put in the popup place
                 * /
                return null;
            }
        });

        GridBagConstraints constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.weightx = 1;
        constraints.weighty = 1;
        constraints.fill = GridBagConstraints.BOTH;
        constraints.anchor = GridBagConstraints.NORTHWEST;

        // canvas.add(_drawArea, constraints);

        final JLabel scaleNum = (JLabel) playerEditor.find( "scale-num" );<commit_msg>add new animation to character and start its thread<commit_after>package com.rafkind.paintown.animator;

import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.io.*;

import org.swixml.SwingEngine;
import javax.swing.filechooser.FileFilter;

import com.rafkind.paintown.animator.CharacterStats;
import com.rafkind.paintown.animator.DrawArea;
import com.rafkind.paintown.exception.*;
import com.rafkind.paintown.*;

public final class Player{

    private JTextField nameField;
    private SwingEngine playerEditor;
    private CharacterStats character;
    private Animation currentAnimation;

    public SpecialPanel getEditor(){
        return new SpecialPanel((JPanel)playerEditor.getRootComponent(), nameField, character );
    }

    private JPanel createAnimation(){
        final JPanel panel = new JPanel();
        panel.setLayout(new GridBagLayout());
        GridBagConstraints constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.weightx = 1;
        constraints.weighty = 1;
        constraints.fill = GridBagConstraints.BOTH;
        constraints.anchor = GridBagConstraints.NORTHWEST;

        final DrawArea drawArea = new DrawArea(new Lambda0(){
            public Object invoke(){
                /* yes, this should be null unless something better
                 * can be put in the popup place
                 */
                return null;
            }
        });

        panel.add(drawArea, constraints);

        /*
        final JLabel scaleNum = (JLabel) playerEditor.find( "scale-num" );
        scaleNum.setText( "Scale: " + _drawArea.getScale() );
        final JSlider scale = (JSlider) playerEditor.find( "scale" );
        scale.setValue( (int)(_drawArea.getScale() * 5.0) );
        scale.addChangeListener( new ChangeListener(){
            public void stateChanged( ChangeEvent e ){
                _drawArea.setScale( scale.getValue() / 5.0 );
                scaleNum.setText( "Scale: " + _drawArea.getScale() );
            }
        });
        */

        return panel;
    }

    public Player(final Animator animator, final CharacterStats character){
        this.character = character;

        playerEditor = new SwingEngine( "animator/base.xml" );

        final SwingEngine contextEditor = new SwingEngine("animator/context.xml");
        final SwingEngine controlEditor = new SwingEngine("animator/controls.xml");

        //debugSwixml(playerEditor);
        //debugSwixml(contextEditor);

        final JSplitPane split = (JSplitPane) playerEditor.find("split");
        SwingUtilities.invokeLater(new Runnable(){
            public void run(){
                if ( split.getDividerLocation() != -1 ){
                    split.setDividerLocation(0.6);
                } else {
                    SwingUtilities.invokeLater(this);
                }
            }

        });

        final JPanel context = (JPanel) playerEditor.find( "context" );
        final JTabbedPane animations = (JTabbedPane) playerEditor.find("animations");

        final Lambda2 changeName = new Lambda2(){
            public Object invoke(Object self, Object name){
                animations.setTitleAt(animations.indexOfComponent((JComponent) self), (String) name);
                return this;
            }
        };

        final JButton addAnimation = (JButton) playerEditor.find("add-animation");
        addAnimation.addActionListener(new AbstractAction(){
            public void actionPerformed(ActionEvent event){
                // animations.add("New animation", createAnimation());
                Animation animation = new Animation();
                character.addAnimation(animation);
                new Thread(animation).start();
                animations.add("New animation", new CharacterAnimation(character, animation, changeName));
            }
        });

        for (Animation animation : character.getAnimations()){
            animations.add(animation.getName(), new CharacterAnimation(character, animation, changeName));
	}

        /*
        // final JPanel canvas = (JPanel) playerEditor.find( "canvas" );

        final DrawArea _drawArea = new DrawArea(new Lambda0(){
            public Object invoke(){
                / * yes, this should be null unless something better
                 * can be put in the popup place
                 * /
                return null;
            }
        });

        GridBagConstraints constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.weightx = 1;
        constraints.weighty = 1;
        constraints.fill = GridBagConstraints.BOTH;
        constraints.anchor = GridBagConstraints.NORTHWEST;

        // canvas.add(_drawArea, constraints);

        final JLabel scaleNum = (JLabel) playerEditor.find( "scale-num" );
{'fraction_non_alphanumeric': 0.10145375811939375, 'fraction_numerical': 0.003917929683472523, 'mean_word_length': 2.281461434370771, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2554657', 'n_tokens_mistral': 2534, 'n_tokens_neox': 2445, 'n_words': 600}