aboutsummaryrefslogtreecommitdiff
path: root/libjava/javax/swing/AbstractButton.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/javax/swing/AbstractButton.java')
-rw-r--r--libjava/javax/swing/AbstractButton.java138
1 files changed, 91 insertions, 47 deletions
diff --git a/libjava/javax/swing/AbstractButton.java b/libjava/javax/swing/AbstractButton.java
index 3c2a4cd..11ab198 100644
--- a/libjava/javax/swing/AbstractButton.java
+++ b/libjava/javax/swing/AbstractButton.java
@@ -51,7 +51,6 @@ import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
-import java.util.EventListener;
import javax.accessibility.AccessibleAction;
import javax.accessibility.AccessibleIcon;
@@ -214,24 +213,28 @@ public abstract class AbstractButton extends JComponent
Action action;
/** The button's current state. */
- ButtonModel model;
+ protected ButtonModel model;
/** The margin between the button's border and its label. */
Insets margin;
- /** a hint to the look and feel class, suggesting which character in the
+ /** A hint to the look and feel class, suggesting which character in the
* button's label should be underlined when drawing the label. */
int mnemonicIndex;
/** Listener the button uses to receive ActionEvents from its model. */
- ActionListener actionListener;
+ protected ActionListener actionListener;
/** Listener the button uses to receive ItemEvents from its model. */
- ItemListener itemListener;
+ protected ItemListener itemListener;
/** Listener the button uses to receive ChangeEvents from its model. */
- ChangeListener changeListener;
+ protected ChangeListener changeListener;
+ /** The time in miliseconds in which clicks get coalesced into a single
+ * <code>ActionEvent</code>. */
+ long multiClickThreshhold;
+
/** Listener the button uses to receive PropertyChangeEvents from its
Action. */
PropertyChangeListener actionPropertyChangeListener;
@@ -296,9 +299,9 @@ public abstract class AbstractButton extends JComponent
/** Fired in a PropertyChangeEvent when the "verticalTextPosition" property changes. */
public static final String VERTICAL_TEXT_POSITION_CHANGED_PROPERTY = "verticalTextPosition";
- /**
+ /**
* A Java Accessibility extension of the AbstractButton.
- */
+ */
protected abstract class AccessibleAbstractButton
extends AccessibleJComponent implements AccessibleAction, AccessibleValue,
AccessibleText
@@ -430,7 +433,7 @@ public abstract class AbstractButton extends JComponent
}
public String getSelectedText()
- {
+ {
return null; // TODO
}
@@ -440,33 +443,6 @@ public abstract class AbstractButton extends JComponent
}
}
- /**
- * Helper class used to subscribe to FocusEvents received by the button.
- */
- private class ButtonFocusListener implements FocusListener
- {
- /**
- * Possibly repaint the model in response to loss of focus.
- *
- * @param event The loss-of-focus event
- */
- public void focusLost(FocusEvent event)
- {
- if (AbstractButton.this.isFocusPainted())
- AbstractButton.this.repaint();
- }
-
- /**
- * Possibly repaint the button in response to acquisition of focus.
- *
- * @param event The gained-focus event
- */
- public void focusGained(FocusEvent event)
- {
- if (AbstractButton.this.isFocusPainted())
- AbstractButton.this.repaint();
- }
- }
/**
* Creates a new AbstractButton object.
@@ -549,12 +525,12 @@ public abstract class AbstractButton extends JComponent
borderPainted = true;
contentAreaFilled = true;
- iconTextGap = 4;
+ focusPainted = true;
+ setFocusable(true);
setAlignmentX(LEFT_ALIGNMENT);
setAlignmentY(CENTER_ALIGNMENT);
- addFocusListener(new ButtonFocusListener());
setDisplayedMnemonicIndex(-1);
}
@@ -602,6 +578,18 @@ public abstract class AbstractButton extends JComponent
}
/**
+ * Returns all added <code>ActionListener</code> objects.
+ *
+ * @return an array of listeners
+ *
+ * @since 1.4
+ */
+ public ActionListener[] getActionListeners()
+ {
+ return (ActionListener[]) listenerList.getListeners(ActionListener.class);
+ }
+
+ /**
* Adds an ItemListener to the button's listener list. When the button's
* model changes state (between any of ARMED, ENABLED, PRESSED, ROLLOVER
* or SELECTED) it fires an ItemEvent, and these listeners will be
@@ -625,6 +613,18 @@ public abstract class AbstractButton extends JComponent
}
/**
+ * Returns all added <code>ItemListener</code> objects.
+ *
+ * @return an array of listeners
+ *
+ * @since 1.4
+ */
+ public ItemListener[] getItemListeners()
+ {
+ return (ItemListener[]) listenerList.getListeners(ItemListener.class);
+ }
+
+ /**
* Adds a ChangeListener to the button's listener list. When the button's
* model changes any of its (non-bound) properties, these listeners will be
* called.
@@ -647,6 +647,18 @@ public abstract class AbstractButton extends JComponent
}
/**
+ * Returns all added <code>ChangeListener</code> objects.
+ *
+ * @return an array of listeners
+ *
+ * @since 1.4
+ */
+ public ChangeListener[] getChangeListeners()
+ {
+ return (ChangeListener[]) listenerList.getListeners(ChangeListener.class);
+ }
+
+ /**
* Calls {@link ItemListener.itemStateChanged} on each ItemListener in
* the button's listener list.
*
@@ -655,9 +667,10 @@ public abstract class AbstractButton extends JComponent
public void fireItemStateChanged(ItemEvent e)
{
e.setSource(this);
- EventListener[] ll = listenerList.getListeners(ItemListener.class);
- for (int i = 0; i < ll.length; i++)
- ((ItemListener)ll[i]).itemStateChanged(e);
+ ItemListener[] listeners = getItemListeners();
+
+ for (int i = 0; i < listeners.length; i++)
+ listeners[i].itemStateChanged(e);
}
/**
@@ -669,9 +682,10 @@ public abstract class AbstractButton extends JComponent
public void fireActionPerformed(ActionEvent e)
{
e.setSource(this);
- EventListener[] ll = listenerList.getListeners(ActionListener.class);
- for (int i = 0; i < ll.length; i++)
- ((ActionListener)ll[i]).actionPerformed(e);
+ ActionListener[] listeners = getActionListeners();
+
+ for (int i = 0; i < listeners.length; i++)
+ listeners[i].actionPerformed(e);
}
/**
@@ -683,9 +697,10 @@ public abstract class AbstractButton extends JComponent
*/
public void fireStateChanged(ChangeEvent e)
{
- EventListener[] ll = listenerList.getListeners(ChangeListener.class);
- for (int i = 0; i < ll.length; i++)
- ((ChangeListener)ll[i]).stateChanged(changeEvent);
+ ChangeListener[] listeners = getChangeListeners();
+
+ for (int i = 0; i < listeners.length; i++)
+ listeners[i].stateChanged(changeEvent);
}
/**
@@ -1879,4 +1894,33 @@ public abstract class AbstractButton extends JComponent
public void updateUI()
{
}
+
+ /**
+ * Returns the current time in milliseconds in which clicks gets coalesced
+ * into a single <code>ActionEvent</code>.
+ *
+ * @return the time in milliseconds
+ *
+ * @since 1.4
+ */
+ public long getMultiClickThreshhold()
+ {
+ return multiClickThreshhold;
+ }
+
+ /**
+ * Sets the time in milliseconds in which clicks gets coalesced into a single
+ * <code>ActionEvent</code>.
+ *
+ * @param threshhold the time in milliseconds
+ *
+ * @since 1.4
+ */
+ public void setMultiClickThreshhold(long threshhold)
+ {
+ if (threshhold < 0)
+ throw new IllegalArgumentException();
+
+ multiClickThreshhold = threshhold;
+ }
}