Java源码示例:edu.uci.ics.jung.visualization.decorators.PickableVertexPaintTransformer

示例1
public DrawnIconVertexDemo(final Deployment dm) {
    this.dmodel = dm;
    // create a simple graph for the demo
    graph = new DirectedSparseGraph<Vertex, Edge>();
    vv = new VisualizationViewer<Vertex, Edge>(new SpringLayout2<Vertex, Edge>(graph));

    vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.cyan));
    vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.cyan));

    vv.getRenderContext().setVertexIconTransformer(vertexColor);


    vv.getRenderContext().setVertexFillPaintTransformer(new PickableVertexPaintTransformer<Vertex>(vv.getPickedVertexState(), Color.white, Color.yellow));
    vv.getRenderContext().setEdgeDrawPaintTransformer(edgeColor);

    vv.setBackground(Color.white);

    // add my listener for ToolTips
    vv.setVertexToolTipTransformer(new ToStringLabeller<Vertex>());
}
 
示例2
protected GraphViewer<V, E> createPrimaryGraphViewer(VisualGraphLayout<V, E> layout,
		Dimension viewerSize) {

	//
	// This method can be overridden by subclasses to perform custom creation and setup.
	// Any setup, like renderers, that this class should not override must be put in this
	// method so that subclasses can override.  Common setup items should be in the 
	// method that calls this one.
	//

	GraphViewer<V, E> viewer = new GraphViewer<>(layout, viewerSize);

	Renderer<V, E> renderer = viewer.getRenderer();
	renderer.setVertexRenderer(new VisualVertexRenderer<>());

	RenderContext<V, E> renderContext = viewer.getRenderContext();

	Color normal = Color.GREEN.darker().darker();
	Color selected = Color.GREEN;
	renderContext.setEdgeDrawPaintTransformer(e -> e.isSelected() ? selected : normal);
	renderContext.setArrowDrawPaintTransformer(e -> e.isSelected() ? selected : normal);
	renderContext.setArrowFillPaintTransformer(e -> e.isSelected() ? selected : normal);

	PickedState<V> pickedVertexState = viewer.getPickedVertexState();
	renderContext.setVertexFillPaintTransformer(
		new PickableVertexPaintTransformer<>(pickedVertexState, Color.WHITE, Color.YELLOW));

	viewer.setBackground(Color.WHITE);

	viewer.setGraphOptions(new VisualGraphOptions());

	return viewer;
}