Hafni is a java swing wrapper for the clojure language focusing on how components change. This means in practice that things that normally wouldn't be changed, or is impossible to change in a convenient way, now is easily changeable and hopefully in a more functional way.
Consider the following example (from Hafni.test.swing.action/button-test2):
(frame :content (comp-and-events (button :name "*") :act (flow (output-arr this :name) >>> (arr #(str % "*")) >>> (input-arr this :name))) :size 200 200 :dont_exit_on_close)
This creates a frame (a window if you so will), with a button as content, size 200x200 and which doesn't close when the frame is closed (useful when working in the repl). It is likely that the code
(comp-and-events (button :name "*") :act (flow (output-arr this :name) >>> (arr #(str % "*")) >>> (input-arr this :name)))
will look very wierd if you haven't read the wiki. That is OK, we will now in a simple (and incomplete) way walk through this code. We first create a button with the text "*".
(button :name "*")
Then, when the button is pressed, the buttons text is extracted, another "*" is added to the end of that text, and set as the current text of the button.
(flow (output-arr this :name) >>> (arr #(str % "*")) >>> (input-arr this :name)))
Thus, the text of the button changes in the following way:
"*" "**" "***" "****"
To accomplish this, Hafni uses the datatypes Event and Arrow which are both explained in the wiki.Wiki/usage
Add [hafni "1.0.1-SNAPSHOT"] as a dependency in leiningen.
To the left is the java class or "functionality", to the right is the function used.
AbstractAction action ButtonGroup button-group JButton button JCheckBox check-box JCheckBoxMenuItem check-box-menu-item JMenuItem menu-item JRadioButton radio-button JRadioButtonMenuItem radio-button-menu-item JToggleButton toggle-button
JComboBox combo-box JList jlist JSpinner spinner JTabbedPane tabbed-pane
JFileChooser/showOpenDialog open-file JFileChooser/showSaveDialog save-file JOptionPane/showMessageDialog error-message info-message message plain-message warning-message JOptionPane/showInputDialog adv-input-dialog text-input-dialog
BorderLayout border-layout BoxLayout box-layout CardLayout card-layout FlowLayout flow-layout
JMenu menu JMenuBar menu-bar JToolBar tool-bar
JPasswordField password-field JTextArea text-area JTextField text-field JTextPane text-pane
File file *path-separator* Font font *available-fonts* Color color
JFrame frame JIcon icon JLabel label JProgressBar progress-bar JScrollPane scroll-pane
Copyright (c) 2011 Jonathan Fischer Friberg
This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.