marytts.signalproc.display
Class FunctionGraph
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
marytts.signalproc.display.FunctionGraph
- All Implemented Interfaces:
- java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, CursorListener, CursorSource
- Direct Known Subclasses:
- Cepstrogram, EnergyGraph, F0Graph, Histogram, SignalGraph, SignalSpectrum, Spectrogram
public class FunctionGraph
- extends javax.swing.JPanel
- implements CursorSource, CursorListener
- Author:
- Marc Schröder
- See Also:
- Serialized Form
| 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.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
| 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 |
protected |
FunctionGraph()
Display a 2d graph showing y(x), with labelled scales. |
|
FunctionGraph(double x0,
double xStep,
double[] y)
Display a 2d graph showing y(x), with labelled scales. |
|
FunctionGraph(int width,
int height,
double x0,
double xStep,
double[] y)
Display a 2d graph showing y(x), with labelled scales. |
|
Method Summary |
void |
addCursorListener(CursorListener l)
|
void |
addDataSeries(double[] data,
java.awt.Color newGraphColor,
int newGraphStyle,
int newDotStyle)
Add a secondary data series to this graph. |
protected void |
createGraphImage()
|
protected void |
drawData(java.awt.Graphics2D g,
int image_fromX,
int image_toX,
int image_refX,
int image_refY,
int startY,
int image_height,
double[] data,
java.awt.Color currentGraphColor,
int currentGraphStyle,
int currentDotStyle)
While painting the graph, draw the actual function data. |
protected void |
drawDot(java.awt.Graphics2D g,
int x,
int y,
int currentDotStyle)
|
protected void |
drawXAxis(java.awt.Graphics2D g,
double width,
int startX,
int startY,
int image_y_origin)
|
protected void |
drawYAxis(java.awt.Graphics2D g,
double height,
int startX,
int startY,
int image_x_origin)
|
protected javax.swing.JPanel |
getControls()
Subclasses may provide specific controls here. |
CursorListener[] |
getCursorListeners()
|
protected java.lang.String |
getLabel(double x,
double y)
|
CursorDisplayer.CursorLine |
getPositionCursor()
|
CursorDisplayer.CursorLine |
getRangeCursor()
|
CursorDisplayer.Label |
getValueLabel()
|
protected double |
getXRange()
|
protected double |
getYRange()
|
double |
getZoomX()
|
protected int |
imageX2indexX(int imageX)
|
protected double |
imageX2X(int imageX)
|
protected double |
imageY2Y(int imageY)
|
protected int |
indexX2imageX(int indexX)
|
void |
initialise(int width,
int height,
double newX0,
double newXStep,
double[] data)
|
protected void |
notifyCursorListeners()
|
void |
paintComponent(java.awt.Graphics gr)
|
boolean |
removeCursorListener(CursorListener l)
|
void |
setPrimaryDataSeriesStyle(java.awt.Color newGraphColor,
int newGraphStyle,
int newDotStyle)
|
void |
setYMinMax(double theYMin,
double theYMax)
Manually set the min and max values for the y axis. |
void |
setZoomX(double factor)
Set the zoom of the X |
javax.swing.JFrame |
showInJFrame(java.lang.String title,
boolean allowZoom,
boolean exitOnClose)
|
javax.swing.JFrame |
showInJFrame(java.lang.String title,
boolean allowZoom,
boolean showControls,
boolean exitOnClose)
|
javax.swing.JFrame |
showInJFrame(java.lang.String title,
int width,
int height,
boolean allowZoom,
boolean exitOnClose)
|
javax.swing.JFrame |
showInJFrame(java.lang.String title,
int width,
int height,
boolean allowZoom,
boolean showControls,
boolean exitOnClose)
|
void |
updateCursorPosition(CursorEvent e)
Used when keeping several FunctionGraphs' cursor positions in synchrony. |
void |
updateData(double newX0,
double newXStep,
double[] data)
Replace the previous data with the given new data. |
protected int |
X2imageX(double x)
|
protected int |
X2indexX(double x)
|
protected int |
y2imageY(double y)
|
| 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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, 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 |
DEFAULT_WIDTH
public static final int DEFAULT_WIDTH
- See Also:
- Constant Field Values
DEFAULT_HEIGHT
public static final int DEFAULT_HEIGHT
- See Also:
- Constant Field Values
DRAW_LINE
public static final int DRAW_LINE
- See Also:
- Constant Field Values
DRAW_DOTS
public static final int DRAW_DOTS
- See Also:
- Constant Field Values
DRAW_LINEWITHDOTS
public static final int DRAW_LINEWITHDOTS
- See Also:
- Constant Field Values
DRAW_HISTOGRAM
public static final int DRAW_HISTOGRAM
- See Also:
- Constant Field Values
DOT_FULLCIRCLE
public static final int DOT_FULLCIRCLE
- See Also:
- Constant Field Values
DOT_FULLSQUARE
public static final int DOT_FULLSQUARE
- See Also:
- Constant Field Values
DOT_FULLDIAMOND
public static final int DOT_FULLDIAMOND
- See Also:
- Constant Field Values
DOT_EMPTYCIRCLE
public static final int DOT_EMPTYCIRCLE
- See Also:
- Constant Field Values
DOT_EMPTYSQUARE
public static final int DOT_EMPTYSQUARE
- See Also:
- Constant Field Values
DOT_EMPTYDIAMOND
public static final int DOT_EMPTYDIAMOND
- See Also:
- Constant Field Values
paddingLeft
protected int paddingLeft
paddingRight
protected int paddingRight
paddingTop
protected int paddingTop
paddingBottom
protected int paddingBottom
x0
protected double x0
xStep
protected double xStep
dataseries
protected java.util.List<double[]> dataseries
ymin
protected double ymin
ymax
protected double ymax
showXAxis
protected boolean showXAxis
showYAxis
protected boolean showYAxis
graphImage
protected java.awt.image.BufferedImage graphImage
backgroundColor
protected java.awt.Color backgroundColor
axisColor
protected java.awt.Color axisColor
graphColor
protected java.util.List<java.awt.Color> graphColor
histogramBorderColor
protected java.awt.Color histogramBorderColor
graphStyle
protected java.util.List<java.lang.Integer> graphStyle
dotStyle
protected java.util.List<java.lang.Integer> dotStyle
dotSize
protected int dotSize
histogramWidth
protected int histogramWidth
autoYMinMax
protected boolean autoYMinMax
positionCursor
protected FunctionGraph.DoublePoint positionCursor
rangeCursor
protected FunctionGraph.DoublePoint rangeCursor
cursorListeners
protected java.util.List cursorListeners
FunctionGraph
protected FunctionGraph()
- Display a 2d graph showing y(x), with labelled scales.
This constructor is for subclasses only, which may need
to perform some operations before calling initialise().
FunctionGraph
public FunctionGraph(double x0,
double xStep,
double[] y)
- Display a 2d graph showing y(x), with labelled scales.
FunctionGraph
public FunctionGraph(int width,
int height,
double x0,
double xStep,
double[] y)
- Display a 2d graph showing y(x), with labelled scales.
initialise
public void initialise(int width,
int height,
double newX0,
double newXStep,
double[] data)
updateData
public void updateData(double newX0,
double newXStep,
double[] data)
- Replace the previous data with the given new data.
Any secondary data series added using {
addDataSeries(double[], Color, int, int) are removed.
- Parameters:
newX0 - x position of first data pointnewXStep - distance between data points on X axisdata - all data points
setPrimaryDataSeriesStyle
public void setPrimaryDataSeriesStyle(java.awt.Color newGraphColor,
int newGraphStyle,
int newDotStyle)
setYMinMax
public void setYMinMax(double theYMin,
double theYMax)
- Manually set the min and max values for the y axis.
- Parameters:
theYMin - theYMax -
addDataSeries
public void addDataSeries(double[] data,
java.awt.Color newGraphColor,
int newGraphStyle,
int newDotStyle)
- Add a secondary data series to this graph.
- Parameters:
data - the function data, which must be of same length as the original data. updateData(double, double, double[])newGraphColor - a colournewGraphStyle - the style for painting this data series. One of DRAW_LINE, DRAW_DOTS, 3, DRAW_HISTOGRAM.newDotStyle - the shape of any dots to use (meaningful only with newGraphStyle == DRAW_DOTS or DRAW_LINEWITHDOTS).
One of DOT_EMPTYCIRCLE, DOT_EMPTYDIAMOND, DOT_EMPTYSQUARE, DOT_FULLCIRCLE, DOT_FULLDIAMOND, DOT_FULLSQUARE.
For other graph styles, this is ignored, and it is recommended to set it to -1 for clarity.
getZoomX
public double getZoomX()
setZoomX
public void setZoomX(double factor)
- Set the zoom of the X
- Parameters:
factor - the zoom factor for X; 1 means that each data point corresponds to one pixel;
0.5 means that 2 data points are mapped onto one pixel; etc.
createGraphImage
protected void createGraphImage()
drawData
protected void drawData(java.awt.Graphics2D g,
int image_fromX,
int image_toX,
int image_refX,
int image_refY,
int startY,
int image_height,
double[] data,
java.awt.Color currentGraphColor,
int currentGraphStyle,
int currentDotStyle)
- While painting the graph, draw the actual function data.
- Parameters:
g - the graphics2d object to paint inimage_fromX - first visible X coordinate of the Graph display area (= after subtracting space reserved for Y axis)image_toX - last visible X coordinate of the Graph display area (= after subtracting space reserved for Y axis)image_refX - X coordinate of the origin, in the display areaimage_refY - Y coordinate of the origin, in the display areaxScaleFactor - conversion factor between data space and image space, image_x = xScaleFactor * data_xyScaleFactor - conversion factor between data space and image space, image_y = yScaleFactor * data_ystartY - the start position on the Y axis (= the lower bound of the drawing area)image_height - the height of the drawable region for the y values
drawDot
protected void drawDot(java.awt.Graphics2D g,
int x,
int y,
int currentDotStyle)
drawYAxis
protected void drawYAxis(java.awt.Graphics2D g,
double height,
int startX,
int startY,
int image_x_origin)
drawXAxis
protected void drawXAxis(java.awt.Graphics2D g,
double width,
int startX,
int startY,
int image_y_origin)
paintComponent
public void paintComponent(java.awt.Graphics gr)
- Overrides:
paintComponent in class javax.swing.JComponent
imageX2indexX
protected int imageX2indexX(int imageX)
imageX2X
protected double imageX2X(int imageX)
indexX2imageX
protected int indexX2imageX(int indexX)
X2imageX
protected int X2imageX(double x)
X2indexX
protected int X2indexX(double x)
imageY2Y
protected double imageY2Y(int imageY)
y2imageY
protected int y2imageY(double y)
getYRange
protected double getYRange()
getXRange
protected double getXRange()
getPositionCursor
public CursorDisplayer.CursorLine getPositionCursor()
- Specified by:
getPositionCursor in interface CursorSource
getRangeCursor
public CursorDisplayer.CursorLine getRangeCursor()
- Specified by:
getRangeCursor in interface CursorSource
getValueLabel
public CursorDisplayer.Label getValueLabel()
- Specified by:
getValueLabel in interface CursorSource
addCursorListener
public void addCursorListener(CursorListener l)
getCursorListeners
public CursorListener[] getCursorListeners()
removeCursorListener
public boolean removeCursorListener(CursorListener l)
notifyCursorListeners
protected void notifyCursorListeners()
updateCursorPosition
public void updateCursorPosition(CursorEvent e)
- Used when keeping several FunctionGraphs' cursor positions in synchrony.
Register each other as cursor listeners before the glass pane; whichever gets
clicked causes the others to be updated. Make sure to add any peers _before_
any displaying cursor listeners, to make sure all are in line before being
displayed.
- Specified by:
updateCursorPosition in interface CursorListener
showInJFrame
public javax.swing.JFrame showInJFrame(java.lang.String title,
boolean allowZoom,
boolean exitOnClose)
showInJFrame
public javax.swing.JFrame showInJFrame(java.lang.String title,
boolean allowZoom,
boolean showControls,
boolean exitOnClose)
showInJFrame
public javax.swing.JFrame showInJFrame(java.lang.String title,
int width,
int height,
boolean allowZoom,
boolean exitOnClose)
showInJFrame
public javax.swing.JFrame showInJFrame(java.lang.String title,
int width,
int height,
boolean allowZoom,
boolean showControls,
boolean exitOnClose)
getControls
protected javax.swing.JPanel getControls()
- Subclasses may provide specific controls here.
- Returns:
- a JPanel filled with the controls, or null if none are to be provided.
getLabel
protected java.lang.String getLabel(double x,
double y)