org.abego.treelayout.util.DefaultConfiguration Java Examples

The following examples show how to use org.abego.treelayout.util.DefaultConfiguration. 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: 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 #2
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 #3
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 #4
Source File: TreeLayoutPerformanceReport.java    From treelayout with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 
 * @param n
 * @return the number of milliseconds to create the tree layout (Time for
 *         creating the tree not included)
 */
private static long layoutRandomTree(int n, int maxChildrenCount,
		Random random) {
	StringTreeNode root = createRandomTree(n, maxChildrenCount, random);

	StringTreeAsTreeForTreeLayout treeForTreeLayout = new StringTreeAsTreeForTreeLayout(
			root);

	long start = System.currentTimeMillis();
	new TreeLayout<StringTreeNode>(treeForTreeLayout,
			new FixedNodeExtentProvider<StringTreeNode>(60, 20),
			new DefaultConfiguration<StringTreeNode>(10, 10));
	long end = System.currentTimeMillis();
	long duration = end - start;

	return duration;
}
 
Example #5
Source File: TreeLayoutTest.java    From treelayout with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testGetBounds() {
	StringTreeNode root = createSampleTree_MultiLineNodes();
	StringTreeAsTreeForTreeLayout tree = new StringTreeAsTreeForTreeLayout(
			root);
	NodeExtentProvider<StringTreeNode> nodeExtentProvider = new MultiLineNodeExtentProvider(
			60, 20, 0);
	DefaultConfiguration<StringTreeNode> config = new DefaultConfiguration<StringTreeNode>(
			10, 10);

	TreeLayout<StringTreeNode> layout = new TreeLayout<StringTreeNode>(
			tree, nodeExtentProvider, config);

	assertEquals(0, layout.getBounds().getX(), 0.0);
	assertEquals(0, layout.getBounds().getY(), 0.0);
	assertEquals(200, layout.getBounds().getWidth(), 0.0);
	assertEquals(70, layout.getBounds().getHeight(), 0.0);
}
 
Example #6
Source File: TreeLayoutTest.java    From treelayout with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void testConstructor() {
	StringTreeNode root = new StringTreeNode("root");
	StringTreeAsTreeForTreeLayout tree = new StringTreeAsTreeForTreeLayout(
			root);
	FixedNodeExtentProvider<StringTreeNode> nodeExtentProvider = new FixedNodeExtentProvider<StringTreeNode>();
	DefaultConfiguration<StringTreeNode> config = new DefaultConfiguration<StringTreeNode>(
			10, 20);

	TreeLayout<StringTreeNode> layout = new TreeLayout<StringTreeNode>(
			tree, nodeExtentProvider, config);

	assertEquals(tree, layout.getTree());
	assertEquals(nodeExtentProvider, layout.getNodeExtentProvider());
	assertEquals(config, layout.getConfiguration());
}
 
Example #7
Source File: TreeLayoutTest.java    From treelayout with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_AlignmentInLevel_TowardsRoot() throws Exception {
	assertEqualsToString(
			"root @ 70,0 (60x20)\nn1\n(first node) @ 0,30 (60x40)\nn2 @ 70,30 (60x20)\nn3\n(last node) @ 140,30 (60x40)\n",
			layout(createSampleTree_MultiLineNodes(),
					new DefaultConfiguration<StringTreeNode>(10,
							10, Location.Top, AlignmentInLevel.TowardsRoot),
					new MultiLineNodeExtentProvider(60, 20, 0)));
}
 
Example #8
Source File: DefaultTreeLayoutConfigurationTest.java    From treelayout with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testConstructor_badGapBetweenNodes() throws Exception {
	try {
		new DefaultConfiguration(0, -1);
		fail("exception expected");
	} catch (Exception ex) {
		assertEquals("gapBetweenNodes must be >= 0", ex.getMessage());
	}
}
 
Example #9
Source File: DefaultTreeLayoutConfigurationTest.java    From treelayout with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testConstructor_badGapBetweenLevels() throws Exception {
	try {
		new DefaultConfiguration(-1, 2);
		fail("exception expected");
	} catch (Exception ex) {
		assertEquals("gapBetweenLevels must be >= 0", ex.getMessage());
	}
}
 
