Skip to content

Instantly share code, notes, and snippets.

View daveray's full-sized avatar

Dave Ray daveray

View GitHub Profile
@daveray
daveray / gist:1000703
Created May 31, 2011 15:39
setVisible
import java.awt.BorderLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class VisibleButton {
@daveray
daveray / gist:1000729
Created May 31, 2011 15:47
seesaw setvisible
(frame :resizable? true
:content (vertical-panel
:id :panel
:items
[(button :text "show button 2"
:listen [:action (fn [e]
(let [btn (select (to-frame e) [:#btn])]
(.setVisible btn true)))])
(doto (button :id :btn :text "here I am") (.setVisible false))]))
@daveray
daveray / JSplitPainInTheAss.java
Created June 12, 2011 21:05
Workaround JSplitPane.setDividerLocation without resorting to sub-classing and other abominations.
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.HierarchyEvent;
import java.awt.event.HierarchyListener;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSplitPane;
@daveray
daveray / seesaw-tests.txt
Created June 14, 2011 00:42
Seesaw Tests
Namespaces
seesaw.test.event
#'seesaw.event/unappend-listener
can remove a listener
#'seesaw.event/listen
can install a mouse-clicked listener
returns a function that will remove the installed listener
can install two mouse-clicked listeners
can install a document listener
can register for a class of events
@daveray
daveray / gist:1040586
Created June 22, 2011 17:17
AWT ScrollPane with Seesaw
(defn heavy-scrollable [target]
(doto (java.awt.ScrollPanel.)
(.add target)))
(show! (frame :content (heavy-scrollable (... make a PApplet))))
@daveray
daveray / pi.clj
Created June 23, 2011 02:54
Seesaw Ad Hoc StyleSheet
(ns pi.core
(:use seesaw.core))
(native!)
(def gap [:fill-h 5])
; Set up the structure of the ui, giving widgets classes and ids as needed.
(defn make-frame []
(frame
@daveray
daveray / main_view.clj
Created June 28, 2011 00:01
Hugo in Seeesaw
(ns hugo.views.main-view
(:use hugo.db.sqlite)
(:use [seesaw core color]))
(defn create-home-view [data]
(show!
(frame
:title "@rippinrobr's Hugo Best Novel Database"
:on-close :exit
:size [500 :by 600]
@daveray
daveray / gist:1055523
Created June 30, 2011 02:49
Async Workflows in Seesaw
(ns seesaw.async
(:use [seesaw core]))
; see http://dotnetslackers.com/articles/net/Programming-user-interfaces-using-f-sharp-workflows.aspx#1478
(defmacro async
"Macro that executes an async call (the first form), ignores its result, and the
executes the body normally."
[async-call & body]
`(~@(apply list (first async-call) `(fn [& args#] ~@body) (rest async-call))))
@daveray
daveray / async.clj
Created July 10, 2011 01:34
Cancelable Asyn
(defprotocol Async
(run-async* [this continue])
(cancel-async* [this]))
(defn await-event
"Awaits the given event on the given target asynchronuously. Passes on the
event to the continuation."
[target event]
(let [remove-fn (promise)]
(reify Async
@daveray
daveray / test.soar
Created August 2, 2011 12:33
Emulating CSoar's 'cmd' function in JSoar
# Emulating CSoar's cmd function in JSoar
# Install a fake "cmd" RHS function.
script javascript {
soar.rhsFunction({
name: "cmd",
execute: function(context, args) {
var cmd = "";
for(var i = 0; i < args.length; i++) {
cmd = cmd + args[i] + " ";