Class: Sol::DCFX

Inherits:
JRubyFX::Application
  • Object
show all
Defined in:
lib/webview/dcfx.rb

Overview

This is the GUI thread. It is the mais JRubyFX application.

Class Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Attribute Details

+ (Object) dashboard

Returns the value of attribute dashboard



39
40
41
# File 'lib/webview/dcfx.rb', line 39

def dashboard
  @dashboard
end

+ (Object) height

Returns the value of attribute height



41
42
43
# File 'lib/webview/dcfx.rb', line 41

def height
  @height
end

+ (Object) launched

Returns the value of attribute launched



42
43
44
# File 'lib/webview/dcfx.rb', line 42

def launched
  @launched
end

+ (Object) width

Returns the value of attribute width



40
41
42
# File 'lib/webview/dcfx.rb', line 40

def width
  @width
end

Class Method Details

+ (Object) launch(width, height)

def self.launch(dashboard, width, height)



133
134
135
136
137
138
# File 'lib/webview/dcfx.rb', line 133

def self.launch(width, height)
  DCFX.launched = true
  DCFX.width = width
  DCFX.height = height
  super()
end

+ (Boolean) launched?


Checks to see if DCFX was already launched. For some reason a JavaFX application can only be launched once.


Returns:

  • (Boolean)


124
125
126
# File 'lib/webview/dcfx.rb', line 124

def self.launched?
  (DCFX.launched)? true : false
end

Instance Method Details

- (Object) start(stage)





50
51
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
80
81
82
83
84
85
86
87
88
89
90
91
92
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
# File 'lib/webview/dcfx.rb', line 50

def start(stage)
  
  browser = WebView.new
  @web_engine = browser.getEngine()
  
  # Load configuration file.  This loads all the Javascript scripts onto the embbeded
  # web browser
  f = Java::JavaIo.File.new("#{File.dirname(__FILE__)}/config.html")
  fil = f.toURI().toURL().toString()
  @web_engine.load(fil)
  
  # sets the communication between the GUI and the dashboard so that we can add new
  # graphics and visualizations to the Web browser without going through the GUI, i.e,
  # we want to drive the visualization through our Ruby scripts and not directly
  # through the GUI. Creates a GuiCommunication service that will execute in a loop
  # and will wait for messages that should be executed on the Gui thread (JavaFX
  # Application).  In order to actually send a message one needs to use the
  # communication "Bridge" by doing:
  # Bridge.instance.send(<receiver>, :executeScript, <javascript>)
  service = GuiCommunication.new
  service.set_on_succeeded(ExecMessages.new(@web_engine, service))
  
  #--------------------------------------------------------------------------------------
  # User Interface
  #--------------------------------------------------------------------------------------
  
  # Add button to run the script. Later should be removed as the graph is supposed to 
  # run when the window is loaded
  # script_button = build(Button, "Run script")
  # script_button.set_on_action { |e| plot }
  
  
  # Example on how to: Add a menu bar -- do not delete (yet!)
  # menu_bar = build(MenuBar)
  # menu_filters = build(Menu, "Filters")
  # add filters to the filter menu
  # add_filters
  # menu_bar.get_menus.add_all(menu_filters)
  
  @web_engine.getLoadWorker().stateProperty().
    addListener(ChangeListener.impl do |ov, old_state, new_state|
                  service.start()
                end)
  
  with(stage, title: "Sol Charting Library (based on DC.js)") do
    Platform.set_implicit_exit(false)
    layout_scene(DCFX.width, DCFX.height, :oldlace) do
      pane = border_pane do
        top menu_bar 
        center browser
        # right script_button
      end
    end
    set_on_close_request do
      stage.close
    end
    show
  end
  
=begin
    @web_engine.set_on_status_changed { |e| p e.toString() }
    @web_engine.set_on_alert { |e| p e.toString() }
    @web_engine.set_on_resized { |e| p e.toString() }
    @web_engine.set_on_visibility_changed { |e| p e.toString() }
    browser.set_on_mouse_entered { |e| p e.toString() }
=end

end