swing 0.1.14 → 0.1.15
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +4 -0
- data/VERSION +1 -1
- data/lib/awt/component.rb +2 -0
- data/lib/swing/j_button.rb +2 -3
- data/lib/swing/j_check_box.rb +2 -3
- data/lib/swing/j_menu_item.rb +1 -2
- data/lib/swing_support/extensions/attributes.rb +1 -5
- data/lib/swing_support/extensions/blocks.rb +31 -0
- data/lib/swing_support.rb +1 -0
- data/spec/swing/j_button_spec.rb +9 -1
- data/spec/swing/j_menu_item_spec.rb +8 -0
- metadata +2 -1
data/HISTORY
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.15
|
data/lib/awt/component.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'swing_support/extensions/attributes'
|
2
|
+
require 'swing_support/extensions/blocks'
|
2
3
|
|
3
4
|
class Awt::Component
|
4
5
|
|
5
6
|
include SwingSupport::Extensions::Attributes
|
7
|
+
include SwingSupport::Extensions::Blocks
|
6
8
|
|
7
9
|
# background Color � �
|
8
10
|
# cursor Cursor � � Cursor.DEFAULT_CURSOR
|
data/lib/swing/j_button.rb
CHANGED
data/lib/swing/j_check_box.rb
CHANGED
@@ -4,10 +4,9 @@ class Swing::JCheckBox
|
|
4
4
|
|
5
5
|
attr_setter :selected
|
6
6
|
|
7
|
-
def
|
8
|
-
super *args
|
9
|
-
|
7
|
+
def add_block_listener &block
|
10
8
|
# TODO: Probably need to implement ItemListener as well?
|
11
9
|
self.addActionListener SwingSupport::ActionListener.new &block
|
12
10
|
end
|
11
|
+
|
13
12
|
end # class JCheckBox
|
data/lib/swing/j_menu_item.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
import java.awt.Dimension
|
2
|
-
|
3
1
|
module SwingSupport
|
4
2
|
module Extensions
|
5
3
|
# Module allows including classes to receive attribute values in an *opts* Hash
|
@@ -44,7 +42,7 @@ module SwingSupport
|
|
44
42
|
# Sets attributes after calling original new
|
45
43
|
def new_with_attributes(*args, &block)
|
46
44
|
opts = args.last.is_a?(Hash) ? args.pop.dup : {}
|
47
|
-
component = self.new_without_attributes(*args
|
45
|
+
component = self.new_without_attributes(*args, &block)
|
48
46
|
|
49
47
|
# Extract known attributes given in opts,
|
50
48
|
# run default actions on them, or return known defaults
|
@@ -78,8 +76,6 @@ module SwingSupport
|
|
78
76
|
# Raises exception if any of the given options left unprocessed
|
79
77
|
raise "Unrecognized options: #{opts}" unless opts.empty?
|
80
78
|
|
81
|
-
yield component if block_given?
|
82
|
-
|
83
79
|
component
|
84
80
|
end
|
85
81
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module SwingSupport
|
2
|
+
module Extensions
|
3
|
+
# Module allows including classes to process blocks given to constructor
|
4
|
+
# If the class defines #add_block_listener method, block is treated as default listener,
|
5
|
+
# otherwise, newly constructed object is just yielded to the block
|
6
|
+
module Blocks
|
7
|
+
def self.included host
|
8
|
+
host.send :extend, ClassMethods
|
9
|
+
host.instance_eval do
|
10
|
+
alias :new_without_blocks :new
|
11
|
+
alias :new :new_with_blocks
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module ClassMethods
|
16
|
+
def new_with_blocks(*args, &block)
|
17
|
+
component = self.new_without_blocks(*args)
|
18
|
+
if block_given?
|
19
|
+
if component.respond_to? :add_block_listener
|
20
|
+
component.add_block_listener &block
|
21
|
+
else
|
22
|
+
# TODO: some kind of fancy processing of nested blocks/components
|
23
|
+
yield component
|
24
|
+
end
|
25
|
+
end
|
26
|
+
component
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/swing_support.rb
CHANGED
data/spec/swing/j_button_spec.rb
CHANGED
@@ -10,8 +10,16 @@ describe Swing::JButton do
|
|
10
10
|
it_behaves_like 'enhanced Swing::JComponent'
|
11
11
|
|
12
12
|
it 'is possible to set :enabled attribute to false' do
|
13
|
-
button = Swing::JButton.new '
|
13
|
+
button = Swing::JButton.new 'Test', :enabled => false
|
14
14
|
button.should_not be_enabled
|
15
15
|
end
|
16
|
+
|
17
|
+
it 'accepts action listener block' do
|
18
|
+
button = Swing::JButton.new('Test') { @block_called = true}
|
19
|
+
@block_called.should be_false
|
20
|
+
|
21
|
+
button.do_click
|
22
|
+
@block_called.should be_true
|
23
|
+
end
|
16
24
|
end
|
17
25
|
end
|
@@ -9,5 +9,13 @@ describe Swing::JMenuItem do
|
|
9
9
|
it_behaves_like 'enhanced Awt::Component'
|
10
10
|
it_behaves_like 'enhanced Swing::JComponent'
|
11
11
|
|
12
|
+
it 'accepts action listener block' do
|
13
|
+
item = Swing::JMenuItem.new('Test') { @block_called = true}
|
14
|
+
@block_called.should be_false
|
15
|
+
|
16
|
+
item.do_click
|
17
|
+
@block_called.should be_true
|
18
|
+
end
|
19
|
+
|
12
20
|
end
|
13
21
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: swing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.1.
|
5
|
+
version: 0.1.15
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- arvicco
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- lib/swing_support/extensions.rb
|
85
85
|
- lib/swing_support/extensions/attr_setter.rb
|
86
86
|
- lib/swing_support/extensions/attributes.rb
|
87
|
+
- lib/swing_support/extensions/blocks.rb
|
87
88
|
- spec/spec_helper.rb
|
88
89
|
- spec/swing_spec.rb
|
89
90
|
- spec/awt/component_spec.rb
|