Solutions to JDNC Exercises

Solutions for Exercise 1: Column Alignment and Colors

1A: Icon and text alignment.
The alignment of text and icon is specified in the enumeration block on a value-by-value basis:

    <enumeration value="Canada" title="Canada" icon="images/flags/canada.gif" horizontalAlignment="leading" horizontalTextPosition="trailing"/>

1B: Changing the header background color to blue.

One possible solution is:
    <header background="cyan"/>

1C: Changing the background colors of the data rows to yellow and orange.

You can use hexidecimal:
    <highlighters>
        <alternateRowHighlighter oddRowBackground="#FFFF00" 
	                         evenRowBackground="#FF9900"/>
    </highlighters>
or the SVG color name:
    <highlighters>
        <alternateRowHighlighter oddRowBackground="yellow" 
	                         evenRowBackground="orange"/> 
    </highlighters>

Solution for Exercise 2: Pattern Matching

2A: Changing the text color to red for countries that begin with B or M.

Add a patternHighlighter on the country column:
    <highlighters>
        <alternateRowHighlighter oddRowBackground="#EEEEFF"
	                         evenRowBackground="#CCCCFF"/>
        <patternHighlighter expression="[B,M].*" testColumn="COUNTRY" 
               foreground="red"/>
    </highlighters>

2B: Changing the text color to blue for Canadian rows.

Add a patternHighlighter on the country column:
    <highlighters>
        <alternateRowHighlighter oddRowBackground="#EEEEFF"
	                         evenRowBackground="#CCCCFF"/>
        <patternHighlighter expression="Canada" testColumn="COUNTRY" 
               foreground="blue"/>
    </highlighters>

Solutions for Exercise 3: Sorting

3A: Sorting on the temperature column:
    <filters>
       <sorter testColumn="TEMPERATURE"/>
    </filters>

3B: Sorting in descending order:

    <filters>
       <sorter testColumn="TEMPERATURE" direction="descending"/>
    </filters>

3C: Adding a secondary sort on latitude:

    <filters>
        <sorter testColumn="TEMPERATURE"/>
	<sorter testColumn="LATITUDE"/>
    </filters>
The order of the sorter tags determines sorting precedence, with the first tag specifying the primary criteria. The latitude column must be added to the view, inside the columns block:
    <columns>
        ...
        <column title="Latitude" binding="LATITUDE" 
	    horizontalAlignment="center"/>
        ...
    </columns>

Solutions for Exercise 4: Data Filtering

4A: Display only samples from 'A' to 'Z' countries:
  <filters>
    <patternFilter expression="['A'-'J'].*" match="caseInsensitive unicodeCase"
                   testColumn="COUNTRY"/>
  </filters>
4B: Filter out samples not from Airport stations:
Searching on the "Air" substring will also find all Airparks, Airfields and Air Stations:
  <filters>
    <patternFilter expression=".*Air.*" match="caseInsensitive unicodeCase"
                   testColumn="STATION"/>
  </filters>

Solutions for Exercise 5: Searching

5A: Search on Station column:
  <filters>
    <patternFilter xml:id="stationFilter" testColumn="STATION"/>
  </filters>
  <toolBar>
    <searchPanel patternFilter="#stationFilter"/>
  </toolBar>

Solutions for Exercise 8: Configuring Actions

8A: Adding Find to the Menus:
The smallIcon attribute is added to the "find" action:
    <action xml:id="find" name="Find" mnemonic="F"
            smallIcon="/toolbarButtonGraphics/general/Find16.gif"
            icon="/toolbarButtonGraphics/general/Find24.gif"
	    accelerator="control F" description="Find an item"/>
The Find menu item is added to the Edit submenu:
    <menuBar>
      <menu action="#file-menu">
        ...
      </menu>
      <menu name="Edit" mnemonic="E" description="Edit Commands">
	<action actionRef="#cut-to-clipboard"/>
	<action actionRef="#copy-to-clipboard"/>
	<action actionRef="#paste-from-clipboard"/>
        <separator/>
        <action actionRef="#find"/>
      </menu>
      <menu name="Format" mnemonic="O" description="Text Formatting Commands">
        <i>...</i>
      </menu>	
    </menuBar>
And also to the popup menu:
      <popupMenu>
        <action actionRef="#cut-to-clipboard"/>
        <action actionRef="#copy-to-clipboard"/>
        <action actionRef="#paste-from-clipboard"/>
        <separator/>
        <action actionRef="#find"/>
        <separator/>
        <action actionRef="#font-bold"/>
        <action actionRef="#font-italic"/>
        <action actionRef="#font-underline"/>
        <separator/>
        <group xml:id="align">
          <action actionRef="#left-justify"/>
          <action actionRef="#center-justify"/>
          <action actionRef="#right-justify"/>
        </group>
      </popupMenu>
8B: Adding New and Open to the Menus:
Originally, the new and open actions were specified in the File menu block. They must be moved to the defs block in order to be reused. A 24x24 tool bar icon is also added to the action tag:
  <om:defs>
    <!-- Custom actions -->
    <action xml:id="new-command" title="New" mnemonic="N" accelerator="control N"
	    smallIcon="/toolbarButtonGraphics/general/New16.gif"
	    icon="/toolbarButtonGraphics/general/New24.gif"
            description="Create a new document"/>
    <action xml:id="open-command" title="Open" mnemonic="O" accelerator="control O"
            smallIcon="/toolbarButtonGraphics/general/Open16.gif"
	    icon="/toolbarButtonGraphics/general/Open24.gif"
            description="Open an existing document"/>
    ...
  </om:defs>
The File menu declaration is simplified:
  <menu action="#file-menu">
    <action actionRef="#new-command"/>
    <action actionRef="#open-command"/>
  </menu>
The New and Open actions are added to the tool bar:
    <toolBar>
      <action actionRef="#new-command"/>
      <action actionRef="#open-command"/>
      <separator/>
      ...
    </toolBar>
The New and Open actions are also added to the popup menu:
  <popupMenu>
    <action actionRef="#new-command"/>
    <action actionRef="#open-command"/>
    <separator/>
    ...
  </popupMenu>
8C: Adding a Refresh Action:
A Refresh action is added to the defs block. The icons are specified from the Java Look and Feel Graphics Repository:
  <om:defs>
    ...
    <action xml:id="refresh" title="Refresh" 
            smallIcon="/toolbarButtonGraphics/general/Refresh16.gif"
	    icon="/toolbarButtonGraphics/general/Refresh24.gif"/>
    ...
  </om:defs>
Add the action to the menu, popup menu and tool bar. All declarations will be the same:
    <action actionRef="#refresh"/>