swing 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY CHANGED
@@ -41,3 +41,7 @@
41
41
  == 0.1.4 / 2011-05-26
42
42
 
43
43
  * More specs
44
+
45
+ == 0.1.5 / 2011-05-26
46
+
47
+ * Attributes speced
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
data/lib/awt/component.rb CHANGED
@@ -16,7 +16,6 @@ class Awt::Component
16
16
  # layout LayoutManager � � BorderLayout( )
17
17
  # locale Locale � �
18
18
  # location Point � �
19
- # locationOnScreen Point � �
20
19
  # name String � � ""
21
20
  # parent Container � � null
22
21
  # size Dimension � �
@@ -27,9 +26,10 @@ class Awt::Component
27
26
  # componentCount int �
28
27
  # components Component[] �
29
28
  # insets Insets � Insets(0,0,0,0)
29
+ # locationOnScreen Point � �
30
30
  # showing boolean � true
31
31
  # valid boolean �
32
32
 
33
- attr_setter :background, :cursor, :enabled, :font, :foreground, :layout, :locale,
34
- :location, :location_on_screen, :name, :parent, :size, :visible
33
+ attr_setter :background, :cursor, :enabled, :font, :foreground, :layout,
34
+ :locale, :location, :name, :size, :visible
35
35
  end
data/lib/swing/j_list.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require 'swing'
2
2
 
3
3
  class Swing::JList
4
+
4
5
  attr_setter :tool_tip_text
5
6
 
6
- end # class List
7
+ end # class JList
7
8
 
@@ -6,9 +6,9 @@ class Swing::JMenuBar
6
6
 
7
7
  attr_setter :tool_tip_text
8
8
 
9
- def initialize opts = {}
10
- super opts
11
-
9
+ # Override post-processing (non-setter) options given to initialize
10
+ def self.post_process component, opts
11
+ # Create menu structure from :structure opt
12
12
  if opts[:structure]
13
13
  [opts[:structure]].flatten.each do |element|
14
14
  case element
@@ -20,15 +20,17 @@ class Swing::JMenuBar
20
20
  end
21
21
  end
22
22
  else
23
- self.add element
23
+ component.add element
24
24
  end
25
25
  end
26
26
  end
27
+ add_component component, opts[:parent]
27
28
  end
28
29
 
29
- # Post-processing (non-setter) options given to initialize
30
+ # Proper way to add menu bar to its parent
30
31
  def self.add_component component, parent
31
- parent.setJMenuBar component if parent
32
+ parent.setJMenuBar component if parent and parent.respond_to? :setJMenuBar
32
33
  end
33
34
 
35
+
34
36
  end
@@ -1,10 +1,12 @@
1
1
  require 'swing'
2
2
 
3
3
  class Swing::JMenuItem
4
+
4
5
  attr_setter :tool_tip_text
5
6
 
6
- def initialize text, opts = {}, &block
7
+ def initialize text, &block
7
8
  super text
8
- self.addActionListener SwingHelper::ActionListener.new &block
9
+ self.addActionListener SwingSupport::ActionListener.new &block
9
10
  end
11
+
10
12
  end
data/lib/swing/j_panel.rb CHANGED
@@ -3,4 +3,5 @@ require 'swing'
3
3
  class Swing::JPanel
4
4
 
5
5
  attr_setter :tool_tip_text
6
+
6
7
  end # class Panel
@@ -6,7 +6,11 @@ class Swing::JSplitPane
6
6
  attr_setter :one_touch_expandable, :orientation, :continuous_layout,
7
7
  :divider_size, :divider_location, :resize_weight
8
8
 
9
- def initialize first, second, opts = {}
10
- super(HORIZONTAL_SPLIT, first, second)
9
+ def initialize *args
10
+ if args.size == 2
11
+ super HORIZONTAL_SPLIT, *args
12
+ else
13
+ super *args
14
+ end
11
15
  end
12
16
  end # class JSplitPane
