irstv/orbisgis — pull request #505 by agouge (2013-08-19 11:34:03+00:00)
Title: Huge refactor

This is a huge refactor of the code which comprises the Simple Style Editor. Not
a whole lot changes visually, but this PR represents a complete reorganization
of the underlying code. For more on this, see the *Developer's notes* section
below.

### Visualize the changes

A picture is worth a thousand words, so please see the class diagrams of the
inheritance [before](https://gist.github.com/agouge/c8ab0b12d26d92ed06dc/raw/4e9f4f04b8b608f837663332df6e5f3979dfe964/old.png) and [after] (https://gist.github.com/agouge/c8ab0b12d26d92ed06dc/raw/24ab369b54e27fca72bae21af3e8a0ab66a3c50d/new.png) the refactor.

## Summary

### Fixed issues

* Fixes #501 - *Add ability to update spinners using the mouse scroll wheel.*
Scroll away!

* Fixes #497 - *Preview not updated correctly when editing the canvas in
Proportional Point*. Now we have a local preview that will be applied if the
user clicks OK and discarded otherwise.

* Fixes #479 - *"Interval Classification - Point" Units ComboBoxes not updating
display correctly*. This actually fixes just the second part, but the first
part is a duplicate of #496. See the *Problems discovered during this
refactor* section below.

* Fixes #503 - *Add proportional spinners*.

* Fixes #504 - *Specify numeric or nonspatial in the field label*.

### Partially fixed issues

* #484 - *Legend panels are being initialized multiple times*.

Much of the work done in this PR is the logical successor of #471, where I
removed 11 unneccessary initializations every time the Simple Style Editor was
opened and 4 (points), 8 (lines) or 11 (polygons) unnecessary initializations
every time a new analysis was created.

The situation is now the following:

* 0 initializations when opening the Simple Style Editor

* 1 (and only 1) initialization when creating a non-classification (unique
or proportional) analysis

* >= 2 initializations when creating a value or interval classification. As
described in #502, the UI is recreated every time the user clicks the
Create button to create a new classification. Once #502 is fixed, #484
will be fixed as well.

* #486 - *Description is not saved in the Rule UI*. Now at least a popup message
warns the user that his description will not be saved.

### Problems discovered during this refactor

* #496 - *Stroke UOM not updated correctly for Interval Classification - Point*.

* #499 - *Wrong preview when removing both border and fill on Unique Symbol - Point*.

* #500 - *Wrong preview when setting a negative symbol width or height*.

* #502 - *Stop classifications from recreating the entire UI*.

## Developer's notes

#### Before

Before this refactor, all code for the Simple Style Editor was contained in the
`org.orbisgis.view.toc.actions.cui.legends package`. More precisely, for each
possible analysis, we had a class which created all components and panels to
assemble a UI. The inheritance was organized in an attempt to reuse some
elements, but unfortunately there were many duplications. For example, there
were 6 different `getUOMCombo` methods, whereas 1 would have sufficed.

In addition, this choice of organization made it impossible for individual
graphical elements to have any inheritance among them. For example, line and
symbol UOM combo boxes, WKN combo boxes and field combo boxes shared no code and
were often implemented in multiple places, adding to the confusion.

Panels were also being initialized up to 3 times when they were created. This
was mainly due to the existence of `setLegend` (not completely removed, but will
be after #502) and `initialize` (completely removed) methods that initialized
the panels and were called in various places. (See #484)

This lack of modularity and abundance of duplication made it difficult to debug
the code, let alone add new features and be confident about their functionality.

#### After

I have created several different packages to better organize the code and
facilitate debugging and new feature implementation. They are:

`org.orbisgis.view.toc.actions.cui.legends.` -->

* `components` - Individual combo boxes, spinners, button groups etc. to be
contained in panels. Inheritance is used as much as possible, and individual
components may be used in various panels.

* `panels` - Individual panels which make up a UI for editing a given style.
Not much inheritance is possible here since panels are generally unique to the
analysis.

* `ui` - an entire UI for a given style. I have conserved the old names but
updated the inheritance, adding `PnlNonClassification` and `PnlProportional`.

I have also removed the initialize methods and moved initialization to the
constructor as much as possible. The `ILegendPanel#setLegend` method has been
removed in all non-classification analyses.

In the `legend` project, I have added a couple missing interfaces to better
organize the code. I often found methods with the same name in many different
classes, but no interface implemented (so that we could use the `@Override`
annotation). New interfaces:

* `IInterpolationLegend`
* `LookupFieldName`

These are in addition to the two interfaces I introduced in fd732d35b234a8a0cae706ab2a8b42329a029281 and the
one @agueganno introduced in b6ec30c77719c6e9341d142223856be7ce0771ce:

* `EnablesStroke`
* `OnVertexOnCentroid`
* `SymbolUom`