Logo Search packages:      
Sourcecode: libjgoodies-forms-java version File versions  Download package

void com::jgoodies::forms::layout::CellConstraints::initFromConstraints ( String  encodedConstraints  )  [inline, private]

Decodes and returns the grid bounds and alignments for this constraints as an array of six integers. The string representation is a comma separated sequence, one of

 "x, y"
 "x, y, w, h"
 "x, y, hAlign, vAlign"
 "x, y, w, h, hAlign, vAlign"
 

Parameters:
encodedConstraints represents horizontal and vertical alignment
Exceptions:
IllegalArgumentException if the encoded constraints do not follow the constraint syntax

Definition at line 559 of file CellConstraints.java.

References decodeAlignment(), decodeInt(), ensureValidOrientations(), gridHeight, gridWidth, gridX, gridY, hAlign, and vAlign.

Referenced by CellConstraints().

                                                                {
        StringTokenizer tokenizer = new StringTokenizer(encodedConstraints, " ,");
        int argCount = tokenizer.countTokens();
        if (!(argCount == 2 || argCount == 4 || argCount == 6))
           throw new IllegalArgumentException(
                    "You must provide 2, 4 or 6 arguments.");
        
        Integer nextInt = decodeInt(tokenizer.nextToken());
        if (nextInt == null) { 
            throw new IllegalArgumentException(
                    "First cell constraint element must be a number.");
        }
        gridX = nextInt.intValue();
        if (gridX <= 0)
            throw new IndexOutOfBoundsException("The grid x must be a positive number.");
            
        nextInt = decodeInt(tokenizer.nextToken());
        if (nextInt == null) {
            throw new IllegalArgumentException(
                    "Second cell constraint element must be a number.");
        }
        gridY = nextInt.intValue();
        if (gridY <= 0)
            throw new IndexOutOfBoundsException(
                    "The grid y must be a positive number.");

        if (!tokenizer.hasMoreTokens())
            return;
            
        String token = tokenizer.nextToken();
        nextInt = decodeInt(token);
        if (nextInt != null) {
            // Case: "x, y, w, h" or
            //       "x, y, w, h, hAlign, vAlign"
            gridWidth = nextInt.intValue();
            if (gridWidth <= 0)
                throw new IndexOutOfBoundsException(
                    "The grid width must be a positive number.");
            nextInt = decodeInt(tokenizer.nextToken());
            if (nextInt == null)
                throw new IllegalArgumentException(
                    "Fourth cell constraint element must be like third.");
            gridHeight = nextInt.intValue();
            if (gridHeight <= 0)
                throw new IndexOutOfBoundsException(
                    "The grid height must be a positive number.");

            if (!tokenizer.hasMoreTokens())
                return;
            token = tokenizer.nextToken();
        }
            
        hAlign = decodeAlignment(token);
        vAlign = decodeAlignment(tokenizer.nextToken());
        ensureValidOrientations(hAlign, vAlign);
    }


Generated by  Doxygen 1.6.0   Back to index