@@ -50,12 +50,17 @@ module SwingSupport
50
50
  # yield opts if block_given?
51
51
  attributes.each { |(name, value)| component.send "#{name}=", *value }
52
52
 
53
- # Post-process non-setter opts
54
- add_component component, opts[:parent]
53
+ # Post-process non-setter opts (setter opts are already consumed by now)
54
+ post_process component, opts
55
55
  component
56
56
  end
57
57
 
58
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
59
64
  def add_component component, parent
60
65
  parent.add component if parent
61
66
  end
@@ -7,15 +7,11 @@ describe Swing::JButton do
7
7
  let(:new_args) { ['Text'] }
8
8
 
9
9
  it_behaves_like 'enhanced awt component'
10
+ it_behaves_like 'tool tipped component'
10
11
 
11
12
  it 'is possible to set :enabled attribute to false' do
12
13
  button = Swing::JButton.new 'Disconnect', :enabled => false
13
14
  button.should_not be_enabled
14
15
  end
15
-
16
- it 'is possible to set :tool_tip_text attribute' do
17
- button = Swing::JButton.new 'Disconnect', :tool_tip_text => 'Blah'
18
- button.tool_tip_text.should == 'Blah'
19
- end
20
16
  end
21
17
  end
@@ -7,15 +7,11 @@ describe Swing::JCheckBox do
7
7
  let(:new_args) { ['Text'] }
8
8
 
9
9
  it_behaves_like 'enhanced awt component'
10
+ it_behaves_like 'tool tipped component'
10
11
 
11
12
  it 'is possible to set :selected attribute' do
12
13
  box = Swing::JCheckBox.new 'Disconnect', :selected => true
13
14
  box.should be_selected
14
15
  end
15
-
16
- it 'is possible to set :tool_tip_text attribute' do
17
- box = Swing::JCheckBox.new 'Disconnect', :tool_tip_text => 'Blah'
18
- box.tool_tip_text.should == 'Blah'
19
- end
20
16
  end
21
17
  end
@@ -3,15 +3,18 @@ require 'swing/shared'
3
3
 
4
4
  describe Swing::JFrame do
5
5
 
6
- context 'creation' do
7
- let(:new_args) { ['Text'] }
6
+ context 'creating' do
7
+ after(:each) {@frame.dispose if @frame}
8
+ let(:new_args) { ['Frame'] }
8
9
 
9
10
  it_behaves_like 'enhanced awt component'
10
11
 
11
- it 'is possible to create frame' do
12
- f = Swing::JFrame.new "Swing GUI",
12
+ it 'is possible to create Frame with options' do
13
+ @frame = Swing::JFrame.new "Swing GUI",
13
14
  :layout => Awt::FlowLayout.new(Awt::FlowLayout::LEFT),
14
15
  :size => [1100, 1200]
15
16
  end
17
+
18
+
16
19
  end
17
20
  end
@@ -7,10 +7,6 @@ describe Swing::JLabel do
7
7
  let(:new_args) { ['Text'] }
8
8
 
9
9
  it_behaves_like 'enhanced awt component'
10
-
11
- it 'is possible to set :tool_tip_text attribute' do
12
- label = Swing::JLabel.new 'Disconnect', :tool_tip_text => 'Blah'
13
- label.tool_tip_text.should == 'Blah'
14
- end
10
+ it_behaves_like 'tool tipped component'
15
11
  end
16
12
  end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+ require 'swing/shared'
