001: /*
002: * Copyright (c) 1998-2004 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Sam
027: */
028:
029: package com.caucho.widget;
030:
031: import com.caucho.util.L10N;
032:
033: import java.util.ArrayList;
034: import java.util.logging.Logger;
035:
036: public class WidgetPreference {
037: private static L10N L = new L10N(WidgetPreference.class);
038:
039: static protected final Logger log = Logger
040: .getLogger(WidgetPreference.class.getName());
041:
042: private String _name;
043: private boolean _isReadOnly;
044: private ArrayList<String> _valuesList;
045: private String[] _valuesArray;
046:
047: public void setName(String name) {
048: _name = name;
049: }
050:
051: public String getName() {
052: return _name;
053: }
054:
055: public void setReadOnly(boolean isReadOnly) {
056: _isReadOnly = isReadOnly;
057: }
058:
059: public boolean isReadOnly() {
060: return _isReadOnly;
061: }
062:
063: public String getValue() {
064: makeValues();
065:
066: if (_valuesArray == null)
067: return null;
068: else if (_valuesArray.length == 0)
069: return "";
070: else
071: return _valuesArray[0];
072: }
073:
074: public String[] getValues() {
075: makeValues();
076:
077: return _valuesArray;
078: }
079:
080: public void addValue(String value) {
081: if (_valuesList == null)
082: _valuesList = new ArrayList<String>();
083:
084: _valuesList.add(value);
085: }
086:
087: private void makeValues() {
088: if (_valuesList != null && _valuesList.size() > 0) {
089:
090: int arraySize = (_valuesArray == null ? 0
091: : _valuesArray.length);
092: int listSize = (_valuesList == null ? 0 : _valuesList
093: .size());
094:
095: String[] newArray = new String[arraySize + listSize];
096:
097: for (int i = 0; i < arraySize; i++)
098: newArray[i] = _valuesArray[i];
099:
100: int i = arraySize;
101:
102: for (int j = 0; j < listSize; j++) {
103: newArray[i] = _valuesList.get(j);
104: i++;
105: }
106:
107: _valuesList = null;
108: _valuesArray = newArray;
109: }
110: }
111: }
|