Package org.scilab.forge.jlatexmath
Class Box
java.lang.Object
org.scilab.forge.jlatexmath.Box
- Direct Known Subclasses:
CharBox
,FcscoreBox
,FramedBox
,GeoGebraLogoBox
,GlueBox
,GraphicsBox
,HorizontalBox
,HorizontalRule
,JavaFontRenderingBox
,OverBar
,OverUnderBox
,ReflectBox
,RotateBox
,ScaleBox
,StrutBox
An abstract graphical representation of a formula, that can be painted. All characters, font
sizes, positions are fixed. Only special Glue boxes could possibly stretch or shrink.
A box has 3 dimensions (width, height and depth), can be composed of other child boxes
that can possibly be shifted (up, down, left or right). Child boxes can also be positioned
outside their parent's box (defined by it's dimensions).
Subclasses must implement the abstract draw(Graphics2D, float, float)
method
(that paints the box). This implementation must start with calling the method
startDraw(Graphics2D, float, float)
and end with calling the method
endDraw(Graphics2D)
to set and restore the color's that must be used for
painting the box and to draw the background! They must also implement the abstract
getLastFontId()
method (the last font
that will be used when this box will be painted).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Color
The background color of the whole box.protected LinkedList<Box>
List of child boxesstatic boolean
protected float
The depth of this box, i.e.protected Box
protected Color
The foreground color of the whole box.protected float
The height of this box, i.e.protected Color
protected Box
protected float
The shift amount: the meaning depends on the particular kind of box (up, down, left, right)protected int
protected float
The width of this box, i.e. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Box()
Creates an empty box (no children) with all dimensions set to 0 and no foreground and background color set (default values will be used: null)protected
Creates an empty box (no children) with all dimensions set to 0 and sets the foreground and background color of the box. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Inserts the given box at the given position in the list of child boxes.void
Inserts the given box at the end of the list of child boxes.abstract void
draw
(Graphics2D g2, float x, float y) Paints this box at the given coordinates using the given graphics context.protected void
drawDebug
(Graphics2D g2, float x, float y) protected void
drawDebug
(Graphics2D g2, float x, float y, boolean showDepth) protected void
endDraw
(Graphics2D g2) Restores the previous color setting.float
getDepth()
Get the depth of this box.float
Get the height of this box.abstract int
Get the id of the font that will be used the last when this box will be painted.float
getShift()
Get the shift amount for this box.float
getWidth()
Get the width of this box.void
negWidth()
void
setDepth
(float d) Set the depth for this box.void
setElderParent
(Box elderParent) void
setHeight
(float h) Set the height for this box.void
void
setShift
(float s) Set the shift amount for this box.void
setWidth
(float w) Set the width for this box.protected void
startDraw
(Graphics2D g2, float x, float y) Stores the old color setting, draws the background of the box (if not null) and sets the foreground color (if not null).
-
Field Details
-
DEBUG
public static boolean DEBUG -
foreground
The foreground color of the whole box. Child boxes can override this color. If it's null and it has a parent box, the foreground color of the parent will be used. If it has no parent, the foreground color of the component on which it will be painted, will be used. -
background
The background color of the whole box. Child boxes can paint a background on top of this background. If it's null, no background will be painted. -
width
protected float widthThe width of this box, i.e. the value that will be used for further calculations. -
height
protected float heightThe height of this box, i.e. the value that will be used for further calculations. -
depth
protected float depthThe depth of this box, i.e. the value that will be used for further calculations. -
shift
protected float shiftThe shift amount: the meaning depends on the particular kind of box (up, down, left, right) -
type
protected int type -
children
List of child boxes -
parent
-
elderParent
-
markForDEBUG
-
-
Constructor Details
-
Box
protected Box()Creates an empty box (no children) with all dimensions set to 0 and no foreground and background color set (default values will be used: null) -
Box
Creates an empty box (no children) with all dimensions set to 0 and sets the foreground and background color of the box.- Parameters:
fg
- the foreground colorbg
- the background color
-
-
Method Details
-
add
Inserts the given box at the end of the list of child boxes.- Parameters:
b
- the box to be inserted
-
add
Inserts the given box at the given position in the list of child boxes.- Parameters:
pos
- the position at which to insert the given boxb
- the box to be inserted
-
setParent
-
getParent
-
setElderParent
-
getElderParent
-
getWidth
public float getWidth()Get the width of this box.- Returns:
- the width of this box
-
negWidth
public void negWidth() -
getHeight
public float getHeight()Get the height of this box.- Returns:
- the height of this box
-
getDepth
public float getDepth()Get the depth of this box.- Returns:
- the depth of this box
-
getShift
public float getShift()Get the shift amount for this box.- Returns:
- the shift amount
-
setWidth
public void setWidth(float w) Set the width for this box.- Parameters:
w
- the width
-
setDepth
public void setDepth(float d) Set the depth for this box.- Parameters:
d
- the depth
-
setHeight
public void setHeight(float h) Set the height for this box.- Parameters:
h
- the height
-
setShift
public void setShift(float s) Set the shift amount for this box.- Parameters:
s
- the shift amount
-
draw
Paints this box at the given coordinates using the given graphics context.- Parameters:
g2
- the graphics (2D) context to use for paintingx
- the x-coordinatey
- the y-coordinate
-
getLastFontId
public abstract int getLastFontId()Get the id of the font that will be used the last when this box will be painted.- Returns:
- the id of the last font that will be used.
-
startDraw
Stores the old color setting, draws the background of the box (if not null) and sets the foreground color (if not null).- Parameters:
g2
- the graphics (2D) contextx
- the x-coordinatey
- the y-coordinate
-
drawDebug
-
drawDebug
-
endDraw
Restores the previous color setting.- Parameters:
g2
- the graphics (2D) context
-