|
From: <jom...@us...> - 2014-06-02 21:28:27
|
Revision: 1784
http://sourceforge.net/p/jason/svn/1784
Author: jomifred
Date: 2014-06-02 21:28:22 +0000 (Mon, 02 Jun 2014)
Log Message:
-----------
improve mind inspector (option to hide annotations, useful with cartaga)
Modified Paths:
--------------
trunk/src/jason/architecture/MindInspectorAgArch.java
trunk/src/jason/control/ExecutionControlGUI.java
trunk/src/jason/jeditplugin/Config.java
trunk/src/jason/util/asl2xml.java
trunk/src/xml/agInspection.xsl
Modified: trunk/src/jason/architecture/MindInspectorAgArch.java
===================================================================
--- trunk/src/jason/architecture/MindInspectorAgArch.java 2014-06-02 18:02:23 UTC (rev 1783)
+++ trunk/src/jason/architecture/MindInspectorAgArch.java 2014-06-02 21:28:22 UTC (rev 1784)
@@ -26,6 +26,8 @@
import jason.asSyntax.ASSyntax;
import jason.asSyntax.NumberTerm;
import jason.asSyntax.Structure;
+import jason.control.ExecutionControlGUI;
+import jason.jeditplugin.Config;
import jason.util.asl2html;
import jason.util.asl2xml;
@@ -37,8 +39,10 @@
import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
+import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.JCheckBox;
@@ -52,6 +56,8 @@
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
+import javax.swing.event.HyperlinkEvent;
+import javax.swing.event.HyperlinkListener;
import org.w3c.dom.Document;
@@ -63,16 +69,23 @@
// variables for mind inspector
protected boolean hasMindInspectorByCycle = false;
protected int updateInterval = 0;
- protected static JFrame mindInspectorFrame = null;
- protected static JTabbedPane mindInspectorTab = null;
- protected JTextPane mindInspectorPanel = null;
- protected JSlider mindInspectorHistorySlider = null;
- protected JCheckBox mindInspectorFreeze = null;
- protected List<String> mindInspectorHistory = null;
- protected asl2xml mindInspectorTransformer = null;
+ protected static JFrame mindInspectorFrame = null;
+ protected static JTabbedPane mindInspectorTab = null;
+ protected JTextPane mindInspectorPanel = null;
+ protected JSlider mindInspectorHistorySlider = null;
+ protected JCheckBox mindInspectorFreeze = null;
+ protected List<Document> mindInspectorHistory = null;
+ protected asl2xml mindInspectorTransformer = null;
- protected String mindInspectorDirectory;
+ protected String mindInspectorDirectory;
+ // Which item is to be shown in HTML interface
+ Map<String,Boolean> show = new HashMap<String,Boolean>();
+
+ // what is currently shown
+ Document agState = null;
+
+
@Override
public void init() {
setupMindInspector(getTS().getSettings().getUserParameter("mindinspector"));
@@ -92,7 +105,7 @@
@Override
public void reasoningCycleStarting() {
if (hasMindInspectorByCycle)
- updateMindInspector();
+ addAgState();
super.reasoningCycleStarting();
}
@@ -128,7 +141,7 @@
try {
while (isRunning()) {
Thread.sleep(updateInterval);
- updateMindInspector();
+ addAgState();
}
} catch (Exception e) {
e.printStackTrace();
@@ -149,8 +162,8 @@
String format = "text/html";
if (mindInspectorFrame == null) { // Initiate the common window
- mindInspectorFrame = new JFrame("Mind Inspector");
- mindInspectorTab = new JTabbedPane();
+ mindInspectorFrame = new JFrame(ExecutionControlGUI.title);
+ mindInspectorTab = new JTabbedPane(JTabbedPane.LEFT);
mindInspectorFrame.getContentPane().add(mindInspectorTab);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
mindInspectorFrame.setBounds(100, 200, (int)((screenSize.width-100)*0.7), (int)((screenSize.height-100)*0.9));
@@ -160,13 +173,27 @@
mindInspectorPanel = new JTextPane();
mindInspectorPanel.setEditable(false);
mindInspectorPanel.setContentType(format);
+ mindInspectorPanel.addHyperlinkListener(new HyperlinkListener() {
+ public void hyperlinkUpdate(HyperlinkEvent evt) {
+ hyperLink(evt);
+ }
+ });
+ show.put("bels", true);
+ show.put("annots", Config.get().getBoolean(Config.SHOW_ANNOTS));
+ show.put("rules", false);
+ show.put("evt", true);
+ show.put("mb", false);
+ show.put("int", false);
+ show.put("int-details", false);
+ show.put("plan", false);
+ show.put("plan-details", false);
// get history
boolean hasHistory = sConf.getArity() == 3 && sConf.getTerm(2).toString().equals("history");
if (! hasHistory) {
mindInspectorTab.add(getAgName(), new JScrollPane(mindInspectorPanel));
} else {
- mindInspectorHistory = new ArrayList<String>();
+ mindInspectorHistory = new ArrayList<Document>();
JPanel pHistory = new JPanel(new BorderLayout());//new FlowLayout(FlowLayout.CENTER));
pHistory.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Agent History", TitledBorder.LEFT, TitledBorder.TOP));
mindInspectorHistorySlider = new JSlider();
@@ -182,7 +209,7 @@
public void stateChanged(ChangeEvent e) {
try {
int c = (int)mindInspectorHistorySlider.getValue();
- mindInspectorPanel.setText(mindInspectorHistory.get(c));
+ showAgState(mindInspectorHistory.get(c));
} catch (Exception e2) { }
}
});
@@ -205,6 +232,26 @@
}
}
+ private void hyperLink(HyperlinkEvent evt) {
+ if (evt.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
+ String uri = "show?";
+ int pos = evt.getDescription().indexOf(uri);
+ if (pos >= 0) {
+ String par = evt.getDescription().substring(pos+uri.length());
+ show.put(par,true);
+ } else {
+ uri = "hide?";
+ pos = evt.getDescription().indexOf(uri);
+ if (pos >= 0) {
+ String par = evt.getDescription().substring(pos+uri.length());
+ show.put(par,false);
+ }
+ }
+ showAgState(agState);
+ }
+ }
+
+
private void setupSlider() {
int size = mindInspectorHistory.size()-1;
@@ -246,22 +293,22 @@
}
- private String previousText = "";
+ private String lastHistoryText = "";
private int fileCounter = 0;
- protected void updateMindInspector() {
+
+ protected void addAgState() {
try {
- Document agState = getTS().getAg().getAgState(); // the XML representation of the agent's mind
- String sMind = mindInspectorTransformer.transform(agState); // transform to HTML
- if (sMind.equals(previousText))
- return; // nothing to log
- previousText = sMind;
+ Document state = getTS().getAg().getAgState(); // the XML representation of the agent's mind
+ String sMind = getAgStateAsString(state, true);
+ if (sMind.equals(lastHistoryText))
+ return;
+ lastHistoryText = sMind;
if (mindInspectorPanel != null) { // output on GUI
- if (mindInspectorFreeze == null || !mindInspectorFreeze.isSelected()) {
- mindInspectorPanel.setText(sMind); // show the HTML in the screen
- }
+ if (mindInspectorFreeze == null || !mindInspectorFreeze.isSelected())
+ showAgState(state);
if (mindInspectorHistory != null) {
- mindInspectorHistory.add(sMind);
+ mindInspectorHistory.add(state);
setupSlider();
mindInspectorHistorySlider.setValue(mindInspectorHistory.size()-1);
}
@@ -275,4 +322,38 @@
e.printStackTrace();
}
}
+
+ private String previousShownText = "";
+ /** show current agent state */
+ void showAgState(Document state) { // in GUI
+ if (state != null) {
+ try {
+ String sMind = getAgStateAsString(state, false);
+ if (sMind.equals(previousShownText))
+ return; // nothing to log
+ previousShownText = sMind;
+ agState = state;
+ mindInspectorPanel.setText(sMind); // show the HTML in the screen
+ } catch (Exception e) {
+ mindInspectorPanel.setText("Error in XML transformation!" + e);
+ e.printStackTrace();
+ }
+ }
+ }
+
+ String getAgStateAsString(Document ag, boolean full) { // full means with show all
+ try {
+ for (String p: show.keySet())
+ if (full)
+ mindInspectorTransformer.setParameter("show-"+p, "true");
+ else
+ mindInspectorTransformer.setParameter("show-"+p, show.get(p)+"");
+ return mindInspectorTransformer.transform(ag); // transform to HTML
+ } catch (Exception e) {
+ mindInspectorPanel.setText("Error in XML transformation!" + e);
+ e.printStackTrace();
+ return "Error XML transformation (MindInspector)";
+ }
+ }
+
}
Modified: trunk/src/jason/control/ExecutionControlGUI.java
===================================================================
--- trunk/src/jason/control/ExecutionControlGUI.java 2014-06-02 18:02:23 UTC (rev 1783)
+++ trunk/src/jason/control/ExecutionControlGUI.java 2014-06-02 21:28:22 UTC (rev 1784)
@@ -24,6 +24,7 @@
package jason.control;
import jason.infra.centralised.RunCentralisedMAS;
+import jason.jeditplugin.Config;
import jason.util.asl2html;
import jason.util.asl2tex;
import jason.util.asl2xml;
@@ -124,7 +125,7 @@
// Which item is to be shown in HTML interface
Map<String,Boolean> show = new HashMap<String,Boolean>();
- static String title = ":: Jason Mind Inspector ::";
+ public static String title = ":: Jason Mind Inspector ::";
void initComponents() {
frame = new JFrame(title);
@@ -305,6 +306,7 @@
show.put("int-details", false);
show.put("plan", false);
show.put("plan-details", false);
+ show.put("annots", Config.get().getBoolean(Config.SHOW_ANNOTS));
}
void setListOfAgsFromInfra() {
Modified: trunk/src/jason/jeditplugin/Config.java
===================================================================
--- trunk/src/jason/jeditplugin/Config.java 2014-06-02 18:02:23 UTC (rev 1783)
+++ trunk/src/jason/jeditplugin/Config.java 2014-06-02 21:28:22 UTC (rev 1784)
@@ -77,6 +77,9 @@
public static final String CHECK_VERSION = "checkLatestVersion";
public static final String WARN_SING_VAR = "warnSingletonVars";
+ public static final String SHOW_ANNOTS = "showAnnots";
+
+
public static final String jacamoHomeProp = "JaCaMoHome";
public static final String SHORT_UNNAMED_VARS = "shortUnnamedVars";
@@ -305,7 +308,12 @@
if (getProperty(JADE_RMA) == null) {
put(JADE_RMA, "true");
}
-
+
+ // show annots
+ if (getProperty(SHOW_ANNOTS) == null) {
+ put(SHOW_ANNOTS, "true");
+ }
+
// Default infrastructures
put("infrastructure.Centralised", CentralisedFactory.class.getName());
put("infrastructure.Jade", JadeFactory.class.getName());
Modified: trunk/src/jason/util/asl2xml.java
===================================================================
--- trunk/src/jason/util/asl2xml.java 2014-06-02 18:02:23 UTC (rev 1783)
+++ trunk/src/jason/util/asl2xml.java 2014-06-02 21:28:22 UTC (rev 1784)
@@ -81,6 +81,10 @@
return transCache;
}
+ public void setParameter(String name, Object value) {
+ if (transCache != null)
+ transCache.setParameter(name, value);
+ }
TransformerFactory fac = null;
TransformerFactory getFactory() throws Exception {
Modified: trunk/src/xml/agInspection.xsl
===================================================================
--- trunk/src/xml/agInspection.xsl 2014-06-02 18:02:23 UTC (rev 1783)
+++ trunk/src/xml/agInspection.xsl 2014-06-02 21:28:22 UTC (rev 1784)
@@ -21,12 +21,13 @@
<xsl:param name="var" select="'rgb(0, 0, 200)'" />
<xsl:param name="string" select="'rgb(0, 0, 250)'" />
- <xsl:param name="show-bels" select="'true'" />
- <xsl:param name="show-rules" select="'true'" />
- <xsl:param name="show-evt" select="'true'" />
- <xsl:param name="show-mb" select="'true'" />
- <xsl:param name="show-plan" select="'true'" />
- <xsl:param name="show-int" select="'true'" />
+ <xsl:param name="show-bels" select="'true'" />
+ <xsl:param name="show-annots" select="'true'" />
+ <xsl:param name="show-rules" select="'true'" />
+ <xsl:param name="show-evt" select="'true'" />
+ <xsl:param name="show-mb" select="'true'" />
+ <xsl:param name="show-plan" select="'true'" />
+ <xsl:param name="show-int" select="'true'" />
<xsl:param name="show-plan-details" select="'true'" />
<xsl:param name="show-int-details" select="'true'" />
@@ -52,6 +53,14 @@
<xsl:apply-templates select="circumstance/actions" />
<!-- xsl:apply-templates select="plans" /-->
+ <tr style="{$trh-style}">
+ <xsl:call-template name="hideshow">
+ <xsl:with-param name="show" select="$show-annots" />
+ <xsl:with-param name="item" select="'annots'" />
+ <xsl:with-param name="ds" select="'Annotations'" />
+ </xsl:call-template>
+ <th/>
+ </tr>
</table>
</html>
</xsl:template>
@@ -61,8 +70,7 @@
<xsl:param name="show" select="'false'" />
<xsl:param name="item" select="'none'" />
<xsl:param name="ds" select="'none'" />
- <xsl:if test="$show='true'">
-
+ <xsl:if test="$show='true'">
<th valign="top" style="{$th-style}">
<hr/>
<a href="hide?{$item}" style="text-decoration: none">
@@ -280,14 +288,17 @@
<xsl:if test="$show-int-details='true'">
<!-- td valign="top" style="{$td-style}" -->
<br/>
- <xsl:apply-templates select="plan"/>
+
+ <font size="-2">
+ <pre> <- ... <xsl:apply-templates select="body"/> </pre>
+ </font>
<!-- /td -->
</xsl:if>
</td>
<xsl:if test="$show-int-details='true'">
<td valign="top" style="{$td-style}">
- <xsl:text> </xsl:text><xsl:text> </xsl:text>
+ <br/>
<xsl:apply-templates select="unifier"/>
</td>
</xsl:if>
@@ -550,11 +561,24 @@
</xsl:template>
<xsl:template match="annotations">
+ <xsl:if test="$show-annots='true'">
<span style="color: rgb(0 ,190, 0)">
<sub>
<xsl:apply-templates />
</sub>
- </span>
+ </span>
+ </xsl:if>
+ <xsl:if test="$show-annots='false'">
+ <xsl:if test="count(list-term) > 0">
+ <sub>
+ <span style="color: rgb(0 ,0, 200)">
+ <a href="show?annots" style="text-decoration: none">
+ <xsl:text>[...]</xsl:text>
+ </a>
+ </span>
+ </sub>
+ </xsl:if>
+ </xsl:if>
</xsl:template>
<xsl:template match="var-term">
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|