BBCode for Graphics2D

For my graduation project we needed the ability to print a couple of bills etc. Printing lines was pretty simple with the LinesPrinter i blogged about a while ago. We had two choices: either implement a specific print method for each module or implement a reusable markup system. Obviously we went for the second option and came up with something alike BBCode. The codes we implemented are:

  • [b]..[/b] for bold
  • [i]..[/i] for italic
  • [color=x]..[/color] for color x
  • ..

    for centered text

  • [r]..[/r] for right aligned text
  • [ll=x]..[/ll] for left aligned text starting from the x-th column at the left
  • [lr=x]..[/lr] for left aligned text starting from the x-th column at the right
  • [rl=x]..[/ll] for right aligned text starting from the x-th column at the left
  • [rr=x]..[/ll] for right aligned text starting from the x-th column at the right

Since the code is written to work on a Graphics2D device you can also render the formatted text on a jpanel etc instead of a printer device. Here is a screenshot of a generated bill (on a jpanel):

rpcode

Feel free to download, try and improve the rpcode.zip package.

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>