artisynth.core.modelmenu
Class DemoMenuParser

java.lang.Object
  extended by artisynth.core.modelmenu.DemoMenuParser

public class DemoMenuParser
extends java.lang.Object

Author:
antonio Parses an XML menu that can be used to create a menu entries for "Models". Doesn't actually build a JMenu, instead all information is constructed in a Tree that holds "MenuEntry" objects with icon/title/type information The XML format supports submenus, icons, dividers, reading classes from a .demoModels file, and reading classes in a given package that are derived from a supplied base class (e.g. RootModel). Other xml menu files can also be imported.

Nested Class Summary
static class DemoMenuParser.MenuType
           
static class DemoMenuParser.SimpleErrorHandler
           
 
Field Summary
static java.lang.String ALL_TAG_FONTNAME
           
static java.lang.String ALL_TAG_FONTSIZE
           
static java.lang.String ALL_TAG_FONTSTYLE
           
static java.lang.String ALL_TAG_FONTSTYLE_BOLD
           
static java.lang.String ALL_TAG_FONTSTYLE_ITALIC
           
static java.lang.String DEMO_TAG
           
static java.lang.String DEMO_TAG_CLASS
           
static java.lang.String DEMO_TAG_ICON
           
static java.lang.String DEMO_TAG_TEXT
           
static java.lang.String DEMOFILE_TAG
           
static java.lang.String DEMOFILE_TAG_FILENAME
           
static java.lang.String DEMOPACKAGE_TAG
           
static java.lang.String DEMOPACKAGE_TAG_BASECLASS
           
static java.lang.String DEMOPACKAGE_TAG_COMPACT
           
static java.lang.String DEMOPACKAGE_TAG_REGEX
           
static java.lang.String DEMOPACKAGE_TAG_SRC
           
static java.lang.String DEMOPACKAGE_TAG_VIEW
           
static java.lang.String DEMOPACKAGE_TAG_VIEW_FLAT
           
static java.lang.String DEMOPACKAGE_TAG_VIEW_HIERARCHICAL
           
static java.lang.String DIVIDER_TAG
           
static java.lang.String HIDDEN_TAG
           
static java.lang.String LABEL_TAG
           
static java.lang.String LABEL_TAG_ICON
           
static java.lang.String LABEL_TAG_TEXT
           
static java.lang.String MENU_TAG
           
static java.lang.String MENU_TAG_ICON
           
static java.lang.String MENU_TAG_TEXT
           
static java.lang.String ROOT_TAG
           
static java.lang.String XMLINCLUDE_TAG
           
static java.lang.String XMLINCLUDE_TAG_FILE
           
 
Constructor Summary
DemoMenuParser()
           
 
Method Summary
static void compactMenu(Tree<MenuEntry> menu)
          If a menu entry has only a single child, it merges it with this one and the new title becomes "title1 (title2)"
static java.lang.String findFile(java.lang.String filename, java.lang.String localPath)
          Finds a file specified by "file" First checks if file is specified by an absolute path.
static java.lang.String getPrefix(java.util.ArrayList<java.lang.String> array)
          Given a list of strings, finds the greatest common prefix
static Tree<MenuEntry> parseXML(java.lang.String filename)
           
static void setFont(Node<MenuEntry> node, java.awt.Font font)
           
static void sortMenu(Node<MenuEntry> root)
           
static void sortMenu(Node<MenuEntry> root, java.util.Comparator<Node<MenuEntry>> comparer)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ROOT_TAG

public static final java.lang.String ROOT_TAG
See Also:
Constant Field Values

MENU_TAG

public static final java.lang.String MENU_TAG
See Also:
Constant Field Values

MENU_TAG_TEXT

public static final java.lang.String MENU_TAG_TEXT
See Also:
Constant Field Values

MENU_TAG_ICON

public static final java.lang.String MENU_TAG_ICON
See Also:
Constant Field Values

DIVIDER_TAG

public static final java.lang.String DIVIDER_TAG
See Also:
Constant Field Values

LABEL_TAG

public static final java.lang.String LABEL_TAG
See Also:
Constant Field Values

LABEL_TAG_ICON

public static final java.lang.String LABEL_TAG_ICON
See Also:
Constant Field Values

LABEL_TAG_TEXT

public static final java.lang.String LABEL_TAG_TEXT
See Also:
Constant Field Values

DEMO_TAG

public static final java.lang.String DEMO_TAG
See Also:
Constant Field Values

