Menu

#188 VertexIconShapeTransformer assumes ImageIcon

open
nobody
None
5
2012-07-30
2012-07-30
Anonymous
No

As the title says, VertexIconShapeTransformer fails to work for custom Icon implementations.

The "public Shape transform(V v)" would actually be a lot simpler if it just used getIcon{Height, Width}!

Discussion

  • Anonymous

    Anonymous - 2012-07-30

    (of course, it is only simpler if the Icon is to be assumed to be a Rectangle)

     
  • Anonymous

    Anonymous - 2012-07-30

    Also, the caching looks like it is assuming that the Icon for a vertex is never going to change. Not sure that is true...

     
  • Anonymous

    Anonymous - 2012-07-30

    I hope you find the following workaround (rewrite) to be useful. It doesn't require all the map setting. I'm sure it's not too hard to rewrite this to be smarter about ImageIcons (Lombok annotations should produce the obvious boilerplate)

    @RequiredArgsConstructor
    public class VertexIconShapeTransformerFixed<V> implements Transformer<V, Shape> {

    private final Transformer<V, Icon> vertexIconTransformer;

    // https://sourceforge.net/tracker/?func=detail&aid=3552131&group_id=73840&atid=539119
    @Override
    public Shape transform(final V v) {
    Icon icon = vertexIconTransformer.transform(v);
    int width = icon.getIconWidth();
    int height = icon.getIconHeight();
    Rectangle shape = new Rectangle(width, height);
    // fommil: I don't understand why this transformation is needed
    AffineTransform transform = AffineTransform.getTranslateInstance(-width / 2, -height / 2);
    return transform.createTransformedShape(shape);
    }
    }

     
  • Anonymous

    Anonymous - 2012-07-30

    isn't sourceforge so developer friendly the way it formats all my Java workarounds ;-) Happy to send you original .java if you e-mail me.

     

Log in to post a comment.

MongoDB Logo MongoDB