cox.jmatt.java.MathTools.demo
Class GPGenerator

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.GPGenerator
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 GPGenerator
extends java.awt.Panel
implements java.awt.event.ActionListener

This class is a graph paper generator demo/utility. It uses SVG and the svg.* package to create various types of graph paper. The SVG documents can then be transformed into PDF or other formats by an external utility like Apache Batik. Each panel creates a different type of graph paper and the output can be sent to the clipboard.

All graph paper generated is by default for letter-sized paper (8.5" x 11") with a viewport set to '850 1100'. This yields a scale of 100 units per inch in both dimensions and that is how all spacing is measured. NOTE: Whenever a length or other absolute linear measure is used each unit is automatically 1/100 of the base unit! So, margin settings are 100 per inch. Default margins are Top 50, Bottom 1150, Left 50 and Right 800; this yields a half-inch margin all the way around the paper.

For advanced users all of these quantities can be changed. The units are all recognized by the SVG standard: inches, centimeters, millimeters, 'em', 'ex', points, picas and pixels. The SVG 'viewBox=' attribute is calculated for 100 user units per inch: it is set to 100 * the (double) value in the height and width TextFields. There is no safety checking so USE WITH CARE!!

Global Pens

GPGenerator defines 31 built-in pens for creating graphs. Specific details are given in the addPens() method, which adds the standard (global) pens to Any SVGTag. Pen 30 is the suppression pen; it has no stroke or fill set, so it is invisible. It can also be hand-edited easily; it appears at the end of the CSS list.

Speaking of CSS, GPGenerator creates a massive embedded stylesheet with each document. More pens than any one utility could ever use. If this becomes a problem the unused pens (CSS rules) are easily deleted. The internal stylesheet is just that, internal!

Why no methods here?!?

Each type of graph paper is generated by its own dedicated GraphPanel. Configuration methods are there. All this class really does is manage them and prepare the SVGTag used for drawing.

Graph Paper and Scripting

Besides being good for generating graph paper the individual generators are also scriptable. The demo.gpgdemo.GraphPanelFactory class ('Notebook' to scripts). facilitates this. When run from the JAR each generator in the GUI is the instance exposed to scripts. This means scripts can set the GUI and GUI settings can affect script output. GraphPanel defines two complementary methods toPizza() and eatPizza(). The former turns the current GUI settings for a generator into java.util.Properties-formatted lines of text. The former takes a Properties object and extracts configuration information from it. Panel 'B' in this demo provides an area to put such information.

Each generator has a '[To Pizza]' button, an '[Eat Pizza]' button and a text field for key prefixes. When the text output from a generator is placed into the pizza area and its '[Eat Pizza]' button clicked it will configure from the data there. The prefix, if provided, is prepended to the property key. This allows multiple configurations to be stored in a single file or placed into the pizza area. Even though it is not a GraphPanel the margin and paper size Panel can also create and consume a pizza.

Available Graph Paper

Each graph paper generator is independent of all the others. The only thing they really share is the pens and those are output with each document. The default values listed on each panel give 'pretty' graph paper but by all means experiment!

A. The Configuration Panel

This class actually has very little to configure. The margins can be set but should be set carefully. Some sanity-checking is done but carelessness with the margins may result in unparseable or invalid documents. As with other quantities the units are 1/100 of an inch.

B. Graph Paper Pizzaria

This panel is for pizza configuration information for the other generators and the Config Panel. Pizzas placed here can be used to configure the other panels.

Clicking the 'B' panel '[Eat Pizza]' button does parse the Properties object BUT it uses it to set default config properties for the getMDraw() method. This means any tag- or pen-class pizza-settable properties can be specified here. All graph paper generators here use this method to get their MathDrawSVG instances so any properties 'eaten' from this panel go there.

C. Square-Grid (Quadrille) Paper

This panel generates plain vanilla square-grid paper. Details are here.

D. Polar Paper

This panel generates polar-grid paper. Details are here.

E. Log and Semilog Paper

This panel generates logarithmic and semilog paper. Details are here.

The default settings have a logarithmic vertical scale (horizontal lines) and a quarter-inch linear horizontal scale (vertical lines). For a decent horizontal log scale use 4 cycles at length 10 with an interval of 55.

F. Multicolumn or Ledger Paper

This generator produces multi-column paper with optional headers and row lines. See here.

G. BPS Chart

BP/S stands for 'Blood Pressure / Sugar' and creates a chart for tracking blood pressure or blood sugar (or both!).

I. Hexagonal-Grid Paper

This is a quick and dirty generator for hex-grid paper. The size and number of hexes can be adjusted and the rows and columns numbered.

I. Bar Chart

This generator generates bar charts. Check here for details.

J. Musical Notation Paper

MusicPanel provides a simple, flexible generator for music paper.

K. Lettering Guide Paper

This panel generates configurable-line paper usable to design lettering guides children use when learning to write.

L. Offset Quadrille Paper

This generator produces square- or rectangular-grid paper with alternate rows offset, resuilting in a brick-like grid.

M. Symmetric Log Paper

This is a modified type of logarithmic paper. The intervals begin at the axis and shrink as they move away from it.

N. Isometric Paper

Isometric paper consists of a grid of equilateral triangles, which is what this generator creates.

