package jas2.bean;

import javax.swing.*;
import javax.swing.tree.*;
import java.awt.*;
import java.util.*;
import jas2.hist.*;
import jas2.job.HistogramAccess;
import jas2.swingstudio.*;

/**
 * A simple bean designed to be inserted into Web pages within JAS
 * @deprecated Use XMLPlot instead
 */

public class Plot extends JPanel implements PageContextHook
{
    public Plot()
    {
        super(new BorderLayout());
        add(m_hist = new JASHist(),BorderLayout.CENTER);
        setPreferredSize(new Dimension(200,200));
    }
    
    public void setData(String data)
    {
        m_data = data;
    }
    public String getData()
    {
        return m_data;
    }
    private void showData() throws Exception
    {
        JavaAnalysisStudio app = JavaAnalysisStudio.getApp();
        TreeModel model = app.getTreeModel();
        
        StringTokenizer pathTokenizer = new StringTokenizer(m_data,":");
        while (pathTokenizer.hasMoreTokens())
        {
            String path = pathTokenizer.nextToken();
            TreeAdaptorSite node = findNode(model,path);
            Object source = node.getAssociatedObject();
            if (source instanceof DataSource)
            {
                JASHistData hist_data = m_hist.addData((DataSource) source);
                hist_data.show(true);
            }
            else if (source instanceof HistogramAccess)
            {
                JASHistData hist_data = m_hist.addData(((HistogramAccess) source).getData());
                hist_data.show(true);
            }
            else throw new IllegalArgumentException("Path "+path+" does not lead to data");
        }
    }
    protected TreeAdaptorSite findNode(TreeModel model,String path) throws IllegalArgumentException
    {
        TreeAdaptorSite node = (TreeAdaptorSite) model.getRoot();
        StringTokenizer tokenizer = new StringTokenizer(path,"/");
        while (tokenizer.hasMoreTokens())
        {
            TreeAdaptorSite newNode = null;
            String token = tokenizer.nextToken();
            Enumeration children = node.children();
            while (children.hasMoreElements())
            {
                TreeAdaptorSite child = (TreeAdaptorSite) children.nextElement();
                if (child.getName().equals(token))
                {
                    newNode = child;
                    break;
                }
            }
            if (newNode == null) throw new IllegalArgumentException("Node "+token+" in "+path+" not found");
            node = newNode;
        }
        return node;
    }
    public void init(PageContext context) throws Exception
    {
        if (m_data != null) showData();
    }
    public void destroy()
    {
        m_hist.destroy();
    }
    protected String m_data;
    protected JASHist m_hist;
}

 

Ads help maintain this website.