Module: JRubyFX::DSL

Includes:
JRubyFX, FXImports
Included in:
Application, Controller, Controller::ClassMethods, Java::JavafxAnimation::Animation, Java::JavafxAnimation::FillTransition, Java::JavafxAnimation::ParallelTransition, Java::JavafxAnimation::PathTransition, Java::JavafxAnimation::StrokeTransition, Java::JavafxAnimation::Timeline, Java::JavafxConcurrent::Service, Java::JavafxConcurrent::Task, Java::JavafxScene::Node, Java::JavafxScene::Parent, Java::JavafxScene::Scene, Java::JavafxSceneChart::Axis, Java::JavafxSceneChart::Chart, Java::JavafxSceneChart::LineChart, Java::JavafxSceneControl::Accordion, Java::JavafxSceneControl::ChoiceBox, Java::JavafxSceneControl::ContextMenu, Java::JavafxSceneControl::ListView, Java::JavafxSceneControl::Menu, Java::JavafxSceneControl::MenuBar, Java::JavafxSceneControl::MenuButton, Java::JavafxSceneControl::MenuItem, Java::JavafxSceneControl::PopupControl, Java::JavafxSceneControl::RadioMenuItem, 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::JavafxSceneControl::TreeView, 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::JavafxSceneMedia::Media, Java::JavafxSceneMedia::MediaPlayer, Java::JavafxSceneMedia::MediaView, 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::PopupWindow, Java::JavafxStage::Stage, Java::JavafxStage::Window, 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::scene::layout::GridPane, 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' => Java::JavafxBeansProperty::SimpleDoubleProperty,
  'xy_chart_series' => Java::javafx.scene.chart.XYChart::Series,
  'xy_chart_data' => Java::javafx.scene.chart.XYChart::Data,
  # Automatically generated
}
NAME_TO_CLASS_NAME =

Automatically generated

