            (if (not= (:widget-type component) "tablecell") (if (:popup component) (awt/setClip 0 0 clip-w clip-h) (awt/clipRect 0 0 clip-w clip-h)))
            (awt/transform awt-viewport-matrix)
            (paint-component-only component dirty-rects)
-           ;(vec (for [[k v] (:children component)] (paint-component-with-children v dirty-rects)))
            (mapv #(paint-component-with-children % dirty-rects) (sort-by :z-position (for [[_ v] (:children component)] v)))
-
            (awt/transform awt-viewport-matrix-inverse)
            (awt/transform awt-position-matrix-inverse)
-           ;(transform awt-transform-matrix-inverse)
-
-           (if (not= (:widget-type component) "tablecell") (awt/popCurrentClip))
-           ]
-        ))
+           (if (not= (:widget-type component) "tablecell") (awt/popCurrentClip))]))
     (catch Exception e (do
                          (fg/log-debug "Exception " (.getMessage e)
                            " when painting component id = " (:id component)

  "Paints component, does not pait children"
  (if (:visible cmpnt)
    (let [ look-vec (:look-vec cmpnt)]
      (flatten-vector [ (if look-vec look-vec) (if (:has-trouble cmpnt) (trouble-look cmpnt dirty-rects)) ]))
    ))

(defn paint-component-only2 [cmpnt dirty-rects]
  "Paints component, does not pait children"
  (if (and (:visible cmpnt) (:look cmpnt))
    (flatten-vector ((:look cmpnt) cmpnt dirty-rects))
    ))

(defn paint-component-with-children [component dirty-rects]
  "Paints component and its children"
  (try
    (let [ clip-w (m/x (:clip-size component))
           clip-h (m/y (:clip-size component))
           position-matrix (:position-matrix component)
           viewport-matrix (:viewport-matrix component)

          ;transform-matrix (m/mx* position-matrix viewport-matrix)
          ;awt-transform-matrix (affinetransform transform-matrix)
          ;awt-transform-matrix-inverse (invert awt-transform-matrix)

          awt-position-matrix (awt/affinetransform position-matrix)
          awt-viewport-matrix (awt/affinetransform viewport-matrix)
          awt-viewport-matrix-inverse (awt/invert awt-viewport-matrix)
          awt-position-matrix-inverse (awt/invert awt-position-matrix)
          ]
        (flatten-vector
          ; TODO WARNING! This is a temporary hack. Otherwise content-pane children do not respect table clip rect (not= (:widget-type component) "tablecell")
          [(if (not= (:widget-type component) "tablecell")  (awt/pushCurrentClip))

                         (.printStackTrace e)))))

(defn paint-all [container clipx clipy clipw cliph]
  (paint-component-with-children container nil))

;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;; New painting approach optimized for web
;;;;;;;;;;;;;;;;;;;;;;;;

(defmulti extract-value (fn [property _ _] (class property)))

(defmethod extract-value Keyword [property f container]
  (f (property container)))

(defmethod extract-value Collection [property f container]
  ;; This reduce accumulates bit flags
  (reduce #(+ (* 2 %1) %2) 0 (for [p property] (f (p container)))))

(defn- get-component-id-path-to-property-value [id-path container property f]
  (let [this-id-path (fgc/conjv id-path (:id container))]
    (apply
      merge
      {this-id-path (extract-value property f container)}
      (for [[_ v] (:children container)] (get-component-id-path-to-property-value this-id-path v property f)))))

(defn get-component-id-path-to-position-matrix [container]
  (get-component-id-path-to-property-value [] container :position-matrix awt/affinetransform))

(defn get-component-id-path-to-viewport-matrix [container]
  (get-component-id-path-to-property-value [] container :viewport-matrix awt/affinetransform))

(defn get-component-id-path-to-clip-size [container]
  (get-component-id-path-to-property-value [] container :clip-size (fn [c] [(m/x c) (m/y c)])))

(defn get-component-id-path-to-look-vector [container]
  (get-component-id-path-to-property-value [] container :look-vec identity))

(defn get-component-id-path-to-child-count [container]
  (get-component-id-path-to-property-value [] container :children count))

(defn get-component-id-path-to-flags [container]
  (get-component-id-path-to-property-value [] container [:rollover-notify-disabled :popup :visible] (fn [v] (if v 1 0))))

(defn get-component-id-path-to-image-url [container]
      (get-component-id-path-to-property-value [] container :image-url identity))

(defn- ready-for-paint? [container]
  (and
    (:position-matrix container)
    (:viewport-matrix container)
    (:clip-size container)
    (:look-vec container)))

;;;
;;; TODO sort by z-order here?
;;;
(defn get-paint-all-sequence
  ([id-path container]
    (if (ready-for-paint? container)
      (apply concat
             [(conj id-path (:id container))]
             (for [[_ v] (:children container)] (get-paint-all-sequence (conj id-path (:id container)) v)))
     []))
  ([container] (get-paint-all-sequence [] container)))



;;;;;;;;;;;;;;
;;;;;;;;;;;;;; Old experimental approaches
;;;;;;;;;;;;;;

;(defn paint-component-only2 [cmpnt dirty-rects]
;  "Paints component, does not pait children"
;  (if (and (:visible cmpnt) (:look cmpnt))
;    (flatten-vector ((:look cmpnt) cmpnt dirty-rects))
;    ))

;(defn get-dirty-rect-from-container [container]
;  (let [ r (:dirty-rect container)]
;    (if r
;      [(double (:x r)) (double (:y r)) (double (:w r)) (double (:h r))])))

;;@todo with such approach clip rect should be passed to evolve
;;
