Listing of Source ../source/GOF/GofAS400HostFieldIdentifier.java
package se.entra.phantom.server;

import java.util.Vector;

/**
 * This class takes all the host fields and creates GofHostFields from them. When creating the 
 * GofHostFields, it will not take into account if the area to identify is smaller than the 
 * actual screen, or if there is a popup window on the screen. These limitations will be taken 
 * into account when fetching the GofHostFields with one of the two methods for fetching.
 * @author J. Bergström
 */
public class GofAS400HostFieldIdentifier extends GofHostFieldIdentifierAdapter
{
  // ----------------
  // INSTANCE METHODS
  // ----------------

  /**
   * This method must create the GofHostFields from the HostScreen's HostFields. It is up this 
   * method to decide if a HostField should be split up to several GofHostFields. The newly 
   * created GofHostFields must be stored internally in the class, since the method GetHostFields 
   * must be able to return them.
   * @param screen The host screen to process.
   */
  @Override
  public void identifyHostFields( HostScreen screen )
  {
    gofHostFields = new Vector<GofHostField>( );

    int w = screen.getWidth( );
    int h = screen.getHeight( );

    int hfX, hfY, restLen;
    String hfText;
    for( HostField hf = screen.getFirstFieldAbsolute( 0 ); hf != null; hf = hf.getNextField( ) )
    {
      hfX = hf.x;
      hfY = hf.y;
      restLen = hf.length;
      hfText = screen.getStringAbsolute( hfX, hfY, restLen );
      while( restLen > 0 )
      {
        int startpos = hf.length - restLen;
        int hfCx = restLen;
        if( hfX + restLen > w )
          hfCx = w - hfX;
        restLen = restLen - hfCx;

        GofHostField gofHostField = new GofHostField( hf, 
                                                      hfX, 
                                                      hfY, 
                                                      hfCx, 
                                                      hfText.substring( startpos, startpos + hfCx ), 
                                                      hf.isEmpty( screen ) );
        gofHostFields.addElement( gofHostField );

        if( restLen > 0 )
        {
          hfX = 0;
          // Must be the host screen height (e.g. 80x24), not screen height (e.g. 80x25).
          // Fix this later!
          hfY = ( hfY + 1 ) % h;
        }
      }
    }
  }
}