swing 0.1.5 → 0.1.7
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.
- data/.gitignore +4 -2
- data/HISTORY +8 -0
- data/VERSION +1 -1
- data/lib/swing/j_frame.rb +2 -14
- data/lib/swing/j_menu_bar.rb +7 -9
- data/lib/swing_support/extensions/attributes.rb +11 -11
- data/spec/awt/component_spec.rb +6 -9
- data/spec/swing/j_menu_bar_spec.rb +19 -0
- data/spec/swing/shared.rb +0 -4
- metadata +1 -1
data/.gitignore
CHANGED
data/HISTORY
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.7
|
data/lib/swing/j_frame.rb
CHANGED
@@ -5,25 +5,13 @@ class Swing::JFrame
|
|
5
5
|
attr_setter :layout, :background, :size, :title,
|
6
6
|
:default_close_operation => EXIT_ON_CLOSE #DISPOSE_ON_CLOSE, HIDE_ON_CLOSE
|
7
7
|
|
8
|
-
# def attributes
|
9
|
-
# a = super
|
10
|
-
# a.delete :tool_tip_text
|
11
|
-
# a
|
12
|
-
# end
|
13
|
-
|
14
8
|
def initialize *args
|
15
|
-
p args
|
16
9
|
super *args
|
17
10
|
|
18
|
-
|
11
|
+
# Yielding self to set up contents before making frame visible
|
12
|
+
yield self if block_given?
|
19
13
|
|
20
14
|
self.location_relative_to = nil
|
21
15
|
self.visible = true
|
22
16
|
end
|
23
|
-
|
24
|
-
# Method that subclasses should override to set up their contents before
|
25
|
-
# JFrame is made visible
|
26
|
-
def setup
|
27
|
-
end
|
28
|
-
|
29
17
|
end
|
data/lib/swing/j_menu_bar.rb
CHANGED
@@ -7,30 +7,28 @@ class Swing::JMenuBar
|
|
7
7
|
attr_setter :tool_tip_text
|
8
8
|
|
9
9
|
# Override post-processing (non-setter) options given to initialize
|
10
|
-
def
|
10
|
+
def post_process opts
|
11
|
+
super
|
11
12
|
# Create menu structure from :structure opt
|
12
13
|
if opts[:structure]
|
13
14
|
[opts[:structure]].flatten.each do |element|
|
14
15
|
case element
|
15
16
|
when Hash # Hash defines menu structure
|
16
17
|
element.each do |menu_name, menu_structure|
|
17
|
-
menu = JMenu.new menu_name.to_s, :parent => self
|
18
|
+
menu = Swing::JMenu.new menu_name.to_s, :parent => self
|
18
19
|
menu_structure.each do |item_name, item_action|
|
19
|
-
JMenuItem.new item_name.to_s, :parent => menu, &item_action
|
20
|
+
Swing::JMenuItem.new item_name.to_s, :parent => menu, &item_action
|
20
21
|
end
|
21
22
|
end
|
22
23
|
else
|
23
|
-
|
24
|
+
self.add element
|
24
25
|
end
|
25
26
|
end
|
26
27
|
end
|
27
|
-
add_component component, opts[:parent]
|
28
28
|
end
|
29
29
|
|
30
30
|
# Proper way to add menu bar to its parent
|
31
|
-
def
|
32
|
-
parent.setJMenuBar
|
31
|
+
def attach_to parent
|
32
|
+
parent.setJMenuBar self if parent and parent.respond_to? :setJMenuBar
|
33
33
|
end
|
34
|
-
|
35
|
-
|
36
34
|
end
|
@@ -14,6 +14,16 @@ module SwingSupport
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
# Post-processing (non-setter) options given to initialize
|
18
|
+
def post_process opts
|
19
|
+
attach_to opts[:parent]
|
20
|
+
end
|
21
|
+
|
22
|
+
# Proper way to add generic component to its parent
|
23
|
+
def attach_to parent
|
24
|
+
parent.add self if parent
|
25
|
+
end
|
26
|
+
|
17
27
|
module ClassMethods
|
18
28
|
def attributes
|
19
29
|
@attributes ||= (superclass.attributes.dup rescue {})
|
@@ -51,19 +61,9 @@ module SwingSupport
|
|
51
61
|
attributes.each { |(name, value)| component.send "#{name}=", *value }
|
52
62
|
|
53
63
|
# Post-process non-setter opts (setter opts are already consumed by now)
|
54
|
-
post_process
|
64
|
+
component.post_process opts
|
55
65
|
component
|
56
66
|
end
|
57
|
-
|
58
|
-
# Post-processing (non-setter) options given to initialize
|
59
|
-
def post_process component, opts
|
60
|
-
add_component component, opts[:parent]
|
61
|
-
end
|
62
|
-
|
63
|
-
# Proper way to add this component to its parent
|
64
|
-
def add_component component, parent
|
65
|
-
parent.add component if parent
|
66
|
-
end
|
67
67
|
end
|
68
68
|
end
|
69
69
|
end
|
data/spec/awt/component_spec.rb
CHANGED
@@ -3,16 +3,13 @@ require 'awt/component'
|
|
3
3
|
|
4
4
|
describe 'java.awt.Component' do
|
5
5
|
context 'defining new methods' do
|
6
|
-
|
7
|
-
button = Swing::JButton.new 'Disconnect'
|
8
|
-
button.should respond_to :blah
|
9
|
-
button.blah
|
10
|
-
end
|
6
|
+
[Swing::JButton, javax.swing.JButton, Swing::JLabel, Swing::Box].each do |klass|
|
11
7
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
8
|
+
it "changes derived subclases #{klass}" do
|
9
|
+
component = klass == Swing::Box ? klass.new(1) : klass.new('Test')
|
10
|
+
component.should respond_to :attach_to
|
11
|
+
component.should respond_to :post_process
|
12
|
+
end
|
16
13
|
end
|
17
14
|
end
|
18
15
|
|
@@ -9,5 +9,24 @@ describe Swing::JMenuBar do
|
|
9
9
|
it_behaves_like 'enhanced awt component'
|
10
10
|
it_behaves_like 'tool tipped component'
|
11
11
|
|
12
|
+
it 'allows to pass parent in as option' do
|
13
|
+
@frame = Swing::JFrame.new 'Menu Test'
|
14
|
+
bar = Swing::JMenuBar.new :parent => @frame
|
15
|
+
bar.parent.should == @frame.layered_pane
|
16
|
+
@frame.dispose
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'allows to set menu structure via options' do
|
20
|
+
# Creating Connect/Disconnect buttons (parentless - detached, for now)
|
21
|
+
@connect_button = Swing::JButton.new('Connect')
|
22
|
+
|
23
|
+
# Creating Menu Bar with buttons
|
24
|
+
Swing::JMenuBar.new :structure =>
|
25
|
+
[
|
26
|
+
@connect_button,
|
27
|
+
@beep_button = Swing::JButton.new('Beep'),
|
28
|
+
{:File => {:Exit => Proc.new { sleep 1 }}}
|
29
|
+
]
|
30
|
+
end
|
12
31
|
end
|
13
32
|
end
|
data/spec/swing/shared.rb
CHANGED