Skip to content
This repository has been archived by the owner on Nov 26, 2022. It is now read-only.

Commit

Permalink
Canvas class for custom painting support in Swing.
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonrw committed Jun 28, 2011
1 parent 748fafd commit dc045eb
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/guiftw/swing/Canvas.clj
@@ -0,0 +1,33 @@
;; Interface for capturing PaintEvents:
(gen-interface
:name guiftw.swing.PaintListener
:extends [java.util.EventListener]
:methods [[paint [java.awt.Graphics] Object]])

(ns guiftw.swing.Canvas
(:gen-class
:extends javax.swing.JPanel
:main false
:init init
:state painters
:methods [[addPaintListener [guiftw.swing.PaintListener] Object]
[removePaintListener [guiftw.swing.PaintListener] Object]
[getPaintListeners [] clojure.lang.PersistentVector]]))

(defn -init [& args]
[args (atom [])])

(defn -addPaintListener [this listener]
(swap! (.painters this) conj listener))

(defn -removePaintListener [this listener]
(swap! (.painters this)
#(into [] (filter (fn [x] (not= x %2)) %1))
listener))

(defn -getPaintListeners [this]
@(.painters this))

(defn -paintComponent [this g]
(doseq [painter @(.painters this)]
(.paint painter g)))

0 comments on commit dc045eb

Please sign in to comment.