Developing cross platform desktop application with Ruby
-
Upload
anis-ahmad -
Category
Technology
-
view
12.136 -
download
1
description
Transcript of Developing cross platform desktop application with Ruby
![Page 1: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/1.jpg)
Desktop Application with Ruby
Getting started with
![Page 2: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/2.jpg)
I am...
PHP ZEND KOHANA JSE JEE Ruby GWT JavaScript
jQuery sinatra BackboneJS CSS3 HTML5 MySQL Drupal MongoDB PHPUNIT Groovy
JRuby Symfony2 SWING
sqlite Doctrain solr Phing grails ...
Anis Uddin AhmadCTO & Co-FounderWNeeds Ltd.
![Page 3: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/3.jpg)
!=
![Page 4: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/4.jpg)
Ruby is not ONLY for web
![Page 5: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/5.jpg)
It's a generic purpose language
![Page 6: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/6.jpg)
generic purpose?
● Web Application
● Desktop Application
● Mobile Application (Yes iPhone too!)
● DSLs
● Antyhing you can think*
![Page 7: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/7.jpg)
So, Ruby can make Desktop App?
Okay...But HOW?
![Page 8: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/8.jpg)
Many Ways!
Shoes Ruby-GNOME2 / GTK
WxRuby Ruby-Tk
Ruby Cocoa / MacRuby
QtRuby JRuby + Swing
FxRuby JRuby + SWT
![Page 9: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/9.jpg)
Many Ways!
Shoes Ruby-GNOME2 / GTK
WxRuby Ruby-Tk
Ruby Cocoa / MacRuby
QtRuby JRuby + Swing
FxRuby JRuby + SWT
![Page 10: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/10.jpg)
Shoes
cross-platform toolkit for writing graphical apps easily
and artfully using Ruby
![Page 11: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/11.jpg)
Starting with Shoes
● Download (http://shoesrb.com/downloads))
● Run Shoes
![Page 12: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/12.jpg)
Starting with Shoes
● Download (http://shoesrb.com/downloads))
● Run Shoes
![Page 13: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/13.jpg)
Shoes example
Shoes.app :width => 300, :height => 200 do button("Click me!") { alert("Good job.") }end
![Page 14: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/14.jpg)
Shoes example
Shoes.app :width => 300, :height => 200 do button("Click me!") { alert("Good job.") }end
![Page 15: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/15.jpg)
Shoes example (Clock)
Shoes.app do @time = title "0:00" every 1 do @time.replace(Time.now.strftime("%I:%M %p")) endend
![Page 17: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/17.jpg)
Packaging Shoes
![Page 18: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/18.jpg)
JRuby
The Ruby Programming Language on the JVM
![Page 19: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/19.jpg)
Ruby for desktop application? Yes we can!
![Page 21: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/21.jpg)
Why JRuby?
● High performance
![Page 22: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/22.jpg)
Why JRuby?
● High performance
● Real threading
![Page 23: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/23.jpg)
Why JRuby?
● High performance
● Real threading
● Vast array of libraries (gems + JARs)
![Page 24: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/24.jpg)
Why JRuby?
● High performance
● Real threading
● Vast array of libraries (gems + JARs)
● Platform Independent
![Page 25: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/25.jpg)
Why JRuby?
● High performance
● Real threading
● Vast array of libraries (gems + JARs)
● Platform Independent
● Enterprise Acceptance
![Page 26: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/26.jpg)
Why JRuby?
● High performance
● Real threading
● Vast array of libraries (gems + JARs)
● Platform Independent
● Enterprise Acceptance
The best of both worlds!
![Page 27: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/27.jpg)
Let's make with JRuby!
![Page 28: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/28.jpg)
Get JRuby
● Download
● Extract
● Add bin subdirectory to your $PATH
– (PATH=path/to/jruby/bin:$PATH)
● Test it: jruby -v
● Assuming you have jdk 1.7 installed● Can be installed with rvm too
![Page 29: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/29.jpg)
Import Java Swing in .rb
include Java
import javax.swing.JFrameimport javax.swing.JComboBoximport javax.swing.JButtonimport javax.swing.JPanelimport javax.swing.JLabelimport javax.swing.JTextField
import java.awt.GridLayout
![Page 30: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/30.jpg)
Make a Frame (JFrame)
class NumberConverter < JFrame
def initializesuper('Number Format Converter')
set_size(400,140);set_visible(true);
set_default_close_operation(JFrame::EXIT_ON_CLOSE);end
end
num_converter = NumberConverter.new
![Page 31: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/31.jpg)
Let's run it!
$ cd go/to/source/dir$ jruby number_converter.rb
![Page 32: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/32.jpg)
Place container
super('Number Format Converter')
main = JPanel.new;
get_content_pane().add("Center", main);
![Page 33: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/33.jpg)
Set Layout
super('Number Format Converter')
main = JPanel.new;main.set_layout(GridLayout.new(3,3,2,2))
get_content_pane().add("Center", main)
![Page 34: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/34.jpg)
Add Components
main.set_layout(GridLayout.new(3,3,2,2))
main.add(JLabel.new("Convert From : ", JLabel::RIGHT))main.add(@cmbFrom = JComboBox.new)main.add(@input = JTextField.new(15))
![Page 35: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/35.jpg)
Where are they going?
main.set_layout(GridLayout.new(3,3,2,2))
main.add(JLabel.new("Convert From : ", JLabel::RIGHT))main.add(@cmbFrom = JComboBox.new)main.add(@input = JTextField.new(15))
1 2 3
4 5 6
7 8 9
![Page 36: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/36.jpg)
Add the rest of
main.add(@input = JTextField.new(15))
# Second rowmain.add(JLabel.new("Convert To : ", JLabel::RIGHT));main.add(@cmbTo = JComboBox.new);main.add(result = JTextField.new(15));
# Third rowmain.add(JLabel.new(" ")); # Leave this cell blankmain.add(btn = JButton.new("CONVERT"));
![Page 37: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/37.jpg)
Let's run again!
$ cd go/to/source/dir$ jruby number_converter.rb
![Page 38: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/38.jpg)
More with components
main.add(result = JTextField.new(15));result.set_editable(false);
main.add(btn = Jbutton.new("CONVERT"));
# Add options to comboBoxesnum_formats = ["Decimal", "Binary", "HexaDecimal", "Octal"]num_formats.each{|format| @cmbFrom.add_item format }num_formats.each{|format| @cmbTo.add_item format }
![Page 39: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/39.jpg)
Set Event Handler
main.add(btn = Jbutton.new("CONVERT"));btn.add_action_listener do |evt|
result.set_text(convert.upcase);end
![Page 40: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/40.jpg)
Set Event Handler cont.
def convert# Take the value of @input# Take formats form @cmbFrom and @cmbTo# Convert to required format
end
end # end of class NumFormat
main.add(btn = Jbutton.new("CONVERT"));btn.add_action_listener do |evt|
result.set_text(convert.upcase);end
![Page 42: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/42.jpg)
![Page 43: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/43.jpg)
Java <=> JRuby Transformation
![Page 44: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/44.jpg)
Java <=> JRuby Transformation
new Car(color, wheels)
Car.new color, wheels
![Page 45: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/45.jpg)
Java <=> JRuby Transformation
JLabel.LEFT
JLabel::LEFT
![Page 46: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/46.jpg)
Java <=> JRuby Transformation
Obj.longFuncName();
Obj.long_func_name
![Page 47: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/47.jpg)
Java <=> JRuby Transformation
String[] options = {"all", "any"};
combo = new JcomboBox(options);
options.each{ |format|
combo.add_item format
}
![Page 48: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/48.jpg)
Java <=> JRuby Transformation
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
doSomething();
}
});
btn.add_action_listener do |evt|
do_something
end
![Page 49: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/49.jpg)
Deployment
Warbler
https://github.com/jruby/warblerhttp://rawr.rubyforge.org/
![Page 50: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/50.jpg)
BTW, JRuby is not ONLY for Desktop
● It's just Ruby*● Rails just works
*Here are differences- https://github.com/jruby/jruby/wiki/DifferencesBetweenMriAndJruby
![Page 51: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/51.jpg)
JRuby Frameworks
● Cheri::Swing
● Limelight
● Monkeybars
● RSwing
● Rubeus
● Swiby
https://github.com/jruby/jruby/wiki/GUIFrameworks
![Page 52: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/52.jpg)
JRuby Frameworks
● Cheri::Swing
● Limelight
● Monkeybars
● RSwing
● Rubeus
● Swiby
Frame.new("hello, world") do |frame| frame.default_close_operation = :exit_on_close frame.size = [200, 200] ...
https://github.com/jruby/jruby/wiki/GUIFrameworks
![Page 53: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/53.jpg)
Questions?
![Page 54: Developing cross platform desktop application with Ruby](https://reader034.fdocuments.net/reader034/viewer/2022052303/554f86c5b4c905435d8b4c3c/html5/thumbnails/54.jpg)