public static void drawVerticalMarginIndicator(Graphics2D g,String text,int x,int y1,int y2){
  if (y1 > y2) {
    int temp=y1;
    y1=y2;
    y2=temp;
  }
  if (text == null) {
    g.drawLine(x,y1,x,y2);
    g.drawLine(x,y1,x - CONNECTION_ARROW_SIZE,y1 + CONNECTION_ARROW_SIZE);
    g.drawLine(x,y1,x + CONNECTION_ARROW_SIZE,y1 + CONNECTION_ARROW_SIZE);
    g.drawLine(x,y2,x - CONNECTION_ARROW_SIZE,y2 - CONNECTION_ARROW_SIZE);
    g.drawLine(x,y2,x + CONNECTION_ARROW_SIZE,y2 - CONNECTION_ARROW_SIZE);
    return;
  }
  Canvas c=new Canvas();
  FontMetrics fm=c.getFontMetrics(sFont);
  g.setFont(sFont);
  int padding=4;
  Rectangle2D bounds=fm.getStringBounds(text,g);
  int th=(int)bounds.getHeight();
  int offset=3 * CONNECTION_ARROW_SIZE;
  int h=((y2 - y1) - (th + 2 * padding)) / 2;
  if (h <= padding) {
    g.drawLine(x,y1,x,y2);
    g.drawString(text,(int)(x - bounds.getWidth() / 2) + offset,y2 - h - padding);
    g.drawLine(x - CONNECTION_ARROW_SIZE,y1,x + CONNECTION_ARROW_SIZE,y1);
    g.drawLine(x - CONNECTION_ARROW_SIZE,y2,x + CONNECTION_ARROW_SIZE,y2);
  }
 else {
    g.drawLine(x,y1,x,y1 + h);
    g.drawLine(x,y2 - h,x,y2);
    g.drawString(text,(int)(x - bounds.getWidth() / 2),y2 - h - padding);
    g.drawLine(x,y1,x - CONNECTION_ARROW_SIZE,y1 + CONNECTION_ARROW_SIZE);
    g.drawLine(x,y1,x + CONNECTION_ARROW_SIZE,y1 + CONNECTION_ARROW_SIZE);
    g.drawLine(x,y2,x - CONNECTION_ARROW_SIZE,y2 - CONNECTION_ARROW_SIZE);
    g.drawLine(x,y2,x + CONNECTION_ARROW_SIZE,y2 - CONNECTION_ARROW_SIZE);
  }
}

public static void drawVerticalMarginIndicator ( Graphics2D g , String text , int x , int y1 , int y2 ) { if ( y1 > y2 ) { int temp = y1 ; y1 = y2 ; y2 = temp ; } if ( text == null ) { g . drawLine ( x , y1 , x , y2 ) ; g . drawLine ( x , y1 , x - CONNECTION_ARROW_SIZE , y1 + CONNECTION_ARROW_SIZE ) ; g . drawLine ( x , y1 , x + CONNECTION_ARROW_SIZE , y1 + CONNECTION_ARROW_SIZE ) ; g . drawLine ( x , y2 , x - CONNECTION_ARROW_SIZE , y2 - CONNECTION_ARROW_SIZE ) ; g . drawLine ( x , y2 , x + CONNECTION_ARROW_SIZE , y2 - CONNECTION_ARROW_SIZE ) ; return ; } Canvas c = new Canvas ( ) ; FontMetrics fm = c . getFontMetrics ( sFont ) ; g . setFont ( sFont ) ; int padding = 4 ; Rectangle2D bounds = fm . getStringBounds ( text , g ) ; int th = ( int ) bounds . getHeight ( ) ; int offset = 3 * CONNECTION_ARROW_SIZE ; int h = ( ( y2 - y1 ) - ( th + 2 * padding ) ) / 2 ; if ( h <= padding ) { g . drawLine ( x , y1 , x , y2 ) ; g . drawString ( text , ( int ) ( x - bounds . getWidth ( ) / 2 ) + offset , y2 - h - padding ) ; g . drawLine ( x - CONNECTION_ARROW_SIZE , y1 , x + CONNECTION_ARROW_SIZE , y1 ) ; g . drawLine ( x - CONNECTION_ARROW_SIZE , y2 , x + CONNECTION_ARROW_SIZE , y2 ) ; } else { g . drawLine ( x , y1 , x , y1 + h ) ; g . drawLine ( x , y2 - h , x , y2 ) ; g . drawString ( text , ( int ) ( x - bounds . getWidth ( ) / 2 ) , y2 - h - padding ) ; g . drawLine ( x , y1 , x - CONNECTION_ARROW_SIZE , y1 + CONNECTION_ARROW_SIZE ) ; g . drawLine ( x , y1 , x + CONNECTION_ARROW_SIZE , y1 + CONNECTION_ARROW_SIZE ) ; g . drawLine ( x , y2 , x - CONNECTION_ARROW_SIZE , y2 - CONNECTION_ARROW_SIZE ) ; g . drawLine ( x , y2 , x + CONNECTION_ARROW_SIZE , y2 - CONNECTION_ARROW_SIZE ) ; } }
utility function to draw a vertical margin indicator
