swing 0.1.5 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -13,13 +13,15 @@ tmtags
13
13
  ## VIM
14
14
  *.swp
15
15
 
16
+ ## IDEA
17
+ *.iml
18
+ .idea
19
+
16
20
  ## PROJECT::GENERAL
17
21
  coverage
18
22
  rdoc
19
23
  pkg
20
24
  log
21
- .iml
22
- .idea
23
25
  .bundle
24
26
 
25
27
  ## PROJECT::SPECIFIC
data/HISTORY CHANGED
@@ -45,3 +45,11 @@
45
45
  == 0.1.5 / 2011-05-26
46
46
 
47
47
  * Attributes speced
48
+
49
+ == 0.1.6 / 2011-05-26
50
+
51
+ * JMenuBar fixed
52
+
53
+ == 0.1.7 / 2011-05-26
54
+
55
+ * Minor fixes
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.5
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
- setup
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
@@ -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 self.post_process component, opts
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
- component.add element
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 self.add_component component, parent
32
- parent.setJMenuBar component if parent and parent.respond_to? :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 component, opts
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
@@ -3,16 +3,13 @@ require 'awt/component'
3
3
 
4
4
  describe 'java.awt.Component' do
5
5
  context 'defining new methods' do
6
- it 'changes derived Ruby subclases' do
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
- it 'changes derived pure Java subclases' do
13
- button = javax.swing.JButton.new 'Disconnect'
14
- button.should respond_to :blah
15
- button.blah
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
@@ -1,9 +1,5 @@
1
1
  shared_examples_for 'enhanced awt component' do
2
2
 
3
- def should_be_all_set component, attributes
4
-
5
- end
6
-
7
3
  after(:each) { @component.dispose if @component.respond_to? :dispose }
8
4
 
9
5
  context 'new with common options' do
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
5
+ version: 0.1.7
6
6
  platform: ruby
7
7
  authors:
8
8
  - arvicco