src/tokenclustering/model/ClusteringAreaData.java
/**
     * Puts a token in this area.
     * @param token The token to put.
     * @return If its possible to put the token.
     */
Puts a token in this area.
@param token The token to put.
@return If its possible to put the token.
Puts a token in this area . @param token The token to put . @return If its possible to put the token .
public boolean canPutToken(Token token) {
        if (this.width < token.getWidth() || this.height < token.getHeight()) {
            return false;
        }
        if (this.getTokens().contains(token)) {
            return false;
        }
        int xPossibilities = this.width - token.getWidth() + 1;
        int yPossibilities = this.height - token.getHeight() + 1;
        ArrayList<Slot> slotsTried = new ArrayList<Slot>();
        for (int i = 0; i < xPossibilities; i++) {
            for (int j = 0; j < yPossibilities; j++) {
                boolean thisTry = true;
                for (int k = 0; k < token.getWidth(); k++) {
                    for (int l = 0; l < token.getHeight(); l++) {
                        Slot slotTried = new Slot(i + k, j + l);
                        if (this.freeSlots.contains(slotTried)) {
                            slotsTried.add(slotTried);
                        } else {
                            thisTry = false;
                        }
                    }
                }
                if (thisTry) {
                    return true;
                } else {
                    slotsTried.clear();
                }
            }
        }
        return false;
    }
public boolean canPutToken ( Token token ) { if ( this . width < token . getWidth ( ) || this . height < token . getHeight ( ) ) { return false ; } if ( this . getTokens ( ) . contains ( token ) ) { return false ; } int xPossibilities = this . width - token . getWidth ( ) + 1 ; int yPossibilities = this . height - token . getHeight ( ) + 1 ; ArrayList < Slot > slotsTried = new ArrayList < Slot > ( ) ; for ( int i = 0 ; i < xPossibilities ; i ++ ) { for ( int j = 0 ; j < yPossibilities ; j ++ ) { boolean thisTry = true ; for ( int k = 0 ; k < token . getWidth ( ) ; k ++ ) { for ( int l = 0 ; l < token . getHeight ( ) ; l ++ ) { Slot slotTried = new Slot ( i + k , j + l ) ; if ( this . freeSlots . contains ( slotTried ) ) { slotsTried . add ( slotTried ) ; } else { thisTry = false ; } } } if ( thisTry ) { return true ; } else { slotsTried . clear ( ) ; } } } return false ; }
Puts a token in this area.
Puts a token in this area .