jrubyfx 1.1.0-java → 2.0.0-java

Sign up to get free protection for your applications and to get access to all the features.
@@ -17,6 +17,7 @@ limitations under the License.
17
17
 
18
18
  require_relative 'utils/common_utils'
19
19
 
20
+
20
21
  # This module contains useful methods for defining JavaFX code. Include it in your
21
22
  # class to use it, and the JRubyFX::FXImports. JRubyFX::Application and JRubyFX::Controller already include it.
22
23
  module JRubyFX
@@ -116,15 +117,20 @@ module JRubyFX
116
117
  end
117
118
  camel = symbol_name.id2name
118
119
  camel = camel[0].upcase + camel[1..-1]
120
+ jcn = type.java_class.name
121
+ java_signature "void set" + camel + "(#{jcn} f)"
119
122
  send(:define_method, "set" + camel) do |val|
120
123
  instance_variable_set("@#{symbol_name}", val)
121
124
  end
125
+ java_signature "#{jcn} get" + camel + "()"
122
126
  send(:define_method, "get" + camel) do
123
127
  instance_variable_get("@#{symbol_name}")
124
128
  end
129
+ java_signature "java.lang.Class " + symbol_name.id2name + "GetType()"
125
130
  send(:define_method, symbol_name.id2name + "GetType") do
126
131
  return type.java_class
127
132
  end
133
+ java_field "@javafx.fxml.FXML #{type.java_class.name} #{symbol_name}", instance_variable: true
128
134
  end
129
135
  def fxml_accessor(symbol_name,ptype=Java::javafx.beans.property.SimpleStringProperty, type=nil)
130
136
  # TODO: RDoc
@@ -167,9 +173,34 @@ module JRubyFX
167
173
  end
168
174
  return instance_variable_get("@#{symbol_name}")
169
175
  end
176
+ send(:define_method, pname.snake_case) do
177
+ send(pname)
178
+ end
170
179
  add_method_signature pname, [ptype]
171
180
  add_method_signature "set" + camel, [java.lang.Void, type]
172
181
  add_method_signature "get" + camel, [type]
173
182
  end
174
183
  end
184
+
185
+ # FXML requires loading both ruby and java classes.
186
+ # JRuby has no such single classloader builtin, so we proxy them all
187
+ # This is a minimal classloader only for classes, resources not supported
188
+ class PolyglotClassLoader < java.lang.ClassLoader
189
+ def initialize()
190
+ super(JRuby.runtime.jruby_class_loader)
191
+ @prefix = File.basename(fxml_root) + "."
192
+ end
193
+ java_signature "java.lang.Class findClass(java.lang.String name)"
194
+ def findClass(a)
195
+ return nil unless a.start_with? @prefix or a[0].upcase == a[0]
196
+ a = a[@prefix.length..-1] unless a[0].upcase == a[0]
197
+ begin # TODO: become_java! idempotent?
198
+ return a.constantize_by(/[.$]/).tap{|x| x.become_java!}.java_class
199
+ rescue NameError
200
+ raise java.lang.ClassNotFoundException.new("Could not find Ruby or Java class '#{a.gsub(/[.$]/, "::")}' or '#{a}'") # Must be a java CNF, not a Ruby Name Error
201
+ end
202
+ end
203
+ become_java!
204
+ end
205
+
175
206
  end
@@ -21,28 +21,27 @@ require_relative 'utils'
21
21
  begin
22
22
  if ENV['JFX_DIR']
23
23
  $LOAD_PATH << ENV['JFX_DIR']
24
- else #should we check for 1.7 vs 1.8? oh well, adding extra paths won't hurt anybody (maybe performance loading)
25
- jfx_path = ENV_JAVA["sun.boot.library.path"]
26
- $LOAD_PATH << if jfx_path.include? ":\\" and !jfx_path.include? "/" # can be tricked, but should work fine
27
- #windows
28
- jfx_path.gsub(/\\bin[\\]*$/i, "\\lib")
29
- else
30
- # *nix
31
- jfx_path.gsub(/[\/\\][amdix345678_]+$/, "") # strip i386 or amd64 (including variants). TODO: ARM
24
+ end
25
+
26
+ # add OpenJFX support if follow instruction from https://openjfx.io
27
+ if ENV['JFX_DIR']
28
+ require 'jfxrt.jar'
29
+ elsif ENV['PATH_TO_FX'] # support the OpenJFX installation as in https://openjfx.io/openjfx-docs/#install-javafx as of 15th May 2020
30
+ Dir.glob(File.join(ENV['PATH_TO_FX'],"*.jar")).each do |jar|
31
+ require jar
32
32
  end
33
33
  end
34
34
 
35
- # Java 8 (after ea-b75) and above has JavaFX as part of the normal distib, only require it if we are 7 or below
36
- jre = ENV_JAVA["java.runtime.version"].match %r{^(?<version>(?<major>\d+)\.(?<minor>\d+))\.(?<patch>\d+)(_\d+)?-?(?<release>ea|u\d)?(-?b(?<build>\d+))?}
37
- require 'jfxrt.jar' if ENV['JFX_DIR'] or
38
- jre[:version].to_f < 1.8 or
39
- (jre[:version].to_f == 1.8 and jre[:release] == 'ea' and jre[:build].to_i < 75)
40
-
35
+ # Java 8 at some point requires explicit toolkit/platform initialization
36
+ # before any controls can be loaded.
37
+ JRubyFX.load_fx
38
+
41
39
  # Attempt to load a javafx class
