Class Chart<VS extends IAbstractChartVisualSet,VSC extends AbstractVisualSetContainer<VS>>

java.lang.Object
com.amalgamasimulation.charts.Chart<VS,VSC>
Type Parameters:
VS - subtype of IAbstractChartVisualSet compatible with this chart
VSC - subtype of AbstractVisualSetContainer compatible with this chart
Direct Known Subclasses:
AbstractBarChart, AbstractGanttChart, AbstractLineChart, HeatmapChart

public abstract class Chart<VS extends IAbstractChartVisualSet,VSC extends AbstractVisualSetContainer<VS>> extends Object
A chart is a GUI component based on JavaFX's XYChart class that can be used to conveniently draw numeric and statistical data. All charts are designed to be compatible with Eclipse RCP applications and SWT framework.
Author:
Aleksey Kirillov
  • Constructor Details

    • Chart

      public Chart()
  • Method Details

    • getChartInternal

      protected abstract com.amalgamasimulation.charts.internals.charts.ChartInternal<?,?,VS,VSC> getChartInternal()
    • initializeChartGroup

      protected void initializeChartGroup(javafx.scene.Group chartGroup, Chart<VS,VSC> chart)
    • getXAxis

      public abstract AbstractAxis<?> getXAxis()
      Returns the X-axis of this chart.
      Returns:
      the X-axis of this chart
    • getYAxis

      public abstract AbstractAxis<?> getYAxis()
      Returns the Y-axis of this chart.
      Returns:
      the Y-axis of this chart
    • setTitle

      public Chart<VS,VSC> setTitle(String title)
      Sets the new title and redraws this chart if title is changed.
      Parameters:
      title - new chart's title
      Returns:
      reference to this object
      See Also:
    • setTitleVisible

      public Chart<VS,VSC> setTitleVisible(boolean visible)
      Specifies whether the title should be drawn. Redraws this chart if visibility is changed.
      Parameters:
      visible - new title visibility
      Returns:
      reference to this object
      See Also:
    • setTitleFont

      public Chart<VS,VSC> setTitleFont(javafx.scene.text.Font font)
      Sets the font to the title. Redraws this chart if the font is changed.
      Parameters:
      font - new title font
      Returns:
      reference to this object
      See Also:
    • setTitleFontSize

      public Chart<VS,VSC> setTitleFontSize(int fontSize)
      Sets the font size of this chart's title. Redraws this chart if font size is changed.
      Parameters:
      fontSize - new title font size
      Returns:
      reference to this object
      See Also:
    • setTitleColor

      public Chart<VS,VSC> setTitleColor(Color color)
      Sets the new color to the title of this chart. Redraws this chart if color is changed.
      Parameters:
      color - new title color
      Returns:
      reference to this object
      See Also:
    • setTitleColor

      public Chart<VS,VSC> setTitleColor(javafx.scene.paint.Color color)
      Sets the new color to the title of this chart. Redraws this chart if color is changed.
      Parameters:
      color - new title color
      Returns:
      reference to this object
      See Also:
    • getTitle

      public String getTitle()
      Returns the title of this chart, or null if the title has not been specified.
      Returns:
      title of this chart, or null if title has not been specified
    • isTitleVisible

      public boolean isTitleVisible()
      Checks whether this chart title should be drawn.
      Returns:
      true if chart title should be drawn, false otherwise
    • getTitleFont

      public javafx.scene.text.Font getTitleFont()
      Returns the font of this chart's title.
      Returns:
      the font of this chart's title
    • getTitleFontSize

      public int getTitleFontSize()
      Returns the font size of this chart's title.
      Returns:
      the font size of this chart's title
    • getTitleColor

      public javafx.scene.paint.Color getTitleColor()
      Returns the color of this chart's title.
      Returns:
      the color of this chart's title
    • setBackgroundColor

      public Chart<VS,VSC> setBackgroundColor(Color color)
      Sets the background color of the entire chart area. Transparent and semi-transparent colors are allowed. Redraws this chart if the color is changed.
      Parameters:
      color - new background color of the chart area
      Returns:
      reference to this object
      See Also:
    • setBackgroundColor

      public Chart<VS,VSC> setBackgroundColor(javafx.scene.paint.Color color)
      Sets the background color of the entire chart area. Transparent and semi-transparent colors are allowed. Redraws this chart if the color is changed.
      Parameters:
      color - new background color of the chart area
      Returns:
      reference to this object
      See Also:
    • setContentBackgroundColor

      public Chart<VS,VSC> setContentBackgroundColor(Color color)
      Sets the background color of this chart's content area. Transparent and semi-transparent colors are allowed. Redraws this chart if the color is changed.
      Parameters:
      color - new background color of the content area
      Returns:
      reference to this object
      See Also:
    • setContentBackgroundColor

      public Chart<VS,VSC> setContentBackgroundColor(javafx.scene.paint.Color color)
      Sets the background color of this chart's content area. Transparent and semi-transparent colors are allowed. Redraws this chart if the color is changed.
      Parameters:
      color - new background color of the content area
      Returns:
      reference to this object
      See Also:
    • getBackgroundColor

      public javafx.scene.paint.Color getBackgroundColor()
      Returns the background color of the entire chart area.
      Returns:
      the background color of the entire chart area
    • getContentBackgroundColor

      public javafx.scene.paint.Color getContentBackgroundColor()
      Returns the background color of this chart content area.
    • setTopMargin

      public Chart<VS,VSC> setTopMargin(double margin)
      Sets the top margin of this chart, in pixels. Top margin is the vertical distance between top border of the chart and content area of the chart. Redraws this chart after setting the new value.
      Parameters:
      margin - top margin of this chart, in pixels
      Returns:
      reference to this object
      See Also:
    • setBottomMargin

      public Chart<VS,VSC> setBottomMargin(double margin)
      Sets the bottom margin of this chart, in pixels. Bottom margin is the vertical distance between bottom border of the chart and content area of the chart. Redraws this chart after setting the new value.
      Parameters:
      margin - bottom margin of this chart, in pixels
      Returns:
      reference to this object
      See Also:
    • setLeftMargin

      public Chart<VS,VSC> setLeftMargin(double margin)
      Sets the left margin of this chart, in pixels. Left margin is the horizontal distance between left border of the chart and content area of the chart. Redraws this chart after setting the new value.
      Parameters:
      margin - left margin of this chart, in pixels
      Returns:
      reference to this object
      See Also:
    • getTopMargin

      public double getTopMargin()
      Returns the top margin of this chart, in pixels.
      Returns:
      the top margin of this chart, in pixels
    • getBottomMargin

      public double getBottomMargin()
      Returns the bottom margin of this chart, in pixels.
      Returns:
      the bottom margin of this chart, in pixels
    • getLeftMargin

      public double getLeftMargin()
      Returns the left margin of this chart, in pixels.
      Returns:
      the left margin of this chart, in pixels
    • setGridLinesVisible

      public Chart<VS,VSC> setGridLinesVisible(boolean visible)
      Specifies whether grid lines should be drawn for this chart and redraws this chart if the visibility is changed. Redraws this chart if visibility is changed.
      Parameters:
      visible - true if grid lines should be drawn, false otherwise
      Returns:
      reference to this object
      See Also:
    • setGridLinesColor

      public Chart<VS,VSC> setGridLinesColor(Color color)
      Sets the new color to the grid lines of this chart. Transparent and semi-transparent colors are allowed. Redraws this chart if color is changed.
      Parameters:
      color - new grid line color
      Returns:
      reference to this object
      See Also:
    • setGridLinesColor

      public Chart<VS,VSC> setGridLinesColor(javafx.scene.paint.Color color)
      Sets the new color to the grid lines. Transparent and semi-transparent colors are allowed. Redraws this chart if color is changed.
      Parameters:
      color - new grid line color
      Returns:
      reference to this object
      See Also:
    • setGridLinesWidth

      public Chart<VS,VSC> setGridLinesWidth(int width)
      Sets the new width to the grid lines of this chart, in pixels. Redraws this chart if width is changed.
      Parameters:
      width - new grid lines width, in pixels
      Returns:
      reference to this object
      See Also:
    • setZeroGridLineVisible

      public Chart<VS,VSC> setZeroGridLineVisible(boolean visible)
      Specifies whether the zero grid line should be drawn. Redraws this chart if the visibility is changed.
      Parameters:
      visible - new zero grid line visibility
      Returns:
      reference to this object
      See Also:
    • setZeroGridLineColor

      public Chart<VS,VSC> setZeroGridLineColor(Color color)
      Sets the new color to the zero grid line of this chart. Redraws this chart if color is changed.
      Parameters:
      color - new zero grid line color
      Returns:
      reference to this object
      See Also:
    • setZeroGridLineColor

      public Chart<VS,VSC> setZeroGridLineColor(javafx.scene.paint.Color color)
      Sets the new color to the zero grid line of this chart. Redraws this chart if color is changed.
      Parameters:
      color - new zero grid line color
      Returns:
      reference to this object
      See Also:
    • setZeroGridLineWidth

      public Chart<VS,VSC> setZeroGridLineWidth(int width)
      Sets the new width to the zero grid line of this chart, in pixels. Redraws this chart if width is changed.
      Parameters:
      width - new zero grid line width, in pixels
      Returns:
      reference to this object
      See Also:
    • isGridLinesVisible

      public boolean isGridLinesVisible()
      Checks whether the grid lines are visible.
      Returns:
      true if grid line are visible, false otherwise
    • getGridLinesColor

      public javafx.scene.paint.Color getGridLinesColor()
      Returns the color of grid lines.
      Returns:
      the color of grid lines
    • getGridLinesWidth

      public int getGridLinesWidth()
      Returns the width of grid lines, in pixels.
      Returns:
      the width of grid lines, in pixels
    • isZeroGridLineVisible

      public boolean isZeroGridLineVisible()
      Checks whether the zero grid line is visible.
      Returns:
      true if zero grid line is visible, false otherwise
    • getZeroGridLineColor

      public javafx.scene.paint.Color getZeroGridLineColor()
      Returns the color of the zero grid line.
      Returns:
      the color of the zero grid line
    • getZeroGridLineWidth

      public int getZeroGridLineWidth()
      Returns the width of the zero grid line, in pixels.
      Returns:
      the width of the zero grid line, in pixels
    • setVisualSetContainer

      public Chart<VS,VSC> setVisualSetContainer(VSC visualSetContainer)
      Sets a container of VisualSet instances to be shown on the chart. Redraws the chart to refresh its contents, visuals and other chart's components. null is allowed in which case the chart will be shown without any data.
      Parameters:
      visualSetContainer - new AbstractVisualSetContainer to be shown on the chart
      Returns:
      reference to this object
      See Also:
    • getVisualSetContainer

      public VSC getVisualSetContainer()
      Returns the AbstractVisualSetContainer currently shown on the chart, or null if AbstractVisualSetContainer has not been specified
      Returns:
      VisualSetContainer currently shown on the chart, or null if AbstractVisualSetContainer has not been specified
    • setVisualSetVisible

      public Chart<VS,VSC> setVisualSetVisible(VS visualSet, boolean visible)
      Specifies whether the VisualSet should be drawn. Redraws this chart if visibility is changed.
      Parameters:
      visualSet - VisualSet for which the new visibility rule is being set
      visible - new visibility
      Returns:
      reference to this object
      See Also:
    • isVisualSetVisible

      public boolean isVisualSetVisible(VS visualSet)
      Checks whether the VisualSet should be drawn.
      Parameters:
      visualSet - VisualSet for which the drawn rule is being checked
      Returns:
      true if the VisualSet should be drawn
    • setVisibility

      public Chart<VS,VSC> setVisibility(boolean visibility)
      Specifies whether the chart should be drawn.
      Parameters:
      visibility - new chart visibility
      Returns:
      reference to this object
    • isVisible

      public boolean isVisible()
      Checks whether the chart should be drawn.
      Returns:
      true if the chart should be drawn
    • setContextMenuVisible

      public Chart<VS,VSC> setContextMenuVisible(boolean menuVisible)
      Specifies whether to display the context menu on right-click on the chart.
      Parameters:
      menuVisible - new context menu visibility
      Returns:
      reference to this object
    • setCopyToClipboardContextMenuItemVisible

      public Chart<VS,VSC> setCopyToClipboardContextMenuItemVisible(boolean copyToClipboardMenuItemVisible)
      Specifies whether the 'Copy to clipboard' context menu item should be enabled. True by default.
      Parameters:
      copyToClipboardMenuItemVisible - new 'copy to clipboard' context menu item visibility
      Returns:
      reference to this object
    • redraw

      public void redraw()
      Causes the chart to be redrawn. Recalculates the contents of the displayed data and redraws all visuals, axes and appearance of the chart accordingly.
    • dispose

      public void dispose()
      Disposes the chart. Must be called to release all resources allocated for the chart. After calling this method, the chart can no longer be used. Attempts to use disposed charts will cause undefined behavior.
    • isDisposed

      public boolean isDisposed()
      Checks if the chart is already disposed.
      Returns:
      true if the chart is already disposed, false otherwise
    • copyToClipboard

      public void copyToClipboard()
      Copies the contents displayed on the chart to the clipboard. This method copies the full content including items not displayed in the currently displayed range. This method uses the clipboard defined by the operating system.
    • addMousePressedHandler

      public Chart<VS,VSC> addMousePressedHandler(Consumer<MouseListenerContext> handler)
      Adds the action to be executed every time a mouse button is pressed.
      Parameters:
      handler - new mouse button pressed action
      Returns:
      reference to this object
    • removeMousePressedHandler

      public Chart<VS,VSC> removeMousePressedHandler(Consumer<MouseListenerContext> handler)
      Removes the previously added mouse button press action.
      Parameters:
      handler - removed mouse button press action
      Returns:
      reference to this object
    • clearMousePressedHandlers

      public Chart<VS,VSC> clearMousePressedHandlers()
      Removes all previously added mouse button press actions.
      Returns:
      reference to this object
    • addMouseReleasedHandler

      public Chart<VS,VSC> addMouseReleasedHandler(Consumer<MouseListenerContext> handler)
      Adds the action to be executed every time a mouse button is released.
      Parameters:
      handler - new mouse button release action
      Returns:
      reference to this object
    • removeMouseReleasedHandler

      public Chart<VS,VSC> removeMouseReleasedHandler(Consumer<MouseListenerContext> handler)
      Removes the previously added mouse button release action.
      Parameters:
      handler - removed mouse button release action
      Returns:
      reference to this object
    • clearMouseReleasedHandlers

      public Chart<VS,VSC> clearMouseReleasedHandlers()
      Removes all the mouse button release actions.
      Returns:
      reference to this object
    • addMouseDraggedHandler

      public Chart<VS,VSC> addMouseDraggedHandler(Consumer<MouseListenerContext> handler)
      Adds the action to be executed every time a mouse is performing drag operation.
      Parameters:
      handler - new mouse drag action
      Returns:
      reference to this object
    • removeMouseDraggedHandler

      public Chart<VS,VSC> removeMouseDraggedHandler(Consumer<MouseListenerContext> handler)
      Removes the mouse drag action.
      Parameters:
      handler - removed mouse drag action
      Returns:
      reference to this object
    • clearMouseDraggedHandlers

      public Chart<VS,VSC> clearMouseDraggedHandlers()
      Removes all the mouse drag actions.
      Returns:
      reference to this object
    • addMouseDragOverHandler

      public Chart<VS,VSC> addMouseDragOverHandler(Consumer<MouseListenerContext> handler)
      Adds the action to be executed every time a mouse is performing drag-over operation.
      Parameters:
      handler - new mouse drag-over action
      Returns:
      reference to this object
    • removeMouseDragOverHandler

      public Chart<VS,VSC> removeMouseDragOverHandler(Consumer<MouseListenerContext> handler)
      Removes the mouse drag-over action.
      Parameters:
      handler - removed mouse drag-over action
      Returns:
      reference to this object
    • clearMouseDragOverHandlers

      public Chart<VS,VSC> clearMouseDragOverHandlers()
      Removes all the mouse drag-over actions.
      Returns:
      reference to this object
    • addMouseDragReleasedHandler

      public Chart<VS,VSC> addMouseDragReleasedHandler(Consumer<MouseListenerContext> handler)
      Adds the action to be executed every time a mouse is performing drag-released operation.
      Parameters:
      handler - new mouse drag-released action
      Returns:
      reference to this object
    • removeMouseDragReleasedHandler

      public Chart<VS,VSC> removeMouseDragReleasedHandler(Consumer<MouseListenerContext> handler)
      Removes the mouse drag-released action.
      Parameters:
      handler - removed mouse drag-released action
      Returns:
      reference to this object
    • clearMouseDragReleasedHandlers

      public Chart<VS,VSC> clearMouseDragReleasedHandlers()
      Removes all the mouse drag-released actions.
      Returns:
      reference to this object
    • addMouseDragExitedHandler

      public Chart<VS,VSC> addMouseDragExitedHandler(Consumer<MouseListenerContext> handler)
      Adds the action to be executed every time a mouse is performing drag-exited operation.
      Parameters:
      handler - new mouse drag-exited action
      Returns:
      reference to this object
    • removeMouseDragExitedHandler

      public Chart<VS,VSC> removeMouseDragExitedHandler(Consumer<MouseListenerContext> handler)
      Removes the mouse drag-exited action.
      Parameters:
      handler - removed mouse drag-exited action
      Returns:
      reference to this object
    • clearMouseDragExitedHandlers

      public Chart<VS,VSC> clearMouseDragExitedHandlers()
      Removes all the mouse drag-exited actions.
      Returns:
      reference to this object
    • addMouseEnteredHandlers

      public Chart<VS,VSC> addMouseEnteredHandlers(Consumer<MouseListenerContext> handler)
      Adds the action to be executed every time a mouse enters to any visual element borders.
      Parameters:
      handler - new mouse enter action
      Returns:
      reference to this object
    • removeMouseEnteredHandler

      public Chart<VS,VSC> removeMouseEnteredHandler(Consumer<MouseListenerContext> handler)
      Removes the mouse enter action.
      Parameters:
      handler - new mouse enter action
      Returns:
      reference to this object
    • clearMouseEnteredHandlers

      public Chart<VS,VSC> clearMouseEnteredHandlers()
      Removes all the mouse enter actions.
      Returns:
      reference to this object
    • addMouseExitedHandler

      public Chart<VS,VSC> addMouseExitedHandler(Consumer<MouseListenerContext> handler)
      Adds the action to be executed every time the mouse exits the previously entered element's bounds.
      Parameters:
      handler - new mouse exit action
      Returns:
      reference to this object
    • removeMouseExitedHandler

      public Chart<VS,VSC> removeMouseExitedHandler(Consumer<MouseListenerContext> handler)
      Removes the mouse exit action.
      Parameters:
      handler - removed mouse exit action
      Returns:
      reference to this object
    • clearMouseExitedHandlers

      public Chart<VS,VSC> clearMouseExitedHandlers()
      Removes all the mouse exit actions.
      Returns:
      reference to this object
    • addMouseScrollHandler

      public Chart<VS,VSC> addMouseScrollHandler(Consumer<javafx.scene.input.ScrollEvent> handler)
      Adds the action to be executed every time the mouse is performing scroll operation .
      Parameters:
      handler - new mouse scroll action
      Returns:
      reference to this object
    • removeMouseScrollHandler

      public Chart<VS,VSC> removeMouseScrollHandler(Consumer<javafx.scene.input.ScrollEvent> handler)
      Removes the mouse scroll action.
      Parameters:
      handler - removed mouse scroll action
      Returns:
      reference to this object
    • clearMouseScrollHandlers

      public Chart<VS,VSC> clearMouseScrollHandlers()
      Removes all the mouse scroll actions.
      Returns:
      reference to this object
    • addKeyPressedHandler

      public Chart<VS,VSC> addKeyPressedHandler(Consumer<javafx.scene.input.KeyEvent> handler)
      Adds the action to be executed every time the key is pressed.
      Parameters:
      handler - new key pressed action
      Returns:
      reference to this object
    • removeKeyPressedHandler

      public Chart<VS,VSC> removeKeyPressedHandler(Consumer<javafx.scene.input.KeyEvent> handler)
      Removes the key pressed action.
      Parameters:
      handler - removed key pressed action
      Returns:
      reference to this object
    • clearKeyPressedHandlers

      public Chart<VS,VSC> clearKeyPressedHandlers()
      Removes all the key pressed actions.
      Returns:
      reference to this object
    • addKeyReleasedHandler

      public Chart<VS,VSC> addKeyReleasedHandler(Consumer<javafx.scene.input.KeyEvent> handler)
      Adds the action to be executed every time the key is released after being pressed.
      Parameters:
      handler - new key released action
      Returns:
      reference to this object
    • removeKeyReleasedHandler

      public Chart<VS,VSC> removeKeyReleasedHandler(Consumer<javafx.scene.input.KeyEvent> handler)
      Removes the key released action.
      Parameters:
      handler - removed key released action
      Returns:
      reference to this object
    • clearKeyReleasedHandlers

      public Chart<VS,VSC> clearKeyReleasedHandlers()
      Removes all the key released actions.
      Returns:
      reference to this object
    • updateSize

      public Chart<VS,VSC> updateSize(double currentZoom, int x, int y, int width, int height, boolean forceUpdate)
      Updates the location and size of the chart and redraws its contents. Does nothing if none of the method parameters has been changed and forceUpdate parameter is set to false.
      Parameters:
      currentZoom - new zoom factor
      x - new x-coordinate related to parent composite, in pixels
      y - new y-coordinate related to parent composite, in pixels
      width - new chart area width, in pixels
      height - new chart area height, in pixels
      forceUpdate - true: the chart will be unconditionally redrawn; false: the chart will be redrawn only if at least one of the other parameters is changed
      Returns:
      reference to this object
      See Also:
    • resizeChart

      public Chart<VS,VSC> resizeChart(int width, int height, boolean forceResize)
      Updates the chart size and redraws its redraws its contents. Does nothing if none of the method parameters has been changed and forceUpdate parameter is set to false.
      Parameters:
      width - new chart area width, in pixels
      height - new chart area height, in pixels
      forceResize - true: the chart will be unconditionally redrawn; false: the chart will be redrawn only if at least one of the other parameters is changed
      Returns:
      reference to this object
      See Also:
    • addRedrawFinishedHandler

      public Chart<VS,VSC> addRedrawFinishedHandler(Runnable handler)
      Adds the action to be executed every time chart redrawing is completed. Note that all chart redrawing operations are performed in a separate thread.
      Parameters:
      handler - new chart redrawing finished action
      Returns:
      reference to this object
    • removeRedrawFinishedHandler

      public Chart<VS,VSC> removeRedrawFinishedHandler(Runnable handler)
      Removes the chart redrawing finished action.
      Parameters:
      handler - removed chart redrawing finished action
      Returns:
      reference to this object
    • clearRedrawFinishedHandlers

      public Chart<VS,VSC> clearRedrawFinishedHandlers()
      Removes all the chart redrawing actions.
      Returns:
      reference to this object
    • addTextLabel

      public Chart<VS,VSC> addTextLabel(LabelSide labelSide, String text)
      Sets the label text for chart. This label is displayed above all other graphical elements.
      Parameters:
      labelSide - the LabelSide of chart where the corresponding label will be drawn
      text - the text of the label
      Returns:
      reference to this object
    • addTextLabel

      public Chart<VS,VSC> addTextLabel(LabelSide labelSide, String text, int fontSize)
      Sets the label text for chart. This label is displayed above all other graphical elements.
      Parameters:
      labelSide - the LabelSide of chart where the corresponding label will be drawn
      text - the text of the label
      fontSize - the font size of the label
      Returns:
      reference to this object
    • removeTextLabel

      public Chart<VS,VSC> removeTextLabel(LabelSide labelSide)
      Removes text label for the specified label side.
      Parameters:
      labelSide - the LabelSide of chart where the corresponding text label is drawn
      Returns:
      reference to this object
    • isRedrawInProgress

      public boolean isRedrawInProgress()
      Checks whether the chart is in the process of being redrawn. All chart redrawing operations are performed in a separate thread, so the chart provides this method to determine whether an update operation is currently being performed. The addRedrawFinishedHandler(Runnable) method can be used to handle event of finishing the redrawing process.
      Returns:
      true if chart is in the process of being redrawn, false otherwise
    • isShown

      @Deprecated public boolean isShown()
      Deprecated.