Package ubic.basecode.graphics
Class MatrixDisplay<R,C>
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
ubic.basecode.graphics.MatrixDisplay<R,C>
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
A visual component for displaying a color matrix
- Author:
- Will Braynen
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Dimension
protected int
protected final int
protected int
protected int
protected boolean
protected boolean
protected Font
protected int
protected int
protected final int
protected int
protected int
protected int
protected int
Fields inherited from class javax.swing.JComponent
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
accessibleContext, 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
ConstructorsConstructorDescriptionMatrixDisplay
(DoubleMatrix<R, C> matrix) MatrixDisplay
(ColorMatrix<R, C> matrix) -
Method Summary
Modifier and TypeMethodDescriptionprotected Dimension
computeSize
(boolean showLabels, boolean showScalebar) compute the size of the matrix in pixels.protected void
drawColumnNames
(Graphics g, boolean leaveRoomForScalebar) Draws column names vertically (turned 90 degrees counter-clockwise)protected void
drawMatrix
(ColorMatrix<R, C> matrix, Graphics g, boolean leaveRoomForLabels, boolean leaveRoomForScalebar) Gets called from #paintComponent and #saveImage.protected void
drawRowNames
(Graphics g, boolean showScalebar) Draws row names (horizontally)protected void
drawScaleBar
(Graphics g, Dimension d, double displayMin, double displayMax) getColor
(int row, int column) Color[]
int
getColumnName
(int column) String[]
double
double
double
double
getMax()
int
double
getMin()
double
getRawValue
(int row, int column) double[]
getRow
(int row) double[]
getRowByName
(R rowName) int
int
int
getRowIndexByName
(R rowName) getRowName
(int row) String[]
boolean
double
getValue
(int row, int column) void
init
(ColorMatrix<R, C> matrix) protected void
initSize()
Sets the display sizestatic <R,
C> MatrixDisplay <R, C> newInstance
(ColorMatrix<R, C> matrix) protected void
void
void
Saves the image to a png file.void
void
saveImage
(ColorMatrix<R, C> matrix, String outPngFilename, boolean showLabels, boolean showScalebar, boolean standardize) void
saveImageToPng
(ColorMatrix<R, C> matrix, OutputStream stream, boolean showLabels, boolean showScalebar, boolean standardize) void
void
setColorMap
(Color[] colorMap) void
setDisplayRange
(double min, double max) void
setLabelsVisible
(boolean isShowLabels) If this display component has already been added to the GUI, it will be resized to fit or exclude the row namesvoid
setMatrix
(ColorMatrix<R, C> matrix) void
setMaxColumnLength
(int columnLength) void
setRowHeight
(int height) void
setRowKeys
(int[] rowKeys) void
setScaleBarVisible
(boolean isShowScale) void
setStandardizedEnabled
(boolean showStandardizedMatrix) void
writeToPng
(ColorMatrix<R, C> matrix, OutputStream stream, boolean showLabels, boolean showScalebar) 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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, 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, 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, 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, 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, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
m_cellSize
-
m_columnLabelHeight
protected int m_columnLabelHeight -
m_defaultResolution
protected final int m_defaultResolution- See Also:
-
m_fontGutter
protected int m_fontGutter -
m_fontSize
protected int m_fontSize -
m_isShowLabels
protected boolean m_isShowLabels -
m_isShowScale
protected boolean m_isShowScale -
m_labelFont
-
m_labelGutter
protected int m_labelGutter -
m_maxColumnLength
protected int m_maxColumnLength -
m_maxFontSize
protected final int m_maxFontSize- See Also:
-
m_ratioWidth
protected int m_ratioWidth -
m_resolution
protected int m_resolution -
m_rowLabelWidth
protected int m_rowLabelWidth -
m_textSize
protected int m_textSize
-
-
Constructor Details
-
MatrixDisplay
-
MatrixDisplay
-
-
Method Details
-
newInstance
-
getColor
-
getColorMap
- Returns:
- the current color map
-
getColorMatrix
-
getColumnCount
public int getColumnCount() -
getColumnName
-
getColumnNames
-
getDisplayMax
public double getDisplayMax() -
getDisplayMin
public double getDisplayMin() -
getDisplayRange
public double getDisplayRange() -
getMatrix
-
getMax
public double getMax()- Returns:
- the largest value in the matrix
-
getMaxColumnLength
public int getMaxColumnLength()- Returns:
- the m_maxColumnLength
-
getMin
public double getMin()- Returns:
- the smallest value in the matrix
-
getMissingColor
- Returns:
- the color used for missing values
-
getRawValue
public double getRawValue(int row, int column) -
getRow
public double[] getRow(int row) -
getRowByName
-
getRowCount
public int getRowCount() -
getRowHeight
public int getRowHeight() -
getRowIndexByName
-
getRowName
-
getRowNames
-
getStandardizedEnabled
public boolean getStandardizedEnabled() -
getValue
public double getValue(int row, int column) -
init
-
resetRowKeys
public void resetRowKeys() -
saveImage
public void saveImage(ColorMatrix<R, C> matrix, String outPngFilename, boolean showLabels, boolean showScalebar, boolean standardize) throws IOException- Parameters:
outPngFilename
- StringshowLabels
- booleanstandardize
- normalize to deviation 1, mean 0. FIXME this is not used?- Throws:
IOException
-
saveImage
Saves the image to a png file.- Parameters:
outPngFilename
- String- Throws:
IOException
-
saveImage
public void saveImage(String outPngFilename, boolean showLabels, boolean showScale) throws IOException - Parameters:
outPngFilename
-showLabels
-- Throws:
IOException
-
saveImageToPng
public void saveImageToPng(ColorMatrix<R, C> matrix, OutputStream stream, boolean showLabels, boolean showScalebar, boolean standardize) throws IOException- Parameters:
stream
-showLabels
-standardize
-- Throws:
IOException
-
setCellSize
-
setColorMap
- Parameters:
colorMap
- an array of colors which define the midpoints in the color map; this can be one of the constants defined in the ColorMap class, like ColorMap.REDGREEN_COLORMAP and ColorMap.BLACKBODY_COLORMAP
-
setDisplayRange
public void setDisplayRange(double min, double max) - Parameters:
min
-max
-
-
setLabelsVisible
public void setLabelsVisible(boolean isShowLabels) If this display component has already been added to the GUI, it will be resized to fit or exclude the row names- Parameters:
isShowLabels
- boolean
-
setMatrix
- Parameters:
matrix
- the new matrix to use; will resize this display component as necessary
-
setMaxColumnLength
public void setMaxColumnLength(int columnLength) - Parameters:
columnLength
- the m_maxColumnLength to set
-
setRowHeight
public void setRowHeight(int height) -
setRowKeys
public void setRowKeys(int[] rowKeys) -
setScaleBarVisible
public void setScaleBarVisible(boolean isShowScale) -
setStandardizedEnabled
public void setStandardizedEnabled(boolean showStandardizedMatrix) -
writeToPng
public void writeToPng(ColorMatrix<R, C> matrix, OutputStream stream, boolean showLabels, boolean showScalebar) throws IOException- Parameters:
matrix
-stream
-showLabels
-showScalebar
-- Throws:
IOException
-
computeSize
compute the size of the matrix in pixels.- Parameters:
withLabels
-- Returns:
-
drawColumnNames
Draws column names vertically (turned 90 degrees counter-clockwise)- Parameters:
g
- Graphics
-
drawMatrix
protected void drawMatrix(ColorMatrix<R, C> matrix, Graphics g, boolean leaveRoomForLabels, boolean leaveRoomForScalebar) Gets called from #paintComponent and #saveImage. Does not draw the labels.- Parameters:
g
- GraphicsleaveRoomForLabels
- boolean
-
drawRowNames
Draws row names (horizontally)- Parameters:
g
- GraphicsshowScalebar
-
-
drawScaleBar
- Parameters:
g
-d
-
-
initSize
protected void initSize()Sets the display size -
paintComponent
- Overrides:
paintComponent
in classJComponent
-