42
40
  Java.javafx.application.Application
43
41
  rescue LoadError, NameError
44
- puts "JavaFX runtime not found. Please install Java 7u6 or newer or set environment variable JFX_DIR to the folder that contains jfxrt.jar "
45
- puts "If you have Java 7u6 or later, this is a bug. Please report to the issue tracker on github. Include your OS version, 32/64bit, and architecture (x86, ARM, PPC, etc)"
42
+ # Advice user too about the OpenJFX support
43
+ puts "JavaFX runtime not found. Please install Java 8 or newer, set environment variable JFX_DIR to the folder that contains jfxrt.jar or set the environment variable PATH_TO_FX that points to the OpenJFX libraries"
44
+ puts "If you have Java 8 or later, this is a bug. Please report to the issue tracker on github. Include your OS version, 32/64bit, and architecture (x86, ARM, PPC, etc)"
46
45
  exit -1
47
46
  end
48
47
 
@@ -63,49 +62,65 @@ module JRubyFX
63
62
  # classes by using either `Hash.flat_tree_inject` from jrubyfx/utils.rb or
64
63
  # writing your own traversal function
65
64
  #
66
- JFX_CLASS_HIERARCHY = { :javafx => {
67
- :animation => %w[Animation AnimationTimer FadeTransition FillTransition Interpolator KeyFrame KeyValue ParallelTransition PathTransition
68
- PauseTransition RotateTransition ScaleTransition SequentialTransition StrokeTransition Timeline Transition TranslateTransition],
69
- :application => ['Platform'],
65
+ JFX_CLASS_HIERARCHY = {
66
+ :javafx => {
67
+ :animation => %w[Animation AnimationTimer FadeTransition FillTransition Interpolatable Interpolator KeyFrame KeyValue ParallelTransition PathTransition PauseTransition RotateTransition ScaleTransition SequentialTransition StrokeTransition Timeline Transition TranslateTransition],
68
+ :application => %w[Application ConditionalFeature HostServices Platform Preloader],
70
69
  :beans => {
71
- :property => %w[SimpleBooleanProperty SimpleDoubleProperty SimpleFloatProperty SimpleIntegerProperty SimpleListProperty SimpleLongProperty SimpleMapProperty SimpleObjectProperty SimpleSetProperty SimpleStringProperty],
72
- #TODO: import more
73
- :value => ['ChangeListener']
70
+ :binding => %w[Binding Bindings BooleanBinding BooleanExpression DoubleBinding DoubleExpression FloatBinding FloatExpression IntegerBinding IntegerExpression ListBinding ListExpression LongBinding LongExpression MapBinding MapExpression NumberBinding NumberExpression NumberExpressionBase ObjectBinding ObjectExpression SetBinding SetExpression StringBinding StringExpression When],
71
+ '' => %w[DefaultProperty InvalidationListener NamedArg Observable WeakInvalidationListener WeakListener],
72
+ :property => {
73
+ :adapter => %w[JavaBeanBooleanProperty JavaBeanBooleanPropertyBuilder JavaBeanDoubleProperty JavaBeanDoublePropertyBuilder JavaBeanFloatProperty JavaBeanFloatPropertyBuilder JavaBeanIntegerProperty JavaBeanIntegerPropertyBuilder JavaBeanLongProperty JavaBeanLongPropertyBuilder JavaBeanObjectProperty JavaBeanObjectPropertyBuilder JavaBeanProperty JavaBeanStringProperty JavaBeanStringPropertyBuilder ReadOnlyJavaBeanBooleanProperty ReadOnlyJavaBeanBooleanPropertyBuilder ReadOnlyJavaBeanDoubleProperty ReadOnlyJavaBeanDoublePropertyBuilder ReadOnlyJavaBeanFloatProperty ReadOnlyJavaBeanFloatPropertyBuilder ReadOnlyJavaBeanIntegerProperty ReadOnlyJavaBeanIntegerPropertyBuilder ReadOnlyJavaBeanLongProperty ReadOnlyJavaBeanLongPropertyBuilder ReadOnlyJavaBeanObjectProperty ReadOnlyJavaBeanObjectPropertyBuilder ReadOnlyJavaBeanProperty ReadOnlyJavaBeanStringProperty ReadOnlyJavaBeanStringPropertyBuilder],
74
+ '' => %w[BooleanProperty BooleanPropertyBase DoubleProperty DoublePropertyBase FloatProperty FloatPropertyBase IntegerProperty IntegerPropertyBase ListProperty ListPropertyBase LongProperty LongPropertyBase MapProperty MapPropertyBase ObjectProperty ObjectPropertyBase Property ReadOnlyBooleanProperty ReadOnlyBooleanPropertyBase ReadOnlyBooleanWrapper ReadOnlyDoubleProperty ReadOnlyDoublePropertyBase ReadOnlyDoubleWrapper ReadOnlyFloatProperty ReadOnlyFloatPropertyBase ReadOnlyFloatWrapper ReadOnlyIntegerProperty ReadOnlyIntegerPropertyBase ReadOnlyIntegerWrapper ReadOnlyListProperty ReadOnlyListPropertyBase ReadOnlyListWrapper ReadOnlyLongProperty ReadOnlyLongPropertyBase ReadOnlyLongWrapper ReadOnlyMapProperty ReadOnlyMapPropertyBase ReadOnlyMapWrapper ReadOnlyObjectProperty ReadOnlyObjectPropertyBase ReadOnlyObjectWrapper ReadOnlyProperty ReadOnlySetProperty ReadOnlySetPropertyBase ReadOnlySetWrapper ReadOnlyStringProperty ReadOnlyStringPropertyBase ReadOnlyStringWrapper SetProperty SetPropertyBase SimpleBooleanProperty SimpleDoubleProperty SimpleFloatProperty SimpleIntegerProperty SimpleListProperty SimpleLongProperty SimpleMapProperty SimpleObjectProperty SimpleSetProperty SimpleStringProperty StringProperty StringPropertyBase],
75
+ },
76
+ :value => %w[ChangeListener ObservableBooleanValue ObservableDoubleValue ObservableFloatValue ObservableIntegerValue ObservableListValue ObservableLongValue ObservableMapValue ObservableNumberValue ObservableObjectValue ObservableSetValue ObservableStringValue ObservableValue ObservableValueBase WeakChangeListener WritableBooleanValue WritableDoubleValue WritableFloatValue WritableIntegerValue WritableListValue WritableLongValue WritableMapValue WritableNumberValue WritableObjectValue WritableSetValue WritableStringValue WritableValue],
77
+ },
78
+ :collections => {
79
+ '' => %w[ArrayChangeListener FXCollections ListChangeListener MapChangeListener ModifiableObservableListBase ObservableArray ObservableArrayBase ObservableFloatArray ObservableIntegerArray ObservableList ObservableListBase ObservableMap ObservableSet SetChangeListener WeakListChangeListener WeakMapChangeListener WeakSetChangeListener],
80
+ :transformation => %w[FilteredList SortedList TransformationList],
74
81
  },
75
- :collections => ['FXCollections'],
76
- :concurrent => %w[Worker Task Service],
77
- :event => %w[Event ActionEvent EventHandler],
78
- :fxml => ['Initializable', 'LoadException'],
79
- :geometry => %w[HorizontalDirection HPos Insets Orientation Pos Rectangle2D Side VerticalDirection VPos],
82
+ :concurrent => %w[ScheduledService Service Task Worker WorkerStateEvent],
83
+ :css => {
84
+ '' => %w[CompoundSelector CssMetaData CssParser Declaration FontCssMetaData FontFace Match ParsedValue PseudoClass Rule Selector SimpleSelector SimpleStyleableBooleanProperty SimpleStyleableDoubleProperty SimpleStyleableFloatProperty SimpleStyleableIntegerProperty SimpleStyleableLongProperty SimpleStyleableObjectProperty SimpleStyleableStringProperty Size SizeUnits Style Styleable StyleableBooleanProperty StyleableDoubleProperty StyleableFloatProperty StyleableIntegerProperty StyleableLongProperty StyleableObjectProperty StyleableProperty StyleablePropertyFactory StyleableStringProperty StyleClass StyleConverter StyleOrigin Stylesheet],
85
+ :converter => %w[BooleanConverter ColorConverter CursorConverter DeriveColorConverter DeriveSizeConverter DurationConverter EffectConverter EnumConverter FontConverter InsetsConverter LadderConverter PaintConverter ShapeConverter SizeConverter StopConverter URLConverter],
86
+ },
87
+ :embed => {
88
+ :swing => %w[JFXPanel SwingFXUtils SwingNode],
89
+ },
90
+ :event => %w[ActionEvent Event EventDispatchChain EventDispatcher EventHandler EventTarget EventType WeakEventHandler],
91
+ :fxml => %w[FXML FXMLLoader Initializable JavaFXBuilderFactory LoadException LoadListener],
92
+ :geometry => %w[BoundingBox Bounds Dimension2D HorizontalDirection HPos Insets NodeOrientation Orientation Point2D Point3D Pos Rectangle2D Side VerticalDirection VPos],
93
+ :print => %w[Collation JobSettings PageLayout PageOrientation PageRange Paper PaperSource PrintColor Printer PrinterAttributes PrinterJob PrintQuality PrintResolution PrintSides],
80
94
  :scene => {
81
- '' => %w[Group Node Parent Scene],
82
- :canvas => ['Canvas'],
83
- :chart => %w[AreaChart Axis BarChart BubbleChart CategoryAxis Chart LineChart NumberAxis
84
- PieChart ScatterChart StackedAreaChart StackedBarChart ValueAxis XYChart],
85
- :control => %w[Accordion Button Cell CheckBox CheckBoxTreeItem CheckMenuItem ChoiceBox ColorPicker ComboBox ContextMenu Hyperlink
86
- Label ListCell ListView Menu MenuBar MenuButton MenuItem Pagination PasswordField PopupControl ProgressBar ProgressIndicator RadioButton
87
- RadioMenuItem ScrollBar ScrollPane Separator SeparatorMenuItem Slider SplitMenuButton SplitPane Tab TableView TableCell TableColumn TabPane TextArea
88
- TextField TitledPane ToggleButton ToggleGroup ToolBar Tooltip TreeCell TreeItem TreeView ContentDisplay OverrunStyle SelectionMode],
89
- :effect => %w[Blend BlendMode Bloom BlurType BoxBlur ColorAdjust ColorInput DisplacementMap DropShadow GaussianBlur Glow ImageInput
90
- InnerShadow Lighting MotionBlur PerspectiveTransform Reflection SepiaTone Shadow],
91
- :image => %w[Image ImageView PixelReader PixelWriter],
92
- :input => %w[Clipboard ClipboardContent ContextMenuEvent DragEvent GestureEvent InputEvent InputMethodEvent KeyCode KeyEvent
93
- Mnemonic MouseDragEvent MouseEvent RotateEvent ScrollEvent SwipeEvent TouchEvent TransferMode ZoomEvent],
94
- :layout => %w[AnchorPane BorderPane ColumnConstraints FlowPane GridPane HBox Pane Priority RowConstraints StackPane TilePane VBox],
95
- :media => %w[AudioClip AudioEqualizer AudioTrack EqualizerBand Media MediaException
96
- MediaErrorEvent MediaMarkerEvent MediaPlayer MediaView VideoTrack],
97
- :paint => %w[Color CycleMethod ImagePattern LinearGradient Paint RadialGradient Stop],
98
- :shape => %w[Arc ArcTo ArcType Circle ClosePath CubicCurve CubicCurveTo Ellipse FillRule HLineTo Line LineTo MoveTo Path PathElement
99
- Polygon Polyline QuadCurve QuadCurveTo Rectangle Shape StrokeLineCap StrokeLineJoin StrokeType SVGPath VLineTo],
100
- :text => %w[Font FontPosture FontSmoothingType FontWeight Text TextAlignment TextBoundsType],
101
- :transform => %w[Affine Rotate Scale Shear Translate],
102
- :web => ['WebView', 'HTMLEditor']
95
+ '' => %w[AccessibleAction AccessibleAttribute AccessibleRole AmbientLight CacheHint Camera Cursor DepthTest Group ImageCursor LightBase Node ParallelCamera Parent PerspectiveCamera PointLight Scene SceneAntialiasing SnapshotParameters SnapshotResult SubScene],
96
+ :canvas => %w[Canvas GraphicsContext],
97
+ :chart => %w[AreaChart Axis BarChart BubbleChart CategoryAxis Chart LineChart NumberAxis PieChart ScatterChart StackedAreaChart StackedBarChart ValueAxis XYChart],
98
+ :control => {
99
+ '' => %w[Accordion Alert Button ButtonBar ButtonBase ButtonType Cell CheckBox CheckBoxTreeItem CheckMenuItem ChoiceBox ChoiceDialog ColorPicker ComboBox ComboBoxBase ContentDisplay ContextMenu Control CustomMenuItem DateCell DatePicker Dialog DialogEvent DialogPane FocusModel Hyperlink IndexedCell IndexRange Label Labeled ListCell ListView Menu MenuBar MenuButton MenuItem MultipleSelectionModel OverrunStyle Pagination PasswordField PopupControl ProgressBar ProgressIndicator RadioButton RadioMenuItem ResizeFeaturesBase ScrollBar ScrollPane ScrollToEvent SelectionMode SelectionModel Separator SeparatorMenuItem SingleSelectionModel Skin SkinBase Skinnable Slider SortEvent Spinner SpinnerValueFactory SplitMenuButton SplitPane Tab TableCell TableColumn TableColumnBase TableFocusModel TablePosition TablePositionBase TableRow TableSelectionModel TableView TabPane TextArea TextField TextFormatter TextInputControl TextInputDialog TitledPane Toggle ToggleButton ToggleGroup ToolBar Tooltip TreeCell TreeItem TreeSortMode TreeTableCell TreeTableColumn TreeTablePosition TreeTableRow TreeTableView TreeView],
100
+ :cell => %w[CheckBoxListCell CheckBoxTableCell CheckBoxTreeCell CheckBoxTreeTableCell ChoiceBoxListCell ChoiceBoxTableCell ChoiceBoxTreeCell ChoiceBoxTreeTableCell ComboBoxListCell ComboBoxTableCell ComboBoxTreeCell ComboBoxTreeTableCell MapValueFactory ProgressBarTableCell ProgressBarTreeTableCell PropertyValueFactory TextFieldListCell TextFieldTableCell TextFieldTreeCell TextFieldTreeTableCell TreeItemPropertyValueFactory],
101
+ :skin => %w[AccordionSkin ButtonBarSkin ButtonSkin CellSkinBase CheckBoxSkin ChoiceBoxSkin ColorPickerSkin ComboBoxBaseSkin ComboBoxListViewSkin ComboBoxPopupControl ContextMenuSkin DateCellSkin DatePickerSkin HyperlinkSkin LabeledSkinBase LabelSkin ListCellSkin ListViewSkin MenuBarSkin MenuButtonSkin MenuButtonSkinBase NestedTableColumnHeader PaginationSkin ProgressBarSkin ProgressIndicatorSkin RadioButtonSkin ScrollBarSkin ScrollPaneSkin SeparatorSkin SliderSkin SpinnerSkin SplitMenuButtonSkin SplitPaneSkin TableCellSkin TableCellSkinBase TableColumnHeader TableHeaderRow TableRowSkin TableRowSkinBase TableViewSkin TableViewSkinBase TabPaneSkin TextAreaSkin TextFieldSkin TextInputControlSkin TitledPaneSkin ToggleButtonSkin ToolBarSkin TooltipSkin TreeCellSkin TreeTableCellSkin TreeTableRowSkin TreeTableViewSkin TreeViewSkin VirtualContainerBase VirtualFlow],
102
+ },
103
+ :effect => %w[Blend BlendMode Bloom BlurType BoxBlur ColorAdjust ColorInput DisplacementMap DropShadow Effect FloatMap GaussianBlur Glow ImageInput InnerShadow Light Lighting MotionBlur PerspectiveTransform Reflection SepiaTone Shadow],
104
+ :image => %w[Image ImageView PixelFormat PixelReader PixelWriter WritableImage WritablePixelFormat],
105
+ :input => %w[Clipboard ClipboardContent ContextMenuEvent DataFormat Dragboard DragEvent GestureEvent InputEvent InputMethodEvent InputMethodHighlight InputMethodRequests InputMethodTextRun KeyCharacterCombination KeyCode KeyCodeCombination KeyCombination KeyEvent Mnemonic MouseButton MouseDragEvent MouseEvent PickResult RotateEvent ScrollEvent SwipeEvent TouchEvent TouchPoint TransferMode ZoomEvent],
106
+ :layout => %w[AnchorPane Background BackgroundFill BackgroundImage BackgroundPosition BackgroundRepeat BackgroundSize Border BorderImage BorderPane BorderRepeat BorderStroke BorderStrokeStyle BorderWidths ColumnConstraints ConstraintsBase CornerRadii FlowPane GridPane HBox Pane Priority Region RowConstraints StackPane TilePane VBox],
107
+ :media => %w[AudioClip AudioEqualizer AudioSpectrumListener AudioTrack EqualizerBand Media MediaErrorEvent MediaException MediaMarkerEvent MediaPlayer MediaView SubtitleTrack Track VideoTrack],
108
+ :paint => %w[Color CycleMethod ImagePattern LinearGradient Material Paint PhongMaterial RadialGradient Stop],
109
+ :robot => %w[Robot],
110
+ :shape => %w[Arc ArcTo ArcType Box Circle ClosePath CubicCurve CubicCurveTo CullFace Cylinder DrawMode Ellipse FillRule HLineTo Line LineTo Mesh MeshView MoveTo ObservableFaceArray Path PathElement Polygon Polyline QuadCurve QuadCurveTo Rectangle Shape Shape3D Sphere StrokeLineCap StrokeLineJoin StrokeType SVGPath TriangleMesh VertexFormat VLineTo],
111
+ :text => %w[Font FontPosture FontSmoothingType FontWeight HitInfo Text TextAlignment TextBoundsType TextFlow],
112
+ :transform => %w[Affine MatrixType NonInvertibleTransformException Rotate Scale Shear Transform TransformChangedEvent Translate],
113
+ :web => %w[HTMLEditor HTMLEditorSkin PopupFeatures PromptData WebEngine WebErrorEvent WebEvent WebHistory WebView],
103
114
  },
104
115
  :stage => %w[DirectoryChooser FileChooser Modality Popup PopupWindow Screen Stage StageStyle Window WindowEvent],
105
- :util => ['Duration']
106
- }
116
+ :util => {
117
+ '' => %w[Builder BuilderFactory Callback Duration FXPermission Pair StringConverter],
118
+ :converter => %w[BigDecimalStringConverter BigIntegerStringConverter BooleanStringConverter ByteStringConverter CharacterStringConverter CurrencyStringConverter DateStringConverter DateTimeStringConverter DefaultStringConverter DoubleStringConverter FloatStringConverter FormatStringConverter IntegerStringConverter LocalDateStringConverter LocalDateTimeStringConverter LocalTimeStringConverter LongStringConverter NumberStringConverter PercentageStringConverter ShortStringConverter TimeStringConverter],
119
+ },
120
+ },
107
121
  }
108
122
 
123
+
109
124
  $WRITE_OUT << <<HERE
110
125
  def const_missing(c)
111
126
  if LOCAL_NAME_MAP.has_key? c
@@ -140,6 +140,9 @@ module JRubyFX
140
140
  },
