Package simtools.ui

Source Code of simtools.ui.StreamingMSDataSourceInformation

/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info:  http://jsynoptic.sourceforge.net/index.html
*
* This program is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2001-2005, by :
*     Corporate:
*         EADS Astrium SAS
*         EADS CRC
*     Individual:
*         Claude Cazenave
*
* $Id: StreamingMSDataSourceInformation.java,v 1.7 2007/09/04 13:05:24 ogor Exp $
*
* Changes
* -------
* 19 avr. 2006  : Initial public release (CC);
*
*/
package simtools.ui;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.util.Date;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;

import simtools.data.DataException;
import simtools.data.DataSource;
import simtools.data.EndNotificationListener;
import simtools.data.async.StreamingMSDataSource;

public class StreamingMSDataSourceInformation extends DataSourceInformation implements EndNotificationListener {
    protected static MenuResourceBundle resources = ResourceFinder.getMenu(StreamingMSDataSourceInformation.class);

    protected JTextField tfTime1;

    protected JTextField tfTime2;

    protected JTextField tfPhysical;

    protected JTextField tfRaw;

    protected JTextField tfLabel;

    protected JTextField tfStatus;

    public void setPanel(DataSource ds) {
        dataSource = ds;
        // Set panels
        setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = STANDARD_INSETS;
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.fill = GridBagConstraints.BOTH;
        gbc.weightx = 1;
        gbc.weighty = 0.2;
        add(createStaticInformationPanel(), gbc);
        gbc.gridy++;
        gbc.weighty = 0.8;
        add(createMSDataSourceInformationPanel(), gbc);
        if (dataSource != null) {
            dataSource.addEndNotificationListener(this);
        }
    }

