Class AxisPanel

    • Field Detail

      • m_Self

        protected AxisPanel m_Self
        the panel itself.
      • m_Direction

        protected Direction m_Direction
        the direction of the axis.
      • m_Orientation

        protected Orientation m_Orientation
        the orientation of the axis.
      • m_Type

        protected Type m_Type
        the type of axis.
      • m_AxisColor

        protected Color m_AxisColor
        the axis color.
      • m_AxisWidth

        protected int m_AxisWidth
        the width of the axis (for HORIZONTAL axes, this is the height, of course).
      • m_AxisName

        protected String m_AxisName
        the name of the axis.
      • m_AxisNameFont

        protected Font m_AxisNameFont
        the font for the axis name.
      • m_AxisNameCentered

        protected boolean m_AxisNameCentered
        whether the axis name is centered in the axis and not at the border.
      • m_LengthTicks

        protected int m_LengthTicks
        the length of the ticks.
      • m_PopupMenuCustomizer

        protected PopupMenuCustomizer m_PopupMenuCustomizer
        an optional customizer for the right-click popup.
      • m_NumberFormatOverride

        protected Hashtable<Type,​String> m_NumberFormatOverride
        for overriding the default number formats.
      • m_ShowGridLines

        protected boolean m_ShowGridLines
        whether to show the coordinate lines for this axis.
      • m_Visibility

        protected Visibility m_Visibility
        the visibility state of the axis.
    • Constructor Detail

      • AxisPanel

        public AxisPanel​(Direction direction,
                         Orientation orientation,
                         Type type)
        Initializes the axis, with color black and 10 ticks, width 20.
        Parameters:
        direction - the direction of the axis
        orientation - the orientation of the axis
        type - the type of axis
      • AxisPanel

        public AxisPanel​(Direction direction,
                         Orientation orientation,
                         Type type,
                         int ticks)
        Initializes the axis, with color black, width 20.
        Parameters:
        direction - the direction of the axis
        orientation - the orientation of the axis
        type - the type of axis
        ticks - the number of ticks on the axis
    • Method Detail

      • assign

        public void assign​(AxisPanel other)
        Obtains all the settings from the other panel. Does not re-use the PopupMenuCustomizer.
        Parameters:
        other - the panel to get the settings from
      • valueToDisplay

        public String valueToDisplay​(double value)
        Transforms the given value into the display (absolute, percentage, log, etc.) format.
        Parameters:
        value - the value to transform
        Returns:
        the display value
      • calculateDimensions

        protected void calculateDimensions()
        calculates and sets the preferred size of the axis.
      • setDirection

        public void setDirection​(Direction value)
        Sets the direction of the axis.
        Parameters:
        value - the direction
      • getDirection

        public Direction getDirection()
        Returns the direction of the axis.
        Returns:
        the direction
      • setOrientation

        public void setOrientation​(Orientation value)
        Sets the orientation of the axis.
        Parameters:
        value - the orientation
      • getOrientation

        public Orientation getOrientation()
        Returns the orientation of the axis.
        Returns:
        the orientation
      • setType

        public void setType​(Type value)
        Sets the type of axis.
        Parameters:
        value - the type
      • getType

        public Type getType()
        Returns the type of axis.
        Returns:
        the type
      • setAxisColor

        public void setAxisColor​(Color value)
        Sets the color of the axis.
        Parameters:
        value - the color to use
      • getAxisColor

        public Color getAxisColor()
        Returns the color of the axis.
        Returns:
        the current color
      • setTickGenerator

        public void setTickGenerator​(TickGenerator value)
        Sets tick generator to use.
        Parameters:
        value - the tick generator
      • getTickGenerator

        public TickGenerator getTickGenerator()
        Returns the current tick generator in use.
        Returns:
        the tick generator
      • setNthValueToShow

        public void setNthValueToShow​(int value)
        Sets the count of ticks a value is shown, i.e., "3" means every third tick: 1, 4, 7, ...
        Parameters:
        value - the count
      • getNthValueToShow

        public int getNthValueToShow()
        Returns the count of ticks a value is shown, i.e., "3" means every third tick: 1, 4, 7, ...
        Returns:
        the count
      • setLengthTicks

        public void setLengthTicks​(int value)
        Sets the length of ticks to display along the axis (at least 4).
        Parameters:
        value - the length of ticks
      • getLengthTicks

        public int getLengthTicks()
        Returns the length of ticks currently displayed.
        Returns:
        the legnth of ticks
      • setAxisWidth

        public void setAxisWidth​(int value)
        Sets the width of the axis (this is height for HORIZONTAL axes, of course), at least 5 pixel.
        Parameters:
        value - the new width
      • getAxisWidth

        public int getAxisWidth()
        Returns the current width of the axis.
        Returns:
        the width
      • getActualAxisWidth

        public int getActualAxisWidth()
        Returns the actual axis width, depending on the visibility.
        Returns:
        the axis width if visible, otherwise 0
      • setAxisName

        public void setAxisName​(String value)
        Sets the name of the axis, null or empty string for none.
        Parameters:
        value - the name of the axis
      • getAxisName

        public String getAxisName()
        Returns the name of the axis, null or empty string if none set.
        Returns:
        the name of the axis or null
      • setAxisNameFont

        public void setAxisNameFont​(Font value)
        Sets the font to use for the axis name.
        Parameters:
        value - the font to use
      • getAxisNameFont

        public Font getAxisNameFont()
        Returns the font being used for the axis name.
        Returns:
        the font in use
      • setAxisNameCentered

        public void setAxisNameCentered​(boolean value)
        Sets whether the axis name is centered in the axis or at the border.
        Parameters:
        value - if true then the name is centered
      • isAxisNameCentered

        public boolean isAxisNameCentered()
        Returns whether the axis name is centered in the axis or at the border.
        Returns:
        true if centered
      • setMinimum

        public void setMinimum​(double value)
        Sets the minimum to display on the axis.
        Parameters:
        value - the minimum value
      • getMinimum

        public double getMinimum()
        Returns the currently set minimum on the axis.
        Returns:
        the minimum value
      • setManualMinimum

        public void setManualMinimum​(Double value)
        Sets the manual minimum to display on the axis.
        Parameters:
        value - the minimum value, null to unset
      • getManualMinimum

        public Double getManualMinimum()
        Returns the currently set manual minimum on the axis.
        Returns:
        the minimum value, null if none set
      • getActualMinimum

        public double getActualMinimum()
        Returns the actual minimum on the axis (incl zoom/panning).
        Returns:
        the actual minimum value
      • getActualMinimumNoMargin

        public double getActualMinimumNoMargin()
        Returns the actual minimum on the axis (excl margins).
        Returns:
        the actual minimum value
      • setMaximum

        public void setMaximum​(double value)
        Sets the maximum to display on the axis.
        Parameters:
        value - the maximum value
      • getMaximum

        public double getMaximum()
        Returns the currently set maximum on the axis.
        Returns:
        the minimum value
      • setManualMaximum

        public void setManualMaximum​(Double value)
        Sets the manual maximum to display on the axis.
        Parameters:
        value - the maximum value, null to unset
      • getManualMaximum

        public Double getManualMaximum()
        Returns the currently set manual maximum on the axis.
        Returns:
        the manual maximum value, null if none set
      • getActualMaximum

        public double getActualMaximum()
        Returns the actual maximum on the axis (incl zoom/panning).
        Returns:
        the actual maximum value
      • getActualMaximumNoMargin

        public double getActualMaximumNoMargin()
        Returns the actual maximum on the axis (excl margins).
        Returns:
        the actual maximum value
      • setTopMargin

        public void setTopMargin​(double value)
        Sets the top margin factor (>= 0.0).
        Parameters:
        value - the top margin
      • getTopMargin

        public double getTopMargin()
        Returns the currently set top margin factor (>= 0.0).
        Returns:
        the top margin
      • setBottomMargin

        public void setBottomMargin​(double value)
        Sets the bottom margin factor (>= 0.0).
        Parameters:
        value - the bottom margin
      • getBottomMargin

        public double getBottomMargin()
        Returns the currently set bottom margin factor (>= 0.0).
        Returns:
        the bottom margin
      • setManualTopMargin

        public void setManualTopMargin​(Double value)
        Sets the manual top margin factor (>= 0.0 or null).
        Parameters:
        value - the top margin
      • getManualTopMargin

        public Double getManualTopMargin()
        Returns the currently set manual top margin factor (>= 0.0 or null).
        Returns:
        the top margin
      • setManualBottomMargin

        public void setManualBottomMargin​(Double value)
        Sets the manual bottom margin factor (>= 0.0 or null).
        Parameters:
        value - the bottom margin
      • getManualBottomMargin

        public Double getManualBottomMargin()
        Returns the currently set manual bottom margin factor (>= 0.0 or null).
        Returns:
        the bottom margin
      • clearPanning

        public void clearPanning()
        Clears the panning.
      • setPixelOffset

        public void setPixelOffset​(int value)
        Sets the pixel offset due to panning.
        Parameters:
        value - the offset
      • getPixelOffset

        public int getPixelOffset()
        Returns the current pixel offset.
        Returns:
        the offset
      • setNumberFormat

        public void setNumberFormat​(String value)
        Sets the pattern used for displaying the numbers on the axis.
        Parameters:
        value - the value to use
        See Also:
        DecimalFormat.applyPattern(String)
      • getNumberFormat

        public String getNumberFormat()
        Returns the pattern used for displaying the numbers on the axis.
        Returns:
        the pattern
        See Also:
        DecimalFormat.toPattern()
      • setShowGridLines

        public void setShowGridLines​(boolean value)
        Enables/disables the display of grid lines for this axis.
        Parameters:
        value - if true then the grid lines will be activated
      • getShowGridLines

        public boolean getShowGridLines()
        Returns whether the grid lines are displayed.
        Returns:
        true if the grid lines are displayed
      • getAxisModel

        public AbstractAxisModel getAxisModel()
        Returns the underlying axis model.
        Returns:
        the model
      • setVisibility

        public void setVisibility​(Visibility value)
        Sets the visibility of the axis.
        Parameters:
        value - the visibility
      • getVisibility

        public Visibility getVisibility()
        Returns the visibility of the axis.
        Returns:
        the visibility
      • canZoom

        public boolean canZoom​(double min,
                               double max)
        Checks whether we can still zoom in.
        Parameters:
        min - the minimum of the zoom
        max - the maximum of the zoom
        Returns:
        true if zoom is possible
      • pushZoom

        public void pushZoom​(double min,
                             double max)
        Adds the zoom to its internal list and updates the axis.
        Parameters:
        min - the minimum of the zoom
        max - the maximum of the zoom
      • popZoom

        public void popZoom()
        Removes the latest zoom, if available.
      • isZoomed

        public boolean isZoomed()
        Returns true if the axis is currently zoomed.
        Returns:
        true if a zoom is in place
      • clearZoom

        public void clearZoom()
        Removes all zooms.
      • getLength

        public int getLength()
        Depending on direction, either returns width (= HORIZONTAL) or height (= VERTICAL).
        Returns:
        the length of the axis
      • selectRange

        public void selectRange()
        Pops up a dialog letting the user choose the range (min/max) for the axis.
      • setRange

        public void setRange​(BaseInterval value)
        Sets the current range of the axis.
        Parameters:
        value - the new range
      • getRange

        public BaseInterval getRange()
        Returns the current range of the axis.
        Returns:
        the current range
      • copyRange

        protected void copyRange()
        Copies the range to the clipboard.
      • pasteRange

        protected void pasteRange()
        Pastes the range from the clipboard, if possible.
      • resetRange

        public void resetRange()
        Resets any manually set range for the axis.
      • selectMargins

        public void selectMargins()
        Pops up a dialog letting the user choose the margins (top/bottom) for the axis.
      • copyMargins

        protected void copyMargins()
        Copies the margins to the clipboard.
      • pasteMargins

        protected void pasteMargins()
        Pastes the margins from the clipboard, if possible.
      • resetMargins

        public void resetMargins()
        Resets any manually set margins for the axis.
      • setPopupMenuCustomizer

        public void setPopupMenuCustomizer​(PopupMenuCustomizer value)
        Sets the class to customize the right-click popup menu.
        Parameters:
        value - the customizer
      • getPopupMenuCustomizer

        public PopupMenuCustomizer getPopupMenuCustomizer()
        Returns the current customizer, can be null.
        Returns:
        the customizer
      • editTickGenerator

        protected void editTickGenerator()
        Allows the user to edit the tick generator.
      • addChangeListener

        public void addChangeListener​(ChangeListener l)
        Adds the given listener to the internal list of change listeners.
        Parameters:
        l - the listener to add
      • removeChangeListener

        public void removeChangeListener​(ChangeListener l)
        Removes the given listener from the internal list of change listeners.
        Parameters:
        l - the listener to remove
      • notifyChangeListeners

        public void notifyChangeListeners()
        Notifies all change listeners.
      • addNumberFormatOverride

        public void addNumberFormatOverride​(Type type,
                                            String format)
        Adds the format override for the specified type. If the current type is the same type as being set, then the format is automatically updated.
        Parameters:
        type - the axis model type
        format - the override
      • removeNumberFormatOverride

        public void removeNumberFormatOverride​(Type type)
        Removes the format override for the specified type. If the current type is the same type as being removed, then the format is reset to the default one.
        Parameters:
        type - the axis model type
      • hasNumberFormatOverride

        public boolean hasNumberFormatOverride​(Type type)
        Returns whether an override format is available for the specified type.
        Parameters:
        type - the axis model type
        Returns:
        true if an override format exists
      • getNumberFormatOverride

        public String getNumberFormatOverride​(Type type)
        Returns the format override for the specified type, null if non-existing.
        Parameters:
        type - the axis model type
        Returns:
        the override format, can be null
      • correctPosition

        public int correctPosition​(int pos)
        "corrects" the position for an origin at bottom-left corner instead of top-left corner, in case of a VERTICAL axis.
        Parameters:
        pos - the position to correct
        Returns:
        the corrected position
      • valueToPos

        public int valueToPos​(double value)
        Returns the position for the given value according to the settings (min and max).
        Parameters:
        value - the value to turn into a position
        Returns:
        the position
      • posToValue

        public double posToValue​(int pos)
        Returns the value for the given position according to the settings (min and max).
        Parameters:
        pos - the position on the panel
        Returns:
        the corresponding value
      • drawBar

        public void drawBar​(Graphics g)
        draws the bar.
        Parameters:
        g - the graphics context
      • isFirst

        protected boolean isFirst​(List<Tick> ticks,
                                  int i,
                                  boolean flipped,
                                  int max)
        Checks whether the tick is the first one.
        Parameters:
        ticks - all the ticks
        i - the current tick's index
        flipped - whether the axis is flipped
        max - the width/height of the panel
        Returns:
        true if first
      • isLast

        protected boolean isLast​(List<Tick> ticks,
                                 int i,
                                 boolean flipped,
                                 int max)
        Checks whether the tick is the last one.
        Parameters:
        ticks - all the ticks
        i - the current tick's index
        flipped - whether the axis is flipped
        max - the width/height of the panel
        Returns:
        true if last
      • skipLabel

        protected boolean skipLabel​(List<Tick> ticks,
                                    int i)
        Checks whether the tick is to be skipped.
        Parameters:
        ticks - all the ticks
        i - the current tick's index
        Returns:
        true if skip
      • hasOverlap

        protected boolean hasOverlap​(Tick tick1,
                                     Tick tick2)
        Checks whether there is an overlap between the labels of the two Ticks.
        Parameters:
        tick1 - the first tick
        tick2 - the second tick
        Returns:
        true if overlapping
      • drawTicks

        protected void drawTicks​(Graphics g)
        draws the ticks.
        Parameters:
        g - the graphics context
      • drawName

        protected void drawName​(Graphics g)
        draws the axis name.
        Parameters:
        g - the graphics context
      • paintComponent

        public void paintComponent​(Graphics g)
        draws the axis.
        Overrides:
        paintComponent in class JComponent
        Parameters:
        g - the graphics context
      • toString

        public String toString()
        Returns a short description of the axis.
        Overrides:
        toString in class Component
        Returns:
        the description