Example #10
Source File: DefaultTreeLayoutConfigurationTest.java    From treelayout with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testConstructor_defaults2() throws Exception {
	DefaultConfiguration config = new DefaultConfiguration(
			1, 2);
	assertEquals(1.0, config.getGapBetweenLevels(1), 0.0);
	assertEquals(2.0, config.getGapBetweenNodes(null, null), 0.0);
	assertEquals(Location.Top, config.getRootLocation());
	assertEquals(AlignmentInLevel.Center, config.getAlignmentInLevel());
}
 
Example #11
Source File: DefaultTreeLayoutConfigurationTest.java    From treelayout with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testConstructor_defaults() throws Exception {
	DefaultConfiguration config = new DefaultConfiguration(
			1, 2, Location.Right);
	assertEquals(1.0, config.getGapBetweenLevels(1), 0.0);
	assertEquals(2.0, config.getGapBetweenNodes(null, null), 0.0);
	assertEquals(Location.Right, config.getRootLocation());
	assertEquals(AlignmentInLevel.Center, config.getAlignmentInLevel());
}
 
Example #12
Source File: DefaultTreeLayoutConfigurationTest.java    From treelayout with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testConstructor() throws Exception {
	DefaultConfiguration config = new DefaultConfiguration(
			1, 2, Location.Right, AlignmentInLevel.AwayFromRoot);
	assertEquals(1.0, config.getGapBetweenLevels(1), 0.0);
	assertEquals(2.0, config.getGapBetweenNodes(null, null), 0.0);
	assertEquals(Location.Right, config.getRootLocation());
	assertEquals(AlignmentInLevel.AwayFromRoot,
			config.getAlignmentInLevel());
}
 
Example #13
Source File: TreeLayoutTest.java    From treelayout with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testBug_CannotHandleNodesWithRedefinedEquals() {
	StringTreeNode root = new StringTreeNode("root",true);
	// add two different nodes that "equal" (because the text is used for
	// "equals" checks) but not identical.
	root.addChild(new StringTreeNode("n1",true));
	root.addChild(new StringTreeNode("n1",true));
	
	// When using "equality" to check nodes in the tree the tree is not
	// layout properly as the "same" node (according to "equals") is in the
	// tree twice.
	StringTreeAsTreeForTreeLayout treeForTreeLayout1 = new StringTreeAsTreeForTreeLayout(
			root);
	TreeLayout<StringTreeNode> layout1 = new TreeLayout<StringTreeNode>(
			treeForTreeLayout1, new FixedNodeExtentProvider<StringTreeNode>(60, 20), new DefaultConfiguration<StringTreeNode>(
							10, 10));
	assertEqualsToString(
			"root @ 0,0 (60x20)\nn1 @ 0,30 (60x20)\nn1 @ 0,30 (60x20)\n",
			layout1);

	// When using "identity" instead (defined by parameter of TreeLayout
	// constructor) the tree layout is fine.
	StringTreeAsTreeForTreeLayout treeForTreeLayout2 = new StringTreeAsTreeForTreeLayout(
			root);
	TreeLayout<StringTreeNode> layout2 = new TreeLayout<StringTreeNode>(
			treeForTreeLayout2, new FixedNodeExtentProvider<StringTreeNode>(60, 20), new DefaultConfiguration<StringTreeNode>(
							10, 10),true);
	assertEqualsToString(
			"root @ 35,0 (60x20)\nn1 @ 0,30 (60x20)\nn1 @ 70,30 (60x20)\n",
			layout2);
}
 
Example #14
Source File: TreeLayoutTest.java    From treelayout with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void testGetNodeBoundsIsCached() {
	StringTreeNode root = new StringTreeNode("root");
	StringTreeAsTreeForTreeLayout tree = new StringTreeAsTreeForTreeLayout(
			root);
	FixedNodeExtentProvider<StringTreeNode> nodeExtentProvider = new FixedNodeExtentProvider<StringTreeNode>();
	DefaultConfiguration<StringTreeNode> config = new DefaultConfiguration<StringTreeNode>(
			10, 20);

	TreeLayout<StringTreeNode> layout = new TreeLayout<StringTreeNode>(
			tree, nodeExtentProvider, config);

	Map<StringTreeNode, Double> nodeBounds = layout.getNodeBounds();
	assertEquals(nodeBounds, layout.getNodeBounds());
}
 
