Skip to content

odyssomay/Hafni

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 

Repository files navigation

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.

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 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 (output-arr this :name) receives the current text, which is then sent to the function #(str % "*") (the arr can be ignored for now). The result of that function is then sent to the buttons text with (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 Event and Arrow which are both explained in the wiki.

Usage

See Wiki/usage

Installation

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

Reference

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

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
GridLayout              grid-layout

Hafni.swing.menu

JMenu                   menu
                        popup-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
MouseInfo               mouse-position

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.

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published