diff -x '*~' -x '*.class' -x '*.j' -x '*.so*' -x '*.jar' -x '*.o' -wNru ../cvs-2/src/java/org/gnu/gtk/OptionMenu.java ./src/java/org/gnu/gtk/OptionMenu.java --- ../cvs-2/src/java/org/gnu/gtk/OptionMenu.java 2003-10-05 03:28:52.000000000 +0300 +++ ./src/java/org/gnu/gtk/OptionMenu.java 2003-10-05 05:58:07.000000000 +0300 @@ -20,7 +20,13 @@ package org.gnu.gtk; +import java.util.Vector; + +import org.gnu.glib.EventMap; import org.gnu.glib.Type; +import org.gnu.gtk.event.OptionMenuEvent; +import org.gnu.gtk.event.OptionMenuListener; +import org.gnu.gtk.event.GtkEventType; /** * An OptionMenu is a widget that allows the user to choose from a list @@ -105,6 +111,88 @@ gtk_option_menu_set_history( handle, index ); } + /* ************************************** + * EVENT LISTENERS + ****************************************/ + + /** + * Listeners for handling button events + */ + private Vector optionMenuListeners = null; + + /** + * Register an object to handle optionMenu events. + * @see org.gnu.gtk.event.OptionMenuListener + */ + public void addListener(OptionMenuListener listener) { + // Don't add the listener a second time if it is in the Vector. + int i = findListener(optionMenuListeners, listener); + if (i == -1) { + if (null == optionMenuListeners) { + optionMenuListeners = new Vector(); + } + optionMenuListeners.addElement(listener); + } + } + /** + * Removes a listener + * @see #addListener(OptionMenuListener) + */ + public void removeListener(OptionMenuListener listener) { + int i = findListener(optionMenuListeners, listener); + if (i > -1) { + optionMenuListeners.remove(i); + } + if (0 == optionMenuListeners.size()) { + optionMenuListeners = null; + } + } + + protected void fireOptionMenuEvent(OptionMenuEvent event) { + if (null == optionMenuListeners) { + return; + } + int size = optionMenuListeners.size(); + int i = 0; + while (i < size) { + OptionMenuListener bl = (OptionMenuListener)optionMenuListeners.elementAt(i); + bl.optionMenuEvent(event); + i++; + } + } + + private void handleChange() { + fireOptionMenuEvent(new OptionMenuEvent(this, OptionMenuEvent.Type.CHANGE)); + } + + protected void initializeEventHandlers() { + super.initializeEventHandlers(); + evtMap.initialize(this); + } + + public Class getEventListenerClass(String signal) { + return evtMap.getListenerClass(signal); + } + + public GtkEventType getEventType(String signal) { + return evtMap.getEventType(signal); + } + + private static EventMap evtMap = new EventMap(); + static { + addEvents(evtMap); + } + + /** + * Implementation method to build an EventMap for this widget class. + * Not useful (or supported) for application use. + */ + protected static void addEvents(EventMap evtMap) { + evtMap.addEvent("changed", "handleChange", + OptionMenuEvent.Type.CHANGE, + OptionMenuListener.class); + } + /**************************************** * BEGINNING OF GENERATED CODE ****************************************/ diff -x '*~' -x '*.class' -x '*.j' -x '*.so*' -x '*.jar' -x '*.o' -wNru ../cvs-2/src/java/org/gnu/gtk/event/OptionMenuEvent.java ./src/java/org/gnu/gtk/event/OptionMenuEvent.java --- ../cvs-2/src/java/org/gnu/gtk/event/OptionMenuEvent.java 1970-01-01 02:00:00.000000000 +0200 +++ ./src/java/org/gnu/gtk/event/OptionMenuEvent.java 2003-10-05 05:59:51.000000000 +0300 @@ -0,0 +1,50 @@ +/* + * Java-Gnome Bindings Library + * + * Copyright 1998-2002 the Java-Gnome Team, all rights reserved. + * + * The Java-Gnome Team Members: + * Jean Van Wyk + * Jeffrey S. Morgan + * Dan Bornstein + * + * The Java-Gnome bindings library is free software distributed under + * the terms of the GNU Library General Public License version 2. + */ + +package org.gnu.gtk.event; + +/** + * An event represeting action by a {@link org.gnu.gtk.OptionMenu} widget. + */ +public class OptionMenuEvent extends GtkEvent { + + /** + * Type of a OptionMenuEvent + */ + public static class Type extends GtkEventType { + private Type(int id, String name){ + super(id, name); + } + /** + * Emitted when a option menu selection changes. + */ + public static final Type CHANGE = new Type(1, "CHANGE"); + } + + + /** + * Creates a new OptionMenu Event. This is used internally by + * java-gnome. Users only have to deal with listeners. + */ + public OptionMenuEvent(Object source, OptionMenuEvent.Type type) { + super(source, type); + } + + /** + * @return True if the type of this event is the same as that stated. + */ + public boolean isOfType(OptionMenuEvent.Type type){ + return (type.getID() == type.getID()); + } +} diff -x '*~' -x '*.class' -x '*.j' -x '*.so*' -x '*.jar' -x '*.o' -wNru ../cvs-2/src/java/org/gnu/gtk/event/OptionMenuListener.java ./src/java/org/gnu/gtk/event/OptionMenuListener.java --- ../cvs-2/src/java/org/gnu/gtk/event/OptionMenuListener.java 1970-01-01 02:00:00.000000000 +0200 +++ ./src/java/org/gnu/gtk/event/OptionMenuListener.java 2003-10-05 05:55:55.000000000 +0300 @@ -0,0 +1,26 @@ +/* + * Java-Gnome Bindings Library + * + * Copyright 1998-2002 the Java-Gnome Team, all rights reserved. + * + * The Java-Gnome Team Members: + * Jean Van Wyk + * Jeffrey S. Morgan + * Dan Bornstein + * + * The Java-Gnome bindings library is free software distributed under + * the terms of the GNU Library General Public License version 2. + */ + +package org.gnu.gtk.event; + +/** + * Listener for the {@link org.gnu.gtk.OptionMenu} widget. + */ +public interface OptionMenuListener { + /** + * This method is called whenever a button event occurs. + */ + public void optionMenuEvent(OptionMenuEvent event ); + +}