| ColorFadeEditor.bml | JavaWorld JavaBeans October 1999 |
001 <?xml version="1.0"?>
002
003 <!-- Register class that converts objects (of type Color) to Color. -->
004 <?bml register com.javaworld.JavaBeans.Oct99.ObjectColorConvertor?>
005
006 <!-- Create a frame to put the bean in -->
007 <bean class="java.awt.Frame" id="MainFrame">
008
009 <!-- Set the frame's title -->
010 <property name="title" value="Color Fade Bar"/>
011
012 <!-- Add a layout to the Frame. Notice that the type of property
013 need not be "String" -->
014 <property name="layout">
015 <bean class="java.awt.BorderLayout"/>
016 </property>
017
018 <!-- Create font bean for labels -->
019 <bean class="java.awt.Font" id="LabelFont">
020 <args>
021 <string>Sans-Serif</string>
022 <field target="class:java.awt.Font" name="BOLD"/>
023 <cast class="int"><string>12</string></cast>
024 </args>
025 </bean>
026
027 <!-- Add the ColorFadeBean to the frame -->
028 <add>
029 <bean class="com.javaworld.JavaBeans.Oct99.ColorFadeBean" id="FadeBar">
030
031 <!-- Note how the string "value" of each property is converted
032 automatically to the property type -->
033 <property name="width" value="300"/>
034 <property name="height" value="50"/>
035 <property name="message" value="Emeralds and Sapphires"/>
036 <property name="messageColor" value="0x4040ff"/>
037 <property name="colorFrom" value="0x80d080"/>
038 <property name="colorTo" value="0x8080d0"/>
039 <property name="fadeDirection" value="2"/>
040
041 <!-- Note how we set the textDirection property to the value
042 of a final static field that we "look up" from the
043 ColorFadeBar class. -->
044 <property name="textDirection">
045 <field target="class:com.javaworld.JavaBeans.Oct99.ColorFadeBar" name="CENTER"/>
046 </property>
047
048 <!-- In order to set a property of type Font, we need to construct
049 a Font object -->
050 <property name="messageFont">
051
052 <!-- The font object created here will be passed to the
053 set accessor for the messageFont property -->
054 <bean class="java.awt.Font">
055 <args>
056 <string>Sans-Serif</string>
057 <cast class="int"><string>1</string></cast>
058 <cast class="int"><string>24</string></cast>
059 </args>
060 </bean>
061 </property>
062 </bean>
063
064 <!-- This tells the layout to use the center -->
065 <string value="Center"/>
066 </add>
067
068 <!-- Put a panel below for color editors -->
069 <add>
070 <bean class="java.awt.Panel">
071 <args>
072 <bean class="java.awt.GridLayout">
073 <args>
074 <cast class="int"><string>1</string></cast> <!-- rows -->
075 <cast class="int"><string>3</string></cast> <!-- cols -->
076 <cast class="int"><string>10</string></cast> <!-- pad -->
077 <cast class="int"><string>10</string></cast> <!-- pad -->
078 </args>
079 </bean>
080 </args>
081
082 <property name="background" value="0xe0e0e0"/>
083
084 <!-- Add a ColorChooser to edit the messageColor of the FadeBar -->
085 <add>
086 <bean class="com.javaworld.JavaBeans.Oct99.ColorChooser" id="TextColorEditor">
087 <args>
088 <property target="FadeBar" name="messageColor"/>
089 </args>
090 <property name="label" value="Text Color"/>
091 <property name="labelFont">
092 <bean source="LabelFont"/>
093 </property>
094 </bean>
095 </add>
096
097 <!-- Add a ColorChooser to edit the fromColor of the FadeBar -->
098 <add>
099 <bean class="com.javaworld.JavaBeans.Oct99.ColorChooser" id="FromColorEditor">
100 <args>
101 <property target="FadeBar" name="colorFrom"/>
102 </args>
103 <property name="label" value="From Color"/>
104 <property name="labelFont">
105 <bean source="LabelFont"/>
106 </property>
107 </bean>
108 </add>
109
110 <!-- Add a ColorChooser to edit the toColor of the FadeBar -->
111 <add>
112 <bean class="com.javaworld.JavaBeans.Oct99.ColorChooser" id="ToColorEditor">
113 <args>
114 <property target="FadeBar" name="colorTo"/>
115 </args>
116 <property name="label" value="To Color"/>
117 <property name="labelFont">
118 <bean source="LabelFont"/>
119 </property>
120 </bean>
121 </add>
122
123 </bean>
124
125 <!-- Second argument to adder for layout -->
126 <string value="South"/>
127
128 </add>
129
130 <!-- This panel contains a TextField used to edit the string -->
131 <add>
132 <bean class="java.awt.Panel">
133
134 <property name="layout">
135 <bean class="java.awt.BorderLayout"/>
136 </property>
137
138 <!-- Add the TextField, and initialize it to the contents of
139 the FadeBar -->
140 <add>
141 <bean class="java.awt.TextField" id="TextEditor">
142 <args><cast class="int"><string value="80"/></cast></args>
143 <property name="text">
144 <property target="FadeBar" name="message"/>
145 </property>
146 </bean>
147 </add>
148
149 </bean>
150
151 <string value="North"/>
152
153 </add>
154
155 <!-- ****************************************************************
156 Event bindings
157 **************************************************************** -->
158
159 <!-- Uncomment this to update only on ENTER -->
160 <!--
161 <event-binding target="TextEditor" name="action">
162 <script>
163 <property target="FadeBar" name="message">
164 <property target="TextEditor" name="text"/>
165 </property>
166 <call-method target="FadeBar" name="repaint"/>
167 </script>
168 </event-binding>
169 -->
170
171 <!-- This binding updates FadeBar's Message property on each keystroke -->
172 <event-binding target="TextEditor" name="text">
173 <script>
174 <property target="FadeBar" name="message">
175 <property target="TextEditor" name="text"/>
176 </property>
177 <call-method target="FadeBar" name="repaint"/>
178 </script>
179 </event-binding>
180
181 <!-- Update FadeBar's color when TextColorEditor has a propertyChange -->
182 <event-binding target="TextColorEditor" name="propertyChange">
183 <script>
184
185 <!-- This is just to demonstrate using a static field, using
186 System.out.println() to print the color in the color editor -->
187
188 <bean source="class:java.lang.System">
189 <field name="out" id="OUT"/>
190 <call-method target="OUT" name="println">
191 <call-method target="TextColorEditor" name="getColor"/>
192 </call-method>
193 </bean>
194
195 <property target="FadeBar" name="messageColor">
196 <cast class="java.awt.Color">
197 <call-method target="TextColorEditor" name="getColor"/>
198 </cast>
199 </property>
200 <call-method target="FadeBar" name="repaint"/>
201 </script>
202 </event-binding>
203
204 <!-- Update FadeBar's colorFrom when FromColorEditor has a propertyChange -->
205 <event-binding target="FromColorEditor" name="propertyChange">
206 <script>
207 <property target="FadeBar" name="colorFrom">
208 <cast class="java.awt.Color">
209 <call-method target="FromColorEditor" name="getColor"/>
210 </cast>
211 </property>
212 <call-method target="FadeBar" name="repaint"/>
213 </script>
214 </event-binding>
215
216 <!-- Update FadeBar's colorTo when ToColorEditor has a propertyChange -->
217 <event-binding target="ToColorEditor" name="propertyChange">
218 <script>
219 <property target="FadeBar" name="colorTo">
220 <call-method target="ToColorEditor" name="getColor"/>
221 </property>
222 <call-method target="FadeBar" name="repaint"/>
223 </script>
224 </event-binding>
225
226 </bean>
227