Hi.

I've been messing with custom EditorPanes and have come up with this
really simple Actor to demonstrate what I'm up to.

The Actor has a single StringParameter.  The editor pane displays this
value and an additional JButton.  When the button is pressed two more
choices are added to the StringParameter.  The ChangeListener isn't
being used yet in the ConfigTestEditorPane class.

For some reason, the Cancel button is no longer working.  I suspect the
generated undo change is not being executed in the correct context.  Any
ideas how I can correct this?

Thanks

Kevin Ruland
University of Kansas.


package edu.tutorial;

import java.awt.Component;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JPanel;

import ptolemy.actor.TypedAtomicActor;
import ptolemy.actor.gui.EditorPaneFactory;
import ptolemy.actor.gui.PtolemyQuery;
import ptolemy.data.expr.StringParameter;
import ptolemy.gui.CloseListener;
import ptolemy.gui.QueryListener;
import ptolemy.kernel.CompositeEntity;
import ptolemy.kernel.util.IllegalActionException;
import ptolemy.kernel.util.NameDuplicationException;
import ptolemy.kernel.util.NamedObj;

public class ConfigTest extends TypedAtomicActor {
    
    public ConfigTest(CompositeEntity container, String name)
    throws IllegalActionException, NameDuplicationException {
        super(container, name);
        MainValue = new StringParameter(this,"MainValue" );
        new ConfigEditorPaneFactory( this, "");
    }
    
    private StringParameter MainValue;
    private static int optionCounter = 0;
    
    private class ConfigEditorPaneFactory extends EditorPaneFactory {
        
        public ConfigEditorPaneFactory(NamedObj container, String name)
        throws IllegalActionException, NameDuplicationException {
            super(container, name);
        }
        public Component createEditorPane() {
            return new ConfigPane( (ConfigTest) getContainer() );
        }
        
        private class ConfigPane extends JPanel implements QueryListener, 
CloseListener {
            
            private ConfigPane( ConfigTest container ) {
                parent = container;
                setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
                query = new PtolemyQuery( parent );
                query.setTextWidth(40);
                query.addStyledEntry( parent.MainValue );
                add(query);
                JButton update = new JButton("ChangeOptions");
                update.addActionListener( new ActionListener() { 
                    public void actionPerformed(ActionEvent e) {
                            changeOptions();
                    }
                });
                add( update );
                
            }
            public void changed(String name) {
                System.out.println("QueryListener.changed: " + name);
            }
            public void windowClosed(Window window, String button) {
                System.out.println( "CloseListener.windowClosed");
                query.windowClosed(window,button);
            }
            private ConfigTest parent;
            private PtolemyQuery query;
            
            private void changeOptions( ) {
                StringParameter p = parent.MainValue;
                  for( int i=0; i < 2; i++ ) {
                        p.addChoice( Integer.toString(optionCounter++) );
                    }
            }
            
        }       
    }
}

Reply via email to