org.jsoar.debugger.WorkingMemoryView Maven / Gradle / Ivy
/*
* Copyright (c) 2010 Dave Ray
*
* Created on Jul 21, 2010
*/
package org.jsoar.debugger;
import java.awt.BorderLayout;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import org.jsoar.debugger.selection.SelectionProvider;
import org.jsoar.debugger.util.SwingTools;
import org.jsoar.debugger.wm.WorkingMemoryTree;
import org.jsoar.kernel.symbols.Identifier;
import org.jsoar.kernel.symbols.Symbols;
/**
* @author ray
*/
public class WorkingMemoryView extends AbstractAdaptableView implements Refreshable
{
private final JSoarDebugger debugger;
private final JTextField roots = new JTextField(" ");
private final WorkingMemoryTree tree;
public WorkingMemoryView(JSoarDebugger debugger)
{
super("workingMemory", "Working Memory");
this.debugger = debugger;
this.tree = new WorkingMemoryTree(this.debugger.getAgent());
tree.addRoot("");
tree.addRoot("");
final JPanel header = new JPanel(new BorderLayout());
header.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
header.add(new JLabel("Roots:"), BorderLayout.WEST);
header.add(roots);
//PromptSupport.setPrompt("Enter ids and vars here, e.g. S1 I2 ...", roots);
roots.addActionListener(e -> addRoots());
SwingTools.addSelectAllOnFocus(roots);
final JPanel treePanel = new JPanel(new BorderLayout());
treePanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
treePanel.add(tree, BorderLayout.CENTER);
final JPanel panel = new JPanel(new BorderLayout());
panel.add(header, BorderLayout.SOUTH);
tree.setBorder(BorderFactory.createLoweredBevelBorder());
panel.add(treePanel, BorderLayout.CENTER);
getContentPane().add(panel);
}
private void addRoots()
{
final String[] parts = roots.getText().trim().split("\\s+");
final Runnable run = () -> {
final List