cox.jmatt.java.MathTools.util
Class MTApplet

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
                  extended by cox.jmatt.java.MathTools.util.MTApplet
All Implemented Interfaces:
MathPrinter, java.awt.datatransfer.ClipboardOwner, java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

public class MTApplet
extends java.applet.Applet
implements java.awt.event.ActionListener, MathPrinter, java.awt.datatransfer.ClipboardOwner

This Applet is designed to allow MathTools scripting via a web browser and to act as CapCom's MathPrinter on an (X)HTML page. The GUI consists of a TextArea used for displaying log and print messages along with Checkboxes to enable/disable log levels, a Checkbox to enable the Clipboard, a [Calc] button to show a QuickRPNCalculator, a [Clr] button to clear the screen. When using MTApplet make sure to leave room for these components!

All MathPrinter method are finalized method because they are not designed to be subclassed. To script MathTools using a browser, embed a MTApplet somewhere in the page. Obtain a reference to it from the scripting language, call setAsPrinter() if desired, and program away!

NOTE: All create__() methods in this Applet return static versions of their class. To obtain the SCROB aliases call the (instance) getSCROB() method on the Object returned.

Applets generally do not have filesystem access so MTApplet will not create and cannot access the MathFileIO class. It can, however, provide Applet-appropriate access via Class.getResourceAsStream(). This functionality is available through the getResourceStream() and getResourceReader() methods. They both operate from MTApplet's Classloader (not the Math ClassLoader) and must work within the security and access restrictions imposed on any Applet. Use as needed but USE WITH CARE!

Security permitting, the processMathObject() method provides access to the system clipboard. If the Object passed in is not null, the '[]CB' Checkbox is enabled, and the security manager allows it the String content of the Object passed in is dumped to the clipboard.

HTML documents using MTApplet on a local machine may need access to Capcom's MAuthenticator or Accessory creation methods it is possible to set the appropriate flags using <param> tags. The two parameters are control.MAuthenticator for setting MAuthenticator access and control.Accessory to allow accessory creation. Setting either of these to 'true' enables the correspoinding field in CapCom.

The Calculator

MTApplet includes a QuickRPNCalculator usable from a dialog. Since calculators are not always a good idea, it can be enabled or disabled via the setCalculatorEnabled(). The showCalc() method can bring up the calculator from within a script, if it is enabled. By default the calculator is disabled. To enable by default use a <param> tag: set control.Calculator to true.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.applet.Applet
java.applet.Applet.AccessibleApplet
 
Nested classes/interfaces inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface cox.jmatt.java.MathTools.util.MathPrinter
LOG_DEBUG, LOG_ERROR, LOG_INFO
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
MTApplet()
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent aev)
          ActionListener method.
 boolean authenticateInstructor(java.lang.String pCode)
          Check an authentication code at Instructor level.
 boolean authenticateProctor(java.lang.String pCode)
          Check an authentication code at Proctor level.
 boolean authenticateStudent(java.lang.String pCode)
          Check an authentication code at Student level.
 void clearScreen()
          Clear the TextArea used for messages.
 void closeAll()
          MTApplet maintains an internal list of resource InputStreams and Readers.
 Arithmetic createArithmetic()
          Create and return an Arithmetic instance.
 COFormatterFactory createCOFormatter()
          Create a COFormatterFactory
 MathConsole createConsole()
          Create and return a MathConsole.
 GraphEngineFactory createGraphEngineFactory()
          Return a new GraphEngineFactory.
 MathDBC createMathDBC()
          Create a MathDBC instance.
 MathGenHTML createMathHTM()
          Return a MathGenHTML object.
 MathSet createMathSet()
          Create a real-number MathSet.
 MathXML createMathXML()
          Create and return a MathXML object.
 MComplex createMComplex()
          Create a MComplex instance.
 MathDrawSVG createMDraw()
          Return a MathDrawSVG object.
 MathEngine createMEngine()
          Create and return an instance of MathEngine.
 MEquation createMEquation()
          Create and return a MEquation.
 MFraction createMFraction(java.lang.String pFormat)
          Create an MFraction from a formatting String.
 MathGenLatex createMLatex()
          Create a MathGenLatex.
 MMatrixBuilder createMMBuilder()
          Create and return a new MMatrixBuilder.
 MRadical createMRadical()
          Create and return a MRadical.
 MathStat createMStat()
          Create and return a MathStat.
 MTest createMTest()
          Create an empty MTest.
 MathTestFormatter createMTFormatter()
          Create a new MathTestFormatter.
 MTXProcessor createMTXPro()
          Create and return a MTXMLProcessor.
 GraphPanelFactory createNotebook()
          Create a GraphPanelFactory.
 Percent createPercent()
          Create and return a Percent instance.
 Polynomial createPolynomial()
          Create a default (zero) Polynomial.
 Polynomial createPolynomial(java.lang.String pPoly)
          Create a Polynomial from a format String.
 Question createQuestion()
          Create and return a blank Question.
 Question createQuestion(java.lang.String pID, java.lang.String pProb, java.lang.String pAns)
          Create and return a Question with all data provided.
 SimpleTagImpl createSimpleTag()
          Return a SimpleTagImpl.
 void destroy()
          Overridden to call MathDBC.closeAll() and this.closeAll().
 java.io.BufferedReader getResourceReader(java.lang.String pName)
          This method works per getResourceStream() (and does use that method) but wraps the resulting stream in a BufferedReader.
 java.io.InputStream getResourceStream(java.lang.String pName)
          This method allows access to Class.getResourceAsStream(), which provides MTApplet with the closest thing to filesystem access it can get.
 void init()
          Calls setUpGUI().
 void lostOwnership(java.awt.datatransfer.Clipboard pClip, java.awt.datatransfer.Transferable pData)
          Required for the ClipboardOwner interface.
 void mathLog(byte pLevel, java.lang.String pMesg, java.lang.Throwable pThr)
          This method may be called directly or via a MathConsole from createConsole()!
 void mathPrintln(java.lang.String pMesg)
          Send a String to the TextArea 'screen.' Can be called directly or through a MathConsole.
 void printClassInfo(java.lang.Object pObj)
          This method prints the Class name of the Object passed in, or 'null' if it is null.
 java.lang.Object processMathObject(java.lang.Object pObj)
          Overridden for clipboard access, security restrictions permitting.
 void setAsPrinter()
          Call this method to set THIS instance of MTApplet as the Global Printer.
 MTApplet setCalculatorEnabled(boolean isEnabled)
          Enable/disable the calculator.
 void setGlobalPizza(java.lang.String pPizza)
          Convenience method for setGlobalPizza(pPizza, null, null).
 void setGlobalPizza(java.lang.String pPizza, java.lang.String pLineSep, java.lang.String pKeySep)
          No scripting tool allows Global Pizza access past getting parameters from it.
 void setUpGUI()
          Set up the GUI.
 void showCalc()
          Display a QuickRPNCalculator if it is enabled.
 
