bakkdoor-rswing 0.1.3 → 0.1.4
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/lib/rswing/components/window.rb +81 -0
- metadata +3 -2
@@ -0,0 +1,81 @@
|
|
1
|
+
module RSwing
|
2
|
+
module Components
|
3
|
+
module Window
|
4
|
+
# Initializes a given Window object with some options.
|
5
|
+
# Valid options include:
|
6
|
+
# 1. <tt>:size => [100,200] # 100x200 pixels</tt> (default: nil)
|
7
|
+
# 2. <tt>:location => [50,50] # Upper left window corner location on screen</tt> (default: nil)
|
8
|
+
def self.init(window, options = {})
|
9
|
+
if(size = Options.value_for(options => :size))
|
10
|
+
window.size = size
|
11
|
+
end
|
12
|
+
|
13
|
+
if(location = Options.value_for(options => :location))
|
14
|
+
window.location = location
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Sets the size of the window. Should be a two-dimensional <tt>Array</tt> of integers.
|
19
|
+
# Example: <tt>window.location = [800, 600] # 800x600 pixels</tt>
|
20
|
+
def size=(new_size = nil)
|
21
|
+
if new_size && new_size.kind_of?(Array)
|
22
|
+
self.setSize(java.awt.Dimension.new(new_size[0], new_size[1]))
|
23
|
+
elsif new_size.kind_of? java.awt.Dimension
|
24
|
+
self.setSize(new_size)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# Sets the location of the window. Should be a two-dimensional <tt>Array</tt> of integers.
|
29
|
+
#
|
30
|
+
# Example:
|
31
|
+
# <tt>window.size = [100, 200] # Upper left window position at (100,200)</tt>
|
32
|
+
#
|
33
|
+
# Also valid standard locations are:
|
34
|
+
# 1. <tt>:center</tt>
|
35
|
+
# 2. <tt>:upper_left</tt>
|
36
|
+
# 3. <tt>:upper_right</tt>
|
37
|
+
# 4. <tt>:lower_left</tt>
|
38
|
+
# 5. <tt>:lower_right</tt>
|
39
|
+
# 6. <tt>:top_center</tt>
|
40
|
+
# 7. <tt>:bottom_center</tt>
|
41
|
+
def location=(new_location = :center)
|
42
|
+
if new_location
|
43
|
+
if new_location.kind_of?(Array)
|
44
|
+
self.setLocation(java.awt.Point.new(new_location[0], new_location[1]))
|
45
|
+
elsif new_location.kind_of? java.awt.Point
|
46
|
+
self.setLocation(new_location)
|
47
|
+
else
|
48
|
+
# possibly one of the following standard options was chosen:
|
49
|
+
screen_dimension = java.awt.Toolkit.default_toolkit.screen_size
|
50
|
+
case new_location
|
51
|
+
when :center
|
52
|
+
x = ((screen_dimension.width - self.width) / 2).to_i
|
53
|
+
y = ((screen_dimension.height - self.height) / 2).to_i
|
54
|
+
when :upper_left
|
55
|
+
x = 0
|
56
|
+
y = 0
|
57
|
+
when :upper_right
|
58
|
+
x = screen_dimension.width - self.width
|
59
|
+
y = 0
|
60
|
+
when :lower_left
|
61
|
+
x = 0
|
62
|
+
y = screen_dimension.height - self.height
|
63
|
+
when :lower_right
|
64
|
+
x = screen_dimension.width - self.width
|
65
|
+
y = screen_dimension.height - self.height
|
66
|
+
when :top_center
|
67
|
+
x = ((screen_dimension.width - self.width) / 2).to_i
|
68
|
+
y = 0
|
69
|
+
when :bottom_center
|
70
|
+
x = ((screen_dimension.width - self.width) / 2).to_i
|
71
|
+
y = screen_dimension.height - self.height
|
72
|
+
end
|
73
|
+
|
74
|
+
# set the new location for window
|
75
|
+
self.location = [x, y]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
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.1.
|
4
|
+
version: 0.1.4
|
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-10-
|
12
|
+
date: 2008-10-30 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -34,6 +34,7 @@ files:
|
|
34
34
|
- lib/rswing/components/options.rb
|
35
35
|
- lib/rswing/components/panel.rb
|
36
36
|
- lib/rswing/components/text_field.rb
|
37
|
+
- lib/rswing/components/window.rb
|
37
38
|
- lib/rswing/components/events/focus_events.rb
|
38
39
|
- lib/rswing/components/events/key_events.rb
|
39
40
|
- lib/rswing/components/events/mouse_events.rb
|