From 00b2ca9927234403ffe59765a3828ffab8fff589 Mon Sep 17 00:00:00 2001 From: Margarida Castro Neves Date: Thu, 27 Feb 2014 12:22:11 +0100 Subject: [PATCH] Added DataLink support --- .../ac/starlink/splat/iface/SplatBrowser.java | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/splat/src/main/uk/ac/starlink/splat/iface/SplatBrowser.java b/splat/src/main/uk/ac/starlink/splat/iface/SplatBrowser.java index 49e00133ed..6d15f22667 100644 --- a/splat/src/main/uk/ac/starlink/splat/iface/SplatBrowser.java +++ b/splat/src/main/uk/ac/starlink/splat/iface/SplatBrowser.java @@ -35,8 +35,10 @@ import java.awt.event.WindowEvent; import java.io.File; import java.io.FileInputStream; +import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; +import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -86,16 +88,26 @@ import uk.ac.starlink.splat.util.MathUtils; import uk.ac.starlink.splat.util.Transmitter; import uk.ac.starlink.splat.util.Utilities; +import uk.ac.starlink.util.DataSource; +import uk.ac.starlink.util.URLDataSource; import uk.ac.starlink.util.gui.BasicFileChooser; import uk.ac.starlink.util.gui.BasicFileFilter; import uk.ac.starlink.util.gui.FileNameListCellRenderer; import uk.ac.starlink.util.gui.GridBagLayouter; import uk.ac.starlink.util.gui.ErrorDialog; +import uk.ac.starlink.votable.VOTableBuilder; +import uk.ac.starlink.splat.vo.DataLinkParams; import uk.ac.starlink.splat.vo.SSAQueryBrowser; import uk.ac.starlink.splat.vo.SSAServerList; import uk.ac.starlink.splat.vo.SSAPAuthenticator; +import uk.ac.starlink.table.DescribedValue; +import uk.ac.starlink.table.RowSequence; +import uk.ac.starlink.table.StarTable; +import uk.ac.starlink.table.StoragePolicy; +import uk.ac.starlink.table.TableFormatException; + /** * This is the main class for the SPLAT program. It creates the * browser interface that displays and controls the global lists of @@ -245,6 +257,7 @@ public class SplatBrowser * SSAP browser. */ protected SSAQueryBrowser ssapBrowser = null; + /** * Stack open or save chooser. @@ -715,6 +728,9 @@ private void createFileMenu() fileMenu.add( ssapAction ).setMnemonic( KeyEvent.VK_P ); toolBar.add( ssapAction ); + + + // Add action to browse the local file system and look for tables // etc. in sub-components. ImageIcon browseImage = @@ -1759,6 +1775,8 @@ protected void showSSAPBrowser() ssapBrowser.setVisible( true ); } + + /** * Open and display all the spectra listed in the newFiles array. Uses a * thread to load the files so that we do not block the UI (although the @@ -1969,9 +1987,11 @@ public void tryAddSpectrum( String name, int usertype ) * * @param props a container class for the spectrum properties, including * the specification (i.e. file name etc.) of the spectrum + * @throws IOException + * @throws TableFormatException */ public void tryAddSpectrum( SpectrumIO.Props props ) - throws SplatException + throws SplatException, TableFormatException, IOException { if ( props.getType() == SpecDataFactory.SED ) { // Could be a source of several spectra. @@ -1989,8 +2009,18 @@ public void tryAddSpectrum( SpectrumIO.Props props ) SpecData spectrum; if ( specstr.contains("REQUEST=getData") && props.getGetDataFormat() != null ) spectrum = specDataFactory.get( props.getSpectrum(), props.getGetDataFormat() ); - else + // if the access_url is a datalink, then we have to get first the Datalink VOTable to get the real access_url of the spectrum. + else { + if (props.getType() == SpecDataFactory.DATALINK) { + DataLinkParams dlparams = new DataLinkParams(props.getSpectrum()); + props.setSpectrum(dlparams.getQueryAccessURL(0)); // get the accessURL for the first service read, in case there are more services !?!?!?!?!?!?!?!?!?!?!? + if ( dlparams.getQueryContentType(0) == null || dlparams.getQueryContentType(0).isEmpty()) + props.setType(SpecDataFactory.GUESS); + else + props.setType(SpecDataFactory.mimeToSPLATType(dlparams.getQueryContentType(0))); + } spectrum = specDataFactory.get( props.getSpectrum(), props.getType() ); + } addSpectrum( spectrum ); props.apply( spectrum ); } @@ -2084,6 +2114,7 @@ public void addSpectrum( SpecData spectrum ) } if ( moreSpectra != null ) { // Abandon the current spectrum and use these instead. + colourAsLoaded=true; for ( int i = 0; i < moreSpectra.length; i++ ) { applyRenderingDefaults( moreSpectra[i] ); globalList.add( moreSpectra[i] ); @@ -3020,6 +3051,7 @@ protected class LocalAction extends AbstractAction public static final int PURGE_SPECTRA = 26; public static final int FITS_VIEWER = 27; public static final int EXIT = 28; + private int type = 0; @@ -3205,8 +3237,7 @@ public void actionPerformed( ActionEvent ae ) fitsSelectedSpectra(); } break; - - + case EXIT: { exitApplicationEvent(); }