From: Lukas P. <pe...@us...> - 2002-08-23 18:20:25
|
Update of /cvsroot/javaprofiler/module/net/sourceforge/javaprofiler/module/nodes In directory usw-pr-cvs1:/tmp/cvs-serv21887 Added Files: RealtimeChildren.java RealtimeTextChildren.java Log Message: added realtime nodes --- NEW FILE: RealtimeChildren.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"); you may not use this file except * in compliance with the License. A copy of the License is available * at http://www.sun.com/ * * The Original Code is the Java Profiler module. The Initial Developers * of the Original Code are Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. * * Portions created by Jan Stola are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Pavel Vacha are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Michal Pise are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Petr Luner are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Lukas Petru are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Marek Przeczek are Copyright (C) 2000-2001. * All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.module.nodes; import java.util.*; import java.beans.FeatureDescriptor; import org.openide.TopManager; import org.openide.nodes.Children; import org.openide.nodes.AbstractNode; import org.openide.nodes.Node; import org.openide.nodes.PropertySupport; import net.sourceforge.javaprofiler.jpi.*; import javax.swing.SwingUtilities; /** This class converts a list of JPI objects into <code>Node</code> objects. * Properly handled classes include <code>ThreadGroupRef</code>, * <code>ThreadRef</code>, <code>ClassRef</code>, <code>TypeRef</code>, <code> * MethodRef</code>. The list is taken from an instance object using specified * getter method and using Reflection. * @author Lukas Petru */ public class RealtimeChildren extends Children.Array { private Object instance; private String getterName; private int childType; private List data=Collections.EMPTY_LIST; private int shownCount; private ChildrenListener listener; public RealtimeChildren(Object object, String getter, int type) { instance=object; getterName=getter; childType=type; } protected Collection initCollection() { try { addChildrenListener(instance, childType); Node.Property pr=new PropertySupport.Reflection(instance, List.class, getterName, null); data=(List) pr.getValue(); } catch (Exception e) { TopManager.getDefault().notifyException(e); } shownCount=data.size(); List nodeList=new ArrayList(); if (data.size()==0) return nodeList; Iterator it=data.iterator(); int i=1; while (it.hasNext()) { Object o=it.next(); Node node=createRealtimeNode(o); node.setName(String.valueOf(i++)); nodeList.add(node); } return nodeList; } void update() { int nw=data.size(); if (nw > shownCount) { List l=data.subList(shownCount, nw); List nodeList=new ArrayList(); Iterator it=l.iterator(); int i=shownCount+1; while (it.hasNext()) { Object o=it.next(); Node node=createRealtimeNode(o); node.setName(String.valueOf(i++)); nodeList.add(node); } add((Node[]) nodeList.toArray(new Node[nw-shownCount])); shownCount=nw; } } private void removeChildrenListener(Object to, int type) { try { to.getClass().getMethod("removeChildrenListener", new Class[]{int.class, ChildrenListener.class}) .invoke(to, new Object[]{new Integer(type), getListener()}); } catch (Exception e) { TopManager.getDefault().notifyException(e); } } private void addChildrenListener(Object to, int type) { try { to.getClass().getMethod("addChildrenListener", new Class[]{int.class, ChildrenListener.class}) .invoke(to, new Object[]{new Integer(type), getListener()}); } catch (Exception e) { TopManager.getDefault().notifyException(e); } } private ChildrenListener getListener() { if (listener==null) { listener=new CustomChildrenListener(this); } return listener; } private Node createRealtimeNode(Object o) { if (o instanceof ThreadRef) { ThreadRef oo=(ThreadRef) o; AbstractNode node=new CallTreeNode(Children.LEAF); node.setDisplayName(oo.getName()); node.setIconBase("/org/openide/resources/beans"); return node; } else if (o instanceof ThreadGroupRef) { ThreadGroupRef oo=(ThreadGroupRef) o; AbstractNode node=new CallTreeNode(Children.LEAF); node.setDisplayName(oo.getName()); node.setIconBase("/org/openide/resources/beans"); return node; } else if (o instanceof ClassRef) { ClassRef oo=(ClassRef) o; AbstractNode node=new CallTreeNode(Children.LEAF); node.setDisplayName(oo.getName()); node.setIconBase("/org/openide/resources/beans"); return node; } else if (o instanceof TypeRef) { TypeRef oo=(TypeRef) o; AbstractNode node=new CallTreeNode(Children.LEAF); node.setDisplayName(oo.getName()); node.setIconBase("/org/openide/resources/beans"); return node; } else if (o instanceof MethodRef) { MethodRef oo=(MethodRef) o; AbstractNode node=new CallTreeNode(Children.LEAF); node.setDisplayName(oo.getName()); node.setIconBase("/org/openide/resources/beans"); return node; } else { // never happens AbstractNode node=new AbstractNode(Children.LEAF); node.setIconBase("/org/openide/resources/pending"); return node; } } } /** This class notifies tied RealtimeChildren object when new children are * available. * @author Lukas Petru */ class CustomChildrenListener implements ChildrenListener { private RealtimeChildren children; public CustomChildrenListener(RealtimeChildren ch) { children=ch; } public void childrenAdded(ChildrenEvent event) { SwingUtilities.invokeLater(new Runnable() { public void run() { children.update(); } }); } public void childrenChanged(ChildrenEvent event) { } } /* * $Log: RealtimeChildren.java,v $ * Revision 1.1 2002/08/23 18:20:18 petrul * added realtime nodes * */ --- NEW FILE: RealtimeTextChildren.java --- /* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"); you may not use this file except * in compliance with the License. A copy of the License is available * at http://www.sun.com/ * * The Original Code is the Java Profiler module. The Initial Developers * of the Original Code are Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. * * Portions created by Jan Stola are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Pavel Vacha are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Michal Pise are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Petr Luner are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Lukas Petru are Copyright (C) 2000-2001. * All Rights Reserved. * * Portions created by Marek Przeczek are Copyright (C) 2000-2001. * All Rights Reserved. * * Contributors: Jan Stola, Pavel Vacha, Michal Pise, Petr Luner, * Lukas Petru and Marek Przeczek. */ package net.sourceforge.javaprofiler.module.nodes; import java.util.*; import org.openide.nodes.Children; import org.openide.nodes.AbstractNode; import org.openide.nodes.Node; import org.openide.nodes.PropertySupport; import net.sourceforge.javaprofiler.jpi.*; /** This class converts a list of String into list of nodes with the same names. * The nodes will have children taken from some list property of realtime * image. The list property is chosen according the String value. * @author Lukas Petru */ public class RealtimeTextChildren extends Children.Array { private String[] texts; public RealtimeTextChildren(String[] text) { texts=text; } protected Collection initCollection() { if (texts.length==0) return Collections.EMPTY_LIST; List nodeList=new ArrayList(); Object parent=((SessionNode) getNode()).getData(); for (int i=0; i<texts.length; i++) { AbstractNode node=new CallTreeNode(new RealtimeChildren(parent, "get"+texts[i], getChildType(texts[i]))); node.setIconBase("/org/openide/resources/groupShadow"); node.setName(texts[i]); nodeList.add(node); } return nodeList; } private int getChildType(String name) { if (name.compareTo("Threads")==0) return Constants.THREAD; else if (name.compareTo("ThreadGroups")==0) return Constants.THREADGROUP; else if (name.compareTo("Classes")==0) return Constants.CLASS; else if (name.compareTo("Types")==0) return Constants.TYPE; else if (name.compareTo("Methods")==0) return Constants.METHOD; else return Constants.NONE; } } /* * $Log: RealtimeTextChildren.java,v $ * Revision 1.1 2002/08/23 18:20:18 petrul * added realtime nodes * */ |