private Paint createFrameGradient(Shape s,int titleHeight,int topToolBarHeight,int bottomToolBarHeight,FourColors defColors){
  Rectangle2D bounds=s.getBounds2D();
  float x=(float)bounds.getX();
  float y=(float)bounds.getY();
  float w=(float)bounds.getWidth();
  float h=(float)bounds.getHeight();
  float midX=x + w / 2.0f;
  float titleBottom=titleHeight / h;
  if (titleBottom >= 1.0f) {
    titleBottom=1.0f - 0.00004f;
  }
  float[] midPoints=null;
  Color[] colors=null;
  if (topToolBarHeight > 0 && bottomToolBarHeight > 0) {
    float topToolBarBottom=(titleHeight + topToolBarHeight) / h;
    if (topToolBarBottom >= 1.0f) {
      topToolBarBottom=1.0f - 0.00002f;
    }
    float bottomToolBarTop=(h - 2 - bottomToolBarHeight) / h;
    if (bottomToolBarTop >= 1.0f) {
      bottomToolBarTop=1.0f - 0.00002f;
    }
    midPoints=new float[]{0.0f,topToolBarBottom,bottomToolBarTop,1.0f};
    colors=new Color[]{defColors.top,defColors.upperMid,defColors.lowerMid,defColors.bottom};
  }
 else   if (topToolBarHeight > 0) {
    float toolBarBottom=(titleHeight + topToolBarHeight) / h;
    if (toolBarBottom >= 1.0f) {
      toolBarBottom=1.0f - 0.00002f;
    }
    midPoints=new float[]{0.0f,toolBarBottom,1.0f};
    colors=new Color[]{defColors.top,defColors.upperMid,defColors.lowerMid};
  }
 else   if (bottomToolBarHeight > 0) {
    float bottomToolBarTop=(h - 2 - bottomToolBarHeight) / h;
    if (bottomToolBarTop >= 1.0f) {
      bottomToolBarTop=1.0f - 0.00002f;
    }
    midPoints=new float[]{0.0f,titleBottom,bottomToolBarTop,1.0f};
    colors=new Color[]{defColors.top,defColors.upperMid,defColors.lowerMid,defColors.bottom};
  }
 else {
    midPoints=new float[]{0.0f,titleBottom,1.0f};
    colors=new Color[]{defColors.top,defColors.upperMid,defColors.bottom};
  }
  return createGradient(midX,y,midX,y + h,midPoints,colors);
}

private Paint createFrameGradient ( Shape s , int titleHeight , int topToolBarHeight , int bottomToolBarHeight , FourColors defColors ) { Rectangle2D bounds = s . getBounds2D ( ) ; float x = ( float ) bounds . getX ( ) ; float y = ( float ) bounds . getY ( ) ; float w = ( float ) bounds . getWidth ( ) ; float h = ( float ) bounds . getHeight ( ) ; float midX = x + w / 2.0f ; float titleBottom = titleHeight / h ; if ( titleBottom >= 1.0f ) { titleBottom = 1.0f - 0.00004f ; } float [ ] midPoints = null ; Color [ ] colors = null ; if ( topToolBarHeight > 0 && bottomToolBarHeight > 0 ) { float topToolBarBottom = ( titleHeight + topToolBarHeight ) / h ; if ( topToolBarBottom >= 1.0f ) { topToolBarBottom = 1.0f - 0.00002f ; } float bottomToolBarTop = ( h - 2 - bottomToolBarHeight ) / h ; if ( bottomToolBarTop >= 1.0f ) { bottomToolBarTop = 1.0f - 0.00002f ; } midPoints = new float [ ] { 0.0f , topToolBarBottom , bottomToolBarTop , 1.0f } ; colors = new Color [ ] { defColors . top , defColors . upperMid , defColors . lowerMid , defColors . bottom } ; } else if ( topToolBarHeight > 0 ) { float toolBarBottom = ( titleHeight + topToolBarHeight ) / h ; if ( toolBarBottom >= 1.0f ) { toolBarBottom = 1.0f - 0.00002f ; } midPoints = new float [ ] { 0.0f , toolBarBottom , 1.0f } ; colors = new Color [ ] { defColors . top , defColors . upperMid , defColors . lowerMid } ; } else if ( bottomToolBarHeight > 0 ) { float bottomToolBarTop = ( h - 2 - bottomToolBarHeight ) / h ; if ( bottomToolBarTop >= 1.0f ) { bottomToolBarTop = 1.0f - 0.00002f ; } midPoints = new float [ ] { 0.0f , titleBottom , bottomToolBarTop , 1.0f } ; colors = new Color [ ] { defColors . top , defColors . upperMid , defColors . lowerMid , defColors . bottom } ; } else { midPoints = new float [ ] { 0.0f , titleBottom , 1.0f } ; colors = new Color [ ] { defColors . top , defColors . upperMid , defColors . bottom } ; } return createGradient ( midX , y , midX , y + h , midPoints , colors ) ; }
create the gradient to paint the frame interior .
