key0-96/
key0-96/doc/key/
key0-96/doc/key/credits/
key0-96/doc/key/developers/
key0-96/doc/key/developers/resources/
key0-96/setup/caves/
key0-96/setup/help/
key0-96/setup/ruins/
key0-96/src/
key0-96/src/commands/
key0-96/src/events/
key0-96/src/hack/
key0-96/src/sql/
key0-96/src/swing/
key0-96/src/talker/forest/
key0-96/src/talker/objects/
key0-96/src/terminals/
/*
**               j###t  ########## ####   ####
**              j###t   ########## ####   ####
**             j###T               "###L J###"
**          ######P'    ##########  #########
**          ######k,    ##########   T######T
**          ####~###L   ####
**          #### q###L  ##########   .#####
**          ####  \###L ##########   #####"
**
**  $Id$
**
**  Class History
**  
**  Date        Name         Description
**  ---------|------------|-----------------------------------------------
**  06Nov98    subtle       created
**
*/

package key;

public final class TextParagraphLengthWrapper extends AtomicSpecial
{
	int byteLimit;
	int lineLimit;
	
	TextParagraphLengthWrapper( int bl, int ll )
	{
		byteLimit = bl;
		lineLimit = ll;
	}

	public int getByteLimit()
	{
		return( byteLimit );
	}

	public int getLineLimit()
	{
		return( lineLimit );
	}
	
	public boolean canUseWith( AtomicElement ae )
	{
		return( ae.getClassOf() == TextParagraph.class );
	}
	
	public Object validateNewValue( Object newValue )
	{
		if( newValue == null )
			return null;
		
		TextParagraph tp = (TextParagraph) newValue;
		
			//  check the byte count
		String s = tp.getText();
		if( s.length() > byteLimit )
			throw new LimitExceededException( "too many characters: " + s.length() + " > " + byteLimit + "." );
		
		int ct = tp.numberOfNewLines();
		
		if( ct > lineLimit )
			throw new LimitExceededException( "too many lines: " + ct + " > " + lineLimit + "." );
		
		return( newValue );
	}
}