{
  'animation' => "Java::JavafxAnimation::Animation",
  'animation_timer' => "Java::JavafxAnimation::AnimationTimer",
  'fade_transition' => "Java::JavafxAnimation::FadeTransition",
  'fill_transition' => "Java::JavafxAnimation::FillTransition",
  'interpolator' => "Java::JavafxAnimation::Interpolator",
  'key_frame' => "Java::JavafxAnimation::KeyFrame",
  'key_value' => "Java::JavafxAnimation::KeyValue",
  'parallel_transition' => "Java::JavafxAnimation::ParallelTransition",
  'path_transition' => "Java::JavafxAnimation::PathTransition",
  'pause_transition' => "Java::JavafxAnimation::PauseTransition",
  'rotate_transition' => "Java::JavafxAnimation::RotateTransition",
  'scale_transition' => "Java::JavafxAnimation::ScaleTransition",
  'sequential_transition' => "Java::JavafxAnimation::SequentialTransition",
  'stroke_transition' => "Java::JavafxAnimation::StrokeTransition",
  'timeline' => "Java::JavafxAnimation::Timeline",
  'transition' => "Java::JavafxAnimation::Transition",
  'translate_transition' => "Java::JavafxAnimation::TranslateTransition",
  'platform' => "Java::JavafxApplication::Platform",
  'simple_boolean_property' => "Java::JavafxBeansProperty::SimpleBooleanProperty",
  'simple_double_property' => "Java::JavafxBeansProperty::SimpleDoubleProperty",
  'simple_float_property' => "Java::JavafxBeansProperty::SimpleFloatProperty",
  'simple_integer_property' => "Java::JavafxBeansProperty::SimpleIntegerProperty",
  'simple_list_property' => "Java::JavafxBeansProperty::SimpleListProperty",
  'simple_long_property' => "Java::JavafxBeansProperty::SimpleLongProperty",
  'simple_map_property' => "Java::JavafxBeansProperty::SimpleMapProperty",
  'simple_object_property' => "Java::JavafxBeansProperty::SimpleObjectProperty",
  'simple_set_property' => "Java::JavafxBeansProperty::SimpleSetProperty",
  'simple_string_property' => "Java::JavafxBeansProperty::SimpleStringProperty",
  'change_listener' => "Java::JavafxBeansValue::ChangeListener",
  'fx_collections' => "Java::JavafxCollections::FXCollections",
  'worker' => "Java::JavafxConcurrent::Worker",
  'task' => "Java::JavafxConcurrent::Task",
  'service' => "Java::JavafxConcurrent::Service",
  'event' => "Java::JavafxEvent::Event",
  'action_event' => "Java::JavafxEvent::ActionEvent",
  'event_handler' => "Java::JavafxEvent::EventHandler",
  'initializable' => "Java::JavafxFxml::Initializable",
  'load_exception' => "Java::JavafxFxml::LoadException",
  'horizontal_direction' => "Java::JavafxGeometry::HorizontalDirection",
  'h_pos' => "Java::JavafxGeometry::HPos",
  'insets' => "Java::JavafxGeometry::Insets",
  'orientation' => "Java::JavafxGeometry::Orientation",
  'pos' => "Java::JavafxGeometry::Pos",
  'rectangle2_d' => "Java::JavafxGeometry::Rectangle2D",
  'side' => "Java::JavafxGeometry::Side",
  'vertical_direction' => "Java::JavafxGeometry::VerticalDirection",
  'v_pos' => "Java::JavafxGeometry::VPos",
  'group' => "Java::JavafxScene::Group",
  'node' => "Java::JavafxScene::Node",
  'parent' => "Java::JavafxScene::Parent",
  'scene' => "Java::JavafxScene::Scene",
  'canvas' => "Java::JavafxSceneCanvas::Canvas",
  'area_chart' => "Java::JavafxSceneChart::AreaChart",
  'axis' => "Java::JavafxSceneChart::Axis",
  'bar_chart' => "Java::JavafxSceneChart::BarChart",
  'bubble_chart' => "Java::JavafxSceneChart::BubbleChart",
  'category_axis' => "Java::JavafxSceneChart::CategoryAxis",
  'chart' => "Java::JavafxSceneChart::Chart",
  'line_chart' => "Java::JavafxSceneChart::LineChart",
  'number_axis' => "Java::JavafxSceneChart::NumberAxis",
  'pie_chart' => "Java::JavafxSceneChart::PieChart",
  'scatter_chart' => "Java::JavafxSceneChart::ScatterChart",
  'stacked_area_chart' => "Java::JavafxSceneChart::StackedAreaChart",
  'stacked_bar_chart' => "Java::JavafxSceneChart::StackedBarChart",
  'value_axis' => "Java::JavafxSceneChart::ValueAxis",
  'xy_chart' => "Java::JavafxSceneChart::XYChart",
  'accordion' => "Java::JavafxSceneControl::Accordion",
  'button' => "Java::JavafxSceneControl::Button",
  'cell' => "Java::JavafxSceneControl::Cell",
  'check_box' => "Java::JavafxSceneControl::CheckBox",
  'check_box_tree_item' => "Java::JavafxSceneControl::CheckBoxTreeItem",
  'check_menu_item' => "Java::JavafxSceneControl::CheckMenuItem",
  'choice_box' => "Java::JavafxSceneControl::ChoiceBox",
  'color_picker' => "Java::JavafxSceneControl::ColorPicker",
  'combo_box' => "Java::JavafxSceneControl::ComboBox",
  'context_menu' => "Java::JavafxSceneControl::ContextMenu",
  'hyperlink' => "Java::JavafxSceneControl::Hyperlink",
  'label' => "Java::JavafxSceneControl::Label",
  'list_cell' => "Java::JavafxSceneControl::ListCell",
  'list_view' => "Java::JavafxSceneControl::ListView",
  'menu' => "Java::JavafxSceneControl::Menu",
  'menu_bar' => "Java::JavafxSceneControl::MenuBar",
  'menu_button' => "Java::JavafxSceneControl::MenuButton",
  'menu_item' => "Java::JavafxSceneControl::MenuItem",
  'pagination' => "Java::JavafxSceneControl::Pagination",
  'password_field' => "Java::JavafxSceneControl::PasswordField",
  'popup_control' => "Java::JavafxSceneControl::PopupControl",
  'progress_bar' => "Java::JavafxSceneControl::ProgressBar",
  'progress_indicator' => "Java::JavafxSceneControl::ProgressIndicator",
  'radio_button' => "Java::JavafxSceneControl::RadioButton",
  'radio_menu_item' => "Java::JavafxSceneControl::RadioMenuItem",
  'scroll_bar' => "Java::JavafxSceneControl::ScrollBar",
  'scroll_pane' => "Java::JavafxSceneControl::ScrollPane",
  'separator' => "Java::JavafxSceneControl::Separator",
  'separator_menu_item' => "Java::JavafxSceneControl::SeparatorMenuItem",
  'slider' => "Java::JavafxSceneControl::Slider",
  'split_menu_button' => "Java::JavafxSceneControl::SplitMenuButton",
  'split_pane' => "Java::JavafxSceneControl::SplitPane",
  'tab' => "Java::JavafxSceneControl::Tab",
  'table_view' => "Java::JavafxSceneControl::TableView",
  'table_cell' => "Java::JavafxSceneControl::TableCell",
  'table_column' => "Java::JavafxSceneControl::TableColumn",
  'tab_pane' => "Java::JavafxSceneControl::TabPane",
  'text_area' => "Java::JavafxSceneControl::TextArea",
  'text_field' => "Java::JavafxSceneControl::TextField",
  'titled_pane' => "Java::JavafxSceneControl::TitledPane",
  'toggle_button' => "Java::JavafxSceneControl::ToggleButton",
  'toggle_group' => "Java::JavafxSceneControl::ToggleGroup",
  'tool_bar' => "Java::JavafxSceneControl::ToolBar",
  'tooltip' => "Java::JavafxSceneControl::Tooltip",
  'tree_cell' => "Java::JavafxSceneControl::TreeCell",
  'tree_item' => "Java::JavafxSceneControl::TreeItem",
  'tree_view' => "Java::JavafxSceneControl::TreeView",
  'content_display' => "Java::JavafxSceneControl::ContentDisplay",
  'overrun_style' => "Java::JavafxSceneControl::OverrunStyle",
  'selection_mode' => "Java::JavafxSceneControl::SelectionMode",
  'blend' => "Java::JavafxSceneEffect::Blend",
  'blend_mode' => "Java::JavafxSceneEffect::BlendMode",
  'bloom' => "Java::JavafxSceneEffect::Bloom",
  'blur_type' => "Java::JavafxSceneEffect::BlurType",
  'box_blur' => "Java::JavafxSceneEffect::BoxBlur",
  'color_adjust' => "Java::JavafxSceneEffect::ColorAdjust",
  'color_input' => "Java::JavafxSceneEffect::ColorInput",
  'displacement_map' => "Java::JavafxSceneEffect::DisplacementMap",
  'drop_shadow' => "Java::JavafxSceneEffect::DropShadow",
  'gaussian_blur' => "Java::JavafxSceneEffect::GaussianBlur",
  'glow' => "Java::JavafxSceneEffect::Glow",
  'image_input' => "Java::JavafxSceneEffect::ImageInput",
  'inner_shadow' => "Java::JavafxSceneEffect::InnerShadow",
  'lighting' => "Java::JavafxSceneEffect::Lighting",
  'motion_blur' => "Java::JavafxSceneEffect::MotionBlur",
  'perspective_transform' => "Java::JavafxSceneEffect::PerspectiveTransform",
  'reflection' => "Java::JavafxSceneEffect::Reflection",
  'sepia_tone' => "Java::JavafxSceneEffect::SepiaTone",
  'shadow' => "Java::JavafxSceneEffect::Shadow",
  'image' => "Java::JavafxSceneImage::Image",
  'image_view' => "Java::JavafxSceneImage::ImageView",
  'pixel_reader' => "Java::JavafxSceneImage::PixelReader",
  'pixel_writer' => "Java::JavafxSceneImage::PixelWriter",
  'clipboard' => "Java::JavafxSceneInput::Clipboard",
  'clipboard_content' => "Java::JavafxSceneInput::ClipboardContent",
  'context_menu_event' => "Java::JavafxSceneInput::ContextMenuEvent",
  'drag_event' => "Java::JavafxSceneInput::DragEvent",
  'gesture_event' => "Java::JavafxSceneInput::GestureEvent",
  'input_event' => "Java::JavafxSceneInput::InputEvent",
  'input_method_event' => "Java::JavafxSceneInput::InputMethodEvent",
  'key_code' => "Java::JavafxSceneInput::KeyCode",
  'key_event' => "Java::JavafxSceneInput::KeyEvent",
  'mnemonic' => "Java::JavafxSceneInput::Mnemonic",
  'mouse_button' => "Java::JavafxSceneInput::MouseButton",
  'mouse_drag_event' => "Java::JavafxSceneInput::MouseDragEvent",
  'mouse_event' => "Java::JavafxSceneInput::MouseEvent",
  'rotate_event' => "Java::JavafxSceneInput::RotateEvent",
  'scroll_event' => "Java::JavafxSceneInput::ScrollEvent",
  'swipe_event' => "Java::JavafxSceneInput::SwipeEvent",
  'touch_event' => "Java::JavafxSceneInput::TouchEvent",
  'transfer_mode' => "Java::JavafxSceneInput::TransferMode",
  'zoom_event' => "Java::JavafxSceneInput::ZoomEvent",
  'anchor_pane' => "Java::JavafxSceneLayout::AnchorPane",
  'border_pane' => "Java::JavafxSceneLayout::BorderPane",
  'column_constraints' => "Java::JavafxSceneLayout::ColumnConstraints",
  'flow_pane' => "Java::JavafxSceneLayout::FlowPane",
  'grid_pane' => "Java::JavafxSceneLayout::GridPane",
  'hbox' => "Java::JavafxSceneLayout::HBox",
  'pane' => "Java::JavafxSceneLayout::Pane",
  'priority' => "Java::JavafxSceneLayout::Priority",
  'row_constraints' => "Java::JavafxSceneLayout::RowConstraints",
  'stack_pane' => "Java::JavafxSceneLayout::StackPane",
  'tile_pane' => "Java::JavafxSceneLayout::TilePane",
  'vbox' => "Java::JavafxSceneLayout::VBox",
  'audio_clip' => "Java::JavafxSceneMedia::AudioClip",
  'audio_equalizer' => "Java::JavafxSceneMedia::AudioEqualizer",
  'audio_track' => "Java::JavafxSceneMedia::AudioTrack",
  'equalizer_band' => "Java::JavafxSceneMedia::EqualizerBand",
  'media' => "Java::JavafxSceneMedia::Media",
  'media_exception' => "Java::JavafxSceneMedia::MediaException",
  'media_error_event' => "Java::JavafxSceneMedia::MediaErrorEvent",
  'media_marker_event' => "Java::JavafxSceneMedia::MediaMarkerEvent",
  'media_player' => "Java::JavafxSceneMedia::MediaPlayer",
  'media_view' => "Java::JavafxSceneMedia::MediaView",
  'video_track' => "Java::JavafxSceneMedia::VideoTrack",
  'color' => "Java::JavafxScenePaint::Color",
  'cycle_method' => "Java::JavafxScenePaint::CycleMethod",
  'image_pattern' => "Java::JavafxScenePaint::ImagePattern",
  'linear_gradient' => "Java::JavafxScenePaint::LinearGradient",
  'paint' => "Java::JavafxScenePaint::Paint",
  'radial_gradient' => "Java::JavafxScenePaint::RadialGradient",
  'stop' => "Java::JavafxScenePaint::Stop",
  'arc' => "Java::JavafxSceneShape::Arc",
  'arc_to' => "Java::JavafxSceneShape::ArcTo",
  'arc_type' => "Java::JavafxSceneShape::ArcType",
  'circle' => "Java::JavafxSceneShape::Circle",
  'close_path' => "Java::JavafxSceneShape::ClosePath",
  'cubic_curve' => "Java::JavafxSceneShape::CubicCurve",
  'cubic_curve_to' => "Java::JavafxSceneShape::CubicCurveTo",
  'ellipse' => "Java::JavafxSceneShape::Ellipse",
  'fill_rule' => "Java::JavafxSceneShape::FillRule",
  'hline_to' => "Java::JavafxSceneShape::HLineTo",
  'line' => "Java::JavafxSceneShape::Line",
  'line_to' => "Java::JavafxSceneShape::LineTo",
  'move_to' => "Java::JavafxSceneShape::MoveTo",
  'path' => "Java::JavafxSceneShape::Path",
  'path_element' => "Java::JavafxSceneShape::PathElement",
  'polygon' => "Java::JavafxSceneShape::Polygon",
  'polyline' => "Java::JavafxSceneShape::Polyline",
  'quad_curve' => "Java::JavafxSceneShape::QuadCurve",
  'quad_curve_to' => "Java::JavafxSceneShape::QuadCurveTo",
  'rectangle' => "Java::JavafxSceneShape::Rectangle",
  'shape' => "Java::JavafxSceneShape::Shape",
  'stroke_line_cap' => "Java::JavafxSceneShape::StrokeLineCap",
  'stroke_line_join' => "Java::JavafxSceneShape::StrokeLineJoin",
  'stroke_type' => "Java::JavafxSceneShape::StrokeType",
  'svg_path' => "Java::JavafxSceneShape::SVGPath",
  'vline_to' => "Java::JavafxSceneShape::VLineTo",
  'font' => "Java::JavafxSceneText::Font",
  'font_posture' => "Java::JavafxSceneText::FontPosture",
  'font_smoothing_type' => "Java::JavafxSceneText::FontSmoothingType",
  'font_weight' => "Java::JavafxSceneText::FontWeight",
  'text' => "Java::JavafxSceneText::Text",
  'text_alignment' => "Java::JavafxSceneText::TextAlignment",
  'text_bounds_type' => "Java::JavafxSceneText::TextBoundsType",
  'affine' => "Java::JavafxSceneTransform::Affine",
  'rotate' => "Java::JavafxSceneTransform::Rotate",
  'scale' => "Java::JavafxSceneTransform::Scale",
  'shear' => "Java::JavafxSceneTransform::Shear",
  'translate' => "Java::JavafxSceneTransform::Translate",
  'web_view' => "Java::JavafxSceneWeb::WebView",
  'html_editor' => "Java::JavafxSceneWeb::HTMLEditor",
  'directory_chooser' => "Java::JavafxStage::DirectoryChooser",
  'file_chooser' => "Java::JavafxStage::FileChooser",
  'modality' => "Java::JavafxStage::Modality",
  'popup' => "Java::JavafxStage::Popup",
  'popup_window' => "Java::JavafxStage::PopupWindow",
  'screen' => "Java::JavafxStage::Screen",
  'stage' => "Java::JavafxStage::Stage",
  'stage_style' => "Java::JavafxStage::StageStyle",
  'window' => "Java::JavafxStage::Window",
  'window_event' => "Java::JavafxStage::WindowEvent",
  'duration' => "Java::JavafxUtil::Duration",
}

