net.sf.mmm.util.text.base
Class DefaultLineWrapper

java.lang.Object
  extended by net.sf.mmm.util.component.base.AbstractComponent
      extended by net.sf.mmm.util.component.base.AbstractLoggableComponent
          extended by net.sf.mmm.util.text.base.AbstractLineWrapper
              extended by net.sf.mmm.util.text.base.DefaultLineWrapper
All Implemented Interfaces:
LineWrapper

@Singleton
@Named
public class DefaultLineWrapper
extends AbstractLineWrapper

This is the default implementation of the LineWrapper interface.

Since:
2.0.0
Author:
Joerg Hohwiller (hohwille at users.sourceforge.net)

Nested Class Summary
private static class DefaultLineWrapper.AutoAdjustInfo
           
protected static class DefaultLineWrapper.CellBuffer
          This inner class represents the buffer used for the text of a text-cell (a line of content inside a column).
protected static class DefaultLineWrapper.ColumnState
          This class represents the state of a text-column.
protected static class DefaultLineWrapper.TextSegment
          This class represents a segment of some text.
protected static class DefaultLineWrapper.TextSegmentType
          This enum contains the possbile types of a DefaultLineWrapper.TextSegment.
 
Field Summary
private  HyphenatorBuilder hyphenatorBuilder
           
 
Constructor Summary
DefaultLineWrapper()
          The constructor.
 
Method Summary
protected  void append(Appendable appendable, DefaultLineWrapper.ColumnState state, DefaultLineWrapper.CellBuffer cellBuffer)
          This method appends the text of a single cell (line of a single column).
protected  void appendCellBuffer(DefaultLineWrapper.ColumnState state, DefaultLineWrapper.CellBuffer buffer)
          This method fills the DefaultLineWrapper.CellBuffer with the payload for the current cell.
protected  void appendWithAlignment(Appendable appendable, DefaultLineWrapper.ColumnState state, boolean doIndentThisLine, DefaultLineWrapper.CellBuffer cellBuffer)
          This method actually appends the text for a single line of a single column according to alignment.
protected  void autoAdjustWidthOfColumns(DefaultLineWrapper.ColumnState[] columnStates, TextTableInfo tableInfo)
          This method calculates the width of the columns to auto-adjust.
protected  void doInitialize()
          This method performs the actual initialization.
protected  void fill(Appendable appendable, char filler, int count)
          This method fills the Appendable with the given count of filler characters.
protected  HyphenatorBuilder getHyphenatorBuilder()
           
private static boolean isIn(char c, char[] chars)
          This method determines if the given character c is contained in chars.
 void setHyphenatorBuilder(HyphenatorBuilder hyphenatorBuilder)
           
private  boolean verifyWithOfColumns(DefaultLineWrapper.ColumnState[] columnStates, TextTableInfo tableInfo)
          This method verifies that the width of the columns are sane.
 int wrap(Appendable appendable, TextTableInfo tableInfo, TextColumn... columns)
          This method is like LineWrapper.wrap(Appendable, TextTableInfo, String, TextColumnInfo, String, TextColumnInfo, String, TextColumnInfo) for any number of columns.
 
Methods inherited from class net.sf.mmm.util.text.base.AbstractLineWrapper
wrap, wrap, wrap
 
Methods inherited from class net.sf.mmm.util.component.base.AbstractLoggableComponent
getLogger, setLogger
 
Methods inherited from class net.sf.mmm.util.component.base.AbstractComponent
doInitialized, getInitializationState, initialize
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hyphenatorBuilder

private HyphenatorBuilder hyphenatorBuilder
See Also:
getHyphenatorBuilder()
Constructor Detail

DefaultLineWrapper

public DefaultLineWrapper()
The constructor.

Method Detail

getHyphenatorBuilder

protected HyphenatorBuilder getHyphenatorBuilder()
Returns:
the hyphenatorBuilder

