cheri 0.0.9 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,23 @@
1
+ # Cheri version of Sun's GridBagLayoutDemo.java demo.
2
+
3
+ # See http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbag.html
4
+
5
+ require 'rubygems'
6
+ require 'cheri/swing'
7
+
8
+ include Cheri::Swing
9
+
10
+ def later(&block)
11
+ javax.swing.SwingUtilities.invoke_later(&block)
12
+ end
13
+ later {
14
+ @frame = swing.frame('grid_bag_layout_demo') {|f|
15
+ grid_table_layout f, :wx=>0.1, :f=>:h
16
+ default_close_operation :EXIT_ON_CLOSE
17
+ grid_row{button 'Button 1'; button 'Button 2'; button 'Button 3'}
18
+ grid_row{button('Long-Named Button 4', :w=>3, :py=>40, :f=>:both){on_click{later{puts 'hi'}}}}
19
+ grid_row{button '5', :a=>:se, :x=>1, :w=>2, :wy=> 0.1, :i=>[10,0,0,0]}
20
+ }
21
+ @frame.pack
22
+ @frame.visible = true
23
+ }
@@ -0,0 +1,34 @@
1
+ require 'rubygems'
2
+ require 'cheri/swing'
3
+
4
+ include Cheri::Swing
5
+
6
+ swing.frame('Anchor/Align') {|f|
7
+ grid_table_layout f, :wx=>0.1, :wy=>0.1
8
+ size 480, 360
9
+ on_window_closing {f.dispose}
10
+ content_pane {background :BLUE}
11
+ grid_row{
12
+ button('NW', :align=>:nw, :colspan=>2) {on_click{puts 'boo'}}
13
+ button('RIGHT', :align=>:right) {on_click{puts 'boo'}}
14
+ }
15
+ grid_row{
16
+ button('CENTER', :align=>:center, :colspan=>3) {on_click{puts 'boo'}}
17
+ }
18
+ grid_row{
19
+ button('LEFT', :align=>:left, :colspan=>2) {on_click{puts 'boo'}}
20
+ button('SE', :align=>:se) {on_click{puts 'boo'}}
21
+ }
22
+ grid_row{
23
+ grid_table(:colspan=>3, :wx=>0.1, :wy=>0.1, :f=>:both, :i=>[64,16], :p=>[5,5]) {
24
+ defaults :wx=>0.1, :wy=>0.1
25
+ etched_border :RAISED
26
+ background :RED
27
+ grid_row(:i=>12){
28
+ checkbox 'who?', :a=>:left
29
+ checkbox 'what?', true
30
+ checkbox 'where?', :a=>:right
31
+ }
32
+ }
33
+ }
34
+ }.visible = true
@@ -0,0 +1,24 @@
1
+ require 'rubygems'
2
+ require 'cheri/swing'
3
+
4
+ include Cheri::Swing
5
+
6
+ swing.frame('Columns') {|f|
7
+ grid_table_layout f, :wx=>0.1#, :wy=>0.1
8
+ size 600, 400
9
+ on_window_closing {f.dispose}
10
+ grid_row(:f=>:h,:a=>:nw){
11
+ label 'Foo', :wx=>0.1
12
+ label 'Bar', :wx=>0.3
13
+ label 'Baz', :wx=>0.6
14
+ }
15
+ 10.times {|n|
16
+ grid_row(:f=>:h,:a=>:nw){
17
+ label('xxx'){background :RED; opaque true}
18
+ label('yyy'){background :GREEN; opaque true}
19
+ label('zzz'){background :BLUE; opaque true}
20
+ }
21
+ }
22
+ # empty row with weighty = 1.0, to force others to the top
23
+ grid_row{label '', :wy=>1.0}
24
+ }.visible = true
Binary file
@@ -38,7 +38,7 @@ class InstanceContext
38
38
  # InstanceContext.new(client,builder_modules) -> anInstanceContext
39
39
  #
