Class TextFragment
java.lang.Object
|
+--AbstractBox
|
+--AbstractRigidBox
|
+--TextFragment
- All Implemented Interfaces:
- Box, RigidBox
- public class TextFragment
- extends AbstractRigidBox
A fragment of text. This is the basic building-block of all
paragraphs. A TextFragment
is meant to be used
together with other fragments to form larger pieces of text. Each
fragment has it's own content, font, and may be a link.
Constructor Summary |
TextFragment(java.lang.String str,
java.awt.Font f,
java.net.URL u)
Creates a new TextFragment . |
Method Summary |
void |
doLayout(java.awt.Graphics g,
javax.swing.JComponent c,
int w)
Makes the box update it's own width and height, and layout
it's child-boxes. |
void |
drawAt(int x,
int y,
DocumentView v)
Draws the box with it's upper-left corner at (x ,
y ). |
Box |
getLargestTail()
Tries to make the largest right part from a split. |
int |
getMinimumWidth()
Returns the minimum width of this TextFragment . |
Box |
getSmallestHead()
Tries to make the smallest left part from a split. |
Box |
splitHead(int w)
Tries to split the box at w . |
boolean |
splitIsPossible(int w)
Reports if a split is possible at w . |
Box |
splitTail(int w)
Tries to split the box at w . |
java.lang.String |
toString()
Gives you information about the box. |
void |
trim(int edge)
Pretends to trim the box - it does nothing as the body of the
method is empty. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
TextFragment
public TextFragment(java.lang.String str,
java.awt.Font f,
java.net.URL u)
- Creates a new
TextFragment
.
- Parameters:
str
- the string contained within this fragment. The
string should contain any white-space necessary to ensure
correct spacing when this fragment is placed side-to-side with
other fragments.f
- the font that will be used when rendering the
fragment. The font is also used when the content is meassured.u
- the URL that this fragment links to. If the fragment
doesn't link to anywhere u
should be
null
.
doLayout
public void doLayout(java.awt.Graphics g,
javax.swing.JComponent c,
int w)
- Description copied from interface:
Box
- Makes the box update it's own width and height, and layout
it's child-boxes.
- Overrides:
doLayout
in class AbstractBox
- Following copied from interface:
Box
- Parameters:
g
- the graphics context. Some boxes, like TextFragments,
need a graphics context before they can determine their width
and height.c
- the component into which the box will be drawn. An
ImageBox needs to know the component to calculate the width
and height.w
- the width available for to the Box.
getMinimumWidth
public int getMinimumWidth()
- Returns the minimum width of this
TextFragment
.
The result is calculated by meassuring every word in the
string and is only calculated once for each fragment.
- Overrides:
getMinimumWidth
in class AbstractBox
- Returns:
- the minimum width.
splitIsPossible
public boolean splitIsPossible(int w)
- Reports if a split is possible at
w
. For a
fragment to be split, it must contain more than a single word.
If it does, the width of the initial word (plus any white
space at the beginning) is meassured and compared with
w
.
- Overrides:
splitIsPossible
in class AbstractRigidBox
- Parameters:
w
- the desired width of the head.- Returns:
true
if w
is greather than
the length of the initial word.
drawAt
public void drawAt(int x,
int y,
DocumentView v)
- Description copied from interface:
Box
- Draws the box with it's upper-left corner at (
x
,
y
).
- Overrides:
drawAt
in class AbstractBox
- Following copied from interface:
Box
- Parameters:
v
- the DocumentView
that does the actual
drawing.x
- the x-coordinate of the upper-left corner.x
- the y-coordinate of the upper-left corner.
splitHead
public Box splitHead(int w)
- Description copied from class:
AbstractRigidBox
- Tries to split the box at
w
.
- Overrides:
splitHead
in class AbstractRigidBox
- Following copied from class:
AbstractRigidBox
- Parameters:
w
- the place where the split should be.- Returns:
- always
null
to indicate that the box can't
be split.
splitTail
public Box splitTail(int w)
- Description copied from class:
AbstractRigidBox
- Tries to split the box at
w
.
- Overrides:
splitTail
in class AbstractRigidBox
- Following copied from class:
AbstractRigidBox
- Parameters:
w
- the place where the split should be.- Returns:
- always
null
to indicate that the box can't
be split.
getSmallestHead
public Box getSmallestHead()
- Description copied from class:
AbstractRigidBox
- Tries to make the smallest left part from a split.
- Overrides:
getSmallestHead
in class AbstractRigidBox
- Following copied from class:
AbstractRigidBox
- Returns:
- always
null
to indicate that the box can't
be split.
getLargestTail
public Box getLargestTail()
- Description copied from class:
AbstractRigidBox
- Tries to make the largest right part from a split.
- Overrides:
getLargestTail
in class AbstractRigidBox
- Following copied from class:
AbstractRigidBox
- Returns:
- always
null
to indicate that the box can't
be split.
trim
public void trim(int edge)
- Description copied from class:
AbstractRigidBox
- Pretends to trim the box - it does nothing as the body of the
method is empty.
- Overrides:
trim
in class AbstractRigidBox
- Following copied from class:
AbstractRigidBox
- Parameters:
edge
- to be trimmed. The value is discarded.
toString
public java.lang.String toString()
- Description copied from interface:
Box
- Gives you information about the box.
- Overrides:
toString
in class AbstractBox
- Following copied from interface:
Box
- Returns:
- information about the box - usefull for debugging.