141
141
  :color => lambda { |value|
142
142
  new_value = NAME_TO_COLORS[value.to_s.gsub(/_/, "")]
143
+ if !new_value && value.kind_of?(Symbol)
144
+ raise ArgumentError.new("No such color: #{value.to_s}")
145
+ end
143
146
  new_value ? new_value : value
144
147
  },
145
148
  :rectangle2d => lambda { |value|
@@ -0,0 +1,48 @@
1
+ class String
2
+
3
+ # steal handy methods from activesupport
4
+ # Tries to find a constant with the name specified in the argument string.
5
+ #
6
+ # 'Module'.constantize # => Module
7
+ # 'Test::Unit'.constantize # => Test::Unit
8
+ #
9
+ # The name is assumed to be the one of a top-level constant, no matter
10
+ # whether it starts with "::" or not. No lexical context is taken into
11
+ # account:
12
+ #
13
+ # C = 'outside'
14
+ # module M
15
+ # C = 'inside'
16
+ # C # => 'inside'
17
+ # 'C'.constantize # => 'outside', same as ::C
18
+ # end
19
+ #
20
+ # NameError is raised when the name is not in CamelCase or the constant is
21
+ # unknown.
22
+ def constantize_by(splitter="::")
23
+ camel_cased_word = self
24
+ names = camel_cased_word.split(splitter)
25
+ names.shift if names.empty? || names.first.empty?
26
+
27
+ names.inject(Object) do |constant, name|
28
+ if constant == Object
29
+ constant.const_get(name)
30
+ else
31
+ candidate = constant.const_get(name)
32
+ next candidate if constant.const_defined?(name, false)
33
+ next candidate unless Object.const_defined?(name)
34
+
35
+ # Go down the ancestors to check it it's owned
36
+ # directly before we reach Object or the end of ancestors.
37
+ constant = constant.ancestors.inject do |const, ancestor|
38
+ break const if ancestor == Object
39
+ break ancestor if ancestor.const_defined?(name, false)
40
+ const
41
+ end
42
+
43
+ # owner is in Object, so raise
44
+ constant.const_get(name, false)
45
+ end
46
+ end
47
+ end
48
+ end
data/lib/jrubyfx/utils.rb CHANGED
@@ -40,14 +40,24 @@ end
40
40
  # Standard ruby String class extensions
41
41
  class String
42
42
  # call-seq:
43
- # snake_case() => string
43
+ # snake_case(ignore_prefix_namespace=false) => string
44
44
  #
45
45
  # Converts a CamelCaseString to a snake_case_string
46
46
  #
47
47
  # "JavaFX".snake_case #=> "java_fx"
48
48
  #
49
- def snake_case
50
- self.gsub(/::/, '/').
49
+ # If ignore_prefix_namespace is specified it will strip
50
+ # any preceding modules/classes off front of string before
51
+ # snake casing:
52
+ # Foo::BigBar #=> "big_bar"
53
+ #
54
+ # By default it will separate modules with a "/":
55
+ # Foo::BigBar #=> "foo/big_bar"
56
+ #
57
+ def snake_case(ignore_prefix_namespace=false)
58
+ base = ignore_prefix_namespace ?
59
+ self.gsub(/.*::/, '') : self.gsub(/::/, '/')
60
+ base.
51
61
  gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
52
62
  gsub(/([a-z\d])([A-Z])/,'\1_\2').
53
63
  tr("-", "_").
@@ -63,3 +73,19 @@ module Enumerable
63
73
  end]
