(ns swtftw.core (:gen-class) (:use (guiftw swt styles)) (:import (org.eclipse.swt SWT) (org.eclipse.swt.widgets Shell Button MessageBox) (org.eclipse.swt.events SelectionListener) (org.eclipse.swt.layout FillLayout))) (def window (swt [Shell [*id :main-window] [Button [*id :super-button]]])) (defn get-info [obj] (reduce str (for [[k v] (bean obj)] (str k " " (->> v str (take 50) (reduce str)) "\n")))) (defn show-info [gui event] (doto (MessageBox. (:root @gui) (bit-or SWT/ICON_INFORMATION SWT/OK)) (.setText "Event Info") (.setMessage (get-info event)) .open)) ;;;; ALTERNATIVE CODE: ;;;; ;;;; Functions message-box and show-info-alternative compose a ;;;; "proper" version of show-info where MessageBox is created using ;;;; GUI FTW!. It shows that using it to such simple functionality ;;;; gives a bit of overhead. BUT: if you'd like to have some global ;;;; message box style in your application it will surely be worth ;;;; it. Also notice that MessageBox creates separate GUI state so it ;;;; could be simpler. (def message-box (swt [MessageBox [:*id :message-box :*cons [(bit-or SWT/ICON_INFORMATION SWT/OK)] :text "Event Info"]])) (defn show-info-alternative [gui event] (let [box-style (stylesheet [:message-box] [:message (get-info event)]) box-state (message-box (:root @gui) box-style) message-window (:root @box-state)] (.open message-window))) ;;;; END of ALTERNATIVE CODE (def look (stylesheet [:main-window] [:text "SWT FTW!" :size ^unroll (300 200) :layout (FillLayout.)] [:super-button] [:*cons [SWT/PUSH] :text "Make something happen!"])) (def actions (stylesheet [:super-button] [:selection+widget-selected show-info])) (defn -main [& args] (let [gui (window look actions) shell (:root @gui)] (.open shell) (swt-loop shell)))