org.wicketstuff.datatable_autocomplete.tree.TrieVisualizer 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.PatriciaTrie;
import org.wicketstuff.datatable_autocomplete.trie.TrieNode;
import edu.uci.ics.jung.algorithms.layout.DAGLayout;
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.visualization.VisualizationViewer;
import edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse;
import edu.uci.ics.jung.visualization.control.ModalGraphMouse;
import edu.uci.ics.jung.visualization.renderers.Renderer.VertexLabel.Position;
/**
 * @author mocleiri
 * 
 *         To visualize the Patricia-Trie using JUNG.
 * 
 * 
 */
public class TrieVisualizer
{
	private TrieGraph graph;
	/**
	 * @param graph
	 * 
	 */
	public TrieVisualizer(String title, TrieGraph graph, TrieVisualizerLayout layoutType)
	{
		this.graph = graph;
		// The Layout is parameterized by the vertex and edge types
		Layout, String> layout = null;
		switch (layoutType)
		{
			case TREE :
				layout = new TreeLayout, String>(
					new DelegateForest, String>(graph));
				break;
			case DAG :
				layout = new DAGLayout, String>(graph);
				break;
		}
		// layout.setSize(new Dimension(300,300)); // sets the initial size of
		// the space
		// The BasicVisualizationServer is parameterized by the edge types
		VisualizationViewer, String> vv = new VisualizationViewer, 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();
			}
		});
		// Create a graph mouse and add it to the visualization component
		DefaultModalGraphMouse, String> gm = new DefaultModalGraphMouse, String>();
		gm.setMode(ModalGraphMouse.Mode.TRANSFORMING);
		vv.setGraphMouse(gm);
		JFrame frame = new JFrame(title);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().add(vv);
		frame.pack();
		frame.setVisible(true);
	}
	public TrieVisualizer(String title, PatriciaTrie trie, TrieVisualizerLayout layoutType)
	{
		this(title, new TrieGraph(trie), layoutType);
	}
}
                     © 2015 - 2025 Weber Informatics LLC | Privacy Policy