Home > Hafni

Hafni

Hafni is a project mainly written in CLOJURE and PERL, it's free.

Hafni is a java swing wrapper for the clojure language focusing on how components change.

=head1 Hafni

Hafni is a java swing wrapper for the clojure language focusing on how components change. This does not only mean that the content displayed should be easy to change, but also that events coming from that content should be handled in a convenient way.

=head3 Example

This is a small taste of Hafni, for a more thorough explanation of the parts of Hafni, see Usage below. The following example comes from C<Hafni.test.swing.action/button-test2>

(frame :content (comp-and-events (button :text "") :act (flow (output-arr this :text) >>> (arr #(str % "")) >>> (input-arr this :text))) :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).

(comp-and-events (button :text "") :act (flow (output-arr this :text) >>> (arr #(str % "")) >>> (input-arr this :text)))

We first create a button with the text "*".

(button :text "*")

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 :text) >>> (arr #(str % "*")) >>> (input-arr this :text)))

What happens is that C<(output-arr this :name)> receives the current text, which is then sent to the function C<#(str % "*")> (the C can be ignored for now). The result of that function is then sent to the buttons text with C<(input-arr this :text)>. The result is that the text of the button changes in the following way:

"" "" "" "****"

To accomplish this, Hafni uses the datatypes I and I which are both explained in the wiki.

=head2 Usage

=begin html

See Wiki/usage

=end html

=head2 Installation

Add [hafni "1.0.6-SNAPSHOT"] as a dependency in leiningen.

=head2 Reference

To the left is the java class or function that is wrapped, to the right is the corresponding function used in Hafni.

=head3 Hafni.swing.action

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

=head3 Hafni.swing.container

JComboBox combo-box JList jlist JSpinner spinner JTabbedPane tabbed-pane

=head3 Hafni.swing.dialog

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

=head3 Hafni.swing.layout

BorderLayout border-layout BoxLayout box-layout CardLayout card-layout FlowLayout flow-layout GridLayout grid-layout

=head3 Hafni.swing.menu

JMenu menu popup-menu JMenuBar menu-bar JToolBar tool-bar

=head3 Hafni.swing.table

JTable table table-model

=head3 Hafni.swing.text

JPasswordField password-field JTextArea text-area JTextField text-field JTextPane text-pane

=head3 Hafni.swing.tree

JTree tree

=head3 Hafni.swing.utils

File file path-separator Font font available-fonts Color color

=head3 Hafni.swing.view

JFrame frame JIcon icon JLabel label JProgressBar progress-bar JScrollPane scroll-pane MouseInfo mouse-position

=head2 License (zlib)

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.