Example #15
Source File: TreeLayoutTest.java    From treelayout with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_AlignmentInLevel_AwayFromRoot() throws Exception {
	assertEqualsToString(
			"root @ 70,0 (60x20)\nn1\n(first node) @ 0,30 (60x40)\nn2 @ 70,50 (60x20)\nn3\n(last node) @ 140,30 (60x40)\n",
			layout(createSampleTree_MultiLineNodes(),
					new DefaultConfiguration<StringTreeNode>(10,
							10, Location.Top, AlignmentInLevel.AwayFromRoot),
					new MultiLineNodeExtentProvider(60, 20, 0)));
}
 
Example #16
Source File: TreeLayoutTest.java    From treelayout with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_AlignmentInLevel_Center() throws Exception {
	assertEqualsToString(
			"root @ 70,0 (60x20)\nn1\n(first node) @ 0,30 (60x40)\nn2 @ 70,40 (60x20)\nn3\n(last node) @ 140,30 (60x40)\n",
			layout(createSampleTree_MultiLineNodes(),
					new DefaultConfiguration<StringTreeNode>(10,
							10, Location.Top, AlignmentInLevel.Center),
					new MultiLineNodeExtentProvider(60, 20, 0)));
}
 
Example #17
Source File: TreeLayoutTest.java    From treelayout with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_RootLocation_Right() throws Exception {
	assertEqualsToString(
			"root @ 140,37 (60x20)\nn1 @ 70,15 (60x20)\nn1.1 @ 0,0 (60x20)\nn1.2 @ 0,30 (60x20)\nn2 @ 70,60 (60x20)\nn2.1 @ 0,60 (60x20)\n",
			layout(createSampleTree_1(),
					new DefaultConfiguration<StringTreeNode>(10,
							10, Location.Right)));
}
 
Example #18
Source File: TreeLayoutTest.java    From treelayout with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_RootLocation_Left() throws Exception {
	assertEqualsToString(
			"root @ 0,37 (60x20)\nn1 @ 70,15 (60x20)\nn1.1 @ 140,0 (60x20)\nn1.2 @ 140,30 (60x20)\nn2 @ 70,60 (60x20)\nn2.1 @ 140,60 (60x20)\n",
			layout(createSampleTree_1(),
					new DefaultConfiguration<StringTreeNode>(10,
							10, Location.Left)));
}
 
Example #19
Source File: TreeLayoutTest.java    From treelayout with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_RootLocation_Bottom() throws Exception {
	assertEqualsToString(
			"root @ 87,60 (60x20)\nn1 @ 35,30 (60x20)\nn1.1 @ 0,0 (60x20)\nn1.2 @ 70,0 (60x20)\nn2 @ 140,30 (60x20)\nn2.1 @ 140,0 (60x20)\n",
			layout(createSampleTree_1(),
					new DefaultConfiguration<StringTreeNode>(10,
							10, Location.Bottom)));
}
 
Example #20
Source File: TreeLayoutTest.java    From treelayout with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void test_RootLocation_Top() throws Exception {
	assertEqualsToString(
			"root @ 87,0 (60x20)\nn1 @ 35,30 (60x20)\nn1.1 @ 0,60 (60x20)\nn1.2 @ 70,60 (60x20)\nn2 @ 140,30 (60x20)\nn2.1 @ 140,60 (60x20)\n",
			layout(createSampleTree_1(),
					new DefaultConfiguration<StringTreeNode>(10,
							10, Location.Top)));

}
 
Example #21
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 #22
Source File: AbegoTreeLayout.java    From fxgraph with Do What The F*ck You Want To Public License 4 votes vote down vote up
public AbegoTreeLayout(double gapBetweenLevels, double gapBetweenNodes, Location location) {
	this(new DefaultConfiguration<ICell>(gapBetweenLevels, gapBetweenNodes, location));
}
 
Example #23
Source File: TreeLayoutTest.java    From treelayout with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
private static TreeLayout<StringTreeNode> layout(StringTreeNode root) {
	return layout(root, new DefaultConfiguration<StringTreeNode>(
			10, 10));
}
 
Example #24
Source File: AbegoTreeLayoutForNetbeans.java    From treelayout with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public AbegoTreeLayoutForNetbeans(N rootNode, int originX, int originY,
		int gapBetweenLevels, int gapBetweenNodes, boolean vertical) {
	this(rootNode, originX, originY, new DefaultConfiguration<N>(
			gapBetweenLevels, gapBetweenNodes, vertical ? Location.Top
					: Location.Left, AlignmentInLevel.TowardsRoot));
}