Constants included from FXImports

FXImports::JFX_CLASS_HIERARCHY, FXImports::LOCAL_NAME_MAP

Constants included from JRubyFX

VERSION

Class Method Summary collapse

Instance Method Summary collapse

Methods included from FXImports

#const_missing

Methods included from JRubyFX

#build, load_fx, #run_later, #with

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.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/jrubyfx/dsl.rb', line 88

def method_missing(name, *args, &block)
  fixed_name = name.to_s.gsub(/!$/, '')
  clazz = NAME_TO_CLASSES[fixed_name]
  unless clazz
    clazz = NAME_TO_CLASS_NAME[fixed_name]
    clazz = (NAME_TO_CLASSES[fixed_name] = clazz.constantize_by("::")) if clazz
  end

  unless clazz
    @supers = {} unless @supers
    @supers[name] = 0 unless @supers.has_key?(name)
    @supers[name] += 1
    if @supers[name] > 3
      raise "Whoa! method_missing caught infinite loop. Trying to run #{name}(#{args.inspect}) failed. Method not found."
    end
    res = super
    @supers[name] -= 1
    return res
  end

  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.



326
327
328
# File 'lib/jrubyfx/dsl.rb', line 326

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



58
59
60
61
# File 'lib/jrubyfx/dsl.rb', line 58

