diff options
Diffstat (limited to 'javax/swing/JComponent.java')
-rw-r--r-- | javax/swing/JComponent.java | 158 |
1 files changed, 73 insertions, 85 deletions
diff --git a/javax/swing/JComponent.java b/javax/swing/JComponent.java index b212c2717..230a8a33a 100644 --- a/javax/swing/JComponent.java +++ b/javax/swing/JComponent.java @@ -69,6 +69,7 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.beans.PropertyVetoException; import java.beans.VetoableChangeListener; +import java.beans.VetoableChangeSupport; import java.io.Serializable; import java.util.ArrayList; import java.util.EventListener; @@ -683,6 +684,11 @@ public abstract class JComponent extends Container implements Serializable */ protected EventListenerList listenerList = new EventListenerList(); + /** + * Handles VetoableChangeEvents. + */ + private VetoableChangeSupport vetoableChangeSupport; + /** * Storage for "client properties", which are key/value pairs associated * with this component by a "client", such as a user application or a @@ -874,7 +880,8 @@ public abstract class JComponent extends Container implements Serializable */ public void removeVetoableChangeListener(VetoableChangeListener listener) { - listenerList.remove(VetoableChangeListener.class, listener); + if (vetoableChangeSupport != null) + vetoableChangeSupport.removeVetoableChangeListener(listener); } /** @@ -890,23 +897,6 @@ public abstract class JComponent extends Container implements Serializable } /** - * Register a <code>PropertyChangeListener</code> for a specific, named - * property. To listen to all property changes, regardless of name, use - * {@link #addPropertyChangeListener(PropertyChangeListener)} instead. - * - * @param propertyName The property name to listen to - * @param listener The listener to register - * - * @see #removePropertyChangeListener(String, PropertyChangeListener) - * @see #changeSupport - */ - public void addPropertyChangeListener(String propertyName, - PropertyChangeListener listener) - { - listenerList.add(PropertyChangeListener.class, listener); - } - - /** * Register a <code>VetoableChangeListener</code>. * * @param listener The listener to register @@ -916,7 +906,10 @@ public abstract class JComponent extends Container implements Serializable */ public void addVetoableChangeListener(VetoableChangeListener listener) { - listenerList.add(VetoableChangeListener.class, listener); + // Lazily instantiate this, it's rarely needed. + if (vetoableChangeSupport == null) + vetoableChangeSupport = new VetoableChangeSupport(this); + vetoableChangeSupport.addVetoableChangeListener(listener); } /** @@ -969,75 +962,76 @@ public abstract class JComponent extends Container implements Serializable } /** - * A variant of {@link #firePropertyChange(String,Object,Object)} - * for properties with <code>boolean</code> values. + * Call {@link VetoableChangeListener#vetoableChange} on all listeners + * registered to listen to a given property. Any method which changes + * the specified property of this component should call this method. * - * @specnote It seems that in JDK1.5 all property related methods have been - * moved to java.awt.Component, except this and 2 others. We call - * super here. I guess this will also be removed in one of the next - * releases. + * @param propertyName The property which changed + * @param oldValue The old value of the property + * @param newValue The new value of the property + * + * @throws PropertyVetoException if the change was vetoed by a listener + * + * @see #addVetoableChangeListener + * @see #removeVetoableChangeListener */ - public void firePropertyChange(String propertyName, boolean oldValue, - boolean newValue) + protected void fireVetoableChange(String propertyName, Object oldValue, + Object newValue) + throws PropertyVetoException { - super.firePropertyChange(propertyName, oldValue, newValue); + if (vetoableChangeSupport != null) + vetoableChangeSupport.fireVetoableChange(propertyName, oldValue, newValue); } + /** - * A variant of {@link #firePropertyChange(String,Object,Object)} - * for properties with <code>char</code> values. + * Fires a property change for a primitive integer property. + * + * @param property the name of the property + * @param oldValue the old value of the property + * @param newValue the new value of the property * - * @specnote It seems that in JDK1.5 all property related methods have been - * moved to java.awt.Component, except this and 2 others. We call - * super here. I guess this will also be removed in one of the next - * releases. + * @specnote This method is implemented in + * {@link Component#firePropertyChange(String, int, int)}. It is + * only here because it is specified to be public, whereas the + * Component method is protected. */ - public void firePropertyChange(String propertyName, char oldValue, - char newValue) + public void firePropertyChange(String property, int oldValue, int newValue) { - super.firePropertyChange(propertyName, oldValue, newValue); + super.firePropertyChange(property, oldValue, newValue); } - + /** - * A variant of {@link #firePropertyChange(String,Object,Object)} - * for properties with <code>int</code> values. + * Fires a property change for a primitive boolean property. * - * @specnote It seems that in JDK1.5 all property related methods have been - * moved to java.awt.Component, except this and 2 others. We call - * super here. I guess this will also be removed in one of the next - * releases. + * @param property the name of the property + * @param oldValue the old value of the property + * @param newValue the new value of the property + * + * @specnote This method is implemented in + * {@link Component#firePropertyChange(String, boolean, boolean)}. + * It is only here because it is specified to be public, whereas + * the Component method is protected. */ - public void firePropertyChange(String propertyName, int oldValue, - int newValue) + public void firePropertyChange(String property, boolean oldValue, + boolean newValue) { - super.firePropertyChange(propertyName, oldValue, newValue); + super.firePropertyChange(property, oldValue, newValue); } /** - * Call {@link VetoableChangeListener#vetoableChange} on all listeners - * registered to listen to a given property. Any method which changes - * the specified property of this component should call this method. + * Fires a property change for a primitive character property. * - * @param propertyName The property which changed - * @param oldValue The old value of the property - * @param newValue The new value of the property - * - * @throws PropertyVetoException if the change was vetoed by a listener - * - * @see #addVetoableChangeListener - * @see #removeVetoableChangeListener + * @param property the name of the property + * @param oldValue the old value of the property + * @param newValue the new value of the property */ - protected void fireVetoableChange(String propertyName, Object oldValue, - Object newValue) - throws PropertyVetoException + public void firePropertyChange(String property, char oldValue, + char newValue) { - VetoableChangeListener[] listeners = getVetoableChangeListeners(); - - PropertyChangeEvent evt = - new PropertyChangeEvent(this, propertyName, oldValue, newValue); - - for (int i = 0; i < listeners.length; i++) - listeners[i].vetoableChange(evt); + // FIXME - This method is already public in awt Component, but + // is included here to work around a compilation bug in gcj 4.1. + super.firePropertyChange(property, oldValue, newValue); } /** @@ -1865,8 +1859,7 @@ public abstract class JComponent extends Container implements Serializable continue; Rectangle compBounds = comp.getBounds(); - boolean isOpaque = comp instanceof JComponent - && ((JComponent) comp).isOpaque(); + boolean isOpaque = comp.isOpaque(); // Add all the current paint rectangles that intersect with the // component to the component's paint rectangle array. @@ -1884,7 +1877,7 @@ public abstract class JComponent extends Container implements Serializable int x, y, w, h; Rectangle rect = new Rectangle(); - // The north retangle. + // The north rectangle. x = Math.max(compBounds.x, r.x); y = r.y; w = Math.min(compBounds.width, r.width + r.x - x); @@ -2018,7 +2011,6 @@ public abstract class JComponent extends Container implements Serializable */ private void paintChildrenOptimized(Graphics g) { - Shape originalClip = g.getClip(); Rectangle inner = SwingUtilities.calculateInnerArea(this, rectCache); g.clipRect(inner.x, inner.y, inner.width, inner.height); Component[] children = getComponents(); @@ -2037,20 +2029,14 @@ public abstract class JComponent extends Container implements Serializable continue; Rectangle bounds = children[i].getBounds(rectCache); - Rectangle oldClip = g.getClipBounds(); - if (oldClip == null) - oldClip = bounds; - if (!g.hitClip(bounds.x, bounds.y, bounds.width, bounds.height)) continue; - boolean translated = false; Graphics g2 = g.create(bounds.x, bounds.y, bounds.width, bounds.height); children[i].paint(g2); g2.dispose(); } - g.setClip(originalClip); } /** @@ -2118,16 +2104,13 @@ public abstract class JComponent extends Container implements Serializable Component root = findPaintRoot(r); // If no paint root is found, then this component is completely overlapped // by another component and we don't need repainting. - if (root == null) - return; - if (root == null || !root.isShowing()) + if (root == null|| !root.isShowing()) return; - - Rectangle rootClip = SwingUtilities.convertRectangle(this, r, root); + SwingUtilities.convertRectangleToAncestor(this, r, root); if (root instanceof JComponent) - ((JComponent) root).paintImmediately2(rootClip); + ((JComponent) root).paintImmediately2(r); else - root.repaint(rootClip.x, rootClip.y, rootClip.width, rootClip.height); + root.repaint(r.x, r.y, r.width, r.height); } /** @@ -2711,6 +2694,11 @@ public abstract class JComponent extends Container implements Serializable */ public void revalidate() { + // As long as we don't have a parent we don't need to do any layout, since + // this is done anyway as soon as we get connected to a parent. + if (getParent() == null) + return; + if (! EventQueue.isDispatchThread()) SwingUtilities.invokeLater(new Runnable() { |