Package tangowidget.util

Source Code of tangowidget.util.TangoTree

//+============================================================================
//Source: package tangowidget.util;/TangoTree.java
//
//project :     GlobalscreenProject
//
//Description: This class hides
//
//Author: ho
//
//Revision: 1.1
//
//Log:
//
//copyleft :Synchrotron SOLEIL
//      L'Orme des Merisiers
//      Saint-Aubin - BP 48
//      91192 GIF-sur-YVETTE CEDEX
//      FRANCE
//
//+============================================================================
package tangowidget.util;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.io.Serializable;
import java.util.List;
import java.util.StringTokenizer;

import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;

import fr.esrf.tangoatk.core.ATKException;
import fr.esrf.tangoatk.core.AttributeList;
import fr.esrf.tangoatk.core.ConnectionException;
import fr.esrf.tangoatk.core.IAttribute;
import fr.esrf.tangoatk.core.IDevice;
import fr.esrf.tangoatk.core.INumberScalar;
import fr.esrf.tangoatk.widget.device.Tree;
import fr.esrf.tangoatk.widget.device.tree.FamilyNode;
import fr.esrf.tangoatk.widget.device.tree.MemberNode;
import fr.esrf.tangoatk.widget.dnd.NodeFactory;
import globalscreen.application.GlobalBean;
import globalscreen.application.GlobalBeanListener;
import globalscreen.plugins.app.Application;

