|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent javax.swing.JPanel net.sourceforge.webcompmath.awt.beans.WCMPanelBean net.sourceforge.webcompmath.awt.beans.WCMExamplesBean
public class WCMExamplesBean
This bean provides a flexible means to create a drop-down list of examples. Each example is a text string made up of semi-colon separated tokens. The tokens correspond to arguments to methods that will be called in loading the example, except that the first token is always the text that will be displayed in the drop-down list. An example template is defined that specifies a list of objects, method names, and argument types. When an example is loaded, the bean will parse the text string one token at a time, and for each token it finds, it will call the appropriate method on the specified object.
For example, the template could have a reference to a WCMExpressionInputBean object with a fieldname of myExprInBean, a method name of "setText" and a type of STRING. If the text for this token in the example string is "x^2+1", when the bean loads the example it will call myExprInBean.setText("x^2+1"). In this way, an example can trigger several method calls to set up the example, such as setting the text of a WCMExpressionInputBean, setting the xmin, xmax, ymin, ymax for a WCMDisplayCanvasBean or WCMLimitControlPanelBean, set the value of a WCMVariableInputBean, etc.
The current version of this bean only supports methods with zero or one arguments. The argument type needs to be specified by the user in the template, in order to handle overloaded methods. The type is specified as an enumeration with the following options: STRING, INT, FLOAT, DOUBLE, LIMITS, BOOLEAN, VALUE, NO_ARG, and DOUBLE_ARRAY.
When an example is loaded, the methods defined in the template are called in the order in which they were specified. This is useful for things like Animator.start(), which you can set up to be called as the last method when loading an example. If a token is missing in an example (either because there are two semi-colons next to each other ("5;x^2;;") or there are fewer tokens in the example than methods in the template, then the method is skipped. Note that this applies to NO_ARG methods, too. If you want a NO_ARG method to be called, put something in the token (e.g., "invoke"). This also means that to call a STRING method with "", you must put "; ;" in the example, and not ";;". The blank space between the semicolons causes the STRING method to be called, but the blank is stripped out before the method is called, thus passing an empty string to the method.
There is also a loadAppletExamples(JApplet applet) method which, when called from an applet using itself as the argument, will load the examples from applet parameter tags, just like the configurable applets based on GenericApplet do.
Here is an example. Note that loadSelectedExample() should get called at the end of applet/application initialization, so that all the elements of the applet/application are present and set up before the example is loaded.
myExample = new WCMExamplesBean();
myExample.addTemplateElement(myExprInBean, "setText", WCMExamplesBean.STRING);
myExample.setExample0("First example;x^2");
myExample.setExample1("Second example;x^3");
myExample.setExample2("Third example; x^4");
myExample.setSelectedExample(0);
myExample.loadSelectedExample();
Nested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.JPanel |
---|
javax.swing.JPanel.AccessibleJPanel |
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
javax.swing.JComponent.AccessibleJComponent |
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 int |
BOOLEAN
For methods like WCMAnimator.setPauseButton(boolean b). |
static int |
DOUBLE
For methods like VariableInput.setMin(double d). |
static int |
DOUBLE_ARRAY
The method takes an array of double. |
static int |
FLOAT
For methods like Graph1D.setLineWidth(float f). |
static int |
INT
For methods like Animator.setIntervals(int i). |
static int |
LIMITS
A set of four numbers, separated by commas (such as "-5, 5, -5, 5"), representing the xmin, xmax, ymin, and ymax limits of a WCMDisplayCanvasBean or WCMLimitControlPanelBean. |
static int |
NO_ARG
The method does not take an argument. |
static int |
STRING
For methods like WCMExpressionInputBean.setText(String s). |
static int |
VALUE
For methods that take a Value object as the argument, like Animator.setIntervals(Value v). |
Fields inherited from class javax.swing.JComponent |
---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
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 | |
---|---|
WCMExamplesBean()
The default constructor. |
Method Summary | |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent evt)
Respond when user clicks a button; not meant to be called directly. |
void |
addExample(java.lang.String s)
Add an example string. |
void |
addTemplateElement(java.lang.Object o,
java.lang.String methodName,
int type)
Add an element to the template. |
protected void |
doLoadExample(java.lang.String example)
Load a specific example string |
java.lang.String |
getExample(int index)
Get an example that has been set. |
java.lang.String |
getExample0()
Get an example string |
java.lang.String |
getExample1()
Get an example string |
java.lang.String |
getExample2()
Get an example string |
java.lang.String |
getExample3()
Get an example string |
java.lang.String |
getExample4()
Get an example string |
java.lang.String |
getExample5()
Get an example string |
java.lang.String |
getExample6()
Get an example string |
java.lang.String |
getExample7()
Get an example string |
java.lang.String |
getExample8()
Get an example string |
java.lang.String |
getExample9()
Get an example string |
javax.swing.JComboBox |
getExampleMenu()
Get the example menu itself. |
javax.swing.JButton |
getLoadExampleButton()
Get the load button itself. |
boolean |
isUseLoadButton()
|
void |
loadAppletExamples(javax.swing.JApplet applet)
Get examples from HTML. |
void |
loadSelectedExample()
Use this method during applet initialization if you have elected not to use a load button and you want the example loaded right away. |
void |
setExample(java.lang.String s,
int index)
Set an example string |
void |
setExample0(java.lang.String s)
Set an example string |
void |
setExample1(java.lang.String s)
Set an example string |
void |
setExample2(java.lang.String s)
Set an example string |
void |
setExample3(java.lang.String s)
Set an example string |
void |
setExample4(java.lang.String s)
Set an example string |
void |
setExample5(java.lang.String s)
Set an example string |
void |
setExample6(java.lang.String s)
Set an example string |
void |
setExample7(java.lang.String s)
Set an example string |
void |
setExample8(java.lang.String s)
Set an example string |
void |
setExample9(java.lang.String s)
Set an example string |
void |
setSelectedExample(int index)
Set which example is selected. |
void |
setUseLoadButton(boolean useLoadButton)
|
Methods inherited from class net.sourceforge.webcompmath.awt.beans.WCMPanelBean |
---|
addImpl, getController, getMainController, paintComponent, remove, setController, setTie1, setTie2, setTie3 |
Methods inherited from class javax.swing.JPanel |
---|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
Methods inherited from class javax.swing.JComponent |
---|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update |
Methods inherited from class java.awt.Container |
---|
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, 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 |
---|
public static final int STRING
public static final int INT
public static final int FLOAT
public static final int DOUBLE
public static final int LIMITS
public static final int BOOLEAN
public static final int VALUE
public static final int NO_ARG
public static final int DOUBLE_ARRAY
Constructor Detail |
---|
public WCMExamplesBean()
Method Detail |
---|
public void addTemplateElement(java.lang.Object o, java.lang.String methodName, int type)
o
- the object whose method is going to be calledmethodName
- the name of the method to calltype
- the type of argument to pass to the method, one of STRING,
INT, FLOAT, DOUBLE, LIMITS, BOOLEAN, VALUE, NO_ARG,
DOUBLE_ARRAY.public void setExample0(java.lang.String s)
s
- the examplepublic java.lang.String getExample0()
public void setExample1(java.lang.String s)
s
- the examplepublic java.lang.String getExample1()
public void setExample2(java.lang.String s)
s
- the examplepublic java.lang.String getExample2()
public void setExample3(java.lang.String s)
s
- the examplepublic java.lang.String getExample3()
public void setExample4(java.lang.String s)
s
- the examplepublic java.lang.String getExample4()
public void setExample5(java.lang.String s)
s
- the examplepublic java.lang.String getExample5()
public void setExample6(java.lang.String s)
s
- the examplepublic java.lang.String getExample6()
public void setExample7(java.lang.String s)
s
- the examplepublic java.lang.String getExample7()
public void setExample8(java.lang.String s)
s
- the examplepublic java.lang.String getExample8()
public void setExample9(java.lang.String s)
s
- the examplepublic java.lang.String getExample9()
public void setExample(java.lang.String s, int index)
s
- the exampleindex
- the index of the example, starting at 0public java.lang.String getExample(int index)
index
- the index of the example
public void addExample(java.lang.String s)
s
- the examplepublic void loadSelectedExample()
public void setSelectedExample(int index)
index
- the index of the example to setpublic void actionPerformed(java.awt.event.ActionEvent evt)
actionPerformed
in interface java.awt.event.ActionListener
evt
- event generated when user clicks a buttonprotected void doLoadExample(java.lang.String example)
example
- public void loadAppletExamples(javax.swing.JApplet applet)
applet
- the applet in which the WCMExamplesBean is embeddedpublic boolean isUseLoadButton()
public void setUseLoadButton(boolean useLoadButton)
useLoadButton
- the useLoadButton to setpublic javax.swing.JComboBox getExampleMenu()
public javax.swing.JButton getLoadExampleButton()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |