bakkdoor-rswing 0.2.1 → 0.2.2

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/LICENSE CHANGED
@@ -1,5 +1,5 @@
1
1
  RSwing is licensed under the GNU LGPL v3.
2
- Copyright (C) 2008 Christopher Bertels, Waldemar Smirnow.
2
+ Copyright (C) 2008 Christopher Bertels.
3
3
 
4
4
  =============================================================================================
5
5
 
data/lib/rswing.rb CHANGED
@@ -53,6 +53,7 @@ require "container"
53
53
  require "window"
54
54
 
55
55
  require "button"
56
+ require "combo_box"
56
57
  require "dialog"
57
58
  require "frame"
58
59
  require "listener"
@@ -0,0 +1,67 @@
1
+ ###############################################################################
2
+ # This file is part of RSwing. #
3
+ # RSwing - Swing wrapper for JRuby #
4
+ # (C) 2008 Christopher Bertels (bakkdoor@flasht.de) #
5
+ # #
6
+ # RSwing is free software: you can redistribute it and/or modify #
7
+ # it under the terms of the GNU Lesser General Public License as published by #
8
+ # the Free Software Foundation, either version 3 of the License, or #
9
+ # (at your option) any later version. #
10
+ # #
11
+ # RSwing is distributed in the hope that it will be useful, #
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14
+ # GNU Lesser General Public License for more details. #
15
+ # #
16
+ # You should have received a copy of the GNU Lesser General Public License #
17
+ # along with RSwing. If not, see <http://www.gnu.org/licenses/>. #
18
+ ###############################################################################
19
+
20
+ module RSwing
21
+ module Components
22
+ JComboBox = javax.swing.JComboBox
23
+
24
+ class ComboBox < JComboBox
25
+ include Component
26
+
27
+ # Valid items are either an array or a ComboBoxModel object.
28
+ # e.g.: <tt>["First item", "Second item"]</tt> (default: nil)
29
+ #
30
+ # Valid options are:
31
+ # 1. <tt>:belongs_to => container</tt> (default: nil)
32
+ # 2. <tt>:name => :text_field</tt> (default: nil)
33
+ def initialize(items = nil, options = {})
34
+ if(items.kind_of? javax.swing.ComboBoxModel)
35
+ super(items)
36
+ elsif(items.kind_of? Array)
37
+ super(items.to_java(:Object))
38
+ else
39
+ super()
40
+ end
41
+
42
+ unless options.empty?
43
+ Container.add_if_requested(self, options)
44
+ end
45
+ end
46
+
47
+ # Returns an item at a given index.
48
+ # Equivalent to ComboBox#item_at
49
+ def [](item_index)
50
+ self.item_at(item_index)
51
+ end
52
+
53
+ # Returns the items of this ComboBox as an Array.
54
+ def items
55
+ @items = []
56
+
57
+ self.item_count.times do |i|
58
+ @items << self[i]
59
+ end
60
+
61
+ @items
62
+ end
63
+
64
+ end
65
+
66
+ end
67
+ end
@@ -23,10 +23,17 @@ module RSwing
23
23
  module ComponentEvents
24
24
  ComponentListener = java.awt.event.ComponentListener
25
25
 
26
- event_for self => :on_component_hidden, ComponentListener => :componentHidden
27
- event_for self => :on_component_moved, ComponentListener => :componentMoved
28
- event_for self => :on_component_resized, ComponentListener => :componentResized
29
- event_for self => :on_component_shown, ComponentListener => :componentShown
26
+ def ComponentEvents.event_mappings
27
+ {
28
+ :on_component_hidden => :componentHidden,
29
+ :on_component_moved => :componentMoved,
30
+ :on_component_resized => :componentResized,
31
+ :on_component_shown => :componentShown
32
+ }
33
+ end
34
+
35
+ Events.map self, ComponentListener, event_mappings
36
+
30
37
  end
31
38
  end
32
39
  end
@@ -23,8 +23,15 @@ module RSwing
23
23
  module ContainerEvents
24
24
  ContainerListener = java.awt.event.ContainerListener
25
25
 
26
- event_for self => :on_component_added, ContainerListener => :componentAdded
27
- event_for self => :on_component_removed, ContainerListener => :componentRemoved
26
+ def ContainerEvents.event_mappings
27
+ {
28
+ :on_component_added => :componentAdded,
29
+ :on_component_removed => :componentRemoved
30
+ }
31
+ end
32
+
33
+ Events.map self, ContainerListener, event_mappings
34
+
28
35
  end
29
36
  end
30
37
  end
@@ -47,6 +47,15 @@ module RSwing
47
47
  end