3
+
4
+ describe Swing::JList do
5
+
6
+ context 'creation' do
7
+ let(:new_args) { [] }
8
+
9
+ it_behaves_like 'enhanced awt component'
10
+ it_behaves_like 'tool tipped component'
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+ require 'swing/shared'
3
+
4
+ describe Swing::JMenuBar do
5
+
6
+ context 'creation' do
7
+ let(:new_args) { [] }
8
+
9
+ it_behaves_like 'enhanced awt component'
10
+ it_behaves_like 'tool tipped component'
11
+
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+ require 'swing/shared'
3
+
4
+ describe Swing::JMenuItem do
5
+
6
+ context 'creation' do
7
+ let(:new_args) { ['Text'] }
8
+
9
+ it_behaves_like 'enhanced awt component'
10
+ it_behaves_like 'tool tipped component'
11
+
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+ require 'swing/shared'
3
+
4
+ describe Swing::JMenu do
5
+
6
+ context 'creation' do
7
+ let(:new_args) { ['Text'] }
8
+
9
+ it_behaves_like 'enhanced awt component'
10
+ it_behaves_like 'tool tipped component'
11
+
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+ require 'swing/shared'
3
+
4
+ describe Swing::JPanel do
5
+
6
+ context 'creation' do
7
+ let(:new_args) { [] }
8
+
9
+ it_behaves_like 'enhanced awt component'
10
+ it_behaves_like 'tool tipped component'
11
+
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require 'swing/shared'
3
+
4
+ describe Swing::JScrollPane do
5
+
6
+ context 'creation' do
7
+ let(:new_args) { [] }
8
+ let(:layout) { Swing::ScrollPaneLayout.new }
9
+
10
+ it_behaves_like 'enhanced awt component'
11
+ it_behaves_like 'tool tipped component'
12
+
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+ require 'swing/shared'
3
+
4
+ describe Swing::JSplitPane do
5
+
6
+ context 'creation' do
7
+ let(:new_args) { [] }
8
+
9
+ it_behaves_like 'enhanced awt component'
10
+ it_behaves_like 'tool tipped component'
11
+
12
+ it 'is possible to use constructor with two children' do
13
+ b1 = Swing::JButton.new 'First'
14
+ b2 = Swing::JButton.new 'Second'
15
+ pane = Swing::JSplitPane.new b1, b2, :tool_tip_text => 'Blah'
16
+ pane.tool_tip_text.should == 'Blah'
17
+ pane.left_component.should == b1
18
+ pane.right_component.should == b2
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+ require 'swing/shared'
3
+
4
+ describe Swing::JTable do
5
+
6
+ context 'creation' do
7
+ let(:new_args) { [2,2] }
8
+
9
+ it_behaves_like 'enhanced awt component'
10
+ it_behaves_like 'tool tipped component'
11
+
12
+ end
13
+ end
data/spec/swing/shared.rb CHANGED
@@ -1,40 +1,47 @@
1
1
  shared_examples_for 'enhanced awt component' do
2
2
 
3
+ def should_be_all_set component, attributes
4
+
5
+ end
6
+
7
+ after(:each) { @component.dispose if @component.respond_to? :dispose }
8
+
3
9
  context 'new with common options' do
4
- it 'is possible to create components with settable attribute' do
5
- p described_class.attributes
6
- background = Awt::Color.new(1, 2, 3)
7
- cursor = Awt::Cursor.new Awt::Cursor::HAND_CURSOR #DEFAULT_CURSOR
8
- enabled = false
9
- font = Awt::Font.new("Trebuchet", Awt::Font::PLAIN, 11)
10
- new_args.push :background => background, :cursor => cursor, :enabled => enabled,
11
- :font => font, :name => 'Blah'
12
- component = described_class.new *new_args
13
- component.background.should == background
14
- component.cursor.should == cursor
15
- component.enabled?.should == false
16
- component.font.should == font
17
- component.name.should == 'Blah'
18
- component.parent.should == nil
10
+ it 'is possible to create this component with settable attribute' do
11
+ # p described_class.attributes
12
+ component_attributes = {
13
+ :background => Awt::Color.new(1, 2, 3),
14
+ :foreground => Awt::Color.new(3, 2, 1),
15
+ :cursor => Awt::Cursor.new(Awt::Cursor::HAND_CURSOR),
16
+ :enabled => false,
17
+ :visible => false,
18
+ :font => Awt::Font.new("Trebuchet", Awt::Font::PLAIN, 11),
19
+ :layout => (defined?(layout) ? layout : Awt::FlowLayout.new),
20
+ :location => Awt::Point.new(10, 20),
21
+ :size => Awt::Dimension.new(300, 300),
22
+ :name => 'Blah',
23
+ }
24
+ @component = described_class.new *(new_args.push component_attributes)
25
+ component_attributes.each do |name, value|
26
+ @component.send(name).should == value
27
+ end
19
28
  end
