Class: JRubyVisualizerController
- Inherits:
-
Object
- Object
- JRubyVisualizerController
- Includes:
- JRubyFX::Controller
- Defined in:
- lib/jruby_visualizer/visualizer_main_app.rb
Overview
Usual controller functionality:
* loading fxml file
* forward UI actions to the CompilerData container
* launch other Applications as concurrent tasks
Instance Attribute Summary collapse
-
#compiler_data ⇒ Object
Returns the value of attribute compiler_data.
-
#information ⇒ Object
Returns the value of attribute information.
Class Method Summary collapse
Instance Method Summary collapse
- #clear_information_view ⇒ Object
- #close_app ⇒ Object
- #fill_ast_view(root_node) ⇒ Object
-
#initialize(compiler_data) ⇒ JRubyVisualizerController
constructor
A new instance of JRubyVisualizerController.
- #launch_about ⇒ Object
- #launch_cfg_view ⇒ Object
- #launch_ir_view ⇒ Object
- #mark_selected_line(line_number) ⇒ Object
- #reset_passes ⇒ Object
- #run_previous_passes_for_selection ⇒ Object
- #scroll_ruby_to_selected_ast ⇒ Object
- #select_ir_pass ⇒ Object
- #step_ir_pass ⇒ Object
Constructor Details
#initialize(compiler_data) ⇒ JRubyVisualizerController
Returns a new instance of JRubyVisualizerController.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/jruby_visualizer/visualizer_main_app.rb', line 131 def initialize(compiler_data) @compiler_data = compiler_data fill_ast_view(@compiler_data.ast_root) # bind change of ast to redrawing AST @compiler_data.ast_root_property.add_change_listener do |new_ast| fill_ast_view(new_ast) end # bind ruby view to value of ruby_code @ruby_view.text_property.bind(@compiler_data.ruby_code_property) # enable scrolling to the ruby code on clicks within the AST scroll_ruby_to_selected_ast # display the IR compiler passes and set the selection to first pass @ir_passes_names = CompilerData.compiler_passes_names @ir_passes_box.items = FXCollections.observable_array_list(@ir_passes_names) @ir_passes_box.value = @selected_ir_pass = @ir_passes_names[0] # background tasks for other views @ir_view_task = SubAppTask.new(:ir_view) @cfg_view_task = SubAppTask.new(:cfg_view) @about_task = SubAppTask.new(:about_page) # Use ListCell with Delete Context Menu in the view for compile information @compile_information.cell_factory = proc { DeletableListCell.new } # information property back ended by the list view for compile information @information = @compile_information.items end |
Instance Attribute Details
#compiler_data ⇒ Object
Returns the value of attribute compiler_data.
129 130 131 |
# File 'lib/jruby_visualizer/visualizer_main_app.rb', line 129 def compiler_data @compiler_data end |
#information ⇒ Object
Returns the value of attribute information.
129 130 131 |
# File 'lib/jruby_visualizer/visualizer_main_app.rb', line 129 def information @information end |
Class Method Details
.pixel_height_of_line ⇒ Object
211 212 213 214 215 216 |
# File 'lib/jruby_visualizer/visualizer_main_app.rb', line 211 def self.pixel_height_of_line monospaced = Java::javafx.scene.text.FontBuilder::create.name('monospaced').size(13).build text = Text.new(' JRubyVisualizer.visualize(ruby_code)') text.set_font(monospaced) text.get_layout_bounds.get_height end |
Instance Method Details
#clear_information_view ⇒ Object
192 193 194 |
# File 'lib/jruby_visualizer/visualizer_main_app.rb', line 192 def clear_information_view @information.clear end |
#close_app ⇒ Object
241 242 243 |
# File 'lib/jruby_visualizer/visualizer_main_app.rb', line 241 def close_app Platform.exit end |
#fill_ast_view(root_node) ⇒ Object
203 204 205 206 207 208 209 |
# File 'lib/jruby_visualizer/visualizer_main_app.rb', line 203 def fill_ast_view(root_node) # clear view @ast_view.root = nil # refill it tree_builder = ASTTreeViewBuilder.new(@ast_view) tree_builder.build_view(root_node) end |
#launch_about ⇒ Object
267 268 269 270 271 272 273 274 275 276 |
# File 'lib/jruby_visualizer/visualizer_main_app.rb', line 267 def launch_about worker_state = Java::javafx.concurrent.Worker::State state = @about_task.state if state == worker_state::READY Platform.run_later(@about_task) elsif state != worker_state::RUNNING @about_task = SubAppTask.new(:about_page) Platform.run_later(@about_task) end end |
#launch_cfg_view ⇒ Object
256 257 258 259 260 261 262 263 264 265 |
# File 'lib/jruby_visualizer/visualizer_main_app.rb', line 256 def launch_cfg_view worker_state = Java::javafx.concurrent.Worker::State state = @cfg_view_task.state if state == worker_state::READY Platform.run_later(@cfg_view_task) elsif state != worker_state::RUNNING @cfg_view_task = SubAppTask.new(:cfg_view) Platform.run_later(@cfg_view_task) end end |
#launch_ir_view ⇒ Object
245 246 247 248 249 250 251 252 253 254 |
# File 'lib/jruby_visualizer/visualizer_main_app.rb', line 245 def launch_ir_view worker_state = Java::javafx.concurrent.Worker::State state = @ir_view_task.state if state == worker_state::READY Platform.run_later(@ir_view_task) elsif state != worker_state::RUNNING @ir_view_task = SubAppTask.new(:ir_view) Platform.run_later(@ir_view_task) end end |
#mark_selected_line(line_number) ⇒ Object
218 219 220 221 222 223 224 225 |
# File 'lib/jruby_visualizer/visualizer_main_app.rb', line 218 def mark_selected_line(line_number) ruby_code = @ruby_view.text ruby_lines = ruby_code.lines.to_a char_begin = ruby_lines[0...line_number].join.chars.count @ruby_view.position_caret(char_begin) char_end = ruby_lines[line_number].chars.count + char_begin @ruby_view.extend_selection(char_end) end |
#reset_passes ⇒ Object
196 197 198 199 200 201 |
# File 'lib/jruby_visualizer/visualizer_main_app.rb', line 196 def reset_passes @compiler_data.reset_scheduler @selected_ir_pass = @ir_passes_names[0] @ir_passes_box.value = @selected_ir_pass clear_information_view end |
#run_previous_passes_for_selection ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/jruby_visualizer/visualizer_main_app.rb', line 164 def run_previous_passes_for_selection if @compiler_data.current_pass.nil? return # beginning of ir passes end current_pass_name = CompilerData.pass_to_s(@compiler_data.current_pass) select_pass_index = @ir_passes_names.index(@selected_ir_pass) current_pass_index = @ir_passes_names.index(current_pass_name) if select_pass_index == current_pass_index return elsif current_pass_index < select_pass_index @compiler_data.step_ir_passes run_previous_passes_for_selection else reset_passes run_previous_passes_for_selection end end |
#scroll_ruby_to_selected_ast ⇒ Object
227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/jruby_visualizer/visualizer_main_app.rb', line 227 def scroll_ruby_to_selected_ast @ast_view.selection_model.selected_item_property.add_change_listener do |ast_tree_cell| start_line = ast_tree_cell.node.position.start_line # first mark the line then scroll to it mark_selected_line(start_line) line_pixels = self.class.pixel_height_of_line # calculate the actual height of the current line in pixels scroll_to_pixels = line_pixels * start_line # scroll to start position of current ast tree cell @ruby_view.set_scroll_top(scroll_to_pixels) end @ast_view.selection_model.set_selected_item(@ast_view.root) end |
#select_ir_pass ⇒ Object
160 161 162 |
# File 'lib/jruby_visualizer/visualizer_main_app.rb', line 160 def select_ir_pass @selected_ir_pass = @ir_passes_box.value end |
#step_ir_pass ⇒ Object
182 183 184 185 186 187 188 189 190 |
# File 'lib/jruby_visualizer/visualizer_main_app.rb', line 182 def step_ir_pass if @compiler_data.next_pass run_previous_passes_for_selection @compiler_data.step_ir_passes @selected_ir_pass = CompilerData.pass_to_s(@compiler_data.current_pass) @ir_passes_box.value = @selected_ir_pass @information << "Successfully passed #{@selected_ir_pass}" end end |