limelight 0.2.0-java → 0.2.1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. data/bin/limelight +2 -3
  2. data/lib/limelight.jar +0 -0
  3. data/lib/limelight/animation.rb +32 -12
  4. data/lib/limelight/build_exception.rb +3 -0
  5. data/lib/limelight/builtin/players/button.rb +17 -2
  6. data/lib/limelight/builtin/players/check_box.rb +21 -2
  7. data/lib/limelight/builtin/players/combo_box.rb +31 -3
  8. data/lib/limelight/builtin/players/combo_box_popup_list.rb +1 -1
  9. data/lib/limelight/builtin/players/combo_box_popup_list_item.rb +1 -1
  10. data/lib/limelight/builtin/players/curtains.rb +1 -1
  11. data/lib/limelight/builtin/players/radio_button.rb +27 -3
  12. data/lib/limelight/builtin/players/text_area.rb +11 -2
  13. data/lib/limelight/builtin/players/text_box.rb +11 -2
  14. data/lib/limelight/button_group_cache.rb +2 -2
  15. data/lib/limelight/casting_director.rb +6 -1
  16. data/lib/limelight/commands.rb +10 -24
  17. data/lib/limelight/file_chooser.rb +16 -3
  18. data/lib/limelight/file_filter.rb +10 -3
  19. data/lib/limelight/java_couplings.rb +11 -10
  20. data/lib/limelight/java_util.rb +36 -3
  21. data/lib/limelight/limelight_exception.rb +3 -1
  22. data/lib/limelight/loaders/file_scene_loader.rb +1 -1
  23. data/lib/limelight/main.rb +108 -0
  24. data/lib/limelight/menu_bar.rb +31 -12
  25. data/lib/limelight/paint_action.rb +4 -2
  26. data/lib/limelight/pen.rb +39 -9
  27. data/lib/limelight/producer.rb +35 -7
  28. data/lib/limelight/production.rb +18 -9
  29. data/lib/limelight/production_builder.rb +22 -5
  30. data/lib/limelight/prop.rb +127 -45
  31. data/lib/limelight/prop_builder.rb +70 -11
  32. data/lib/limelight/scene.rb +25 -21
  33. data/lib/limelight/stage.rb +68 -18
  34. data/lib/limelight/stage_builder.rb +68 -27
  35. data/lib/limelight/styles.rb +327 -30
  36. data/lib/limelight/styles_builder.rb +91 -21
  37. data/lib/limelight/theater.rb +23 -11
  38. data/lib/limelight/util.rb +28 -6
  39. data/lib/limelight/version.rb +1 -1
  40. data/productions/startup/players/browse_button.rb +1 -1
  41. data/spec/builtin/players/check_box_spec.rb +1 -1
  42. data/spec/builtin/players/radio_button_spec.rb +2 -2
  43. data/spec/builtin/players/text_area_spec.rb +1 -1
  44. data/spec/builtin/players/text_box_spec.rb +1 -1
  45. data/spec/commands_spec.rb +4 -3
  46. data/spec/prop_builder_spec.rb +40 -29
  47. data/spec/prop_spec.rb +5 -1
  48. data/spec/stage_spec.rb +15 -15
  49. data/spec/styles_spec.rb +36 -0
  50. data/spec/theater_spec.rb +8 -8
  51. metadata +6 -3
@@ -14,8 +14,15 @@ require 'limelight/production'
14
14
 
15
15
  module Limelight
16
16
 
17
+ # A Producer has the hefty responsibility of producing Productions. Given a directory, it will load the neccessary
18
+ # files and create all the neccessary objects to bring a Production to life.
19
+ #
20
+ # For directory structures, see Limelight::Main
21
+ #
17
22
  class Producer
18
23
 
24
+ # Creates a new Producer and has it open a Production by specified name.
25
+ #
19
26
  def self.open(production_name)
20
27
  producer = new(production_name)
21
28
  producer.open
@@ -23,7 +30,10 @@ module Limelight
23
30
 
24
31
  attr_reader :loader, :theater, :production
25
32
  attr_writer :builtin_styles
26
-
33
+
34
+ # A Production name, or root directory, must be provided. If not Theater is provided, one will be created.
35
+ # You may also provide an existing Production for which this Producer will interact.
36
+ #
27
37
  def initialize(root_path, theater=nil, production=nil)
28
38
  if(root_path[-4..-1] == ".llp")
29
39
  root_path = unpack_production(root_path)
