1 /*
2 * Copyright 2006-2016 The JGUIraffe Team.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License")
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.sf.jguiraffe.gui.forms;
17
18 /**
19 * <p>
20 * A simple default implementation of the <code>ComponentHandler</code>
21 * interface.
22 * </p>
23 * <p>
24 * This class implements all methods required by the
25 * <code>ComponentHandler</code> interface without being backed by a really
26 * GUI component. All get and set methods operate on internal properties. The
27 * class can be used for testing or for components that need a faked component
28 * handler.
29 * </p>
30 *
31 * @author Oliver Heger
32 * @version $Id: ComponentHandlerImpl.java 205 2012-01-29 18:29:57Z oheger $
33 */
34 public class ComponentHandlerImpl implements ComponentHandler<Object>
35 {
36 /** Stores the data of this handler. */
37 private Object data;
38
39 /** Holds a reference to the associated component. */
40 private Object component;
41
42 /** Stores the data type of this handler. */
43 private Class<?> type;
44
45 /** A flag whether this handler is enabled. */
46 private boolean enabled;
47
48 /**
49 * Returns the underlying component.
50 *
51 * @return the component
52 */
53 public Object getComponent()
54 {
55 return component;
56 }
57
58 /**
59 * Sets the underlying component. The passed in object is simply stored in
60 * an internal property.
61 *
62 * @param c the component
63 */
64 public void setComponent(Object c)
65 {
66 component = c;
67 }
68
69 /**
70 * Returns data of this handler. This data is simply stored in an internal
71 * property.
72 *
73 * @return the component's data
74 */
75 public Object getData()
76 {
77 return data;
78 }
79
80 /**
81 * Sets data of this handler. The passed in data object is stored in an
82 * internal property.
83 *
84 * @param data the data object
85 */
86 public void setData(Object data)
87 {
88 this.data = data;
89 }
90
91 /**
92 * Returns the data type of this handler.
93 *
94 * @return the data type
95 */
96 public Class<?> getType()
97 {
98 return type;
99 }
100
101 /**
102 * Allows to set this handler's data type. The type set with this method
103 * will be returned by the <code>getType()</code> method. It should always
104 * be initialized first.
105 *
106 * @param type the type of this handler
107 */
108 public void setType(Class<?> type)
109 {
110 this.type = type;
111 }
112
113 /**
114 * Returns the outer component of this handler. This is the same as the
115 * normal component.
116 *
117 * @return the handler's outer component
118 */
119 public Object getOuterComponent()
120 {
121 return getComponent();
122 }
123
124 /**
125 * Returns the enabled flag.
126 *
127 * @return the enabled flag
128 */
129 public boolean isEnabled()
130 {
131 return enabled;
132 }
133
134 /**
135 * Sets the enabled flag. This flag is simply realized by an internal member
136 * variable.
137 *
138 * @param f the flag value
139 */
140 public void setEnabled(boolean f)
141 {
142 enabled = f;
143 }
144 }