Menu

#1 custom drawing and algorithms

open
nobody
None
5
2006-04-28
2006-04-28
No

The treemap library allows the consumer to specify the
filling to be used when drawing each node. However, I
want to do more customization of the drawing of each node.

The drawing of each node is done by the fillNode method
of the TMAlorithm class. This seems to me a slightly
strange place to put this code as my changes affect the
border (I want to indicate which node is currectly
'selected'), and the contents of the leaf nodes. This
is independent of the algormithm used to layout the
nodes. But that is not a problem, I only use the
squarified algorithm so I can derive from
TMAlgorithmSquarified and override fillNode.

The problem now is that there is no method by which I
can pass my new algorithm class to the treemap code.
You allow us only to pass a name, from which the
alorithm class is looked-up. I find this strange
design because it adds complexity and restricts the
library users with no apparent benefit. Why did you do
this? The obvious way would be to pass the algormithm
implementation object directly:

<code>
view.setAlgorithm(new TMAlgorithmSquarified());
</code>

This has the following advantages:
1. It is simpler
2. The application can pass its own algorithm, and not
be restricted to the two provided
3. Parameters can be passed to the algorithm
constructor (they can be set by fetching the algormithm
object back from the view and calling a set method, but
what about algorithm specific parameters that do not
have setters in TMAlgorithm?)

Add the following method and deprecate the placing of
algorithms in store and the name strings.

<code>
public void setAlgorithm(TMAlgorithm algorithm) {
drawer = algorithm;
repaint();
}
</code>

- Nigel Westbury

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.