wiki:JComponentEnvironment

JComponentEnvironment and constructing Swing user interfaces using the VirtualHumanLoader

The JComponentEnvironment can be used to set up the user interface layout of demo in which the different UI elements are later filled out using the XML specification. The layout can be created using JPanels (or any other JComponent):

final JFrame jframe = new JFrame();
final AsapEnvironment ee = new AsapEnvironment();
final JComponentEnvironment jce = new JComponentEnvironment();
try
{
    SwingUtilities.invokeAndWait(new Runnable()
    {

        @Override
        public void run()
        {
            JPanel jPanel = new JPanel();
            jce.registerComponent("panel1", jPanel);
            jframe.setLayout(new BorderLayout());
            jframe.add(jPanel, BorderLayout.SOUTH);
        }
    });
}
catch (InvocationTargetException e)
{
    throw new RuntimeException(e);
}
catch (InterruptedException e)
{
    throw new RuntimeException(e);
}
ArrayList<Environment> environments = new ArrayList<Environment>();
environments.add(jce);
...
ee.init(environments, clock);
..
ee.loadVirtualHuman("humanoid", "", "humanoid.xml", "AsapRealizer demo");

The registered component can then be hooked up to a JComponentEmbodimentLoader in the VirtualHumanLoader:

<Loader id="panelembodiment" loader="hmi.jcomponentenvironment.loader.JComponentEmbodimentLoader">
  <JComponent id="panel1"/>             
</Loader>

Which can be used in any other loader, for example in a JLabelTextEmbodiment:

<Loader id="textembodiment" loader="asap.textengine.JLabelTextEmbodiment" requiredloaders="panelembodiment"/>
<Loader id="textengine" loader="asap.textengine.loader.TextEngineLoader" requiredloaders="textembodiment"/>

Setting a new JFrame

<Loader id="frame1" loader="hmi.jcomponentenvironment.loader.JFrameLoader"><JFrame title="BML flow visualization" width="1024" height="768"/></Loader>
<Loader id="panel1" loader="hmi.jcomponentenvironment.loader.JComponentEmbodimentLoader">
  <JComponent id="frame1"/>             
</Loader>

This creates a new JFrame with a single panel in it. The panel is registered on the JComponentEnvironment with id "frame1" and can be hooked up with a JComponentEmbodimentLoader.