jsky.catalog.gui
Class BasicTablePlotter

java.lang.Object
  extended by jsky.catalog.gui.BasicTablePlotter
All Implemented Interfaces:
diva.canvas.event.LayerListener, java.util.EventListener, javax.swing.event.ChangeListener, TablePlotter

public class BasicTablePlotter
extends java.lang.Object
implements TablePlotter, diva.canvas.event.LayerListener, javax.swing.event.ChangeListener

Implements basic plotting of catalog tables on in an image window. For each row in a table query result, one or more symbols may be displayed in an image window at a position given by the row's coordinate columns.

Note: This class was previously implemented using Diva figures for catalog symbols, however this turned out to be slow for large numbers of figures, so this version handles the drawing and selection of catalog symbols directly.

Version:
$Revision: 1.3 $
Author:
Allan Brighton

Nested Class Summary
protected  class BasicTablePlotter.FigureListItem
          Local class used for SymbolListItem.figureList elements (one for each plot symbol).
protected  class BasicTablePlotter.SymbolListItem
          Local class used for TableListItem.symbolList elements (one for each plot symbol entry, for each table)
protected  class BasicTablePlotter.TableListItem
          Local class used for tableList elements (one for each table).
 
Constructor Summary
BasicTablePlotter()
          Default Constructor (Note: you need to call setCanvasGraphics() and setCoordinateConverter() before using this object).
 
Method Summary
 void addSymbolSelectionListener(SymbolSelectionListener listener)
          Add a listener for selection events on symbols
 void addTableSelectionListener(TableSelectionListener listener)
          Add a listener for selection events on tables
 boolean check(TableQueryResult table)
          Check if there is an image loaded and if so, if it supports world coordinates.
 void deselectSymbol(TableQueryResult table, int tableRow)
          Deselect the symbol corresponding to the given table row
protected  void fireSymbolSelectionEvent(TableQueryResult table, int row, boolean isSelected)
          Notify any listeners that a symbol was selected or deselected.
protected  void fireTableSelectionEvent(TableQueryResult table, int row, boolean selected)
          Notify any listeners that a table row was selected
 CanvasGraphics getCanvasGraphics()
          Return the object to use to draw catalog symbols
 NamedCoordinates getCatalogPosition(java.awt.geom.Point2D.Double p)
          If the given screen coordinates point is within a displayed catalog symbol, set it to point to the center of the symbol and return the name and coordinates (and brightness, if known) from the catalog table row.
 javax.swing.JPanel getConfigPanel(TableQueryResult table)
          Return a panel to use to configure the plot symbols for the given table.
 CoordinateConverter getCoordinateConverter()
          Return the object used to convert to screen coordinates for drwing
protected  int getCoordType(java.lang.String name)
          Return the CoordinateConverter type code for the given name.
protected  void getNorthAndEast(java.awt.geom.Point2D.Double center, double size, double ratio, double angle, java.awt.geom.Point2D.Double north, java.awt.geom.Point2D.Double east)
           
 TablePlotSymbol[] getPlotSymbolInfo(TableQueryResult table)
          Return the plot symbol info for the given table.
protected  CoordinateRadius getTableRegion(TableQueryResult table)
          Scan the given table and return an object describing the area of the sky that it covers, or null if not known.
 TableQueryResult[] getTables()
          Return an array containing the tables managed by this object.
 boolean isVisible()
          Return true if catalog symbols are visible, false if they are hidden.
protected  java.awt.Shape makeShape(TablePlotSymbol symbol, double x, double y, double size, double ratio, double angle)
          Return the Shape object for the given symbol.
 void mouseClicked(diva.canvas.event.LayerEvent e)
          Invoked when the mouse is clicked on a layer or figure.
 void mouseDragged(diva.canvas.event.LayerEvent e)
          Invoked when the mouse moves while the button is still held down.
 void mousePressed(diva.canvas.event.LayerEvent e)
          Invoked when the mouse is pressed on a layer or figure.
 void mouseReleased(diva.canvas.event.LayerEvent e)
          Invoked when the mouse is released on a layer or figure.
 void paintSymbols(java.awt.Graphics2D g2d, java.awt.geom.Rectangle2D region)
          Paint the catalog symbols using the given graphics object.
 void plot(TableQueryResult table)
          Plot the given table data.
