001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2002, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program 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
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020: package com.salmonllc.swing;
021:
022: /////////////////////////
023: //$Archive: /SOFIA/SourceCode/com/salmonllc/swing/SOption.java $
024: //$Author: Dan $
025: //$Revision: 2 $
026: //$Modtime: 5/07/03 11:53a $
027: /////////////////////////
028:
029: /**
030: * This type is used for the options in the SComboBox, SCheckBox, SList, SToggleButton, etc. It contains an internal key value, but display an external display value.
031: */
032: public class SOption {
033: private String _display;
034: private String _key;
035:
036: /**
037: * This method is the default Constructor
038: */
039: public SOption() {
040: super ();
041: }
042:
043: /**
044: * Creates a new Option object
045: */
046: public SOption(String key, String disp) {
047: super ();
048: setKey(key);
049: setDisplay(disp);
050: }
051:
052: /**
053: * Sets the display value.
054: */
055: public void setDisplay(String display) {
056: _display = display;
057: }
058:
059: /**
060: * Returns the display value.
061: */
062: public String getDisplay() {
063: return _display;
064: }
065:
066: /**
067: * Sets the key value.
068: */
069: public void setKey(String key) {
070: _key = key;
071: }
072:
073: /**
074: * Returns the key value.
075: */
076: public String getKey() {
077: return _key;
078: }
079:
080: /**
081: * @see Object#toString()
082: */
083: public String toString() {
084: return getDisplay();
085: }
086:
087: /**
088: * Returns true if the object.toString() passed equals the key value
089: */
090: public boolean equals(Object o) {
091: if (o == null) {
092: if (_key == null || _key.length() == 0)
093: return true;
094: else
095: return false;
096: }
097: String val = null;
098: if (o instanceof SOption) {
099: val = ((SOption) o).getKey();
100: return compValues(val, _key);
101: } else {
102: val = o.toString().trim();
103: return compValues(val, _key) || compValues(val, _display);
104: }
105: }
106:
107: private boolean compValues(String val, String val2) {
108: if (val == null || val.equals("")) {
109: if (val2 == null || val2.length() == 0)
110: return true;
111: else
112: return false;
113: } else {
114: if (val2 == null || val2.equals(""))
115: return false;
116: else
117: return val.equals(val2);
118: }
119:
120: }
121: }
|