/*
* Copyright (c) 2003, The JUNG Authors
* All rights reserved.
*
* This software is open-source under the BSD license; see either "license.txt"
* or https://github.com/jrtom/jung/blob/master/LICENSE for a description.
*
*/
package edu.uci.ics.jung.samples;
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Paint;
import java.awt.Stroke;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import com.google.common.base.Function;
import com.google.common.base.Functions;
import edu.uci.ics.jung.algorithms.layout.FRLayout;
import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.util.TestGraphs;
import edu.uci.ics.jung.visualization.DefaultVisualizationModel;
import edu.uci.ics.jung.visualization.GraphZoomScrollPane;
import edu.uci.ics.jung.visualization.VisualizationModel;
import edu.uci.ics.jung.visualization.VisualizationViewer;
import edu.uci.ics.jung.visualization.control.CrossoverScalingControl;
import edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse;
import edu.uci.ics.jung.visualization.control.ModalGraphMouse;
import edu.uci.ics.jung.visualization.control.ScalingControl;
import edu.uci.ics.jung.visualization.decorators.ToStringLabeller;
import edu.uci.ics.jung.visualization.renderers.DefaultVertexLabelRenderer;
import edu.uci.ics.jung.visualization.renderers.GradientVertexRenderer;
import edu.uci.ics.jung.visualization.renderers.VertexLabelAsShapeRenderer;
/**
* This demo shows how to use the vertex labels themselves as
* the vertex shapes. Additionally, it shows html labels
* so they are multi-line, and gradient painting of the
* vertex labels.
*
* @author Tom Nelson
*
*/
public class VertexLabelAsShapeDemo extends JApplet {
/**
*
*/
private static final long serialVersionUID = 1017336668368978842L;
Graph graph;
VisualizationViewer vv;
Layout layout;
/**
* create an instance of a simple graph with basic controls
*/
public VertexLabelAsShapeDemo() {
// create a simple graph for the demo
graph = TestGraphs.getOneComponentGraph();
layout = new FRLayout(graph);
Dimension preferredSize = new Dimension(400,400);
final VisualizationModel visualizationModel =
new DefaultVisualizationModel(layout, preferredSize);
vv = new VisualizationViewer(visualizationModel, preferredSize);
// this class will provide both label drawing and vertex shapes
VertexLabelAsShapeRenderer vlasr = new VertexLabelAsShapeRenderer(vv.getRenderContext());
// customize the render context
vv.getRenderContext().setVertexLabelTransformer(
// this chains together Functions so that the html tags
// are prepended to the toString method output
Functions.
Ads help maintain this website.