Archive

Archive for February, 2009

Richard Stallman talk in Oslo - impressions

February 28th, 2009
Richard Stallman talking in Oslo

Richard Stallman talking in Oslo. Taken by Gisle Hannemyr. (CC BY-NC-SA 3.0)

Earlier this week, on the 23rd of february, one of the biggest advocates for free software was at Storsalen in Chateau Neuf in Oslo: Richard Stallman. Founder of the Free Software Foundation, initiator of the GNU project and creator of the original emacs. His talk was titled “Copyright vs. Community in the Age of Computer Networks - Free software and beyond”.

Summary below:

Copyright, developed in the age of the printing press, was designed to fit with the system of centralized copying imposed by the printing press. But the copyright system does not fit well with computer networks, and only draconian punishments can enforce it.

The global corporations that profit from copyright are lobbying for draconian punishments, and to increase their copyright powers, while suppressing public access to technology. But if we seriously hope to serve the only legitimate purpose of copyright-to promote progress, for the benefit of the public - then we must make changes in the other direction.

As an introduction, Richard Stallman will speak about the goals and philosophy of the Free Software Movement. The GNU operating system which he launched in 1984 is used by millions of users in conjunction with the kernel, Linux.

He did a brief introduction to to the four freedoms of free software:

  • Freedom 0: The freedom to run the program for any purpose.
  • Freedom 1: The freedom to study and modify the program.
  • Freedom 2: The freedom to copy the program so you can help your neighbor.
  • Freedom 3: The freedom to improve the program, and release your improvements to the public, so that the whole community benefits.

Then he mentioned, briefly the history of GNU and where Linux fits in it. Namely the GNU/Linux naming controversy. Then the real talk started, doing a quick and disputable history of copyright history from people copying text and manuscripts, to the modern printing press and age of computers. He made it clear that copyright differs from patent law and other related laws. So the talk would be focused on copyright. He then moved on to criticizing the entertainment industry such as record companies and other companies that develop and maintain DRM (Digital Restrictions Management [sic]). At the end, he changed in to his alter ego- Saint IGNUcius of the Church of Emacs. Which brought up quite some laughs. Then there was  an audience Q&A.

It would be easy to dismiss Stallman as a raving mad hippie, talking about “the corrupt megacorporations” and undemocratic governments supporting their activities and limiting the freedom of the user. However, he has had such an impact on the development of free software that he is not dismissable. He brings up very many valid points and examples of companies that create software or otherwise make works that benefit the society, unaccessible or restricted.

As games is one of the large competitors to music and film in this generation, in my opinion he should have mentioned more about DRM in games (even though most games are proprietary and thus, an evil that should not be used). Malware such as StarForce and SecuRom, restricting the gamer’s freedom to play the game when he or she wants to and otherwise infringing on all four freedoms of software.

I think the Q&A could have been a panel debate instead. One of the questions from the audience came from the notable Håkon Wium Lie (CSS, web standards). The panel could have consisted of such people and maybe representatives from the government. Notably the school system (how can free software make elementary school pupils free?), NRK etc. The result was that the Q&A was abit messy. Gisle Hannemyr, the debate leader had to cut alot of people short. Some questions (and answers) were very interesting, but some were kind of a waste of time for all parts.

All in all, it was an interesting talk and I felt the audience was at periods quite enraptured. The copyright debate is an important one and highly relevant as the pirate bay trial is ongoing.

Image at the top is taken by Gisle Hannemyr and licensed under CC BY-NC-SA 3.0

Free software , , , , , , , , , ,

Useful Swing libraries for look and feel, layout and data binding

February 2nd, 2009

Recently I’ve been looking into Java Swing development. Last time I touched this was probably 3 years ago, during an undergraduate course. We made some basic GUIs to create family trees and lines pointing to children, parents, siblings etc.

Now, Swing has evolved quite alot since then. Especially with the advent of new libraries to make development easier. I remember some things to be issues with vanilla Swing. Namely, the look and feel, the overhead and complexity of creating layout, and updating the domain model in a way that didn’t break the MVC pattern.