64
74
  end
65
75
  end
76
+
77
+ module JRubyFX
78
+ def self.load_fx(force=false)
79
+ return if @already_loaded_fx and !force
80
+ @already_loaded_fx = true
81
+ java.util.concurrent.CountDownLatch.new(1).tap do |latch|
82
+ platform = unless javafx.application.Platform.respond_to? :startup
83
+ com.sun.javafx.application.PlatformImpl
84
+ else
85
+ javafx.application.Platform
86
+ end
87
+ platform.startup { latch.countDown }
88
+ latch.await
89
+ end
90
+ end
91
+ end
@@ -1,4 +1,4 @@
1
1
  module JRubyFX
2
2
  # Current gem version. Used in rake task.
3
- VERSION='1.1.0'
3
+ VERSION='2.0.0'
4
4
  end
data/lib/jrubyfx.rb CHANGED
@@ -15,12 +15,13 @@ See the License for the specific language governing permissions and
15
15
  limitations under the License.
16
16
  =end
17
17
 
18
- if RUBY_VERSION.include? "1.8" or !JRUBY_VERSION
19
- puts "JRubyFX requires JRuby to be in 1.9 mode"
18
+ if !JRUBY_VERSION
19
+ puts "JRubyFX requires JRuby"
20
20
  exit -2
