cheri 0.0.9 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -166,6 +166,17 @@ private
166
166
  end
167
167
  end #ProcBuilder
168
168
 
169
+ class PropAwareClassBuilder < ClassBuilder
170
+ private
171
+ def create
172
+ if Hash === @props
173
+ @args << @props
174
+ @props = nil
175
+ end
176
+ @obj = @clazz.new(*@args)
177
+ end
178
+ end #PropAwareProcBuilder
179
+
169
180
  class CherifyBuilder < BaseBuilder
170
181
  def initialize(ctx,sym,obj,*args,&block)
171
182
  super(ctx,sym,*args,&block)
@@ -217,13 +228,16 @@ end #StandardFactory
217
228
 
218
229
  module GridTableFactory
219
230
  SwingLayout = org.cheri.swing.layout
220
- @names = [:grid_table,:grid_row,:empty_cell]
231
+ @names = [:grid_table_layout,:grid_table,:grid_row,:empty_cell]
221
232
  def self.builder(ctx,sym,*args,&block)
222
- if sym == :grid_table
233
+ case sym
234
+ when :grid_table_layout
235
+ PropAwareClassBuilder.new(ctx,sym,SwingLayout::GridTableLayout,*args,&block)
236
+ when :grid_table
223
237
  ClassBuilder.new(ctx,sym,SwingLayout::GridTable,*args,&block)
224
- elsif sym == :grid_row
238
+ when :grid_row
225
239
  ClassBuilder.new(ctx,sym,SwingLayout::GridRow,*args,&block)
226
- elsif sym == :empty_cell
240
+ when :empty_cell
227
241
  ClassBuilder.new(ctx,sym,SwingLayout::EmptyCell,*args,&block)
228
242
  else
229
243
  nil
@@ -248,8 +262,9 @@ RPC = javax.swing.RootPaneContainer
248
262
  @procs = {}
249
263
  class << self
250
264
  def builder(ctx,sym,*args,&block)
251
- proc = @procs[sym]
252
- proc ? ProcBuilder.new(ctx,sym,proc,*args,&block) : nil
265
+ if proc = @procs[sym]
266
+ ProcBuilder.new(ctx,sym,proc,*args,&block)
267
+ end
253
268
  end
254
269
  def box
255
270
  @box ||= CJava.get_class('javax.swing.Box')
@@ -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
@@ -28,26 +28,15 @@ require 'thread'
28
28
  module Cheri
29
29
  module VERSION #:nodoc:
30
30
  MAJOR = 0
31
- MINOR = 0
32
- TINY = 9
31
+ MINOR = 5
32
+ TINY = 0
33
33
  STRING = [MAJOR, MINOR, TINY].join('.').freeze
34
34
  end
35
35
  #:stopdoc:
36
36
  PathExp = Regexp.new "cheri-#{VERSION::STRING}\\/lib$"
37
37
  #:startdoc:
38
38
  class CheriException < StandardError; end
39
- # global threadsafe; set if all Cheri module instances in a system
40
- # must be threadsafe
41
- # TODO: not yet widely implemented by Cheri modules
42
- @threadsafe = false
43
39
  class << self
44
- def threadsafe?
45
- @threadsafe
46
- end
47
- # once threadsafe is set, it cannot be unset (by normal means)
48
- def threadsafe!
49
- @threadsafe ||= true
50
- end
51
40
  def type_error(object, *expected_type)
52
41
  TypeError.new("wrong argument type #{object.class} (expected #{expected_type.join(' or ')})")
53
42
  end
@@ -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
@@ -331,6 +331,7 @@ end #MethodRec
331
331
 
332
332
 
333
333
  class RubyExplorer
334
+ DeprecatedVars = ["$="]
334
335
  # TODO: aggregate values that will be displayed together
335
336
  def ruby_platform
336
337
  RUBY_PLATFORM
@@ -348,6 +349,7 @@ class RubyExplorer
348
349
  def global_vars
