Skip to content

Commit

Permalink
window module added. handles attributes for window-classes (e.g. fram…
Browse files Browse the repository at this point in the history
…e and dialog). additional options added.
  • Loading branch information
bakkdoor committed Oct 8, 2008
1 parent 92d2b71 commit e17b501
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 14 deletions.
4 changes: 3 additions & 1 deletion lib/rswing/components/dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ module Components
# (<tt>show()</tt> and <tt>showOptions</tt>).
# Can also be used to create custom dialogs by extending from this class.
class Dialog < JDialog
include Window
include Container

def initialize(title, options = {}, &block)
super(Options.value_for(options => :belongs_to), title, Options.value_for(options => :modal))

Window.init(self, options)

if(name = Options.value_for(options => :name) && owner.class.include?(Container))
owner.add_with_name(self, name)
end
Expand All @@ -21,7 +24,6 @@ def initialize(title, options = {}, &block)
if block_given?
yield self
end

end

# Creates a MessageDialog.
Expand Down
15 changes: 2 additions & 13 deletions lib/rswing/components/frame.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ module Components
JFrame = javax.swing.JFrame

class Frame < JFrame
include Window
include Container

# valid options are:
# 1. <tt>:size => [800, 600]</tt> 800x600 pixels (default: nil)
def initialize(title, options = {}, &block)
super(title)

if(size = Options.value_for(options => :size))
self.size = size
end
Window.init(self, options)

# falls block übergeben wurde, mit aktuellem objekt aufrufen
if block_given?
Expand All @@ -38,16 +37,6 @@ def default_close_operation=(op = :hide_on_close)
self.setDefaultCloseOperation(JFrame::EXIT_ON_CLOSE)
end
end

# Sets the size of the frame. Should be a two-dimensional Array of Integers.
# Example: <tt>frame.size = [800, 600] # 800x600 pixels</tt>
def size=(new_size = nil)
if new_size && new_size.kind_of?(Array)
self.setSize(java.awt.Dimension.new(new_size[0], new_size[1]))
elsif new_size.kind_of? java.awt.Dimension
self.setSize(new_size)
end
end
end
end
end
1 change: 1 addition & 0 deletions lib/rswing/components/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def self.gui_options
:font => nil,
:doc => nil,
:size => nil,
:location => nil,
:columns => 10,
:text => ""
}
Expand Down
41 changes: 41 additions & 0 deletions lib/rswing/components/window.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module RSwing
module Components
module Window
# Initializes a given Window object with some options.
# Valid options include:
# 1. <tt>:size => [100,200] # 100x200 pixels</tt> (default: nil)
# 2. <tt>:location => [50,50] # Upper left window corner location on screen</tt> (default: nil)
def self.init(window, options = {})
if(size = Options.value_for(options => :size))
window.size = size
end

if(location = Options.value_for(options => :location))
window.location = location
end
end

# Sets the size of the window. Should be a two-dimensional <tt>Array</tt> of integers.
# Example: <tt>window.size = [800, 600] # 800x600 pixels</tt>
def size=(new_size = nil)
if new_size && new_size.kind_of?(Array)
self.setSize(java.awt.Dimension.new(new_size[0], new_size[1]))
elsif new_size.kind_of? java.awt.Dimension
self.setSize(new_size)
end
end

# Sets the location of the window. Should be a two-dimensional <tt>Array</tt> of integers.
# Example: <tt>window.size = [100, 200] # Upper left window position at (100,200)</tt>
def location=(new_location = nil)
if new_location
if new_location.kind_of?(Array)
self.setSize(java.awt.Point.new(new_location[0], new_location[1]))
elsif new_location.kind_of? java.awt.Point
self.setLocation(new_location)
end
end
end
end
end
end

0 comments on commit e17b501

Please sign in to comment.