View Javadoc
1 /* 2 * Scope: a generic MVC framework. 3 * Copyright (c) 2000-2002, The Scope team 4 * All rights reserved. 5 * 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 14 * Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * Neither the name "Scope" nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 * 35 * 36 * $Id: SSlider.java,v 1.8 2002/09/13 17:04:41 ludovicc Exp $ 37 */ 38 package org.scopemvc.view.swing; 39 40 import java.beans.Beans; 41 import javax.swing.JSlider; 42 import javax.swing.JToolTip; 43 import org.apache.commons.logging.Log; 44 import org.apache.commons.logging.LogFactory; 45 import org.scopemvc.core.Control; 46 import org.scopemvc.core.Controller; 47 import org.scopemvc.core.PropertyView; 48 import org.scopemvc.core.Selector; 49 import org.scopemvc.view.util.ModelBindable; 50 51 /*** 52 * <P> 53 * 54 * A JSlider whose value is bound to an int property of a model object. </P> <P> 55 * 56 * Note that the Selector specified for a SCheckbox must select a single Integer 57 * or int property. </P> <P> 58 * 59 * SSlider responds to the bound model or the particular bound property becoming 60 * read-only by disabling itself. A SSlider is also disabled if it has no bound 61 * model or property, or the property is a null Integer. </P> 62 * 63 * @author <A HREF="mailto:smeyfroi@users.sourceforge.net">Steve Meyfroidt</A> 64 * @created 05 September 2002 65 * @version $Revision: 1.8 $ $Date: 2002/09/13 17:04:41 $ 66 */ 67 public class SSlider extends JSlider 68 implements PropertyView, ModelBindable, Refreshable { 69 70 private static final Log LOG = LogFactory.getLog(SSlider.class); 71 72 /*** 73 * Helper to manage model to view binding. 74 */ 75 private SwingBoundModel boundModel = new SwingBoundModel(this); 76 77 /*** 78 * Helper to manage validation state. 79 */ 80 private ValidationHelper validationHelper = new ValidationHelper(this); 81 82 /*** 83 * SSlider can "hold" a null when bound to a Integer property that happens 84 * to be null. 85 */ 86 private boolean valueIsNull = false; 87 88 89 /*** 90 * Constructor for the SSlider object 91 */ 92 public SSlider() { 93 setEnabled(Beans.isDesignTime()); 94 } 95 96 97 // ------------------- Delegate to BoundModel ------------------- 98 99 /*** 100 * Gets the bound model 101 * 102 * @return The boundModel value 103 */ 104 public final Object getBoundModel() { 105 return boundModel.getBoundModel(); 106 } 107 108 109 /*** 110 * Gets the selector 111 * 112 * @return The selector value 113 */ 114 public final Selector getSelector() { 115 return boundModel.getSelector(); 116 } 117 118 119 /*** 120 * Get the current value (what would be set as a property of the bound model 121 * object) being presented on the View. 122 * 123 * @return an Integer or null when (! isEnabled()) 124 */ 125 public Object getViewValue() { 126 /* 127 * throws IllegalArgumentException 128 */ 129 if (valueIsNull) { 130 return null; 131 } 132 133 return new Integer(getModel().getValue()); 134 } 135 136 137 /*** 138 * Don't assign a Controller to this component, instead delegate to the 139 * containing SwingView that has a parent Controller. 140 * 141 * @return The controller value 142 */ 143 public Controller getController() { 144 return null; 145 } 146 147 148 /*** 149 * Don't assign a Controller to SSlider, instead delegate to the containing 150 * SwingView that has a parent Controller. 151 * 152 * @param inControl TODO: Describe the Parameter 153 */ 154 public void issueControl(Control inControl) { 155 SwingUtil.issueControl(this, inControl); 156 } 157 158 159 /*** 160 * Sets the bound model 161 * 162 * @param inModel The new boundModel value 163 */ 164 public final void setBoundModel(Object inModel) { 165 boundModel.setBoundModel(inModel); 166 } 167 168 169 /*** 170 * Sets the selector 171 * 172 * @param inSelector The new selector value 173 */ 174 public final void setSelector(Selector inSelector) { 175 boundModel.setSelector(inSelector); 176 } 177 178 179 /*** 180 * Sets the selector string 181 * 182 * @param inSelectorString The new selectorString value 183 */ 184 public final void setSelectorString(String inSelectorString) { 185 boundModel.setSelectorString(inSelectorString); 186 } 187 188 /*** 189 * Don't assign a Controller to this component, instead delegate to the 190 * containing SwingView that has a parent Controller. 191 * 192 * @param inController The new controller value 193 */ 194 public void setController(Controller inController) { 195 throw new UnsupportedOperationException("Can't assign a Controller to a " + getClass()); 196 } 197 198 // --------------------- Implement ModelBindable ---------------------- 199 200 /*** 201 * Incoming value is a Boolean or null. 202 * 203 * @param inValue TODO: Describe the Parameter 204 * @param inReadOnly TODO: Describe the Parameter 205 */ 206 public void updateFromProperty(Object inValue, boolean inReadOnly) { 207 if (LOG.isDebugEnabled()) { 208 LOG.debug("updateFromProperty: " + inValue + ", " + inReadOnly); 209 } 210 211 if (inValue == null || !(inValue instanceof Integer)) { 212 valueIsNull = true; 213 setEnabled(false); 214 return; 215 } 216 217 valueIsNull = false; 218 setEnabled(!inReadOnly); 219 setValue(((Integer) inValue).intValue()); 220 } 221 222 223 /*** 224 * TODO: document the method 225 * 226 * @param inException TODO: Describe the Parameter 227 */ 228 public void validationFailed(Exception inException) { 229 validationHelper.validationFailed(inException); 230 } 231 232 233 /*** 234 * TODO: document the method 235 */ 236 public void validationSuccess() { 237 validationHelper.validationSuccess(); 238 } 239 240 241 /*** 242 * TODO: document the method 243 * 244 * @return TODO: Describe the Return Value 245 */ 246 public JToolTip createToolTip() { 247 return validationHelper.createToolTip(super.createToolTip()); 248 } 249 250 251 // ------------------ Refreshable ------------------------- 252 253 /*** 254 * TODO: document the method 255 */ 256 public void refresh() { 257 Object propertyValue = boundModel.getPropertyValue(); 258 boolean propertyReadOnly = boundModel.getPropertyReadOnly(); 259 updateFromProperty(propertyValue, propertyReadOnly); 260 } 261 262 263 // ---------------------- View to model ---------------------- 264 265 /*** 266 * Update the bound model with the new value, then send a ChangeEvent, whose 267 * source is this Slider, to each listener. <br> 268 * This method method is called each time a ChangeEvent is received from the 269 * model. 270 */ 271 protected void fireStateChanged() { 272 valueIsNull = false; 273 boundModel.updateModel(); 274 super.fireStateChanged(); 275 } 276 }

This page was automatically generated by Maven