de.dfki.lt.signalproc.display
Class FunctionGraph

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by de.dfki.lt.signalproc.display.FunctionGraph
All Implemented Interfaces:
CursorListener, CursorSource, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible
Direct Known Subclasses:
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 Class Summary
 class FunctionGraph.DoublePoint
           
 
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
 
Field Summary
protected  java.awt.Color axisColor
           
protected  java.awt.Color backgroundColor
           
protected  java.util.List cursorListeners
           
static int DEFAULT_HEIGHT
           
static int DEFAULT_WIDTH
           
static int DOT_EMPTYCIRCLE
           
static int DOT_EMPTYDIAMOND
           
static int DOT_EMPTYSQUARE
           
static int DOT_FULLCIRCLE
           
static int DOT_FULLDIAMOND
           
static int DOT_FULLSQUARE
           
protected  int dotSize
           
protected  int dotStyle
           
static int DRAW_DOTS
           
static int DRAW_HISTOGRAM
           
static int DRAW_LINE
           
static int DRAW_LINEWITHDOTS
           
protected  java.awt.Color graphColor
           
protected  java.awt.image.BufferedImage graphImage
           
protected  int graphStyle
           
protected  java.awt.Color histogramBorderColor
           
protected  int histogramWidth
           
protected  int paddingBottom
           
protected  int paddingLeft
           
protected  int paddingRight
           
protected  int paddingTop
           
protected  FunctionGraph.DoublePoint positionCursor
           
protected  FunctionGraph.DoublePoint rangeCursor
           
protected  boolean showXAxis
           
protected  boolean showYAxis
           
protected  double x0
           
protected  double xStep
           
protected  double[] y
           
protected  double ymax
           
protected  double ymin
           
 
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)
           
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)
          While painting the graph, draw the actual function data.
protected  void drawDot(java.awt.Graphics2D g, int x, int y)
           
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 x0, double xStep, double[] y)
           
protected  void notifyCursorListeners()
           
 void paintComponent(java.awt.Graphics gr)
           
 boolean removeCursorListener(CursorListener l)
           
 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.
protected  void updateData(double x0, double xStep, double[] y)
           
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
 

Field Detail

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

y

protected double[] y

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.awt.Color graphColor

histogramBorderColor

protected java.awt.Color histogramBorderColor

graphStyle

protected int graphStyle

dotStyle

protected int dotStyle

dotSize

protected int dotSize

histogramWidth

protected int histogramWidth

positionCursor

protected FunctionGraph.DoublePoint positionCursor

rangeCursor

protected FunctionGraph.DoublePoint rangeCursor

cursorListeners

protected java.util.List cursorListeners
Constructor Detail

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.

Method Detail

initialise

public void initialise(int width,
                       int height,
                       double x0,
                       double xStep,
                       double[] y)

updateData

protected void updateData(double x0,
                          double xStep,
                          double[] y)

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)
While painting the graph, draw the actual function data.

Parameters:
g - the graphics2d object to paint in
image_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 area
image_refY - Y coordinate of the origin, in the display area
xScaleFactor - conversion factor between data space and image space, image_x = xScaleFactor * data_x
yScaleFactor - conversion factor between data space and image space, image_y = yScaleFactor * data_y
startY - 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)

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)