@@ -32,12 +42,17 @@ module Limelight
32
42
  @theater = theater.nil? ? Theater.new : theater
33
43
  @production = production
34
44
  end
35
-
45
+
46
+ # Returns the CastingDirector for this Production.
47
+ #
36
48
  def casting_director
37
49
  @casting_director = CastingDirector.new(loader) if not @casting_director
38
50
  return @casting_director
39
51
  end
40
-
52
+
53
+ # Opens the Production specified during construction. If the file 'init.rb' exists in the root directory of the
54
+ # Production, it will be loaded before anything else.
55
+ #
41
56
  def open()
42
57
  establish_production
43
58
  Kernel.load(@loader.path_to("init.rb")) if @loader.exists?("init.rb")
@@ -49,6 +64,8 @@ module Limelight
49
64
  @casting_director = nil
50
65
  end
51
66
 
67
+ # Opens the specified Scene onto the Spcified Stage.
68
+ #
52
69
  def open_scene(path, stage)
53
70
  styles = load_styles(path)
54
71
  merge_with_root_styles(styles)
@@ -57,7 +74,9 @@ module Limelight
57
74
 
58
75
  stage.open(scene)
59
76
  end
60
-
77
+
78
+ # Loads the 'stages.rb' file and configures all the Stages in the Production.
79
+ #
61
80
  def load_stages
62
81
  content = @loader.load("stages.rb")
63
82
  stages = Limelight.build_stages(@theater) do
@@ -69,7 +88,9 @@ module Limelight
69
88
  end
70
89
  return stages
71
90
  end
72
-
91
+
92
+ # Loads of the 'props.rb' file for a particular Scene and creates all the Prop objects and Scene.
93
+ #
73
94
  def load_props(path, options = {})
74
95
  return Scene.new(options) if path.nil?
75
96
  filename = File.join(path, "props.rb")
@@ -83,7 +104,9 @@ module Limelight
83
104
  end
84
105
  end
85
106
  end
86
-
107
+
108
+ # Loads the specified 'styles.rb' file and created a Hash of Styles.
109
+ #
87
110
  def load_styles(path)
88
111
  styles = builtin_styles
89
112
  return styles if path.nil?
@@ -98,7 +121,9 @@ module Limelight
98
121
  end
99
122
  end
100
123
  end
101
-
124
+
125
+ # Loads the 'production.rb' file if it exists and configures the Production.
126
+ #
102
127
  def establish_production
103
128
  return if @production
104
129
  if @loader.exists?("production.rb")
@@ -115,6 +140,9 @@ module Limelight
115
140
  end
116
141
  end
117
142
 
143
+ # A production with multiple Scenes may have a 'styles.rb' file in the root directory. This is called the
144
+ # root_style. This method loads the root_styles, if they haven't already been loaded, and returns them.
145
+ #
118
146
  def root_styles
119
147
  return @root_syles if @root_syles
120
148
  if @loader.exists?('styles.rb')
@@ -4,12 +4,17 @@
4
4
  require 'limelight/limelight_exception'
5
5
 
6
6
  module Limelight
7
-
7
+
8
+ # The root object of Limelight Production. Every Prop in a production has access to its Production object.
9
+ # Therefore it is typical to store reasources in the Production.
10
+ #
11
+ # Productions are configured, and attributes are added, by the ProductionBuilder.
12
+ #
8
13
  class Production
9
14
 
10
15
  class << self
11
16
 
12
- def index(production)
17
+ def index(production) #:nodoc:
13
18
  @index = [] if @index.nil?
14
19
  if production.name.nil?
15
20
  assign_name_to(production)
@@ -19,12 +24,12 @@ module Limelight
19
24
  @index << production
20
25
  end
21
26
 
22
- def [](name)
27
+ def [](name) #:nodoc:
23
28
  return nil if @index.nil?
24
29
  return @index.find { |production| production.name == name }
25
30
  end
26
31
 
27
- def assign_name_to(production)
32
+ def assign_name_to(production) #:nodoc:
28
33
  count = @index.length + 1
29
34
  while name_taken?(count.to_s)
30
35
  count += 1
@@ -32,28 +37,32 @@ module Limelight
32
37
  production.name = count.to_s
33
38
  end
34
39
 
35
- def name_taken?(name)
40
+ def name_taken?(name) #:nodoc:
36
41
  return self[name] != nil
37
42
  end
38
43
 
39
- def clear_index
44
+ def clear_index #:nodoc:
40
45
  @index = []
41
46
  end
