private synchronized void initMedia(){
  if (initialized) {
    return;
  }
 else {
    initialized=true;
  }
  if (pageSizes == null) {
    return;
  }
  cupsMediaPrintables=new MediaPrintableArea[nPageSizes];
  cupsMediaSNames=new MediaSizeName[nPageSizes];
  cupsCustomMediaSNames=new CustomMediaSizeName[nPageSizes];
  CustomMediaSizeName msn;
  MediaPrintableArea mpa;
  float length, width, x, y, w, h;
  for (int i=0; i < nPageSizes; i++) {
    width=(float)(pageSizes[i * 6] / PRINTER_DPI);
    length=(float)(pageSizes[i * 6 + 1] / PRINTER_DPI);
    x=(float)(pageSizes[i * 6 + 2] / PRINTER_DPI);
    h=(float)(pageSizes[i * 6 + 3] / PRINTER_DPI);
    w=(float)(pageSizes[i * 6 + 4] / PRINTER_DPI);
    y=(float)(pageSizes[i * 6 + 5] / PRINTER_DPI);
    msn=new CustomMediaSizeName(media[i * 2],media[i * 2 + 1],width,length);
    if ((cupsMediaSNames[i]=msn.getStandardMedia()) == null) {
      cupsMediaSNames[i]=msn;
      if ((width > 0.0) && (length > 0.0)) {
        try {
          new MediaSize(width,length,Size2DSyntax.INCH,msn);
        }
 catch (        IllegalArgumentException e) {
          new MediaSize(length,width,Size2DSyntax.INCH,msn);
        }
      }
    }
    cupsCustomMediaSNames[i]=msn;
    mpa=null;
    try {
      mpa=new MediaPrintableArea(x,y,w,h,MediaPrintableArea.INCH);
    }
 catch (    IllegalArgumentException e) {
      if (width > 0 && length > 0) {
        mpa=new MediaPrintableArea(0,0,width,length,MediaPrintableArea.INCH);
      }
    }
    cupsMediaPrintables[i]=mpa;
  }
  cupsMediaTrays=new MediaTray[nTrays];
  MediaTray mt;
  for (int i=0; i < nTrays; i++) {
    mt=new CustomMediaTray(media[(nPageSizes + i) * 2],media[(nPageSizes + i) * 2 + 1]);
    cupsMediaTrays[i]=mt;
  }
}

private synchronized void initMedia ( ) { if ( initialized ) { return ; } else { initialized = true ; } if ( pageSizes == null ) { return ; } cupsMediaPrintables = new MediaPrintableArea [ nPageSizes ] ; cupsMediaSNames = new MediaSizeName [ nPageSizes ] ; cupsCustomMediaSNames = new CustomMediaSizeName [ nPageSizes ] ; CustomMediaSizeName msn ; MediaPrintableArea mpa ; float length , width , x , y , w , h ; for ( int i = 0 ; i < nPageSizes ; i ++ ) { width = ( float ) ( pageSizes [ i * 6 ] / PRINTER_DPI ) ; length = ( float ) ( pageSizes [ i * 6 + 1 ] / PRINTER_DPI ) ; x = ( float ) ( pageSizes [ i * 6 + 2 ] / PRINTER_DPI ) ; h = ( float ) ( pageSizes [ i * 6 + 3 ] / PRINTER_DPI ) ; w = ( float ) ( pageSizes [ i * 6 + 4 ] / PRINTER_DPI ) ; y = ( float ) ( pageSizes [ i * 6 + 5 ] / PRINTER_DPI ) ; msn = new CustomMediaSizeName ( media [ i * 2 ] , media [ i * 2 + 1 ] , width , length ) ; if ( ( cupsMediaSNames [ i ] = msn . getStandardMedia ( ) ) == null ) { cupsMediaSNames [ i ] = msn ; if ( ( width > 0.0 ) && ( length > 0.0 ) ) { try { new MediaSize ( width , length , Size2DSyntax . INCH , msn ) ; } catch ( IllegalArgumentException e ) { new MediaSize ( length , width , Size2DSyntax . INCH , msn ) ; } } } cupsCustomMediaSNames [ i ] = msn ; mpa = null ; try { mpa = new MediaPrintableArea ( x , y , w , h , MediaPrintableArea . INCH ) ; } catch ( IllegalArgumentException e ) { if ( width > 0 && length > 0 ) { mpa = new MediaPrintableArea ( 0 , 0 , width , length , MediaPrintableArea . INCH ) ; } } cupsMediaPrintables [ i ] = mpa ; } cupsMediaTrays = new MediaTray [ nTrays ] ; MediaTray mt ; for ( int i = 0 ; i < nTrays ; i ++ ) { mt = new CustomMediaTray ( media [ ( nPageSizes + i ) * 2 ] , media [ ( nPageSizes + i ) * 2 + 1 ] ) ; cupsMediaTrays [ i ] = mt ; } }
initialize media by translating ppd info to printservice attributes .
