summaryrefslogtreecommitdiff
path: root/gnu/java
diff options
context:
space:
mode:
authorLillian Angel <langel@redhat.com>2006-06-30 14:47:15 +0000
committerLillian Angel <langel@redhat.com>2006-06-30 14:47:15 +0000
commit0eb701748dbfd2390ece1496946a44d4a085cad3 (patch)
treeda9e2b74d0b2594bbd0ee138d36ed795835c92ab /gnu/java
parente911f0a36cab61c963f9b2abe338b6434435ba1a (diff)
downloadclasspath-0eb701748dbfd2390ece1496946a44d4a085cad3.tar.gz
2006-06-30 Lillian Angel <langel@redhat.com>
Tom Fitzsimmons <fitzsim@redhat.com> * gnu/java/awt/peer/gtk/GtkCheckboxGroupPeer.java: Removed class. * gnu/java/awt/peer/gtk/GtkCheckboxPeer.java: Added current_group, groupMap fields. Added definitions for new native functions. (create): Removed FIXME. Added code to create the check button or radio button when appropriate. Updated groupMap to contain pointer to the newly created group. (setCheckboxGroup): Added code to handle all cases. Removing a button from a group, adding a button to a group, or changing the group of a button. (dispose): Changed to call super. * include/Makefile.am: Removed reference to gnu_java_awt_peer_gtk_GtkCheckboxGroupPeer.h. * include/gnu_java_awt_peer_gtk_GtkCheckboxGroupPeer.h: Removed file. * include/gnu_java_awt_peer_gtk_GtkCheckboxPeer.h: Added definitions for new functions. * native/jni/gtk-peer/Makefile.am: Removed reference to gnu_java_awt_peer_gtk_GtkCheckboxGroupPeer.c. * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxGroupPeer.c: Removed file. * native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCheckboxPeer.c (Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_combobox_get_widget): Renamed to checkbox_get_widget. (Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_connectSignals): Changed to use checkbox_get_widget. (Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_nativeSetCheckboxGroup): Removed. (Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_gtkWidgetModifyFont): Changed to use checkbox_get_widget. (Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_gtkButtonSetLabel): Likewise. (Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_createCheckButton): New function. Creates checkbutton without a group. (Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_createRadioButton): Creates a radio button in a group, using groupPointer. If groupPointer is 0, then a new group is created. (Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_addToGroup): Adds the check button to a group, using groupPointer. A radio button is created in its place. If groupPointer is 0, then a new group is created. (Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_removeFromGroup): The radio button is removed from the group. A check button is created in its place. (Java_gnu_java_awt_peer_gtk_GtkCheckboxPeer_switchToGroup): The radio button is moved to a new group.
Diffstat (limited to 'gnu/java')
-rw-r--r--gnu/java/awt/peer/gtk/GtkCheckboxGroupPeer.java86
-rw-r--r--gnu/java/awt/peer/gtk/GtkCheckboxPeer.java134
2 files changed, 111 insertions, 109 deletions
diff --git a/gnu/java/awt/peer/gtk/GtkCheckboxGroupPeer.java b/gnu/java/awt/peer/gtk/GtkCheckboxGroupPeer.java
deleted file mode 100644
index 46b0733d3..000000000
--- a/gnu/java/awt/peer/gtk/GtkCheckboxGroupPeer.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/* GtkCheckboxGroupPeer.java - Wrap a CheckboxGroup
- Copyright (C) 2002 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package gnu.java.awt.peer.gtk;
-
-import java.awt.CheckboxGroup;
-import java.util.WeakHashMap;
-
-// Note that there is no peer interface for a CheckboxGroup. We
-// introduce our own in order to make it easier to keep a piece of
-// native state for each one.
-public class GtkCheckboxGroupPeer extends GtkGenericPeer
-{
- // This maps from a CheckboxGroup to the native peer.
- private static WeakHashMap map = new WeakHashMap ();
-
- // Find the native peer corresponding to a CheckboxGroup.
- public static synchronized GtkCheckboxGroupPeer
- getCheckboxGroupPeer (CheckboxGroup group)
- {
- if (group == null)
- return null;
- GtkCheckboxGroupPeer nat = (GtkCheckboxGroupPeer) map.get (group);
- if (nat == null)
- {
- nat = new GtkCheckboxGroupPeer ();
- map.put (group, nat);
- }
- return nat;
- }
-
- private GtkCheckboxGroupPeer ()
- {
- // We don't need any special state here. Note that we can't store
- // a reference to the java-side CheckboxGroup. That would mean
- // they could never be collected.
- super (null);
- }
-
- // Dispose of our native resources.
- public native void dispose ();
-
- // Remove a given checkbox from this group.
- public native void remove (GtkCheckboxPeer box);
-
- // When collected, clean up the native state.
- protected void finalize ()
- {
- dispose ();
- }
-}
diff --git a/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java b/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java
index 2963c4334..fc50ee028 100644
--- a/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java
+++ b/gnu/java/awt/peer/gtk/GtkCheckboxPeer.java
@@ -40,20 +40,32 @@ package gnu.java.awt.peer.gtk;
import java.awt.Checkbox;
import java.awt.CheckboxGroup;
-import java.awt.peer.CheckboxPeer;
-
import java.awt.event.ItemEvent;
+import java.awt.peer.CheckboxPeer;
+import java.util.WeakHashMap;
+/**
+ * This class wraps either a GtkCheckButton or a GtkOptionButton
+ * depending on if this peer's owner belongs to a CheckboxGroup.
+ */
public class GtkCheckboxPeer extends GtkComponentPeer
implements CheckboxPeer
{
- // Group from last time it was set.
- public GtkCheckboxGroupPeer old_group;
+ // The CheckboxGroup to which this GtkCheckboxPeer's owner belongs.
+ public CheckboxGroup current_group;
// The current state of the GTK checkbox.
- private boolean currentState;
+ private boolean currentState;
+
+ // A map from CheckboxGroup to GSList* GTK option group pointer.
+ private static WeakHashMap groupMap = new WeakHashMap();
- public native void create (GtkCheckboxGroupPeer group);
- public native void nativeSetCheckboxGroup (GtkCheckboxGroupPeer group);
+ public native void createCheckButton ();
+ public native long createRadioButton (long groupPointer);
+
+ public native long addToGroup (long groupPointer);
+ public native long removeFromGroup ();
+ public native long switchToGroup (long groupPointer);
+
public native void connectSignals ();
/**
@@ -68,14 +80,37 @@ public class GtkCheckboxPeer extends GtkComponentPeer
super (c);
}
- // FIXME: we must be able to switch between a checkbutton and a
- // radiobutton dynamically.
public void create ()
{
Checkbox checkbox = (Checkbox) awtComponent;
- CheckboxGroup g = checkbox.getCheckboxGroup ();
- old_group = GtkCheckboxGroupPeer.getCheckboxGroupPeer (g);
- create (old_group);
+ current_group = checkbox.getCheckboxGroup ();
+ if (current_group == null)
+ {
+ // Initially we're not part of a group so we're backed by a
+ // GtkCheckButton.
+ createCheckButton();
+ }
+ else
+ {
+ // Initially we're part of a group.
+
+ // See if this group is already stored in our map.
+ Long groupPointer = (Long) groupMap.get(current_group);
+ if (groupPointer == null)
+ {
+ // We don't know about this group. Create a new native
+ // group pointer for this group and store it in our map.
+ groupMap.put(current_group, new Long (createRadioButton(0)));
+ }
+ else
+ {
+ // We already know about this group. Pass the
+ // corresponding native group pointer value to the native
+ // create method.
+ groupMap.put(current_group,
+ new Long(createRadioButton(groupPointer.longValue())));
+ }
+ }
currentState = checkbox.getState();
gtkToggleButtonSetActive(currentState);
@@ -106,14 +141,71 @@ public class GtkCheckboxPeer extends GtkComponentPeer
public void setCheckboxGroup (CheckboxGroup group)
{
- GtkCheckboxGroupPeer gp
- = GtkCheckboxGroupPeer.getCheckboxGroupPeer (group);
- if (gp != old_group)
+ if (current_group == null && group != null)
+ {
+ // This peer's owner is currently not in a group, and now
+ // we're adding it to a group. This means that the backing
+ // GtkWidget will change from a GtkCheckButton to a
+ // GtkRadioButton.
+
+ current_group = group;
+
+ // See if the new group is already stored in our map.
+ Long groupPointer = (Long) groupMap.get(current_group);
+ if (groupPointer == null)
+ {
+ // We don't know about this group. Create a new native
+ // group pointer for this group and store it in our map.
+ groupMap.put(current_group, new Long (addToGroup(0)));
+ }
+ else
+ {
+ // We already know about this group. Pass the
+ // corresponding native group pointer value to the native
+ // create method.
+ groupMap.put(current_group,
+ new Long(addToGroup(groupPointer.longValue())));
+ }
+ }
+ else if (current_group != null && group == null)
+ {
+ // This peer's owner is currently in a group, and now we're
+ // removing it from a group. This means that the backing
+ // GtkWidget will change from a GtkRadioButton to a
+ // GtkCheckButton.
+ groupMap.put(current_group, new Long (removeFromGroup()));
+ current_group = group;
+ }
+ else if (current_group == null && group == null)
+ {
+ // This peer's owner is currently not in a group, and we're
+ // not adding it to a group, so simply return.
+ return;
+ }
+ else if (current_group != group)
{
- if (old_group != null)
- old_group.remove (this);
- nativeSetCheckboxGroup (gp);
- old_group = gp;
+ // This peer's owner is currently in a group, and now we're
+ // putting it in another group. This means that we must
+ // remove the backing GtkRadioButton from one group and add it
+ // to the other group.
+
+ // See if the new group is already stored in our map.
+ Long groupPointer = (Long) groupMap.get(group);
+ if (groupPointer == null)
+ {
+ // We don't know about this group. Create a new native
+ // group pointer for this group and store it in our map.
+ groupMap.put(group, new Long (switchToGroup(0)));
+ }
+ else
+ {
+ // We already know about this group. Pass the
+ // corresponding native group pointer value to the native
+ // create method.
+ groupMap.put(group,
+ new Long(switchToGroup(groupPointer.longValue())));
+ }
+ current_group = group;
}
}
@@ -133,10 +225,6 @@ public class GtkCheckboxPeer extends GtkComponentPeer
public void dispose ()
{
- // Notify the group so that the native state can be cleaned up
- // appropriately.
- if (old_group != null)
- old_group.remove (this);
super.dispose ();
}
}