Created
December 16, 2014 19:59
-
-
Save lsgrep/b2126378a3dfc2d9c1e2 to your computer and use it in GitHub Desktop.
playing with clojure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns learn.ui | |
(:require [seesaw.core :as ui]) | |
(:use seesaw.font) | |
(:require [clj-http.client :as http]) | |
) | |
(def my-frame (ui/frame :title "awesome")) | |
(-> my-frame ui/pack! ui/show!) | |
(def lbl (ui/label "I'm another label")) | |
(ui/config! my-frame :content lbl) | |
(defn display [content] | |
(ui/config! my-frame :content content) | |
content | |
) | |
(display lbl) | |
(ui/config! lbl :background :pink :foreground :red) | |
(ui/config! lbl :font "Monaco") | |
(ui/config! lbl :font (font :name :monospaced | |
:style #{:bold :italic} | |
:size 18 | |
)) | |
(def b (ui/button :text "click Me")) | |
(ui/alert "I am an alert") | |
(display b) | |
(ui/listen b :action (fn [e] (ui/alert e "Thanks!"))) | |
(ui/listen b :mouse-entered #(ui/config! % :foreground :blue) | |
:mouse-exited #(ui/config! % :foreground :red)) | |
(def lb (ui/listbox :model (-> 'seesaw.core ns-publics keys sort))) | |
(display lb) | |
(display (ui/scrollable lb)) | |
(ui/selection lb) | |
(type *1) | |
(ui/selection lb {:multi? true}) | |
(ui/selection! lb 'all-frames) | |
(ui/listen lb :selection (fn[e] (println "Selection is:" (ui/selection e )))) | |
(def field (display (ui/text "This is a text field"))) | |
(ui/text field) | |
(ui/text! field "A new fucking value") | |
(ui/config! field :font "Ubuntu Mono 18" :background "cyan") | |
(def area (ui/text :multi-line? true :font "Monaco 20" | |
:text "This | |
is | |
my | |
multi | |
line | |
shit")) | |
(display area) | |
(print (http/get "http://clojure.org")) | |
(ui/text! area (:body (http/get "http://clojure.org"))) | |
(display (ui/scrollable area)) | |
(ui/scroll! area :to :top) | |
(ui/scroll! area :to :bottom) | |
(ui/scroll! area :to [:line 50]) | |
(def split (ui/left-right-split (ui/scrollable lb) (ui/scrollable area) | |
:divider-location 1/3)) | |
(display split) | |
(defn doc-str [s] | |
(-> (symbol "seesaw.core" (name s)) resolve meta :doc)) | |
(ui/listen lb :selection | |
(fn [e] | |
(when-let [s (ui/selection e)] | |
(-> area | |
(ui/text! (doc-str s)) | |
(ui/scroll! :to :top))))) | |
(def rbs (for [i [:source :doc]] | |
(ui/radio :id i :class :type :text (name i)))) | |
(display (ui/border-panel | |
:north (ui/horizontal-panel :items rbs) | |
:center split | |
:vgap 5 :hgap 5 :border 5)) | |
(ui/select my-frame [:JRadioButton]) | |
(ui/select my-frame [:.type]) | |
(ui/select my-frame [:#source]) | |
(def group (ui/button-group)) | |
(ui/config! (ui/select my-frame [:.type]) :group group) | |
(ui/selection group) | |
(-> group ui/selection ui/id-of) | |
(-> group ui/selection ui/id-of) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment