diff options
Diffstat (limited to 'libjava/classpath/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java')
| -rw-r--r-- | libjava/classpath/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java | 57 |
1 files changed, 28 insertions, 29 deletions
diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java index 3e05cf8ab07..094aa3c0391 100644 --- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java +++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java @@ -1,5 +1,5 @@ /* GtkCheckboxPeer.java -- Implements CheckboxPeer with GTK - Copyright (C) 1998, 1999, 2002, 2003 Free Software Foundation, Inc. + Copyright (C) 1998, 1999, 2002, 2003, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -42,6 +42,8 @@ import java.awt.Checkbox; import java.awt.CheckboxGroup; import java.awt.peer.CheckboxPeer; +import java.awt.event.ItemEvent; + public class GtkCheckboxPeer extends GtkComponentPeer implements CheckboxPeer { @@ -49,12 +51,15 @@ public class GtkCheckboxPeer extends GtkComponentPeer public GtkCheckboxGroupPeer old_group; // The current state of the GTK checkbox. private boolean currentState; - private boolean changing = false; public native void create (GtkCheckboxGroupPeer group); public native void nativeSetCheckboxGroup (GtkCheckboxGroupPeer group); public native void connectSignals (); - native void gtkWidgetModifyFont (String name, int style, int size); + + /** + * Overridden to set Font of label inside button. + */ + protected native void gtkWidgetModifyFont(String name, int style, int size); native void gtkButtonSetLabel (String label); native void gtkToggleButtonSetActive (boolean is_active); @@ -71,23 +76,24 @@ public class GtkCheckboxPeer extends GtkComponentPeer CheckboxGroup g = checkbox.getCheckboxGroup (); old_group = GtkCheckboxGroupPeer.getCheckboxGroupPeer (g); create (old_group); - gtkToggleButtonSetActive (checkbox.getState ()); + currentState = checkbox.getState(); + gtkToggleButtonSetActive(currentState); gtkButtonSetLabel (checkbox.getLabel ()); } - public void setState (boolean state) + /** + * Sets native GtkCheckButton is state is different from current + * state. Will set currentState to state to prevent posting an + * event since events should only be posted for user initiated + * clicks on the GtkCheckButton. + */ + synchronized public void setState (boolean state) { - // prevent item_toggled_cb -> postItemEvent -> - // awtComponent.setState -> this.setState -> - // gtkToggleButtonSetActive self-deadlock on the GDK lock. - if (changing && Thread.currentThread() == GtkToolkit.mainThread) + if (currentState != state) { - changing = false; - return; + currentState = state; + gtkToggleButtonSetActive(state); } - - if (currentState != state) - gtkToggleButtonSetActive (state); } public void setLabel (String label) @@ -111,22 +117,15 @@ public class GtkCheckboxPeer extends GtkComponentPeer // Override the superclass postItemEvent so that the peer doesn't // need information that we have. // called back by native side: item_toggled_cb - public void postItemEvent (Object item, int stateChange) + synchronized public void postItemEvent(Object item, boolean state) { - Checkbox currentCheckBox = ((Checkbox)awtComponent); - // A firing of the event is only desired if the state has changed due to a - // button press. The currentCheckBox's state must be different from the - // one that the stateChange is changing to. - // stateChange = 1 if it goes from false -> true - // stateChange = 2 if it goes from true -> false - if (( !currentCheckBox.getState() && stateChange == 1) - || (currentCheckBox.getState() && stateChange == 2)) - { - super.postItemEvent (awtComponent, stateChange); - currentState = !currentCheckBox.getState(); - changing = true; - currentCheckBox.setState(currentState); - } + // Only fire event is state actually changed. + if (currentState != state) + { + currentState = state; + super.postItemEvent(awtComponent, + state ? ItemEvent.SELECTED : ItemEvent.DESELECTED); + } } public void dispose () |