42
47
 
43
- def error_if_duplicate_name(name)
48
+ def error_if_duplicate_name(name) #:nodoc:
44
49
  raise Limelight::LimelightException.new("Production name '#{name}' is already taken") if name_taken?(name)
45
50
  end
46
51
 
47
52
  end
48
53
 
49
54
  attr_reader :producer, :theater, :name
50
-
55
+
56
+ # Users typically need not create Production objects.
57
+ #
51
58
  def initialize(producer, theater)
52
59
  @producer = producer
53
60
  @theater = theater
54
61
  self.class.index(self)
55
62
  end
56
-
63
+
64
+ # Sets the name of the Production. The name must be unique amongst all Productions in memory.
65
+ #
57
66
  def name=(value)
58
67
  self.class.error_if_duplicate_name(value)
59
68
  @name = value
@@ -5,13 +5,26 @@ require 'limelight/production'
5
5
  require 'limelight/limelight_exception'
6
6
 
7
7
  module Limelight
8
-
8
+
9
+ # A trigger to configure Production objects using the ProductionBuilder DSL.
10
+ #
11
+ # See Limelight::ProductionBuilder
12
+ #
9
13
  def self.build_production(producer, theater, &block)
10
14
  builder = ProductionBuilder.new(producer, theater)
11
15
  builder.instance_eval(&block) if block
12
16
  return builder.__production__
13
17
  end
14
-
18
+
19
+ # The basis of the DSL for building Style objects.
20
+ #
21
+ # name "Stage Composer"
22
+ # attribute :controller
23
+ # attribute :inspector
24
+ #
25
+ # The above example names the Production 'Stage Composer' and creates two attributes on the Production: 'controller'
26
+ # and 'inspector'
27
+ #
15
28
  class ProductionBuilder
16
29
 
17
30
  class << self
@@ -26,12 +39,14 @@ module Limelight
26
39
  @__production__ = Production.new(producer, theater)
27
40
  end
28
41
 
29
- def method_missing(sym, value)
42
+ def method_missing(sym, value) #:nodoc:
30
43
  setter_sym = "#{sym}=".to_s
31
44
  raise ProductionBuilderException.new(sym) if !@__production__.respond_to?(setter_sym)
32
45
  @__production__.send(setter_sym, value)
33
46
  end
34
-
47
+
48
+ # Creates an attribute on the Production
49
+ #
35
50
  def attribute(sym)
36
51
  ProductionBuilder.current_attribute = sym
37
52
  class << @__production__
@@ -39,7 +54,9 @@ module Limelight
39
54
  end
40
55
  end
41
56
  end
42
-
57
+
58
+ # Thrown if there is an error in the ProductionBuilder DSL
59
+ #
43
60
  class ProductionBuilderException < LimelightException
44
61
  def initialize(name)
45
62
  super("'#{name}' is not a valid production property")
@@ -7,16 +7,22 @@ require 'limelight/paint_action'
7
7
  require 'limelight/animation'
8
8
 
9
9
  module Limelight
10
+
11
+ # Prop is the fundamental building block of a scene. A prop represents a rectangular area in the scene, of almost any dimension.
12
+ # It may have borders, backgrounds, margin, padding, and it may contain other props or text. However it is the props'
13
+ # Styles that determine their size and appearance.
14
+ #
15
+ # A Prop may have one parent and many children. Hense, when put together, they form a tree structure. The Scene is
16
+ # the root Prop of a tree.
17
+ #
10
18
  class Prop
11
19
 
12
20
  class << self
13
21
 
14
- def event(*syms)
22
+ def event(event_symbol)
15
23
  @events ||= []
16
- syms.each do |sym|
17
- @events << sym unless @events.include?(sym)
18
- define_method(sym) { |event| } # do nothing by default
19
- end
24
+ @events << event_symbol unless @events.include?(event_symbol)
25
+ define_method(event_symbol) { |event| } # do nothing by default
20
26
  end
21
27
 
22
28
  def events
@@ -27,72 +33,100 @@ module Limelight
27
33
 
28
34
  include UI::Api::Prop
29
35
 
