/ / Selezione per: classe o: id in altalena - interfaccia utente, clojure, altalena

Selezione per: classe o: id in altalena - interfaccia utente, clojure, altalena

Ecco dal tutorial altalena:

(def rbs (for [i [:source :doc]]
(radio :id i :class :type :text (name i))))

(display (border-panel
:north (horizontal-panel :items rbs)
:center split
:vgap 5
:hgap 5
:border 5))

(select f [:JRadioButton])
(select f [:.type])
(select f [:#source])

Quando si seleziona per: class, è stato aggiunto un punto in: type così abbiamo ottenuto: .type, e quando si seleziona per id, è stato aggiunto un # così abbiamo ottenuto: #source, perché?

risposte:

0 per risposta № 1

Questa è solo una parte della sintassi per i selettori che ti permettono di specificare cosa vuoi selezionare.

Il docstring per il select funzione documenta la sintassi completa del selettore. Non copierò l'intera docstring, ma ecco alcuni punti salienti:

[:#id]            ID
[:tag]            "Simple" (not fully-qualified) class name
[:<class-name>]   Fully-qualified class name; also matches subclasses
[:<class-name!>]  Exact class match
[:.<class>]       "Class" match, as set using :class option
[:*]              Everything

Esempi di ciascuno:

;; Widget with ID box1.
(select root [:#box1])
;; Class Label, e.g. com.myns.Label or org.foo.Label.
(select root [:Label])
;; javax.swing.text.JTextComponent and descendants.
(select root [:<javax.swing.text.JTextComponent>])
;; Only javax.swing.text.JTextComponent
(select root [:<javax.swing.text.JTextComponent!>])
;; Class class1, e.g. (flow-panel :class :class1)
(select root [:.class1])
;; Everything
(select root [:*])

Nota anche che questi possono essere combinati, ad es.

;; Everything under widgets with class javax.swing.text.JTextComponent
;; (or subclasses) and class input.
(select root [:<javax.swing.text.JTextComponent>.input :*])