Swixml was updated to version 0.5.

The available swixml.jar is optimized for size (32Kb) and doesn't give you a
lot of debug info.
Therefore, if you need to debug into swixml you may want to get the source.
As always, the latest source, javadoc, and tag/attribute API is available in
a zip file for download. http://www.swixml.org/swixml.zip

Also, see the custom attributes documentation for recently added custom
attributes:
http://www.swixml.org/tagdocs/customattr.html

One of the major feature is this release is probably the availability of
Actions.
Take a look at this sample to learn about a new way to link event handlers
to widgets:

The sample show 2 different ways how to hookup widget with event handlers.
The link between the widget and the event handler is defined in the XML,
which avoids the otherwise required manual linkage through code, which is
shown as well.

The "new" way looks very clean, no find() required, no id attribute
required, clean code.
Please let me know what you think ...

Wolf

Sample:
XML==================================================================

<?xml version="1.0" encoding="UTF-8"?>
<frame title="Swixml - Action Sample" size="280,140">
  <menubar>
    <menu text="File">
      <menuitem text="User" icon="/icons/user.gif" mnemonic="VK_N"
Action="usrAction"/> // NEW STUFF !!!
      <menuitem id="mi_doc" text="Document" icon="/icons/open.gif"
mnemonic="VK_O" ActionCommand="document"/>
      <menuitem id="mi_svr" text="Server" icon="/icons/server.gif"
mnemonic="VK_S" ActionCommand="server"/>
      <separator/>
      <menuitem text="Exit" icon="/icons/exit.gif" mnemonic="VK_X"
ActionCommand="exit"/>
    </menu>
    <menu text="Help">
      <menuitem text="About" enabled="true" icon="/icons/info.gif"
ActionCommand="about"/>
    </menu>
  </menubar>

  <panel layout="borderlayout" constraints="BorderLayout.NORTH">
    <toolbar floatable="true" borderPainted="true" orientation="HORIZONTAL">
      <button ToolTipText="User" enabled="true" icon="/icons/usrx.gif"
Action="usrAction"/>
      <button id="btn_doc" ToolTipText="Document" enabled="true"
icon="/icons/docx.gif" ActionCommand="document"/>
      <button id="btn_svr" ToolTipText="Server" enabled="true"
icon="/icons/svrx.gif" ActionCommand="server"/>
    </toolbar>
  </panel>
  <panel>
    <label text="This is the Action Sample" />
  </panel>
</frame>

JAVA==================================================================

package org.swixml.examples;

import org.swixml.SwingEngine;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;

public class Action extends SwingEngine {

  private String msg = "Clicked";

  /** public member variable defines the NEW action */
  public AbstractAction usrAction = new AbstractAction() { // NEW STUFF !!!
but needs to be public
    /** Invoked when an action occurs. */
    public void actionPerformed(ActionEvent e) {
      System.out.println( msg + "User" ); // access outer class member
      this.setEnabled( false ); // disables all buttons that are tied to
this action
    }
  };

  public ActionListener anyAction = new ActionListener() {
    /** Invoked when an action occurs. */
    public void actionPerformed(ActionEvent e) {
      System.out.println( e.getActionCommand().toString() );

      if (e.getActionCommand().equals( "server" )) {
        System.out.println( "Server Button clicked" );
      }
    }
  };

  private Action() {
    try {
      this.render( new URL(
"file:///C:/work/swixex/classes/org/swixml/examples/action.xml" ) );
      ((AbstractButton) this.find( "mi_doc" )).addActionListener(
anyAction );
      ((AbstractButton) this.find( "btn_doc" )).addActionListener(
anyAction );
      ((AbstractButton) this.find( "mi_svr" )).addActionListener(
anyAction );
      ((AbstractButton) this.find( "btn_svr" )).addActionListener(
anyAction );
    } catch (Exception e) {
      e.printStackTrace();
    }
    this.getRootComponent().setVisible( true );
  }

  public static void main(String[] args) {
    new Action();
  }
}


Reply via email to