Previous Topic

Next Topic

Book Contents

Book Index

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 Design Science. 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 Style Editor. This functionality is already provided by the Simple Editor 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 Simple Editor class. Note that 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();
}

Previous Topic

Next Topic

Book Contents

Book Index


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