uk.ac.starlink.table.gui
Class AbstractTableLoadDialog

java.lang.Object
  extended byuk.ac.starlink.table.gui.AbstractTableLoadDialog
All Implemented Interfaces:
TableLoadDialog
Direct Known Subclasses:
BasicTableLoadDialog, MultiTableLoadDialog

public abstract class AbstractTableLoadDialog
extends Object
implements TableLoadDialog

Skeleton implementation of a TableLoadDialog. Concrete subclasses should implement the abstract methods submitLoad(javax.swing.JDialog, uk.ac.starlink.table.StarTableFactory, java.lang.String, uk.ac.starlink.table.gui.TableConsumer) and cancelLoad().

Subclasses are encouraged to override the JComponent.setEnabled(boolean) method to en/disable child components which ought not to be active while a load is actually taking place. The overriding implementation ought to call super.setEnabled.

Since:
8 Oct 2009

Constructor Summary
AbstractTableLoadDialog(String name, String description)
          Constructor.
 
Method Summary
static IOException asIOException(Throwable th)
          Converts an exception to an IOException, probably by wrapping it in one.
protected abstract  void cancelLoad()
          Should interrupt any current load action, so that any pending load which is not complete should avoid passing tables to the consumer in the future, and preferably any work in progress should be stopped.
protected  JDialog createDialog(Component parent)
          Constructs a dialogue based on the component returned by createQueryPanel(); that component forms the main part of the dialogue window, with an OK and Cancel button shown as well.
protected abstract  Component createQueryPanel()
          Returns the component which contains all the implementation-specific GUI components, including query controls etc.
protected  Action getCancelAction()
          Returns the action associated with hitting the Cancel dialogue button.
 String getDescription()
          Description of this dialogue.
 Icon getIcon()
          Icon associated with this dialogue.
 String getName()
          Name of this dialogue.
protected  Action getOkAction()
          Returns the action associated with hitting the OK dialogue button.
protected  JProgressBar getProgessBar()
          Returns the progress bar at the bottom of the dialogue window.
 Component getQueryPanel()
          Returns the lazily-constructed query panel.
protected  boolean isActive(JDialog dialog)
          Indicates whether the given dialogue is currently being displayed to the user containing this component.
protected  void setBusy(boolean busy)
          Gives visible indication (including disabling components) that this component is active or not.
protected  void setFormatModel(ComboBoxModel formatModel)
          Installs a table format selector intot this dialogue.
 void setIcon(Icon icon)
          Sets the icon to associate with this dialogue.
 void setIconUrl(URL iconUrl)
          Sets the icon to associate with this dialogue by specifying its URL.
 boolean showLoadDialog(Component parent, StarTableFactory factory, ComboBoxModel formatModel, TableConsumer consumer)
          Presents the user with a dialogue which may be used to specify a table to load.
protected abstract  void submitLoad(JDialog dialog, StarTableFactory tfact, String format, TableConsumer consumer)
          Should feed a table or tables to the given consuemer based on the current state of this component.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface uk.ac.starlink.table.gui.TableLoadDialog
isAvailable
 

Constructor Detail

AbstractTableLoadDialog

public AbstractTableLoadDialog(String name,
                               String description)
Constructor.

Parameters:
name - dialogue name (typically used as text of a button)
description - dialogue description (typically used as tooltip text)
Method Detail

getName

public String getName()
Description copied from interface: TableLoadDialog
Name of this dialogue. This will typically be used as the text of a button (Action.NAME) which invokes showLoadDialog.

Specified by:
getName in interface TableLoadDialog
Returns:
name

getDescription

public String getDescription()
Description copied from interface: TableLoadDialog
Description of this dialogue. This will typically be used as the tooltip text of a button (Action.SHORT_DESCRIPTION) which invokes showLoadDialog

Specified by:
getDescription in interface TableLoadDialog
Returns:
short description

getIcon

public Icon getIcon()
Description copied from interface: TableLoadDialog
Icon associated with this dialogue. A size of 24x24 pixels is preferred. Null may be returned if no icon is available.

Specified by:
getIcon in interface TableLoadDialog
Returns:
icon

setIcon

public void setIcon(Icon icon)
Sets the icon to associate with this dialogue.


setIconUrl

public void setIconUrl(URL iconUrl)
Sets the icon to associate with this dialogue by specifying its URL. If a null URL is given, the icon is set null.

Parameters:
iconUrl - URL of gif, png or jpeg icon

submitLoad

protected abstract void submitLoad(JDialog dialog,
                                   StarTableFactory tfact,
                                   String format,
                                   TableConsumer consumer)
                            throws Exception
