ULC Iconizer

Purpose

This extension provides developers with the concept of Iconizers that allows the simple, fast and consistent creation of fancy (tool bar) button icon effects.

ulc-iconizer

Using iconizers for the creation of a set of consistent icons based on simple source icons has the following advantages:

  • less time-consuming pixel-work in a paint application: global background images are added dynamically, shadows are painted on demand, offsets can be configured, ...
  • more flexibility for global changes: when using a factory approach for creating iconizers, global changes (e.g. new background image for all icons) can be applied in the blink of an eye
  • better consistency: no "one-pixel-shift-errors", configured effects are always applied consistently to the whole set of icons
  • lower bandwidth usage: as the iconizers create the effect-enabled icons directly on the client side, only the source icon(s) for each button has/have to be sent to the client
  • highly customizable and extensible: existing iconizers can be configured in different ways and combined using the provided chaining iconizer. writing custom iconizers is also easy ...

What's new?

  • Iconizer can be used with RadioButton and CheckBox.

How to use

The following shows some features of the iconizers concept.

Creation of a button having effect-enabled icons is straight-forward:

ULCAbstractIconizer iconizer = IconizerFactory.createPressInStyleIconizer();
ULCIcon icon = new ULCIcon(getClass().getResource("/iconA.png"));
ULCIconizedButton iconizedButton = new ULCIconizedButton(icon, iconizer);

When changing an icon during runtime, the iconizer configured for the affected button re-applies its effects to the new source icon. Thus, the following code results to a change in the base icon, but the iconizer effects remain the same:

iconizedButton.setIcon(new ULCIcon(getClass().getResource("/iconB.png"));

In order to disable the iconizer and consequently removing the corresponding effects from the source icon (only displaying the source icon as per default without iconizers), the following is appropriate:

iconizedButton.setIconizer(null);

ULCIconizedButtoninstances do support actions. Using the custom action key ULCIconizedButton.ICONIZER, an inconizer instance can get configured with the action and thus, is set to the button when an action gets set. Also, whenever the value of the action key ULCIconizedButton.ICONIZER changes, the iconizer property of the button gets updated:

private static class IconizerAction extends AbstractAction {

    public IconizerAction(ULCIcon icon, ULCAbstractIconizer iconizer) {
        super(null, icon);

putValue(ULCIconizedButton.ICONIZER, iconizer); }

public void actionPerformed(ActionEvent actionEvent) { } }

...

ULCAbstractIconizer iconizer = … ULCIcon icon = … AbstractAction action = new IconizerAction(icon, iconizer); ULCIconizedButton iconizedButton = new ULCIconizedButton(action);

Iconizer instances can be shared on the server-side. E.g. when creating a set of tool bar buttons that all should have the same iconizer effects applied, a factory method may be useful:

public static ULCButton createToolBarButton(String text, ULCIcon icon) {

    ULCIconizedButton iconizedButton = new ULCIconizedButton(text, icon, getToolBarIconizer());
    …
    return iconizedButton;
}

private static ULCAbstractIconizer getToolBarIconizer() { ULCAbstractIconizer toolBarIconizer = (ULCAbstractIconizer)ApplicationContext.getAttribute("toolBarIconizer"); if (toolBarIconizer == null) { toolBarIconizer = IconizerFactory.createPressInStyleIconizer(); ApplicationContext.setAttribute("toolBarIconizer", toolBarIconizer); } return toolBarIconizer; }

The IconizerFactory provides creators for well-known effects.

Using the ULCIconizerChain class, multiple iconizers can get chained and thus, their functionality is combined.

public static ULCAbstractIconizer createStickOutStyleIconizer() {

    return new ULCIconizerChain(new ULCAbstractIconizer[]{
            new ULCShadowIconizer(0, 2, 0),
            new ULCOffsetIconizer(new Point(0, 0), new Point(-1, -1), new Point(0, 0))
    });

}

How it is implemented

The ULCIconizedButton extends the standard ULCButton and provides the possibility for setting an iconizer. Implementations of ULCAbstractIconizer on the server side also extend the abstract UIAbstractIconizer class on the client side. The corresponding UIAbstractIconizer implementation is responsible for creating an basic IIconizer instance which in fact applies the effects to the server-side configured icons. Icons configured using the corresponding methods setIcon(), setRolloverIcon() and setPressedIcon() on ULCAbstractButton are used as the source icons to which the iconizers apply their effects.

Resources