Java Rectangle Create Parse getRectangle(Preferences prefs, String sName, int iDefaultWidth, int iDefaultHeight)

Here you can find the source of getRectangle(Preferences prefs, String sName, int iDefaultWidth, int iDefaultHeight)

Description

reads a rectangle from the preferences

License

Open Source License

Parameter

Parameter Description
prefs the preferences base path
sName the node relative to the base path
iDefaultWidth the default width for the rectangle, if no entry was found
iDefaultHeight the default height for the rectangle, if no entry was found

Declaration

public static Rectangle getRectangle(Preferences prefs, String sName, int iDefaultWidth, int iDefaultHeight) 

Method Source Code

//package com.java2s;
//it under the terms of the GNU Affero General Public License as published by

import java.awt.Rectangle;

import java.util.prefs.Preferences;

public class Main {
    private static final String PREFS_KEY_RECTANGLE_X = "x";
    private static final String PREFS_KEY_RECTANGLE_Y = "y";
    private static final String PREFS_KEY_RECTANGLE_WIDTH = "width";
    private static final String PREFS_KEY_RECTANGLE_HEIGHT = "height";

    /**//from   ww w . jav a  2s.  c om
     * reads a rectangle from the preferences
     * @param prefs the preferences base path
     * @param sName the node relative to the base path
     * @param iDefaultWidth the default width for the rectangle, if no entry was found
     * @param iDefaultHeight the default height for the rectangle, if no entry was found
     */
    public static Rectangle getRectangle(Preferences prefs, String sName, int iDefaultWidth, int iDefaultHeight) {
        /** @todo this should not build a node for a non-existing node! */
        final Preferences node = prefs.node(sName);

        final int x = node.getInt(PREFS_KEY_RECTANGLE_X, 0);
        final int y = node.getInt(PREFS_KEY_RECTANGLE_Y, 0);
        final int width = node.getInt(PREFS_KEY_RECTANGLE_WIDTH, iDefaultWidth);
        final int height = node.getInt(PREFS_KEY_RECTANGLE_HEIGHT, iDefaultHeight);

        return new Rectangle(x, y, width, height);
    }
}

Related

  1. decodeBounds(String sBounds)
  2. getRectangle(Map bounds)
  3. getRectangle(Properties prop, final String key, final Rectangle def)
  4. getRectangle(String rectStr)
  5. newRectangle(int x1, int y1, int x2, int y2)
  6. rectangleToString(Rectangle r)