BlueJscript Concepts

To use BlueJscript you need to know javascript, html, BlueJ. You also need to understand the flow of events that happen within the system so you know how to change the script to suit your needs.

The following documents and its link will explain where script execution begin and where events come and go.

Script starting point

The first thing that it is done after the BlueJscript extension is loaded is to look for the first and initial command. It is important to note that it is a command and not a filename where to load commands from. The initial command can be anything or even a few commands one after the other, the essential thing is that it fits one line.

The initial command may come either from a command line or the Preference panel. An example of both will clarify the matter.

Command line profile command

The following example will show how to start blueJ by a command line and pass some paramteres to it. It is a visual basic script and works under Windows XP, but once you grasp the concept you will be able to start BlueJscrip with a profile anywhere you wish.

<script language="javascript"> 
var shell = new ActiveXObject('WScript.Shell');

/*
 * Tries to get the parent of the current URL
 */
function getParent()
   {
   var baseUrl = document.URL;

   // We try to get rid of anything that is after a question mark
   var url2 = baseUrl;
   var qi = baseUrl.lastIndexOf("?");
   if ( qi > 0 ) url2 = baseUrl.substr(0,qi);

   // We transform silly windows path into standard url..
   var url3 = url2.replace(/\\/g,'/');

   return url3.substr(0, url3.lastIndexOf("/"));
   }

function runlink() 
   {
   LIB="/c:/bluej/lib";
   JAVA_HOME="c:\\jdk141"';

  profileCmd="load(new java.net.URL('"+getParent()+"/reflection.js'));";
  profile=' -Dbluejscript.profile="'+profileCmd+'" ';

   jarfile=LIB+"/bluej.jar";
   command=JAVA_HOME+'/bin/java '+profile+' -jar '+jarfile;

  shell.Run (command,1,false);
  }

</script> 

The most important thing is starting java with a property defined, this means looking for -Dbluejscript.profile="'+profile+'" in the above line. Again the proper use of single and double quotes is absolutely relevant So the above script will start BlueJ and will define a property called bluejscript.profile that holds the first command that BlueJscript will execute. In the example above it will be a load command.

User profile definition

If no profile command is passed at startup BlueJscript will look into the user bluej directory for a file called profile.js. If this file is found it will be loaded at bluejscript startup.

Project profile definition

If no user profile is defined then the profile that is bound with the project is executed. Again the file being looked is called profile.js. It is important to note that no provision is made for concurrent execution and one script will be executed only if the previous one terminates.

 

What happens next

The command being executed at startup may or may not finish its execution. It may finish it if it is something simple like jsConsole.setVisible(true); or may not finish if it is a script that constitues a faull tutorial that will close at the end.

In any case, to interact with the console you need to see it, if there is no console visible and no way to show it (es: by means of a button) then you can only obey to what the script is asking you. To get the console you need to step out of the script by starting BlueJscript with a different startup command.

It is important to remembar that there is only one point of script execution and multiple source of javascript. The status window of the console should tell you what the system is currently doing at the moment.