
jadex.tools.ruleprofiler.RuleProfilerPlugin Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-tools-bdi Show documentation
Show all versions of jadex-tools-bdi Show documentation
The Jadex tools bdi package contains
JCC plugins for Jadex BDI agents.
The newest version!
package jadex.tools.ruleprofiler;
import jadex.base.gui.asynctree.ISwingNodeHandler;
import jadex.base.gui.asynctree.ISwingTreeNode;
import jadex.base.gui.asynctree.ITreeNode;
import jadex.base.gui.componenttree.ComponentTreePanel;
import jadex.base.gui.componenttree.IActiveComponentTreeNode;
import jadex.base.gui.plugin.AbstractJCCPlugin;
import jadex.bdi.BDIAgentFactory;
import jadex.bridge.service.search.SServiceProvider;
import jadex.bridge.service.types.cms.ICMSComponentListener;
import jadex.bridge.service.types.cms.IComponentDescription;
import jadex.bridge.service.types.cms.IComponentManagementService;
import jadex.commons.future.IFuture;
import jadex.commons.gui.CombiIcon;
import jadex.commons.gui.ObjectCardLayout;
import jadex.commons.gui.SGUI;
import jadex.commons.gui.future.SwingDefaultResultListener;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.util.Map;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTree;
import javax.swing.SwingUtilities;
import javax.swing.UIDefaults;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.TreePath;
/**
* The rule profiler allows to browse through
* profiling information gathered in the rule system.
*/
public class RuleProfilerPlugin extends AbstractJCCPlugin implements ICMSComponentListener
{
// -------- constants --------
/**
* The image icons.
*/
protected static final UIDefaults icons = new UIDefaults(new Object[]{
"profiler", SGUI.makeIcon(AbstractJCCPlugin.class, "/jadex/tools/ruleprofiler/images/ruleprofiler.png"),
"profiler_sel", SGUI.makeIcon(AbstractJCCPlugin.class, "/jadex/tools/ruleprofiler/images/ruleprofiler_sel.png"),
"profile_agent", SGUI.makeIcon(AbstractJCCPlugin.class, "/jadex/tools/ruleprofiler/images/new_introspector.png"),
"close_profiler", SGUI.makeIcon(AbstractJCCPlugin.class, "/jadex/tools/ruleprofiler/images/close_introspector.png"),
"profiler_empty", SGUI.makeIcon(AbstractJCCPlugin.class, "/jadex/tools/ruleprofiler/images/introspector_empty.png"),
"component_debugged", SGUI.makeIcon(AbstractJCCPlugin.class, "/jadex/tools/ruleprofiler/images/overlay_introspected.png"),
"stop_debugger", SGUI.makeIcon(AbstractJCCPlugin.class, "/jadex/tools/ruleprofiler/images/overlay_notintrospected.png")
});
//-------- attributes --------
/** The split panel. */
protected JSplitPane split;
/** The agent tree table. */
protected ComponentTreePanel comptree;
/** The detail panel. */
protected JPanel detail;
/** The detail layout. */
protected ObjectCardLayout cards;
//-------- constructors --------
/**
* Create a new rule profiler plugin.
*/
public RuleProfilerPlugin()
{
}
//-------- IControlCenterPlugin interface --------
/**
* @return The plugin name
* @see jadex.base.gui.plugin.IControlCenterPlugin#getName()
*/
public String getName()
{
return "Rule Profiler";
}
/**
* @return The icon of plugin
* @see jadex.base.gui.plugin.IControlCenterPlugin#getToolIcon()
*/
public Icon getToolIcon(boolean selected)
{
return selected? icons.getIcon("profiler_sel"): icons.getIcon("profiler");
}
/**
* Create tool bar.
* @return The tool bar.
*/
public JComponent[] createToolBar()
{
JButton b1 = new JButton(START_PROFILER);
b1.setBorder(null);
b1.setToolTipText(b1.getText());
b1.setText(null);
b1.setEnabled(true);
JButton b2 = new JButton(STOP_PROFILER);
b2.setBorder(null);
b2.setToolTipText(b2.getText());
b2.setText(null);
b2.setEnabled(true);
return new JComponent[]{b1, b2};
}
/**
* Create main panel.
* @return The main panel.
*/
public JComponent createView()
{
this.split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true);
split.setOneTouchExpandable(true);
comptree = new ComponentTreePanel(getJCC().getPlatformAccess(), getJCC().getCMSHandler(), getJCC().getPropertyHandler(), getJCC().getIconCache());
comptree.setMinimumSize(new Dimension(0, 0));
split.add(comptree);
comptree.getTree().getSelectionModel().addTreeSelectionListener(new TreeSelectionListener()
{
public void valueChanged(TreeSelectionEvent e)
{
JTree tree = comptree.getTree();
if(tree.getSelectionPath()!=null)
{
Object node = tree.getSelectionPath().getLastPathComponent();
if(node instanceof IActiveComponentTreeNode)
{
cards.show(((IActiveComponentTreeNode)node).getDescription());
}
}
}
});
comptree.addNodeHandler(new ShowRemoteControlCenterHandler(getJCC(), getView()));
comptree.addNodeHandler(new ISwingNodeHandler()
{
public Action[] getPopupActions(ISwingTreeNode[] nodes)
{
Action[] ret = null;
boolean allbdi = true;
for(int i=0; allbdi && i componentRemoved(final IComponentDescription ad, Map results)
{
// Update components on awt thread.
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
if(BDIAgentFactory.FILETYPE_BDIAGENT.equals(ad.getType()))
{
if(cards.isAvailable(ad))
{
detail.remove(cards.getComponent(ad));
}
}
}
});
return IFuture.DONE;
}
/**
* Called when an component is born.
* @param ad the component description.
*/
public IFuture componentAdded(final IComponentDescription ad)
{
return IFuture.DONE;
}
/**
* Called when an component changed.
* @param ad the component description.
*/
public IFuture componentChanged(final IComponentDescription ad)
{
return IFuture.DONE;
}
/**
* Shutdown the plugin.
*/
public IFuture shutdown()
{
if(comptree!=null)
comptree.dispose();
return IFuture.DONE;
}
final AbstractAction START_PROFILER = new AbstractAction("Profile Agent", icons.getIcon("profile_agent"))
{
public void actionPerformed(ActionEvent e)
{
TreePath[] paths = comptree.getTree().getSelectionPaths();
for(int i=0; paths!=null && i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy