Class: JavaFXImpl::Launcher

Inherits:
Object
  • Object
show all
Defined in:
lib/jrubyfx/java_fx_impl.rb

Constant Summary collapse

@@launchCalled =

Atomic boolean go boom on bikini

AtomicBoolean.new(false)

Class Method Summary collapse

Class Method Details

.launch_app(classObj, args = nil) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/jrubyfx/java_fx_impl.rb', line 52

def self.launch_app(classObj, args=nil)
  #prevent multiple!
  if @@launchCalled.getAndSet(true)
    throw IllegalStateException.new "Application launch must not be called more than once"
  end
  
  begin
    #create a java thread, and run the real worker, and wait till it exits
    count_down_latch = CountDownLatch.new(1)
    thread = Java.java.lang.Thread.new do
      begin
        launch_app_from_thread(classObj)
      rescue => ex
        puts "Exception starting app:"
        p ex
        p ex.backtrace
      end
      count_down_latch.countDown #always count down
    end
    thread.name = "JavaFX-Launcher"
    thread.start
    count_down_latch.await
  rescue => ex
    puts "Exception launching JavaFX-Launcher thread:"
    p ex
    puts ex.backtrace
  end
end

.launch_app_after_platform(classO) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/jrubyfx/java_fx_impl.rb', line 101

def self.launch_app_after_platform(classO)
  #listeners - for the end
  finished_latch = CountDownLatch.new(1)
  
  # register for shutdown
  PlatformImpl.addListener(FinisherInterface.new {
      # this is called when the stage exits
      finished_latch.countDown
    })

  app = classO.new
  # do we need to register the params if there are none? - apparently not
  app.init()
  
  error = false
  #RUN! and hope it works!
  PlatformImpl.runAndWait do
    begin
      stage = Stage.new
      stage.impl_setPrimary(true)
      app.start(stage)
      # no countDown here because its up top... yes I know
    rescue => ex
      puts "Exception running Application:"
      p ex
      puts ex.backtrace
      error = true
      finished_latch.countDown # but if we fail, we need to unlatch it
    end
  end
    
  #wait for stage exit
  finished_latch.await
  
  # call stop on the interface
  app.stop() unless error
end

.launch_app_from_thread(classO) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/jrubyfx/java_fx_impl.rb', line 81

def self.launch_app_from_thread(classO)
  #platformImpl startup?
  finished_latch = CountDownLatch.new(1)
  PlatformImpl.startup do
    finished_latch.countDown
  end
  finished_latch.await
  
  begin
    launch_app_after_platform(classO) #try to launch the app
  rescue => ex
    puts "Error running Application:"
    p ex
    puts ex.backtrace
  end
  
  #kill the toolkit and exit
  PlatformImpl.tkExit
end