Class GenericGraphApplet
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- java.awt.Panel
-
- java.applet.Applet
-
- GenericGraphApplet
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.awt.event.ItemListener
,java.awt.image.ImageObserver
,java.awt.MenuContainer
,java.io.Serializable
,java.util.EventListener
,javax.accessibility.Accessible
- Direct Known Subclasses:
AnimatedGraph
,Derivatives
,EpsilonDelta
,FamiliesOfGraphs
,FunctionComposition
,IntegralCurves
,MultiGraph
,Parametric
,RiemannSums
,SecantTangent
,SimpleGraph
public class GenericGraphApplet extends java.applet.Applet implements java.awt.event.ActionListener, java.awt.event.ItemListener
GenericGraphApplet serves as a base class for applets that have a DisplayCanvas in the CENTER of a BorderLayout and that are configurable by a large number of applet parameters. This base class sets up the basic structure of the applet and processes many applet parameters. Most of the work is done in methods that can be overridden in subclasses. If the height of the applet is greater than 100 and if the applet parameter "LaunchButtonName" is not defined, then the main panel of the applet appears in the applet itself. Otherwise, the applet appears as a button. Clicking the button opens the main panel of the applet in a separate, resizable frame.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected DisplayCanvas
canvas
The canvas for displaying axes, graphs, etc.protected java.awt.Button
computeButton
A button that the user presses to recompute the display.protected int[]
defaultFrameSize
The default size for the frame when the applet runs a launch button.protected JCMPanel
exampleMenuPanel
A panel containing examples specified in applet parameters, if any.protected java.lang.String
frameTitle
The string that is used as the title of the frame, if the applet appears as a launch button.protected ExpressionInput
functionInput
An input box for inputting an expression.protected JCMPanel
inputPanel
A panel containing the functionInput.protected LimitControlPanel
limitsPanel
Controls the limits of the x- and y-coordinates on the canvas.protected Controller
mainController
The Controller from the mainPanel.protected JCMPanel
mainPanel
The main panel of the applet, containing a display canvas and other components.protected java.util.Hashtable
parameterDefaults
A hash table that, if non-null, can hold values for applet params.protected Parser
parser
The parser which is used for parsing input from the functionInput box.protected Variable
xVar
The variable that is created and added to the parser.
-
Constructor Summary
Constructors Constructor Description GenericGraphApplet()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
actionPerformed(java.awt.event.ActionEvent evt)
Respond when user clicks a button; not meant to be called directly.protected void
addCanvasBorder()
This method is called by setUpMainPanel() to add a border to the canvas (since the border is typically the last thing that should be added, on top of anything else in the canvas.void
destroy()
Closes the frame (if any) when the applet is destroyed.protected void
doLoadExample(java.lang.String example)
This method is called when the user loads an example from the example menu (if any).protected java.awt.Color
getColorParam(java.lang.String data)
Get The value of an applet parameter that specifies a color.protected java.awt.Color
getColorParam(java.lang.String paramName, java.awt.Color defaultColor)
Get The value of an applet parameter that specifies a color.protected double[]
getNumericParam(java.lang.String paramName)
Get The value of an applet parameter that consists of a list of numbers.protected double[]
getNumericParam(java.lang.String paramName, double[] defaults)
Get The value of an applet parameter that consists of a list of numbers.java.lang.String
getParameter(java.lang.String paramName)
Override the standard applet method getParameter(String) so that when no param value is provided in the applet tag, and if parameterDefaults is non-null, it will check for a value the parameterDefaults.protected java.lang.String
getParameter(java.lang.String paramName, java.lang.String defaultValue)
Get the value of an applet parameter, but return a default if the value is null.void
init()
The init() method is called by the system to set up the applet.void
itemStateChanged(java.awt.event.ItemEvent evt)
Respond when user chooses an example from the example menu.protected Axes
makeAxes()
Construct a set of Axes, based on applet params "AxesColor", "AxesLightColor", "XLabel", "YLabel", "LabelColor".protected TableFunction
parseTableFuncDef(java.lang.String def)
Create a TableFunction from a string.protected void
setUpBottomPanel()
This method checks the applet parameter "UseFunctionInput".protected void
setUpCanvas()
This method is called by mainPanel() to set up the display canvas and add it to the main panel.protected void
setUpExampleMenu()
This method processes applet parameters that specify examples for the applet and adds them to a menu of examples.protected void
setUpLimitsPanel()
This method sets up the limit control panel and adds it to the main panel.protected void
setUpMainPanel()
This method is called to set up the main panel of the applet.protected void
setUpParameterDefaults()
This method, which is empty in the GenericGraphApplet class, can be defined in a subclass to set default values for applet params that are different from the ones provided in this class.protected void
setUpParser()
This method is called by setUpMainPanel() to set up the parser to be used in the applet.protected void
setUpTopPanel()
This method is called by setUpMainPanel() to add a panel at the top of the applet.void
stop()
Releases the resources used by the display canvas when the applet is stopped.-
Methods inherited from class java.applet.Applet
getAccessibleContext, getAppletContext, getAppletInfo, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameterInfo, isActive, isValidateRoot, newAudioClip, play, play, resize, resize, setStub, showStatus, start
-
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, 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, 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, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, reshape, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setMixingCutoutShape, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
parser
protected Parser parser
The parser which is used for parsing input from the functionInput box.
-
mainPanel
protected JCMPanel mainPanel
The main panel of the applet, containing a display canvas and other components.
-
mainController
protected Controller mainController
The Controller from the mainPanel.
-
canvas
protected DisplayCanvas canvas
The canvas for displaying axes, graphs, etc.
-
limitsPanel
protected LimitControlPanel limitsPanel
Controls the limits of the x- and y-coordinates on the canvas.
-
functionInput
protected ExpressionInput functionInput
An input box for inputting an expression.
-
xVar
protected Variable xVar
The variable that is created and added to the parser. The default name of this variable is "x", but that can be changed using the "Variable" applet param. The variable is created in the setUpParser() method.
-
inputPanel
protected JCMPanel inputPanel
A panel containing the functionInput. It appears at the bottom of the main panel.
-
exampleMenuPanel
protected JCMPanel exampleMenuPanel
A panel containing examples specified in applet parameters, if any. It appears at the top of the main panel.
-
computeButton
protected java.awt.Button computeButton
A button that the user presses to recompute the display. (Ths user can also just press return in one of the input boxes.)
-
frameTitle
protected java.lang.String frameTitle
The string that is used as the title of the frame, if the applet appears as a launch button. This title is also used on the launch button, unless the applet parameter "LaunchButtonName" has a value. This is set in the init() method.
-
defaultFrameSize
protected int[] defaultFrameSize
The default size for the frame when the applet runs a launch button. Can be overidden by the FrameSize applet param.
-
parameterDefaults
protected java.util.Hashtable parameterDefaults
A hash table that, if non-null, can hold values for applet params. While this is not set to a non-null value in this class, its value can be set in the setUpAppletDefaults() method. The values in this hash table will be returned by the getParameter() method when no value is provided in the applet. For example, this class uses a default value of "s" vor the the param "Variable". A subclass could put a different value in the parameterDefaults hash table, and this value will be used in preference to "x".
-
-
Method Detail
-
init
public void init()
The init() method is called by the system to set up the applet. If the applet does not appear as a button, then init() creates the main panel of the applet and calls setUpMainPanel to set it up. If any error occurs during calls to setUpParser(), setUpExampleMenu(), or setUpMainPanel(), then the applet will just show an error message, and stack trace will be printed to standard output.- Overrides:
init
in classjava.applet.Applet
-
setUpMainPanel
protected void setUpMainPanel()
This method is called to set up the main panel of the applet. The main panel object, of type JCMPanel, already exists in the variable mainPanel when it is called. It begins by calling setUpParser() and setUpExampleMenu(). This method processes applet parameters "Insets", "BackgroundColor", and "ForegroundColor" to set the gap and colors of the panel. It creates a DisplayCanvas and, if the applet parameter "UseLimitsPanel" is not equal to "no", it creates a LimitControlPanel. The coordinate limits are set using the "Limits" applet param, if presetn. This method assigns the Controller from the mainPanel to the member variable mainController. It then calls setUpBottomPanel(), setUpTopPanel(), setUpCanvas(), addCanvasBorder(), and, if there is a limits panel, setUpLimitsPanel(), in that order. Finally, if the value of the applet parameter "LoadFirstExample" is not "no", and if any examples were specifed, then the first ewxample is loaded.
-
setUpCanvas
protected void setUpCanvas()
This method is called by mainPanel() to set up the display canvas and add it to the main panel. The canvas already exists in the member variable canvas when this method is called. This method adds only a set of axes to the canvas, sets the mainController to report errors using the canvas, and adds the canvas to the CENTER of the main panel. This method processes applet parameters "UsePanner", "CanvasColor", "UseMouseZoom", and "UseOffscreenCanvas". Typically, this method will be overridden in subclasses to add more Drawable items to the canvas. In this case, super.setUpCanvas() should be called first.
-
makeAxes
protected Axes makeAxes()
Construct a set of Axes, based on applet params "AxesColor", "AxesLightColor", "XLabel", "YLabel", "LabelColor".
-
addCanvasBorder
protected void addCanvasBorder()
This method is called by setUpMainPanel() to add a border to the canvas (since the border is typically the last thing that should be added, on top of anything else in the canvas. It processes the applet parameters "BorderWidth" and "BorderColor". If the border width is zero, no border is added. (The default width is 2.)
-
setUpBottomPanel
protected void setUpBottomPanel()
This method checks the applet parameter "UseFunctionInput". If the value is anything but "no", then a panel is created that contains an ExpressionInput (stored in the member variable functionInput) and possibly a ComputeButton and lable for the input box. This panel is a JCMPanel using BorderLayout. In is stored in the member variable inputPanel and is added to the SOUTH position of the mainPanel. The method also processes applet parameters "Function", "UseComputeButton", "ComputeButtonName", and "FunctionLabel". The ComputeButton, if it exists, is stored in the member variable computeButton. Note that nothing at all is done by this method if the value of the applet parameter "UseFunctionInput" is no.
-
setUpLimitsPanel
protected void setUpLimitsPanel()
This method sets up the limit control panel and adds it to the main panel. The limit control panel already exists when this method is called and is stored in the member variable limitsPanel. The applet parameters "TwoLimitsColumns", "UseSetLimitsButton", "UseZoomButtons", "UseEqualizeButtons", "UseRestoreButton", "PanelBackground", and "LimitsOnLeft" are processed. The limits panel is set to report its errors using the display canvas.
-
setUpTopPanel
protected void setUpTopPanel()
This method is called by setUpMainPanel() to add a panel at the top of the applet. If there is an example menu, then the panel containing that menu is added to the NORTH position of the main panel. Otherwise, the value of the applet parameter named "PanelTitle" is checked. If this value exists, it is placed in a label at the top of the panel. The color of the text on the label is given by the valur of the applet parameter "TitleColor" (default is new Color(200,0,0)).
-
setUpExampleMenu
protected void setUpExampleMenu()
This method processes applet parameters that specify examples for the applet and adds them to a menu of examples. If any examples exist, they are placed in a menu and a panel is created to hold the menu. The panel is stored in the instance variable exampleMenuPanel, which is used in the setUpTopPanel() method. This method is called by init(). If you don't want to process examples, you could override it to do nothing. If you do want to process examples, you have to override the doLoadExample() method to process a string from the menu. Examples are specified in applet parameters named "Example", "Example1", "Example2", .... The value should consist of a name for the example (which appears in the menu) followed by a ";" followed by a string that defines the example. The string that defines the example is passed to the doLoadExample() method when the user loads the example.
-
setUpParser
protected void setUpParser()
This method is called by setUpMainPanel() to set up the parser to be used in the applet. When it is called, a parser already esists and is stored in the member variable named parser. This method configures the parser according to the values of the applet parameters "StandardFunctions", "Booleans", "OptionalStars", "OptionalParens", and "Factorials". It then looks for function defintions in applet parameters named "Define", "Define1", "Define2", ...., and if any are found the functions are added to the parser so that they can be used in expressions. A function definition can take a form such as "g(x)=x^2" or "fred(s,t) = 3*s + sin(t)", for example, or it can be defined by a table of values. A table function is defined using the syntax decribed in the parseTableFuncDef() method. Finally, a variable is created and added to the parser using the value of the applet param "Variable", with "x" as the default variable name.
-
doLoadExample
protected void doLoadExample(java.lang.String example)
This method is called when the user loads an example from the example menu (if any). The parameter is the string that defines the example. By default, this method does nothhing. It should be overridden to load the example.
-
setUpParameterDefaults
protected void setUpParameterDefaults()
This method, which is empty in the GenericGraphApplet class, can be defined in a subclass to set default values for applet params that are different from the ones provided in this class. The method should create a new HashTable, assign it to the instance variable parameterDefaults, and then add name/value pairs to the hash table. This method is called at the very beginning of the init() method.
-
getParameter
public java.lang.String getParameter(java.lang.String paramName)
Override the standard applet method getParameter(String) so that when no param value is provided in the applet tag, and if parameterDefaults is non-null, it will check for a value the parameterDefaults. (The parameterDefaults instance variable can be defined in the setUpParameterDefaults() method.)- Overrides:
getParameter
in classjava.applet.Applet
-
getParameter
protected java.lang.String getParameter(java.lang.String paramName, java.lang.String defaultValue)
Get the value of an applet parameter, but return a default if the value is null.- Parameters:
paramName
- The name of the applet parameter.defaultValue
- The value to be returned if getParameter(paramName) is null.
-
getNumericParam
protected double[] getNumericParam(java.lang.String paramName)
Get The value of an applet parameter that consists of a list of numbers. The parameter value, if any, is parsed and returned as array of double values. The numbers can be separated by commas, spaces, tabs, or semicolons. If there is a parse error, null is returned.
-
getNumericParam
protected double[] getNumericParam(java.lang.String paramName, double[] defaults)
Get The value of an applet parameter that consists of a list of numbers. The parameter value, if any, is parsed and returned as array of double values. The numbers can be separated by commas, spaces, tabs, or semicolons.- Parameters:
paramName
- The name of the applet parameter.defaultValue
- The value to be returned if getParameter(paramName) is null or is not a valid list of numbers.
-
getColorParam
protected java.awt.Color getColorParam(java.lang.String data)
Get The value of an applet parameter that specifies a color. The color can be specfied as a list of three numbers in the range 0 to 255 or by one of the standard color names ("black", "red", "blue", "green", "yellow", "cyan", "magenta", "gray", "darkgray", "lightgray", "pink", "orange", "white"). Color names are not case sensitive. If the value of the applet parameter is null does not specify a legal color, then the return value is null.
-
getColorParam
protected java.awt.Color getColorParam(java.lang.String paramName, java.awt.Color defaultColor)
Get The value of an applet parameter that specifies a color. The color can be specfied as a list of three numbers in the range 0 to 255 or by one of the standard color names ("black", "red", "blue", "green", "yellow", "cyan", "magenta", "gray", "darkgray", "lightgray", "pink", "orange", "white"). Color names are not case sensitive.- Parameters:
paramName
- The name of the applet parameter.defaultColor
- The value to be returned if getParameter(paramName) is null or is not a valid color.
-
stop
public void stop()
Releases the resources used by the display canvas when the applet is stopped.- Overrides:
stop
in classjava.applet.Applet
-
destroy
public void destroy()
Closes the frame (if any) when the applet is destroyed.- Overrides:
destroy
in classjava.applet.Applet
-
parseTableFuncDef
protected TableFunction parseTableFuncDef(java.lang.String def)
Create a TableFunction from a string. The string can start with the word "table", which is ignored. The next item can optionally be one of the table styles "smooth", "linear", or "step". The default is "smooth". Then values must be specified. If the next word is "intervals", it can be followed by numbers giving the number of intervals, the minumum x, and the maximum x, and the y-values for up to (intervals+1) points evenly distributed between xmin and xmax (unassigned y-values will be zero). If no data is specified, a table function with 6 intervals between xmin = -5 and xmax = 5 and all y-values zero is created. If "intervals" is not specified, the remaining items are numbers giving pairs of (x,y)-values. Items can be separated spaces, tabs, and commas. A ParseError will be thrown if the data is illegal.
-
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent evt)
Respond when user clicks a button; not meant to be called directly.- Specified by:
actionPerformed
in interfacejava.awt.event.ActionListener
-
itemStateChanged
public void itemStateChanged(java.awt.event.ItemEvent evt)
Respond when user chooses an example from the example menu. (This will only happen if the param UseLoadButton is not set to "yes".)- Specified by:
itemStateChanged
in interfacejava.awt.event.ItemListener
-
-