Home
  · Order
  · Resellers
  · Contact us
  · Web tips
  · About
Shareware
  · PMVR
  · SlideShow
  · GoRound
Java Tools
  · JexePack
  · Jobfuscate
  · MakeInstall
Affordware
  · PhotoFinder
  · PrintEnvelope
  · WinOpen
  · Label
Java Applets
  · Reference
  · Scripting
  · ControlPad
Learning + Fun
  · NX 101
  · Pano Help
  · Bug Free C
  · Space Rocks
 
DuckwareQuality by Design
 You are here: Duckware » Java Applets » Scripting   Contact us  
Scripting Duckware Java Applets

1. Native Duckware Scripting
2. Native Scripting Internationalization
3. Native Scripting Examples
4. JavaScript Scripting

 
  1. Native Duckware Scripting
All Duckware applets support an internal scripting language, called Native Scripting. The scripting engine is implemented in 100% Java code, so there are no compatibility problems like those possible with JavaScript scripting.

The first step in taking advantage of Native scripting is to assign a unique name, within a web page, to all of your applets. For example:
<applet name="pmvr" code="pmvr.class" width=500 height=300>
  ...
  </applet>
To run a script within an applet when that applet initializes, just set the "script" applet parameter (which all Duckware applets support) to the name of your script file. For example,
<applet name="pmvr" code="pmvr.class" width=500 height=300>
  <param name="script" value="script.txt">
  </applet>
The scripting engine would read and process the commands in the "script.txt" script file. This "script.txt" file might look like:
image=newimage.jpg
auto=20
center=1568
Where each line in the script file is just assigning a new value to an applet parameter. Just review the online manual for the applet you are scripting to see what parameters are available to you (they vary from applet to applet). The syntax of each line in a script file looks like:
parameter = value
For simple scripting, this is probably all you need. However, for advanced scripting, the scripting engine allows multiple scripts to share a single script file. You just need to refer to the script file and the script section when running a script. For example:
<applet name="pmvr" code="pmvr.class" width=500 height=300>
  <param name="script" value="script.txt:gotoKitchen">
  </applet>
Where the new "script.txt" file with sections added might look like:
[gotoKitchen]
  image=images/kitchen.jpg
  auto=20
  center=1568
[gotoPorch]
  image=images/porch.jpg
  center=200
TIP: It is possible to place a script inline within an HTML document. Just place the entire script in a comment block within your HTML file, and place and ending "[eof]" section at the end of your script. Inline scripting example.

Sometimes, it is not enough to just set parameters within the applet that is running the script. Sometimes you need to set parameters in other applets as well. To support this, the scripting engine allows for an optional "appletname." to prefix variable names. For example:
[gotoKitchen]
  image=images/kitchen.jpg
  auto=20
  center=1568
  FloorPlan.image=images/firstfloor.gif
  FloorPlan.x=120
  FloorPlan.y=52
So the final syntax for lines within a script is:
{applet.}parameter = value
To use this feature, your applets must be uniquely named as described at the beginning of this section. Please refer to the Java APPLET Reference for detailed instructions on how to set the "name" of your Java applet.

Another way to accomplish the same thing is to ask the FloorPlan applet to run a script, which causes parameters within the FloorPlan applet to be set. Since a single file can now contain multiple scripts, the new script file might look like:
[gotoKitchen]
  image=images/kitchen.jpg
  auto=20
  center=1568
  FloorPlan.script=$THIS:firstfloor
[firstfloor]
  image=images/firstfloor.gif
  x=120
  y=52
Note that you must give a filename (and optional section) when setting the "script" parameter. However, placing the filename of the script within the script itself over and over would make it very hard to rename the script. So, the scripting engine allows for variable substitution of the script filename via the "$THIS" variable. The scripting engine replaces any "$THIS" that it finds with the filename of the running script, allowing a script to refer to itself.

TIP: When creating your scripts, make sure to open the Java Console in your web browser and watch for any error messages from the scripting engine. Syntax errors and other errors are reported within this Java Console.
 
  2. Native Scripting Internationalization
Note: Internationalization support initially added to the Duckware applets in version /5 of the applet acore class via the optional I18N class file. However, in version /11 of the applet acore class, I18N is now a standard part of the Duckware applets, so internationalization support is always available. Also, /11 standardizes on the Unicode encoding for script files to provide internationalization support.

To support internationization within a script file, start by writing your script using the Unicode character encoding (Unicode little and Unicode big are both supported). Most platforms supply editors that support Unicode. Under Windows, use wordpad.exe and under Unix, use vi.

