Class XmlUi

java.lang.Object
ucar.unidata.ui.XmlUi
All Implemented Interfaces:
ActionListener, ItemListener, EventListener
Direct Known Subclasses:
IdvXmlUi

public class XmlUi extends Object implements ActionListener, ItemListener
This class can create a UI from a "skin" xml. See the file ../apps/example/docs/xmlui.html for further details.
  • Field Details

  • Constructor Details

    • XmlUi

      public XmlUi()
      default ctor
    • XmlUi

      public XmlUi(String xml, Hashtable idToComponent, ActionListener actionListener)
      ctor
      Parameters:
      xml - The raw xml
      idToComponent - pre-defined id to component mapping. Allows you to have your own components that are referenced by the xml
      actionListener - Listener to pass events to
    • XmlUi

      public XmlUi(Element root, ActionListener actionListener)
      ctor
      Parameters:
      root - xml
      actionListener - Listener to pass events to
    • XmlUi

      public XmlUi(Element root, Hashtable idToComponent, ActionListener actionListener, Hashtable initProperties)
      Create the XmlUi processor. Root should point to a "skin" node. idToComponent is a Hashtable with application specific collection of id->java.awt.Component pairs. (May be null). actionListener - > route actions to it. (May be null).
      Parameters:
      root - xml root
      idToComponent - pre-defined id to component mapping. Allows you to have your own components that are referenced by the xml
      actionListener - Listener to pass events to
      initProperties - initial properties
    • XmlUi

      public XmlUi(Element root, Element startNode, Hashtable idToComponent, ActionListener actionListener, Hashtable initProperties)
  • Method Details

    • setStartNode

      public void setStartNode(Element node)
    • dispose

      public void dispose()
      The destructor
    • initializeComponents

      protected void initializeComponents(Element root)
      initialize
      Parameters:
      root - xml root
    • hasComponent

      public boolean hasComponent(String id)
      Does this object hold this component
      Parameters:
      id - component id
      Returns:
      do we currently have this component
    • addComponent

      public void addComponent(String id, Element component)
      Add the component
      Parameters:
      id - id
      component - component
    • addComponent

      public void addComponent(String id, Component comp)
      Add the given component to the idToComponent map. If the component already exists throw an IllegalStateException
      Parameters:
      id -
      comp -
    • getComponent

      public Component getComponent(String id)
      Return the Component identified by id
      Parameters:
      id - component id
      Returns:
      The component
    • getComponents

      public List getComponents()
      Get the list of components created
      Returns:
      components
    • getAlign

      public int getAlign(String align)
      Get the align value from the given string name
      Parameters:
      align - name
      Returns:
      align value
    • getAttr

      public String getAttr(Element node, String attr)
      Get the value of the given attribute on the node. This will first see if the node has the attribute. If not this will look into the styles. If still no value we will look up the xml tree to see if there is any attributes on nodes with the inherit prefix: i:attr_name If we find a value we will then convert any macros (defined with %...%)
      Parameters:
      node - node
      attr - attribute name
      Returns:
      value or null if none found
    • inheritNameOldWay

      public static String inheritNameOldWay(String attr)
      Get the inherited attribute name
      Parameters:
      attr - attr name
      Returns:
      i:attr
    • inheritName

      public static String inheritName(String attr)
    • getAttr

      public int getAttr(Element node, String attr, int dflt)
      Get the attribute value
      Parameters:
      node - node
      attr - attr
      dflt - default
      Returns:
      value or dflt
    • getAttr

      public double getAttr(Element node, String attr, double dflt)
      Get the attribute value
      Parameters:
      node - node
      attr - attr
      dflt - default
      Returns:
      value or dflt
    • getAttr

      public boolean getAttr(Element node, String attr, boolean dflt)
      Get the attribute value
      Parameters:
      node - node
      attr - attr
      dflt - default
      Returns:
      value or dflt
    • getAttr

      public String getAttr(Element node, String attr, String dflt)
      Get the attribute value
      Parameters:
      node - node
      attr - attr
      dflt - default
      Returns:
      value or dflt
    • getAttr

      public Color getAttr(Element node, String attr, Color dflt)
      Get the attribute value
      Parameters:
      node - node
      attr - attr
      dflt - default
      Returns:
      value or dflt
    • getAttr

      public ImageIcon getAttr(Element node, String attr, ImageIcon dflt)
      Get the attribute value
      Parameters:
      node - node
      attr - attr
      dflt - default
      Returns:
      value or dflt
    • getBorder

      public Border getBorder(String type, Element node)
      Create the border
      Parameters:
      type - border type
      node - xml node that holds any other attributes needed
      Returns:
      The border
    • setRoot

      public void setRoot(Element root)
      Set the xml root and reinitialize
      Parameters:
      root - xml root
    • getContents

      public Component getContents()
      Create, if needed, and return the gui
      Returns:
      gui
    • getProperty

      public String getProperty(String name)
      Look up the property
      Parameters:
      name - property name
      Returns:
      property value
    • xmlToUi

      protected Component xmlToUi(Element node)
      Convert the given xml node tree to a gui component
      Parameters:
      node - node
      Returns:
      gui
    • getImage

      public static Image getImage(String path)
      Create an image
      Parameters:
      path - image path
      Returns:
      image
    • getImageAttr

      public Image getImageAttr(Element node, String attr)
      Get image defined by attr name
      Parameters:
      node - node
      attr - attr
      Returns:
      image
    • createComponent

      public Component createComponent(Element node, String id)
      Create the awt Component defined by the given skin node.
      Parameters:
      node - node
      id - id
      Returns:
      The component
    • makeButton

      public JComponent makeButton(String tag, Element node)
      Make a button
      Parameters:
      tag - tag name
      node - node
      Returns:
      button
    • itemStateChanged

      public void itemStateChanged(ItemEvent event)
      handle event
      Specified by:
      itemStateChanged in interface ItemListener
      Parameters:
      event - event
    • actionPerformed

      public void actionPerformed(ActionEvent event)
      handle event. This calls actionPerformedInner in a non-swing thread
      Specified by:
      actionPerformed in interface ActionListener
      Parameters:
      event - event
    • extractOneArg

      public static String extractOneArg(String cmd)
      utility to parse commands
      Parameters:
      cmd - command
      Returns:
      The arg
    • extractTwoArgs

      public static String[] extractTwoArgs(String cmd)
      utility to parse commands
      Parameters:
      cmd - command
      Returns:
      The args
    • main

      public static void main(String[] args)
      test
      Parameters:
      args - args