Methods inherited from class java.applet.Applet
getAccessibleContext, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start, stop
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MTApplet

public MTApplet()
Method Detail

init

public void init()
Calls setUpGUI(). If subclassing this must be done manually!

Overrides:
init in class java.applet.Applet

setUpGUI

public final void setUpGUI()
Set up the GUI. Finalized to allow subclassing.


destroy

public void destroy()
Overridden to call MathDBC.closeAll() and this.closeAll(). If overriding this method they must be called manually.

Overrides:
destroy in class java.applet.Applet

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent aev)
ActionListener method. All it does is clear the screen or show the calculator (if enabled).

Specified by:
actionPerformed in interface java.awt.event.ActionListener

clearScreen

public void clearScreen()
Clear the TextArea used for messages.


showCalc

public final void showCalc()
Display a QuickRPNCalculator if it is enabled. If not, nothing happens.


setCalculatorEnabled

public final MTApplet setCalculatorEnabled(boolean isEnabled)
Enable/disable the calculator. If the calculator is visible when it is disabled it is hidden. Returns a self-reference to allow the calculator to be enabled and made visible (if desired) with one statement.

Parameters:
isEnabled - true to enable the calculator, false to disable and possibly hide it.

mathLog

public final void mathLog(byte pLevel,
                          java.lang.String pMesg,
                          java.lang.Throwable pThr)
This method may be called directly or via a MathConsole from createConsole()!

Specified by:
mathLog in interface MathPrinter
Parameters:
pLevel - One of the LOG_ levels defined above.
pMesg - A String message describing the event.
pThr - A Throwable generated by the event. May be null.

mathPrintln

public final void mathPrintln(java.lang.String pMesg)
Send a String to the TextArea 'screen.' Can be called directly or through a MathConsole.

Specified by:
mathPrintln in interface MathPrinter
Parameters:
pMesg - The String message to be printed.

processMathObject

public final java.lang.Object processMathObject(java.lang.Object pObj)
Overridden for clipboard access, security restrictions permitting. If the '[]CB' Checkbox is enabled and pObj is not null its String content is wrapped in a Transferable and sent to the clipboard.

Specified by:
processMathObject in interface MathPrinter
Parameters:
pObj - The data to be processed.
Returns:
The result of processing the data given.

lostOwnership

public void lostOwnership(java.awt.datatransfer.Clipboard pClip,
                          java.awt.datatransfer.Transferable pData)
Required for the ClipboardOwner interface. Default behavior prints a Debug-level message when ownership is lost.

Specified by:
lostOwnership in interface java.awt.datatransfer.ClipboardOwner

setAsPrinter

public final void setAsPrinter()
Call this method to set THIS instance of MTApplet as the Global Printer.


printClassInfo

public void printClassInfo(java.lang.Object pObj)
This method prints the Class name of the Object passed in, or 'null' if it is null.


setGlobalPizza

public void setGlobalPizza(java.lang.String pPizza,
                           java.lang.String pLineSep,
                           java.lang.String pKeySep)

