The classes in the MathTools.demo package are primarily designed around demonstrating the MathTools themselves. They are designed to explore the various methods in the MathTools core classes but they are useful in their own right. Apart from demonstration and exploration they excel at working through individual problems in program design, and in connecting different designs together. They can also help in working out small parts of the overall application. And, of course, they work very well to demonstrate the MathTools classes.

MTDemo: The Supervisor

MTDemo is a specifically-purposed class used to collect all of the other demo applications. It is a self-starting and automatically-closing Frame with two main components: the BasicMathPrinter at the top and the actual demo panels at the bottom. Its sole raison d'etre is as a container for the other demonstration panels. It is the Main-Class of the MathTools jar and can be started by double-clicking it.

MTDemo's GUI is deliberately austere and functional. Its BasicMathPrinter is CapCom's global printer and it provides a display area for all of the other classes. All of the demo classes use CapCom.println() which goes to BasicMathPrinter. The menu selects the specific demo to view and the [<<|] and [|>>] buttons flip through them sequentially. The demo panels themselves appear in a CardLayout below the BasicMathPrinter.

PizzaPanel

The foundation of most of the demo classes is the PizzaPanel. It was designed especially for testing and demonstrating class methods. The PizzaPanel itself consists of a TextArea, [Go!] and [Clear] buttons and a configurable area at BorderLayout.NORTH. The demo Panels fill this with a title and a Choice component. PizzaPanel's TextArea has a configurable number of entries labelled 'par.0,' 'par.1,' up to 'par.9' in the default flavor.

The power of the Pizza comes when the [Go!] button is clicked. Doing so calls the processGoButton() method which is designed to be overridden and filled with demonstration code. The method eatPizza() causes the TextArea to be read into a Properties object from which values can be drawn. Each parameter can be interpreted as a String, an int, a long, a double, or a boolean value. Doing so is as simple as calling as__(x) where '__' is the type of value desired and x is the parameter number. In the demos provided with MathTools, the processGoButton() eats the pizza (prepares the parameters), reads the selection from the Choice, and executes the appropriate code.

The demo classes that have 'Pizza' in their names use PizzaPanel for testing and demonstration. Although MTDemo is a fairly single-purpose class, there is no reason the other pizzas can't be added to another program. Nor any reason another program could not use a PizzaPanel!

GPGenerator

This PizzaPanel subclass is both a demo and a useful tool unto itself. GPGenerator, or Graph Paper Generator does exactly what its name implies. It uses the SVG classes directly from Java to create common types of graph paper. Each 'sheet' is letter-size and has specific options that can be configured. (More complex requirements must be done by script or subclass!)

GPGenerator pre-defines a variety of StylePens, any of which can be specified for any part of the graph paper. There are five stroke colors times four different dash array options, TextPens, thick-line pens and even an invisible pen!

ScriptPanel

ScriptPanel was designed specifically to demonstrate how MathTools can be combined with a scripting language. It is much, much more than that, however. It provides a fully-functional scripting environment courtesy of the javax.script API. ScriptPanel includes four components: the Script Source panel, the Script Pizza panel, the Config panel and the URL Loader panel.

The Script Source panel holds the script to be executed. The Script Pizza panel loads the Global Pizza before running the script. The Config panel picks options and settings, including the scripting language to use, and the URL Loader panel can be used to deliver an URLClassLoader to the ScriptEngineFactory. When the script is executed any properties in the Pizza panel are sent to the Global Pizza, a ScriptEngineFactory is created - optionally around the URLClassLoader - and the MathTools core classes are added to the engine. When the script completes the return Object is converted to a String which is displayed on the MathPrinter and sent to the clipboard, if it is enabled. If an error occurs during script execution it is reported at the Error level.

Even though ScriptPanel is minimal, it is complete. It provides several extension points in the form of overridable methods called before the script starts, when it ends, a method to configure the ScriptEngine and a method to deliver a ClassLoader. Of all the demo classes it is by far the most complex and flexible.

One other note about ScriptPanel. Because a FileDialog might not be present, the Buttons to clear the script are and pizza area are located on the Config panel and locked! This is done to prevent accidental clearing. This is only inconvenient until the first time it prevents accidental loss of a LONG script!

URLLoaderPanel

The URLLoaderPanel provides a minimal GUI around creating and configuring an URLClassLoader. It provides a TextArea to hold a list of URLs and buttons to clear the list area and check the URLs there. If URLLoaderPanel is constructed around a Dialog or Frame it also provides a button to pick a file URL via a FileDialog and another to load a list of URLs from a file. Two methods are present for use in constructing ClassLoaders. The getURL[] method parses the URLs listed, ignores the bad ones and loads the good ones into an array which is returned. The getURLClassLoader() method calls getURLS() and instantiates an URLClassLoader around the resulting array.

URLLoaderPanel was originally a part of ScriptPanel. It was factored out to provide an easy way for other applications to embed an easy way to a ClassLoader. Because of this, URLLoaderPanel and ScriptPanel DO make use of the CapCom Shelf. Before ScriptPanel creates its URLLoaderPanel it shelves Buttons to advance and move back its CardLayout. These are shelved under they keys URL_PANEL_EAST and URL_PANEL_WEST. Any Component can be put there, simply call CapCom.storeObject(URLLoaderPanel.URL_PANEL_EAST, ComponentToStore) and it will be installed in the EAST part of the display.