40
40
  def initialize(client,cfg)
41
- @c = client
41
+ # @c = client
42
42
  @g = cfg
43
43
  # TODO: properties, aliases should probably be threadsafe hashes/maps,
44
44
  # though contention would be extremely unlikely given expected usage (any
@@ -57,9 +57,9 @@ class InstanceContext
57
57
  end
58
58
  end
59
59
 
60
- def client
61
- @c
62
- end
60
+ # def client
61
+ # @c
62
+ # end
63
63
 
64
64
  def cfg
65
65
  @g
@@ -104,6 +104,7 @@ class InstanceContext
104
104
  def current
105
105
  key = @t ? Thread.current : Thread.current.__id__
106
106
  @h[key] ||= Context.new(self,@c)
107
+ # Thread.current[:cheri_ctx] ||= Context.new(self,nil)
107
108
  end
108
109
 
109
110
  # Overrides the default Object#inspect to prevent mind-boggling circular displays in IRB.
@@ -145,7 +146,7 @@ class Context
145
146
  @u = u.dup
146
147
  end
147
148
  @l = ictx.aliases
148
- @c = client
149
+ # @c = client
149
150
  @m = ConnectionMinder.new
150
151
  @s = [] # stack
151
152
  @p = {} # configuration properties
@@ -155,9 +156,9 @@ class Context
155
156
  @i
156
157
  end
157
158
 
158
- def client
159
- @c
160
- end
159
+ # def client
160
+ # @c
161
+ # end
161
162
 
162
163
  def auto
163
164
  # same mods or both nil
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (C) 2007,2008 William N Dortch <bill.dortch@gmail.com>
2
+ # Copyright (C) 2007,2008,2009 William N Dortch <bill.dortch@gmail.com>
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -29,8 +29,10 @@ class BuilderException < Cheri::CheriException; end
29
29
 
30
30
  class << self
31
31
  def append_features(clazz) #:nodoc:
32
- return super unless clazz.instance_of?(Class) &&
33
- !clazz.instance_variable_get(:@__cheri_cfg).instance_of?(Config)
32
+ # return super unless clazz.instance_of?(Class) &&
33
+ # !clazz.instance_variable_get(:@__cheri_cfg).instance_of?(Config)
34
+ return super unless Class === clazz &&
35
+ !(Config === clazz.instance_variable_get(:@__cheri_cfg))
34
36
  clazz.instance_variable_set(:@__cheri_cfg,Config.new(CheriModule))
35
37
  # we don't support subclassing for builder modules installed at the
36
38
  # top level (in Object). method_missing will be inherited, but will
@@ -1,5 +1,5 @@
1
1
  #--
2
- # Copyright (C) 2007,2008 William N Dortch <bill.dortch@gmail.com>
2
+ # Copyright (C) 2007,2008,2009 William N Dortch <bill.dortch@gmail.com>
3
3
  #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining
5
5
  # a copy of this software and associated documentation files (the
@@ -34,6 +34,7 @@ SwingConnecter = Cheri::Builder::TypeConnecter.new(Cheri::AWT::AWTConnecter) do
34
34
  S = java.lang.String.new ''
35
35
  TreePath = javax.swing.tree.TreePath
36
36
  GridBagConstraints = java.awt.GridBagConstraints
37
+ GridTableLayout = org.cheri.swing.layout.GridTableLayout
37
38
 
38
39
  type javax.swing.JComponent do
39
40
  connect javax.swing.border.Border, :setBorder
@@ -148,12 +149,14 @@ SwingConnecter = Cheri::Builder::TypeConnecter.new(Cheri::AWT::AWTConnecter) do
148
149
  table.add(comp,constraints)
149
150
  end
150
151
  else
151
- table.add(comp)
152
+ #table.add(comp)
153
+ # workaround intermittent JRuby bug with overloaded methods
154
+ table.add(comp,nil)
152
155
  end
153
156
  end