protected  void plotRow(TableQueryResult table, int row, java.util.Vector rowVec, double x, double y, int cooSys, TablePlotSymbol symbol)
           
protected  void plotSymbol(TableQueryResult table, int row, TablePlotSymbol symbol, double x, double y, int cooSys, double radius, double ratio, double angle, java.lang.String label)
           
protected  void plotSymbols(TableQueryResult table, TablePlotSymbol[] symbols)
          Plot the table data using the given symbol descriptions.
 void removeSymbolSelectionListener(SymbolSelectionListener listener)
          Remove a listener for selection events on symbols
 void removeTableSelectionListener(TableSelectionListener listener)
          Remove a listener for selection events on tables
protected  void repaint(java.awt.Shape shape)
          Schedule a repaint of the area given by the given shape
 void replotAll()
          Recalculate the coordinates and replot all symbols after a change in the coordinate system.
protected  void rotatePoint(java.awt.geom.Point2D.Double p, java.awt.geom.Point2D.Double center, double angle)
           
 void selectSymbol(TableQueryResult table, int tableRow)
          Select the symbol corresponding to the given table row
 void selectSymbol(TableQueryResult table, int tableRow, boolean selected)
          Set the selection state of the symbol corresponding to the given table row
 void setCanvasGraphics(CanvasGraphics canvasGraphics)
          Set the object to use to draw catalog symbols
 void setCoordinateConverter(CoordinateConverter c)
          Set the object used to convert to screen coordinates for drwing
 void setPlotSymbolInfo(TableQueryResult table, TablePlotSymbol[] symbols)
          Set the plot symbol info for the given table
 void setVisible(boolean isVisible)
          If the given argument is false, hide all plot symbols managed by this object, otherwise show them again.
 void stateChanged(javax.swing.event.ChangeEvent e)
          Called when the WCS info changes
protected  boolean tableInRange(TableQueryResult table)
          Return true if the coordinates of the objects in the given table may be in a range where they can be plotted in the current image.
 void transformGraphics(java.awt.geom.AffineTransform trans)
          Transform the plot symbols using the given AffineTransform (called when the image is transformed, to keep the plot symbols up to date).
 void unplot(TableQueryResult table)
          Erase the plot of the given table data
 void unplotAll()
          Erase all plot symbols
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicTablePlotter

public BasicTablePlotter()
Default Constructor (Note: you need to call setCanvasGraphics() and setCoordinateConverter() before using this object).

Method Detail

setCanvasGraphics

public void setCanvasGraphics(CanvasGraphics canvasGraphics)
Set the object to use to draw catalog symbols

Specified by:
setCanvasGraphics in interface TablePlotter

getCanvasGraphics

public CanvasGraphics getCanvasGraphics()
Return the object to use to draw catalog symbols

Specified by:
getCanvasGraphics in interface TablePlotter

getCoordinateConverter

public CoordinateConverter getCoordinateConverter()
Return the object used to convert to screen coordinates for drwing

Specified by:
getCoordinateConverter in interface TablePlotter

setCoordinateConverter

public void setCoordinateConverter(CoordinateConverter c)
Set the object used to convert to screen coordinates for drwing

Specified by:
setCoordinateConverter in interface TablePlotter

check

public boolean check(TableQueryResult table)
Check if there is an image loaded and if so, if it supports world coordinates. If no image is loaded, try to generate a blank image for plotting.

Parameters:
table - describes the table data
Returns:
false if no suitable image could be used or generated, otherwise true

plot

public void plot(TableQueryResult table)
Plot the given table data.

Specified by:
plot in interface TablePlotter
Parameters:
table - describes the table data

