简体   繁体   中英

Create “different” vertices with JUNG

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

You have to use Transformer, eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM