Module: JRubyFX::DSL
- Includes:
- JRubyFX
- Included in:
- Application, Controller, Controller::ClassMethods, Java::JavafxAnimation::FillTransition, Java::JavafxAnimation::ParallelTransition, Java::JavafxAnimation::PathTransition, Java::JavafxAnimation::StrokeTransition, Java::JavafxAnimation::Timeline, Java::JavafxScene::Node, Java::JavafxScene::Parent, Java::JavafxScene::Scene, Java::JavafxSceneChart::Axis, Java::JavafxSceneChart::Chart, Java::JavafxSceneControl::Accordion, Java::JavafxSceneControl::ContextMenu, Java::JavafxSceneControl::ListView, Java::JavafxSceneControl::Menu, Java::JavafxSceneControl::MenuBar, Java::JavafxSceneControl::MenuButton, Java::JavafxSceneControl::MenuItem, Java::JavafxSceneControl::ScrollBar, Java::JavafxSceneControl::ScrollPane, Java::JavafxSceneControl::Separator, Java::JavafxSceneControl::Slider, Java::JavafxSceneControl::SplitPane, Java::JavafxSceneControl::Tab, Java::JavafxSceneControl::TabPane, Java::JavafxSceneControl::TableColumn, Java::JavafxSceneControl::TableView, Java::JavafxSceneControl::TextField, Java::JavafxSceneControl::TitledPane, Java::JavafxSceneControl::ToggleButton, Java::JavafxSceneControl::ToolBar, Java::JavafxSceneControl::Tooltip, Java::JavafxSceneControl::TreeItem, Java::JavafxSceneEffect::Blend, Java::JavafxSceneEffect::ColorInput, Java::JavafxSceneEffect::DropShadow, Java::JavafxSceneEffect::InnerShadow, Java::JavafxSceneEffect::Shadow, Java::JavafxSceneLayout::ColumnConstraints, Java::JavafxSceneLayout::FlowPane, Java::JavafxSceneLayout::GridPane, Java::JavafxSceneLayout::HBox, Java::JavafxSceneLayout::RowConstraints, Java::JavafxSceneLayout::StackPane, Java::JavafxSceneLayout::TilePane, Java::JavafxSceneLayout::VBox, Java::JavafxScenePaint::Color, Java::JavafxScenePaint::Stop, Java::JavafxSceneShape::Arc, Java::JavafxSceneShape::Circle, Java::JavafxSceneShape::Path, Java::JavafxSceneShape::SVGPath, Java::JavafxSceneShape::Shape, Java::JavafxSceneText::Text, Java::JavafxSceneWeb::WebView, Java::JavafxStage::Stage, Java::javafx::scene::chart::XYChart, Java::javafx::scene::chart::XYChart::Data, Java::javafx::scene::chart::XYChart::Series, Java::javafx::scene::control::TreeView, Java::javafx::scene::layout::BorderPane, Java::javafx::stage::FileChooser, Java::javafx::stage::Stage
- Defined in:
- lib/jrubyfx/dsl.rb,
lib/jrubyfx/dsl_map.rb
Overview
Defines a nice DSL for building JavaFX applications. Include it in a class for access to the DSL. JRubyFX::Application and JRubyFX::Controller include it already.
Defined Under Namespace
Modules: ClassUtils
Constant Summary collapse
- NAME_TO_CLASSES =
{ # Manual overrides 'observable_array_list' => proc { |*args| FXCollections.observable_array_list(*args) }, 'double_property' => SimpleDoubleProperty, 'xy_chart_series' => Java::javafx.scene.chart.XYChart::Series, 'xy_chart_data' => Java::javafx.scene.chart.XYChart::Data, # Automatically generated 'animation' => Animation, 'animation_timer' => AnimationTimer, 'fade_transition' => FadeTransition, 'fill_transition' => FillTransition, 'interpolator' => Interpolator, 'key_frame' => KeyFrame, 'key_value' => KeyValue, 'parallel_transition' => ParallelTransition, 'path_transition' => PathTransition, 'pause_transition' => PauseTransition, 'rotate_transition' => RotateTransition, 'scale_transition' => ScaleTransition, 'sequential_transition' => SequentialTransition, 'stroke_transition' => StrokeTransition, 'timeline' => Timeline, 'transition' => Transition, 'translate_transition' => TranslateTransition, 'platform' => Platform, 'simple_boolean_property' => SimpleBooleanProperty, 'simple_double_property' => SimpleDoubleProperty, 'simple_float_property' => SimpleFloatProperty, 'simple_integer_property' => SimpleIntegerProperty, 'simple_list_property' => SimpleListProperty, 'simple_long_property' => SimpleLongProperty, 'simple_map_property' => SimpleMapProperty, 'simple_object_property' => SimpleObjectProperty, 'simple_set_property' => SimpleSetProperty, 'simple_string_property' => SimpleStringProperty, 'change_listener' => ChangeListener, 'fx_collections' => FXCollections, 'event' => Event, 'action_event' => ActionEvent, 'event_handler' => EventHandler, 'initializable' => Initializable, 'load_exception' => LoadException, 'horizontal_direction' => HorizontalDirection, 'h_pos' => HPos, 'insets' => Insets, 'orientation' => Orientation, 'pos' => Pos, 'rectangle2_d' => Rectangle2D, 'side' => Side, 'vertical_direction' => VerticalDirection, 'v_pos' => VPos, 'group' => Group, 'node' => Node, 'parent' => Parent, 'scene' => Scene, 'canvas' => Canvas, 'area_chart' => AreaChart, 'axis' => Axis, 'bar_chart' => BarChart, 'bubble_chart' => BubbleChart, 'category_axis' => CategoryAxis, 'chart' => Chart, 'line_chart' => LineChart, 'number_axis' => NumberAxis, 'pie_chart' => PieChart, 'scatter_chart' => ScatterChart, 'stacked_area_chart' => StackedAreaChart, 'stacked_bar_chart' => StackedBarChart, 'value_axis' => ValueAxis, 'xy_chart' => XYChart, 'accordion' => Accordion, 'button' => Button, 'cell' => Cell, 'check_box' => CheckBox, 'check_box_tree_item' => CheckBoxTreeItem, 'check_menu_item' => CheckMenuItem, 'choice_box' => ChoiceBox, 'color_picker' => ColorPicker, 'combo_box' => ComboBox, 'context_menu' => ContextMenu, 'hyperlink' => Hyperlink, 'label' => Label, 'list_cell' => ListCell, 'list_view' => ListView, 'menu' => Menu, 'menu_bar' => MenuBar, 'menu_button' => MenuButton, 'menu_item' => MenuItem, 'pagination' => Pagination, 'password_field' => PasswordField, 'popup_control' => PopupControl, 'progress_bar' => ProgressBar, 'progress_indicator' => ProgressIndicator, 'radio_button' => RadioButton, 'radio_menu_item' => RadioMenuItem, 'scroll_bar' => ScrollBar, 'scroll_pane' => ScrollPane, 'separator' => Separator, 'separator_menu_item' => SeparatorMenuItem, 'slider' => Slider, 'split_menu_button' => SplitMenuButton, 'split_pane' => SplitPane, 'tab' => Tab, 'table_view' => TableView, 'table_cell' => TableCell, 'table_column' => TableColumn, 'tab_pane' => TabPane, 'text_area' => TextArea, 'text_field' => TextField, 'titled_pane' => TitledPane, 'toggle_button' => ToggleButton, 'toggle_group' => ToggleGroup, 'tool_bar' => ToolBar, 'tooltip' => Tooltip, 'tree_cell' => TreeCell, 'tree_item' => TreeItem, 'tree_view' => TreeView, 'content_display' => ContentDisplay, 'overrun_style' => OverrunStyle, 'selection_mode' => SelectionMode, 'blend' => Blend, 'blend_mode' => BlendMode, 'bloom' => Bloom, 'blur_type' => BlurType, 'box_blur' => BoxBlur, 'color_adjust' => ColorAdjust, 'color_input' => ColorInput, 'displacement_map' => DisplacementMap, 'drop_shadow' => DropShadow, 'gaussian_blur' => GaussianBlur, 'glow' => Glow, 'image_input' => ImageInput, 'inner_shadow' => InnerShadow, 'lighting' => Lighting, 'motion_blur' => MotionBlur, 'perspective_transform' => PerspectiveTransform, 'reflection' => Reflection, 'sepia_tone' => SepiaTone, 'shadow' => Shadow, 'image' => Image, 'image_view' => ImageView, 'pixel_reader' => PixelReader, 'pixel_writer' => PixelWriter, 'clipboard' => Clipboard, 'clipboard_content' => ClipboardContent, 'context_menu_event' => ContextMenuEvent, 'drag_event' => DragEvent, 'gesture_event' => GestureEvent, 'input_event' => InputEvent, 'input_method_event' => InputMethodEvent, 'key_code' => KeyCode, 'key_event' => KeyEvent, 'mnemonic' => Mnemonic, 'mouse_drag_event' => MouseDragEvent, 'mouse_event' => MouseEvent, 'rotate_event' => RotateEvent, 'scroll_event' => ScrollEvent, 'swipe_event' => SwipeEvent, 'touch_event' => TouchEvent, 'transfer_mode' => TransferMode, 'zoom_event' => ZoomEvent, 'anchor_pane' => AnchorPane, 'border_pane' => BorderPane, 'column_constraints' => ColumnConstraints, 'flow_pane' => FlowPane, 'grid_pane' => GridPane, 'hbox' => HBox, 'pane' => Pane, 'priority' => Priority, 'row_constraints' => RowConstraints, 'stack_pane' => StackPane, 'tile_pane' => TilePane, 'vbox' => VBox, 'audio_clip' => AudioClip, 'audio_equalizer' => AudioEqualizer, 'audio_track' => AudioTrack, 'equalizer_band' => EqualizerBand, 'media' => Media, 'media_exception' => MediaException, 'media_error_event' => MediaErrorEvent, 'media_marker_event' => MediaMarkerEvent, 'media_player' => MediaPlayer, 'media_view' => MediaView, 'video_track' => VideoTrack, 'color' => Color, 'cycle_method' => CycleMethod, 'image_pattern' => ImagePattern, 'linear_gradient' => LinearGradient, 'paint' => Paint, 'radial_gradient' => RadialGradient, 'stop' => Stop, 'arc' => Arc, 'arc_to' => ArcTo, 'arc_type' => ArcType, 'circle' => Circle, 'close_path' => ClosePath, 'cubic_curve' => CubicCurve, 'cubic_curve_to' => CubicCurveTo, 'ellipse' => Ellipse, 'fill_rule' => FillRule, 'hline_to' => HLineTo, 'line' => Line, 'line_to' => LineTo, 'move_to' => MoveTo, 'path' => Path, 'path_element' => PathElement, 'polygon' => Polygon, 'polyline' => Polyline, 'quad_curve' => QuadCurve, 'quad_curve_to' => QuadCurveTo, 'rectangle' => Rectangle, 'shape' => Shape, 'stroke_line_cap' => StrokeLineCap, 'stroke_line_join' => StrokeLineJoin, 'stroke_type' => StrokeType, 'svg_path' => SVGPath, 'vline_to' => VLineTo, 'font' => Font, 'font_posture' => FontPosture, 'font_smoothing_type' => FontSmoothingType, 'font_weight' => FontWeight, 'text' => Text, 'text_alignment' => TextAlignment, 'text_bounds_type' => TextBoundsType, 'affine' => Affine, 'rotate' => Rotate, 'scale' => Scale, 'shear' => Shear, 'translate' => Translate, 'web_view' => WebView, 'html_editor' => HTMLEditor, 'directory_chooser' => DirectoryChooser, 'file_chooser' => FileChooser, 'modality' => Modality, 'popup' => Popup, 'popup_window' => PopupWindow, 'screen' => Screen, 'stage' => Stage, 'stage_style' => StageStyle, 'window' => Window, 'window_event' => WindowEvent, 'duration' => Duration, }
Constants included from JRubyFX
Constants included from FXImports
FXImports::JFX_CLASS_HIERARCHY
Class Method Summary collapse
-
.compile_dsl(out) ⇒ Object
This loads the entire DSL.
-
.included(mod) ⇒ Object
When a class includes JRubyFX, extend (add to the metaclass) ClassUtils.
-
.load_dsl ⇒ Object
This loads the entire DSL.
- .write_color_method_converter(outf, in_class, jfuncnclasses) ⇒ Object
-
.write_enum_converter(outf) ⇒ Object
Loads the special symbol to enum converter functions into all methods and enums.
- .write_enum_method_converter(outf, in_class, jfuncnclasses) ⇒ Object
Instance Method Summary collapse
- #logical_lookup(*args) ⇒ Object
-
#method_missing(name, *args, &block) ⇒ Object
(also: #node_method_missing)
This is the heart of the DSL.
- #self_test_lookup(selector) ⇒ Object
Methods included from JRubyFX
Methods included from Utils::CommonUtils
#attempt_conversion, #populate_properties, #split_args_from_properties
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object Also known as: node_method_missing
This is the heart of the DSL. When a method is missing and the name of the method is in the NAME_TO_CLASSES mapping, it calls JRubyFX.build with the Java class. This means that instead of saying
build(JavaClass, hash) { ... }
you can say
java_class(hash) { ... }
Another major portion of the DSL is the ability to implicitly add new created components to their parent on construction. There are a few places where this is undesirable. In order to prevent implicit construction you can add a ‘!’ on the end:
circle!(30)
This will construct a Circle but it will not add it into its parent container. This is useful for specifying clipping regions in particular.
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/jrubyfx/dsl.rb', line 79 def method_missing(name, *args, &block) clazz = NAME_TO_CLASSES[name.to_s.gsub(/!$/, '')] if caller[0] == caller[2] raise "Whoa! method_missing caught infinite loop. Trying to run #{name}(#{args.inspect}) failed. Method not found." end super unless clazz build(clazz, *args, &block) end |
Class Method Details
.compile_dsl(out) ⇒ Object
This loads the entire DSL. Call this immediately after requiring this file, but not inside this file, or it requires itself twice.
270 271 272 |
# File 'lib/jrubyfx/dsl.rb', line 270 def self.compile_dsl(out) JRubyFX::DSL.write_enum_converter out end |
.included(mod) ⇒ Object
When a class includes JRubyFX, extend (add to the metaclass) ClassUtils
50 51 52 |
# File 'lib/jrubyfx/dsl.rb', line 50 def self.included(mod) mod.extend(JRubyFX::DSL::ClassUtils) end |
.load_dsl ⇒ Object
This loads the entire DSL. Call this immediately after requiring this file, but not inside this file, or it requires itself twice.
257 258 259 260 261 262 263 264 265 266 |
# File 'lib/jrubyfx/dsl.rb', line 257 def self.load_dsl unless File.size? "#{File.dirname(__FILE__)}/core_ext/precompiled.rb" puts "Please run `rake reflect` to generate the converters" exit -1 end rt = "#{File.dirname(__FILE__)}/core_ext".sub /\Ajar:/, "" Dir.glob("#{rt}/*.rb") do |file| require file end end |
.write_color_method_converter(outf, in_class, jfuncnclasses) ⇒ Object
222 223 224 225 226 227 228 229 230 231 |
# File 'lib/jrubyfx/dsl.rb', line 222 def self.write_color_method_converter(outf, in_class, jfuncnclasses) jfuncnclasses.each do |jfunc| next if jfunc.include? "impl_" outf[in_class.to_s] << <<ENDNAIVE def #{jfunc.to_s.gsub(/^set/i,'').snake_case}=(value) #{jfunc}(JRubyFX::Utils::CommonConverters::CONVERTERS[:color].call(value)) end ENDNAIVE end end |
.write_enum_converter(outf) ⇒ Object
Loads the special symbol to enum converter functions into all methods and enums
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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/jrubyfx/dsl.rb', line 95 def self.write_enum_converter(outf) # use reflection to load all enums into all_enums and methods that use them # into enum_methods mod_list = { :methods =>{}, :all => [] } JRubyFX::DSL::NAME_TO_CLASSES.each do |n,cls| cls.java_class.java_instance_methods.each do |method| args = method.argument_types.find_all(&:enum?).tap {|i| mod_list[:all] << i } # one and only, must be a setter style if method.argument_types.length == 1 and (args.length == method.argument_types.length) and !(cls.ancestors[1].public_instance_methods.include? method.name.to_sym) mod_list[:methods][cls] = [] unless mod_list[:methods][cls] # stuff both method name and the type of the argument in mod_list[:methods][cls] << [method.name, JavaUtilities.get_proxy_class(args[0])] end end if cls.respond_to? :ancestors and cls.ancestors.include? JavaProxy # some are not java classes. ignore those end require 'yaml' child_catcher = {} # finally, "override" each method mod_list[:methods].each do |clz, method| child_catcher[clz.to_s] = "" unless child_catcher[clz.to_s] write_enum_method_converter child_catcher, clz, method end # cleanout and search for colors. TODO: combind with previous mod_list = {:methods =>{}, :all => []} JRubyFX::DSL::NAME_TO_CLASSES.each do |n,cls| cls.java_class.java_instance_methods.each do |method| args = method.argument_types.find_all{|i| JavaUtilities.get_proxy_class(i).ancestors.include? Java::javafx.scene.paint.Paint} # one and only, must be a setter style if args.length == 1 and !(cls.ancestors[1].public_instance_methods.include? method.name.to_sym) #TODO: multiple args mod_list[:methods][cls] = [] unless mod_list[:methods][cls] # stuff both method name and the type of the argument in mod_list[:methods][cls] << method.name end end if cls.respond_to? :ancestors and cls.ancestors.include? JavaProxy # some are not java classes. ignore those end mod_list[:methods].each do |clz, method| child_catcher[clz.to_s] = "" unless child_catcher[clz.to_s] write_color_method_converter child_catcher, clz, method end # load the yaml descriptors ydescs = YAML.load_file("#{File.dirname(__FILE__)}/core_ext/exts.yml") builders = {add: ->(on, adder){ " def add(value) #{adder}() << value end\n" }, rotate: ->(on){ " def rotate(*args) transforms << build(Rotate, *args) end\n" }, method_missing: ->(on, type) { # we must manually call super otherwise it will call super(type) " def method_missing(name, *args, &block) super(name, *args, &block).tap do |obj| add(obj) if obj.kind_of?(#{type}) && !name.to_s.end_with?('!') end end\n" }, logical_child: ->(on, prop_name){" #TODO: logical_child(#{prop_name})\n"}, logical_children: ->(on, prop_name){" #TODO: logical_children(#{prop_name})\n"}, getter_setter: ->(on, name) { # FIXME: Is arity of splat the best way to do this? " def #{name}(*r) if r.length > 0 self.#{name} = r[0] else get_#{name} end end\n" }, new_converter: ->(on, *args){ els = 0 " def self.new(*args) super *JRubyFX::Utils::CommonConverters.convert_args(args, #{args.map{|i|i.map(&:to_sym)}.inspect}) end\n" }, dsl: ->(on, *args){" "}, } #parse the ydescs ydescs.each do |clz, acts| acts.each do |mname, arg| child_catcher[clz] = "" unless child_catcher[clz] lamb = builders[mname.to_sym] arg = [arg] unless arg.is_a? Array child_catcher[clz] << lamb.call(*([clz] + arg)) end end child_catcher.each do |clz, defs| next if defs == "" || defs == nil # TODO: do we need to include the dsl? is this the fastest way to do it? outf<< <<HERDOC class #{clz} include JRubyFX::DSL #{defs}end HERDOC end end |
.write_enum_method_converter(outf, in_class, jfuncnclasses) ⇒ Object
211 212 213 214 215 216 217 218 219 220 |
# File 'lib/jrubyfx/dsl.rb', line 211 def self.write_enum_method_converter(outf, in_class, jfuncnclasses) jfuncnclasses.each do |jfunc, jclass| next if jfunc.include? "impl_" outf[in_class.to_s] << <<ENDNAIVE def #{jfunc.to_s.gsub(/^set/i,'').snake_case}=(rbenum) java_send #{jfunc.inspect}, [#{jclass}], JRubyFX::Utils::CommonConverters.parse_ruby_symbols(rbenum, #{jclass}) end ENDNAIVE end end |
Instance Method Details
#logical_lookup(*args) ⇒ Object
243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/jrubyfx/dsl.rb', line 243 def logical_lookup(*args) unless self.is_a?(Node) p self p self.to_s return self_test_lookup(*args) end self.lookup(*args) || self.tap do |x| return nil unless x.respond_to? :children return x.children.map_find{|i| i.logical_lookup(*args)} end end |
#self_test_lookup(selector) ⇒ Object
233 234 235 236 237 238 239 240 241 |
# File 'lib/jrubyfx/dsl.rb', line 233 def self_test_lookup(selector) if selector.start_with? "#" return (if "##{self.id}" == selector self else nil end) end end |