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: SMenuItem.java,v 1.12 2002/09/13 17:04:40 ludovicc Exp $ 37 */ 38 package org.scopemvc.view.swing; 39 40 import java.awt.event.ActionEvent; 41 import java.beans.Beans; 42 import javax.swing.JMenuItem; 43 import javax.swing.KeyStroke; 44 import org.apache.commons.logging.Log; 45 import org.apache.commons.logging.LogFactory; 46 import org.scopemvc.core.Control; 47 import org.scopemvc.core.Controller; 48 import org.scopemvc.util.UIStrings; 49 50 /*** 51 * <P> 52 * 53 * A JMenuItem that can be owned by a SwingView using {@link 54 * org.scopemvc.controller.swing.SwingContext}, and which causes its owning view 55 * to issue a Control when selected. </P> 56 * 57 * @author <A HREF="mailto:smeyfroi@users.sourceforge.net">Steve Meyfroidt</A> 58 * @created 05 September 2002 59 * @version $Revision: 1.12 $ $Date: 2002/09/13 17:04:40 $ 60 */ 61 public class SMenuItem extends JMenuItem implements SwingSubView { 62 63 private static final Log LOG = LogFactory.getLog(SMenuItem.class); 64 65 /*** 66 * View that 'owns' this menuitem at any time. When selected, the menuitem 67 * causes its owner to issue a Control. 68 */ 69 private SwingView owner; 70 71 private String controlID; 72 73 /*** 74 * Empty constructor required by GUI designers 75 */ 76 public SMenuItem() { 77 this(null); 78 } 79 80 /*** 81 * Constructor for the SMenuItem object 82 * 83 * @param inControlID TODO: Describe the Parameter 84 */ 85 public SMenuItem(String inControlID) { 86 this(inControlID, null, null); 87 } 88 89 90 /*** 91 * Sets text by looking up ControlID in UIStrings. 92 * 93 * @param inControlID issue this Control when user chooses menuitem. 94 * @param inView the parent View that owns this menuitem. This is the view 95 * that will issue a Control when the menuitem is actioned. 96 */ 97 public SMenuItem(String inControlID, SwingView inView) { 98 this(inControlID, inView, null); 99 } 100 101 102 /*** 103 * Sets text by looking up ControlID in UIStrings. 104 * 105 * @param inControlID issue this Control when user chooses menuitem. 106 * @param inView the parent View that owns this menuitem. This is the view 107 * that will issue a Control when the menuitem is actioned. 108 * @param accelerator the KeyStroke to use as an accelerator for this 109 * menuitem. 110 */ 111 public SMenuItem(String inControlID, SwingView inView, KeyStroke accelerator) { 112 setControlID(inControlID); 113 setAccelerator(accelerator); 114 if (inView != null) { 115 inView.addSubView(this); 116 } else { 117 setEnabled(Beans.isDesignTime()); 118 // owner will enable later - except for design time 119 } 120 } 121 122 123 /*** 124 * Gets the control ID 125 * 126 * @return The controlID value 127 */ 128 public String getControlID() { 129 return controlID; 130 } 131 132 133 /*** 134 * Gets the owner 135 * 136 * @return The owner value 137 */ 138 public SwingView getOwner() { 139 return owner; 140 } 141 142 143 /*** 144 * Don't assign a Controller to SMenuItem, instead delegate to the 145 * containing SwingView that has a parent Controller. 146 * 147 * @param inControl TODO: Describe the Parameter 148 */ 149 public void issueControl(Control inControl) { 150 if (owner != null) { 151 owner.issueControl(inControl); 152 } 153 } 154 155 156 /*** 157 * Don't assign a Controller to SMenuItem, instead delegate to the 158 * containing SwingView that has a parent Controller. 159 * 160 * @return The controller value 161 */ 162 public Controller getController() { 163 return null; 164 } 165 166 /*** 167 * Gets the bound model 168 * 169 * @return The boundModel value 170 */ 171 public Object getBoundModel() { 172 return null; 173 } 174 175 176 /*** 177 * Sets the control ID 178 * 179 * @param inControlID The new controlID value 180 */ 181 public void setControlID(String inControlID) { 182 controlID = inControlID; 183 if (controlID != null) { 184 setText(UIStrings.get(controlID)); 185 } 186 } 187 188 /*** 189 * Sets the owner 190 * 191 * @param inView The new owner value 192 */ 193 public void setOwner(SwingView inView) { 194 owner = inView; 195 if (owner != null) { 196 inView.addSubView(this); 197 } 198 setEnabled(owner != null || Beans.isDesignTime()); 199 } 200 201 /*** 202 * Don't assign a Controller to this component, instead delegate to the 203 * containing SwingView that has a parent Controller. 204 * 205 * @param inController The new controller value 206 */ 207 public void setController(Controller inController) { 208 throw new UnsupportedOperationException("Can't assign a Controller to a " + getClass()); 209 } 210 211 /*** 212 * Sets the bound model 213 * 214 * @param inModel The new boundModel value 215 */ 216 public void setBoundModel(Object inModel) { 217 // noop 218 } 219 220 221 /*** 222 * TODO: document the method 223 * 224 * @param inView TODO: Describe the Parameter 225 */ 226 public void unsetOwner(SwingView inView) { 227 if (owner != inView) { 228 return; 229 } 230 231 if (owner != null) { 232 owner.removeSubView(this); 233 } 234 owner = null; 235 setEnabled(false); 236 } 237 238 239 /*** 240 * TODO: document the method 241 * 242 * @param inEvent TODO: Describe the Parameter 243 */ 244 protected void fireActionPerformed(ActionEvent inEvent) { 245 if (controlID != null) { 246 issueControl(createControl()); 247 } 248 } 249 250 /*** 251 * Override this to create something other than a simple no-parameter 252 * Control. 253 * 254 * @return Control issued when button pressed: here a simple no-parameter 255 * Control 256 */ 257 protected Control createControl() { 258 if (controlID == null) { 259 throw new RuntimeException("Can't create a Control because no ControlID set."); 260 } 261 262 return new Control(controlID); 263 } 264 }

This page was automatically generated by Maven