Search in sources :

Example 1 with IAttribute

use of gaiasky.util.filter.attrib.IAttribute in project gaiasky by langurmonkey.

the class EventScriptingInterface method getAttributeByName.

private IAttribute getAttributeByName(String name, CatalogInfo ci) {
    try {
        // One of the default attributes
        Class<?> clazz = Class.forName("gaiasky.util.filter.attrib.Attribute" + name);
        Constructor<?> ctor = clazz.getConstructor();
        return (IAttribute) ctor.newInstance();
    } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException | IllegalAccessException | InvocationTargetException e) {
        // Try extra attributes
        if (ci.object instanceof ParticleGroup) {
            ParticleGroup pg = (ParticleGroup) ci.object;
            ObjectDoubleMap.Keys<UCD> ucds = pg.get(0).extraKeys();
            for (UCD ucd : ucds) if (ucd.colname.equalsIgnoreCase(name))
                return new AttributeUCD(ucd);
        }
    }
    return null;
}
Also used : AttributeUCD(gaiasky.util.filter.attrib.AttributeUCD) InvocationTargetException(java.lang.reflect.InvocationTargetException) Keys(com.badlogic.gdx.Input.Keys) AttributeUCD(gaiasky.util.filter.attrib.AttributeUCD) UCD(gaiasky.util.ucd.UCD) IAttribute(gaiasky.util.filter.attrib.IAttribute)

Example 2 with IAttribute

use of gaiasky.util.filter.attrib.IAttribute in project gaiasky by langurmonkey.

the class EventScriptingInterface method highlightDataset.

@Override
public boolean highlightDataset(String dsName, String attributeName, String colorMap, double minMap, double maxMap, boolean highlight) {
    if (checkString(dsName, "datasetName")) {
        boolean exists = this.catalogManager.contains(dsName);
        if (exists) {
            CatalogInfo ci = this.catalogManager.get(dsName);
            IAttribute attribute = getAttributeByName(attributeName, ci);
            int cmapIndex = getCmapIndexByName(colorMap);
            if (attribute != null && cmapIndex >= 0) {
                ci.plainColor = false;
                ci.hlCmapIndex = cmapIndex;
                ci.hlCmapMin = minMap;
                ci.hlCmapMax = maxMap;
                ci.hlCmapAttribute = attribute;
                postRunnable(() -> EventManager.publish(Event.CATALOG_HIGHLIGHT, this, ci, highlight));
            } else {
                if (attribute == null)
                    logger.error("Could not find attribute with name '" + attributeName + "'");
                if (cmapIndex < 0)
                    logger.error("Could not find color map with name '" + colorMap + "'");
            }
        } else {
            logger.warn("Dataset with name " + dsName + " does not exist");
        }
        return exists;
    }
    return false;
}
Also used : IAttribute(gaiasky.util.filter.attrib.IAttribute)

Aggregations

IAttribute (gaiasky.util.filter.attrib.IAttribute)2 Keys (com.badlogic.gdx.Input.Keys)1 AttributeUCD (gaiasky.util.filter.attrib.AttributeUCD)1 UCD (gaiasky.util.ucd.UCD)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1