Class ChartPanel

All Implemented Interfaces:
ImageObserver, MenuContainer, PropertyChangeListener, Serializable, EventListener, Accessible

public class ChartPanel extends JLayeredPane implements PropertyChangeListener
A decoration for Chart2D that adds various controls for a Chart2D and it's ITrace2D instances in form of popup menues.

Performance note

The context menu items register themselves with the chart to adapt their basic UI properties (font, foreground color, background color) via weak referenced instances of LayoutFactory.BasicPropertyAdaptSupport . This ensures that dropping a complete menu tree from the UI makes them garbage collectable without introduction of highly unstable and unmaintainable active memory management code. A side effect is that these listeners remain in the property change listener list of the chart unless they are finalized.

Adding and removing many traces to / from charts that are wrapped in ChartPanel without System.gc() followed by System.runFinalization() in your code will leave a huge amount of listeners for non-visible uncleaned menu items in the chart which causes a high cpu throttle for increasing the listener list.

The reason seems to be the implementation of ( EventListenerList that is used by SwingPropertyChangeSupport). It is based upon an array an grows only for the space of an additional listener by using System.arraycopy(java.lang.Object, int, java.lang.Object, int, int) (ouch, this should be changed).

Profiling a day with showed that up to 2000 dead listeners remained in the list. The cpu load increased after about 200 add / remove trace operations. Good news is that no memory leak could be detected.

If those add and remove trace operations on ChartPanel - connected charts are performed with intermediate UI action property change events on dead listeners will let them remove themselves from the listener list thus avoiding the cpu overhead. So UI / user - controlled applications will unlikely suffer from this problem.

Author:
Achim Westermann
See Also:
  • Field Details

    • m_labelPanel

      protected JPanel m_labelPanel

      An internal panel for the labels of the traces that uses a FlowLayout.

  • Constructor Details

    • ChartPanel

      public ChartPanel(Chart2D chart)
      Creates an instance that decorates the given chart with controls in form of popup menus.

      Parameters:
      chart - A configured Chart2D instance that will be displayed and controlled by this panel.
    • ChartPanel

      public ChartPanel(Chart2D chart, boolean adaptUI2Chart)
      Creates an instance that decorates the given chart with controls in form of popup menus.

      Parameters:
      chart - A configured Chart2D instance that will be displayed and controlled by this panel.
      adaptUI2Chart - if true the menu will adapt it's basic UI properties (font, foreground and background color) to the given chart.
  • Method Details