Package com.amalgamasimulation.charts
Class Chart<VS extends IAbstractChartVisualSet,VSC extends AbstractVisualSetContainer<VS>>
java.lang.Object
com.amalgamasimulation.charts.Chart<VS,VSC>
- Type Parameters:
VS- subtype ofIAbstractChartVisualSetcompatible with this chartVSC- subtype ofAbstractVisualSetContainercompatible 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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddKeyPressedHandler(Consumer<javafx.scene.input.KeyEvent> handler) Adds the action to be executed every time the key is pressed.addKeyReleasedHandler(Consumer<javafx.scene.input.KeyEvent> handler) Adds the action to be executed every time the key is released after being pressed.Adds the action to be executed every time a mouse is performing drag-exited operation.Adds the action to be executed every time a mouse is performing drag operation.Adds the action to be executed every time a mouse is performing drag-over operation.Adds the action to be executed every time a mouse is performing drag-released operation.Adds the action to be executed every time a mouse enters to any visual element borders.Adds the action to be executed every time the mouse exits the previously entered element's bounds.Adds the action to be executed every time a mouse button is pressed.Adds the action to be executed every time a mouse button is released.addMouseScrollHandler(Consumer<javafx.scene.input.ScrollEvent> handler) Adds the action to be executed every time the mouse is performing scroll operation .addRedrawFinishedHandler(Runnable handler) Adds the action to be executed every time chart redrawing is completed.addTextLabel(LabelSide labelSide, String text) Sets the label text for chart.addTextLabel(LabelSide labelSide, String text, int fontSize) Sets the label text for chart.Removes all the key pressed actions.Removes all the key released actions.Removes all the mouse drag-exited actions.Removes all the mouse drag actions.Removes all the mouse drag-over actions.Removes all the mouse drag-released actions.Removes all the mouse enter actions.Removes all the mouse exit actions.Removes all previously added mouse button press actions.Removes all the mouse button release actions.Removes all the mouse scroll actions.Removes all the chart redrawing actions.voidCopies the contents displayed on the chart to the clipboard.voiddispose()Disposes the chart.javafx.scene.paint.ColorReturns the background color of the entire chart area.doubleReturns the bottom margin of this chart, in pixels.javafx.scene.paint.ColorReturns the background color of this chart content area.doubleReturns the left margin of this chart, in pixels.getTitle()Returns the title of this chart, ornullif the title has not been specified.javafx.scene.paint.ColorReturns the color of this chart's title.javafx.scene.text.FontReturns the font of this chart's title.intReturns the font size of this chart's title.doubleReturns the top margin of this chart, in pixels.Returns theAbstractVisualSetContainercurrently shown on the chart, ornullifAbstractVisualSetContainerhas not been specifiedabstract AbstractAxis<?> getXAxis()Returns the X-axis of this chart.abstract AbstractAxis<?> getYAxis()Returns the Y-axis of this chart.protected voidinitializeChartGroup(javafx.scene.Group chartGroup, Chart<VS, VSC> chart) booleanChecks if the chart is already disposed.booleanChecks whether the chart is in the process of being redrawn.booleanChecks whether this chart title should be drawn.booleanChecks whether the chart should be drawn.booleanisVisualSetVisible(VS visualSet) Checks whether theVisualSetshould be drawn.voidredraw()Causes the chart to be redrawn.removeKeyPressedHandler(Consumer<javafx.scene.input.KeyEvent> handler) Removes the key pressed action.removeKeyReleasedHandler(Consumer<javafx.scene.input.KeyEvent> handler) Removes the key released action.Removes the mouse drag-exited action.Removes the mouse drag action.Removes the mouse drag-over action.Removes the mouse drag-released action.Removes the mouse enter action.Removes the mouse exit action.Removes the previously added mouse button press action.Removes the previously added mouse button release action.removeMouseScrollHandler(Consumer<javafx.scene.input.ScrollEvent> handler) Removes the mouse scroll action.removeRedrawFinishedHandler(Runnable handler) Removes the chart redrawing finished action.removeTextLabel(LabelSide labelSide) Removes text label for the specified label side.resizeChart(int width, int height, boolean forceResize) Updates the chart size and redraws its redraws its contents.setBackgroundColor(Color color) Sets the background color of the entire chart area.setBackgroundColor(javafx.scene.paint.Color color) Sets the background color of the entire chart area.setBottomMargin(double margin) Sets the bottom margin of this chart, in pixels.setContentBackgroundColor(Color color) Sets the background color of this chart's content area.setContentBackgroundColor(javafx.scene.paint.Color color) Sets the background color of this chart's content area.setContextMenuVisible(boolean menuVisible) Specifies whether to display the context menu on right-click on the chart.setCopyToClipboardContextMenuItemVisible(boolean copyToClipboardMenuItemVisible) Specifies whether the 'Copy to clipboard' context menu item should be enabled.setLeftMargin(double margin) Sets the left margin of this chart, in pixels.Sets the new title and redraws this chart if title is changed.setTitleColor(Color color) Sets the new color to the title of this chart.setTitleColor(javafx.scene.paint.Color color) Sets the new color to the title of this chart.setTitleFont(javafx.scene.text.Font font) Sets the font to the title.setTitleFontSize(int fontSize) Sets the font size of this chart's title.setTitleVisible(boolean visible) Specifies whether the title should be drawn.setTopMargin(double margin) Sets the top margin of this chart, in pixels.setVisibility(boolean visibility) Specifies whether the chart should be drawn.setVisualSetContainer(VSC visualSetContainer) Sets a container ofVisualSetinstances to be shown on the chart.setVisualSetVisible(VS visualSet, boolean visible) Specifies whether theVisualSetshould be drawn.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.
-
Constructor Details
-
Chart
public Chart()
-
-
Method Details
-
getChartInternal
-
initializeChartGroup
-
getXAxis
Returns the X-axis of this chart.- Returns:
- the X-axis of this chart
-
getYAxis
Returns the Y-axis of this chart.- Returns:
- the Y-axis of this chart
-
setTitle
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
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
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
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
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
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
Returns the title of this chart, ornullif the title has not been specified.- Returns:
- title of this chart, or
nullif title has not been specified
-
isTitleVisible
public boolean isTitleVisible()Checks whether this chart title should be drawn.- Returns:
trueif chart title should be drawn,falseotherwise
-
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
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
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
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
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
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
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
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
-
setVisualSetContainer
Sets a container ofVisualSetinstances to be shown on the chart. Redraws the chart to refresh its contents, visuals and other chart's components.nullis allowed in which case the chart will be shown without any data.- Parameters:
visualSetContainer- newAbstractVisualSetContainerto be shown on the chart- Returns:
- reference to this object
- See Also:
-
getVisualSetContainer
Returns theAbstractVisualSetContainercurrently shown on the chart, ornullifAbstractVisualSetContainerhas not been specified- Returns:
- VisualSetContainer currently shown on the chart, or
nullifAbstractVisualSetContainerhas not been specified
-
setVisualSetVisible
Specifies whether theVisualSetshould be drawn. Redraws this chart if visibility is changed.- Parameters:
visualSet-VisualSetfor which the new visibility rule is being setvisible- new visibility- Returns:
- reference to this object
- See Also:
-
isVisualSetVisible
Checks whether theVisualSetshould be drawn. -
setVisibility
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
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:
trueif the chart is already disposed,falseotherwise
-
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
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
Removes the previously added mouse button press action.- Parameters:
handler- removed mouse button press action- Returns:
- reference to this object
-
clearMousePressedHandlers
Removes all previously added mouse button press actions.- Returns:
- reference to this object
-
addMouseReleasedHandler
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
Removes the previously added mouse button release action.- Parameters:
handler- removed mouse button release action- Returns:
- reference to this object
-
clearMouseReleasedHandlers
Removes all the mouse button release actions.- Returns:
- reference to this object
-
addMouseDraggedHandler
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
Removes the mouse drag action.- Parameters:
handler- removed mouse drag action- Returns:
- reference to this object
-
clearMouseDraggedHandlers
Removes all the mouse drag actions.- Returns:
- reference to this object
-
addMouseDragOverHandler
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
Removes the mouse drag-over action.- Parameters:
handler- removed mouse drag-over action- Returns:
- reference to this object
-
clearMouseDragOverHandlers
Removes all the mouse drag-over actions.- Returns:
- reference to this object
-
addMouseDragReleasedHandler
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
Removes the mouse drag-released action.- Parameters:
handler- removed mouse drag-released action- Returns:
- reference to this object
-
clearMouseDragReleasedHandlers
Removes all the mouse drag-released actions.- Returns:
- reference to this object
-
addMouseDragExitedHandler
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
Removes the mouse drag-exited action.- Parameters:
handler- removed mouse drag-exited action- Returns:
- reference to this object
-
clearMouseDragExitedHandlers
Removes all the mouse drag-exited actions.- Returns:
- reference to this object
-
addMouseEnteredHandlers
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
Removes the mouse enter action.- Parameters:
handler- new mouse enter action- Returns:
- reference to this object
-
clearMouseEnteredHandlers
Removes all the mouse enter actions.- Returns:
- reference to this object
-
addMouseExitedHandler
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
Removes the mouse exit action.- Parameters:
handler- removed mouse exit action- Returns:
- reference to this object
-
clearMouseExitedHandlers
Removes all the mouse exit actions.- Returns:
- reference to this object
-
addMouseScrollHandler
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
Removes the mouse scroll action.- Parameters:
handler- removed mouse scroll action- Returns:
- reference to this object
-
clearMouseScrollHandlers
Removes all the mouse scroll actions.- Returns:
- reference to this object
-
addKeyPressedHandler
Adds the action to be executed every time the key is pressed.- Parameters:
handler- new key pressed action- Returns:
- reference to this object
-
removeKeyPressedHandler
Removes the key pressed action.- Parameters:
handler- removed key pressed action- Returns:
- reference to this object
-
clearKeyPressedHandlers
Removes all the key pressed actions.- Returns:
- reference to this object
-
addKeyReleasedHandler
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
Removes the key released action.- Parameters:
handler- removed key released action- Returns:
- reference to this object
-
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 tofalse.- Parameters:
currentZoom- new zoom factorx- new x-coordinate related to parent composite, in pixelsy- new y-coordinate related to parent composite, in pixelswidth- new chart area width, in pixelsheight- new chart area height, in pixelsforceUpdate-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
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 tofalse.- Parameters:
width- new chart area width, in pixelsheight- new chart area height, in pixelsforceResize-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
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
Removes the chart redrawing finished action.- Parameters:
handler- removed chart redrawing finished action- Returns:
- reference to this object
-
clearRedrawFinishedHandlers
Removes all the chart redrawing actions.- Returns:
- reference to this object
-
addTextLabel
Sets the label text for chart. This label is displayed above all other graphical elements.- Parameters:
labelSide- theLabelSideof chart where the corresponding label will be drawntext- the text of the label- Returns:
- reference to this object
-
addTextLabel
Sets the label text for chart. This label is displayed above all other graphical elements.- Parameters:
labelSide- theLabelSideof chart where the corresponding label will be drawntext- the text of the labelfontSize- the font size of the label- Returns:
- reference to this object
-
removeTextLabel
Removes text label for the specified label side.- Parameters:
labelSide- theLabelSideof 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. TheaddRedrawFinishedHandler(Runnable)method can be used to handle event of finishing the redrawing process.- Returns:
trueif chart is in the process of being redrawn,falseotherwise
-