Model-View-Controller (MVC) is an architecture pattern to seperate business logic (Model) from GUI elements (View). In addition, keeping the business logic seperated from the domain model, but it’s not the main point. The Controller acts as a mediator between the user’s actions and the business logic. Typically in a Swing application, it will react to certain events, process and check user input and then pass it down to the business logic.

When looking around for libraries, I had some criterias. There had to be good and easily accessible documentation and less overall overhead than vanilla Swing.

First I tried the GUI builder in Netbeans 6.0 (formerly Project Matisse), which is a very powerful tool for creating Swing desktop applications with little coding overhead. It has a simple drag and drop visual interface. In addition it can bind domain objects to some fields with the beansbinding library. However I found it to be cumbersome to use, customizing code took too long time and anyone that did not use the GUI builder would have had a hard time understanding the messy generated code.

I found three libraries that solved my needs for customizable look and feel, easy layout and data binding. Below I will briefly outline what each library offers and give a very simple example.

Substance

Substance aims to create a fast, solid and extensible library for visually appealing Swing applications. There are alot of options to tweak around with, but the most basic use is given below:

UIManager.setLookAndFeel(new org.jvnet.substance.skin.SubstanceMagmaLookAndFeel());

This sets the look and feel, Magma.

Jgoodies Forms

Jgoodies Forms facilitates the layout process and makes it better.  It has powerful features for creating precise, flexible and more readable layout code.

private JComponent buildPanel() {
    initComponents();
    FormLayout layout = new FormLayout("$lcgap,p,$lcgap,150dlu,$lcgap",
    "$lgap,p,$lgap,p,$lgap,p,$lgap");
    PanelBuilder builder = new PanelBuilder(layout);
    CellConstraints cc = new CellConstraints();

    builder.addSeparator("BookRegistration", cc.xyw(2, 2, 4));
    builder.addLabel("Name", cc.xy(2, 4));
    builder.add(nameField, cc.xy(4, 4));
    builder.addLabel("Author", cc.xy(2, 6));
    builder.add(authorField, cc.xy(4, 6));

    return builder.getPanel();
}

Which will produce something like this (inside a JFrame):

bookapp_form

Intitially the FormLayout might seem like some mumbo-jumbo. But when you get to know it, it starts to make sense. It is very powerful and you can create almost any layout with it. The PanelBuilder has alot of helpers for boilerplate code, such as adding labels and seperators that goes with other typical JComponents.

Jgoodies Binding

Jgoodies Binding main goals are to stream-line the development process for data-binding and assist in seperating the presentation layer from the domain layer.

public class Book extends Model {

    public static final String PROPERTY_NAME = "name";
    public static final String PROPERTY_AUTHOR = "author";
    private String name;
    private String author;

    public Book() {
    }

    public String getAuthor() {
    return author;
    }

    public void setAuthor(String author) {
        String oldAuthor = this.author;
        firePropertyChange(PROPERTY_AUTHOR, oldAuthor, author);
        this.author = author;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        String oldName = this.name;
        firePropertyChange(PROPERTY_NAME, oldName, name);
        this.name = name;
    }
}

/**
* BookApplication class
*/


private void initComponents() {
    nameField = BasicComponentFactory.createTextField(presentationModel.getModel(Book.PROPERTY_NAME),false);
    authorField = BasicComponentFactory.createTextField(presentationModel.getModel(Book.PROPERTY_AUTHOR),false);
    nameLabel = BasicComponentFactory.createLabel(presentationModel.getModel(Book.PROPERTY_NAME));
}

Notice that the Book-class extends the binding-library Model. It is an abstract class to make it easier to change bean properties. Whenever a bean property is set, it fires a property change to notify any listeners that the bean property has changed. The BasicComponentFactory can automagically create various Swing components to listen on ValueModels.

Putting it all together

When all is put together, it looks something like this:

bookapp_all

Here, the name in the Book object is bound to the name JTextField (by referring to PROPERTY_NAME). The JLabel at the bottom listens on any changes and updates itself accordingly.

The many GUI builders out there opts for rapid GUI layout and construction. But in my opinion they suffer from clunky, uncustomizable and hard-to-read generated code. It also makes the project highly dependent on the GUI builder in question. Which is why I have presented three handy libraries for easy, maintainable and cleaner Swing GUI development.

Java, Programming , , , , , , , , , , , , ,