21
21
  end
22
- if Gem::Version.new(JRUBY_VERSION) < Gem::Version.new("1.7.4")
23
- puts "Warning: JRuby 1.7.3 and prior have bugs that can cause strange errors. Do not submit any bug reports. Please use JRuby 1.7.4 or later."
22
+ if Gem::Version.new(JRUBY_VERSION) < Gem::Version.new("9.3.4.0")
23
+ puts "JRubyFX 2.0 requires JRuby 9.3.4.0 or later. Use JRubyFX 1.x for earlier versions."
24
+ exit -2
24
25
  end
25
26
 
26
27
  require 'java' # for java_import
@@ -34,7 +35,8 @@ end
34
35
  require_relative 'jrubyfx/imports'
35
36
  require_relative 'jrubyfx/module'
36
37
  require_relative 'jrubyfx/dsl'
38
+ require_relative 'jrubyfx/dsl_control'
37
39
  JRubyFX::DSL.load_dsl # load it after we require the dsl package to not loop around
40
+ require_relative 'jrubyfx/fxml_helper'
38
41
  require_relative 'jrubyfx/application'
39
42
  require_relative 'jrubyfx/controller'
40
- require_relative 'jrubyfx/java_fx_impl'
data/lib/jrubyfx_tasks.rb CHANGED
@@ -26,14 +26,14 @@ module JRubyFX
26
26
  module Tasks
