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: SButton.java,v 1.9 2002/09/13 17:03:49 ludovicc Exp $
37 */
38 package org.scopemvc.view.swing;
39
40
41 import java.awt.event.ActionEvent;
42 import javax.swing.JButton;
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.View;
48 import org.scopemvc.util.UIStrings;
49
50 /***
51 * <P>
52 *
53 * A JButton that issues a Control when pressed. The button label comes from
54 * UIStrings keyed against the Control ID. </P>
55 *
56 * @author <A HREF="mailto:smeyfroi@users.sourceforge.net">Steve Meyfroidt</A>
57 * @created 05 September 2002
58 * @version $Revision: 1.9 $ $Date: 2002/09/13 17:03:49 $
59 */
60 public class SButton extends JButton implements View {
61
62 private static final Log LOG = LogFactory.getLog(SButton.class);
63
64 private String controlID;
65 private String modelActionName;
66
67 /***
68 * Constructor for the SButton object
69 */
70 public SButton() {
71 this(null);
72 }
73
74 /***
75 * Constructor for the SButton object
76 *
77 * @param inControlID TODO: Describe the Parameter
78 */
79 public SButton(String inControlID) {
80 setControlID(inControlID);
81 }
82
83 // -------------- implement View ------------------
84
85 /***
86 * Don't assign a Controller to this component, instead delegate to the
87 * containing SwingView that has a parent Controller.
88 *
89 * @return The controller value
90 */
91 public Controller getController() {
92 return null;
93 }
94
95 /***
96 * Gets the bound model
97 *
98 * @return The boundModel value
99 */
100 public Object getBoundModel() {
101 return null;
102 }
103
104 /***
105 * Gets the control ID
106 *
107 * @return The controlID value
108 */
109 public String getControlID() {
110 return controlID;
111 }
112
113 /***
114 * Issue a Control to the View's parent (owner) Controller.
115 *
116 * @param inControl The Control to issue
117 */
118 public void issueControl(Control inControl) {
119 SwingUtil.issueControl(this, inControl);
120 }
121
122 /***
123 * Sets the control ID
124 *
125 * @param inControlID The new controlID value
126 */
127 public void setControlID(String inControlID) {
128 controlID = inControlID;
129 if (controlID != null && getText().length() == 0) {
130 setText(UIStrings.get(controlID));
131 }
132 }
133
134 /***
135 * Don't assign a Controller to this component, instead delegate to the
136 * containing SwingView that has a parent Controller.
137 *
138 * @param inController The new controller value
139 */
140 public void setController(Controller inController) {
141 throw new UnsupportedOperationException("Can't assign a Controller to a " + getClass());
142 }
143
144 /***
145 * Sets the bound model
146 *
147 * @param inModel The new boundModel value
148 */
149 public void setBoundModel(Object inModel) {
150 // noop
151 }
152
153 /***
154 * TODO: document the method
155 *
156 * @param inEvent TODO: Describe the Parameter
157 */
158 public void fireActionPerformed(ActionEvent inEvent) {
159 if (controlID != null) {
160 issueControl(createControl());
161 }
162 }
163
164
165 /***
166 * Override this to create something other than a simple no-parameter
167 * Control or ModelActionControl.
168 *
169 * @return Control issued when button pressed: here a simple no-parameter
170 * Control
171 */
172 protected Control createControl() {
173 if (controlID == null) {
174 throw new RuntimeException("Can't create a Control because no ControlID set.");
175 }
176
177 return new Control(controlID);
178 }
179 }
This page was automatically generated by Maven