NetStrokes Developer's Guide

Contents

How to install

NetStrokes consists of two Java applets: the Canvas and the Control Panel. The best method to embed it in a web page is to use the included JavaScript drawer.js which allows you to display the applet correctly in most popular browsers, and initiate Java installation in case the user's computer hasn't Java.

Example

// Include drawer.js in your HTML
<script language="javascript" src="applet/drawer.js"></script>

// Define the applet attibutes and parameters
<script language="javascript">
    // Create an instance of the Drawer.
    // The Drawer constructor requires one parameter: the applet's directory
    var drawer = new Drawer('./applet/');

    // Define the save script
    drawer.canvas.param.save = 'save.aspx';

    // Define other parameters if necessary
    // ...

    // Output the editor GUI to the page
    drawer.write();
</script>
In the usual case you have to:
  1. Create an instance of the Drawing() object.
  2. Assign necessary parameters
  3. Output the editor's GUI to the page using the method write().

How to save the drawing

To receive the user's drawing on the server you have to create a server-side script which expects post request from the form like the following:

<form action="url_of_name_your_script" method="post">
    <input type="text" name="drawing">
    <input type="submit">
</form>

Also, you have to specify the script name as the NetStrokes parameter save, for example:

    drawer.canvas.param.save = 'save.aspx';
When the user presses the "Save" button (it looks like a floppy disk) NetStrokes posts the drawing to the specified script. The drawing is assigned to the posted field "drawing". It's value is the drawing in SVG format.

Response of the save script

Since the save script is requested from the applet the response is returned to the applet as well. The Drawer doesn't understand HTML and can't display it, so you shouldn't output HTML in your save script. Instead you have to output special commands (as plain text) which allows you redirecting the browser to another page, and/or displaying an error message, for example:

    #SHOWDOCUMENT=my_confirm_page.html

Now formally: The response should be a one or more of the following commands separated by new line:

Command Action
#SHOWDOCUMENT=<url of the document> The browser opens a new document. The parameter is the document's URL.
The URL can be either absolute or relative to the save script.
#SETDOCTAG=<target frame> The parameter is the target frame for the document opened by #SHOWDOCUMENT command.
This command should be sent before #SHOWDOCUMENT to have an effect.
If this command is not specified the document replaces the current web page.
#SHOWMESSAGE=<message text> The message text is displayed in a popup dialog.
#SHOWERROR=<message text> The same as #SHOWMESSAGE but the dialog is error decorated.
#SHOWSTATUS=<text to display> The text is displayed in the browser's status line.

How to load a drawing

NetStrokes can load drawings saved earlier. To load a drawing from the server define it's URL by the parameter canvas.param.load, for example:

    drawer.canvas.param.load = 'myimage.svg';

The URL can be either absolute or relative to the current page.

NOTE: The program can open only the files produced by itself. Don't try to open SVG files produced by other programs. The program can't display them correctly.

Parameters

The applet can be customized with parameters. Parameters can be defined with JavaScript

    drawer.parameter_name = parameter_value;

Below you find the list of supported parameters:

Parameter Name Parameter Value
canvas.param.save URL of the save script. The URL can be either absolute or relative to the current page.
canvas.param.load URL of the drawing to load at startup. The URL can be either absolute or relative to the current page.
canvas.param.export Specifies that a raster copy of the drawing is included in the save request. The parameter value should be in the following form:
format:png; width:400; height:300
where: the format can be 'png' or 'jpeg', width and height must be integer values. The image file is BASE64 encoded and assigned to the request field 'export'.
canvas.param.model_size Defines the size of the new drawing. The value is width and height, separated by a comma. This value is ignored if you load a drawing with the parameter (canvas.param.load)
canvas.param.canvas_bgcolor Background color of the drawing canvas defined as #RRGGBB. If this parameter is not set the canvas background is transparent. Note: The background of the canvas doesn't affect the background of the saved picture which is always transparent.
canvas.param.canvas_bgimage URL of the background image to display under the drawing. The image should be JPEG or GIF, or PNG, or SVG file. The image is not included in the saved SVG file.
canvas.param.canvas_fgimage URL of the foreground image to display on the top of the drawing. The image should be JPEG or GIF, or PNG, or SVG file. The image is not included in the saved SVG file.
controlPanel.param.tools Defines what drawing tools to display. The tool names are defined by their keywords and should be separated by commas. The following tools are supported:
select, free_hand, line, polyline, rectangle, roundrect, ellipse, area, polygon
controlPanel.param.draw_colors Defines the list of drawing (outline) colors. Colors are defined as #RRGGBB values separated by comma.
Example: #000000,#FF0000,#00FF00,#0000FF,#C0C0C0,#000000
controlPanel.param.fill_colors Defines the list of colors to fill drawn shapes. Colors are defined as #RRGGBB values separated by comma.
Example: #000000,#C0C0C0,#000000,#FF0000,#00FF00,#0000FF
controlPanel.param.set_tool Sets the current drawing tool at startup. Use a keyword from the list of available tools
controlPanel.param.set_draw_color Sets current draw color at startup
controlPanel.param.set_fill_color Sets current fill color at startup
controlPanel.param.set_stroke Sets current stroke at startup

Clipart Panel

Clipart panel allows display of a collection of SVG images. The user can drag and drop them to the canvas.
To create a Clipart Panel on a web page use the following example:

  var drawer = new Drawer('./applet/'); 

  // get an instance of Clipart panel from the Drawer() object
  var clipartPanel = drawer.createClipartPanel();
  
  // set the panel parameters
  clipartPanel.height = 100;
  clipartPanel.width  = 500;
  clipartPanel.param.clipart_archive = 'my_cliparts.zip';
  clipartPanel.param.rows = 1;
  clipartPanel.param.cols = 5;

  clipartPanel.write(); 

Here is the list of clipart panel parameters:

Parameter Name Parameter Value
clipart_archive URL of a ZIP archive on the server. The archive should contain clipart files in SVG format.
rows The number of rows to arrange clip arts on the panel
cols The number of columns to arrange clip arts on the panel
bgcolor Background color of the panel defined as #RRGGBB.

Notes:

 

Using background and foreground images

The drawing canvas allows to display a background and/or foreground image. The image should be JPEG, or GIF, or PNG, or SVG file.
To specify the background image use the canvas parameter canvas_bgimage.
Example:

    drawer.canvas.param.canvas_bgimage = 'myimage.jpg';
To specify the foreground image use the canvas parameter canvas_fgimage.
Example:

    drawer.canvas.param.canvas_fgimage = 'myimage.svg';

The background and foreground images are NOT included in the saved file. If you want to include them for printing or display purposes, insert them as the first (for background) or the last (for foreground) image tag in the SVG file, for example:

    <image x="0" y="0" width="800", height="600" xlink:href="myimage.jpg"/>

The attributes width and height should be set according to the width and height of the viewBox attribute of the host SVG file.

 

Localization

The program has several text labels on its GUI. If you want to display them in a different language open the file resources.txt located in the applet directory and replace values of items that start from text.


Copyright 2007-2008, Igor Zhukovsky, www.izhuk.com