New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom method call support #1

Closed
mesousa opened this Issue Apr 26, 2011 · 2 comments

Comments

Projects
None yet
2 participants
@mesousa
Copy link
Contributor

mesousa commented Apr 26, 2011

Support for custom method call (not just setter) for an object being created would be nice.
For example:

(def tab1
     (swing
      ;;; some content
      ))
(def gui
     (swing
      [JFrame [:*id :main-window]
       [JTabbedPane [:*id :tabbed]]]))

Now to add tab to window i should do something like this:

(def tabbed (-> @(gui nil) :ids :tabbed))
(.addTab tabbed (:root @(tab1)))

Instead, it would make sense to do something like this in declaration:

(def gui
     (swing
      [JFrame [:*id :main-window]
       [JTabbedPane [:*id :tabbed
            :&add-tab (:root @(tab1))]]]))
@ghost

This comment has been minimized.

Copy link

ghost commented Apr 26, 2011

That's interesting problem and I thought about it and came with different solution: That one could write custom adders (fns that take parent-to-be, child-to-be and their styles and does smth with them). Custom adder would be called instead of default (.add parent object). Example code:

(def window
  (swing [JFrame []
          [JTabbedPane [:*adder (fn [parent parent-style child child-style]
                                  (.addTab parent (:*tab-title child-style) child))]
           [JLabel [:*tab-title "First tab!"]]
           [JLabel [:*tab-title "Second tab!"]]]]))

That will keep elegance of tree structure. Also, only "parenting" logic is altered, logic behind putting objects in gui state is left intact. That means that objects inside JTabbedPane will go into same gui state that all of the others. Notice that in your example added tab is part of different gui state.

It would also solve problem that I was having with JScrolledPane (which doesn't support normal .add too), like this:

(def window
  (swing [JFrame []
          [JScrollPane [:*adder (fn [parent parent-style child child-style]
                                  (.setViewportView parent child))]
           [JTextArea]]]))

Maybe adding support for custom method calls will be helpful in other scenarios but I need to hear more use cases for that :)

@ghost

This comment has been minimized.

Copy link

ghost commented May 15, 2011

See src/guiftw/examples/swing/custom_adders.clj for an example. Run it with lein run -m guiftw.examples.swing.custom-adders :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment