Hello,

  Allow me to highlight the blog story titled "XML to
Swing and the Gradual API" by Joshua Marinacci.

  Joshua writes:

There are a slew of XML UI languages out there for
building Swing UIs. Tons! Metric Tonnes!! And yet few
get used. Most of these systems require you to convert
a large portion of your program over. Even when you
can use it just one part of the program you still have
to redesign your GUI bindings, move your event
handlers, etc. There are new interfaces to be
implemented. Classes to initalize. And once that's
done you are locked in to that language, which may
make long term maintainence a headache.

Here is a simple XML UI language that solves most of
these problems and I think highlights what I've
learned over the years about writing sucessful APIs
(mostly by writing lots of unsucessful ones)

This creates a panel with two buttons, one with an
icon.

<panel layout="row">
    <button id="quit" text="Quit" icon="quit.png"/>
    <button id="start" text="Start"/>
</panel>

Be Familiar. The markup above looks very simple but a
lot of thought went into it. The XML elements map
directly to the real Swing components and have the
same names (minus the leading Js). The text and icon
fields match getter/setter methods on the real
objects. The layout is a row, which doesn't map
directly to a RowLayout object but it's conceptually
unabiguous what a row is so it will still make sense
to the developer. (It's actually a BoxLayout set to
X_AXIS). All pretty straightforward because it maps
directly to what the system replaces; to what the
developer is expecting.

Here's how you call it from code:

import org.joshy.guibuilder.*;

public class TestProg extends JPanel {

    public JButton quit;
    public JButton start;
    
    public static void main(String[] args) {
        TestProg prog = new TestProg();
        GuiBuilder.build("layout.xml"),prog);
        prog.createEvents();
    }
    
    public void createEvents() {        
        quit.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent
evt) {
                System.out.println("quitting");
                System.exit(0);
            }
        });
    }
    
}

That's it. The GuiBuilder class creates all of the
declared components from the XML and assigns them
through reflection to the fields in the TestProg
class. Very simple and efficent.  

   More @
http://weblogs.java.net/blog/joshy/archive/2004/12/xml_to_swing_an_1.html

   What's your take? Is Joshua Marinacci reinventing
the wheel by creating yet another XML UI language
solution for Java?

   - Gerald

-----------------------
Gerald Bauer
Rich Client Conference (RichCon) 2005 -
http://richcon.com
XUL News Wire - http://xulnews.com
XUL Alliance - http://xulalliance.org
United XAML - http://unitedxaml.org


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now. 
http://productguide.itmanagersjournal.com/
_______________________________________________
xul-announce mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/xul-announce

Reply via email to