question: public static void drawSnapHorizontalMargin ( ViewTransform transform , Graphics2D g , int x1 , int x2 , int y1 , String text , boolean textOver ) { Canvas c = new Canvas ( ) ; FontMetrics fm = c . getFontMetrics ( sFont ) ; g . setFont ( sFont ) ; int padding = transform . getSwingDimension ( 4 ) ; Rectangle2D bounds = fm . getStringBounds ( text , g ) ; int tw = ( int ) bounds . getWidth ( ) ; int offset = 6 * CONNECTION_ARROW_SIZE ; if ( x1 > x2 ) { int temp = x1 ; x1 = x2 ; x2 = temp ; } int w = ( ( x2 - x1 ) - ( tw + 2 * padding ) ) / 2 ; if ( w <= padding ) { g . drawLine ( x1 , y1 , x2 , y1 ) ; if ( textOver ) { offset = - 1 * offset / 2 ; } g . drawString ( text , x1 + w + padding , y1 + offset ) ; } else { g . drawLine ( x1 , y1 , x1 + w , y1 ) ; g . drawLine ( x2 - w , y1 , x2 , y1 ) ; g . drawString ( text , x1 + w + padding , ( int ) ( y1 + ( bounds . getHeight ( ) / 2 ) ) ) ; } g . drawLine ( x1 , y1 - CONNECTION_ARROW_SIZE , x1 , y1 + CONNECTION_ARROW_SIZE ) ; g . drawLine ( x2 , y1 - CONNECTION_ARROW_SIZE , x2 , y1 + CONNECTION_ARROW_SIZE ) ; }
target:  Draw a snap horizontal margin indicator