/*
 This file is part of the software framework JStatCom, 
 a library for building applications for data based analysis.

 Copyright (C) 2000-2005  Markus Kraetzig

 This library 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 library 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 library; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 USA
 */

package com.jstatcom.model.control;

import java.awt.Color;

import javax.swing.border.BevelBorder;
import javax.swing.border.TitledBorder;

import com.jstatcom.component.ResultField;
import com.jstatcom.model.JSCTypes;
import com.jstatcom.model.Symbol;
import com.jstatcom.model.SymbolEvent;
import com.jstatcom.model.SymbolListener;

/**
 * Default symbol panel to be used for all types that do not have a distinct
 * panel. It uses the display method of JSCData to
 * print the values to a text area.
 * 
 * @author Markus Kraetzig 
 */
public final class DefaultSymbolPanel extends SymbolPanel {

    private JSCTypes currentType = null;

    private ResultField resultField = null;

    /**
     * Creates a DefaultSymbolPanel
     */
    public DefaultSymbolPanel() {
        super();
        initialize();
    }

    /**
     * This method initializes this
     * 
     * @return void
     */
    private void initialize() {
        this.setLayout(new java.awt.BorderLayout());
        this.add(getResultField(), java.awt.BorderLayout.CENTER);
        this.setSize(400, 236);
        setBorder(new TitledBorder(new BevelBorder(BevelBorder.LOWERED),
                "Value", TitledBorder.RIGHT, TitledBorder.TOP));
        getResultField().setText("");
        getResultField().getTextArea().setBackground(Color.LIGHT_GRAY);
    }

    /*
     * @see com.jstatcom.model.symbolpanels.SymbolPanel#setSymbol(com.jstatcom.model.Symbol)
     */
    public void setSymbol(Symbol symbol) {
        if (symbol == null)
            throw new IllegalArgumentException("Argument was null.");

        if (currentType != symbol.type) {
            currentType = symbol.type;
            setBorder(new TitledBorder(new BevelBorder(BevelBorder.LOWERED),
                    "Value of " + symbol.type + "", TitledBorder.RIGHT,
                    TitledBorder.TOP));
        }
        setDisplay(symbol);
        symbol.addSymbolListener(new SymbolListener() {
            public void valueChanged(SymbolEvent evt) {
                setDisplay(evt.getSource());
            }
        });
    }

    private void setDisplay(Symbol sym) {
        if (sym.isEmpty()) {
            getResultField().setText("");
            getResultField().getTextArea().setBackground(Color.LIGHT_GRAY);
        } else {
            getResultField().setText(sym.display());
            getResultField().getTextArea().setBackground(Color.WHITE);
        }

    }

    /**
     * This method initializes resultField
     * 
     * @return com.jstatcom.component.ResultField
     */
    private com.jstatcom.component.ResultField getResultField() {
        if (resultField == null) {
            resultField = new com.jstatcom.component.ResultField();
            resultField.setEditable(false);
        }
        return resultField;
    }

    /**
     * Empty implementation.
     * 
     * @param editable
     */
    public void setSymbolEditable(boolean editable) {

    }
} // @jve:visual-info decl-index=0 visual-constraint="10,10"

 

Ads help maintain this website.