Update of /cvsroot/javaprofiler/module/net/sourceforge/javaprofiler/module/nodes In directory usw-pr-cvs1:/tmp/cvs-serv3565 Added Files: InterfaceRepository.java PDataChildren.java PDataNode.java PSelectorChildren.java SnapshotNode2.java Log Message: nodes, version 2 --- NEW FILE: InterfaceRepository.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 net.sourceforge.javaprofiler.jpi.*; class InterfaceRepository { private static boolean isInit=false; private static Map class2Type=null; public static int objectType(Object sample) { init(); Iterator it=class2Type.entrySet().iterator(); while (it.hasNext()) { java.util.Map.Entry entry=(java.util.Map.Entry) it.next(); Class testClass=(Class) entry.getKey(); if (testClass.isInstance(sample)) return ((Integer) entry.getValue()).intValue(); } throw new IllegalArgumentException("Illegal:"+String.valueOf(sample)); } public static int[] getChildTypes(int type) { switch(type) { case Constants.NONE: return new int[]{Constants.THREAD, Constants.CPU_TRACE, Constants.MON_TRACE, Constants.TYPE, Constants.ALLOC_TRACE, Constants.THREADGROUP, Constants.CLASS}; case Constants.THREAD: return new int[]{Constants.CPU_THREAD_TRACE, Constants.MON_THREAD_TRACE}; case Constants.CPU_TRACE: return new int[]{Constants.FRAME, Constants.CPU_THREAD_TRACE}; case Constants.CPU_THREAD_TRACE: return new int[]{}; case Constants.MON_TRACE: return new int[]{Constants.FRAME, Constants.MON_THREAD_TRACE}; case Constants.MON_THREAD_TRACE: return new int[]{}; case Constants.TYPE: return new int[]{Constants.ALLOC_TYPE_TRACE}; case Constants.ALLOC_TRACE: return new int[]{Constants.FRAME, Constants.ALLOC_TYPE_TRACE}; case Constants.ALLOC_TYPE_TRACE: return new int[]{}; case Constants.THREADGROUP: return new int[]{Constants.THREAD}; case Constants.CLASS: return new int[]{Constants.FIELD, Constants.METHOD}; case Constants.METHOD: return new int[]{}; case Constants.FIELD: return new int[]{}; } throw new IllegalArgumentException("Illegal:"+String.valueOf(type)); } public static String getListName(int type) { switch(type) { case Constants.THREAD: return "Threads"; case Constants.CPU_TRACE: return "CPUTraces"; case Constants.CPU_THREAD_TRACE: return "CPUThreadTraces"; case Constants.MON_TRACE: return "MonTraces"; case Constants.MON_THREAD_TRACE: return "MonThreadTraces"; case Constants.TYPE: return "Types"; case Constants.ALLOC_TRACE: return "AllocTraces"; case Constants.ALLOC_TYPE_TRACE: return "AllocTypeTraces"; case Constants.FRAME: return "Frames"; case Constants.THREADGROUP: return "ThreadGroups"; case Constants.CLASS: return "Classes"; case Constants.METHOD: return "Methods"; case Constants.FIELD: return "Fields"; } throw new IllegalArgumentException(String.valueOf(type)); } public static String getSelectorIconBase(int type) { switch(type) { case Constants.FRAME: return "/net/sourceforge/javaprofiler/module/resources/" + "FramesNodeIcon"; default: return "/org/openide/resources/localFS"; } } private static void init() { if (!isInit) { class2Type=new HashMap(); class2Type.put(VirtualMachineImageRef.class, new Integer(Constants.NONE)); class2Type.put(ThreadRef.class, new Integer(Constants.THREAD)); class2Type.put(CPUTraceRef.class, new Integer(Constants.CPU_TRACE)); class2Type.put(CPUThreadTraceRef.class, new Integer(Constants.CPU_THREAD_TRACE)); class2Type.put(MonTraceRef.class, new Integer(Constants.MON_TRACE)); class2Type.put(MonThreadTraceRef.class, new Integer(Constants.MON_THREAD_TRACE)); class2Type.put(TypeRef.class, new Integer(Constants.TYPE)); class2Type.put(AllocTraceRef.class, new Integer(Constants.ALLOC_TRACE)); class2Type.put(AllocTypeTraceRef.class, new Integer(Constants.ALLOC_TYPE_TRACE)); class2Type.put(FrameRef.class, new Integer(Constants.FRAME)); class2Type.put(ThreadGroupRef.class, new Integer(Constants.THREADGROUP)); class2Type.put(ClassRef.class, new Integer(Constants.CLASS)); class2Type.put(MethodRef.class, new Integer(Constants.METHOD)); class2Type.put(FieldRef.class, new Integer(Constants.FIELD)); isInit=true; } } } /* * $Log: InterfaceRepository.java,v $ * Revision 1.1 2002/08/28 18:02:38 petrul * nodes, version 2 * */ --- NEW FILE: PDataChildren.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.Node; import org.openide.nodes.AbstractNode; import net.sourceforge.javaprofiler.jpi.*; import net.sourceforge.javaprofiler.module.sheets.*; class PDataChildren extends Children.Array { private final List data; PDataChildren(List list) { data=list; } protected Collection initCollection() { 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=createNode(o); node.setName(String.valueOf(i++)); nodeList.add(node); } return nodeList; } private Node createThreadRef(ThreadRef oo) { AbstractNode node=new PDataNode(new PSelectorChildren(oo), new ThreadSheet(oo)); node.setDisplayName(oo.getName()); node.setIconBase("/org/openide/resources/beans"); return node; } private Node createCPUTraceRef(CPUTraceRef oo) { AbstractNode node=new PDataNode(new PSelectorChildren(oo), new CPUSheet(oo)); node.setDisplayName(oo.toString()); node.setIconBase("/org/openide/resources/beans"); return node; } private Node createCPUThreadTraceRef(CPUThreadTraceRef oo) { AbstractNode node=new PDataNode(Children.LEAF, new CPUSheet(oo)); node.setDisplayName(oo.toString()); node.setIconBase("/org/openide/resources/beans"); return node; } private Node createMonTraceRef(MonTraceRef oo) { AbstractNode node=new PDataNode(new PSelectorChildren(oo), new MonSheet(oo)); node.setDisplayName(oo.toString()); node.setIconBase("/org/openide/resources/beans"); return node; } private Node createMonThreadTraceRef(MonThreadTraceRef oo) { AbstractNode node=new PDataNode(Children.LEAF, new MonSheet(oo)); node.setDisplayName(oo.toString()); node.setIconBase("/org/openide/resources/beans"); return node; } private Node createTypeRef(TypeRef oo) { AbstractNode node=new PDataNode(new PSelectorChildren(oo), new TypeSheet(oo)); node.setDisplayName(oo.toString()); node.setIconBase("/org/openide/resources/beans"); return node; } private Node createAllocTraceRef(AllocTraceRef oo) { AbstractNode node=new PDataNode(new PSelectorChildren(oo), new AllocSheet(oo)); node.setDisplayName(oo.toString()); node.setIconBase("/org/openide/resources/beans"); return node; } private Node createAllocTypeTraceRef(AllocTypeTraceRef oo) { AbstractNode node=new PDataNode(Children.LEAF, new AllocSheet(oo)); node.setDisplayName(oo.toString()); node.setIconBase("/org/openide/resources/beans"); return node; } private Node createFrameRef(FrameRef oo) { AbstractNode node=new AbstractNode(Children.LEAF); node.setDisplayName(oo.toString()); node.setIconBase("/org/openide/resources/beans"); return node; } private Node createThreadGroupRef(ThreadGroupRef oo) { AbstractNode node=new PDataNode(new PSelectorChildren(oo), new ThreadgroupSheet(oo)); node.setDisplayName(oo.toString()); node.setIconBase("/org/openide/resources/beans"); return node; } private Node createClassRef(ClassRef oo) { AbstractNode node=new PDataNode(new PSelectorChildren(oo), new ClassSheet(oo)); node.setDisplayName(oo.toString()); node.setIconBase("/org/openide/resources/beans"); return node; } private Node createMethodRef(MethodRef oo) { AbstractNode node=new PDataNode(Children.LEAF, new MethodSheet(oo)); node.setDisplayName(oo.toString()); node.setIconBase("/org/openide/resources/beans"); return node; } private Node createFieldRef(FieldRef oo) { AbstractNode node=new PDataNode(Children.LEAF, new FieldSheet(oo)); node.setDisplayName(oo.toString()); node.setIconBase("/org/openide/resources/beans"); return node; } private Node createNode(Object o) { if (o instanceof ThreadRef) { return createThreadRef((ThreadRef) o); } else if (o instanceof CPUTraceRef) { return createCPUTraceRef((CPUTraceRef) o); } else if (o instanceof CPUThreadTraceRef) { return createCPUThreadTraceRef((CPUThreadTraceRef) o); } else if (o instanceof MonTraceRef) { return createMonTraceRef((MonTraceRef) o); } else if (o instanceof MonThreadTraceRef) { return createMonThreadTraceRef((MonThreadTraceRef) o); } else if (o instanceof TypeRef) { return createTypeRef((TypeRef) o); } else if (o instanceof AllocTraceRef) { return createAllocTraceRef((AllocTraceRef) o); } else if (o instanceof AllocTypeTraceRef) { return createAllocTypeTraceRef((AllocTypeTraceRef) o); } else if (o instanceof FrameRef) { return createFrameRef((FrameRef) o); } else if (o instanceof ThreadGroupRef) { return createThreadGroupRef((ThreadGroupRef) o); } else if (o instanceof ClassRef) { return createClassRef((ClassRef) o); } else if (o instanceof MethodRef) { return createMethodRef((MethodRef) o); } else if (o instanceof FieldRef) { return createFieldRef((FieldRef) o); } else { // never happens AbstractNode node=new AbstractNode(Children.LEAF); node.setDisplayName("error"); node.setIconBase("/org/openide/resources/pending"); return node; } } } /* * $Log: PDataChildren.java,v $ * Revision 1.1 2002/08/28 18:02:38 petrul * nodes, version 2 * */ --- NEW FILE: PDataNode.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 org.openide.nodes.AbstractNode; import org.openide.nodes.Children; import org.openide.nodes.Sheet; import org.openide.util.HelpCtx; import net.sourceforge.javaprofiler.module.sheets.SheetFactory; /** An enhancement to <code>AbstractNode</code> adding support for <code> * SheetFactory</code>. It also disables copy action. * @author Lukas Petru */ public class PDataNode extends AbstractNode { private SheetFactory sheet; public PDataNode(Children children) { this(children, null); } public PDataNode(Children children, SheetFactory shFactory) { super(children); sheet=shFactory; } public Sheet createSheet() { Sheet res=(sheet!=null) ? sheet.create() : super.createSheet(); sheet=null; return res; } public boolean canCopy() { return false; } public HelpCtx getHelpCtx() { return new HelpCtx(getClass()); } } --- NEW FILE: PSelectorChildren.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.TopManager; import org.openide.nodes.Children; import org.openide.nodes.Node; import org.openide.nodes.AbstractNode; import org.openide.nodes.PropertySupport; import net.sourceforge.javaprofiler.jpi.VirtualMachineImageRef; class PSelectorChildren extends Children.Array { private final Object source; PSelectorChildren(Object selectFrom) { source=selectFrom; } protected Collection initCollection() { int type=InterfaceRepository.objectType(source); int[] childTypes=InterfaceRepository.getChildTypes(type); if (childTypes.length==0) return Collections.EMPTY_LIST; List nodeList=new ArrayList(); nodeList.addAll(getSpecialNodes()); for (int i=0; i<childTypes.length; i++) { String listName=InterfaceRepository.getListName(childTypes[i]); List childrenList=getChildren(source, "get" + listName); Children children; if (childrenList.size()==0) children=Children.LEAF; else children=new PDataChildren(childrenList); AbstractNode node=new AbstractNode(children); node.setName(listName); node.setDisplayName(listName); // icon node.setIconBase(InterfaceRepository.getSelectorIconBase( childTypes[i])); nodeList.add(node); } return nodeList; } private List getChildren(Object parent, String getter) { try { Node.Property pr=new PropertySupport.Reflection(parent, List.class, getter, null); List data=(List) pr.getValue(); return data; } catch (Exception e) { TopManager.getDefault().notifyException(e); throw new RuntimeException(getter); } } List getSpecialNodes() { int type=InterfaceRepository.objectType(source); if (source instanceof VirtualMachineImageRef) { List nodeList=new ArrayList(); VirtualMachineImageRef ref=(VirtualMachineImageRef) source; AbstractNode node=new CallTreeNode(new CallTreeChildren( ref.getThreadGroups())); node.setName("CallTree"); node.setDisplayName("Call Tree"); node.setIconBase( "/net/sourceforge/javaprofiler/module/resources/CallTreeIcon"); nodeList.add(node); node=new CallTreeNode(new BacktraceChildren( ref.getCPUTraces(), 1)); node.setName("Backtrace"); node.setDisplayName("Merg CPUTraces"); node.setIconBase( "/net/sourceforge/javaprofiler/module/resources/BacktraceIcon"); nodeList.add(node); return nodeList; } else return Collections.EMPTY_LIST; } } /* * $Log: PSelectorChildren.java,v $ * Revision 1.1 2002/08/28 18:02:38 petrul * nodes, version 2 * */ --- NEW FILE: SnapshotNode2.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.io.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.*; import javax.swing.*; import javax.swing.border.TitledBorder; import org.openide.*; import org.openide.actions.*; import org.openide.nodes.*; import org.openide.filesystems.*; import org.openide.loaders.DataFolder; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; import org.openide.util.actions.SystemAction; import net.sourceforge.javaprofiler.jpi.VirtualMachineImageRef; import net.sourceforge.javaprofiler.module.data.Snapshot; import net.sourceforge.javaprofiler.module.actions.*; import net.sourceforge.javaprofiler.module.data.ProfilerData; /** * Node for one snapshot. * * @author Jan Stola, LukasPetru */ public class SnapshotNode2 extends AbstractNode implements SnapshotCookie { private Snapshot snapshot; private static ResourceBundle bundle=NbBundle.getBundle(SnapshotNode.class); public SnapshotNode2(Snapshot snapshot) { super(new PSelectorChildren(snapshot.getSnapshot())); this.snapshot=snapshot; setIconBase("/net/sourceforge/javaprofiler/module/resources/SnapshotNodeIcon"); setDisplayName(snapshot.getName()); setShortDescription(NbBundle.getMessage(SnapshotNode.class, "HINT_snapshotNode")); getCookieSet().add(this); } /** Returns the <code>Snapshot</code> object that is represented by this * node. */ public Snapshot getSnapshot() { return snapshot; } protected SystemAction[] createActions() { return new SystemAction[] { SystemAction.get(CloseSnapshotAction.class), SystemAction.get(SaveSnapshotAction.class), null, SystemAction.get(PropertiesAction.class) }; } public HelpCtx getHelpCtx() { return new HelpCtx(SnapshotNode.class); } protected Sheet createSheet() { Sheet sheet=super.createSheet(); Sheet.Set props=sheet.get(Sheet.PROPERTIES); if (props==null) { props=Sheet.createPropertiesSet(); sheet.put(props); } props.put(new PropertySupport.ReadWrite("name", String.class, bundle.getString("LBL_snapshotName"), bundle.getString("HINT_snapshotName")) { public Object getValue() { return snapshot.getName(); } public void setValue(Object o) { snapshot.setName((String)o); SnapshotNode2.this.setDisplayName(snapshot.getName()); } }); props.put(new PropertySupport.ReadOnly("time", long.class, bundle.getString("LBL_snapshotTime"), bundle.getString("HINT_snapshotTime")) { public Object getValue() { return new Long(snapshot.getSnapshot().time()); } }); props.put(new PropertySupport.ReadOnly("totalMemory", long.class, bundle.getString("LBL_totalMemory"), bundle.getString("HINT_totalMemory")) { public Object getValue() { return new Long(snapshot.getSnapshot().totalMemory()); } }); props.put(new PropertySupport.ReadOnly("freeMemory", long.class, bundle.getString("LBL_freeMemory"), bundle.getString("HINT_freeMemory")) { public Object getValue() { return new Long(snapshot.getSnapshot().freeMemory()); } }); props.put(new PropertySupport.ReadOnly("takenMemory", long.class, bundle.getString("LBL_takenMemory"), bundle.getString("HINT_takenMemory")) { public Object getValue() { return new Long(snapshot.getSnapshot().totalMemory()-snapshot.getSnapshot().freeMemory()); } }); return sheet; } public boolean canCopy() { return false; } /** * Closes the snapshot. */ public boolean close() { ProfilerData.getData().removeSnapshot(snapshot); return true; } /** * Saves the snapshot. */ public void save() { final DataFolderPanel dfp=new DataFolderPanel(); DialogDescriptor dd=new DialogDescriptor(dfp, bundle.getString("LBL_saveSnapshotDialog"), true, new ActionListener() { public void actionPerformed(ActionEvent evt) { ObjectOutputStream oos=null; try { DataFolder df=(DataFolder)dfp.getPropertyValue(); FileObject pf=df.getPrimaryFile(); FileObject fo=pf.createData(dfp.getSnapshotName(), "snapshot"); //NOI18N FileLock fl=fo.lock(); OutputStream os=fo.getOutputStream(fl); oos=new ObjectOutputStream(os); oos.writeObject(snapshot.getSnapshot()); } catch (Exception e) { TopManager.getDefault().notifyException(e); } finally { try { if (oos!=null) oos.close(); } catch (IOException ioe) {} } } }); Dialog dialog=TopManager.getDefault().createDialog(dd); dialog.setVisible(true); } /** Tells if this snapshot was created with call-tree information. For use * by the OpenCallTree action. */ public boolean isCallTreeEnabled() { //PENDING return true; } } /* * $Log: SnapshotNode2.java,v $ * Revision 1.1 2002/08/28 18:02:38 petrul * nodes, version 2 * */ |