001: // WebOnSwing - Web Application Framework
002: //Copyright (C) 2004 Fernando Damian Petrola
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: package net.ar.webonswing.swing.components.validators;
019:
020: import javax.swing.JComponent;
021:
022: import net.ar.webonswing.WosFramework;
023: import net.ar.webonswing.swing.components.validators.contributors.RangeValidatorUIContributor;
024:
025: public class JRangeValidator extends JGroupValidator {
026: protected JCompareValidator lowValidator, highValidator;
027: protected JCompareValidator.Type type = JCompareValidator.Type.STRING;
028:
029: public JRangeValidator() {
030: setContributor();
031: }
032:
033: public JRangeValidator(JComponent aComponentToValidate,
034: String aMessage, String aGroupMessage,
035: boolean hasRemoteValidation, Object aLowValue,
036: Object aHighValue, JCompareValidator.Type aType) {
037: super (aComponentToValidate, aMessage, aGroupMessage,
038: hasRemoteValidation);
039:
040: setType(aType);
041: setLowValue(aLowValue);
042: setHighValue(aHighValue);
043:
044: setContributor();
045: }
046:
047: public JRangeValidator(JComponent aComponentToValidate,
048: String aMessage, String aGroupMessage,
049: boolean hasRemoteValidation, JComponent aLowComponent,
050: JComponent aHighComponent, JCompareValidator.Type aType) {
051: super (aComponentToValidate, aMessage, aGroupMessage,
052: hasRemoteValidation);
053:
054: setType(aType);
055: setLowComponent(aLowComponent);
056: setHighComponent(aHighComponent);
057:
058: setContributor();
059: }
060:
061: protected void setContributor() {
062: WosFramework.assignContributor(this ,
063: RangeValidatorUIContributor.class);
064: }
065:
066: protected boolean performValidation() {
067: return lowValidator.doValidation()
068: && highValidator.doValidation();
069: }
070:
071: public JComponent getHighComponent() {
072: return highValidator.getComponentToCompare();
073: }
074:
075: public JComponent getLowComponent() {
076: return lowValidator.getComponentToCompare();
077: }
078:
079: public Object getHighValue() {
080: return highValidator.getValueToCompare();
081: }
082:
083: public Object getLowValue() {
084: return lowValidator.getValueToCompare();
085: }
086:
087: public void setHighComponent(JComponent highComponent) {
088: highValidator = changeValidator(highValidator,
089: new JCompareValidator(getComponentToValidate(), "", "",
090: isRemoteValidation(), highComponent,
091: JCompareValidator.Operation.lessThanEqual,
092: getType()));
093: }
094:
095: public void setHighValue(Object highValue) {
096: highValidator = changeValidator(highValidator,
097: new JCompareValidator(getComponentToValidate(), "", "",
098: isRemoteValidation(), highValue,
099: JCompareValidator.Operation.lessThanEqual,
100: getType()));
101: }
102:
103: public void setLowComponent(JComponent lowComponent) {
104: lowValidator = changeValidator(lowValidator,
105: new JCompareValidator(getComponentToValidate(), "", "",
106: isRemoteValidation(), lowComponent,
107: JCompareValidator.Operation.greaterThanEqual,
108: getType()));
109: }
110:
111: public void setLowValue(Object lowValue) {
112: lowValidator = changeValidator(lowValidator,
113: new JCompareValidator(getComponentToValidate(), "", "",
114: isRemoteValidation(), lowValue,
115: JCompareValidator.Operation.greaterThanEqual,
116: getType()));
117: }
118:
119: protected JCompareValidator changeValidator(
120: JCompareValidator oldValidator,
121: JCompareValidator newValidator) {
122: if (oldValidator != null)
123: remove(removeValidator(oldValidator));
124:
125: if (newValidator != null)
126: add(addValidator(newValidator));
127:
128: return newValidator;
129: }
130:
131: public JCompareValidator.Type getType() {
132: return type;
133: }
134:
135: public void setType(JCompareValidator.Type aType) {
136: this.type = aType;
137:
138: if (lowValidator != null)
139: lowValidator.setType(type);
140:
141: if (highValidator != null)
142: highValidator.setType(type);
143: }
144: }
|