package hep.aida.ref.plotter.style.editor;
/*
 * StyleTreeNode.java
 *
 * Created on June 13, 2005, 6:14 PM
 */

import hep.aida.IBaseStyle;
import hep.aida.IPlotterStyle;
import hep.aida.ref.plotter.BaseStyle;
import hep.aida.ref.plotter.PlotterStyle;
import hep.aida.ref.plotter.Style;

import java.beans.PropertyChangeEvent;
import java.util.List;
import java.util.Vector;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.border.EtchedBorder;
import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;

import com.l2fprod.common.propertysheet.PropertySheetPanel;

/**
 *
 * @author  The FreeHEP team @ SLAC
 */

public class StyleTreeNode implements TreeNode {
    
    private IBaseStyle style;
    private TreePath path;
    private PropertySheetPanel stylePanel;
    //private JScrollPane scrollPanel;
    
    private Vector children;
    private int nChildren;
    private boolean recursive;
    private boolean hasBeenFilled = false;
    private StyleTreeNode parent;
    private TreePath parentPath;
    
    
    // Mainly for constructing root node
    public StyleTreeNode(IPlotterStyle style) {
        this(style, true);
    }
    public StyleTreeNode(IPlotterStyle style, boolean recursive) {
        this(style, null, null, recursive);
    }
    
    // For constructing child nodes
    public StyleTreeNode(IBaseStyle style, StyleTreeNode parent, TreePath parentPath) {
        this(style, parent, parentPath, true);
    }
    public StyleTreeNode(IBaseStyle style, StyleTreeNode parent, TreePath parentPath, boolean recursive) {
        this.style  = style;
        this.parent = parent;
        this.parentPath = parentPath;
        String nodeName = null;
        try {
            if (style instanceof IPlotterStyle && ((BaseStyle) style).isParameterSet(Style.PLOTTER_STYLE_NAME, false))
                nodeName = ((IPlotterStyle) style).parameterValue(Style.PLOTTER_STYLE_NAME);
            
        } catch (Exception e) { e.printStackTrace();}
        if (nodeName == null || nodeName.trim().equals("")) nodeName = style.name();
        if (parentPath == null) path = new TreePath(nodeName);
        else path = parentPath.pathByAddingChild(nodeName);
        
        createChildren();
        
        createPanel();
    }
    
    
    // Service methods
    
    public String toString() { 
        String nodeName = null;
        if (style != null) nodeName = style.name();
        if (path != null) nodeName = path.getLastPathComponent().toString();
        return nodeName;
    }
    
    public IBaseStyle getStyle() {
        return style;
    }
    
    public JComponent getStylePanel() {
        return stylePanel;
    }
    //public JComponent getScrollPanel() {
    //    return scrollPanel;
    //}
    
    private void createChildren() {
        IBaseStyle[] ch = style.children();
        if (ch == null || ch.length == 0) {
            nChildren = 0;
            children = new Vector();
            hasBeenFilled = true;
            return;
        }
        nChildren = ch.length;
        
        if (style instanceof PlotterStyle) {
            List list = ((PlotterStyle) style).parentList();
            if (list != null) nChildren += list.size();
        }
        
        if (recursive) fillChildren();
    }
    
    private void fillChildren() {
        if (children == null) children = new Vector();
        IBaseStyle[] ch = style.children();
        
        if (ch == null) return;
        for (int i=0; i
                    



        
      

Ads help maintain this website.