001: /*
002: * Copyright (C) 2005 Jeff Tassin
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */
018:
019: package com.jeta.swingbuilder.interfaces.userprops;
020:
021: import java.awt.Color;
022:
023: import com.jeta.forms.logger.FormsLogger;
024: import com.jeta.open.registry.JETARegistry;
025:
026: /**
027: * Utils for store/retrive user properties
028: *
029: * @author Jeff Tassin
030: */
031: public class TSUserPropertiesUtils {
032:
033: public static boolean getBoolean(String propName, boolean defValue) {
034: boolean result = defValue;
035: TSUserProperties userprops = (TSUserProperties) JETARegistry
036: .lookup(TSUserProperties.COMPONENT_ID);
037: String value = userprops.getProperty(propName);
038: if (value != null) {
039: try {
040: result = Boolean.valueOf(value).booleanValue();
041: } catch (Exception e) {
042: FormsLogger.debug(e);
043: }
044: }
045:
046: return result;
047: }
048:
049: public static Color getColor(String propName, Color defaultColor) {
050: assert (defaultColor != null);
051: if (defaultColor != null) {
052: int rgb = getInteger(propName, defaultColor.getRGB());
053: return new Color(rgb);
054: } else {
055: return Color.black;
056: }
057: }
058:
059: public static int getInteger(String propName, int defValue) {
060: int result = defValue;
061: TSUserProperties userprops = (TSUserProperties) JETARegistry
062: .lookup(TSUserProperties.COMPONENT_ID);
063: String value = userprops.getProperty(propName);
064: if (value != null) {
065: try {
066: result = Integer.parseInt(value);
067: } catch (Exception e) {
068: FormsLogger.debug(e);
069: }
070: }
071: return result;
072: }
073:
074: public static String getString(String propName, String defValue) {
075: TSUserProperties userprops = (TSUserProperties) JETARegistry
076: .lookup(TSUserProperties.COMPONENT_ID);
077: return userprops.getProperty(propName, defValue);
078: }
079:
080: public static void setBoolean(String propName, boolean value) {
081: TSUserProperties userprops = (TSUserProperties) JETARegistry
082: .lookup(TSUserProperties.COMPONENT_ID);
083: userprops.setProperty(propName, String.valueOf(value));
084: }
085:
086: public static void setColor(String propName, Color color) {
087: assert (color != null);
088: if (color != null) {
089: setInteger(propName, color.getRGB());
090: }
091: }
092:
093: public static void setInteger(String propName, int value) {
094: TSUserProperties userprops = (TSUserProperties) JETARegistry
095: .lookup(TSUserProperties.COMPONENT_ID);
096: userprops.setProperty(propName, String.valueOf(value));
097: }
098:
099: public static void setString(String propName, String value) {
100: TSUserProperties userprops = (TSUserProperties) JETARegistry
101: .lookup(TSUserProperties.COMPONENT_ID);
102: userprops.setProperty(propName, value);
103: }
104:
105: }
|