Class Trace2DAxisSwap

  • All Implemented Interfaces:
    ITrace2D, java.beans.PropertyChangeListener, java.io.Serializable, java.lang.Comparable<ITrace2D>, java.util.EventListener

    public class Trace2DAxisSwap
    extends java.lang.Object
    implements ITrace2D, java.lang.Comparable<ITrace2D>
    A delegator / proxy that delegates all calls to an internal constructor-given ITrace2d and swaps the data of the added Point2D instances.

    x values become y values and vice versa. Performance is bad, as unnecessary instances are created (each TracePoint2D is instantiated twice) so this instance is for debugging / testing purposes only.

    Version:
    $Revision: 1.34 $
    Author:
    Achim Westermann
    See Also:
    Serialized Form
    • Constructor Detail

      • Trace2DAxisSwap

        public Trace2DAxisSwap​(ITrace2D trace)
        Creates an instance that will swap the axis of the given delegate.

        Parameters:
        trace - the delegate instance to decorate with axis swapping.
    • Method Detail

      • addErrorBarPolicy

        public 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 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)
      • addPoint

        public boolean addPoint​(ITracePoint2D p)
        Description copied from interface: ITrace2D
        Adds the given TracePoint2D to the internal data.

        Try to pass instances of TracePoint2D to this instance instead of invoking ITrace2D.addPoint(double, double) to increase performance. Else the given point has to be copied into such an instance from the other method and delegated to this method.

        Implementations decide whether the point will be accepted or not. So they have to update the internal properties minX, maxX,maxY and minY and also care about firing property change events for those properties by method PropertyChangeSupport.firePropertyChange(java.beans.PropertyChangeEvent).

        Specified by:
        addPoint in interface ITrace2D
        Parameters:
        p - the point to add.
        Returns:
        true if the operation was successful, false else.
        See Also:
        ITrace2D.addPoint(info.monitorenter.gui.chart.ITracePoint2D)
      • 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).
      • addPropertyChangeListener

        public 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 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)
      • getColor

        public java.awt.Color getColor()
        Description copied from interface: ITrace2D
        Because the color is data common to a trace of a Chart2D it is stored here.

        On the other hand only the corresponding Chart2D may detect the same color chosen for different IChart2D instances to be displayed. Therefore it is allowed to return null. This is a message to the Chart2D to leave it the choice of the color. Then the Chart2D will chose a color not owned by another ITrace2D instance managed and assign it to the null- returning instance.

        The Chart2D will often call this method. So try to cache the value in implementation and only check on modifications of TracePoint instances or on add- invocations for changes.

        Specified by:
        getColor in interface ITrace2D
        Returns:
        The chosen java.awt.Color or null if the decision for the color should be made by the corresponding Chart2D.
        See Also:
        ITrace2D.getColor()
      • getHasErrorBars

        public 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()
      • getLabel

        public java.lang.String getLabel()
        Description copied from interface: ITrace2D
        Callback method for the Chart2D that returns a String describing the label of the ITrace2D that will be displayed below the drawing area of the Chart2D.

        This method should be implemented and finalized ASAP in the inheritance tree and rely on the property name and physicalUnits.

        Specified by:
        getLabel in interface ITrace2D
        Returns:
        a String describing the Axis being accessed.
        See Also:
        ITrace2D.getLabel()
      • getMaxSize

        public int getMaxSize()
        Description copied from interface: ITrace2D

        Returns the maximum amount of TracePoint2D instances that may be added. For implementations that limit the maximum amount this is a reasonable amount. Non-limiting implementations should return Integer.MAX_VALUE. This allows to detect the unlimitedness. Of course no implementation could store that amount of points.

        Specified by:
        getMaxSize in interface ITrace2D
        Returns:
        The maximum amount of TracePoint2D instances that may be added.
        See Also:
        ITrace2D.getMaxSize()
      • getMaxX

        public double getMaxX()
        Description copied from interface: ITrace2D
        Returns the maximum value to be displayed on the x- axis of the Chart2D. Implementations should be synchronized for multithreaded use. No exception is thrown. In case of empty data (no tracepoints) 0 should be returned, to let the Chart2D know.

        The Chart2D will often call this method. So try to cache the value in implementation and only check on modifications of TracePoint instances or on add- invocations for changes.

        Specified by:
        getMaxX in interface ITrace2D
        Returns:
        the maximum value of the internal data for the x- dimension.
        See Also:
        ITrace2D.getMaxX()
      • getMaxY

        public double getMaxY()
        Description copied from interface: ITrace2D
        Returns the maximum value to be displayed on the y- axis of the Chart2D. Implementations should be synchronized for multithreaded use. No exception is thrown. In case of empty data (no tracepoints) 0 should be returned. (watch division with zero).

        Specified by:
        getMaxY in interface ITrace2D
        Returns:
        the maximum value of the internal data for the y- dimension.
        See Also:
        ITrace2D.getMaxY()
      • getMinX

        public double getMinX()
        Description copied from interface: ITrace2D
        Returns the minimum value to be displayed on the x- axis of the Chart2D.

        Implementations should be synchronized for multithreaded use. No exception is thrown. In case of empty data (no tracepoints) 0 should be returned. (watch division with zero).

        The Chart2D will often call this method. So try to cache the value in implementation and only check on modifications of TracePoint instances or on add- invocations for changes.

        Specified by:
        getMinX in interface ITrace2D
        Returns:
        the minimum value of the internal data for the x- dimension.
        See Also:
        ITrace2D.getMinX()
      • getMinY

        public double getMinY()
        Description copied from interface: ITrace2D
        Returns the minimum value to be displayed on the y- axis of the Chart2D.

        Implementations should be synchronized for multithreaded use. No exception is thrown. In case of empty data (no tracepoints) 0 should be returned. (watch division with zero).

        The Chart2D will often call this method. So try to cache the value in implementation and only check on modifications of TracePoint instances or on add- invocations for changes.

        Specified by:
        getMinY in interface ITrace2D
        Returns:
        the minimum value of the internal data for the y- dimension.
        See Also:
        ITrace2D.getMinY()
      • getName

        public java.lang.String getName()
        Description copied from interface: ITrace2D
        Returns the name of this trace.

        Specified by:
        getName in interface ITrace2D
        Returns:
        the name of this trace.
        See Also:
        ITrace2D.getName()
      • getNearestPointEuclid

        public ITrace2D.DistancePoint getNearestPointEuclid​(double x,
                                                            double y)
        Description copied from interface: ITrace2D
        Returns the nearest point to the given normalized value coordinates of this trace in Euclid distance.

        Please note that the arguments must be normalized value coordinates like provided by a TracePoint2D.getScaledX() or the division of a pixel coordinate by the total pixel range of the chart.

        Using the Manhattan distance is much faster than Euclid distance as it only includes basic addition an absolute value for computation per point (vs. square root, addition and quadrature for Euclid distance). However the euclid distance spans a circle for the nearest points which is visually more normal for end users than the Manhattan distance which forms a rhombus and reaches far distances in only one dimension.

        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)
        Description copied from interface: ITrace2D
        Returns the nearest point to the given normalized value coordinates of this trace in Manhattan distance.

        Please note that the arguments must be normalized value coordinates like provided by a TracePoint2D.getScaledX() or the division of a pixel coordinate by the total pixel range of the chart.

        Using the Manhattan distance is much faster than Euclid distance as it only includes basic addition an absolute value for computation per point (vs. square root, addition and quadrature for Euclid distance).

        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 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 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(java.lang.String)
      • getStroke

        public java.awt.Stroke getStroke()
        Description copied from interface: ITrace2D
        Returns the Stroke that is used to render this instance.

        Specified by:
        getStroke in interface ITrace2D
        Returns:
        the Stroke that is used to render this instance.
        See Also:
        ITrace2D.getStroke()
      • getZIndex

        public 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 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()
      • iterator

        public java.util.Iterator<ITracePoint2D> iterator()
        Description copied from interface: ITrace2D
        Returns an Iterator over the internal TracePoint2D instances.

        Implementations should be synchronized. This method is meant to allow modifications of the intenal TracePoint2D instances, so the original points should be returned.

        There is no guarantee that changes made to the contained tracepoints will be reflected in the display immediately. The order the iterator returns the TracePoint2D instances decides how the Chart2D will paint the trace.

        Specified by:
        iterator in interface ITrace2D
        Returns:
        an Iterator over the internal TracePoint2D instances.
        See Also:
        ITrace2D.iterator()
      • propertyChange

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

        public boolean removePointHighlighter​(IPointPainter<?> highlighter)
        Description copied from interface: ITrace2D
        Removes the given point highlighter, if it's class is contained.

        Specified by:
        removePointHighlighter in interface ITrace2D
        Parameters:
        highlighter - the highlighter to remove.
        Returns:
        true if a point highlighter of the class of the given argument was removed.
      • setName

        public void setName​(java.lang.String name)
        Description copied from interface: ITrace2D
        Assingns a specific name to the ITrace2D which will be displayed by the Chart2D.

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

        public 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(java.lang.String, java.lang.String)
      • setPointHighlighter

        public java.util.Set<IPointPainter<?>> setPointHighlighter​(IPointPainter<?> highlighter)
        Description copied from interface: ITrace2D
        Replaces all internal point highlighters by the new one.

        Specified by:
        setPointHighlighter in interface ITrace2D
        Parameters:
        highlighter - the new sole highlighter to use.
        Returns:
        the Set<IPointPainter> that was used before or null if nothing changed.
      • setStroke

        public 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 void setVisible​(boolean visible)
        Description copied from interface: ITrace2D
        Set the visibility. If argument is false, this instance will not be rendered by a Chart2D.

        Specified by:
        setVisible in interface ITrace2D
        Parameters:
        visible - true if this trace should be painted, false else.
        See Also:
        ITrace2D.setVisible(boolean)
      • setZIndex

        public 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()
        Overrides:
        toString in class java.lang.Object
        See Also:
        Object.toString()