The Robot Application Programming Interface Delegate Project
|
/* * Copyright (c) 2009 United States Government as represented by the * Administrator of the National Aeronautics and Space Administration. * All Rights Reserved. */ package gov.nasa.rapid.examples.models; import gov.nasa.rapid.dds.Agent; import gov.nasa.rapid.event.IRapidEventListener; import gov.nasa.rapid.event.RapidEventCollector; import gov.nasa.rapid.examples.ClientRapidAgent; import gov.nasa.rapid.message.MessageType; import java.util.ArrayList; import java.util.EventObject; import java.util.List; public class RapidExampleModel { protected ClientRapidAgent rapidAgent; protected String message = ""; protected long timeStamp = -1; protected float[] values = new float[]{0, 0, 0}; protected String name = ""; protected List<ModelChangedListener> listeners = new ArrayList<ModelChangedListener>(); public RapidExampleModel(Agent agent) { rapidAgent = ClientRapidAgent.getInstance(agent); } protected void registerForMessage(Agent srcAgent, MessageType messageType, IRapidEventListener eventListener) { Agent [] agentList = new Agent[] {srcAgent}; registerForMessage(agentList, messageType, eventListener); } protected void registerForMessage(Agent[] srcAgents, MessageType messageType, IRapidEventListener eventListener) { try { RapidEventCollector.getInstance().registerForMessages( srcAgents, messageType, eventListener ); } catch (Exception e) { e.printStackTrace(); } } public String getMessage() { return message; } public long getTimeStamp() { return timeStamp; } public float[] getValues() { return values; } public void setMessage(String m) { message = m; } public void setValues(float [] v) { values = v; } public void setValues(double [] v) { float[] f = new float[]{(float)v[0], (float)v[1], (float)v[2]}; setValues(f); } public void setTimeStamp(long t) { timeStamp = t; } public void addModelChangedListener(ModelChangedListener l) { listeners.add(l); } public void updateModelChangedListeners() { for (ModelChangedListener l : listeners) l.modelChanged(new EventObject(this)); } public String getModelName() { return name; } public void setModelName(String n) { name = n; } }