27
27
  extend Rake::DSL
28
28
  # Base URL of JRuby-complete.jar download location
29
- BASE_URL='http://repository.codehaus.org/org/jruby/jruby-complete'
29
+ BASE_URL='http://jruby.org.s3.amazonaws.com/downloads'
30
30
 
31
31
  ##
32
32
  # Downloads the jruby-complete jar file for `jruby_version` and save in
33
33
  # ~/.jruby-jar/jruby-complete.jar unless it already exits. If the jar is
34
34
  # corrupt or an older version, set force to true to delete and re-download
35
35
  def download_jruby(jruby_version, force=false)
36
- dist = "#{ENV['HOME']}/.jruby-jar"
36
+ dist = "#{Dir.home}/.jruby-jar"
37
37
  unless force || (File.exists?("#{dist}/jruby-complete-#{jruby_version}.jar") && File.size("#{dist}/jruby-complete-#{jruby_version}.jar") > 0)
38
38
  mkdir_p dist
39
39
  base_dir = Dir.pwd
@@ -69,6 +69,8 @@ module JRubyFX
69
69
  FileList[src].each do |iv_srv|
70
70
  cp_r iv_srv, "#{target}/#{File.basename(iv_srv)}" if (main_script == nil || main_script != iv_srv) && opts[:file_filter].call(iv_srv)