30
- attr_reader :panel, :style, :hover_style, :children, :scene, :parent
31
- attr_reader :name, :id, :players
32
- getters :panel, :style, :hover_style, :scene, :name, :text
33
- setters :text
34
-
36
+ attr_reader :panel #:nodoc:
37
+ attr_reader :style, :hover_style, :children, :scene, :parent, :name, :id, :players
38
+ getters :panel, :style, :hover_style, :scene, :name, :text #:nodoc:
39
+ setters :text #:nodoc:
40
+
41
+ # When creating a Prop, an optional Hash is accepted. These are called initialization options.
42
+ # The key/value pairs in the initialiaztion options will be used to
43
+ # set properties on the Prop, it Style, or included Player properties. These properties are not set
44
+ # until the prop is added to a Prop tree with a Scene.
45
+ #
35
46
  def initialize(hash = {})
36
47
  @options = hash
37
48
  @children = []
38
49
  @style = Styles::ScreenableStyle.new
39
50
  @panel = UI::Model::Panel.new(self)
40
51
  end
41
-
52
+
53
+ # Add a Prop as a child of this Prop.
54
+ #
42
55
  def add(child)
43
56
  child.set_parent(self)
44
57
  @children << child
45
58
  @panel.add(child.panel)
46
59
  end
47
-
60
+
61
+ # Same as add. Returns self so adding may be chained.
62
+ #
63
+ # prop << child1 << child2 << child3
64
+ #
48
65
  def <<(child)
49
66
  add(child)
50
67
  return self
51
68
  end
52
-
69
+
70
+ # Allows the adding of child Props using the PropBuilder DSL.
71
+ #
72
+ # prop.build do
73
+ # child1 do
74
+ # grand_child
75
+ # end
76
+ # child2
77
+ # end
78
+ #
53
79
  def build(&block)
54
80
  require 'limelight/prop_builder'
55
81
  builder = Limelight::PropBuilder.new(self)
56
82
  builder.instance_eval(&block)
57
83
  end
58
-
84
+
85
+ # Removes a child Prop. The child Prop will be parentless after removal.
86
+ #
59
87
  def remove(child)
60
88
  if children.delete(child)
61
89
  @panel.remove(child.panel)
62
90
  end
63
91
  end
64
-
92
+
93
+ # Removes all child Props.
94
+ #
65
95
  def remove_all
66
96
  @panel.remove_all
67
97
  @children = []
68
98
  end
69
-
70
- def add_controller(controller_module)
71
- extend controller_module unless self.is_a?(controller_module)
99
+
100
+ # Injects the behavior of the specified Player into the Prop. The Player must be a Module.
101
+ #
102
+ def include_player(player_module)
103
+ extend player_module unless self.is_a?(player_module)
72
104
  end
73
105
 
74
- alias :include_player :add_controller
75
-
76
- def update
106
+ def update #:nodoc:
77
107
  return if(@scene.nil? || !@scene.visible)
78
108
  @panel.doLayout
79
109
  @panel.repaint
80
110
  end
81
111
 
82
- def update_now
112
+ def update_now #:nodoc:
83
113
  return if(@scene.nil? || !@scene.visible)
84
114
  @panel.doLayout()
85
115
  @panel.paintImmediately(0, 0, @panel.width, @panel.height)
86
116
  end
87
-
117
+
118
+ # A hook to invoke behavior after a Prop is painted.
119
+ #
88
120
  def after_painting(flag = true, &block)
89
121
  if flag
90
122
  @panel.after_paint_action = PaintAction.new(&block)
91
123
  else
92
124
  @panel.after_paint_action = nil
93
125
  end
94
- end
95
-
126
+ end
127
+
128
+ # Searches all children for a Prop with the given id. Returns the desired Prop if found, nil otherwise.
129
+ #
96
130
  def find(id)
97
131
  return self if @id == id
98
132
  @children.each do |child|
@@ -101,73 +135,111 @@ module Limelight
101
135
  end
102
136
  return nil
103
137
  end
104
-
138
+
139
+ # Searches all children for Props with the specified name. Returns an Array of matching Props. Returns an
140
+ # empty Array is none are found.
141
+ #
105
142
  def find_by_name(name, results = [])
106
143
  results << self if @name == name
107
144
  @children.each { |child| child.find_by_name(name, results) }
108
145
  return results
109
146
  end
110
-
147
+
148
+ # Sets the text of this Prop. If a prop is given text, it will become sterilized (it may not have any more children).
149
+ # Some Players such as text_box, will cause the text to appear in the text_box.
150
+ #
111
151
  def text=(value)
112
- @panel.text = value
152
+ @panel.text = value.to_s
113
153
  end
114
-
154
+
155
+ # Returns the text of the Prop.
156
+ #
115
157
  def text
116
158
  return panel.text
117
159
  end
118
160
 
