cox.jmatt.java.MathTools.util
Class BasicMathPrinter

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by cox.jmatt.java.MathTools.util.BasicMathPrinter
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 BasicMathPrinter
extends java.awt.Panel
implements MathPrinter, java.awt.event.ActionListener, java.awt.datatransfer.ClipboardOwner

This class provides a MathPrinter implementation with all required methods and several extension points. The basic log and print functions are covered and extra machinery is provided to extract the stack trace from a Throwable and return it as a String. In addition, BMP provides a simple GUI with a TextArea to receive messages, Checkboxes to selectively enable/disable the three log levels, a Checkbox to enable/disable stack trace printing, and a Button to clear the console (txaConsole). The standard GUI arranges the buttons and checkboxes to the right of the console. This is accomplished via the standardGUI() method which returns a reference to the MathPrinter itself; the constructor DOES NOT establish the GUI!

The extension machinery comes via the required processMathObject() method and the processGoButton() method. MathTools-using applications can use the first method as required per the purpose of the application. The latter method is used if BMP is subclassed as the application's GUI. The processGoButton() method is called whenever the [Go!] button is clicked. Default behavior is to test the log and print methods but it is primarily provided to allow for easy subclassing: applications with minimal GUI requirements can simply subclass BMP and provide what they need there. (The default version also checks for version information in the resource 'version.txt' in the top level of the JAR file.)

For subclasses with more complex GUI requirements, standardGUI() is NOT mandatory! Each necessary component, txaConsole and the control Panel, has a finalized public to build it. For a complex GUI, subclass BMP, set the layout as required and add txaConsole and getControlPanel() wherever they are convenient. The getTitle() method is used in the standardGUI() to put a title in the NORTH position. If the GUI requirement is more complex still, implement the MathPrinter interface manually.

All MathPrinter methods except processMathObject() are finalized. This is done to prevent infinite loops: BMP is designed to RECEIVE from CapCom, not to SEND to it. If overriding the processMathObject() method DO NOT call CapCom.processMathObject(), otherwise bad things will happen! Default behavior for the processMathObject() method is to dump the toString()'ed contents of the argument to the clipboard if this is enabled and the argument is not null.

See Also:
Serialized Form

Nested Class Summary
 
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
 java.awt.TextArea txaConsole
          This is the TextArea used for displaying information.
 
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
BasicMathPrinter()
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent aev)
          This method checks to see if the [Clr] or [Go!] buttos have been pressed.
 void clearScreen()
          Clear the TextArea.
 java.awt.Panel getControlPanel(boolean pVertical)
          The control Panel holds the [Go!] and [Clr] buttons as well as the log enable\disable checkboxes.
 java.lang.String getTitle()
          Override this method to change BMP's title to something other than 'Basic MathPrinter'.
 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 pErr)
          Logged messages and stack traces appear in the TextArea if their levels are enabled.
 void mathPrintln(java.lang.String pMesg)
          These messages go straight to the TextArea.
 void printStackTrace(java.lang.Throwable pThr)
          Extract and print the Stack Trace from a throwable.
 void processGoButton()
          This method provides an extension point for simple subclasses.
 java.lang.Object processMathObject(java.lang.Object pObj)
          This method provides access to the system Clipboard if the '[]Clip' Checkbox is enabled.
 MathPrinter standardGUI()
          This method sets up the standard GUI: BorderLayout with getTitle() in the NORTH position, txaConsole in the CENTER, and the control panel at EAST.
 
Methods inherited from class java.awt.Panel
addNotify, getAccessibleContext
 
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, getLocale, 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, resize, resize, 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
 

Field Detail

txaConsole

public final java.awt.TextArea txaConsole
This is the TextArea used for displaying information. The standard format has it in the center of a BorderLayout but subclasses may wish to change its location. If so, it is critical that it be added somewhere, otherwise the printed information will not display properly!

Constructor Detail

BasicMathPrinter

public BasicMathPrinter()
Method Detail

standardGUI

public final MathPrinter standardGUI()
This method sets up the standard GUI: BorderLayout with getTitle() in the NORTH position, txaConsole in the CENTER, and the control panel at EAST. It returns a reference to the MathPrinter itself to allow for customization. Subclasses can rearrange things but when only a MathPrinter is needed the construct (new BasicMathPrinter()).standardGUI() can be used in place of the constructor.


getControlPanel

public final java.awt.Panel getControlPanel(boolean pVertical)
The control Panel holds the [Go!] and [Clr] buttons as well as the log enable\disable checkboxes. It can be presented vertically or horizontally.

Parameters:
pVertical - true for a vertical bar, false for horizontal.

mathLog

public final void mathLog(byte pLevel,
                          java.lang.String pMesg,
                          java.lang.Throwable pErr)
Logged messages and stack traces appear in the TextArea if their levels are enabled.

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

printStackTrace

public void printStackTrace(java.lang.Throwable pThr)
Extract and print the Stack Trace from a throwable. If 'S Trace' is enabled and pThr is not null.


mathPrintln

public final void mathPrintln(java.lang.String pMesg)
These messages go straight to the TextArea.

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

processMathObject

public java.lang.Object processMathObject(java.lang.Object pObj)
This method provides access to the system Clipboard if the '[]Clip' Checkbox is enabled. If the Object passed in is not null and the clipboard is enabled, the Object's toString() content is wrapped in the appropriate Transferable and sent to the clipboard. Any errors are reported at Debug level. The Object sent in is returned unaltered.

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

processGoButton

public void processGoButton()
This method provides an extension point for simple subclasses. It is called whenever the [Go!] button is clicked. The default implementation provides a basic test of the logging and print methods, including setting itself as the Global Printer. It will also look for the resource '/version.txt' and print its contents, if found. This file is in the top level of the JAR and stores, well, version information.


getTitle

public java.lang.String getTitle()
Override this method to change BMP's title to something other than 'Basic MathPrinter'.


clearScreen

public void clearScreen()
Clear the TextArea.


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent aev)
This method checks to see if the [Clr] or [Go!] buttos have been pressed. Subclasses overriding this method should call super.actionPerformed() to allow for proper clearing of the screen and [Go!] button processing.

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