T
- the type of a matrix elementpublic class MatrixEditor<T> extends BaseComponent
setMatrix(Matrix)
. If the matrix editor is in edit mode (setEditable(boolean)
)
the user can select matrix elements and he can modify them using the keyboard. You can retrieve a modified matrix with getMatrix()
.
setElementBackground(int, int, Color)
/setElementForeground(int, int, Color)
.
MatrixElementFormat
is responsible for how an object is formatted in the matrix. Additionally it is used to parse a user input string
into a concrete element object if the user modifies an element. The matrix editor provides implementations for several types like
MatrixEditor.StringElementFormat
, MatrixEditor.NumericElementFormat
, MatrixEditor.IntegerElementFormat
, MatrixEditor.FloatElementFormat
, ...
Integer.MAX_VALUE
to identify elements as infinity.Integer.MAX_VALUE
objects with an infinity symbol:
// set the matrix ... // create the mask final Mask m = new Mask(Integer.MAX_VALUE, Symbol.getPredefinedSymbol(PredefinedSymbol.INFINITY)); // add the mask to the matrix editor matrixEditor.addMask(m);Labels:
setRowLabels(Map)
you set a row label map and with setColumnLabels(Map)
you set a column label map. Ensure that you activate setPaintLabels(boolean)
to display the labels.
addRowStrikeout(Strikeout)
and addColumnStrikeout(Strikeout)
to add new strikeouts or to change a strikeout for a specific index. You can remove them by using either removeRowStrikeout(int)
/removeColumnStrikeout(int)
or removeLastRowStrikeout()
/removeLastColumnStrikeout()
.Modifier and Type | Class and Description |
---|---|
static class |
MatrixEditor.DoubleElementFormat
The element format for
Double objects in a matrix. |
static class |
MatrixEditor.FloatElementFormat
The element format for
Float objects in a matrix. |
static class |
MatrixEditor.IntegerElementFormat
The element format for
Integer objects in a matrix. |
static class |
MatrixEditor.LongElementFormat
The element format for
Long objects in a matrix. |
static class |
MatrixEditor.NumericElementFormat<T extends java.lang.Number>
The element format for
Number objects in a matrix. |
static class |
MatrixEditor.Strikeout
Represents a strikeout in the matrix editor.
|
static class |
MatrixEditor.StringElementFormat
The element format for
String objects in a matrix. |
javax.swing.JComponent.AccessibleJComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor and Description |
---|
MatrixEditor(MatrixElementFormat<T> format)
Creates a new matrix editor.
|
MatrixEditor(MatrixElementFormat<T> format,
Matrix<T> matrix)
Creates a new matrix editor.
|
Modifier and Type | Method and Description |
---|---|
void |
addColumnStrikeout(MatrixEditor.Strikeout strikeout)
Adds a column strikeout.
|
protected void |
addImpl(java.awt.Component component,
java.lang.Object constraints,
int index) |
void |
addMask(Mask mask)
Adds a new mask to the matrix editor.
|
void |
addRowStrikeout(MatrixEditor.Strikeout strikeout)
Adds a row strikeout.
|
void |
clearSelection()
Clears the selection in the matrix editor.
|
boolean |
getAutoRepaint()
Indicates whether auto repaint is enabled.
|
int |
getColumnSpacing()
Gets the column spacing of the matrix.
|
java.awt.Color |
getElementBackground(int i,
int j)
Gets the background color of a matrix element.
|
java.awt.Color |
getElementForeground(int i,
int j)
Gets the foreground color of a matrix element.
|
Mask |
getMask(int index)
Gets a mask at a given index.
|
int |
getMaskCount()
Gets the number of masks that are defined for the matrix editor.
|
Matrix<T> |
getMatrix()
Gets the matrix that is displayed.
|
java.awt.Dimension |
getPreferredSize()
Gets the preferred size of the matrix editor.
|
int |
getRowHeight()
Gets the height of a row in the matrix editor.
|
int |
getRowSpacing()
Gets the row spacing of the matrix.
|
boolean |
isEditable()
Indicates whether the matrix is editable or not.
|
boolean |
isPaintLabels()
Indicates whether the matrix editor displays row and column labels.
|
void |
removeAll()
The components of the matrix editor cannot be removed.
|
void |
removeAllColumnStrikeouts()
Removes all column strikeouts.
|
void |
removeAllRowStrikeouts()
Removes all row strikeouts.
|
void |
removeColumnStrikeout(int columnIndex)
Removes the strikeout for the specified column if there is one.
|
void |
removeLastColumnStrikeout()
Removes the strikeout of a column that was added as a last.
|
void |
removeLastRowStrikeout()
Removes the strikeout of a row that was added as a last.
|
void |
removeMask(Mask mask)
Removes the mask from the matrix editor.
|
void |
removeRowStrikeout(int rowIndex)
Removes the strikeout for the specified row if there is one.
|
protected void |
repaintComponent()
Repaints the component.
|
void |
setAutoRepaint(boolean autoRepaint)
Sets whether auto repaint is enabled.
|
void |
setColumnLabels(java.util.Map<java.lang.Integer,java.lang.String> labels)
Sets the column labels of the matrix editor.
|
void |
setColumnSpacing(int spacing)
Sets the column spacing of the matrix.
|
void |
setEditable(boolean editable)
Sets whether the matrix is editable or not.
|
void |
setElementBackground(int i,
int j,
java.awt.Color color)
Sets the background color of a matrix element.
|
void |
setElementForeground(int i,
int j,
java.awt.Color color)
Sets the foreground color of a matrix element.
|
void |
setFont(java.awt.Font f)
Sets the font of the matrix editor which is used to render the matrix elements.
|
void |
setLayout(java.awt.LayoutManager mgr)
The layout of a matrix editor may not be changed meaning this method does nothing!
|
void |
setMatrix(Matrix<T> matrix)
Sets the matrix that should be displayed.
|
void |
setPaintLabels(boolean paint)
Sets whether the matrix editor should display row and column labels.
|
void |
setRowLabels(java.util.Map<java.lang.Integer,java.lang.String> labels)
Sets the row labels of the matrix editor.
|
void |
setRowSpacing(int spacing)
Sets the row spacing of the matrix.
|
isRepaintDisabled, repaint, setRepaintDisabled
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, 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, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, 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, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
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, remove, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, transferFocusDownCycle, validate, validateTree
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, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
public MatrixEditor(MatrixElementFormat<T> format) throws java.lang.IllegalArgumentException
format
- the format of the matrix elementsjava.lang.IllegalArgumentException
- public MatrixEditor(MatrixElementFormat<T> format, Matrix<T> matrix) throws java.lang.IllegalArgumentException
format
- the format of the matrix elementsmatrix
- the matrix to display or null
if no matrix should be displayed initiallyjava.lang.IllegalArgumentException
- public boolean getAutoRepaint()
true
if auto repaint is enabled otherwise false
public void setAutoRepaint(boolean autoRepaint)
BaseComponent.repaint()
automatically if a method is invoked that is marked as
auto repaintable.autoRepaint
- true
if auto repaint should be enabled otherwise false
public boolean isEditable()
true
if the editor is in editable mode otherwise false
public void setEditable(boolean editable)
editable
- true
if the editor should be set in editable mode otherwise false
public void clearSelection()
public final Matrix<T> getMatrix()
null
if currently no matrix is displayedpublic final void setMatrix(Matrix<T> matrix)
BaseComponent.repaint()
.
setAutoRepaint(boolean)
)!matrix
- the matrix to display or null
public int getMaskCount()
public Mask getMask(int index) throws java.lang.IndexOutOfBoundsException
12345
should be masked with the infinity symbol. Therefore you create a new mask and add it to the matrix editor like:
// create the mask final Mask infMask = new Mask(12345, Symbol.getPredefinedSymbol(PredefinedSymbol.INFINITY)); // add it to the matrix matrixTable.addMask(infMask);
index
- the indexjava.lang.IndexOutOfBoundsException
- index < 0 || index >= getMaskCount()
)public void addMask(Mask mask)
12345
should be masked with the infinity symbol. Therefore you create a new mask and add it to the matrix editor like:
// create the mask final Mask infMask = new Mask(12345, Symbol.getPredefinedSymbol(PredefinedSymbol.INFINITY)); // add it to the matrix matrixTable.addMask(infMask);
setAutoRepaint(boolean)
)!mask
- the mask to be addedpublic void removeMask(Mask mask)
setAutoRepaint(boolean)
)!mask
- the mask that should be removedpublic java.awt.Color getElementBackground(int i, int j)
i
- the row index of the element in the matrixj
- the column index of the element in the matrixpublic void setElementBackground(int i, int j, java.awt.Color color) throws java.lang.IndexOutOfBoundsException
setAutoRepaint(boolean)
)!i
- the row index of the element in the matrixj
- the column index of the element in the matrixcolor
- the background colorjava.lang.IndexOutOfBoundsException
- public java.awt.Color getElementForeground(int i, int j)
i
- the row index of the element in the matrixj
- the column index of the element in the matrixpublic void setElementForeground(int i, int j, java.awt.Color color) throws java.lang.IndexOutOfBoundsException
setAutoRepaint(boolean)
)!i
- the row index of the element in the matrixj
- the column index of the element in the matrixcolor
- the foreground colorjava.lang.IndexOutOfBoundsException
- public int getColumnSpacing()
public void setColumnSpacing(int spacing) throws java.lang.IllegalArgumentException
setAutoRepaint(boolean)
)!spacing
- the spacing between two columnsjava.lang.IllegalArgumentException
- < 0
public int getRowSpacing()
public void setRowSpacing(int spacing) throws java.lang.IllegalArgumentException
setAutoRepaint(boolean)
)!spacing
- the spacing between two rowsjava.lang.IllegalArgumentException
- < 0
public boolean isPaintLabels()
setAutoRepaint(boolean)
)!true
if row and column labels are displayed otherwise false
public void setPaintLabels(boolean paint)
setAutoRepaint(boolean)
)!paint
- true
if row and column labels should be displayed otherwise false
public void setRowLabels(java.util.Map<java.lang.Integer,java.lang.String> labels)
setAutoRepaint(boolean)
)!labels
- the labels map that maps a row index (key) onto a label text (value)setPaintLabels(boolean)
public void setColumnLabels(java.util.Map<java.lang.Integer,java.lang.String> labels)
setAutoRepaint(boolean)
)!labels
- the labels map that maps a column index (key) onto a label text (value)setPaintLabels(boolean)
public void addRowStrikeout(MatrixEditor.Strikeout strikeout) throws java.lang.IllegalArgumentException
setAutoRepaint(boolean)
)!strikeout
- the strikeoutjava.lang.IllegalArgumentException
- public void removeRowStrikeout(int rowIndex)
setAutoRepaint(boolean)
)!rowIndex
- the index of the row its strikeout should be removedpublic void removeLastRowStrikeout()
setAutoRepaint(boolean)
)!public void removeAllRowStrikeouts()
setAutoRepaint(boolean)
)!public void addColumnStrikeout(MatrixEditor.Strikeout strikeout) throws java.lang.IllegalArgumentException
setAutoRepaint(boolean)
)!strikeout
- the strikeoutjava.lang.IllegalArgumentException
- public void removeColumnStrikeout(int columnIndex)
setAutoRepaint(boolean)
)!columnIndex
- the index of the column its strikeout should be removedpublic void removeLastColumnStrikeout()
setAutoRepaint(boolean)
)!public void removeAllColumnStrikeouts()
setAutoRepaint(boolean)
)!public int getRowHeight()
public void setFont(java.awt.Font f)
setFont
in class javax.swing.JComponent
f
- the fontpublic void setLayout(java.awt.LayoutManager mgr)
setLayout
in class java.awt.Container
mgr
- the layout managerpublic void removeAll()
removeAll
in class java.awt.Container
public java.awt.Dimension getPreferredSize()
getPreferredSize
in class javax.swing.JComponent
protected void addImpl(java.awt.Component component, java.lang.Object constraints, int index)
addImpl
in class java.awt.Container
protected void repaintComponent()
BaseComponent.repaint()
. You can override this method to repaint sub-components but ensure that
the super type method is invoked too meaning:
protected void repaintComponent() { // repaint the parent super.repaintComponent(); // repaint sub-components ... }
repaintComponent
in class BaseComponent