48
48
  end
49
49
  end
50
+
51
+ # maps the events of a listener_class to a module, specified in a event_mappings_hash
52
+ # e.g. (in FocusEvents-Module): <tt>Events.map self, FocusListener, FocusEvents.event_mappings</tt>
53
+ def Events.map(module_to_map, listener_class_to_map, event_mappings_hash)
54
+ event_mappings_hash.each_pair do |ruby_event, java_method|
55
+ event_for module_to_map => ruby_event, listener_class_to_map => java_method
56
+ end
57
+ end
58
+
50
59
  end
51
60
  end
52
61
  end
@@ -23,13 +23,15 @@ module RSwing
23
23
  module FocusEvents
24
24
  FocusListener = java.awt.event.FocusListener
25
25
 
26
- # Eventhandler for on_focus (focusGained) event.
27
- # Takes a block, which will get executed, when this event is fired.
28
- event_for self => :on_focus, FocusListener => :focusGained
26
+ def FocusEvents.event_mappings
27
+ {
28
+ :on_focus => :focusGained,
29
+ :on_focus_lost => :focusLost
30
+ }
31
+ end
32
+
33
+ Events.map self, FocusListener, event_mappings
29
34
 
30
- # Eventhandler for focus_lost (focusLost) event.
31
- # Takes a block, which will get executed, when this event is fired.
32
- event_for self => :on_focus_lost, FocusListener => :focusLost
33
35
  end
34
36
  end
35
37
  end
@@ -23,8 +23,15 @@ module RSwing
23
23
  module HierarchyBoundsEvents
24
24
  HierarchyBoundsListener = java.awt.event.HierarchyBoundsListener
25
25
 
26
- event_for self => :on_ancestor_moved, HierarchyBoundsListener => :ancestorMoved
27
- event_for self => :on_ancestor_resized, HierarchyBoundsListener => :ancestorResized
26
+ def HierarchyBoundsEvents.event_mappings
27
+ {
28
+ :on_ancestor_moved => :ancestorMoved,
29
+ :on_ancestor_resized => :ancestorResized
30
+ }
31
+ end
32
+
33
+ Events.map self, HierarchyBoundsListener, event_mappings
34
+
28
35
  end
29
36
  end
30
37
  end
@@ -23,8 +23,15 @@ module RSwing
23
23
  module InputMethodEvents
24
24
  InputMethodListener = java.awt.event.InputMethodListener
25
25
 
26
- event_for self => :on_input_method_text_changed, InputMethodListener => :inputMethodTextChanged
27
- event_for self => :on_caret_position_changed, InputMethodListener => :caretPositionChanged
26
+ def InputMethodEvents.event_mappings
27
+ {
28
+ :on_input_method_text_changed => :inputMethodTextChanged,
29
+ :on_caret_position_changed => :caretPositionChanged
30
+ }
31
+ end
32
+
33
+ Events.map self, InputMethodListener, event_mappings
34
+
28
35
  end
29
36
  end
30
37
  end
@@ -23,9 +23,16 @@ module RSwing
23
23
  module KeyEvents
24
24
  KeyListener = java.awt.event.KeyListener
25
25
 
26
- event_for self => :on_key_pressed, KeyListener => :keyPressed
27
- event_for self => :on_key_released, KeyListener => :keyReleased
28
- event_for self => :on_key_typed, KeyListener => :keyTyped
26
+ def KeyEvents.event_mappings
27
+ {
28
+ :on_key_pressed => :keyPressed,
29
+ :on_key_released => :keyReleased,
30
+ :on_key_typed => :keyTyped
31
+ }
32
+ end
33
+
34
+ Events.map self, KeyListener, event_mappings
35
+
29
36
  end
30
37
  end
31
38
  end
@@ -23,11 +23,18 @@ module RSwing
23
23
  module MouseEvents
24
24
  MouseListener = java.awt.event.MouseListener
25
25
 
26
- event_for self => :on_mouse_clicked, MouseListener => :mouseClicked
27
- event_for self => :on_mouse_entered, MouseListener => :mouseEntered
28
- event_for self => :on_mouse_exited, MouseListener => :mouseExited
29
- event_for self => :on_mouse_pressed, MouseListener => :mousePressed
30
- event_for self => :on_mouse_released, MouseListener => :mouseReleased
26
+ def MouseEvents.event_mappings
27
+ {
28
+ :on_mouse_clicked => :mouseClicked,
29
+ :on_mouse_entered => :mouseEntered,
30
+ :on_mouse_exited => :mouseExited,
31
+ :on_mouse_pressed => :mousePressed,
32
+ :on_mouse_released => :mouseReleased
33
+ }
34
+ end
35
+
36
+ Events.map self, MouseListener, event_mappings
37
+
31
38
  end
