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(application_class, *args) ⇒ 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(application_class, *args)
  #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(application_class, args)
      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(application_class, args) ⇒ Object



93
94
95
96
97
98
99
100
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
# File 'lib/jrubyfx/java_fx_impl.rb', line 93

def self.launch_app_after_platform(application_class, args)
  #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
    })

  application = application_class.new

  unless application.is_a? Java::javafx.application.Application
    raise "Invalid type: cannot launch non-Application"
  end

  ParametersImpl.registerParameters(application, ParametersImpl.new(args))

  application.init

  error = false
  #RUN! and hope it works!
  PlatformImpl.runAndWait do
    begin
      stage = Stage.new
      stage.impl_setPrimary(true)
      application.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
  application.stop unless error
end

.launch_app_from_thread(application_class, args) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
# File 'lib/jrubyfx/java_fx_impl.rb', line 81

def self.launch_app_from_thread(application_class, args)
  begin
    launch_app_after_platform(application_class, args) 
  rescue => ex
    puts "Error running Application:"
    p ex
    puts ex.backtrace
  end

  PlatformImpl.tkExit # kill the toolkit and exit
end