71
71
  end
72
+ cp_r "./.jrubyfx_cache", "#{target}/.jrubyfx_cache"
73
+
72
74
  cp main_script, "#{target}/jar-bootstrap.rb" unless main_script == nil
73
75
 
74
76
  unless File.exists? "#{target}/jar-bootstrap.rb"
@@ -105,7 +107,7 @@ module JRubyFX
105
107
  # edit the jar
106
108
  base_dir = Dir.pwd
107
109
  cd target
108
- sh "#{opts[:jar]} ufe '#{output_jar}' org.jruby.JarBootstrapMain *"
110
+ sh "#{opts[:jar]} ufe '#{output_jar}' org.jruby.JarBootstrapMain * .jr*"
109
111
  chmod 0775, output_jar
110
112
  cd base_dir
111
113
 
@@ -161,7 +163,9 @@ module JRubyFX
161
163
  def compile(cmdline)
162
164
  require 'jrubyfx/compiler_app'
163
165
  $JRUBYFX_AOT_COMPILING = true
166
+ $JRUBYFX_AOT_ERROR = false
164
167
  CompilerApp.launch(*cmdline) # must use this to provide a full javafx environ so controls will build properly
168
+ raise $JRUBYFX_AOT_ERROR if $JRUBYFX_AOT_ERROR
165
169
  end
166
170
 
167
171
 
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jrubyfx
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: 1.1.0
4
+ version: 2.0.0
6
5
  platform: java
7
6
  authors:
8
7
  - Patrick Plenefisch
@@ -12,56 +11,36 @@ authors:
12
11
  autorequire:
13
12
  bindir: bin
14
13
  cert_chain: []
15
- date: 2013-09-28 00:00:00.000000000 Z
14
+ date: 2022-04-16 00:00:00.000000000 Z
16
15
  dependencies:
17
16
  - !ruby/object:Gem::Dependency
18
- name: rake
19
- version_requirements: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - '>='
22
- - !ruby/object:Gem::Version
23
- version: '0'
24
- none: false
25
17
  requirement: !ruby/object:Gem::Requirement
26
18
  requirements:
27
- - - '>='
19
+ - - ">="
28
20
  - !ruby/object:Gem::Version
29
21
  version: '0'
30
- none: false
22
+ name: rake
31
23
  prerelease: false
32
24
  type: :development
33
- - !ruby/object:Gem::Dependency
34
- name: rspec
35
25
  version_requirements: !ruby/object:Gem::Requirement
36
26
  requirements:
37
- - - '>='
27
+ - - ">="
38
28
  - !ruby/object:Gem::Version
39
29
  version: '0'
40
- none: false
30
+ - !ruby/object:Gem::Dependency
41
31
  requirement: !ruby/object:Gem::Requirement
42
32
  requirements:
43
- - - '>='
33
+ - - ">="
44
34
  - !ruby/object:Gem::Version
45
35
  version: '0'
46
- none: false
36
+ name: rspec
47
37
  prerelease: false
48
38
  type: :development
49
- - !ruby/object:Gem::Dependency
50
- name: jrubyfx-fxmlloader
51
39
  version_requirements: !ruby/object:Gem::Requirement
52
40
  requirements:
53
- - - '>='
41
+ - - ">="
54
42
  - !ruby/object:Gem::Version
55
- version: '0.3'
56
- none: false
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - '>='
60
- - !ruby/object:Gem::Version
61
- version: '0.3'
62
- none: false
63
- prerelease: false
64
- type: :runtime
43
+ version: '0'
65
44
  description: Enables JavaFX with FXML controllers and application in pure ruby
66
45
  email:
67
46
  - simonpatp@gmail.com
@@ -75,80 +54,75 @@ executables:
75
54
  extensions: []
76
55
  extra_rdoc_files: []
77
56
  files:
57
+ - LICENSE
58
+ - README.md
59
+ - bin/jrubyfx-compile
60
+ - bin/jrubyfx-generator
61
+ - bin/jrubyfx-jarify
78
62
  - lib/jrubyfx.rb
79
- - lib/jrubyfx_tasks.rb
80
- - lib/jrubyfx/part_imports.rb
81
- - lib/jrubyfx/dsl.rb
82
- - lib/jrubyfx/version.rb
83
- - lib/jrubyfx/controller.rb
84
- - lib/jrubyfx/compiler_app.rb
85
- - lib/jrubyfx/dsl_map.rb
86
- - lib/jrubyfx/imports.rb
87
- - lib/jrubyfx/module.rb
88
63
  - lib/jrubyfx/application.rb
