question: public static void drawHorizontalMarginIndicator ( Graphics2D g , String text , int x1 , int x2 , int y ) { if ( x1 > x2 ) { int temp = x1 ; x1 = x2 ; x2 = temp ; } if ( text == null ) { g . drawLine ( x1 , y , x2 , y ) ; g . drawLine ( x1 , y , x1 + CONNECTION_ARROW_SIZE , y - CONNECTION_ARROW_SIZE ) ; g . drawLine ( x1 , y , x1 + CONNECTION_ARROW_SIZE , y + CONNECTION_ARROW_SIZE ) ; g . drawLine ( x2 , y , x2 - CONNECTION_ARROW_SIZE , y - CONNECTION_ARROW_SIZE ) ; g . drawLine ( x2 , y , x2 - CONNECTION_ARROW_SIZE , y + 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 tw = ( int ) bounds . getWidth ( ) ; int offset = 3 * CONNECTION_ARROW_SIZE ; int w = ( ( x2 - x1 ) - ( tw + 2 * padding ) ) / 2 ; if ( w <= padding ) { g . drawLine ( x1 , y , x2 , y ) ; g . drawString ( text , x1 + w + padding , y + offset ) ; g . drawLine ( x1 , y - CONNECTION_ARROW_SIZE , x1 , y + CONNECTION_ARROW_SIZE ) ; g . drawLine ( x2 , y - CONNECTION_ARROW_SIZE , x2 , y + CONNECTION_ARROW_SIZE ) ; } else { g . drawLine ( x1 , y , x1 + w , y ) ; g . drawLine ( x2 - w , y , x2 , y ) ; g . drawString ( text , x1 + w + padding , ( int ) ( y + ( bounds . getHeight ( ) / 2 ) ) ) ; g . drawLine ( x1 , y , x1 + CONNECTION_ARROW_SIZE , y - CONNECTION_ARROW_SIZE ) ; g . drawLine ( x1 , y , x1 + CONNECTION_ARROW_SIZE , y + CONNECTION_ARROW_SIZE ) ; g . drawLine ( x2 , y , x2 - CONNECTION_ARROW_SIZE , y - CONNECTION_ARROW_SIZE ) ; g . drawLine ( x2 , y , x2 - CONNECTION_ARROW_SIZE , y + CONNECTION_ARROW_SIZE ) ; } }
target:  Utility function to draw an horizontal margin indicator