Some libraries were grown up during JaLingo development.

Feel free to contact me if you have any questions.
Drop me a message if you use them in your projects.

jaesar[chicken-monkey]users.sourceforge.net

ActionBinder

ActionBinder ties actions of Swing components to your methods.

In few words: you write small annotations for fields of UI components instead of writing typical inner classes (implementation of listeners).

Let's start with a piece of code:

public class Example1 {
    @NListener ( type = ActionListener.class, mappings = "actionPerformed > ok" )
    private JButton okButton = new JButton( "OK" );

    public Example1() {
        ActionBinder.bind( this );
    }

    public void ok( ActionEvent e ) {
        System.out.println( "ok" );
    }
}
The above code works as if you have actually written:
// compare to old fashion way
public class Example1 {
   private JButton okButton = new JButton( "OK" );

    public Example1() {
        okButton.addActionListener( new ActionListener() {
            public void actionPerformed( ActionEvent e ) {
                ok( e );
            }
        } );
    }

    public void ok( ActionEvent e ) {
        System.out.println( "ok" );
    }
}
Another example that uses boolean filter method feature:
public class Example2 {
    @NListener ( type = ActionListener.class,
                                      mappings = "actionPerformed > askConfirmation > ok" )
    private JButton okButton = new JButton( "OK" );

    public Example2() {
        ActionBinder.bind( this );
    }

    public void ok() {
        System.out.println( "ok" );
    }

    public boolean askConfirmation() {
        return JOptionPane.showConfirmDialog( okButton, "Are you sure?", "Confirmation",
                JOptionPane.YES_NO_OPTION ) == JOptionPane.YES_OPTION;
    }
}
Method "ok" will be invoked if "askConfirmation" method returns true.

The "ok" method has no ActionEvent parameter: you may copy signature from listner's "actionPerfomed( ActionEvent e )" method or leave it without parameters - as you wish.

You can use neested filter methods. For example:
"actionPerformed > askConfirmation > askConfirmation > askConfirmation > ok".

And finally, a complex example:

public class Example3 {
    @NListenerGroup ( {
        @NListener ( type = KeyListener.class, mappings = "keyPressed > onKeyPressed" ),
        @NListener ( property = "document", type = DocumentListener.class, mappings = {
            "insertUpdate > onDocumentInsert",
            "removeUpdate > onDocumentRemove" } ),
        @NListener ( type = MouseListener.class, mappings = {
                "mouseClicked > onMouseClick",
                "mouseEntered > onMouseEnter",
                "mouseExited  > onMouseExit" } )
    } )

    private JTextField field = new JTextField();

    public Example3() {
        ActionBinder.bind( this );
    }

    public void onKeyPressed( KeyEvent e ) {
        System.out.println( "onKeyPressed:"  + e );
    }
    public void onDocumentInsert( DocumentEvent e ) {
        System.out.println( "onDocumentInsert:"  + e );
    }
    public void onDocumentRemove( DocumentEvent e ) {
        System.out.println( "onDocumentRemove:"  + e );
    }
    public void onMouseClick( MouseEvent e ) {
        System.out.println( "onMouseClick:"  + e );
    }
    public void onMouseEnter( MouseEvent e ) {
        System.out.println( "onMouseEnter:"  + e );
    }
    public void onMouseExit( MouseEvent e ) {
        System.out.println( "onMouseExit:"  + e );
    }
}
If you want several @NListeners for a component, put them into a @NListenerGroup
(Java does not allow multiple annotations of the same type per code element).

Imagine, how big and messy would be the same code with lots of inner classes.

Pros and cons
Pros: ActionBinder reduces amount of code by eliminating the need to write listeners.
It keeps all binding configuration in one place: in annotations of fields.

Cons: refactoring tools like IntelliJ IDEA or Eclipse may break the configuration when you rename action methods. Thus you should pay additional attention for it.

Nevertheless, if the refactoring break some bindings, ActionBinder.bind(...) will raise an exception describing what's wrong.

Download JaLingo Libraries 0.6.0 (282KB)

ExternalSort

ExternalSort package allows to sort big amounts of data which do not fit into memory. ExternalSort uses external storage (files, DBs etc.) for paging intermediate sort results.

You provide a comparator, source, destination, persisters of your beans/data and ExternalSorter does the rest. You can replace default storage strategies and sorting algorithms with your ones.

Additionally, you can do merge stuff with ExternalSort's internal class ja.centre.util.sort./external.MergingMultipartReader.

Examples of sorting:
ja.centre.util.sort.external.ExternalSorterTest
ja.lingo.engine.bunchindex.BunchIndexMerger (in JaLingo sources)
ja.lingo.engine.dictionaryindex.builder.sorter.DictionaryIndexSorter (in JaLingo sources)

Examples of merging:
ja.lingo.engine.articlebunchindex.ArticleBunchIndexMerger (in JaLingo sources)

Download JaLingo Libraries 0.6.0 (282KB)

Copyright © 2002-2006 Oleksandr Shyshko,
jaesar[chicken-monkey]users.sourceforge.net
SourceForge Logo GetJava Download Button Support This Project