349
350
  result = []
350
351
  global_variables.each do |v|
352
+ next if DeprecatedVars.include?v
351
353
  ev = eval(v) rescue '???'
352
354
  if Array === ev
353
355
  eva = []
@@ -112,6 +112,9 @@ class ClassBuilder < BaseBuilder
112
112
  private
113
113
  def create
114
114
  @obj = @clazz.new(*@args)
115
+ def @obj.java_class
116
+ self.class.java_class
117
+ end if BUG_JRUBY_3476
115
118
  end
116
119
  end #ClassBasedBuilder
117
120
 
@@ -249,7 +252,7 @@ Aliases = {:on_click => 'actionPerformed'.freeze}
249
252
  return false,nil unless (obj = bld.object).respond_to?(:java_class) &&
250
253
  ((method_name = Aliases[sym]) || (s = sym.to_s).rindex(On,0))
251
254
  method_name ||= Util.lcc(s[3,s.length])
252
- unless (info = Interfaces.get_listener_info(obj.java_class,method_name))
255
+ unless (info = Interfaces.get_listener_info(obj.java_class||obj.class.java_class,method_name))
253
256
  raise NameError,"no Java interface found matching event handler name: #{sym}"
254
257
  end
255
258
  raise ArgumentError,"missing block for event handler: #{sym}" unless block
@@ -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
@@ -25,15 +25,14 @@
25
25
  module Cheri
26
26
  module Java
27
27
  JRuby = Cheri::JRuby #:nodoc:
28
- class LocatableIcon < ::Java::JavaxSwing::ImageIcon
29
- def initialize(location,*r)
30
- super
31
- @location = location
32
- end
33
- def location
34
- @location
35
- end
36
- end
28
+ ImageIcon = javax.swing.ImageIcon
29
+ CL = java.lang.ClassLoader
30
+ @icons = {}
31
+
32
+ #check for singleton/java_class bug in JRuby versions 1.1.4, 1.1.5 and 1.1.6 (see JRUBY-3476)
33
+ x = java.lang.Object.new
34
+ def x.foo; end
35
+ BUG_JRUBY_3476 = !x.java_class
37
36
 
38
37
  class << self
39
38
  def get_class(*r)
@@ -44,7 +43,8 @@ class << self
44
43
  #
45
44
  # Returns an instance of LocatableIcon for file at #{Cheri.img_path}#{filename}.
46
45
  def get_icon(n)
47
- LocatableIcon.new("#{Cheri.img_path}#{n}")
46
+ path = "#{Cheri.img_path}#{n}"
47
+ @icons[path] ||= ImageIcon.new(CL.get_system_resource(path) || path)
48
48
  end
49
49
  # Returns the 16x16 Cheri icon.
50
50
  def cheri_icon
@@ -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
@@ -24,6 +24,7 @@
24
24
 
25
25
  if RUBY_PLATFORM =~ /java/ && defined?JRUBY_VERSION
26
26
  require 'java'
27
+ require 'jruby'
27
28
  require 'cheri/cheri'
28
29
  require 'cheri/jruby/jruby'
29
30
  else
