FilePage Event Example for Visual J++

This example shows how the FilePage event can be used to size and position a lead control when an image is loaded.

private void LEAD1_filePage(Object source, Event e)
{
   // Set the variables used for preserving the aspect ratio.
   // Allow for a border of 1/8 of the form size.
   // The units of measure do not matter, since we are calculating proportions.
   int nHeightFactor = (int) LEAD1.getInfoHeight();
   int nWidthFactor  = (int) LEAD1.getInfoWidth();
   int nHeightAllowed = getSize().y * 3 / 4;
   int nWidthAllowed  = getSize().x * 3 / 4;

   // Center the LEAD control on the form, preserving the aspect ratio.
   // Check to see if using the maximum width will make the image too tall.
   // Set the dimensions based on the result.
   Rectangle rectLead = new Rectangle();
   if( ( ( nWidthAllowed * nHeightFactor ) / nWidthFactor ) < nHeightAllowed )
   {
      rectLead.x      = getSize().x / 8;
      rectLead.width  = nWidthAllowed;
      rectLead.height = ( rectLead.width * nHeightFactor ) / nWidthFactor;
      rectLead.y      = ( getSize().y - rectLead.height ) / 2;
   }
   else
   {
      rectLead.y      = getSize().y / 8;
      rectLead.height = nHeightAllowed;
      rectLead.width  = ( rectLead.height * nWidthFactor) / nHeightFactor;
      rectLead.x      = ( getSize().x - rectLead.width ) / 2;
   }

   LEAD1.setLocation( rectLead.x, rectLead.y );
   LEAD1.setSize( rectLead.width, rectLead.height );

   // Set the image display size to match the LEAD control.
   LEAD1.setAutoScroll( false );
   LEAD1.setAutoSetRects( true );
   LEAD1.setAutoRepaint( true );
   LEAD1.setPaintSizeMode( (short) LTOCXU.PaintSizeModeConstants.PAINTSIZEMODE_FIT );
}