A new Swixml version has been released and is available for download at the
Swixml Web site at http://www.swixml.org

Beside minor bug fixes, since this release every instanced SwingEngine has
its very own Parser, which used to be a Singleton.

More importantly however, this release features a new custom attribute:
initclass, which takes a class name.
The initclass is loaded, an instance is obtained, and passed into the
constructor of the tag's implementing class.
The development of idea and code was mostly driven by Frank Meissner of
Authentidate (http://www.authentidate.de and http://www.authentidate.com)

Great work Frank! We hope you continue to contribute great ideas and code.

To explain this new feature I have added a sample at
http://www.swixml.org/samples/

Here are the basics:
1.) The in initclass provided class is loaded and either a static
getInstance() method is called or a new instance is constructed.
2.) In the tag-implementing class, a constructor is located that accepts the
initclass.
3.) The tag-implementing class is constructed with an initclass instance as
a construction parameter.

Complete Sample:

XML: xml/InitClass.xml

<?xml version="1.0" encoding="UTF-8"?>
 <frame size="640,480" title="InitClass Attribute Sample">
   <panel constraints="BorderLayout.CENTER">
     <label DisplayedMnemonic="VK_E" LabelFor="tf">
       ComboBox
     </label>
     <combobox initclass="com.carlsbadcubes.examples.ComboModel"
Action="DO_SELECT" />
   </panel>
 </frame>


Java: com.carlsbadcubes.examples.ComboModel

 public class ComboModel extends DefaultComboBoxModel {
   public ComboModel( ) {
     super( new Object[] { "Bird", "Cat", "Dog", "Rabbit", "Pig" } );
   }
 }
}

Java: com.carlsbadcubes.examples.ComboModel
public class InitClass extends WindowAdapter {
  public Action DO_SELECT = new AbstractAction() {
    public void actionPerformed(ActionEvent e) {
      System.out.println( ((JComboBox)
e.getSource()).getSelectedItem().toString() );
    }
  };

  private InitClass() throws Exception {
    new SwingEngine( this ).render( "xml/InitClass.xml" ).setVisible(
true );
  }

  public static void main(String[] args) {
    try {
      new InitClass();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}

Here is what happens:
When the parser finds the <combobox> tag with the ComboModel initclass
attribute, it looks for a static public getInstance method in the ComboModel
class. Since there is no such method declared, a new ComboModel object is
instantiated.

The javax.swing.JComboBox is the registered implementing class for the
combobox tag. The JComboBox class is now introspected for a constructor that
would accept a ComboModel or a ancestor, which results in this ctor:
JComboBox(ComboBoxModel aModel).

The ComboModel instance is now passed into the constructor creating a new
JComboBox object.
Eventually, the SwingEngine links the mentioned public Action with the
JComboBox object.

The in initclass provided class needs to be loadable at runtime - has to be
in the classpath, jar, etc.
Moreover, it needs to implement a public static getInstance() method
(Singleton i.e.) or a public default constructor.

--
Wolf Paulus
C a r l s b a d   C u b e s
mailto:[EMAIL PROTECTED]

CONFIDENTIALITY NOTICE:
This message is intended only for the use of the individual or entity to
which it is addressed, and may contain information that is privileged,
confidential and exempt from disclosure under applicable law.
If you are not the intended recipient, please contact the sender by reply
email and destroy all copies of the original message.


Reply via email to