From: <jom...@us...> - 2014-09-14 17:29:05
|
Revision: 1802 http://sourceforge.net/p/jason/svn/1802 Author: jomifred Date: 2014-09-14 17:29:02 +0000 (Sun, 14 Sep 2014) Log Message: ----------- use courier in repl gui :-) Modified Paths: -------------- trunk/build.xml trunk/release-notes.txt trunk/src/jason/infra/centralised/RunCentralisedMAS.java trunk/src/jason/infra/repl/ReplAg.java Added Paths: ----------- trunk/src/jason/infra/repl/ReplAgGUI.java Modified: trunk/build.xml =================================================================== --- trunk/build.xml 2014-09-13 23:50:27 UTC (rev 1801) +++ trunk/build.xml 2014-09-14 17:29:02 UTC (rev 1802) @@ -174,7 +174,7 @@ <copy file="${jasonJar}" tofile="${replJar}" /> <echo file="default.mas2j"> MAS repl { - agents: repl_agent agentClass jason.infra.repl.ReplAg; + agents: repl_agent agentClass jason.infra.repl.ReplAgGUI; } </echo> <jar update="yes" jarfile="${replJar}" > Modified: trunk/release-notes.txt =================================================================== --- trunk/release-notes.txt 2014-09-13 23:50:27 UTC (rev 1801) +++ trunk/release-notes.txt 2014-09-14 17:29:02 UTC (rev 1802) @@ -1,4 +1,14 @@ --------------------------- +version 1.4.2 + +revision XXX on SVN +--------------------------- + +New features +- REPL button on MASConsole and jason-repl.jar + + +--------------------------- version 1.4.1 revision 1792 on SVN Modified: trunk/src/jason/infra/centralised/RunCentralisedMAS.java =================================================================== --- trunk/src/jason/infra/centralised/RunCentralisedMAS.java 2014-09-13 23:50:27 UTC (rev 1801) +++ trunk/src/jason/infra/centralised/RunCentralisedMAS.java 2014-09-14 17:29:02 UTC (rev 1802) @@ -28,7 +28,7 @@ import jason.asSyntax.directives.DirectiveProcessor; import jason.asSyntax.directives.Include; import jason.control.ExecutionControlGUI; -import jason.infra.repl.ReplAg; +import jason.infra.repl.ReplAgGUI; import jason.jeditplugin.Config; import jason.mas2j.AgentParameters; import jason.mas2j.ClassParameters; @@ -367,7 +367,7 @@ agArch.setAgName(n.getText()); agArch.setEnvInfraTier(env); try { - agArch.createArchs(null, ReplAg.class.getName(), null, null, new Settings(), RunCentralisedMAS.this); + agArch.createArchs(null, ReplAgGUI.class.getName(), null, null, new Settings(), RunCentralisedMAS.this); Thread agThread = new Thread(agArch); agArch.setThread(agThread); agThread.start(); Modified: trunk/src/jason/infra/repl/ReplAg.java =================================================================== --- trunk/src/jason/infra/repl/ReplAg.java 2014-09-13 23:50:27 UTC (rev 1801) +++ trunk/src/jason/infra/repl/ReplAg.java 2014-09-14 17:29:02 UTC (rev 1802) @@ -10,32 +10,12 @@ import jason.asSyntax.Plan; import jason.asSyntax.PlanBody; import jason.asSyntax.Trigger; -import jason.util.asl2html; -import java.awt.BorderLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.util.logging.LogRecord; -import java.util.logging.StreamHandler; - -import javax.swing.JFrame; -import javax.swing.JScrollPane; -import javax.swing.JTextArea; -import javax.swing.JTextField; -import javax.swing.JTextPane; - -import org.w3c.dom.Document; - -public class ReplAg extends Agent { +public abstract class ReplAg extends Agent { - asl2html agTransformer = new asl2html("/xml/agInspection.xsl"); - JTextPane mindPanel = null; - JTextField command = null; - JTextArea output = null; - String[] replCmds = { clear.class.getName(), - verbose.class.getName(), + //verbose.class.getName(), mi.class.getName()}; int cmdCounter = 0; @@ -43,34 +23,8 @@ @Override public void initAg() { super.initAg(); - initGui(); - initLogger(); - if (mindPanel != null) { - new Thread("update mind thread") { - public void run() { - while (getTS().getUserAgArch().isRunning()) { - try { - updateMindView(); - sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - }; - }.start(); - } } - void initLogger() { - getTS().getLogger().addHandler( new StreamHandler() { - @Override - public synchronized void publish(LogRecord l) { - output.append(l.getMessage()+"\n"); - output.setCaretPosition( output.getDocument().getLength()); - } - }); - } - @Override public void load(String asSrc) throws JasonException { super.load(null); @@ -81,9 +35,8 @@ }*/ } - void execCmd() { + void execCmd(String sCmd) { try { - String sCmd = command.getText().trim(); if (sCmd.endsWith(".")) sCmd = sCmd.substring(0,sCmd.length()-1); for (String c: replCmds) { @@ -109,73 +62,18 @@ //getTS().getC().addAchvGoal(g, null); getTS().getC().addIntention(i); cmdCounter++; - command.setText(""); + clear(); getTS().getUserAgArch().wake(); } catch (Exception e) { - output.setText("Error parsing "+command.getText()+"\n"+e); + print("Error parsing "+sCmd+"\n"+e); } } - - static int lastPos = 30; - - void initGui() { - command = new JTextField(40); - command.setToolTipText("Type a Jason operation here."); - command.addActionListener(new ActionListener() { - @Override - public void actionPerformed(ActionEvent arg0) { - execCmd(); - } - }); - //mindPanel = new JTextPane(); - //mindPanel.setEditable(false); - //mindPanel.setContentType("text/html"); - - output = new JTextArea(5,50); - output.setEditable(false); - output.setText("Example of operations you can type:\n +bel; !goal; .add_plan({+!goal <- .print(ok) }); !!goal; \n .send(bob,tell,hello);\n"); - output.append(" ?bel(A); .findall(X,bel(X),L); \n"); - output.append(" .mi // to open mind inspector\n"); - output.append(" .verbose(2) // to show debug messages\n"); - output.append(" .clear // clean console\n"); - output.append("\nYou can add more agents using the button 'new REPL ag' in MAS Console."); - - output.append("\n"); - - - JFrame f = new JFrame(".:: REPL Interface for "+getTS().getUserAgArch().getAgName()+" ::."); - f.getContentPane().setLayout(new BorderLayout()); - f.getContentPane().add(BorderLayout.NORTH,command); - //f.getContentPane().add(BorderLayout.CENTER, new JScrollPane(mindPanel)); - f.getContentPane().add(BorderLayout.CENTER,new JScrollPane(output)); - - f.pack(); - int h = 200; - int w = (int)(h*2*1.618); - f.setBounds((int)(h*0.618), 20, w, h); - f.setLocation(lastPos, 200+lastPos); - lastPos += 50; - f.setVisible(true); + public void print(String s) { + System.out.println(s+"\n"); } public void clear() { - output.setText(""); } - private String lastMind = ""; - - void updateMindView() { - getTS().getUserAgArch().setCycleNumber(cmdCounter); - Document agState = getAgState(); // the XML representation of the agent's mind - try { - String sMind = agTransformer.transform(agState); // transform to HTML - if (!sMind.equals(lastMind)) - mindPanel.setText(sMind); // show the HTML in the screen - lastMind = sMind; - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } } Added: trunk/src/jason/infra/repl/ReplAgGUI.java =================================================================== --- trunk/src/jason/infra/repl/ReplAgGUI.java (rev 0) +++ trunk/src/jason/infra/repl/ReplAgGUI.java 2014-09-14 17:29:02 UTC (rev 1802) @@ -0,0 +1,127 @@ +package jason.infra.repl; + +import java.awt.BorderLayout; +import java.awt.Font; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.logging.LogRecord; +import java.util.logging.StreamHandler; + +import javax.swing.JFrame; +import javax.swing.JScrollPane; +import javax.swing.JTextArea; +import javax.swing.JTextField; + +public class ReplAgGUI extends ReplAg { + + JTextField command = null; + JTextArea output = null; + + //asl2html agTransformer = new asl2html("/xml/agInspection.xsl"); + //JTextPane mindPanel = null; + + @Override + public void initAg() { + super.initAg(); + initGui(); + initLogger(); + /*if (mindPanel != null) { + new Thread("update mind thread") { + public void run() { + while (getTS().getUserAgArch().isRunning()) { + try { + updateMindView(); + sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + }; + }.start(); + }*/ + } + + void initLogger() { + getTS().getLogger().addHandler( new StreamHandler() { + @Override + public synchronized void publish(LogRecord l) { + output.append(l.getMessage()+"\n"); + output.setCaretPosition( output.getDocument().getLength()); + } + }); + } + + + static int lastPos = 30; + + void initGui() { + Font font = new Font("Courier", Font.PLAIN, 14); + command = new JTextField(40); + command.setFont(font); + command.setToolTipText("Type a Jason operation here."); + command.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent arg0) { + execCmd(command.getText().trim()); + } + }); + + //mindPanel = new JTextPane(); + //mindPanel.setEditable(false); + //mindPanel.setContentType("text/html"); + + output = new JTextArea(5,50); + output.setFont(font); + output.setEditable(false); + output.setText("Example of operations you can type:\n +bel; !goal; .add_plan({+!goal <- .print(ok) }); !!goal; \n .send(bob,tell,hello);\n"); + output.append(" ?bel(A); .findall(X,bel(X),L); \n"); + output.append(" .mi // to open mind inspector\n"); + output.append(" .verbose(2) // to show debug messages\n"); + output.append(" .clear // clean console\n"); + output.append("\nYou can add more agents using the button 'new REPL ag' in MAS Console."); + + output.append("\n"); + + + JFrame f = new JFrame(".:: REPL Interface for "+getTS().getUserAgArch().getAgName()+" ::."); + f.getContentPane().setLayout(new BorderLayout()); + f.getContentPane().add(BorderLayout.NORTH,command); + //f.getContentPane().add(BorderLayout.CENTER, new JScrollPane(mindPanel)); + f.getContentPane().add(BorderLayout.CENTER,new JScrollPane(output)); + + f.pack(); + int h = 200; + int w = (int)(h*2*1.618); + f.setBounds((int)(h*0.618), 20, w, h); + f.setLocation(lastPos, 200+lastPos); + lastPos += 50; + f.setVisible(true); + } + + @Override + public void clear() { + output.setText(""); + } + + @Override + public void print(String s) { + output.append(s+"\n"); + } + + /* + private String lastMind = ""; + + void updateMindView() { + getTS().getUserAgArch().setCycleNumber(cmdCounter); + Document agState = getAgState(); // the XML representation of the agent's mind + try { + String sMind = agTransformer.transform(agState); // transform to HTML + if (!sMind.equals(lastMind)) + mindPanel.setText(sMind); // show the HTML in the screen + lastMind = sMind; + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + }*/ +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |