SlideShare a Scribd company logo
Desktop Application using
JRuby + SWT
呂旺燊
專家講座 C :
Desktop Application using JRuby + SWT
個人簡介
       
           呂旺燊
          Twitter: @tkalu
          RoR programmer
       
           任職於和多 handlino.com
Fire.app




           http://fireapp.handlino.com/
HTML prototyping tool
網頁原型設計工具


      HTML + CSS + JavaScript
HTML
支援多種 Template language
●   ERB
●   HAML
●   Slim
●   Markdown
CSS




 http://sass-lang.com/   http://compass-style.org/
JavaScript




             http://coffeescript.org/
Server
Simple Web Server
可以在瀏覽器裏面透過 http://127.0.0.1:24681的網址
瀏覽專案內容

Support LiveReload protocol
當檔案修改之後 , 瀏覽器會自動更新
Ref.
● http://livereload.com/

● LiveReload Protocol
跨平台支援




 Linux   OS X   Windows
簡潔的介面 - 1
簡潔的介面 - 2
為什麼打造 Fire.app



  故事要從遇見 Compass 說起了 ......
Compass Awesome!!!




        from http://sonspring.com/journal/sass-for-designers
痛恨 command line....
需要跨平台
需要 GUI - 1
Ruby GUI Library
 ● Tk
 ● wxRuby


 ● qtRuby
                   Cross-Platform
 ● Ruby/GTK


 ● Shoes


 ● FXRuby


 ● MacRuby
需要 GUI - 2
         Eclipse


        Java + SWT


       JRuby + SWT
成果

     2010.12 推出 Compass.app

     2012.04 推出 Fire.app
誰需要 JRuby + SWT ?

       或是

為什麼選擇 JRuby+SWT?
誰需要 JRuby + SWT ?

 1. 熟悉 Ruby 想寫 GUIa

 2. 想使用的 Library 只有 Ruby 的版本

 3. 很熟 SWT 想改用 Ruby 的語法寫程式
回到正題



 如何用 JRuby 搭配 SWT 開發程式
