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 /java/awt/Choice.java | |
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 'java/awt/Choice.java')
-rw-r--r-- | java/awt/Choice.java | 77 |
1 files changed, 34 insertions, 43 deletions
diff --git a/java/awt/Choice.java b/java/awt/Choice.java index 7e3334d45..3352b1b5e 100644 --- a/java/awt/Choice.java +++ b/java/awt/Choice.java @@ -177,9 +177,8 @@ public class Choice extends Component if (i < 0 || i >= pItems.size()) return false; - Choice.this.processItemEvent(new ItemEvent(Choice.this, - ItemEvent.ITEM_STATE_CHANGED, - this, ItemEvent.SELECTED)); + Choice.this.select( i ); + return true; } } @@ -246,14 +245,11 @@ public class Choice extends Component pItems.addElement(item); - int i = pItems.size () - 1; if (peer != null) - { - ChoicePeer cp = (ChoicePeer) peer; - cp.add (item, i); - } - else if (selectedIndex == -1) - select(0); + ((ChoicePeer) peer).add(item, getItemCount() - 1); + + if (selectedIndex == -1) + select( 0 ); } /** @@ -293,11 +289,9 @@ public class Choice extends Component pItems.insertElementAt(item, index); if (peer != null) - { - ChoicePeer cp = (ChoicePeer) peer; - cp.add (item, index); - } - else if (selectedIndex == -1 || selectedIndex >= index) + ((ChoicePeer) peer).add (item, index); + + if (selectedIndex == -1 || selectedIndex >= index) select(0); } @@ -332,20 +326,21 @@ public class Choice extends Component pItems.removeElementAt(index); if (peer != null) + ((ChoicePeer) peer).remove( index ); + + if( getItemCount() == 0 ) + selectedIndex = -1; + else { - ChoicePeer cp = (ChoicePeer) peer; - cp.remove (index); - } - else - { - if (getItemCount() == 0) - selectedIndex = -1; - else if (index == selectedIndex) - select(0); + if( index == selectedIndex ) + { + if( peer != null ) + ((ChoicePeer)peer).select( 0 ); // force an event here + } + else if( selectedIndex > index ) + select( selectedIndex - 1 ); } - if (selectedIndex > index) - --selectedIndex; } /** @@ -418,13 +413,12 @@ public class Choice extends Component if ((index < 0) || (index >= getItemCount())) throw new IllegalArgumentException("Bad index: " + index); - if (pItems.size() > 0) { - selectedIndex = index; - ChoicePeer cp = (ChoicePeer) peer; - if (cp != null) { - cp.select(index); - } - } + if( selectedIndex == index ) + return; + + selectedIndex = index; + if( peer != null ) + ((ChoicePeer)peer).select( index ); } /** @@ -437,8 +431,8 @@ public class Choice extends Component public synchronized void select(String item) { int index = pItems.indexOf(item); - if (index >= 0) - select(index); + if( index >= 0 ) + select( index ); } /** @@ -490,12 +484,12 @@ public class Choice extends Component void dispatchEventImpl(AWTEvent e) { - if (e.id <= ItemEvent.ITEM_LAST - && e.id >= ItemEvent.ITEM_FIRST - && (item_listeners != null || (eventMask & AWTEvent.ITEM_EVENT_MASK) != 0)) + super.dispatchEventImpl(e); + + if( e.id <= ItemEvent.ITEM_LAST && e.id >= ItemEvent.ITEM_FIRST && + ( item_listeners != null || + ( eventMask & AWTEvent.ITEM_EVENT_MASK ) != 0 ) ) processEvent(e); - else - super.dispatchEventImpl(e); } /** @@ -506,9 +500,6 @@ public class Choice extends Component protected void processItemEvent(ItemEvent event) { int index = pItems.indexOf((String) event.getItem()); - // Don't call back into the peers when selecting index here - if (event.getStateChange() == ItemEvent.SELECTED) - this.selectedIndex = index; if (item_listeners != null) item_listeners.itemStateChanged(event); } |