119
161
  #TODO - MDM - DELETE ME
120
- def stage
162
+ def stage #:nodoc:
121
163
  return scene.stage
122
164
  end
123
-
165
+
166
+ # Returns the current Production this Prop lives in.
167
+ #
124
168
  def production
125
169
  return scene.production
126
170
  end
127
171
 
128
- def to_s
172
+ def to_s #:nodoc:
129
173
  return "#{self.class.name}[id: #{@id}, name: #{@name}]"
130
174
  end
131
175
 
132
- def inspect
176
+ def inspect #:nodoc:
133
177
  return self.to_s
134
178
  end
135
179
 
136
180
  # unusual name because it's not part of public api
137
- def set_parent(parent)
181
+ def set_parent(parent) #:nodoc:
138
182
  @parent = parent
139
183
  set_scene parent.scene
140
184
  end
141
185
 
142
186
  # unusual name because it's not part of public api
143
- def set_scene(scene)
187
+ def set_scene(scene) #:nodoc:
144
188
  return if scene == @scene || scene.nil?
145
189
  @scene = scene
146
190
  illuminate
147
191
  children.each { |child| child.set_scene(scene) }
148
192
  end
149
-
193
+
194
+ # Allows the addition of extra initialization options. Will raise an exception if the Prop has already been
195
+ # illuminated (added to a scene).
196
+ #
150
197
  def add_options(more_options)
151
198
  raise "Too late to add options" if @options.nil?
152
199
  @options.merge!(more_options)
153
200
  end
154
-
201
+
202
+ # Returns a Box representing the relative bounds of the Prop. Is useful with usign the Pen.
203
+ #
204
+ # box = prop.area
205
+ # box.x, box.y # represents the Prop's location within its parent Prop
206
+ # box.width, box.height # represents the Prop's dimensions
207
+ #
155
208
  def area
156
209
  return panel.get_box.clone
157
210
  end
158
-
211
+
212
+ # Returns a Box representing the bounds inside the borders of the prop. If the Prop's style has no margin or
213
+ # border_width, then this will be equivalant to area.
214
+ #
159
215
  def bordered_area
160
216
  return panel.get_box_inside_borders.clone
161
217
  end
162
-
218
+
219
+ # Returns a Pen object. Pen objects allow to you to draw directly on the screen, withing to bounds of this Prop.
220
+ #
163
221
  def pen
164
222
  return Pen.new(panel.getGraphics)
165
223
  end
166
-
224
+
225
+ # Plays a sound on the computers audio output. The parameter is the filename of a .au sound file.
226
+ # This filename should relative to the root directory of the current Production, or an absolute path.
227
+ #
167
228
  def play_sound(filename)
168
229
  @panel.play_sound(@scene.loader.path_to(filename))
169
230
  end
170
231
 
232
+ # Initiate an animation loop. Options may include :name (string), :updates_per_second (int: defaults to 60)
233
+ # An Animation object is returned.
234
+ # The provided block will be invoked :updates_per_second times per second until the Animation is stopped.
235
+ #
236
+ # @animation = prop.animate(:updates_per_second => 20) do
237
+ # prop.style.border_width = (prop.style.top_border_width.to_i + 1).to_s
238
+ # @animation.stop if prop.style.top_border_width.to_i > 60
239
+ # end
240
+ #
241
+ # This above example will cause the Prop's border to grow until it is 60 pixels wide.
242
+ #
171
243
  def animate(options={}, &block)
172
244
  animation = Animation.new(self, block, options)
173
245
  animation.start
@@ -175,11 +247,21 @@ module Limelight
175
247
  end
176
248
 
177
249
  # GUI Events ##########################################
178
-
179
- EVENTS = [:mouse_clicked, :mouse_entered, :mouse_exited, :mouse_pressed, :mouse_released, :mouse_dragged, :mouse_moved,
180
- :key_typed, :key_pressed, :key_released, :focus_gained, :focus_lost, :button_pressed, :value_changed]
181
-
182
- event *EVENTS
250
+
251
+ event :mouse_clicked
252
+ event :mouse_entered
253
+ event :mouse_exited
254
+ event :mouse_pressed
255
+ event :mouse_released
256
+ event :mouse_dragged
257
+ event :mouse_moved
258
+ event :key_typed
259
+ event :key_pressed
260
+ event :key_released
261
+ event :focus_gained
262
+ event :focus_lost
263
+ event :button_pressed
264
+ event :value_changed
183
265
 
184
266
  private ###############################################
185
267