/**
* @author ho
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class TangoTree extends Tree implements GlobalBean, Serializable, MouseListener{
   
    private static final long serialVersionUID = 1L;
    private boolean        m_isStarted = false;
    private JPopupMenu    m_customPopupMenu = null;


    /**
     *
     */
    public TangoTree() {
        super();
        addMouseListener(this);
        refresh();
  }
   
   
   
    protected void addAttributes(DefaultMutableTreeNode top, AttributeList attributes) {
    NodeFactory nodeFactory = NodeFactory.getInstance();
  IAttribute attribute;
  DefaultMutableTreeNode node;
  for (int j = 0; j < attributes.size(); j++) {
      attribute = (IAttribute)attributes.get(j);
      node = new DefaultMutableTreeNode(nodeFactory.getNode4Entity(attribute));
      top.add(node);
  } // end of for ()
    }
   
    @SuppressWarnings("unchecked")
    protected void addDevices(FamilyNode family, java.util.List devices) {
    MemberNode device = null;
    DefaultMutableTreeNode attributes = null;
    IDevice d;
  
   
    for (int i = 0; i < devices.size(); i++) {
        AttributeList scalarList = new AttributeList();
        AttributeList al = new AttributeList();
  
    d = (IDevice)devices.get(i);
    //System.out.println("devicename = " + d.getName());
    List<?> childrenlist = family.getChildren();
    for(int j = 0 ;  j < childrenlist.size() ; j++)
    {
        MemberNode devicelocal = null;
        //System.out.println("childrenlist[" + j + "] = " + childrenlist.get(j).getClass());
        devicelocal = (MemberNode)childrenlist.get(j);
        if(devicelocal.getName().toLowerCase().equals(d.getName()))
            device = devicelocal;
    }
    //device = family.getChild((d.getName()));
    //System.out.println("device :" + device);
    device.setAttributeList(scalarList);
 
    device.setDevice(d);

    try {
        al.add(d.getName() + "/*");
    } catch (ATKException e) {
  error(e);
    }

    if (al.size() > 0) {
    {
        IAttribute attribute = null;
        for(int j = 0; j < al.size() ; j++)
        {
            attribute = (IAttribute)al.get(j);
            if(attribute instanceof INumberScalar)
          {
                //System.out.println(attribute.getName() + " is a scalar ");
                try
                {
                    scalarList.add(attribute.getName());
                  }
                catch (ConnectionException e1) {}
          }
        }
       
        if (scalarList.size() > 0)
            attributes = new DefaultMutableTreeNode("Attributes");
    }
    device.add(attributes);
  addAttributes(attributes, scalarList);
    }
}
}
   
    /* (non-Javadoc)
     * @see globalscreen.application.GlobalBean#setApplication(globalscreen.plugins.app.Application)
     */
    public void setApplication(Application arg0) {
    }

    /* (non-Javadoc)
     * @see globalscreen.application.GlobalBean#construct()
     */
    public void construct() {
    }

    /* (non-Javadoc)
     * @see globalscreen.application.GlobalBean#start()
     */
    public void start() {
        // System.out.println("START");
        // TODO start method
        m_isStarted = true;
     }

    /* (non-Javadoc)
     * @see globalscreen.application.GlobalBean#stop()
     */
    public void stop() {
        // System.out.println("STOP");
        // TODO stop method
        m_isStarted = false;
    }

    /* (non-Javadoc)
     * @see globalscreen.application.GlobalBean#setGlobalBeanListener(globalscreen.application.GlobalBeanListener)
     */
    public void setGlobalBeanListener(GlobalBeanListener arg0) {
    }
   
    /* (non-Javadoc)
     * @see tangowidget.util.ITangoWidget#isStarted()
     */
    public boolean isStarted() {
        return m_isStarted;
    }
   
    public static void main(String [] args) {
      JFrame frame = new JFrame();
      TangoTree tree = new TangoTree();
      JPopupMenu monPopupMenu = new JPopupMenu();
      monPopupMenu.setDoubleBuffered(true);
      JMenuItem monMenu = new JMenuItem();
      monMenu.setText("MON MENU");
      monPopupMenu.add(monMenu);
     
      tree.setCustomPopupMenu(monPopupMenu);
      tree.setShowEntities(true);
      frame.setContentPane(tree);
      frame.pack();
      frame.setVisible(true);
    }



    /* (non-Javadoc)
     * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
     */
    public void mouseClicked(MouseEvent e) {
        if((m_customPopupMenu != null&& (getSelectionCount() != 0))
        {
          if (e.getClickCount() == 1 && e.getButton() == MouseEvent.BUTTON3)
              m_customPopupMenu.show(e.getComponent(), e.getX(), e.getY());
        }
    }



    /* (non-Javadoc)
     * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
     */
    public void mousePressed(MouseEvent arg0) {
    
    }



    /* (non-Javadoc)
     * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
     */
    public void mouseReleased(MouseEvent arg0) {
      
    }
   
    public String[] getAttributeNameArray()
    {
        String[] attributeArray = new String[getSelectionCount()];
        TreePath[] pathList = getSelectionPaths();
        if(pathList != null)
        {
          for(int i = 0 ; i < pathList.length ; i++)
          {
              attributeArray[i] = getAttributeName(pathList[i]);
              //System.out.println("attributeArray[" + i + "]=" + attributeArray[i]);
          }
        }
        return attributeArray;
    }
   
    public String getAttributeName(TreePath path)
    {
        String attributeName = "";
        //getSelectionPaths();
        if(path != null)
        {
           
            String[] pathArray = null;
            String pathstring = path.toString();
            pathstring = pathstring.substring(1,pathstring.length()- 1);
           
            //System.out.println("pathstring " + pathstring);
           
            StringTokenizer st = new StringTokenizer(pathstring, ",");
            pathArray = new String[st.countTokens()];
            int count = 0;
            while (st.hasMoreTokens())
                pathArray[count++] = st.nextToken().trim();
           
            attributeName = pathArray[1] + "/" + pathArray[2]+ "/" + pathArray[3] + "/" + pathArray[pathArray.length-1];
           // System.out.println("attribute " + attributeName);
           
        }
       
        return attributeName;
    }
  
    /* (non-Javadoc)
     * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
     */
    public void mouseEntered(MouseEvent arg0) {
    }



    /* (non-Javadoc)
     * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
     */
    public void mouseExited(MouseEvent arg0) {
    }

    public JPopupMenu getCustomPopupMenu() {
        return m_customPopupMenu;
    }
   
    public void setCustomPopupMenu(JPopupMenu popupMenu) {
        m_customPopupMenu = popupMenu;
    }
}
TOP

Related Classes of tangowidget.util.TangoTree

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.