com.unitesk.atp.text.filters
Class IndentFilter

java.lang.Object
  extended by com.unitesk.atp.text.filters.Filter
      extended by com.unitesk.atp.text.filters.IndentFilter
All Implemented Interfaces:
TextReceiver

public class IndentFilter
extends Filter

This filter manages indent levels and inserts spaces according to the current indent level at the start of every line.

Version:
$Id: IndentFilter.java,v 1.1 2004/10/09 06:36:40 all-x Exp $
Author:
Alexey Demakov

Field Summary
static int DEFAULT_INDENT_STEP
          The default value of indent step.
 
Fields inherited from class com.unitesk.atp.text.filters.Filter
client
 
Constructor Summary
IndentFilter(TextReceiver client)
          Constructs indent filter with default indent step.
IndentFilter(TextReceiver client, int indent_step)
          Constructs indent server with given indent step.
 
Method Summary
static String fill(char c, int l)
          Fills a string with characters.
 int getIndent()
          Returns the current indent level.
 int getIndentStep()
          Returns the indent step.
 boolean isLineStart()
          Returns the current state of the line start indicator.
 void nl()
          Receives line separator and passes it to the client.
 void popIndent()
          Restores the previous indent level.
 void pushIndent(int indent)
          Pushes in stack new indent level.
 void txt(String str)
          Receives string and passes it to the client inserting appropriate number of spaces at the start of each line
 
Methods inherited from class com.unitesk.atp.text.filters.Filter
getClient
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_INDENT_STEP

public static final int DEFAULT_INDENT_STEP
The default value of indent step.

See Also:
Constant Field Values
Constructor Detail

IndentFilter

public IndentFilter(TextReceiver client)
Constructs indent filter with default indent step.

See Also:
DEFAULT_INDENT_STEP

IndentFilter

public IndentFilter(TextReceiver client,
                    int indent_step)
Constructs indent server with given indent step.

Parameters:
indent_step - the indent step value
Throws:
IllegalArgumentException - if indent_step <= 0
Method Detail

getIndentStep

public int getIndentStep()
Returns the indent step.


pushIndent

public void pushIndent(int indent)
Pushes in stack new indent level.

Parameters:
indent - the new indent level
Throws:
IllegalArgumentException - if indent is negative

getIndent

public int getIndent()
Returns the current indent level.

Throws:
EmptyStackException - if no indent level is in stack.

popIndent

public void popIndent()
Restores the previous indent level.

Throws:
EmptyStackException - if no indent level is in stack.

txt

public void txt(String str)
Receives string and passes it to the client inserting appropriate number of spaces at the start of each line

Specified by:
txt in interface TextReceiver
Overrides:
txt in class Filter
Parameters:
str - the string to receive
Throws:
NullPointerException - if str is null

nl

public void nl()
Receives line separator and passes it to the client. The next string received by TextReceiver.txt(String) will be prefixed by indent.

Specified by:
nl in interface TextReceiver
Overrides:
nl in class Filter
Throws:
NullPointerException - if c is null

isLineStart

public boolean isLineStart()
Returns the current state of the line start indicator.


fill

public static String fill(char c,
                          int l)
Fills a string with characters.

Parameters:
c - the character to fill
l - the length of the string
Returns:
The string of the length l filled by c. If l < 0 empty string is returned.


Copyright © 2001-2006 ISP RAS, RedVerst Group. All Rights Reserved.