Search in sources :

Example 1 with UI

use of org.jpos.ui.UI in project jPOS by jpos.

the class JTreeFactory method create.

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));
                    }
                // System.out.println ("ACTION: " + action);
                // System.out.println ("COMMAND: " + command);
                }
            }
        }
    });
    return tree;
}
Also used : StringTokenizer(java.util.StringTokenizer) UI(org.jpos.ui.UI) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ActionListener(java.awt.event.ActionListener) HashMap(java.util.HashMap) ActionEvent(java.awt.event.ActionEvent) TreeSelectionListener(javax.swing.event.TreeSelectionListener) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 StringTokenizer (java.util.StringTokenizer)1 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)1 TreeSelectionListener (javax.swing.event.TreeSelectionListener)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 UI (org.jpos.ui.UI)1