Skip to content
This repository

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

tree: 9409cd7671

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 src
Octocat-spinner-32 README.pod
Octocat-spinner-32 project.clj
README.pod

Hafni

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.

Example

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.

Usage

See Wiki/usage

Installation

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

Reference

To the left is the java class or "functionality", to the right is the function used.

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

Hafni.swing.container

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

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

Hafni.swing.layout

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

Hafni.swing.menu

 JMenu                  menu
 JMenuBar               menu-bar
 JToolBar               tool-bar

Hafni.swing.table

 JTable                 table
                        table-model

Hafni.swing.text

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

Hafni.swing.tree

 JTree                  tree

Hafni.swing.utils

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

Hafni.swing.view

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

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.

Something went wrong with that request. Please try again.