|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object mwt.Skin
public class Skin
A skin is used to paint regions of different sizes using the same look and feel.
A skin can be created giving images (an "image skin"), or giving colors ("colour rectangle skin").
To create an image skin, you must provide an array of 9 images.
The next example shows how they will be used:
Each image of the given array maps in the next way:7 0 1 0, 2, 4, 5: sides 6 8 2 1, 3, 5, 7: borders 5 4 3 8: fill |
"Middle" sides (2 and 6), are repeated in y axis until they fill the desired area.
"Center" sides (0 and 4), are repeated in x axis until they fill the desired area.
The "fill" image is repeated in both axis.
Border images are blitted as they are.
If images are repeated too many times, the application may run slower.
To improve this, you can resize the images when the skin is created. However, this requires
more memory.
Another drawback is that if the images are resized, they may lose the alpha channel info.
A colour rectangle skin is created by giving an array of integers.
The skin will draw a rectangle using this colour data which must contain at least 1 value.
The first index value is the background fill, next values are frames from outside to inside.
0xFFE220 |
0x000000 |
0x5999FF |
0x000000 |
0xD9C01C |
|
0xFFCCCF |
0xA34184 |
0xFF66CF |
0xFF66CF |
||
0xFFFFFF |
0x000000 |
0xA1C632 |
0xCFFF40 |
Classes that extend a Skin must override the following methods:
The contructor must call the default constructorSkin()
.
Example:
class MySkin extends Skin { int newAttribute = ...; public MySkin(int newAttribute) { super(); // this is not necessary this.newAttribute = newAttribute; } protected void copy(MySkin s) { super.copy(s); s.newAttribute = this.newAttribute; } private MySkin() {} public Skin clone() { MySkin s = new MySkin(); copy(s); return s; } protected void paint(Graphics g, int width, int height) { // new implementation } }
To improve performance, there's a mechanism to create a cache if the component calling
is double buffered.
The default implementation has an important drawback; alpha values are ignored.
You can extend this class and implement a better cache mechanism overriding the
createBuffer(int, int)
method.
Constructor Summary | |
---|---|
Skin()
Creates a "dummy" skin, paint calls are ignored. |
|
Skin(javax.microedition.lcdui.Image[] images,
int newSize)
Creates an image skin. |
|
Skin(int[] colors)
Creates a "colour rectangle" skin. |
Method Summary | |
---|---|
Skin |
clone()
Gets a clone of this skin. |
protected void |
copy(Skin skin)
Copies this skin into the given skin. |
protected javax.microedition.lcdui.Image |
createBuffer(int width,
int height)
Creates an image that will be used as a buffer. |
void |
paint(Component c,
javax.microedition.lcdui.Graphics g)
Paints a component into the given graphics object. |
protected void |
paint(javax.microedition.lcdui.Graphics g,
int width,
int height)
Paints this skin into the given graphics object with the given width and height. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Skin()
public Skin(int[] colors)
public Skin(javax.microedition.lcdui.Image[] images, int newSize)
images
- The array with 9 images in the correspoding ordernewSize
- The new size, or 0 to skip resizingMethod Detail |
---|
public Skin clone()
clone
in class java.lang.Object
protected void copy(Skin skin)
public final void paint(Component c, javax.microedition.lcdui.Graphics g)
createBuffer(int, int)
.
protected javax.microedition.lcdui.Image createBuffer(int width, int height)
Image buf = Image.createImage(c.getWidth(),c.getHeight()); this.paint(buf.getGraphics(),c.getWidth(),c.getHeight()); return buf;MWT handles memory management automatically.
protected void paint(javax.microedition.lcdui.Graphics g, int width, int height)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |