Module: RSwing::Components::Window

Includes:
Container, Events::PropertyChanged, Events::WindowFocus, Events::WindowState
Included in:
Dialog, Frame
Defined in:
lib/rswing/components/window.rb

Constant Summary

Constants included from Events::WindowFocus

Events::WindowFocus::WindowFocusListener

Constants included from Events::WindowState

Events::WindowState::WindowStateListener

Constants included from Events::PropertyChanged

Events::PropertyChanged::PropertyChangeListener

Constants included from Events::ContainerEvents

Events::ContainerEvents::ContainerListener

Constants included from Events::FocusEvents

Events::FocusEvents::FocusListener

Constants included from Events::InputMethodEvents

Events::InputMethodEvents::InputMethodListener

Constants included from Events::HierarchyBoundsEvents

Events::HierarchyBoundsEvents::HierarchyBoundsListener

Constants included from Events::KeyEvents

Events::KeyEvents::KeyListener

Constants included from Events::MouseWheelEvents

Events::MouseWheelEvents::MouseWheelListener

Constants included from Events::MouseMotionEvents

Events::MouseMotionEvents::MouseMotionListener

Constants included from Events::MouseEvents

Events::MouseEvents::MouseListener

Constants included from Events::ComponentEvents

Events::ComponentEvents::ComponentListener

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Events::WindowFocus

event_mappings

Methods included from Container

#[], #add, add_if_requested, #add_with_name, #components, #remove

Methods included from Events::ContainerEvents

event_mappings

Methods included from Events::FocusEvents

event_mappings

Methods included from Events::InputMethodEvents

event_mappings

Methods included from Events::HierarchyBoundsEvents

event_mappings

Methods included from Events::KeyEvents

event_mappings

Methods included from Events::MouseMotionEvents

event_mappings

Methods included from Events::MouseEvents

event_mappings

Methods included from Events::ComponentEvents

event_mappings

Class Method Details

.init(window, options = {}) ⇒ Object

Initializes a given Window object with some options. Valid options include:

  1. :size => [100,200] # 100x200 pixels (default: nil)

  2. :location => [50,50] # Upper left window corner location on screen (default: nil)



34
35
36
37
38
39
40
41
42
# File 'lib/rswing/components/window.rb', line 34

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

Instance Method Details

#location=(new_location = :center) ⇒ Object

Sets the location of the window. Should be a two-dimensional Array of integers.

Example: window.size = [100, 200] # Upper left window position at (100,200)

Also valid standard locations are:

  1. :center

  2. :upper_left

  3. :upper_right

  4. :lower_left

  5. :lower_right

  6. :top_center

  7. :bottom_center



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/rswing/components/window.rb', line 67

def location=(new_location = :center)
  if new_location
    if new_location.kind_of?(Array)
      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
        x = 0
        y = 0
      when :upper_right
        x = screen_dimension.width - self.width
        y = 0
      when :lower_left
        x = 0
        y = screen_dimension.height - self.height
      when :lower_right
        x = screen_dimension.width - self.width
        y = screen_dimension.height - self.height
      when :top_center
        x = ((screen_dimension.width - self.width) / 2).to_i
        y = 0
      when :bottom_center
        x = ((screen_dimension.width - self.width) / 2).to_i
        y = screen_dimension.height - self.height
      end
      
      # set the new location for window
      self.location = [x, y]
    end
  end
end

#size=(new_size = nil) ⇒ Object

Sets the size of the window. Should be a two-dimensional Array of integers. Example: window.location = [800, 600] # 800x600 pixels



46
47
48
49
50
51
52
# File 'lib/rswing/components/window.rb', line 46

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