Should feed a table or tables to the given consuemer based on the current state of this component. This method is invoked when the OK action is selected by the user.

Parameters:
dialog - dialogue currently containing this component
tfact - table factory to use for generating tables
format - selected table format; it may or may not be appropriate to ignore this hint
consumer - destination for loaded table or tables
Throws:
Exception

cancelLoad

protected abstract void cancelLoad()
Should interrupt any current load action, so that any pending load which is not complete should avoid passing tables to the consumer in the future, and preferably any work in progress should be stopped.


createQueryPanel

protected abstract Component createQueryPanel()
Returns the component which contains all the implementation-specific GUI components, including query controls etc. Only called once.

Returns:
returns the component containing query controls

getQueryPanel

public Component getQueryPanel()
Returns the lazily-constructed query panel.

Returns:
query panel

showLoadDialog

public boolean showLoadDialog(Component parent,
                              StarTableFactory factory,
                              ComboBoxModel formatModel,
                              TableConsumer consumer)
Description copied from interface: TableLoadDialog
Presents the user with a dialogue which may be used to specify a table to load. This method should return true if an attempt will be made to load a table, and false if it will not (for instance if the user hit a Cancel button).

In the event that true is returned, the implementation of this method should ensure that notification of the table load attempt should be made to the consumer argument using the defined TableConsumer methods. The purpose of doing it like this (rather than just returning a StarTable from this method) is so that the table loading, which may be time-consuming, can be done in a thread other than the event dispatch thread on which this method will have been called. The LoadWorker class is provided to assist with this; the usual idiom for performing the load from the event dispatch thread within the implementation of this method looks like this:

     new LoadWorker( tableConsumer, tableId ) {
         protected StarTable attemptLoad() throws IOException {
             return tableFactory.makeStarTable( ... );
         }
     }.invoke();
 

Error conditions during the course of the user interaction by this method should in general be dealt with by informing the user (e.g. with a popup) and permitting another attempt. Some sort of cancel button should be provided which should trigger return with a false result.

The formatModel argument may be used to determine or set the format to be used for interpreting tables. Its entries are Strings, and in general the selected one should be passed as the handler argument to one of factory's makeStarTable methods. The dialogue may wish to allow the user to modify the selection by presenting a JComboBox based on this model. A suitable model can be obtained using TableLoadChooser.makeFormatBoxModel(uk.ac.starlink.table.StarTableFactory).

Specified by:
showLoadDialog in interface TableLoadDialog
Parameters:
parent - parent window
factory - factory which may be used for table creation
formatModel - comboBoxModel
consumer - object which can do something with the loaded table
Returns:
true if an attempt will be made to load a table

createDialog

protected JDialog createDialog(Component parent)
Constructs a dialogue based on the component returned by createQueryPanel(); that component forms the main part of the dialogue window, with an OK and Cancel button shown as well. This method may be overridden by subclasses to customise the dialogue's appearance.

Parameters:
parent - component
Returns:
modal dialogue

setFormatModel

protected void setFormatModel(ComboBoxModel formatModel)
Installs a table format selector intot this dialogue. If it makes sense for a concrete dialogue implementation to display format selection, it should override this method in such a way as to present the format model to the user for selection (presumably by setting it as the model of a visible JComboBox).

The default implementation does nothing (suitable for classes which can't make sense of varying table formats).

Parameters:
formatModel - selector model to install

getOkAction

protected Action getOkAction()
Returns the action associated with hitting the OK dialogue button.

Returns:
OK action

getCancelAction

protected Action getCancelAction()
Returns the action associated with hitting the Cancel dialogue button.

Returns:
Cancel action

getProgessBar

protected JProgressBar getProgessBar()
Returns the progress bar at the bottom of the dialogue window.


setBusy

protected void setBusy(boolean busy)
Gives visible indication (including disabling components) that this component is active or not.

Parameters:
busy - whether we're busy

isActive

protected boolean isActive(JDialog dialog)
Indicates whether the given dialogue is currently being displayed to the user containing this component.

Parameters:
dialog - dialog window to test
Returns:
true iff dialog is being displayed

asIOException

public static IOException asIOException(Throwable th)
Converts an exception to an IOException, probably by wrapping it in one. This utility method can be used for wrapping up an exception of some other kind if it needs to be thrown in TableSupplier.getTable.

Parameters:
th - base throwable
Returns:
IOException based on th

Copyright © 2004 CLRC: Central Laboratory of the Research Councils. All rights reserved.