|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
HeatMap
public class HeatMap
Title: HeatMap
Description: HeatMap is a JPanel that displays a 2-dimensional array of data using a selected color gradient scheme.
For specifying data, the first index into the double[][] array is the x- coordinate, and the second index is the y-coordinate. In the constructor and updateData method, the 'useGraphicsYAxis' parameter is used to control whether the row y=0 is displayed at the top or bottom. Since the usual graphics coordinate system has y=0 at the top, setting this parameter to true will draw the y=0 row at the top, and setting the parameter to false will draw the y=0 row at the bottom, like in a regular, mathematical coordinate system. This parameter was added as a solution to the problem of "Which coordinate system should we use? Graphics, or mathematical?", and allows the user to choose either coordinate system. Because the HeatMap will be plotting the data in a graphical manner, using the Java Swing framework that uses the standard computer graphics coordinate system, the user's data is stored internally with the y=0 row at the top.
There are a number of defined gradient types (look at the static fields), but you can create any gradient you like by using either of the following functions in the Gradient class:
myHeatMap.updateGradient(Gradient.createMultiGradient(new Color[] {Color.red, Color.white, Color.blue}, 256));
By default, the graph title, axis titles, and axis tick marks are not displayed. Be sure to set the appropriate title before enabling them.
Copyright: Copyright (c) 2007, 2008
HeatMap is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
HeatMap is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with HeatMap; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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.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 | |
---|---|
HeatMap(double[][] data,
boolean useGraphicsYAxis,
java.awt.Color[] colors)
|
Method Summary | |
---|---|
static double[][] |
generatePyramidData(int dimension)
This function generates an appropriate data array for display. |
static double[][] |
generateRampTestData()
This function generates data that is not vertically-symmetric, which makes it very useful for testing which type of vertical axis is being used to plot the data. |
static double[][] |
generateSinCosData(int dimension)
This function generates an appropriate data array for display. |
void |
paintComponent(java.awt.Graphics g)
The overridden painting method, now optimized to simply draw the data plot to the screen, letting the drawImage method do the resizing. |
void |
setColorBackground(java.awt.Color bg)
Updates the background color. |
void |
setColorForeground(java.awt.Color fg)
Updates the foreground color. |
void |
setCoordinateBounds(double xMin,
double xMax,
double yMin,
double yMax)
Specify the coordinate bounds for the map. |
void |
setDrawLegend(boolean drawLegend)
Updates the state of the legend. |
void |
setDrawTitle(boolean drawTitle)
Updates the state of the title. |
void |
setDrawXAxisTitle(boolean drawXAxisTitle)
Updates the state of the X-Axis Title. |
void |
setDrawXTicks(boolean drawXTicks)
Updates the state of the X-Axis ticks. |
void |
setDrawYAxisTitle(boolean drawYAxisTitle)
Updates the state of the Y-Axis Title. |
void |
setDrawYTicks(boolean drawYTicks)
Updates the state of the Y-Axis ticks. |
void |
setTitle(java.lang.String title)
Updates the title. |
void |
setXAxisTitle(java.lang.String xAxisTitle)
Updates the X-Axis title. |
void |
setXCoordinateBounds(double xMin,
double xMax)
Specify the coordinate bounds for the X-range. |
void |
setXMaxCoordinateBounds(double xMax)
Specify the coordinate bounds for the X Max. |
void |
setXMinCoordinateBounds(double xMin)
Specify the coordinate bounds for the X Min. |
void |
setYAxisTitle(java.lang.String yAxisTitle)
Updates the Y-Axis title. |
void |
setYCoordinateBounds(double yMin,
double yMax)
Specify the coordinate bounds for the Y-range. |
void |
setYMaxCoordinateBounds(double yMax)
Specify the coordinate bounds for the Y Max. |
void |
setYMinCoordinateBounds(double yMin)
Specify the coordinate bounds for the Y Min. |
void |
updateData(double[][] data,
boolean useGraphicsYAxis)
Updates the data display, calls drawData() to do the expensive re-drawing of the data plot, and then calls repaint(). |
void |
updateGradient(java.awt.Color[] colors)
Updates the gradient used to display the data. |
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, 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, 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, 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, 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, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, 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 HeatMap(double[][] data, boolean useGraphicsYAxis, java.awt.Color[] colors)
data
- The data to display, must be a complete array (non-ragged)useGraphicsYAxis
- If true, the data will be displayed with the y=0 row at the top of the screen. If false, the data will be displayed with they=0 row at the bottom of the screen.colors
- A variable of the type Color[]. See also #createMultiGradient
and #createGradient
.Method Detail |
---|
public void setCoordinateBounds(double xMin, double xMax, double yMin, double yMax)
xMin
- The lower bound of x-values, used for axis labelsxMax
- The upper bound of x-values, used for axis labelspublic void setXCoordinateBounds(double xMin, double xMax)
xMin
- The lower bound of x-values, used for axis labelsxMax
- The upper bound of x-values, used for axis labelspublic void setXMinCoordinateBounds(double xMin)
xMin
- The lower bound of x-values, used for axis labelspublic void setXMaxCoordinateBounds(double xMax)
xMax
- The upper bound of x-values, used for axis labelspublic void setYCoordinateBounds(double yMin, double yMax)
yMin
- The lower bound of y-values, used for axis labelsyMax
- The upper bound of y-values, used for axis labelspublic void setYMinCoordinateBounds(double yMin)
yMin
- The lower bound of Y-values, used for axis labelspublic void setYMaxCoordinateBounds(double yMax)
yMax
- The upper bound of y-values, used for axis labelspublic void setTitle(java.lang.String title)
title
- The new titlepublic void setDrawTitle(boolean drawTitle)
drawTitle
- Specifies if the title should be drawnpublic void setXAxisTitle(java.lang.String xAxisTitle)
xAxisTitle
- The new X-Axis titlepublic void setDrawXAxisTitle(boolean drawXAxisTitle)
drawXAxisTitle
- Specifies if the X-Axis title should be drawnpublic void setYAxisTitle(java.lang.String yAxisTitle)
yAxisTitle
- The new Y-Axis titlepublic void setDrawYAxisTitle(boolean drawYAxisTitle)
drawYAxisTitle
- Specifies if the Y-Axis title should be drawnpublic void setDrawLegend(boolean drawLegend)
drawLegend
- Specifies if the legend should be drawnpublic void setDrawXTicks(boolean drawXTicks)
drawXTicks
- Specifies if the X-Axis ticks should be drawnpublic void setDrawYTicks(boolean drawYTicks)
drawYTicks
- Specifies if the Y-Axis ticks should be drawnpublic void setColorForeground(java.awt.Color fg)
fg
- Specifies the desired foreground colorpublic void setColorBackground(java.awt.Color bg)
bg
- Specifies the desired background colorpublic void updateGradient(java.awt.Color[] colors)
colors
- A variable of type Color[]public static double[][] generateRampTestData()
public static double[][] generateSinCosData(int dimension)
dimension
- Size of each side of the returned array
public static double[][] generatePyramidData(int dimension)
dimension
- Size of each side of the returned array
public void updateData(double[][] data, boolean useGraphicsYAxis)
data
- The data to display, must be a complete array (non-ragged)useGraphicsYAxis
- If true, the data will be displayed with the y=0 row at the top of the screen. If false, the data will be displayed with the y=0 row at the bottom of the screen.public void paintComponent(java.awt.Graphics g)
paintComponent
in class javax.swing.JComponent
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |