profligacy 0.2-jruby

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/COPYING +55 -0
  2. data/LICENSE +55 -0
  3. data/README +22 -0
  4. data/Rakefile +48 -0
  5. data/doc/rdoc/classes/Proc.html +152 -0
  6. data/doc/rdoc/classes/Proc.src/M000001.html +18 -0
  7. data/doc/rdoc/classes/Proc.src/M000002.html +18 -0
  8. data/doc/rdoc/classes/Profligacy.html +111 -0
  9. data/doc/rdoc/classes/Profligacy/Swing.html +113 -0
  10. data/doc/rdoc/classes/Profligacy/Swing/Build.html +238 -0
  11. data/doc/rdoc/classes/Profligacy/Swing/Build.src/M000003.html +23 -0
  12. data/doc/rdoc/classes/Profligacy/Swing/Build.src/M000004.html +18 -0
  13. data/doc/rdoc/classes/Profligacy/Swing/Build.src/M000005.html +45 -0
  14. data/doc/rdoc/classes/Profligacy/Swing/Build.src/M000006.html +18 -0
  15. data/doc/rdoc/classes/Profligacy/Swing/Build.src/M000007.html +22 -0
  16. data/doc/rdoc/classes/Profligacy/Swing/Listeners.html +123 -0
  17. data/doc/rdoc/classes/Profligacy/Swing/RunnableProc.html +161 -0
  18. data/doc/rdoc/classes/Profligacy/Swing/RunnableProc.src/M000008.html +18 -0
  19. data/doc/rdoc/classes/Profligacy/Swing/RunnableProc.src/M000009.html +18 -0
  20. data/doc/rdoc/created.rid +1 -0
  21. data/doc/rdoc/files/COPYING.html +168 -0
  22. data/doc/rdoc/files/LICENSE.html +168 -0
  23. data/doc/rdoc/files/README.html +127 -0
  24. data/doc/rdoc/files/lib/profligacy/swing_rb.html +108 -0
  25. data/doc/rdoc/fr_class_index.html +32 -0
  26. data/doc/rdoc/fr_file_index.html +30 -0
  27. data/doc/rdoc/fr_method_index.html +35 -0
  28. data/doc/rdoc/index.html +24 -0
  29. data/doc/rdoc/rdoc-style.css +208 -0
  30. data/examples/prefuse_sample.rb +62 -0
  31. data/examples/swing1.rb +19 -0
  32. data/examples/swing2.rb +26 -0
  33. data/examples/swing3.rb +38 -0
  34. data/examples/swing4.rb +34 -0
  35. data/examples/swing5.rb +31 -0
  36. data/examples/swing6.rb +33 -0
  37. data/examples/swing7.rb +37 -0
  38. data/examples/swing8.rb +64 -0
  39. data/lib/profligacy/swing.rb +139 -0
  40. data/tools/rakehelp.rb +121 -0
  41. metadata +88 -0