setHyphenatorBuilder

@Inject
public void setHyphenatorBuilder(HyphenatorBuilder hyphenatorBuilder)
Parameters:
hyphenatorBuilder - is the hyphenatorBuilder to set

doInitialize

protected void doInitialize()
This method performs the actual initialization. It is called when AbstractComponent.initialize() is invoked for the first time.
ATTENTION:
When you override this method from a sub-class you need to do a super.AbstractComponent.doInitialize().

Overrides:
doInitialize in class AbstractLoggableComponent

autoAdjustWidthOfColumns

protected void autoAdjustWidthOfColumns(DefaultLineWrapper.ColumnState[] columnStates,
                                        TextTableInfo tableInfo)
This method calculates the width of the columns to auto-adjust.

Parameters:
columnStates - are the DefaultLineWrapper.ColumnStates.
tableInfo - is the TextTableInfo containing the available width.

wrap

public int wrap(Appendable appendable,
                TextTableInfo tableInfo,
                TextColumn... columns)
This method is like LineWrapper.wrap(Appendable, TextTableInfo, String, TextColumnInfo, String, TextColumnInfo, String, TextColumnInfo) for any number of columns.

Parameters:
appendable - is the target where to append to.
tableInfo - is the TextTableInfo for the general layout.
columns - are the columns to append.
Returns:
the number of lines that have been appended excluding the first line. In other words the number of line separators that have been appended.

verifyWithOfColumns

private boolean verifyWithOfColumns(DefaultLineWrapper.ColumnState[] columnStates,
                                    TextTableInfo tableInfo)
This method verifies that the width of the columns are sane.

Parameters:
columnStates - are the DefaultLineWrapper.ColumnStates.
tableInfo - is the TextTableInfo.
Returns:
true if the width is sane, false otherwise.

isIn

private static boolean isIn(char c,
                            char[] chars)
This method determines if the given character c is contained in chars.

Parameters:
c - is the character to check.
chars - is the array with the matching characters.
Returns:
true if c is contained in chars, false otherwise.

appendCellBuffer

protected void appendCellBuffer(DefaultLineWrapper.ColumnState state,
                                DefaultLineWrapper.CellBuffer buffer)
This method fills the DefaultLineWrapper.CellBuffer with the payload for the current cell.

Parameters:
state - is the DefaultLineWrapper.ColumnState.
buffer - is the DefaultLineWrapper.CellBuffer.

append

protected void append(Appendable appendable,
                      DefaultLineWrapper.ColumnState state,
                      DefaultLineWrapper.CellBuffer cellBuffer)
               throws IOException
This method appends the text of a single cell (line of a single column).

Parameters:
appendable - is the Appendable where to append the text to.
state - the DefaultLineWrapper.ColumnState of the current column where to fill a single cell.
cellBuffer - is the DefaultLineWrapper.CellBuffer for the payload of the current cell.
Throws:
IOException - if caused by the Appendable.

appendWithAlignment

protected void appendWithAlignment(Appendable appendable,
                                   DefaultLineWrapper.ColumnState state,
                                   boolean doIndentThisLine,
                                   DefaultLineWrapper.CellBuffer cellBuffer)
                            throws IOException
This method actually appends the text for a single line of a single column according to alignment.

Parameters:
appendable - is where to append to.
state - is the current DefaultLineWrapper.ColumnState.
doIndentThisLine - - true if the current cell should be indented, false otherwise.
cellBuffer - is the text to align and append.
Throws:
IOException - if throw by the Appendable.

fill

protected void fill(Appendable appendable,
                    char filler,
                    int count)
             throws IOException
This method fills the Appendable with the given count of filler characters.

Parameters:
appendable - is the Appendable to fill.
filler - is the fill-character.
count - is the number of fill-characters (filler) to add.
Throws:
IOException - if caused by the Appendable.


Copyright © 2001-2010 mmm-Team. All Rights Reserved.