public static CC parseComponentConstraint ( String s ) { CC cc = new CC ( ) ; if ( s . length ( ) == 0 ) { return cc ; } String [ ] parts = toTrimmedTokens ( s , ',' ) ; for ( String part : parts ) { try { if ( part . length ( ) == 0 ) { continue ; } int ix = - 1 ; char c = part . charAt ( 0 ) ; if ( c == 'n' ) { if ( part . equals ( "north" ) ) { cc . setDockSide ( 0 ) ; continue ; } if ( part . equals ( "newline" ) ) { cc . setNewline ( true ) ; continue ; } if ( part . startsWith ( "newline " ) ) { String gapSz = part . substring ( 7 ) . trim ( ) ; cc . setNewlineGapSize ( parseBoundSize ( gapSz , true , true ) ) ; continue ; } } if ( c == 'f' && ( part . equals ( "flowy" ) || part . equals ( "flowx" ) ) ) { cc . setFlowX ( part . charAt ( 4 ) == 'x' ? Boolean . TRUE : Boolean . FALSE ) ; continue ; } if ( c == 's' ) { ix = startsWithLenient ( part , "skip" , 4 , true ) ; if ( ix > - 1 ) { String num = part . substring ( ix ) . trim ( ) ; cc . setSkip ( num . length ( ) != 0 ? Integer . parseInt ( num ) : 1 ) ; continue ; } ix = startsWithLenient ( part , "split" , 5 , true ) ; if ( ix > - 1 ) { String split = part . substring ( ix ) . trim ( ) ; cc . setSplit ( split . length ( ) > 0 ? Integer . parseInt ( split ) : LayoutUtil . INF ) ; continue ; } if ( part . equals ( "south" ) ) { cc . setDockSide ( 2 ) ; continue ; } ix = startsWithLenient ( part , new String [ ] { "spany" , "sy" } , new int [ ] { 5 , 2 } , true ) ; if ( ix > - 1 ) { cc . setSpanY ( parseSpan ( part . substring ( ix ) . trim ( ) ) ) ; continue ; } ix = startsWithLenient ( part , new String [ ] { "spanx" , "sx" } , new int [ ] { 5 , 2 } , true ) ; if ( ix > - 1 ) { cc . setSpanX ( parseSpan ( part . substring ( ix ) . trim ( ) ) ) ; continue ; } ix = startsWithLenient ( part , "span" , 4 , true ) ; if ( ix > - 1 ) { String [ ] spans = toTrimmedTokens ( part . substring ( ix ) . trim ( ) , ' ' ) ; cc . setSpanX ( spans [ 0 ] . length ( ) > 0 ? Integer . parseInt ( spans [ 0 ] ) : LayoutUtil . INF ) ; cc . setSpanY ( spans . length > 1 ? Integer . parseInt ( spans [ 1 ] ) : 1 ) ; continue ; } ix = startsWithLenient ( part , "shrinkx" , 7 , true ) ; if ( ix > - 1 ) { cc . getHorizontal ( ) . setShrink ( parseFloat ( part . substring ( ix ) . trim ( ) , ResizeConstraint . WEIGHT_100 ) ) ; continue ; } ix = startsWithLenient ( part , "shrinky" , 7 , true ) ; if ( ix > - 1 ) { cc . getVertical ( ) . setShrink ( parseFloat ( part . substring ( ix ) . trim ( ) , ResizeConstraint . WEIGHT_100 ) ) ; continue ; } ix = startsWithLenient ( part , "shrink" , 6 , false ) ; if ( ix > - 1 ) { String [ ] shrinks = toTrimmedTokens ( part . substring ( ix ) . trim ( ) , ' ' ) ; cc . getHorizontal ( ) . setShrink ( parseFloat ( part . substring ( ix ) . trim ( ) , ResizeConstraint . WEIGHT_100 ) ) ; if ( shrinks . length > 1 ) { cc . getVertical ( ) . setShrink ( parseFloat ( part . substring ( ix ) . trim ( ) , ResizeConstraint . WEIGHT_100 ) ) ; } continue ; } ix = startsWithLenient ( part , new String [ ] { "shrinkprio" , "shp" } , new int [ ] { 10 , 3 } , true ) ; if ( ix > - 1 ) { String sp = part . substring ( ix ) . trim ( ) ; if ( sp . startsWith ( "x" ) || sp . startsWith ( "y" ) ) { ( sp . startsWith ( "x" ) ? cc . getHorizontal ( ) : cc . getVertical ( ) ) . setShrinkPriority ( Integer . parseInt ( sp . substring ( 2 ) ) ) ; } else { String [ ] shrinks = toTrimmedTokens ( sp , ' ' ) ; cc . getHorizontal ( ) . setShrinkPriority ( Integer . parseInt ( shrinks [ 0 ] ) ) ; if ( shrinks . length > 1 ) { cc . getVertical ( ) . setShrinkPriority ( Integer . parseInt ( shrinks [ 1 ] ) ) ; } } continue ; } ix = startsWithLenient ( part , new String [ ] { "sizegroupx" , "sizegroupy" , "sgx" , "sgy" } , new int [ ] { 9 , 9 , 2 , 2 } , true ) ; if ( ix > - 1 ) { String sg = part . substring ( ix ) . trim ( ) ; char lc = part . charAt ( ix - 1 ) ; if ( lc != 'y' ) { cc . getHorizontal ( ) . setSizeGroup ( sg ) ; } if ( lc != 'x' ) { cc . getVertical ( ) . setSizeGroup ( sg ) ; } continue ; } } if ( c == 'g' ) { ix = startsWithLenient ( part , "growx" , 5 , true ) ; if ( ix > - 1 ) { cc . getHorizontal ( ) . setGrow ( parseFloat ( part . substring ( ix ) . trim ( ) , ResizeConstraint . WEIGHT_100 ) ) ; continue ; } ix = startsWithLenient ( part , "growy" , 5 , true ) ; if ( ix > - 1 ) { cc . getVertical ( ) . setGrow ( parseFloat ( part . substring ( ix ) . trim ( ) , ResizeConstraint . WEIGHT_100 ) ) ; continue ; } ix = startsWithLenient ( part , "grow" , 4 , false ) ; if ( ix > - 1 ) { String [ ] grows = toTrimmedTokens ( part . substring ( ix ) . trim ( ) , ' ' ) ; cc . getHorizontal ( ) . setGrow ( parseFloat ( grows [ 0 ] , ResizeConstraint . WEIGHT_100 ) ) ; cc . getVertical ( ) . setGrow ( parseFloat ( grows . length > 1 ? grows [ 1 ] : "" , ResizeConstraint . WEIGHT_100 ) ) ; continue ; } ix = startsWithLenient ( part , new String [ ] { "growprio" , "gp" } , new int [ ] { 8 , 2 } , true ) ; if ( ix > - 1 ) { String gp = part . substring ( ix ) . trim ( ) ; char c0 = gp . length ( ) > 0 ? gp . charAt ( 0 ) : ' ' ; if ( c0 == 'x' || c0 == 'y' ) { ( c0 == 'x' ? cc . getHorizontal ( ) : cc . getVertical ( ) ) . setGrowPriority ( Integer . parseInt ( gp . substring ( 2 ) ) ) ; } else { String [ ] grows = toTrimmedTokens ( gp , ' ' ) ; cc . getHorizontal ( ) . setGrowPriority ( Integer . parseInt ( grows [ 0 ] ) ) ; if ( grows . length > 1 ) { cc . getVertical ( ) . setGrowPriority ( Integer . parseInt ( grows [ 1 ] ) ) ; } } continue ; } if ( part . startsWith ( "gap" ) ) { BoundSize [ ] gaps = parseGaps ( part ) ; if ( gaps [ 0 ] != null ) { cc . getVertical ( ) . setGapBefore ( gaps [ 0 ] ) ; } if ( gaps [ 1 ] != null ) { cc . getHorizontal ( ) . setGapBefore ( gaps [ 1 ] ) ; } if ( gaps [ 2 ] != null ) { cc . getVertical ( ) . setGapAfter ( gaps [ 2 ] ) ; } if ( gaps [ 3 ] != null ) { cc . getHorizontal ( ) . setGapAfter ( gaps [ 3 ] ) ; } continue ; } } if ( c == 'a' ) { ix = startsWithLenient ( part , new String [ ] { "aligny" , "ay" } , new int [ ] { 6 , 2 } , true ) ; if ( ix > - 1 ) { cc . getVertical ( ) . setAlign ( parseUnitValueOrAlign ( part . substring ( ix ) . trim ( ) , false , null ) ) ; continue ; } ix = startsWithLenient ( part , new String [ ] { "alignx" , "ax" } , new int [ ] { 6 , 2 } , true ) ; if ( ix > - 1 ) { cc . getHorizontal ( ) . setAlign ( parseUnitValueOrAlign ( part . substring ( ix ) . trim ( ) , true , null ) ) ; continue ; } ix = startsWithLenient ( part , "align" , 2 , true ) ; if ( ix > - 1 ) { String [ ] gaps = toTrimmedTokens ( part . substring ( ix ) . trim ( ) , ' ' ) ; cc . getHorizontal ( ) . setAlign ( parseUnitValueOrAlign ( gaps [ 0 ] , true , null ) ) ; if ( gaps . length > 1 ) { cc . getVertical ( ) . setAlign ( parseUnitValueOrAlign ( gaps [ 1 ] , false , null ) ) ; } continue ; } } if ( ( c == 'x' || c == 'y' ) && part . length ( ) > 2 ) { char c2 = part . charAt ( 1 ) ; if ( c2 == ' ' || ( c2 == '2' && part . charAt ( 2 ) == ' ' ) ) { if ( cc . getPos ( ) == null ) { cc . setPos ( new UnitValue [ 4 ] ) ; } else if ( cc . isBoundsInGrid ( ) == false ) { throw new IllegalArgumentException ( "Cannot combine 'position' with 'x/y/x2/y2' keywords." ) ; } int edge = ( c == 'x' ? 0 : 1 ) + ( c2 == '2' ? 2 : 0 ) ; UnitValue [ ] pos = cc . getPos ( ) ; pos [ edge ] = parseUnitValue ( part . substring ( 2 ) . trim ( ) , null , c == 'x' ) ; cc . setPos ( pos ) ; cc . setBoundsInGrid ( true ) ; continue ; } } if ( c == 'c' ) { ix = startsWithLenient ( part , "cell" , 4 , true ) ; if ( ix > - 1 ) { String [ ] grs = toTrimmedTokens ( part . substring ( ix ) . trim ( ) , ' ' ) ; if ( grs . length < 2 ) { throw new IllegalArgumentException ( "At least two integers must follow " + part ) ; } cc . setCellX ( Integer . parseInt ( grs [ 0 ] ) ) ; cc . setCellY ( Integer . parseInt ( grs [ 1 ] ) ) ; if ( grs . length > 2 ) { cc . setSpanX ( Integer . parseInt ( grs [ 2 ] ) ) ; } if ( grs . length > 3 ) { cc . setSpanY ( Integer . parseInt ( grs [ 3 ] ) ) ; } continue ; } } if ( c == 'p' ) { ix = startsWithLenient ( part , "pos" , 3 , true ) ; if ( ix > - 1 ) { if ( cc . getPos ( ) != null && cc . isBoundsInGrid ( ) ) { throw new IllegalArgumentException ( "Can not combine 'pos' with 'x/y/x2/y2' keywords." ) ; } String [ ] pos = toTrimmedTokens ( part . substring ( ix ) . trim ( ) , ' ' ) ; UnitValue [ ] bounds = new UnitValue [ 4 ] ; for ( int j = 0 ; j < pos . length ; j ++ ) { bounds [ j ] = parseUnitValue ( pos [ j ] , null , j % 2 == 0 ) ; } if ( bounds [ 0 ] == null && bounds [ 2 ] == null || bounds [ 1 ] == null && bounds [ 3 ] == null ) { throw new IllegalArgumentException ( "Both x and x2 or y and y2 can not be null!" ) ; } cc . setPos ( bounds ) ; cc . setBoundsInGrid ( false ) ; continue ; } ix = startsWithLenient ( part , "pad" , 3 , true ) ; if ( ix > - 1 ) { UnitValue [ ] p = parseInsets ( part . substring ( ix ) . trim ( ) , false ) ; cc . setPadding ( new UnitValue [ ] { p [ 0 ] , p . length > 1 ? p [ 1 ] : null , p . length > 2 ? p [ 2 ] : null , p . length > 3 ? p [ 3 ] : null } ) ; continue ; } ix = startsWithLenient ( part , "pushx" , 5 , true ) ; if ( ix > - 1 ) { cc . setPushX ( parseFloat ( part . substring ( ix ) . trim ( ) , ResizeConstraint . WEIGHT_100 ) ) ; continue ; } ix = startsWithLenient ( part , "pushy" , 5 , true ) ; if ( ix > - 1 ) { cc . setPushY ( parseFloat ( part . substring ( ix ) . trim ( ) , ResizeConstraint . WEIGHT_100 ) ) ; continue ; } ix = startsWithLenient ( part , "push" , 4 , false ) ; if ( ix > - 1 ) { String [ ] pushs = toTrimmedTokens ( part . substring ( ix ) . trim ( ) , ' ' ) ; cc . setPushX ( parseFloat ( pushs [ 0 ] , ResizeConstraint . WEIGHT_100 ) ) ; cc . setPushY ( parseFloat ( pushs . length > 1 ? pushs [ 1 ] : "" , ResizeConstraint . WEIGHT_100 ) ) ; continue ; } } if ( c == 't' ) { ix = startsWithLenient ( part , "tag" , 3 , true ) ; if ( ix > - 1 ) { cc . setTag ( part . substring ( ix ) . trim ( ) ) ; continue ; } } if ( c == 'w' || c == 'h' ) { if ( part . equals ( "wrap" ) ) { cc . setWrap ( true ) ; continue ; } if ( part . startsWith ( "wrap " ) ) { String gapSz = part . substring ( 5 ) . trim ( ) ; cc . setWrapGapSize ( parseBoundSize ( gapSz , true , true ) ) ; continue ; } boolean isHor = c == 'w' ; if ( isHor && ( part . startsWith ( "w " ) || part . startsWith ( "width " ) ) ) { String uvStr = part . substring ( part . charAt ( 1 ) == ' ' ? 2 : 6 ) . trim ( ) ; cc . getHorizontal ( ) . setSize ( parseBoundSize ( uvStr , false , true ) ) ; continue ; } if ( ! isHor && ( part . startsWith ( "h " ) || part . startsWith ( "height " ) ) ) { String uvStr = part . substring ( part . charAt ( 1 ) == ' ' ? 2 : 7 ) . trim ( ) ; cc . getVertical ( ) . setSize ( parseBoundSize ( uvStr , false , false ) ) ; continue ; } if ( part . startsWith ( "wmin " ) || part . startsWith ( "wmax " ) || part . startsWith ( "hmin " ) || part . startsWith ( "hmax " ) ) { String uvStr = part . substring ( 5 ) . trim ( ) ; if ( uvStr . length ( ) > 0 ) { UnitValue uv = parseUnitValue ( uvStr , null , isHor ) ; boolean isMin = part . charAt ( 3 ) == 'n' ; DimConstraint dc = isHor ? cc . getHorizontal ( ) : cc . getVertical ( ) ; dc . setSize ( new BoundSize ( isMin ? uv : dc . getSize ( ) . getMin ( ) , dc . getSize ( ) . getPreferred ( ) , isMin ? ( dc . getSize ( ) . getMax ( ) ) : uv , uvStr ) ) ; continue ; } } if ( part . equals ( "west" ) ) { cc . setDockSide ( 1 ) ; continue ; } if ( part . startsWith ( "hidemode " ) ) { cc . setHideMode ( Integer . parseInt ( part . substring ( 9 ) ) ) ; continue ; } } if ( c == 'i' && part . startsWith ( "id " ) ) { cc . setId ( part . substring ( 3 ) . trim ( ) ) ; int dIx = cc . getId ( ) . indexOf ( '.' ) ; if ( dIx == 0 || dIx == cc . getId ( ) . length ( ) - 1 ) { throw new IllegalArgumentException ( "Dot must not be first or last!" ) ; } continue ; } if ( c == 'e' ) { if ( part . equals ( "east" ) ) { cc . setDockSide ( 3 ) ; continue ; } if ( part . equals ( "external" ) ) { cc . setExternal ( true ) ; continue ; } ix = startsWithLenient ( part , new String [ ] { "endgroupx" , "endgroupy" , "egx" , "egy" } , new int [ ] { - 1 , - 1 , - 1 , - 1 } , true ) ; if ( ix > - 1 ) { String sg = part . substring ( ix ) . trim ( ) ; char lc = part . charAt ( ix - 1 ) ; DimConstraint dc = ( lc == 'x' ? cc . getHorizontal ( ) : cc . getVertical ( ) ) ; dc . setEndGroup ( sg ) ; continue ; } } if ( c == 'd' ) { if ( part . equals ( "dock north" ) ) { cc . setDockSide ( 0 ) ; continue ; } if ( part . equals ( "dock west" ) ) { cc . setDockSide ( 1 ) ; continue ; } if ( part . equals ( "dock south" ) ) { cc . setDockSide ( 2 ) ; continue ; } if ( part . equals ( "dock east" ) ) { cc . setDockSide ( 3 ) ; continue ; } if ( part . equals ( "dock center" ) ) { cc . getHorizontal ( ) . setGrow ( new Float ( 100f ) ) ; cc . getVertical ( ) . setGrow ( new Float ( 100f ) ) ; cc . setPushX ( new Float ( 100f ) ) ; cc . setPushY ( new Float ( 100f ) ) ; continue ; } } if ( c == 'v' ) { ix = startsWithLenient ( part , new String [ ] { "visualpadding" , "vp" } , new int [ ] { 3 , 2 } , true ) ; if ( ix > - 1 ) { UnitValue [ ] p = parseInsets ( part . substring ( ix ) . trim ( ) , false ) ; cc . setVisualPadding ( new UnitValue [ ] { p [ 0 ] , p . length > 1 ? p [ 1 ] : null , p . length > 2 ? p [ 2 ] : null , p . length > 3 ? p [ 3 ] : null } ) ; continue ; } } UnitValue horAlign = parseAlignKeywords ( part , true ) ; if ( horAlign != null ) { cc . getHorizontal ( ) . setAlign ( horAlign ) ; continue ; } UnitValue verAlign = parseAlignKeywords ( part , false ) ; if ( verAlign != null ) { cc . getVertical ( ) . setAlign ( verAlign ) ; continue ; } throw new IllegalArgumentException ( "Unknown keyword." ) ; } catch ( Exception ex ) { ex . printStackTrace ( ) ; throw new IllegalArgumentException ( "Error parsing Constraint: '" + part + "'" ) ; } } return cc ; }
Parses one component constraint and returns the parsed value .