T
- the type of a matrix elementpublic class MatrixView<T> extends View
MatrixView(String, MatrixElementFormat, boolean, LanguageFile, String)
to specify a language file from which
labels, tooltips and messages are read by the given language id. The following language labels are available:
Resources.LANGUAGE_FILE
.
setMatrix(Matrix)
. If the matrix view 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 matrixView.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(MatrixEditor.Strikeout)
and addColumnStrikeout(MatrixEditor.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()
.
View.saveConfiguration(Configuration)
and View.loadConfiguration(Configuration)
.
It is saved or restored the visibility of the view. This makes it possible that you can store the state of the view persistent.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 |
---|
MatrixView(java.lang.String title,
MatrixElementFormat<T> elementFormat)
Creates a new matrix view.
|
MatrixView(java.lang.String title,
MatrixElementFormat<T> elementFormat,
boolean closable)
Creates a new matrix view.
|
MatrixView(java.lang.String title,
MatrixElementFormat<T> elementFormat,
boolean closable,
LanguageFile langFile,
java.lang.String langID)
Creates a new matrix view.
|
Modifier and Type | Method and Description |
---|---|
void |
addColumnStrikeout(MatrixEditor.Strikeout strikeout)
Adds a column strikeout.
|
void |
addMask(Mask mask)
Adds a new mask to the matrix view.
|
void |
addRowStrikeout(MatrixEditor.Strikeout strikeout)
Adds a row strikeout.
|
void |
clearSelection()
Clears the selection in the matrix view.
|
boolean |
getAutoRepaint()
Indicates whether auto repaint is enabled in the view.
|
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 view.
|
Matrix<T> |
getMatrix()
Gets the matrix that is displayed.
|
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 view displays row and column labels.
|
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 view.
|
void |
removeRowStrikeout(int rowIndex)
Removes the strikeout for the specified row if there is one.
|
protected void |
repaintComponent()
Repaints the component.
|
void |
reset()
Resets the matrix view meaning the matrix is set to
null , the labels are cleared and the paint labels flag is reset
to false and all strikeouts (of rows and columns) are removed. |
void |
setAutoRepaint(boolean autoRepaint)
Sets whether the view is allowed to be auto repainted.
|
void |
setColumnLabels(java.util.Map<java.lang.Integer,java.lang.String> labels)
Sets the column labels of the matrix view.
|
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 view which is used to render the matrix elements.
|
void |
setMatrix(Matrix<T> matrix)
Sets the matrix that should be displayed.
|
void |
setPaintLabels(boolean paint)
Sets whether the matrix view should display row and column labels.
|
void |
setRepaintDisabled(boolean disabled)
Sets whether the repaint of the component is disabled meaning the component cannot be repainted until the disable state is revoked.
|
void |
setRowLabels(java.util.Map<java.lang.Integer,java.lang.String> labels)
Sets the row labels of the matrix view.
|
void |
setRowSpacing(int spacing)
Sets the row spacing of the matrix.
|
addHeaderBarComponent, addHeaderBarSeparator, addImpl, autoRepaint, beforeRemove, close, extendTitle, getContentPanel, getTitle, highlight, highlight, isClosable, isVisible, loadConfiguration, loadConfiguration, readConfigurationData, removeAll, removeHeaderBarComponent, saveConfiguration, saveConfiguration, setBorder, setCloseButtonToolTip, setLayout, setVisible, toString, writeConfigurationData
isRepaintDisabled, repaint
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, getPreferredSize, 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, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, 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, 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, transferFocus, transferFocusBackward, transferFocusUpCycle
public MatrixView(java.lang.String title, MatrixElementFormat<T> elementFormat) throws java.lang.IllegalArgumentException
title
- the title of the view which is displayed in the header barelementFormat
- the format of the matrix elements (like MatrixEditor.StringElementFormat
, MatrixEditor.NumericElementFormat
and so on of the MatrixEditor
)java.lang.IllegalArgumentException
- public MatrixView(java.lang.String title, MatrixElementFormat<T> elementFormat, boolean closable) throws java.lang.IllegalArgumentException
title
- the title of the view which is displayed in the header barelementFormat
- the format of the matrix elements (like MatrixEditor.StringElementFormat
, MatrixEditor.NumericElementFormat
and so on of the MatrixEditor
)closable
- true
if the matrix view can be closed by the user using the "X" in the header bar otherwise false
(if a matrix view is not closable he must be set invisible manually using View.setVisible(boolean)
if required)java.lang.IllegalArgumentException
- public MatrixView(java.lang.String title, MatrixElementFormat<T> elementFormat, boolean closable, LanguageFile langFile, java.lang.String langID) throws java.lang.IllegalArgumentException
LanguageFile
and a language id to display language dependent
messages and tooltips in the matrix view. The following language labels are available:
title
- the title of the view which is displayed in the header barelementFormat
- the format of the matrix elements (like MatrixEditor.StringElementFormat
, MatrixEditor.NumericElementFormat
and so on of the MatrixEditor
)closable
- true
if the matrix view can be closed by the user using the "X" in the header bar otherwise false
(if a matrix view is not closable he must be set invisible manually using View.setVisible(boolean)
if required)langFile
- the language file or null
if the matrix view should not use language dependent labels, tooltips or messages (in this case the predefined labels, tooltips and messages are shown)langID
- the language idjava.lang.IllegalArgumentException
- public boolean getAutoRepaint()
getAutoRepaint
in class View
true
if auto repainting is allowed otherwise false
public void setAutoRepaint(boolean autoRepaint)
BaseComponent.repaint()
on your own to visualize the changes you made to a component or view.
BaseComponent.repaint()
method of the view is automatically
invoked to make the changes visible. But ensure that this does not overload the EDT (event dispatch thread).n
objects in a loop and you activate the auto repaint option.n
calls to BaseComponent.repaint()
instead of one call at the end of the loop.GuiRequest
) and in consequence of that
the algorithm must wait until the pending event is processed in the EDT.setAutoRepaint
in class View
autoRepaint
- true
if auto repainting should be enabled otherwise false
public void reset()
null
, the labels are cleared and the paint labels flag is reset
to false
and all strikeouts (of rows and columns) are removed.
reset
in class View
setMatrix(Matrix)
public boolean isEditable()
true
if the view is in editable mode otherwise false
public void setEditable(boolean editable)
editable
- true
if the view 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 view 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 view 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()
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 setRepaintDisabled(boolean disabled)
BaseComponent.repaint()
is invoked automatically.
setRepaintDisabled
in class BaseComponent
disabled
- true
if the repaint mechanism should be disabled otherwise false
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