Commits

Anonymous committed feba33c

Removed old code from cells, added new swing example and fixed new bugs in swing lib.

  • Participants
  • Parent commits 88f8fc2

Comments (0)

Files changed (5)

examples/swing3.clj

+(ns user
+  (:import
+    (javax.swing JFrame JMenuBar JMenu JMenuItem JSeparator))
+  (:use
+    (net.ksojat.neman
+      core
+      [swing :only [swing doswing]])))
+
+(defn run-it []
+  (swing
+    (=> (JFrame. "Frame")
+      :Size [500 300]
+      :DefaultCloseOperation JFrame/DISPOSE_ON_CLOSE
+    
+      (setJMenuBar
+        (=> (JMenuBar.)
+          [(=> [JMenu "&File"]
+             [(=> [JMenuItem "&New [ctrl N]"])
+              (=> [JMenuItem "&Open [ctrl O]"])
+              (JSeparator.)
+              (=> [JMenuItem "&Quit [ctrl Q]"])])
+
+           (=> [JMenu "&Edit"]
+             [(=> [JMenuItem "Cu&t [ctrl X]"])
+              (=> [JMenuItem "&Copy [ctrl C]"])
+              (=> [JMenuItem "&Paste [ctrl V]"])])
+
+           (=> [JMenu "&Help"]
+             [(=> [JMenuItem "&About"])])]))
+
+      :Visible true)))
+
+(doswing
+  (run-it))

neman/cells/src/net/ksojat/neman/cells.clj

 (defn -getValidator [this]
   (.. this state getValidator))
 
-;(defn -addWatch [this watcher action send-off]
-;  (.. this state (addWatch watcher action send-off)))
 (defn -addWatch [this key f]
   (.. this state (addWatch key f)))
 
-;(defn -removeWatch [this watcher]
-;  (.. this state (removeWatch watcher)))
 (defn -removeWatch [this key]
   (.. this state (removeWatch key)))
 
 (defn -notifyWatches [this]
   (.. this state notifyWatches))
 
-;;
-;; Property Listeners
-;;
-
-;(defmulti add-listener
-;  (fn [object property callback] [(class object) property]))
-
-;(defmulti remove-listener
-;  (fn [object listener] [(class object) (class listener)]))
-
-;(import '(javax.swing JTextField)
-;        '(java.awt.event ActionListener ActionEvent))
-
-;(defmethod add-listener [JTextField :text] [object _ callback]
-;  (let [listener (proxy [ActionListener] []
-;                   (actionPerformed [#^ActionEvent e]
-;                     (callback)))]
-;    (.addActionListener object listener)
-;    listener))
-
-;(defmethod remove-listener [JTextField ActionListener] [object listener]
-;  (.removeActionListener object listener))
-
-;;
-;;
-;;
-
-;(defn add-parent-watcher [parent update-fn]
-;  (if (vector? parent)
-;    (let [[object property] parent]
-;      (add-listener object property update-fn))
-;    (let [watcher (agent nil)]
-;      (add-watcher parent :send watcher (fn [& _] (update-fn)))
-;      watcher)))
-
-;(defn remove-parent-watcher [parent watcher]
-;  (if (instance? IRef parent)
-;    (remove-watcher  parent watcher)
-;    (remove-listener parent watcher)))
-
 (defn genkey []
   (keyword (name (gensym))))
 
+; TODO: Fix this, never read parent value with deref, use this value for calculation
 (defn add-parent-watcher [parent update-fn]
   (if (vector? parent)
     (let [[object property] parent]
       (add-property-listener object property (fn [& _] (update-fn))))
-    (let [watcher (agent nil)]
-      (add-watch parent (genkey) (fn [& _] (update-fn)))
-      ;(add-watcher parent :send watcher (fn [& _] (update-fn)))
-      nil)))
+    (add-watch parent (genkey) (fn [& _] (update-fn)))))
 
 (defn remove-parent-watcher [parent watcher]
   (if (instance? IRef parent)
      (update#)
      cell#))
 
-;(use ['net.ksojat.neman.swing :only '(swing-unwrap)])
-
 (defmacro bind [object property parents bindings expr]
   `(let [f# (fn []
               (let

neman/core/src/net/ksojat/neman/core/beans.clj

                (.getEventSetDescriptors (bean-info type)))]
     (if (= (count desc) 1)
       (let [listener (.getListenerType (first desc))]
+        ; TODO: Fix this
         ;(.addMethod event-listener [type action] (fn [& _] [listener action]))
         [listener action]))))
 

neman/core/src/net/ksojat/neman/core/builder.clj

               (and (seq? m) (= (first m) 'clojure.core/unquote))
                 (let [[_ [mf & mr]] m]
                   (recur ms (conj p `(let [x# (unwrap ~gx)] (~mf x# ~@mr)))))
-                  ;(recur ms (conj p `(~mf ~gx ~@mr))))
               (and (seq? m) (= (first m) 'clojure.core/unquote-splicing))
                 (let [[_ m] m]
-                  ; TODO: Unwrap object like in unquote
                   (recur ms (conj p `(do ~m))))
               (keyword? m)
                 (let [[_ val & ms] mx]

neman/swing/src/net/ksojat/neman/swing.clj

   javax.swing.JToolBar  :vector add)
 
 (defmethod patch [javax.swing.JFrame 'add] [f _ x]
-  (.add f (unwrap x) (:layout-data @(.state x))))
+  (if (instance? net.ksojat.neman.swing.Wrapper x)
+    (.add f (unwrap x) (:layout-data @(.state x)))
+    (.add f x)))
+
+(defmethod patch [javax.swing.JPanel 'add] [f _ x]
+  (if (instance? net.ksojat.neman.swing.Wrapper x)
+    (.add f (unwrap x) (:layout-data @(.state x)))
+    (.add f x)))
+
+(defmethod patch [javax.swing.JFrame 'setJMenuBar] [frame _ menu-bar]
+  (.setJMenuBar frame (unwrap menu-bar)))
+
+(defmethod patch [javax.swing.JMenuBar 'add] [menu _ item]
+  (.add menu (unwrap item)))
+
+(defmethod patch [javax.swing.JMenu 'add] [menu _ item]
+  (.add menu (unwrap item)))
+
+(defmethod patch [javax.swing.JSplitPane 'setLeftComponent] [pane _ component]
+  (.setLeftComponent pane (unwrap component)))
+
+(defmethod patch [javax.swing.JSplitPane 'setRightComponent] [pane _ component]
+  (.setRightComponent pane (unwrap component)))
+
+(defmethod patch [javax.swing.JSplitPane 'setTopComponent] [pane _ component]
+  (.setTopComponent pane (unwrap component)))
+
+(defmethod patch [javax.swing.JSplitPane 'setBottomComponent] [pane _ component]
+  (.setBottomComponent pane (unwrap component)))
 
 (defmethod patch [javax.swing.JRadioButtonMenuItem 'setGroup] [o _ g]
   (.add g o))
         (.setDisplayedMnemonicIndex index)))
     x))
 
-(defmethod ctor javax.swing.AbstractButton [c s]
+(defmethod ctor javax.swing.AbstractButton [[c s]]
   (let [o (Reflector/invokeConstructor c RT/EMPTY_ARRAY)]
     (set-abutton o s)))
 
 ;;
 
 (defn swing-wrap [x]
-  (net.ksojat.neman.swing.Wrapper. x))
+  (if (isa? (class x) java.awt.Component)
+    (net.ksojat.neman.swing.Wrapper. x)
+    x))
 
 (defn swing-unwrap [x]
   (if (instance? net.ksojat.neman.swing.Wrapper x)