jadex.rules.tools.reteviewer.NodePanel Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-rules-tools Show documentation
Show all versions of jadex-rules-tools Show documentation
The Jadex rules tools package contains tools for the Jadex rule engine.
package jadex.rules.tools.reteviewer;
import java.awt.BorderLayout;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
import jadex.commons.SReflect;
import jadex.commons.SUtil;
import jadex.commons.gui.SGUI;
import jadex.rules.rulesystem.rete.Tuple;
import jadex.rules.rulesystem.rete.constraints.ConstraintIndexer;
import jadex.rules.rulesystem.rete.constraints.IConstraintEvaluator;
import jadex.rules.rulesystem.rete.nodes.AbstractBetaNode;
import jadex.rules.rulesystem.rete.nodes.AlphaNode;
import jadex.rules.rulesystem.rete.nodes.CollectNode;
import jadex.rules.rulesystem.rete.nodes.INode;
import jadex.rules.rulesystem.rete.nodes.ReteMemory;
import jadex.rules.rulesystem.rete.nodes.SplitNode;
import jadex.rules.rulesystem.rete.nodes.TerminalNode;
import jadex.rules.rulesystem.rete.nodes.TestNode;
import jadex.rules.rulesystem.rete.nodes.TypeNode;
import jadex.rules.state.IOAVState;
/**
* Display information about a single node.
*/
public class NodePanel extends JPanel
{
//-------- attributes --------
/** The node. */
protected INode node;
/** The rete memory. */
protected ReteMemory mem;
/** The state. */
protected IOAVState state;
/** The property panel. */
protected PropertyPanel pp;
/** The memory panel. */
protected MemoryPanel mp;
//-------- constructors --------
/**
* Create a new node panel.
*/
public NodePanel(INode node, ReteMemory mem, IOAVState state)
{
this.node = node;
this.mem = mem;
this.state = state;
this.pp = new PropertyPanel(getNodeProperties());
this.mp = new MemoryPanel();
pp.setBorder(BorderFactory.createTitledBorder("Node properties"));
mp.setBorder(BorderFactory.createTitledBorder("Memory"));
this.setLayout(new BorderLayout());
this.add(pp, BorderLayout.NORTH);
this.add(mp, BorderLayout.CENTER);
}
/**
* Set the node.
* @param node The node.
*/
public void setNode(INode node)
{
this.node = node;
refresh();
}
/**
* Get the node.
* @return The node.
*/
public INode getNode()
{
return node;
}
/**
* Get the node properties.
* @return The node properties.
*/
public Map getNodeProperties()
{
Map ret = new LinkedHashMap();
if(node!=null)
{
ret.put("Type", SReflect.getUnqualifiedClassName(node.getClass()));
ret.put("Id", Integer.valueOf(node.getNodeId()));
//ret.put("Use count", node.getUseCount());
if(node instanceof TypeNode)
{
TypeNode n = (TypeNode)node;
ret.put("Object type:", n.getObjectType().getName());
}
else if(node instanceof SplitNode)
{
SplitNode n = (SplitNode)node;
ret.put("Attribute:", n.getAttribute().getName());
ret.put("Split in:", Integer.valueOf(n.getSplitPattern().length));
ret.put("Split pattern:", SUtil.arrayToString(n.getSplitPattern()));
}
else if(node instanceof TestNode)
{
TestNode n = (TestNode)node;
ret.put("Evaluator:", n.getConstraintEvaluator());
}
else if(node instanceof AlphaNode)
{
AlphaNode n = (AlphaNode)node;
IConstraintEvaluator[] evas = n.getConstraintEvaluators();
for(int i=0; evas!=null && i
© 2015 - 2024 Weber Informatics LLC | Privacy Policy