limelight 0.5.0-java → 0.5.1-java

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/init.rb CHANGED
@@ -1,16 +1,12 @@
1
1
  #- Copyright � 2008-2009 8th Light, Inc. All Rights Reserved.
2
2
  #- Limelight and all included source files are distributed under terms of the GNU LGPL.
3
3
 
4
- $LIMELIGHT_LIB = File.expand_path(File.dirname(__FILE__))
5
- $: << $LIMELIGHT_LIB unless $:.include?($LIMELIGHT_LIB)
6
- $LIMELIGHT_HOME = File.expand_path(File.join($LIMELIGHT_LIB, ".."))
4
+
7
5
 
8
6
  require 'java'
9
7
  if File.exists?(File.dirname(__FILE__) + "/limelight.jar")
10
8
  require File.expand_path(File.dirname(__FILE__) + "/limelight.jar")
11
9
  end
12
10
 
11
+ require File.expand_path(File.dirname(__FILE__) + "/limelight/limelight_init")
13
12
 
14
- # ENV["GEM_HOME"] = ENV["GEM_PATH"] = File.expand_path(File.dirname(__FILE__) + "/../../jruby/lib/ruby/gems/1.8")
15
- require 'rubygems'
16
- require 'limelight/java_couplings'
data/lib/limelight.jar CHANGED
Binary file
@@ -10,6 +10,10 @@ module Production
10
10
  @alert_monitor = @monitor.new_cond
11
11
  end
12
12
 
13
+ def allow_close?
14
+ return false
15
+ end
16
+
13
17
  def default_scene
14
18
  nil
15
19
  end
@@ -53,7 +53,7 @@ module Limelight
53
53
  raise "Missing template type" if @template_type.nil?
54
54
  raise "Unknown template type: #{@template_type}" if !["production", "scene"].include?(@template_type)
55
55
  self.send "parse_#{@template_type}".to_sym, args
56
- @spec_path = File.join(@production_path, "spec") unless @spec_path
56
+ @spec_path = "spec" unless @spec_path
57
57
  end
58
58
 
59
59
  def do_requires #:nodoc:
@@ -18,7 +18,7 @@ module Limelight
18
18
 
19
19
  install_as "open"
20
20
 
21
- DEFAULT_PRODUCTION = File.expand_path($LIMELIGHT_HOME + "/productions/startup")
21
+ DEFAULT_PRODUCTION = File.expand_path($LIMELIGHT_HOME + "/productions/playbills.lll")
22
22
 
23
23
  attr_reader :drb_port
24
24
 
@@ -36,7 +36,7 @@ module Limelight
36
36
  return "<production_path>"
37
37
  end
38
38
 
39
- def do_requires
39
+ def do_requires
40
40
  Main.initialize_context
41
41
  require 'limelight/producer'
42
42
  end
@@ -50,8 +50,8 @@ module Limelight
50
50
  end
51
51
 
52
52
  def process
53
- Studio.publish_on_drb(@drb_port.to_i) if @drb_port
54
- Studio.open(@production_path)
53
+ Context.instance.studio.publish_on_drb(@drb_port.to_i) if @drb_port
54
+ Context.instance.studio.open(@production_path)
55
55
  end
56
56
 
57
57
  end
@@ -6,6 +6,7 @@ module Limelight #:nodoc:
6
6
  Main = Java::limelight.Main
7
7
  ResourceLoader = Java::limelight.ResourceLoader
8
8
  Context = Java::limelight.Context
9
+ Studio = Java::limelight.ui.api.Studio
9
10
 
10
11
  module Background
11
12
  Animation = Java::limelight.background.Animation
@@ -49,7 +50,7 @@ module Limelight #:nodoc:
49
50
  Prop = Java::limelight.ui.api.Prop
50
51
  Stage = Java::limelight.ui.api.Stage
51
52
  Theater = Java::limelight.ui.api.Theater
52
- Studio = Java::limelight.ui.api.Studio
53
+ Production = Java::limelight.ui.api.Production
53
54
  end
54
55
 
55
56
  module Painting #:nodoc:
@@ -0,0 +1,12 @@
1
+ #- Copyright � 2008-2009 8th Light, Inc. All Rights Reserved.
2
+ #- Limelight and all included source files are distributed under terms of the GNU LGPL.
3
+
4
+ $LIMELIGHT_LIB = File.expand_path(File.join(File.dirname(__FILE__), '..'))
5
+ $: << $LIMELIGHT_LIB unless $:.include?($LIMELIGHT_LIB)
6
+ $LIMELIGHT_HOME = File.expand_path(File.join($LIMELIGHT_LIB, ".."))
7
+
8
+ if Java::java.lang.System.getProperty("limelight.home").nil?
9
+ Java::java.lang.System.setProperty("limelight.home", $LIMELIGHT_HOME)
10
+ end
11
+
12
+ require 'limelight/java_couplings'
@@ -23,15 +23,27 @@ module Limelight
23
23
  #
