Class ArberChartPanel
- All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible
ArberChartPanel
High-performance Swing panel for rendering charts with multiple layers. This panel is the primary UI component of the framework.
Key Features:
- Multi-Layer Architecture: Supports overlays and multiple series (e.g., candles + indicators).
- Zero-Allocation Rendering: Optimized paint loop to minimize GC pressure.
- Smart Hit-Testing: Snapping and multi-series tooltips.
- Theming: Integrated with
ChartThemefor dark/light mode support. - Interactive Navigation: High-precision zooming and panning.
- Export & Tools: Context menu for exporting to PNG/SVG/PDF and resetting view.
- Since:
- 2024-06-01
- Version:
- 1.0.0
- Author:
- Arber Gashi
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
Fields inherited from class JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionArberChartPanel(ChartModel initialModel, ChartRenderer initialRenderer) Creates a new high-performance chart panel with an initial dataset. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLayer(ChartModel model, ChartRenderer renderer) Adds a new data series to the chart.voidvoidaddOverlay(ChartRenderer renderer) Adds an overlay renderer that uses the PRIMARY model (the first one added).voidRemoves all layers and clears the chart.voiddoLayout()voidExports the current chart view to a file.voidExports the chart to a file in the specified format via the configured export handler.intReturns the number of render layers in this chart.Returns the visibility model used by the interactive legend.getTheme()Returns the current theme of this chart panel.booleanChecks if the legend is currently visible.booleanprotected voidRender order: background fill -> grid layer -> data layers -> overlays.voidResets the zoom to fit all data.voidsetMultiColorEnabled(boolean enabled) Enables or disables multi-color mode on renderers that support it.setRenderHints(ChartRenderHints renderHints) Sets rendering hints for this panel.voidupdateUI()withAnimations(boolean enabled) Enables or disables smooth animations for zoom and pan operations.Convenience helper to dock the legend to a side.withExportHandler(ChartExportHandler handler) Sets the export handler used by export actions.withGridLayer(GridLayer gridLayer) Sets the grid layer for this chart.withLegend(boolean visible) Controls the visibility of the chart legend.withLegendConfig(LegendConfig config) Configures legend placement.withLocale(Locale locale) Sets the locale used for formatting axis labels and tooltips.Convenience helper to use overlay legend at a position.withTheme(ChartTheme theme) Sets the theme for this chart panel and propagates it to all existing renderers.withTooltips(boolean enabled) Enables or disables tooltips.withXAxisConfig(AxisConfig config) Configures the X-axis behavior and formatting.withYAxisConfig(AxisConfig config) Configures the Y-axis behavior and formatting.Methods inherited from class JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUIMethods inherited from class JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods inherited from class Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeMethods inherited from class Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Constructor Details
-
ArberChartPanel
Creates a new high-performance chart panel with an initial dataset.- Parameters:
initialModel- The primary data model to display.initialRenderer- The renderer responsible for visualizing the data.
-
-
Method Details
-
addLayer
Adds a new data series to the chart.The chart supports stacking multiple layers. Each layer consists of a data model and a renderer. Layers are drawn in the order they are added (Painter's Algorithm).
This method is safe to call on the EDT only; it triggers repainting.
- Parameters:
model- The data model containing the series data.renderer- The renderer used to visualize this specific series.
-
addOverlay
Adds an overlay renderer that uses the PRIMARY model (the first one added).This is useful for technical indicators (e.g., Moving Averages, Regression Lines) that are derived from the main dataset but require a separate rendering pass.
Overlay renderers share the primary model and are drawn as additional layers.
- Parameters:
renderer- The overlay renderer.
-
clearLayers
public void clearLayers()Removes all layers and clears the chart.Listeners are removed and the panel is repainted.
-
setMultiColorEnabled
public void setMultiColorEnabled(boolean enabled) Enables or disables multi-color mode on renderers that support it.- Parameters:
enabled- true to enable multi-color rendering
-
updateUI
-
isOptimizedDrawingEnabled
public boolean isOptimizedDrawingEnabled()- Overrides:
isOptimizedDrawingEnabledin classJComponent
-
doLayout
-
paintComponent
Render order: background fill -> grid layer -> data layers -> overlays.- Overrides:
paintComponentin classJComponent
-
withGridLayer
Sets the grid layer for this chart.- Parameters:
gridLayer- The grid layer to use (e.g.,DefaultGridLayerorMedicalGridLayer).- Returns:
- This panel for chaining.
-
getTheme
Returns the current theme of this chart panel. -
setRenderHints
Sets rendering hints for this panel. -
withTheme
Sets the theme for this chart panel and propagates it to all existing renderers.Runtime Theme Switching: This method can be called at any time to change the visual appearance dynamically (e.g., Dark ↔ Light mode). All layers will be updated immediately, and the panel will repaint.
- Parameters:
theme- The theme to apply. Must not benull.- Returns:
- This panel for chaining.
- Throws:
NullPointerException- ifthemeisnull.
-
withLocale
Sets the locale used for formatting axis labels and tooltips.- Parameters:
locale- locale to apply (null resets to JVM default)- Returns:
- this panel for chaining
-
withTooltips
Enables or disables tooltips.- Parameters:
enabled- True to enable tooltips, false to disable.- Returns:
- This panel for chaining.
-
withLegend
Controls the visibility of the chart legend.- Parameters:
visible- True to show the legend, false to hide it.- Returns:
- This panel for chaining.
-
withLegendConfig
Configures legend placement.This is the recommended API for professional applications that need either an overlay legend or a docked legend outside of the plot area.
- Parameters:
config- legend configuration (null uses defaults)- Returns:
- this panel for chaining
-
withDockedLegend
Convenience helper to dock the legend to a side.- Parameters:
side- dock side- Returns:
- this panel for chaining
-
withOverlayLegend
Convenience helper to use overlay legend at a position.- Parameters:
pos- overlay position- Returns:
- this panel for chaining
-
withAnimations
Enables or disables smooth animations for zoom and pan operations.When enabled, zoom operations will use
AnimationUtilsfor smooth eased transitions. Default istrue.- Parameters:
enabled-trueto enable animations,falsefor instant updates.- Returns:
- This panel for chaining.
-
withXAxisConfig
Configures the X-axis behavior and formatting.- Parameters:
config- axis configuration (null uses defaults)- Returns:
- this panel for chaining
-
withYAxisConfig
Configures the Y-axis behavior and formatting.- Parameters:
config- axis configuration (null uses defaults)- Returns:
- this panel for chaining
-
resetZoom
public void resetZoom()Resets the zoom to fit all data. -
export
Exports the current chart view to a file.- Parameters:
file- The output file.
-
getLayerCount
public int getLayerCount()Returns the number of render layers in this chart.- Returns:
- the number of layers
-
isLegendVisible
public boolean isLegendVisible()Checks if the legend is currently visible.- Returns:
- true if the legend is visible, false otherwise
-
exportAs
Exports the chart to a file in the specified format via the configured export handler. Supported formats: PNG, SVG, PDF.An export handler must be configured via
withExportHandler(ChartExportHandler)before calling this method.- Parameters:
format- the export format ("png", "svg", or "pdf")- Throws:
IllegalStateException- if no export handler is configured
-
withExportHandler
Sets the export handler used by export actions.- Parameters:
handler- export handler (may be null to disable exports)- Returns:
- this panel for chaining
-
addNotify
public void addNotify()- Overrides:
addNotifyin classJComponent
-
getLayerVisibilityModel
Returns the visibility model used by the interactive legend.- Returns:
- layer visibility model
-