Package jsynoptic.builtin.ui

Source Code of jsynoptic.builtin.ui.TextPropertiesPanel

/* ========================
* 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-2004, by :
*     Corporate:
*         EADS Astrium SAS
*         EADS CRC
*     Individual:
*         Nicolas Brodu
*         Jean-Baptiste Lièvremont
*
* $$Id: TextPropertiesPanel.java,v 1.27 2008/10/06 11:08:01 ogor Exp $$
*
* Changes
* -------
*
*/package jsynoptic.builtin.ui;

import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeSupport;
import java.util.ResourceBundle;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.ListCellRenderer;
import javax.swing.SwingConstants;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;

import jsynoptic.builtin.TextShape;
import jsynoptic.ui.JSynoptic;
import simtools.data.DataInfo;
import simtools.data.DataSource;
import simtools.data.DataSourcePool;
import simtools.data.DuplicateIdException;
import simtools.ui.ActionCheckBox;
import simtools.ui.ColorMapper;
import simtools.ui.FontChooserPanel;
import simtools.ui.NumberField;
import simtools.ui.GridBagPanel;
import simtools.ui.ResourceFinder;
import simtools.ui.FilteredSourceTree;
import simtools.ui.SourceTree;
import simtools.ui.TextMapper;

public class TextPropertiesPanel extends PropertiesPanel2D {
    private PropertyChangeSupport changes = new PropertyChangeSupport(this);

    public static ResourceBundle resources = ResourceFinder.get(TextShape.class);

    protected JButton bbackcolor, bframecolor, beditmapper, bnewmapper, bdelmapper, bduplicateMapper;

    protected ActionCheckBox cbDataSource;

    protected JCheckBox cbBack, cbFrame, cbMargin, cbFontLocked, cbFrameLocked, cbDisplayValue, cbDisplayUnit,
            cbDisplayComments, cbDisplayName;

    protected JLabel lwidth, lheight, lmapper, lPrintfFormat,  lformat, lformatdigits, lcharNumber;

    protected JTextField ldynamicDsId;
   
    protected NumberField nfWidth, nfHeight, nfformat, nfCharNumber;

    protected JTextField tfText, tfPrintfFormat;

    protected FilteredSourceTree dstree;

    protected JComboBox cbxformat, cbxmapper;

    protected JPanel cards;

    protected DataSource source;

    protected TextMapper mapper;

    protected FontChooserPanel fontChooserPanel;

    protected GridBagPanel dynamicDataPanel;

    protected GridBagPanel textSizePanel;

    public TextPropertiesPanel(String shapeName) {
        this(false, shapeName);
    }

    public TextPropertiesPanel(boolean showTransform, String shapeName) {
        super(false, true, true, showTransform, shapeName);
        source = null;
        tfText = new JTextField("");
        fontChooserPanel = new FontChooserPanel(this, simtools.shapes.AbstractShape.FONT_NAMES, tfText);
        dynamicDataPanel = new GridBagPanel(resources.getString("DynamicData"));
        textSizePanel = new GridBagPanel(resources.getString("TextSize"));
       
        // Create contents
        setTextSizePanel();
        setDynamicDataSource();
     
        removeAll();
               
        addOnCurrentRow(tfText, 3, true, false, true);
             
        addOnCurrentRow(fontChooserPanel);
        addOnCurrentRow(colorAndStrokePanel);
        addOnCurrentRow(textSizePanel);

        carriageReturn();
        addOnCurrentRow(dynamicDataPanel, 3, true, true, true);
    }
    /**
     * Arrange text size elements in a text size panel Overwrite this method in
     * sub class to modify the arrangement
     *
     * @return the text size panel
     */
    protected void setTextSizePanel() {
        cbMargin = new JCheckBox(resources.getString("EnableMargin"), true);
        cbFontLocked = new ActionCheckBox(resources.getString("FixedFontSize"), true) {
            public void actionPerformed(ActionEvent e) {
                if (isSelected()) {
                    cbFrameLocked.setSelected(false);
                }
                lcharNumber.setEnabled(cbFrameLocked.isSelected());
                nfCharNumber.setEnabled(cbFrameLocked.isSelected());
            }
        };
        lcharNumber = new JLabel(resources.getString("CharNumber"));
        nfCharNumber = new NumberField(0, 5);
        cbFrameLocked = new ActionCheckBox(resources.getString("FixedFrame"), false) {
            public void actionPerformed(ActionEvent e) {
                if (isSelected()) {
                    cbFontLocked.setSelected(false);
                }
                lcharNumber.setEnabled(cbFrameLocked.isSelected());
                nfCharNumber.setEnabled(cbFrameLocked.isSelected());
            }
        };
        lcharNumber.setEnabled(cbFrameLocked.isSelected());
        nfCharNumber.setEnabled(cbFrameLocked.isSelected());
        // Set contents
        textSizePanel.addOnCurrentRow(cbFrameLocked);
        textSizePanel.addOnCurrentRow(cbFontLocked, 2);
        textSizePanel.carriageReturn();
        textSizePanel.addOnCurrentRow(lcharNumber);
        textSizePanel.addOnCurrentRow(nfCharNumber, 2);
        textSizePanel.carriageReturn();
        textSizePanel.addOnCurrentRow(cbMargin);
        textSizePanel.carriageReturn();
        textSizePanel.addOnCurrentRow(lTransformation);
        textSizePanel.addOnCurrentRow(editTransformButton);
        textSizePanel.addOnCurrentRow(delTransformButton);
        textSizePanel.carriageReturn();
    }