24
24
  class Producer
25
25
 
26
- # Creates a new Producer and has it open a Production by specified name.
27
- #
28
- def self.open(production_name, options={})
29
- producer = new(production_name)
30
- begin
31
- producer.open(options)
32
- rescue Exception => e
33
- puts e
34
- puts e.backtrace
26
+ class << self
27
+ # Creates a new Producer and has it open a Production by specified name.
28
+ #
29
+ def open(production_name, options={})
30
+ producer = new(production_name)
31
+ begin
32
+ producer.open(options)
33
+ rescue Exception => e
34
+ puts e
35
+ puts e.backtrace
36
+ end
37
+ end
38
+
39
+ # Returns a hash of all the built-in Limglight Styles
40
+ #
41
+ def builtin_styles
42
+ unless @builtin_styles
43
+ builtin_styles_file = File.join($LIMELIGHT_LIB, "limelight", "builtin", "styles.rb")
44
+ @builtin_styles = Limelight.build_styles_from_file(builtin_styles_file)
45
+ end
46
+ return @builtin_styles
35
47
  end
36
48
  end
37
49
 
@@ -50,7 +62,7 @@ module Limelight
50
62
  root_path = unpack_production(root_path)
51
63
  end
52
64
  @production = production || Production.new(root_path)
53
- @theater = theater.nil? ? Theater.new : theater
65
+ @theater = theater.nil? ? Theater.new(@production) : theater
54
66
  establish_production
55
67
  end
56
68
 
@@ -77,15 +89,23 @@ module Limelight
77
89
  load_stages if File.exists?(@production.stages_file)
78
90
  end
79
91
 
92
+ # Returns true if the production is compatible with the current version of Limelight or if the user proceeds
93
+ # despite the incompatible warning.
94
+ #
95
+ def can_proceed_with_compatibility?
96
+ return true if version_compatible?
97
+ return true if Context.instance.studio.utilities_production.should_proceed_with_incompatible_version(@production.name, @production.minimum_limelight_version)
98
+ return false
99
+ end
100
+
80
101
  # Opens the Production.
81
102
  #
82
103
  def open(options = {})
83
- return unless version_compatible? || Studio.utilities_production.proceed_with_incompatible_version?(@production.name, @production.minimum_limelight_version)
84
104
  @production.production_opening
85
105
  load
86
106
  @production.production_loaded
87
107
  if @theater.has_stages?
88
- @theater.stages.each do |stage|
108
+ @theater.stages.each do |stage|
89
109
  open_scene(stage.default_scene.to_s, stage) if stage.default_scene
90
110
  end
91
111
  elsif @production.default_scene
@@ -144,7 +164,7 @@ module Limelight
144
164
  # Loads the specified 'styles.rb' file and created a Hash of Styles.
145
165
  #
146
166
  def load_styles(context)
147
- extendable_styles = Studio.builtin_styles.merge(@production.root_styles)
167
+ extendable_styles = Producer.builtin_styles.merge(@production.root_styles)
148
168
  return extendable_styles.dup if not File.exists?(context.styles_file)
149
169
  new_styles = Limelight.build_styles_from_file(context.styles_file, extendable_styles)
150
170
  return extendable_styles.merge(new_styles)
@@ -3,7 +3,6 @@
3
3
 
4
4
  require 'limelight/limelight_exception'
5
5
  require 'limelight/file_loader'
6
- require 'limelight/studio'
7
6
  require 'drb'
8
7
 
9
8
  module Limelight
@@ -15,6 +14,8 @@ module Limelight
15
14
  #
16
15
  class Production
17
16
 
17
+ include UI::Api::Production
18
+
18
19
  class << self
19
20
 
20
21
  def [](name) #:nodoc:
@@ -26,6 +27,7 @@ module Limelight
26
27
  attr_reader :name, :root
27
28
  attr_accessor :producer, :theater
28
29
 
30
+
29
31
  # Users typically need not create Production objects.
30
32
  #
31
33
  def initialize(path)
@@ -36,7 +38,7 @@ module Limelight
36
38
  # Sets the name of the Production. The name must be unique amongst all Productions in memory.
37
39
  #
38
40
  def name=(value)
