cheri 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -6,21 +6,394 @@ based on the framework, as well as a builder-builder tool for easily creating
6
6
  simple builders. Cheri also comes with a demo application, Cheri::JRuby::Explorer,
7
7
  that is built using two of the supplied builders (Cheri::Swing and Cheri::Html).
8
8
 
9
- This version (0.0.5) is an early beta release. Some features are not yet fully
10
- developed, in particular the HTML/XML components. On the other hand, Cheri::Swing,
11
- which is the successor to JRBuilder (http://www2.webng.com/bdortch/jrbuilder), is
12
- relatively mature, in an adolescent sort of way, though many features could be added.
9
+ This version (0.0.6) is an early beta release. Some features are still not fully
10
+ developed (though we're getting close). So do expect some bugs, especially in
11
+ Cheri::JRuby::Explorer (CJX), which is very much a work in progress. I note some
12
+ known problems in the CJX section below.
13
13
 
14
- But do expect some bugs, especially in Cheri::JRuby::Explorer (CJX), which is very
15
- much a work in progress. I note some known problems in the section below.
16
-
17
- Documentation will be forthcoming over the next couple of days (from this writing,
18
- 8 June 2007), so watch the Cheri websites at RubyForge for updates:
14
+ Documentation will be forthcoming over the coming days, so watch the Cheri pages
15
+ at RubyForge for updates:
19
16
 
20
17
  http://cheri.rubyforge.org/
21
18
  http://rubyforge.org/projects/cheri
22
19
 
23
- In the meantime, here is a very brief summary of CJX.
20
+
21
+ == Quick Start
22
+
23
+ Cheri builders are mixin modules; to use one, you include it in a class. The builder's
24
+ functionality is available to instances of that class, and any subclasses (unless the
25
+ including class is Object � inclusion in Object / at the top level is supported, but
26
+ discouraged; inheritance is disabled in that case).
27
+
28
+ require 'rubygems'
29
+ require 'cheri/swing'
30
+ ...
31
+ include Cheri::Swing
32
+
33
+ All Cheri builders implement a +cheri+ method (the _proxy_ method), which plays two roles,
34
+ depending on how it's called. When called with a block, the cheri method enables Cheri
35
+ builder syntax within its scope for all included builders. When called without a block,
36
+ it returns a CheriProxy object that can act as a receiver for builder methods, for any
37
+ included builder.
38
+
39
+ @frame = cheri.frame('Hello!') #=> JFrame (for Cheri::Swing)
40
+
41
+ cheri {
42
+ @frame = frame('Hello!')
43
+ }
44
+
45
+ The +cheri+ method is also used to set global Cheri options. Currently only one
46
+ global option, +alias+, is defined:
47
+
48
+ cheri[:alias=>[:cbox,:check_box,:tnode,:default_mutable_tree_node]]
49
+
50
+ cheri.cbox #=> JCheckBox (Cheri::Swing)
51
+ cheri.tnode #=> DefaultMutableTreeNode (Cheri::Swing)
52
+
53
+ Each built-in Cheri builder also supplies its own proxy method (in addition to the +cheri+
54
+ method): +swing+ for Cheri::Swing (and also +awt+, since Cheri::Swing includes Cheri::AWT),
55
+ +html+ for Cheri::Html, and +xml+ for Cheri::Xml. These methods play the same dual
56
+ scoping/proxy roles as the +cheri+ method, but apply only to their respective builders.
57
+ (Each also provides additional functionality; see the sections on individual builders for details.)
58
+ The builder-specific proxy methods also serve to disambiguate overloaded builder method names:
59
+
60
+ swing.frame #=> javax.swing.JFrame
61
+ awt.frame #=> java.awt.Frame
62
+ html.frame #=> HTML frame (Cheri::Html::EmptyElem)
63
+
64
+ === Cheri::Swing
65
+
66
+ To include:
67
+
68
+ require 'rubygems'
69
+ require 'cheri/swing'
70
+ ...
71
+ include Cheri::Swing
72
+
73
+ Note that inclusion at the top level is not recommended.
74
+
75
+ Options:
76
+
77
+ swing[:auto]
78
+ swing[:auto=>true] #=> Enables auto mode (no swing/cheri block required)
79
+
80
+ Cheri::Swing (which includes Cheri::AWT) includes methods (Ruby-cased class names)
81
+ for all javax.swing, javax.swing.border and java.awt classes, plus many in javax.swing.table,
82
+ javax.swing.tree, java.awt.image and java.awt.geom. You can extend Cheri::Swing with other
83
+ classes/packages (including 3rd party, or your own!) using the Cheri builder-builder's
84
+ +build_package+ method.
85
+
86
+ Cheri::Swing (and any other builder based on Cheri::Java) also provides easy-to-use
87
+ on_xxx methods to implement event listeners. Any event listener supported by a class
88
+ (through an addXxxListener method) can be accessed from Cheri::Swing using an on_xxx method
89
+ (where xxx is the Ruby-cased event-method name). Because it is so widely used in Swing,
90
+ the ActionListener#actionPerformed event method is aliased as on_click:
91
+
92
+ @frame = swing.frame('Hello') {
93
+ size 500,500
94
+ flow_layout
95
+ on_window_closing {|event| @frame.dispose}
96
+ button('Hit me') {
97
+ on_click { puts 'button clicked' }
98
+ }
99
+ }
100
+
101
+ The +cherify+ and +cheri_yield+ methods can be used to incorporate objects created
102
+ outside the Cheri::Swing framework (+cherify+), or to re-introduce objects created
103
+ earlier within the framework (+cheri_yield+):
104
+
105
+ class MyButton < javax.swing.JButton
106
+ ...
107
+ end
108
+ ...
109
+ a_button = MyButton.new
110
+ ...
111
+ @frame = swing.frame('Hello') {
112
+ size 500,500
113
+ flow_layout
114
+ cherify(a_button) {
115
+ on_click { puts 'button clicked' }
116
+ }
117
+ }
118
+
119
+ @frame = swing.frame('Hello') {
120
+ menu_bar {
121
+ @file_menu = menu('File') {
122
+ menu_item('Exit') {on_click {@frame.dispose } }
123
+ }
124
+ }
125
+ }
126
+ # => add a new item later:
127
+ cheri_yield(@file_menu) {
128
+ menu_item('Open...') {
129
+ on_click { ... }
130
+ }
131
+ }
132
+
133
+ The Cheri builder-builder can be used to extend Cheri::Swing in a couple of ways.
134
+ Individual classes can be included using the +build+ statement, while entire
135
+ packages can be included using the +build_package+ statement. Note that you may
136
+ need to supply connection logic if the incorporated classes use methods other
137
+ than +add+ to connect child objects to parent objects; see file
138
+ /lib/cheri/builder/swing/connecter.rb for many examples.
139
+
140
+ // Java:
141
+ package my.pkg;
142
+ public class MyParent extends javax.swing.JComponent {
143
+ ...
144
+ public void addChild(MyChild child) {
145
+ ...
146
+ }
147
+ }
148
+ ...
149
+ public class MyChild {
150
+ ...
151
+ }
152
+
153
+ # JRuby:
154
+ require 'cheri/swing'
155
+ ...
156
+ include Cheri::Swing
157
+ ...
158
+ # easy-to-reference names; could use include_package instead
159
+ MyParent = Java::my.pkg.MyParent
160
+ MyChild = Java::my.pkg.MyChild
161
+
162
+ # example specifying each class; 'custom' names may be specified
163
+ MyBuilder = Cheri::Builder.new_builder do
164
+ extend_builder Cheri::Swing
165
+ build MyParent,:pappy
166
+ build MyChild,:kiddo
167
+ type MyParent do
168
+ connect MyChild,:addChild
169
+ end
170
+ end
171
+
172
+ include MyBuilder
173
+ @frame = swing.frame('My test') {
174
+ ...
175
+ panel {
176
+ pappy {
177
+ kiddo { ... }
178
+ }
179
+ }
180
+ }
181
+
182
+ # example specifying package; default naming
183
+ MyBuilder = Cheri::Builder.new_builder do
184
+ extend_builder Cheri::Swing
185
+ build_package 'my.package'
186
+ type MyParent do
187
+ connect MyChild,:addChild
188
+ end
189
+ end
190
+
191
+ include MyBuilder
192
+ @frame = swing.frame('My test') {
193
+ ...
194
+ panel {
195
+ my_parent {
196
+ my_child { ... }
197
+ }
198
+ }
199
+ }
200
+
201
+ You can also use the builder-builder just to add conection logic to Cheri::Swing,
202
+ as not every possible connection type is defined.
203
+
204
+ See the Cheri::JRuby::Explorer (CJX) code (under lib/cheri/jruby/explorer) for
205
+ extensive examples of Cheri::Swing usage.
206
+
207
+ === Cheri::Xml
208
+
209
+ To include:
210
+
211
+ require 'rubygems'
212
+ require 'cheri/xml'
213
+ ...
214
+ include Cheri::Xml
215
+
216
+ Note that inclusion at the top level is not recommended.
217
+
218
+ Options:
219
+
220
+ xml[:any]
221
+ xml[:any=>true] #=> Any tag name inside xml {} will be accepted
222
+
223
+ xml[:accept=>[:aaa,:bbb,:nnn]] #=> only specified tag names accepted
224
+ (see builder-builder example below for alternative approach)
225
+
226
+ xml[:format]
227
+ xml[:format=>true] #=> output formatted with line-feeds only
228
+
229
+ xml[:indent] #=> output indented by 2 spaces per level
230
+ xml[:indent=>nnn] #=> output indented by nnn spaces per level
231
+
232
+ xml[:margin=>nnn] #=> output indented by margin (in addition to :indent)
233
+
234
+ xml[:esc]
235
+ xml[:esc=>true] #=> output will be escaped (off by default for performance)
236
+
237
+ xml[:ns=>:xxx] #=> declare xxx as a namespace prefix
238
+ xml[:ns=>[:xxx,:yyy,:zzz...]] #=> declare xxx,yyy,zzz as namespace prefixes
239
+
240
+ xml[:alias=>[:alias1,:name1,:alias2,:name2...] #=> declare tag aliases
241
+
242
+ xml[:attr=>[:alias1,:attr1...]] #=> declare attribute aliases
243
+
244
+ Options specified using xml[opts] apply to all threads for an instance.
245
+ Options specified using xml(opts) apply only to the current thread/scope:
246
+
247
+ # example
248
+ xml[:any=>true,:indent=>3,:esc=>false]
249
+ @out = xml {
250
+ # nothing escaped at this level
251
+ aaa{
252
+ bbb {
253
+ xml(:esc=>true) {
254
+ # everything escaped in this scope
255
+ ddd { ... }
256
+ eee { ... }
257
+ }}}}
258
+
259
+ The result of an +xml+ block will be one of several types of object, depending
260
+ on the tags used and how they are invoked. The result object can be coerced to a String,
261
+ directly by calling its #to_s method, or indirectly by using << to append it to a
262
+ String or IO stream. The #to_s method also takes an optional String/stream parameter;
263
+ for streams, this is the most efficient way to render the XML.
264
+
265
+ # example
266
+ xml[:any,:indent]
267
+ @result = xml{
268
+ aaa(:an_attr='a value',:another=>'value 2') {
269
+ bbb { ccc }
270
+ }
271
+ }
272
+ puts @result #=> XML
273
+ @result.to_s #=> XML
274
+ a_string << @result #=> appends XML
275
+ a_stream << @result #=> appends XML
276
+ @result.to_s(a_string) #=> appends XML more efficiently
277
+ @result.to_s(a_stream) #=> appends XML more efficiently
278
+
279
+ # result:
280
+ <?xml version="1.0" encoding="UTF-8"?>
281
+ <aaa another="value 2" an_attr="a value">
282
+ <bbb>
283
+ <ccc />
284
+ </bbb>
285
+ </aaa>
286
+
287
+ To omit the XML declaration, use +xml+ as the receiver for the initial element:
288
+
289
+ xml.aaa{bbb}
290
+ # result
291
+ <aaa>
292
+ <bbb />
293
+ </aaa>
294
+
295
+ Alias element names that are lengthy, or can't be used directly in Ruby:
296
+
297
+ xml[:alias=>[:cls,:class]]
298
+ xml.aaa{cls}
299
+ # result
300
+ <aaa>
301
+ <class />
302
+ </aaa>
303
+
304
+ Declare namespace prefixes, and apply them directly (using myns.tag or myns::tag), or
305
+ apply them to all elements in a scope:
306
+
307
+ xml[:alias=>[:env,:Envelope,:hdr,:Header,:body,:Body]]
308
+ xml[:ns=>:soap]
309
+ xml { soap {
310
+ env(:xxx=>'yyy') {
311
+ hdr
312
+ body
313
+ }}}
314
+
315
+ # result
316
+ <?xml version="1.0" encoding="UTF-8"?>
317
+ <soap:Envelope xxx="yyy">
318
+ <soap:Header />
319
+ <soap:Body />
320
+ </soap:Envelope>
321
+
322
+ Use no_ns to turn off a namespace, or specify a different namespace:
323
+
324
+ xml[:alias=>[:env,:Envelope,:hdr,:Header,:body,:Body]]
325
+ xml[:ns=>[:soap,:xx]]
326
+ xml {
327
+ aaa {
328
+ soap { env {
329
+ hdr
330
+ body {
331
+ no_ns {
332
+ bbb
333
+ xx::ccc
334
+ ddd
335
+ xx {eee; fff}
336
+ }}}}}}
337
+
338
+ # result
339
+ <?xml version="1.0" encoding="UTF-8"?>
340
+ <aaa>
341
+ <soap:Envelope>
342
+ <soap:Header />
343
+ <soap:Body>
344
+ <bbb />
345
+ <xx:ccc />
346
+ <ddd />
347
+ <xx:eee />
348
+ <xx:fff />
349
+ </soap:Body>
350
+ </soap:Envelope>
351
+ </aaa>
352
+
353
+ Use the Cheri builder-builder to define more explicit element relationships:
354
+
355
+ require 'cheri/xml'
356
+
357
+ my_content_elems = [:aaa,:bbb,:ccc]
358
+ my_empty_elems = [:xxx,:yyy]
359
+
360
+ MyBuilder = Cheri::Builder.new_builder do
361
+ extend_builder Cheri::Xml
362
+ build Cheri::Xml::Elem,my_content_elems
363
+ build Cheri::Xml::EmptyElem,my_empty_elems
364
+ symbol :aaa { connect :bbb,:ccc }
365
+ symbol :bbb { connect :xxx }
366
+ symbol :ccc { connect :yyy }
367
+ # raise error to prevent non-connects from silently failing
368
+ type Cheri::Xml::XmlElement do
369
+ connect Cheri::Xml::XmlElement do |parent,child|
370
+ raise TypeError,"can't add #{child.sym} to #{parent.sym}"
371
+ end
372
+ end
373
+ end
374
+ include Cheri::Xml
375
+ include MyBuilder
376
+
377
+ === Cheri::Html
378
+
379
+ Documentation TBD
380
+
381
+ Options:
382
+
383
+ html[:format]
384
+ html[:format=>true] #=> output formatted with line-feeds only
385
+
386
+ html[:indent] #=> output indented by 2 spaces per level
387
+ html[:indent=>nnn] #=> output indented by nnn spaces per level
388
+
389
+ html[:margin=>nnn] #=> output indented by margin (in addition to :indent)
390
+
391
+ html[:esc]
392
+ html[:esc=>true] #=> output will be escaped (off by default for performance)
393
+
394
+ === Cheri builder-builder
395
+
396
+ Documentation TBD
24
397
 
25
398
  == Cheri::JRuby::Explorer (CJX)
26
399
 
@@ -46,8 +419,7 @@ Alternatively, you can load and run it in one step:
46
419
  require 'cheri/cjx'
47
420
 
48
421
  This will take several seconds to load and start -- performance will be one area
49
- of improvement for versions 0.0.6 and beyond. Once it loads, it should be fairly
50
- clear what to do.
422
+ of ongoing improvement. Once it loads, it should be fairly clear what to do.
51
423
 
52
424
  Some known issues:
53
425
 
@@ -60,8 +432,8 @@ Some known issues:
60
432
  GridBagLayout. Ugh.
61
433
 
62
434
  * Global variables are currently shown, um, globally, when many of them should be shown
63
- per thread. This will be fixed in 0.0.6, which will include a Thread section with
64
- other goodies as well (thread-local vars, status, etc.).
435
+ per thread. This will be fixed in a later version, which will include a Thread section
436
+ with other goodies as well (thread-local vars, status, etc.).
65
437
 
66
438
  To install the CJX DRb server component in an instance (assuming the Cheri gem is
67
439
  installed):
@@ -87,4 +459,4 @@ Please visit the Cheri site for more documentation, I'll be continually adding t
87
459
  in the coming days.
88
460
 
89
461
  Bill Dortch <cheri.project@gmail.com>
90
- 10 June 2007
462
+ 19 June 2007
data/lib/cheri/awt.rb CHANGED
@@ -22,8 +22,10 @@
22
22
  #++
23
23
  #
24
24
 
25
- if (defined?JRUBY_VERSION) && 0 == (JRUBY_VERSION =~ /(\d+\.\d+\.\d+)([-\.A-Z0-9]*)/) &&
26
- (($1 == '1.0.0' && ($2.empty? || $2 >= 'RC3')) || $1 > '1.0.0')
25
+ if (defined?JRUBY_VERSION) &&
26
+ ((JRUBY_VERSION =~ /^(\d+\.\d+\.\d+)([-\.A-Z0-9]*)/ &&
27
+ (($1 == '1.0.0' && ($2.empty? || $2 >= 'RC3')) || $1 > '1.0.0')) ||
28
+ (JRUBY_VERSION =~ /^(\d+\.\d+)([-\.A-Z0-9]*)/ && $1 >= '1.1'))
27
29
 
28
30
  require 'cheri/java/builder'
29
31
  require 'cheri/builder/awt/types'
data/lib/cheri/builder.rb CHANGED
@@ -24,6 +24,7 @@
24
24
 
25
25
  require 'cheri/cheri'
26
26
  require 'cheri/builder/base'
27
+ require 'cheri/builder/markup'
27
28
  require 'cheri/builder/config'
28
29
  require 'cheri/builder/connecter'
29
30
  require 'cheri/builder/context'