stateChanged

public void stateChanged(javax.swing.event.ChangeEvent e)
Called when the WCS info changes

Specified by:
stateChanged in interface javax.swing.event.ChangeListener

getPlotSymbolInfo

public TablePlotSymbol[] getPlotSymbolInfo(TableQueryResult table)
Return the plot symbol info for the given table.

Specified by:
getPlotSymbolInfo in interface TablePlotter
Parameters:
table - object representing the catalog table
Returns:
an array of TablePlotSymbol objects, one for each plot symbol defined.

setPlotSymbolInfo

public void setPlotSymbolInfo(TableQueryResult table,
                              TablePlotSymbol[] symbols)
Set the plot symbol info for the given table

Specified by:
setPlotSymbolInfo in interface TablePlotter

plotSymbols

protected void plotSymbols(TableQueryResult table,
                           TablePlotSymbol[] symbols)
Plot the table data using the given symbol descriptions.

Parameters:
table - describes the table data
symbols - an array of objects describing the symbols to plot

plotRow

protected void plotRow(TableQueryResult table,
                       int row,
                       java.util.Vector rowVec,
                       double x,
                       double y,
                       int cooSys,
                       TablePlotSymbol symbol)

plotSymbol

protected void plotSymbol(TableQueryResult table,
                          int row,
                          TablePlotSymbol symbol,
                          double x,
                          double y,
                          int cooSys,
                          double radius,
                          double ratio,
                          double angle,
                          java.lang.String label)

getCoordType

protected int getCoordType(java.lang.String name)
Return the CoordinateConverter type code for the given name.


makeShape

protected java.awt.Shape makeShape(TablePlotSymbol symbol,
                                   double x,
                                   double y,
                                   double size,
                                   double ratio,
                                   double angle)
Return the Shape object for the given symbol.

Parameters:
symbol - an object describing the symbol
x - the X position screen coordinate
y - the Y position screen coordinate
size - the radius of the symbol in screen coordinates
ratio - the x/y ratio (ellipticity ratio) of the symbol
angle - the rotation angle

getNorthAndEast

protected void getNorthAndEast(java.awt.geom.Point2D.Double center,
                               double size,
                               double ratio,
                               double angle,
                               java.awt.geom.Point2D.Double north,
                               java.awt.geom.Point2D.Double east)

rotatePoint

protected void rotatePoint(java.awt.geom.Point2D.Double p,
                           java.awt.geom.Point2D.Double center,
                           double angle)

unplot

public void unplot(TableQueryResult table)
Erase the plot of the given table data

Specified by:
unplot in interface TablePlotter

unplotAll

public void unplotAll()
Erase all plot symbols

Specified by:
unplotAll in interface TablePlotter

replotAll

public void replotAll()
Recalculate the coordinates and replot all symbols after a change in the coordinate system.

Specified by:
replotAll in interface TablePlotter

getTables

public TableQueryResult[] getTables()
Return an array containing the tables managed by this object.

Specified by:
getTables in interface TablePlotter

repaint

protected void repaint(java.awt.Shape shape)
Schedule a repaint of the area given by the given shape


selectSymbol

public void selectSymbol(TableQueryResult table,
                         int tableRow,
                         boolean selected)
Set the selection state of the symbol corresponding to the given table row


selectSymbol

public void selectSymbol(TableQueryResult table,
                         int tableRow)
Select the symbol corresponding to the given table row

Specified by:
selectSymbol in interface TablePlotter

deselectSymbol

public void deselectSymbol(TableQueryResult table,
                           int tableRow)
Deselect the symbol corresponding to the given table row

Specified by:
deselectSymbol in interface TablePlotter

addSymbolSelectionListener

public void addSymbolSelectionListener(SymbolSelectionListener listener)
Add a listener for selection events on symbols

Specified by:
addSymbolSelectionListener in interface TablePlotter

removeSymbolSelectionListener

