Unified Typesetting API M1-20040817

de.inghuimische.uta.util
Class BreakpointUtil

java.lang.Object
  extended byde.inghuimische.uta.util.BreakpointUtil

public class BreakpointUtil
extends Object

An utility class meant to support high quality, paragraph based linebreak algorithms. This class supports you with a factory method for breakpoints (singleton pattern) and a method that allows you to find the shortest path between all breakpoints.

This class depends on the JGraphT library (available under the Gnu Lesser General Public License).

Author:
Christian Ziesemer

Constructor Summary
BreakpointUtil(GraphAdapter anAdapter)
           
 
Method Summary
protected  void addEdge(Breakpoint source, double weight, Breakpoint target)
          This method is used internally by createEdges(Breakpoint) you normally should not call it directly, compare Breakpoint.addPreviousBreakpoint(Breakpoint, Line).
protected  void createEdges(Breakpoint bp)
          Creates the edges starting at the given node and going backwards through all previous breakpoints using the information provided by the Breakpoint.getPreviousBreakpoints() and Breakpoint.getDemerits(Breakpoint) methods.
 List findOptimalBreakpoints()
          The same as findOptimalBreakpoints(getStartNode(), getEndNode()).
 List findOptimalBreakpoints(Breakpoint startNode, Breakpoint endNode)
          Searches the shortest path in the graph between the given breakpoints.
 Breakpoint getBreakpoint(Item prevItem)
          Factory method that ensures that exactly one breakpoint is associated with a given item.
 Breakpoint getDefaultStartNode()
          Returns the breakpoint every linebreak algorithm should return as the first one.
 Breakpoint getEndNode()
          Returns the endNode.
 Breakpoint getStartNode()
          Returns the startNode.
 void setEndNode(Breakpoint endNode)
          Sets the end node.
 void setStartNode(Breakpoint startNode)
          Sets the start node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BreakpointUtil

public BreakpointUtil(GraphAdapter anAdapter)
Method Detail

getBreakpoint

public Breakpoint getBreakpoint(Item prevItem)
Factory method that ensures that exactly one breakpoint is associated with a given item. Breakpoints are automatically added to the graph.

Parameters:
prevItem - The item before the breakpoint.
Returns:
The requested breakpoint.

createEdges

protected void createEdges(Breakpoint bp)
Creates the edges starting at the given node and going backwards through all previous breakpoints using the information provided by the Breakpoint.getPreviousBreakpoints() and Breakpoint.getDemerits(Breakpoint) methods.

Calling this method is of course only useful if all previous breakpoints are known.


addEdge

protected void addEdge(Breakpoint source,
                       double weight,
                       Breakpoint target)
This method is used internally by createEdges(Breakpoint) you normally should not call it directly, compare Breakpoint.addPreviousBreakpoint(Breakpoint, Line).

Parameters:
source - The source breakpoint.
weight - The weight of the edge, the demerits.
target - The target breakpoint.

findOptimalBreakpoints

public List findOptimalBreakpoints()
The same as findOptimalBreakpoints(getStartNode(), getEndNode()).


findOptimalBreakpoints

public List findOptimalBreakpoints(Breakpoint startNode,
                                   Breakpoint endNode)
Searches the shortest path in the graph between the given breakpoints. The shortest path is the global optimum of all breakpoints.

Parameters:
startNode - The node to start from.
endNode - The end node.
Returns:
A list containing the breakpoints lying on the shortest path or null if no such path exists.

getEndNode

public Breakpoint getEndNode()
Returns the endNode.

Returns:
Returns the endNode.

setEndNode

public void setEndNode(Breakpoint endNode)
Sets the end node.

Parameters:
endNode - The endNode to set.

getStartNode

public Breakpoint getStartNode()
Returns the startNode.

Returns:
Returns the startNode.

setStartNode

public void setStartNode(Breakpoint startNode)
Sets the start node.

Parameters:
startNode - The startNode to set.

getDefaultStartNode

public Breakpoint getDefaultStartNode()
Returns the breakpoint every linebreak algorithm should return as the first one. This is the breakpoint with the previous item null.

Returns:
The breakpoint returned by getBreakpoint(null).

Unified Typesetting API M1-20040817


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