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 ofIAbstractChartVisualSet
compatible with this chartVSC
- subtype ofAbstractVisualSetContainer
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 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.void
Copies the contents displayed on the chart to the clipboard.void
dispose()
Disposes the chart.javafx.scene.paint.Color
Returns the background color of the entire chart area.double
Returns the bottom margin of this chart, in pixels.javafx.scene.paint.Color
Returns the background color of this chart content area.javafx.scene.paint.Color
Returns the color of grid lines.int
Returns the width of grid lines, in pixels.double
Returns the left margin of this chart, in pixels.getTitle()
Returns the title of this chart, ornull
if the title has not been specified.javafx.scene.paint.Color
Returns the color of this chart's title.javafx.scene.text.Font
Returns the font of this chart's title.int
Returns the font size of this chart's title.double
Returns the top margin of this chart, in pixels.Returns theAbstractVisualSetContainer
currently shown on the chart, ornull
ifAbstractVisualSetContainer
has not been specifiedabstract AbstractAxis
<?> getXAxis()
Returns the X-axis of this chart.abstract AbstractAxis
<?> getYAxis()
Returns the Y-axis of this chart.javafx.scene.paint.Color
Returns the color of the zero grid line.int
Returns the width of the zero grid line, in pixels.protected void
initializeChartGroup
(javafx.scene.Group chartGroup, Chart<VS, VSC> chart) boolean
Checks if the chart is already disposed.boolean
Checks whether the grid lines are visible.boolean
Checks whether the chart is in the process of being redrawn.boolean
isShown()
Deprecated.boolean
Checks whether this chart title should be drawn.boolean
Checks whether the chart should be drawn.boolean
isVisualSetVisible
(VS visualSet) Checks whether theVisualSet
should be drawn.boolean
Checks whether the zero grid line is visible.void
redraw()
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.setGridLinesColor
(Color color) Sets the new color to the grid lines of this chart.setGridLinesColor
(javafx.scene.paint.Color color) Sets the new color to the grid lines.setGridLinesVisible
(boolean visible) Specifies whether grid lines should be drawn for this chart and redraws this chart if the visibility is changed.setGridLinesWidth
(int width) Sets the new width to the grid lines of this chart, in pixels.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 ofVisualSet
instances to be shown on the chart.setVisualSetVisible
(VS visualSet, boolean visible) Specifies whether theVisualSet
should be drawn.setZeroGridLineColor
(Color color) Sets the new color to the zero grid line of this chart.setZeroGridLineColor
(javafx.scene.paint.Color color) Sets the new color to the zero grid line of this chart.setZeroGridLineVisible
(boolean visible) Specifies whether the zero grid line should be drawn.setZeroGridLineWidth
(int width) Sets the new width to the zero grid line of this chart, in pixels.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, ornull
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
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
-
setGridLinesVisible
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
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
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
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
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
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
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
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
Sets a container ofVisualSet
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
- newAbstractVisualSetContainer
to be shown on the chart- Returns:
- reference to this object
- See Also:
-
getVisualSetContainer
Returns theAbstractVisualSetContainer
currently shown on the chart, ornull
ifAbstractVisualSetContainer
has not been specified- Returns:
- VisualSetContainer currently shown on the chart, or
null
ifAbstractVisualSetContainer
has not been specified
-
setVisualSetVisible
Specifies whether theVisualSet
should be drawn. Redraws this chart if visibility is changed.- Parameters:
visualSet
-VisualSet
for which the new visibility rule is being setvisible
- new visibility- Returns:
- reference to this object
- See Also:
-
isVisualSetVisible
Checks whether theVisualSet
should 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:
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
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
- theLabelSide
of 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
- theLabelSide
of 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
- theLabelSide
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. TheaddRedrawFinishedHandler(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.
-