/*
* StyleTree.java
*
* Created on 28 Sep, 2007, 2:43:06 PM
*
*
*/
package org.openoffice.odf.style;
/**
*
* @author amitksaha <amitksaha@openoffice.org>
*/
import javax.swing.tree.DefaultMutableTreeNode;
import java.util.Enumeration;
/*
* Implementation of the Style Hierarchy in ODF documents
* EXPERIMENTAL CODE
*/
public class StyleTree {
private DefaultMutableTreeNode top;
public void getStyle(String style_name) {
//Create the nodes.
top = new DefaultMutableTreeNode(“ODT Style Families”);
createNodes(top);
search(style_name);
}
private void createNodes(DefaultMutableTreeNode top) {
DefaultMutableTreeNode style_family = null;
DefaultMutableTreeNode parent_style = null;
DefaultMutableTreeNode style_name_1 = null;
DefaultMutableTreeNode style_name_2 = null;
DefaultMutableTreeNode style_name_3 = null;
style_family = new DefaultMutableTreeNode(“graphic”);
top.add(style_family);
style_family = new DefaultMutableTreeNode(“Paragraph”);
top.add(style_family);
parent_style = new DefaultMutableTreeNode(“standard”);
style_family.add(parent_style);
style_name_1 = new DefaultMutableTreeNode(“index”);
parent_style.add(style_name_1);
style_name_2 = new DefaultMutableTreeNode(“Text_20_body”);
parent_style.add(style_name_2);
style_name_1 = new DefaultMutableTreeNode(“P1″);
style_name_2.add(style_name_1);
style_name_1 = new DefaultMutableTreeNode(“P2″);
style_name_2.add(style_name_1);
style_name_1 = new DefaultMutableTreeNode(“Heading”);
style_name_2.add(style_name_1);
style_name_1 = new DefaultMutableTreeNode(“List”);
style_name_2.add(style_name_1);
style_name_3 = new DefaultMutableTreeNode(“caption”);
parent_style.add(style_name_3);
style_family = new DefaultMutableTreeNode(“table”);
top.add(style_family);
style_family = new DefaultMutableTreeNode(“table_row”);
top.add(style_family);
}
private void search(String item){
Enumeration res = top.depthFirstEnumeration();
for (; res.hasMoreElements()
{
Object obj = res.nextElement();
//trivial typecast
DefaultMutableTreeNode node = (DefaultMutableTreeNode)obj;
if(item.equals(node.toString())){
//traverse up the tree for the style information
System.out.println(“Style Information for: ” + item);
System.out.println(“Style Family: ” + node.getParent().getParent().getParent().toString());
System.out.println(“Parent Style: ” + node.getParent().getParent().toString());
System.out.println(“Previous Higher Style Category: ” + node.getParent().toString());
}
}
}
}
Posted by amit