I am trying to create my own Transformer
for shape and size of nodes in a visualization with JUNG2.
However, I keep running into typing problems. I narrowed down my problem to the following example.
PluggableRenderContext
in JUNG does a simple instantiation of ConstantTransformer
, where V is the vertex type:
protected Transformer<V,Shape> vertexShapeTransformer =
new ConstantTransformer(
new Ellipse2D.Float(-10,-10,20,20));
However, if I do my own instantiation in Scala like so
val vertexShapeTransformer: Transformer[Int, Shape] =
new ConstantTransformer(new Ellipse2D.Float(-10,-10,20,20));
I get a typing error:
type mismatch;
found: org.apache.commons.collections15.functors.ConstantTransformer[java.awt.geom.Ellipse2D.Float]
required: org.apache.commons.collections15.Transformer[Int,java.awt.Shape]"
As far as I understand, the types are conceptually compatible: ConstantTransformer
is-a Transformer[Object, Shape]
and Ellipse2D
is-a Shape
.
I assume it boils down to the fact that Scala's Int
is not an Object
. I cannot find a solution for this problem, though, but cannot imagine that this whole part of the library is rendered unusable as a result.
What can I do about it?
You might need to give scala a little help with the types. I'm not sure if this will work but you could try typing the ConstantTransformer
:
val vertexShapeTransformer: Transformer[Int, Shape] =
new ConstantTransformer[Shape](new Ellipse2D.Float(-10,-10,20,20))
UPDATE
This should work, the type that you can pass to Transformer is anything up to Integer (not Int):
val vertexShapeTransformer: Transformer[_ >: Integer, Shape] =
new ConstantTransformer(new Ellipse2D.Float(-10,-10,20,20))