Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions Notes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# What is this?
This document explains the extra syntactic sugar JRubyFX applies to JavaFX. All Java-style versions always work, this is just special ruby versions of the syntax.

# Enums and constants (including Color)
All JavaFX enums and some constants can be specified as a ruby symbol in setters and constructors. This includes most usages of `Color`.
If you have a constant or enum that is not being converted to a Java enum properly (easy to spot because of `Exception running Application: #<TypeError: cannot convert instance of class org.jruby.RubySymbol to _CLASS_TYPE_>`), it is proabbly a bug and please report it. Note that you must use either the `build` family of functions (`build`, `with`, and DSL _class_type_()), or the snake_cased= version of the setter. setProperty is not overridden in case you want to avoid conversions.

### Example
The following two lines are equivilent

stage.init_style = :transparent

stage.init_style = StageStyle::TRANSPARENT

Some Non-enum constants also work:

timeline.cycle_count = :indefinite

# Duration
Any duration can be specified the java way (`Duration.millis(500)`) or with the monkey-patched Number class:

500.ms # => Duration.millis(500)
2.sec # => Duration.seconds(2)
20.min # => Duration.minutes(20)
24.hrs # => Duration.hours(24)
1.hr # => Duration.hours(1)

# Animation
There are three types of animation syntaxes: Java style, multiple style, and single style. Java style is just java, use google for examples.

### Single Style
Animate is a method on the timeline:

rectangle(x: 10, y: 40, width: 50, height: 50, fill: :red) do
# note we must save this here as the property is
# on the rectangle, not the timeline
translate_x = translateXProperty
timeline(cycle_count: :indefinite, auto_reverse: true) do
# animates given property for given timeline
# marks, over given values
animate translate_x, 0.sec => 1.sec, 0 => 200
end.play # play immediatly
end

### Multiple Style
This is for creating actual transition objects:

transition = parallel_transition(:node => self) do
rotate_transition(duration: 5.sec, angle: {0 => 360})
fade_transition(duration: 5.sec, value: {0.0 => 1.0})
scale_transition(duration: 5.sec, x: {0.0 => 1.0}, y: {0.0 => 1.0})
end

Some classes are probbably missing this, please report this.

# Builder methods
Many classes have automatic adding of children, like Panels and Timelines. To utilize, create the object inside one of the builders (build, with, or the DSL _class_name_). See the analog_clock example for details.

11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ The syntax of the FXML side of JRubyFX should be fairly stable, but the JavaFX D
At this point in time, no custom ruby controls are supported from FXML, though you
can certainly create them in code.

Build
Install
-----
```text
gem install jrubyfx
```

Manual Build and Install
-----
Build is done using rake/gem/bundler/rdoc. You obviously need JRuby, Java 1.7 (with JavaFX) also.

Expand Down Expand Up @@ -61,7 +67,7 @@ Require the 'jrubyfx' file/gem, and subclass JRubyFX::Application (and JRubyFX::
At the bottom of the file, call _yourFXApplicationClass_.launch().
Override start(stage) in the application. See samples/fxml/Demo.rb for commented FXML example,
or the fils in samples/javafx for non-FXML (programatic JavaFX, but you should really
look into FXML, its better) or see the Getting Started Guide.
look into FXML, its better) or see the Getting Started Guide and the Notes.

If you want rdoc, run `rake rdoc`.

Expand All @@ -74,6 +80,7 @@ Issues
as above.
* Errors loading jfxrt.jar are bugs. Please report if you encounter this issue, tell us your platform,
OS, and version of JRuby
* Jarify command needs the `jar` executable in your path.
* Any other difficulties are bugs. Please report them

License
Expand Down
41 changes: 41 additions & 0 deletions lib/jrubyfx/core_ext/column_constraints.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
=begin
JRubyFX - Write JavaFX and FXML in Ruby
Copyright (C) 2013 The JRubyFX Team

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=end
# JRubyFX DSL extensions for JavaFX Column Constraints
class Java::javafx::scene::layout::ColumnConstraints
extend JRubyFX::Utils::CommonConverters

