Update of /cvsroot/synclast/client/src/com/synclast/ui
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv13816
Modified Files:
Container.java
Log Message:
Fixed a major focus bug with remove.
Basically, when a widget was removed from Container, the focusable count in container was being updated, but the focused index was not. If the widget that was removed was the one with focus, this would be a problem, since either a different widget or no widget would now be considered "focussed". If the widget was the last widget in the Container, or the widget that was after it in the Widget vector was not a KeyEventListener, calls that interact with focus, such as hideNotify(), would result in either a ArrayIndexOutOfBoundsException or a ClassCastException respectively. This was a hard bug to duplicate.
This bug might also be present in the replace logic, where the new widget replacing the old widget is not a KeyEventListener, and the old one was, and had focus. I am still testing this case.
Index: Container.java
===================================================================
RCS file: /cvsroot/synclast/client/src/com/synclast/ui/Container.java,v
retrieving revision 1.39
retrieving revision 1.40
diff -C2 -d -r1.39 -r1.40
*** Container.java 20 Sep 2006 12:19:53 -0000 1.39
--- Container.java 3 Oct 2006 10:11:06 -0000 1.40
***************
*** 317,320 ****
--- 317,322 ----
*/
public void remove(Widget widget) {
+ //record index so we can fix focus later (if necessary)
+ int index = widgets.indexOf(widget);
if(widgets.removeElement(widget)) {
UIContext context = getContext();
***************
*** 332,335 ****
--- 334,342 ----
setFocusable(-1);
}
+ //fix focus if necessary
+ if(index >= 0 && focused == index) {
+ focused = -1;
+ passFocus(1);
+ }
invalidate();
}
|