/* ========================
* 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: MultiStampedDataSourceInformation.java,v 1.5 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.MultiStampedDataSource;
public class MultiStampedDataSourceInformation extends DataSourceInformation implements EndNotificationListener {
protected static MenuResourceBundle resources = ResourceFinder.getMenu(StreamingMSDataSourceInformation.class);
protected JTextField tfTime1;
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);
// Notify data source
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();
tfPhysical = new JTextField();
tfRaw = new JTextField();
tfLabel = new JTextField();
tfStatus = new JTextField();
tfTime1.setEditable(false);
tfPhysical.setEditable(false);
tfRaw.setEditable(false);
tfLabel.setEditable(false);
tfStatus.setEditable(false);
tfTime1.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);
// 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);
updateMSvalues();
return _msPanel;
}
public void notificationEnd(Object referer) {
updatevalues();
}
protected void updateMSvalues() {
try {
if (dataSource instanceof MultiStampedDataSource) {
MultiStampedDataSource jds = (MultiStampedDataSource) dataSource;
if (jds.getTime() != null) {
Number time = (Number) jds.getTime().getValue(jds.getLastIndex());
tfTime1.setText(TimeStampedDataSourceInformation.dateTimeFormatter
.format(new Date(time.longValue())));
}
if (jds.getRaw() != null) {
Long raw = new Long(jds.getRaw().getLongValue(jds.getLastIndex()));
tfRaw.setText(raw.toString());
}
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() {
updateMSvalues();
}
/*
* (non-Javadoc)
*
* @see simtools.ui.DataSourceInformation#dispose()
*/
public void dispose() {
if (dataSource != null) {
dataSource.removeEndNotificationListener(this);
}
}
}