39
- Studio.error_if_duplicate_name(value)
41
+ Context.instance.studio.error_if_duplicate_name(value)
40
42
  @name = value
41
43
  end
42
44
 
@@ -138,9 +140,19 @@ module Limelight
138
140
  # Closes the production. If there are no more productions open, the Limelight runtime will shutdown.
139
141
  #
140
142
  def close
143
+ return if @closed
141
144
  self.production_closing
142
- Studio.production_closed(self)
145
+ @theater.close
146
+ @closed = true
143
147
  self.production_closed
148
+ Context.instance.studio.production_closed(self)
149
+ end
150
+
151
+ # Called when the last stage in this production's theater is closed. If the allow_close? returns true
152
+ # this production will be closed.
153
+ #
154
+ def theater_empty!
155
+ close if allow_close?
144
156
  end
145
157
 
146
158
  # Returned the name of the default scene. This is only used when there are not stages defined in the production.
@@ -164,6 +176,14 @@ module Limelight
164
176
  return @root_styles
165
177
  end
166
178
 
179
+ alias :getName :name #:nodoc:
180
+ alias :setName :name= #:nodoc:
181
+ alias :allowClose :allow_close? #:nodoc:
182
+
183
+ def callMethod(name, args) #:nodoc:
184
+ send(name.to_sym, *args)
185
+ end
186
+
167
187
  end
168
188
 
169
189
  end
@@ -88,7 +88,7 @@ module Limelight
88
88
  # Creates a new Producer to open the specified Production.
89
89
  #
90
90
  def open_production(production_path)
91
- Thread.new { Studio.open(production_path) }
91
+ Thread.new { Context.instance.studio.open(production_path) }
92
92
  end
93
93
 
94
94
  # Opens the specified Scene on the Stage currently occupied by this Scene.
@@ -34,7 +34,7 @@ module Spec
34
34
  uses_limelight({:scene => scene_name}.merge(options))
35
35
  end
36
36
 
37
- def self.uses_limelight(options, &prop_block)
37
+ def self.uses_limelight(options = {}, &prop_block)
38
38
  include Limelight::Specs::SpecHelper
39
39
 
40
40
  before(:each) do
@@ -186,6 +186,7 @@ module Limelight
186
186
  # See load_scene
187
187
  #
188
188
  def open(scene)
189
+ @current_scene.visible = false if @current_scene
189
190
  scene.stage = self
190
191
  scene.illuminate
191
192
  load_scene(scene)
@@ -197,16 +198,22 @@ module Limelight
197
198
  # Closes the Stage. It's window will no longer be displayed on the screen.
198
199
  #
199
200
  def close
200
- @theater.stage_closed(self)
201
201
  @frame.close
202
+ closed
203
+ end
204
+
205
+ # Invoked when the stage has been closed. Users need not call it.
206
+ #
207
+ def closed
202
208
  @current_scene.visible = false if @current_scene
203
209
  @current_scene = nil
210
+ @theater.stage_closed(self)
204
211
  end
205
212
 
206
213
  # Loads a scene on the Stage. If the Stage is currently hosting a Scene, the original Scene will be removed and
207
214
  # the new Scene will replace it.
208
215
  #
209
- def load_scene(scene)
216
+ def load_scene(scene)
210
217
  # @frame.setJMenuBar(scene.menu_bar)
211
218
  @frame.load(scene.panel)
212
219
  if (has_static_size?(scene.style))
@@ -233,7 +240,7 @@ module Limelight
233
240
  def alert(message)
234
241
  Thread.new do
235
242
  begin
236
- Studio.utilities_production.alert(message)
243
+ Context.instance.studio.utilities_production.alert(message)
237
244
  rescue StandardError => e
238
245
  puts "Error on alert: #{e}"
239
246
  end
@@ -10,12 +10,11 @@ module Limelight
10
10
  #
11
11
  class Studio
12
12
 
13
- include Limelight::UI::Api::Studio
14
-
15
13
  class << self
16
14
 
17
15
  def install #:nodoc:
18
16
  Context.instance.studio = instance
17
+ return instance
19
18
  end
20
19
 
21
20
  def instance #:nodoc:
@@ -23,163 +22,164 @@ module Limelight
23
22
  return @studio
24
23
  end
25
24
 
26
- def index(production) #:nodoc:
27
- @index = [] if @index.nil?
28
- if name_taken?(production.name)
29
- assign_unique_name(production)
30
- elsif production.name.nil?
31
- assign_name_to(production)
32
- else
33
- error_if_duplicate_name(production.name)
34
- end
35
- @index << production
36
- end
37
-
38
- # Returns the production with the specified name that was previously opened but the Studio.
39
- #
40
- def [](name)
41
- return nil if @index.nil?
42
- return @index.find { |production| production.name == name }
43
- end
44
-
45
- def name_taken?(name) #:nodoc:
46
- return self[name] != nil
47
- end
48
-
49
25
  def reset #:nodoc:
