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.

This entry was posted on Wednesday, June 14th, 2006 at 02:34 and is filed under Java. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Comments are closed.