use of org.astrogrid.samp.Metadata in project gaiasky by langurmonkey.
the class SAMPClient method initialize.
public void initialize(final Skin skin) {
// Disable logging
java.util.logging.Logger.getLogger("org.astrogrid.samp").setLevel(Level.OFF);
// Init map
idToNode = new TwoWayHashmap<>();
idToUrl = new HashMap<>();
ClientProfile cp = DefaultClientProfile.getProfile();
conn = new GaiaSkyHubConnector(cp);
// Configure it with metadata about this application
Metadata meta = new Metadata();
meta.setName(Settings.APPLICATION_NAME);
meta.setDescriptionText("3D Universe application focused on ESA's Gaia satellite");
meta.setDocumentationUrl(Settings.DOCUMENTATION);
meta.setIconUrl(Settings.ICON_URL.replaceAll("[^\\x00-\\x7F]", "?"));
meta.put("author.name", Settings.AUTHOR_NAME_PLAIN);
meta.put("author.email", Settings.AUTHOR_EMAIL);
meta.put("author.affiliation", Settings.AUTHOR_AFFILIATION_PLAIN);
meta.put("home.page", Settings.WEBPAGE);
meta.put("gaiasky.version", Settings.settings.version.version);
conn.declareMetadata(meta);
// Load table
conn.addMessageHandler(new AbstractMessageHandler("table.load.votable") {
public Map<Object, Object> processCall(HubConnection c, String senderId, Message msg) {
// do stuff
String name = (String) msg.getParam("name");
String id = (String) msg.getParam("table-id");
String url = (String) msg.getParam("url");
boolean loaded = loadVOTable(url, id, name, skin);
if (!loaded) {
logger.info(I18n.txt("samp.error.votable", name));
}
return null;
}
});
// Select one row
conn.addMessageHandler(new AbstractMessageHandler("table.highlight.row") {
public Map<Object, Object> processCall(HubConnection c, String senderId, Message msg) {
// do stuff
long row = Parser.parseLong((String) msg.getParam("row"));
String id = (String) msg.getParam("table-id");
// First, fetch table if not here
boolean loaded = idToNode.containsKey(id);
// If table here, select
if (loaded) {
logger.info("Select row " + row + " of " + id);
if (idToNode.containsKey(id)) {
if (idToNode.getForward(id) instanceof ParticleGroup) {
// Stars or particles
ParticleGroup pg = (ParticleGroup) idToNode.getForward(id);
pg.setFocusIndex((int) row);
preventProgrammaticEvents = true;
EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraMode.FOCUS_MODE);
EventManager.publish(Event.FOCUS_CHANGE_CMD, this, pg);
preventProgrammaticEvents = false;
} else if (idToNode.getForward(id) != null) {
// Star cluster
FadeNode fn = idToNode.getForward(id);
if (fn.children != null && fn.children.size > (int) row) {
SceneGraphNode sgn = fn.children.get((int) row);
preventProgrammaticEvents = true;
EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraMode.FOCUS_MODE);
EventManager.publish(Event.FOCUS_CHANGE_CMD, this, sgn);
preventProgrammaticEvents = false;
} else {
logger.info("Star cluster to select not found: " + row);
}
}
}
}
return null;
}
});
// Select multiple rows
conn.addMessageHandler(new AbstractMessageHandler("table.select.rowList") {
public Map<Object, Object> processCall(HubConnection c, String senderId, Message msg) {
// do stuff
ArrayList<String> rows = (ArrayList<String>) msg.getParam("row-list");
String id = (String) msg.getParam("table-id");
// First, fetch table if not here
boolean loaded = idToNode.containsKey(id);
// If table here, select
if (loaded && rows != null && !rows.isEmpty()) {
logger.info("Select " + rows.size() + " rows of " + id + ". Gaia Sky does not support multiple selection, so only the first entry is selected.");
// We use the first one, as multiple selections are not supported in Gaia Sky
int row = Integer.parseInt(rows.get(0));
if (idToNode.containsKey(id)) {
FadeNode fn = idToNode.getForward(id);
if (fn instanceof ParticleGroup) {
ParticleGroup pg = (ParticleGroup) fn;
pg.setFocusIndex(row);
preventProgrammaticEvents = true;
EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraManager.CameraMode.FOCUS_MODE);
EventManager.publish(Event.FOCUS_CHANGE_CMD, this, pg);
preventProgrammaticEvents = false;
}
}
}
return null;
}
});
// Point in sky
conn.addMessageHandler(new AbstractMessageHandler("coord.pointAt.sky") {
public Map<Object, Object> processCall(HubConnection c, String senderId, Message msg) {
// do stuff
double ra = Parser.parseDouble((String) msg.getParam("ra"));
double dec = Parser.parseDouble((String) msg.getParam("dec"));
logger.info("Point to coordinate (ra,dec): (" + ra + ", " + dec + ")");
EventManager.publish(Event.CAMERA_MODE_CMD, this, CameraMode.FREE_MODE);
EventManager.publish(Event.FREE_MODE_COORD_CMD, this, ra, dec);
return null;
}
});
// This step required even if no custom message handlers added.
conn.declareSubscriptions(conn.computeSubscriptions());
// Keep a look out for hubs if initial one shuts down
conn.setAutoconnect(10);
}
use of org.astrogrid.samp.Metadata in project aspro by JMMC-OpenDev.
the class VotableSampMessageHandler method processMessage.
/**
* Implements message processing
*
* @param senderId public ID of sender client
* @param message message with MType this handler is subscribed to
* @throws SampException if any error occured while message processing
*/
@Override
protected void processMessage(final String senderId, final Message message) throws SampException {
if (logger.isDebugEnabled()) {
logger.debug("\tReceived '{}' message from '{}' : '{}'.", this.handledMType(), senderId, message);
}
// get url of votable (locally stored) :
final String voTableURL = (String) message.getRequiredParam("url");
logger.debug("processMessage: VOTable URL = {}", voTableURL);
if (voTableURL == null) {
throw new SampException("Can not get the url of the votable");
}
URI voTableURI;
try {
voTableURI = new URI(voTableURL);
} catch (URISyntaxException use) {
logger.error("invalid URI", use);
throw new SampException("Can not read the votable : " + voTableURL, use);
}
File voTableFile = null;
try {
final String scheme = voTableURI.getScheme();
if (scheme.equalsIgnoreCase("file")) {
try {
voTableFile = new File(voTableURI);
} catch (IllegalArgumentException iae) {
logger.debug("Invalid URI: {}", voTableURL, iae);
// aladin bug: URI has an authority component
try {
voTableURI = new URI(scheme, voTableURI.getPath(), null);
} catch (URISyntaxException use) {
logger.error("invalid URI", use);
throw new SampException("Can not read the votable : " + voTableURL, use);
}
}
try {
voTableFile = new File(voTableURI);
} catch (IllegalArgumentException iae) {
logger.info("Invalid URI: {}", voTableURL, iae);
}
} else {
final File file = FileUtils.getTempFile("votable-", ".vot");
if (Http.download(voTableURI, file, false)) {
voTableFile = file;
}
}
if (voTableFile == null) {
throw new SampException("Not supported URI scheme : " + voTableURL);
}
final String votable = FileUtils.readFile(voTableFile);
logger.debug("votable :\n{}", votable);
String searchCalVersion = null;
// Note: Getting SearchCal version in sender meta data is not robust:
// do not work with AppLauncher as senderMetadata corresponds to AppLauncher.metadata and not SearchCal !
// TODO: use VOTABLE information instead !
// Note: can be null if the client map is not up to date or the client disconnected:
final Metadata senderMetadata = SampManager.getMetaData(senderId);
if (senderMetadata != null) {
logger.debug("senderMetadata: {}", senderMetadata);
final String senderName = senderMetadata.getName();
if ("searchcal".equalsIgnoreCase(senderName) || "getstar".equalsIgnoreCase(senderName)) {
// SearchCal release > 4.4.1:
searchCalVersion = senderMetadata.getString(SampMetaData.RELEASE_VERSION.id());
if (searchCalVersion == null) {
// SearchCal release <= 4.4.1:
searchCalVersion = senderMetadata.getString("searchcal.version");
}
}
}
logger.debug("SearchCal version = {}", searchCalVersion);
if (searchCalVersion == null) {
// TODO: use 'undefined' as SearchCal version temporarly:
if (!SearchCalVOTableHandler.processMessage(votable, "undefined")) {
AnyVOTableHandler.processVOTable(votable, false);
}
} else {
SearchCalVOTableHandler.processMessage(votable, searchCalVersion);
}
} catch (IOException ioe) {
MessagePane.showErrorMessage("Can not read the votable :\n\n" + voTableURL);
throw new SampException("Can not read the votable : " + voTableURL, ioe);
}
}
Aggregations