Class ATrace2D

    • Field Detail

      • m_computingTraces

        protected java.util.List<ITrace2D> m_computingTraces
        The list of traces that compute their values from this trace.
      • m_maxX

        protected double m_maxX
        Cached maximum x value for performance improvement.
      • m_maxXErrorBar

        protected double m_maxXErrorBar
        Cached maximum x value with error bar extension for performance improvement.
      • m_maxY

        protected double m_maxY
        Cached maximum y value for performance improvement.
      • m_maxYErrorBar

        protected double m_maxYErrorBar
        Cached maximum y value with error bar extension for performance improvement.
      • m_minX

        protected double m_minX
        Cached minimum x value for performance improvement.
      • m_minXErrorBar

        protected double m_minXErrorBar
        Cached minimum x value with error bar extension for performance improvement.
      • m_minY

        protected double m_minY
        Cached minimum y value for performance improvement.
      • m_minYErrorBar

        protected double m_minYErrorBar
        Cached minimum y value with error bar extension for performance improvement.
      • m_name

        protected java.lang.String m_name
        The name property.
      • m_physicalUnitsX

        protected java.lang.String m_physicalUnitsX
        The physical unit property for x dimension.
      • m_physicalUnitsY

        protected java.lang.String m_physicalUnitsY
        The physical unit property for x dimension.
      • m_propertyChangeSupport

        protected java.beans.PropertyChangeSupport m_propertyChangeSupport
        The instance that add support for firing PropertyChangeEvents and maintaining PropertyChangeListeners.

      • m_renderer

        protected java.lang.Object m_renderer
        The Chart2D this trace is added to. Needed for synchronization.
    • Constructor Detail

      • ATrace2D

        public ATrace2D()
        Defcon.

    • Method Detail

      • getInstanceCount

        public static int getInstanceCount()
        Returns the instanceCount for all ATrace2D subclasses.
        Returns:
        Returns the instanceCount for all ATrace2D subclasses.
      • ensureInitialized

        protected final void ensureInitialized()
        Ensures that no deadlock due to a missing internal chart reference may occur.
        Throws:
        java.lang.IllegalStateException - if this trace is not assigned to a chart.
      • addErrorBarPolicy

        public final boolean addErrorBarPolicy​(IErrorBarPolicy<?> errorBarPolicy)
        Description copied from interface: ITrace2D
        Adds the given error bar policy to the internal set of error bar policies.

        It will be the last error bar policy to render (most forward on screen).

        Specified by:
        addErrorBarPolicy in interface ITrace2D
        Parameters:
        errorBarPolicy - the error bar policy to add for rendering this trace's error bars.
        Returns:
        true if the painter was added (same instance was not contained before).
        See Also:
        ITrace2D.addErrorBarPolicy(info.monitorenter.gui.chart.IErrorBarPolicy)
      • addPoint

        public final boolean addPoint​(double x,
                                      double y)
        Description copied from interface: ITrace2D
        Adds a trace point to the internal data.

        Warning:
        Do not call this method before this trace has been added to a chart or you will not succeed as the chart is needed to get the proper Chart2D.getTracePointProvider().

        Specified by:
        addPoint in interface ITrace2D
        Parameters:
        x - the x-value of the point to add.
        y - the y-value of the point to add.
        Returns:
        true if the operation was successful, false else.
        See Also:
        ITrace2D.addPoint(double, double)
      • addPointHighlighter

        public boolean addPointHighlighter​(IPointPainter<?> highlighter)
        Description copied from interface: ITrace2D
        Adds the given point painter to the internal set of point highlighters.

        It will be the last point painter to paint highlighting if highlighting is active.

        Specified by:
        addPointHighlighter in interface ITrace2D
        Parameters:
        highlighter - the highlighter to add for highlighting this trace.
        Returns:
        true if the highlighter was added (class of instance not contained before).
        See Also:
        ITrace2D.addPointHighlighter(info.monitorenter.gui.chart.IPointPainter)
      • addPointInternal

        protected abstract boolean addPointInternal​(ITracePoint2D p)

        Override this template method for the custom add operation that depends on the policies of the implementation.

        No property change events have to be fired by default. If this method returns true the outer logic of the calling method addPoint(ITracePoint2D) will perform bound checks for the new point and fire property changes as described in method firePointChanged(ITracePoint2D, int).

        In special cases - when additional modifications to the internal set of points take place (e.g. a further point gets removed) this method should return false (regardless whether the new point was accepted or not) and perform bound checks and fire the property changes as mentioned above "manually".

        Parameters:
        p - the point to add.
        Returns:
        true if the given point was accepted or false if not.
      • addPropertyChangeListener

        public final void addPropertyChangeListener​(java.lang.String propertyName,
                                                    java.beans.PropertyChangeListener listener)
        Description copied from interface: ITrace2D
        Registers a property change listener that will be informed about changes of the property identified by the given propertyName.

        Specified by:
        addPropertyChangeListener in interface ITrace2D
        Parameters:
        propertyName - the name of the property the listener is interested in
        listener - a listener that will only be informed if the property identified by the argument propertyName changes
        See Also:
        ITrace2D.addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
      • compareTo

        public final int compareTo​(ITrace2D o)
        Specified by:
        compareTo in interface java.lang.Comparable<ITrace2D>
        Parameters:
        o - the trace to compare to.
        Returns:
        see interface.
        See Also:
        Comparable.compareTo(java.lang.Object)
      • finalize

        protected void finalize()
                         throws java.lang.Throwable
        Decreases internal instance count by one.

        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable - if something goes wrong.
      • firePointAdded

        protected void firePointAdded​(ITracePoint2D added)
        Fire property change events related to an added point.

        A property change event for property ITrace2D.PROPERTY_TRACEPOINT with null as the old value and the new point as the new value is fired. This allows e.g. rescaling of those instances (instead of having to rescale a whole trace).

        Additionally before this property change, property change events for bounds are fired as described in method firePointChanged(ITracePoint2D, int).

        Parameters:
        added - the point that was added.
      • firePointRemoved

        protected void firePointRemoved​(ITracePoint2D removed)
        Fire property change events related to a removed point.

        A property change event for property ITrace2D.PROPERTY_TRACEPOINT with a point as the old value and null as the new value is fired. This allows e.g. rescaling of those instances (instead of having to rescale a whole trace).

        Additionally before this property change, property change events for bounds are fired as described in method firePointChanged(ITracePoint2D, int).

        Parameters:
        removed - the point that was removed.
      • firePropertyChange

        protected final void firePropertyChange​(java.lang.String property,
                                                java.lang.Object oldvalue,
                                                java.lang.Object newvalue)
        Fires a property change event to the registered listeners.

        Parameters:
        property - one of the PROPERTY_XXX constants defined in ITrace2D.
        oldvalue - the old value of the property.
        newvalue - the new value of the property.
      • getChangeListeners

        public java.util.List<javax.swing.event.ChangeListener> getChangeListeners()
        Returns a shallow copied list of the change listeners of this instance.

        Returns:
        a shallow copied list of the change listeners of this instance.
      • getColor

        public final java.awt.Color getColor()
        Get the Color this trace will be painted with.

        Specified by:
        getColor in interface ITrace2D
        Returns:
        the Color of this instance
      • getHasErrorBars

        public final boolean getHasErrorBars()
        Description copied from interface: ITrace2D
        Returns true if this trace has error bars configured.

        If this returns false, no error bars will be painted for this trace.

        Specified by:
        getHasErrorBars in interface ITrace2D
        Returns:
        true if this trace has error bars configured.
        See Also:
        ITrace2D.getHasErrorBars()
      • getMaxX

        public final double getMaxX()
        Returns the original maximum x- value ignoring the offsetX.

        Specified by:
        getMaxX in interface ITrace2D
        Returns:
        the original maximum x- value ignoring the offsetX.
      • getMaxY

        public final double getMaxY()
        Returns the original maximum y- value ignoring the offsetY.

        Specified by:
        getMaxY in interface ITrace2D
        Returns:
        the original maximum y- value ignoring the offsetY.
      • getMinX

        public final double getMinX()
        Returns the original minimum x- value ignoring the offsetX.

        Specified by:
        getMinX in interface ITrace2D
        Returns:
        the original minimum x- value ignoring the offsetX.
      • getMinY

        public final double getMinY()
        Returns the original minimum y- value ignoring the offsetY.

        Specified by:
        getMinY in interface ITrace2D
        Returns:
        the original minimum y- value ignoring the offsetY.
      • getNearestPointEuclid

        public ITrace2D.DistancePoint getNearestPointEuclid​(double x,
                                                            double y)
        Naive implementation that iterates over every point.

        Subclasses that have more insight about their internal data storage could override this with a faster implementation (e.g. if the points are kept in a sorted order a skip - strategy) could find the minimum faster.

        Specified by:
        getNearestPointEuclid in interface ITrace2D
        Parameters:
        x - the x value as a normalized value between 0 and 1.0.
        y - the x value as a normalized value between 0 and 1.0.
        Returns:
        the nearest point to the given normalized value coordinates of this trace in Euclid distance.
        See Also:
        ITrace2D.getNearestPointEuclid(double, double)
      • getNearestPointManhattan

        public ITrace2D.DistancePoint getNearestPointManhattan​(double x,
                                                               double y)
        Naive implementation that iterates over every point.

        Subclasses that have more insight about their internal data storage could override this with a faster implementation (e.g. if the points are kept in a sorted order a skip - strategy could find the minimum faster.

        Specified by:
        getNearestPointManhattan in interface ITrace2D
        Parameters:
        x - the x value as a normalized value between 0 and 1.0.
        y - the x value as a normalized value between 0 and 1.0.
        Returns:
        the nearest point to the given normalized value coordinates of this trace in Manhattan distance.
        See Also:
        ITrace2D.getNearestPointManhattan(double, double)
      • getPhysicalUnitsX

        public final java.lang.String getPhysicalUnitsX()
        Description copied from interface: ITrace2D
        Returns the physical unit string value for the x dimension.

        Specified by:
        getPhysicalUnitsX in interface ITrace2D
        Returns:
        the physical unit string value for the x dimension.
        See Also:
        ITrace2D.getPhysicalUnitsX()
      • getPhysicalUnitsY

        public final java.lang.String getPhysicalUnitsY()
        Description copied from interface: ITrace2D
        Returns the physical unit string value for the y dimension.

        Specified by:
        getPhysicalUnitsY in interface ITrace2D
        Returns:
        the physical unit string value for the y dimension.
        See Also:
        ITrace2D.getPhysicalUnitsY()
      • getPropertyChangeListeners

        public java.beans.PropertyChangeListener[] getPropertyChangeListeners​(java.lang.String property)
        Description copied from interface: ITrace2D
        Returns all property change listeners for the given property.

        Specified by:
        getPropertyChangeListeners in interface ITrace2D
        Parameters:
        property - one of the constants with the PROPERTY_ prefix defined in this class or subclasses.
        Returns:
        the property change listeners for the given property.
        See Also:
        ITrace2D.getPropertyChangeListeners(String)
      • getStroke

        public final java.awt.Stroke getStroke()
        Get the Stroke object this instance will be painted with.

        Specified by:
        getStroke in interface ITrace2D
        Returns:
        the Stroke object this ITrace2D will be painted with.
        See Also:
        ITrace2D.getStroke()
      • getZIndex

        public final java.lang.Integer getZIndex()
        Description copied from interface: ITrace2D
        The z-index defines the order in which this instance will be painted.

        A higher value will bring it more "to the front".

        Specified by:
        getZIndex in interface ITrace2D
        Returns:
        the z-index that will define the order in which this instance will be painted.
        See Also:
        ITrace2D.getZIndex()
      • isVisible

        public final boolean isVisible()
        Description copied from interface: ITrace2D
        Returns true if this instance should be rendered.

        Specified by:
        isVisible in interface ITrace2D
        Returns:
        true if this instance should be rendered.
        See Also:
        ITrace2D.isVisible()
      • maxXSearch

        protected void maxXSearch()
        Internal search for the maximum x value that is only invoked if no cached value is at hand or bounds have changed by adding new points.

        The result is assigned to the property maxX.

        See Also:
        getMaxX()
      • maxYSearch

        protected void maxYSearch()
        Internal search for the maximum y value that is only invoked if no cached value is at hand or bounds have changed by adding new points.

        The result is assigned to the property maxY.

        See Also:
        getMaxY()
      • minXSearch

        protected void minXSearch()
        Internal search for the minimum x value that is only invoked if no cached value is at hand or bounds have changed by adding new points.

        The result is assigned to the property minX.

        See Also:
        getMinX()
      • minYSearch

        protected void minYSearch()
        Internal search for the minimum y value that is only invoked if no cached value is at hand or bounds have changed by adding new points.

        The result is assigned to the property minY.

        See Also:
        getMinY()
      • propertyChange

        public void propertyChange​(java.beans.PropertyChangeEvent evt)
        Specified by:
        propertyChange in interface java.beans.PropertyChangeListener
        See Also:
        PropertyChangeListener.propertyChange(java.beans.PropertyChangeEvent)
      • removeAllPointsInternal

        protected abstract void removeAllPointsInternal()
        Override this template method for the custom remove operation that depends on the Collection used in the implementation.

        No change events have to be fired, this is done by ATrace2D.

      • removePointInternal

        protected abstract ITracePoint2D removePointInternal​(ITracePoint2D point)
        Override this template method for the custom remove operation that depends on the internal storage the implementation.

        The returned point may be the same as the given. But some "computing" traces like Trace2DArithmeticMean will internally delete a different point and return that one.

        No property change events have to be fired by default. If this method returns null the outer logic of the calling method removePoint(ITracePoint2D) will perform bound checks for the returned point and fire property changes for the properties ITrace2D.PROPERTY_MAX_X, ITrace2D.PROPERTY_MIN_X, ITrace2D.PROPERTY_MAX_Y and ITrace2D.PROPERTY_MIN_Y.

        In special cases - when additional modifications to the internal set of points take place (e.g. a further point get added) this method should return false (regardless whether the old point was really removed or not) and perform bound checks and fire the property changes as mentioned above "manually".

        Parameters:
        point - the point to remove.
        Returns:
        null if unsuccessful (and no events should be fired) or the point that actually was removed (in case different than the given one it should be somehow related to the given one).
      • setColor

        public final void setColor​(java.awt.Color color)

        Set the Color this trace will be painted with.

        Specified by:
        setColor in interface ITrace2D
        Parameters:
        color - the Color this trace will be painted with.
      • setName

        public final void setName​(java.lang.String name)
        Sets the descriptive name for this trace.

        If the given argument is null or consists of whitespaces only the lable for this trace might become invisible (depending on physical units set).

        Specified by:
        setName in interface ITrace2D
        Parameters:
        name - the descriptive name for this trace.
        See Also:
        ITrace2D.setName(java.lang.String)
      • setPhysicalUnits

        public final void setPhysicalUnits​(java.lang.String xunit,
                                           java.lang.String yunit)
        Description copied from interface: ITrace2D
        Assigns a specific String representing the physical unit to the ITrace2D (e.g. Volt, Ohm, lux, ...) which will be displayed by the Chart2D

        Specified by:
        setPhysicalUnits in interface ITrace2D
        Parameters:
        xunit - the physical unit for the x axis.
        yunit - the physical unit for the y axis.
        See Also:
        ITrace2D.setPhysicalUnits(String, String)
      • setRenderer

        public final void setRenderer​(Chart2D renderer)
        Allows the chart this instance is painted by to register itself.

        This is internally required for synchronization and re-ordering due to z-Index changes.

        Specified by:
        setRenderer in interface ITrace2D
        Parameters:
        renderer - the chart that paints this instance.
      • setStroke

        public final void setStroke​(java.awt.Stroke stroke)
        Description copied from interface: ITrace2D
        Allows to specify the rendering of the ITrace2D. This Stroke will be assigned to the Graphics2D by the rendering Chart2D when painting this instance.

        Specified by:
        setStroke in interface ITrace2D
        Parameters:
        stroke - the stroke to use for painting this trace.
        See Also:
        ITrace2D.setStroke(java.awt.Stroke)
      • setVisible

        public final void setVisible​(boolean visible)

        Set the visible property of this instance.

        Invisible ITrace2D instances (visible == false) will not be painted.

        Specified by:
        setVisible in interface ITrace2D
        Parameters:
        visible - the visible property of this instance to set.
        See Also:
        ITrace2D.setVisible(boolean)
      • setZIndex

        public final void setZIndex​(java.lang.Integer zIndex)
        Description copied from interface: ITrace2D
        Sets the internal z-index property. This decides the order in which different traces within the same Chart2D are painted.

        The higher the given value is the more this trace will be brought to front.

        The value must not be lower than ITrace2D.Z_INDEX_MIN(0) and higher than ITrace2D.ZINDEX_MAX(100).

        This might not be tested for increased performance but ignoring these bounds may result in wrong ordering of display.

        Specified by:
        setZIndex in interface ITrace2D
        Parameters:
        zIndex - the z index of this trace - the lower the value the more in front the trace will appear amongst other traces in the same chart.
        See Also:
        ITrace2D.setZIndex(java.lang.Integer)
      • showsErrorBars

        public boolean showsErrorBars()
        Description copied from interface: ITrace2D
        Tests whether error bars are painted by this trace.

        Returns true if

        Specified by:
        showsErrorBars in interface ITrace2D
        Returns:
        true if this trace renders error bars.
        See Also:
        ITrace2D.showsErrorBars()
      • toString

        public java.lang.String toString()
        Returns getName().

        Overrides:
        toString in class java.lang.Object
        Returns:
        getName().