#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

  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous - 2012-07-30

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

     
  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous - 2012-07-30

    conversion of an Icon to an Image, e.g.

    http://stackoverflow.com/questions/5830533

     
  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    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...

     
  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    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);
    }
    }

     
  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    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.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks