Xoetrope
View

Advanced Tutorial - More on Framesets - Create a new frame
SUMMARY  This step will take a look at how you can manipulate the declared framesets for a XUI project. This is particularly useful where you wish to show progress information

FURTHER READING  Review the 'introductory' tutorial for how to declare framesets.

In this step we will create a frame which will appear or disappear depending on where we are in the application. We can start by editing the frameset file

Listing 1 - frames.xml
<FrameSet>
    <Frame name="banner" constraint="NORTH" content="banner" 
	width="640" height="96"/>
    <Frame name="appstatus" constraint="WEST" content="appstatus" 
	width="150" height="500" />
    <Frame name="content" constraint="CENTER" content="welcome" 
	width="490" height="288" /> 
    <Frame name="navPanel" constraint="SOUTH" content="navPanel" 
	width="640" height="96"/>
</FrameSet>

The new frame will be loaded to the left of the content frame between the banner and navPanel frames.

The appstatus page should now be defined as follows..

Listing 2 - appstatus.xml
<XPage class="net.xoetrope.mortgage.AppStatus" style="Heading" resource="">
    <Components>
        <Label x="149" y="0" w="1" h="500" style="banner" opaque="true"/>
    </Components>
</XPage>

The single component simply draws a line to the extreme right of the frame, creating a boundry. Now the AppStatus class can be created...

Listing 3 - AppStatus.java
public class AppStatus extends XPage implements NavigationListener {

  public void navigate( int page )
  {
    final int width = page == 0 ? 0 : 100;
    Container c = getParent();
    c.setVisible( width == 0 ? false : true );
    c.getParent().doLayout();
    SwingUtilities.invokeLater( new Runnable() 
    {
      public void run() 
      {
        XPage currentPage = ( XPage )pageMgr.getCurrentPage( "content" );
        currentPage.getParent().doLayout();
      }
    } );
  }

  public void setApplicant( int applicant )
  {
  
  }
    
}

The navigate function is passed the index of the current page and if page is zero the frame is made invisible. If it is anything other than zero it is made visible again. The setApplicant function passes the value of the current customer. The AppStatus page implements a new interface called NavigatorListener which follows...

Listing 4 - NavigationListener.java
package net.xoetrope.mortgage.navigate;

public interface NavigationListener {
  public void navigate( int page );
  public void setApplicant( int applicant );
}

The NavigationListener interface declares a single function, navigate which is called when the Navigator moves to a new page so the Navigator class needs to be amended as follows...

Listing 5 - Navigator.java

private NavigationListener navListener;

  private Navigator() {
    XProject project = XProjectManager.getCurrentProject();
    rb = project.getResourceBundle( project.getStartupParam( "Language" ) );
    pageMgr = XProjectManager.getPageManager();
    //navPage = ( XPage )( ( XTarget ) 
	pageMgr.getTarget( "navPanel" ) ).getComponent( 0 );
    rootModel = ( XBaseModel ) XProjectManager.getModel();
    navMdl = ( XBaseModel ) rootModel.get( "navigation" );
  }

  public void setNavPage( XPage page )
  {
    navPage = page;
  }
  
  public void setNavigationListener( NavigationListener listener )
  {
    navListener = listener;
  }

  private void setPage( String pageName )
  {
    XPage newPage = ( XPage )pageMgr.showPage( pageName, "content" );
    newPage.setExceptionHandler( new ExceptionHandler( newPage ) );
    setCurrentTitle( newPage );
    if ( navListener != null )
      navListener.navigate( currentMdl );
  }
  
  private void setCustomer( int increment )
  {
    customer += increment;
    if ( navListener != null )
      navListener.setApplicant( customer );
  }

  
  public void reset()
  {
    currentMdl = 0;
    customer = 0;
    numCustomers = 0;
    if ( navListener != null )
      navListener.navigate( 0 );
  }

The navPage variable is passed to the instance instead of looking it up in the constructor. The reset function needs to be called when the application returns to the welcome page after an appication has been processed.

The navPanel page needs to use an XPage class as follows...

Listing 6 - navpanel.xml
  <XPage style="Heading" class="net.xoetrope.mortgage.NavPanel">
    ...

Listing 7 - NavPanel.java
public class NavPanel extends XPage {
  
  public void pageCreated()
  {
    XPage appStatus = ( XPage )pageMgr.getPage( "appstatus" );
    Navigator navigator = Navigator.getInstance();
    navigator.setNavigationListener( ( NavigationListener ) appStatus );
    navigator.setNavPage( this );
    ( ( NavigationListener ) appStatus ).navigate( 0 );
  }
  
}

This code sets the NavigationListener interface in the Navigator Singleton instance. It also sets the NavPanel class as the navPage in the Navigator instance.

Run the application and the welcome page will appear as usual. Click the next button and the personal page will appear with the appstatus page to it's left as in the screenshot below.

Log in or register to download the source code for this step.