Unidata IDV Workshop for version 6.3 > Java Developer Topics > Display Controls
5.6.2 Creating a Weather Text Display Control
Let's create a custom DisplayControl for our weather text that will
use the category "wxtext" that we created in the Data Source.
- Change to the example directory.
cd /home/idv/idv/ucar/unidata/apps/example
- Open WxTextDisplayControl.java in an editor and let's look what's there.
- Copy
controls.xml
up from the resources subdirectory and
take a look at that.
- Compile the display control.
- Start the IDV.
- Select a product from the
Weather Text
chooser
and click the Add Source
button.
- Display the data in the
Weather Text
display.
Now let's add in a widget that will highlight some text.
- Exit the IDV.
- Open WxTextDisplayControl.java in an editor.
- Uncomment:
- the section in
doMakeContents
for the JTextField
that allows user input.
- the line in the default constructor to use the
FLAG_COLOR
attribute.
- the
getColorWidgetLabel()
method
- Start the IDV and load in some weather text.
- Type in some text to hightlight and hit enter. Does it get highlighted?
- Notice that we have a new item in the Edit menu which allows us to
change the highlight color. Change it. Does anything happen? Hit
return in the TextField. Does it change then?
- Exit the IDV.
- Open WxTextDisplayControl.java in an editor.
- Uncomment the applyColor method. This is called when the color
changes.
- Compile and restart the IDV and load in some weather text.
- Type in some text to highlight and hit enter. Change the color.
Does it change now?
- Save this as your default bundle and then reload it. Notice that the
text is not hightlighted this time. We need to add some bean property
methods to save the selected text. Add the following methods:
/**
* Get the highlighted text
*
* @return the highlighted text
*/
public String getHighlightedText() {
return highlightedText;
}
/**
* Set the text to hightlight
*
* @param text the text to hightlight
*/
public void setHighlightedText(String text) {
highlightedText = text;
}
- Since we use the FLAG_COLOR attribute any color changes we make
get saved automatically.
Now, let's add in a point that shows where the station is. Remember,
we passed along the station as a property to the data source. We can
add those properties to the DataChoice by passing them along when we
create the DirectDataChoice.
- Edit the WxTextDataSource and where we create the DirectDataChoice, change:
DataChoice.NULL_PROPERTIES); //no properties
to:
getProperties());
- Now, let's uncomment the section of code in the
WxTextDisplayControl.init
that adds in
a displayable to the default ViewManager.
- Compile the files.
- Start the ExampleIdv and remove the default bundle:
idve -cleardefault
- Load in some weather text.
- Change the color. What happens to the selector point?
Unidata IDV Workshop for version 6.3 > Java Developer Topics > Display Controls