Skip to content

Commit

Permalink
default locations added. for now only :center works. also updated rsw…
Browse files Browse the repository at this point in the history
…ing.rb, since it missed the require for the new window module
  • Loading branch information
bakkdoor committed Oct 8, 2008
1 parent e17b501 commit 9a2790f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
21 changes: 13 additions & 8 deletions lib/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@ module Main
require "rswing"

include RSwing::Components

BorderLayout = java.awt.BorderLayout
# geht genauso wie die 'normale' variante:
# frame = Frame.new("hallo, welt")
# ... # hier dann einfach auch zugriffe auf frame
Frame.new("hallo, welt", :size => [800, 600]) do |frame|
Frame.new("hallo, welt", :size => [800, 600], :location => :center) do |frame|
frame.default_close_operation = :exit_on_close

Panel.new(java.awt.GridLayout.new(1,1), :size => [300, 500], :name => :panel, :belongs_to => frame) do |panel|
Button.new("test", :belongs_to => panel, :name => :testButton) do |btn|
Panel.new(:name => :panel, :belongs_to => frame, :layout_manager => BorderLayout.new) do |panel|
Button.new("test", :belongs_to => panel, :name => :testButton, :layout => BorderLayout::NORTH) do |btn|
btn.on_click do
Dialog.showOption "bitte auswählen:", :option_type => :yes_no, :option_values => ["Aha", "ohno"],
:title => "auswahl treffen!", :belongs_to => frame
end

btn.on_click do
Dialog.show("mein text", :dialog_type => :error, :title => "hello, world", :belongs_to => frame)
Dialog.show "mein text",
:dialog_type => :error,
:title => "hello, world",
:belongs_to => frame,
:location => :center
end


Expand Down Expand Up @@ -45,14 +49,15 @@ module Main
end

# dialog testen
Dialog.new("mein titel", :modal => true) do |dial|
Dialog.new("mein titel", :modal => true, :location => :center, :size => [500,500]) do |dial|
Button.new("click me", :belongs_to => dial, :name => :clickButton) do |button|
button.on_click do
Dialog.show("test dialog", :dialog_type => :info, :title => "hey, was geht?")
Dialog.show "test dialog",
:dialog_type => :info,
:title => "hey, was geht?"
end
end

dial.size = java.awt.Dimension.new(300,300)
dial.visible = true
end

Expand Down
4 changes: 3 additions & 1 deletion lib/rswing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
require "events/mouse_events"

# containers
require "button"
require "container"
require "window"

require "button"
require "dialog"
require "frame"
require "listener"
Expand Down
36 changes: 32 additions & 4 deletions lib/rswing/components/window.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.init(window, options = {})
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>
# Example: <tt>window.location = [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]))
Expand All @@ -26,13 +26,41 @@ def size=(new_size = nil)
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)
#
# Example:
# <tt>window.size = [100, 200] # Upper left window position at (100,200)</tt>
#
# Also valid standard locations are:
# 1. <tt>:center</tt>
# 2. <tt>:upper_left</tt>
# 3. <tt>:upper_right</tt>
# 4. <tt>:lower_left</tt>
# 5. <tt>:lower_right</tt>
# 6. <tt>:top_center</tt>
# 7. <tt>:bottom_center</tt>
def location=(new_location = :center)
if new_location
if new_location.kind_of?(Array)
self.setSize(java.awt.Point.new(new_location[0], new_location[1]))
self.setLocation(java.awt.Point.new(new_location[0], new_location[1]))
elsif new_location.kind_of? java.awt.Point
self.setLocation(new_location)
else
# possibly one of the following standard options was chosen:
screen_dimension = java.awt.Toolkit.default_toolkit.screen_size
case new_location
when :center
x = ((screen_dimension.width - self.width) / 2).to_i
y = ((screen_dimension.height - self.height) / 2).to_i
when :upper_left
when :upper_right
when :lower_left
when :lower_right
when :top_center
when :bottom_center
end

# set the new location for window
self.location = [x, y]
end
end
end
Expand Down

0 comments on commit 9a2790f

Please sign in to comment.