jfg

http://jfg.googlecode.com

A simple GUI creator based on reflection. In Java.

Introduction

The idea of this library is to create forms based on object atributes instead of having to write all the layout code by hand. To do that, it uses object reflection and a lightweight MVC model, where the programmer have only to write the model code.

Sometimes you are writing a POC or wants easy access to the attributes of some object (or even wants a simple form requesting some data from an user) but don’t want the burden to write a GUI for that. In this cases jfg came at hand. It allows the creation of simple forms with 2 lines of code, and supports the basic java types, recursive objects (aka one object as a field of the other), static attributes (if it recives a Class) and listeners for the model. It can apply the user input automatically or only when requested. Also, it tries to be very customizable.

For the view, it supports SWT widgets.

For the model, it supports Reflection, a Map of fields or Custom attributes.

Overview

The simplest way to use it is:

// Create the form
  1. JfgFormComposite form = new JfgFormComposite(shell, SWT.NONE);
  2.  
  3. // Add elements to form
  4. form.addContentsFrom(new ReflectionGroup(obj));

full source code

You can use a Map:

// Create the object
  1. Map<String, Object> map = new LinkedHashMap<String, Object>();
  2. map.put("Text", "abcd");
  3. map.put("Number", Integer.valueOf(0));
  4. map.put("Checkbox", Boolean.TRUE);
  5.  
  6. // Create the form
  7. final JfgFormComposite form = new JfgFormComposite(shell, SWT.NONE);
  8.  
  9. // Add elements to form
  10. form.addContentsFrom(new MapGroup(map));

full source code

You can also add custom attributes:

// Create the form
  1. JfgFormComposite form = new JfgFormComposite(shell, SWT.NONE);
  2.  
  3. // Add elements to form
  4. form.add(new AbstractAttribute() {
  5.     public String getName()
  6.     {
  7.         return "gui.name";
  8.     }
  9.     public Object getType()
  10.     {
  11.         return String.class;
  12.     }
  13.     public Object getValue()
  14.     {
  15.         return obj.getName();
  16.     }
  17.     public void setValue(Object value)
  18.     {
  19.         obj.setName((String) value);
  20.     }
  21. });

full source code

Download

Lib: jfg-0.2.jar
Examples: jfg-examples-0.2.zip

Latest Version

jfg 0.2

Sources

SVN at http://jfg.googlecode.com

License

LGPL