changeset 107:5fdb0bb99f75

Updated dependencies: Clojure 1.3.0, Guava 10.0. Use new CacheBuilder API.
author Mikhail Kryshen <mikhail@kryshen.net>
date Thu, 06 Oct 2011 16:49:14 +0300
parents f42e2b9e1ad9
children 520aa5fa9286
files project.clj src/net/kryshen/indyvon/layers.clj
diffstat 2 files changed, 10 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/project.clj	Wed Sep 21 02:27:11 2011 +0300
+++ b/project.clj	Thu Oct 06 16:49:14 2011 +0300
@@ -1,8 +1,8 @@
 (defproject indyvon "1.0.0-SNAPSHOT"
   :description "INteractive DYnamic VisualizatiON library"
   ;;:warn-on-reflection true
-  :dependencies [[org.clojure/clojure "1.3.0-RC0"]
-                 [com.google.guava/guava "r09"]]
+  :dependencies [[org.clojure/clojure "1.3.0"]
+                 [com.google.guava/guava "10.0"]]
   ;;:aot [net.kryshen.indyvon.core
   ;;      net.kryshen.indyvon.async
   ;;      net.kryshen.indyvon.layers
--- a/src/net/kryshen/indyvon/layers.clj	Wed Sep 21 02:27:11 2011 +0300
+++ b/src/net/kryshen/indyvon/layers.clj	Thu Oct 06 16:49:14 2011 +0300
@@ -28,8 +28,7 @@
    (java.awt.geom AffineTransform Point2D$Double)
    (java.awt.font FontRenderContext TextLayout)
    java.util.concurrent.TimeUnit
-   com.google.common.collect.MapMaker
-   com.google.common.base.Function))
+   (com.google.common.cache Cache CacheBuilder CacheLoader)))
   
 ;; Define as macro to avoid unnecessary calculation of inner and outer
 ;; sizes in the first case.
@@ -169,19 +168,17 @@
 (defn- re-split [^java.util.regex.Pattern re s]
   (seq (.split re s)))
 
-(def ^{:private true} text-layout-cache
-  (-> (MapMaker.)
+(def ^:private ^Cache text-layout-cache
+  (-> (CacheBuilder/newBuilder)
       (.softValues)
       (.expireAfterAccess (long 1) TimeUnit/SECONDS)
-      (.makeComputingMap
-       (reify Function
-         (apply [_ k]
-           (TextLayout. ^String (k 0)
-                        ^Font (k 1)
-                        ^FontRenderContext (k 2)))))))
+      (.build
+       (proxy [CacheLoader] []
+         (load [[^String s ^Font f ^FontRenderContext frc]]
+           (TextLayout. s f frc))))))
 
 (defn- get-text-layout [line font font-context]
-  (get text-layout-cache [line font font-context]))
+  (.get text-layout-cache [line font font-context]))
 
 (defn- layout-text
   [lines ^Font font ^FontRenderContext font-context]