![]() |
|
You can easily extend the capabilities of the script, the only requirement
is that you should be a beginner level java programmer.
Any component created by you can be added to the script. The component
can be any java object. The easiest way to add custom components to the
script as a new tag is to create a new interpreter for your new tag.
The required API Documentation is provided in the API Doc folder.
ex:-
import java.awt.*;
import vscript.interpreter.*;
import vscript.*;
import vscript.parser.*;
import vscript.GUI.*;
public class YourClassInterpreter extends TagInterpreter
{
public Object interpretObject(Tag tag)
{
YourClass object=new YourClass();
return object;
}
}
Creating an interpreter is as simple as subclassing the TagInterpreter
calss and overriding interpretObject(Tag tag) method.
The interpretObject method should return an instance of your object.
After the interpreter is created new tag can be added to the script
by using the taginfo tag as follows.
<taginfo>
newtag1 YourClassInterpreter,
newtag2 YourClassInterpreter,...
</taginfo>
<newtag1 nt1,pos="100,100,400,200"></newtag1>
<newtag2 nt2,></newtag1>
As the following code demonstrates all common attributes for GUI components
can be processed using the processAttributes helper method.
public class YourClassInterpreter extends TagInterpreter
{
public Object interpretObject(Tag tag)
{
YourClass object=new YourClass();
/**Required only if object is a visible GUI component.*/
TagInterpreter.processAttributes(object,tag),
return object;
}
}
Generating Events , Supporting Messages and DataValues
In order for new components to support event generation, recieve messaegs and provide data values the vscript.message.Messagable interface must be implemented.
The interface has the following three methods.
handleMessage(Message msg)
Any message send to this object is passed as a Message object through
the handle massage method. Each component can respond appropriately to
messages.
setEventTagManager(EventTagManager etm)
This method is used to pass a reference of EventTagManager object in
order to allow the component to generate events. The method can keep a
reference to EventTagManager object in order to generate events when required.
Generating an event ‘testEvent’ is as simple as
EventTagManagerObject.process(testEvent)
String GetDataValue(String data)
This method must be overridden if the component has to provide data
values. It has to return value corresponding to passed data. It can return
any string based on the data values it needs to support.
SAMPLE COMPONENT
The following sample component is a button that produces a beep sound
when pressed. It also produces the beep event when ever the beep sound
is produced. It can accept the beep message up on which it produces a beep
sound.
The code for the component and corresponding interpreter are
BeepComponent.javaBeepInterpreter.java
After compiling these classes they can be tested using the following
script.
beep.txt