20
29
  end
21
30
 
22
- # context 'new with options (without parent)' do
23
- # {Swing::JLabel => 'Text', Swing::JButton => 'Text', Swing::JCheckBox => 'Text',
24
- # Swing::JFrame => 'Text', Swing::JList => [], Swing::JMenu => [], Swing::JMenuBar=> [],
25
- # Swing::JMenuItem => [], Swing::JPanel => [], Swing::JScrollPane => [],
26
- # Swing::JSplitPane => [], Swing::JTable => [2, 2]}.each do |klass, args|
27
- # it 'is possible to create components with settable attribute' do
28
- # p klass.attributes
29
- # constructor_args.push constructor_options
30
- # component = klass.new(*args, :name => 'Blah')
31
- # component.name.should == 'Blah'
32
- # component.parent.should == nil
33
- # end
34
- # end
35
- # end
31
+ context 'new with parent' do
32
+ unless described_class == Swing::JFrame || described_class == Swing::JMenuBar
33
+ it 'is possible to set parent via options' do
34
+ parent = Swing::JPanel.new
35
+ @component = described_class.new *(new_args.push :parent => parent)
36
+ @component.parent.should == parent
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ shared_examples_for 'tool tipped component' do
43
+ it 'is possible to set :tool_tip_text attribute' do
44
+ @component = described_class.new *(new_args.push :tool_tip_text => 'Blah')
45
+ @component.tool_tip_text.should == 'Blah'
46
+ end
36
47
  end
37
- #{Swing::JLabel => 'Text', Swing::JButton => 'Text', Swing::JCheckBox => 'Text',
38
- # Swing::JFrame => 'Text', Swing::JList => [], Swing::JMenu => [], Swing::JMenuBar=> [],
39
- # Swing::JMenuItem => [], Swing::JPanel => [], Swing::JScrollPane => [],
40
- # Swing::JSplitPane => [], Swing::JTable => [2, 2]}.each do |klass, args|
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: swing
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.4
5
+ version: 0.1.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - arvicco
@@ -90,6 +90,14 @@ files:
90
90
  - spec/swing/j_check_box_spec.rb
91
91
  - spec/swing/j_frame_spec.rb
92
92
  - spec/swing/j_label_spec.rb
93
+ - spec/swing/j_list_spec.rb
94
+ - spec/swing/j_menu_bar_spec.rb
95
+ - spec/swing/j_menu_item_spec.rb
96
+ - spec/swing/j_menu_spec.rb
97
+ - spec/swing/j_panel_spec.rb
98
+ - spec/swing/j_scroll_pane_spec.rb
99
+ - spec/swing/j_split_pane_spec.rb
100
+ - spec/swing/j_table_spec.rb
93
101
  - spec/swing/shared.rb
94
102
  - features/swing.feature
95
103
  - features/step_definitions/swing_steps.rb
@@ -148,4 +156,12 @@ test_files:
148
156
  - spec/swing/j_check_box_spec.rb
149
157
  - spec/swing/j_frame_spec.rb
150
158
  - spec/swing/j_label_spec.rb
159
+ - spec/swing/j_list_spec.rb
160
+ - spec/swing/j_menu_bar_spec.rb
161
+ - spec/swing/j_menu_item_spec.rb
162
+ - spec/swing/j_menu_spec.rb
163
+ - spec/swing/j_panel_spec.rb
164
+ - spec/swing/j_scroll_pane_spec.rb
165
+ - spec/swing/j_split_pane_spec.rb
166
+ - spec/swing/j_table_spec.rb
151
167
  - spec/swing/shared.rb