06-14-2011 02:18 PM
I ended up needing to work on an odd-ball Manager. Basically, I want a Manager that can take Fields and Managers (as it already can), lay them out, and pain them.
But, I don't want any of the fields to get focus, be clickable, and for the manager itself to be the one to get focus and to be highlighted.
Currently I have a basic extended HorizontalFieldManager with a slightly modified paint function and with some overridden interaction functions that hopefully will allow me to make the class "clickable".
Unfortunately focus always goes into the fields contained by the manager. I am not very good at any GUI work and have yet to figure out what functions I should override to keep focus on the Manager and not the Fields within it.
Any ideas?
Solved! Go to Solution.
06-14-2011 02:29 PM
There is a nice little gadget which should help you - NullField. It is invisible, takes no room on the screen, but can be focusable (and is focusable by default). Add such field to your Manager, listen on the focus on it and react accordingly.
I've done it many times with great success.
06-14-2011 02:46 PM
I think there is a further trick - make all the Fields in the Manager non focusable. Except the NullField that will get focus. Have your Manager listen for focusEvents on that NullField, and have it 'paint' appropriately. .
06-14-2011 02:52 PM
Sounds perfect. Simulator starting up...
06-14-2011 03:01 PM - last edited on 06-14-2011 03:02 PM
Focus now works perfectly.
But my click functions are, non-functional. Any ideas? Or any other comments for that manner.
I posted the code I have:
private static class SelectField extends HorizontalFieldManager implements FocusChangeListener
{
private boolean click;
public SelectField()
{
this(0);
}
public SelectField(long style)
{
super(style);
NullField field = new NullField();
field.setFocusListener(this);
add(field);
}
protected void paint(Graphics graphics)
{
if(this.getField(0).isFocus())
{
int tc = graphics.getColor();
graphics.setColor(Color.RED);
graphics.fillRect(0, 0, this.getWidth(), this.getHeight());
graphics.setColor(tc);
}
super.paint(graphics);
}
public void focusChanged(Field field, int eventType)
{
if(eventType == FocusChangeListener.FOCUS_LOST)
{
click = false;
}
invalidate();
}
protected boolean navigationClick(int status, int time)
{
if(this.getField(0).isFocus())
{
click = true;
return true;
}
return super.navigationClick(status, time);
}
protected boolean navigationUnclick(int status, int time)
{
if(this.getField(0).isFocus() && click)
{
click = false;
invokeAction(0);
return true;
}
return super.navigationUnclick(status, time);
}
protected boolean trackwheelClick(int status, int time)
{
if(this.getField(0).isFocus())
{
click = true;
return true;
}
return super.trackwheelClick(status, time);
}
protected boolean trackwheelUnclick(int status, int time)
{
if(this.getField(0).isFocus() && click)
{
click = false;
invokeAction(0);
return true;
}
return super.trackwheelUnclick(status, time);
}
protected boolean touchEvent(TouchEvent message)
{
switch(message.getEvent())
{
case TouchEvent.CLICK:
invokeAction(0);
break;
}
return super.touchEvent(message);
}
}
Note: The red color is solely for debugging purposes. I'll replace with a better color later.
06-17-2011 07:45 AM