constrain = map_converter(constrain_to_pref: CONSTRAIN_TO_PREF,
constrain: CONSTRAIN_TO_PREF,
pref: CONSTRAIN_TO_PREF,
preferred: CONSTRAIN_TO_PREF)

converter_for :new, [], [:none], [:none, :none, constrain], [:none, :none, constrain, :none, :none, :none]

end

# JRubyFX DSL extensions for JavaFX Row Constraints
class Java::javafx::scene::layout::RowConstraints
extend JRubyFX::Utils::CommonConverters

constrain = map_converter(constrain_to_pref: CONSTRAIN_TO_PREF,
constrain: CONSTRAIN_TO_PREF,
pref: CONSTRAIN_TO_PREF,
preferred: CONSTRAIN_TO_PREF)

converter_for :new, [], [:none], [:none, :none, constrain], [:none, :none, constrain, :none, :none, :none]

end
30 changes: 30 additions & 0 deletions lib/jrubyfx/core_ext/effects.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
=begin
JRubyFX - Write JavaFX and FXML in Ruby
Copyright (C) 2013 The JRubyFX Team

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=end
# JRubyFX DSL extensions for JavaFX drop shadows
class Java::javafx::scene::effect::DropShadow
extend JRubyFX::Utils::CommonConverters

converter_for :color, [:color]

class << self
extend JRubyFX::Utils::CommonConverters

converter_for :new, [], [:none, :color], [:none, :none, :none, :color],
[enum_converter(Java::javafx::scene::effect::BlurType), :color, :none, :none, :none, :none]
end

end
23 changes: 23 additions & 0 deletions lib/jrubyfx/core_ext/media_player.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
=begin
JRubyFX - Write JavaFX and FXML in Ruby
Copyright (C) 2013 The JRubyFX Team

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=end
# JRubyFX DSL extensions for JavaFX color stops
class Java::javafx::scene::media::MediaPlayer
extend JRubyFX::Utils::CommonConverters

converter_for :cycle_count, [map_converter(indefinite: INDEFINITE)]

end
26 changes: 26 additions & 0 deletions lib/jrubyfx/core_ext/pagination.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
=begin
JRubyFX - Write JavaFX and FXML in Ruby
Copyright (C) 2013 The JRubyFX Team

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=end
# JRubyFX DSL extensions for JavaFX Progress *
class Java::javafx::scene::control::Pagination
extend JRubyFX::Utils::CommonConverters

indeterm_map = map_converter(indeterminate: INDETERMINATE)

converter_for :page_count, [indeterm_map]
converter_for :new, [], [indeterm_map], [indeterm_map, :none]

end
38 changes: 38 additions & 0 deletions lib/jrubyfx/core_ext/progress_indicator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
=begin
JRubyFX - Write JavaFX and FXML in Ruby
Copyright (C) 2013 The JRubyFX Team

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=end
# JRubyFX DSL extensions for JavaFX Progress *
class Java::javafx::scene::control::ProgressIndicator
extend JRubyFX::Utils::CommonConverters

progress_conv = map_converter(indeterminate_progress: INDETERMINATE_PROGRESS,
indeterminate: INDETERMINATE_PROGRESS)

converter_for :progress, [progress_conv]
converter_for :new, [], [progress_conv]

end
# JRubyFX DSL extensions for JavaFX Progress *
class Java::javafx::scene::control::ProgressBar
extend JRubyFX::Utils::CommonConverters

progress_conv = map_converter(indeterminate_progress: INDETERMINATE_PROGRESS,
indeterminate: INDETERMINATE_PROGRESS)

converter_for :progress, [progress_conv]
converter_for :new, [], [progress_conv]

end
10 changes: 10 additions & 0 deletions lib/jrubyfx/core_ext/radial_gradient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ class << self
converter_for :new, [:none, :none, :none, :none, :none, :none, enum_converter(CycleMethod), :none]
end
end

