Class MultiplotPanel

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible
Direct Known Subclasses:
DiagnosticPlotPanel, GADiagnosticPlotPanel, PlotDeck

public class MultiplotPanel extends JPanel
A Swing panel that hosts multiple PlotPanels, showing exactly one at a time.

This component is intended for "diagnostic docks" in simulation views (e.g., a network decluttering view) where you want a small gallery of predefined plots rather than arbitrary user-loaded plots.

UI model

  • A Gallery menu lists available plots; selecting an entry makes it active.
  • An optional File menu provides Save for the active plot.
  • The plot-specific Edit Plot menu (a SplotEditMenu) is rebuilt when the active plot changes.

Implementation notes

  • Uses a CardLayout so plots are added once and then switched by card name, avoiding remove/add churn.
  • All UI mutations are executed on the Swing EDT. If a caller invokes methods from a non-EDT thread (e.g., a simulation thread), the work is safely marshaled to the EDT.
  • The first plot added is automatically selected and displayed.

Threading

Public methods that mutate the UI will run on the EDT. If called off-EDT, they are queued via SwingUtilities.invokeLater(Runnable).

Author:
heddle
See Also:
  • Constructor Details

    • MultiplotPanel

      public MultiplotPanel(boolean includeFileMenu)
      Create a multi-plot panel.
      Parameters:
      includeFileMenu - if true, include a File menu with Save
    • MultiplotPanel

      protected MultiplotPanel(boolean includeFileMenu, boolean showSinglePlotGallery)
      Create a plot host with explicit single-plot Gallery behavior.

      This overload is primarily useful to unified plot hosts such as PlotDeck. Existing callers retain the historical behavior through MultiplotPanel(boolean), which always displays Gallery.

      Parameters:
      includeFileMenu - if true, include a File menu with Save
      showSinglePlotGallery - if true, display Gallery even with zero or one registered plots; if false, display it only when at least two plots are available
  • Method Details

    • addPlot

      public void addPlot(String title, PlotPanel pp)
      Add a plot panel to this multiplot panel.

      The plot is registered in the Gallery menu and placed into the CardLayout. If this is the first plot added, it becomes the active plot automatically.

      Parameters:
      title - title for the Gallery menu item (non-null)
      pp - the plot panel to add (non-null)
    • removePlot

      public void removePlot(PlotPanel pp)
      Remove a plot panel from this multiplot panel.

      If the removed plot was active, another plot is selected if available; otherwise the panel becomes empty.

      Parameters:
      pp - the plot panel to remove (non-null)
    • removeAllPlots

      public void removeAllPlots()
      Remove all plots from this multiplot panel and show an empty placeholder.

      This removes the plots from the UI (it does not call clearData()).

    • clearAllPlots

      public void clearAllPlots()
      Clear all data on all curves for all plots.

      Use with caution: this wipes the data from every plot canvas.

    • getActivePlotPanel

      public PlotPanel getActivePlotPanel()
      Get the active plot panel, or null if none.
      Returns:
      the active plot panel or null
    • getMenuBar

      public JMenuBar getMenuBar()
      Returns the menu bar owned by this plot host.

      The returned component is live. It is exposed for embedding and inspection; callers should prefer the plot-host methods over directly removing MDI-managed menus.

      Returns:
      menu bar containing File, Gallery, and active-plot edit menus
    • getPlotCount

      public int getPlotCount()
      Returns:
      number of plots currently registered with this host