50
- @index = []
51
- @is_shutdown = false
52
- @is_shutting_down = false
53
26
  @studio = nil
54
27
  end
55
28
 
56
- def error_if_duplicate_name(name) #:nodoc:
57
- raise Limelight::LimelightException.new("Production name '#{name}' is already taken") if name_taken?(name)
58
- end
29
+ end
59
30
 
60
- # Opens the production at the specified path.
61
- #
62
- def open(production_path)
63
- begin
64
- producer = Producer.new(production_path)
65
- production = producer.production
66
- index(production)
67
- producer.open
68
- return production
69
- rescue StandardError => e
70
- alert_and_shutdown(e)
71
- end
31
+ def index(production) #:nodoc:
32
+ @index = [] if @index.nil?
33
+ if name_taken?(production.name)
34
+ assign_unique_name(production)
35
+ elsif production.name.nil?
36
+ assign_name_to(production)
37
+ else
38
+ error_if_duplicate_name(production.name)
72
39
  end
40
+ @index << production
41
+ end
73
42
 
74
- # Returns true if all of the open productions allow closing.
75
- #
76
- def should_allow_shutdown
77
- return true if @index.nil?
78
- return @index.all? { |production| production.allow_close? }
79
- end
43
+ # Returns the production with the specified name that was previously opened but the Studio.
44
+ #
45
+ def [](name)
46
+ return nil if @index.nil?
47
+ return @index.find { |production| production.name == name }
48
+ end
80
49
 
81
- # If allowed (should_allow_shutdown), this will close all open productions and shutdown the limelight runtime.
82
- #
83
- def shutdown
84
- return if @is_shutdown || @is_shutting_down
85
- return unless should_allow_shutdown
86
- @is_shutting_down = true
87
- @index.each { |production| production.close } if @index
88
- @utilities_production.close if @utilities_production
89
- @is_shutdown = true
90
- Thread.new { Context.instance().shutdown }
91
- end
50
+ def name_taken?(name) #:nodoc:
51
+ return self[name] != nil
52
+ end
92
53
 
93
- # Called when a production is closed to notify the studio of the event.
94
- #
95
- def production_closed(production)
96
- @index.delete(production) if @index
97
- shutdown if @index && @index.empty?
98
- end
54
+ def error_if_duplicate_name(name) #:nodoc:
55
+ raise Limelight::LimelightException.new("Production name '#{name}' is already taken") if name_taken?(name)
56
+ end
99
57
 
100
- # Returns an array of all the productions
101
- #
102
- def productions
103
- return @index.nil? ? [] : @index.dup
58
+ # Opens the production at the specified path.
59
+ #
60
+ def open(production_path)
61
+ begin
62
+ src = <<END
63
+ #begin
64
+ puts "$:: \#{$:.join(", ")}"
65
+ puts "__FILE__: \#{__FILE__}"
66
+ require 'limelight/limelight_init'
67
+ require 'limelight/producer'
68
+ producer = Limelight::Producer.new("#{production_path}")
69
+ production = producer.production
70
+ Java::java.lang.Thread.currentThread.handle = production
71
+ producer.open
72
+ #rescue Exception => e
73
+ # raise e
74
+ #end
75
+ END
76
+ production = Context.instance().runtimeFactory.spawn(src)
77
+ index(production)
78
+ return production
79
+ rescue StandardError => e
80
+ alert_and_shutdown(e)
104
81
  end
82
+ end
105
83
 
106
- # Publish the Studio, using DRb, on the specified port.
107
- #
108
- def publish_on_drb(port)
109
- @drb_server = DRb.start_service("druby://0.0.0.0:#{port}", self)
110
- end
84
+ # def open(production_path)
85
+ # begin
86
+ # producer = Producer.new(production_path)
87
+ # production = producer.production
88
+ # index(production)
89
+ # producer.open
90
+ # return production
91
+ # rescue StandardError => e
92
+ # alert_and_shutdown(e)
93
+ # end
94
+ # end
95
+
96
+ # Returns true if all of the open productions allow closing.
97
+ #
98
+ def should_allow_shutdown
99
+ return true if @index.nil?
100
+ return @index.all? { |production| production.allow_close? }
101
+ end
111
102
 