# JRubyFX DSL extensions for JavaFX Linear Gradients
class Java::javafx::scene::paint::LinearGradient
class << self
java_import Java::javafx.scene.paint.CycleMethod
extend JRubyFX::Utils::CommonConverters

converter_for :new, [:none, :none, :none, :none, :none, enum_converter(CycleMethod), :none]
end
end
39 changes: 39 additions & 0 deletions lib/jrubyfx/core_ext/region.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
=begin
JRubyFX - Write JavaFX and FXML in Ruby
Copyright (C) 2013 The JRubyFX Team

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=end
# JRubyFX DSL extensions for JavaFX color stops
class Java::javafx::scene::layout::Region
extend JRubyFX::Utils::CommonConverters

use_sizes = map_converter(use_pref_size: USE_PREF_SIZE,
use_computed_size: USE_COMPUTED_SIZE,
pref_size: USE_PREF_SIZE,
computed_size: USE_COMPUTED_SIZE,
preferred_size: USE_PREF_SIZE,
compute_size: USE_COMPUTED_SIZE,
pref: USE_PREF_SIZE,
computed: USE_COMPUTED_SIZE,
preferred: USE_PREF_SIZE,
compute: USE_COMPUTED_SIZE)

converter_for :min_width, [use_sizes]
converter_for :min_height, [use_sizes]
converter_for :pref_width, [use_sizes]
converter_for :pref_height, [use_sizes]
converter_for :max_width, [use_sizes]
converter_for :max_height, [use_sizes]

end
37 changes: 37 additions & 0 deletions lib/jrubyfx/core_ext/rotate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
=begin
JRubyFX - Write JavaFX and FXML in Ruby
Copyright (C) 2013 The JRubyFX Team

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
=end
# JRubyFX DSL extensions for JavaFX color stops
class Java::javafx::scene::transform::Rotate
extend JRubyFX::Utils::CommonConverters

@@axis_conversions = map_converter(x_axis: X_AXIS,
y_axis: Y_AXIS,
z_axis: Z_AXIS,
x: X_AXIS,
y: Y_AXIS,
z: Z_AXIS)

converter_for :axis, [@@axis_conversions]

class << self
extend JRubyFX::Utils::CommonConverters

converter_for :new, [], [:none], [:none, @axis_conversions], [:none, :none, :none],
[:none, :none, :none, :none], [:none, :none, :none, :none, @axis_conversions]
end

end
8 changes: 8 additions & 0 deletions lib/jrubyfx/core_ext/table_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ class Java::javafx::scene::control::TableView
java_import Java::javafx.scene.control.TableColumn

include JRubyFX::DSL
extend JRubyFX::Utils::CommonConverters

include_add :get_columns
include_method_missing TableColumn

resize_policy = map_converter(unconstrained_resize_policy: UNCONSTRAINED_RESIZE_POLICY,
constrained_resize_policy: CONSTRAINED_RESIZE_POLICY,
unconstrained: UNCONSTRAINED_RESIZE_POLICY,
constrained: CONSTRAINED_RESIZE_POLICY)

converter_for :column_resize_policy, [resize_policy]
end
11 changes: 4 additions & 7 deletions lib/jrubyfx/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,11 @@ def self.inject_enum_method_converter(jfunc, in_class)
# This loads the entire DSL. Call this immediately after requiring
# this file, but not inside this file, or it requires itself twice.
def self.load_dsl
# we must load it AFTER we finish declaring the DSL class
# This loads all custom DSL overrides that exist
JRubyFX::DSL::NAME_TO_CLASSES.each do |name, cls|
require_relative "core_ext/#{name}" if File.exists? "#{File.dirname(__FILE__)}/core_ext/#{name}.rb"
rt = "#{File.dirname(__FILE__)}/core_ext/"
Dir.foreach rt do |file|
require_relative "core_ext/#{file}" unless [".", ".."].include? file
end
# observable_value is not in the list, so include it manually
require_relative 'core_ext/observable_value'


JRubyFX::DSL.load_enum_converter()
end
end
Expand Down
Loading