Previous Topic

Next Topic

Book Contents

Book Index

Sample Java Application

The sample Java program below illustrates how to use the EquationComposer class to generate images from MathML. The source code is provided so that you can experiment with different techniques for use in your own programs.

Prerequisites for Running the Program

  • Java 1.6 or higher
  • The dessci.lic file needs to be in the same directory as the sample code batch file or shell script.
  • The required .jar file needs to be on the classpath: MathFlow.jar (all MathFlow SDK classes)

Running the Program

<path-to-mathflow-sdk>/java/samples/equation_composer_app.bat (on Windows systems)
<path-to-mathflow-sdk>/java/samples/equation_composer_app.sh (on non-Windows systems)

The sample program allows you to change the input parameters used to generate an equation image (see below). After changing the input parameters and telling the program where to save the generated image, click the Generate Image File button. This will refresh the image shown and save the image to a file, and the Clear Image button will remove the image and any text in the status bar.

equation_composer_java

About the Script

The batch file (or shell script) calls EquationComposerApplication.

java -classpath .;../MathFlow.jar

com/yourcompany/samplecode/composer/EquationComposerApplication

Note that the source code for the sample program is located in the following directory:

<path-to-mathflow-sdk>java/samples/com/yourcompany/samplecode/composer/EquationComposerApplication.java

Programming Notes

The main functions/subroutines in this program are as follows:

generateImageFile()

Uses a Try/Catch block to

  • Call setOptions to set the options for the Equation Composer using the values of the program controls
  • Call the method to generate the image

setOptions()

  • Sets the value of each option for the Equation Composer from the corresponding program control
  • The general strategy in the sample application for handling exceptions in the SetOption methods is as follows:
    • If an option is required (i.e., license, mathml or mathmlfile) and an exception is thrown by the SetOption method, throw an exception with the error message returned from the SetOption method.
    • If an option is optional and has a default value (e.g., pointsize), catch any exception thrown by the SetOption method, retain the warning message for display later and continue processing, using the default value for that option
    • If an option is optional and does not have a default value (e.g., logfile), catch any exception thrown by the SetOption method, retain the resulting message for display later and continue processing

Note that this is only one way in which the options for an Equation Composer can be set. Another possible approach would be to call each set method when the value of a program control changes.

getOptions()

Sets the value of the program controls from the corresponding options of the Equation Composer

readOptions()

Uses a Try/Catch block to

  • Call the method to read the options from an XML file
  • Call getOptions to set the value of the program controls using the options for the Equation Composer

saveOptions()

Uses a Try/Catch block to

  • Call setOptions to set the options for the Equation Composer using the values of the program controls
  • Call the method to save the options to an XML file

Previous Topic

Next Topic

Book Contents

Book Index


[Design Science Home]
Copyright © 1996-2016 Design Science, Inc. All rights reserved.