def self.included(mod)
  mod.extend(JRubyFX::DSL::ClassUtils)
  mod.extend(JRubyFX::FXImports)
end

.load_dslObject

This loads the entire DSL. Call this immediately after requiring this file, but not inside this file, or it requires itself twice.



313
314
315
316
317
318
319
320
321
322
# File 'lib/jrubyfx/dsl.rb', line 313

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



278
279
280
281
282
283
284
285
286
287
# File 'lib/jrubyfx/dsl.rb', line 278

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



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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/jrubyfx/dsl.rb', line 115

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_CLASS_NAME.each do |n,clsz|
    cls = eval(clsz) # TODO: use constantize
    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_CLASS_NAME.each do |n,clsz|
    cls = eval(clsz) # TODO: use constantize
    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

  # cleanout and search for events. TODO: combind with previous
  mod_list = {:methods =>{}}
  JRubyFX::DSL::NAME_TO_CLASS_NAME.each do |n,clsz|
    cls = eval(clsz) # TODO: use constantize
    cls.java_class.java_instance_methods.each do |method|
      # one and only, must be a setter style
      if method.name.start_with? "setOn"  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_event_method 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(#{JRubyFX::DSL::NAME_TO_CLASS_NAME['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



267
268
269
270
271
272
273
274
275
276
# File 'lib/jrubyfx/dsl.rb', line 267

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

.write_event_method(outf, in_class, jfuncnclasses) ⇒ Object



252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/jrubyfx/dsl.rb', line 252

def self.write_event_method(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}(&block)
if block_given?
  #{jfunc.to_s} block
else
  #{jfunc.to_s.gsub(/^set/i,'get')}
end
  end
ENDNAIVE
  end
end

Instance Method Details

#logical_lookup(*args) ⇒ Object



299
300
301
302
303
304
305
306
307
308
309
# File 'lib/jrubyfx/dsl.rb', line 299

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



289
290
291
292
293
294
295
296
297
# File 'lib/jrubyfx/dsl.rb', line 289

def self_test_lookup(selector)
  if selector.start_with? "#"
    return (if "##{self.id}" == selector
        self
      else
        nil
      end)
  end
end