* @see org.jpos.ui.UIFactory
*/
@SuppressWarnings("unchecked")
public class JTreeFactory implements UIFactory {
public JComponent create (UI ui, Element e) {
final UI parentUI = ui;
final Map map = new HashMap ();
final JTree tree = new JTree (getNode (e, map));
String font = e.getAttributeValue ("font");
if (font != null)
tree.setFont (Font.decode (font));
tree.setRootVisible (e.getTextTrim().length() > 0);
tree.addTreeSelectionListener (
new TreeSelectionListener() {
public void valueChanged(TreeSelectionEvent evt) {
DefaultMutableTreeNode node =
(DefaultMutableTreeNode)
tree.getLastSelectedPathComponent();
if (node != null) {
String s = (String) map.get (node);
if (s != null) {
StringTokenizer st = new StringTokenizer (s);
String action = st.nextToken ();
String command = null;
if (st.hasMoreTokens ())
command = st.nextToken ();
ActionListener al =
(ActionListener) parentUI.get(action);
if (al != null) {
al.actionPerformed (
new ActionEvent (node, 0, command)
);
}