Class GraphicsWindow

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants
Direct Known Subclasses:
DensityWindow, HistogramWindow, LinesWindow, Plot3DWindow, PlotWindow

public abstract class GraphicsWindow extends AuxWindow
Abstract superclass for windows doing N-dimensional plots of table data.

The basic way that plotting works is as follows. Almost all the controls visible on the GraphicsWindow do nothing except trigger the replot action getReplotListener() when their state changes, which schedules a replot to occur later on the event dispatch thread. When the replot is executed, the getPlotState() method is called which goes through all the controls and assembles a PlotState object (of a class which is probably specific to the window implementation). Only if this PlotState differs from the last gathered PlotState will any actual plotting action take place. This means that we don't worry about triggering loads of replot actions - as long as the state doesn't change materially between one and the next, they're cheap. If the state does change materially, then a new plot is required. The work done for plotting depends on the details of how the PlotState has changed - in some cases new data will be acquired (PointSelection.readPoints is called - possibly expensive), but if the data is the same as before, the plot just needs to be redrawn (usually quite fast, since the various plotting classes are written as efficiently as possible). It is therefore very important for performance reasons that you can tell whether one plot state differs from the last one. Since the PlotState is a newly created object each time, its equals() method is used - so PlotState.equals() must be written with great care. There's an assertion in this class which tests that two PlotStates gathered at the same time are equal, so you should find out if your equals() method is calling two equal states unequal. If it's calling two unequal states equal, then you'll find that the plot doesn't get updated when state changes.

