/* * This file is part of the Remote Sensor Actuator Interface (ReSAI). * * Copyright(c) Andreas Kipp, Frederic Siepmann * http://opensource.cit-ec.de/projects/resai * * This file may be licensed under the terms of of the * GNU Lesser General Public License Version 3 (the ``LGPL''), * or (at your option) any later version. * * Software distributed under the License is distributed * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either * express or implied. See the LGPL for the specific language * governing rights and limitations. * * You should have received a copy of the LGPL along with this * program. If not, go to http://www.gnu.org/licenses/lgpl.html * or write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * The development of this software was supported by the * Excellence Cluster EXC 277 Cognitive Interaction Technology. * The Excellence Cluster EXC 277 is a grant of the Deutsche * Forschungsgemeinschaft (DFG) in the context of the German * Excellence Initiative. * */ /** * Panel for beacon information. * * @author akipp */ package de.unibi.airobots.resaijavaclient.gui.panels; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.util.Observable; import java.util.Observer; import javax.swing.JLabel; import javax.swing.JPanel; import de.unibi.airobots.resaijavaclient.communicaton.Communicator; import de.unibi.airobots.resaijavaclient.communicaton.XMPPCommunicator; import de.unibi.airobots.resaijavaclient.communicaton.XMPPPacketListener; import de.unibi.airobots.resaijavaclient.constants.Constants; import de.unibi.airobots.resaijavaclient.helper.TimeConverter; public class BeaconPanel extends JPanel implements Observer { private static final long serialVersionUID = 1L; private JLabel lblServerTime = new JLabel(""); private JLabel lblServer = new JLabel("ServerTime:"); private JLabel lblClientTime = new JLabel(""); private JLabel lblClient = new JLabel("ClientTime:"); public BeaconPanel(Communicator communicator) { XMPPPacketListener pl = new XMPPPacketListener(); XMPPCommunicator com = (XMPPCommunicator) communicator; com.addListener(pl); pl.addObserver(this); JPanel pane = new JPanel(); pane.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = 0; pane.add(lblServer,c); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 1; c.gridy = 0; pane.add(lblServerTime,c); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = 1; pane.add(lblClient,c); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 1; c.gridy = 1; pane.add(lblClientTime,c); add(pane); } @Override public void update(Observable o, Object arg1) { if (o instanceof XMPPPacketListener) { XMPPPacketListener xmppListener = (XMPPPacketListener) o; if (xmppListener.getReceivedProperties().containsKey(Constants.CMD)) { if (xmppListener.getReceivedProperties().get(Constants.CMD).equals(Constants.BEACON)) { String serverTime = TimeConverter.toDateTime(Long .parseLong(xmppListener.getReceivedProperties().get( Constants.SERVER_TIME))); lblServerTime.setText(serverTime); String clientTime = TimeConverter.toDateTime(Long .parseLong(xmppListener.getReceivedProperties().get( Constants.CLIENT_TIME))); lblClientTime.setText(clientTime); } } } } }