32
39
  end
33
40
  end
@@ -23,8 +23,15 @@ module RSwing
23
23
  module MouseMotionEvents
24
24
  MouseMotionListener = java.awt.event.MouseMotionListener
25
25
 
26
- event_for self => :on_mouse_dragged, MouseMotionListener => :mouseDragged
27
- event_for self => :on_mouse_moved, MouseMotionListener => :mouseMoved
26
+ def MouseMotionEvents.event_mappings
27
+ {
28
+ :on_mouse_dragged => :mouseDragged,
29
+ :on_mouse_moved => :mouseMoved
30
+ }
31
+ end
32
+
33
+ Events.map self, MouseMotionListener, event_mappings
34
+
28
35
  end
29
36
  end
30
37
  end
@@ -23,13 +23,20 @@ module RSwing
23
23
  module WindowEvents
24
24
  WindowListener = java.awt.event.WindowListener
25
25
 
26
- event_for self => :on_window_activated, WindowListener => :windowActivated
27
- event_for self => :on_window_closed, WindowListener => :windowClosed
28
- event_for self => :on_window_closing, WindowListener => :windowClosing
29
- event_for self => :on_window_deactivated, WindowListener => :windowDeactivated
30
- event_for self => :on_window_deiconified, WindowListener => :windowDeiconified
31
- event_for self => :on_window_iconified, WindowListener => :windowIconified
32
- event_for self => :on_window_opened, WindowListener => :windowOpened
26
+ def WindowEvents.event_mappings
27
+ {
28
+ :on_window_activated => :windowActivated,
29
+ :on_window_closed => :windowClosed,
30
+ :on_window_closing => :windowClosing,
31
+ :on_window_deactivated => :windowDeactivated,
32
+ :on_window_deiconified => :windowDeiconified,
33
+ :on_window_iconified => :windowIconified,
34
+ :on_window_opened => :windowOpened
35
+ }
36
+ end
37
+
38
+ Events.map self, WindowListener, event_mappings
39
+
33
40
  end
34
41
  end
35
42
  end
@@ -23,8 +23,15 @@ module RSwing
23
23
  module WindowFocus
24
24
  WindowFocusListener = java.awt.event.WindowFocusListener
25
25
 
26
- event_for self => :on_window_focus, WindowFocusListener => :windowGainedFocus
27
- event_for self => :on_window_focus_lost, WindowFocusListener => :windowLostFocus
26
+ def WindowFocus.event_mappings
27
+ {
28
+ :on_window_focus => :windowGainedFocus,
29
+ :on_window_focus_lost => :windowLostFocus
30
+ }
31
+ end
32
+
33
+ Events.map self, WindowFocusListener, event_mappings
34
+
28
35
  end
29
36
  end
30
37
  end
@@ -31,6 +31,8 @@ module RSwing
31
31
  # 4. <tt>:font => nil</tt> (default nil)
32
32
  # 5. <tt>:visible => false</tt> (default: true)
33
33
  # 6. <tt>:editable => false</tt> (default: true)
34
+ # 7. <tt>:belongs_to => container</tt> (default: nil)
35
+ # 8. <tt>:name => :text_field</tt> (default: nil)
34
36
  def initialize(options = {})
35
37
  if(options.empty?)
36
38
  super()
data/test/test_button.rb CHANGED
@@ -12,6 +12,6 @@ class TestButton < Test::Unit::TestCase
12
12
  end
13
13
 
14
14
  def test_events
15
- should_have_events @button => [:on_click, :on_focus, :on_focus_lost]
15
+ should_have_events @button => Events::ComponentEvents.event_mappings.keys
16
16
  end
17
17
  end
@@ -50,6 +50,6 @@ class TestContainer < Test::Unit::TestCase
50
50
 
51
51
  def test_events
52
52
  frame = Frame.new "my frame"
53
- should_have_events frame => [:on_focus, :on_focus_lost, :on_property_changed]
53
+ should_have_events frame => Events::ContainerEvents.event_mappings.keys
54
54
  end
55
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bakkdoor-rswing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Bertels
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-03 00:00:00 -08:00
12
+ date: 2008-11-04 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -27,6 +27,7 @@ files:
27
27
  - Rakefile
28
28
  - lib/rswing.rb
29
29
  - lib/rswing/components/button.rb
30
+ - lib/rswing/components/combo_box.rb
30
31
  - lib/rswing/components/component.rb
31
32
  - lib/rswing/components/container.rb
32
33
  - lib/rswing/components/dialog.rb