Permalink
Browse files

Finished basic cursor implementation. Use :cursor option.

  • Loading branch information...
1 parent 63a47bd commit d609dce886c31bf8699e7a3ee1c3aa61a140be5a @daveray committed Jun 12, 2011
Showing with 22 additions and 3 deletions.
  1. +2 −1 src/seesaw/core.clj
  2. +4 −0 src/seesaw/cursor.clj
  3. +2 −1 src/seesaw/examples/kitchensink.clj
  4. +11 −1 test/seesaw/test/core.clj
  5. +3 −0 test/seesaw/test/cursor.clj
View
3 src/seesaw/core.clj
@@ -18,7 +18,7 @@
(:use [seesaw util meta to-widget]
[clojure.string :only (capitalize split)])
(:require [seesaw color font border invoke timer selection
- event selector icon action cells table graphics bind])
+ event selector icon action cells table graphics bind cursor])
(:import [javax.swing
SwingConstants UIManager ScrollPaneConstants
BoxLayout
@@ -645,6 +645,7 @@
:tip #(.setToolTipText %1 (str (ensure-sync-when-atom %1 :tip %2)))
:text #(.setText %1 (str (ensure-sync-when-atom %1 :text %2)))
:icon #(.setIcon %1 (make-icon (ensure-sync-when-atom %1 :icon %2)))
+ :cursor #(.setCursor %1 (apply seesaw.cursor/cursor (to-seq %2)))
:action #(.setAction %1 (ensure-sync-when-atom %1 :action %2))
:editable? #(.setEditable %1 (boolean (ensure-sync-when-atom %1 :editable? %2)))
:visible? #(.setVisible %1 (boolean (ensure-sync-when-atom %1 :visible? %2)))
View
4 src/seesaw/cursor.clj
@@ -64,6 +64,9 @@
Same for setting the cursor with (seesaw.core/config!).
+ Also, the size of a cursor is platform dependent, so some experimentation
+ will be required with creating custom cursors from images.
+
See:
http://download.oracle.com/javase/6/docs/api/java/awt/Cursor.html
@@ -73,6 +76,7 @@
(cond
; TODO protocol if this gets any more nasty
(keyword? type) (Cursor. (built-in-cursor-map type))
+ (instance? Cursor type) type
(instance? java.awt.Image type) (apply custom-cursor type args)
(instance? javax.swing.ImageIcon type) (apply cursor (.getImage type) args)
:else (throw (IllegalArgumentException. (str "Don't know how to make cursor from " type)))))
View
3 src/seesaw/examples/kitchensink.clj
@@ -50,7 +50,8 @@
:items [(label
:border (line-border)
:text "This label acts like a link"
- :id :link)
+ :id :link
+ :cursor :hand)
(text
:text "HI"
:listen [:action :handler (fn [e] (println (.. (to-widget e) (getText))))])
View
12 test/seesaw/test/core.clj
@@ -9,7 +9,8 @@
; You must not remove this notice, or any other, from this software.
(ns seesaw.test.core
- (:require [seesaw.selector :as selector])
+ (:require [seesaw.selector :as selector]
+ [seesaw.cursor :as cursor])
(:use seesaw.core
seesaw.font
seesaw.graphics
@@ -156,6 +157,15 @@
b (.getBounds p)]
(expect (= [23 45 67 89] [(.x b) (.y b) (.width b) (.height b)])))))
+ (testing "the :cursor option"
+ (it "sets the widget's cursor when given a cursor"
+ (let [c (cursor/cursor :hand)
+ p (apply-default-opts (JPanel.) {:cursor c})]
+ (expect (= c (.getCursor p)))))
+ (it "sets the widget's cursor when given a cursor type keyword"
+ (let [p (apply-default-opts (JPanel.) {:cursor :hand})]
+ (expect (= java.awt.Cursor/HAND_CURSOR (.getType (.getCursor p)))))))
+
(test-option :foreground (color 255 0 0) (color 0 0 0))
(test-option :background (color 255 0 0) (color 0 0 0))
;; TODO: (test-option :border (color 255 0 0) (color 0 0 0))
View
3 test/seesaw/test/cursor.clj
@@ -23,6 +23,9 @@
(describe cursor
(test-built-ins)
+ (it "should return its input if given a cursor"
+ (let [c (cursor :hand)]
+ (expect (= c (cursor c)))))
(it "should create a custom cursor from an image with hotspot (0, 0)"
(let [img (buffered-image 16 16)
cur (cursor img)]

0 comments on commit d609dce

Please sign in to comment.