    protected JPanel createMSDataSourceInformationPanel() {
        JPanel _msPanel = new JPanel();
        _msPanel.setBorder(new TitledBorder(resources.getString("dynamicInformation")));
        _msPanel.setLayout(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = STANDARD_INSETS;
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.weighty = 1;
        gbc.anchor = GridBagConstraints.EAST;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        // textfileds
        tfTime1 = new JTextField();
        tfTime2 = new JTextField();
        tfPhysical = new JTextField();
        tfRaw = new JTextField();
        tfLabel = new JTextField();
        tfStatus = new JTextField();
        tfTime1.setEditable(false);
        tfTime2.setEditable(false);
        tfPhysical.setEditable(false);
        tfRaw.setEditable(false);
        tfLabel.setEditable(false);
        tfStatus.setEditable(false);
        tfTime1.setColumns(FIELD_SIZE);
        tfTime2.setColumns(FIELD_SIZE);
        tfPhysical.setColumns(FIELD_SIZE);
        tfRaw.setColumns(FIELD_SIZE);
        tfLabel.setColumns(FIELD_SIZE);
        tfStatus.setColumns(FIELD_SIZE);
        // time 1
        _msPanel.add(new JLabel(resources.getString("time1")), gbc);
        gbc.weightx = 1;
        gbc.gridwidth = 3;
        gbc.gridx++;
        gbc.anchor = GridBagConstraints.WEST;
        tfTime1.setMinimumSize(tfTime1.getPreferredSize());
        _msPanel.add(tfTime1, gbc);
        // time 2
        gbc.gridx = 0;
        gbc.gridy++;
        gbc.weightx = 0;
        gbc.anchor = GridBagConstraints.EAST;
        _msPanel.add(new JLabel(resources.getString("time2")), gbc);
        gbc.weightx = 1;
        gbc.gridwidth = 3;
        gbc.gridx++;
        gbc.anchor = GridBagConstraints.WEST;
        tfTime2.setMinimumSize(tfTime2.getPreferredSize());
        _msPanel.add(tfTime2, gbc);
        // phys
        gbc.gridx = 0;
        gbc.gridy++;
        gbc.weightx = 0;
        gbc.anchor = GridBagConstraints.EAST;
        _msPanel.add(new JLabel(resources.getString("physical")), gbc);
        gbc.weightx = 1;
        gbc.gridwidth = 3;
        gbc.gridx++;
        gbc.anchor = GridBagConstraints.WEST;
        tfPhysical.setMinimumSize(tfPhysical.getPreferredSize());
        _msPanel.add(tfPhysical, gbc);
        // raw
        gbc.gridx = 0;
        gbc.gridy++;
        gbc.weightx = 0;
        gbc.anchor = GridBagConstraints.EAST;
        _msPanel.add(new JLabel(resources.getString("raw")), gbc);
        gbc.weightx = 1;
        gbc.gridwidth = 3;
        gbc.gridx++;
        gbc.anchor = GridBagConstraints.WEST;
        tfRaw.setMinimumSize(tfRaw.getPreferredSize());
        _msPanel.add(tfRaw, gbc);
        // label
        gbc.gridx = 0;
        gbc.gridy++;
        gbc.weightx = 0;
        gbc.anchor = GridBagConstraints.EAST;
        _msPanel.add(new JLabel(resources.getString("label")), gbc);
        gbc.weightx = 1;
        gbc.gridwidth = 3;
        gbc.gridx++;
        gbc.anchor = GridBagConstraints.WEST;
        tfLabel.setMinimumSize(tfLabel.getPreferredSize());
        _msPanel.add(tfLabel, gbc);
        // status
        gbc.gridx = 0;
        gbc.gridy++;
        gbc.weightx = 0;
        gbc.anchor = GridBagConstraints.EAST;
        _msPanel.add(new JLabel(resources.getString("status")), gbc);
        gbc.weightx = 1;
        gbc.gridwidth = 3;
        gbc.gridx++;
        gbc.anchor = GridBagConstraints.WEST;
        tfStatus.setMinimumSize(tfStatus.getPreferredSize());
        _msPanel.add(tfStatus, gbc);
        updateSMSvalues();
        return _msPanel;
    }

    public void notificationEnd(Object referer) {
        updatevalues();
    }

    protected void updateSMSvalues() {
        try {
            if (dataSource instanceof StreamingMSDataSource) {
                StreamingMSDataSource jds = (StreamingMSDataSource) dataSource;
                if (jds.getTime() != null) {
                    Number time = (Number) jds.getTime().getValue(jds.getLastIndex());
                    tfTime1.setText(TimeStampedDataSourceInformation.dateTimeFormatter
                            .format(new Date(time.longValue())));
                }
                if (jds.getTime2() != null) {
                    double time2 = jds.getTime2().getDoubleValue(jds.getLastIndex());
                    tfTime2.setText(String.valueOf(time2));
                }
                if (jds.getRaw() != null) {
                    Long raw = new Long(jds.getRaw().getLongValue(jds.getLastIndex()));
                    tfRaw.setText(String.valueOf(raw));
                }
                Object value = jds.getValue(jds.getLastIndex());
                tfPhysical.setText(value.toString());
                if (jds.getLabel() != null) {
                    String label = (String) jds.getLabel().getValue(jds.getLastIndex());
                    tfLabel.setText(String.valueOf(label));
                }
                if (jds.getStatus() != null) {
                    Integer valueNumber = new Integer(((Long) jds.getStatus().getValue(jds.getLastIndex())).intValue());
                    tfStatus.setText(valueNumber.toString());
                }
            }
        } catch (DataException e) {
        }
    }

    protected void updatevalues() {
        updateSMSvalues();
    }

    /*
     * (non-Javadoc)
     *
     * @see simtools.ui.DataSourceInformation#dispose()
     */
    public void dispose() {
        if (dataSource != null) {
            dataSource.removeEndNotificationListener(this);
        }
    }
}
TOP

Related Classes of simtools.ui.StreamingMSDataSourceInformation

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.