public void removeSymbolSelectionListener(SymbolSelectionListener listener)
Remove a listener for selection events on symbols

Specified by:
removeSymbolSelectionListener in interface TablePlotter

fireSymbolSelectionEvent

protected void fireSymbolSelectionEvent(TableQueryResult table,
                                        int row,
                                        boolean isSelected)
Notify any listeners that a symbol was selected or deselected.

Parameters:
table - the table containing the symbol
row - the row index of the selected symbol
isSelected - set to true if the symbol was selected, false if deselected

addTableSelectionListener

public void addTableSelectionListener(TableSelectionListener listener)
Add a listener for selection events on tables

Specified by:
addTableSelectionListener in interface TablePlotter

removeTableSelectionListener

public void removeTableSelectionListener(TableSelectionListener listener)
Remove a listener for selection events on tables

Specified by:
removeTableSelectionListener in interface TablePlotter

fireTableSelectionEvent

protected void fireTableSelectionEvent(TableQueryResult table,
                                       int row,
                                       boolean selected)
Notify any listeners that a table row was selected

Parameters:
table - the table containing the selected row
row - the selected row index
selected - set to true if the row was selected, false if deselected

setVisible

public void setVisible(boolean isVisible)
If the given argument is false, hide all plot symbols managed by this object, otherwise show them again.

Specified by:
setVisible in interface TablePlotter

isVisible

public boolean isVisible()
Return true if catalog symbols are visible, false if they are hidden.


getConfigPanel

public javax.swing.JPanel getConfigPanel(TableQueryResult table)
Return a panel to use to configure the plot symbols for the given table.

Specified by:
getConfigPanel in interface TablePlotter
Parameters:
table - the result of a query

paintSymbols

public void paintSymbols(java.awt.Graphics2D g2d,
                         java.awt.geom.Rectangle2D region)
Paint the catalog symbols using the given graphics object.

Specified by:
paintSymbols in interface TablePlotter
Parameters:
g2d - the graphics context
region - if not null, the region to paint

transformGraphics

public void transformGraphics(java.awt.geom.AffineTransform trans)
Transform the plot symbols using the given AffineTransform (called when the image is transformed, to keep the plot symbols up to date).

Specified by:
transformGraphics in interface TablePlotter

tableInRange

protected boolean tableInRange(TableQueryResult table)
Return true if the coordinates of the objects in the given table may be in a range where they can be plotted in the current image.


getTableRegion

protected CoordinateRadius getTableRegion(TableQueryResult table)
Scan the given table and return an object describing the area of the sky that it covers, or null if not known.


mouseDragged

public void mouseDragged(diva.canvas.event.LayerEvent e)
Invoked when the mouse moves while the button is still held down.

Specified by:
mouseDragged in interface diva.canvas.event.LayerListener

mousePressed

public void mousePressed(diva.canvas.event.LayerEvent e)
Invoked when the mouse is pressed on a layer or figure.

Specified by:
mousePressed in interface diva.canvas.event.LayerListener

mouseReleased

public void mouseReleased(diva.canvas.event.LayerEvent e)
Invoked when the mouse is released on a layer or figure.

Specified by:
mouseReleased in interface diva.canvas.event.LayerListener

mouseClicked

public void mouseClicked(diva.canvas.event.LayerEvent e)
Invoked when the mouse is clicked on a layer or figure.

Note that if a catalog symbol is selected, the event is modified, so that any other listeners will get the modified location, which is set to the center of the selected catalog symbol. This implements a kind of "snap to catalog symbol" feature for any layer listeners that are added after this instance.

Specified by:
mouseClicked in interface diva.canvas.event.LayerListener

getCatalogPosition

public NamedCoordinates getCatalogPosition(java.awt.geom.Point2D.Double p)
If the given screen coordinates point is within a displayed catalog symbol, set it to point to the center of the symbol and return the name and coordinates (and brightness, if known) from the catalog table row. Otherwise, return null and do nothing.

Specified by:
getCatalogPosition in interface TablePlotter