Unified Typesetting API M1-20040817

de.inghuimische.uta.linebreaking
Class FirstFitAlgorithm

java.lang.Object
  extended byde.inghuimische.uta.linebreaking.AbstractLinebreakAlgorithm
      extended byde.inghuimische.uta.linebreaking.LineBasedBreakAlgorithm
          extended byde.inghuimische.uta.linebreaking.FirstFitAlgorithm
All Implemented Interfaces:
LinebreakAlgorithm, QManageable

public class FirstFitAlgorithm
extends LineBasedBreakAlgorithm

A simple implementation of a line based break algorithm. This algorithm implements the first-fit strategy. The first item that does not fit into the current line is moved to the next. This is a sample implementation. Using the simpleFit switch you can choose between a simple first-fit implementation and a shortest-path based one. The shortest-path version demonstrates the use of the BreakpointUtil class.

Internally a state pattern is used to switch between the two implementations.

Author:
Christian Ziesemer

Nested Class Summary
 class FirstFitAlgorithm.ShortestPathFirstFit
          More complex implementation of the first-fit algorithm, meant as proof-of-concept.
 class FirstFitAlgorithm.SimpleFirstFit
          Simple first-fit implementation conforming to UTA.
 class FirstFitAlgorithm.State
          Simple class with utility methods to allow state pattern.
 
Field Summary
protected  Vector breakpoints
          The breakpoints found.
 
Fields inherited from class de.inghuimische.uta.linebreaking.AbstractLinebreakAlgorithm
features, lineNumber, lineWidthModel
 
Constructor Summary
FirstFitAlgorithm()
          Constructs a new line break algorithm with the simpler first-fit implementation not using BreakpointUtil.
FirstFitAlgorithm(boolean simpleFit)
          The simpleFit switch tells which implementation of the first-fit method should be used.
 
Method Summary
 void consider(Item newItem)
          Tells the line breaker that he has to consider a newly generated item.
 List getBreakpoints()
          Returns the generated breakpoints.
 void linebreak(String text)
          This is a simple implementation of the first-fit algorithm (break before the first item that does not fit into the line).
 
Methods inherited from class de.inghuimische.uta.linebreaking.AbstractLinebreakAlgorithm
getFeatures, getLineWidthModel, nextLineWidth, setLineWidthModel
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

breakpoints

protected Vector breakpoints
The breakpoints found.

Constructor Detail

FirstFitAlgorithm

public FirstFitAlgorithm()
Constructs a new line break algorithm with the simpler first-fit implementation not using BreakpointUtil.


FirstFitAlgorithm

public FirstFitAlgorithm(boolean simpleFit)
The simpleFit switch tells which implementation of the first-fit method should be used. If true an implementation depending on BreakpointUtil will be used. If false a simple implementation is used.

Parameters:
simpleFit - Tells which implementation of the first-fit method should be used.
See Also:
FirstFitAlgorithm.SimpleFirstFit, FirstFitAlgorithm.ShortestPathFirstFit
Method Detail

consider

public void consider(Item newItem)
Description copied from interface: LinebreakAlgorithm
Tells the line breaker that he has to consider a newly generated item. This allows implementations which do typesetting and linebreaking simultaneous.

Parameters:
newItem - The new Item to consider.

getBreakpoints

public List getBreakpoints()
Description copied from interface: LinebreakAlgorithm
Returns the generated breakpoints. Calling this method only makes sense if no further calls to LinebreakAlgorithm.consider(Item) are made.

Returns:
The generated breakpoints.

linebreak

public void linebreak(String text)
This is a simple implementation of the first-fit algorithm (break before the first item that does not fit into the line). Only used for testing purposes.


Unified Typesetting API M1-20040817


An inghuimische.de project.
Copyright (C) 2004 Christian Ziesemer; See the Mozilla Public License for more details.