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

public abstract class Box extends Object
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

    Fields
    Modifier and Type
    Field
    Description
    protected Color
    The background color of the whole box.
    protected LinkedList<Box>
    List of child boxes
    static 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

    Constructors
    Modifier
    Constructor
    Description
    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)
    protected
    Box(Color fg, Color bg)
    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 Type
    Method
    Description
    void
    add(int pos, Box b)
    Inserts the given box at the given position in the list of child boxes.
    void
    add(Box b)
    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
    Restores the previous color setting.
    float
    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
    Get the shift amount for this box.
    float
    Get the width of this box.
    void
     
    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
    setParent(Box parent)
     
    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).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEBUG

      public static boolean DEBUG
    • foreground

      protected Color 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

      protected Color 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 width
      The width of this box, i.e. the value that will be used for further calculations.
    • height

      protected float height
      The height of this box, i.e. the value that will be used for further calculations.
    • depth

      protected float depth
      The depth of this box, i.e. the value that will be used for further calculations.
    • shift

      protected float shift
      The shift amount: the meaning depends on the particular kind of box (up, down, left, right)
    • type

      protected int type
    • children

      protected LinkedList<Box> children
      List of child boxes
    • parent

      protected Box parent
    • elderParent

      protected Box elderParent
    • markForDEBUG

      protected Color 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

      protected Box(Color fg, Color bg)
      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 color
      bg - the background color
  • Method Details

    • add

      public void add(Box b)
      Inserts the given box at the end of the list of child boxes.
      Parameters:
      b - the box to be inserted
    • add

      public void add(int pos, Box b)
      Inserts the given box at the given position in the list of child boxes.
      Parameters:
      pos - the position at which to insert the given box
      b - the box to be inserted
    • setParent

      public void setParent(Box parent)
    • getParent

      public Box getParent()
    • setElderParent

      public void setElderParent(Box elderParent)
    • getElderParent

      public Box 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

      public abstract void draw(Graphics2D g2, float x, float y)
      Paints this box at the given coordinates using the given graphics context.
      Parameters:
      g2 - the graphics (2D) context to use for painting
      x - the x-coordinate
      y - 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

      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).
      Parameters:
      g2 - the graphics (2D) context
      x - the x-coordinate
      y - the y-coordinate
    • drawDebug

      protected void drawDebug(Graphics2D g2, float x, float y, boolean showDepth)
    • drawDebug

      protected void drawDebug(Graphics2D g2, float x, float y)
    • endDraw

      protected void endDraw(Graphics2D g2)
      Restores the previous color setting.
      Parameters:
      g2 - the graphics (2D) context