cox.jmatt.java.MathTools.demo
Class MTFormatterDemo

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by cox.jmatt.java.MathTools.demo.MTFormatterDemo
All Implemented Interfaces:
java.awt.event.ActionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible

public class MTFormatterDemo
extends java.awt.Panel
implements java.awt.event.ActionListener

This class provides a fairly comprehensive demonstration of MathTestFormatter and serves as a handy utility in its own right. The GUI consists of the main (File) panel, an internal template panel, a Properties panel, and a regex data Panel. The main panel has TextFields for selecting template or Properties files as well as a Checkbox to send the formatted template to CapCom.processMathObject(), a Checkbox to enable regex matching and a TextField to enter the regular expression. Since MTDemo uses a BasicMathPrinter this sends the result to the clipboard.

The template can be internal or external. The internal area can be loaded (if this class is built around a Dialog or Frame). The Properties can be both internal and external. Enabling the '[]Properties file' Checkbox on the File panel loads Properties from the file specified. Enabling the internal Properties Checkbox parses the Properties panel (addProperties(String, null, null)) and adds them to the formatter. The order in which properties are set is exactly that: external first followed by internal.

Once the template String and Properties are set the template is formatted using the zero-argument method. From there the result is printed and, if the Checkbox is enabled, processed.

To format using regular expressions enable the '[]Regex' checkbox on the file panel and enter the regular expression in that TextField. The data String(s) to which the regex is to be applied should be entered or loaded in the Regex Data panel. The content is split on newlines and the array is then sent to the reFormat() method. The results are then re-assembled into a newline-separated String and printed/processed.

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
static java.lang.String KEY_FILE
          String constant used to add the File (main) panel.
static java.lang.String KEY_PROPS
          String constant used to add the internal Properties panel.
static java.lang.String KEY_REGEX
          String constant used to add the regular expression data panel.
static java.lang.String KEY_TEMPLATE
          String constant used to add the internal template panel.
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
MTFormatterDemo()
          Zero-argument version, no [Load] buttons will be present.
MTFormatterDemo(java.awt.Dialog pParent)
          Build a demo around a Dialog to allow FileDialogs for loading.
MTFormatterDemo(java.awt.Frame pParent)
          Build a demo around a Frame to allow FileDialogs for loading.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent aev)
          Overridden to handle button clicks, nothing else.
 void clearPanel(java.lang.String pWhich, boolean pOkToClear)
          Clear the internal template or Properties panels.
 java.awt.Panel filePanel()
          Build the File panel.
 java.lang.String formatTemplate()
          This method actually merges the template and data.
 void loadFile(java.lang.String pFile, java.lang.String pWhere)
          Load a file into the internal template or Properties.
 void processGoButton()
          This method is called when the [Go!] button is clicked.
 java.awt.Panel propsPanel()
          Build the internal Properties panel.
 java.awt.Panel regexPanel()
          Build the regex data panel.
 java.awt.Panel standardGUI()
          Build the standard MTFormatterDemo GUI.
 java.awt.Panel templatePanel()
          Build the internal template panel.
 
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

KEY_FILE

public static final java.lang.String KEY_FILE
String constant used to add the File (main) panel.

See Also:
Constant Field Values

KEY_TEMPLATE

public static final java.lang.String KEY_TEMPLATE
String constant used to add the internal template panel.

See Also:
Constant Field Values

KEY_PROPS

public static final java.lang.String KEY_PROPS
String constant used to add the internal Properties panel.

See Also:
Constant Field Values

KEY_REGEX

public static final java.lang.String KEY_REGEX
String constant used to add the regular expression data panel.

See Also:
Constant Field Values
Constructor Detail

MTFormatterDemo

public MTFormatterDemo()
Zero-argument version, no [Load] buttons will be present.


MTFormatterDemo

public MTFormatterDemo(java.awt.Frame pParent)
Build a demo around a Frame to allow FileDialogs for loading.


MTFormatterDemo

public MTFormatterDemo(java.awt.Dialog pParent)
Build a demo around a Dialog to allow FileDialogs for loading.

Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent aev)
Overridden to handle button clicks, nothing else.

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

standardGUI

public final java.awt.Panel standardGUI()
Build the standard MTFormatterDemo GUI.


filePanel

public final java.awt.Panel filePanel()
Build the File panel.


templatePanel

public final java.awt.Panel templatePanel()
Build the internal template panel.


propsPanel

public final java.awt.Panel propsPanel()
Build the internal Properties panel.


regexPanel

public final java.awt.Panel regexPanel()
Build the regex data panel.


clearPanel

public final void clearPanel(java.lang.String pWhich,
                             boolean pOkToClear)
Clear the internal template or Properties panels. Since the [Load] button might not be present the clear functions are locked. The internal machinery clears based on the state of the '[]Lock' checkboxes.

Parameters:
pWhich - KEY_TEMPLATE to clear the template panel, KEY_PROPS to clear the Properties panel, KEY_REGEX to clear the regex data.
pOkToClear - true to really clear it, false not to.

loadFile

public final void loadFile(java.lang.String pFile,
                           java.lang.String pWhere)
Load a file into the internal template or Properties. The pWhich parameter determines who gets the load, the pFile determines the file to load. Any errors are reported at Error level.

Parameters:
pWhere - KEY_TEMPLATE to load an internal template, KEY_PROPS to load the Properties panel, KEY_REGEX to load regex data.
pFile - The name of the file to load.

formatTemplate

public java.lang.String formatTemplate()
This method actually merges the template and data. It reads the internal template or loads, depending on which is selected, collects Properties from the internal set and loads the properties file if enabled, then formats the template. The result is returned as a String. Any errors are reported at Error level and the return value is a blank String. If regex matching is enabled the regex on the File panel is compiled and applied to each String in the regex data area; the content of the TextArea is split on newlines and the resulting array sent to reFormat().


processGoButton

public void processGoButton()
This method is called when the [Go!] button is clicked. It calls formatTemplate(), prints the result, and sends it to CapCom.processMathObject() if that is enabled. For a BasicMathPrinter this dumps the String to the clipboard.