bakkdoor-rswing 0.1.2 → 0.1.3
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/README +5 -4
- data/lib/rswing/components/container.rb +34 -0
- data/lib/rswing/components/dialog.rb +17 -31
- data/lib/rswing/components/frame.rb +6 -17
- data/lib/rswing/components/options.rb +6 -1
- data/lib/rswing/components/panel.rb +2 -10
- data/lib/rswing.rb +3 -1
- metadata +2 -2
data/README
CHANGED
@@ -19,13 +19,13 @@ Some examples:
|
|
19
19
|
|
20
20
|
Frame.new("hello, world") do |frame|
|
21
21
|
frame.default_close_operation = :exit_on_close
|
22
|
-
frame.size =
|
22
|
+
frame.size = [200,200]
|
23
23
|
|
24
24
|
# create a new button, belonging to this frame with a given name to access it easily later
|
25
25
|
Button.new("OK", :belongs_to => frame, :name => :okButton) do |btn|
|
26
26
|
|
27
27
|
btn.on_click do
|
28
|
-
Dialog.show
|
28
|
+
Dialog.show "Button clicked!", :dialog_type => :info, :title => "My Title", :belongs_to => frame
|
29
29
|
end
|
30
30
|
|
31
31
|
btn.on_focus do
|
@@ -42,9 +42,10 @@ Some examples:
|
|
42
42
|
|
43
43
|
# options-dialog
|
44
44
|
options = ["Yes", "No", "Cancel"]
|
45
|
-
selected_value = Dialog.showOption(
|
45
|
+
selected_value = Dialog.showOption(options.join(" or ") + "?",
|
46
46
|
:option_values => options,
|
47
|
-
:option_type => :yes_no_cancel
|
47
|
+
:option_type => :yes_no_cancel,
|
48
|
+
:belongs_to => frame)
|
48
49
|
|
49
50
|
puts "#{selected_value} was selected"
|
50
51
|
|
@@ -1,6 +1,28 @@
|
|
1
1
|
module RSwing
|
2
2
|
module Components
|
3
3
|
module Container
|
4
|
+
|
5
|
+
# Adds a component with a set of options to this container.
|
6
|
+
def add(component, options = {})
|
7
|
+
if(self.respond_to?(:getContentPane))
|
8
|
+
self.add_to_content_pane(component, options)
|
9
|
+
else
|
10
|
+
# this should be handled somehow later on:
|
11
|
+
if(layout = Options.value_for(options => :layout))
|
12
|
+
super(component, layout)
|
13
|
+
else
|
14
|
+
super(component)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# if :name given, add with name
|
19
|
+
if(name = Options.value_for(options => :name))
|
20
|
+
self.add_with_name(component, name)
|
21
|
+
end
|
22
|
+
|
23
|
+
component # return component
|
24
|
+
end
|
25
|
+
|
4
26
|
# Adds a component to the component_hash with a given name symbol.
|
5
27
|
# Raises an exception if name already taken.
|
6
28
|
def add_with_name(component, name_symbol)
|
@@ -47,6 +69,18 @@ module RSwing
|
|
47
69
|
def component_hash
|
48
70
|
@component_hash ||= {}
|
49
71
|
end
|
72
|
+
|
73
|
+
# Adds a component with given options to the <tt>content_pane</tt> of a container.
|
74
|
+
# This will only work, if the container actually has a <tt>content_pane</tt>
|
75
|
+
# and should only be called by the <tt>add()</tt> method inside of the
|
76
|
+
# <tt>container</tt> module.
|
77
|
+
def add_to_content_pane(component, options)
|
78
|
+
if(layout = Options.value_for(options => :layout))
|
79
|
+
self.content_pane.add(component, layout)
|
80
|
+
else
|
81
|
+
self.content_pane.add(component)
|
82
|
+
end
|
83
|
+
end
|
50
84
|
end
|
51
85
|
end
|
52
86
|
end
|
@@ -8,10 +8,13 @@ module RSwing
|
|
8
8
|
# (<tt>show()</tt> and <tt>showOptions</tt>).
|
9
9
|
# Can also be used to create custom dialogs by extending from this class.
|
10
10
|
class Dialog < JDialog
|
11
|
+
include Window
|
11
12
|
include Container
|
12
13
|
|
13
|
-
def initialize(
|
14
|
-
super(
|
14
|
+
def initialize(title, options = {}, &block)
|
15
|
+
super(Options.value_for(options => :belongs_to), title, Options.value_for(options => :modal))
|
16
|
+
|
17
|
+
Window.init(self, options)
|
15
18
|
|
16
19
|
if(name = Options.value_for(options => :name) && owner.class.include?(Container))
|
17
20
|
owner.add_with_name(self, name)
|
@@ -21,34 +24,16 @@ module RSwing
|
|
21
24
|
if block_given?
|
22
25
|
yield self
|
23
26
|
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
# Adds a component with a set of options to this dialog.
|
28
|
-
def add(component, options = {})
|
29
|
-
if(layout = Options.value_for(options => :layout))
|
30
|
-
self.content_pane.add(component, layout)
|
31
|
-
else
|
32
|
-
self.content_pane.add(component)
|
33
|
-
end
|
34
|
-
|
35
|
-
|
36
|
-
# wenn :name angegeben wurde, mit aufnehmen
|
37
|
-
if(name = Options.value_for(options => :name))
|
38
|
-
self.add_with_name(component, name)
|
39
|
-
end
|
40
|
-
|
41
|
-
component #zurückgeben
|
42
27
|
end
|
43
28
|
|
44
29
|
# Creates a MessageDialog.
|
45
|
-
# - <tt>parent</tt>: Parent-Container for this dialog.
|
46
30
|
# - <tt>message</tt>: Message, to be displayed in this dialog.
|
47
31
|
# - <tt>options</tt>: Options-Hash with the following valid values:
|
48
32
|
# 1. <tt>:dialog_type => (:error | :question | :plain | :warning | :info)</tt> (default: :info)
|
49
33
|
# 2. <tt>:title => "my title"</tt> (defailt: <tt>""</tt>)
|
50
34
|
# 3. <tt>:modal => false</tt> (default: true)
|
51
|
-
|
35
|
+
# 4. <tt>:belongs_to => parent</tt> Parent-Container for this dialog (default: nil)
|
36
|
+
def self.show(message, options = {})
|
52
37
|
message_type =
|
53
38
|
case Options.value_for(options => :dialog_type)
|
54
39
|
when :error
|
@@ -63,27 +48,28 @@ module RSwing
|
|
63
48
|
JOptionPane::INFORMATION_MESSAGE
|
64
49
|
end
|
65
50
|
|
66
|
-
JOptionPane.showMessageDialog(
|
51
|
+
JOptionPane.showMessageDialog(Options.value_for(options => :belongs_to), message,
|
52
|
+
Options.value_for(options => :title), message_type)
|
67
53
|
end
|
68
54
|
|
69
55
|
# Creates a OptionsDialog (Dialog with selection for different Options).
|
70
|
-
# - <tt>parent</tt>: Parent-Container for this dialog.
|
71
56
|
# - <tt>message</tt>: Message, to be displayed in the dialog.
|
72
57
|
# - <tt>options</tt>: Options-Hash with the following valid values:
|
73
58
|
# 1. <tt>:option_type => (:yes_no | :yes_no_cancel)</tt> (default: <tt>:yes_no</tt>)
|
74
|
-
# 2. <tt>:option_values => ["OK", "Cancel", "Quit"]</tt> (default: <tt>["
|
75
|
-
# 3. <tt>:title => "
|
59
|
+
# 2. <tt>:option_values => ["OK", "Cancel", "Quit"]</tt> (default: <tt>["Yes", "No"]</tt>)
|
60
|
+
# 3. <tt>:title => "my title"</tt> (default: <tt>""</tt>)
|
76
61
|
# 4. <tt>:modal => false</tt> (default: <tt>true</tt>)
|
77
|
-
# 5. <tt>:icon => nil</tt> (default:
|
78
|
-
|
79
|
-
|
62
|
+
# 5. <tt>:icon => nil</tt> (default: nil)
|
63
|
+
# 6. <tt>:belongs_to => parent</tt> Parent-Container for this dialog (default: nil)
|
64
|
+
def self.showOption(message, options = {})
|
65
|
+
title = options[:title].nil? ? Options.gui_options[:option_default_title] : options[:title]
|
80
66
|
icon = Options.value_for(options => :icon)
|
81
67
|
|
82
68
|
option_type = option_type_for(Options.value_for(options => :option_type))
|
83
69
|
option_values = Options.value_for(options => :option_values)
|
84
70
|
|
85
|
-
selected_option_index = JOptionPane.showOptionDialog(
|
86
|
-
|
71
|
+
selected_option_index = JOptionPane.showOptionDialog(Options.value_for(options => :belongs_to), message,
|
72
|
+
title, option_type, JOptionPane::QUESTION_MESSAGE, icon, option_values.to_java(:Object), nil);
|
87
73
|
|
88
74
|
option_values[selected_option_index]
|
89
75
|
end
|
@@ -3,33 +3,22 @@ module RSwing
|
|
3
3
|
JFrame = javax.swing.JFrame
|
4
4
|
|
5
5
|
class Frame < JFrame
|
6
|
+
include Window
|
6
7
|
include Container
|
7
8
|
|
8
|
-
|
9
|
+
# valid options are:
|
10
|
+
# 1. <tt>:size => [800, 600]</tt> 800x600 pixels (default: nil)
|
11
|
+
def initialize(title, options = {}, &block)
|
9
12
|
super(title)
|
10
13
|
|
14
|
+
Window.init(self, options)
|
15
|
+
|
11
16
|
# falls block übergeben wurde, mit aktuellem objekt aufrufen
|
12
17
|
if block_given?
|
13
18
|
yield self
|
14
19
|
end
|
15
20
|
end
|
16
21
|
|
17
|
-
def add(component, options = {})
|
18
|
-
if(layout = Options.value_for(options => :layout))
|
19
|
-
self.content_pane.add(component, layout)
|
20
|
-
else
|
21
|
-
self.content_pane.add(component)
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
# wenn :name angegeben wurde, mit aufnehmen
|
26
|
-
if(name = Options.value_for(options => :name))
|
27
|
-
self.add_with_name(component, name)
|
28
|
-
end
|
29
|
-
|
30
|
-
component #zurückgeben
|
31
|
-
end
|
32
|
-
|
33
22
|
# Sets the default close operation for this frame.
|
34
23
|
# Valid operations are:
|
35
24
|
# 1. <tt>:do_nothing_on_close</tt>
|
@@ -12,14 +12,18 @@ module RSwing
|
|
12
12
|
:double_buffer => true,
|
13
13
|
:dialog_type => :info,
|
14
14
|
:option_type => :yes_no,
|
15
|
-
:option_values => ["
|
15
|
+
:option_values => ["Yes", "No"],
|
16
|
+
:option_default_title => "Please select:",
|
16
17
|
:icon => nil,
|
17
18
|
:belongs_to => nil,
|
18
19
|
:layout => nil,
|
20
|
+
:layout_manager => nil,
|
19
21
|
:title => nil,
|
20
22
|
:name => nil,
|
21
23
|
:font => nil,
|
22
24
|
:doc => nil,
|
25
|
+
:size => nil,
|
26
|
+
:location => nil,
|
23
27
|
:columns => 10,
|
24
28
|
:text => ""
|
25
29
|
}
|
@@ -31,6 +35,7 @@ module RSwing
|
|
31
35
|
# * Example:
|
32
36
|
# <tt>Options.value_for(options => :name)</tt>
|
33
37
|
def self.value_for(hash)
|
38
|
+
raise "Value must be a hash!" unless hash.kind_of? Hash
|
34
39
|
hash.each_pair do |options_hash, option_key|
|
35
40
|
# es sollte nur ein paar angegeben werden, sodass wir einfach nur das erste nehmen
|
36
41
|
# und den entsprechenden wert zurückgeben
|
@@ -8,8 +8,8 @@ module RSwing
|
|
8
8
|
include Events::MouseEvents
|
9
9
|
include Events::FocusEvents
|
10
10
|
|
11
|
-
def initialize(
|
12
|
-
super(layout_manager, Options.value_for(options => :double_buffer))
|
11
|
+
def initialize(options = {}, &block)
|
12
|
+
super(Options.value_for(options => :layout_manager), Options.value_for(options => :double_buffer))
|
13
13
|
|
14
14
|
if (border_title = Options.value_for(options => :title))
|
15
15
|
border = BorderFactory.createTitledBorder(border_title)
|
@@ -24,14 +24,6 @@ module RSwing
|
|
24
24
|
|
25
25
|
Container.add_if_requested(self, options)
|
26
26
|
end
|
27
|
-
|
28
|
-
def add(component, options = {})
|
29
|
-
super.add(component)
|
30
|
-
|
31
|
-
if(name = Options.value_for(options => :name))
|
32
|
-
self.add_with_name(component, name)
|
33
|
-
end
|
34
|
-
end
|
35
27
|
end
|
36
28
|
end
|
37
29
|
end
|
data/lib/rswing.rb
CHANGED
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.3
|
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-29 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|