Search in sources :

Example 1 with URLDataSource

use of uk.ac.starlink.util.URLDataSource in project gaiasky by langurmonkey.

the class SAMPClient method loadVOTable.

/**
 * Loads a VOTable into a star group
 *
 * @param url  The URL to fetch the table
 * @param id   The table id
 * @param name The table name
 *
 * @return Boolean indicating whether loading succeeded or not
 */
private boolean loadVOTable(final String url, final String id, final String name, final Skin skin) {
    logger.info("Loading VOTable: " + name + " from " + url);
    // Load selected file
    try {
        DataSource dataSource = new URLDataSource(new URL(url));
        Stage ui = GaiaSky.instance.mainGui.getGuiStage();
        String fileName = dataSource.getName();
        final DatasetLoadDialog dld = new DatasetLoadDialog(I18n.txt("gui.dsload.title") + ": " + fileName, fileName, skin, ui);
        Runnable doLoad = () -> {
            try {
                DatasetOptions datasetOptions = dld.generateDatasetOptions();
                // Load dataset
                boolean loaded = ((EventScriptingInterface) GaiaSky.instance.scripting()).loadDataset(id, dataSource, CatalogInfoSource.SAMP, datasetOptions, true);
                if (loaded) {
                    // Select first
                    CatalogInfo ci = catalogManager.get(id);
                    if (ci.object != null) {
                        if (ci.object instanceof ParticleGroup) {
                            ParticleGroup pg = (ParticleGroup) ci.object;
                            if (pg.data() != null && !pg.data().isEmpty() && pg.isVisibilityOn()) {
                                EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraManager.CameraMode.FOCUS_MODE);
                                EventManager.publish(Event.FOCUS_CHANGE_CMD, this, pg.getRandomParticleName());
                            }
                        } else if (ci.object.children != null && !ci.object.children.isEmpty() && ci.object.children.get(0).isVisibilityOn()) {
                            EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraManager.CameraMode.FOCUS_MODE);
                            EventManager.publish(Event.FOCUS_CHANGE_CMD, this, ci.object.children.get(0));
                        }
                        // Open UI datasets
                        GaiaSky.instance.scripting().maximizeInterfaceWindow();
                        GaiaSky.instance.scripting().expandGuiComponent("DatasetsComponent");
                        idToNode.add(id, ci.object);
                        idToUrl.put(id, url);
                    }
                }
            } catch (Exception e) {
                logger.error(I18n.txt("notif.error", fileName), e);
            }
        };
        dld.setAcceptRunnable(() -> {
            Thread t = new Thread(doLoad);
            t.start();
        });
        dld.show(ui);
        return true;
    } catch (Exception e) {
        logger.error(I18n.txt("notif.error", url), e);
        return false;
    }
}
Also used : DatasetLoadDialog(gaiasky.interafce.DatasetLoadDialog) URLDataSource(uk.ac.starlink.util.URLDataSource) ParticleGroup(gaiasky.scenegraph.ParticleGroup) Stage(com.badlogic.gdx.scenes.scene2d.Stage) DatasetOptions(gaiasky.data.group.DatasetOptions) URL(java.net.URL) DataSource(uk.ac.starlink.util.DataSource) URLDataSource(uk.ac.starlink.util.URLDataSource)

Aggregations

Stage (com.badlogic.gdx.scenes.scene2d.Stage)1 DatasetOptions (gaiasky.data.group.DatasetOptions)1 DatasetLoadDialog (gaiasky.interafce.DatasetLoadDialog)1 ParticleGroup (gaiasky.scenegraph.ParticleGroup)1 URL (java.net.URL)1 DataSource (uk.ac.starlink.util.DataSource)1 URLDataSource (uk.ac.starlink.util.URLDataSource)1