static int calcSize(int origDim,String requestedDim,int defaultDim,boolean negativeAllowed){
  if (requestedDim == null) {
    return defaultDim;
  }
  boolean percent=false;
  if (requestedDim.endsWith("%")) {
    percent=true;
    requestedDim=requestedDim.substring(0,requestedDim.length() - 1);
  }
 else   if (requestedDim.endsWith("px")) {
    requestedDim=requestedDim.substring(0,requestedDim.length() - 2);
  }
  int dim=0;
  try {
    dim=Integer.parseInt(requestedDim);
  }
 catch (  Exception e) {
    return origDim;
  }
  if ((dim < 0) && (!negativeAllowed)) {
    return origDim;
  }
  if (percent) {
    return origDim * dim / 100;
  }
 else {
    return dim;
  }
}

static int calcSize ( int origDim , String requestedDim , int defaultDim , boolean negativeAllowed ) { if ( requestedDim == null ) { return defaultDim ; } boolean percent = false ; if ( requestedDim . endsWith ( "%" ) ) { percent = true ; requestedDim = requestedDim . substring ( 0 , requestedDim . length ( ) - 1 ) ; } else if ( requestedDim . endsWith ( "px" ) ) { requestedDim = requestedDim . substring ( 0 , requestedDim . length ( ) - 2 ) ; } int dim = 0 ; try { dim = Integer . parseInt ( requestedDim ) ; } catch ( Exception e ) { return origDim ; } if ( ( dim < 0 ) && ( ! negativeAllowed ) ) { return origDim ; } if ( percent ) { return origDim * dim / 100 ; } else { return dim ; } }
calculates width or height of an element according to its original size , requested size and default size
