How To Lookup Widgets
Gerald Bauer <[email protected]> Fri, 19 Sep 2003 10:45:15 -0700 (PDT)
| Newsgroups | gmane.comp.java.luxor-xul.user |
|---|---|
| Message-ID | <[email protected]> |
Hi Anakrewn Meidis,
Hi all,
First Anakrewn I hope you don't mind if I answer in
public on the mailing list so others can share their
comments.
>>> The most important thing i'd like to talk about is
>>> the init.bsh script
>>> found and samples/tree/scripts.
>> As far as I can tell let's move all the lookup and
>> registration methods into the Luxor core such as
>> XulMan for example.
> Yes.I have the same opinion.
> The most suitable place probably would be the
XulManager.
> When all components are created then the Interpreter
will be
> instanciated and so on.
> What is interesting to discuss is how the XulManager
will give
> references to components to the scripts.
> One possible solution is usage of ids(like is done
now by the init.bsh)
> for example Component lookupComponent(String name)
> Component lookupComponent(Component uncestor, String
name)
> and perhaps other convinient methods as well.
I've already added some lookup methods to Luxor Beta
9 that we can use for a start.
The salsa module now includes a static CompUtils
class for widget lookup. For example:
public class CompUtils
{
public static JComponent get( Container parent,
String id )
{
// find component; using breath first search
Component c[] = parent.getComponents();
if( c == null )
return null;
for( int i=0; i < c.length; i++ )
{
String name = c[i].getName();
if( name != null && name.equals( id ) )
return (JComponent) c[i];
}
for( int i=0; i < c.length; i++ )
if( c[i] instanceof Container )
{
JComponent found = get( (Container) c[i], id
);
if( found != null )
return found;
}
return null;
}
and so on and so forth.
And I've created new Swing classes such as JFrameEx
and JPanelEx that include the get() method for easy
widget lookup.
Example:
public class JFrameEx extends JFrame
{
public JFrameEx() { super(); }
public JFrameEx( String title ) { super( title ); }
public JComponent get( String id )
{
JComponent comp = CompUtils.get( this, id );
if( comp != null )
return comp;
Status.error( "could not find component reference " +
id + " inside frame" );
return null;
}
}
and finally I've changed the Luxor kernel (XulManager,
and so on) to use the new J*Ex classes instead of the
plain old standard Swing classes such as JFrame,
JPanel and so on.
Let me know what you think.
> An other issue is how XulManager (or any other class
responsible for
> this task) will load the scripts.
> The solution I provided is ruther unacceptable.
> It loads (if exists) the scripts/init.bsh which
afterwords
> loads the rest of the scripts.
Good question. Let's improve the widget lookup first
and then see how to improve the script loading. Any
suggestions are welcome.
- Gerald
-------------------------------------------------------
This sf.net email is sponsored by:ThinkGeek
Welcome to geek heaven.
http://thinkgeek.com/sf