We're going to look at how to extend the Example user interfaces.
- From a terminal window cd to the example apps directory:
cd /home/idv/idv/ucar/unidata/apps/example
- View the idv.rbi file:
less idv.rbi
and note the skin entry:
<!--The different user interfaces available -->
<resources name="idv.resource.skin">
<resource
location="/ucar/unidata/apps/example/resources/skin.xml"
label="Example>Example UI">
<property name="view_class" value="ucar.unidata.idv.MapViewManager"/>
</resource>
</resources>
- We're going to change the example skin.
- cd into the resources directory and bring up the skin.xml in an editor.
- We're going to add a label above the view. Change the following xml:
<idv.view place="Center" class="${view_class}"/>
To:
<panel layout="border" place="Center">
<label text="Example Skin" fontsize="24" place="North"/>
<idv.view place="Center" class="${view_class}"/>
</panel>
- Test this real quickly with the XmlUi:
java ucar.unidata.ui.XmlUi skin.xml
- If it is correct then run the example idv:
java ucar.unidata.apps.example.ExampleIdv
- Note that this skin is not the default.
- Go up a level to the example directory.
- Edit the idv.rbi file and add the property line to the skin entry:
<property name="default" value="true"/>
e.g.:
<resource
location="/ucar/unidata/apps/example/resources/skin.xml"
label="Example>Example UI">
<property name="view_class" value="ucar.unidata.idv.MapViewManager"/>
<property name="default" value="true"/>
</resource>
- Save the idv.rbi file and run the ExampleIdv again.
- Note that there are still the system skins available.
- Go back to the example idv.rbi file and add a loadmore="false" to the resources tag:
<resources name="idv.resource.skin" loadmore="false">
- Run the ExampleIdv again. Note that there is only the example skin.
- Now, one more thing. Lets write a little Java code.
- Go to the example skin.rbi and change the label tag you added to
be example.label:
<example.label text="Example Skin" place="North"/>
- Bring up the ExampleUIManager.java in an editor.
- Look for the doMakeIdvXmlUi method. Notice we create our own IdvXmlUi
object. So far it does nothing.
- Lets add some code that can handle this tag. e.g.:
public Component createComponent(Element node, String id) {
String tagName = node.getTagName();
if(tagName.equals("example.label")) {
JLabel label = new JLabel(XmlUtil.getAttribute(node, XmlUi.ATTR_TEXT));
label.setForeground(Color.red);
return label;
}
return super.createComponent(node, id);
}
- Compile and run the ExampleIdv
- Clean up our changes. Remove the loadmore="false" attribute
and the default property from the idv.rbi
- One more thing, let's look at the ExampleUIManager again and see how we can skip this whole
skin thing if needed.
- Look at the method:
public IdvWindow createNewWindow(List viewManagers, boolean notifyCollab,
String title, String skinPath,
Element skinRoot) {...}
- This method is responsible for creating the GUI windows in the IDV.
- Note the code in there that allows us to skip or not skip the skins:
if(!testNewWindow) {
return super.createNewWindow(viewManagers, notifyCollab,title, skinPath, skinRoot);
}
Unidata IDV Workshop for version 3.0u1 > Java Developer Topics > IDV User Interfaces