Class PlotView

All Implemented Interfaces:
IFeedbackProvider, IFileDropHandler, ComponentListener, FocusListener, MouseListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, RootPaneContainer, WindowConstants

public class PlotView extends BaseView
Predefined view that displays a plot loaded from an splot JSON file.

PlotView hosts a CardLayout deck with two cards:

File drag-and-drop

Drop support for .plot.json and .splot.json files is activated in the constructor via BaseView.enableFileDrop(java.util.function.Predicate). Subclasses that need to accept additional file types should call enableFileDrop with a broader predicate and extend filesDropped(java.util.List<java.io.File>) accordingly.

Plot lifecycle

All panel swaps (open, drag-and-drop, external programmatic switch) flow through setPlotPanel(edu.cnu.mdi.splot.plot.PlotPanel), which is the single choke-point responsible for keeping the canvas reference, the edit menu, and the View menu in sync.

See Also:
  • Field Details

  • Constructor Details

    • PlotView

      public PlotView()
      Create a PlotView with the default title "sPlot".
    • PlotView

      public PlotView(Object... keyVals)
      Create a PlotView from alternating key/value property pairs.

      The view is built in four steps:

      1. A CardLayout deck is created holding the standard plot card (CARD_PLOT) and the 2-D histogram card (CARD_HISTO2D).
      2. File drag-and-drop is enabled for .plot.json and .splot.json files via BaseView.enableFileDrop(Predicate). The handler is installed once on all appropriate surfaces (canvas, viewport, and frame); it does not need to be re-installed when the plot panel is replaced by setPlotPanel(edu.cnu.mdi.splot.plot.PlotPanel).
      3. Plot and edit menus are added to the menu bar.
      4. The View menu state is synchronised with the current panel's capabilities.
      Parameters:
      keyVals - alternating PropertyUtils key/value pairs
  • Method Details

    • getViewInfo

      public AbstractViewInfo getViewInfo()
      Get an information object describing this view, used in the UI and for help.
      Overrides:
      getViewInfo in class BaseView
      Returns:
      view info, or null
    • getImageComponent

      public Component getImageComponent()
      The component that best represents this view as a static image, for screenshot/clipboard capture (see TakePicture).

      The default returns the container's drawable component, which is correct for ordinary item-based 2D views: for those, the container component already shows everything the view has to offer. Views whose visible content is not fully contained in that one component should override this. PlotView is the prototypical example: its title, legend, and axis labels live on the surrounding PlotPanel, not on the inner PlotCanvas the container exposes, so capturing the container component alone would silently drop them.

      This exists so callers that want "an image of this view" — a toolbar's camera button, a menu action, a future export feature — have one consistent, view-owned question to ask, instead of each caller re-deriving its own answer (or a shared utility like TakePicture having to special-case specific view/panel types itself).

      PlotView's title, legend, and axis labels live on _plotPanel, not on the inner PlotCanvas the container exposes, so the default (container-based) implementation would silently drop them. Returns whichever card is currently showing, so a capture taken while the 2-D histogram card is visible captures that instead of the (hidden) plot.

      Overrides:
      getImageComponent in class BaseView
      Returns:
      the component to capture as this view's image; the container's component if one is present, otherwise this view itself
    • showCard

      public void showCard(String cardName)
      Toggles between the Plot and Histo2D cards.
      Parameters:
      cardName - Use PlotView.CARD_PLOT or PlotView.CARD_HISTO2D
    • createDecoratedPlotPanel

      protected final PlotPanel createDecoratedPlotPanel(PlotCanvas canvas)
      Create a panel using this view's configured feedback policy.
    • switchToPlotPanel

      public void switchToPlotPanel(PlotPanel plotPanel)
      Switch to a different plot panel (and its canvas)
      Parameters:
      plotPanel - the new plot panel
    • getPlotCanvas

      public PlotCanvas getPlotCanvas()
      Get the plot canvas
      Returns:
      th plot canvas
    • filesDropped

      public void filesDropped(List<File> files)
      Handle plot files dropped on this view through drag-and-drop.

      Only the first file in the list is used; the filter set by BaseView.enableFileDrop(Predicate) in the constructor already guarantees every entry ends with .plot.json or .splot.json, so no second format check is required here.

      The parent directory of the dropped file is remembered (see FileDialogs.rememberDirectory(java.lang.String, java.nio.file.Path)) so that the next "Open" dialog opens in the same location.

      Specified by:
      filesDropped in interface IFileDropHandler
      Overrides:
      filesDropped in class BaseView
      Parameters:
      files - the accepted dropped files; never null, never empty