154
157
  connect org.cheri.swing.layout.GridRow do |table,row,sym,constraints|
155
- row.default_constraints = constraints if constraints && !constraints.empty?
156
- table.add_row row
158
+ #row.default_constraints = constraints if constraints && !constraints.empty?
159
+ table.add_row row, constraints
157
160
  end
158
161
  end
159
162
 
@@ -162,7 +165,29 @@ SwingConnecter = Cheri::Builder::TypeConnecter.new(Cheri::AWT::AWTConnecter) do
162
165
  if constraints && !constraints.empty?
163
166
  row.add(comp,constraints)
164
167
  else
165
- row.add(comp)
168
+ #row.add(comp)
169
+ # workaround intermittent JRuby bug with overloaded methods
170
+ row.add(comp, nil)
171
+ end
172
+ end
173
+ end
174
+
175
+ type java.awt.Container do
176
+ connect org.cheri.swing.layout.GridRow do |cnt,row,sym,constraints|
177
+ if GridTableLayout === (gtl = cnt.get_layout)
178
+ gtl.add_row row, constraints
179
+ else
180
+ warn "grid_row specified but layout is not GridTableLayout"
181
+ end
182
+ end
183
+ end
184
+
185
+ type javax.swing.RootPaneContainer do
186
+ connect org.cheri.swing.layout.GridRow do |cnt,row,sym,constraints|
187
+ if GridTableLayout === (gtl = cnt.content_pane.get_layout)
188
+ gtl.add_row row, constraints
189
+ else
190
+ warn "grid_row specified but layout is not GridTableLayout"
166
191
  end
167
192
  end
168
193
  end
