Reputation: 21
Basically I have a class, GraphData.java, that contains static classes with constructors for making vertices and edges in my Java with JUNG program. One of the properties in the vertex class I have is private int dataType. Based on this dataType (either 1, 2, or 3) the node will be displayed as a circle, square, or triangle. This I can do when I manually create the nodes in my main class and hardcore the dataType. I'm looking for a more dynamic solution.
What I want to be able to do is say regular left click will set dataType to 1 thus draw a circle, but if I hold shift and left click it will set dataType to 2 thus drawing a square and ctrl + click for a triangle. Does anyone know how to do this? Thanks in advance.
Here is the mouse that I'm currently using:
EditingModalGraphMouse gm = new EditingModalGraphMouse(vv.getRenderContext(),
GraphData.MyVertexFactory.getInstance(),
GraphData.MyEdgeFactory.getInstance());
Upvotes: 1
Views: 643
Reputation: 2968
You have to use Transformer, e.g. extend EllipseVertexShapeTransformer and implement method transform when you can change your shape. Than, add this Transformer to your VisualizationViewer. Also, check source code of JUNG demos - it covers most of cases.
Upvotes: 1