jung 自定义顶点形状或图片
可以变为三角形,正方形,多边形。。
只需将 BasicVisualizationServer升级为VisualizationViewer,然后变换器生成图形,渲染环境即可。
// vv = new BasicVisualizationServer<People, Link>(layout);vv = new VisualizationViewer<People, Link>(layout);// 设置顶点文本标签vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<People>());// 设置边文本标签vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<Link>());//自定义顶点形状//设置顶点形状的显示尺寸为:字符数*8+16Transformer<People, Integer> vst = new Transformer<People, Integer>() {public Integer transform(People i) {int len = i.toString().length();if (len < 3)len = 3;return new Integer(len * 8 + 50);}};//高宽比变换器Transformer<People, Float> vart = new Transformer<People, Float>() {public Float transform(People i) {int len = i.toString().length();if (len < 3)len = 3;return new Float(2.0 / len);}};//构造顶点形状工厂final VertexShapeFactory<People> vsf = new VertexShapeFactory<People>();//设置顶点形状变换器Transformer<People, Shape> vstr = new Transformer<People, Shape>() {public Shape transform(People p) {return vsf.getRectangle(p);}};//将形状变换器置入渲染环境中vv.getRenderContext().setVertexShapeTransformer(vstr);// 响应鼠标事件DefaultModalGraphMouse<People, Link> gm = new DefaultModalGraphMouse<People, Link>();gm.setMode(Mode.PICKING);vv.setGraphMouse(gm);getContentPane().add(vv);pack();--------------------------------------------------------------------------------------------//将顶点设置为图片final ImageIcon ii=new ImageIcon("1.gif");Transformer <Integer, Icon> vit=new Transformer<Integer,Icon>(){public Icon transform(Integer arg0) {return ii;}};vv.getRenderContext().setVertexIconTransformer(vit);vv.getRenderer().getVertexLabelRenderer().setPosition(Position.E);