89
- - lib/jrubyfx/java_fx_impl.rb
90
- - lib/jrubyfx/utils.rb
91
- - lib/jrubyfx/core_ext/grid_pane.rb
92
- - lib/jrubyfx/core_ext/media_player.rb
64
+ - lib/jrubyfx/compiler_app.rb
65
+ - lib/jrubyfx/controller.rb
66
+ - lib/jrubyfx/core_ext/border_pane.rb
67
+ - lib/jrubyfx/core_ext/column_constraints.rb
68
+ - lib/jrubyfx/core_ext/drag_event.rb
93
69
  - lib/jrubyfx/core_ext/duration.rb
94
70
  - lib/jrubyfx/core_ext/effects.rb
95
- - lib/jrubyfx/core_ext/transition.rb
96
- - lib/jrubyfx/core_ext/pagination.rb
97
- - lib/jrubyfx/core_ext/drag_event.rb
98
- - lib/jrubyfx/core_ext/region.rb
99
- - lib/jrubyfx/core_ext/image_view.rb
100
- - lib/jrubyfx/core_ext/tree_view.rb
101
- - lib/jrubyfx/core_ext/table_view.rb
71
+ - lib/jrubyfx/core_ext/exts.yml
102
72
  - lib/jrubyfx/core_ext/file_chooser.rb
103
73
  - lib/jrubyfx/core_ext/geometry.rb
104
- - lib/jrubyfx/core_ext/xy_chart.rb
105
- - lib/jrubyfx/core_ext/rotate.rb
106
- - lib/jrubyfx/core_ext/exts.yml
107
- - lib/jrubyfx/core_ext/column_constraints.rb
74
+ - lib/jrubyfx/core_ext/grid_pane.rb
75
+ - lib/jrubyfx/core_ext/image_view.rb
76
+ - lib/jrubyfx/core_ext/media_player.rb
108
77
  - lib/jrubyfx/core_ext/observable_value.rb
78
+ - lib/jrubyfx/core_ext/pagination.rb
79
+ - lib/jrubyfx/core_ext/path.rb
109
80
  - lib/jrubyfx/core_ext/precompiled.rb
81
+ - lib/jrubyfx/core_ext/progress_indicator.rb
82
+ - lib/jrubyfx/core_ext/radial_gradient.rb
83
+ - lib/jrubyfx/core_ext/region.rb
84
+ - lib/jrubyfx/core_ext/rotate.rb
110
85
  - lib/jrubyfx/core_ext/stage.rb
111
- - lib/jrubyfx/core_ext/border_pane.rb
86
+ - lib/jrubyfx/core_ext/table_view.rb
112
87
  - lib/jrubyfx/core_ext/timeline.rb
113
- - lib/jrubyfx/core_ext/radial_gradient.rb
114
- - lib/jrubyfx/core_ext/progress_indicator.rb
115
- - lib/jrubyfx/core_ext/path.rb
116
- - lib/jrubyfx/utils/common_utils.rb
117
- - lib/jrubyfx/utils/common_converters.rb
88
+ - lib/jrubyfx/core_ext/transition.rb
89
+ - lib/jrubyfx/core_ext/tree_view.rb
90
+ - lib/jrubyfx/core_ext/xy_chart.rb
91
+ - lib/jrubyfx/dsl.rb
92
+ - lib/jrubyfx/dsl_control.rb
93
+ - lib/jrubyfx/dsl_map.rb
94
+ - lib/jrubyfx/fxml_helper.rb
95
+ - lib/jrubyfx/imports.rb
96
+ - lib/jrubyfx/module.rb
97
+ - lib/jrubyfx/part_imports.rb
98
+ - lib/jrubyfx/utils.rb
118
99
  - lib/jrubyfx/utils/__ignore_java_stupid_rdoc.rb
119
- - LICENSE
120
- - README.md
121
- - bin/jrubyfx-generator
122
- - bin/jrubyfx-jarify
123
- - bin/jrubyfx-compile
100
+ - lib/jrubyfx/utils/common_converters.rb
101
+ - lib/jrubyfx/utils/common_utils.rb
102
+ - lib/jrubyfx/utils/string_utils.rb
103
+ - lib/jrubyfx/version.rb
104
+ - lib/jrubyfx_tasks.rb
124
105
  homepage: https://github.com/jruby/jrubyfx
125
- licenses: []
106
+ licenses:
107
+ - Apache-2.0
108
+ metadata: {}
126
109
  post_install_message:
127
110
  rdoc_options: []
128
111
  require_paths:
129
112
  - lib
130
113
  required_ruby_version: !ruby/object:Gem::Requirement
131
114
  requirements:
132
- - - '>='
115
+ - - ">="
133
116
  - !ruby/object:Gem::Version
134
117
  version: '0'
135
- segments:
136
- - 0
137
- hash: 2
138
- none: false
139
118
  required_rubygems_version: !ruby/object:Gem::Requirement
140
119
  requirements:
141
- - - '>='
120
+ - - ">="
142
121
  - !ruby/object:Gem::Version
143
122
  version: '0'
144
- segments:
145
- - 0
146
- hash: 2
147
- none: false
148
123
  requirements: []
149
- rubyforge_project: jrubyfx
150
- rubygems_version: 1.8.24
124
+ rubygems_version: 3.2.29
151
125
  signing_key:
152
- specification_version: 3
126
+ specification_version: 4
153
127
  summary: JavaFX for JRuby with FXML
154
128
  test_files: []