org.abego.treelayout.TreeLayout Java Examples

The following examples show how to use org.abego.treelayout.TreeLayout. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbegoTreeLayoutForNetbeans.java    From treelayout with BSD 3-Clause "New" or "Revised" License 7 votes vote down vote up
@Override
protected void performGraphLayout(UniversalGraph<N, E> graph) {
	if (!graph.getNodes().contains(rootNode)) {
		throw new IllegalArgumentException(
				"graph does not contain rootNode");
	}

	TreeLayout<N> layout = new TreeLayout<N>(new MyTreeForTreeLayout(
			rootNode, graph), new MyNodeExtentProvider(graph),
			configuration);
	Map<N, Rectangle2D.Double> bounds = layout.getNodeBounds();
	for (Map.Entry<N, Rectangle2D.Double> entry : bounds.entrySet()) {
		Rectangle2D.Double rect = entry.getValue();
		Point pt = new Point((int) Math.round(rect.getX() + originX),
				(int) Math.round(rect.getY() + originY));
		setResolvedNodeLocation(graph, entry.getKey(), pt);
	}
}
 
Example #2
Source File: TreeViewer.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void setTree(Tree root) {
	if ( root!=null ) {
		boolean useIdentity = true; // compare node identity
		this.treeLayout =
			new TreeLayout<Tree>(getTreeLayoutAdaptor(root),
								 new TreeViewer.VariableExtentProvide(this),
								 new DefaultConfiguration<Tree>(gapBetweenLevels,
																gapBetweenNodes),
								 useIdentity);
		// Let the UI display this new AST.
		updatePreferredSize();
	}
	else {
		this.treeLayout = null;
		repaint();
	}
}
 
Example #3
Source File: SVGDemo.java    From treelayout with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Returns an SVG text displaying a tree with nodes placed according to a
 * layout created by {@link TreeLayout}.
 * 
 * @param args [unused]
 */
public static void main(String[] args) {
	// get the sample tree
	TreeForTreeLayout<TextInBox> tree = SampleTreeFactory
			.createSampleTree();

	// setup the tree layout configuration
	double gapBetweenLevels = 50;
	double gapBetweenNodes = 10;
	DefaultConfiguration<TextInBox> configuration = new DefaultConfiguration<TextInBox>(
			gapBetweenLevels, gapBetweenNodes);

	// create the NodeExtentProvider for TextInBox nodes
	TextInBoxNodeExtentProvider nodeExtentProvider = new TextInBoxNodeExtentProvider();

	// create the layout
	TreeLayout<TextInBox> treeLayout = new TreeLayout<TextInBox>(tree,
			nodeExtentProvider, configuration);

	// Generate the SVG and write it to System.out
	SVGForTextInBoxTree generator = new SVGForTextInBoxTree(treeLayout);
	System.out.println(generator.getSVG());
}
 
Example #4
Source File: SwingDemo.java    From treelayout with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Shows a dialog with a tree in a layout created by {@link TreeLayout},
 * using the Swing component {@link TextInBoxTreePane}.
 * 
 * @param args args[0]: treeName (default="")
 */
public static void main(String[] args) {
	// get the sample tree
	String treeName = (args.length > 0) ? args[0] : "";
	TreeForTreeLayout<TextInBox> tree = getSampleTree(treeName);
			
	// setup the tree layout configuration
	double gapBetweenLevels = 50;
	double gapBetweenNodes = 10;
	DefaultConfiguration<TextInBox> configuration = new DefaultConfiguration<TextInBox>(
			gapBetweenLevels, gapBetweenNodes);

	// create the NodeExtentProvider for TextInBox nodes
	TextInBoxNodeExtentProvider nodeExtentProvider = new TextInBoxNodeExtentProvider();

	// create the layout
	TreeLayout<TextInBox> treeLayout = new TreeLayout<TextInBox>(tree,
			nodeExtentProvider, configuration);

	// Create a panel that draws the nodes and edges and show the panel
	TextInBoxTreePane panel = new TextInBoxTreePane(treeLayout);
	showInDialog(panel);
}
 
Example #5
Source File: TreePostScriptGenerator.java    From codebuff with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public TreePostScriptGenerator(List<String> ruleNames, Tree root,
							   String fontName, int fontSize)
{
	this.root = root;
	setTreeTextProvider(new TreeViewer.DefaultTreeTextProvider(ruleNames));
	doc = new PostScriptDocument(fontName, fontSize);
	boolean compareNodeIdentities = true;
	this.treeLayout =
		new TreeLayout<Tree>(getTreeLayoutAdaptor(root),
							 new VariableExtentProvide(),
							 new DefaultConfiguration<Tree>(gapBetweenLevels,
															gapBetweenNodes,
															Configuration.Location.Bottom),
                                compareNodeIdentities);
}
 
Example #6
Source File: TextInBoxTreePane.java    From treelayout with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Specifies the tree to be displayed by passing in a {@link TreeLayout} for
 * that tree.
 * 
 * @param treeLayout the {@link TreeLayout} to be displayed
 */
public TextInBoxTreePane(TreeLayout<TextInBox> treeLayout) {
	this.treeLayout = treeLayout;

	Dimension size = treeLayout.getBounds().getBounds().getSize();
	setPreferredSize(size);
}
 
Example #7
Source File: SVGForTextInBoxTree.java    From treelayout with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * @param treeLayout the {@link TreeLayout} to be rendered as SVG
 */
public SVGForTextInBoxTree(TreeLayout<TextInBox> treeLayout) {
	this.treeLayout = treeLayout;
}