JRuby 中使用 Java 程式
 # 使用 Java 的環境
 require 'java'

 # 載入指定的 jar 檔
 require 'path/to/mycode.jar'

 # 取得目前的 Java 版號
 java.lang.System.getProperties["java.runtime.
 version"]

 更多資料請參考
 https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby
載入 SWT
 前往 SWT 官網下載檔案後解壓縮後可以取
 得 swt.jar 後 , 透過下列兩行程式碼即可
 載入 SWT

 require "java"
 require "download/path/swt"
Hellow Word!
  display = org.eclipse.swt.widgets.Display.new
  shell    = org.eclipse.swt.widgets.Shell.new(display)
 row_layout=
org.eclipse.swt.layout.RowLayout.new(org.eclipse.swt.SWT::HO
RIZONTAL)
  shell.setLayout( row_layout)

  label = org.eclipse.swt.widgets.Label.new(shell,
org.eclipse.swt.SWT::HORIZONTAL )
  label.setText( 'Hello World!' )
  shell.open

 while(!shell.is_disposed) do
   display.sleep if(!display.read_and_dispatch)
 end

 display.dispose
更加的 Ruby 風格
module Swt
  import org.eclipse.swt.SWT
  import org.eclipse.swt.program.Program

  module Widgets
    import org.eclipse.swt.widgets.Display
    import org.eclipse.swt.widgets.Label
    import org.eclipse.swt.widgets.Shell
  end
  module Layout
    import org.eclipse.swt.layout.RowLayout
  end
end
Hello World! 加強版
display = Swt::Widgets::Display.get_current
shell    = Swt::Widgets::Shell.new(display)
shell.layout =
Swt::Layout::RowLayout.new(Swt::SWT::HORIZONTAL)
label = Swt::Widgets::Label.new(shell,
Swt::SWT::HORIZONTAL )
label.text = 'Hello World!'
shell.open

while(!shell.is_disposed) do
  display.sleep if(!display.read_and_dispatch)
end

display.dispose
其他開發心得

 ●
   SWT 跨平台問題
 ●
   調整啟動速度
 ●
   打包程式
 ●
   Mac 上隱藏 Dock 的圖示
SWT 跨平台問題
SWT_LIB_PATH ="#{LIB_PATH}/swt"

if org.jruby.platform.Platform::IS_MAC
  os="osx"
elsif org.jruby.platform.Platform::IS_LINUX
  os="linux"
elsif org.jruby.platform.Platform::IS_WINDOWS
  os="win"
end

if org.jruby.platform.Platform::ARCH =~ /64/
  arch="64"
else
  arch="32"
end

require "#{SWT_LIB_PATH}/swt_#{os}#{arch}"
調整啟動速度
   1. 不要使用 rubygem 管理 library
     require "rubygems" 會花上約 0.7 秒
     建議自己將需要的 library 的路徑加到 $LOAD_PATH
     中

   2. 需要使用時才 require library
     JRuby require 的成本十分龐大 , 建議要用到的時候才進
     行 require 的動作 , 而不是程式一啟動就將需要 library
     全部載入

其他技巧還可參考
http://headius.blogspot.com/2010/03/jruby-startup-time-tips.html
打包程式
使用 Rawr http://github.com/rawr/rawr Rawr 包裝了
launch4j提供 JRuby 程式更加方便的打包方式

安裝 rawr 到系統 :
 gem install rawr
建立專案 :
 rawr install {project_path}
打包 Mac 程式:
 rake rawr:bundle:app
打包 Windows 程式:
 rake rawr:bundle:exe
Mac 上隱藏 Dock 的圖示
 在 OSX 中使用 SWT 的程式會預設在 Dock 中顯示
 圖示 , 如果想要做出 只顯示在 system tray 上面
 的效果 , 需會要修改 Info.plist, 必須在 <dict> 中
 添加下列內容 :

     <key>NSUIElement</key>
     <string>1</string>
範例程式


            請前往下方 Github 網址下載
https://github.com/tka/jruby-rawr-swt-helloworld
Live Demo




     如果有時間的話 .....
Thank You
如果還有時間 ....




     JRuby on Android
    http://ruboto.org/
Thank You

More Related Content

What's hot (20)

PDF
CP 值很高的 Gulp
Yvonne Yu
 
PDF
Node.js從無到有 基本課程
Simon Su
 
PDF
Npm 套件管理 & 常用開發工具介紹
wantingj
 
PDF
React.js what do you really mean?
昱安 周
 
PDF
Gulp.js 自動化前端任務流程
洧杰 廖
 
PPTX
Cinder snapshot and backup
Felix Ma
 
PDF
學好 node.js 不可不知的事
Ben Lue
 
PPTX
快快樂樂學 Angular 2 開發框架
Will Huang
 
PDF
使用 Load Balancer 與 Redis 部署 LAMP Server 高併發架構 - Global Azure Taiwan 20200425 ...
Laird Cheng
 
PDF
SITCON 2016 ─ Modern Front-End Workflow with Webpack
昱安 周
 
PPTX
Node.js中间件 connect模块深入浅出
Eric Xiao
 
PPTX
SQL Server 資料庫版本控管
Will Huang
 
PDF
App house
Fred Chien
 
PPTX
使用 TypeScript 駕馭 Web 世界的脫韁野馬:以 Angular 2 開發框架為例
Will Huang
 
PPTX
JavaScript 物件導向觀念入門 v.s. TypeScript 開發實戰 (微軟實戰課程日)
Will Huang
 
PDF
Node.js 進攻桌面開發
Fred Chien
 
PDF
用最潮的 Java script 盡情開發 kde qt 程式
Fred Chien
 
PPTX
TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式
Will Huang
 
ODP
GNU Build System
imacat .
 
PDF
AWS EC2 for beginner
azole Lai
 
CP 值很高的 Gulp
Yvonne Yu
 
Node.js從無到有 基本課程
Simon Su
 
Npm 套件管理 & 常用開發工具介紹
wantingj
 
React.js what do you really mean?
昱安 周
 
Gulp.js 自動化前端任務流程
洧杰 廖
 
Cinder snapshot and backup
Felix Ma
 
學好 node.js 不可不知的事
Ben Lue
 
快快樂樂學 Angular 2 開發框架
Will Huang
 
使用 Load Balancer 與 Redis 部署 LAMP Server 高併發架構 - Global Azure Taiwan 20200425 ...
Laird Cheng
 
SITCON 2016 ─ Modern Front-End Workflow with Webpack
昱安 周
 
Node.js中间件 connect模块深入浅出
Eric Xiao
 
SQL Server 資料庫版本控管
Will Huang
 
App house
Fred Chien
 
使用 TypeScript 駕馭 Web 世界的脫韁野馬:以 Angular 2 開發框架為例
Will Huang
 
JavaScript 物件導向觀念入門 v.s. TypeScript 開發實戰 (微軟實戰課程日)
Will Huang
 
Node.js 進攻桌面開發
Fred Chien
 
用最潮的 Java script 盡情開發 kde qt 程式
Fred Chien
 
TypeScript 開發實戰:開發即時互動的 html5 websocket 聊天室應用程式
Will Huang
 
GNU Build System
imacat .
 
AWS EC2 for beginner
azole Lai
 

Similar to 2012 java two-desktop-appliction-using-j-ruby-with-swt (20)

PPT
Java 1(Java概述)
xzdbd
 
PPT
Html5
cazhfe
 
PDF
docker intro
koji lin
 
PPTX
Node.js长连接开发实践
longhao
 
PDF
Hadoop开发者入门专刊
liangxiao0315
 
PDF
Build desktop app_by_xulrunner
Rack Lin
 
PDF
從軟體開發角度
談 Docker 的應用
謝 宗穎
 
PDF
从无阻塞并行脚本加载(Lab.js)到浏览器消息模型
Jackson Tian
 
PDF
凌波微步:wagon + VS Code 的輕功哲學
Shengyou Fan
 
PPT
互联网创业服务器运维工具集
zhen chen
 
PPT
Node分享 展烨
tb-vertical-guide
 
PPTX
介紹前端 Web 技術在跨平台開發上的應用
Jerry Lin
 
PDF
J Ruby和Rails 让Ruby语言融入Java项目
George Ang
 
PDF
Node js实践
myzykj
 
PDF
Javascript primer plus
Dongxu Yao
 
PDF
Big Java, Big Data
Kuo-Chun Su
 
PPT
IKVM.NET 深入敵營的 Java
建興 王
 
PDF
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩
Wen-Tien Chang
 
PDF
打開窗,讓大象跨進來 - Microsoft HDInsight
Kuo-Chun Su
 
PDF
給 iOS 工程師的 Flutter 開發
Weizhong Yang
 
Java 1(Java概述)
xzdbd
 
Html5
cazhfe
 
docker intro
koji lin
 
Node.js长连接开发实践
longhao
 
Hadoop开发者入门专刊
liangxiao0315
 
Build desktop app_by_xulrunner
Rack Lin
 
從軟體開發角度
談 Docker 的應用
謝 宗穎
 
从无阻塞并行脚本加载(Lab.js)到浏览器消息模型
Jackson Tian
 
凌波微步:wagon + VS Code 的輕功哲學
Shengyou Fan
 
互联网创业服务器运维工具集
zhen chen
 
Node分享 展烨
tb-vertical-guide
 
介紹前端 Web 技術在跨平台開發上的應用
Jerry Lin
 
J Ruby和Rails 让Ruby语言融入Java项目
George Ang
 
Node js实践
myzykj
 
Javascript primer plus
Dongxu Yao
 
Big Java, Big Data
Kuo-Chun Su
 
IKVM.NET 深入敵營的 Java
建興 王
 
A brief introduction to Vagrant – 原來 VirtualBox 可以這樣玩
Wen-Tien Chang
 
打開窗,讓大象跨進來 - Microsoft HDInsight
Kuo-Chun Su
 
給 iOS 工程師的 Flutter 開發
Weizhong Yang
 
Ad

2012 java two-desktop-appliction-using-j-ruby-with-swt

  • 2. 專家講座 C : Desktop Application using JRuby + SWT
  • 3. 個人簡介  呂旺燊  Twitter: @tkalu  RoR programmer  任職於和多 handlino.com
  • 4. Fire.app http://fireapp.handlino.com/
  • 6. HTML 支援多種 Template language ● ERB ● HAML ● Slim ● Markdown
  • 7. CSS http://sass-lang.com/ http://compass-style.org/
  • 8. JavaScript http://coffeescript.org/
  • 9. Server Simple Web Server 可以在瀏覽器裏面透過 http://127.0.0.1:24681的網址 瀏覽專案內容 Support LiveReload protocol 當檔案修改之後 , 瀏覽器會自動更新 Ref. ● http://livereload.com/ ● LiveReload Protocol
  • 10. 跨平台支援 Linux OS X Windows
  • 13. 為什麼打造 Fire.app 故事要從遇見 Compass 說起了 ......
  • 14. Compass Awesome!!! from http://sonspring.com/journal/sass-for-designers
  • 17. 需要 GUI - 1 Ruby GUI Library ● Tk ● wxRuby ● qtRuby Cross-Platform ● Ruby/GTK ● Shoes ● FXRuby ● MacRuby
  • 18. 需要 GUI - 2 Eclipse Java + SWT JRuby + SWT
  • 19. 成果 2010.12 推出 Compass.app 2012.04 推出 Fire.app
  • 20. 誰需要 JRuby + SWT ? 或是 為什麼選擇 JRuby+SWT?
  • 21. 誰需要 JRuby + SWT ? 1. 熟悉 Ruby 想寫 GUIa 2. 想使用的 Library 只有 Ruby 的版本 3. 很熟 SWT 想改用 Ruby 的語法寫程式
  • 22. 回到正題 如何用 JRuby 搭配 SWT 開發程式
  • 23. JRuby 中使用 Java 程式 # 使用 Java 的環境 require 'java' # 載入指定的 jar 檔 require 'path/to/mycode.jar' # 取得目前的 Java 版號 java.lang.System.getProperties["java.runtime. version"] 更多資料請參考 https://github.com/jruby/jruby/wiki/CallingJavaFromJRuby
  • 24. 載入 SWT 前往 SWT 官網下載檔案後解壓縮後可以取 得 swt.jar 後 , 透過下列兩行程式碼即可 載入 SWT require "java" require "download/path/swt"
  • 25. Hellow Word! display = org.eclipse.swt.widgets.Display.new shell = org.eclipse.swt.widgets.Shell.new(display) row_layout= org.eclipse.swt.layout.RowLayout.new(org.eclipse.swt.SWT::HO RIZONTAL) shell.setLayout( row_layout) label = org.eclipse.swt.widgets.Label.new(shell, org.eclipse.swt.SWT::HORIZONTAL ) label.setText( 'Hello World!' ) shell.open while(!shell.is_disposed) do display.sleep if(!display.read_and_dispatch) end display.dispose
  • 26. 更加的 Ruby 風格 module Swt import org.eclipse.swt.SWT import org.eclipse.swt.program.Program module Widgets import org.eclipse.swt.widgets.Display import org.eclipse.swt.widgets.Label import org.eclipse.swt.widgets.Shell end module Layout import org.eclipse.swt.layout.RowLayout end end
  • 27. Hello World! 加強版 display = Swt::Widgets::Display.get_current shell = Swt::Widgets::Shell.new(display) shell.layout = Swt::Layout::RowLayout.new(Swt::SWT::HORIZONTAL) label = Swt::Widgets::Label.new(shell, Swt::SWT::HORIZONTAL ) label.text = 'Hello World!' shell.open while(!shell.is_disposed) do display.sleep if(!display.read_and_dispatch) end display.dispose
  • 28. 其他開發心得 ● SWT 跨平台問題 ● 調整啟動速度 ● 打包程式 ● Mac 上隱藏 Dock 的圖示
  • 29. SWT 跨平台問題 SWT_LIB_PATH ="#{LIB_PATH}/swt" if org.jruby.platform.Platform::IS_MAC os="osx" elsif org.jruby.platform.Platform::IS_LINUX os="linux" elsif org.jruby.platform.Platform::IS_WINDOWS os="win" end if org.jruby.platform.Platform::ARCH =~ /64/ arch="64" else arch="32" end require "#{SWT_LIB_PATH}/swt_#{os}#{arch}"
  • 30. 調整啟動速度 1. 不要使用 rubygem 管理 library require "rubygems" 會花上約 0.7 秒 建議自己將需要的 library 的路徑加到 $LOAD_PATH 中 2. 需要使用時才 require library JRuby require 的成本十分龐大 , 建議要用到的時候才進 行 require 的動作 , 而不是程式一啟動就將需要 library 全部載入 其他技巧還可參考 http://headius.blogspot.com/2010/03/jruby-startup-time-tips.html
  • 31. 打包程式 使用 Rawr http://github.com/rawr/rawr Rawr 包裝了 launch4j提供 JRuby 程式更加方便的打包方式 安裝 rawr 到系統 : gem install rawr 建立專案 : rawr install {project_path} 打包 Mac 程式: rake rawr:bundle:app 打包 Windows 程式: rake rawr:bundle:exe
  • 32. Mac 上隱藏 Dock 的圖示 在 OSX 中使用 SWT 的程式會預設在 Dock 中顯示 圖示 , 如果想要做出 只顯示在 system tray 上面 的效果 , 需會要修改 Info.plist, 必須在 <dict> 中 添加下列內容 : <key>NSUIElement</key> <string>1</string>
  • 33. 範例程式 請前往下方 Github 網址下載 https://github.com/tka/jruby-rawr-swt-helloworld
  • 34. Live Demo 如果有時間的話 .....
  • 36. 如果還有時間 .... JRuby on Android http://ruboto.org/