Simple Editor application

MathFlow Simple Editor components can be used within Java applications. There are two versions of the Simple Editor component. Note: These pages linked below are offered here for your convenience. If you have installed the MathFlow SDK, it's better if you refer to the copy that was installed with the SDK. These are located in the javadocs folder, which for Windows is specifically
C:/Program Files (x86)/MathFlow SDK/2.1/java/docs/javadoc/com/dessci/mathflow/sdk/editor/

The SimpleEditorFrame components can be embedded either directly in a Java application or opened in a separate, non-modal window. The SimpleEditorDialog components can be opened in a separate modal window. To create an instance of either one of these, the constructor is called with two or more of the following objects:

  • (Required) Host Application for callbacks and notifications.
  • (Required) License key or FlexNet license file.
  • (Optional) SimpleConfigInfo. More information in the javadocs folder, at /webeq3/app/.
  • (Optional) OptionsInfo, which allows you to save the General Editing Preferences to an external file to persist user settings. More information in the javadocs folder, at /webeq3/util/.

Overview, Simple Editor application

Included in the MathFlow SDK is a sample Simple Editor application, located at

<path-to-mathflow-sdk>/java/samples/com/yourcompany/samplecode/editor/SimpleEditorDemoApplication.java

There is a bat file to run the demo application:

<path-to-mathflow-sdk>/java/samples/simplEditor.bat

This sample application illustrates how to include the MathFlow SDK Simple Editor in your own application. In this case, the SimpleEditorDialog class is used to create a modal pop-up MathML editor:

Simple Editor application

This sample application does the following:

  • Read MathML from a file
  • Write MathML to a file
  • Send MathML to the Simple Editor
  • Retrieve MathML from the Simple Editor
  • Retrieve an image of the MathML equation from the Simple Editor
  • Display the current MathML
  • Display an image of the MathML equation from the Simple Editor once OK has been clicked in the editor
  • Display an about box

Simple Editor classes

The following classes have been written for the sample Simple Editor application:

  • SimpleEditorDemoApplication: The host application that launches the customized SimpleEditorDialog.
  • SampleSimpleEditorDialog: A subclass of the SimpleEditorDialog class customized for this application.
  • SampleSimpleEditorAboutBox: A subclass of the SimpleEditorAboutBox class customized for this application.

SimpleEditorDemoApplication

The SimpleEditorDemoApplication user interface consists of the following:

  • File Menu
    • Open MathML…
    • Save MathML…
    • Quit
  • Help Menu
    • About MathFlow SDK Simple Editor
  • MathML source panel
  • Preview image panel
  • Edit Equation… button
NOTE: The code discussed in this topic can be found in SimpleEditorDemoApplication.java, located at <MathFlow installation folder>/java/samples/com/yourcompany/samplecode/editor/SimpleEditorDemoApplication.java.
  1. The constructor sets the application title, font preferences and calls initUI() to create the application's UI elements. It also changes the cursor to a wait cursor. For more information on setting the font preferences, see Java rendering engine.
  2. The createEditor method creates two objects, which are then passed into the constructor of the SampleSimpleEditorDialog:
    • Creates a SimpleConfigurationInfo object to indicate which features are turned on or off in the editor. You can also set the type of end-user help system in this object. See the sample code in SimpleEditorDemoApplication.java (mentioned above) and End-user help options for choosing and setting your help system.
    • Sets the key string, which is either the path to a FlexNet license file or a license key string assigned by Wiris. See the sample code in SimpleEditorDemoApplication.java (mentioned above) and MathFlow SDK licenses for help setting the license string and more information about the license types.
  3. The method showEditor checks to see if createEditor() has been successful and displays the Style Editor as a dialog.
  4. The updateSrcAndImage method retrieves the MathML from the editor using the editor's getMathML method, and displays it in the MathML source panel. The method also retrieves an image of the equation, using the editor's getEquationImage method, as well as its size using the editor's getPreferredWidthAt and getPreferredHeightAt methods. The image is then displayed in the Image preview panel.
  5. The notifyEditorShown method is used by the editorDialog to notify the host application when the editor has been shown. The host application then resets the cursor back to its default state.
  6. The host application can also display a customized About box. See SampleSimpleEditorAboutBox.java, located at <MathFlow installation folder>/java/samples/com/yourcompany/samplecode/editor/SimpleEditorAboutBox.java.

SampleSimpleEditorDialog

The SampleSimpleEditorDialog class extends the SimpleEditorDialog class provided in the MFSimpleEditor.jar file. The constructor for this class requires the following:

  • A reference to the host application
  • A license key string, which can either be a path to the license file or a key string provided by Wiris. See MathFlow SDK licenses.
  • A configuration object to indicate which built-in features to turn on or off

One of the host application's functions is to request the MathML of the equation in the Simple Editor. This functionality is already provided by the SimpleEditor class; therefore, creating a method to access it is straightforward.

public String getMathML(){
    return getFormattedMathML(Equation.PRESENTATION,
      Equation.PRETTY_PRINT,
      0, "", Equation.ENTITY_NAMES);
  }

Similarly, the host application needs a way to send MathML to the Simple Editor. Again, this functionality is already provided by the SimpleEditor class. Note you will need to reset the undo stack since it is a new equation.

public void setMathML(String mathml) {
    super.setMathML(mathml);
    // we want to clear the undo stack from previous editing operations
    clearUndoStack();
  }

The host application needs a way to retrieve an image of the MathML equation in the Simple Editor. This functionality is already provided by the class. In this case, only the point size and background color of the equation are passed in, but there are other parameters that can be used to control the look of an equation.

public Image getEquationImage(int pointsize, String bgcolor) {
    return getEquationImage(pointsize, 0, "black",
      bgcolor, "left", "top", 0, 0, 0, 0);
  }

It is also possible to customize the about box to add additional information. See the code for the customized about box in SampleSimpleEditorAboutBox.java.

protected void showAboutBox() {
    if (aboutBox == null) {
      aboutBox = new SampleSimpleEditorAboutBox(this);
    }
    Rectangle r1 = getBounds();
    Rectangle r2 = aboutBox.getBounds();
    aboutBox.setLocation(r1.x + (r1.width - r2.width) / 2,
      r1.y + (r1.height - r2.height) / 2);
    aboutBox.show();
  }

Finally, when the Simple Editor is closed, it calls back to the host application to tell it to update the MathML Source and Preview Image parts of its screen.

protected void closeEditorWindow() {
    if (getCallbackInfo() == COMPLETED) {
      ownerApp.updateSrcAndImage();
    }
    // you MUST write out the users preferences or any changes will be lost
    writeExportOptions();
    hide();
  }