112
- # Returns the utilities production; a production used by limelight.
113
- #
114
- def utilities_production
115
- if @utilities_production == nil
116
- producer = Producer.new(File.join($LIMELIGHT_LIB, "limelight", "builtin", "utilities_production"))
117
- @utilities_production = producer.production
118
- producer.open
119
- end
120
- return @utilities_production
121
- end
103
+ # If allowed (should_allow_shutdown), this will close all open productions and shutdown the limelight runtime.
104
+ #
105
+ def shutdown
106
+ return if @is_shutdown || @is_shutting_down
107
+ return unless should_allow_shutdown
108
+ @is_shutting_down = true
109
+ @index.each { |production| production.close } if @index
110
+ @utilities_production.close if @utilities_production
111
+ @is_shutdown = true
112
+ Thread.new { Context.instance().shutdown }
113
+ end
122
114
 
123
- # Returns a hash of all the built-in Limglight Styles
124
- #
125
- def builtin_styles
126
- unless @builtin_styles
127
- builtin_styles_file = File.join($LIMELIGHT_LIB, "limelight", "builtin", "styles.rb")
128
- @builtin_styles = Limelight.build_styles_from_file(builtin_styles_file)
129
- end
130
- return @builtin_styles
131
- end
115
+ # Called when a production is closed to notify the studio of the event.
116
+ #
117
+ def production_closed(production)
118
+ puts "Studio.production_closed @index: #{@index}"
119
+ if @index
120
+ @index.delete(production)
121
+ puts "closing production: #{production}"
122
+ production.audit
123
+ Context.instance().runtimeFactory.terminate(production)
124
+ puts "index.inspect: #{@index.inspect}"
125
+ end
126
+ shutdown if @index && @index.empty?
127
+ end
132
128
 
133
- private #############################################
129
+ # Returns an array of all the productions
130
+ #
131
+ def productions
132
+ return @index.nil? ? [] : @index.dup
133
+ end
134
134
 
135
- def assign_unique_name(production) #:nodoc:
136
- count = 2
137
- name = production.name
138
- while name_taken?(name)
139
- name = "#{production.name}_#{count}"
140
- count += 1
141
- end
142
- production.name = name
143
- end
135
+ # Publish the Studio, using DRb, on the specified port.
136
+ #
137
+ def publish_on_drb(port)
138
+ @drb_server = DRb.start_service("druby://0.0.0.0:#{port}", self)
139
+ end
144
140
 
145
- def assign_name_to(production) #:nodoc:
146
- count = @index.length + 1
147
- while name_taken?(count.to_s)
148
- count += 1
149
- end
150
- production.name = count.to_s
141
+ # Returns the utilities production; a production used by limelight.
142
+ #
143
+ def utilities_production
144
+ if @utilities_production == nil
145
+ producer = Producer.new(File.join($LIMELIGHT_LIB, "limelight", "builtin", "utilities_production"))
146
+ @utilities_production = producer.production
147
+ producer.open
151
148
  end
149
+ return @utilities_production
150
+ end
152
151
 
153
- def alert_and_shutdown(e)
154
- begin
155
- message = "#{e}\n#{e.backtrace.join("\n")}"
156
- utilities_production.alert(message)
157
- shutdown if @index.nil? || @index.empty?
158
- rescue Exception => e
159
- puts e
160
- puts e.backtrace
161
- end
162
- end
152
+ private #############################################
163
153
 
154
+ def assign_unique_name(production) #:nodoc:
155
+ count = 2
156
+ name = production.name
157
+ while name_taken?(name)
158
+ name = "#{production.name}_#{count}"
159
+ count += 1
160
+ end
161
+ production.name = name
164
162
  end
165
163
 
166
- # Same as the class level method.
167
- #
168
- def open(production_path)
169
- self.class.open(production_path)
164
+ def assign_name_to(production) #:nodoc:
165
+ count = @index.length + 1
166
+ while name_taken?(count.to_s)
167
+ count += 1
168
+ end
169
+ production.name = count.to_s
170
170
  end
171
171
 
172
- # Same as the class level method.
173
- #
174
- def should_allow_shutdown
175
- return self.class.should_allow_shutdown
172
+ def alert_and_shutdown(e)
173
+ begin
174
+ message = "#{e}\n#{e.backtrace.join("\n")}"
175
+ utilities_production.alert(message)
176
+ shutdown if @index.nil? || @index.empty?
177
+ rescue Exception => e
178
+ puts e
179
+ puts e.backtrace
180
+ end
176
181
  end
177
182
 
178
- # Same as the class level method.
179
- #
180
- def shutdown
181
- self.class.shutdown()
182
- end
183
183
  end
184
184
 
185
185
  end