Class: Glimmer::Swing::ShapeProxy
- Inherits:
-
Object
- Object
- Glimmer::Swing::ShapeProxy
show all
- Includes:
- Packages
- Defined in:
- lib/glimmer/swing/shape_proxy.rb
Overview
Proxy for Java2D shape objects
Follows the Proxy Design Pattern
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#content(&block) ⇒ Object
-
#draw_paint ⇒ Object
(also: #draw_color)
-
#draw_paint=(*args) ⇒ Object
(also: #draw_color=)
-
#fill_paint ⇒ Object
(also: #fill_color)
-
#fill_paint=(*args) ⇒ Object
(also: #fill_color=)
-
#initialize(parent, keyword, *args, &block) ⇒ ShapeProxy
constructor
A new instance of ShapeProxy.
-
#method_missing(method_name, *args, &block) ⇒ Object
-
#post_add_content ⇒ Object
Subclasses may override to perform post add_content work (normally must call super).
-
#post_initialize_child(child) ⇒ Object
Subclasses may override to perform post initialization work on an added child (normally must also call super).
-
#respond_to?(method_name, *args, &block) ⇒ Boolean
-
#respond_to_original?(method_name, *args, &block) ⇒ Boolean
-
#send_to_original(method_name, *args, &block) ⇒ Object
-
#stroke ⇒ Object
-
#stroke=(*args) ⇒ Object
Methods included from Packages
included
Constructor Details
#initialize(parent, keyword, *args, &block) ⇒ ShapeProxy
Returns a new instance of ShapeProxy.
103
104
105
106
107
108
109
110
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 103
def initialize(parent, keyword, *args, &block)
@parent_proxy = parent
@keyword = keyword
@args = args
@block = block
build
post_add_content if @block.nil?
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
131
132
133
134
135
136
137
138
139
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 131
def method_missing(method_name, *args, &block)
if @original.respond_to?("set_#{method_name}", true) && !args.empty?
send_to_original("set_#{method_name}", *args, &block)
elsif @original.respond_to?(method_name, true)
send_to_original(method_name, *args, &block)
else
super
end
end
|
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
101
102
103
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 101
def args
@args
end
|
#block ⇒ Object
Returns the value of attribute block.
101
102
103
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 101
def block
@block
end
|
#keyword ⇒ Object
Returns the value of attribute keyword.
101
102
103
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 101
def keyword
@keyword
end
|
#original ⇒ Object
Returns the value of attribute original.
101
102
103
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 101
def original
@original
end
|
#parent_proxy ⇒ Object
Returns the value of attribute parent_proxy.
101
102
103
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 101
def parent_proxy
@parent_proxy
end
|
Class Method Details
.create(parent, keyword, *args, &block) ⇒ Object
37
38
39
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 37
def create(parent, keyword, *args, &block)
shape_proxy_class(keyword).new(parent, keyword, *args, &block)
end
|
.exist?(keyword) ⇒ Boolean
33
34
35
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 33
def exist?(keyword)
!!shape_class(keyword)
end
|
.flyweight_shape_class ⇒ Object
Flyweight Design Pattern memoization cache. Can be cleared if memory is needed.
96
97
98
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 96
def flyweight_shape_class
@flyweight_shape_class ||= {}
end
|
.keyword(shape_proxy_class) ⇒ Object
59
60
61
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 59
def keyword(shape_proxy_class)
shape_proxy_class.to_s.underscore.sub(/_proxy$/, '')
end
|
.shape_class(keyword) ⇒ Object
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 71
def shape_class(keyword)
unless flyweight_shape_class.keys.include?(keyword)
begin
shape_class_name = shape_class_symbol(keyword).to_s
shape_class = eval("#{shape_class_name}2D::Double") rescue eval(shape_class_name)
unless shape_class.ancestors.include?(Java::JavaAwt::Shape)
shape_class = shape_class_manual_entries[keyword]
if shape_class.nil?
Glimmer::Config.logger.debug {"Class #{shape_class} matching #{keyword} is not a subclass of java.awt.Component"}
return nil
end
end
flyweight_shape_class[keyword] = shape_class
rescue SyntaxError, NameError => e
Glimmer::Config.logger.debug {e.full_message}
nil
rescue => e
Glimmer::Config.logger.debug {e.full_message}
nil
end
end
flyweight_shape_class[keyword]
end
|
.shape_class_manual_entries ⇒ Object
63
64
65
66
67
68
69
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 63
def shape_class_manual_entries
{
}
end
|
.shape_class_symbol(keyword) ⇒ Object
55
56
57
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 55
def shape_class_symbol(keyword)
keyword.camelcase(:upper).to_sym
end
|
.shape_proxy_class(keyword) ⇒ Object
41
42
43
44
45
46
47
48
49
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 41
def shape_proxy_class(keyword)
begin
class_name = shape_proxy_class_symbol(keyword)
Glimmer::Swing::ShapeProxy.const_get(class_name)
rescue => e
Glimmer::Config.logger.debug e.full_message
Glimmer::Swing::ShapeProxy
end
end
|
.shape_proxy_class_symbol(keyword) ⇒ Object
51
52
53
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 51
def shape_proxy_class_symbol(keyword)
"#{keyword.camelcase(:upper)}Proxy".to_sym
end
|
Instance Method Details
#content(&block) ⇒ Object
#draw_paint ⇒ Object
Also known as:
draw_color
162
163
164
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 162
def draw_paint
@draw_paint
end
|
#draw_paint=(*args) ⇒ Object
Also known as:
draw_color=
157
158
159
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 157
def draw_paint=(*args)
@draw_paint = Color.new(*args)
end
|
#fill_paint ⇒ Object
Also known as:
fill_color
172
173
174
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 172
def fill_paint
@fill_paint
end
|
#fill_paint=(*args) ⇒ Object
Also known as:
fill_color=
167
168
169
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 167
def fill_paint=(*args)
@fill_paint = Color.new(*args)
end
|
#post_add_content ⇒ Object
Subclasses may override to perform post add_content work (normally must call super)
113
114
115
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 113
def post_add_content
@parent_proxy&.post_initialize_child(self)
end
|
#post_initialize_child(child) ⇒ Object
Subclasses may override to perform post initialization work on an added child (normally must also call super)
118
119
120
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 118
def post_initialize_child(child)
@original.append(child.original, false) if @original&.is_a?(Path2D) && child.is_a?(ShapeProxy)
end
|
#respond_to?(method_name, *args, &block) ⇒ Boolean
122
123
124
125
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 122
def respond_to?(method_name, *args, &block)
respond_to_original?(method_name, *args, &block) ||
super(method_name, true)
end
|
#respond_to_original?(method_name, *args, &block) ⇒ Boolean
127
128
129
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 127
def respond_to_original?(method_name, *args, &block)
@original.respond_to?(method_name, true) || @original.respond_to?("set_#{method_name}", true)
end
|
#send_to_original(method_name, *args, &block) ⇒ Object
141
142
143
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 141
def send_to_original(method_name, *args, &block)
@original.send(method_name, *normalize_args(args), &block)
end
|
#stroke ⇒ Object
153
154
155
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 153
def stroke
@stroke
end
|
#stroke=(*args) ⇒ Object
149
150
151
|
# File 'lib/glimmer/swing/shape_proxy.rb', line 149
def stroke=(*args)
@stroke = BasicStroke.new(*args)
end
|