Re: parameters for actions?

Dennis Ponos <[email protected]> 26 Jan 2005 15:50:36 -0800
Newsgroups gmane.comp.embedded.carlsbad-cubes
Message-ID <[email protected]>
Thank you again for your quick and complete reply.  See below... 

On Wed, 2005-01-26 at 12:43, Frank Meissner wrote:
> No, not necessarily. You may write your action like this:
> public class MyAction extends AbstractAction {
>    MyAction(String menuId, String textFieldId) {
>      this.menuId = menuId;
>      this.textFieldId = textFieldId;
>    }
>    public void actionPerformed(ActionEvent ae) {
>      JMenuItem jmi = swingEngine.find(menuId);
>      JTextComponent jtc = swingEngine.find(textFieldId);
>      ...
>      jmi.setEnabled(<somewickedcomputation(jtc)>);
>    }
> }
> 
> public class MySwingEngine extends SwingEngine {
>    public Action myAction1 = new MyAction("menu1", "text1");
>    public Action myAction2 = new MyAction("menu2", "text2");
>    MySwingEngine() {
>      comp = render("...");
>      ...
>    }
> 
> }
> 

Yes.  So this is what I meant by needing "another" action.  In this
example, we have only one Action class (MyAction) that performs the
method generically, but MySwingEngine has multiple instances of
MyAction.  If the GUI later has menu3/text3 that needs to be maintained
the same way, I would need to add myAction3 to MySwingEngine. 

The reason why this would be an issue for me is that I am going to be
writing a controller engine for unknown applications.  Application
developers will be developing multiple applications using the engine I
create, and the only GUI development they will be doing is with the XML
descriptors.  So the engine, and it's Actions, cannot make ANY
assumptions about specific widgets or widget names, etc....

And you are right, setEnabled will be the result of some wicked
computation! :-) 


> Or, you could write your own components having a specialized setter 
> waiting for ids to be supplied.
> public MyButton extends JButton {
>    public void setMyIds(String csvIds) {
>      ...
>    }
> }
> 
> <mybutton myids="id1,id2"...>
> 

Yes.  I think that this approach would give me the generic functionality
I am looking for.  The parameters are specified in the XML.  There is
only one Action, which performs generically, and the engine remains
stable. 

This gives me a lot to think about in regards to a possible design for
my "generic engine".