public class FunctionGraph extends JPanel implements CursorSource, CursorListener
Modifier and Type | Class and Description |
---|---|
class |
FunctionGraph.DoublePoint |
JPanel.AccessibleJPanel
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
protected boolean |
autoYMinMax |
protected Color |
axisColor |
protected Color |
backgroundColor |
protected List |
cursorListeners |
protected List<double[]> |
dataseries |
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 List<Integer> |
dotStyle |
static int |
DRAW_DOTS |
static int |
DRAW_HISTOGRAM |
static int |
DRAW_LINE |
static int |
DRAW_LINEWITHDOTS |
protected List<Color> |
graphColor |
protected BufferedImage |
graphImage |
protected List<Integer> |
graphStyle |
protected 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 |
ymax |
protected double |
ymin |
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Modifier | Constructor and Description |
---|---|
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.
|
Modifier and Type | Method and Description |
---|---|
void |
addCursorListener(CursorListener l) |
void |
addDataSeries(double[] data,
Color newGraphColor,
int newGraphStyle,
int newDotStyle)
Add a secondary data series to this graph.
|
protected void |
createGraphImage() |
protected void |
drawData(Graphics2D g,
int image_fromX,
int image_toX,
int image_refX,
int image_refY,
int startY,
int image_height,
double[] data,
Color currentGraphColor,
int currentGraphStyle,
int currentDotStyle)
While painting the graph, draw the actual function data.
|
protected void |
drawDot(Graphics2D g,
int x,
int y,
int currentDotStyle) |
protected void |
drawXAxis(Graphics2D g,
double width,
int startX,
int startY,
int image_y_origin) |
protected void |
drawYAxis(Graphics2D g,
double height,
int startX,
int startY,
int image_x_origin) |
protected JPanel |
getControls()
Subclasses may provide specific controls here.
|
CursorListener[] |
getCursorListeners() |
protected 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(Graphics gr) |
boolean |
removeCursorListener(CursorListener l) |
void |
setPrimaryDataSeriesStyle(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
|
JFrame |
showInJFrame(String title,
boolean allowZoom,
boolean exitOnClose) |
JFrame |
showInJFrame(String title,
boolean allowZoom,
boolean showControls,
boolean exitOnClose) |
JFrame |
showInJFrame(String title,
int width,
int height,
boolean allowZoom,
boolean exitOnClose) |
JFrame |
showInJFrame(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) |
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
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
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
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
public static final int DEFAULT_WIDTH
public static final int DEFAULT_HEIGHT
public static final int DRAW_LINE
public static final int DRAW_DOTS
public static final int DRAW_LINEWITHDOTS
public static final int DRAW_HISTOGRAM
public static final int DOT_FULLCIRCLE
public static final int DOT_FULLSQUARE
public static final int DOT_FULLDIAMOND
public static final int DOT_EMPTYCIRCLE
public static final int DOT_EMPTYSQUARE
public static final int DOT_EMPTYDIAMOND
protected int paddingLeft
protected int paddingRight
protected int paddingTop
protected int paddingBottom
protected double x0
protected double xStep
protected List<double[]> dataseries
protected double ymin
protected double ymax
protected boolean showXAxis
protected boolean showYAxis
protected BufferedImage graphImage
protected Color backgroundColor
protected Color axisColor
protected Color histogramBorderColor
protected int dotSize
protected int histogramWidth
protected boolean autoYMinMax
protected FunctionGraph.DoublePoint positionCursor
protected FunctionGraph.DoublePoint rangeCursor
protected List cursorListeners
protected FunctionGraph()
public FunctionGraph(double x0, double xStep, double[] y)
x0
- x0xStep
- xStepy
- ypublic FunctionGraph(int width, int height, double x0, double xStep, double[] y)
width
- widthheight
- heightx0
- x0xStep
- xStepy
- ypublic void initialise(int width, int height, double newX0, double newXStep, double[] data)
public void updateData(double newX0, double newXStep, double[] data)
addDataSeries(double[], Color, int, int)
are removed.newX0
- x position of first data pointnewXStep
- distance between data points on X axisdata
- all data pointspublic void setPrimaryDataSeriesStyle(Color newGraphColor, int newGraphStyle, int newDotStyle)
public void setYMinMax(double theYMin, double theYMax)
theYMin
- the Y mintheYMax
- the Y maxpublic void addDataSeries(double[] data, Color newGraphColor, int newGraphStyle, int newDotStyle)
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.public double getZoomX()
public void setZoomX(double factor)
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.protected void createGraphImage()
protected void drawData(Graphics2D g, int image_fromX, int image_toX, int image_refX, int image_refY, int startY, int image_height, double[] data, Color currentGraphColor, int currentGraphStyle, int currentDotStyle)
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 areastartY
- 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 valuesdata
- datacurrentGraphColor
- current graph colorcurrentGraphStyle
- current graph stylecurrentDotStyle
- current dot styleprotected void drawDot(Graphics2D g, int x, int y, int currentDotStyle)
protected void drawYAxis(Graphics2D g, double height, int startX, int startY, int image_x_origin)
protected void drawXAxis(Graphics2D g, double width, int startX, int startY, int image_y_origin)
public void paintComponent(Graphics gr)
paintComponent
in class JComponent
protected int imageX2indexX(int imageX)
protected double imageX2X(int imageX)
protected int indexX2imageX(int indexX)
protected int X2imageX(double x)
protected int X2indexX(double x)
protected double imageY2Y(int imageY)
protected int y2imageY(double y)
protected double getYRange()
protected double getXRange()
public CursorDisplayer.CursorLine getPositionCursor()
getPositionCursor
in interface CursorSource
public CursorDisplayer.CursorLine getRangeCursor()
getRangeCursor
in interface CursorSource
public CursorDisplayer.Label getValueLabel()
getValueLabel
in interface CursorSource
public void addCursorListener(CursorListener l)
public CursorListener[] getCursorListeners()
public boolean removeCursorListener(CursorListener l)
protected void notifyCursorListeners()
public void updateCursorPosition(CursorEvent e)
updateCursorPosition
in interface CursorListener
e
- e cursor eventpublic JFrame showInJFrame(String title, boolean allowZoom, boolean showControls, boolean exitOnClose)
public JFrame showInJFrame(String title, int width, int height, boolean allowZoom, boolean exitOnClose)
public JFrame showInJFrame(String title, int width, int height, boolean allowZoom, boolean showControls, boolean exitOnClose)
protected JPanel getControls()
protected String getLabel(double x, double y)
Copyright © 2000–2016 DFKI GmbH. All rights reserved.