Skip to content
This repository
Browse code

rsyntax support. See seesaw.rsyntax/text-area.

  • Loading branch information...
commit 19a65bfe29b7c2dd0b87eb3bfe00a42467e93d5b 1 parent 85b2fc7
Dave Ray authored May 07, 2012
66  src/seesaw/rsyntax.clj
... ...
@@ -0,0 +1,66 @@
  1
+;  Copyright (c) Dave Ray, 2012. All rights reserved.
  2
+
  3
+;   The use and distribution terms for this software are covered by the
  4
+;   Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
  5
+;   which can be found in the file epl-v10.html at the root of this
  6
+;   distribution.
  7
+;   By using this software in any fashion, you are agreeing to be bound by
  8
+;   the terms of this license.
  9
+;   You must not remove this notice, or any other, from this software.
  10
+
  11
+(ns ^{:doc "Support for RSyntaxTextArea: http://fifesoft.com/rsyntaxtextarea/index.php"
  12
+      :author "Dave Ray"}
  13
+  seesaw.rsyntax
  14
+  (:require [seesaw.core :as core]
  15
+            [seesaw.util :as util]
  16
+            [seesaw.options :as options]
  17
+            [seesaw.widget-options :as widget-options]
  18
+            clojure.reflect
  19
+            clojure.string)
  20
+  (:import [org.fife.ui.rsyntaxtextarea SyntaxConstants]))
  21
+
  22
+(defn- normalize-style-name [s]
  23
+  (-> (name s)
  24
+    (clojure.string/replace "_" "-")
  25
+    (clojure.string/lower-case)
  26
+    (.substring (count "SYNTAX_STYLE_"))
  27
+    keyword))
  28
+
  29
+(def ^{:private true} syntax-table
  30
+  (->> (clojure.reflect/reflect SyntaxConstants)
  31
+    :members
  32
+    (map :name)
  33
+    ; there's gotta be a better way
  34
+    (map (fn [n]
  35
+           [(normalize-style-name n) (eval `(. SyntaxConstants ~n))]))
  36
+    (into {})))
  37
+
  38
+(def text-area-options
  39
+  (merge
  40
+    core/text-area-options
  41
+    (options/option-map
  42
+      (options/bean-option
  43
+        [:syntax :syntax-editing-style]
  44
+        org.fife.ui.rsyntaxtextarea.RSyntaxTextArea
  45
+        syntax-table
  46
+        nil
  47
+        (keys syntax-table)))))
  48
+
  49
+(widget-options/widget-option-provider
  50
+  org.fife.ui.rsyntaxtextarea.RSyntaxTextArea
  51
+  text-area-options)
  52
+
  53
+(defn text-area
  54
+  "Create a new RSyntaxTextArea.
  55
+
  56
+  In addition to normal seesaw.core/text stuff, supports the following:
  57
+
  58
+    :syntax The syntax highlighting. Defaults to :none. Use
  59
+            seesaw.dev/show-options to get full list.
  60
+
  61
+  See:
  62
+    (seesaw.core/text)
  63
+    http://javadoc.fifesoft.com/rsyntaxtextarea/
  64
+  "
  65
+  [& opts]
  66
+  (apply core/config! (org.fife.ui.rsyntaxtextarea.RSyntaxTextArea.) opts))
1  test/seesaw/test/examples/launcher.clj
@@ -47,6 +47,7 @@
47 47
    'piano
48 48
    'popup
49 49
    'rpn
  50
+   'rsyntax
50 51
    'scribble
51 52
    'scroll
52 53
    'slider
28  test/seesaw/test/examples/rsyntax.clj
... ...
@@ -0,0 +1,28 @@
  1
+;  Copyright (c) Dave Ray, 2012. All rights reserved.
  2
+
  3
+;   The use and distribution terms for this software are covered by the
  4
+;   Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
  5
+;   which can be found in the file epl-v10.html at the root of this 
  6
+;   distribution.
  7
+;   By using this software in any fashion, you are agreeing to be bound by
  8
+;   the terms of this license.
  9
+;   You must not remove this notice, or any other, from this software.
  10
+
  11
+(ns seesaw.test.examples.rsyntax
  12
+  (:use [seesaw core]
  13
+        seesaw.test.examples.example)
  14
+  (:require [seesaw.rsyntax :as rsyntax]
  15
+            [clojure.java.io :as io]))
  16
+
  17
+(defn make-frame []
  18
+  (frame :title "RSyntax Example" :width 500 :height 400 
  19
+    :content (scrollable 
  20
+               (rsyntax/text-area 
  21
+                 :text (io/resource "seesaw/test/examples/rsyntax.clj")
  22
+                 :syntax :clojure))))
  23
+
  24
+(defexample []
  25
+  (make-frame) )
  26
+
  27
+;(run :dispose)
  28
+
22  test/seesaw/test/rsyntax.clj
... ...
@@ -0,0 +1,22 @@
  1
+;  Copyright (c) Dave Ray, 2011. All rights reserved.
  2
+
  3
+;   The use and distribution terms for this software are covered by the
  4
+;   Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
  5
+;   which can be found in the file epl-v10.html at the root of this 
  6
+;   distribution.
  7
+;   By using this software in any fashion, you are agreeing to be bound by
  8
+;   the terms of this license.
  9
+;   You must not remove this notice, or any other, from this software.
  10
+
  11
+(ns seesaw.test.rsyntax
  12
+  (:require [seesaw.rsyntax :as rsyntax]
  13
+            [seesaw.core :as core])
  14
+  (:use [lazytest.describe :only (describe it testing)]
  15
+        [lazytest.expect :only (expect)]))
  16
+
  17
+(describe text-area
  18
+  (it "creates a text area"
  19
+    (let [ta (rsyntax/text-area :syntax :clojure)]
  20
+      (expect (instance? org.fife.ui.rsyntaxtextarea.RSyntaxTextArea ta))
  21
+      (expect (= "text/clojure" (core/config ta :syntax))))))
  22
+

0 notes on commit 19a65bf

Please sign in to comment.
Something went wrong with that request. Please try again.