<commit_before>; Copyright (c) 2015 <NAME> and contributors. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file LICENSE at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.

(ns ^{:doc "Namespace that contains functions needed for
            defining look functions and obtaining paint
            sequnces from components and containers."
      :author "<NAME>"}
  flatgui.paint
  (:import (clojure.lang Keyword)
           (java.util Collection))
  (:require [flatgui.base :as fg]
            [flatgui.comlogic :as fgc]
            ;[flatgui.access :as access]
            [flatgui.awt :as awt]
            [flatgui.util.matrix :as m]
            [flatgui.util.rectmath :as r]
            ))

(defn get-color-from-component [component color-property]
  "Extracts color property value for component. It may be specified
   directly by absolute value, or by a keyword - reference to
   component's theme which may change during component's lifetime"
  (let [color-property-value (color-property component)]
    (if (nil? color-property-value)
      nil
      (if (keyword? color-property)
        (color-property-value (:theme component))
        color-property-value))))

(defn- empty-paint-seq-element? [e]
  (or (nil? e) (and (coll? e) (empty? e))))

(defn leaf? [v]
  (and
    (not (empty-paint-seq-element? v))
    (not (some (fn [e] (vector? e)) v))))

(defn- filter-nils-out [v]
  (if (and (not (empty? v)) (nil? (first v)))
    []
    v))

(defn- conj-if-not-empty [coll x]
  (if (empty? x)
    coll
    (conj coll x)))

(defn flatten-vector
  "Suppose a vector that does not contain vectors among
   its elements, it the tree leaf. This functions unrolls
   tree-like structure or vectors into single vector that
   contains only leafs. It is supposed that each vector
   may contain either vectors only, or non-vector elements
   only."
  ([preceding v]
    (if (empty-paint-seq-element? v)
      preceding
      (if (leaf? v)
        (conj-if-not-empty preceding (filter-nils-out v))
        (loop [ result preceding
                i 0]
          (if (< i (count v))
            (recur
              (let [ e (nth v i)]
                  (if (leaf? e) (conj-if-not-empty result (filter-nils-out e)) (into result (flatten-vector e))))
              (inc i))
            result)))))
  ([v] (flatten-vector [] v)))

(defn- gen-param-keyword [param]
  (if (keyword? param)
    param
    (first param)))

(defn- gen-param-name [param]
  (symbol (name (gen-param-keyword param))))

(defn- gen-param-binding-value [param]
  `(let [ ~'value (~param ~'comp-property-map)]
    (if (fgc/standard-color? ~'value) (get-color-from-component ~'comp-property-map ~param) ~'value)))
<commit_msg>Doc typo fix<commit_after>; Copyright (c) 2015 <NAME> and contributors. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file LICENSE at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.

(ns ^{:doc "Namespace that contains functions needed for
            defining look functions and obtaining paint
            sequnces from components and containers."
      :author "<NAME>v"}
  flatgui.paint
  (:import (clojure.lang Keyword)
           (java.util Collection))
  (:require [flatgui.base :as fg]
            [flatgui.comlogic :as fgc]
            ;[flatgui.access :as access]
            [flatgui.awt :as awt]
            [flatgui.util.matrix :as m]
            [flatgui.util.rectmath :as r]
            ))

(defn get-color-from-component [component color-property]
  "Extracts color property value for component. It may be specified
   directly by absolute value, or by a keyword - reference to
   component's theme which may change during component's lifetime"
  (let [color-property-value (color-property component)]
    (if (nil? color-property-value)
      nil
      (if (keyword? color-property)
        (color-property-value (:theme component))
        color-property-value))))

(defn- empty-paint-seq-element? [e]
  (or (nil? e) (and (coll? e) (empty? e))))

(defn leaf? [v]
  (and
    (not (empty-paint-seq-element? v))
    (not (some (fn [e] (vector? e)) v))))

(defn- filter-nils-out [v]
  (if (and (not (empty? v)) (nil? (first v)))
    []
    v))

(defn- conj-if-not-empty [coll x]
  (if (empty? x)
    coll
    (conj coll x)))

(defn flatten-vector
  "Suppose a vector that does not contain vectors among
   its elements, it the tree leaf. This function unrolls
   tree-like structure of vectors into single vector that
   contains only leafs. It is supposed that each vector
   may contain either vectors only, or non-vector elements
   only."
  ([preceding v]
    (if (empty-paint-seq-element? v)
      preceding
      (if (leaf? v)
        (conj-if-not-empty preceding (filter-nils-out v))
        (loop [ result preceding
                i 0]
          (if (< i (count v))
            (recur
              (let [ e (nth v i)]
                  (if (leaf? e) (conj-if-not-empty result (filter-nils-out e)) (into result (flatten-vector e))))
              (inc i))
            result)))))
  ([v] (flatten-vector [] v)))

(defn- gen-param-keyword [param]
  (if (keyword? param)
    param
    (first param)))

(defn- gen-param-name [param]
  (symbol (name (gen-param-keyword param))))

(defn- gen-param-binding-value [param]
  `(let [ ~'value (~param ~'comp-property-map)]
    (if (fgc/standard-color? ~'value) (get-color-from-component ~'comp-property-map ~param) ~'value)))

{'fraction_non_alphanumeric': 0.12660764990813428, 'fraction_numerical': 0.0030065141139134794, 'mean_word_length': 2.6623853211009174, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2933496', 'n_tokens_mistral': 1913, 'n_tokens_neox': 1872, 'n_words': 670}