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

import java.util.Vector;

/**
 * The identification of the area represented by this class is very simple. It just takes a 
 * start line and an end line from server.ini file, and finds all the GofHostFields that are 
 * between these two lines, the specified start- and end line included. 
 * @author J. Bergström
 */
public class GofTitleAreaIdentifier extends GofHostAreaIdentifierAdapter
{
  // ------------------
  // INSTANCE VARIABLES
  // ------------------

  /**
   * The first line that belongs to this area. Defaults to 0 (the screen's first line).
   */
  private int startLine = 0;

  /**
   * The last line that belongs to this area. Defaults to 0 (the screen's first line),
   * which will give a no area at all.
   */
  private int endLine = 0;

  // ----------------
  // INSTANCE METHODS
  // ----------------

  /**
   * The settings for this class are red just after the instance of the class has been started, 
   * during server startup. Below is an example of how these two settings might look in the 
   * server.ini file:
   * <pre>
   *    titlearea_startline=0
   *    titlearea_endline=1
   * </pre>
   * <p>
   * In this example, the area will be made up of the first two lines.
   * @param confFile   The server ini file.
   * @param subsection The section containing the Gui-on-the-fly settings to be used.
   */
  @Override
  public void getAreaSettings( IniFile confFile, String subsection )
  {
    String setting = confFile.getData( subsection, "titlearea_startline" );
    try
    {
      startLine = Integer.valueOf( setting ).intValue( );
    }
    catch( NumberFormatException e )
    {
      startLine = 0;
    }
    setting = confFile.getData( subsection, "titlearea_endline" );
    try
    {
      endLine = Integer.valueOf( setting ).intValue( );
    }
    catch( NumberFormatException e )
    {
      endLine = 0;
    }
  }

  /**
   * A method that identifies which of the Gui-on-the-fly host fields that belong to the area.
   * @param gofHostFields A <code>Vector</code> containing all the screens gof host fields.
   * @param x             The start column of the area to be analyzed.
   * @param y             The start line of the area to be analyzed.
   * @param w             The width of the area to be analyzed.
   * @param h             The height of the area to be analyzed.
   */
  @Override
  public Vector<GofHostField> identifyArea( Vector<GofHostField> gofHostFields, int x, int y, int w, int h )
  {
    Vector<GofHostField> unusedGofHostFields = new Vector<GofHostField>( );

    for( int i = 0, s = gofHostFields.size( ); i < s; i++ )
    {
      GofHostField ghf = gofHostFields.elementAt( i );
      int ghfy = ghf.getY( );
      if( ghfy >= startLine && ghfy <= endLine )
        areaGofHostFields.addElement( ghf );
      else
        unusedGofHostFields.addElement( ghf );
    }

    return unusedGofHostFields;
  }
}