The perspective generator produces a one-point perspective grid. Both horizontal and vertical perspective can be configured independently.

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 boolean GP_DEBUG
          This constant is defined to assist in developing the various graph paper generators.
static java.lang.String GPG_CLIP
          This constant holds the name of the <clipPath> defined around the margins of the paper.
static int MAX_PEN
          Static constant for the number of the last defined pen.
 
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
GPGenerator()
          Standard constructor.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent aev)
          Handle all button clicks.
static void addPens(SVGTag gPaper)
          Add the standard pens to the SVGTag supplied.
 void eatPizza(java.util.Properties pPizza, java.lang.String pPrefix)
          Load size and margin settings from a Properties object.
 void eatPizza(java.lang.String pPrefix)
          Load configuraton data from the Pizzaria panel.
static StylePen getClipPen()
          This method is used in conjunction with the margin clipPath tag that is automatically defined.
static MathDrawSVG getMDraw()
          This class maintains ONE MathDrawSVG instance.
 java.awt.Menu getMenu()
          This is the menu that appears in the Demo Frame whenever 'View/Graph Paper' is selected.
 void setPizza(java.lang.String pPizza)
          Put a non-null, non-blank String into the Pizzaria area.
 java.awt.Panel standardGUI()
          Build the standard GUI.
 java.lang.String toPizza(java.lang.String pPrefix)
          Even though this is not technically a GraphPanel this method was defined to allow persistence of margin and size settings.
 
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

MAX_PEN

public static final int MAX_PEN
Static constant for the number of the last defined pen.

See Also:
Constant Field Values

GP_DEBUG

public static boolean GP_DEBUG

This constant is defined to assist in developing the various graph paper generators. It is settable via the '[]GP Debug' Checkbox on the margin panel here, GraphPanel and GraphPanelFactory Its only effect here is to draw a border along the margins of the SVGTag delivered to the panels when in GUI mode. The value is set any time the '[Go!]' button is clicked.


GPG_CLIP

public static final java.lang.String GPG_CLIP
This constant holds the name of the <clipPath> defined around the margins of the paper. This tag is not actually applied, it is defined in case it is needed and its ID is here. This String does NOT start with the '#' character!

See Also:
Constant Field Values
Constructor Detail

GPGenerator

public GPGenerator()
Standard constructor. Nothing else needed.

Method Detail

getClipPen

public static StylePen getClipPen()

This method is used in conjunction with the margin clipPath tag that is automatically defined. It is ONLY defined within this class, so this is of most use when subclassing. The StylePen returned has NO attributes set other than the clip URL, which refers to the clipPath tag.


getMDraw

public static MathDrawSVG getMDraw()
This class maintains ONE MathDrawSVG instance. This is done to allow pre-configuration if needed. This method maintains it. Clicking the '[Reset]' button on the Pizzaria panel clears the current instance and forces a new one the next time this method is called.


getMenu

public java.awt.Menu getMenu()
This is the menu that appears in the Demo Frame whenever 'View/Graph Paper' is selected. It is normally disabled but specifically selecting the 'Graph Paper' option from the 'View' menu OR clicking any button on a Graph Paper Generator panel enables it.


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent aev)
Handle all button clicks.

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

addPens

public static final void addPens(SVGTag gPaper)

Add the standard pens to the SVGTag supplied. The detailed descriptions are here.

Pen_0 to Pen_4: Line Pens
'stroke-width: 1; fill: none'
'stroke' (colors): black, #333, #555, #777, #bbb
Pen_5 to Pen_9
'stroke-width: 1; fill: none'
'stroke-dasharray: 10 10'
'stroke' (colors): black, #333, #555, #777, #bbb
Pen_10 to Pen_14
'stroke-width: 1; fill: none'
'stroke-dasharray: 5 5'
'stroke' (colors): black, #333, #555, #777, #bbb
Pen_15 to Pen_19
'stroke-width: 1; fill: none'
'stroke-dasharray: 2 2'
'stroke' (colors): black, #333, #555, #777, #bbb
Pen_20 to Pen_24: Text Pens
'stroke-width: 1; stroke: none; fill: black;'
Text anchor point: center.
Font size: 10, 15, 20, 25, 30
Pen_25 to Pen_29: Thick Line Pens
'stroke-width: 4; fill: none'
'stroke' (colors): black, #333, #555, #777, #bbb
Pen_30: Suppression Pen
'stroke: none; fill: none;'

The font sizes range from (about) 8-point to (roughly) 24-point. The 'stroke: none' makes the letters look nice.

Parameters:
gPaper - The SVGTag to receive the standard StylePens.

standardGUI

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


toPizza

public java.lang.String toPizza(java.lang.String pPrefix)
Even though this is not technically a GraphPanel this method was defined to allow persistence of margin and size settings. The two Checkboxes, 'processMathObject' and 'Debug mode' are not saved.


eatPizza

public void eatPizza(java.util.Properties pPizza,
                     java.lang.String pPrefix)
Load size and margin settings from a Properties object. If present the prefix is prepended to the property keys.


eatPizza

public void eatPizza(java.lang.String pPrefix)
Load configuraton data from the Pizzaria panel.


setPizza

public void setPizza(java.lang.String pPizza)
Put a non-null, non-blank String into the Pizzaria area.