Introduction

GUI Commands is a comprehensive framework for button, menu and toolbar management in Swing user interface applications. It provides a complete solution that is easy to use, and provides functionality well beyond Swing's in-built Action class.

Why use Commands?

If you've come from a Drag & Drop builder environment you may be wondering why go to all this effort just to create a button. The main difficulty with the Drag & Drop approach is that the behaviour of a button often goes beyond just a simple method call. For example:

  1. You may need to provide multiple button instances.
  2. They may need to be enabled and disabled depending on the application state.
  3. And they may need to be hidden if a user doesn't have the required privileges.

In cases like these the Drag & Drop approach doesn't scale. Worse than that, it often leads to complicated code with hard to find bugs.

The Command style of development provides an Object Oriented approach to buttons and menus. Instead creating buttons, you create commands. You then use the command to create as many buttons or menu items as you require. The command then monitors any appropriate application state. When the state changes the command updates its enabled state and all of its buttons update automatically. This way, all the business rules regarding that command are defined entirely within the command itself.

Grouping Commands Into Menus and Toolbars

GUI Commands goes beyond Swing in that it provides comprehensive support for grouping commands into menus and toolbars. You simply define your menu or toolbar structure and GUI Commands will create and maintain it for you. Groups can contain both commands and other groups. They can be modified at runtime allowing you to create dynamic menus and toolbars will little effort.

Infrastructure

GUI Commands also provides standard infrastructure and mechanisms for performing such common tasks as configuration, delegation, glass pane activation and more. This provides a consistent approach for application development that can be easily understood and applied. This is very important when dealing with larger teams and more complex projects.

Convenience

The combination of commands, groups and common infrastructure allows you create complex functionality quickly and easily. On top of this, the library also provides standard commands for actions such as opening files, displaying recent file lists, closing windows and displaying command descriptions. Beyond this there are many convenience methods that make life easier; ActionCommand.getInvokerWindow() is a typical example.