Tuesday, May 26, 2009

Bordered text

How about adding a fancy bordered text to your customized UI? Simple, draw the text with the border color four times around the anchor point with just one pixel difference. Then draw the text with the desired color at the anchor point. Did not get it? How about the source code below?

public void drawBorderedText(Graphics g, String text,
  int x, int y, int anchor, int textColor, int borderColor)
{
  // draw border
  g.setColor(borderColor);
  g.drawString(text, x - 1, y - 1, anchor);
  g.drawString(text, x - 1, y + 1, anchor);
  g.drawString(text, x + 1, y - 1, anchor);
  g.drawString(text, x + 1, y + 1, anchor);
  // draw text
  g.setColor(textColor);
  g.drawString(text, x, y, anchor);
}

Monday, May 25, 2009

My News view

I share what I consider interesting news at this site. If you want to easily follow them please use this RSS feed

These are the same news available at this blog, section "Also read...".

Saturday, May 16, 2009

Development branches

How can I evolve two different versions of the same application? Using the same source code? For example, if one version uses MIDP 2.0 but the other uses MIDP 1.0? The answer is preprocessing.

Since October/2003 I use Antenna: an Ant plugin that allows a developer to easily build, preverify and package a Java ME application, but it also has a pre-processor built in. To use it you need to add special line comments in your source code and call the wtkpreprocess task before calling the build task.
Below is an example of such line comments:

//#ifdef midp20
list.setBackgroundColor(display.getColor(Display.COLOR_BACKGROUND));
//#endif

ifdef means If Defined.
My build.xml Ant script will have the following lines:

<wtkpreprocess src="./src" dest="./prep" symbols="midp20"/>
<wtkbuild src="./prep" dest="./bin"/>

With this the preprocessor will match the informed symbol "midp20" with the ifdef value and keep the original code unchanged.
To differ between the two versions I will need two targets in build.xml. One for MIDP 2.0 and the other for MIDP 1.0. The first will use the sample above, but the target for MIDP 1.0 will use:

<wtkpreprocess src="./src" dest="./prep"/>
<wtkbuild src="./prep" dest="./bin"/>

Without any symbols the preprocessor will change the source code and add comment lines between ifdef and endif. The changed code at prep folder will look like this:

//#ifdef midp20
//list.setBackgroundColor(display.getColor(Display.COLOR_BACKGROUND));
//#endif

You can also use preprocessing with NetBeans Mobility Pack and Eclipse MTJ (EclipseME has moved to this project).

Related Topics: