|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.microedition.lcdui.Displayable
javax.microedition.lcdui.Canvas
org.inclou.Palette.PaletteCanvas
You should note that this is a javax.microedition.lcdui.Canvas subclass and therefore the present library must be used by J2 Micro Edition applications. You should note that the GrayScale screen mode might show non-grayscale colors, as the system maps the RGB color system to the most similar displayable color.
This Canvas subclass shows a palette where one can choose a color. A palette is like a table where each square contains a color. It can be used as library by other J2ME applications such as MIDlets. The palette can contain color squares of a fixed size (as many as fit in the screen) or a determined number of color squares (its size depending on the screen size). It also allows you to preselect a color.
A ChoserInterface interface must be passed to the constructor in order to tell the PaletteCanvas what to do when a color is selected by user, as well as passing to the application the selected color.
Colors can be selected by means of game pad or pointer. Application can select FullColor or GrayScale screen mode by calling setFullColorMode(boolean full), usually before PaletteCanvas is made visible. By default, Full Color mode is initially set. Both palettes will have the same number of rows and cols.
The number of rows (square size recalculated) are rounded so rows is ultiple of 2 and/or 3. It is rounded to the nearest lower value using the PaletteCanvas.facts precalculated table. Rows and cols can also become to different lower values if the display can actually display fewer colors than rows and cols specified in constructor, according to the parameter passed to the constructor.
There is a fixed margin of 3 px between squares. Those in the boundaries have an external margin of 2 px. Canvas should be 5x5px at least. The palette will show 4 rows and 2 cols at least, even if display can actually show only 2 colors for example.
The number of rows and cols, as well as the size of squares, can actually be different than specified in constructor as a result of considerations above.
If you want to know exactly how the PaletteCanvas.facts values have been calculated please refer to PaletteCanvas.java source code (see very bottom).
|
Canvas diagram which shows drawing details. This is a 4 rows and 3 columns
PaletteCanvas. Width and height of squares are both 3 pixels. This represents
to be a 23x39px Canvas. Note that there is 1px left in the right and 2 px left
in the bottom.
A grid has been drawed, and gray pixels are those used for drawing the black surrounding rectangle which indicates current square selection (in this case row 0 column 0). Neither grid nor gray pixels are drawn. This is only a diagram, and this colors are arbitrarily selected. |
MIDpaletteSelector,
ChoserInterface| Field Summary | |
static byte[] |
factA
facts[n] values are already split into two factors for speeding execution. |
static byte[] |
factB
facts[n] values are already split into two factors for speeding execution. |
static short[] |
facts
Possible values for numrows parameter in constructor. |
static byte |
SQUARES_SIZE
Used when specifying a certain size for squares. |
static boolean |
TABLE_SIZE
Used when specifying a certain number of rows and cols. |
| Fields inherited from class javax.microedition.lcdui.Canvas |
DOWN, FIRE, GAME_A, GAME_B, GAME_C, GAME_D, KEY_NUM0, KEY_NUM1, KEY_NUM2, KEY_NUM3, KEY_NUM4, KEY_NUM5, KEY_NUM6, KEY_NUM7, KEY_NUM8, KEY_NUM9, KEY_POUND, KEY_STAR, LEFT, RIGHT, UP |
| Constructor Summary | |
PaletteCanvas(ChoserInterface cc)
Basic constructor. |
|
PaletteCanvas(ChoserInterface cc,
int max)
Basic constructor. |
|
PaletteCanvas(ChoserInterface cc,
short numrows,
short numcols,
int max,
boolean b)
Advanced constructor. |
|
PaletteCanvas(ChoserInterface cc,
short squarewidth,
short squareheight,
int max,
byte c)
Advanced constructor. |
|
| Method Summary | |
void |
commandAction(Command c,
Displayable d)
|
boolean |
isInFullColorMode()
Returns information about what screen color mode of PaletteCanvas will be shown if it is requested to be shown. |
protected void |
keyPressed(int keyCode)
|
protected void |
keyReleased(int keyCode)
|
protected void |
keyRepeated(int keyCode)
|
void |
paint(Graphics g)
|
protected void |
pointerDragged(int x,
int y)
|
protected void |
pointerPressed(int x,
int y)
|
protected void |
pointerReleased(int x,
int y)
|
void |
setColorMode(boolean fullcolor)
Switches between FullColor and GrayScale palette screen mode. |
void |
setInterface(ChoserInterface ci)
Sets desired ChoserInterface, usually used if one want to set a different inferface after instantiation of a PaletteCanvas. |
int |
setSelected(int c)
Preselects a color, generally before PaletteCanvas is shown by a main application. |
| Methods inherited from class javax.microedition.lcdui.Canvas |
getGameAction, getKeyCode, getKeyName, hasPointerEvents, hasPointerMotionEvents, hasRepeatEvents, hideNotify, isDoubleBuffered, repaint, repaint, serviceRepaints, setFullScreenMode, showNotify |
| Methods inherited from class javax.microedition.lcdui.Displayable |
addCommand, getHeight, getTicker, getTitle, getWidth, isShown, removeCommand, setCommandListener, setTicker, setTitle |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static final short[] facts
public static final byte[] factA
public static final byte[] factB
public static final boolean TABLE_SIZE
public static final byte SQUARES_SIZE
| Constructor Detail |
public PaletteCanvas(ChoserInterface cc)
cc - Interface that must be called when a color is selected.
public PaletteCanvas(ChoserInterface cc,
int max)
cc - Interface that must be called when a color is selected.max - Maximum number of colors that the screen can actually display,
or desired maximum number of displayable colors. If set to 0 or less,
no boundaries are regarded.
public PaletteCanvas(ChoserInterface cc,
short squarewidth,
short squareheight,
int max,
byte c)
cc - Interface that must be called when a color is selected.max - Maximum number of colors that the screen can actually display,
or desired maximum number of displayable colors. If set to 0 or less,
no boundaries are regarded.squarewidth - Desired square width for each color of the palette.squareheight - Desired square height for each color of the palette.c - This argument has no effect. SQUARES_SIZE static value can be used. It only selects this type of constructor and not PaletteCanvas (ColorChoser cc, int numrows, int numcols, int max, boolean b).SQUARES_SIZE,
TABLE_SIZE
public PaletteCanvas(ChoserInterface cc,
short numrows,
short numcols,
int max,
boolean b)
cc - Interface that must be called when a color is selected.max - Maximum number of colors that the screen can actually display,
or desired maximum number of displayable colors. If set to 0 or less,
no boundaries are regarded.numrows - Desired number of rows of the palette.numcols - Desired number of columns of the palette.b - This argument has no effect. TABLE_SIZE static value can be used. It only selects the type of constructor, not PaletteCanvas (ColorChoser cc, int squarewidth, int squareheight, int max, char c).SQUARES_SIZE,
TABLE_SIZE| Method Detail |
public boolean isInFullColorMode()
public void setInterface(ChoserInterface ci)
ci - ChoserInterface pointer desired to handle PaletteCanvas events.public int setSelected(int c)
c - Color that is wanted to be preselected, in RGB format. Filtered with c&0xFFFFFF so bits in the left are ignored. If it is less than 0 no action is performed.
public void paint(Graphics g)
public void commandAction(Command c,
Displayable d)
commandAction in interface CommandListenerpublic void setColorMode(boolean fullcolor)
fullcolor - True if Full Color screen mode desired. False if Gray Scale mode desired.protected void keyPressed(int keyCode)
protected void keyReleased(int keyCode)
protected void keyRepeated(int keyCode)
protected void pointerDragged(int x,
int y)
protected void pointerPressed(int x,
int y)
protected void pointerReleased(int x,
int y)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||