Java Rectangle Create Parse decodeBounds(String sBounds)

Here you can find the source of decodeBounds(String sBounds)

Description

Decode the comma separated values stored in sBounds.

License

Open Source License

Parameter

Parameter Description
sBounds a parameter

Return

the rectangle

Declaration

public static Rectangle decodeBounds(String sBounds) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006 Sybase, Inc. and others.
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from w  w  w  .j a v  a 2 s.c o  m*/
 *     Sybase, Inc. - initial API and implementation
 *******************************************************************************/

import java.awt.Rectangle;

public class Main {
    /**
     * Decode the comma separated values stored in sBounds. This method is
     * normally called to decode the location/size of a component which has been
     * saved into a Properties object. See encodeBounds(); Order of items in the
     * string is (x, y, w, h)
     * @param sBounds 
     * @return the rectangle
     */
    public static Rectangle decodeBounds(String sBounds) {
        int index;
        int ii;
        int theValue[] = new int[4];
        String tmpString;
        String restString = sBounds;

        for (ii = 0; ii < 4; ii++) {
            theValue[ii] = 0;
        }
        try {
            for (ii = 0; ii < 4; ii++) {
                index = restString.indexOf(","); //$NON-NLS-1$
                if (index > 0) {
                    tmpString = restString.substring(0, index);
                    restString = restString.substring(index + 1);
                } else {
                    tmpString = restString; // should only happen on the last
                    // one....
                    restString = null; // will cause an exception if not last
                    // one...
                }
                theValue[ii] = Integer.valueOf(tmpString).intValue();
            }
        } catch (Exception ee)// NOPMD
        {
            // the property value maybe an invalid value, the editor should show
            // these to user.
        }

        return new Rectangle(theValue[0], theValue[1], theValue[2], theValue[3]);
    }
}

Related

  1. getRectangle(Map bounds)
  2. getRectangle(Preferences prefs, String sName, int iDefaultWidth, int iDefaultHeight)
  3. getRectangle(Properties prop, final String key, final Rectangle def)
  4. getRectangle(String rectStr)