“GUIs are described in XML documents,parsed at runtime, and rendered intojavax.swing components.”                         ...
<html> <head>  ..  <link rel="stylesheet" type="text/css" href="/Styles/main.css"/>  <script type="text/javascript" src="/...
Models       Knowledge             Requirements   DeclarativeReal World             Architecture                          ...
<?xml version="1.0" encoding="UTF-8"?><frame size="440,380" title="Hello SWIXML World"> <panel constraints="BorderLayout.N...
public class Foo {    public Foo() throws Exception {      new SwingEngine().render( "xml/gui.xml" ).setVisible( true );  ...
<frame size="440,380" title="Hello SWIXML World">  ...             ... equivalent to ... JFrame frame = new JFrame(); fram...
● applet              ● label                 ● slider● button              ● list                  ● spinner● buttongroup...
public class Foo {    public Foo() throws Exception {      SwingEngine.getTaglib().registerTag( "Calendar", JCalendar.clas...
<?xml version="1.0" encoding="UTF-8" ?><frame title="Custom Tags" size="400,260"> <panel layout="BorderLayout">   <panel b...
<frame ... plaf="org.jvnet.substance.skin.SubstanceRavenLookAndFeel">                                                     ...
<panel>   <combobox action=”doSelect” initclass=”com.company.MyModel”/> </panel>.. equivalent to ..                      i...
<frame ... bundle="locale.myBundle" locale="de">1   src        1  com.company             MyClass.java               ......
accelerator                name      disabledicons              text      Localized      displayedmnemonics         title ...
<label text="beatles_addr" color="blue"/>                 vs.        <label color="blue">           Abbey Road        </la...
<label text="My blue label" foreground="blue" font="Verdana-BOLD-18”/>   java.swing.Action                    java.awt.Ins...
public interface Converter {     Object convert( Class type, Attribute attr, Localizer localizer );     Class convertsTo()...
package org.swixml.converters;import org.jdom.Attribute;import org.swixml.*;import java.awt.*;public class FontConverter i...
<?xml version="1.0" encoding="UTF-8" ?><frame ... >  <menubar>      <menu text="File">       <menuitem id="mi_save" text="...
<?xml version="1.0" encoding="UTF-8" ?><frame ... >  <menubar>     <menu text="File">        <menuitem text="Open File" ac...
Demo
java.netswixml.org
Joshua Marinacci, Member of Sun’s Swing Team: “The net result of working                      with SwixML is delivering be...
Thanks for  coming
Swixml, XML-based domain-specific language for declaring Java Swing GUIs
Upcoming SlideShare
Loading in …5
×

Swixml, XML-based domain-specific language for declaring Java Swing GUIs

7,535 views

Published on

SwiXml is a small GUI generating engine for Java applications and applets. Graphical User Interfaces are described in XML documents that are parsed at runtime and rendered into javax.swing objects.
Theoretically, you can look at SwiXml as an XML based domain-specific language, allowing to declare Java Swing GUIs. The Swixml engine will then later at runtime, take a GUI declaration and create that User-Interface on the fly, just like a Web Browser would do with an HTML document.
SwiXml doesn\'t introduce any new layout managers or component classes. Instead, it operates directly on the Swing component classes using introspection.

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
7,535
On SlideShare
0
From Embeds
0
Number of Embeds
2,891
Actions
Shares
0
Downloads
1
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Swixml, XML-based domain-specific language for declaring Java Swing GUIs

  1. 1. “GUIs are described in XML documents,parsed at runtime, and rendered intojavax.swing components.” [Apache License V.2.0]
  2. 2. <html> <head> .. <link rel="stylesheet" type="text/css" href="/Styles/main.css"/> <script type="text/javascript" src="/Scripts/global.js"/> </head> <body> <div id="content"> .. </div> .. </body></html> Separation of Concerns
  3. 3. Models Knowledge Requirements DeclarativeReal World Architecture Imperative Code
  4. 4. <?xml version="1.0" encoding="UTF-8"?><frame size="440,380" title="Hello SWIXML World"> <panel constraints="BorderLayout.NORTH"> <label font="ARIAL-BOLD-16" foreground="blue" text="Hello World!"/> </panel> <panel constraints="BorderLayout.SOUTH"> <button text="Click Here" /> </panel></frame>
  5. 5. public class Foo { public Foo() throws Exception { new SwingEngine().render( "xml/gui.xml" ).setVisible( true ); } public static void main( String[] args ) throws Exception { new Foo(); }}
  6. 6. <frame size="440,380" title="Hello SWIXML World"> ... ... equivalent to ... JFrame frame = new JFrame(); frame.setSize( new Dimension( 440, 380 ) ); frame.setTitle( “Hello SWIXML World” );
  7. 7. ● applet ● label ● slider● button ● list ● spinner● buttongroup ● menu ● splitpane● checkbox ● menubar ● tabbedpane● checkboxmenuitem ● menuitem ● tableElements● combobox ● optionpane ● tableheader● component ● panel ● textarea● desktoppane ● passwordfield ● textfield● dialog ● popupmenu ● textpane● editorpane ● progressbar ● togglebutton● formattedtextfield ● radiobutton ● toolbar● frame ● radiobuttonmenuitem ● tree● hbox ● scrollpane ● vbox● internalframe ● separator ● ... custom tags
  8. 8. public class Foo { public Foo() throws Exception { SwingEngine.getTaglib().registerTag( "Calendar", JCalendar.class ); new SwingEngine().render( "xml/jcal.xml" ).setVisible( true ); } public static void main( String[] args ) throws Exception { new Foo(); }}
  9. 9. <?xml version="1.0" encoding="UTF-8" ?><frame title="Custom Tags" size="400,260"> <panel layout="BorderLayout"> <panel background="white" constraints="BorderLayout.NORTH"> <label font="Comic Sans MS-BOLD-18" foreground="black"> Custom Components in Swixml </label> </panel> <calendar border="TitledBorder(JCalendar)" initclass="java.util.Date"/> </panel></frame>
  10. 10. <frame ... plaf="org.jvnet.substance.skin.SubstanceRavenLookAndFeel"> QuaquaSubstance
  11. 11. <panel> <combobox action=”doSelect” initclass=”com.company.MyModel”/> </panel>.. equivalent to .. initclass() initclass( String s ) initclass.getInstance() JPanel pnl = new JPanel(); JComboBox cbx = new JComboBox(); cbx.setModel ( new com.company.MyModel() ); cbx.setAction( client.doSelect ); pnl.add( cbx );
  12. 12. <frame ... bundle="locale.myBundle" locale="de">1 src 1 com.company MyClass.java ... 1 xml myGUI.xml ... 1 locale myBundle_en.properties myBundle_fr.properties1 myBundle_de.properties
  13. 13. accelerator name disabledicons text Localized displayedmnemonics title icon titleat icons titles Attributes iconimage tooltiptext label tooltiptexts mnemonic ... custom attributes mnemonicsorg.swixml.Parser.LOCALIZED_ATTRIBUTES.add( "myAttribute" )
  14. 14. <label text="beatles_addr" color="blue"/> vs. <label color="blue"> Abbey Road </label>
  15. 15. <label text="My blue label" foreground="blue" font="Verdana-BOLD-18”/> java.swing.Action java.awt.Insets javax.swing.border.Border javax.swing.KeyStroke java.awt.Color java.awt.LayoutManager java.awt.Dimension java.util.Locale Converters java.awt.Font java.awt.Image java.awt.Point java.awt.Rectangle javax.swing.Icon Primitives javax.swing.IconImage ... custom converters
  16. 16. public interface Converter { Object convert( Class type, Attribute attr, Localizer localizer ); Class convertsTo(); }ConverterLibrary.getInstance().register( myConverter );
  17. 17. package org.swixml.converters;import org.jdom.Attribute;import org.swixml.*;import java.awt.*;public class FontConverter implements Converter { public Object convert( Class type, Attribute attr, Localizer localizer ) throws Exception { return attr != null ? Font.decode( attr.getValue() ) : null; } public Class convertsTo() { return Font.class; }}
  18. 18. <?xml version="1.0" encoding="UTF-8" ?><frame ... > <menubar> <menu text="File"> <menuitem id="mi_save" text="Save" actioncommand="AC_SAVE"/> .. <panel border="EtchedBorder"> <button id="btn1" . . . /> ..public class Foo implements ActionListener { private JButton btn1; // auto-assigned by Swixml private JMenuItem mi_save; // auto-assigned by Swixml public Foo() throws Exception { Container c = new SwingEngine( this ).render( "xml/gui.xml" ); mi_save.addActionListener( this ); ..
  19. 19. <?xml version="1.0" encoding="UTF-8" ?><frame ... > <menubar> <menu text="File"> <menuitem text="Open File" action="open"/> <separator/> ..</frame>public class Foo { public Action open = new AbstractAction() { // auto-bound public void actionPerformed( ActionEvent e ) { // by Swixml ... } }; public Foo() throws Exception { new SwingEngine( this ).render( "xml/gui.xml" ).setVisible( true ); ..
  20. 20. Demo
  21. 21. java.netswixml.org
  22. 22. Joshua Marinacci, Member of Sun’s Swing Team: “The net result of working with SwixML is delivering better-looking applications in less time, and that is always a good thing.” Ben Galbraith, author of Professional JSP 2.0 and Professional Apache Tomcat: “SwixML is the most mature XUL/Swing offering. If youre looking for a way to define your Swing UIs in XML, SwixML is one of the best choices around.” Rick Jelliffe, CTO of Topologi: “By moving to SwixML, we reduced source code size by 500k and improved maintainability and startup time.” Kate Rhodes: “I think that SwixML is the easiest way to define a Swing layout, period.” Hans Mueller, CTO for Suns Desktop Division: ”When defining Java Swing GUIs declaratively, SwixML is the strongest example.”© 2003-2006 Carlsbad Cubes© 2011 wolfpaulus.com
  23. 23. Thanks for coming

×