Skip to content

Commit

Permalink
added button_events module and check_box class
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkdoor committed Nov 4, 2008
1 parent 51a0018 commit 0181d5b
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 9 deletions.
4 changes: 2 additions & 2 deletions examples/numberconverter.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Numberconverter

require "rubygems"
require "rswing"
#require "rubygems"
require "lib/rswing"

include RSwing::Components

Expand Down
2 changes: 2 additions & 0 deletions lib/rswing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class Module
end

# event-modules
require "events/button_events"
require "events/component_events"
require "events/container_events"
require "events/focus_events"
Expand All @@ -53,6 +54,7 @@ class Module
require "window"

require "button"
require "check_box"
require "combo_box"
require "dialog"
require "frame"
Expand Down
10 changes: 4 additions & 6 deletions lib/rswing/components/button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

module RSwing
module Components
ActionListener = java.awt.event.ActionListener
JButton = javax.swing.JButton

# Button-Class. Wraps JButton-Class.
class Button < JButton
include Component
include Events::ButtonEvents

# - <tt>text</tt>: The Text to be displayed on the button.
# - <tt>options</tt>: Options-Hash with the following valid values:
Expand All @@ -46,12 +46,10 @@ def initialize(text, options = {}, &block)
yield self
end

Container.add_if_requested(self, options)
unless options.empty?
Container.add_if_requested(self, options)
end
end

# Eventhandler for clicked (actionPerformed) event.
# Takes a block, which will be executed if this event occurs.
event_for self => :on_click, ActionListener => :actionPerformed
end
end
end
55 changes: 55 additions & 0 deletions lib/rswing/components/check_box.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
###############################################################################
# This file is part of RSwing. #
# RSwing - Swing wrapper for JRuby #
# (C) 2008 Christopher Bertels (bakkdoor@flasht.de) #
# #
# RSwing is free software: you can redistribute it and/or modify #
# it under the terms of the GNU Lesser General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# RSwing is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU Lesser General Public License for more details. #
# #
# You should have received a copy of the GNU Lesser General Public License #
# along with RSwing. If not, see <http://www.gnu.org/licenses/>. #
###############################################################################

module RSwing
module Components
JCheckBox = javax.swing.JCheckBox

# CheckBox-Class. Wraps JCheckBox-Class.
class CheckBox < JCheckBox
include Component
include Events::ButtonEvents

# - <tt>text</tt>: The Text to be displayed on the checkbox.
# - <tt>options</tt>: Options-Hash with the following valid values:
# 1. <tt>:visible => true</tt>
# 2. <tt>:enabled => true</tt>
# 3. <tt>:selected => true</tt> # (default: false)
# 4. <tt>:layout => nil</tt> # Layout-Options (e.g. GridBagContraints-Object) (default: none)
# 5. <tt>:icon => nil</tt> # Icon-Symbol to be displayed next to/instead of the text on the checkbox (default: none)
# 6. <tt>:name => :check_box</tt> Name of the checkbox for access via parent-container (default: none)
def initialize(text, options = {}, &block)
super(text, Options.value_for(options => :selected))

self.visible = Options.value_for(options => :visible)
self.enabled = Options.value_for(options => :enabled)
self.icon = Options.value_for(options => :icon)

# call block with current object, if given
if block_given?
yield self
end

unless options.empty?
Container.add_if_requested(self, options)
end
end
end
end
end
36 changes: 36 additions & 0 deletions lib/rswing/components/events/button_events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
###############################################################################
# This file is part of RSwing. #
# RSwing - Swing wrapper for JRuby #
# (C) 2008 Christopher Bertels (bakkdoor@flasht.de) #
# #
# RSwing is free software: you can redistribute it and/or modify #
# it under the terms of the GNU Lesser General Public License as published by #
# the Free Software Foundation, either version 3 of the License, or #
# (at your option) any later version. #
# #
# RSwing is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU Lesser General Public License for more details. #
# #
# You should have received a copy of the GNU Lesser General Public License #
# along with RSwing. If not, see <http://www.gnu.org/licenses/>. #
###############################################################################

module RSwing
module Components
module Events
module ButtonEvents
ActionListener = java.awt.event.ActionListener
ItemListener = java.awt.event.ItemListener
ChangeListener = javax.swing.event.ChangeListener

# Eventhandler for clicked (actionPerformed) event.
# Takes a block, which will be executed if this event occurs.
event_for self => :on_click, ActionListener => :actionPerformed
event_for self => :on_item_state_changed, ItemListener => :itemStateChanged
event_for self => :on_state_changed, ChangeListener => :stateChanged
end
end
end
end
3 changes: 2 additions & 1 deletion lib/rswing/components/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def self.gui_options
:size => nil,
:location => nil,
:columns => 10,
:text => ""
:text => "",
:selected => false
}
end

Expand Down

0 comments on commit 0181d5b

Please sign in to comment.