com.googlecode.whatswrong
Class TokenLayout

java.lang.Object
  extended by com.googlecode.whatswrong.TokenLayout

public class TokenLayout
extends java.lang.Object

A TokenLayout object lays out a collection of tokens in sequence by placing a stack of property values of each token at a position corresponding to the index of the token. The order in which the property values are stacked depends on the level of each corresponding property. The first property (with highest level) is rendered in black while the remaining property values are rendered in gray.

Note that the TokenLayout remembers the bounds of each token property stack and the text layout of each property value. This can be handy when other layouts (e.g., DependencyLayout) want to connect the tokens.

Author:
Sebastian Riedel

Constructor Summary
TokenLayout()
           
 
Method Summary
 java.util.Map<Token,Bounds1D> estimateTokenBounds(NLPInstance instance, java.util.Map<Token,java.lang.Integer> tokenWidths, java.awt.Graphics2D g2d)
          Method estimateTokenBounds calculates the horizontal bounds of each token in the layout of the tokens.
 int getBaseline()
          Gets the y value at which the token layout should start.
 java.awt.geom.Rectangle2D getBounds(Token vertex)
          Gets the bounds of the property value stack of the given token.
 int getFromSplitPoint()
          Returns the index of the first split point from which the token layout starts to render or -1 if it begins from the start of the token sequence.
 int getHeight()
          Gets the total height of this TokenLayout (covering all token stacks).
 int getMargin()
          Returns the margin between token stacks.
 java.awt.font.TextLayout getPropertyTextLayout(Token vertex, int index)
          Returns the text layout for a given property and property index in the stack.
 int getRowHeight()
          Gets the height of each property value row in the stack.
 int getToSplitPoint()
          Returns the index of the the split point at which the token renderer should stop rendering the token sequence.
 int getWidth()
          Gets the total width of this TokenLayout (covering all token stacks).
 java.awt.Dimension layout(NLPInstance instance, java.util.Map<Token,java.lang.Integer> tokenWidths, java.awt.Graphics2D g2d)
          Lays out all tokens in the given collection as stacks of property values that are placed next to each other according the order of the tokens (as indicated by their indices).
 void setBaseline(int baseline)
          Sets the y value at which the token layout should start.
 void setFromSplitPoint(int fromSplitPoint)
          Sets the first split point from which the token layout starts to render or -1 if it begins from the start of the token sequence.
 void setMargin(int margin)
          Sets the margin between token stacks.
 void setRowHeight(int rowHeight)
          Sets the height of each property value row in the stack.
 void setToSplitPoint(int toSplitPoint)
          Returns the index of the the split point at which the token renderer should stop rendering the token sequence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TokenLayout

public TokenLayout()
Method Detail

setRowHeight

public void setRowHeight(int rowHeight)
Sets the height of each property value row in the stack.

Parameters:
rowHeight - the height of each property value row in the stack.

setBaseline

public void setBaseline(int baseline)
Sets the y value at which the token layout should start.

Parameters:
baseline - the y value at which the token layout should start.

getFromSplitPoint

public int getFromSplitPoint()
Returns the index of the first split point from which the token layout starts to render or -1 if it begins from the start of the token sequence.

Returns:
the index of the first split point or -1 if renderering happens from the beginning of the token sequence.

setFromSplitPoint

public void setFromSplitPoint(int fromSplitPoint)
Sets the first split point from which the token layout starts to render or -1 if it begins from the start of the token sequence.

Parameters:
fromSplitPoint - the index of the first split point or -1 if renderering should happen from the beginning of the token sequence.

getToSplitPoint

public int getToSplitPoint()
Returns the index of the the split point at which the token renderer should stop rendering the token sequence.

Returns:
the index of split point at which the renderer stops or -1 if renderering goes to the end of the token sequence.

setToSplitPoint

public void setToSplitPoint(int toSplitPoint)
Returns the index of the the split point at which the token renderer should stop rendering the token sequence.

Parameters:
toSplitPoint - the index of split point at which the renderer stops or -1 if renderering goes to the end of the token sequence.

setMargin

public void setMargin(int margin)
Sets the margin between token stacks.

Parameters:
margin - the margin between token stacks.

getRowHeight

public int getRowHeight()
Gets the height of each property value row in the stack.

Returns:
the height of each property value row in the stack.

getBaseline

public int getBaseline()
Gets the y value at which the token layout should start.

Returns:
the y value at which the token layout should start.

getMargin

public int getMargin()
Returns the margin between token stacks.

Returns:
the margin between token stacks.

estimateTokenBounds

public java.util.Map<Token,Bounds1D> estimateTokenBounds(NLPInstance instance,
                                                         java.util.Map<Token,java.lang.Integer> tokenWidths,
                                                         java.awt.Graphics2D g2d)
Method estimateTokenBounds calculates the horizontal bounds of each token in the layout of the tokens.

Parameters:
instance - the NLPInstance to layout.
tokenWidths - A map that defines some minomal widths for each token. The estimated bounds will fulfill the width requirements specified by this map. If a token has no required width its estimated width will be based on the length of its textual properties.
g2d - The graphics object to render to.
Returns:
Map A mapping from tokens to estimated horizontal bounds in the layout.

layout

public java.awt.Dimension layout(NLPInstance instance,
                                 java.util.Map<Token,java.lang.Integer> tokenWidths,
                                 java.awt.Graphics2D g2d)
Lays out all tokens in the given collection as stacks of property values that are placed next to each other according the order of the tokens (as indicated by their indices).

After this method has been called the properties of the layout (height, width, bounding boxes of token stacks and text layouts of each property value) can be queried by calling the appropriate get methods.

Parameters:
instance - the NLPInstance to layout.
tokenWidths - if some tokens need extra space (for example because they have self loops in a DependencyLayout) the space they need can be provided through this map.
g2d - the graphics object to draw to.
Returns:
the dimension of the drawn graph.

getPropertyTextLayout

public java.awt.font.TextLayout getPropertyTextLayout(Token vertex,
                                                      int index)
Returns the text layout for a given property and property index in the stack.

Parameters:
vertex - the token for which we want the text layout of a propery of it.
index - the index of the property in the stack.
Returns:
the text layout of the property value at index index of the stack for the token vertex

getBounds

public java.awt.geom.Rectangle2D getBounds(Token vertex)
Gets the bounds of the property value stack of the given token.

Parameters:
vertex - the token for which to get the bounds for.
Returns:
a bounding box around the stack of property values for the given token.

getWidth

public int getWidth()
Gets the total width of this TokenLayout (covering all token stacks).

Returns:
the total width of this TokenLayout.

getHeight

public int getHeight()
Gets the total height of this TokenLayout (covering all token stacks).

Returns:
the total width of this TokenLayout.


Copyright © 2009. All Rights Reserved.