@@ -0,0 +1,31 @@
1
+ require 'profligacy/swing'
2
+
3
+ class ToggleButtonDemo
4
+ include_package 'javax.swing'
5
+ include_package 'java.awt'
6
+ include_package 'javax.swing.border'
7
+ include Profligacy
8
+
9
+ def initialize
10
+ @ui = Swing::Build.new JFrame, :label, :button do |c,i|
11
+ c.label = JLabel.new "Button is off."
12
+ c.button = JToggleButton.new "On/Off"
13
+
14
+ i.button = { :item => method(:toggled) }
15
+ end
16
+
17
+ @ui.layout = FlowLayout.new
18
+ @ui.build("Toggle Demo").default_close_operation = JFrame::EXIT_ON_CLOSE
19
+ end
20
+
21
+ def toggled(type, event)
22
+ if @ui.button.selected?
23
+ @ui.label.text = "Button is on."
24
+ else
25
+ @ui.label.text = "Button is off."
26
+ end
27
+ end
28
+ end
29
+
30
+
31
+ SwingUtilities.invoke_later proc { ToggleButtonDemo.new }.to_runnable
@@ -0,0 +1,33 @@
1
+ require 'profligacy/swing'
2
+
3
+ class TwoTFDemo
4
+ include_package 'javax.swing'
5
+ include_package 'java.awt'
6
+ include_package 'javax.swing.border'
7
+ include Profligacy
8
+
9
+ def initialize
10
+ @ui = Swing::Build.new JFrame, :texts, :label do |c,i|
11
+ c.texts = [ JTextField.new(10), JTextField.new(10)]
12
+ c.texts.each_with_index {|t,n| t.action_command = "text#{n}" }
13
+ c.label = JLabel.new "Something will show up here."
14
+
15
+ i.texts = {:action => method(:text_action) }
16
+ end
17
+
18
+ @ui.layout = FlowLayout.new
19
+ @ui.build("Two Text Fields Demo").default_close_operation = JFrame::EXIT_ON_CLOSE
20
+ end
21
+
22
+ def text_action(type, event)
23
+ puts "EVENT: #{type} #{event.action_command}"
24
+ if event.action_command == "text0"
25
+ @ui.label.text = "ENTER pressed in first text"
26
+ else
27
+ @ui.label.text = "ENTER pressed in second text"
28
+ end
29
+ end
30
+ end
31
+
32
+
33
+ SwingUtilities.invoke_later proc { TwoTFDemo.new }.to_runnable
@@ -0,0 +1,37 @@
1
+ require 'profligacy/swing'
2
+
3
+ class ChangeDemo
4
+ include_package 'javax.swing'
5
+ include_package 'java.awt'
6
+ include_package 'javax.swing.border'
7
+ include Profligacy
8
+
9
+ def initialize
10
+ @ui = Swing::Build.new JFrame, :button, :label do |c,i|
11
+ c.label = JLabel.new
12
+ c.button = JButton.new "Press for Change Event Test"
13
+
14
+ i.button = { :change => method(:change_check) }
15
+ end
16
+
17
+ @ui.layout = FlowLayout.new
18
+ frame = @ui.build("Change Demo")
19
+ frame.set_size(250,160)
20
+ frame.default_close_operation = JFrame::EXIT_ON_CLOSE
21
+ end
22
+
23
+ def change_check(type, event)
24
+ model = event.source.model
25
+ what = []
26
+ [:enabled?, :rollover?, :armed?, :pressed?].each do |test|
27
+ if model.send(test)
28
+ what << "#{test}<br>"
29
+ end
30
+ end
31
+
32
+ @ui.label.text = "<html>Current state:<br>#{what.join(" ")}"
33
+ end
34
+ end
35
+
36
+
37
+ SwingUtilities.invoke_later proc { ChangeDemo.new }.to_runnable
@@ -0,0 +1,64 @@
1
+ require 'profligacy/swing'
2
+
3
+ class PhoneBookDemo
4
+ include_package 'javax.swing'
5
+ include_package 'java.awt'
6
+ include_package 'javax.swing.border'
7
+ include Profligacy
8
+
9
+ def initialize
10
+ children = [:lab_name, :name, :lab_number, :number, :lab_options,
11
+ :ignore_case, :exact, :starts, :ends]
12
+
13
+ @search_style = :exact
14
+
15
+ @ui = Swing::Build.new(JFrame, *children) do |c,i|
16
+ c.lab_name = JLabel.new "Name"
17
+ c.lab_number = JLabel.new "Number"
18
+ c.lab_options = JLabel.new "Search Options"
19
+ c.name = JTextField.new 10
20
+ c.number = JTextField.new 10
21
+
22
+ c.exact = JRadioButton.new("Exact Match", true)
23
+ c.starts = JRadioButton.new("Starts With")
24
+ c.ends = JRadioButton.new("Ends With")
25
+
26
+ b = ButtonGroup.new
27
+ [c.exact, c.starts, c.ends].each {|x| b.add(x) }
28
+
29
+ i.name = {:action => proc {|t,e| @ui.number.text = find(@names, e.source.text) } }
30
+ i.number = {:action => proc {|t,e| @ui.name.text = find(@numbers, e.source.text) } }
31
+ i.exact = {:action => proc {|t,e| @search_style = :exact } }
32
+ i.starts = {:action => proc {|t,e| @search_style = :starts } }
33
+ i.ends = {:action => proc {|t,e| @search_style = :ends } }
34
+ end
35
+
36
+ @ui.layout = GridLayout.new 0,1
37
+ @ui.build("Phone Book").default_close_operation = JFrame::EXIT_ON_CLOSE
38
+
39
+ @names = {
40
+ "Zed A. Shaw" => "917-555-5555",
41
+ "Frank Blank" => "212-554-5555"
42
+ }
43
+
44
+ @numbers = {
45
+ "917-555-5555" => "Zed A. Shaw",
46
+ "212-554-5555" => "Frank Blank"
47
+ }
48
+ end
49
+
50
+
51
+ protected
52
+ def find(inside, text)
53
+ results = case @search_style
54
+ when :exact; inside.keys.grep /^#{text}$/
55
+ when :starts; inside.keys.grep /^#{text}/
56
+ when :ends; inside.keys.grep /#{text}$/
57
+ end
58
+
59
+ inside[results[0]] || ""
60
+ end
61
+ end
62
+
63
+
64
+ SwingUtilities.invoke_later proc { PhoneBookDemo.new }.to_runnable
@@ -0,0 +1,139 @@
1
+ require 'java'
2
+
3
+ import 'javax.swing.SwingUtilities'
4
+
5
+ module Profligacy
6
+ module Swing
7
+ include_class 'java.lang.Runnable'
8
+ include_package 'java.awt.event'
9
+ include_package 'javax.swing.event'
10
+ include_package 'javax.swing'
11
+ include_package 'java.awt'
12
+
13
+ class RunnableProc
14
+ include Runnable
15
+ def initialize(&block)
16
+ @block = block
17
+ end
18
+
19
+ def run
20
+ @block.call
21
+ end
22
+ end
23
+
24
+
25
+ module Listeners
26
+ AWT_LISTENERS = ["Action","Adjustment","AWTEvent","Component","Container","Focus",
27
+ "HierarchyBounds","Hierarchy","InputMethod","Item","Key","Mouse",
28
+ "MouseMotion","MouseWheel","Text",
29
+ "WindowFocus","Window","WindowState",]
30
+
31
+ SWING_LISTENERS = [ "Ancestor", "Caret", "CellEditor", "Change",
32
+ "Document", "Hyperlink", "InternalFrame", "ListData",
33
+ "ListSelection", "MenuDragMouse", "MenuKey", "Menu",
34
+ "MouseInput", "PopupMenu", "TableColumnModel", "TableModel",
35
+ "TreeExpansion", "TreeModel", "TreeSelection", "TreeWillExpand",
36
+ "UndoableEdit", ]
37
+
38
+ horrid_java_sucks_ass_hack = (SWING_LISTENERS + AWT_LISTENERS).collect do |listener|
39
+ <<-END
40
+ class #{listener}ListenerProc
41
+ include Profligacy::Swing::#{listener}Listener
42
+
43
+ def initialize(&block)
44
+ @block = block
45
+ end
46
+
47
+ def method_missing(symb, *args)
48
+ @block.call(symb, *args)
49
+ end
50
+ end
51
+ END
52
+ end
53
+
54
+ module_eval horrid_java_sucks_ass_hack.join("\n")
55
+ end
56
+
57
+ class Build
58
+ attr_accessor :children
59
+ attr_accessor :contents
60
+ attr_accessor :interactions
61
+ attr_accessor :layout
62
+ attr_accessor :container
63
+
64
+ include_package 'javax.swing'
65
+
66
+ def initialize(*children)
67
+ @container_class = children.shift
68
+ @children = children
69
+ @klass = Struct.new *@children
70
+ @contents = @klass.new
71
+ @interactions = @klass.new
72
+ yield @contents, @interactions
73
+ end
74
+
75
+ def interactions
76
+ yield @contents, @interactions
77
+ end
78
+
79
+ def build(*args)
80
+ # create the container they ask for with these args
81
+ @container = @container_class.new *args
82
+ # tack on the layout they wanted
83
+ @container.layout = layout if layout
84
+
85
+ # go through all the children, add them on and tack on the callbacks
86
+ @children.each {|child|
87
+ if @contents[child]
88
+ # if this component answers the each call then go through all
89
+ component = @contents[child]
90
+ each_or_one(component) {|c| @container.add(c) }
91
+
92
+ actions = @interactions[child]
93
+ # now we tack on the callback
94
+ actions.each { |type, callback|
95
+ each_or_one(component) do |c|
96
+ c.send("add_#{type}_listener", callback.to_proc.to_listener(type))
97
+ end
98
+ } if actions
99
+ end
100
+ }
101
+
102
+ # even though swing doesn't do this, we do
103
+ @container.pack if @container.respond_to? :pack
104
+ @container.visible = true if @container.respond_to? :visible
105
+
106
+ # and now they can do whatever they want to the container
107
+ @container
108
+ end
109
+
110
+ def method_missing(symb, *args)
111
+ @contents[symb]
112
+ end
113
+
114
+ protected
115
+
116
+ # allows for a block of code to be run on each element of
117
+ # anything responding to each, or just on one item
118
+ def each_or_one(component)
119
+ if component.respond_to? :each
120
+ component.each {|c| yield c }
121
+ else
122
+ yield component
123
+ end
124
+ end
125
+
126
+ end
127
+ end
128
+ end
129
+
130
+ class Proc
131
+ def to_listener(action)
132
+ Profligacy::Swing::Listeners.const_get("#{action.to_s.capitalize}ListenerProc").new &self
133
+ end
134
+
135
+ def to_runnable
136
+ Profligacy::Swing::RunnableProc.new &self
137
+ end
138
+ end
139
+
data/tools/rakehelp.rb ADDED
@@ -0,0 +1,121 @@
1
+ def make(makedir)
2
+ Dir.chdir(makedir) do
3
+ sh(PLATFORM =~ /win32/ ? 'nmake' : 'make')
4
+ end
5
+ end
6
+
7
+
8
+ def extconf(dir)
9
+ Dir.chdir(dir) do ruby "extconf.rb" end
10
+ end
11
+
12
+
13
+ def setup_tests
14
+ Rake::TestTask.new do |t|
15
+ t.libs << "test"
16
+ t.test_files = FileList['test/test*.rb']
17
+ t.verbose = true
18
+ end
19
+ end
20
+
21
+
22
+ def setup_clean otherfiles
23
+ files = ['build/*', '**/*.o', '**/*.so', '**/*.a', 'lib/*-*', '**/*.log'] + otherfiles
24
+ CLEAN.include(files)
25
+ end
26
+
27
+
28
+ def setup_rdoc files
29
+ Rake::RDocTask.new do |rdoc|
30
+ rdoc.rdoc_dir = 'doc/rdoc'
31
+ rdoc.options << '--line-numbers'
32
+ rdoc.rdoc_files.add(files)
33
+ end
34
+ end
35
+
36
+
37
+ def setup_extension(dir, extension)
38
+ ext = "ext/#{dir}"
39
+ ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}"
40
+ ext_files = FileList[
41
+ "#{ext}/*.c",
42
+ "#{ext}/*.h",
43
+ "#{ext}/extconf.rb",
44
+ "#{ext}/Makefile",
45
+ "lib"
46
+ ]
47
+
48
+ task "lib" do
49
+ directory "lib"
50
+ end
51
+
52
+ desc "Builds just the #{extension} extension"
53
+ task extension.to_sym => ["#{ext}/Makefile", ext_so ]
54
+
55
+ file "#{ext}/Makefile" => ["#{ext}/extconf.rb"] do
56
+ extconf "#{ext}"
57
+ end
58
+
59
+ file ext_so => ext_files do
60
+ make "#{ext}"
61
+ cp ext_so, "lib"
62
+ end
63
+ end
64
+
65
+
66
+ def base_gem_spec(pkg_name, pkg_version)
67
+ rm_rf "test/coverage"
68
+
69
+ pkg_version = pkg_version
70
+ pkg_name = pkg_name
71
+ pkg_file_name = "#{pkg_name}-#{pkg_version}"
72
+ Gem::Specification.new do |s|
73
+ s.name = pkg_name
74
+ s.version = pkg_version
75
+ s.platform = Gem::Platform::RUBY
76
+ s.has_rdoc = true
77
+ s.extra_rdoc_files = [ "README" ]
78
+
79
+ s.files = %w(COPYING LICENSE README Rakefile) +
80
+ Dir.glob("{bin,doc/rdoc}/**/*") +
81
+ Dir.glob("ext/**/*.{h,c,rb}") +
82
+ Dir.glob("examples/**/*.rb") +
83
+ Dir.glob("tools/*.rb") +
84
+ Dir.glob(RUBY_PLATFORM !~ /mswin/ ? "lib/**/*.rb" : "lib/**/*")
85
+
86
+ s.require_path = "lib"
87
+ s.extensions = FileList["ext/**/extconf.rb"].to_a
88
+ s.bindir = "bin"
89
+ end
90
+ end
91
+
92
+ def setup_gem(pkg_name, pkg_version)
93
+ spec = base_gem_spec(pkg_name, pkg_version)
94
+ yield spec if block_given?
95
+
96
+
97
+ Rake::GemPackageTask.new(spec) do |p|
98
+ p.gem_spec = spec
99
+ p.need_tar = true if RUBY_PLATFORM !~ /mswin/
100
+ end
101
+ end
102
+
103
+ def sub_project(project, *targets)
104
+ targets.each do |target|
105
+ Dir.chdir "projects/#{project}" do
106
+ sh %{rake --trace #{target.to_s} }
107
+ end
108
+ end
109
+ end
110
+
111
+ # Conditional require rcov/rcovtask if present
112
+ begin
113
+ require 'rcov/rcovtask'
114
+
115
+ Rcov::RcovTask.new do |t|
116
+ t.test_files = FileList['test/test*.rb']
117
+ t.rcov_opts << "-x /usr"
118
+ t.output_dir = "test/coverage"
119
+ end
120
+ rescue Object
121
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
3
+ requirements:
4
+ - - '>'
5
+ - !ruby/object:Gem::Version
6
+ version: 0.0.0
7
+ version:
8
+ email:
9
+ cert_chain:
10
+ summary: Profligacy is a Swing helper for JRuby.
11
+ post_install_message:
12
+ homepage:
13
+ extra_rdoc_files:
14
+ - README
15
+ signing_key:
16
+ name: profligacy
17
+ rdoc_options: []
18
+ rubyforge_project:
19
+ autorequire:
20
+ executables: []
21
+ description: Profligacy is a Swing helper for JRuby.
22
+ default_executable:
23
+ files:
24
+ - COPYING
25
+ - LICENSE
26
+ - README
27
+ - Rakefile
28
+ - doc/rdoc/classes
29
+ - doc/rdoc/created.rid
30
+ - doc/rdoc/files
31
+ - doc/rdoc/fr_class_index.html
32
+ - doc/rdoc/fr_file_index.html
33
+ - doc/rdoc/fr_method_index.html
34
+ - doc/rdoc/index.html
35
+ - doc/rdoc/rdoc-style.css
36
+ - doc/rdoc/classes/Proc.html
37
+ - doc/rdoc/classes/Proc.src
38
+ - doc/rdoc/classes/Profligacy
39
+ - doc/rdoc/classes/Profligacy.html
40
+ - doc/rdoc/classes/Proc.src/M000001.html
41
+ - doc/rdoc/classes/Proc.src/M000002.html
42
+ - doc/rdoc/classes/Profligacy/Swing
43
+ - doc/rdoc/classes/Profligacy/Swing.html
44
+ - doc/rdoc/classes/Profligacy/Swing/Build.html
45
+ - doc/rdoc/classes/Profligacy/Swing/Build.src
46
+ - doc/rdoc/classes/Profligacy/Swing/Listeners.html
47
+ - doc/rdoc/classes/Profligacy/Swing/RunnableProc.html
48
+ - doc/rdoc/classes/Profligacy/Swing/RunnableProc.src
49
+ - doc/rdoc/classes/Profligacy/Swing/Build.src/M000003.html
50
+ - doc/rdoc/classes/Profligacy/Swing/Build.src/M000004.html
51
+ - doc/rdoc/classes/Profligacy/Swing/Build.src/M000005.html
52
+ - doc/rdoc/classes/Profligacy/Swing/Build.src/M000006.html
53
+ - doc/rdoc/classes/Profligacy/Swing/Build.src/M000007.html
54
+ - doc/rdoc/classes/Profligacy/Swing/RunnableProc.src/M000008.html
55
+ - doc/rdoc/classes/Profligacy/Swing/RunnableProc.src/M000009.html
56
+ - doc/rdoc/files/COPYING.html
57
+ - doc/rdoc/files/LICENSE.html
58
+ - doc/rdoc/files/README.html
59
+ - doc/rdoc/files/lib
60
+ - doc/rdoc/files/lib/profligacy
61
+ - doc/rdoc/files/lib/profligacy/swing_rb.html
62
+ - examples/prefuse_sample.rb
63
+ - examples/swing1.rb
64
+ - examples/swing2.rb
65
+ - examples/swing3.rb
66
+ - examples/swing4.rb
67
+ - examples/swing5.rb
68
+ - examples/swing6.rb
69
+ - examples/swing7.rb
70
+ - examples/swing8.rb
71
+ - tools/rakehelp.rb
72
+ - lib/profligacy/swing.rb
73
+ specification_version: 1
74
+ extensions: []
75
+ rubygems_version: 0.9.4
76
+ requirements: []
77
+ authors:
78
+ - Zed A. Shaw
79
+ platform: jruby
80
+ date: 2007-07-04 04:00:00 +00:00
81
+ require_paths:
82
+ - lib
83
+ version: !ruby/object:Gem::Version
84
+ version: !str 0.2
85
+ test_files: []
86
+ bindir: bin
87
+ dependencies: []
88
+ has_rdoc: true