    /**
     * Arrange dynamic elements in a dynamic panel Overwrite this method in sub
     * class to modify the arrangement
     */
    protected void setDynamicDataSource() {
        dstree = FilteredSourceTree.getFromPool("PropertiesPanel0");
       
        cbDataSource = new ActionCheckBox(resources.getString("UseADataSource"), source != null) {
            public void actionPerformed(ActionEvent e) {
                displayDynamicCustomisation(isSelected());
                updateWarnings();
            }
        };
        ldynamicDsId = new JTextField();
        ldynamicDsId.setPreferredSize(new Dimension(200, 20));
        ldynamicDsId.setEditable(true);
        ldynamicDsId.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String dsId = ldynamicDsId.getText();
                DataSource ds = null;
                try {
                    ds = DataSourcePool.global.getDataSourceWithId(dsId);
                } catch (DuplicateIdException e1) {
                }

                if (ds == null){
                    displayWarning(dsId + resources.getString("isNoAnExistingDataSource"));
                    ldynamicDsId.setText( source==null? "" : DataInfo.getId(source));
                } else {
                    // Set source with entered id
                    dstree.setSelectedValue(ds);

                    if (canSetDataSource(ds)){
                        source = ds;
                    }
                    updateWarnings()
                }
            }
        });
       
        cbDisplayName = new JCheckBox(resources.getString("Name"), false);
        cbDisplayValue = new ActionCheckBox(resources.getString("Value"), true) {
            public void actionPerformed(ActionEvent e) {
                cbxformat.setEnabled(isSelected());
                lformat.setEnabled(isSelected());
                lPrintfFormat.setEnabled(isSelected());
                tfPrintfFormat.setEnabled(isSelected());
            }
        };
        cbDisplayUnit = new JCheckBox(resources.getString("Unit"), false);
        cbDisplayComments = new JCheckBox(resources.getString("Comments"), false);

        // Initialise source tree
        dstree.setSelectedValue(source);
           
        lformat = new JLabel(resources.getString("ValueFormat"));
        cbxformat = new JComboBox();
        cbxformat.addItem(resources.getString("String"));
        cbxformat.addItem(resources.getString("Decimal"));
        cbxformat.addItem(resources.getString("Scientific"));
        cbxformat.addItem(resources.getString("Hexadecimal"));
        cbxformat.addItem(resources.getString("Octal"));
        cbxformat.addItem(resources.getString("Binary"));
        cbxformat.addItem(resources.getString("UseMapper"));
        cbxformat.addItem(resources.getString("Date"));
        cbxformat.addItem(resources.getString("Time"));
        cbxformat.addItem(resources.getString("DateTime"));
        cbxformat.addItem(resources.getString("PrintfFormat"));
        cbxformat.addItem(resources.getString("UseDataSourceFormat"));
        cbxformat.setEditable(false);
        // CARD PANEL
        cards = new JPanel();
        cards.setLayout(new CardLayout());
        // JSYnoptic formater
        lformatdigits = new JLabel(resources.getString("DecimalDigits:"));
        nfformat = new NumberField(0, 3);
        nfformat.setColumns(10);
        nfformat.setHorizontalAlignment(SwingConstants.RIGHT);
        GridBagPanel digitsPanel = new GridBagPanel();
        digitsPanel.addOnCurrentRow(lformatdigits);
        digitsPanel.addOnCurrentRow(nfformat);
        digitsPanel.carriageReturn();
        cards.add(digitsPanel, "jsynopticFormat");
        // Printf Formater
        GridBagPanel printfPanel = new GridBagPanel();
        lPrintfFormat = new JLabel(resources.getString("PrintfFormat"));
        tfPrintfFormat = new JTextField(10);
        printfPanel.addOnCurrentRow(lPrintfFormat);
        printfPanel.addOnCurrentRow(tfPrintfFormat);
        printfPanel.carriageReturn();
        cards.add(printfPanel, "printfFormat");
        cards.add(new GridBagPanel(), "noAttributes");
        // Mapper
        cbxmapper = new JComboBox();
        cbxmapper.addItem(resources.getString("=======NONE======="));
        int idx = 0;
        if (TextMapper.textMappers != null) {
            for (int i = 0; i < TextMapper.textMappers.size(); ++i) {
                TextMapper tm = (TextMapper) TextMapper.textMappers.get(i);
                if (tm.equals(mapper)) {
                    idx = i + 1;
                }
                cbxmapper.addItem(tm);
            }
        }
        cbxmapper.setEditable(false);
        cbxmapper.setSelectedIndex(idx);
        beditmapper = new JButton(resources.getString("Edit"));
        bnewmapper = new JButton(resources.getString("New"));
        bdelmapper = new JButton(resources.getString("Delete"));
        bduplicateMapper = new JButton(resources.getString("Duplicate"));
        if (idx == 0) {
            beditmapper.setEnabled(false);
            bdelmapper.setEnabled(false);
            bduplicateMapper.setEnabled(false);
        }
        cbxmapper.setRenderer(new ListCellRenderer() {
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                    boolean cellHasFocus) {
                String s = value.toString();
                if (s.length() > 18) {
                    s = s.substring(0, 15) + "...";
                }
                return new JLabel(s);
            }
        });
        beditmapper.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (mapper == null) {
                    return;
                }
                mapper.editDialog(TextPropertiesPanel.this.getOwner());
                cbxmapper.repaint(); // in case of name change
            }
        });
        bnewmapper.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                mapper = TextMapper.createTextMapperDialog(TextPropertiesPanel.this.getOwner());
                if (TextMapper.textMappers == null) {
                    TextMapper.textMappers = new Vector();
                }
                TextMapper.textMappers.add(mapper);
                cbxmapper.addItem(mapper);
                cbxmapper.setSelectedItem(mapper);
                cards.revalidate();
            }
        });
        bdelmapper.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (mapper == null) {
                    return;
                }
                if (TextMapper.textMappers != null) {
                    TextMapper.textMappers.remove(mapper);
                }
                cbxmapper.removeItem(mapper);
                cbxmapper.setSelectedIndex(0);
                mapper = null;
                bdelmapper.setEnabled(false);
                bduplicateMapper.setEnabled(false);
                beditmapper.setEnabled(false);
            }
        });
       
        bduplicateMapper.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (mapper == null) {
                    return;
                }
                try {
                    TextMapper tm =  (TextMapper)((TextMapper)mapper).clone();
                    if (TextMapper.textMappers != null) {
                        TextMapper.textMappers.add(tm);
                    }
                    mapper = tm;
                    cbxmapper.addItem(mapper);
                    cbxmapper.setSelectedItem(mapper);
                   
                }catch (CloneNotSupportedException cnse){
                }
            }
        });
       
        cbxmapper.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                int idx = cbxmapper.getSelectedIndex();
                if (idx == 0) {
                    beditmapper.setEnabled(false);
                    bdelmapper.setEnabled(false);
                    bduplicateMapper.setEnabled(false);
                    mapper = null;
                } else {
                    mapper = (TextMapper) cbxmapper.getItemAt(idx);
                    beditmapper.setEnabled(true);
                    bdelmapper.setEnabled(true);
                    bduplicateMapper.setEnabled(true);
                }
            }
        });
        GridBagPanel mapperPanel = new GridBagPanel();
        mapperPanel.addOnCurrentRow(cbxmapper, 2);
        mapperPanel.addOnCurrentRow(beditmapper);
        mapperPanel.addOnCurrentRow(bnewmapper);
        mapperPanel.addOnCurrentRow(bdelmapper);
        mapperPanel.addOnCurrentRow(bduplicateMapper);
        mapperPanel.carriageReturn();
        cards.add(mapperPanel, "mapper");
        CardLayout cl = (CardLayout) (cards.getLayout());
        if (cbxformat.getSelectedIndex() == TextShape.FORMAT_MAPPER) {
            cl.show(cards, "mapper");
        } else {
            cl.show(cards, "bounds");
        }
        tfText.getDocument().addDocumentListener(new DocumentListener() {
            public void insertUpdate(DocumentEvent e) {
                updateName();
            }

            public void removeUpdate(DocumentEvent e) {
                updateName();
            }

            public void changedUpdate(DocumentEvent e) {
                updateName();
            }

            private void updateName() {
                TextPropertiesPanel.this.setName(tfText.getText());
            }
        });
        setName(tfText.getText());
        cbxformat.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if ((cbxformat.getSelectedIndex() == TextShape.FORMAT_DECIMAL)
                        || (cbxformat.getSelectedIndex() == TextShape.FORMAT_SCIENTIFIC)) {
                    nfformat.setEnabled(true);
                    lformatdigits.setEnabled(true);
                } else {
                    nfformat.setEnabled(false);
                    lformatdigits.setEnabled(false);
                }
                if (cbxformat.getSelectedIndex() == TextShape.FORMAT_USE_DATA_SOURCE) {
                    if (DataInfo.getPrintfFormat(source) != null) {
                        tfPrintfFormat.setText(DataInfo.getPrintfFormat(source));
                    } else {
                        tfPrintfFormat.setText("");
                        if (JSynoptic.gui != null) {
                            JSynoptic.gui.setStatus(resources.getString("NoDataSourceFormat"));
                        } else {
                            System.err.println(resources.getString("NoDataSourceFormat"));
                        }
                    }
                    tfPrintfFormat.setEditable(false);
                } else if (cbxformat.getSelectedIndex() == TextShape.FORMAT_PRINTF) {
                    tfPrintfFormat.setEditable(true);
                }
                CardLayout cl = (CardLayout) (cards.getLayout());
                if (cbxformat.getSelectedIndex() == TextShape.FORMAT_MAPPER) {
                    cl.show(cards, "mapper");
                } else if ((cbxformat.getSelectedIndex() == TextShape.FORMAT_DATE)
                        || (cbxformat.getSelectedIndex() == TextShape.FORMAT_TIME)
                        || (cbxformat.getSelectedIndex() == TextShape.FORMAT_DATE_TIME)) {
                    cl.show(cards, "noAttributes");
                } else if ((cbxformat.getSelectedIndex() == TextShape.FORMAT_USE_DATA_SOURCE)
                        || (cbxformat.getSelectedIndex() == TextShape.FORMAT_PRINTF)
                        || (cbxformat.getSelectedIndex() == TextShape.FORMAT_DATE_TIME)) {
                    cl.show(cards, "printfFormat");
                } else {
                    cl.show(cards, "jsynopticFormat");
                }
            }
        });
        dstree.getSourceTree().addTreeSelectionListener(new TreeSelectionListener() {
            public void valueChanged(TreeSelectionEvent e) {
   boolean isMyEvent = false;
                if (e.getSource() instanceof SourceTree) {
                    SourceTree st = (SourceTree) e.getSource();
                    if (st.getParent() == dstree.getScrollPane().getViewport()) {
                        isMyEvent = true;
                    }
                }
                if (!isMyEvent) {
                    return;
                }
                if (!e.isAddedPath()) {
                    return;
                }
                Object o = dstree.getSelectedSourceOrCollection();
                updateWarnings();
                if ((o instanceof DataSource) && canSetDataSource((DataSource) o)) {
                    source = (DataSource) o;
                } else {
                    source = null;
                }
                // Set textpropertiespanel name
                String name = DataInfo.getLabel(source);
                if ((name == null) || (name.equals(""))) {
                    name = tfText.getText();
                }
                setName(name);
                String id = DataInfo.getId(source);
                if ((id != null) && !(id.equals(""))) {
                    ldynamicDsId.setText(id);
                } else {
                    ldynamicDsId.setText("");
                }
                if ((source != null) && (cbxformat.getSelectedIndex() == TextShape.FORMAT_USE_DATA_SOURCE)) {
                    if (DataInfo.getPrintfFormat(source) != null) {
                        tfPrintfFormat.setText(DataInfo.getPrintfFormat(source));
                    } else {
                        tfPrintfFormat.setText("");
                        if (JSynoptic.gui != null) {
                            JSynoptic.gui.setStatus(resources.getString("NoDataSourceFormat"));
                        } else {
                            System.err.println(resources.getString("NoDataSourceFormat"));
                        }
                    }
                    tfPrintfFormat.setEditable(false);
                }
            }
        });
        displayStrokeCustomisation(cbdraw.isSelected());
        String id = DataInfo.getId(source);
     
      
        if ((id != null) && !(id.equals(""))) {
            ldynamicDsId.setText(id);
        } else {
            ldynamicDsId.setText("");
        }
       
        // CREATE CONTENTS
        dynamicDataPanel.addOnCurrentRow(cbDataSource, 2);
        dynamicDataPanel.addOnCurrentRow(ldynamicDsId, 1, true, false, true);
        dynamicDataPanel.addOnCurrentRow(cbDisplayName);
        dynamicDataPanel.addOnCurrentRow(cbDisplayValue);
        dynamicDataPanel.addOnCurrentRow(cbDisplayUnit);
        dynamicDataPanel.addOnCurrentRow(cbDisplayComments);
        dynamicDataPanel.carriageReturn();
        dynamicDataPanel.addOnCurrentRow(dstree, 1, true, true, true);
        dynamicDataPanel.addOnCurrentRow(lformat);
        dynamicDataPanel.addOnCurrentRow(cbxformat, 3);
        dynamicDataPanel.addOnCurrentRow(cards, 1, true, false, true);
    }

    /**
     * Overwrite this method for specific needs regarding selected data source
     * in source tree
     *
     * @param ds ,
     *            the data source to asign to text shape
     * @return true if operation can be performed
     */
    protected boolean canSetDataSource(DataSource ds) {
        return true;
    }

    /*
     * (non-Javadoc)
     *
     * @see jsynoptic.builtin.ui.PropertiesPanel1D#updateWarnings()
     */
    public boolean updateWarnings() {
        boolean res;
       
        if ((cbDataSource.isSelected()) && (!(dstree.getSelectedSourceOrCollection() instanceof DataSource))) {
            displayWarning(resources.getString("selectADataSource"));
            res = true;
           
        } else {
            res = super.updateWarnings();
        }
       
        return res;
    }

    public void updateSourceTree() {
        // Set viewport before
        // select value to prevent
        // other shapes using same
        // source tree
        // from having their source value changed
        dstree.getScrollPane().setViewportView(dstree.getSourceTree());
          
        dstree.setSelectedValue(source);
        dstree.setEnabled(cbDataSource.isSelected());
    }

    protected void displayDynamicCustomisation(boolean display) {
        dstree.setEnabled(display);
        cbxformat.setEnabled(display);
        lformat.setEnabled(display);
        cbxformat.setEnabled(display);
        tfText.setEnabled(!display);
        cbDisplayUnit.setEnabled(display);
        cbDisplayComments.setEnabled(display);
        cbDisplayName.setEnabled(display);
        cbDisplayValue.setEnabled(display);
        tfPrintfFormat.setEnabled(display);
        lPrintfFormat.setEnabled(display);
        ldynamicDsId.setVisible(display);
        if (display) {
            dstree.setSelectedValue(source);
            dstree.getScrollPane().setViewportView(dstree.getSourceTree());
            
            ActionListener[] al = cbxformat.getActionListeners();
            if (al != null) {
                for (int i = 0; i < al.length; ++i) {
                    al[i].actionPerformed(new ActionEvent(cbxformat, 0, ""));
                }
            }
            String name = DataInfo.getLabel(source);
            if ((name == null) || (name.equals(""))) {
                name = tfText.getText();
            }
            TextPropertiesPanel.this.setName(name);
        } else {
            source = null;
            lformatdigits.setEnabled(false);
            nfformat.setEnabled(false);
            TextPropertiesPanel.this.setName(tfText.getText());
        }
    }

    /*
     * (non-Javadoc)
     *
     * @see java.awt.Component#setName(java.lang.String)
     */
    public void setName(String name) {
        String oldName = getName();
        if (oldName == null) {
            oldName = "";
        }
        if (name == null) {
            name = "";
        }
        super.setName(name);
        if (!oldName.equals(name)) {
            changes.firePropertyChange("name", oldName, name);
        }
    }

    /*
     * (non-Javadoc)
     *
     * @see java.lang.Object#toString()
     */
    public String toString() {
        String name = getName();
        if (name == null) {
            return super.toString();
        } else {
            return name;
        }
    }

    protected String fillColorChooserTitle() {
        return resources.getString("ChooseBackgroundColor");
    }

    protected String fillColorLabel() {
        return resources.getString("UseBackgroundColor");
    }

    protected String lineColorChooserTitle() {
        return resources.getString("ChooseFrameColor");
    }

    protected String lineColorLabel() {
        return resources.getString("DisplayFrame");
    }

    public String[] getPropertyNames() {
        if (_propertyNames == null) {
            _propertyNames = new TextShape.TextShapePropertiesNames().getPropertyNames();
        }
        return _propertyNames;
    }

    /*
     * (non-Javadoc)
     *
     * @see simtools.ui.JPropertiesPanel#getPropertyValue(java.lang.String)
     */
    public Object getPropertyValue(String name) {
        Object res = super.getPropertyValue(name);
        if (name.equalsIgnoreCase("TEXT")) {
            res = tfText.getText();
        } else if (name.equalsIgnoreCase("TEXT_COLOR")) {
            res = fontChooserPanel.getTextColor();
        } else if (name.equalsIgnoreCase("DISPLAY_NAME")) {
            res = new Boolean(cbDisplayName.isSelected());
        } else if (name.equalsIgnoreCase("DISPLAY_VALUE")) {
            res = new Boolean(cbDisplayValue.isSelected());
        } else if (name.equalsIgnoreCase("DISPLAY_UNIT")) {
            res = new Boolean(cbDisplayUnit.isSelected());
        } else if (name.equalsIgnoreCase("DISPLAY_COMMENTS")) {
            res = new Boolean(cbDisplayComments.isSelected());
        } else if (name.equalsIgnoreCase("TEXT_SOURCE")) {
            res = cbDataSource.isSelected() ? source : null;
        } else if (name.equalsIgnoreCase("VALUE_FORMAT")) {
            res = new Integer(cbxformat.getSelectedIndex());
        } else if (name.equalsIgnoreCase("FORMAT_MAPPER")) {
            res = mapper;
        } else if (name.equalsIgnoreCase("DECIMAL_DIGITS")) {
            res = new Integer((int) nfformat.getLongValue());
        } else if (name.equalsIgnoreCase("VALUE_PRINTF_FORMAT")) {
            res = (!tfPrintfFormat.getText().equals("")) ? tfPrintfFormat.getText() : null;
        } else if (name.equalsIgnoreCase("TEXT_MAPPER")) {
            res = fontChooserPanel.getTextMapper();
        } else if (name.equalsIgnoreCase("TEXT_MAPPER_SOURCE")) {
            res = fontChooserPanel.getTextMapperSource();
        } else if (name.equalsIgnoreCase("ENABLE_MARGIN")) {
            res = new Boolean(cbMargin.isSelected());
        } else if (name.equalsIgnoreCase("FONT_LOCK")) {
            res = new Boolean(cbFontLocked.isSelected());
        } else if (name.equalsIgnoreCase("FONT")) {
            fontChooserPanel.apply();
            res = fontChooserPanel.getCurrentFont();
        } else if (name.equalsIgnoreCase("FRAME_LOCK")) {
            res = new Boolean(cbFrameLocked.isSelected());
        } else if (name.equalsIgnoreCase("CHAR_NUMBER")) {
            res = new Integer((int) nfCharNumber.getLongValue());
        }
        return res;
    }

    /*
     * (non-Javadoc)
     *
     * @see simtools.ui.JPropertiesPanel#setPropertyValue(java.lang.String,
     *      java.lang.Object)
     */
    public void setPropertyValue(String name, Object value) {
        if (name.equalsIgnoreCase("TEXT")) {
            if (value instanceof String) {
                tfText.setText((String) value);
            }
        } else if (name.equalsIgnoreCase("TEXT_COLOR")) {
            if (value instanceof Color) {
                fontChooserPanel.setTextColor((Color) value);
                fontChooserPanel.getTextColorButton().setBackground((Color) value);
            }
        } else if (name.equalsIgnoreCase("DISPLAY_NAME")) {
            if (value instanceof Boolean) {
                cbDisplayName.setSelected(((Boolean) value).booleanValue());
            }
        } else if (name.equalsIgnoreCase("DISPLAY_VALUE")) {
            if (value instanceof Boolean) {
                cbDisplayValue.setSelected(((Boolean) value).booleanValue());
            }
        } else if (name.equalsIgnoreCase("DISPLAY_UNIT")) {
            if (value instanceof Boolean) {
                cbDisplayUnit.setSelected(((Boolean) value).booleanValue());
            }
        } else if (name.equalsIgnoreCase("DISPLAY_COMMENTS")) {
            if (value instanceof Boolean) {
                cbDisplayComments.setSelected(((Boolean) value).booleanValue());
            }
        } else if (name.equalsIgnoreCase("VALUE_FORMAT")) {
            if (value instanceof Integer) {
                cbxformat.setSelectedIndex(((Integer) value).intValue());
            }
        } else if (name.equalsIgnoreCase("FORMAT_MAPPER")) {
            if (value instanceof TextMapper) {
                mapper = (TextMapper) value;
                for (int i = 0; i < cbxmapper.getItemCount(); i++) {
                    if (cbxmapper.getItemAt(i).equals(mapper)) {
                        cbxmapper.setSelectedIndex(i);
                        break;
                    }
                }
            }
        } else if (name.equalsIgnoreCase("TEXT_SOURCE")) {
            if (value instanceof DataSource) {
                source = (DataSource) value;
            } else {
                source = null;
            }
            cbDataSource.setSelected(source != null);
            cbDataSource.apply();
        } else if (name.equalsIgnoreCase("DECIMAL_DIGITS")) {
            if (value instanceof Integer) {
                nfformat.setValue(((Integer) value).intValue());
            }
        } else if (name.equalsIgnoreCase("VALUE_PRINTF_FORMAT")) {
            if (value instanceof String) {
                tfPrintfFormat.setText((String) value);
            }
        } else if (name.equalsIgnoreCase("TEXT_MAPPER")) {
            if (value instanceof ColorMapper) {
                fontChooserPanel.setTextMapper((ColorMapper) value);
            } else {
                fontChooserPanel.setTextMapper(null);
            }
        } else if (name.equalsIgnoreCase("TEXT_MAPPER_SOURCE")) {
            if (value instanceof DataSource) {
                fontChooserPanel.setTextMapperSource((DataSource) value);
            } else {
                fontChooserPanel.setTextMapperSource(null);
            }
        } else if (name.equalsIgnoreCase("ENABLE_MARGIN")) {
            if (value instanceof Boolean) {
                cbMargin.setSelected(((Boolean) value).booleanValue());
            }
        } else if (name.equalsIgnoreCase("FONT_LOCK")) {
            if (value instanceof Boolean) {
                cbFontLocked.setSelected(((Boolean) value).booleanValue());
            }
        } else if (name.equalsIgnoreCase("FONT")) {
            if (value instanceof Font) {
                fontChooserPanel.setCurrentFont((Font) value);
            }
        } else if (name.equalsIgnoreCase("FRAME_LOCK")) {
            if (value instanceof Boolean) {
                cbFrameLocked.setSelected(((Boolean) value).booleanValue());
                lcharNumber.setEnabled(cbFrameLocked.isSelected());
                nfCharNumber.setEnabled(cbFrameLocked.isSelected());
            }
        } else if (name.equalsIgnoreCase("CHAR_NUMBER")) {
            if (value instanceof Integer) {
                nfCharNumber.setValue(((Integer) value).intValue());
            }
        }
        super.setPropertyValue(name, value);
    }
}
TOP

Related Classes of jsynoptic.builtin.ui.TextPropertiesPanel

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.