DEMO_TAG_TEXT

public static final java.lang.String DEMO_TAG_TEXT
See Also:
Constant Field Values

DEMO_TAG_CLASS

public static final java.lang.String DEMO_TAG_CLASS
See Also:
Constant Field Values

DEMO_TAG_ICON

public static final java.lang.String DEMO_TAG_ICON
See Also:
Constant Field Values

DEMOFILE_TAG

public static final java.lang.String DEMOFILE_TAG
See Also:
Constant Field Values

DEMOFILE_TAG_FILENAME

public static final java.lang.String DEMOFILE_TAG_FILENAME
See Also:
Constant Field Values

DEMOPACKAGE_TAG

public static final java.lang.String DEMOPACKAGE_TAG
See Also:
Constant Field Values

DEMOPACKAGE_TAG_SRC

public static final java.lang.String DEMOPACKAGE_TAG_SRC
See Also:
Constant Field Values

DEMOPACKAGE_TAG_VIEW

public static final java.lang.String DEMOPACKAGE_TAG_VIEW
See Also:
Constant Field Values

DEMOPACKAGE_TAG_VIEW_FLAT

public static final java.lang.String DEMOPACKAGE_TAG_VIEW_FLAT
See Also:
Constant Field Values

DEMOPACKAGE_TAG_VIEW_HIERARCHICAL

public static final java.lang.String DEMOPACKAGE_TAG_VIEW_HIERARCHICAL
See Also:
Constant Field Values

DEMOPACKAGE_TAG_BASECLASS

public static final java.lang.String DEMOPACKAGE_TAG_BASECLASS
See Also:
Constant Field Values

DEMOPACKAGE_TAG_REGEX

public static final java.lang.String DEMOPACKAGE_TAG_REGEX
See Also:
Constant Field Values

DEMOPACKAGE_TAG_COMPACT

public static final java.lang.String DEMOPACKAGE_TAG_COMPACT
See Also:
Constant Field Values

XMLINCLUDE_TAG

public static final java.lang.String XMLINCLUDE_TAG
See Also:
Constant Field Values

XMLINCLUDE_TAG_FILE

public static final java.lang.String XMLINCLUDE_TAG_FILE
See Also:
Constant Field Values

HIDDEN_TAG

public static final java.lang.String HIDDEN_TAG
See Also:
Constant Field Values

ALL_TAG_FONTNAME

public static final java.lang.String ALL_TAG_FONTNAME
See Also:
Constant Field Values

ALL_TAG_FONTSTYLE

public static final java.lang.String ALL_TAG_FONTSTYLE
See Also:
Constant Field Values

ALL_TAG_FONTSTYLE_BOLD

public static final java.lang.String ALL_TAG_FONTSTYLE_BOLD
See Also:
Constant Field Values

ALL_TAG_FONTSTYLE_ITALIC

public static final java.lang.String ALL_TAG_FONTSTYLE_ITALIC
See Also:
Constant Field Values

ALL_TAG_FONTSIZE

public static final java.lang.String ALL_TAG_FONTSIZE
See Also:
Constant Field Values
Constructor Detail

DemoMenuParser

public DemoMenuParser()
Method Detail

parseXML

public static Tree<MenuEntry> parseXML(java.lang.String filename)
                                throws java.io.IOException,
                                       javax.xml.parsers.ParserConfigurationException,
                                       org.xml.sax.SAXException
Throws:
java.io.IOException
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException

findFile

public static java.lang.String findFile(java.lang.String filename,
                                        java.lang.String localPath)
Finds a file specified by "file" First checks if file is specified by an absolute path. If not found, checks if it's relative to the supplied localPath. As a last resort, it searches ARTISYNTH_PATH

Returns:
The absolute path of the file, null if not found

compactMenu

public static void compactMenu(Tree<MenuEntry> menu)
If a menu entry has only a single child, it merges it with this one and the new title becomes "title1 (title2)"


setFont

public static void setFont(Node<MenuEntry> node,
                           java.awt.Font font)

sortMenu

public static void sortMenu(Node<MenuEntry> root,
                            java.util.Comparator<Node<MenuEntry>> comparer)

sortMenu

public static void sortMenu(Node<MenuEntry> root)

getPrefix

public static java.lang.String getPrefix(java.util.ArrayList<java.lang.String> array)
Given a list of strings, finds the greatest common prefix

Parameters:
array - input array of strings
Returns:
the greatest common prefix