add get-colors' to
color-database<%>'
This commit is contained in:
parent
c7464dcbd3
commit
6a99c93ebb
|
@ -7,7 +7,8 @@
|
||||||
color-green
|
color-green
|
||||||
color-blue
|
color-blue
|
||||||
color-alpha
|
color-alpha
|
||||||
color-database<%> the-color-database
|
(rename-out [color-database-intf color-database<%>])
|
||||||
|
the-color-database
|
||||||
color->immutable-color)
|
color->immutable-color)
|
||||||
|
|
||||||
(define-local-member-name
|
(define-local-member-name
|
||||||
|
@ -88,7 +89,13 @@
|
||||||
|
|
||||||
(define color-objects (make-hash))
|
(define color-objects (make-hash))
|
||||||
|
|
||||||
(defclass color-database<%> object%
|
(define color-database-intf
|
||||||
|
(let ([color-database<%> (interface ()
|
||||||
|
find-color
|
||||||
|
get-names)])
|
||||||
|
color-database<%>))
|
||||||
|
|
||||||
|
(defclass* color-database<%> object% (color-database-intf)
|
||||||
(super-new)
|
(super-new)
|
||||||
(def/public (find-color [string? name])
|
(def/public (find-color [string? name])
|
||||||
(let ([name (string-downcase name)])
|
(let ([name (string-downcase name)])
|
||||||
|
@ -100,7 +107,9 @@
|
||||||
(send c set-immutable)
|
(send c set-immutable)
|
||||||
(hash-set! color-objects name c)
|
(hash-set! color-objects name c)
|
||||||
c)
|
c)
|
||||||
#f))))))
|
#f)))))
|
||||||
|
(def/public (get-names)
|
||||||
|
(sort (hash-map colors (lambda (k v) k)) string<?)))
|
||||||
|
|
||||||
(define the-color-database (new color-database<%>))
|
(define the-color-database (new color-database<%>))
|
||||||
|
|
||||||
|
|
|
@ -202,10 +202,16 @@ See also @racket[color%].
|
||||||
|
|
||||||
|
|
||||||
@defmethod[(find-color [color-name string?])
|
@defmethod[(find-color [color-name string?])
|
||||||
(or/c (is-a?/c color%) false/c)]{
|
(or/c (is-a?/c color%) #f)]{
|
||||||
|
|
||||||
Finds a color by name (character case is ignored). If no color is
|
Finds a color by name (character case is ignored). If no color is
|
||||||
found for the name, @racket[#f] is returned.
|
found for the name, @racket[#f] is returned.}
|
||||||
|
|
||||||
}}
|
|
||||||
|
@defmethod[(get-names) (listof string?)]{
|
||||||
|
|
||||||
|
Returns an alphabetically sorted list of case-folded color names for which
|
||||||
|
@method[color-database<%> find-color] returns a @racket[color%] value.}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ Regexps are `equal?' when they have the same source [byte] string
|
||||||
Numbers, characters, strings, byte strings, and regexps are interned by
|
Numbers, characters, strings, byte strings, and regexps are interned by
|
||||||
read and datum->syntax
|
read and datum->syntax
|
||||||
Added read-intern-literal
|
Added read-intern-literal
|
||||||
|
racket/draw: added get-names to color-database<%>
|
||||||
mzlib/pconvert: added add-make-prefix-to-constructor parameter,
|
mzlib/pconvert: added add-make-prefix-to-constructor parameter,
|
||||||
which changes the default constructor-style printing in DrRacket
|
which changes the default constructor-style printing in DrRacket
|
||||||
to avoid a make- prefix; the HtDP languages set the parameter to #t
|
to avoid a make- prefix; the HtDP languages set the parameter to #t
|
||||||
|
|
Loading…
Reference in New Issue
Block a user