简体   繁体   English

用JUNG创建“不同”的顶点

[英]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. 基本上,我有一个GraphData.java类,其中包含带有构造函数的静态类,这些构造函数用于使用JUNG程序在Java中制作顶点和边。 One of the properties in the vertex class I have is private int dataType. 我拥有的顶点类中的属性之一是private int dataType。 Based on this dataType (either 1, 2, or 3) the node will be displayed as a circle, square, or triangle. 基于此数据类型(1、2或3),节点将显示为圆形,正方形或三角形。 This I can do when I manually create the nodes in my main class and hardcore the dataType. 当我在主类中手动创建节点并对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. 我想做的是说,常规的左键单击会将dataType设置为1,从而绘制一个圆,但是如果我按住shift并单击鼠标左键,会将dataType设置为2,从而绘制一个正方形,然后按ctrl +单击一个三角形。 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. 您必须使用Transformer,例如扩展EllipseVertexShapeTransformer并在可以更改形状时实现方法转换。 Than, add this Transformer to your VisualizationViewer. 然后,将此Transformer添加到您的VisualizationViewer中。 Also, check source code of JUNG demos - it covers most of cases. 另外,请检查JUNG演示的源代码-它涵盖了大多数情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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