From eced91210fd097e28da3221c00e99aaf89fb889d Mon Sep 17 00:00:00 2001 From: graydon Date: Thu, 22 Jan 2004 09:54:19 +0000 Subject: 2004-01-22 Graydon Hoare * gnu/java/awt/peer/gtk/GdkClasspathFontPeer.java: * gnu/java/awt/peer/gtk/GdkGlyphVector.java: Predicate static initialization on GtkToolkit.useGraphics2D(). * java/awt/Component.java (processPaintEvent): Consume event. * javax/swing/AbstractButton.java: Reimplement, document. * javax/swing/DefaultButtonModel.java: Reimplement, document. * javax/swing/JComponent.java (paint): Use double buffer. (listenerList): Enable member. * javax/swing/ToggleButtonModel.java: Remove incorrect constructor. * javax/swing/JToggleButton.java (JToggleButton): Modify model constructor. * javax/swing/SwingUtilities.java (layoutCompoundLabel): Adjust arithmetic. * javax/swing/plaf/basic/BasicButtonUI.java: Reimplement, document. * javax/swing/plaf/basic/BasicGraphicsUtils.java (getPreferredButtonSize): Include margins in calculation. * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c (Java_gnu_java_awt_peer_gtk_GtkWindowPeer_connectSignals): Receive up events from subordinate layout component. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@76344 138bc75d-0d04-0410-961f-82ee72b054a4 --- libjava/javax/swing/DefaultButtonModel.java | 459 ++++++++++++++++++++++------ 1 file changed, 371 insertions(+), 88 deletions(-) (limited to 'libjava/javax/swing/DefaultButtonModel.java') diff --git a/libjava/javax/swing/DefaultButtonModel.java b/libjava/javax/swing/DefaultButtonModel.java index 52b78b33782..1997e6a1ff2 100644 --- a/libjava/javax/swing/DefaultButtonModel.java +++ b/libjava/javax/swing/DefaultButtonModel.java @@ -1,5 +1,5 @@ /* DefaultButtonModel.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -35,9 +35,10 @@ 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 javax.swing; +import java.awt.AWTEvent; +import java.awt.AWTEventMulticaster; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.ItemEvent; @@ -49,130 +50,412 @@ import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; import javax.swing.event.EventListenerList; -public class DefaultButtonModel - implements ButtonModel, Serializable +/** + * The purpose of this class is to model the dynamic state of an abstract + * button. The concrete button type holding this state may be a a "toggle" + * button (checkbox, radio button) or a "push" button (menu button, button). + * + * Any change to the model's properties will trigger the firing of a + * ChangeEvent. + * + * Any change to the "pressed" property will trigger the firing of an + * ItemEvent in addition to ChangeEvent. + * + * Any change which causes the enabled, armed and pressed properties to + * simultaneously become true will trigger the firing of an + * ActionEvent in addition to the ChangeEvent. + * + * @author Graydon Hoare (graydon&064;redhat.com) + */ +public class DefaultButtonModel implements ButtonModel, Serializable { static final long serialVersionUID = -5342609566534980231L; - Vector actions = new Vector(); + /** Indicates that the button is partially committed to being + pressed, but not entirely. This usually happens when a user has pressed + but not yet released the mouse button. */ + static int ARMED = 1; - Vector items = new Vector(); - Vector changes = new Vector(); - ButtonGroup group; - JComponent comp; + /** State constant indicating that the button is enabled. Buttons cannot + be pressed or selected unless they are enabled. */ + static int ENABLED = 2; - - DefaultButtonModel(JComponent a) - { - comp = a; - } + /** State constant indicating that the button has been fully + pressed. This usually happens when a user has released the mouse over a + previously "armed" button. */ + static int PRESSED = 4; + + /** State constant indicating that the mouse is currently positioned over + the button. */ + static int ROLLOVER = 8; + /** State constant indicating that the button is selected. This constant + is only meaningful for toggle-type buttons (radio buttons, + checkboxes). */ + static int SELECTED = 16; + + /** Represents the "state properties" (armed, enabled, pressed, rollover + and selected) by a bitwise combination of integer constants. */ + int stateMask; + + /** List of ItemListeners, ChangeListeners, and ActionListeners + registered on this model. */ + EventListenerList listenerList; + + /** The single ChangeEvent this model (re)uses to call its + ChangeListeners. */ + ChangeEvent changeEvent; + + /** The group this model belongs to. Only one button in a group may be + selected at any given time. */ + ButtonGroup group; + /** The key code (one of {@link java.awt.event.KeyEvent} VK_*) used to + press this button via a keyboard interface. */ + int mnemonic; + + /** The string used as the "command" property of any ActionEvent this + model sends. */ + String actionCommand; + + public DefaultButtonModel() + { + stateMask = 0; + listenerList = new EventListenerList(); + changeEvent = new ChangeEvent(this); + } + + /** + * Return null. Use {@link AbstractButton} if you wish to + * interface with a button via an {@link ItemSelectable} interface. + * + * @return null + */ public Object[] getSelectedObjects() { return null; } - - public void fireItemStateChanged(ItemEvent event) - { - for (int i=0;itrue. + * + * @param e The ActionEvent to fire + */ + public void fireActionPerformed(ActionEvent e) + { + EventListener[] ll = listenerList.getListeners(ActionListener.class); + for (int i = 0; i < ll.length; i++) + ((ActionListener)ll[i]).actionPerformed(e); + } + + /** + * Inform each ChangeListener in the {@link listenerList} that a + * ChangeEvent has occurred. This happens in response to the any change + * to a property of the model. + * + * @param event The ChangeEvent to fire + */ + public void fireStateChanged(ChangeEvent e) + { + EventListener[] ll = listenerList.getListeners(ChangeListener.class); + for (int i = 0; i < ll.length; i++) + ((ChangeListener)ll[i]).stateChanged(e); + } + + /** + * Helper method to fire a ChangeEvent with the model as the event's + * source. + */ + protected void changeState(int stateflag, boolean b) { - for (int i=0;itrue at a time. + * + * @param g The new "group" property + */ + public void setGroup(ButtonGroup g) + { + if (group != g) + { + group = g; + fireStateChanged(changeEvent); } } - public boolean isSelected() { return sel; } } - - - - - - - -- cgit v1.2.3