/*====================================================================*\ Function.java Function class. ------------------------------------------------------------------------ This file is part of FuncPlotter, a combined Java application and applet for plotting explicit functions in one variable. Copyright 2005-2007 Andy Morgan-Richards. FuncPlotter is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . \*====================================================================*/ // IMPORTS import java.awt.Color; //---------------------------------------------------------------------- // FUNCTION CLASS class Function implements Cloneable { //////////////////////////////////////////////////////////////////////// // Constants //////////////////////////////////////////////////////////////////////// public static final char SEPARATOR_CHAR = ';'; //////////////////////////////////////////////////////////////////////// // Constructors //////////////////////////////////////////////////////////////////////// public Function( Color colour, Expression expression ) { this( colour, expression, true ); } //------------------------------------------------------------------ public Function( Color colour, Expression expression, boolean visible ) { this.colour = colour; this.expression = expression; this.visible = visible; } //------------------------------------------------------------------ //////////////////////////////////////////////////////////////////////// // Instance methods : overriding methods //////////////////////////////////////////////////////////////////////// public Object clone( ) { Function function = null; try { function = (Function)super.clone( ); function.colour = new Color( colour.getRGB( ) ); try { function.expression = new Expression( expression.toString( ) ); } catch ( Expression.Exception e ) { // ignore: no exception is thrown } } catch ( CloneNotSupportedException e ) { e.printStackTrace( ); } return function; } //------------------------------------------------------------------ public boolean equals( Object obj ) { if ( obj instanceof Function ) { Function function = (Function)obj; return ( colour.equals( function.colour ) && expression.equals( function.expression ) ); } return false; } //------------------------------------------------------------------ public String toString( ) { return expression.toString( ); } //------------------------------------------------------------------ //////////////////////////////////////////////////////////////////////// // Instance methods //////////////////////////////////////////////////////////////////////// public Color getColour( ) { return colour; } //------------------------------------------------------------------ public Expression getExpression( ) { return expression; } //------------------------------------------------------------------ public boolean isVisible( ) { return visible; } //------------------------------------------------------------------ public void setVisible( boolean visible ) { this.visible = visible; } //------------------------------------------------------------------ //////////////////////////////////////////////////////////////////////// // Instance variables //////////////////////////////////////////////////////////////////////// private Color colour; private Expression expression; private boolean visible; } //----------------------------------------------------------------------