Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Glimmer DSL for JFX enables building desktop applications with JavaFX via JRuby.
JavaFX has been Java's next generation technology for a while for desktop application GUI development. Unfortunately, when it divorced itself from its JavaFX Script roots, it became no better than Java Swing in syntax.
Furthermore, the whole stage and scene production metaphor made everything more complicated to get into it for software engineers who encountered it for the first time. After all, desktop developers simply think of windows, not stages or scenes. The metaphor unfortunately pushes software engineers into thinking of low-level details (e.g. nodes) that are not important in developing business desktop applications.
FXML attempted to rectify the situation by making JavaFX more declarative than its Swing-like Java syntax. Unfortunately, XML, like its cousin HTML, brings all the same problems web developers face in day-to-day in suffering through multi-language dissonance to desktop software engineering. That defeats the whole point about desktop software engineering being a lot more productive than web development for simple local apps. FXML was really just a step back into the wrong direction.
Glimmer DSL for JFX aims to overcome the hurdles of JavaFX by providing a declarative hierarchical alternative to FXML in pure Ruby as one language (not multi-language mixing dissonance), which supercharges productivity and maintainability in developing JavaFX applications similarly to Glimmer DSL for SWT through:
Hello, World!
window {
title 'Hello, World!'
label('Hello, World!')
}
NOTE: Glimmer DSL for JFX is currently in early alpha mode (incomplete proof-of-concept). Please help make better by contributing, adopting for small or low risk projects, and providing feedback. It is still an early alpha, so the more feedback and issues you report the better.
Other Glimmer DSL gems you might be interested in:
rvm install jruby-9.2.19.0
; On Windows, find at https://www.jruby.org/download)PATH_TO_FX
environment variable to path of lib
directory in extracted "SDK" directory)Note: On the Mac, if you have Glimmer DSL for SWT installed, and it added export JRUBY_OPTS="$JRUBY_OPTS -J-XstartOnFirstThread"
to your .zprofile
, .zshrc
, .bash_profile
, or .bashrc
, make sure to disable it before using Glimmer DSL for JFX. Unfortunately, it is not compatible with it and will hang its apps until disabled.
Make sure to download the right JavaFX SDK for your platform and CPU architecture from https://gluonhq.com/products/javafx/ and then set the PATH_TO_FX environment variable to the location of the lib directory in the extracted SDK directory.
Run this command to install directly:
gem install glimmer-dsl-jfx -v0.0.1
Add the following to Gemfile
:
gem 'glimmer-dsl-jfx', '0.0.1'
And, then run:
bundle
Require the library and mixin the Glimmer
module to utilize the Glimmer GUI DSL for JFX:
require 'glimmer-dsl-jfx'
include Glimmer
window {
title 'Hello, World!'
label('Hello, World!')
}
For actual application development outside of simple demos, mixin the Glimmer
module into a custom application class instead:
require 'glimmer-dsl-jfx'
class SomeApplication
include Glimmer
def launch
window {
title 'Hello, World!'
label('Hello, World!')
}
end
end
SomeApplication.new.launch
The Glimmer GUI DSL enables development of desktop graphical user interfaces in a manner similar to HTML, but in one language, Ruby, thus avoiding the multi-language separation dissonance encountered on the web, especially given that Ruby looping/conditional constructs do not need scriptlets to be added around View code. This makes desktop development extremely productive.
1 - Keywords
Always start with window
, which simplifies/replaces both the Stage
and Scene
concepts, having both their properties. Additionally, window
removes the need to extend Application
as it does so automatically internally.
Inside window
, you may declare any JavaFX control with its keyword, which is the underscored version of the class name. For example, label
is the keyword for javafx.scene.control.Label
Examples:
v_box
label
button
2 - Arguments
You may pass any arguments that a JavaFX control constructor accepts to its Glimmer keyword.
Example (Label
and Button
have a constructor signature that accepts a string representing the text property):
label('Full Name')
button('Submit Form')
The recommended style is to always wrap arguments with parentheses for control keywords.
3 - Content Block
You may pass a content block to any JavaFX control keyword, which contains properties and/or nested controls.
Example:
window {
title 'Hello, Window!'
width 320
height 240
v_box {
label('Hello, Label!')
button('Hello, Button!')
}
}
The recommended style for the content block is always curly braces {}
to denote as View nesting code different from looping/conditional logic, which utilizes do;end
instead.
Property arguments never have parentheses.
4 - Listeners
You may declare listeners with their on_
-prefixed event method name as found in the JavaFX Javadoc. For example: on_action
, on_key_pressed
, on_key_released
, on_key_typed
, on_mouse_clicked
, and on_mouse_moved
.
For example, Button
has an onAction
method. In Glimmer, you simply underscore that:
window {
title 'Hello, Button!'
button('Click') { |b|
on_action do
b.text = 'Clicked'
end
}
}
The recommended style for listeners is always a do; end
block.
5 - Component Proxy & Methods
When utilizing the Glimmer GUI DSL, you get back proxy objects that wrap JavaFX Javadoc controls. To access the original control wrapped by the proxy object, you may call the #jfx
method.
Furthermore, you may invoke any method available on the control indirectly on the proxy object, like the #text
method on label
.
label1 = label('Full Name')
label1.text # same as label1.jfx.text
6 - Observe Model Attributes
In Smalltalk-MVC (Model View Controller Architectural Pattern), the View is an active View that observes the Model for changes and updates itself.
This can be achieved with the Glimmer GUI DSL using the observe
keyword, which takes a model (any object, including self
) and attribute Symbol or String expression (e.g. :count
or 'address.street'
).
The model is automatically enhanced as an Glimmer::DataBinding::ObservableModel
/ Glimmer::DataBinding::ObservableHash
/ Glimmer::DataBinding::ObservableArray
depending on its type to support notifying observers of attribute changes (when performed using the attribute writer, which automatically calls added method notify_observers(attribute)
)
Note that it is usually recommended to observe external model objects (not self
), but self
is OK in very simple cases or presentation-related attributes only.
Example:
require 'glimmer-dsl-jfx'
class Counter
attr_accessor :count
def initialize
self.count = 0
end
end
class HelloButton
include Glimmer
def initialize
@counter = Counter.new
observe(@counter, :count) do |new_count|
@button.text = "Click To Increment: #{new_count}"
end
end
def launch
window {
title 'Hello, Button!'
@button = button('Click To Increment: 0') {
on_action do
@counter.count += 1
end
}
}
end
end
HelloButton.new.launch
window
automatically builds an Application
object, sets Stage
properties and sets a Scene
in primary stage.You can run the girb
command (bin/girb
if you cloned the project locally):
girb
This gives you irb
with the glimmer-dsl-jfx
gem loaded and the Glimmer
module mixed into the main object for easy experimentation with GUI.
Run with gem installed:
jruby -r glimmer-dsl-jfx -e "require 'samples/hello/hello_world'"
Or run from locally cloned project directory:
jruby -r ./lib/glimmer-dsl-jfx samples/hello/hello_world.rb
require 'glimmer-dsl-jfx'
include Glimmer
window {
title 'Hello, World!'
label('Hello, World!')
}
Run with gem installed:
jruby -r glimmer-dsl-jfx -e "require 'samples/hello/hello_button'"
Or run from locally cloned project directory:
jruby -r ./lib/glimmer-dsl-jfx samples/hello/hello_button.rb
Version 1 (without model) - samples/hello/hello_button.rb:
require 'glimmer-dsl-jfx'
include Glimmer
window {
title 'Hello, Button!'
@button = button('Click To Increment: 0') {
on_action do
button_text_match = @button.text.match(/([^0-9]+)(\d+)$/)
count = button_text_match[2].to_i + 1
@button.text = "#{button_text_match[1]}#{count}"
end
}
}
Version 2 (with model) - samples/hello/hello_button2.rb:
require 'glimmer-dsl-jfx'
class Counter
attr_accessor :count
def initialize
self.count = 0
end
end
class HelloButton
include Glimmer
def initialize
@counter = Counter.new
end
def launch
window {
title 'Hello, Button!'
@button = button('Click To Increment: 0') {
on_action do
@counter.count += 1
@button.text = "Click To Increment: #{new_count}"
end
}
}
end
end
HelloButton.new.launch
If you encounter issues that are not reported, discover missing features that are not mentioned in TODO.md, or think up better ways to use JavaFX than what is possible with Glimmer DSL for JFX, you may submit an issue or pull request on GitHub. In the meantime while waiting for a fix, you may try older gem versions of Glimmer DSL for JFX in case you find one that does not have the issue and actually works.
These features have been planned or suggested. You might see them in a future version of Glimmer DSL for JFX. You are welcome to contribute more feature suggestions.
Click here to view contributor commits.
Copyright (c) 2021 Andy Maleh.
--
Built for Glimmer (DSL Framework).
FAQs
Unknown package
We found that glimmer-dsl-jfx demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.