org.wicketstuff.datatable_autocomplete.tree.TreeVisualizer Maven / Gradle / Ivy
                 Go to download
                
        
                    Show more of this group  Show more artifacts with this name
Show all versions of datatable-autocomplete-test Show documentation
                Show all versions of datatable-autocomplete-test Show documentation
Test code for visualizing a Trie.  Seperated so that projects can use the JUNG visualization against their actual production data
                
             The newest version!
        
        /*
 * 
 * ==============================================================================
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.wicketstuff.datatable_autocomplete.tree;
import java.awt.Dimension;
import javax.swing.JFrame;
import org.apache.commons.collections15.Transformer;
import org.wicketstuff.datatable_autocomplete.trie.TrieNode;
import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.algorithms.layout.TreeLayout;
import edu.uci.ics.jung.graph.DelegateForest;
import edu.uci.ics.jung.graph.DirectedGraph;
import edu.uci.ics.jung.visualization.BasicVisualizationServer;
import edu.uci.ics.jung.visualization.renderers.Renderer.VertexLabel.Position;
/**
 * @author mocleiri
 * 
 */
public class TreeVisualizer
{
	/**
	 * @param graph
	 * 
	 */
	public TreeVisualizer(String title, DirectedGraph, String> graph)
	{
		super();
		// The Layout is parameterized by the vertex and edge types
		Layout, String> layout = new TreeLayout, String>(
			new DelegateForest, String>(graph));
// layout.setSize(new Dimension(300,300)); // sets the initial size of the space
		// The BasicVisualizationServer is parameterized by the edge types
		BasicVisualizationServer, String> vv = new BasicVisualizationServer, String>(
			layout);
		vv.setPreferredSize(new Dimension(350, 350)); // Sets the viewing area size
		vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
		vv.getRenderContext().setVertexLabelTransformer(new Transformer, String>()
		{
			public String transform(TrieNode node)
			{
				return node.getCharacter();
			}
		});
		JFrame frame = new JFrame(title);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().add(vv);
		frame.pack();
		frame.setVisible(true);
	}
}
              © 2015 - 2025 Weber Informatics LLC | Privacy Policy