@@ -0,0 +1,467 @@
1
+ #--
2
+ # Copyright (C) 2007,2008 William N Dortch <bill.dortch@gmail.com>
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+ #
24
+
25
+
26
+ module Cheri
27
+ # TODO: module comments
28
+
29
+ module Swing
30
+ VERSION = Cheri::VERSION
31
+
32
+ CJava = Cheri::Java #:nodoc:
33
+ CBuilder = Cheri::Builder #:nodoc:
34
+ JBuilder = Cheri::Java::Builder #:nodoc:
35
+ AWT = Cheri::AWT #:nodoc:
36
+ AWTFrame = Cheri::AWT::AWTFrame #:nodoc:
37
+ AWTProxy = Cheri::AWT::AWTProxy #:nodoc:
38
+ JComp = javax.swing.JComponent #:nodoc:
39
+ RPC = javax.swing.RootPaneContainer #:nodoc:
40
+ # types checked by cherify/cheri_yield logic
41
+ # TODO: more
42
+ SwingTypes = [
43
+ javax.swing.Action,
44
+ javax.swing.JComponent,
45
+ javax.swing.RootPaneContainer,
46
+ javax.swing.border.Border
47
+ ]
48
+ SwingPkg = 'javax.swing.'
49
+
50
+ class << self
51
+ def append_features(clazz)
52
+ CBuilder.module_included(Cheri::AWT,clazz)
53
+ CBuilder.module_included(JBuilder,clazz)
54
+ CBuilder.module_included(self,clazz)
55
+ super
56
+ end
57
+ private :append_features
58
+
59
+ def factory
60
+ SwingFactory
61
+ end
62
+
63
+ def connecter
64
+ SwingConnecter
65
+ end
66
+
67
+ def consumer
68
+ SwingConsumer
69
+ end
70
+
71
+ def resolver
72
+ SwingResolver
73
+ end
74
+
75
+ # a bit expensive, but only used by cherify/cheri_yield
76
+ def swing?(obj)
77
+ obj.respond_to?(:java_class) &&
78
+ (obj.java_class.name.rindex(SwingPkg,0) ||
79
+ !(obj.class.ancestors & SwingTypes).empty?)
80
+ end
81
+ end #self
82
+
83
+ # call-seq:
84
+ # awt([*args] [, &block]) -> AWTProxy if no block given, else result of block
85
+ #
86
+ #--
87
+ # Duplicating this here rather than including Cheri::AWT. (See note re: performance)
88
+ #++
89
+ def awt(*r,&k)
90
+ if ctx = __cheri_ctx
91
+ if k
92
+ AWTFrame.new(ctx,*r,&k).run
93
+ else
94
+ ctx[:awt_proxy] ||= AWTProxy.new(ctx,*r)
95
+ end
96
+ end
97
+ end
98
+ private :awt
99
+
100
+ # call-seq:
101
+ # swing([*args] [, &block]) -> SwingProxy if no block given, else result of block
102
+ #
103
+ def swing(*r,&k)
104
+ if ctx = __cheri_ctx
105
+ if k
106
+ if ctx.empty? && (c = ctx.client).kind_of?(RPC) || c.kind_of?(JComp)
107
+ ctx.fsend(CheriYieldFactory,:cheri_yield,c,&k)
108
+ else
109
+ SwingFrame.new(ctx,*r,&k).run
110
+ end
111
+ else
112
+ ctx[:swing_proxy] ||= SwingProxy.new(ctx,*r)
113
+ end
114
+ end
115
+ end
116
+ private :swing
117
+
118
+ AnyTypes = {
119
+ javax.swing.ButtonGroup => true
120
+ }
121
+
122
+ class BaseBuilder < Cheri::Java::Builder::BaseBuilder
123
+ JF = CJava.get_class('javax.swing.JFrame')
124
+
125
+ def mod
126
+ Cheri::Swing
127
+ end
128
+
129
+ def any?
130
+ @any
131
+ end
132
+
133
+ private
134
+ def post
135
+ @obj.icon_image ||= CJava.cheri_icon.image if @obj.kind_of?(JF)
136
+ if AnyTypes[@clazz]
137
+ @any = true
138
+ @not_parent = true
139
+ @not_child = true
140
+ end
141
+ end
142
+ end #BaseBuilder
143
+
144
+ class ClassBuilder < BaseBuilder
145
+ def initialize(ctx,sym,clazz,*args,&block)
146
+ super(ctx,sym,*args,&block)
147
+ @clazz = clazz
148
+ @resolve = true
149
+ end
150
+ private
151
+ def create
152
+ @obj = @clazz.new(*@args)
153
+ end
154
+ end #ClassBuilder
155
+
156
+ class ProcBuilder < BaseBuilder
157
+ def initialize(ctx,sym,proc,*args,&block)
158
+ super(ctx,sym,*args,&block)
159
+ @proc = proc
160
+ end
161
+ private
162
+ def create
163
+ @obj = @proc.call(*@args)
164
+ @clazz = @obj.class
165
+ @resolve = true
166
+ end
167
+ end #ProcBuilder
168
+
169
+ class CherifyBuilder < BaseBuilder
170
+ def initialize(ctx,sym,obj,*args,&block)
171
+ super(ctx,sym,*args,&block)
172
+ @obj = obj
173
+ @clazz = obj.class
174
+ @no_create = true
175
+ @resolve = true
176
+ end
177
+ end #CherifyBuilder
178
+
179
+ class CheriYieldBuilder < BaseBuilder
180
+ def initialize(ctx,sym,obj,*args,&block)
181
+ super(ctx,sym,*args,&block)
182
+ @obj = obj
183
+ @clazz = obj.class
184
+ @no_create = true
185
+ @not_child = true
186
+ @resolve = true
187
+ end
188
+ end #CheriYieldBuilder
189
+
190
+ # TODO: comments
191
+ module CherifyFactory
192
+ S = ::Cheri::Swing #:nodoc:
193
+ def self.builder(ctx,sym,*args,&block)
194
+ return nil unless sym == :cherify && !args.empty? && S.swing?(args[0])
195
+ raise Cheri.argument_error(args.length,1..2) unless args.length == 1 || args.length == 2
196
+ CherifyBuilder.new(ctx,sym,*args,&block)
197
+ end
198
+ end #CherifyFactory
199
+
200
+ # TODO: comments
201
+ module CheriYieldFactory # < Cheri::AbstractFactory
202
+ S = ::Cheri::Swing #:nodoc:
203
+ def self.builder(ctx,sym,*args,&block)
204
+ return nil unless sym == :cheri_yield && !args.empty? && S.swing?(args[0])
205
+ raise Cheri.argument_error(args.length,1) unless args.length == 1
206
+ CheriYieldBuilder.new(ctx,sym,*args,&block)
207
+ end
208
+ end #CheriYieldFactory
209
+
210
+ # TODO: comments
211
+ module StandardFactory
212
+ def self.builder(ctx,sym,*args,&block)
213
+ clazz = Types.get_class(sym)
214
+ clazz ? ClassBuilder.new(ctx,sym,clazz,*args,&block) : nil
215
+ end
216
+ end #StandardFactory
217
+
218
+ module GridTableFactory
219
+ SwingLayout = org.cheri.swing.layout
220
+ @names = [:grid_table,:grid_row,:empty_cell]
221
+ def self.builder(ctx,sym,*args,&block)
222
+ if sym == :grid_table
223
+ ClassBuilder.new(ctx,sym,SwingLayout::GridTable,*args,&block)
224
+ elsif sym == :grid_row
225
+ ClassBuilder.new(ctx,sym,SwingLayout::GridRow,*args,&block)
226
+ elsif sym == :empty_cell
227
+ ClassBuilder.new(ctx,sym,SwingLayout::EmptyCell,*args,&block)
228
+ else
229
+ nil
230
+ end
231
+ end
232
+ def self.names
233
+ @names
234
+ end
235
+ end
236
+
237
+ module BoxComponentFactory
238
+ CJava = Cheri::Java
239
+ X_AXIS = 0
240
+ Y_AXIS = 1
241
+ LINE_AXIS = 2
242
+ PAGE_AXIS = 3
243
+ RPC = javax.swing.RootPaneContainer
244
+ @box = nil
245
+ @box_layout = nil
246
+ @panel = nil
247
+ @dimension = nil
248
+ @procs = {}
249
+ class << self
250
+ def builder(ctx,sym,*args,&block)
251
+ proc = @procs[sym]
252
+ proc ? ProcBuilder.new(ctx,sym,proc,*args,&block) : nil
253
+ end
254
+ def box
255
+ @box ||= CJava.get_class('javax.swing.Box')
256
+ end
257
+ def box_layout
258
+ @box_layout ||= CJava.get_class('javax.swing.BoxLayout')
259
+ end
260
+ def panel
261
+ @panel ||= CJava.get_class('javax.swing.JPanel')
262
+ end
263
+ def dimension
264
+ @dimension ||= CJava.get_class('java.awt.Dimension')
265
+ end
266
+ def names
267
+ @names ||= @procs.keys
268
+ end
269
+ end #self
270
+
271
+ @procs[:box_layout] =
272
+ Proc.new do |obj,axis|
273
+ iaxis = case axis
274
+ when :X_AXIS : X_AXIS
275
+ when :Y_AXIS : Y_AXIS
276
+ when :LINE_AXIS : LINE_AXIS
277
+ when :PAGE_AXIS : PAGE_AXIS
278
+ else axis
279
+ end
280
+ box_layout.new(obj.kind_of?(RPC) ? obj.content_pane : obj,iaxis)
281
+ end
282
+ @procs[:x_box] = @procs[:h_box] = @procs[:horizontal_box] = Proc.new { box.new(X_AXIS) }
283
+ @procs[:y_box] = @procs[:v_box] = @procs[:vertical_box] = Proc.new { box.new(Y_AXIS) }
284
+ @procs[:line_box] = Proc.new { box.new(LINE_AXIS) }
285
+ @procs[:page_box] = Proc.new { box.new(PAGE_AXIS) }
286
+ @procs[:x_panel] = @procs[:h_panel] = @procs[:horizontal_panel] =
287
+ Proc.new do |*args|
288
+ p = panel.new(*args)
289
+ p.setLayout(box_layout.new(p,X_AXIS))
290
+ p
291
+ end
292
+ @procs[:y_panel] = @procs[:v_panel] = @procs[:vertical_panel] =
293
+ Proc.new do |*args|
294
+ p = panel.new(*args)
295
+ p.setLayout(box_layout.new(p,Y_AXIS))
296
+ p
297
+ end
298
+ @procs[:line_panel] =
299
+ Proc.new do |*args|
300
+ p = panel.new(*args)
301
+ p.setLayout(box_layout.new(p,LINE_AXIS))
302
+ p
303
+ end
304
+ @procs[:page_panel] =
305
+ Proc.new do |*args|
306
+ p = panel.new(*args)
307
+ p.setLayout(box_layout.new(p,PAGE_AXIS))
308
+ p
309
+ end
310
+ @procs[:glue] = Proc.new { box.createGlue }
311
+ @procs[:x_glue] = @procs[:h_glue] = @procs[:horizontal_glue] = Proc.new { box.createHorizontalGlue }
312
+ @procs[:y_glue] = @procs[:v_glue] = @procs[:vertical_glue] = Proc.new { box.createVerticalGlue }
313
+ @procs[:x_strut] = @procs[:h_strut] = @procs[:horizontal_strut] =
314
+ Proc.new do |*args|
315
+ box.createHorizontalStrut(*args)
316
+ end
317
+ @procs[:y_strut] = @procs[:v_strut] = @procs[:vertical_strut] =
318
+ Proc.new do |*args|
319
+ box.createVerticalStrut(*args)
320
+ end
321
+ @procs[:rigid_area] = @procs[:spacer] =
322
+ Proc.new do |*args|
323
+ box.createRigidArea(dimension.new(*args))
324
+ end
325
+ @procs[:x_spacer] = @procs[:h_spacer] = @procs[:horizontal_spacer] =
326
+ Proc.new do |*args|
327
+ box.createRigidArea(dimension.new(args[0],0))
328
+ end
329
+ @procs[:y_spacer] = @procs[:v_spacer] = @procs[:vertical_spacer] =
330
+ Proc.new do |*args|
331
+ box.createRigidArea(dimension.new(0,args[0]))
332
+ end
333
+ @procs[:filler] =
334
+ Proc.new do |*args|
335
+ box::Filler.new(dimension.new(args[0],args[1]),
336
+ dimension.new(args[2],args[3]),
337
+ dimension.new(args[4],args[5]))
338
+ end
339
+ end #BoxComponentFactory
340
+
341
+
342
+ # TODO: more factories
343
+
344
+ module DialogComponentFactory
345
+ CJava = Cheri::Java
346
+
347
+ end #DialogComponentFactory
348
+
349
+
350
+ SwingFactory = Cheri::Builder::SuperFactory.new do |f|
351
+ f << StandardFactory
352
+ f << GridTableFactory
353
+ f << BoxComponentFactory
354
+ f << Cheri::AWT::StandardFactory
355
+ f << CheriYieldFactory
356
+ f << CherifyFactory
357
+ f << Cheri::Java::Builder::CheriYieldFactory
358
+ f << Cheri::Java::Builder::CherifyFactory
359
+ f << Cheri::Builder::CheriYieldFactory
360
+ f << Cheri::Builder::CherifyFactory
361
+ end
362
+
363
+ class SwingProxy < Cheri::AWT::AWTProxy
364
+
365
+ impl(Types.names)
366
+ impl(BoxComponentFactory.names)
367
+ impl(GridTableFactory.names)
368
+
369
+ def initialize(ctx,*r)
370
+ super
371
+ if Hash === r.last
372
+ @ctx.auto!(mod) if r.last[:auto]
373
+ end
374
+ end
375
+
376
+ def mod
377
+ Cheri::Swing
378
+ end
379
+ private :mod
380
+
381
+ def [](opts)
382
+ raise Cheri.type_error(opts,Hash,Symbol) unless Hash === opts || Symbol === opts
383
+ if opts == :auto || (Hash === opts && opts[:auto])
384
+ @ctx.ictx.auto!(mod)
385
+ @ctx.auto!(mod)
386
+ # if (c = @ctx.client).kind_of?(RPC) || c.kind_of?(JComp)
387
+ # @ctx.push(b = CheriYieldBuilder.new(@ctx,:cheri_yield,c))
388
+ # b.run
389
+ # else
390
+ # @ctx.push(SwingFrame.new(@ctx))
391
+ # end
392
+ end
393
+ nil
394
+ end
395
+ end #SwingProxy
396
+
397
+ class SwingFrame
398
+ include Cheri::Builder::Frame
399
+ def initialize(ctx,*r,&k)
400
+ super
401
+ @obj = ctx[:swing_proxy] ||= SwingProxy.new(ctx,*r)
402
+ end
403
+
404
+ def mod
405
+ Cheri::Swing
406
+ end
407
+ end #SwingFrame
408
+
409
+ SwingResolver = Cheri::Java::Builder::ConstantResolver.new do |r|
410
+ r << Cheri::AWT::Constants
411
+ r << Constants
412
+ end
413
+
414
+ module AlignMethodConsumer
415
+ BOTTOM = 1.0
416
+ CENTER = 0.5
417
+ LEFT = 0.0
418
+ RIGHT = 1.0
419
+ TOP = 0.0
420
+ JComp = javax.swing.JComponent
421
+
422
+ def self.consume(ctx,bld,sym,*args,&k)
423
+ return false,nil unless sym == :align && (obj = bld.object).kind_of?(JComp)
424
+ argc = args.length
425
+ raise Cheri.new_argument_error(argc,1..2) unless argc == 1 || argc == 2
426
+ x_val = nil
427
+ y_val = nil
428
+ 0.upto(argc-1) do |i|
429
+ arg = args[i]
430
+ if arg.kind_of?(Numeric)
431
+ unless argc == 2
432
+ raise ArgumentError,"align can't evaluate numeric value with only one argument -- specify both x and y"
433
+ end
434
+ i == 0 ? x_val = arg : y_val = arg
435
+ else
436
+ raise ArgumentError,"invalid argument for align: #{arg}" unless arg.instance_of?(Symbol)
437
+ case arg
438
+ when :TOP : y_val = TOP
439
+ when :BOTTOM : y_val = BOTTOM
440
+ when :LEFT : x_val = LEFT
441
+ when :RIGHT : x_val = RIGHT
442
+ when :CENTER :
443
+ if argc ==2
444
+ i == 0 ? x_val = CENTER : y_val = CENTER
445
+ else
446
+ x_val = y_val = CENTER
447
+ end
448
+ else raise ArgumentError,"invalid argument for align: #{arg}"
449
+ end
450
+ end
451
+ end
452
+ obj.alignment_x = x_val if x_val
453
+ obj.alignment_y = y_val if y_val
454
+ return true,nil
455
+ end
456
+ end #AlignMethodConsumer
457
+
458
+ SwingConsumer = Cheri::Builder::SuperConsumer.new do |c|
459
+ c << AlignMethodConsumer
460
+ c << Cheri::AWT::SizeMethodConsumer
461
+ c << Cheri::Java::Builder::EventMethodConsumer
462
+ c << Cheri::Java::Builder::GenericConsumer
463
+ c << Cheri::Builder::DefaultConsumer
464
+ end
465
+
466
+ end #Swing
467
+ end #Cheri