So, assumming that you saved this script in Unicode (little):
face=SimplifiedChinese
auto=20
center=1568
link0=40,60,kitchen.html,Kitchen~吲吳吴吵吶
a hex dump of this script file would like like the following, where you can clearly see that each character in this Unicode file uses two bytes:
00000000: FF FE 66 00 61 00 63 00 65 00 3D 00 53 00 69 00   ..f.a.c.e.=.S.i.
00000010: 6D 00 70 00 6C 00 69 00 66 00 69 00 65 00 64 00   m.p.l.i.f.i.e.d.
00000020: 43 00 68 00 69 00 6E 00 65 00 73 00 65 00 0D 00   C.h.i.n.e.s.e...
00000030: 0A 00 61 00 75 00 74 00 6F 00 3D 00 32 00 30 00   ..a.u.t.o.=.2.0.
00000040: 0D 00 0A 00 63 00 65 00 6E 00 74 00 65 00 72 00   ....c.e.n.t.e.r.
00000050: 3D 00 31 00 35 00 36 00 38 00 0D 00 0A 00 6C 00   =.1.5.6.8.....l.
00000060: 69 00 6E 00 6B 00 30 00 3D 00 34 00 30 00 2C 00   i.n.k.0.=.4.0.,.
00000070: 36 00 30 00 2C 00 6B 00 69 00 74 00 63 00 68 00   6.0.,.k.i.t.c.h.
00000080: 65 00 6E 00 2E 00 68 00 74 00 6D 00 6C 00 2C 00   e.n...h.t.m.l.,.
00000090: 4B 00 69 00 74 00 63 00 68 00 65 00 6E 00 7E 00   K.i.t.c.h.e.n.~.
000000A0: 32 54 33 54 34 54 35 54 36 54 0D 00 0A 00 .. ..   2T3T4T5T6T......
Because most Unicode font files do not provide support for all Unicode characters, you must actually tell the Java applets which TrueType font contains the characters you intend to use by using the face param, which all Duckware applets support. For example:
<param name="face" value="MS Song">
The face param can either be a single TrueType font to use, or it can be comma separated list of TrueType font names, where the first font in that list that is found is the font that is used. Or just use a built-in language name as the font name for common languages: TraditionalChinese, SimplifiedChinese, Japanese, Korean. For example:
<param name="face" value="SimplifiedChinese">
Finally, any time you specify a string in any Duckware applet that ends up being displayed in the GUI, specify both an English and Native Language translation, separated by a tilde, using the following syntax:
English Text String~Native Text String
For example:
link0=40,60,kitchen.html,Kitchen~吲吳吴吵吶
This syntax allows for maximum compatibility (and recovery) when deploying your applet. On those computers that have the required font installed, your internationalized text is used. However, on those computers that do not have the proper font support installed (or a Java VM that does not support TrueType fonts), then the English text will be used.

TIP: If you are using an applet on a web page that is internationalized to (for example) Simplified Chinese, it makes a lot of sense to also use a charset in the HTML to indicate the same character set. Typical web browser behavior is to demand load the required fonts, so font support is then automatic. Slick!
 
  3. Native Scripting Examples
  • Hawaii Tour - A very extensive example of Native Scripting and ControlPad usage. Take note that the links at the bottom of the web page that switch scenes were implemented with the ControlPad applet. Just view the HTML source (and script) to see how it works.
  • Image Selection - Changing the PMVR image using the ControlPad applet and an inline script
  • Scrolling Controls - VCR-style controls by using the ControlPad applet
  • ControlPad Applet Example - The ControlPad example uses native scripting
  • GoRound Demo - Image menu changes GoRound scene by using the ControlPad applet
 
  4. JavaScript Scripting
Note: Internet Explorer on the Mac does not support JavaScript scripting. See Java Applet Technical Note 02/19/2001 for details. The impact is not that great since IE for the Mac is a discontinued product, so most people have already switch to Apple's Safari (or other web browsers), that do support JavaScript scripting. However, if you want your web pages to be 100% fully Mac compatibility, you should only use Native Scripting [§1].
Refer to the Netscape JavaScript 1.1 Guide for a technical reference manual on JavaScript
All Duckware applets can be controlled via JavaScript. Using JavaScript is optional and normally only used by web masters, or those who can program in HTML. All Duckware applets have a public function, which can be accessed from JavaScript, that looks like:
public void set( String name, String value )
Just use the same parameter names and values that are described in the parameter tables in the manual for the applet. In order to access the applets via JavaScript, each applet must be given a unique name in the HTML code. For example, this is how the PMVR applet might be named:
<applet name="pmvr" code="pmvr.class" width=500 height=300>
  ...
  </applet>
Then JavaScript can be used to change applet parameters at any time (using the name that was given to the applet in HTML). For example:
document.pmvr.set('image','newimage.jpg');
document.pmvr.set('auto','20');
document.pmvr.set('center','1568');
Copyright © 2000-2013 Duckware