diff options
author | Sven de Marothy <sven@physto.se> | 2006-07-30 09:01:32 +0000 |
---|---|---|
committer | Sven de Marothy <sven@physto.se> | 2006-07-30 09:01:32 +0000 |
commit | f4df190ddc38b931eea27551323af4b9d38a76a3 (patch) | |
tree | cab4e985aafb68b25d649464a45ba54d045ef754 /gnu | |
parent | fbcab5251aa8d5256e1493cab1cd4ebf909b9395 (diff) | |
download | classpath-f4df190ddc38b931eea27551323af4b9d38a76a3.tar.gz |
2006-07-30 Sven de Marothy <sven@physto.se>
* java/awt/Choice.java:
(accessibleAction): Call select() directly.
(add, insert, remove): Reimplement.
(dispatchEventImpl): Always call super.
(processItemEvent): Does not set the index.
* include/gnu_java_awt_peer_gtk_GtkChoicePeer.h
* native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkChoicePeer.c
(append): removed.
(nativeAdd): Name changed to add.
(selection_changed_cb): Simplify callback.
* gnu/java/awt/peer/gtk/GtkChoicePeer.java
(selected): New field.
(add): Replaced with native impl.
(handleEvent): New method.
Diffstat (limited to 'gnu')
-rw-r--r-- | gnu/java/awt/peer/gtk/GtkChoicePeer.java | 97 |
1 files changed, 51 insertions, 46 deletions
diff --git a/gnu/java/awt/peer/gtk/GtkChoicePeer.java b/gnu/java/awt/peer/gtk/GtkChoicePeer.java index ed7dc74d2..33632cbdf 100644 --- a/gnu/java/awt/peer/gtk/GtkChoicePeer.java +++ b/gnu/java/awt/peer/gtk/GtkChoicePeer.java @@ -39,12 +39,15 @@ exception statement from your version. */ package gnu.java.awt.peer.gtk; import java.awt.Choice; +import java.awt.AWTEvent; import java.awt.event.ItemEvent; import java.awt.peer.ChoicePeer; public class GtkChoicePeer extends GtkComponentPeer implements ChoicePeer { + private int selected; + public GtkChoicePeer (Choice c) { super (c); @@ -52,31 +55,33 @@ public class GtkChoicePeer extends GtkComponentPeer int count = c.getItemCount (); if (count > 0) { - String items[] = new String[count]; for (int i = 0; i < count; i++) - items[i] = c.getItem (i); - - append (items); - } + add( c.getItem(i), i ); - int selected = c.getSelectedIndex(); - if (selected >= 0) - select(selected); + selected = c.getSelectedIndex(); + if( selected >= 0 ) + select( selected ); + } + else + selected = -1; } native void create (); - native void append (String items[]); native int nativeGetSelected (); - native void nativeAdd (String item, int index); - native void nativeRemove (int index); - native void nativeRemoveAll (); native void connectSignals (); native void selectNative (int position); + native void selectNativeUnlocked (int position); + public native void add (String item, int index); + + native void nativeRemove(int index); + + native void nativeRemoveAll(); + public void select (int position) { if (Thread.currentThread() == GtkToolkit.mainThread) @@ -85,42 +90,15 @@ public class GtkChoicePeer extends GtkComponentPeer selectNative (position); } - public void add (String item, int index) + public void remove( int index ) { - int before = nativeGetSelected(); - - nativeAdd (item, index); - - /* Generate an ItemEvent if we added the first one or - if we inserted at or before the currently selected item. */ - if ((before < 0) || (before >= index)) - { - // Must set our state before notifying listeners - ((Choice) awtComponent).select (((Choice) awtComponent).getItem (0)); - postItemEvent (((Choice) awtComponent).getItem (0), ItemEvent.SELECTED); - } + selected = -1; // we do not want to trigger a select event here. + nativeRemove( index ); } - public void remove (int index) - { - int before = nativeGetSelected(); - int after; - - nativeRemove (index); - after = nativeGetSelected(); - - /* Generate an ItemEvent if we are removing the currently selected item - and there are at least one item left. */ - if ((before == index) && (after >= 0)) - { - // Must set our state before notifying listeners - ((Choice) awtComponent).select (((Choice) awtComponent).getItem (0)); - postItemEvent (((Choice) awtComponent).getItem (0), ItemEvent.SELECTED); - } - } - - public void removeAll () + public void removeAll() { + selected = -1; // we do not want to trigger a select event here. nativeRemoveAll(); } @@ -129,8 +107,35 @@ public class GtkChoicePeer extends GtkComponentPeer add (item, position); } - protected void postChoiceItemEvent (String label, int stateChange) + /** + * Callback from the native side on an item-select event, + * which posts an event. The event is only posted if it represents an actual + * change. Selected is set to the peer's state initially, so that the + * first call to select(int) from the constructor will not trigger an event. + * (it should not) + */ + protected void postChoiceItemEvent ( int index ) + { + if( selected != index ) + { + selected = index; + postItemEvent (((Choice) awtComponent).getItem( selected ), + ItemEvent.SELECTED); + } + } + + /** + * Catches the event and calls Choice.select() if the component state + * needs updating. + */ + public void handleEvent (AWTEvent event) { - postItemEvent (label, stateChange); + super.handleEvent( event ); + if( event instanceof ItemEvent ) + if( ((ItemEvent)event).getItemSelectable() == awtComponent && + ((ItemEvent)event).getStateChange() == ItemEvent.SELECTED ) + if( ((Choice)awtComponent).getSelectedIndex() != selected ) + ((Choice)awtComponent).select( selected ); } } + |