|
||||||||||
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.DataTableInput
public class DataTableInput
A DataTableInput lets the user input a grid of real numbers arranged in rows and columns. Each column has a name, and rows are numbered starting from 1. The column names and row numbers can be displayed, optionally. By default, a new row is added automatically if the user moves down out of the last row by pressing return or down-arrow, provided the last row is non-empty. Rows can also be added programmatically. Columns are usually added in the constructor, but they can also be added later. If the user leaves a cell at a time when the content of that cell does not represent a legal number, then the message "bad input" will be displayed in the cell.
A DataTableInput can be given a name and can then be added to a parser. The parser will then recognize the name of the table. In an expression, the table name can be followed by a ".", then one of the column names from table, then an expression in parentheses. This represents a reference to the number in one of the cells in the table. The expression gives the number of the row, where rows are numbered starting from 1. For example: "data.A(3)" represents the third number in column "A" in a table named data. The table name and "." can also be followed by the word "sum" and an expression in parentheses. An expression used in this way can include references to the column names in the table and to the special value "rowNumber". The value of expression is computed for each row in the table and the sum of the values is computed. In the expression that is being summed, a column name represents the number in that column and rowNumber represents the number of the row. For example: "data.sum(A^2)". Finally, the "." can be followed by the word "count". "count" can, optionally be followed by an empty pair of parentheses. This represents the number of rows. For example: "data.count". Empty rows at the bottom of the table are ignored in both "sum" and "count".
Note that rows are numbered starting from 1 because row numbers can be visible to the user, who shouldn't be subjected to zero-based numbering. However, columns are always numbered from zero.
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 |
---|
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 | |
---|---|
DataTableInput()
Create a DataTableInput with no columns. |
|
DataTableInput(java.lang.String name,
int columns)
Create a table with the specified number of columns, named "A", "B", etc. |
|
DataTableInput(java.lang.String name,
java.lang.String[] columnNames)
Create a table with the specified column names. |
Method Summary | |
---|---|
int |
addColumn()
Add a column at the right side of the table, with all cells initially empty. |
int |
addColumn(java.lang.String name)
Add a column with the specified name at the right side of the table, with all cells initially empty. |
void |
addRows(int rowCt)
Add the specified number of empty rows at the bottom of the table. |
void |
addVariablesToParser(Parser p)
Add a row number variable (from the getRowNumberVariable() method) and a column variable for each column (from the getColumnVariable() method) to the parser. |
void |
clear()
Remove all rows from the table, leaving just one empty row. |
void |
deleteCurrentRow()
Delete the row that contains the cell that the user is editing. |
void |
doParse(Parser parser,
ParserContext context)
Required by the ParserExtension interface and not meant to be called directly. |
boolean |
getAutoAddRows()
Get the value of the autoAddRows property, which determines whether empty rows are automatically added to the bottom of the table when needed. |
java.awt.Color |
getBlankBackground()
Returns the color that is used for blank areas in the table, below the rows of cells. |
java.awt.Color |
getCellBackground()
Returns the color that is used as a background for cells in the table. |
double |
getCellContents(int row,
int col)
Get the number in the specified row and column. |
int |
getColumnCount()
Get the number of columns in the table. |
java.lang.String |
getColumnName(int i)
Get the name of column number i, where columns are numbered starting from zero. |
protected Variable |
getColumnVariable(int columnNum)
Return a column variable for the specified column, where columns are numbered starting from 1. |
int |
getCurrentRowNumber()
Return the current row number. |
double |
getEmptyCellValue()
Get the value that is represented by an empty cell. |
java.awt.Color |
getGridColor()
Returns the color that is used for the lines between cells in the table. |
java.awt.Color |
getLabelBackground()
Returns the color that is used as a background for row numbers and column titles. |
java.lang.String |
getName()
Get the name of the DataInputTable (which might be null). |
int |
getNonEmptyRowCount()
Return the number of rows in the table, ignoring empty rows at the bottom of the table. |
protected Variable |
getRowNumberVariable()
Get a variable that represents the current row number in the table, as set by the setCurrentRowNumber() method. |
long |
getSerialNumber()
Get the serial number of the table. |
boolean |
getShowColumnTitles()
Test whether the column name is shown at the top of each column. |
boolean |
getShowRowNumbers()
Test whether row numbers are shown. |
boolean |
getThrowErrors()
Get the value of the throwErrors property, which determines whether an error is thrown when an attempt is made to refer to the value of a cell that contains an invalid string. |
void |
insertRow()
Insert a row before the row that contains the cell that the user is editing. |
boolean |
readFromStream(java.io.Reader in)
Read data for table from the specified Reader. |
void |
setAutoAddRows(boolean auto)
If the value of autoAddRows is true, then an empty row is added to the table automatically when the user attempts to move down from the last row of the table, provided that the last row is non-empty (so there can only be one auto-added row at a time). |
void |
setBlankBackground(java.awt.Color color)
Get the color to be used as a background blank areas in the table, below the rows of cells. |
void |
setCellBackground(java.awt.Color color)
Set the color to be used as a background for cells in the table. |
void |
setCellContents(int row,
int col,
double val)
Put the given real number, val, in the cell in the specified row and column, where rows are numbered starting from 1 and columns are numbered starting from zero. |
void |
setColumnName(int i,
java.lang.String name)
Set the name of column number i, where columns are numbered starting from zero. |
void |
setCurrentRowNumber(int i)
Set the current row in the table. |
void |
setEmptyCellValue(double val)
Set the value that should be returned when the value of an empty cell is requested. |
void |
setGridColor(java.awt.Color color)
Get the color to be used for the lines between cells in the table. |
void |
setLabelBackground(java.awt.Color color)
Set the color to be used as a background for row numbers and column titles. |
void |
setName(java.lang.String name)
Set the name of this DataTableInput. |
void |
setShowColumnTitles(boolean show)
If set to true, then the column name is shown at the top of each column. |
void |
setShowRowNumbers(boolean show)
If set to true, then the row number is shown at the left of each row. |
void |
setThrowErrors(boolean throwErr)
Set the throwErrors property. |
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, paintComponent, 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, addImpl, 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, 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, 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, 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 |
Constructor Detail |
---|
public DataTableInput()
public DataTableInput(java.lang.String name, java.lang.String[] columnNames)
name
- table namecolumnNames
- names of the columnspublic DataTableInput(java.lang.String name, int columns)
name
- table namecolumns
- number of columnsMethod Detail |
---|
public void doParse(Parser parser, ParserContext context)
doParse
in interface ParserExtension
parser
- parser to usecontext
- context to usepublic int getNonEmptyRowCount()
public double getCellContents(int row, int col)
row
- row of desired cellcol
- column of desired cell
public void setCellContents(int row, int col, double val)
row
- row of desired cellcol
- column of desired cellval
- value to put in cellpublic void setCurrentRowNumber(int i)
i
- the desired row numberpublic int getCurrentRowNumber()
protected Variable getColumnVariable(int columnNum)
columnNum
- the desired column
protected Variable getRowNumberVariable()
public void addVariablesToParser(Parser p)
p
- parser to add variables topublic long getSerialNumber()
public void setThrowErrors(boolean throwErr)
throwErr
- true or falsepublic boolean getThrowErrors()
public void setEmptyCellValue(double val)
val
- value to return for empty cellspublic double getEmptyCellValue()
public void setAutoAddRows(boolean auto)
auto
- true or falsepublic boolean getAutoAddRows()
public void setName(java.lang.String name)
setName
in interface MathObject
setName
in class java.awt.Component
name
- name of the tablepublic java.lang.String getName()
getName
in interface MathObject
getName
in class java.awt.Component
public void setColumnName(int i, java.lang.String name)
i
- column numbername
- column namepublic java.lang.String getColumnName(int i)
i
- column number
public void addRows(int rowCt)
rowCt
- number of rows to addpublic void insertRow()
public void deleteCurrentRow()
public void clear()
public int getColumnCount()
public int addColumn()
public int addColumn(java.lang.String name)
name
- the column name
public boolean getShowColumnTitles()
public void setShowColumnTitles(boolean show)
show
- true or falsepublic boolean getShowRowNumbers()
public void setShowRowNumbers(boolean show)
show
- true or falsepublic java.awt.Color getLabelBackground()
public void setLabelBackground(java.awt.Color color)
color
- desired background colorpublic java.awt.Color getCellBackground()
public void setCellBackground(java.awt.Color color)
color
- cell background colorpublic java.awt.Color getBlankBackground()
public void setBlankBackground(java.awt.Color color)
color
- background colorpublic java.awt.Color getGridColor()
public void setGridColor(java.awt.Color color)
color
- line colorpublic boolean readFromStream(java.io.Reader in)
in
- input to read from
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |