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
public class MatrixDisplay<R,C> extends JPanel
A visual component for displaying a color matrix- Author:
- Will Braynen
- See Also:
- Serialized Form
-
-
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
Fields Modifier and Type Field Description protected Dimensionm_cellSizeprotected intm_columnLabelHeightprotected intm_defaultResolutionprotected intm_fontGutterprotected intm_fontSizeprotected booleanm_isShowLabelsprotected booleanm_isShowScaleprotected Fontm_labelFontprotected intm_labelGutterprotected intm_maxColumnLengthprotected intm_maxFontSizeprotected intm_ratioWidthprotected intm_resolutionprotected intm_rowLabelWidthprotected intm_textSize-
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
Constructors Constructor Description MatrixDisplay(DoubleMatrix<R,C> matrix)MatrixDisplay(ColorMatrix<R,C> matrix)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected DimensioncomputeSize(boolean showLabels, boolean showScalebar)compute the size of the matrix in pixels.protected voiddrawColumnNames(Graphics g, boolean leaveRoomForScalebar)Draws column names vertically (turned 90 degrees counter-clockwise)protected voiddrawMatrix(ColorMatrix<R,C> matrix, Graphics g, boolean leaveRoomForLabels, boolean leaveRoomForScalebar)Gets called from #paintComponent and #saveImage.protected voiddrawRowNames(Graphics g, boolean showScalebar)Draws row names (horizontally)protected voiddrawScaleBar(Graphics g, Dimension d, double displayMin, double displayMax)ColorgetColor(int row, int column)Color[]getColorMap()ColorMatrix<R,C>getColorMatrix()intgetColumnCount()ObjectgetColumnName(int column)String[]getColumnNames()doublegetDisplayMax()doublegetDisplayMin()doublegetDisplayRange()DoubleMatrix<R,C>getMatrix()doublegetMax()intgetMaxColumnLength()doublegetMin()ColorgetMissingColor()doublegetRawValue(int row, int column)double[]getRow(int row)double[]getRowByName(R rowName)intgetRowCount()intgetRowHeight()intgetRowIndexByName(R rowName)ObjectgetRowName(int row)String[]getRowNames()booleangetStandardizedEnabled()doublegetValue(int row, int column)voidinit(ColorMatrix<R,C> matrix)protected voidinitSize()Sets the display sizestatic <R,C>
MatrixDisplay<R,C>newInstance(ColorMatrix<R,C> matrix)protected voidpaintComponent(Graphics g)voidresetRowKeys()voidsaveImage(String outPngFilename)Saves the image to a png file.voidsaveImage(String outPngFilename, boolean showLabels, boolean showScale)voidsaveImage(ColorMatrix<R,C> matrix, String outPngFilename, boolean showLabels, boolean showScalebar, boolean standardize)voidsaveImageToPng(ColorMatrix<R,C> matrix, OutputStream stream, boolean showLabels, boolean showScalebar, boolean standardize)voidsetCellSize(Dimension d)voidsetColorMap(Color[] colorMap)voidsetDisplayRange(double min, double max)voidsetLabelsVisible(boolean isShowLabels)If this display component has already been added to the GUI, it will be resized to fit or exclude the row namesvoidsetMatrix(ColorMatrix<R,C> matrix)voidsetMaxColumnLength(int columnLength)voidsetRowHeight(int height)voidsetRowKeys(int[] rowKeys)voidsetScaleBarVisible(boolean isShowScale)voidsetStandardizedEnabled(boolean showStandardizedMatrix)voidwriteToPng(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, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
m_cellSize
protected Dimension m_cellSize
-
m_columnLabelHeight
protected int m_columnLabelHeight
-
m_defaultResolution
protected final int m_defaultResolution
- See Also:
- Constant Field Values
-
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
protected Font m_labelFont
-
m_labelGutter
protected int m_labelGutter
-
m_maxColumnLength
protected int m_maxColumnLength
-
m_maxFontSize
protected final int m_maxFontSize
- See Also:
- Constant Field Values
-
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 Detail
-
MatrixDisplay
public MatrixDisplay(ColorMatrix<R,C> matrix)
-
MatrixDisplay
public MatrixDisplay(DoubleMatrix<R,C> matrix)
-
-
Method Detail
-
newInstance
public static <R,C> MatrixDisplay<R,C> newInstance(ColorMatrix<R,C> matrix)
-
getColor
public Color getColor(int row, int column)
-
getColorMap
public Color[] getColorMap()
- Returns:
- the current color map
-
getColorMatrix
public ColorMatrix<R,C> getColorMatrix()
-
getColumnCount
public int getColumnCount()
-
getColumnName
public Object getColumnName(int column)
-
getColumnNames
public String[] getColumnNames()
-
getDisplayMax
public double getDisplayMax()
-
getDisplayMin
public double getDisplayMin()
-
getDisplayRange
public double getDisplayRange()
-
getMatrix
public DoubleMatrix<R,C> 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
public Color getMissingColor()
- Returns:
- the color used for missing values
-
getRawValue
public double getRawValue(int row, int column)
-
getRow
public double[] getRow(int row)
-
getRowByName
public double[] getRowByName(R rowName)
-
getRowCount
public int getRowCount()
-
getRowHeight
public int getRowHeight()
-
getRowIndexByName
public int getRowIndexByName(R rowName)
-
getRowName
public Object getRowName(int row)
-
getRowNames
public String[] getRowNames()
-
getStandardizedEnabled
public boolean getStandardizedEnabled()
-
getValue
public double getValue(int row, int column)
-
init
public void init(ColorMatrix<R,C> matrix)
-
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
public void saveImage(String outPngFilename) throws IOException
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
public void setCellSize(Dimension d)
-
setColorMap
public void setColorMap(Color[] colorMap)
- 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
public void setMatrix(ColorMatrix<R,C> matrix)
- 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
protected Dimension computeSize(boolean showLabels, boolean showScalebar)
compute the size of the matrix in pixels.- Parameters:
withLabels-- Returns:
-
drawColumnNames
protected void drawColumnNames(Graphics g, boolean leaveRoomForScalebar)
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
protected void drawRowNames(Graphics g, boolean showScalebar)
Draws row names (horizontally)- Parameters:
g- GraphicsshowScalebar-
-
drawScaleBar
protected void drawScaleBar(Graphics g, Dimension d, double displayMin, double displayMax)
- Parameters:
g-d-
-
initSize
protected void initSize()
Sets the display size
-
paintComponent
protected void paintComponent(Graphics g)
- Overrides:
paintComponentin classJComponent
-
-