/*
 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.equation;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.LayoutManager;

import javax.swing.JPanel;

import com.jstatcom.model.Scope;

/**
 * Abstract class for all equation term components. 
 * 
 * @author Alexander Benkwitz, Markus Kraetzig
 */
public abstract class EqTerm extends JPanel {

	// Indicates if there is data for display.
	private boolean dataAvailable;
	private Scope symbolScope = Scope.GLOBAL;

	/**
	 * Default constructor.
	 */
	public EqTerm() {
		this(new FlowLayout());
	}

	/**
	 * Constructor for a layout.
	 * 
	 * @param layout java.awt.LayoutManager
	 */
	public EqTerm(LayoutManager layout) {
		super(layout);
		dataAvailable = false;
		setVisible(false);
	}

	/**
	 * Gets the maximum size, which is equal to the preferred size.
	 * 
	 * @return java.awt.Dimension
	 */
	public Dimension getMaximumSize() {
		return getPreferredSize();
	}

	/**
	 * Gets the minimum size that is not less than 20.
	 * 
	 * @return java.awt.Dimension
	 */
	public Dimension getMinimumSize() {
		Dimension dim = super.getMinimumSize();
		dim.width = Math.max(20, dim.width);
		dim.height = Math.max(20, dim.height);
		return dim;
	}

	/**
	 * Gets the preferred size which is not less than the
	 * minimum size.
	 * 
	 * @return java.awt.Dimension
	 */
	public Dimension getPreferredSize() {
		Dimension dim = getMinimumSize();
		Dimension dimPref = super.getPreferredSize();
		dim.width = Math.max(dimPref.width, dim.width);
		dim.height = Math.max(dimPref.height, dim.height);
		return dim;
	}

	/**
	 * Sets whether data is available and manages 
	 * visibility accordingly.
	 * 
	 * @param isDataAvailable true if available, component
	 *                        will be set visible
	 */
	public void setDataAvailable(boolean isDataAvailable) {
		dataAvailable = isDataAvailable;
		setVisible(dataAvailable);
	}

	/**
	 * Handles the leading sign property.
	 * 
	 * @param isVisible true if sign is visible
	 */
	public abstract void setLeadingSignVisible(boolean isVisible);

	/**
	 * Extends the super method by firering the (boolean) property change "visible".
	 * 
	 * @param aFlag  true to make the component visible
	 */
	public void setVisible(boolean aFlag) {
		aFlag = aFlag && dataAvailable;
		boolean oldValue = isVisible();
		if (aFlag != oldValue) {
			super.setVisible(aFlag);
			firePropertyChange("visible", oldValue, isVisible());
		}
	}
	/**
	 * Gets the current scope, which defines which symbol
	 * table to use (local, global
	 * or upper).
	 * 
	 * @return symbol scope
	 */
	public Scope getSymbolScope() {
		return symbolScope;
	}

	/**
	 * Sets the symbol scope, which defines which symbol
	 * table to use (local, global
	 * or upper). 
	 * 
	 * @param scope the symbol scope
	 * @throws IllegalArgumentException if (scope == null)
	 */
	public void setSymbolScope(Scope scope) {
		if (scope == null)
			throw new IllegalArgumentException("Argument was null.");
		symbolScope = scope;
	}
}
 

Ads help maintain this website.