Package simtools.ui

Source Code of simtools.ui.DataSourceInformation

/* ========================
* 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: DataSourceInformation.java,v 1.5 2007/09/04 13:02:34 ogor Exp $
*
* Changes
* -------
* 6 avr. 2006  : Initial public release (CC);
*
*/
package simtools.ui;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;
import simtools.data.DataInfo;
import simtools.data.DataSource;

/**
* UI that provides information related to a data source
* @author zxpletran007
*
*/
public class DataSourceInformation extends JPanel {
    protected DataSource dataSource = null;

    protected static MenuResourceBundle resources = ResourceFinder.getMenu(DataSourceInformation.class);

    protected JTextField tfName;

    protected JTextField tfId;

    protected JTextField tfUnit;

    protected JTextField tfComments;

    protected JTextField tfFormat;

    protected static final Insets STANDARD_INSETS = new Insets(5, 5, 5, 5);

    protected static final int FIELD_SIZE = 15;

    protected static final int DATE_FIELD_SIZE = 30;

    protected static final int SMALL_FIELD_SIZE = 4;

    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);
    }

    protected JPanel createStaticInformationPanel() {
        JPanel _globalPanel = new JPanel();
        _globalPanel.setBorder(new TitledBorder(resources.getString("staticInformation")));
        _globalPanel.setLayout(new GridBagLayout());
        // textfileds
        tfName = new JTextField();
        tfId = new JTextField();
        tfUnit = new JTextField();
        tfComments = new JTextField();
        tfFormat = new JTextField();
        tfName.setEditable(false);
        tfId.setEditable(false);
        tfUnit.setEditable(false);
        tfComments.setEditable(false);
        tfFormat.setEditable(false);
        tfName.setColumns(FIELD_SIZE);
        tfId.setColumns(FIELD_SIZE);
        tfUnit.setColumns(SMALL_FIELD_SIZE);
        tfComments.setColumns(FIELD_SIZE);
        tfFormat.setColumns(SMALL_FIELD_SIZE);
        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;
        _globalPanel.add(new JLabel(resources.getString("id")), gbc);
        gbc.gridx++;
        gbc.weightx = 0.7;
        _globalPanel.add(tfId, gbc);
        gbc.anchor = GridBagConstraints.WEST;
        gbc.gridx++;
        gbc.weightx = 0.7;
        _globalPanel.add(new JLabel(resources.getString("name")), gbc);
        gbc.gridx++;
        gbc.weightx = 0.7;
        _globalPanel.add(tfName, gbc);
        if ((DataInfo.getUnit(dataSource) != null) && (!DataInfo.getUnit(dataSource).equals(""))) {
            gbc.gridx++;
            gbc.weightx = 0;
            _globalPanel.add(new JLabel(resources.getString("unit")), gbc);
            gbc.gridx++;
            gbc.weightx = 0.3;
            gbc.anchor = GridBagConstraints.WEST;
            _globalPanel.add(tfUnit, gbc);
        }
        if ((DataInfo.getComment(dataSource) != null) && (!DataInfo.getComment(dataSource).equals(""))) {
            gbc.gridx = 0;
            gbc.gridy++;
            gbc.weightx = 0;
            gbc.anchor = GridBagConstraints.EAST;
            _globalPanel.add(new JLabel(resources.getString("description")), gbc);
            gbc.weightx = 1;
            gbc.gridwidth = 3;
            gbc.gridx++;
            gbc.anchor = GridBagConstraints.WEST;
            tfComments.setColumns(38);
            tfComments.setMinimumSize(tfComments.getPreferredSize());
            _globalPanel.add(tfComments, gbc);
        }
        if ((DataInfo.getPrintfFormat(dataSource) != null) && (!DataInfo.getPrintfFormat(dataSource).equals(""))) {
            gbc.gridx = 0;
            gbc.gridy++;
            gbc.weightx = 0;
            gbc.anchor = GridBagConstraints.EAST;
            _globalPanel.add(new JLabel(resources.getString("format")), gbc);
            gbc.weightx = 1;
            gbc.gridwidth = 3;
            gbc.gridx++;
            gbc.anchor = GridBagConstraints.WEST;
            tfFormat.setColumns(38);
            tfFormat.setMinimumSize(tfFormat.getPreferredSize());
            _globalPanel.add(tfFormat, gbc);
        }
        updateStaticValues();
        return _globalPanel;
    }

    protected void updateStaticValues() {
        if (DataInfo.getLabel(dataSource) != null) {
            tfName.setText(DataInfo.getLabel(dataSource));
        }
        if (DataInfo.getId(dataSource) != null) {
            tfId.setText(DataInfo.getId(dataSource));
        }
        if (DataInfo.getComment(dataSource) != null) {
            tfComments.setText(DataInfo.getComment(dataSource));
        }
        if (DataInfo.getUnit(dataSource) != null) {
            tfUnit.setText(DataInfo.getUnit(dataSource));
        }
        if (DataInfo.getPrintfFormat(dataSource) != null) {
            tfFormat.setText(DataInfo.getPrintfFormat(dataSource));
        }
    }

    /**
     * Let sub class do action when information dialog box is closed
     */
    public void dispose() {
    }
}
TOP

Related Classes of simtools.ui.DataSourceInformation

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.