Skip to content

Commit

Permalink
topcat: acquire metadata for VizieR table in CDS xmatch window
Browse files Browse the repository at this point in the history
Retrieve the metadata from the Xmatch service and display it when
the CDS table is selected.  Improve window cosmetics also.
  • Loading branch information
mbtaylor authored and mmpcn committed Nov 27, 2014
1 parent 63ec0b0 commit 9fa6473
Show file tree
Hide file tree
Showing 3 changed files with 325 additions and 47 deletions.
193 changes: 168 additions & 25 deletions topcat/src/main/uk/ac/starlink/topcat/join/CdsTableSelector.java
@@ -1,20 +1,26 @@
package uk.ac.starlink.topcat.join;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import uk.ac.starlink.table.gui.LabelledComponentStack;
import uk.ac.starlink.topcat.Downloader;
import uk.ac.starlink.topcat.TopcatUtils;
import uk.ac.starlink.ttools.cone.CdsUploadMatcher;
import uk.ac.starlink.ttools.cone.CdsUploadMatcher.VizierMeta;

/**
* Component that allows the user to select table names for use with
Expand All @@ -27,8 +33,16 @@
*/
public class CdsTableSelector extends JPanel {

private final JLabel label_;
private final JLabel selectorLabel_;
private final JComboBox nameSelector_;
private final VizierMetaDownloader metaDownloader_;
private final JTextField nameField_;
private final JTextField aliasField_;
private final JTextField descField_;
private final JTextField nrowField_;
private final ExecutorService metaExecutor_;
private String tableName_;
private Future<?> metaFuture_;

private static final Downloader<String[]> aliasDownloader_ =
createAliasDownloader();
Expand All @@ -45,7 +59,7 @@ public CdsTableSelector() {
nameSelector_.setSelectedItem( null );

/* Populate with vizier aliases. */
nameSelector_.addItem( "SIMBAD" );
nameSelector_.addItem( CdsUploadMatcher.SIMBAD_NAME );
if ( aliasDownloader_.isComplete() ) {
addAliases( aliasDownloader_.getData() );
}
Expand All @@ -63,29 +77,42 @@ public void run() {
aliasLoader.setDaemon( true );
aliasLoader.start();
}
label_ = new JLabel( "VizieR Table Name: " );
nameSelector_.addItemListener( new ItemListener() {
public void itemStateChanged( ItemEvent evt ) {
updateTableName();
}
} );
selectorLabel_ = new JLabel( "VizieR Table ID/Alias: " );

/* Place selector and annotaion. */
/* Selector line. */
JComponent selectorLine = Box.createHorizontalBox();
selectorLine.add( label_ );
selectorLine.add( selectorLabel_ );
selectorLine.add( nameSelector_ );
selectorLine.add( Box.createHorizontalStrut( 5 ) );
selectorLine.add( aliasDownloader_.createMonitorComponent() );

/* Table metadata. */
LabelledComponentStack stack = new LabelledComponentStack();
nameField_ = createMetaField();
stack.addLine( "ID", nameField_ );
aliasField_ = createMetaField();
stack.addLine( "Alias", aliasField_ );
descField_ = createMetaField();
stack.addLine( "Description", descField_ );
nrowField_ = createMetaField();
stack.addLine( "Row Count", nrowField_ );
JComponent infoLine = Box.createHorizontalBox();
JLabel infoLabel =
new JLabel( "Select alias or use VizieR ID like "
+ "\"II/246/out\"" ) {
protected void paintComponent( Graphics g ) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
super.paintComponent( g2 );
}
};
Font font = new Font( "DialogInput", Font.ITALIC, 10 );
infoLabel.setFont( font );
infoLine.add( Box.createHorizontalGlue() );
infoLine.add( infoLabel );
metaDownloader_ = new VizierMetaDownloader();
metaExecutor_ = Executors.newSingleThreadExecutor();
infoLine.add( stack );
infoLine.add( Box.createHorizontalStrut( 5 ) );
JComponent metaMonBox = Box.createVerticalBox();
metaMonBox.add( metaDownloader_.createMonitorComponent() );
metaMonBox.add( Box.createVerticalGlue() );
infoLine.add( metaMonBox );

/* Initialise and place components. */
updateTableName();
JComponent main = Box.createVerticalBox();
add( main, BorderLayout.CENTER );
main.add( selectorLine );
Expand All @@ -99,14 +126,73 @@ protected void paintComponent( Graphics g ) {
* @return currently selected table name
*/
public String getTableName() {
return (String) nameSelector_.getSelectedItem();
return tableName_;
}

@Override
public void setEnabled( boolean isEnabled ) {
super.setEnabled( isEnabled );
nameSelector_.setEnabled( isEnabled );
label_.setEnabled( isEnabled );
selectorLabel_.setEnabled( isEnabled );
}

/**
* Invoked when the selected table name may have changed.
* Updates the display accordingly.
* Must be invoked from the Event Dispatch Thread.
*/
private void updateTableName() {
String tableName = (String) nameSelector_.getSelectedItem();
tableName_ = tableName;
metaDownloader_.setTableName( tableName );
if ( tableName != null ) {
if ( metaDownloader_.isComplete() ) {
setMetadata( metaDownloader_.getData() );
}
else {
if ( metaFuture_ != null ) {
metaFuture_.cancel( true );
}
metaFuture_ = metaExecutor_.submit( new Runnable() {
public void run() {
final VizierMeta meta = metaDownloader_.waitForData();
SwingUtilities.invokeLater( new Runnable() {
public void run() {
setMetadata( meta );
}
} );
}
} );
}
}
}

/**
* Updates the display to show a given table metadata object.
*
* @param meta metadata to display
*/
private void setMetadata( VizierMeta meta ) {
String name = null;
String alias = null;
String description = null;
Long nrow = null;
if ( meta != null ) {
name = meta.getName();
alias = meta.getPrettyName();
description = meta.getDescription();
nrow = meta.getRowCount();
if ( alias != null && alias.equals( name ) ) {
alias = null;
}
}
setMetaField( nameField_, name );
setMetaField( aliasField_, alias );
setMetaField( descField_, description );
setMetaField( nrowField_,
nrow == null
? null
: TopcatUtils.formatLong( nrow.longValue() ) );
}

/**
Expand All @@ -122,6 +208,29 @@ private void addAliases( String[] aliases ) {
}
}

/**
* Returns a new component that can display a line of text.
*
* @return text-bearing component
*/
private static JTextField createMetaField() {
JTextField textField = new JTextField();
textField.setEditable( false );
textField.setBorder( BorderFactory.createEmptyBorder() );
return textField;
}

/**
* Sets the text of a one-line text component.
*
* @param field field created by createMetaField
* @param text text value (null to clear)
*/
private void setMetaField( JTextField field, String text ) {
field.setText( text );
field.setCaretPosition( 0 );
}

/**
* Returns a downloader for Xmatch service alias names.
*
Expand All @@ -134,4 +243,38 @@ public String[] attemptReadData() throws IOException {
}
};
}

/**
* Downloads metadata about a vizier table.
* A single instance is used by CdsTableSelector, but the current table
* can be reset.
*/
private static class VizierMetaDownloader extends Downloader<VizierMeta> {

private String tableName_;

/**
* Constructor.
*/
VizierMetaDownloader() {
super( VizierMeta.class, "VizieR table metadata" );
}

public VizierMeta attemptReadData() throws IOException {
return CdsUploadMatcher.readVizierMetadata( tableName_ );
}

/**
* Sets the table name or ID for which metadata is required.
* Resetting this value causes the downloader to be cleared.
*
* @param vizier table name or ID
*/
public void setTableName( String tableName ) {
if ( tableName == null || ! tableName.equals( tableName_ ) ) {
clearData();
}
tableName_ = tableName;
}
}
}
53 changes: 34 additions & 19 deletions topcat/src/main/uk/ac/starlink/topcat/join/UploadMatchPanel.java
Expand Up @@ -12,6 +12,7 @@
import java.util.ArrayList;
import java.util.List;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JComboBox;
import javax.swing.JComponent;
Expand All @@ -33,6 +34,7 @@
import uk.ac.starlink.table.Tables;
import uk.ac.starlink.table.ValueInfo;
import uk.ac.starlink.table.storage.MonitorStoragePolicy;
import uk.ac.starlink.topcat.AuxWindow;
import uk.ac.starlink.topcat.BasicAction;
import uk.ac.starlink.topcat.ColumnSelector;
import uk.ac.starlink.topcat.ControlWindow;
Expand Down Expand Up @@ -101,13 +103,29 @@ public UploadMatchPanel( JProgressBar progBar ) {

/* Field for remote table. */
cdsTableSelector_ = new CdsTableSelector();
Box remoteLine = Box.createHorizontalBox();
remoteLine.add( cdsTableSelector_ );
remoteLine.add( Box.createHorizontalGlue() );
main.add( remoteLine );
main.add( Box.createVerticalStrut( 5 ) );
cdsTableSelector_.setBorder(
BorderFactory.createCompoundBorder(
AuxWindow.makeTitledBorder( "Remote Table" ),
BorderFactory.createEmptyBorder( 5, 5, 5, 5 ) ) );
cList.add( cdsTableSelector_ );

/* Containers for different input fields. */
JComponent localBox = Box.createVerticalBox();
JComponent paramBox = Box.createVerticalBox();
localBox.setBorder(
BorderFactory.createCompoundBorder(
AuxWindow.makeTitledBorder( "Local Table" ),
BorderFactory.createEmptyBorder( 5, 5, 5, 5 ) ) );
paramBox.setBorder(
BorderFactory.createCompoundBorder(
AuxWindow.makeTitledBorder( "Match Parameters" ),
BorderFactory.createEmptyBorder( 5, 5, 5, 5 ) ) );
main.add( cdsTableSelector_ );
main.add( Box.createVerticalStrut( 5 ) );
main.add( localBox );
main.add( Box.createVerticalStrut( 5 ) );
main.add( paramBox );

/* Field for input table. */
final JComboBox tableSelector = new TablesListComboBox();
tableSelector.addItemListener( new ItemListener() {
Expand All @@ -122,8 +140,8 @@ public void itemStateChanged( ItemEvent evt ) {
tableLine.add( tableLabel );
tableLine.add( new ShrinkWrapper( tableSelector ) );
tableLine.add( Box.createHorizontalGlue() );
main.add( tableLine );
main.add( Box.createVerticalStrut( 5 ) );
localBox.add( tableLine );
localBox.add( Box.createVerticalStrut( 5 ) );

/* Fields for position parameters. */
raSelector_ = new ColumnSelector( Tables.RA_INFO, true );
Expand All @@ -132,8 +150,8 @@ public void itemStateChanged( ItemEvent evt ) {
JLabel raSysLabel = new JLabel( " (J2000)" );
raLine.add( raSysLabel );
raLine.add( Box.createHorizontalGlue() );
main.add( raLine );
main.add( Box.createVerticalStrut( 5 ) );
localBox.add( raLine );
localBox.add( Box.createVerticalStrut( 5 ) );
cList.add( raSelector_ );
cList.add( raSysLabel );
decSelector_ = new ColumnSelector( Tables.DEC_INFO, true );
Expand All @@ -142,8 +160,8 @@ public void itemStateChanged( ItemEvent evt ) {
JLabel decSysLabel = new JLabel( " (J2000)" );
decLine.add( decSysLabel );
decLine.add( Box.createHorizontalGlue() );
main.add( decLine );
main.add( Box.createVerticalStrut( 5 ) );
localBox.add( decLine );
localBox.add( Box.createVerticalStrut( 5 ) );
cList.add( decSelector_ );
cList.add( decSysLabel );
srField_ = DoubleValueField.makeSizeDegreesField( SR_INFO );
Expand All @@ -156,8 +174,8 @@ public void itemStateChanged( ItemEvent evt ) {
srLine.add( Box.createHorizontalGlue() );
srField_.getConverterSelector().setSelectedIndex( 2 );
srField_.getEntryField().setText( "1.0" );
main.add( srLine );
main.add( Box.createVerticalStrut( 5 ) );
paramBox.add( srLine );
paramBox.add( Box.createVerticalStrut( 5 ) );
cList.add( srField_.getEntryField() );
cList.add( srField_.getLabel() );
cList.add( srField_.getConverterSelector() );
Expand All @@ -166,17 +184,14 @@ public void itemStateChanged( ItemEvent evt ) {
TopcatUtils.alignComponents( new JComponent[] {
raSelector_.getLabel(),
decSelector_.getLabel(),
srField_.getLabel()
} );
TopcatUtils.alignComponents( new JComponent[] {
raSelector_.getColumnComponent(),
decSelector_.getColumnComponent(),
srField_.getEntryField(),
} );
TopcatUtils.alignComponents( new JComponent[] {
raSelector_.getUnitComponent(),
decSelector_.getUnitComponent(),
srField_.getConverterSelector(),
} );

/* Service access parameters. */
Expand All @@ -188,8 +203,8 @@ public void itemStateChanged( ItemEvent evt ) {
modeLine.add( Box.createHorizontalGlue() );
cList.add( modeLabel );
cList.add( modeSelector_ );
main.add( modeLine );
main.add( Box.createVerticalStrut( 5 ) );
paramBox.add( modeLine );
paramBox.add( Box.createVerticalStrut( 5 ) );
Box blockLine = Box.createHorizontalBox();
blockSelector_ = new JComboBox();
for ( int i = 0; i < BLOCK_SIZES.length; i++ ) {
Expand All @@ -203,7 +218,7 @@ public void itemStateChanged( ItemEvent evt ) {
blockLine.add( Box.createHorizontalGlue() );
cList.add( blockLabel );
cList.add( blockSelector_ );
main.add( blockLine );
paramBox.add( blockLine );

/* Actions to start/stop match. */
startAction_ = new BasicAction( "Go", null,
Expand Down

0 comments on commit 9fa6473

Please sign in to comment.