add get-colors' to color-database<%>'

This commit is contained in:
Matthew Flatt 2011-11-22 20:17:58 -07:00
parent c7464dcbd3
commit 6a99c93ebb
3 changed files with 22 additions and 6 deletions

View File

@ -7,7 +7,8 @@
color-green
color-blue
color-alpha
color-database<%> the-color-database
(rename-out [color-database-intf color-database<%>])
the-color-database
color->immutable-color)
(define-local-member-name
@ -88,7 +89,13 @@
(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)
(def/public (find-color [string? name])
(let ([name (string-downcase name)])
@ -100,7 +107,9 @@
(send c set-immutable)
(hash-set! color-objects name c)
c)
#f))))))
#f)))))
(def/public (get-names)
(sort (hash-map colors (lambda (k v) k)) string<?)))
(define the-color-database (new color-database<%>))

View File

@ -202,10 +202,16 @@ See also @racket[color%].
@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
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.}
}

View File

@ -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
read and datum->syntax
Added read-intern-literal
racket/draw: added get-names to color-database<%>
mzlib/pconvert: added add-make-prefix-to-constructor parameter,
which changes the default constructor-style printing in DrRacket
to avoid a make- prefix; the HtDP languages set the parameter to #t