@@ -0,0 +1,407 @@
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
+ module JRuby
28
+ module Explorer
29
+
30
+ class ConnectionDialog
31
+ include Cheri::Swing
32
+ def initialize(main)
33
+ swing[:auto=>true]
34
+ @main = main
35
+ @main_frame = main.main_frame
36
+ @dialog = dialog @main_frame, 'New Connection', true do |d|
37
+ box_layout(d, :Y_AXIS)
38
+ size 240,180
39
+ default_close_operation :HIDE_ON_CLOSE
40
+ y_glue
41
+
42
+ x_box do
43
+ y_box do
44
+ label 'Host:'
45
+ y_spacer 4
46
+ label 'Port:'
47
+ y_spacer 4
48
+ label 'Display name:'
49
+ end
50
+ x_spacer 10
51
+ y_box do
52
+ @con_host = text_field do
53
+ columns 10
54
+ maximum_size dimension(100,24)
55
+ text 'localhost'
56
+ end
57
+ y_spacer 4
58
+ @con_port = text_field do
59
+ columns 10
60
+ maximum_size dimension(100,24)
61
+ end
62
+ y_spacer 4
63
+ @con_name = text_field do
64
+ #align :RIGHT
65
+ columns 10
66
+ maximum_size dimension(100,24)
67
+ end
68
+ end
69
+ end
70
+ y_spacer 16
71
+ x_box do
72
+ x_glue
73
+ button 'Connect' do
74
+ on_click do
75
+ host = @con_host.text
76
+ host.strip! if host
77
+ port = @con_port.text
78
+ port.strip! if port
79
+ name = @con_name.text
80
+ if name
81
+ name.strip!
82
+ name = nil if name.empty?
83
+ end
84
+ if !port || port.empty?
85
+ JOptionPane.show_message_dialog(@main_frame,"Please enter a port number",
86
+ 'Connection Error', JOptionPane::ERROR_MESSAGE)
87
+ elsif !(port = Integer(port) rescue nil)
88
+ JOptionPane.show_message_dialog(@main_frame,"Invalid port: #{@con_port.text}",
89
+ 'Connection Error', JOptionPane::ERROR_MESSAGE)
90
+ else
91
+ @dialog.visible = false
92
+ reset_fields
93
+ @main.new_connection(port,name,host)
94
+ end
95
+ end
96
+ end
97
+ x_spacer 10
98
+ button 'Cancel' do
99
+ on_click do
100
+ @dialog.visible = false
101
+ reset_fields
102
+ end
103
+ end
104
+ x_glue
105
+ end
106
+ y_glue
107
+ end
108
+ reset_fields
109
+ @main.center(@main_frame,@dialog)
110
+ end
111
+
112
+ def reset_fields
113
+ @con_host.text = 'localhost'
114
+ @con_port.text = ''
115
+ @con_name.text = ''
116
+ end
117
+ private :reset_fields
118
+
119
+ def value
120
+ @dialog
121
+ end
122
+
123
+ def show
124
+ @dialog.visible = true
125
+ end
126
+
127
+ def hide
128
+ @dialog.visible = false
129
+ end
130
+
131
+ end
132
+
133
+ class SearchDialog
134
+ include Cheri::Swing
135
+ def initialize(main)
136
+ swing[:auto=>true]
137
+ @main = main
138
+ @main_frame = main.main_frame
139
+ @dialog = dialog @main_frame, 'Search ObjectSpace', true do |d|
140
+ box_layout d, :Y_AXIS
141
+ size 400,300
142
+ default_close_operation :HIDE_ON_CLOSE
143
+ y_glue
144
+ x_panel do
145
+ x_spacer 4
146
+ label 'Instance:'
147
+ x_spacer 10
148
+ @instance_list = combo_box instance_list do
149
+ editable false
150
+ end
151
+ x_spacer 4
152
+ end
153
+ y_glue
154
+ x_panel do
155
+ compound_border(
156
+ titled_border('Find specific object') { etched_border :LOWERED },
157
+ empty_border(4,8,4,8)
158
+ )
159
+ y_box do
160
+ label 'Object id:'
161
+ end
162
+ x_spacer 10
163
+ y_box do
164
+ y_glue
165
+ @object_id = text_field do
166
+ columns 16
167
+ fixed_size 100,24
168
+ end
169
+ y_glue
170
+ end
171
+ x_glue
172
+ y_box do
173
+ y_glue
174
+ button 'Find' do
175
+ on_click do
176
+ id = nil_if_empty(@object_id.text)
177
+ id = Integer(id) rescue nil if id
178
+ if !id
179
+ JOptionPane.show_message_dialog(@dialog,"Please enter a valid id",
180
+ 'Search Error', JOptionPane::ERROR_MESSAGE)
181
+ else
182
+ @dialog.visible = false
183
+ @object_id.text = ''
184
+ @main.new_find(@instances[@instance_list.selected_index],id)
185
+ end
186
+ end
187
+ end
188
+ y_glue
189
+ end
190
+ end
191
+
192
+ y_glue
193
+
194
+ y_panel do
195
+ compound_border(
196
+ titled_border('Search for instances by type and optional variable/value') { etched_border :LOWERED },
197
+ empty_border(4,8,4,8)
198
+ )
199
+ x_panel do
200
+ y_box do
201
+ y_glue
202
+ label 'Class or Module:'
203
+ y_glue
204
+ label 'Variable name:'
205
+ y_glue
206
+ label 'Search string or /regexp/:'
207
+ y_glue
208
+ end
209
+ x_spacer 6
210
+ y_box do
211
+ y_glue
212
+ label '@'
213
+ y_glue
214
+ end
215
+ y_box do
216
+ y_glue
217
+ @clazz = text_field do
218
+ columns 20
219
+ fixed_size 200,24
220
+ end
221
+ y_glue
222
+ @name1 = text_field do
223
+ columns 20
224
+ fixed_size 200,24
225
+ end
226
+ y_glue
227
+ @value1 = text_field do
228
+ columns 20
229
+ fixed_size 200,24
230
+ end
231
+ y_glue
232
+ end
233
+ x_glue
234
+ y_box do
235
+ button 'Find' do
236
+ on_click do
237
+ clazz = nil_if_empty(@clazz.text)
238
+ name = nil_if_empty(@name1.text)
239
+ value = @value1.text
240
+ value = nil if value.empty?
241
+ instance = @instances[@instance_list.selected_index]
242
+ if !clazz
243
+ JOptionPane.show_message_dialog(@dialog,"Please enter a Class or Module name",
244
+ 'Search Error', JOptionPane::ERROR_MESSAGE)
245
+ elsif clazz !~ /^([A-Z])((\w|::[A-Z])*)$/
246
+ JOptionPane.show_message_dialog(@dialog,"Invalid Class or Module name, please re-enter",
247
+ 'Search Error', JOptionPane::ERROR_MESSAGE)
248
+ elsif name && name !~ /^([A-Za-z_])(\w*)$/
249
+ JOptionPane.show_message_dialog(@dialog,"Invalid variable name, please re-enter",
250
+ 'Search Error', JOptionPane::ERROR_MESSAGE)
251
+ elsif !instance.proxy.object_space? && clazz != 'Class'
252
+ JOptionPane.show_message_dialog(@dialog,"Only class 'Class' supported when ObjectSpace disabled",
253
+ 'Search Error', JOptionPane::ERROR_MESSAGE)
254
+ else
255
+ if value && value.strip.length != value.length
256
+ rsp = JOptionPane.show_confirm_dialog(@main_frame,
257
+ "Value contains leading/trailing whitespace -- continue?")
258
+ else
259
+ rsp = nil
260
+ end
261
+ unless rsp && rsp != JOptionPane::YES_OPTION
262
+ @dialog.visible = false
263
+ gc = @gc.selected
264
+ reset_fields
265
+ @main.new_search(instance,clazz,name,value,gc)
266
+ end
267
+ end
268
+ end
269
+ end
270
+ end
271
+ end
272
+ x_panel do
273
+ @gc = check_box 'GC target instance before search'
274
+ end
275
+ end
276
+ y_glue
277
+ x_box do
278
+ x_glue
279
+ button 'Cancel' do
280
+ on_click do
281
+ @dialog.visible = false
282
+ end
283
+ end
284
+ x_glue
285
+ end
286
+ y_glue
287
+ end
288
+
289
+ @main.center(@main_frame,@dialog)
290
+ end
291
+
292
+ def nil_if_empty(val)
293
+ if val
294
+ val.strip!
295
+ val = nil if val.empty?
296
+ end
297
+ val
298
+ end
299
+
300
+ def reset_fields
301
+ @clazz.text = ''
302
+ @name1.text = ''
303
+ @value1.text = ''
304
+ @gc.selected = false
305
+ end
306
+ private :reset_fields
307
+
308
+ def value
309
+ @dialog
310
+ end
311
+
312
+ def show(clazz = nil)
313
+ @clazz.text = clazz if clazz
314
+ update_instance_list
315
+ @dialog.visible = true
316
+ end
317
+
318
+ def hide
319
+ @dialog.visible = false
320
+ end
321
+
322
+ def instance_list
323
+ @instances = @main.instance_list
324
+ arr = Array.new(@instances.length) {|i| @instances[i].name}
325
+ arr.to_java
326
+ end
327
+
328
+ def update_instance_list
329
+ new_list = instance_list
330
+ @instance_list.remove_all_items
331
+ new_list.each do |name|
332
+ @instance_list.add_item name
333
+ end
334
+ end
335
+
336
+
337
+ end
338
+
339
+ class AboutDialog
340
+ include Cheri::Swing
341
+ include Cheri::Html
342
+
343
+ # Undefining this so I can use it in Cheri::Html. Could always
344
+ # just use html.p instead.
345
+ undef_method :p
346
+
347
+ def initialize(main)
348
+ swing[:auto]
349
+ @main = main
350
+ @main_frame = main.main_frame
351
+ @dialog = dialog @main_frame, 'About Cheri::JRuby::Explorer', true do |d|
352
+ size 600,450
353
+ default_close_operation :HIDE_ON_CLOSE
354
+ @view ||= scroll_pane do
355
+ align :LEFT
356
+ @html_view = editor_pane do
357
+ editable false
358
+ content_type 'text/html'
359
+ html { head { style 'body { font-family: sans-serif; }' }
360
+ body(:bgolor=>:white) { div(:align=>:center) {
361
+ h3 font(:color=>:blue) {"Cheri::JRuby::Explorer version #{Cheri::VERSION::STRING}"}
362
+ p 'Written by Bill Dortch ', esc('<cheri.project@gmail.com>'), br,
363
+ 'Copyright &copy; 2007 William N Dortch'
364
+ p
365
+ table(:width=>'97%') {
366
+ tr{td(:align=>:left) {
367
+ p 'Cheri::JRuby::Explorer (CJX) demonstrates some of the features ',
368
+ 'of the Cheri builder framework, and may even prove useful ',
369
+ 'in its own right. CJX is built using the Cheri::Swing and Cheri::Html ',
370
+ 'components of the framework.'
371
+ p
372
+ p 'This is a ',i('very'),' early Beta release, of both Cheri and CJX, so do ',
373
+ 'expect bugs, crashes, and the like. The Cheri framework itself is pretty ',
374
+ 'stable (though I refactor it weekly, it seems), but the CJX code is mostly ',
375
+ 'untested beyond the confines of my desktop.'
376
+ p
377
+ p 'For more information, and to report bugs or suggest features, please visit ',
378
+ 'the Cheri project pages on RubyForge, at ', a(b('http://cheri.rubyforge.org'),
379
+ :href=>'http://cheri.rubyforge.org/'), ' and ', a(b('http://rubyforge.org/projects/cheri'),
380
+ :href=>'http://rubyforge.org/projects/cheri'), '.'
381
+ }}
382
+ }
383
+ }}}
384
+ end
385
+ end
386
+ end
387
+ @main.center(@main_frame,@dialog)
388
+ end
389
+
390
+ def value
391
+ @dialog
392
+ end
393
+
394
+ def show
395
+ @dialog.visible = true
396
+ end
397
+
398
+ def hide
399
+ @dialog.visible = false
400
+ end
401
+
402
+ end
403
+
404
+
405
+ end #Explorer
406
+ end #JRuby
407
+ end #Cheri