No scripting tool allows Global Pizza access past getting parameters from it. Applications can set the Global Pizza before script execution, so methods like MathEngine's blines() can function. This method provides MTApplet with the capability to set the Global Pizza, presumably before execution of a script requiring such access.

This method splits the supplied String first on pLineSep and then each 'line' on pKeySep. The result is then added to a Properties object which, when the lines run out, is set as the Global Pizza. The default values for pLineSep and pKeySep are a newline and an equals sign, respectively. The second split has an upper limit of two, so the key separator can be used afterward and will not lose data.

Parameters:
pPizza - The String containing the Properties-formatted data for the Global Pizza.
pLineSep - The separator to split the data into 'lines.' Defaults to a single newline.
pKeySep - The String used to separate the key from the value.

setGlobalPizza

public void setGlobalPizza(java.lang.String pPizza)
Convenience method for setGlobalPizza(pPizza, null, null).


getResourceStream

public final java.io.InputStream getResourceStream(java.lang.String pName)
This method allows access to Class.getResourceAsStream(), which provides MTApplet with the closest thing to filesystem access it can get. The access is only allowed within the bounds of the Applet security constraints so all of its restrictions are in effect. The Math ClassLoader is not accessed so only the resources available to a normal Applet can be fetched. Use with care! Any errors are reported at Error level and the return value for such is null.

Parameters:
pName - The name of the resource to be fetched.

getResourceReader

public final java.io.BufferedReader getResourceReader(java.lang.String pName)
This method works per getResourceStream() (and does use that method) but wraps the resulting stream in a BufferedReader. Restrictions are per getResourceStream() and if a stream cannot be created the return value is null. Any errors are reported at Error level.

Parameters:
pName - The name of the resource to be read.

closeAll

public final void closeAll()
MTApplet maintains an internal list of resource InputStreams and Readers. This method closes them and reports any errors from attempting to do so. The destroy() method calls this one automatically but subclasses overriding it might not. If there is any doubt, call it from the script! Multiple calls will have no ill effects.


authenticateStudent

public final boolean authenticateStudent(java.lang.String pCode)
Check an authentication code at Student level.


authenticateProctor

public final boolean authenticateProctor(java.lang.String pCode)
Check an authentication code at Proctor level.


authenticateInstructor

public final boolean authenticateInstructor(java.lang.String pCode)
Check an authentication code at Instructor level.


createQuestion

public Question createQuestion()
Create and return a blank Question.


createQuestion

public Question createQuestion(java.lang.String pID,
                               java.lang.String pProb,
                               java.lang.String pAns)
Create and return a Question with all data provided.


createMEngine

public MathEngine createMEngine()
Create and return an instance of MathEngine.


createConsole

public MathConsole createConsole()
Create and return a MathConsole. This method uses the zero-argument constructor so the Console returned reflects all method calls through CapCom.


createArithmetic

public Arithmetic createArithmetic()
Create and return an Arithmetic instance.


createMathXML

public MathXML createMathXML()
Create and return a MathXML object.


createPolynomial

public Polynomial createPolynomial()
Create a default (zero) Polynomial.


createPolynomial

public Polynomial createPolynomial(java.lang.String pPoly)
Create a Polynomial from a format String.

Parameters:
pPoly - A String conforming to the Polynomial.createPolynomial() method. Which this one calls!

createMFraction

public MFraction createMFraction(java.lang.String pFormat)
Create an MFraction from a formatting String.


createMMBuilder

public MMatrixBuilder createMMBuilder()
Create and return a new MMatrixBuilder.


createPercent

public Percent createPercent()
Create and return a Percent instance.


createMEquation

public MEquation createMEquation()
Create and return a MEquation.


createMRadical

public MRadical createMRadical()
Create and return a MRadical.


createMStat

public MathStat createMStat()
Create and return a MathStat.


createMTXPro

public MTXProcessor createMTXPro()
Create and return a MTXMLProcessor. IMPORTANT NOTE: If used from a web browser, Applet security constraints may restrict this class!


createGraphEngineFactory

public GraphEngineFactory createGraphEngineFactory()
Return a new GraphEngineFactory.


createMDraw

public MathDrawSVG createMDraw()
Return a MathDrawSVG object.


createMathHTM

public MathGenHTML createMathHTM()
Return a MathGenHTML object.


createSimpleTag

public SimpleTagImpl createSimpleTag()
Return a SimpleTagImpl.


createMathDBC

public MathDBC createMathDBC()
Create a MathDBC instance.


createMTest

public MTest createMTest()
Create an empty MTest.


createMTFormatter

public MathTestFormatter createMTFormatter()
Create a new MathTestFormatter.


createCOFormatter

public COFormatterFactory createCOFormatter()
Create a COFormatterFactory


createNotebook

public GraphPanelFactory createNotebook()
Create a GraphPanelFactory.


createMLatex

public MathGenLatex createMLatex()
Create a MathGenLatex.


createMComplex

public MComplex createMComplex()
Create a MComplex instance.


createMathSet

public MathSet createMathSet()
Create a real-number MathSet.