Since:
26 Oct 2005
Author:
Mark Taylor
See Also:
  • Constructor Details

    • GraphicsWindow

      public GraphicsWindow(String viewName, uk.ac.starlink.ttools.plot.TablePlot plot, String[] axisNames, int naux, boolean hasLabels, ErrorModeSelectionModel[] errorModeModels, Component parent)
      Constructor. A number of main axes are defined by the axisNames array, which also defines the dimensionality. The naux variable gives a maximum number of auxiliary axes which will be managed by this window - these give extra dimensions which can be mapped to, for instance, colour changes in plotted points. If no auxiliary axes are required, supply naux=0.
      Parameters:
      viewName - name of the view window
      plot - component which draws the plot
      axisNames - array of labels by which each main axis is known
      naux - number of auxiliary axes
      errorModeModels - array of selecction models for error modes
      parent - parent window - may be used for positioning
  • Method Details

    • setVisible

      public void setVisible(boolean visible)
      Overrides:
      setVisible in class AuxWindow
    • init

      protected void init()
      Perform initialisation which can't be done in the constructor (typically because it calls potentially overridden methods).
    • getExtrasPanel

      public JComponent getExtrasPanel()
      Returns a panel into which additional window-specific control components can be added. By default it is empty.
      Returns:
      extra control panel
    • getMainRangeCount

      public int getMainRangeCount()
      Returns the number of axes whose ranges can be reset excluding any auxiliary axes.
    • setGuidePointCount

      public void setGuidePointCount(int npoint)
      Provides a hint to this window how many points it's likely to be plotting. This should be called before the window is first displayed, and may influence the default plotting style.
      Parameters:
      npoint - approximate number of data points that may be plotted
    • setPadRatio

      public void setPadRatio(double pad)
      Sets the ratio by which the data ranges calculated by the GraphicsWindow implementation of calculateRanges(uk.ac.starlink.topcat.plot.PointSelection, uk.ac.starlink.topcat.plot.Points, uk.ac.starlink.ttools.plot.PlotState) are padded.
      Parameters:
      pad - padding ratio (typically a few percent)
    • getPadRatio

      public double getPadRatio()
      Returns the ratio by which the data ranges calculated by the GraphicsWindow implememetation of calculateRanges(uk.ac.starlink.topcat.plot.PointSelection, uk.ac.starlink.topcat.plot.Points, uk.ac.starlink.ttools.plot.PlotState) are padded.
      Returns:
      padding ratio (by default a few percent)
    • getPointSelectorToolBar

      public JToolBar getPointSelectorToolBar()
      Returns the toolbar used for controls specific to the PointSelector component.
      Returns:
      point selector toolbar
    • getExportMenu

      public JMenu getExportMenu()
      Returns the menu which contains export actions.
      Returns:
      export menu
    • createMarkerStyleMenu

      public JMenu createMarkerStyleMenu(uk.ac.starlink.ttools.plot.StyleSet[] styleSets)
      Constructs and returns a menu for selecting marker styles. Selecting an item from this list resets all plotting styles in this window according to the selected StyleSet.
      Parameters:
      styleSets - style sets to be presented in the menu
      Returns:
      menu
    • createErrorModeMenu

      public JMenu createErrorModeMenu()
      Constructs and returns a menu which can be used to select error modes for this window.
      Returns:
      new error mode selection menu
    • createErrorRendererMenu

      public JMenu createErrorRendererMenu(uk.ac.starlink.ttools.plot.ErrorRenderer[] renderers)
      Constructs and returns a menu which can be used to select error styles to be imposed at once on all subsets.
      Parameters:
      renderers - full list of renderers which may be used to draw errors
    • getPointSelectors

      public PointSelectorSet getPointSelectors()
      Returns the PointSelectorSet component used by this window.
      Returns:
      point selector set
    • getDataRanges

      public uk.ac.starlink.ttools.plot.Range[] getDataRanges()
      Returns the most recently calculated data range objects. These were calculated by invocation of calculateRanges(uk.ac.starlink.topcat.plot.PointSelection, uk.ac.starlink.topcat.plot.Points, uk.ac.starlink.ttools.plot.PlotState), which probably occurred during the last data read or rescale operation. They describe the natural ranges of the data, which typically means that they defibe an N-dimensional region into which all the current data points fall.
      Returns:
      array of data ranges, one for each axis
    • getViewRanges

      public uk.ac.starlink.ttools.plot.Range[] getViewRanges()
      Returns an array of ranges which may be set to determine the actual range of visible data displayed by this plot. The dimensions should generally match those returned by getDataRanges(). The actual range of visible data will generally be got by combining the data range with the visible range on each axis. Elements of the returned array may have their states altered, but should not be replaced, since these elements are kept up to date by the editors in the axis window.
      Returns:
      array of visible ranges, one for each axis
    • getFlipModels

      public ToggleButtonModel[] getFlipModels()
      Returns an array of button models representing the inversion state for each axis. Selected state for each model indicates that that axis has been flipped.
      Returns:
      button models for flip state
    • getLogModels

      public ToggleButtonModel[] getLogModels()
      Returns an array of button models representing the log/linear state for each axis. Selected state for each model indicates that that axis is logarithmic, unselected means linear.
      Returns:
      button models for log state
    • getErrorModeModels

      public ErrorModeSelectionModel[] getErrorModeModels()
      Returns the models for selecting error modes.
      Returns:
      error mode models
    • getLegendModel

      public ToggleButtonModel getLegendModel()
      Returns the model which indicates whether the legend is visible or not.
      Returns:
      legend visibility model
    • getPoints

      public Points getPoints()
      Returns the most recently read Points object.
      Returns:
      points object
    • getStatusBox

      public Box getStatusBox()
      Returns a line suitable for putting status information into.
      Returns:
      status component
    • getAuxAxisCount

      public int getAuxAxisCount()
      Returns the total (maximum) number of auxiliary axes used by this window.
      Returns:
      maximum number of aux axes
    • getVisibleAuxAxisCount

      public int getVisibleAuxAxisCount()
      Returns the number of currently visible auxiliary axes for this window.
      Returns:
      number of visible aux axes
    • getPlot

      public uk.ac.starlink.ttools.plot.TablePlot getPlot()
      Returns the plot object for this window.
      Returns:
      plot
    • getPlotPanel

      protected abstract JComponent getPlotPanel()
      Returns the component containing the graphics output of this window. This is the component which is exported or printed etc alongside the legend which is managed by GraphicsWindow. It should therefore contain only the output data, not any user interface decoration.
      Returns:
      plot container
    • doReplot

      protected void doReplot(uk.ac.starlink.ttools.plot.PlotState state)
      Performs an actual plot.
      Parameters:
      state - plot state determining details of plot configuration
    • createPointSelector

      protected PointSelector createPointSelector()
      Returns a new PointSelector instance to be used for selecting points to be plotted.
      Returns:
      new point selector component
    • addExtraAxes

      protected AxesSelector addExtraAxes(AxesSelector axsel)
      Adds additional axes to a given AxesSelector as appropriate for this window. The returned value may or may not be the same as the input axsel object.

      This method is called by GraphicsWindow's implementation of createPointSelector().

      Parameters:
      axsel - basic axes selector
      Returns:
      axes selector containing additional auxiliary axes as appropriate
    • createStyleEditor

      protected abstract StyleEditor createStyleEditor()
      Creates a style editor suitable for this window.
      Returns:
      new style editor
    • getDefaultStyles

      public abstract uk.ac.starlink.ttools.plot.StyleSet getDefaultStyles(int npoint)
      Returns a StyleSet which can supply markers. The npoint may be used as a hint for how many points are expected to be drawn with it.
      Parameters:
      npoint - approximate number of points - use -1 for unknown
      Returns:
      style factory
    • setStyles

      public void setStyles(uk.ac.starlink.ttools.plot.StyleSet styleSet)
      Sets the style set to use for this window.
      Parameters:
      styleSet - new style set
    • getStyles

      public MutableStyleSet getStyles()
      Returns a style set suitable for use with a new PointSelector. Note this is not the same object as was set by setStyles(uk.ac.starlink.ttools.plot.StyleSet), but it is based on it - it will dispense styles from the same set, but avoid styles already dispensed to other selectors.
      Returns:
      style set suitable for a new selector
    • createPlotState

      protected uk.ac.starlink.ttools.plot.PlotState createPlotState()
      Constructs a new PlotState. This is called by getPlotState() prior to the PlotState configuration done there. Thus if a subclass wants to provide and configure a particular state (for instance one of a specialised subclass of PlotState) it can override this method to do so. The default implementation just invokes new PlotState().
      Returns:
      returns a new PlotState object ready for generic configuration
    • getPlotState

      public uk.ac.starlink.ttools.plot.PlotState getPlotState()
      Returns an object which characterises the choices the user has made in the GUI to indicate the plot that s/he wants to see.

      The GraphicsWindow implementation of this method as well as populating the state with standard information also calls PointSelection.readPoints(javax.swing.BoundedRangeModel) and calculateRanges(uk.ac.starlink.topcat.plot.PointSelection, uk.ac.starlink.topcat.plot.Points, uk.ac.starlink.ttools.plot.PlotState) if necessary.

      Returns:
      snapshot of the currently-selected plot request
    • getGridModel

      public ToggleButtonModel getGridModel()
      Returns the button model used to select whether a grid will be drawn or not.
      Returns:
      grid toggle model
    • getReplotAction

      public Action getReplotAction()
      Returns an action which can be used to force a replot of the plot.
      Returns:
      replot action
    • getRescaleAction

      public Action getRescaleAction()
      Returns an action which will recalculate data ranges, clear view ranges, and replot the data.
      Returns:
      rescale action
    • getAxisEditAction

      public Action getAxisEditAction()
      Returns an action which can be used to configure axes manually.
      Returns:
      axis configuration action
    • setMainTable

      public void setMainTable(TopcatModel tcModel)
      Sets the main table in the point selector component.
      Parameters:
      tcModel - new table
    • replot

      public void replot()
      Redraws the plot if any of the characteristics indicated by the currently-requested plot state have changed since the last time it was done. If no changes have been made, no work is done, in which case it will be cheap to call.

      This method schedules a replot on the event dispatch thread, so it may be called from any thread.

    • isLegendInteresting

      protected boolean isLegendInteresting(uk.ac.starlink.ttools.plot.PlotState state)
      Indicates whether the legend is worth showing for a given plot state.
      Parameters:
      state - plot state
      Returns:
      true iff the legend would show non-trivial information
    • getReplotListener

      protected GraphicsWindow.ReplotListener getReplotListener()
      Returns a listener which will perform a replot when any event occurs.
      Returns:
      replot listener
    • getAxisWindow

      public AxisWindow getAxisWindow()
      Returns the axis configuration window associated with this window.
      Returns:
      axis editor dialogue
    • addNewSubsets

      protected void addNewSubsets(BitSet pointsMask)
      Adds a new row subset to tables associated with this window as appropriate. The subset is based on a bit vector representing the points in this window's Points object.
      Parameters:
      pointsMask - bit vector giving included points
    • calculateRanges

      public uk.ac.starlink.ttools.plot.Range[] calculateRanges(uk.ac.starlink.ttools.plot.PlotData data, uk.ac.starlink.ttools.plot.PlotState state)
      Calculates data ranges for a given data set. The returned Range array is the one which will be returned from future calls of getDataRanges().
      Parameters:
      data - point data for the plot
      state - plot state
      Returns:
      ranges
    • getColumnIndex

      public int getColumnIndex(TableColumn tcol)
      Returns the index in the TableModel (not the TableColumnModel) of the given TableColumn.
      Parameters:
      tcol - the column whose index is to be found
      Returns:
      the index of tcol in the table model
    • dispose

      public void dispose()
      Overrides:
      dispose in class Window
    • createErrorModeModels

      public static ErrorModeSelectionModel[] createErrorModeModels(String[] axisNames)
      Creates a default set of ErrorModeSelectionModels given a list of axis names.
      Parameters:
      axisNames - array of axis names
      Returns:
      array of error model selection models, one for each axis
    • getStandardMarkStyleSets

      public static uk.ac.starlink.ttools.plot.StyleSet[] getStandardMarkStyleSets()
      Returns an array of StyleSets which dispense MarkStyle objects, suitable for general purpose scatter plots.
      Returns:
      styleset library
    • fixDefaultErrorRenderers

      public static uk.ac.starlink.ttools.plot.StyleSet[] fixDefaultErrorRenderers(uk.ac.starlink.ttools.plot.ErrorRenderer erend, uk.ac.starlink.ttools.plot.StyleSet[] styleSets)
      Utility method to adjust an array of style sets so that all its members use a given error renderer by default.
      Parameters:
      erend - desired default error renderer
      styleSets - input style set array
      Returns:
      output array of modified style sets