|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
info.monitorenter.gui.chart.Chart2D
public class Chart2D
Chart2D
is a component for displaying the data contained in a
ITrace2D
. It inherits many features from javax.swing.JPanel
and
allows specific configuration.
In order to simplify the use of it, the scaling, labeling and choosing of display- range is done
automatically which flattens the free configuration.
There are several default settings that may be changed in Chart2D
TracePoint2D
contained in the all ITrace2d
instances connected. This is because the
IAxis
of the chart (for x and y) use by default a
RangePolicyUnbounded
. To change this, get the
axis of the chart to change (via getAxisX()
, getAxisY()
) and invoke
IAxis.setRangePolicy(IRangePolicy)
with the desired viewport
behavior.
paint()
operation every TracePoint2D
is taken from
the ITrace2D
- instance exactly in the order, it's iterator returns them. From
every TracePoint2D
then a line is drawn to the next. ITrace2D
to avoid this. To change this line painting behaviour you can use custom
renderers at the level of traces via
ITrace2D.addTracePainter(ITracePainter)
or
ITrace2D.setTracePainter(ITracePainter)
.
IAxis.setPaintScale(boolean)
This allows saving of many computations.
... Chart2D test = new Chart2D(); JFrame frame = new JFrame("Chart2D- Debug"); frame.setSize(400,200); frame.setVisible(true); ITrace2D atrace = new Trace2DLtd(100); ... <further configuration of trace> ... test.addTrace(atrace); .... while(expression){ atrace.addPoint(adouble,bdouble); .... }
PropertyChangeListener
instances may be added via
Container.addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
.
They inherit the properties to listen from
Container.addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
.
Additionally more PropertyChangeEvents
are triggered.
As the set of traces inside this class is a collection (and no single property) the
PropertyChangeEvent
fired for a change of properties property will contain a
reference to the Chart2D
instance as well as the ITrace2D
(if
involved in the change).
getPropertyName() |
getSource() |
getOldValue() |
getNewValue() |
occurence |
---|---|---|---|---|
PROPERTY_ADD_REMOVE_TRACE |
Chart2D |
null | ITrace2D |
if a new instance is added. |
PROPERTY_ADD_REMOVE_TRACE |
Chart2D |
ITrace2D |
null | if an instance is deleted. |
PROPERTY_BACKGROUND_COLOR |
Chart2D |
Color |
Color |
if a change of the background color occurs. |
PROPERTY_AXIS_X |
Chart2D |
IAxis |
IAxis |
if a new axis is set in x dimension. |
PROPERTY_AXIS_Y |
Chart2D |
IAxis |
IAxis |
if a new axis is set in y dimension. |
PROPERTY_GRID_COLOR |
Chart2D |
Color |
Color |
if a change of the grid color occurs. |
PROPERTY_PAINTLABELS |
Chart2D |
Boolean |
Boolean |
if a change of the paint labels flag occurs. |
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.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
---|---|
static String[] |
AXIX_CONSTANT_NAMES
Speaking names for axis constants - used for debugging only. |
protected static boolean |
DEBUG_SCALING
A package wide switch for debugging problems with scaling. |
static boolean |
DEBUG_THREADING
A package wide switch for debugging problems with multithreading. |
static String |
PROPERTY_ADD_REMOVE_TRACE
The bean property constant identifying a change of the internal set of
instances. |
static String |
PROPERTY_AXIS_X
The bean property constant identifying a change of the internal
instance for the x dimension. |
static String |
PROPERTY_AXIS_Y
The bean property constant identifying a change of the internal
instance for the y dimension. |
static String |
PROPERTY_BACKGROUND_COLOR
The bean property constant identifying a change of the background color. |
static String |
PROPERTY_FONT
The bean property constant identifying a change of the font. |
static String |
PROPERTY_FOREGROUND_COLOR
The bean property constant identifying a change of the foreground color. |
static String |
PROPERTY_GRID_COLOR
The bean property constant identifying a change of the grid color. |
static String |
PROPERTY_PAINTLABELS
The bean property constant identifying a change of the paint labels flag. |
static int |
X
Constant describing the x axis (needed for scaling). |
static int |
X_Y
Constant describing the x and y axis (needed for scaling). |
static int |
Y
Constant describing the y axis (needed for scaling). |
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 | |
---|---|
Chart2D()
Creates a new chart. |
Method Summary | |
---|---|
void |
addTrace(ITrace2D points)
Adds the trace to this chart. |
JToolTip |
createToolTip()
|
void |
destroy()
Destroys the chart. |
protected void |
finalize()
Cleanup when this instance is dropped. |
protected double |
findMaxX()
Searches for the maximum x value of all contained ITraces. |
protected double |
findMaxY()
Searches for the maximum y value of all contained ITraces. |
protected double |
findMinX()
Searches for the minimum x value of all contained ITraces. |
protected double |
findMinY()
Searches for the minimum y value of all contained ITraces. |
IAxisTickPainter |
getAxisTickPainter()
Returns the painter for the ticks of the axis. |
IAxis |
getAxisX()
Returns the axis for the x dimension. |
IAxis |
getAxisY()
Returns the axis for the y dimension. |
Color |
getGridColor()
Returns the color of the grid. |
double |
getMaxX()
Returns the maximum x-value of all contained instances. |
double |
getMaxY()
Returns the maximum y-value of all contained instances. |
int |
getMinPaintLatency()
Returns the chart - wide setting for the ms to give a repaint operation time for collecting several repaint requests into one (performance vs. update speed). |
double |
getMinX()
Returns the minimum x-value of all contained instances. |
double |
getMinY()
Returns the minimum y-value of all contained instances. |
double |
getOffsetX()
Returns the minimum x-value displayed by this chart. |
Chart2D |
getSynchronizedXStartChart()
Returns the chart that will be synchronized for finding the start coordinate of this chart to draw in x dimension ( ). |
String |
getToolTipText(MouseEvent event)
|
Set |
getTraces()
Returns the internal set of traces that are currently rendered by this instance. |
int |
getXChartEnd()
Returns the x coordinate of the chart's right edge in px. |
int |
getXChartStart()
Returns the x coordinate of the chart's left edge in px. |
int |
getYChartEnd()
Returns the y coordinate of the upper edge of the chart's display area in px. |
int |
getYChartStart()
Returns the y coordinate of the chart's lower edge in px. |
protected boolean |
isDirtyScaling()
Returns true if the bounds of all TracePoint2D instances of all internal
ITrace2D instances have changed since all points have been normalized to a value
between 0 and 1. |
protected boolean |
isDirtyScaling(int axis)
Returns true if the bounds in the given dimension of all TracePoint2D instances of all
internal ITrace2D instances have changed since all points have been normalized to a
value between 0 and 1. |
boolean |
isPaintLabels()
Returns true if labels for each chart are painted below it, false else. |
protected boolean |
isRequestedRepaint()
Returns the requestedRepaint. |
boolean |
isToolTipCoords()
Returns true if chart coordinates are drawn as tool tips. |
Iterator |
iterator()
Returns an Iterator over the contained ITrace2D instances. |
void |
paint(Graphics g)
A basic rule of a JComponent is: Never invoke this method directly. |
void |
propertyChange(PropertyChangeEvent evt)
Called from ATrace2D.setZIndex(Integer) to show that
property ITrace2D.PROPERTY_ZINDEX has changed. |
void |
removeTrace(ITrace2D points)
Removes the given instance from this Chart2D if it is contained. |
void |
repaint()
Deprecated. use setRequestedRepaint(boolean) . |
void |
repaint(int x,
int y,
int width,
int height)
Deprecated. use setRequestedRepaint(boolean) . |
void |
repaint(long tm)
Deprecated. use setRequestedRepaint(boolean) . |
void |
repaint(long tm,
int x,
int y,
int width,
int height)
Deprecated. use setRequestedRepaint(boolean) . |
void |
repaint(Rectangle r)
Deprecated. use setRequestedRepaint(boolean) . |
void |
setAxisTickPainter(IAxisTickPainter tickPainter)
Sets the axis tick painter. |
void |
setAxisX(AAxis axisX)
Set the x axis to use. |
void |
setAxisY(AAxis axisY)
Set the y axis to use. |
void |
setBackground(Color bg)
|
void |
setForeground(Color fg)
|
void |
setGridColor(Color gridclr)
Set the grid color to use. |
void |
setMinPaintLatency(int minPaintLatency)
Sets the ms to give a repaint operation time for collecting several repaint requests into one (performance vs. update speed). |
void |
setPaintLabels(boolean paintLabels)
Decide wether labels for each chart are painted below it. |
void |
setRequestedRepaint(boolean requestedRepaint)
Sets the requestedRepaint. |
void |
setSynchronizedXStartChart(Chart2D synchronizedXStartChart)
Sets the chart that will be synchronized for finding the start coordinate of this chart to draw in x dimension ( ). |
void |
setToolTipCoords(boolean toolTipCoords)
Set wether this component should display the chart coordinates as a tool tip. |
BufferedImage |
snapShot()
Returns a BufferedImage with the current width and height of the chart filled with the Chart2D's graphics that may be written to a file or OutputStream by using: ImageIO.write(java.awt.image.RenderedImage, java.lang.String, java.io.File) . |
BufferedImage |
snapShot(int width,
int height)
Returns a BufferedImage with the given width and height that is filled with tChart2D's graphics that may be written to a file or OutputStream by using: ImageIO.write(java.awt.image.RenderedImage, java.lang.String, java.io.File) . |
String |
toString()
|
TracePoint2D |
translateMousePosition(MouseEvent mouseEvent)
Returns the translation of the mouse event coordinates of the given mouse event to the value within the chart. |
Methods inherited from class javax.swing.JPanel |
---|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String[] AXIX_CONSTANT_NAMES
protected static final boolean DEBUG_SCALING
public static final boolean DEBUG_THREADING
public static final String PROPERTY_ADD_REMOVE_TRACE
constant
identifying a change of the internal set of
ITrace2D
instances.
Use this constant to register a PropertyChangeListener
with the
Chart2D
.
See the class description for property change events fired.
public static final String PROPERTY_AXIS_X
constant
identifying a change of the internal
IAxis
instance for the x dimension.
Use this constant to register a PropertyChangeListener
with the
Chart2D
.
See the class description for property change events fired.
public static final String PROPERTY_AXIS_Y
constant
identifying a change of the internal
IAxis
instance for the y dimension.
Use this constant to register a PropertyChangeListener
with the
Chart2D
.
See the class description for property change events fired.
public static final String PROPERTY_BACKGROUND_COLOR
constant
identifying a change of the background color. PropertyChangeListener
with the
Chart2D
.
The property change events for this change are constructed and fired by the superclass
Container
so this constant is just for clarification of the String that is
related to that property.
public static final String PROPERTY_FONT
The bean property constant
identifying a change of the font.
Use this constant to register a PropertyChangeListener
with the
Chart2D
.
The property change events for this change are constructed and fired by the superclass
Container
so this constant is just for clarification of the String that is
related to that property.
public static final String PROPERTY_FOREGROUND_COLOR
constant
identifying a change of the foreground color. PropertyChangeListener
with the
Chart2D
.
The property change events for this change are constructed and fired by the superclass
Container
so this constant is just for clarification of the String that is
related to that property.
public static final String PROPERTY_GRID_COLOR
constant
identifying a change of the grid color.
Use this constant to register a PropertyChangeListener
with the
Chart2D
.
public static final String PROPERTY_PAINTLABELS
constant
identifying a change of the paint labels flag.
Use this constant to register a PropertyChangeListener
with the
Chart2D
.
public static final int X
public static final int X_Y
public static final int Y
Constructor Detail |
---|
public Chart2D()
Method Detail |
---|
public final void addTrace(ITrace2D points)
ITrace2D.isVisible()
returns
true) in this chart.
This method will trigger a PropertyChangeEvent
being fired on all instances
registered by
Container.addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
(registered with String
argument PROPERTY_ADD_REMOVE_TRACE
).
points
- the trace to add.PROPERTY_ADD_REMOVE_TRACE
public JToolTip createToolTip()
createToolTip
in class JComponent
JComponent.createToolTip()
public void destroy()
This method is only of interest if you have an application that dynamically adds and removes charts. So if you use the same Chart2D object(s) during the applications lifetime there is no need to use this method.
protected void finalize() throws Throwable
The internal painter thread is stoppped.
finalize
in class Object
Throwable
- if a finalizer of a superclass fails.Object.finalize()
protected final double findMaxX()
This method is triggered when a trace fired a property change for property
with a value lower than the internal stored
maximum x.
ITrace2D.PROPERTY_MAX_X
Performance breakdown is avoided because all ITrace2D
implementations cache
their max and min values.
Note that the Chart2D
itself does not use this value for painting. It uses
AAxis.getRange()
which itself accesses this value by accessors and additionally filters
the value by it's assigned internal
ARangePolicy
.
protected final double findMaxY()
This method is triggered when a trace fired a property change for property
with a value lower than the internal stored
maximum x.
ITrace2D.PROPERTY_MAX_Y
Note that the Chart2D
itself does not use this value for painting. It uses
AAxis.getRange()
which itself accesses this value by accessors and additionally filters
the value by it's assigned internal
ARangePolicy
.
protected final double findMinX()
This method is triggered when a trace fired a property change for property
with a value lower than the internal stored
maximum x.
ITrace2D.PROPERTY_MIN_Y
Note that the Chart2D
itself does not use this value for painting. It uses
AAxis.getRange()
which itself accesses this value by accessors and additionally filters
the value by it's assigned internal
ARangePolicy
.
protected final double findMinY()
This method is triggered when a trace fired a property change for property
with a value lower than the internal stored
maximum x.
ITrace2D.PROPERTY_MIN_Y
Note that the Chart2D
itself does not use this value for painting. It uses
AAxis.getRange()
which itself accesses this value by accessors and additionally filters
the value by it's assigned internal
ARangePolicy
.
public IAxisTickPainter getAxisTickPainter()
public final IAxis getAxisX()
public final IAxis getAxisY()
public final Color getGridColor()
public final double getMaxX()
ITrace2D
instances.
ITrace2D
instances.public final double getMaxY()
ITrace2D
instances.
ITrace2D
instances.public int getMinPaintLatency()
public final double getMinX()
ITrace2D
instances.
ITrace2D
instances.getOffsetX()
public final double getMinY()
ITrace2D
instances.
ITrace2D
instances.public final double getOffsetX()
This value is not neccessarily the minimum x-value of all internal
instances. Rounding or forced bounds on the internal
ITrace2D
X -
may have an effect on this value.
AAxis
getMinX()
public Chart2D getSynchronizedXStartChart()
getXChartStart()
).
This feature is used to allow two separate charts to be painted stacked in y dimension (one below the other) that have different x start coordinates (because of different y labels that shift that value) with an equal starting x value (thus be comparable visually if their x values match).
getXChartStart()
).public String getToolTipText(MouseEvent event)
getToolTipText
in class JComponent
JComponent.getToolTipText(java.awt.event.MouseEvent)
public final Set getTraces()
Caution: the original internal set is returned. Modifications on the returned set could cause problems.
public final int getXChartEnd()
public int getXChartStart()
public final int getYChartEnd()
Pixel coordinates in awt / swing start from top and increase towards the bottom.
public int getYChartStart()
Pixel coordinates in awt / swing start from top and increase towards the bottom.
protected final boolean isDirtyScaling()
TracePoint2D
instances of all internal
ITrace2D
instances have changed since all points have been normalized to a value
between 0 and 1.
TracePoint2D
instances of all internal
ITrace2D
instances have changed since all points have been normalized to a
value between 0 and 1.protected final boolean isDirtyScaling(int axis)
TracePoint2D
instances of all
internal ITrace2D
instances have changed since all points have been normalized to a
value between 0 and 1.
axis
- one of X
or Y
.
TracePoint2D
instances of all internal
ITrace2D
instances have changed since all points have been normalized to a
value between 0 and 1.public final boolean isPaintLabels()
Returns true if labels for each chart are painted below it, false else.
protected boolean isRequestedRepaint()
public final boolean isToolTipCoords()
public final Iterator iterator()
Iterator
over the contained ITrace2D
instances.
Iterator
over the contained ITrace2D
instances.public void paint(Graphics g)
JComponent.paint(java.awt.Graphics)
for details.
If you do invoke this method you may encounter performance issues, flickering UI and even deadlocks.
paint
in class JComponent
g
- the graphics context to use.public void propertyChange(PropertyChangeEvent evt)
Called from ATrace2D.setZIndex(Integer)
to show that
property ITrace2D.PROPERTY_ZINDEX
has changed.
This class adds itself as a PropertyChangeListener
to the
ATrace2D
in method
addTrace(ITrace2D)
.
Also used for properties
,
ITrace2D.PROPERTY_MAX_X
. ITrace2D.PROPERTY_MAX_Y
and ITrace2D.PROPERTY_MIN_X
to adapt to bound changes.
ITrace2D.PROPERTY_MIN_Y
propertyChange
in interface PropertyChangeListener
evt
- the property change event that was fired.PropertyChangeListener.propertyChange(java.beans.PropertyChangeEvent)
public final void removeTrace(ITrace2D points)
Removes the given instance from this Chart2D
if it is contained.
This method will trigger a PropertyChangeEvent
being fired on all instances
registered by
Container.addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
(registered with String
argument PROPERTY_ADD_REMOVE_TRACE
).
points
- the trace to remove.PROPERTY_ADD_REMOVE_TRACE
public void repaint()
setRequestedRepaint(boolean)
.
repaint
in class Component
Component.repaint()
public void repaint(int x, int y, int width, int height)
setRequestedRepaint(boolean)
.
repaint
in class Component
Component.repaint(int, int, int, int)
public void repaint(long tm)
setRequestedRepaint(boolean)
.
repaint
in class Component
Component.repaint(long)
public void repaint(long tm, int x, int y, int width, int height)
setRequestedRepaint(boolean)
.
repaint
in class JComponent
JComponent.repaint(long, int, int, int, int)
public void repaint(Rectangle r)
setRequestedRepaint(boolean)
.
repaint
in class JComponent
JComponent.repaint(java.awt.Rectangle)
public void setAxisTickPainter(IAxisTickPainter tickPainter)
tickPainter
- The axis tick painter to set.public void setAxisX(AAxis axisX)
axisX
- The axisX to set.public void setAxisY(AAxis axisY)
axisY
- The axisY to set.public void setBackground(Color bg)
setBackground
in class JComponent
Component.setBackground(java.awt.Color)
public void setForeground(Color fg)
setForeground
in class JComponent
Component.setForeground(java.awt.Color)
public final void setGridColor(Color gridclr)
Set the grid color to use.
gridclr
- the grid color to use.public void setMinPaintLatency(int minPaintLatency)
minPaintLatency
- the setting for the ms to give a repaint operation time for collecting several
repaint requests into one (performance vs. update speed).public void setPaintLabels(boolean paintLabels)
Decide wether labels for each chart are painted below it. If set to true this will be done, else labels will be ommited.
paintLabels
- the value for paintLabels to set.public final void setRequestedRepaint(boolean requestedRepaint)
Internal method to request a repaint that guarantees that two invocations of
will always have at least have an interval of
ms.
setMinPaintLatency(int)
Methods
must not be called from application code that has to inform the UI to update the chart directly
or a performance problem may arise as java awt / swing implementation does not guarantee to
collapse several repaint requests into a single one but prefers to issue many paint invocations
causing a high CPU load in realtime scenarios (adding several 100 points per second to a
chart).
repaint()
, repaint(long)
,
repaint(Rectangle)
, repaint(int, int, int, int)
and repaint(long, int, int, int, int)
Only the internal timer may invoke the methods mentioned above.
requestedRepaint
- the requestedRepaint to set.public void setSynchronizedXStartChart(Chart2D synchronizedXStartChart)
getXChartStart()
).
This feature is used to allow two separate charts to be painted stacked in y dimension (one below the other) that have different x start coordinates (because of different y labels that shift that value) with an equal starting x value (thus be comparable visually if their x values match).
synchronizedXStartChart
- the chart that will be synchronized for finding the start coordinate of this chart
to draw in x dimension (getXChartStart()
).public final void setToolTipCoords(boolean toolTipCoords)
This turns on tool tip support (like
JComponent.setToolTipText(java.lang.String)
) if neccessary.
toolTipCoords
- The toolTipCoords to set.public BufferedImage snapShot()
ImageIO.write(java.awt.image.RenderedImage, java.lang.String, java.io.File)
.
If the width and height of this chart is zero (this happens when the chart has not been
JComponent.setVisible(boolean)
, the chart was not integrated into layout
correctly or the chart's dimenision was set to this value, a default of width 600 and height
400 will temporarily be set (syncrhonized), the image will be rendered, the old dimension will
be reset and the image will be returned.
If you want to paint offscreen images (without
displayed chart) prefer invoke snapShot(int, int)
instead.
public BufferedImage snapShot(int width, int height)
ImageIO.write(java.awt.image.RenderedImage, java.lang.String, java.io.File)
.
width
- the width of the image to create.height
- the height of the image to create.
public String toString()
toString
in class Component
Object.toString()
public TracePoint2D translateMousePosition(MouseEvent mouseEvent) throws IllegalArgumentException
Note that the mouse event has to be an event fired on this component!
mouseEvent
- a mouse event that has been fired on this component.
IllegalArgumentException
- if the given mouse event does not belong to this component.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |